| | |
| | | import com.hx.exception.TipsException; |
| | | import com.hx.mybatisTool.SqlSentence; |
| | | import com.hx.phiappt.common.BaseClassifyConstants; |
| | | import com.hx.phiappt.common.enums.MeiJiResourceFileEnum; |
| | | import com.hx.phiappt.common.enums.MeiJiResourceFileP2Enum; |
| | | import com.hx.phiappt.constants.tool.UserInfoTool; |
| | | 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.model.micro.MicroRecord; |
| | | import com.hx.phiappt.model.micro.MicroRecordData; |
| | | import com.hx.phiappt.model.treatPlan.TreatPlan; |
| | | import com.hx.phiappt.model.treatPlan.TreatPlanItem; |
| | | import com.hx.phiappt.util.SystemParameterUtil; |
| | | import com.hx.phiappt.vo.mj.MjDataVo; |
| | | import com.hx.phiappt.vo.mj.MjIndicationVo; |
| | | import com.hx.phiappt.vo.mj.MjTypeVo; |
| | | import com.hx.phip.config.TimeBean; |
| | | import com.hx.phip.service.EmployeeRoleService; |
| | |
| | | import com.hz.his.dto.micro.MicroRecordDto; |
| | | import com.hz.his.dto.micro.MicroRecordIdDto; |
| | | import com.hz.his.feign.service.phis.SFileService; |
| | | import com.hz.his.vo.mj.MjIndicationDetailVo; |
| | | import com.platform.exception.PlatTipsException; |
| | | import com.platform.resultTool.PlatformCode; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** 查看记录详情-艾芯荟小程序-展示详细数据 */ |
| | | @RequestMapping("/crm/see/V2/detail") |
| | | public Result seeDetailV2(@RequestBody MicroRecordDto dto){ |
| | | logger.info("查看详细数据-艾芯荟小程序展示样式,入参:" + JSON.toJSONString(dto)); |
| | | if (dto == null) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "数据格式错误,参数为空!"); |
| | | } |
| | | //美际档案标识 |
| | | String mjRecordId = dto.getId(); |
| | | if (StringUtils.isEmpty(mjRecordId)) { |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "请选择要查看的报告!"); |
| | | } |
| | | //颜值规划关联的美际报告 |
| | | MjSkinReport mjSkinReport = commonService.selectOneByKey(MjSkinReportMapper.class,mjRecordId); |
| | | if (mjSkinReport == null){ |
| | | throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL, "美际报告数据获取异常,请联系管理员!"); |
| | | } |
| | | //校验归属 |
| | | if (StringUtils.noNull(dto.getUserId()) && !dto.getUserId().equals(mjSkinReport.getCustomerId())){ |
| | | logger.error("皮测详细数据校验归属,参数客户:{},报告客户{}",dto.getUserId(),mjSkinReport.getCustomerId()); |
| | | throw new TipsException("获取报告信息失败,请联系您的专属客服!"); |
| | | } |
| | | //处理链接 |
| | | if (!StringUtils.isEmpty(mjSkinReport.getShareUrl()) && !mjSkinReport.getShareUrl().contains("https")) { |
| | | mjSkinReport.setShareUrl( mjSkinReport.getShareUrl().replace("http", "https")); |
| | | } |
| | | if (!StringUtils.isEmpty(mjSkinReport.getViewUrl()) && !mjSkinReport.getViewUrl().contains("https")) { |
| | | mjSkinReport.setViewUrl(mjSkinReport.getViewUrl().replace("http", "https")); |
| | | } |
| | | SqlSentence sqlSentence = new SqlSentence(); |
| | | Map<String, Object> sqlMap = new HashMap<>(); |
| | | sqlMap.put("isDel",BaseEntity.NO); |
| | | sqlMap.put("isUp",BaseEntity.YES); |
| | | sqlMap.put("mjSkinReportId",mjRecordId); |
| | | |
| | | //返回数据 |
| | | Map<String,Object> data = new HashMap<>(); |
| | | //1.美际报告数据 |
| | | data.put("mjSkinReportId",mjRecordId); |
| | | data.put("icon",mjSkinReport.getIcon()); |
| | | data.put("shareUrl",mjSkinReport.getShareUrl()); |
| | | data.put("viewUrl",mjSkinReport.getViewUrl()); |
| | | |
| | | //获取自然光的照片 |
| | | Map<String, Object> map = getMiddleFileUrl(mjSkinReport, sqlMap, sqlSentence); |
| | | //2.照片验签访问返回 |
| | | data.put("fileUrl", ComparePhotoUtil.getDecryptImagesUrl(sFileService, map.get("fileUrl").toString())); |
| | | |
| | | //症状,分类名 |
| | | Map<String, String> nameTypeMap = getIndMap(); |
| | | //3.返回分类名 |
| | | data.put("typeNameList",nameTypeMap.values().stream().distinct().collect(Collectors.toList())); |
| | | |
| | | //适应症名称,数据 |
| | | Map<String, MjIndicationDetailVo> detailVoMap = getMjIndicationDetailVoMap(nameTypeMap, mjSkinReport, sqlMap, sqlSentence); |
| | | //4.返回症状数据 |
| | | List<MjIndicationDetailVo> detailVoList = new ArrayList<>(); |
| | | for (Map.Entry<String, MjIndicationDetailVo> voEntry : detailVoMap.entrySet()) { |
| | | detailVoList.add(voEntry.getValue()); |
| | | } |
| | | data.put("detailVoList",detailVoList); |
| | | |
| | | return Result.success(data); |
| | | } |
| | | |
| | | /** |
| | | * 处理每个症状的数据 |
| | | */ |
| | | private Map<String, MjIndicationDetailVo> getMjIndicationDetailVoMap(Map<String, String> nameTypeMap |
| | | , MjSkinReport mjSkinReport, Map<String, Object> sqlMap, SqlSentence sqlSentence) { |
| | | //适应症名称,适应症数据 |
| | | Map<String, MjIndicationDetailVo> detailVoMap = new HashMap<>(); |
| | | MjIndicationDetailVo mjIndicationDetailVo = null; |
| | | //1.封装症状数据 |
| | | if (StringUtils.noNull(mjSkinReport.getContents())) { |
| | | List<MjDataVo> mjDataVoList = JSONArray.parseArray(mjSkinReport.getContents(), MjDataVo.class); |
| | | //处理分类 |
| | | if (mjDataVoList != null && mjDataVoList.size() > 0) { |
| | | for (MjDataVo mjDataVo : mjDataVoList) { |
| | | mjIndicationDetailVo = new MjIndicationDetailVo(); |
| | | mjIndicationDetailVo.setName(mjDataVo.getName()); |
| | | String typeName = nameTypeMap.get(mjDataVo.getName()); |
| | | mjIndicationDetailVo.setTypeName(StringUtils.isEmpty(typeName) ? "其他" : typeName); |
| | | mjIndicationDetailVo.setDegree(MjSkinReport.getDegree(mjDataVo.getLevel())); |
| | | if (mjDataVo.getResult() != null) { |
| | | mjIndicationDetailVo.setScore(mjDataVo.getResult().toString()); |
| | | } |
| | | detailVoMap.put(mjDataVo.getName(), mjIndicationDetailVo); |
| | | } |
| | | } |
| | | } |
| | | if (detailVoMap.size() < 1) { |
| | | return detailVoMap; |
| | | } |
| | | //2.查询适应症数据 |
| | | sqlMap.put("dataType", Indication.DATA_TYPE_MICRO_PLAN); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" SELECT i.id,i.name,i.byName,i.description,i.dailyCare,i.beautScience,i.reason,i.imgUrl FROM indication AS i "); |
| | | sql.append(" WHERE i.isDel = #{m.isDel} AND isUp = #{m.isUp} AND i.dataType = #{m.dataType} "); |
| | | sql.append(" AND i.name IN ( "); |
| | | for (String name : detailVoMap.keySet()) { |
| | | sql.append("'").append(name).append("'").append(","); |
| | | } |
| | | sql.delete(sql.length() - 1, sql.length()); |
| | | sql.append(" )"); |
| | | sqlSentence.sqlSentence(sql.toString(), sqlMap); |
| | | List<Indication> indicationList = commonService.selectList(IndicationMapper.class, sqlSentence); |
| | | if (indicationList != null && indicationList.size() > 0) { |
| | | for (Indication indication : indicationList) { |
| | | mjIndicationDetailVo = detailVoMap.get(indication.getName()); |
| | | if (mjIndicationDetailVo == null) { |
| | | continue; |
| | | } |
| | | mjIndicationDetailVo.setDetailMsg(indication.getDescription()); |
| | | mjIndicationDetailVo.setImgUrl(indication.getImgUrl()); |
| | | detailVoMap.put(indication.getName(), mjIndicationDetailVo); |
| | | } |
| | | } |
| | | //3.处理治疗设备和治疗项目 |
| | | if (indicationList != null && indicationList.size() > 0) { |
| | | //先查询适应症关联的治疗方案 |
| | | sqlMap.put("typeStr", TreatPlan.TYPE_STR_INDICATION); |
| | | sql.delete(0, sql.length()); |
| | | sql.append(" SELECT t.id,d.name FROM treat_plan AS t "); |
| | | sql.append(" JOIN treat_plan_indication AS p ON p.treatPlanId = t.id "); |
| | | sql.append(" JOIN indication AS d ON d.id = p.indicationId "); |
| | | sql.append(" WHERE t.isDel = #{m.isDel} AND t.typeStr = #{m.typeStr} AND t.isUp = #{m.isUp} "); |
| | | sql.append(" AND p.isDel = #{m.isDel} AND d.isDel = #{m.isDel} "); |
| | | sql.append(" AND d.id IN ( "); |
| | | for (Indication indication : indicationList) { |
| | | sql.append("'").append(indication.getId()).append("'").append(","); |
| | | } |
| | | sql.delete(sql.length() - 1, sql.length()); |
| | | sql.append(" )"); |
| | | sql.append(" GROUP BY t.id,d.id "); |
| | | sqlSentence.sqlSentence(sql.toString(), sqlMap); |
| | | logger.info("查询适应症关联的治疗方案sql:{},Map:{}", sqlSentence.getSqlSentence(),JSON.toJSONString(sqlSentence.getM())); |
| | | List<TreatPlan> treatPlanList = commonService.selectList(TreatPlanMapper.class, sqlSentence); |
| | | if (treatPlanList != null && treatPlanList.size() > 0){ |
| | | //治疗方案对应的设备 |
| | | String deviceSql = " SELECT id,describeMsg,imgUrl,name FROM treat_plan_device WHERE isDel = 0 AND treatPlanId = #{m.treatPlanId} "; |
| | | //治疗方案对应的项目 |
| | | String projectSql = " SELECT id,commonId FROM treat_plan_item WHERE isDel = 0 AND treatPlanId = #{m.treatPlanId} "; |
| | | //返回的数据 |
| | | List<Map<String, Object>> deviceTotalList = null; |
| | | //治疗的项目标识 |
| | | List<String> goodsIdList = null; |
| | | for (TreatPlan treatPlan : treatPlanList) { |
| | | sqlMap.put("treatPlanId", treatPlan.getId()); |
| | | mjIndicationDetailVo = detailVoMap.get(treatPlan.getName()); |
| | | if (mjIndicationDetailVo == null) { |
| | | continue; |
| | | } |
| | | deviceTotalList = mjIndicationDetailVo.getDeviceList(); |
| | | if (deviceTotalList == null){ |
| | | deviceTotalList = new ArrayList<>(); |
| | | } |
| | | //查询设备数据 |
| | | sqlSentence.sqlSentence(deviceSql, sqlMap); |
| | | List<Map<String, Object>> deviceList = commonService.selectListMap(TreatPlanDeviceMapper.class, sqlSentence); |
| | | if (deviceList != null && deviceList.size() > 0) { |
| | | //查询项目数据 |
| | | sqlSentence.sqlSentence(projectSql, sqlMap); |
| | | List<TreatPlanItem> projectList = commonService.selectList(TreatPlanItemMapper.class, sqlSentence); |
| | | if (projectList != null && projectList.size() > 0) { |
| | | goodsIdList = projectList.stream().map(TreatPlanItem::getCommonId).collect(Collectors.toList()); |
| | | }else { |
| | | goodsIdList = new ArrayList<>(); |
| | | } |
| | | //给每个设备数据关联上相同治疗方案的推荐项目 |
| | | for (Map<String, Object> map : deviceList) { |
| | | map.put("goodsIdList", goodsIdList); |
| | | } |
| | | deviceTotalList.addAll(deviceList); |
| | | } |
| | | mjIndicationDetailVo.setDeviceList(deviceTotalList); |
| | | detailVoMap.put(treatPlan.getName(), mjIndicationDetailVo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //4.查询上一次同类型的美际报告,上一次分值 |
| | | MjSkinReport lastMjSkinReport = getLastMjSkinReport(mjSkinReport, sqlMap, sqlSentence); |
| | | if (lastMjSkinReport != null && StringUtils.noNull(lastMjSkinReport.getContents())) { |
| | | List<MjDataVo> mjDataVoList = JSONArray.parseArray(lastMjSkinReport.getContents(), MjDataVo.class); |
| | | if (mjDataVoList != null && mjDataVoList.size() > 0) { |
| | | for (MjDataVo mjDataVo : mjDataVoList) { |
| | | mjIndicationDetailVo = detailVoMap.get(mjDataVo.getName()); |
| | | if (mjIndicationDetailVo == null) { |
| | | continue; |
| | | } |
| | | if (mjDataVo.getResult() != null) { |
| | | mjIndicationDetailVo.setLastScore(mjDataVo.getResult().toString()); |
| | | } |
| | | detailVoMap.put(mjDataVo.getName(), mjIndicationDetailVo); |
| | | } |
| | | } |
| | | } |
| | | return detailVoMap; |
| | | } |
| | | |
| | | /** |
| | | * 返回症状结构数据 |
| | | */ |
| | | private Map<String, String> getIndMap() { |
| | | SystemParameter systemParameter = SystemParameterUtil.selectByNameInsert(SystemParameter.KEY_MJ_INDICATION_TYPE, "[]", null, commonService); |
| | | List<MjIndicationVo> list = JSONArray.parseArray(systemParameter.getParamValue(), MjIndicationVo.class); |
| | | Map<String, String> nameTypeMap = new HashMap<>(); |
| | | if (list != null && list.size() > 0) { |
| | | for (MjIndicationVo mjIndicationVo : list) { |
| | | if (mjIndicationVo.getNameList() != null && mjIndicationVo.getNameList().size() > 0) { |
| | | for (String name : mjIndicationVo.getNameList()) { |
| | | nameTypeMap.put(name, mjIndicationVo.getTypeName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return nameTypeMap; |
| | | } |
| | | |
| | | /** |
| | | * 获取自然光的图 |
| | | */ |
| | | private Map<String, Object> getMiddleFileUrl(MjSkinReport mjSkinReport, Map<String, Object> sqlMap, SqlSentence sqlSentence) { |
| | | if (mjSkinReport == null) { |
| | | return null; |
| | | } |
| | | //看看当前是什么拍摄设备的数据,拿取自然光的数据 |
| | | String edition = mjSkinReport.getEdition(); |
| | | if (StringUtils.isEmpty(mjSkinReport.getEdition())) { |
| | | if (StringUtils.noNull(mjSkinReport.getScannerId()) && mjSkinReport.getScannerId().startsWith("P2")) { |
| | | edition = "2"; |
| | | } else { |
| | | edition = "1"; |
| | | } |
| | | } |
| | | if ("2".equals(edition)) { |
| | | sqlMap.put("fileName", MeiJiResourceFileP2Enum.FLAG_RGB_MIDDLE_T.getFlag()); |
| | | } else { |
| | | sqlMap.put("fileName", MeiJiResourceFileEnum.FLAG_RGB_MIDDLE_T.getFlag()); |
| | | } |
| | | //拿自然光的照片 |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" SELECT id,fileName,fileUrl FROM mj_resource_file WHERE isDel = #{m.isDel} "); |
| | | sql.append(" AND mjSkinReportId = #{m.mjSkinReportId} AND LOWER(fileName) = #{m.fileName} LIMIT 1 "); |
| | | sqlSentence.sqlSentence(sql.toString(), sqlMap); |
| | | Map<String, Object> map = commonService.selectOneMap(MjResourceFileMapper.class, sqlSentence); |
| | | if (map == null) { |
| | | map = new HashMap<>(); |
| | | map.put("fileUrl", ""); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 获取同类型的上次的美际数据 |
| | | */ |
| | | private MjSkinReport getLastMjSkinReport(MjSkinReport mjSkinReport, Map<String, Object> sqlMap, SqlSentence sqlSentence) { |
| | | if (mjSkinReport == null || StringUtils.isEmpty(mjSkinReport.getEdition())) { |
| | | return null; |
| | | } |
| | | sqlMap.put("isDel", BaseEntity.NO); |
| | | sqlMap.put("edition", mjSkinReport.getEdition()); |
| | | sqlMap.put("customerId", mjSkinReport.getCustomerId()); |
| | | sqlMap.put("createdTime", mjSkinReport.getCreatedTime()); |
| | | |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append(" SELECT * FROM mj_skin_report WHERE isDel = #{m.isDel} AND edition = #{m.edition} "); |
| | | sql.append(" AND customerId = #{m.customerId} AND createdTime < #{m.createdTime} "); |
| | | sql.append(" ORDER BY createdTime DESC LIMIT 1 "); |
| | | sqlSentence.sqlSentence(sql.toString(), sqlMap); |
| | | return commonService.selectOne(MjSkinReportMapper.class, sqlSentence); |
| | | } |
| | | |
| | | } |