linzhijie
2021-03-11 93af1c6ffb9ae0e894689ad3a37b548e57d54cff
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.ots.project.exam.service.impl;
 
import com.ots.common.utils.DateUtils;
import com.ots.common.utils.StringUtils;
import com.ots.common.utils.text.Convert;
import com.ots.framework.web.service.DictService;
import com.ots.project.exam.domain.TExamLevel;
import com.ots.project.exam.mapper.TExamLevelMapper;
import com.ots.project.exam.service.ITExamLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
 
/**
 * 问卷类型Service业务层处理
 *
 * @author ots
 * @date 2019-12-15
 */
@Service("examLevel")
public class TExamLevelServiceImpl implements ITExamLevelService {
    @Autowired
    private TExamLevelMapper tExamLevelMapper;
 
    @Autowired
    private DictService dictService;
 
    /**
     * 查询问卷类型
     *
     * @param id 问卷类型ID
     * @return 问卷类型
     */
    @Override
    public TExamLevel selectTExamLevelById(Long id) {
        return tExamLevelMapper.selectTExamLevelById(id);
    }
 
    @Override
    public List<TExamLevel> selectTExamLevelByUuid(String uuid) {
        return tExamLevelMapper.selectTExamLevelByUuid(uuid);
    }
 
    @Override
    public TExamLevel selectTExamLevelByUuidLan(String uuid,String langType) {
        return tExamLevelMapper.selectTExamLevelByUuidLan(uuid,langType);
    }
 
    @Override
    public List<TExamLevel> selectTExamLevelAndTSubjectById(Long id) {
        return tExamLevelMapper.selectTExamLevelAndTSubjectById(id);
    }
 
    /**
     * 查询问卷类型列表
     *
     * @param tExamLevel 问卷类型
     * @return 问卷类型
     */
    @Override
    public List<TExamLevel> selectTExamLevelList(TExamLevel tExamLevel) {
        //globalization(tExamLevel);
        return tExamLevelMapper.selectTExamLevelList(tExamLevel);
    }
 
    // 国际化
    private void globalization(TExamLevel tExamLevel) {
        if(StringUtils.isNotBlank(tExamLevel.getUuid())){
            /*List<DictData> lang_types = this.dictService.getType("lang_type");
            List<TExamLevel> ts = new ArrayList<TExamLevel>();
            for (DictData lang_type : lang_types) {
                TExamLevel l = this.tExamLevelMapper.selectTExamLevelByUuidLan(tExamLevel.getUuid(), lang_type.getDictValue());
                if (l == null) {
                    TExamLevel p = new TExamLevel();
                    p.setUuid(tExamLevel.getUuid());
                    p.setLangType(lang_type.getDictValue());
                    p.setCreateTime(new Date());
                    ts.add(p);
                }
            }
            if (ts.size() > 0) {
                for (TExamLevel t : ts) {
                    this.tExamLevelMapper.insertTExamLevel(t);
                }
            }*/
        }else{
            tExamLevel.setLangType(this.dictService.getLangType(LocaleContextHolder.getLocale().toString()));
        }
    }
 
    public List<TExamLevel> selectTExamLevelList() {
        TExamLevel t = new TExamLevel();
        t.setLangType(this.dictService.getLangType(LocaleContextHolder.getLocale().toString()));
        return tExamLevelMapper.selectTExamLevelList(t);
    }
 
    @Override
    public List<TExamLevel> selectTExamLevelListByType(String type) {
        List<Integer> types = new ArrayList<>();
        if (StringUtils.equals(type, "question")) {
            types.add(1);
            types.add(3);
        }
 
        if (StringUtils.equals(type, "questionnaire")) {
            types.add(1);
            types.add(2);
        }
        return tExamLevelMapper.selectTExamLevelListByType(types.stream().toArray(Integer[]::new));
    }
 
    @Override
    public List<TExamLevel> selectTExamLevelByquestionTemplateIdList(String questionTemplateId) {
        return tExamLevelMapper.selectTExamLevelByquestionTemplateIdList(questionTemplateId);
    }
 
    /**
     * 新增问卷类型
     *
     * @param tExamLevel 问卷类型
     * @return 结果
     */
    @Override
    public int insertTExamLevel(TExamLevel tExamLevel) {
        tExamLevel.setCreateTime(DateUtils.getNowDate());
        tExamLevel.setQuestionTemplateName(dictService.getLabel("questionnaire_template", tExamLevel.getQuestionTemplateId()));
        if (StringUtils.isBlank(tExamLevel.getUuid())) {
                tExamLevel.setUuid(UUID.randomUUID().toString().replaceAll("-",""));
        }
        return tExamLevelMapper.insertTExamLevel(tExamLevel);
    }
 
    /**
     * 修改问卷类型
     *
     * @param tExamLevel 问卷类型
     * @return 结果
     */
    @Override
    public int updateTExamLevel(TExamLevel tExamLevel) {
        tExamLevel.setUpdateTime(DateUtils.getNowDate());
        tExamLevel.setQuestionTemplateName(dictService.getLabel("questionnaire_template", tExamLevel.getQuestionTemplateId()));
        if (StringUtils.isBlank(tExamLevel.getUuid())) {
            tExamLevel.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
        }
        return tExamLevelMapper.updateTExamLevel(tExamLevel);
    }
 
    /**
     * 删除问卷类型对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTExamLevelByIds(String ids) {
        return tExamLevelMapper.deleteTExamLevelByIds(Convert.toStrArray(ids));
    }
 
    /**
     * 删除问卷类型信息
     *
     * @param id 问卷类型ID
     * @return 结果
     */
    public int deleteTExamLevelById(Long id) {
        return tExamLevelMapper.deleteTExamLevelById(id);
    }
}