zjh
2025-01-15 5489d624e6642b459ecf8d143c548ac8a980a8c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.ltkj.hosp.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ltkj.common.utils.DateUtils;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.hosp.domain.TjSurveyOptions;
import com.ltkj.hosp.domain.TjSurveyQuestion;
import com.ltkj.hosp.domain.TjSurveyTempQues;
import com.ltkj.hosp.mapper.TjSurveyQuestionMapper;
import com.ltkj.hosp.service.ITjSurveyQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 问卷问题Service业务层处理
 *
 * @author ltkj_赵佳豪&李格
 * @date 2023-04-07
 */
@Service
public class TjSurveyQuestionServiceImpl extends ServiceImpl<TjSurveyQuestionMapper, TjSurveyQuestion> implements ITjSurveyQuestionService {
    @Autowired
    private TjSurveyQuestionMapper tjSurveyQuestionMapper;
 
    @Autowired
    private ITjSurveyQuestionService tjSurveyQuestionService;
 
    /**
     * 查询问卷问题
     *
     * @param qid 问卷问题主键
     * @return 问卷问题
     */
    @Override
    public TjSurveyQuestion selectTjSurveyQuestionByQid(String qid) {
        return tjSurveyQuestionMapper.selectTjSurveyQuestionByQid(qid);
    }
 
    @Override
    public List<TjSurveyOptions> selectOptionsByQid(String qid) {
        return tjSurveyQuestionMapper.selectOptionsByQid(qid);
    }
 
    /**
     * 查询问卷问题列表
     *
     * @param tjSurveyQuestion 问卷问题
     * @return 问卷问题
     */
    @Override
    public List<TjSurveyQuestion> selectTjSurveyQuestionList(TjSurveyQuestion tjSurveyQuestion) {
        return tjSurveyQuestionMapper.selectTjSurveyQuestionList(tjSurveyQuestion);
    }
 
    /**
     * 新增问卷问题
     *
     * @param tjSurveyQuestion 问卷问题
     * @return 结果
     */
//    @Transactional
    @Override
    public int insertTjSurveyQuestion(TjSurveyQuestion tjSurveyQuestion) {
        tjSurveyQuestion.setCreateTime(DateUtils.getNowDate());
        tjSurveyQuestion.setCreateBy(SecurityUtils.getLoginUser().getUsername());
//        int rows = tjSurveyQuestionMapper.insertTjSurveyQuestion(tjSurveyQuestion);
        if (tjSurveyQuestionService.save(tjSurveyQuestion)) {
            insertTjSurveyOptions(tjSurveyQuestion);
            return 1;
        }
        return 0;
    }
 
    /**
     * 修改问卷问题
     *
     * @param tjSurveyQuestion 问卷问题
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTjSurveyQuestion(TjSurveyQuestion tjSurveyQuestion) {
        tjSurveyQuestion.setUpdateTime(DateUtils.getNowDate());
        tjSurveyQuestionMapper.deleteTjSurveyOptionsByQid(tjSurveyQuestion.getQid());
        insertTjSurveyOptions(tjSurveyQuestion);
        return tjSurveyQuestionMapper.updateTjSurveyQuestion(tjSurveyQuestion);
    }
 
    /**
     * 批量删除问卷问题
     *
     * @param qids 需要删除的问卷问题主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTjSurveyQuestionByQids(String[] qids) {
        tjSurveyQuestionMapper.deleteTjSurveyOptionsByQids(qids);
        return tjSurveyQuestionMapper.deleteTjSurveyQuestionByQids(qids);
    }
 
    /**
     * 删除问卷问题信息
     *
     * @param qid 问卷问题主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTjSurveyQuestionByQid(Long qid) {
        tjSurveyQuestionMapper.deleteTjSurveyOptionsByQid(qid);
        return tjSurveyQuestionMapper.deleteTjSurveyQuestionByQid(qid);
    }
 
    @Override
    public List<TjSurveyTempQues> selectOptionsByMid(String mid) {
        return tjSurveyQuestionMapper.selectOptionsByMid(mid);
    }
 
    @Override
    public List<TjSurveyQuestion> getOptionsByMid(String mid) {
        return tjSurveyQuestionMapper.getOptionsByMid(mid);
    }
 
    /**
     * 新增问卷选项信息
     *
     * @param tjSurveyQuestion 问卷问题对象
     */
    public void insertTjSurveyOptions(TjSurveyQuestion tjSurveyQuestion) {
        List<TjSurveyOptions> tjSurveyOptionsList = tjSurveyQuestion.getTjSurveyOptionsList();
        Long qid = tjSurveyQuestion.getQid();
        if (StringUtils.isNotNull(tjSurveyOptionsList)) {
            List<TjSurveyOptions> list = new ArrayList<TjSurveyOptions>();
            for (TjSurveyOptions tjSurveyOptions : tjSurveyOptionsList) {
                tjSurveyOptions.setQid(qid.toString());
                tjSurveyOptions.setDeleted(0);
                tjSurveyOptions.setCreateBy(SecurityUtils.getLoginUser().getUsername());
                tjSurveyOptions.setCreateTime(DateUtils.getNowDate());
                list.add(tjSurveyOptions);
            }
            if (list.size() > 0) {
                for (TjSurveyOptions tjSurveyOptions : list) {
                    tjSurveyOptions.setDeleted(0);
                    tjSurveyQuestionMapper.insertTjSurveyOptions(tjSurveyOptions);
                }
            }
        }
    }
}