赵文轩
2024-10-31 75605bab29e6e5db93f4ba1f12d9f2fe9015990c
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
package com.ltkj.web.controller.mall;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.framework.config.UserHoder;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 问卷记录Controller
 * @Company: 西安路泰科技有限公司
 * @Author: zjh
 * @Date: 2023/7/26 08:50
 */
@RestController
@RequestMapping("/cus/surveyRecord")
@Api(tags = "体检小程序端问卷记录调查接口")
public class WxTjSurveyRecordController extends BaseController {
 
    @Resource
    private ITjSurveyRecordService tjSurveyRecordService;
    @Resource
    private ITjCustomerService tjCustomerService;
    @Resource
    private ITjOrderService tjOrderService;
    @Resource
    private TjSurveyRecordDetailService tjSurveyRecordDetailService;
    @Autowired
    private ITjSurveyTemplateService tjSurveyTemplateService;
    @Autowired
    private ITjSurveyQuestionService tjSurveyQuestionService;
 
    /**
     * 小程序判断是否填写过问卷(0未填1已填)
     */
    @GetMapping("/appSurveyByIdCard")
    @ApiOperation(value = "小程序判断是否填写过问卷(0未填1已填)")
    public AjaxResult appSurveyByIdCard(@RequestParam @ApiParam(value = "tjNumber") String tjNumber) {
        LambdaQueryWrapper<TjSurveyRecord> wqqq = new LambdaQueryWrapper<>();
        wqqq.eq(TjSurveyRecord::getTjnumber, tjNumber);
        List<TjSurveyRecord> byId = tjSurveyRecordService.list(wqqq);
        if (byId != null) {
            if (byId.size() > 0) {
                return AjaxResult.success(1);
            } else {
                return AjaxResult.success(0);
            }
        }
        return AjaxResult.success(0);
 
    }
 
    /**
     * 小程序端问卷查询记录
     */
    @GetMapping("/appGetTiJian")
    @ApiOperation(value = "小程序端问卷查询记录")
    public AjaxResult appGetTiJian(@RequestParam @ApiParam(value = "cusIdCard") String cusIdCard) {
        Map<String, Object> res = new HashMap<>();
        LambdaQueryWrapper<TjCustomer> wqqq = new LambdaQueryWrapper<>();
        wqqq.eq(TjCustomer::getCusIdcard, cusIdCard);
        TjCustomer one1 = tjCustomerService.getOne(wqqq);
        if (one1 == null) {
            return AjaxResult.error("查无此人");
        }
        LambdaQueryWrapper<TjOrder> wq0 = new LambdaQueryWrapper<>();
        wq0.eq(TjOrder::getUserId, one1.getCusId());
        List<TjOrder> tjOrders = tjOrderService.list(wq0);
 
        if (tjOrders != null && tjOrders.size() > 0) {
            for (TjOrder tjOrder : tjOrders) {
                if (tjOrder.getFinishTime() != null) {
                    tjOrder.setTjFinishStatus("已完成");
                } else {
                    tjOrder.setTjFinishStatus("未完成");
                }
            }
        }
        res.put("tjOrders", tjOrders);
        res.put("customer", one1);
        return AjaxResult.success(res);
    }
 
 
    /**
     * 新增问卷记录
     */
    @ApiOperation(value = "新增问卷记录")
    @PostMapping
    public AjaxResult add(@RequestBody List<TjSurveyRecord> tjSurveyRecord) {
        if (tjSurveyRecord != null && tjSurveyRecord.size() > 0) {
            List<TjSurveyRecord> a = new ArrayList<>();
            //先放第一个
            a.add(tjSurveyRecord.get(0));
            //对集合进行遍历 如果集合的问题id和第一个id一样
            for (int i = 1; i < tjSurveyRecord.size(); i++) {
                if (a.size()<=1){
                    continue;
                }
                if ((tjSurveyRecord.get(i)).getQid().equals((a.get(i - 1)).getQid())) {
                    a.get(i - 1).getTjSurveyRecordDetailList().add((tjSurveyRecord.get(i).getTjSurveyRecordDetailList()).get(0));
                } else {
                    a.add(tjSurveyRecord.get(i));
                }
            }
            Wxuser wxuser = UserHoder.getWxuser();
            for (TjSurveyRecord surveyRecord : a) {
                surveyRecord.setOpenId(wxuser.getOpenid());
                surveyRecord.setPhone(wxuser.getPhone());
                surveyRecord.setUserName(wxuser.getNickname());
                surveyRecord.setCreateId(String.valueOf(wxuser.getId()));
                surveyRecord.setUpdateId(String.valueOf(wxuser.getId()));
                tjSurveyRecordService.save(surveyRecord);
                List<TjSurveyRecordDetail> recordDetailList = surveyRecord.getTjSurveyRecordDetailList();
                if (null != recordDetailList && recordDetailList.size() > 0) {
                    tjSurveyRecordDetailService.saveBatch(recordDetailList);
                }
            }
        }
        return AjaxResult.success();
    }
 
 
    /**
     * 获取问卷模板
     */
    @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("暂无信息");
    }
}