zjh
2023-10-12 8cde7ee1143bae70eb68d2b75f572d5b4dbadf98
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
package com.ltkj.web.controller.app;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.domain.entity.SysDictData;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.common.utils.bean.BeanUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.TjCustomer;
import com.ltkj.hosp.domain.TjOrder;
import com.ltkj.hosp.service.ITjCustomerService;
import com.ltkj.hosp.service.ITjOrderService;
import com.ltkj.system.service.ISysDictDataService;
import com.ltkj.system.service.ISysDictTypeService;
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.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * @Author: 西安路泰科技有限公司/lige
 * @Date: 2023/1/12 11:08
 */
@RestController
@RequestMapping("/cus/hospital")
@Api(tags = "小程序-客户信息")
public class CustomerController extends BaseController {
 
    @Resource
    private ITjCustomerService customerService;
 
    @Resource
    private ITjOrderService tjOrderService;
 
    @Autowired
    private ISysDictTypeService dictTypeService;
 
    /**
     * 小程序就诊人列表
     */
    @GetMapping("/getListByOpenId")
    @ApiOperation(value = "小程序-就诊人列表")
    public AjaxResult getListByOpenId(@RequestParam String openId) {
        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
        wq.eq(TjCustomer::getConnect, openId);
        final List<TjCustomer> list = customerService.list(wq);
        return AjaxResult.success(list);
    }
 
