chenjiahe
2024-05-30 a5704a4dd10ad7de4b91f05951e3bb019ccfa256
提交 | 用户 | age
758a33 1 package com.hx.phip.controller.consultation;
R 2
3
fac939 4 import com.alibaba.fastjson.JSON;
758a33 5 import com.alibaba.fastjson.JSONObject;
fac939 6 import com.alibaba.fastjson.TypeReference;
758a33 7 import com.github.pagehelper.PageHelper;
R 8 import com.github.pagehelper.PageInfo;
9 import com.hx.common.BaseController;
018779 10 import com.hx.common.service.CommonService;
d4c5bd 11 import com.hx.mybatis.aes.springbean.VariableAesKey;
758a33 12 import com.hx.mybatisTool.SqlSentence;
01d533 13 import com.hx.phiappt.common.UserProjectConstants;
00c80a 14 import com.hx.phiappt.constants.tool.PageUtil;
01d533 15 import com.hx.phiappt.constants.tool.user.UserProjectTool;
b33cd3 16 import com.hx.phiappt.dao.mapper.*;
a5704a 17 import com.hx.phiappt.model.*;
b33cd3 18 import com.hx.phiappt.model.guide.VisitRecord;
01d533 19 import com.hx.phiappt.model.user.UserProjectItem;
fac939 20 import com.hx.phip.service.SystemParameterService;
758a33 21 import com.hx.phip.service.consultation.ConsultationRecordService;
R 22 import com.hx.util.StringUtils;
a5704a 23 import com.hz.his.dto.consultation.ConsultAppearancePlanVo;
758a33 24 import com.hz.his.dto.consultation.ConsultRecordDto;
a5704a 25 import com.hz.his.dto.consultation.ConsultTreatProjectVo;
758a33 26 import com.platform.exception.PlatTipsException;
R 27 import com.platform.resultTool.PlatformCode;
28 import com.platform.resultTool.PlatformResult;
b1323a 29 import lombok.extern.slf4j.Slf4j;
758a33 30 import org.springframework.beans.BeanUtils;
R 31 import org.springframework.web.bind.annotation.RequestBody;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RequestMethod;
34 import org.springframework.web.bind.annotation.RestController;
35
36 import javax.annotation.Resource;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
01d533 40
R 41 import static com.hx.phiappt.constants.tool.user.UserProjectTool.getStatusName;
758a33 42
R 43 /**
44  * 咨询记录
45  */
b1323a 46 @Slf4j
758a33 47 @RestController
R 48 @RequestMapping("/consultation/record")
49 public class ConsultationRecordController extends BaseController {
50
51     @Resource
52     private ConsultationRecordService consultationRecordService;
fac939 53     @Resource
R 54     private SystemParameterService systemParameterService;
758a33 55
R 56     /**
57      * 新增
58      */
a5704a 59     @RequestMapping(value = "/addOrUpdate", method = RequestMethod.POST)
ca7ad5 60     public PlatformResult addOrEditData(@RequestBody ConsultRecordDto consultRecordDto) {
758a33 61         //参数校验
fc0b15 62         checkParams(consultRecordDto);
758a33 63
R 64         if (!StringUtils.isEmpty(consultRecordDto.getId())) {
65             ConsultationRecord consultationRecord = commonService.selectOneByKey(ConsultationRecordMapper.class, consultRecordDto.getId());
66             if (consultationRecord == null) {
67                 throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!");
68             }
2d9644 69             consultRecordDto.setCreateTime(consultationRecord.getCreateTime());
758a33 70         }
R 71
fac939 72         String id = consultationRecordService.insertOrEdit(consultRecordDto, systemParameterService, commonService);
758a33 73         JSONObject data = new JSONObject();
R 74         data.put("id", id);
75         return PlatformResult.success(data);
76     }
77
78
79     /**
80      * 详情
81      */
82     @RequestMapping(value = "/detail", method = RequestMethod.POST)
ca7ad5 83     public PlatformResult detail(@RequestBody ConsultRecordDto consultRecordDto) {
758a33 84
3433c6 85         if (StringUtils.isEmpty(consultRecordDto.getId())) {
758a33 86             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "id为空");
R 87         }
88
e7373c 89         SqlSentence sqlSentence = new SqlSentence();
R 90         StringBuffer sql = new StringBuffer();
91         Map<String, Object> values = new HashMap<>();
92         sqlSentence.setM(values);
93
94         values.put("id",consultRecordDto.getId());
10cc5c 95         sql.append(" SELECT cr.id,cr.consultType, cr.userId, cr.shopId, cr.departmentCode, cr.departmentName , cr.methodCode, cr.methodCodeName, cr.description , CONCAT(COALESCE(cr.content,''), '\\r\\n',COALESCE(cr.remark,'')) AS content, cr.isCanCome , cr.adminType, cr.adminId, cr.adminName, cr.hisId, cr.isVisit , cr.visitType, cr.isPay, cr.payLabelInfo, cr.isDraft, cr.satisfie , cr.faceDoctorId, cr.treatDoctorId, cr.dosageParams, cr.appealDetail, cr.treatPlanQuote , cr.anamnesis, cr.hasTreatProjects, cr.lastTreatDoctorId, cr.lastTreatProjects, cr.facePlan, date_format(cr.createTime, '%Y-%m-%d %H:%i:%s') as createTime,cr.doubt,cr.dissent,cr.budget,cr.interestedActivities,cr.followUpWorks FROM consultation_record cr WHERE cr.isDel = 0 AND cr.id = #{m.id} ");
e7373c 96         sqlSentence.setSqlSentence(sql.toString());
R 97         ConsultationRecord consultationRecord = commonService.selectOne(ConsultationRecordMapper.class,sqlSentence);
758a33 98         if (consultationRecord == null) {
R 99             throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!");
100         }
101
806848 102         if(consultationRecord.getContent().startsWith("\\r\\n") || StringUtils.isEmpty(consultationRecord.getContent())) {
R 103             consultationRecord.setContent(null);
104         }
105
758a33 106         BeanUtils.copyProperties(consultationRecord, consultRecordDto);
R 107
108
109         values.put("isDel", BaseEntity.NO);
110         values.put("consultationRecordId", consultationRecord.getId());
111         values.put("userId", consultationRecord.getUserId());
112
113         // 推荐项目列表
2ecfaf 114         sql.delete(0, sql.length());
ed91bd 115         sql.append("SELECT crp.projectId,crp.projectName FROM `consultation_recommended_project` AS crp LEFT JOIN project AS pro ON pro.id=crp.projectId WHERE  crp.userId=#{m.userId} AND crp.consultationRecordId =#{m.consultationRecordId} AND crp.isDel=#{m.isDel}");
758a33 116         sqlSentence.setSqlSentence(sql.toString());
R 117         List<Map<String, Object>> recommendedProjectList = commonService.selectListMap(ConsultationRecommendedProjectMapper.class, sqlSentence);
118         consultRecordDto.setRecommendProjectList(recommendedProjectList);
119
120         // 治疗项目
121         sql.delete(0, sql.length());
a5704a 122         values.put("type", ConsultationTreatProject.PROJECT_TYPE_TREAT);
C 123         sql.append("SELECT crp.projectId,crp.projectName FROM `consultation_treat_project` AS crp LEFT JOIN project AS pro ON pro.id=crp.projectId WHERE  crp.userId=#{m.userId} AND crp.consultationRecordId =#{m.consultationRecordId} AND crp.isDel=#{m.isDel} AND crp.type = #{m.type}");
758a33 124         sqlSentence.setSqlSentence(sql.toString());
R 125         List<Map<String, Object>> treatProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence);
126         consultRecordDto.setTreatProjectList(treatProjectList);
a5704a 127
C 128         // 预约项目
129         sql.delete(0, sql.length());
130         values.put("type", ConsultationTreatProject.PROJECT_TYPE_PRE);
131         sql.append("SELECT crp.projectId,crp.projectName FROM consultation_treat_project AS crp LEFT JOIN project AS pro ON pro.id=crp.projectId WHERE  crp.userId=#{m.userId} AND crp.consultationRecordId =#{m.consultationRecordId} AND crp.isDel=#{m.isDel} AND crp.type = #{m.type}");
132         sqlSentence.setSqlSentence(sql.toString());
133         List<Map<String, Object>> preProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence);
134         consultRecordDto.setPreProjectList(JSON.parseArray(JSON.toJSONString(preProjectList), ConsultTreatProjectVo.class));
135
136         //颜值规划
137         sql.delete(0, sql.length());
138         sql.append("SELECT cap.details FROM consultation_appearance_plan cap WHERE cap.consultationRecordId =#{m.consultationRecordId} AND cap.isDel=#{m.isDel}");
139         sqlSentence.setSqlSentence(sql.toString());
140         List<Map<String, Object>> appearancePlan = commonService.selectListMap(ConsultationAppearancePlanMapper.class, sqlSentence);
141         consultRecordDto.setAppearancePlanList(JSON.parseArray(JSON.toJSONString(appearancePlan), ConsultAppearancePlanVo.class));
9b263a 142
646e90 143         //面诊医生
R 144         Employee faceEmp = commonService.selectOneByKey(EmployeeMapper.class, consultRecordDto.getFaceDoctorId());
145         consultRecordDto.setFaceDoctorName(faceEmp == null ? null : faceEmp.getCnName());
146
147         //治疗医生
148         Employee treatEmp = commonService.selectOneByKey(EmployeeMapper.class, consultRecordDto.getTreatDoctorId());
149         consultRecordDto.setTreatDoctorName(treatEmp == null ? null : treatEmp.getCnName());
150
151         //查询用户顾问名称
152         User user = commonService.selectOneByKey(UserMapper.class, consultRecordDto.getUserId());
0a676d 153         if (user != null) {
018779 154             if (!StringUtils.isEmpty(user.getHisCorpUserId())) {
0a676d 155                 Employee corpEmp = commonService.selectOneByKey(EmployeeMapper.class, user.getHisCorpUserId());
R 156                 consultRecordDto.setHisCorpUserName(corpEmp == null ? null : corpEmp.getCnName());
157             }
158             //手机号
9ed3ed 159             if(StringUtils.isEmpty(user.getTel()) || user.getTel().equals("测试服不存")) {
R 160                 consultRecordDto.setTel("-");
161             }else {
162                 consultRecordDto.setTel(user.getTel().substring(0, 3) + "****" + user.getTel().substring(7));
163             }
9b263a 164         }
758a33 165
133297 166 //        //返回基本信息
e356f0 167 //        if (StringUtils.isEmpty(consultRecordDto.getContent())) {
R 168 //            sql.delete(0, sql.length());
169 //            sql.append(" select * from consultation_record where isDel = 0 and id!= #{m.consultationRecordId} and userId = #{m.userId} order by createTime desc limit 1 ");
170 //            sqlSentence.setSqlSentence(sql.toString());
171 //            ConsultationRecord consultContent = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence);
172 //            consultRecordDto.setContent(consultContent != null ? consultContent.getContent() : null);
173 //        }
646e90 174
R 175         //非初复诊返回下面的值
94fddf 176         if (consultRecordDto.getConsultType() == 2) {
fac939 177             if (StringUtils.isEmpty(consultRecordDto.getLastTreatDoctorId())) {
R 178                 //为空 查询上一次的咨询记录的数据 拿到咨询医生 ID、名称
9521ea 179                 Map<String, Object> lastDetail = lastDetail(consultRecordDto.getUserId(), consultRecordDto.getId(),1);
646e90 180                 if (lastDetail != null) {
R 181                     if (lastDetail.containsKey("treatDoctorId") && lastDetail.get("treatDoctorId") != null && !StringUtils.isEmpty(lastDetail.get("treatDoctorId").toString())) {
182                         consultRecordDto.setLastTreatDoctorId(lastDetail.get("treatDoctorId").toString());
183                     }
184
b33cd3 185                     if (lastDetail.containsKey("treatDoctorName") && lastDetail.get("treatDoctorName") != null && !StringUtils.isEmpty(lastDetail.get("treatDoctorName").toString())) {
646e90 186                         consultRecordDto.setLastTreatDoctorName(lastDetail.get("treatDoctorName").toString());
b33cd3 187                     }
646e90 188                 }
fac939 189             } else {
R 190                 //不为空 则拿取当前的数据
ed91bd 191                 consultRecordDto.setLastTreatDoctorId(consultationRecord.getLastTreatDoctorId());
fac939 192                 Employee docEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getLastTreatDoctorId());
R 193                 consultRecordDto.setLastTreatDoctorName(docEmp.getCnName());
194             }
195
b1323a 196             List<Map<String, Object>> lastTreatProjectList;
646e90 197             //为空 查询上一次的咨询记录的数据 拿到上一条记录存储的治疗项目数据
R 198             if (StringUtils.isEmpty(consultRecordDto.getLastTreatProjects())
199                     || "[]".equals(consultRecordDto.getLastTreatProjects())
200                     || "null".equals(consultRecordDto.getLastTreatProjects())) {
201
9521ea 202                 Map<String, Object> lastDetail = lastDetail(consultRecordDto.getUserId(), consultRecordDto.getId(),1);
646e90 203                 if (lastDetail.containsKey("lastTreatProject")
R 204                         && lastDetail.get("lastTreatProject") != null
205                         && !StringUtils.isEmpty(lastDetail.get("lastTreatProject").toString())
206                         && !"[]".equals(lastDetail.get("lastTreatProject").toString())
207                         && !"null".equals(lastDetail.get("lastTreatProject").toString())) {
208                     lastTreatProjectList = JSON.parseObject(JSON.toJSONString(lastDetail.get("lastTreatProject")), new TypeReference<List<Map<String, Object>>>() {
fac939 209                     });
R 210                     consultRecordDto.setLastTreatProjectList(lastTreatProjectList);
211                 }
212             } else {
213                 //不为空 则拿取当前存储的上一次治疗项目数据
e356f0 214                 lastTreatProjectList = JSON.parseObject(consultRecordDto.getLastTreatProjects(), new TypeReference<List<Map<String, Object>>>() {
fac939 215                 });
R 216                 consultRecordDto.setLastTreatProjectList(lastTreatProjectList);
217             }
218         }
219
758a33 220         JSONObject data = new JSONObject();
fac939 221         consultRecordDto.setLastTreatProjects(null);
27b17f 222         data.put("info", consultRecordDto);
758a33 223
R 224         return PlatformResult.success(data);
225
226     }
227
228
229     /**
230      * 删除
231      */
232     @RequestMapping(value = "/del", method = RequestMethod.POST)
ca7ad5 233     public PlatformResult del(@RequestBody ConsultRecordDto consultRecordDto) {
758a33 234
3433c6 235         if (StringUtils.isEmpty(consultRecordDto.getId())) {
758a33 236             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "id为空");
R 237         }
238
239         ConsultationRecord consultationRecord = commonService.selectOneByKey(ConsultationRecordMapper.class, consultRecordDto.getId());
240         if (consultationRecord == null) {
241             throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!");
242         }
243
244
245         SqlSentence sqlSentence = new SqlSentence();
246         Map<String, Object> values = new HashMap<>();
247         sqlSentence.setM(values);
248
249         values.put("isDel", BaseEntity.NO);
250         values.put("consultationRecordId", consultationRecord.getId());
251
252         sqlSentence.setSqlSentence(" isDel = #{m.isDel} where id = #{m.consultationRecordId} and isDel = 0 ");
253         commonService.updateWhere(ConsultationRecordMapper.class, sqlSentence);
254
255         return PlatformResult.success();
256
257     }
258
259
260     /**
261      * 列表
262      */
263     @RequestMapping(value = "/user/list", method = RequestMethod.POST)
ca7ad5 264     public PlatformResult list(@RequestBody ConsultRecordDto consultRecordDto) {
758a33 265
R 266         if (consultRecordDto == null) {
267             throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空");
268         }
269
c5a96c 270 //        if (StringUtils.isEmpty(consultRecordDto.getUserId())) {
R 271 //            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空");
272 //        }
758a33 273
R 274         SqlSentence sqlSentence = new SqlSentence();
275         StringBuffer sql = new StringBuffer();
276         Map<String, Object> values = new HashMap<>();
277         sqlSentence.setM(values);
d4c5bd 278         values.put("key", VariableAesKey.AES_KEY);
d42117 279
e7373c 280         sql.append(" SELECT cr.id, cr.userId, cr.shopId, cr.departmentCode, cr.departmentName , cr.methodCode, cr.methodCodeName ");
94fddf 281         sql.append(" , cr.description , CONCAT(COALESCE(cr.content,''),'\\r\\n', COALESCE(cr.remark,'')) AS contents, cr.isCanCome , cr.adminType, cr.adminId, cr.adminName");
e7373c 282         sql.append(" , cr.hisId, cr.isVisit , cr.visitType, cr.isPay, cr.payLabelInfo, cr.isDraft, cr.satisfie , cr.faceDoctorId");
R 283         sql.append(" , cr.treatDoctorId, cr.dosageParams, cr.appealDetail, cr.treatPlanQuote , cr.anamnesis, cr.hasTreatProjects");
2c2a7e 284         sql.append(" , cr.lastTreatDoctorId, cr.lastTreatProjects, cr.facePlan, date_format(cr.createTime, '%Y-%m-%d %H:%i:%s') as createTime ");
e7373c 285         sql.append(" , u.CIQ, f.cnName AS faceDoctorName ,t.cnName AS treatDoctorName,s.name as shopName,u.name as userName ");
d4c5bd 286         sql.append(" ,insert(CONVERT(AES_DECRYPT(UNHEX(u.tel), #{m.key}) , CHAR), 4, 4, '****') as tel");
R 287         sql.append(" ,uStatistics.recentVisitType,uStatistics.recentVisitStatus,uStatistics.isMakeADeal");
a5704a 288         sql.append(" ,cr.doubt,cr.dissent,cr.budget,cr.interestedActivities,cr.followUpWorks,cr.userCareer");
C 289         sql.append(" ,cr.workRest,cr.character,cr.userLike,cr.maritalStatus,cr.preparationPregnancy");
290         sql.append(" ,cr.allergyHistory,cr.diseaseHistory,cr.unanamnesis,cr.anamTreatAgency,cr.anamTreatDoctor");
291         sql.append(" ,cr.anamTreatSatisfaction,cr.estimateMapper,cr.specialSituation");
758a33 292         sql.append(" FROM consultation_record cr ");
R 293         sql.append(" LEFT JOIN user u ON cr.userId = u.id ");
94fd34 294         sql.append(" LEFT JOIN employee f ON cr.faceDoctorId = f.id");
R 295         sql.append(" LEFT JOIN employee t ON cr.treatDoctorId = t.id ");
758a33 296         sql.append(" LEFT JOIN shop s on cr.shopId = s.id ");
d4c5bd 297         sql.append(" LEFT JOIN user_statistics AS uStatistics ON uStatistics.userId = cr.userId ");
c5a96c 298         sql.append(" WHERE cr.isDel = 0 ");
758a33 299
98eb74 300         // 咨询方式代码查找
b1323a 301         if (!StringUtils.isEmpty(consultRecordDto.getMethodCode())) {
98eb74 302             sql.append(" AND cr.methodCode=#{m.methodCode}");
b1323a 303             values.put("methodCode", consultRecordDto.getMethodCode());
ed91bd 304         }
758a33 305
d4c5bd 306         //用户搜索
fac939 307         if (!StringUtils.isEmpty(consultRecordDto.getUserId())) {
d4c5bd 308             values.put("userId", consultRecordDto.getUserId());
R 309             sql.append(" and cr.userId = #{m.userId} ");
758a33 310         }
R 311
119d7e 312         //时间搜索
fac939 313         if (!StringUtils.isEmpty(consultRecordDto.getStartTime())) {
57e1fb 314             values.put("startTime", consultRecordDto.getStartTime());
C 315             sql.append(" and cr.createTime >= #{m.startTime}");
119d7e 316         }
fac939 317         if (!StringUtils.isEmpty(consultRecordDto.getEndTime())) {
57e1fb 318             sql.append(" and cr.createTime <= #{m.endTime}");
C 319             values.put("endTime", consultRecordDto.getEndTime());
119d7e 320         }
R 321
d4c5bd 322         // 用户名查找
fac939 323         if (!StringUtils.isEmpty(consultRecordDto.getUserName())) {
d4c5bd 324             sql.append(" AND (u.name LIKE #{m.userName} OR u.tel LIKE #{m.userName} OR u.CIQ LIKE #{m.userName} OR u.memberNO LIKE #{m.userName})");
fac939 325             values.put("userName", "%" + consultRecordDto.getUserName() + "%");
119d7e 326         }
R 327
d4c5bd 328         // 关键字搜索
fac939 329         if (!StringUtils.isEmpty(consultRecordDto.getKeyWord())) {
d4c5bd 330             sql.append(" AND (cr.content LIKE #{m.keyWord} OR cr.description LIKE #{m.keyWord} OR cr.remark LIKE #{m.keyWord})");
fac939 331             values.put("keyWord", "%" + consultRecordDto.getKeyWord() + "%");
d4c5bd 332         }
R 333
334         // 咨询师
fac939 335         if (!StringUtils.isEmpty(consultRecordDto.getHisCorpUserId())) {
d4c5bd 336             sql.append(" AND u.hisCorpUserId=#{m.hisCorpUserId}");
fac939 337             values.put("hisCorpUserId", consultRecordDto.getHisCorpUserId());
d4c5bd 338         }
R 339
340         // 电网咨询师
fac939 341         if (!StringUtils.isEmpty(consultRecordDto.getInternetCorpUserId())) {
d4c5bd 342             sql.append(" AND u.internetCorpUserId=#{m.internetCorpUserId}");
fac939 343             values.put("internetCorpUserId", consultRecordDto.getInternetCorpUserId());
d4c5bd 344         }
R 345
346         // 客服
fac939 347         if (!StringUtils.isEmpty(consultRecordDto.getChatCorpUserId())) {
d4c5bd 348             sql.append(" AND u.chatCorpUserId=#{m.chatCorpUserId}");
fac939 349             values.put("chatCorpUserId", consultRecordDto.getChatCorpUserId());
d4c5bd 350         }
R 351
352         // 创建人
fac939 353         if (!StringUtils.isEmpty(consultRecordDto.getCreateEmployeeId())) {
d4c5bd 354             sql.append(" AND cr.adminId=#{m.createEmployeeId}");
fac939 355             values.put("createEmployeeId", consultRecordDto.getCreateEmployeeId());
d4c5bd 356         }
R 357
358         // 创建人部门
fac939 359         if (!StringUtils.isEmpty(consultRecordDto.getCreateEmployeePartId())) {
d4c5bd 360             // 根据部门查询数据
fac939 361             String employeePartQuery = handlerAppendQuery("cr.adminId", consultRecordDto.getCreateEmployeePartId(), 1);
d4c5bd 362             // 判断是否有查询数据
R 363             if (!StringUtils.isEmpty(employeePartQuery)) {
364                 sql.append(employeePartQuery);
365             } else {
366                 // 未查询到数据处理
367                 sql.append(" AND cr.adminId=''");
368             }
369         }
370
371         // 关注活动
fac939 372         if (!StringUtils.isEmpty(consultRecordDto.getFocusActivityId())) {
d4c5bd 373             // 根据关注活动查询数据
fac939 374             String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getFocusActivityId(), 2);
d4c5bd 375             // 判断是否有查询数据
R 376             if (!StringUtils.isEmpty(employeePartQuery)) {
377                 sql.append(employeePartQuery);
378             } else {
379                 // 未查询到数据处理
380                 sql.append(" AND cr.id=''");
381             }
382         }
383
384         // 推荐项目
fac939 385         if (!StringUtils.isEmpty(consultRecordDto.getRecommendProjectIds())) {
d4c5bd 386             // 根据推荐项目查询数据
fac939 387             String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getRecommendProjectIds(), 5);
d4c5bd 388             // 判断是否有查询数据
R 389             if (!StringUtils.isEmpty(employeePartQuery)) {
390                 sql.append(employeePartQuery);
391             } else {
392                 // 未查询到数据处理
393                 sql.append(" AND cr.id=''");
394             }
395         }
396
397         // 治疗项目
fac939 398         if (!StringUtils.isEmpty(consultRecordDto.getTreatProjectIds())) {
d4c5bd 399             // 根据推荐项目查询数据
fac939 400             String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getTreatProjectIds(), 6);
d4c5bd 401             // 判断是否有查询数据
R 402             if (!StringUtils.isEmpty(employeePartQuery)) {
403                 sql.append(employeePartQuery);
404             } else {
405                 // 未查询到数据处理
406                 sql.append(" AND cr.id=''");
407             }
408         }
409
410         // 客户来源一级渠道
fac939 411         if (!StringUtils.isEmpty(consultRecordDto.getChannelId())) {
d4c5bd 412             sql.append(" AND u.channelId = #{m.channelId} ");
fac939 413             values.put("channelId", consultRecordDto.getChannelId());
d4c5bd 414         }
R 415
416         // 客户来源二级渠道
fac939 417         if (!StringUtils.isEmpty(consultRecordDto.getChannel2Id())) {
d4c5bd 418             sql.append(" AND u.channel2Id = #{m.channel2Id} ");
fac939 419             values.put("channel2Id", consultRecordDto.getChannel2Id());
d4c5bd 420         }
R 421
422
423         // 到访类型
fac939 424         if (!StringUtils.isEmpty(consultRecordDto.getRecentVisitType())) {
d4c5bd 425             sql.append(" AND uStatistics.recentVisitType = #{m.recentVisitType} ");
fac939 426             values.put("recentVisitType", consultRecordDto.getRecentVisitType());
d4c5bd 427         }
R 428
429         // 到访状态
fac939 430         if (consultRecordDto.getRecentVisitStatus() != null) {
d4c5bd 431             sql.append(" AND uStatistics.recentVisitStatus = #{m.recentVisitStatus} ");
R 432             values.put("recentVisitStatus", consultRecordDto.getRecentVisitStatus());
433         }
434
435         // 是否成交
fac939 436         if (consultRecordDto.getIsMakeADeal() != null) {
d4c5bd 437             sql.append(" AND uStatistics.isMakeADeal = #{m.isMakeADeal} ");
R 438             values.put("isMakeADeal", consultRecordDto.getIsMakeADeal());
439         }
440
441         // 是否草稿
fac939 442         if (consultRecordDto.getIsDraft() != null) {
d4c5bd 443             sql.append(" AND cr.isDraft = #{m.isDraft} ");
R 444             values.put("isDraft", consultRecordDto.getIsDraft());
445         }
446
447         // 门店查找
fac939 448         if (!StringUtils.isEmpty(consultRecordDto.getShopId())) {
d4c5bd 449             sql.append(" and cr.shopId=#{m.shopId}");
fac939 450             values.put("shopId", consultRecordDto.getShopId());
c5a96c 451         }
R 452
788548 453         sql.append(" group by cr.id ");
758a33 454         sqlSentence.setSqlSentence(sql.toString());
fac939 455         PageHelper.startPage(consultRecordDto.getPageNum(), consultRecordDto.getPageSize(), " cr.createTime desc ");
758a33 456         List<Map<String, Object>> consultationRecordList = commonService.selectListMap(ConsultationRecordMapper.class, sqlSentence);
R 457
94fddf 458         if(consultationRecordList!= null && consultationRecordList.size()>0){
R 459
460             sql.delete(0, sql.length());
461             sql.append(" select * from consultation_treat_project where consultationRecordId = #{m.recordId} and isDel = 0  ");
758a33 462             consultationRecordList.forEach(c -> {
R 463                 values.put("recordId", c.get("id"));
464                 sqlSentence.setSqlSentence(sql.toString());
465                 List<Map<String, Object>> treatProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence);
466                 c.put("treatProjectList", treatProjectList);
467             });
468
94fddf 469             sql.delete(0, sql.length());
R 470             sql.append(" select * from consultation_recommended_project where consultationRecordId = #{m.recordId} and isDel = 0  ");
758a33 471             consultationRecordList.forEach(c -> {
R 472                 values.put("recordId", c.get("id"));
473                 sqlSentence.setSqlSentence(sql.toString());
474                 List<Map<String, Object>> recommendedProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence);
475                 c.put("recommendedProjectList", recommendedProjectList);
476             });
94fddf 477
R 478             //去除返回的数据 出现的换行符号
479             consultationRecordList.forEach(c->{
806848 480                 if(c.get("contents").toString().startsWith("\\r\\n") || StringUtils.isEmpty(c.get("contents").toString())) {
94fddf 481                     c.remove("contents");
R 482                 }else {
483                     c.put("content",c.get("contents"));
dadd57 484                     c.remove("contents");
94fddf 485                 }
R 486             });
487
758a33 488         }
R 489         PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(consultationRecordList);
490         return PlatformResult.success(pageInfo);
491
492     }
493
27b17f 494     /**
R 495      * 获取上一次的信息
496      */
497     @RequestMapping(value = "/last/detail", method = RequestMethod.POST)
94fd34 498     public PlatformResult lastDetail(@RequestBody(required = false) ConsultRecordDto consultRecordDto) {
27b17f 499
R 500         if (consultRecordDto == null) {
501             throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空");
502         }
503
504         if (StringUtils.isEmpty(consultRecordDto.getUserId())) {
505             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空");
506         }
507
508         JSONObject data = new JSONObject();
9521ea 509         data.put("lastInfo", lastDetail(consultRecordDto.getUserId(), null,0));
27b17f 510
R 511         return PlatformResult.success(data);
512
513     }
514
758a33 515
018779 516     /**
R 517      * 本次治疗项目或者 上次治疗项目下拉使用 已划扣执行的项目列表
518      */
519     @RequestMapping("/deduction/project/list")
520     public PlatformResult deductionProjectList(@RequestBody(required = false) ConsultRecordDto consultRecordDto) {
521
522         if (consultRecordDto == null) {
523             throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空");
524         }
525
526         if (StringUtils.isEmpty(consultRecordDto.getUserId())) {
527             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空");
528         }
529
00c80a 530         PageHelper.startPage(PageUtil.getPageNum(consultRecordDto.getPageNum()),PageUtil.getPageSize(consultRecordDto.getPageSize()));
8acb15 531         List<Map<String, Object>> list = deductionProjectList(consultRecordDto.getUserId(),consultRecordDto.getUseType(),consultRecordDto.getKeyWord(), commonService);
00c80a 532         PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
018779 533
00c80a 534         return PlatformResult.success(pageInfo);
018779 535
R 536     }
537
538
758a33 539     //////////////////////////////////////////////////////
R 540
fac939 541
R 542     //封装获取上一次咨询的 治疗医生 治疗项目
9521ea 543     public Map<String, Object> lastDetail(String userId, String detailId,Integer isInfo) {
fac939 544
R 545         SqlSentence sqlSentence = new SqlSentence();
546         StringBuffer sql = new StringBuffer();
547         Map<String, Object> values = new HashMap<>();
548         sqlSentence.setM(values);
549         values.put("userId", userId);
b1323a 550         ConsultationRecord consultationRecord;
646e90 551
9521ea 552         if (!StringUtils.isEmpty(detailId) && isInfo!= null && isInfo == 1) {
646e90 553             values.put("id", detailId);
018779 554             sql.delete(0, sql.length());
646e90 555             sql.append(" select * from consultation_record where isDel = 0 and userId = #{m.userId} and id!= #{m.id} order by createTime desc limit 1 ");
9521ea 556             sqlSentence.setSqlSentence(sql.toString());
R 557             consultationRecord = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence);
558         }else {
559             sql.delete(0, sql.length());
560             sql.append(" select * from consultation_record where isDel = 0 and userId = #{m.userId} order by createTime desc limit 1 ");
646e90 561             sqlSentence.setSqlSentence(sql.toString());
R 562             consultationRecord = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence);
b1323a 563         }
fac939 564
646e90 565         Map<String, Object> data = new HashMap<>();
fac939 566         if (consultationRecord != null) {
R 567             values.put("isDel", BaseEntity.NO);
568             values.put("consultationRecordId", consultationRecord.getId());
569
570             //治疗医生
571             Employee docEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getTreatDoctorId());
572             data.put("treatDoctorName", docEmp == null ? null : docEmp.getCnName());
573             data.put("treatDoctorId", docEmp == null ? null : docEmp.getId());
574
00c80a 575             //面诊医生
R 576             Employee faceEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getFaceDoctorId());
049a1a 577             data.put("faceDoctorName", faceEmp == null ? null : faceEmp.getCnName());
R 578             data.put("faceDoctorId", faceEmp == null ? null : faceEmp.getId());
00c80a 579
9b263a 580             //基本信息
e450d9 581 //            data.put("content", consultationRecord.getContent());
9b263a 582
b1323a 583             List<Map<String, Object>> lastTreatProject;
9521ea 584             if( !StringUtils.isEmpty(consultationRecord.getLastTreatProjects())
R 585                     && !"[]".equals(consultationRecord.getLastTreatProjects())
586                     && !"null".equals(consultationRecord.getLastTreatProjects())){
587                 // 治疗项目
e356f0 588                 lastTreatProject = JSON.parseObject(consultationRecord.getLastTreatProjects(), new TypeReference<List<Map<String, Object>>>() {
b1323a 589                 });
R 590                 data.put("lastTreatProject", lastTreatProject);
591             } else {
98eb74 592                 sql.delete(0, sql.length());
9b263a 593                 sql.append("SELECT crp.projectId as id ,crp.projectName as name FROM `consultation_treat_project` AS crp LEFT JOIN project AS pro ON pro.id=crp.projectId WHERE  crp.userId=#{m.userId} AND crp.consultationRecordId =#{m.consultationRecordId} AND crp.isDel=#{m.isDel}");
98eb74 594                 sqlSentence.setSqlSentence(sql.toString());
R 595                 lastTreatProject = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence);
b1323a 596                 data.put("lastTreatProject", lastTreatProject);
018779 597             }
R 598         } else {
599             //治疗医生
600             VisitRecord visitRecord = visitRecordInfo(userId);
601             if (visitRecord != null) {
602                 data.put("treatDoctorName", StringUtils.isEmpty(visitRecord.getDoctorName()) ? null : visitRecord.getDoctorName());
603                 data.put("treatDoctorId", StringUtils.isEmpty(visitRecord.getDoctorId()) ? null : visitRecord.getDoctorId());
604             }
605
606             //面诊医生 参与人员是多个时 拿取第一个数据作为面诊医生
8acb15 607             List<Map<String, Object>> deductionList = deductionProjectList(userId,null,null, commonService);
018779 608             if (deductionList != null && deductionList.size() != 0) {
664111 609                 if (deductionList.get(0).containsKey("deductionSingleId") && !StringUtils.isEmpty(deductionList.get(0).get("deductionSingleId").toString())) {
R 610                     Map<String, Object> deductionJsonEmp = deductionJsonEmp(deductionList.get(0).get("deductionSingleId").toString());
611                     if (deductionJsonEmp != null) {
612                         if (deductionJsonEmp.containsKey("employeeId") && !StringUtils.isEmpty(deductionJsonEmp.get("employeeId").toString())) {
613                             data.put("faceDoctorId", deductionJsonEmp.get("employeeId"));
614                         }
615                         if (deductionJsonEmp.containsKey("employeeName") && !StringUtils.isEmpty(deductionJsonEmp.get("employeeName").toString())) {
616                             data.put("faceDoctorName", deductionJsonEmp.get("employeeName"));
617                         }
018779 618                     }
R 619                 }
98eb74 620             }
fac939 621         }
R 622         return data;
623     }
624
625
758a33 626     /**
R 627      * 参数校验
628      */
fc0b15 629     public void checkParams(ConsultRecordDto consultRecordDto) {
758a33 630
R 631         if (consultRecordDto == null) {
632             throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空");
fac939 633         }
R 634
635         if (consultRecordDto.getSatisfie() == null) {
636             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "满意度为空");
758a33 637         }
R 638
639         if (StringUtils.isEmpty(consultRecordDto.getUserId())) {
640             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空");
641         }
642
643         if (StringUtils.isEmpty(consultRecordDto.getFaceDoctorId())) {
644             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "面诊医生为空");
645         }
646
647         if (consultRecordDto.getConsultType() == null) {
648             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "咨询类型为空");
649         }
fc0b15 650
98eb74 651         if (consultRecordDto.getConsultType() == 1) {
fc0b15 652             if (StringUtils.isEmpty(consultRecordDto.getAppealDetail())) {
R 653                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "主要诉求为空");
654             }
655
656             if (StringUtils.isEmpty(consultRecordDto.getTreatPlanQuote())) {
657                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗方案&报价为空");
658             }
fac939 659
R 660             if (StringUtils.isEmpty(consultRecordDto.getRecommendProjectIds())) {
661                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "推荐项目为空");
662             }
fc0b15 663         }
R 664
98eb74 665         if (consultRecordDto.getConsultType() == 2) {
fc0b15 666             if (StringUtils.isEmpty(consultRecordDto.getFacePlan())) {
R 667                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "面诊方案为空");
668             }
669         }
758a33 670     }
R 671
672
fac939 673     /**
R 674      * 处理多个条件查询 拼接Sql
675      **/
676     private String handlerAppendQuery(String fieldName, String keyId, Integer type) {
d4c5bd 677         SqlSentence sqlSentence = new SqlSentence();
R 678         Map<String, Object> sqlValue = new HashMap<>();
679         sqlValue.put("isDel", BaseEntity.NO);
680         sqlValue.put("keyId", keyId);
681         String sql = "";
682         String getId = "";
fac939 683         if (type == 1) {
d4c5bd 684             // 根据部门名称查询
R 685             sql = "SELECT DISTINCT empl.id FROM employee AS empl LEFT JOIN employee_role AS erole ON erole.employeeId=empl.id  " +
686                     "WHERE empl.isDel=#{m.isDel} AND erole.departmentId=#{m.keyId}";
687             getId = "id";
fac939 688         } else if (type == 2) {
d4c5bd 689             // 根据关注活动查询
R 690             sql = "SELECT DISTINCT consultationRecordId FROM `consultation_focus_activity` WHERE activityId =#{m.keyId} AND isDel=#{m.isDel}";
691             getId = "consultationRecordId";
692         }
693 //        else if(type == 3){
694 //            // 根据咨询项目类别查询
695 //            sql = "SELECT DISTINCT consultationRecordId FROM `consultation_needed_project` WHERE projectTypeId =#{m.keyId} AND isDel=#{m.isDel}";
696 //            getId = "consultationRecordId";
697 //        } else if(type == 4){
698 //            // 根据潜在项目类别查询
699 //            sql = "SELECT DISTINCT consultationRecordId FROM `consultation_potential_project` WHERE projectTypeId =#{m.keyId} AND isDel=#{m.isDel}";
700 //            getId = "consultationRecordId";
701 //        }
fac939 702         else if (type == 5) {
d4c5bd 703             // 根据推荐项目查询
R 704             sql = "SELECT DISTINCT consultationRecordId FROM `consultation_recommended_project` WHERE projectId =#{m.keyId} AND isDel=#{m.isDel}";
705             getId = "consultationRecordId";
fac939 706         } else if (type == 6) {
d4c5bd 707             // 根据治疗项目查询
R 708             sql = "SELECT DISTINCT consultationRecordId FROM `consultation_treat_project` WHERE projectId =#{m.keyId} AND isDel=#{m.isDel}";
709             getId = "consultationRecordId";
710         }
711         sqlSentence.sqlSentence(sql, sqlValue);
712         List<Map<String, Object>> mapList = commonService.selectListMap(com.hx.phiappt.dao.mapper.EmployeeMapper.class, sqlSentence);
fac939 713         if (mapList != null && mapList.size() > 0) {
d4c5bd 714             StringBuilder sqlBuilder = new StringBuilder();
R 715             sqlBuilder.append(" and ").append(fieldName).append(" in ( ");
716             for (Map<String, Object> mapInfo : mapList) {
717                 if (mapInfo != null) {
718                     sqlBuilder.append("'").append(mapInfo.get(getId)).append("'").append(",");
719                 }
720             }
721             sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length());
722             sqlBuilder.append(")");
723             return sqlBuilder.toString();
724         }
725         return null;
726     }
727
728
018779 729     /**
R 730      * 已执行划扣的项目
731      **/
8acb15 732     public static List<Map<String, Object>> deductionProjectList(String userId,String useType,String keyWord, CommonService commonService) {
018779 733         SqlSentence sqlSentence = new SqlSentence();
R 734         Map<String, Object> values = new HashMap<>();
735         sqlSentence.setM(values);
736         values.put("userId", userId);
737
00c80a 738         StringBuffer sql = new StringBuffer();
01d533 739         sql.append(" SELECT dp.deductionSingleId,p.id,p.name,p.specification,upi.id as upiId ");
00c80a 740
17049c 741         if(!StringUtils.isEmpty(useType) && useType.equals("admin")){
00c80a 742             sql.append(" ,p.unit,p.treatmentItemsNum AS courseCount,p.category,p.price,p.originalPrice,p.coding");
R 743         }
744
745         sql.append(" FROM user_project_item upi ");
746         sql.append(" LEFT JOIN USER us ON us.id = upi.userId ");
747         sql.append(" LEFT JOIN deduction_project dp ON upi.id = dp.userProjectItemId ");
bd9553 748         sql.append(" LEFT JOIN project p on upi.goodsId = p.id  ");
00c80a 749         sql.append(" WHERE 1 = 1 AND upi.userId = #{m.userId} ");
18f8aa 750         sql.append(" AND ( upi.effectiveStatus = 3 OR ( upi.effectiveStatus = 1 AND upi.notUsedNum = 0 AND upi.usedNum > 0 ) ");
01d533 751         sql.append(" OR ( upi.effectiveStatus = 1 AND upi.usedNum > 0 AND upi.notUsedNum > 0 ) ");
R 752         sql.append(" OR ( upi.effectiveStatus = 1 AND upi.usedNum <= 0 AND upi.cancelNum < upi.usedTotal AND upi.notUsedNum > 0 )) ");
bd9553 753         sql.append(" AND upi.isDel = 0 ");
8acb15 754
R 755         if (!StringUtils.isEmpty(keyWord)) {
756             sql.append(" and ( p.name like #{m.keyWord} or p.coding like #{m.keyWord} )");
757             values.put("keyWord", "%" + keyWord + "%");
758         }
759
00c80a 760         sql.append("  GROUP BY upi.id");
R 761         sql.append(" ORDER BY upi.createTime DESC, upi.goodsName DESC");
762         sqlSentence.setSqlSentence(sql.toString());
018779 763         List<Map<String, Object>> list = commonService.selectListMap(UserProjectItemMapper.class, sqlSentence);
01d533 764         if (list != null && list.size() > 0) {
R 765             //处理状态返回展示
766             for (Map<String, Object> objectMap : list) {
767                 // 用户项目信息
768                 UserProjectItem userProjectItem = commonService.selectOneByKey(UserProjectItemMapper.class, objectMap.get("upiId"));
769                 if (userProjectItem != null) {
770                     // 状态
771                     Integer status = null;
772                     // 待执行 项目有效 已执行数量 <= 0 & 已取消数量<总次数 & 未使用次数 > 0 & 还没过期(暂时不用判断)
773                     if (UserProjectConstants.EFF_STATUS_YES == userProjectItem.getEffectiveStatus() && userProjectItem.getUsedNum() <= 0
774                             && userProjectItem.getCancelNum() < userProjectItem.getUsedTotal() && userProjectItem.getNotUsedNum() > 0) {
775                         status = UserProjectTool.STATUS_WAIT;
776                     }
777                     // 执行中 项目有效 已执行数量>0 & 有效可执行次数 > 0 & 还没过期(暂时不用判断)
778                     if (status == null && UserProjectConstants.EFF_STATUS_YES == userProjectItem.getEffectiveStatus()
779                             && userProjectItem.getUsedNum() > 0 && userProjectItem.getNotUsedNum() > 0) {
780                         status = UserProjectTool.STATUS_USED;
781                     }
782                     // 已执行 有效可执行次数 = 0 & 已执行数量 > 0
783                     if (status == null && (UserProjectConstants.EFF_STATUS_DONE == userProjectItem.getEffectiveStatus() ||
784                             (UserProjectConstants.EFF_STATUS_YES == userProjectItem.getEffectiveStatus() &&
785                                     userProjectItem.getNotUsedNum() == 0 && userProjectItem.getUsedNum() > 0))) {
786                         status = UserProjectTool.STATUS_DONE;
787                     }
788                     // 状态不为空在处理
789                     if (status != null) {
790                         objectMap.put("status", status);
791                         objectMap.put("statusName", getStatusName(status));
792                     }
793                 }
794             }
795         }
018779 796         return list;
R 797     }
798
799
800     /**
801      * 划扣参与人 - 治疗医生
802      **/
803     private Map<String, Object> deductionJsonEmp(String deductionSingleId) {
804         SqlSentence sqlSentence = new SqlSentence();
805         Map<String, Object> values = new HashMap<>();
806         sqlSentence.setM(values);
807
808         values.put("isDel", BaseEntity.NO);
809         values.put("id", deductionSingleId);
810         values.put("roleUniqueStr", "doctor");
811
812         sqlSentence.setSqlSentence("SELECT employeeId,employeeName FROM deduction_join WHERE deductionSingleId=#{m.id} AND isDel=#{m.isDel} and  roleUniqueStr = #{m.roleUniqueStr} order by createTime desc limit 1 ");
813         Map<String, Object> subMap = commonService.selectOneMap(DeductionJoinMapper.class, sqlSentence);
814         return subMap;
815     }
816
817
818     /**
819      * 划扣参与人 - 治疗医生
820      **/
821     private VisitRecord visitRecordInfo(String userId) {
822         SqlSentence sqlSentence = new SqlSentence();
823         Map<String, Object> values = new HashMap<>();
824         sqlSentence.setM(values);
825
826         values.put("userId", userId);
827         sqlSentence.setSqlSentence("select * from v_visit_record where isDel = 0 and userId = #{m.userId} order by createTime desc limit 1");
828         VisitRecord visitRecord = commonService.selectOne(VisitRecordMapper.class, sqlSentence);
829         return visitRecord;
830     }
831
832
758a33 833 }