fhx
2023-12-08 37022a5aa114261dcb9e4f312b07c6e029f59e24
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
package com.hx.phip.controller.treat;
 
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import com.hx.common.BaseController;
import com.hx.exception.TipsException;
import com.hx.guide.dao.mapper.VisitOrderMapper;
import com.hx.guide.model.VisitOrder;
import com.hx.guide.vo.treatOrder.TreatOrderReqVo;
import com.hx.mybatis.aes.springbean.VariableAesKey;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.DeductionSingleConstants;
import com.hx.phiappt.common.RoleType;
import com.hx.phiappt.common.TreatSingleConstants;
import com.hx.phiappt.dao.mapper.*;
import com.hx.phiappt.model.*;
import com.hx.phiappt.model.treat.TreatProject;
import com.hx.phiappt.model.treat.TreatProjectDoctor;
import com.hx.phiappt.model.treat.TreatSingle;
import com.hx.phiappt.model.treat.TreatSingleSign;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.dao.mapper.TreatProjectMapper;
import com.hx.phip.service.AppointmentService;
import com.hx.phip.service.EmployeeService;
import com.hx.phip.service.UserService;
import com.hx.phip.service.treat.TreatSingleService;
import com.hx.phip.service.treat.TreatV3Service;
import com.hx.phip.tool.SendSMSTool;
import com.hx.phip.util.api.CrmUtil;
import com.hx.resultTool.Result;
import com.hx.util.DateUtil;
import com.hx.util.StringUtils;
import com.platform.constants.PlatformPattern;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import com.platform.resultTool.PlatformResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 治疗通知单控制器
 *
 * @USER: zhouxiang
 * @DATE: 2021/12/03
 */
@RestController
@RequestMapping("/treat")
public class TreatController extends BaseController {
 
    private static Logger logger = LoggerFactory.getLogger(TreatController.class);
 
    @Resource
    private TreatV3Service treatV3Service;
    @Resource
    private UserService userService;
    @Resource
    private TreatSingleService treatSingleService;
    @Resource
    private AppointmentService appointmentService;
    @Resource
    private CustomParameter customParameter;
    @Resource
    private EmployeeService employeeService;
 
