zhaowenxuan
2024-10-21 936e2c79cd741472a6acfe28d730eb644b082cf7
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package com.ltkj.web.controller.system;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
 
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.TreeSelect;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.core.domain.entity.SysDictData;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.ITjSurveyQuestionService;
import com.ltkj.system.service.ISysConfigService;
import com.ltkj.system.service.ISysDeptService;
import com.ltkj.system.service.ISysDictDataService;
import com.ltkj.tduck.domain.UserFormEntity;
import com.ltkj.tduck.enums.FormSourceTypeEnum;
import com.ltkj.tduck.enums.FormStatusEnum;
import com.ltkj.tduck.service.UserFormService;
import com.ltkj.tduck.utils.ShortIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.BusinessType;
import com.ltkj.hosp.service.ITjSurveyTemplateService;
import com.ltkj.common.utils.poi.ExcelUtil;
import com.ltkj.common.core.page.TableDataInfo;
 
/**
 * 问卷模板Controller
 *
 * @author ltkj_赵佳豪&李格
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/hosp/surveyTemplate")
@Api(tags = "问卷模板")
public class TjSurveyTemplateController extends BaseController {
    @Autowired
    private ITjSurveyTemplateService tjSurveyTemplateService;
 
    @Autowired
    private ITjSurveyQuestionService tjSurveyQuestionService;
    @Autowired
    private ISysConfigService configService;
 
    @Autowired
    private UserFormService formService;
 
    @Autowired
    private ISysDeptService deptService;
    /**
     * 判断是否开启填鸭表单设计
     */
    @ApiOperation(value = "判断是否开启填鸭表单设计")
    @GetMapping(value = "/needDesign")
    public AjaxResult needDesign() {
        final String call = configService.selectConfigByKey("need_design");
        return AjaxResult.success(call);
    }
 
    /**
     * 判断该模板是否可删除
     */
    @ApiOperation(value = "判断该模板是否可删除")
    @GetMapping(value = "/canDelete")
    public AjaxResult canDelete(Long id) {
        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(id);
//        List<FwdPlanInfoVo> fwdPlanInfoVos = fwdSqlMapper.canDelete(id);
        if (byId !=null && byId.getQybz().equals("0")){
            return AjaxResult.success(false);
        }
        return AjaxResult.success(true);
    }
 
 
 
    /**
     * 查询问卷模板列表
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:list')")
    @GetMapping("/list")
    public TableDataInfo list(TjSurveyTemplate tjSurveyTemplate) {
        startPage();
        List<TjSurveyTemplate> list = tjSurveyTemplateService.selectTjSurveyTemplateList(tjSurveyTemplate);
        return getDataTable(list);
    }
 
    /**
     * 导出问卷模板列表
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:export')")
    @Log(title = "问卷模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TjSurveyTemplate tjSurveyTemplate) {
        List<TjSurveyTemplate> list = tjSurveyTemplateService.selectTjSurveyTemplateList(tjSurveyTemplate);
        ExcelUtil<TjSurveyTemplate> util = new ExcelUtil<TjSurveyTemplate>(TjSurveyTemplate.class);
        util.exportExcel(response, list, "问卷模板数据");
    }
 
    /**
     * 获取问卷模板详细信息
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:query')")
    @GetMapping(value = "/{mid}")
    public AjaxResult getInfo(@PathVariable("mid") Long mid) {
        return success(tjSurveyTemplateService.selectTjSurveyTemplateByMid(mid));
    }
 
//    /**
//     * 获取问卷模板
//     */
//    @GetMapping("/getQuesByMid")
//    @ApiOperation(value = "获取问卷模板信息")
//    public AjaxResult getQuesByMid(@RequestParam Long mid) {
//        List<TjSurveyQuestion> l1=new ArrayList<>();
//        TjSurveyTemplate byId = tjSurveyTemplateService.selectTjSurveyTemplateByMid(mid);
//        List<TjSurveyTempQues> tjSurveyTempQuesList = byId.getTjSurveyTempQuesList();
//        if (tjSurveyTempQuesList!=null){
//            for (TjSurveyTempQues tjSurveyTempQues : tjSurveyTempQuesList) {
//                TjSurveyQuestion byId1 = tjSurveyQuestionService.selectTjSurveyQuestionByQid(tjSurveyTempQues.getQid());
//                if (byId1!=null){
//                    l1.add(byId1);
//                }
//            }
//            return AjaxResult.success(l1);
//        }
//        return AjaxResult.success("暂无信息");
//    }
 
    @GetMapping("/getQuesByMid")
    @ApiOperation(value = "获取问卷模板信息")
    public AjaxResult getQuesByMid(@RequestParam Long mid) {
        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(Long.valueOf(mid));
        if(null !=byId){
            if ("1".equals(byId.getQybz())){
                return AjaxResult.success("该问卷模板不存在或已停用");
            }
            //判断是否有问题
            if(byId.getDesignId()!=null){
                return AjaxResult.success(byId.getDesignId());
            }
            LambdaQueryWrapper<TjSurveyQuestion> wq1=new LambdaQueryWrapper<>();
            wq1.eq(TjSurveyQuestion::getMid,byId.getMid());
            final List<TjSurveyQuestion> list1 = tjSurveyQuestionService.list(wq1);
            for (TjSurveyQuestion tjSurveyQuestion : list1) {
                final List<TjSurveyOptions> tjSurveyOptions = tjSurveyQuestionService.selectOptionsByQid(String.valueOf(tjSurveyQuestion.getQid()));
                tjSurveyQuestion.setTjSurveyOptionsList(tjSurveyOptions);
            }
            return AjaxResult.success(list1);
 
        }
        return AjaxResult.success("暂无信息");
    }
 
 
    /**
     * 获取问卷模板
     */
    @GetMapping("/getQuesByMids")
    @ApiOperation(value = "获取问卷模板信息")
    public AjaxResult getQuesByMids(@RequestParam Long mid) {
 
        List<TjSurveyQuestion> l1 = new ArrayList<>();
//        TjSurveyTemplate byId = tjSurveyTemplateService.selectTjSurveyTemplateByMid(mid);
        List<TjSurveyTempQues> tjSurveyTempQuesList = tjSurveyQuestionService.selectOptionsByMid(mid.toString());
        if (tjSurveyTempQuesList != null && tjSurveyTempQuesList.size()>0) {
            for (TjSurveyTempQues tjSurveyTempQues : tjSurveyTempQuesList) {
                TjSurveyQuestion byId1 = tjSurveyQuestionService.selectTjSurveyQuestionByQid(tjSurveyTempQues.getQid());
                if (byId1 != null) {
                    l1.add(byId1);
                }
            }
            return AjaxResult.success(l1);
        }
        List<TjSurveyQuestion> optionsByMid = tjSurveyQuestionService.getOptionsByMid(mid.toString());
        if(null !=optionsByMid && optionsByMid.size()>0){
            return AjaxResult.success(optionsByMid);
        }
        return AjaxResult.success("暂无信息");
    }
 
 
    /**
     * 新增问卷模板
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:add')")
    @Log(title = "问卷模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TjSurveyTemplate tjSurveyTemplate) {
//        return toAjax(tjSurveyTemplateService.insertTjSurveyTemplate(tjSurveyTemplate));
        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByTjCategory(tjSurveyTemplate.getTempType());
        if(null !=byId){
            return AjaxResult.error("该类型模板已存在  不可重复创建!!!");
        }
        final String call = configService.selectConfigByKey("need_design");
        //判断是否开启填鸭表单设计
        if ("true".equals(call)){
            UserFormEntity form=new UserFormEntity();
            form.setFormKey(ShortIdUtils.genId());
            form.setName("<h2 style=\"text-align: center;\">"+tjSurveyTemplate.getTempName()+"</h2>");
            form.setStatus(1);
            form.setSourceType(1);
            form.setCreateTime(new DateTime());
            form.setType("1");
            form.setDeleted(false);
            final boolean save = formService.save(form);
            if (save){
                tjSurveyTemplate.setDesignId(form.getFormKey());
                final int i = tjSurveyTemplateService.insertTjSurveyTemplate(tjSurveyTemplate);
                if (i==1) {
                    return AjaxResult.success(form);
                }
            }
        }else{
            final int i = tjSurveyTemplateService.insertTjSurveyTemplate(tjSurveyTemplate);
            if (i==1) {
                return AjaxResult.success(false);
            }
        }
        return AjaxResult.success(false);
    }
 
    @GetMapping("/getQuestionsByMid")
    public Map<String, Object> getQuestionsByMid(@RequestParam("mid") Long mid,
                                                 @RequestParam(required = false) String question,
                                                 @RequestParam("pageNum") int pageNum,
                                                 @RequestParam("pageSize") int pageSize) {
        Map<String, Object> res = new HashMap<>();
//        List<TjSurveyQuestion> list = tjSurveyTemplateService.getQuestionsByMid(mid);
        LambdaQueryWrapper<TjSurveyQuestion> wq1=new LambdaQueryWrapper<>();
        wq1.eq(TjSurveyQuestion::getMid,mid);
        if(null !=question && !question.equals("")){
            wq1.like(TjSurveyQuestion::getQuestion,question);
        }
        final List<TjSurveyQuestion> list = tjSurveyQuestionService.list(wq1);
 
        int start = 0, end = 0;
        start = (pageNum - 1) * pageSize;
        end = start + pageSize;
        end = Math.min(list.size(), end);
        List<TjSurveyQuestion> result = new ArrayList<>();
        for (int i = start; i < end; i++) {
            result.add(list.get(i));
        }
        final TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(mid);
        for (TjSurveyQuestion tjSurveyQuestion : result) {
            tjSurveyQuestion.setTemplate(byId);
            final List<TjSurveyOptions> tjSurveyOptions = tjSurveyQuestionService.selectOptionsByQid(String.valueOf(tjSurveyQuestion.getQid()));
            tjSurveyQuestion.setTjSurveyOptionsList(tjSurveyOptions);
        }
        res.put("data", result);
//        res.put("temp", tjSurveyTemplateService.selectTjSurveyTemplateByMid(mid));
        res.put("total", list.size());
        return res;
    }
 
 
    /**
     * 查询问卷模板列表
     */
    @GetMapping("/listByDeptId")
    public AjaxResult listByDeptId(SysDept dept) {
        List<TreeSelect> treeSelects =deptService.selectDeptList1(dept);
        return AjaxResult.success(treeSelects);
    }
 
 
    /**
     * 查询问卷模板列表
     */
    @GetMapping("/listByDeptId1")
    public AjaxResult listByDeptId1() {
        SysDictData data=new SysDictData();
        data.setDictType("question_template_type");
        data.setStatus("0");
        List<TreeTjSurveryTemplate> list = tjSurveyTemplateService.selectDictDataList(data);
        if(null !=list && list.size()>0){
            for (TreeTjSurveryTemplate dictData : list) {
                List<TreeTjSurveryTemplate> templateList = tjSurveyTemplateService.getTreeTjSurveryTemplate(dictData.getVaule());
                dictData.setChildren(templateList);
            }
        }
        return AjaxResult.success(list);
    }
 
 
 
    @GetMapping("/getTjrWnJuanMoBan")
    public AjaxResult getTjrWnJuanMoBan(String tjCategory) {
        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByTjCategory(tjCategory);
//        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(Long.valueOf(mid));
        if(null !=byId){
            if ("1".equals(byId.getQybz())){
                return AjaxResult.success("该问卷模板不存在或已停用");
            }
            //判断是否有问题
            if(byId.getDesignId()!=null){
                return AjaxResult.success(byId.getDesignId());
            }
            LambdaQueryWrapper<TjSurveyQuestion> wq1=new LambdaQueryWrapper<>();
            wq1.eq(TjSurveyQuestion::getMid,byId.getMid());
            final List<TjSurveyQuestion> list1 = tjSurveyQuestionService.list(wq1);
            for (TjSurveyQuestion tjSurveyQuestion : list1) {
                final List<TjSurveyOptions> tjSurveyOptions = tjSurveyQuestionService.selectOptionsByQid(String.valueOf(tjSurveyQuestion.getQid()));
                tjSurveyQuestion.setTjSurveyOptionsList(tjSurveyOptions);
            }
            return AjaxResult.success(list1);
 
        }
        return AjaxResult.success("暂无信息");
    }
 
 
 
    /**
     * 修改问卷模板
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:edit')")
    @Log(title = "问卷模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TjSurveyTemplate tjSurveyTemplate) {
        TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(tjSurveyTemplate.getMid());
        if(null ==byId){
            return AjaxResult.error("该模板不存在!!!");
        }
        return toAjax(tjSurveyTemplateService.updateTjSurveyTemplate(tjSurveyTemplate));
    }
 
    /**
     * 删除问卷模板
     */
    //@PreAuthorize("@ss.hasPermi('hosp:surveyTemplate:remove')")
    @Log(title = "问卷模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mids}")
    public AjaxResult remove(@PathVariable Long[] mids) {
        return toAjax(tjSurveyTemplateService.deleteTjSurveyTemplateByMids(mids));
    }
 
 
    /**
     * 问卷启用禁用
     */
    @GetMapping("/updateQybz")
    @ApiOperation(value = "问卷启用禁用")
    public AjaxResult updateQybz(@RequestParam Long mid,@RequestParam String qybz) {
        final TjSurveyTemplate byId = tjSurveyTemplateService.selectTemplateByMid1(mid);
        byId.setQybz(qybz);
        if ("0".equals(qybz) && tjSurveyTemplateService.qybzTjSurveyTemplateByQy(byId.getMid())==1){
            return AjaxResult.success("启用成功!");
        }else if ("1".equals(qybz) && tjSurveyTemplateService.qybzTjSurveyTemplateByJy(byId.getMid())==1){
            return AjaxResult.success("禁用成功!");
        }else {
            return AjaxResult.error("出错了,请联系工作人员!");
        }
 
    }
}