    /**
     * 解绑就诊人
     */
    @PostMapping("/delCustomer")
    @ApiOperation(value = "小程序-解绑就诊人")
    public AjaxResult delCustomer(@RequestBody @ApiParam(value = "客户对象信息") TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error();
        }
        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper();
        wq.eq(TjCustomer::getCusIdcard, tjCustomer.getCusIdcard());
        wq.eq(TjCustomer::getCusPhone, tjCustomer.getCusPhone());
        wq.eq(TjCustomer::getCusName, tjCustomer.getCusName());
        final TjCustomer one = customerService.getOne(wq);
        one.setConnect("");
        final boolean b = customerService.updateById(one);
        if (b) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error("解绑失败");
        }
 
    }
 
    /**
     * 新增并绑定就诊人
     */
    @PostMapping("/addNew")
    @ApiOperation(value = "小程序-新增并绑定就诊人")
    public AjaxResult addNew(@RequestBody @ApiParam(value = "客户对象信息") TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error("添加失败");
        }
        String cusIdcard = tjCustomer.getCusIdcard();
        if (cusIdcard == null) {
            return AjaxResult.error("添加失败");
        }
        //判断身份证号格式是否正确
        if (!MatchUtils.isMobileNO(tjCustomer.getCusPhone()))
            return AjaxResult.error("手机号错误");
 
        if(cusIdcard.length()==18){
            if (!MatchUtils.isIdCard(cusIdcard)) {
                return AjaxResult.error("身份证号码错误");
            }
        }
        if(cusIdcard.length()==9){
            if (!MatchUtils.cardValidates(cusIdcard)) {
                return AjaxResult.error("身份证号码错误");
            }
        }
 
        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper<>();
        wq.eq(TjCustomer::getCusIdcard, cusIdcard);
        TjCustomer customer = customerService.getOne(wq);
 
        if (customer != null) {
//            BeanUtils.copyBeanProp(tjCustomer, customer);
//            String substring = cusIdcard.substring(cusIdcard.length() - 6);
//            substring = DigestUtils.md5DigestAsHex(substring.getBytes());
//            customer.setCusPassword(substring);
//            customer.setCusBrithday(DateUtil.parse(MatchUtils.getBirthDayByIdCard(cusIdcard), "yyyy-MM-dd"));
//            tjCustomer.setCusSex(Long.valueOf(MatchUtils.getSexByIdCard(cusIdcard)));
//            // tjCustomer.setAddr(MatchUtils.getNativePlace(Integer.parseInt(cusIdcard)));
//            tjCustomer.setAge(String.valueOf(MatchUtils.getAgeByIdCard(cusIdcard)));
//            tjCustomer.setIdType("1");
//            tjCustomer.setAgeUnit("0");
//            if (customerService.updateById(customer)) {
//                return AjaxResult.success(tjCustomer);
//            }
 
            return AjaxResult.error("该人员已存在");
        }
        String substring = cusIdcard.substring(cusIdcard.length() - 6);
        substring = DigestUtils.md5DigestAsHex(substring.getBytes());
        tjCustomer.setCusPassword(substring);
        tjCustomer.setCusBrithday(DateUtil.parse(MatchUtils.getBirthDayByIdCard(cusIdcard), "yyyy-MM-dd"));
        tjCustomer.setCusSex(Long.valueOf(MatchUtils.getSexByIdCard(cusIdcard)));
        //tjCustomer.setAddr(MatchUtils.getNativePlace(Integer.parseInt((cusIdcard))));
        tjCustomer.setAge(String.valueOf(MatchUtils.getAgeByIdCard(cusIdcard)));
        tjCustomer.setIdType("1");
        tjCustomer.setAgeUnit("0");
        tjCustomer.setRole(2L);
        tjCustomer.setCusIntroduce("无");
        tjCustomer.setCusNumber(0L);
        tjCustomer.setCusIsvip("N");
        if (customerService.save(tjCustomer)) {
            return AjaxResult.success(tjCustomer);
        }
        return AjaxResult.error("添加失败");
    }
 
    /**
     * 小程序体检报告列表
     */
    @GetMapping("/getReportList")
    @ApiOperation(value = "小程序-体检报告列表")
    public AjaxResult getReportList(@RequestParam @ApiParam(value = "手机号") String cusPhone) {
        return AjaxResult.success();
    }
 
    /**
     * 回显就诊人
     */
    @PostMapping("/showCustomer")
    @ApiOperation(value = "小程序-回显就诊人")
    public AjaxResult showCustomer(@RequestBody @ApiParam(value = "客户对象信息") TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error();
        }
        LambdaQueryWrapper<TjCustomer> wq = new LambdaQueryWrapper();
        wq.eq(TjCustomer::getCusIdcard, tjCustomer.getCusIdcard());
        wq.eq(TjCustomer::getCusPhone, tjCustomer.getCusPhone());
        wq.eq(TjCustomer::getCusName, tjCustomer.getCusName());
        final TjCustomer one = customerService.getOne(wq);
        return AjaxResult.success(one);
    }
 
    /**
     * 小程序判断是否能编辑
     */
    @PostMapping("/canUpdate")
    @ApiOperation(value = "小程序判断是否能编辑")
    public AjaxResult canUpdate(@RequestBody TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error("出错了,请联系工作人员!");
        }
        LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
        wq.eq(TjOrder::getUserId, tjCustomer.getCusId());
        final List<TjOrder> list = tjOrderService.list(wq);
        if (list.size() != 0) {
            return AjaxResult.success(0);
        }
        return AjaxResult.success(1);
    }
 
    /**
     * 小程序编辑就诊人信息
     */
    @PostMapping("/updateCustomerBy")
    @ApiOperation(value = "小程序-修改就诊人信息")
    public AjaxResult updateCustomerBy(@RequestBody TjCustomer tjCustomer) {
        if (tjCustomer == null) {
            return AjaxResult.error("修改失败");
        }
        TjCustomer one = customerService.getById(tjCustomer);
        one.setCusName(tjCustomer.getCusName());
        one.setCusIdcard(tjCustomer.getCusIdcard());
        one.setCusPhone(tjCustomer.getCusPhone());
        one.setCusNational(tjCustomer.getCusNational());
        one.setCusMarryStatus(tjCustomer.getCusMarryStatus());
        if (customerService.updateById(one)) {
            return AjaxResult.success(one);
        }
        return AjaxResult.error("修改失败");
    }
 
    /**
     * 小程序根据手机号码获取用户身份证号码
     */
    @GetMapping(value = "/getIdCardByPhone")
    @ApiOperation(value = "小程序根据手机号码获取用户身份证号码")
    public AjaxResult getIdCardByPhone(@RequestParam @ApiParam(value = "手机号") String phone) {
        if (!"".equals(phone) && phone != null && MatchUtils.isMobileNO(phone)) {
            LambdaQueryWrapper<TjCustomer> qw = new LambdaQueryWrapper<>();
            qw.eq(TjCustomer::getCusPhone, phone);
            List<TjCustomer> tjCustomer1 = customerService.list(qw);
            if (tjCustomer1 != null && tjCustomer1.size()>0) {
                List<String> num = new ArrayList<>();
                for (TjCustomer tjCustomer : tjCustomer1) {
                    num.add(tjCustomer.getCusIdcard());
                }
                return AjaxResult.success(num);
            }
            return AjaxResult.success("暂无记录,请先绑定身份证号!");
        }
        return AjaxResult.error("手机号无效");
    }
 
    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/type/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data)) {
            data = new ArrayList<SysDictData>();
        }
        return success(data);
    }
 
}