    /**
     * 创建治疗通知单
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public PlatformResult create(@RequestBody(required = false) TreatOrderReqVo reqVo) {
 
        //获取-判断治疗通知单信息
        if (reqVo == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗单信息为空");
        }
        logger.info("新增治疗单参数:{}", JSONObject.toJSONString(reqVo) );
 
        //治疗通知单对象
        TreatSingle treatSingle = reqVo.createTreatSingle();
        //治疗单签名
        List<TreatSingleSign> signList = reqVo.getSignList();
 
        //校验参数
        checkTreatSingleParam(true, treatSingle, signList);
 
        //判断是否发送通知MIC分配治疗
        Integer isMicNotice = BaseEntity.NO;
//        if(reqVo.getIsMicNotice() != null && reqVo.getIsMicNotice() == BaseEntity.YES){
//            isMicNotice = BaseEntity.YES;
//        }
 
        //治疗单项目
        List<TreatProject> projectList = reqVo.getProjectList();
        if (projectList == null || projectList.size() == 0) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗通知单的治疗项目不能为空");
        }
        //检查项目参数
        checkProjectParam(projectList);
 
        if(StringUtils.isEmpty(reqVo.getRoleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "操作人角色标识为空");
        }
        EmployeeRole employeeRole = employeeService.selectRoleInfoById(reqVo.getRoleId());
        if(employeeRole == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到操作人角色信息!");
        }
 
        VisitOrder visitOrder = commonService.selectOneByKey(VisitOrderMapper.class, treatSingle.getVisitOrderId());
        if(visitOrder == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到到访订单信息");
        }
        treatSingle.setUserId(visitOrder.getUserId());
 
 
 
 
        treatV3Service.add(treatSingle, projectList, visitOrder, employeeRole, isMicNotice, signList);
 
        //返回id
        JSONObject data = new JSONObject();
        data.put("treatSingleId", treatSingle.getId());
 
        return PlatformResult.success(data);
    }
 
    /**
     * 修改治疗通知单
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public PlatformResult edit(@RequestBody(required = false) TreatOrderReqVo reqVo) {
 
        //获取-判断治疗通知单信息
        if (reqVo == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗单信息为空");
        }
 
        //治疗通知单对象
        TreatSingle treatSingle = reqVo.createTreatSingle();
        //治疗单签名
        List<TreatSingleSign> signList = reqVo.getSignList();
        //校验参数
        checkTreatSingleParam(false, treatSingle, signList);
 
 
        List<TreatProject> projectList = reqVo.getProjectList();
        if (projectList == null || projectList.size() == 0) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗通知单的治疗项目不能为空");
        }
        checkProjectParam(projectList);
 
        TreatSingle updateTreat = commonService.selectOneByKey(TreatSingleMapper.class,treatSingle.getId());
        if(updateTreat == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "未找到");
        }
 
//        //判断是否发送通知MIC分配治疗(如果治疗单分配医生不为空,则不继续通知MIC)
//        Integer isMicNotice = BaseEntity.NO;
//        if(reqVo.getIsMicNotice() != null && reqVo.getIsMicNotice() == BaseEntity.YES
//                && StringUtils.noNull(updateTreat.getaDoctorId())){
//            isMicNotice = BaseEntity.YES;
//        }
 
        if(updateTreat.getStatus() == TreatSingleConstants.STATUS_CANCEL){
            throwParamException("作废治疗通知单不可修改!");
        }
 
        if(StringUtils.isEmpty(reqVo.getRoleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "操作人角色标识为空");
        }
        EmployeeRole employeeRole = employeeService.selectRoleInfoById(reqVo.getRoleId());
        if(employeeRole == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到操作人角色信息!");
        }
 
        VisitOrder visitOrder = commonService.selectOneByKey(VisitOrderMapper.class, updateTreat.getVisitOrderId());
        if(visitOrder == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到到访订单信息");
        }
 
        //修改
        treatSingle.setTreatSingleNo(updateTreat.getTreatSingleNo());
        treatSingle.setCommonId(updateTreat.getCommonId());
        treatSingle.setaNurseId(updateTreat.getaNurseId());
        treatSingle.setaDoctorId(updateTreat.getaDoctorId());
        treatV3Service.edit(treatSingle, projectList, visitOrder, employeeRole, updateTreat, signList);
 
        //当状态是 待确认 发送短信给客户确认
        if(treatSingle.getStatus()==TreatSingleConstants.STATUS_WAIT_CONFIRM){
            //修改治疗通知单发送给客户
            editSendMsg(treatSingle.getId(), visitOrder.getUserId());
        }
 
        //返回id
        JSONObject data = new JSONObject();
        data.put("treatSingleId", treatSingle.getId());
        return PlatformResult.success(data);
    }
 
    /** 作废 */
    @RequestMapping(value = "/invalid", method = RequestMethod.POST)
    public PlatformResult invalid(@RequestBody(required = false) TreatOrderReqVo reqVo) {
 
        //获取-判断治疗通知单信息
        if (reqVo == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗单信息为空");
        }
 
        if (StringUtils.isEmpty(reqVo.getTreatSingleId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单标识为空");
        }
 
        if(StringUtils.isEmpty(reqVo.getRoleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "操作人角色标识为空");
        }
 
 
        //治疗通知单对象
        TreatSingle treatSingle = commonService.selectOneByKey(TreatSingleMapper.class, reqVo.getTreatSingleId());
        if(treatSingle == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "查询不到治疗通知单信息!");
        }
 
        //查询治疗通知单有划扣过(已执行),则不可作废
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        values.put("treatSingleId", reqVo.getTreatSingleId());
        values.put("commonId", treatSingle.getCommonId());
        values.put("status", DeductionSingleConstants.STATUS_DONE_EXECUTE);
        sqlSentence.setSqlSentence(" isDel = 0 and status = #{m.status} and commonId = #{m.commonId} and treatSingleId = #{m.treatSingleId} ");
        int count = commonService.selectCount(com.hx.phiappt.dao.mapper.DeductionSingleMapper.class, sqlSentence);
        if(count > 0){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单有划扣记录,不可作废!如想作废请先作废关联划扣记录");
        }
 
        EmployeeRole employeeRole = employeeService.selectRoleInfoById(reqVo.getRoleId());
        if(employeeRole == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到操作人角色信息!");
        }
 
        VisitOrder visitOrder = commonService.selectOneByKey(VisitOrderMapper.class, treatSingle.getVisitOrderId());
        if(visitOrder == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到到访订单信息");
        }
 
        treatV3Service.invalidTreat(treatSingle, visitOrder, employeeRole);
 
        return PlatformResult.success();
    }
 
