zjh
2025-02-15 d4ab42ad79027bc6696b524ec4b2b446816d2a08
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
package com.ltkj.web.controller.system;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.core.redis.RedisCache;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.system.service.ISysConfigService;
import com.ltkj.system.service.ISysDeptService;
import com.ltkj.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.common.utils.poi.ExcelUtil;
import com.ltkj.common.core.page.TableDataInfo;
 
/**
 * 问卷记录Controller
 *
 * @author ltkj_赵佳豪&李格
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/hosp/surveyRecord")
public class TjSurveyRecordController extends BaseController {
    @Resource
    private ITjSurveyRecordService tjSurveyRecordService;
    @Resource
    private TjSurveyRecordDetailService tjSurveyRecordDetailService;
    @Resource
    private ITjCustomerService tjCustomerService;
    @Resource
    private ITjOrderService tjOrderService;
 
 
    /**
     * 查询问卷记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TjSurveyRecord tjSurveyRecord) {
        startPage();
        List<TjSurveyRecord> list = tjSurveyRecordService.selectTjSurveyRecordList(tjSurveyRecord);
        if(null !=list && list.size()>0){
            for (TjSurveyRecord record : list) {
                record.setUserName(MatchUtils.hideCusName(record.getUserName()));
               record.setPhone(MatchUtils.hidePhoneNum(record.getPhone()));
            }
        }
        return getDataTable(list);
    }
//
//    /**
//     * 导出问卷记录列表
//     */
//    @Log(title = "问卷记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TjSurveyRecord tjSurveyRecord) {
//        List<TjSurveyRecord> list = tjSurveyRecordService.selectTjSurveyRecordList(tjSurveyRecord);
//        ExcelUtil<TjSurveyRecord> util = new ExcelUtil<TjSurveyRecord>(TjSurveyRecord.class);
//        util.exportExcel(response, list, "问卷记录数据");
//    }
 
    /**
     * 获取问卷记录详细信息
     */
    @GetMapping(value = "/{rid}")
    public AjaxResult getInfo(@PathVariable("rid") Long rid) {
        return success(tjSurveyRecordService.selectTjSurveyRecordByRid(rid));
    }
 
 
    /**
     * 小程序判断是否填写过问卷(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 = "新增问卷记录")
    @Log(title = "问卷记录", businessType = BusinessType.INSERT)
    @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));
                }
            }
            for (TjSurveyRecord surveyRecord : a) {
                tjSurveyRecordService.save(surveyRecord);
                List<TjSurveyRecordDetail> recordDetailList = surveyRecord.getTjSurveyRecordDetailList();
                if (null != recordDetailList && recordDetailList.size() > 0) {
                    tjSurveyRecordDetailService.saveBatch(recordDetailList);
                }
            }
        }
        return AjaxResult.success();
    }
//
//    /**
//     * 修改问卷记录
//     */
//    @Log(title = "问卷记录", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TjSurveyRecord tjSurveyRecord) {
//        return toAjax(tjSurveyRecordService.updateTjSurveyRecord(tjSurveyRecord));
//    }
//
//    /**
//     * 删除问卷记录
//     */
//    @Log(title = "问卷记录", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{rids}")
//    public AjaxResult remove(@PathVariable Long[] rids) {
//        return toAjax(tjSurveyRecordService.deleteTjSurveyRecordByRids(rids));
//    }
}