package com.hx.phip.controller.consultation; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hx.common.BaseController; import com.hx.common.service.CommonService; import com.hx.guide.model.VisitRecord; import com.hx.mybatis.aes.springbean.VariableAesKey; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.constants.tool.PageUtil; import com.hx.phiappt.dao.mapper.ConsultationRecommendedProjectMapper; import com.hx.phiappt.dao.mapper.DeductionJoinMapper; import com.hx.phiappt.dao.mapper.UserProjectItemMapper; import com.hx.phiappt.model.BaseEntity; import com.hx.phiappt.model.ConsultationRecord; import com.hx.phiappt.model.Employee; import com.hx.phiappt.model.User; import com.hx.phip.dao.mapper.*; import com.hx.phip.service.SystemParameterService; import com.hx.phip.service.consultation.ConsultationRecordService; import com.hx.util.StringUtils; import com.hz.his.dto.consultation.ConsultRecordDto; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import com.platform.resultTool.PlatformResult; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; 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.HashMap; import java.util.List; import java.util.Map; /** * 咨询记录 */ @Slf4j @RestController @RequestMapping("/consultation/record") public class ConsultationRecordController extends BaseController { @Resource private ConsultationRecordService consultationRecordService; @Resource private SystemParameterService systemParameterService; /** * 新增 */ @RequestMapping(value = "/add/or/edit", method = RequestMethod.POST) public PlatformResult addOrEditData(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { //参数校验 checkParams(consultRecordDto); if (!StringUtils.isEmpty(consultRecordDto.getId())) { ConsultationRecord consultationRecord = commonService.selectOneByKey(ConsultationRecordMapper.class, consultRecordDto.getId()); if (consultationRecord == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!"); } } String id = consultationRecordService.insertOrEdit(consultRecordDto, systemParameterService, commonService); JSONObject data = new JSONObject(); data.put("id", id); return PlatformResult.success(data); } /** * 详情 */ @RequestMapping(value = "/detail", method = RequestMethod.POST) public PlatformResult detail(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { if (StringUtils.isEmpty(consultRecordDto.getId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "id为空"); } ConsultationRecord consultationRecord = commonService.selectOneByKey(ConsultationRecordMapper.class, consultRecordDto.getId()); if (consultationRecord == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!"); } BeanUtils.copyProperties(consultationRecord, consultRecordDto); SqlSentence sqlSentence = new SqlSentence(); StringBuffer sql = new StringBuffer(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("isDel", BaseEntity.NO); values.put("consultationRecordId", consultationRecord.getId()); values.put("userId", consultationRecord.getUserId()); // 推荐项目列表 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}"); sqlSentence.setSqlSentence(sql.toString()); List> recommendedProjectList = commonService.selectListMap(ConsultationRecommendedProjectMapper.class, sqlSentence); consultRecordDto.setRecommendProjectList(recommendedProjectList); // 治疗项目 sql.delete(0, sql.length()); 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}"); sqlSentence.setSqlSentence(sql.toString()); List> treatProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence); consultRecordDto.setTreatProjectList(treatProjectList); //面诊医生 Employee faceEmp = commonService.selectOneByKey(EmployeeMapper.class, consultRecordDto.getFaceDoctorId()); consultRecordDto.setFaceDoctorName(faceEmp == null ? null : faceEmp.getCnName()); //治疗医生 Employee treatEmp = commonService.selectOneByKey(EmployeeMapper.class, consultRecordDto.getTreatDoctorId()); consultRecordDto.setTreatDoctorName(treatEmp == null ? null : treatEmp.getCnName()); //查询用户顾问名称 User user = commonService.selectOneByKey(UserMapper.class, consultRecordDto.getUserId()); if (user != null) { if (!StringUtils.isEmpty(user.getHisCorpUserId())) { Employee corpEmp = commonService.selectOneByKey(EmployeeMapper.class, user.getHisCorpUserId()); consultRecordDto.setHisCorpUserName(corpEmp == null ? null : corpEmp.getCnName()); } //手机号 if(StringUtils.isEmpty(user.getTel()) || user.getTel().equals("测试服不存")) { consultRecordDto.setTel("-"); }else { consultRecordDto.setTel(user.getTel().substring(0, 3) + "****" + user.getTel().substring(7)); } } //返回基本信息 // if (StringUtils.isEmpty(consultRecordDto.getContent())) { // sql.delete(0, sql.length()); // sql.append(" select * from consultation_record where isDel = 0 and id!= #{m.consultationRecordId} and userId = #{m.userId} order by createTime desc limit 1 "); // sqlSentence.setSqlSentence(sql.toString()); // ConsultationRecord consultContent = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence); // consultRecordDto.setContent(consultContent != null ? consultContent.getContent() : null); // } //非初复诊返回下面的值 if (consultRecordDto.getConsultType() >= 2) { if (StringUtils.isEmpty(consultRecordDto.getLastTreatDoctorId())) { //为空 查询上一次的咨询记录的数据 拿到咨询医生 ID、名称 Map lastDetail = lastDetail(consultRecordDto.getUserId(), consultRecordDto.getId(),1); if (lastDetail != null) { if (lastDetail.containsKey("treatDoctorId") && lastDetail.get("treatDoctorId") != null && !StringUtils.isEmpty(lastDetail.get("treatDoctorId").toString())) { consultRecordDto.setLastTreatDoctorId(lastDetail.get("treatDoctorId").toString()); } if (lastDetail.containsKey("treatDoctorName") && lastDetail.get("treatDoctorName") != null && !StringUtils.isEmpty(lastDetail.get("treatDoctorName").toString())) consultRecordDto.setLastTreatDoctorName(lastDetail.get("treatDoctorName").toString()); } } else { //不为空 则拿取当前的数据 consultRecordDto.setLastTreatDoctorId(consultationRecord.getLastTreatDoctorId()); Employee docEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getLastTreatDoctorId()); consultRecordDto.setLastTreatDoctorName(docEmp.getCnName()); } List> lastTreatProjectList; //为空 查询上一次的咨询记录的数据 拿到上一条记录存储的治疗项目数据 if (StringUtils.isEmpty(consultRecordDto.getLastTreatProjects()) || "[]".equals(consultRecordDto.getLastTreatProjects()) || "null".equals(consultRecordDto.getLastTreatProjects())) { Map lastDetail = lastDetail(consultRecordDto.getUserId(), consultRecordDto.getId(),1); if (lastDetail.containsKey("lastTreatProject") && lastDetail.get("lastTreatProject") != null && !StringUtils.isEmpty(lastDetail.get("lastTreatProject").toString()) && !"[]".equals(lastDetail.get("lastTreatProject").toString()) && !"null".equals(lastDetail.get("lastTreatProject").toString())) { lastTreatProjectList = JSON.parseObject(JSON.toJSONString(lastDetail.get("lastTreatProject")), new TypeReference>>() { }); consultRecordDto.setLastTreatProjectList(lastTreatProjectList); } } else { //不为空 则拿取当前存储的上一次治疗项目数据 lastTreatProjectList = JSON.parseObject(consultRecordDto.getLastTreatProjects(), new TypeReference>>() { }); consultRecordDto.setLastTreatProjectList(lastTreatProjectList); } } JSONObject data = new JSONObject(); consultRecordDto.setLastTreatProjects(null); data.put("info", consultRecordDto); return PlatformResult.success(data); } /** * 删除 */ @RequestMapping(value = "/del", method = RequestMethod.POST) public PlatformResult del(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { if (StringUtils.isEmpty(consultRecordDto.getId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "id为空"); } ConsultationRecord consultationRecord = commonService.selectOneByKey(ConsultationRecordMapper.class, consultRecordDto.getId()); if (consultationRecord == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到咨询记录!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("isDel", BaseEntity.NO); values.put("consultationRecordId", consultationRecord.getId()); sqlSentence.setSqlSentence(" isDel = #{m.isDel} where id = #{m.consultationRecordId} and isDel = 0 "); commonService.updateWhere(ConsultationRecordMapper.class, sqlSentence); return PlatformResult.success(); } /** * 列表 */ @RequestMapping(value = "/user/list", method = RequestMethod.POST) public PlatformResult list(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { if (consultRecordDto == null) { throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空"); } // if (StringUtils.isEmpty(consultRecordDto.getUserId())) { // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空"); // } SqlSentence sqlSentence = new SqlSentence(); StringBuffer sql = new StringBuffer(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("key", VariableAesKey.AES_KEY); sql.append(" select cr.*, u.CIQ, f.cnName AS faceDoctorName ,t.cnName AS treatDoctorName,s.name as shopName,u.name as userName "); sql.append(" ,insert(CONVERT(AES_DECRYPT(UNHEX(u.tel), #{m.key}) , CHAR), 4, 4, '****') as tel"); sql.append(" ,uStatistics.recentVisitType,uStatistics.recentVisitStatus,uStatistics.isMakeADeal"); sql.append(" FROM consultation_record cr "); sql.append(" LEFT JOIN user u ON cr.userId = u.id "); sql.append(" LEFT JOIN employee f ON cr.faceDoctorId = f.id"); sql.append(" LEFT JOIN employee t ON cr.treatDoctorId = t.id "); sql.append(" LEFT JOIN shop s on cr.shopId = s.id "); sql.append(" LEFT JOIN user_statistics AS uStatistics ON uStatistics.userId = cr.userId "); sql.append(" WHERE cr.isDel = 0 "); // 咨询方式代码查找 if (!StringUtils.isEmpty(consultRecordDto.getMethodCode())) { sql.append(" AND cr.methodCode=#{m.methodCode}"); values.put("methodCode", consultRecordDto.getMethodCode()); } //用户搜索 if (!StringUtils.isEmpty(consultRecordDto.getUserId())) { values.put("userId", consultRecordDto.getUserId()); sql.append(" and cr.userId = #{m.userId} "); } //时间搜索 if (!StringUtils.isEmpty(consultRecordDto.getStartTime())) { values.put("startTime", consultRecordDto.getStartTime() + "00:00:00"); sql.append(" and cr.createTime >= #{m.startTime} "); } if (!StringUtils.isEmpty(consultRecordDto.getEndTime())) { sql.append(" and cr.createTime <= #{m.endTime} "); values.put("endTime", consultRecordDto.getEndTime() + "23:59:59"); } // 用户名查找 if (!StringUtils.isEmpty(consultRecordDto.getUserName())) { 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})"); values.put("userName", "%" + consultRecordDto.getUserName() + "%"); } // 关键字搜索 if (!StringUtils.isEmpty(consultRecordDto.getKeyWord())) { sql.append(" AND (cr.content LIKE #{m.keyWord} OR cr.description LIKE #{m.keyWord} OR cr.remark LIKE #{m.keyWord})"); values.put("keyWord", "%" + consultRecordDto.getKeyWord() + "%"); } // 咨询师 if (!StringUtils.isEmpty(consultRecordDto.getHisCorpUserId())) { sql.append(" AND u.hisCorpUserId=#{m.hisCorpUserId}"); values.put("hisCorpUserId", consultRecordDto.getHisCorpUserId()); } // 电网咨询师 if (!StringUtils.isEmpty(consultRecordDto.getInternetCorpUserId())) { sql.append(" AND u.internetCorpUserId=#{m.internetCorpUserId}"); values.put("internetCorpUserId", consultRecordDto.getInternetCorpUserId()); } // 客服 if (!StringUtils.isEmpty(consultRecordDto.getChatCorpUserId())) { sql.append(" AND u.chatCorpUserId=#{m.chatCorpUserId}"); values.put("chatCorpUserId", consultRecordDto.getChatCorpUserId()); } // 创建人 if (!StringUtils.isEmpty(consultRecordDto.getCreateEmployeeId())) { sql.append(" AND cr.adminId=#{m.createEmployeeId}"); values.put("createEmployeeId", consultRecordDto.getCreateEmployeeId()); } // 创建人部门 if (!StringUtils.isEmpty(consultRecordDto.getCreateEmployeePartId())) { // 根据部门查询数据 String employeePartQuery = handlerAppendQuery("cr.adminId", consultRecordDto.getCreateEmployeePartId(), 1); // 判断是否有查询数据 if (!StringUtils.isEmpty(employeePartQuery)) { sql.append(employeePartQuery); } else { // 未查询到数据处理 sql.append(" AND cr.adminId=''"); } } // 关注活动 if (!StringUtils.isEmpty(consultRecordDto.getFocusActivityId())) { // 根据关注活动查询数据 String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getFocusActivityId(), 2); // 判断是否有查询数据 if (!StringUtils.isEmpty(employeePartQuery)) { sql.append(employeePartQuery); } else { // 未查询到数据处理 sql.append(" AND cr.id=''"); } } // 推荐项目 if (!StringUtils.isEmpty(consultRecordDto.getRecommendProjectIds())) { // 根据推荐项目查询数据 String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getRecommendProjectIds(), 5); // 判断是否有查询数据 if (!StringUtils.isEmpty(employeePartQuery)) { sql.append(employeePartQuery); } else { // 未查询到数据处理 sql.append(" AND cr.id=''"); } } // 治疗项目 if (!StringUtils.isEmpty(consultRecordDto.getTreatProjectIds())) { // 根据推荐项目查询数据 String employeePartQuery = handlerAppendQuery("cr.id", consultRecordDto.getTreatProjectIds(), 6); // 判断是否有查询数据 if (!StringUtils.isEmpty(employeePartQuery)) { sql.append(employeePartQuery); } else { // 未查询到数据处理 sql.append(" AND cr.id=''"); } } // 客户来源一级渠道 if (!StringUtils.isEmpty(consultRecordDto.getChannelId())) { sql.append(" AND u.channelId = #{m.channelId} "); values.put("channelId", consultRecordDto.getChannelId()); } // 客户来源二级渠道 if (!StringUtils.isEmpty(consultRecordDto.getChannel2Id())) { sql.append(" AND u.channel2Id = #{m.channel2Id} "); values.put("channel2Id", consultRecordDto.getChannel2Id()); } // 到访类型 if (!StringUtils.isEmpty(consultRecordDto.getRecentVisitType())) { sql.append(" AND uStatistics.recentVisitType = #{m.recentVisitType} "); values.put("recentVisitType", consultRecordDto.getRecentVisitType()); } // 到访状态 if (consultRecordDto.getRecentVisitStatus() != null) { sql.append(" AND uStatistics.recentVisitStatus = #{m.recentVisitStatus} "); values.put("recentVisitStatus", consultRecordDto.getRecentVisitStatus()); } // 是否成交 if (consultRecordDto.getIsMakeADeal() != null) { sql.append(" AND uStatistics.isMakeADeal = #{m.isMakeADeal} "); values.put("isMakeADeal", consultRecordDto.getIsMakeADeal()); } // 是否草稿 if (consultRecordDto.getIsDraft() != null) { sql.append(" AND cr.isDraft = #{m.isDraft} "); values.put("isDraft", consultRecordDto.getIsDraft()); } // 门店查找 if (!StringUtils.isEmpty(consultRecordDto.getShopId())) { sql.append(" and cr.shopId=#{m.shopId}"); values.put("shopId", consultRecordDto.getShopId()); } sql.append(" group by cr.id "); sqlSentence.setSqlSentence(sql.toString()); PageHelper.startPage(consultRecordDto.getPageNum(), consultRecordDto.getPageSize(), " cr.createTime desc "); List> consultationRecordList = commonService.selectListMap(ConsultationRecordMapper.class, sqlSentence); sql.delete(0, sql.length()); sql.append(" select * from consultation_treat_project where consultationRecordId = #{m.recordId} and isDel = 0 "); if (consultationRecordList != null && consultationRecordList.size() > 0) { consultationRecordList.forEach(c -> { values.put("recordId", c.get("id")); sqlSentence.setSqlSentence(sql.toString()); List> treatProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence); c.put("treatProjectList", treatProjectList); }); } sql.delete(0, sql.length()); sql.append(" select * from consultation_recommended_project where consultationRecordId = #{m.recordId} and isDel = 0 "); if (consultationRecordList != null && consultationRecordList.size() > 0) { consultationRecordList.forEach(c -> { values.put("recordId", c.get("id")); sqlSentence.setSqlSentence(sql.toString()); List> recommendedProjectList = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence); c.put("recommendedProjectList", recommendedProjectList); }); } PageInfo> pageInfo = new PageInfo<>(consultationRecordList); return PlatformResult.success(pageInfo); } /** * 获取上一次的信息 */ @RequestMapping(value = "/last/detail", method = RequestMethod.POST) public PlatformResult lastDetail(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { if (consultRecordDto == null) { throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空"); } if (StringUtils.isEmpty(consultRecordDto.getUserId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空"); } JSONObject data = new JSONObject(); data.put("lastInfo", lastDetail(consultRecordDto.getUserId(), null,0)); return PlatformResult.success(data); } /** * 本次治疗项目或者 上次治疗项目下拉使用 已划扣执行的项目列表 */ @RequestMapping("/deduction/project/list") public PlatformResult deductionProjectList(@RequestBody(required = false) ConsultRecordDto consultRecordDto) { if (consultRecordDto == null) { throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空"); } if (StringUtils.isEmpty(consultRecordDto.getUserId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空"); } PageHelper.startPage(PageUtil.getPageNum(consultRecordDto.getPageNum()),PageUtil.getPageSize(consultRecordDto.getPageSize())); List> list = deductionProjectList(consultRecordDto.getUserId(),consultRecordDto.getUseType(), commonService); PageInfo> pageInfo = new PageInfo<>(list); return PlatformResult.success(pageInfo); } ////////////////////////////////////////////////////// //封装获取上一次咨询的 治疗医生 治疗项目 public Map lastDetail(String userId, String detailId,Integer isInfo) { SqlSentence sqlSentence = new SqlSentence(); StringBuffer sql = new StringBuffer(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("userId", userId); ConsultationRecord consultationRecord; if (!StringUtils.isEmpty(detailId) && isInfo!= null && isInfo == 1) { values.put("id", detailId); sql.delete(0, sql.length()); sql.append(" select * from consultation_record where isDel = 0 and userId = #{m.userId} and id!= #{m.id} order by createTime desc limit 1 "); sqlSentence.setSqlSentence(sql.toString()); consultationRecord = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence); }else { sql.delete(0, sql.length()); sql.append(" select * from consultation_record where isDel = 0 and userId = #{m.userId} order by createTime desc limit 1 "); sqlSentence.setSqlSentence(sql.toString()); consultationRecord = commonService.selectOne(ConsultationRecordMapper.class, sqlSentence); } Map data = new HashMap<>(); if (consultationRecord != null) { values.put("isDel", BaseEntity.NO); values.put("consultationRecordId", consultationRecord.getId()); //治疗医生 Employee docEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getTreatDoctorId()); data.put("treatDoctorName", docEmp == null ? null : docEmp.getCnName()); data.put("treatDoctorId", docEmp == null ? null : docEmp.getId()); //面诊医生 Employee faceEmp = commonService.selectOneByKey(EmployeeMapper.class, consultationRecord.getFaceDoctorId()); data.put("faceDoctorName", faceEmp == null ? null : faceEmp.getCnName()); data.put("faceDoctorId", faceEmp == null ? null : faceEmp.getId()); //基本信息 // data.put("content", consultationRecord.getContent()); List> lastTreatProject; if( !StringUtils.isEmpty(consultationRecord.getLastTreatProjects()) && !"[]".equals(consultationRecord.getLastTreatProjects()) && !"null".equals(consultationRecord.getLastTreatProjects())){ // 治疗项目 lastTreatProject = JSON.parseObject(consultationRecord.getLastTreatProjects(), new TypeReference>>() { }); data.put("lastTreatProject", lastTreatProject); } else { sql.delete(0, sql.length()); 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}"); sqlSentence.setSqlSentence(sql.toString()); lastTreatProject = commonService.selectListMap(ConsultationTreatProjectMapper.class, sqlSentence); data.put("lastTreatProject", lastTreatProject); } } else { //治疗医生 VisitRecord visitRecord = visitRecordInfo(userId); if (visitRecord != null) { data.put("treatDoctorName", StringUtils.isEmpty(visitRecord.getDoctorName()) ? null : visitRecord.getDoctorName()); data.put("treatDoctorId", StringUtils.isEmpty(visitRecord.getDoctorId()) ? null : visitRecord.getDoctorId()); } //面诊医生 参与人员是多个时 拿取第一个数据作为面诊医生 List> deductionList = deductionProjectList(userId,null, commonService); if (deductionList != null && deductionList.size() != 0) { Map deductionJsonEmp = deductionJsonEmp(deductionList.get(0).get("deductionSingleId").toString()); if (deductionJsonEmp != null) { if (deductionJsonEmp.containsKey("employeeId") && !StringUtils.isEmpty(deductionJsonEmp.get("employeeId").toString())) { data.put("faceDoctorId", deductionJsonEmp.get("employeeId")); } if (deductionJsonEmp.containsKey("employeeName") && !StringUtils.isEmpty(deductionJsonEmp.get("employeeName").toString())) { data.put("faceDoctorName", deductionJsonEmp.get("employeeName")); } } } } return data; } /** * 参数校验 */ public void checkParams(ConsultRecordDto consultRecordDto) { if (consultRecordDto == null) { throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA, "数据参数为空"); } if (consultRecordDto.getSatisfie() == null) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "满意度为空"); } if (StringUtils.isEmpty(consultRecordDto.getUserId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户ID为空"); } if (StringUtils.isEmpty(consultRecordDto.getFaceDoctorId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "面诊医生为空"); } if (consultRecordDto.getConsultType() == null) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "咨询类型为空"); } if (consultRecordDto.getConsultType() == 1) { if (StringUtils.isEmpty(consultRecordDto.getAppealDetail())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "主要诉求为空"); } if (StringUtils.isEmpty(consultRecordDto.getTreatPlanQuote())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "治疗方案&报价为空"); } if (StringUtils.isEmpty(consultRecordDto.getRecommendProjectIds())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "推荐项目为空"); } } if (consultRecordDto.getConsultType() == 2) { if (StringUtils.isEmpty(consultRecordDto.getFacePlan())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "面诊方案为空"); } } } /** * 处理多个条件查询 拼接Sql **/ private String handlerAppendQuery(String fieldName, String keyId, Integer type) { SqlSentence sqlSentence = new SqlSentence(); Map sqlValue = new HashMap<>(); sqlValue.put("isDel", BaseEntity.NO); sqlValue.put("keyId", keyId); String sql = ""; String getId = ""; if (type == 1) { // 根据部门名称查询 sql = "SELECT DISTINCT empl.id FROM employee AS empl LEFT JOIN employee_role AS erole ON erole.employeeId=empl.id " + "WHERE empl.isDel=#{m.isDel} AND erole.departmentId=#{m.keyId}"; getId = "id"; } else if (type == 2) { // 根据关注活动查询 sql = "SELECT DISTINCT consultationRecordId FROM `consultation_focus_activity` WHERE activityId =#{m.keyId} AND isDel=#{m.isDel}"; getId = "consultationRecordId"; } // else if(type == 3){ // // 根据咨询项目类别查询 // sql = "SELECT DISTINCT consultationRecordId FROM `consultation_needed_project` WHERE projectTypeId =#{m.keyId} AND isDel=#{m.isDel}"; // getId = "consultationRecordId"; // } else if(type == 4){ // // 根据潜在项目类别查询 // sql = "SELECT DISTINCT consultationRecordId FROM `consultation_potential_project` WHERE projectTypeId =#{m.keyId} AND isDel=#{m.isDel}"; // getId = "consultationRecordId"; // } else if (type == 5) { // 根据推荐项目查询 sql = "SELECT DISTINCT consultationRecordId FROM `consultation_recommended_project` WHERE projectId =#{m.keyId} AND isDel=#{m.isDel}"; getId = "consultationRecordId"; } else if (type == 6) { // 根据治疗项目查询 sql = "SELECT DISTINCT consultationRecordId FROM `consultation_treat_project` WHERE projectId =#{m.keyId} AND isDel=#{m.isDel}"; getId = "consultationRecordId"; } sqlSentence.sqlSentence(sql, sqlValue); List> mapList = commonService.selectListMap(com.hx.phiappt.dao.mapper.EmployeeMapper.class, sqlSentence); if (mapList != null && mapList.size() > 0) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append(" and ").append(fieldName).append(" in ( "); for (Map mapInfo : mapList) { if (mapInfo != null) { sqlBuilder.append("'").append(mapInfo.get(getId)).append("'").append(","); } } sqlBuilder.delete(sqlBuilder.length() - 1, sqlBuilder.length()); sqlBuilder.append(")"); return sqlBuilder.toString(); } return null; } /** * 已执行划扣的项目 **/ public static List> deductionProjectList(String userId,String useType, CommonService commonService) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("userId", userId); StringBuffer sql = new StringBuffer(); sql.append(" SELECT dp.deductionSingleId,p.id,p.name,p.specification "); if(!StringUtils.isEmpty(useType) && useType.equals("admin")){ sql.append(" ,p.unit,p.treatmentItemsNum AS courseCount,p.category,p.price,p.originalPrice,p.coding"); } sql.append(" FROM user_project_item upi "); sql.append(" LEFT JOIN user_project up ON up.id = upi.userProjectId "); sql.append(" LEFT JOIN USER us ON us.id = upi.userId "); sql.append(" LEFT JOIN deduction_project dp ON upi.id = dp.userProjectItemId "); sql.append(" LEFT JOIN project p on up.goodsId = p.id "); sql.append(" WHERE 1 = 1 AND upi.userId = #{m.userId} "); sql.append(" AND ( upi.effectiveStatus = 3 OR ( upi.effectiveStatus = 1 AND upi.notUsedNum = 0 AND upi.usedNum > 0 ) "); sql.append(" OR ( upi.effectiveStatus = 1 AND upi.usedNum > 0 AND upi.notUsedNum > 0 )) "); sql.append(" AND up.isDel = 0 AND upi.isDel = 0 "); sql.append(" GROUP BY upi.id"); sql.append(" ORDER BY upi.createTime DESC, upi.goodsName DESC"); sqlSentence.setSqlSentence(sql.toString()); List> list = commonService.selectListMap(UserProjectItemMapper.class, sqlSentence); return list; } /** * 划扣参与人 - 治疗医生 **/ private Map deductionJsonEmp(String deductionSingleId) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("isDel", BaseEntity.NO); values.put("id", deductionSingleId); values.put("roleUniqueStr", "doctor"); 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 "); Map subMap = commonService.selectOneMap(DeductionJoinMapper.class, sqlSentence); return subMap; } /** * 划扣参与人 - 治疗医生 **/ private VisitRecord visitRecordInfo(String userId) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("userId", userId); sqlSentence.setSqlSentence("select * from v_visit_record where isDel = 0 and userId = #{m.userId} order by createTime desc limit 1"); VisitRecord visitRecord = commonService.selectOne(VisitRecordMapper.class, sqlSentence); return visitRecord; } }