    /** 更新治疗单签名 */
    @RequestMapping(value ="/updateSign", method = RequestMethod.POST)
    public Result updateSign(@RequestBody(required = false) TreatOrderReqVo reqVo){
        if(reqVo == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "请求对象为空!");
        }
 
        if(StringUtils.isEmpty(reqVo.getRoleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "操作人标识不能为空!");
        }
 
        if(StringUtils.isEmpty(reqVo.getTreatSingleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "操作人标识不能为空!");
        }
 
        if(reqVo.getSignList() == null || reqVo.getSignList().size() < 1){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "签名信息不能为空!");
        }
 
 
        EmployeeRole employeeRole = employeeService.selectRoleInfoById(reqVo.getRoleId());
        if(employeeRole == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到操作人角色信息!");
        }
 
        TreatSingle treatSingle = treatSingleService.selectOneByKey(reqVo.getTreatSingleId());
        if(treatSingle == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到治疗通知单信息!");
        }
 
        checkSignParam(reqVo.getSignList(), treatSingle);
 
        treatV3Service.updateSign(treatSingle, reqVo.getSignList(), employeeRole);
 
        return Result.success();
    }
 
    /**
     * 客户确认治疗通知单
     */
    @RequestMapping(value = "/confirmTreatNotice", method = RequestMethod.POST)
    public PlatformResult confirmTreatNotice(@RequestBody String param) {
        if (StringUtils.isEmpty(param)) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗单参数为空");
        }
 
        JSONObject jsonObject = JSONObject.parseObject(param);
        if (!jsonObject.containsKey("treatSingleId")) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗单id为空");
        }
 
        TreatSingle treatSingle = treatSingleService.selectOneByKey(jsonObject.getString("treatSingleId"));
        if (treatSingle == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "找不到治疗通知单信息");
        }
 
        if (treatSingle.getStatus() == TreatSingleConstants.STATUS_CONFIRM) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单已确认");
        }
 
        Appointment appointment = appointmentService.selectOneByKeyBlob(treatSingle.getCommonId());
        if(appointment == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "找不到预约单信息");
        }
 
 
        treatSingleService.updateTreatStatus(treatSingle,appointment,commonService);
 
        return PlatformResult.success();
    }
 
    /**
     * 查询治疗通知单详情信息
     */
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public PlatformResult getTreatList(@RequestBody String param) {
        //判断参数
        if (StringUtil.isEmpty(param)) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单id不能为空");
        }
 
        JSONObject jsonObject = JSONObject.parseObject(param);
        if (!jsonObject.containsKey("treatSingleId")) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单id不能为空");
        }
 
        //查询治疗通知单
        TreatSingle treatSingle = treatSingleService.selectOneByKey(jsonObject.getString("treatSingleId"));
        if (treatSingle == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单id不能为空");
        }
        //查询预约信息
        Appointment appointment = appointmentService.selectOneByKey( treatSingle.getCommonId());
        if (appointment == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "找不到预约信息");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> map = new HashMap<>();
        sqlSentence.setM(map);
 
        //查询项目信息
        map.put("singleId", treatSingle.getId());
        sqlSentence.setSqlSentence("SELECT p.positionData, p.projectNo as projectId,p.hisId as projectNo, p.projectName, p.num FROM treat_project p LEFT JOIN treat_single s ON p.treatSingleId = s.id where  p.treatSingleId = #{m.singleId} and s.isDel=0 and p.isDel=0");
        List<Map<String, Object>> projectList = commonService.selectListMap(TreatProjectMapper.class, sqlSentence);
 
        //人员信息
        map.put("userId", appointment.getUserId());
        map.put("key", VariableAesKey.AES_KEY);
        sqlSentence.setSqlSentence("select insert(CONVERT(AES_DECRYPT(UNHEX(tel), #{m.key}) , CHAR), 4, 4, '****') as tel,id,name,CIQ from user where id=#{m.userId} and isDel=0 ");
        User user = commonService.selectOne(UserMapper.class, sqlSentence);
        if (user == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "用户信息为空");
        }
        //医生信息
        sqlSentence.setSqlSentence("select * from treat_project_doctor where isDel=0 and treatSingleId=#{m.singleId}");
        List<TreatProjectDoctor> projectDoctors = commonService.selectList(TreatProjectDoctorMapper.class, sqlSentence);
        List<Map<String, Object>> maps=new ArrayList<>();
        if(projectDoctors !=null && projectDoctors.size()>0){
            for(TreatProjectDoctor vo:projectDoctors){
                Map<String,Object> employeeMap=new HashMap<>();
                Employee employee=commonService.selectOneByKey(EmployeeMapper.class, vo.getCommonId());
                employeeMap.put("projectId",vo.getTreatProjectId());
                employeeMap.put("projectHisId",vo.getTreatProjectHisId());
                employeeMap.put("employeeName",employee.getCnName());
                employeeMap.put("employeeId",employee.getId());
                maps.add(employeeMap);
            }
        }
 
        map.clear();
        map.put("createTime", DateUtil.formatDate(treatSingle.getCreateTime(), "yyy.MM.dd HH:mm"));
        map.put("name", user.getName());
        map.put("ciq", user.getCIQ());
        map.put("tel", user.getTel());
        map.put("shopName", treatSingle.getShopName());
        map.put("employeeName", treatSingle.getOperatorName());
        map.put("projectList", projectList);
        map.put("remarkInfo", treatSingle.getRemarkInfo());
        map.put("status",treatSingle.getStatus());
        map.put("employeeList",maps);
        map.put("employeeType",appointment.getIsLifeBeauty() ==null||appointment.getIsLifeBeauty()==0? RoleType.UNIQUE_STR_DOCTOR:RoleType.UNIQUE_STR_NURSE);
 
        return PlatformResult.success(map);
    }
 
    /**
     * 重新发送短信
     *
     * @param param
     * @return
     */
    @RequestMapping("/againSendMsg")
    public PlatformResult sendMsg(@RequestBody String param) {
        //校验参数
        if (StringUtils.isEmpty(param)) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "请传治疗通知单参数");
        }
        //转成对象
        JSONObject object = JSONObject.parseObject(param);
        //判断参数
        if (!object.containsKey("treatSingleId")) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "请传治疗通知单参数");
        }
        //查询治疗通知单
        TreatSingle treatSingle = commonService.selectOneByKey(TreatSingleMapper.class, object.getString("treatSingleId"));
        if (treatSingle == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "找不到治疗通知单信息");
        }
        //判断状态 短信是否是已确认 未确认发送短信
        if (treatSingle.getStatus() == TreatSingleConstants.STATUS_CONFIRM) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单已确认");
        }
 
        //查询预约信息
        Appointment appointment = commonService.selectOneByKey(com.hx.guide.dao.mapper.AppointmentMapper.class, treatSingle.getCommonId());
        if (appointment == null) {
            throw new TipsException("找不到预约信息");
        }
 
        //用户信息
        User userInfo = commonService.selectOneByKey(com.hx.guide.dao.mapper.UserMapper.class, appointment.getUserId());
        if (userInfo == null) {
            throw new TipsException("找不到用户信息!");
        }
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        //通过预约id查询到预约信息获取用户手机号
        values.put("commonId", object.getString("appId"));
        sqlSentence.setSqlSentence("select u.tel from appointment a  left join user u on u.id=a.userId where a.id =#{m.commonId} and u.isDel=0 and a.isDel=0 ");
        Map<String, Object> map = userService.selectOneMap(sqlSentence);
        if(PlatformPattern.PROD.equals(customParameter.getPlatformPattern())){
            map.put("treatSingleId",treatSingle.getId());
            CrmUtil.sendCrmSMS(map,commonService,0);
        }else{
            net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject();
            //发送短信
            jsonObject = SendSMSTool.msgSend("测试服假链接"+"https://wxaurl.cn/66666666", map.get("tel").toString(), "", 1);
 
//        logger.info("发送短信返回:"+jsonObject.toString());
 
            if (jsonObject.getInt("code") != 0) {
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "发送短信失败");
            }
        }
 
