package com.hx.phip.service.treat.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.common.dao.CommonDao; import com.hx.common.service.CommonService; import com.hx.exception.TipsException; import com.hx.guide.config.BaseConfig; import com.hx.guide.service.tools.TreatSingleLogTool; import com.hx.guide.service.tools.VGuideLogTool; import com.hx.guide.service.tools.VLatelyLogTool; import com.hx.guide.util.CreateNo; import com.hx.guide.util.TreatNoticeUtil; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.common.RoleType; import com.hx.phiappt.common.TreatSingleConstants; import com.hx.phiappt.constants.VisitOrderCommon; import com.hx.phiappt.constants.VisitOrderLogConstants; import com.hx.phiappt.constants.tool.employee.EmployeeTool; import com.hx.phiappt.dao.mapper.*; import com.hx.phiappt.model.*; import com.hx.phiappt.model.guide.VisitOrder; import com.hx.phiappt.model.treat.*; import com.hx.phiappt.vo.treat.TreatProjectModeDataVo; import com.hx.phip.common.wx.corp.WeiXinCorpMpUtil; import com.hx.phip.common.wx.corp.WeiXinMpUtil; import com.hx.phip.config.CustomParameter; import com.hx.phip.config.GlobalExceptionHandler; import com.hx.phip.service.treat.TreatV3Service; import com.hx.phip.util.api.TreatUtil; import com.hx.util.StringUtils; import com.platform.constants.PlatformPattern; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @Transactional @Service public class TreatV3ServiceImpl implements TreatV3Service { private static Logger logger = LoggerFactory.getLogger(TreatV3ServiceImpl.class); @Resource private ShopMapper shopMapper; @Resource private EmployeeMapper employeeMapper; @Resource private TreatSingleMapper treatSingleMapper; @Resource private TreatProjectMapper treatProjectMapper; @Resource private UserMapper userMapper; @Resource private CommonService commonService; @Resource private CustomParameter customParameter; @Resource private VisitOrderMapper visitOrderMapper; @Resource private CommonDao commonDao; @Resource private TreatProjectDoctorMapper treatProjectDoctorMapper; @Resource private TreatBodyPartMapper treatBodyPartMapper; @Resource private UserFamiliesRoomMapper userFamiliesRoomMapper; @Resource private FamiliesRoomMapper familiesRoomMapper; @Resource private UserBeChangeLogMapper userBeChangeLogMapper; @Resource private TreatSingleSignMapper treatSingleSignMapper; @Resource private SystemParameterMapper systemParameterMapper; /** 新增治疗通知单 */ @Override public void add(TreatSingle treatSingle, List projectList, VisitOrder visitOrder , EmployeeRole employeeRole, Integer isMicNotice, List signList) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); //判断查询操作员工信息 Employee employee = employeeMapper.selectOneByKey(treatSingle.getOperatorId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到操作人的信息[01]:" + treatSingle.getOperatorId()); } treatSingle.setOperatorName(employee.getCnName()); //创建编号 treatSingle.setTreatSingleNo(CreateNo.createGivenNo("ZLD", employee.getCnName())); //判断查询操作员工门店信息 Shop shop = shopMapper.selectOneByKey(treatSingle.getShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到操作人门店信息" + treatSingle.getShopId()); } treatSingle.setShopName(shop.getName()); //判断查询开单人 employee = employeeMapper.selectOneByKey(treatSingle.getDeveloperId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到开单人的信息" + treatSingle.getDeveloperId()); } treatSingle.setDeveloperName(employee.getCnName()); //判断查询开单人门店信息 shop = shopMapper.selectOneByKey(treatSingle.getDeveloperShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到开单人门店信息" + treatSingle.getDeveloperShopId()); } treatSingle.setDeveloperShopName(shop.getName()); //创建治疗通知单 if (treatSingleMapper.insert(treatSingle) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "新增治疗通知单失败!"); } //更改到访订单中的的是否开治疗单状态------------------------------------------------------- values.clear(); values.put("id", visitOrder.getId()); sqlSentence.setSqlSentence(" isTreatOrder = isTreatOrder + 1 where id = #{m.id} "); //如果到访单为待沟通,则创建治疗通知单后修改状态为:分配治疗 if(visitOrder.getStatus() == VisitOrderCommon.WAIT_GT){ values.put("status", VisitOrderCommon.STATUS_DISTRIBUTIVE_TREAT); sqlSentence.setSqlSentence(" status = #{m.status}, isTreatOrder = isTreatOrder + 1 where id = #{m.id} "); } if (visitOrderMapper.updateWhere(sqlSentence) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "新增治疗通知单:更新到访订单状态失败!"); } //创建治疗项目----------------------------------------------------------------------------- StringBuffer projectNameSb = new StringBuffer(); String doctorName = null; for (TreatProject project : projectList) { project.setPositionData(""); project.setTreatSingleNo(treatSingle.getTreatSingleNo()); project.setTreatSingleId(treatSingle.getId()); if (treatProjectMapper.insert(project) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "新增治疗项目失败!"); } //新增关联治疗通知单项目的医生 doctorName = addTreatProjectDoctor(project, doctorName); //新增处理部位信息 handleBodyPart(project, false); //处理项目适应症 handleTreatProjectIndication(project, true); //拼接项目名 projectNameSb.append(projectNameSb.length() > 0 ? "+" : "").append(project.getProjectName()); } //处理治疗单签名------------------------------------------------------------------------- handleSignData(signList, treatSingle.getId(), false, employeeRole); //新增治疗单日志 StringBuffer logInfo = TreatSingleLogTool.addLogInfo(treatSingle, projectList); TreatSingleLogTool.addLog(commonService, TreatSingleConstants.LOG_TYPE_CREATE, treatSingle, employeeRole, logInfo.toString()); // //所有状态下都发送治疗通知单给MIC // //发送企业微信通知MIC进行分配治疗(正式环境才发) // if (isMicNotice == BaseEntity.YES && PlatformPattern.PROD.equals(customParameter.getPlatformPattern())) { // try{ // String mpToken = WeiXinMpUtil.getAccessToken(commonService, customParameter.getCorpMpAppId()); // String corpMpToken = WeiXinCorpMpUtil.getAccessToken(commonService, customParameter.getCorpMpAppId()); // if(StringUtils.isEmpty(mpToken)){ // throw new TipsException("获取小程序Token异常!"); // } // if(StringUtils.isEmpty(corpMpToken)){ // throw new TipsException("获取企业应用小程序Token异常!"); // } // TreatUtil.sendTreatNoticeShopMic(commonService, visitOrder, TreatUtil.NOTICE_TYPE_ADD, "1000050", mpToken, corpMpToken, doctorName, projectNameSb.toString()); // }catch (Exception e){ // logger.error("新增治疗单发送企业消息失败:{}", e.getMessage()); // logger.error(GlobalExceptionHandler.getExceptionInformation(e)); // } // } } /** 编辑治疗通知单 */ @Override public void edit(TreatSingle treatSingle, List projectList, VisitOrder visitOrder , EmployeeRole employeeRole, TreatSingle updateTreat, List signList) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); StringBuffer sql = new StringBuffer(); //判断查询操作员工信息 Employee employee; // employee = employeeMapper.selectOneByKey(treatSingle.getOperatorId()); // if (employee == null) { // throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到操作人的信息[02]:" + treatSingle.getOperatorId()); // } // values.put("operatorName", employee.getCnName()); // values.put("operatorId", employee.getId()); //判断查询操作员工门店信息 Shop shop = shopMapper.selectOneByKey(treatSingle.getShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到操作人门店信息" + treatSingle.getShopId()); } values.put("shopName", shop.getName()); values.put("shopId", shop.getId()); //判断查询开单人 employee = employeeMapper.selectOneByKey(treatSingle.getDeveloperId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到开单人的信息" + treatSingle.getDeveloperId()); } values.put("developerName", employee.getCnName()); values.put("developerId", employee.getId()); //判断查询开单人门店信息 shop = shopMapper.selectOneByKey(treatSingle.getDeveloperShopId()); if (shop == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "未找到开单人门店信息" + treatSingle.getDeveloperShopId()); } values.put("developerShopName", shop.getName()); values.put("developerShopId", shop.getId()); //更改到访订单中的的是否开治疗单状态 sql.delete(0, sql.length()); if(visitOrder.getIsTreatOrder() == BaseEntity.NO){ sql.append(",isTreatOrder = isTreatOrder + 1 "); } if(visitOrder.getStatus() == VisitOrderCommon.WAIT_GT){ sql.append(",status = #{m.status} "); values.put("status", VisitOrderCommon.STATUS_DISTRIBUTIVE_TREAT); } if(sql.length() > 0){ values.put("id", visitOrder.getId()); sql.append(" , editTime = now() where id = #{m.id} "); sqlSentence.setSqlSentence( sql.toString().replaceFirst(",", "")); if (visitOrderMapper.updateWhere(sqlSentence) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "修改治疗通知单:更新到访订单状态失败!"); } } //修改治疗通知单 values.put("remarkInfo", treatSingle.getRemarkInfo()); values.put("id", treatSingle.getId()); values.put("status", treatSingle.getStatus()); values.put("orderClassify", treatSingle.getOrderClassify()); values.put("isWillPhoto", treatSingle.getIsWillPhoto()); values.put("allergyInfo", treatSingle.getAllergyInfo()); values.put("isFirstFm", treatSingle.getIsFirstFm()); values.put("isRd", treatSingle.getIsRd()); values.put("isUserSign", treatSingle.getIsUserSign()); sql.delete(0,sql.length()); //operatorName = #{m.operatorName},operatorId = #{m.operatorId}, sql.append(" developerName = #{m.developerName},developerId = #{m.developerId},remarkInfo = #{m.remarkInfo} "); sql.append(" ,developerShopName = #{m.developerShopName},developerShopId = #{m.developerShopId} "); sql.append(" ,shopName = #{m.shopName},shopId = #{m.shopId},status = #{m.status} "); sql.append(" , orderClassify = #{m.orderClassify}, isWillPhoto = #{m.isWillPhoto}, allergyInfo = #{m.allergyInfo} "); sql.append(" , isFirstFm = #{m.isFirstFm}, isRd = #{m.isRd}, isUserSign = #{m.isUserSign} "); sql.append(" where id = #{m.id} "); sqlSentence.setSqlSentence(sql.toString()); if (treatSingleMapper.updateWhere(sqlSentence) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "修改失败!"); } //获取编辑治疗单信息变化日志信息 StringBuffer logInfo = TreatSingleLogTool.editLogInfo(treatSingle, updateTreat); //出来治疗通知单项目信息 ----------------------------------------------- Map pMap = handleEditProject(treatSingle, projectList, logInfo); //处理治疗单签名------------------------------------------------------------------------- handleSignData(signList, treatSingle.getId(), true, employeeRole); //新增治疗单日志 TreatSingleLogTool.addLog(commonService, TreatSingleConstants.LOG_TYPE_EDIT, treatSingle, employeeRole, logInfo.toString()); //----------------------------------------------------------------------- //发送企业微信修改之前的医生、护士、MIC,药房企业微信通知 //当状态是已确认或者待确认时 需要通知(正式环境才发) if ((treatSingle.getStatus()==TreatSingleConstants.STATUS_WAIT_CONFIRM || treatSingle.getStatus() == TreatSingleConstants.STATUS_CONFIRM ) && PlatformPattern.PROD.equals(customParameter.getPlatformPattern())) { try{ String mpToken = WeiXinMpUtil.getAccessToken(commonService, customParameter.getCorpMpAppId()); String corpMpToken = WeiXinCorpMpUtil.getAccessToken(commonService, customParameter.getCorpMpAppId()); if(StringUtils.isEmpty(mpToken)){ throw new TipsException("获取小程序Token异常!"); } if(StringUtils.isEmpty(corpMpToken)){ throw new TipsException("获取企业应用小程序Token异常!"); } TreatUtil.editTreatNotice2(commonService, visitOrder, treatSingle , "1000050", corpMpToken, mpToken); }catch (Exception e){ logger.error("编辑治疗单发送企业消息失败:{}", e.getMessage()); logger.error(GlobalExceptionHandler.getExceptionInformation(e)); } } } /** 作废治疗通知单 */ public void invalidTreat(TreatSingle treatSingle, VisitOrder visitOrder, EmployeeRole employeeRole) { User user = commonDao.selectOneByKey(UserMapper.class, visitOrder.getUserId()); if(user == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到客户信息!"); } Shop shop = commonDao.selectOneByKey(ShopMapper.class, visitOrder.getShopId()); if(shop == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS, "找不到门店信息!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("treatSingleId", treatSingle.getId()); //查询治疗通知单项目列表 sqlSentence.setSqlSentence(" select id, projectName, hisId from treat_project where isDel = 0 and treatSingleId = #{m.treatSingleId} "); List> tpList = treatProjectMapper.selectListMap(sqlSentence); StringBuffer sb = new StringBuffer(); if(tpList != null && tpList.size() > 0){ sqlSentence.setSqlSentence("SELECT e.id, e.cnName, e.userId, d.type from treat_project_doctor d left join employee e on e.id = d.commonId where d.isDel=0 and d.treatSingleId = #{m.treatSingleId} and d.treatProjectId = #{m.treatProjectId} "); List> treatProjectDoctors ; for(Map m : tpList) { sb.append(m.get("projectName")).append(";"); //查询项目对应多个医生或护士 values.put("treatProjectId", m.get("id")); treatProjectDoctors = treatProjectDoctorMapper.selectListMap(sqlSentence); if(treatProjectDoctors != null && treatProjectDoctors.size() > 0){ m.put("eList", treatProjectDoctors); } } //对应作废处理关联划扣数据逻辑 invalidTreatUpdateDeductData(tpList); } //删除治疗单 values.put("status", TreatSingleConstants.STATUS_CANCEL); sqlSentence.setSqlSentence(" status = #{m.status}, isDel = 1, editTime = now() where id = #{m.treatSingleId} "); if (treatSingleMapper.updateWhere(sqlSentence)!= 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "作废治疗通知单失败!"); } // sqlSentence.setSqlSentence(" isDel = 1 where treatSingleId = #{m.treatSingleId} and isDel = 0 "); // //删除治疗单项目等信息 // treatProjectMapper.updateWhere(sqlSentence); // //删除治疗单医生信息 // treatProjectDoctorMapper.updateWhere(sqlSentence); // //删除治疗通知单项目部分信息 // treatBodyPartMapper.updateWhere(sqlSentence); values.put("id", visitOrder.getId()); sqlSentence.sqlUpdate(" isTreatOrder = isTreatOrder - 1 WHERE id = #{m.id} ", values); if (visitOrderMapper.updateWhere(sqlSentence) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "修改到访订单信息失败!"); } Integer oldStatus = visitOrder.getStatus(); Integer newStatus = visitOrder.getStatus(); //新增日志 VLatelyLogTool.addV3(VisitOrderLogConstants.LOG_TYPE_DEL_TREAT_SINGLE, oldStatus, newStatus,"作废治疗通知单", "作废治疗通知单(导医)",employeeRole,visitOrder.getId(),visitOrder.getShopId(),visitOrder.getUserId(), commonDao); VGuideLogTool.addV3(VisitOrderLogConstants.LOG_TYPE_DEL_TREAT_SINGLE, oldStatus, newStatus, visitOrder.getPreStartTime(),new Date(),0,"作废治疗通知单(导医)",employeeRole,visitOrder.getId(),visitOrder.getShopId(),visitOrder.getUserId(),commonDao); //新增治疗单日志 TreatSingleLogTool.addLog(commonService, TreatSingleConstants.LOG_TYPE_CANCEL, treatSingle, employeeRole, null); try{ BaseConfig baseConfig = new BaseConfig(); baseConfig.setCorpId(customParameter.getCorpMpAppId()); baseConfig.setCorpMpSecret(customParameter.getCorpMpSecret()); //发送通知 TreatNoticeUtil.treatNoticeCancelSendMsg(visitOrder, user, shop, sb.toString(),tpList, baseConfig, commonDao); }catch (TipsException|PlatTipsException e){ logger.error("作废治疗通知单发送企业通知失败:{}", e.getMessage()); }catch (Exception e){ logger.error("作废治疗通知单发送企业通知失败:{}", GlobalExceptionHandler.getExceptionInformation(e)); } } /** 更新治疗单签名 */ @Override public void updateSign(TreatSingle treatSingle, List signList, EmployeeRole employeeRole) { SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("treatSingleId", treatSingle.getId()); StringBuffer logInfo = new StringBuffer(); logInfo.append("更新签名类型:"); Integer isUseSign = treatSingle.getIsUserSign(); for(TreatSingleSign sign : signList){ //类型 values.put("signPerType", sign.getSignPerType()); //删除旧的 sqlSentence.setSqlSentence(" isDel = 1, editTime = now() where isDel = 0 and treatSingleId = #{m.treatSingleId} and signPerType = #{m.signPerType} "); commonService.updateWhere(TreatSingleSignMapper.class, sqlSentence); //新增 sign.setTreatSingleId(treatSingle.getId()); sign.setOpId(employeeRole.getEmployeeId()); sign.setOpMan(employeeRole.getCnName()); sign.setOpRoleId(employeeRole.getId()); sign.setOpShopId(employeeRole.getShopId()); sign.setOpRoleStr(employeeRole.getRoleUniqueStr()); if(commonService.insert(TreatSingleSignMapper.class, sign) != 1){ throw new TipsException("新增治疗单签名失败!"); } //判断用户是否签名 if(TreatSingleSign.SIGN_PER_TYPE_USER.equals(sign.getSignPerType())){ isUseSign = BaseEntity.YES; } //拼接日志 logInfo.append(TreatSingleSign.signPerTypeCh(sign.getSignPerType())).append("、"); } logInfo.delete(logInfo.length() - 1, logInfo.length()); //更新治疗单是否用户已签名 if(treatSingle.getIsUserSign() == BaseEntity.NO && isUseSign == BaseEntity.YES){ values.put("id", treatSingle.getId()); sqlSentence.setSqlSentence(" isUserSign = 1 where id = #{m.id} "); if(treatSingleMapper.updateWhere(sqlSentence) != 1){ throw new TipsException("更新治疗单签名失败!"); } } //新增治疗单日志 TreatSingleLogTool.addLog(commonService, TreatSingleConstants.LOG_TYPE_EDIT_SIGN, treatSingle, employeeRole, logInfo.toString()); } /**处理用户科室关系*/ @Override public void doctorRoomHandler(String treatSingleId) { logger.info("-----新增治疗单,多线程处理用户科室关系----"); TreatSingle treatSingle = treatSingleMapper.selectOneByKey(treatSingleId); if (treatSingle == null){ logger.info("新增治疗单处理科室关系,查询治疗单失败"+treatSingleId); return; } if (StringUtils.isEmpty(treatSingle.getUserId())){ logger.info("新增治疗单处理科室关系,用户id为空"); return; } User user = userMapper.selectOneByKey(treatSingle.getUserId()); if (user == null){ logger.info("新增治疗单处理科室关系,查询用户失败"+treatSingle.getUserId()); return; } SqlSentence sqlSentence = new SqlSentence(); Map sqlMap = new HashMap<>(); sqlMap.put("isDel",BaseEntity.NO); sqlMap.put("userId",treatSingle.getUserId()); sqlMap.put("treatSingleId",treatSingleId); sqlMap.put("type","doctor"); sqlSentence.sqlSentence("SELECT * FROM user_families_room WHERE isDel = #{m.isDel} " + " AND userId = #{m.userId} AND familiesRoomName IN ('注射科','皮肤科') ",sqlMap); List userFamiliesRoomList = userFamiliesRoomMapper.selectList(sqlSentence); Map dataMap = new HashMap<>(); if (userFamiliesRoomList != null && userFamiliesRoomList.size() > 0){ for (UserFamiliesRoom userFamiliesRoom : userFamiliesRoomList) { dataMap.put(userFamiliesRoom.getFamiliesRoomId(),userFamiliesRoom); } } sqlSentence.sqlSentence("SELECT * FROM treat_project_doctor WHERE isDel = #{m.isDel} " + " AND treatSingleId = #{m.treatSingleId} AND type = #{m.type} ",sqlMap); List treatProjectDoctorList = treatProjectDoctorMapper.selectList(sqlSentence); if (treatProjectDoctorList != null && treatProjectDoctorList.size() > 0){ //去重map(科室标识,数据) List checkList = new ArrayList<>(); for (TreatProjectDoctor treatProjectDoctor : treatProjectDoctorList) { if (StringUtils.isEmpty(treatProjectDoctor.getDepartmentId())){ continue; } if (checkList.contains(treatProjectDoctor.getDepartmentId())){ logger.info("新增治疗单处理科室关系,重复的科室关系,跳过处理:"+treatProjectDoctor.getDepartmentId()); continue; } //查询科室 UserFamiliesRoom mapData = dataMap.get(treatProjectDoctor.getDepartmentId()); if (mapData != null){ logger.info("新增治疗单处理科室关系,已存在科室关系,跳过处理:"+mapData.getFamiliesRoomName()); continue; } logger.info("新增治疗单处理科室关系,治疗单医生数据:"+JSON.toJSONString(treatProjectDoctor)); FamiliesRoom familiesRoom = familiesRoomMapper.selectOneByKey(treatProjectDoctor.getDepartmentId()); //找不到科室信息不处理 if (familiesRoom == null){ logger.info("新增治疗单处理科室关系,查询科室失败,跳过处理:"+treatProjectDoctor.getDepartmentId()); continue; } //不是皮肤科和注射科不处理 if (!"注射科".equals(familiesRoom.getFamiliesRoomName()) && !"皮肤科".equals(familiesRoom.getFamiliesRoomName())){ logger.info("新增治疗单处理科室关系,非注射科和皮肤科,跳过处理:"+familiesRoom.getFamiliesRoomName()); continue; } UserFamiliesRoom userFamiliesRoom = new UserFamiliesRoom(); userFamiliesRoom.setUserId(treatSingle.getUserId()); userFamiliesRoom.setFamiliesRoomId(treatProjectDoctor.getDepartmentId()); userFamiliesRoom.setFamiliesRoomName(familiesRoom.getFamiliesRoomName()); userFamiliesRoom.setDoctorId(treatProjectDoctor.getCommonId()); Employee employee = employeeMapper.selectOneByKey(treatProjectDoctor.getCommonId()); if (employee != null){ userFamiliesRoom.setDoctorName(employee.getCnName()); } userFamiliesRoom.setIsDefault(0); if (userFamiliesRoomMapper.insert(userFamiliesRoom) != 1){ throw new TipsException("新增失败1!"+ JSON.toJSONString(userFamiliesRoom)); } //新增修改记录 UserBeChangeLog userBeChangeLog = new UserBeChangeLog(); userBeChangeLog.setUserId(user.getId()); userBeChangeLog.setUserName(user.getName()); userBeChangeLog.setUserLevel(user.getUserLevel()); userBeChangeLog.setUserType(user.getUserType()); userBeChangeLog.setUserStatus(user.getUserStatus()); userBeChangeLog.setHisCorpUserId(user.getHisCorpUserId()); userBeChangeLog.setBelongShopId(user.getShopId()); userBeChangeLog.setMemberNO(user.getMemberNO()); userBeChangeLog.setCIQ(user.getCIQ()); userBeChangeLog.setChangeType(UserBeChangeLog.CHANGE_TYPE_ROOM_DOCTOR); userBeChangeLog.setCommonId(treatProjectDoctor.getCommonId()); if (employee != null){ userBeChangeLog.setCommonValue(employee.getCnName()); } userBeChangeLog.setRoomId(treatProjectDoctor.getDepartmentId()); userBeChangeLog.setRoomName(familiesRoom.getFamiliesRoomName()); userBeChangeLog.setRemark("治疗单:"+treatSingle.getTreatSingleNo()); if (userBeChangeLogMapper.insert(userBeChangeLog) != 1){ throw new TipsException("新增失败2!"+ JSON.toJSONString(userBeChangeLog)); } checkList.add(treatProjectDoctor.getDepartmentId()); } } } /** 处理治疗单模式数据 */ public void handleModeData(List treatProjectList){ //先过滤出打法不为空的治疗单项目:项目名,打法 Map dataMap = treatProjectList.stream().filter(s->StringUtils.noNull(s.getItemMode())).collect(Collectors.toMap(TreatProject::getProjectName, TreatProject::getItemMode)); if(dataMap == null || dataMap.size() < 1){ return; } SystemParameter sp = systemParameterMapper.selectOneByName(SystemParameter.KEY_ZLD_PROJECT_MODE_DATA); List modeDataVoList = null; if(sp != null && StringUtils.isEmpty(sp.getParamValue())){ modeDataVoList = JSONArray.parseArray(sp.getParamValue(), TreatProjectModeDataVo.class); } if(modeDataVoList == null){ modeDataVoList = new ArrayList<>(); } TreatProjectModeDataVo modeDataVo; for(Map.Entry entry : dataMap.entrySet()){ //没有时则 if(modeDataVoList.size() == 0){ modeDataVoList.add(new TreatProjectModeDataVo(entry.getKey(), entry.getValue())); continue; } for(int i = 0; i < modeDataVoList.size(); i++){ modeDataVo = modeDataVoList.get(i); //有相同的项目名数据 if(modeDataVo.getProjectName().equals(entry.getKey())){ //然后对应的打法不存在 if(!modeDataVo.getModeList().contains(entry.getValue())){ modeDataVo.getModeList().add(entry.getValue()); continue; } } //最后一个时表示没匹配到,则新增 if(i == modeDataVoList.size() - 1){ modeDataVoList.add(new TreatProjectModeDataVo(entry.getKey(), entry.getValue())); } } } if(modeDataVoList.size() < 1){ return; } JSONArray arr = JSONArray.parseArray(JSONObject.toJSONString(modeDataVoList)); if(sp == null){ sp = new SystemParameter(); sp.setParamName(SystemParameter.KEY_ZLD_PROJECT_MODE_DATA); sp.setParamValue(arr.toString()); systemParameterMapper.insert(sp); }else{ sp.setParamValue(arr.toString()); systemParameterMapper.updateInfoById(sp); } } /////////////////////////////////////////////////////////////////////////////// //处理编辑治疗通知单时项目变动逻辑 public Map handleEditProject(TreatSingle treatSingle, List projectList, StringBuffer logInfo){ SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("id", treatSingle.getId()); //逻辑删除原治疗通知单人员 sqlSentence.setSqlSentence("isDel = 1 where treatSingleId = #{m.id} and isDel = 0 "); treatProjectDoctorMapper.updateWhere(sqlSentence); //查询原治疗通知单项目列表 sqlSentence.setSqlSentence(" select * from treat_project where isDel = 0 and treatSingleId = #{m.id} "); List tpList = treatProjectMapper.selectList(sqlSentence); Map tpMap = new HashMap<>(); if(tpList != null && tpList.size() >= 0){ tpMap = tpList.stream().collect(Collectors.toMap(TreatProject::getId, Function.identity())); } //创建新的治疗项目 StringBuffer projectNameSb = new StringBuffer(); String doctorName = null; TreatProject oldTp = null; for (TreatProject treatProject : projectList) { treatProject.setTreatSingleId(treatSingle.getId()); oldTp = tpMap.get(treatProject.getId()); //原项目 if(oldTp != null){ //更新 if (treatProjectMapper.updateEditInfo(treatProject) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "修改治疗项目数量失败!"); } if(oldTp.getNum() != treatProject.getNum()){ logInfo.append("修改【").append(oldTp.getProjectName()).append(" x ").append(treatProject.getNum()).append("】").append(";"); } //清除更新后的项目 tpMap.remove(treatProject.getId()); }else{ //新项目 treatProject.setTreatSingleNo(treatSingle.getTreatSingleNo()); if (treatProjectMapper.insert(treatProject) != 1) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "修改时新增治疗项目失败!"); } //添加日志内容 logInfo.append("新增【").append(treatProject.getProjectName()).append(" x ").append(treatProject.getNum()).append("】").append(";"); } //新增项目人员 doctorName = addTreatProjectDoctor(treatProject, doctorName); //编辑处理部位信息 handleBodyPart(treatProject, true); //处理项目适应症 handleTreatProjectIndication(treatProject, true); //拼接项目名 projectNameSb.append(projectNameSb.length() > 0 ? "+" : "").append(treatProject.getProjectName()); } //删除项目 values.clear(); List> deductList = null; for(Map.Entry tp : tpMap.entrySet()){ oldTp = tp.getValue(); values.put("treatProjectId", oldTp.getId()); //先查询划扣参数 sqlSentence.setSqlSentence(" select dp.id as deductionProjectId, ds.id as deductionSingleId, ds.treatSingleId from deduction_project dp left join deduction_single ds on ds.id = dp.deductionSingleId where dp.treatProjectId = #{m.treatProjectId} "); deductList = commonDao.selectListMap(DeductionProjectMapper.class, sqlSentence); if(deductList != null && deductList.size() > 0){ //清空划扣记录的关联 for(Map deduct : deductList){ //划扣项目 if(deduct.containsKey("deductionProjectId") && !StringUtils.isEmpty(deduct.get("deductionProjectId").toString())){ values.put("deductionProjectId", deduct.get("deductionProjectId")); sqlSentence.setSqlSentence(" treatProjectId = null where id = #{m.deductionProjectId} "); if(commonDao.updateWhere(DeductionProjectMapper.class, sqlSentence) != 1){ throw new TipsException("编辑治疗通知单:清除划扣项目关联id失败!" + deduct.get("deductionProjectId")); } } //划扣记录 if(deduct.containsKey("deductionSingleId") && !StringUtils.isEmpty(deduct.get("deductionSingleId").toString())){ values.put("deductionSingleId", deduct.get("deductionSingleId")); sqlSentence.setSqlSentence(" treatSingleId = null where id = #{m.deductionSingleId} "); if(commonDao.updateWhere(DeductionSingleMapper.class, sqlSentence) != 1){ // throw new TipsException("编辑治疗通知单:清除划扣记录关联id失败!"); } } } } //删除治疗通知单项目 sqlSentence.setSqlSentence(" isDel = 1 where id = #{m.treatProjectId} "); if(treatProjectMapper.updateWhere(sqlSentence) != 1){ throw new TipsException("编辑治疗通知单:更新删除治疗通知单项目失败!" + oldTp.getId()); } //添加日志内容 logInfo.append("将【").append(oldTp.getProjectName()).append("】项目删除"); } //返回要使用参数 values.clear(); values.put("projectName", projectNameSb.toString()); values.put("doctorName", doctorName); return values; } //新增治疗通知单项目人员 public String addTreatProjectDoctor(TreatProject treatProject, String doctorName) { // 如果项目人员为空 List treatProjectDoctorList = treatProject.getTreatProjectDoctorList(); if (treatProjectDoctorList == null || treatProjectDoctorList.size() < 1) { return doctorName; } // if (treatProjectDoctorList == null || treatProjectDoctorList.size() < 1) { // //如果新对象字段为空,走旧字段逻辑 // // 如果项目人员为空 // List doctorIds = treatProject.getDoctorIds(); // if(doctorIds == null || doctorIds.size() < 1){ // return null; // } // // //获取人员id数组 // TreatProjectDoctor treatProjectDoctor; // for(String doctorId : doctorIds){ // treatProjectDoctor = new TreatProjectDoctor(); // treatProjectDoctor.setType(RoleType.UNIQUE_STR_DOCTOR); // treatProjectDoctor.setTreatSingleId(treatProject.getTreatSingleId()); // treatProjectDoctor.setTreatProjectHisId(treatProject.getHisId()); // treatProjectDoctor.setTreatProjectId(treatProject.getId()); // treatProjectDoctor.setCommonId(doctorId); // treatProjectDoctorMapper.insert(treatProjectDoctor); // } // return null; // } // 获取人员对象 for (TreatProjectDoctor treatProjectDoctor : treatProjectDoctorList) { //如果医生名称为空,则查询获取一个 if(StringUtils.isEmpty(doctorName)){ doctorName = EmployeeTool.getCnName(treatProjectDoctor.getCommonId(), commonService); } treatProjectDoctor.setType(RoleType.UNIQUE_STR_DOCTOR); treatProjectDoctor.setTreatSingleId(treatProject.getTreatSingleId()); treatProjectDoctor.setTreatProjectHisId(treatProject.getHisId()); treatProjectDoctor.setTreatProjectId(treatProject.getId()); // 主诊医生信息处理 if (!StringUtils.isEmpty(treatProjectDoctor.getPrimaryDoctorId())) { Employee employee = employeeMapper.selectOneByKey(treatProjectDoctor.getPrimaryDoctorId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "主诊医生信息不存在!"); } } // 治疗医生处理 if (!StringUtils.isEmpty(treatProjectDoctor.getCommonId())) { Employee employee = employeeMapper.selectOneByKey(treatProjectDoctor.getCommonId()); if (employee == null) { throw new PlatTipsException(PlatformCode.ERROR_TIPS, "治疗医生信息不存在!"); } } treatProjectDoctorMapper.insert(treatProjectDoctor); } return doctorName; } //处理项目选择部位数据 public void handleBodyPart(TreatProject treatProject, boolean isEdit){ List bpList = treatProject.getBpList(); if(bpList == null ){ bpList = new ArrayList<>(); } Map oldMap = new HashMap<>(); //编辑时,查询原治疗单项目部分信息 if(isEdit){ List oldList = treatBodyPartMapper.selectListByTreatProjectId(treatProject.getId()); if(oldList != null && oldList.size() > 0){ oldMap = oldList.stream().collect(Collectors.toMap(TreatBodyPart::getBodyPartItemId, TreatBodyPart::getId)); } } //遍历处理 for(TreatBodyPart treatBodyPart : bpList){ if(oldMap.containsKey(treatBodyPart.getBodyPartItemId())){ //更新其他信息 treatBodyPart.setId(oldMap.get(treatBodyPart.getBodyPartItemId())); treatBodyPartMapper.updateOtherInfo(treatBodyPart); oldMap.remove(treatBodyPart.getBodyPartItemId()); continue; } //新增 treatBodyPart.setTreatSingleId(treatProject.getTreatSingleId()); treatBodyPart.setTreatProjectId(treatProject.getId()); if(treatBodyPartMapper.insert(treatBodyPart) != 1){ throw new TipsException("新增治疗单项目部位信息失败!"); } } //删除 if(oldMap.size() > 0){ for(Map.Entry entry : oldMap.entrySet()){ treatBodyPartMapper.updateDelById(entry.getValue()); } } } //处理项目适应症数据 public void handleTreatProjectIndication(TreatProject treatProject, boolean isEdit){ List indicationList = treatProject.getIndicationList(); if(indicationList == null){ indicationList = new ArrayList<>(); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); Map oldMap = new HashMap<>(); //编辑时,查询原治疗单项目部分信息 if(isEdit){ values.put("treatProjectId", treatProject.getId()); sqlSentence.setSqlSentence(" select * from treat_project_indication where isDel = 0 and treatProjectId = #{m.treatProjectId} "); List oldList = commonService.selectList(TreatProjectIndicationMapper.class, sqlSentence); if(oldList != null && oldList.size() > 0){ oldMap = oldList.stream().collect(Collectors.toMap(TreatProjectIndication::getIndicationId, TreatProjectIndication::getId)); } } //遍历处理 for(TreatProjectIndication treatProjectIndication : indicationList){ if(oldMap.containsKey(treatProjectIndication.getIndicationId())){ oldMap.remove(treatProjectIndication.getIndicationId()); continue; } //新增 treatProjectIndication.setTreatSingleId(treatProject.getTreatSingleId()); treatProjectIndication.setTreatProjectId(treatProject.getId()); if(commonService.insert(TreatProjectIndicationMapper.class,treatProjectIndication) != 1){ throw new TipsException("新增治疗单项目适应症失败!"); } } //删除 if(oldMap.size() > 0){ values.clear(); sqlSentence.setSqlSentence(" isDel = 1, editTime = now() where id = #{m.id} "); for(Map.Entry entry : oldMap.entrySet()){ values.put("id", entry.getValue()); commonService.updateWhere(TreatProjectIndicationMapper.class, sqlSentence); } } } //处理治疗单签名数据 public void handleSignData(List signList, String treatSingleId, boolean isEdit, EmployeeRole employeeRole){ if(signList == null){ signList = new ArrayList<>(); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); //存储删除的信息 Map delMap = new HashMap<>(); //判断编辑时才查旧数据出来匹配删除 if(isEdit){ values.put("treatSingleId", treatSingleId); sqlSentence.setSqlSentence(" select * from treat_single_sign where isDel = 0 and treatSingleId = #{m.treatSingleId} "); List oldList = commonService.selectList(TreatSingleSignMapper.class, sqlSentence); if(oldList != null && oldList.size() > 0){ delMap = oldList.stream().collect(Collectors.toMap(TreatSingleSign::getSignPerType, Function.identity())); } } TreatSingleSign oldSign; sqlSentence.setSqlSentence(" signPerName = #{m.signPerName}, signImg = #{m.signImg}, editTime = now() where id = #{m.id} "); //遍历 for(TreatSingleSign sign : signList){ if(delMap.containsKey(sign.getSignPerType())){ oldSign = delMap.get(sign.getSignPerType()); //判断更新 if(!sign.getSignImg().equals(oldSign.getSignImg())){ sign.setId(oldSign.getId()); if(treatSingleSignMapper.updateInfo(sign) != 1){ throw new TipsException("更新治疗单签名失败!"); } } delMap.remove(sign.getSignPerType()); }else{ //新增 sign.setTreatSingleId(treatSingleId); sign.setOpId(employeeRole.getEmployeeId()); sign.setOpMan(employeeRole.getCnName()); sign.setOpRoleId(employeeRole.getId()); sign.setOpShopId(employeeRole.getShopId()); sign.setOpRoleStr(employeeRole.getRoleUniqueStr()); if(commonService.insert(TreatSingleSignMapper.class, sign) != 1){ throw new TipsException("新增治疗单签名失败!"); } } } //删除 if(delMap.size() > 0){ values.clear(); sqlSentence.setSqlSentence(" isDel = 1, editTime = now() where id = #{m.id} "); for(Map.Entry entry : delMap.entrySet()){ values.put("id", entry.getValue().getId()); if(commonService.updateWhere(TreatSingleSignMapper.class, sqlSentence) != 1){ throw new TipsException("删除治疗单签名失败!"); } } } } //作废处理关联划扣数据逻辑 private void invalidTreatUpdateDeductData(List> tpList){ SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); List> deductList = null; for(Map tp : tpList){ values.put("treatProjectId", tp.get("id")); //先查询划扣参数 sqlSentence.setSqlSentence(" select dp.id as deductionProjectId, ds.id as deductionSingleId, ds.treatSingleId from deduction_project dp left join deduction_single ds on ds.id = dp.deductionSingleId where dp.treatProjectId = #{m.treatProjectId} "); deductList = commonDao.selectListMap(DeductionProjectMapper.class, sqlSentence); if(deductList != null && deductList.size() > 0){ //清空划扣记录的关联 for(Map deduct : deductList){ //划扣项目 if(deduct.containsKey("deductionProjectId") && !StringUtils.isEmpty(deduct.get("deductionProjectId").toString())){ values.put("deductionProjectId", deduct.get("deductionProjectId")); sqlSentence.setSqlSentence(" treatProjectId = null where id = #{m.deductionProjectId} "); if(commonDao.updateWhere(DeductionProjectMapper.class, sqlSentence) != 1){ throw new PlatTipsException(PlatformCode.ERROR_TIPS, "清除划扣项目关联id失败!" + deduct.get("deductionProjectId")); } } //划扣记录 if(deduct.containsKey("deductionSingleId") && !StringUtils.isEmpty(deduct.get("deductionSingleId").toString())){ values.put("deductionSingleId", deduct.get("deductionSingleId")); sqlSentence.setSqlSentence(" treatSingleId = null where id = #{m.deductionSingleId} "); if(commonDao.updateWhere(com.hx.phiappt.dao.mapper.DeductionSingleMapper.class, sqlSentence) != 1){ // throw new TipsException("清除划扣记录关联id失败!"); } } } } } } }