123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.diagbot.client.UserServiceClient;
- import com.diagbot.dto.GetMedicalInfoDetailDTO;
- import com.diagbot.dto.GetMedicalInfoListDTO;
- import com.diagbot.dto.RespDTO;
- import com.diagbot.entity.Concept;
- import com.diagbot.entity.LibraryInfo;
- import com.diagbot.entity.Medical;
- import com.diagbot.enums.LexiconTypeEnum;
- import com.diagbot.exception.CommonErrorCode;
- import com.diagbot.exception.CommonException;
- import com.diagbot.service.MedicalService;
- import com.diagbot.service.impl.MedicalServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.StringUtil;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.AddMedicalInfoVO;
- import com.diagbot.vo.GetMedicalInfoDetailVO;
- import com.diagbot.vo.GetMedicalInfoListVO;
- import com.diagbot.vo.RemoveMedicalInfoVO;
- import org.apache.commons.lang.time.DateFormatUtils;
- import org.apache.poi.hssf.usermodel.HSSFDateUtil;
- import org.apache.poi.hssf.usermodel.HSSFWorkbook;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.stereotype.Component;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.InputStream;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * @Description: 术语临床信息查询业务层
- * @author: Weixuan Huang
- * @time: 2019/1/16 16:07
- */
- @Component
- public class MedicalFacade extends MedicalServiceImpl {
- @Autowired
- private ConceptFacade conceptFacade;
- @Autowired
- private LibraryInfoFacade libraryInfoFacade;
- @Autowired
- @Qualifier("medicalServiceImpl")
- private MedicalService medicalService;
- @Autowired
- private UserServiceClient userServiceClient;
- /**
- * 获取医学术语命名列表
- *
- * @param getMedicalInfoListVO
- * @return
- */
- public IPage<GetMedicalInfoListDTO> getMedicalInfoList(GetMedicalInfoListVO getMedicalInfoListVO) {
- IPage<GetMedicalInfoListDTO> ipage = this.baseMapper.getMedicalInfoList(getMedicalInfoListVO);
- if (ipage.getRecords().size() == 0) {
- return ipage;
- }
- List<String> ids = ipage.getRecords().stream().map(i -> i.getOperName()).distinct().collect(Collectors.toList());
- RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
- if (respDTO == null || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
- throw new CommonException(CommonErrorCode.RPC_ERROR,
- "获取用户信息失败");
- }
- ipage.getRecords().forEach(i -> {
- i.setOperName(respDTO.data.get(i.getOperName()));
- });
- return ipage;
- }
- /**
- * 医学术语命名删除
- *
- * @param removeMedicalInfoVO
- * @return
- */
- public Boolean removeMedicalInfo(RemoveMedicalInfoVO removeMedicalInfoVO) {
- Medical medical = this.getById(removeMedicalInfoVO.getMedicalId());
- if (medical == null || medical.getIsDeleted().equals("Y")) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS);
- }
- medical.setIsDeleted("Y");
- medical.setModifier(UserUtils.getCurrentPrincipleID());
- medical.setGmtModified(DateUtil.now());
- return updateById(medical);
- }
- /**
- * 获取术语医学属性详情
- *
- * @param getMedicalInfoDetailVO
- * @return
- */
- public GetMedicalInfoDetailDTO getMedicalInfoDetail(GetMedicalInfoDetailVO getMedicalInfoDetailVO) {
- Medical medical = this.getById(getMedicalInfoDetailVO.getMedicalId());
- if (medical == null || medical.getIsDeleted().equals("Y")) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS);
- }
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
- libraryInfoQe.eq("is_deleted", "N");
- libraryInfoQe.eq("is_concept", "1");
- libraryInfoQe.eq("concept_id", medical.getConceptId());
- LibraryInfo libraryInfo = libraryInfoFacade.getOne(libraryInfoQe);
- if (libraryInfo == null) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, "术语医学属性所属概念不存在!");
- }
- GetMedicalInfoDetailDTO getMedicalInfoDetailDTO = new GetMedicalInfoDetailDTO();
- BeanUtil.copyProperties(medical, getMedicalInfoDetailDTO);
- getMedicalInfoDetailDTO.setConceptName(libraryInfo.getName());
- getMedicalInfoDetailDTO.setConceptType(LexiconTypeEnum.getName(libraryInfo.getTypeId().intValue()));
- return getMedicalInfoDetailDTO;
- }
- /**
- * 术语医学属性添加或者编辑
- *
- * @param addMedicalInfoVO
- * @return
- */
- public Boolean addMedicalInfo(AddMedicalInfoVO addMedicalInfoVO) {
- Map<String, Object> ckMap = checkAddMedicalInfoVO(addMedicalInfoVO);
- Object message = ckMap.get("message");
- if (message != null) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, message.toString());
- }
- return saveOrUpdate((Medical) (ckMap.get("medical")));
- }
- /**
- * 校验即将添加的数据
- *
- * @param addMedicalInfoVO
- * @return 返回map中,包含2个字段:message和medical,message-为空时,表示正常,取medical
- */
- private Map<String, Object> checkAddMedicalInfoVO(AddMedicalInfoVO addMedicalInfoVO) {
- Map<String, Object> retMap = new HashMap<>();
- QueryWrapper<LibraryInfo> libraryInfoQe = new QueryWrapper<LibraryInfo>();
- libraryInfoQe.eq("is_deleted", "N");
- libraryInfoQe.eq("is_concept", "1");
- libraryInfoQe.eq("name", addMedicalInfoVO.getConceptName());
- libraryInfoQe.eq("type", addMedicalInfoVO.getConceptType());
- LibraryInfo libraryInfo = libraryInfoFacade.getOne(libraryInfoQe);
- if (libraryInfo == null) {
- retMap.put("message", "术语概念名称不存在");
- return retMap;
- }
- Concept concept = conceptFacade.getById(libraryInfo.getConceptId());
- if (concept == null || concept.getIsDeleted().equals("Y")) {
- retMap.put("message", "术语概念名称不存在");
- return retMap;
- }
- List<String> infoNames = new ArrayList<>();
- infoNames.add(addMedicalInfoVO.getName());
- infoNames.add(addMedicalInfoVO.getStdName());
- infoNames.add(addMedicalInfoVO.getCateName());
- infoNames.add(addMedicalInfoVO.getGrp());
- QueryWrapper<LibraryInfo> libraryInfoQe1 = new QueryWrapper<LibraryInfo>();
- libraryInfoQe1.in("name", infoNames);
- libraryInfoQe1.eq("is_concept", "1");
- libraryInfoQe1.eq("is_deleted", "N");
- Map<String, List<LibraryInfo>> libraryInfoListMap = libraryInfoFacade.list(libraryInfoQe1).stream().collect(Collectors.groupingBy(LibraryInfo::getName));
- if (libraryInfoListMap.get(addMedicalInfoVO.getName()).size() == 0) {
- retMap.put("message", "术语名称不存在");
- return retMap;
- }
- if (libraryInfoListMap.get(addMedicalInfoVO.getStdName()).size() == 0) {
- retMap.put("message", "术语标准名不存在");
- return retMap;
- }
- if (libraryInfoListMap.get(addMedicalInfoVO.getCateName()).size() == 0) {
- retMap.put("message", "术语小类名称不存在");
- return retMap;
- }
- if (libraryInfoListMap.get(addMedicalInfoVO.getGrp()).size() == 0) {
- retMap.put("message", "术语类组不存在");
- return retMap;
- }
- // QueryWrapper<Bodypart> bodypartQe = new QueryWrapper<>();
- // bodypartQe.eq("is_deleted", "N");
- // bodypartQe.eq("bodypart", addMedicalInfoVO.getBodypart());
- // if(bodypartFacade.list(bodypartQe).size()==0){
- // retMap.put("message", "一级部位不存在");
- // return retMap;
- // }
- // bodypartQe.eq("sub_bodypart", addMedicalInfoVO.getSubBodypart());
- // if(bodypartFacade.list(bodypartQe).size()==0){
- // retMap.put("message", "二级部位不存在");
- // return retMap;
- // }
- String currentUser = UserUtils.getCurrentPrincipleID();
- Date now = DateUtil.now();
- QueryWrapper<Medical> medicalQe = new QueryWrapper<>();
- medicalQe.eq("concept_id", libraryInfo.getConceptId());
- Medical medical = this.getOne(medicalQe);
- if (medical == null) {
- medical = new Medical();
- medical.setCreator(currentUser);
- medical.setGmtCreated(now);
- }
- medical.setIsDeleted("N");
- medical.setModifier(currentUser);
- medical.setGmtModified(now);
- medical.setConceptId(libraryInfo.getConceptId());
- BeanUtil.copyProperties(addMedicalInfoVO, medical);
- retMap.put("medical", medical);
- return retMap;
- }
- /**
- * 术语医学属性excel文件导入
- *
- * @param file
- * @return
- */
- public Boolean medicalInfoExcelIm(MultipartFile file) {
- List<AddMedicalInfoVO> addMedicalInfoVOList = new ArrayList<>();
- StringBuffer sbf = new StringBuffer();
- InputStream inputStream = null;
- Workbook wb = null;
- try {
- if (!file.isEmpty()) {
- inputStream = file.getInputStream();
- if (inputStream.available() > 512000) {
- sbf.append("文件最大支持500KB!").append("<br/>");
- } else {
- String fileName = file.getOriginalFilename();
- if (fileName.lastIndexOf(".") != -1) {
- String type = fileName.substring(fileName.lastIndexOf("."));
- if (type.equals(".xls")) {
- wb = new HSSFWorkbook(inputStream);
- } else if (type.equals(".xlsx")) {
- wb = new XSSFWorkbook(inputStream);
- }
- if (wb != null) {
- Sheet sheet = wb.getSheetAt(0);
- int count = 0;
- String conceptName, conceptType, name, stdName, cateName, grp, gender, minAge, maxAge, bodypart, subBodypart, displayOrder, dept, code, note;
- Integer minAge_, maxAge_;
- for (Row row : sheet) {
- count++;
- if (count == 1 || row == null) {
- continue;
- }
- conceptName = getValue(row.getCell(0)).trim().replace(" ", "");
- conceptType = getValue(row.getCell(1)).trim().replace(" ", "");
- name = getValue(row.getCell(2)).trim().replace(" ", "");
- stdName = getValue(row.getCell(3)).trim().replace(" ", "");
- cateName = getValue(row.getCell(4)).trim().replace(" ", "");
- grp = getValue(row.getCell(5)).trim().replace(" ", "");
- gender = getValue(row.getCell(6)).trim().replace(" ", "");
- minAge = getValue(row.getCell(7)).trim().replace(" ", "");
- maxAge = getValue(row.getCell(8)).trim().replace(" ", "");
- bodypart = getValue(row.getCell(9)).trim().replace(" ", "");
- subBodypart = getValue(row.getCell(10)).trim().replace(" ", "");
- displayOrder = getValue(row.getCell(11)).trim().replace(" ", "");
- dept = getValue(row.getCell(12)).trim().replace(" ", "");
- code = getValue(row.getCell(13)).trim().replace(" ", "");
- note = getValue(row.getCell(14)).trim().replace(" ", "");
- if (StringUtil.isEmpty(conceptName) && StringUtil.isEmpty(name)
- && StringUtil.isEmpty(stdName) && StringUtil.isEmpty(cateName)
- && StringUtil.isEmpty(grp) && StringUtil.isEmpty(gender)
- && StringUtil.isEmpty(minAge) && StringUtil.isEmpty(maxAge)
- && StringUtil.isEmpty(bodypart) && StringUtil.isEmpty(subBodypart)
- && StringUtil.isEmpty(displayOrder) && StringUtil.isEmpty(dept)
- && StringUtil.isEmpty(code) && StringUtil.isEmpty(note)
- && StringUtil.isEmpty(conceptType)) {
- continue;
- }
- if (StringUtil.isEmpty(conceptName) || StringUtil.isEmpty(name)
- || StringUtil.isEmpty(stdName) || StringUtil.isEmpty(cateName)
- || StringUtil.isEmpty(grp) || StringUtil.isEmpty(gender)
- || StringUtil.isEmpty(minAge) || StringUtil.isEmpty(maxAge)
- || StringUtil.isEmpty(bodypart) || StringUtil.isEmpty(subBodypart)
- || StringUtil.isEmpty(dept) || StringUtil.isEmpty(conceptType)) {
- sbf.append("第" + count + "行数据不完整;").append("<br/>");
- continue;
- }
- if (!gender.equals("1") && !gender.equals("2") && !gender.equals("3")) {
- sbf.append("第" + count + "行数据中性别非1、2、3;").append("<br/>");
- continue;
- }
- AddMedicalInfoVO addMedicalInfoVO = new AddMedicalInfoVO();
- addMedicalInfoVO.setConceptName(conceptName);
- addMedicalInfoVO.setConceptType(conceptType);
- addMedicalInfoVO.setName(name);
- addMedicalInfoVO.setStdName(stdName);
- addMedicalInfoVO.setCateName(cateName);
- addMedicalInfoVO.setGrp(grp);
- addMedicalInfoVO.setGender(gender);
- addMedicalInfoVO.setBodypart(bodypart);
- addMedicalInfoVO.setSubBodypart(subBodypart);
- addMedicalInfoVO.setDisplayOrder(displayOrder);
- addMedicalInfoVO.setDept(dept);
- addMedicalInfoVO.setCode(code);
- addMedicalInfoVO.setNote(note);
- try {
- minAge_ = Integer.parseInt(minAge);
- maxAge_ = Integer.parseInt(maxAge);
- } catch (Exception e) {
- minAge_ = null;
- maxAge_ = null;
- }
- if (minAge_ == null || maxAge_ == null) {
- sbf.append("第" + count + "行数据中年龄非整数;").append("<br/>");
- continue;
- }
- addMedicalInfoVO.setMinAge(minAge_);
- addMedicalInfoVO.setMaxAge(maxAge_);
- addMedicalInfoVOList.add(addMedicalInfoVO);
- }
- } else {
- sbf.append("非excel文件无法解析!").append("<br/>");
- }
- } else {
- sbf.append("未知文件无法解析!").append("<br/>");
- }
- }
- } else {
- sbf.append("无文件上传!").append("<br/>");
- }
- } catch (Exception e) {
- sbf.append("解析失败!").append("<br/>");
- } finally {
- try {
- if (wb != null) {
- wb.close();
- }
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (Exception e) {
- }
- }
- /*****************excel文件本身问题提醒************************/
- if (sbf.length() > 0) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- /****************excel文件中所有术语概念存在重复提示---术语概念名称和类型一样即重复***********************/
- Map<String, List<AddMedicalInfoVO>> addMedicalInfoVOListMap = addMedicalInfoVOList.stream().collect(Collectors.groupingBy(AddMedicalInfoVO::getConceptName));
- for (String key : addMedicalInfoVOListMap.keySet()) {
- if (addMedicalInfoVOListMap.get(key).size() > 1 && addMedicalInfoVOListMap.get(key).stream().map(i -> i.getConceptType()).distinct().count() == 1) {
- sbf.append(key).append(" ");
- }
- }
- if (sbf.length() > 0) {
- sbf.append("(术语概念名称存在重复)");
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- /**************校验每一组数据,同时组装*************************/
- List<Medical> saveOrUpdateMedicalList = new ArrayList<>();
- Map<String, Object> ckMap = null;
- Object message = null;
- for (AddMedicalInfoVO i : addMedicalInfoVOList) {
- ckMap = checkAddMedicalInfoVO(i);
- message = ckMap.get("message");
- if (message != null) {
- sbf.append(message.toString()).append("(").append(i.getConceptName()).append(")").append("<br/>");
- } else {
- saveOrUpdateMedicalList.add((Medical) (ckMap.get("medical")));
- }
- }
- if (sbf.length() > 0) {
- throw new CommonException(CommonErrorCode.RPC_ERROR, sbf.toString());
- }
- return medicalService.saveOrUpdateBatch(saveOrUpdateMedicalList);
- }
- @SuppressWarnings("deprecation")
- private String getValue(Cell cell) {
- try {
- Object obj = null;
- switch (cell.getCellTypeEnum()) {
- case BOOLEAN:
- obj = cell.getBooleanCellValue();
- break;
- case ERROR:
- obj = cell.getErrorCellValue();
- break;
- case NUMERIC:
- if (HSSFDateUtil.isCellDateFormatted(cell)) {
- Date date = cell.getDateCellValue();
- obj = DateFormatUtils.format(date, "yyyy-MM-dd");
- } else {
- obj = cell.getNumericCellValue();
- DecimalFormat df = new DecimalFormat("0");
- obj = df.format(obj);
- }
- break;
- case STRING:
- obj = cell.getStringCellValue();
- break;
- default:
- break;
- }
- return obj.toString();
- } catch (Exception e) {
- return "";
- }
- }
- }
|