//        VLatelyLog vLatelyLog = new VLatelyLog(TreatSingleConstants.STATUS_CONFIRM, "客户自己确认治疗通知单", "治疗通知单,客户已确认自己的治疗通知单", userInfo.getCIQ() + userInfo.getName(), null,
//                null, null, null, userInfo.getId());
//
//        commonService.insert(com.hx.guide.dao.mapper.VLatelyLogMapper.class,vLatelyLog);
 
 
        return PlatformResult.success();
 
    }
 
 
    ////////////////////////////////////////////////////////////////////////////////////////////////
 
    public void editSendMsg(String treatSingleId,String userId) {
 
        //查询治疗通知单
        TreatSingle treatSingle = commonService.selectOneByKey(TreatSingleMapper.class, treatSingleId);
        if (treatSingle == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "找不到治疗通知单信息");
        }
//        //判断状态 短信是否是已确认 未确认发送短信
//        if (treatSingle.getStatus() == TreatSingleConstants.STATUS_CONFIRM) {
//            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_TYPE, "治疗通知单已确认");
//        }
 
 
        //查询预约信息
        Appointment appointment = commonService.selectOneByKey(AppointmentMapper.class, treatSingle.getCommonId());
        if (appointment == null) {
            throw new TipsException("找不到预约信息");
        }
 
        //用户信息
        User userInfo = commonService.selectOneByKey(UserMapper.class, appointment.getUserId());
        if (userInfo == null) {
            throw new TipsException("找不到用户信息!");
        }
 
 
        SqlSentence sqlSentence = new SqlSentence();
        Map<String, Object> values = new HashMap<>();
        sqlSentence.setM(values);
        //通过预约id查询到预约信息获取用户手机号
        values.put("commonId", userId);
        sqlSentence.setSqlSentence("SELECT tel FROM `user` WHERE id = #{m.commonId} AND isDel = 0");
        Map<String, Object> map = userService.selectOneMap(sqlSentence);
 
        if(PlatformPattern.PROD.equals(customParameter.getPlatformPattern())){
            map.put("treatSingleId",treatSingle.getId());
            CrmUtil.sendCrmSMS(map,commonService,1);
        }else{
            net.sf.json.JSONObject jsonObject = new net.sf.json.JSONObject();
            //发送短信
            jsonObject = SendSMSTool.msgSend("测试服假链接"+"https://wxaurl.cn/66666666", map.get("tel").toString(), "", 1);
 
//        logger.info("发送短信返回:"+jsonObject.toString());
 
            if (jsonObject.getInt("code") != 0) {
                throw new PlatTipsException(PlatformCode.ERROR_TIPS, "发送短信失败");
            }
        }
 
 
