package com.hx.phip.controller.micro; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hx.common.BaseController; import com.hx.mybatisTool.SqlSentence; import com.hx.phiappt.common.BaseClassifyConstants; import com.hx.phiappt.common.enums.MeiJiResourceFileEnum; import com.hx.phiappt.constants.tool.comparePhoto.ComparePhotoUtil; import com.hx.phiappt.constants.tool.employee.EmployeeTool; import com.hx.phiappt.constants.tool.meiji.MeiJiDataTool; import com.hx.phiappt.constants.tool.shop.ShopTool; import com.hx.phiappt.dao.mapper.*; import com.hx.phiappt.model.BaseEntity; import com.hx.phiappt.model.Employee; import com.hx.phiappt.model.User; import com.hx.phiappt.model.indication.Indication; import com.hx.phiappt.model.indication.IndicationType; import com.hx.phiappt.model.micro.MicroPlan; import com.hx.phiappt.model.micro.MicroPlanIndication; import com.hx.phiappt.model.micro.MicroPlanItem; import com.hx.phiappt.model.micro.MicroRecord; import com.hx.phiappt.model.questionnaire.QuestionInvestigate; import com.hx.phiappt.model.treatPlan.TreatPlanItem; import com.hx.phiappt.vo.base.BaseClassifyReqVo; import com.hx.phip.common.MicroRecordConstants; import com.hx.phip.service.EmployeeRoleService; import com.hx.phip.service.mirco.MircoRecordService; import com.hx.resultTool.Result; import com.hx.util.DateUtil; import com.hx.util.MapUtil; import com.hx.util.StringUtils; import com.hz.crm.dto.GoodsSkuDto; import com.hz.crm.feign.FGoodsSkuService; import com.hz.his.dto.micro.MicroRecordDto; import com.hz.his.feign.service.phis.SFileService; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * 微整规划记录 * @USER: fhx * @DATE: 2023/10/31 **/ @Slf4j @RestController @RequestMapping("/micro/record") public class MicroRecordController extends BaseController { @Resource private EmployeeRoleService employeeRoleService; @Resource private MircoRecordService mircoRecordService; @Resource private SFileService sFileService; @Resource private FGoodsSkuService fGoodsSkuService; /** 微整记录列表 */ @RequestMapping("/list") public Result list(@RequestBody MicroRecordDto dto){ if(StringUtils.isEmpty(dto.getUserId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户标识不能为空!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("userId", dto.getUserId()); StringBuffer sql = new StringBuffer(); sql.append(" select id, userName, opName, createTime, editTime,isView,isDraft ") .append(" from micro_record where isDel = 0 and userId = #{m.userId} "); if(StringUtils.noNull(dto.getStartTime())){ values.put("startTime", DateUtil.dayToStart(DateUtil.parseString_2(dto.getStartTime()))); sql.append(" and createTime >= #{m.startTime} "); } if(StringUtils.noNull(dto.getEndTime())){ values.put("endTime", DateUtil.dayToEnd(DateUtil.parseString_2(dto.getEndTime()))); sql.append(" and createTime <= #{m.endTime} "); } // 是否草稿 if (dto.getIsDraft() != null){ values.put("isDraft", dto.getIsDraft()); sql.append(" and isDraft <= #{m.isDraft} "); } sqlSentence.setSqlSentence(sql.toString()); PageHelper.startPage(dto.getPageNum(), dto.getPageSize(), " createTime desc "); List list = commonService.selectList(MicroRecordMapper.class, sqlSentence); PageInfo pageInfo = new PageInfo(list); Map data = new HashMap<>(); data.put("list", pageInfo.getList()); data.put("total", pageInfo.getTotal()); data.put("pages", pageInfo.getPages()); data.put("pageNum", pageInfo.getPageNum()); data.put("pageSize", pageInfo.getPageSize()); data.put("isLastPage", pageInfo.isIsLastPage()); return Result.success(data); } /** 记录详情 */ @RequestMapping("/details") public Result details(@RequestBody MicroRecordDto dto){ if(StringUtils.isEmpty(dto.getId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划记录标识不能为空!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("microRecordId", dto.getId()); sqlSentence.setSqlSentence(" select id, userId, userName, createTime,isDraft from micro_record where id = #{m.microRecordId} "); Map infoMap = commonService.selectOneMap(MicroRecordMapper.class, sqlSentence); if(infoMap == null || infoMap.size() < 1){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到微整规划记录信息!"); } //查询微整规划 sqlSentence.setSqlSentence(" select id, mjSkinReportId, recommend, sortNum from micro_plan where isDel = 0 and microRecordId = #{m.microRecordId} order by sortNum asc "); List> planList = commonService.selectListMap(MicroPlanMapper.class, sqlSentence); Map mjData = null; if(planList != null && planList.size() > 0){ StringBuffer sql = new StringBuffer(); sql.append(" select mpi.indicationId, i.name as indName, mpi.typeJson, mpi.sortNum, mpi.otherInd ") .append(" , mpi.degreeTypeId, bc.name as degreeType ") .append(" from micro_plan_indication mpi ") .append(" left join indication i on i.id = mpi.indicationId ") .append(" left join base_classify bc on bc.id = mpi.degreeTypeId ") .append(" where mpi.isDel = 0 and mpi.microPlanId = #{m.microPlanId} ") .append(" order by mpi.sortNum asc "); String indSql = sql.toString(); sql.setLength(0); sql.append(" select i.commonId, i.commonType, i.commonName, i.sortNum, i.timeTypeId, bc.name as timeType ") .append(" from micro_plan_item i ") .append(" join base_classify bc on bc.id = i.timeTypeId ") .append(" where i.isDel = 0 and i.microPlanId = #{m.microPlanId} ") .append(" order by bc.sortNo asc, i.sortNum asc "); List> itemList = null; for(Map m : planList){ values.put("microPlanId", m.get("id")); //查询适应症 sqlSentence.setSqlSentence(indSql); m.put("indicationList", commonService.selectListMap(MicroPlanMapper.class, sqlSentence)); //查询疗程项目 sqlSentence.setSqlSentence(sql.toString()); itemList = commonService.selectListMap(MicroPlanMapper.class, sqlSentence); m.put("itemList", itemList); handleItemOtherInfo(itemList); } } JSONObject data = new JSONObject(); data.put("info", infoMap); data.put("planList", planList); // data.put("mjData", mjData); return Result.success(data); } /** 适应症数据 */ @RequestMapping("/indication/data") public Result indicationData(@RequestBody MicroRecordDto dto){ SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); //查询适应症 values.put("dataType", Indication.DATA_TYPE_MICRO_PLAN); sqlSentence.setSqlSentence(" select id, name from indication where isDel = 0 and isUp = 1 and dataType = #{m.dataType} "); List> indicationList = commonService.selectListMap(IndicationMapper.class, sqlSentence); //遍历查询适应症关联分类 sqlSentence.setSqlSentence(" select id, assocId, typeId, typeLevel, typeName from indication_type where isDel = 0 and indicationId = #{m.indicationId} "); List typeList = null; Map>> typeMap = new HashMap<>(); String typeId; for(Map indMap : indicationList){ values.put("indicationId", indMap.get("id")); typeList = commonService.selectList(IndicationTypeMapper.class, sqlSentence); typeList = IndicationType.handleListData(typeList); //遍历给对应分类分配关联的适应症 for(IndicationType indicationType : typeList){ typeId = IndicationType.getLastTypeId(indicationType); if(!typeMap.containsKey(typeId)){ typeMap.put(typeId, new ArrayList<>()); } typeMap.get(typeId).add(indMap); } } //查询适应症分类 values.put("type", BaseClassifyConstants.TYPE_INDICATION); sqlSentence.setSqlSentence(" select id, name, parentId, level from base_classify where isDel = 0 and isUp = 1 and type = #{m.type} order by sortNo asc "); List> indTypeList = commonService.selectListMap(BaseClassifyMapper.class, sqlSentence); //遍历对应适应症分类下有那些对应的适应症 for(Map m : indTypeList){ if(typeMap.containsKey(m.get("id"))){ m.put("indicationList", typeMap.get(m.get("id"))); } } indTypeList = BaseClassifyReqVo.getTreeDataToMap(indTypeList); //查询治疗建议-程度类型数据 values.put("type", BaseClassifyConstants.TYPE_TREAT_PLAN_DEGREE); sqlSentence.setSqlSentence(" select id, name from base_classify where isDel = 0 and isUp = 1 and type = #{m.type} order by sortNo asc "); List> degreeTypeList = commonService.selectListMap(BaseClassifyMapper.class, sqlSentence); //查询治疗建议-时间类型数据 values.put("type", BaseClassifyConstants.TYPE_TREAT_PLAN_TIME); sqlSentence.setSqlSentence(" select id, name from base_classify where isDel = 0 and isUp = 1 and type = #{m.type} order by sortNo asc "); List> timeTypeList = commonService.selectListMap(BaseClassifyMapper.class, sqlSentence); //用户不为空则查询用户最新美际皮肤报告记录 Map mjData = null; if(StringUtils.noNull(dto.getUserId())){ //编辑时传了美际id,则根据id查 if(StringUtils.noNull(dto.getMjSkinReportId())){ values.put("mjSkinReportId", dto.getMjSkinReportId()); sqlSentence.setSqlSentence(" select id, icon, viewUrl, contents from mj_skin_report where id = #{m.mjSkinReportId} "); }else{ values.put("customerId", dto.getUserId()); sqlSentence.setSqlSentence(" select id, icon, viewUrl, contents from mj_skin_report where isDel = 0 and customerId = #{m.customerId} order by createdTime desc limit 1 "); } mjData = commonService.selectOneMap(BaseClassifyMapper.class, sqlSentence); //转换程度类型列表 Map degreeMap = degreeTypeList.stream().collect(Collectors.toMap(m->m.get("name").toString(), m->m.get("id").toString())); //处理美际数据 handleMjData(mjData, degreeMap, sqlSentence, values); } JSONObject data = new JSONObject(); data.put("indTypeList", indTypeList); data.put("degreeTypeList", degreeTypeList); data.put("timeTypeList", timeTypeList); data.put("mjData", mjData); return Result.success(data); } /** 适应症治疗建议 */ @RequestMapping("/treatPlan") public Result treatPlan(@RequestBody MicroRecordDto dto){ if(StringUtils.isEmpty(dto.getIndicationId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "适应症标识不能为空!"); } if(StringUtils.isEmpty(dto.getDegreeTypeId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "程度类型标识不能为空!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); values.put("indicationId", dto.getIndicationId()); values.put("degreeTypeId", dto.getDegreeTypeId()); StringBuffer sql = new StringBuffer(); sql.append(" select i.commonId, i.commonType, i.commonName, tp.timeTypeId, bc.`name` as timeType ") .append(" from treat_plan tp ") .append(" join base_classify bc on bc.id = tp.timeTypeId ") .append(" join treat_plan_indication ind on ind.treatPlanId = tp.id and ind.isDel = 0 ") .append(" join treat_plan_item i on i.treatPlanId = tp.id and i.isDel = 0 ") .append(" where tp.isDel = 0 and tp.isUp = 1 and ind.indicationId = #{m.indicationId} ") .append(" and tp.degreeTypeId = #{m.degreeTypeId} ") .append(" order by bc.sortNo asc "); sqlSentence.setSqlSentence(sql.toString()); List> list = commonService.selectListMap(TreatPlanMapper.class, sqlSentence); handleItemOtherInfo(list); JSONObject data = new JSONObject(); data.put("list", list); return Result.success(data); } /** 新增微整记录 */ @RequestMapping("/add") public Result add(@RequestBody MicroRecordDto dto){ String json = JSONObject.toJSONString(dto); log.info("新增微整记录请求参数:{}", json); MicroRecord microRecord = JSONObject.parseObject(json, MicroRecord.class); //检查参数 checkParams(microRecord, false); //根据操作人角色id查询操作人信息 Employee employee = employeeRoleService.selectEmployeeById(microRecord.getOpRoleId()); if(employee == null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到操作人信息!"); } microRecord.setOpId(employee.getId()); microRecord.setOpName(employee.getCnName()); microRecord.setOpShopId(employee.getShopId()); microRecord.setOpRoleStr(employee.getRoleStr()); //查询用户信息 User user = commonService.selectOneByKey(UserMapper.class, microRecord.getUserId()); if(user == null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到用户信息!"); } microRecord.setUserId(user.getId()); microRecord.setUserName(user.getName()); microRecord.setCIQ(user.getCIQ()); microRecord.setUserLevel(user.getUserLevel()); microRecord.setUserStatus(user.getUserStatus()); microRecord.setUserConsultantId(user.getHisCorpUserId()); microRecord.setUserConsultantName(EmployeeTool.getCnName(microRecord.getUserConsultantId(), commonService)); microRecord.setUserShopId(user.getShopId()); microRecord.setUserShopName(ShopTool.getShopName(microRecord.getUserShopId(), commonService)); // 草稿 if (dto.getIsDraft() != null){ microRecord.setIsDraft(dto.getIsDraft()); } //新增 mircoRecordService.add(microRecord); return Result.success(); } /** 修改微整记录 */ @RequestMapping("/edit") public Result edit(@RequestBody MicroRecordDto dto){ String json = JSONObject.toJSONString(dto); log.info("编辑微整记录请求参数:{}", json); MicroRecord microRecord = JSONObject.parseObject(json, MicroRecord.class); //检查参数 checkParams(microRecord, true); //编辑 mircoRecordService.edit(microRecord); return Result.success(); } /** 删除微整记录 */ @RequestMapping("/del") public Result del(@RequestBody MicroRecordDto dto){ String json = JSONObject.toJSONString(dto); log.info("删除微整记录请求参数:{}", json); MicroRecord microRecord = JSONObject.parseObject(json, MicroRecord.class); if(StringUtils.isEmpty(microRecord.getId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "记录标识不能为空!"); } //删除 mircoRecordService.del(microRecord); return Result.success(); } //////////////////////////////////////////////////////////////////////////////////////// //检查参数 private void checkParams(MicroRecord microRecord, boolean isEdit){ if(isEdit){ if(StringUtils.isEmpty(microRecord.getId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "记录标识不能为空!"); } }else{ if(StringUtils.isEmpty(microRecord.getUserId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户标识不能为空!"); } if(StringUtils.isEmpty(microRecord.getOpRoleId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "操作人角色标识不能为空!"); } } if(microRecord.getPlanList() == null || microRecord.getPlanList().size() < 1){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划信息不能为空!"); } for(MicroPlan plan : microRecord.getPlanList()) { if(plan.getIndicationList() == null || plan.getIndicationList().size() < 1){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划适应症信息不能为空!"); } for(MicroPlanIndication ind : plan.getIndicationList()){ if(StringUtils.isEmpty(ind.getIndicationId()) && StringUtils.isEmpty(ind.getOtherInd())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划适应症不能为空!"); } // if(StringUtils.isEmpty(ind.getDegreeTypeId())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划适应症程度类型标识不能为空!"); // } if(StringUtils.isEmpty(ind.getTypeJson())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划适应症分类信息不能为空!"); } } if(plan.getItemList() == null || plan.getItemList().size() < 1){ return; // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划疗程信息不能为空!"); } for(MicroPlanItem item : plan.getItemList()){ if(StringUtils.isEmpty(item.getTimeTypeId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划疗程时间类型标识不能为空!"); } if(StringUtils.isEmpty(item.getCommonId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划疗程项目标识不能为空!"); } if(StringUtils.isEmpty(item.getCommonName())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划疗程项目名称不能为空!"); } if(StringUtils.isEmpty(item.getCommonType())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "微整规划疗程项目类型不能为空!"); } } } } //处理美际数据 private void handleMjData(Map mjData, Map degreeMap, SqlSentence sqlSentence, Map values){ if(mjData != null){ JSONArray arr = JSONArray.parseArray(mjData.get("contents").toString()); BigDecimal result = BigDecimal.TEN; JSONObject json = new JSONObject(); for(int i = 0 ;i < arr.size(); i++){ if(arr.getJSONObject(i).getBigDecimal("result").compareTo(result) < 0){ json = arr.getJSONObject(i); result = json.getBigDecimal("result"); } } mjData.put("name", json.getString("name")); mjData.put("degree", json.getString("degree")); //获取二级分类程度数据 mjData.put("typeDegreeData", MeiJiDataTool.getTypeDegreeData(mjData.get("contents").toString(), degreeMap)); mjData.remove("contents"); //查询对应关联资源文件记录 values.put("mjSkinReportId", mjData.get("id")); sqlSentence.setSqlSentence(" select fileName, fileUrl from mj_resource_file where isDel = 0 and mjSkinReportId = #{m.mjSkinReportId} "); List> list = commonService.selectListMap(MjResourceFileMapper.class, sqlSentence); if(list != null && list.size() > 0){ String flag; for(Map map : list){ //文件验签访问 map.put("fileUrl", ComparePhotoUtil.getDecryptImagesUrl(sFileService, map.get("fileUrl").toString())); //遍历根据文件名转换展示名和排序号 flag = map.get("fileName").toString(); flag = flag.toLowerCase(Locale.ROOT); for (MeiJiResourceFileEnum meiJiResourceFileEnum : MeiJiResourceFileEnum.values()) { if (Objects.equals(meiJiResourceFileEnum.getFlag(), flag)){ map.put("sortNum", meiJiResourceFileEnum.getSortNum()); map.put("showName", meiJiResourceFileEnum.getShowName()); break; } } } //排序 list.sort(Comparator.comparing((Map h) -> ((int) h.get("sortNum")))); mjData.put("rsList", list); } } } //处理查询关联项其他信息 private void handleItemOtherInfo( List> itemList){ if(itemList == null || itemList.size() < 1){ return; } //项目sql String skuSql = " SELECT DISTINCT ( p.id ), p.NAME as name, p.specification AS spec, p.unit, p.price, p.coding AS code, 1 AS type , pi.doctorQualification,pi.bodyPartName FROM project p LEFT JOIN project_info pi on p.id=pi.projectId WHERE p.id = #{m.id} "; //促销 String promotionSql = " select p.id, p.`name`, p.total as price , 3 as type from promotion p where p.id = #{m.id} "; //卡项 String cardItemSql = " select ci.id, ci.`name`, ci.total as price , 4 as type from card_item ci where ci.id = #{m.id} "; //项目手册skuSql String wdSkuSql = "select GROUP_CONCAT(introProjectManualId) as introProjectManualIds from intro_project_manual_project where isDel = 0 and projectId = #{m.id}"; //项目手册spuSql String wdSpuSql = "select GROUP_CONCAT(introProjectManualId) as introProjectManualIds from intro_project_manual_spu where isDel = 0 and projectGeneralId = #{m.id}"; //客户案例skuSql String alSkuSql = "select GROUP_CONCAT(introUserCasesId) as introUserCasesIds from intro_user_cases_project where isDel = 0 and projectId = #{m.id}"; //客户案例spuSql String alSpuSql = "select GROUP_CONCAT(introUserCasesId) as introUserCasesIds from intro_user_cases_spu where isDel = 0 and projectGeneralId = #{m.id}"; SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); Map queryMap = null; for(Map map : itemList){ values.put("id", map.get("commonId")); if(TreatPlanItem.COMMON_TYPE_SKU.equals(map.get("commonType").toString())){ sqlSentence.setSqlSentence(skuSql); queryMap = commonService.selectOneMap(MicroRecordMapper.class, sqlSentence); map.put("price", MapUtil.getString(queryMap, "price")); map.put("unit", MapUtil.getString(queryMap, "unit")); map.put("spec", MapUtil.getString(queryMap, "spec")); map.put("doctorQualification", MapUtil.getString(queryMap, "doctorQualification")); map.put("bodyPartName", MapUtil.getString(queryMap, "bodyPartName")); //查询sku关联项目手册介绍id sqlSentence.setSqlSentence(wdSkuSql); queryMap = commonService.selectOneMap(TreatPlanItemMapper.class, sqlSentence); map.put("introProjectManualIds", MapUtil.getString(queryMap, "introProjectManualIds")); //查询sku关联客户案例介绍id sqlSentence.setSqlSentence(alSkuSql); queryMap = commonService.selectOneMap(TreatPlanItemMapper.class, sqlSentence); map.put("introUserCasesIds", MapUtil.getString(queryMap, "introUserCasesIds")); }else if(TreatPlanItem.COMMON_TYPE_SPU.equals(map.get("commonType").toString())){ //查询spu关联项目手册介绍id sqlSentence.setSqlSentence(wdSpuSql); queryMap = commonService.selectOneMap(TreatPlanItemMapper.class, sqlSentence); map.put("introProjectManualIds", MapUtil.getString(queryMap, "introProjectManualIds")); //查询spu关联客户案例介绍id sqlSentence.setSqlSentence(alSpuSql); queryMap = commonService.selectOneMap(TreatPlanItemMapper.class, sqlSentence); map.put("introUserCasesIds", MapUtil.getString(queryMap, "introUserCasesIds")); }else if(TreatPlanItem.COMMON_TYPE_PROMOTION.equals(map.get("commonType").toString())){ sqlSentence.setSqlSentence(promotionSql); queryMap = commonService.selectOneMap(MicroRecordMapper.class, sqlSentence); map.put("price", MapUtil.getString(queryMap, "price")); }else if(TreatPlanItem.COMMON_TYPE_CARD_ITEM.equals(map.get("commonType").toString())){ sqlSentence.setSqlSentence(cardItemSql); queryMap = commonService.selectOneMap(MicroRecordMapper.class, sqlSentence); map.put("price", MapUtil.getString(queryMap, "price")); } } } ///////////////////////////////////////////////////////////////////////////////////////////// /** crm查看记录详情 */ @RequestMapping("/crm/see") public Result see(@RequestBody MicroRecordDto dto){ if( null ==dto || StringUtils.isEmpty(dto.getUserId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "用户标识不能为空!"); } SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.setM(values); StringBuffer sql = new StringBuffer(); if (StringUtils.isEmpty(dto.getId())){ values.put("userId", dto.getUserId()); sql.append(" select id, userName, opName, createTime, editTime,isView ") .append(" from micro_record where isDel = 0 and userId = #{m.userId} order by createTime desc limit 1"); }else { values.put("id", dto.getId()); sql.append(" select id, userName, opName, createTime, editTime,isView ") .append(" from micro_record where isDel = 0 and id = #{m.id} "); } sqlSentence.setSqlSentence(sql.toString()); MicroRecord microRecord = commonService.selectOne(MicroRecordMapper.class, sqlSentence); JSONObject data = new JSONObject(); //白光紧数据 Map whiteLightTautMap = new HashMap<>(); //美塑数据 Map beautifulPlasticMap = new HashMap<>(); if (null != microRecord){ sqlSentence.setM(values); values.put("microRecordId", microRecord.getId()); sqlSentence.setSqlSentence(" select id, userId, userName, createTime from micro_record where id = #{m.microRecordId} "); Map infoMap = commonService.selectOneMap(MicroRecordMapper.class, sqlSentence); if(infoMap == null || infoMap.size() < 1){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "查询不到微整规划记录信息!"); } //查询微整规划 sqlSentence.setSqlSentence(" select id, mjSkinReportId, recommend, sortNum from micro_plan where isDel = 0 and microRecordId = #{m.microRecordId} order by sortNum asc "); List> planList = commonService.selectListMap(MicroPlanMapper.class, sqlSentence); Map mjData = null; if (planList != null && planList.size() > 0) { //白光紧诊断结果 List whiteLightTautDiagnostic = new ArrayList<>(); //美塑数据诊断结果 List beautifulPlasticDiagnostic = new ArrayList<>(); //白光紧诊断建议 List whiteLightTautRecommend = new ArrayList<>(); //美塑数据诊断建议 List beautifulPlasticRecommend = new ArrayList<>(); List> whiteLightTautDiagnosDevices = new ArrayList<>(); List> beautifulPlasticDevices = new ArrayList<>(); sql = new StringBuffer(); sql.append(" select mpi.indicationId, i.name as indName, mpi.typeJson, mpi.sortNum, mpi.otherInd ") .append(" , mpi.degreeTypeId, bc.name as degreeType,i.description,i.dailyCare,i.beautScience,i.reason ") .append(" from micro_plan_indication mpi ") .append(" left join indication i on i.id = mpi.indicationId ") .append(" left join base_classify bc on bc.id = mpi.degreeTypeId ") .append(" where mpi.isDel = 0 and mpi.microPlanId = #{m.microPlanId} ") .append(" order by mpi.sortNum asc "); String indSql = sql.toString(); String sqlA = "SELECT * FROM indication_type where isDel = 0 " + "and indicationId = #{m.indicationId} and typeLevel < 3 order by typeLevel"; sql.setLength(0); sql.append(" select i.commonId, i.commonType, i.commonName, i.sortNum, i.timeTypeId, bc.name as timeType ") .append(" from micro_plan_item i ") .append(" join base_classify bc on bc.id = i.timeTypeId ") .append(" where i.isDel = 0 and i.microPlanId = #{m.microPlanId} ") .append(" order by bc.sortNo asc, i.sortNum asc "); String indName= ""; String degreeType= ""; List> indicationListMap = new ArrayList<>(); for (Map m : planList) { values.put("microPlanId", m.get("id")); if (BaseEntity.YES.equals((Integer) m.get("sortNum"))){ if (null != m.get("recommend")){ whiteLightTautRecommend.add(MapUtil.getString(m,"recommend")); } handleDevice(m.get("id").toString(), whiteLightTautDiagnosDevices); }else if (QuestionInvestigate.STATUS_TOW.equals((Integer) m.get("sortNum"))){ if (null != m.get("recommend")){ beautifulPlasticRecommend.add(MapUtil.getString(m,"recommend")); } handleDevice(m.get("id").toString(), beautifulPlasticDevices); } //查询适应症 sqlSentence.setSqlSentence(indSql); List> list = commonService.selectListMap(MicroPlanMapper.class, sqlSentence); //m.put("indicationList", list); if (null != list && list.size() > 0) { for (Map map : list) { //查询对应证一级和二级名称 values.put("indicationId", map.get("indicationId")); sqlSentence.sqlSentence(sqlA, values); List indicationTypes = commonService.selectList(IndicationTypeMapper.class, sqlSentence); if (null != indicationTypes && indicationTypes.size() > 0) { for (IndicationType indicationType : indicationTypes) { if (IndicationType.YES.equals(indicationType.getTypeLevel())) { map.put("parentType", indicationType.getTypeName()); if (null != map.get("indName")){ indName = map.get("indName").toString(); }else { indName = ""; } if (MicroRecordConstants.WHITE_ARR.contains(indicationType.getTypeName())){ map.put("typeOne", "症状特点"); map.put("typeTwo", "日常护理"); if (null != map.get("degreeType")){ degreeType = map.get("degreeType").toString(); }else { degreeType = ""; } whiteLightTautDiagnostic.add(handleJsonStr( map.get("typeJson").toString(),map.get("otherInd"),indName,degreeType,null)); }else if (MicroRecordConstants.BEAUTIFUL_USER.contains(indicationType.getTypeName())){ map.put("typeThree", "美学科普"); map.put("typeFour", "原因及作用"); beautifulPlasticDiagnostic.add(handleJsonStr( map.get("typeJson").toString(),map.get("otherInd"),indName,degreeType,null) ); } } else if (2 == indicationType.getTypeLevel()) { map.put("sonType", indicationType.getTypeName()); } } }else { //log.info("==================:{}",m.get("sortNum")); if (null != m.get("sortNum")){ //log.info("=========22222=========:{}",m.get("sortNum")); if (BaseEntity.YES.equals((Integer) m.get("sortNum"))){ map.put("typeOne", "症状特点"); map.put("typeTwo", "日常护理"); if (null != map.get("degreeType")){ degreeType = map.get("degreeType").toString(); }else { degreeType = ""; } whiteLightTautDiagnostic.add(handleJsonStr( map.get("typeJson").toString(),map.get("otherInd"),"其他",degreeType,map.get("indicationId"))); }else { map.put("typeThree", "美学科普"); map.put("typeFour", "原因及作用"); beautifulPlasticDiagnostic.add(handleJsonStr( map.get("typeJson").toString(),map.get("otherInd"),"其他",degreeType,map.get("indicationId")) ); } } } if (null != map.get("indicationId") && !StringUtils.isEmpty(map.get("indicationId").toString())){ indicationListMap.add(map); } } } //查询疗程项目 //sqlSentence.setSqlSentence(sql.toString()); //itemList = commonService.selectListMap(MicroPlanMapper.class, sqlSentence); //queryItemOtherInfo(itemList, sqlSentence, values); //m.put("itemList", itemList); //查询美际数据 if (mjData == null && StringUtils.noNull(MapUtil.getString(m, "mjSkinReportId"))) { values.put("mjSkinReportId", m.get("mjSkinReportId")); sqlSentence.setSqlSentence(" select id, icon, viewUrl, contents from mj_skin_report where id = #{m.mjSkinReportId} "); mjData = commonService.selectOneMap(BaseClassifyMapper.class, sqlSentence); if (null != mjData && null != mjData.get("viewUrl")){ //替换http String viewUrl = mjData.get("viewUrl").toString(); if (!viewUrl.startsWith("https")){ String s = viewUrl.replaceFirst("http", "https"); mjData.put("viewUrl",s); } } //handleMjData(mjData); } data.put("indicationListMap", indicationListMap); } whiteLightTautMap.put("whiteLightTautDiagnostic",whiteLightTautDiagnostic); whiteLightTautMap.put("whiteLightTautRecommend",whiteLightTautRecommend); whiteLightTautMap.put("whiteLightTautDiagnosDevices",whiteLightTautDiagnosDevices); beautifulPlasticMap.put("beautifulPlasticDiagnostic",beautifulPlasticDiagnostic); beautifulPlasticMap.put("beautifulPlasticRecommend",beautifulPlasticRecommend); beautifulPlasticMap.put("beautifulPlasticDevices",beautifulPlasticDevices); data.put("whiteLightTautMap", whiteLightTautMap); data.put("beautifulPlasticMap", beautifulPlasticMap); } data.put("info", infoMap); // data.put("planList", planList); data.put("mjData", mjData); } updateIsView( microRecord); return Result.success(data); } //处理设备信息 private void handleDevice(String microPlanId,List> devices){ SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); values.put("microPlanId",microPlanId); sqlSentence.sqlSentence("SELECT d.*,m.commonId as projectId FROM micro_plan_item m " + " left JOIN project_device_parameter p ON m.commonId = p.projectId and p.isDel = 0 " + " left JOIN device d ON p.deviceId = d.id " + " WHERE m.isDel = 0 AND m.microPlanId =#{m.microPlanId} group by m.commonId ",values); List> deviceList = commonService.selectListMap(DeviceMapper.class,sqlSentence); GoodsSkuDto goodsSkuDto = new GoodsSkuDto(); Map map = null; StringBuilder ids = new StringBuilder(); for (Map device : deviceList) { /* if (null != device.get("name") && device.get("name").toString().startsWith("B_")){ device.put("name",device.get("name").toString().replaceFirst("B_","")); }*/ if (null != device.get("projectId")){ if (!ids.toString().contains(device.get("projectId").toString())){ ids.append(device.get("projectId").toString()).append(","); } //map.put("intro",device.get("intro")); //map.put("projectId",device.get("projectId")); //查询crm spuId /* goodsSkuDto.setHisId(device.get("projectId").toString()); Result goodsByHisIdOne = fGoodsSkuService.findGoodsByHisIdOne(goodsSkuDto); if (goodsByHisIdOne.checkCode()){ JSONObject object = goodsByHisIdOne.getObject(goodsByHisIdOne.getData(), JSONObject.class); Map goods = (Map)object.get("goods"); if (null != goods && null != goods.get("goodsId")){ map = new HashMap<>(); map.put("goodsId",goods.get("goodsId").toString()); if (null != goods.get("imgUrl")){ map.put("imgUrl",goods.get("imgUrl").toString()); } if (null != goods.get("goodsName")){ map.put("name",goods.get("goodsName").toString()); } devices.add(map); } }*/ } } if (ids.length() > 0 && ids.toString().endsWith(",")){ String id = ids.substring(0, ids.length() - 1); goodsSkuDto.setIds(id); Result goodsByHisIdOne = fGoodsSkuService.findGoodsByHisIdOne(goodsSkuDto); if (goodsByHisIdOne.checkCode()){ JSONObject jsonObject = goodsByHisIdOne.getJsonObject(goodsByHisIdOne.getData()); if (null != jsonObject){ List> list = (List>)jsonObject.get("goods"); devices.addAll(list); } }else { log.info("请求crm开放平台返回数据:{}", JSON.toJSONString(goodsByHisIdOne)); } } } private String handleJsonStr(String str,Object otherInd,String indName,String degreeType,Object indicationId){ // log.info("==================:{}",str); List list = JSONArray.parseArray(str, JSONObject.class); List level = list.stream().sorted(Comparator.comparing(obj -> obj.getInteger("level"))).collect(Collectors.toList()); StringBuffer s = new StringBuffer(); if (null != level && level.size() > 0) { for (int i=0;i values = new HashMap<>(); values.put("userId",dto.getUserId()); sqlSentence.sqlSentence(" isDel = 0 and isView = 0 and userId = #{m.userId} ",values); int count = commonService.selectCount(MicroRecordMapper.class, sqlSentence); values = new HashMap<>(); values.put("count",count); return Result.success(values); } }