//        VLatelyLog vLatelyLog = new VLatelyLog(TreatSingleConstants.STATUS_CONFIRM, "修改治疗单时客户需确认治疗单", "修改治疗通知单,客户已确认自己的治疗通知单", userInfo.getCIQ() + userInfo.getName(), null,
//                null, null, null, userInfo.getId());
//
//        commonService.insert(com.hx.guide.dao.mapper.VLatelyLogMapper.class,vLatelyLog);
 
    }
 
 
    /** 治疗通知单参数校验 */
    private void checkTreatSingleParam(boolean isAdd, TreatSingle treatSingle, List<TreatSingleSign> signList) {
 
        //新增才校验的参数
        if(isAdd){
            if (StringUtils.isEmpty(treatSingle.getCommonId())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "预约id为空");
            }
 
            if (StringUtils.isEmpty(treatSingle.getVisitOrderId())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "到访订单标识为空");
            }
        }
 
        if (StringUtils.isEmpty(treatSingle.getType())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗通知单类型为空");
        }
 
        if (treatSingle.getStatus() == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "状态为空");
        }
        if (StringUtils.isEmpty(treatSingle.getShopId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "所属门店标识为空");
        }
 
        if (StringUtils.isEmpty(treatSingle.getOperatorId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "下单操作人标识为空");
        }
 
        if (StringUtils.isEmpty(treatSingle.getDeveloperShopId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "开单人门店标识为空");
        }
 
        if (StringUtils.isEmpty(treatSingle.getDeveloperId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "开单人标识为空");
        }
 
        if (treatSingle.getOrderClassify() == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "订单分类不能为空!");
        }
 
        //校验签名参数----------------------------------------------------------------------------------
        if(signList != null && signList.size() > 0){
            checkSignParam(signList, treatSingle);
        }
 
        //----------------------------------------------------------------------------------
    }
 
    /** 检测校验治疗单签名参数 */
    private void checkSignParam(List<TreatSingleSign> signList, TreatSingle treatSingle){
        treatSingle.setIsUserSign(BaseEntity.NO);
        for(TreatSingleSign sign : signList){
            if(StringUtils.isEmpty(sign.getSignImg())){
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"签名图片不能为空!");
            }
            if(StringUtils.isEmpty(sign.getSignPerType())){
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"签名人类型不能为空!");
            }
            if(StringUtils.isEmpty(sign.getSignPerName())){
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"签名人名称不能为空!");
            }
 
            //判断类型,更改对应值
            if(TreatSingleSign.SIGN_PER_TYPE_USER.equals(sign.getSignPerType())){
                sign.setSortNo(1);
                treatSingle.setIsUserSign(BaseEntity.YES);
            }else if(TreatSingleSign.SIGN_PER_TYPE_NURSE1.equals(sign.getSignPerType())){
                sign.setSortNo(2);
            }else if(TreatSingleSign.SIGN_PER_TYPE_NURSE2.equals(sign.getSignPerType())){
                sign.setSortNo(3);
            }else if(TreatSingleSign.SIGN_PER_TYPE_DOCTOR.equals(sign.getSignPerType())){
                sign.setSortNo(4);
            }
        }
    }
 
    /** 治疗项目参数校验 */
    private void checkProjectParam(List<TreatProject> treatProjectList) {
 
        for(TreatProject treatProject : treatProjectList){
            if (StringUtils.isEmpty(treatProject.getProjectNo())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "项目编号不能为空");
            }
 
            if (StringUtils.isEmpty(treatProject.getProjectName())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "项目名称不能为空");
            }
 
            if (treatProject.getPrice() == null) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "价格不能为空");
            }
 
            if (treatProject.getNum() == null) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "数量不能为空");
            }
 
            if (treatProject.getUseDuration() == null) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗时长不能为空");
            }
 
            if (StringUtils.isEmpty(treatProject.getProjectId())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "项目标识不能为空");
            }
 
            if (StringUtils.isEmpty(treatProject.getGoodsId())) {
                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "公用项目标识不能为空");
            }
 
//            if (StringUtils.isEmpty(treatProject.getUserProjectItemId())) {
//                throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户项目标识不能为空");
//            }
        }
    }
 
 
 
 
}