Browse Source

优化代码

gaodm 6 years ago
parent
commit
dc6081e0d2

+ 1 - 6
icssman-service/src/main/java/com/diagbot/facade/DeptVitalFacade.java

@@ -170,12 +170,7 @@ public class DeptVitalFacade extends DeptVitalServiceImpl {
                 notIn("id", vitalIds).
                 eq("type", QuestionTypeEnum.Vital.getKey());
         List<QuestionInfo> unSelectedVitalList = questionFacade.list(unSelectedVitalQueryWrapper);
-        List<QuestionShortDTO> unSelectedVitals = Lists.newArrayList();
-        for (QuestionInfo questionInfo : unSelectedVitalList) {
-            QuestionShortDTO questionShortDTO = new QuestionShortDTO();
-            BeanUtil.copyProperties(questionInfo, questionShortDTO);
-            unSelectedVitals.add(questionShortDTO);
-        }
+        List<QuestionShortDTO> unSelectedVitals = BeanUtil.listCopyTo(unSelectedVitalList, QuestionShortDTO.class);
         deptVitalDTO.setUnSelectedVitals(unSelectedVitals);
         return deptVitalDTO;
     }

+ 2 - 9
icssman-service/src/main/java/com/diagbot/facade/DisclaimerInformationFacade.java

@@ -13,6 +13,7 @@ import com.diagbot.enums.StatusEnum;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
 import com.diagbot.service.impl.DisclaimerInformationServiceImpl;
+import com.diagbot.util.BeanUtil;
 import com.diagbot.util.DateUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.util.UserUtils;
@@ -70,16 +71,8 @@ public class DisclaimerInformationFacade extends DisclaimerInformationServiceImp
         List<DisclaimerInformationDTO> dataNew = new ArrayList<DisclaimerInformationDTO>();
         for (DisclaimerInformationDTO disclaimerInformationDTO : data) {
             DisclaimerInformationDTO dis = new DisclaimerInformationDTO();
-            dis.setId(disclaimerInformationDTO.getId());
-            dis.setDescription(disclaimerInformationDTO.getDescription());
-            dis.setDisclaimerCode(disclaimerInformationDTO.getDisclaimerCode());
-            dis.setGmtCreate(disclaimerInformationDTO.getGmtCreate());
+            BeanUtil.copyProperties(disclaimerInformationDTO, dis);
             dis.setModifier(userNames.get(disclaimerInformationDTO.getModifier()));
-            dis.setOrderNo(disclaimerInformationDTO.getOrderNo());
-            dis.setRemark(disclaimerInformationDTO.getRemark());
-            dis.setStatus(disclaimerInformationDTO.getStatus());
-            dis.setTitle(disclaimerInformationDTO.getTitle());
-            //dis.setVersionId(disclaimerInformationDTO.getVersionId());
 
             dataNew.add(dis);
         }

+ 6 - 12
icssman-service/src/main/java/com/diagbot/facade/IntroduceInfoFacade.java

@@ -297,12 +297,9 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
                 .eq("sub_type",0)
                 .notIn("id", questionIds);
         List<QuestionInfo> unRelatedQuestionList = questionFacade.list(unRelatedQuestionWrapper);
-        List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
-        for (QuestionInfo questionInfo : unRelatedQuestionList) {
-            QuestionShortDTO questionShortDTO = new QuestionShortDTO();
-            BeanUtil.copyProperties(questionInfo, questionShortDTO);
-            unRelatedQuestionDTOList.add(questionShortDTO);
-        }
+
+        List<QuestionShortDTO> unRelatedQuestionDTOList
+                = BeanUtil.listCopyTo(unRelatedQuestionList, QuestionShortDTO.class);
         introducePageDTO.setUnRelatedQuestionList(unRelatedQuestionDTOList);
 
         return introducePageDTO;
@@ -318,12 +315,9 @@ public class IntroduceInfoFacade extends IntroduceInfoServiceImpl {
         unRelatedQuestionWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
                 .eq("sub_type",0);
         List<QuestionInfo> unRelatedQuestionList = questionFacade.list(unRelatedQuestionWrapper);
-        List<QuestionShortDTO> unRelatedQuestionDTOList = Lists.newLinkedList();
-        for (QuestionInfo questionInfo : unRelatedQuestionList) {
-            QuestionShortDTO questionShortDTO = new QuestionShortDTO();
-            BeanUtil.copyProperties(questionInfo, questionShortDTO);
-            unRelatedQuestionDTOList.add(questionShortDTO);
-        }
+
+        List<QuestionShortDTO> unRelatedQuestionDTOList
+                = BeanUtil.listCopyTo(unRelatedQuestionList, QuestionShortDTO.class);
         return unRelatedQuestionDTOList;
     }
 }

+ 68 - 69
icssman-service/src/main/java/com/diagbot/facade/ModuleInfoFacade.java

@@ -37,6 +37,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Description:
@@ -86,47 +87,48 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param addModulInfoVO
      * @return
      */
-    public Boolean saveModuleInfo(AddModuleInfoVO addModulInfoVO){
+    public Boolean saveModuleInfo(AddModuleInfoVO addModulInfoVO) {
         String userId = UserUtils.getCurrentPrincipleID();
         Date now = DateUtil.now();
         //查询该模板是否添加过
         QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
         moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
-                .eq("name",addModulInfoVO.getName());
+                .eq("name", addModulInfoVO.getName());
         ModuleInfo moduleInfos = this.getOne(moduleInfoQueryWrapper);
-        if(null != moduleInfos){
+        if (null != moduleInfos) {
             throw new CommonException(CommonErrorCode.INSERT_DATA_FAILED,
                     "模板名重复,请勿重复添加");
         }
         ModuleInfo moduleInfo = new ModuleInfo();
-        BeanUtil.copyProperties(addModulInfoVO,moduleInfo);
+        BeanUtil.copyProperties(addModulInfoVO, moduleInfo);
         moduleInfo.setCreator(userId);
         moduleInfo.setModifier(userId);
         moduleInfo.setGmtCreate(now);
         moduleInfo.setGmtModified(now);
         this.save(moduleInfo);
         Long moduleId = moduleInfo.getId();
-        return moduleDetailFacade.saveOrUpdateInfos(addModulInfoVO,moduleId);
+        return moduleDetailFacade.saveOrUpdateInfos(addModulInfoVO, moduleId);
     }
+
     /**
      * 修改模板
      *
      * @param updateModuleInfoVO
      * @return
      */
-    public Boolean updateModuleInfo(UpdateModuleInfoVO updateModuleInfoVO){
+    public Boolean updateModuleInfo(UpdateModuleInfoVO updateModuleInfoVO) {
         String userId = UserUtils.getCurrentPrincipleID();
         UpdateWrapper<ModuleInfo> moduleInfoUpdateWrapper = new UpdateWrapper<>();
         moduleInfoUpdateWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
-                .eq("id",updateModuleInfoVO.getId())
-                .set("name",updateModuleInfoVO.getName())
-                .set("type",updateModuleInfoVO.getType())
-                .set("modifier",userId)
-                .set("gmt_modified",DateUtil.now());
-        this.update(new ModuleInfo(),moduleInfoUpdateWrapper);
+                .eq("id", updateModuleInfoVO.getId())
+                .set("name", updateModuleInfoVO.getName())
+                .set("type", updateModuleInfoVO.getType())
+                .set("modifier", userId)
+                .set("gmt_modified", DateUtil.now());
+        this.update(new ModuleInfo(), moduleInfoUpdateWrapper);
         AddModuleInfoVO addModuleInfoVO = new AddModuleInfoVO();
-        BeanUtil.copyProperties(updateModuleInfoVO,addModuleInfoVO);
-        return moduleDetailFacade.saveOrUpdateInfos(addModuleInfoVO,updateModuleInfoVO.getId());
+        BeanUtil.copyProperties(updateModuleInfoVO, addModuleInfoVO);
+        return moduleDetailFacade.saveOrUpdateInfos(addModuleInfoVO, updateModuleInfoVO.getId());
     }
 
     /**
@@ -135,7 +137,7 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param moduleGetQuestionInfoVO
      * @return
      */
-    public List<GetQuestionInfoDTO> getQuestionInfos(ModuleGetQuestionInfoVO moduleGetQuestionInfoVO){
+    public List<GetQuestionInfoDTO> getQuestionInfos(ModuleGetQuestionInfoVO moduleGetQuestionInfoVO) {
         List<GetQuestionInfoDTO> getQuestionInfoDTOS = questionFacade.moduleGetQuestiongInfoByName(moduleGetQuestionInfoVO);
         return getQuestionInfoDTOS;
     }
@@ -146,45 +148,42 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param getModuleInfoVO
      * @return
      */
-    public List<ModuleInfoDTO> getModuleInfo(GetModuleInfoVO getModuleInfoVO){
+    public List<ModuleInfoDTO> getModuleInfo(GetModuleInfoVO getModuleInfoVO) {
         //获取模板信息
         QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
-        moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey());
-        if(getModuleInfoVO.getType() != null){
-            moduleInfoQueryWrapper.eq("type",getModuleInfoVO.getType());
+        moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
+        if (getModuleInfoVO.getType() != null) {
+            moduleInfoQueryWrapper.eq("type", getModuleInfoVO.getType());
         }
         List<ModuleInfo> moduleInfoList = this.list(moduleInfoQueryWrapper);
-        List<Long> moduleIdList = new ArrayList<>();
-        for (ModuleInfo moduleInfo:moduleInfoList) {
-            moduleIdList.add(moduleInfo.getId());
-        }
+        List<Long> moduleIdList = moduleInfoList.stream().map(m -> m.getId()).collect(Collectors.toList());
         //获取模板明细信息
         QueryWrapper<ModuleDetail> moduleDetailQueryWrapper = new QueryWrapper<>();
-        moduleDetailQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
-            .in("module_id",moduleIdList);
+        moduleDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .in("module_id", moduleIdList);
         List<ModuleDetail> moduleDetailList = moduleDetailFacade.list(moduleDetailQueryWrapper);
         //将模板明细根据模板id放入map
-        Map<Long,List<ModuleDetail>> moduleDetailMap = new HashMap<>();
+        Map<Long, List<ModuleDetail>> moduleDetailMap = new HashMap<>();
         List<ModuleDetail> allModuleDetials = null;
-        for (ModuleInfo moduleInfo:moduleInfoList) {
+        for (ModuleInfo moduleInfo : moduleInfoList) {
             allModuleDetials = new ArrayList<>();
-            for (ModuleDetail moduleDetail:moduleDetailList) {
-               if(moduleInfo.getId().longValue() == moduleDetail.getModuleId().longValue()){
-                   allModuleDetials.add(moduleDetail);
-               }
+            for (ModuleDetail moduleDetail : moduleDetailList) {
+                if (moduleInfo.getId().longValue() == moduleDetail.getModuleId().longValue()) {
+                    allModuleDetials.add(moduleDetail);
+                }
             }
-            moduleDetailMap.put(moduleInfo.getId(),allModuleDetials);
+            moduleDetailMap.put(moduleInfo.getId(), allModuleDetials);
         }
         //给ModuleInfoDTO设值
         List<ModuleInfoDTO> moduleInfoDTOList = new ArrayList<>();
         ModuleInfoDTO moduleInfoDTO = null;
-            for (ModuleInfo moduleInfo:moduleInfoList) {
-                moduleInfoDTO = new ModuleInfoDTO();
-                moduleInfoDTO.setId(moduleInfo.getId());
-                moduleInfoDTO.setName(moduleInfo.getName());
-                moduleInfoDTO.setModuleDetails(moduleDetailMap.get(moduleInfoDTO.getId()));
-                moduleInfoDTOList.add(moduleInfoDTO);
-            }
+        for (ModuleInfo moduleInfo : moduleInfoList) {
+            moduleInfoDTO = new ModuleInfoDTO();
+            moduleInfoDTO.setId(moduleInfo.getId());
+            moduleInfoDTO.setName(moduleInfo.getName());
+            moduleInfoDTO.setModuleDetails(moduleDetailMap.get(moduleInfoDTO.getId()));
+            moduleInfoDTOList.add(moduleInfoDTO);
+        }
         return moduleInfoDTOList;
     }
 
@@ -194,7 +193,7 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param getModuleInfoVO
      * @return
      */
-    public IPage<ModuleInfoListDTO> getModuleInfoList(GetModuleInfoVO getModuleInfoVO){
+    public IPage<ModuleInfoListDTO> getModuleInfoList(GetModuleInfoVO getModuleInfoVO) {
         //获取模板信息
         IPage<ModuleInfoListDTO> moduleInfoDTOIPage = this.getModuleInfoListByType(getModuleInfoVO);
         List<String> ids = new ArrayList<>();
@@ -203,14 +202,14 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
         }
         //获取模板类型名称
         QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
-        dictionaryInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
-            .eq("group_type",4)
-            .eq("return_type",1)
-            .orderByDesc("order_no");
+        dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq("group_type", 4)
+                .eq("return_type", 1)
+                .orderByDesc("order_no");
         List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
-        Map<String,DictionaryInfo> dictionaryInfoMap = new HashMap<>();
-        for (DictionaryInfo dictionaryInfo:dictionaryInfoList) {
-            dictionaryInfoMap.put(dictionaryInfo.getVal(),dictionaryInfo);
+        Map<String, DictionaryInfo> dictionaryInfoMap = new HashMap<>();
+        for (DictionaryInfo dictionaryInfo : dictionaryInfoList) {
+            dictionaryInfoMap.put(dictionaryInfo.getVal(), dictionaryInfo);
         }
         //获取用户信息
         RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(ids);
@@ -232,37 +231,37 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param getModuleDetailInfoVO
      * @return
      */
-    public List<GetModuleDetailInfoDTO> getModuleDetailInfo(GetModuleDetailInfoVO getModuleDetailInfoVO){
+    public List<GetModuleDetailInfoDTO> getModuleDetailInfo(GetModuleDetailInfoVO getModuleDetailInfoVO) {
         List<GetModuleDetailInfoDTO> getModuleDetailInfoDTOList = new ArrayList<>();
         GetModuleDetailInfoDTO getModuleDetailInfoDTO = null;
         //获取模板明细
         QueryWrapper<ModuleDetail> moduleDetailQueryWrapper = new QueryWrapper<>();
-        moduleDetailQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
-            .eq("module_id",getModuleDetailInfoVO.getModuleId());
+        moduleDetailQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq("module_id", getModuleDetailInfoVO.getModuleId());
         List<ModuleDetail> moduleDetailList = moduleDetailFacade.list(moduleDetailQueryWrapper);
         //获取标签信息
         QueryWrapper<QuestionInfo> questionInfoQueryWrapper = new QueryWrapper<>();
-        questionInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey());
+        questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
         List<QuestionInfo> questionInfoList = questionFacade.list(questionInfoQueryWrapper);
-        Map<Long,QuestionInfo> questionInfoMap = new HashMap<>();
+        Map<Long, QuestionInfo> questionInfoMap = new HashMap<>();
         for (QuestionInfo questionInfo : questionInfoList) {
-            questionInfoMap.put(questionInfo.getId(),questionInfo);
+            questionInfoMap.put(questionInfo.getId(), questionInfo);
         }
         //获取模板信息
         QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
-        questionInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey());
+        questionInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
         List<ModuleInfo> moduleInfoList = this.list(moduleInfoQueryWrapper);
-        Map<Long,ModuleInfo> moduleInfoMap = new HashMap<>();
+        Map<Long, ModuleInfo> moduleInfoMap = new HashMap<>();
         for (ModuleInfo moduleInfo : moduleInfoList) {
-            moduleInfoMap.put(moduleInfo.getId(),moduleInfo);
+            moduleInfoMap.put(moduleInfo.getId(), moduleInfo);
         }
         //循环给出参赋值
-        for (ModuleDetail moduleDetail: moduleDetailList) {
+        for (ModuleDetail moduleDetail : moduleDetailList) {
             getModuleDetailInfoDTO = new GetModuleDetailInfoDTO();
-            BeanUtil.copyProperties(moduleDetail,getModuleDetailInfoDTO);
-            if(moduleDetail.getQuestionId() != null){
+            BeanUtil.copyProperties(moduleDetail, getModuleDetailInfoDTO);
+            if (moduleDetail.getQuestionId() != null) {
                 getModuleDetailInfoDTO.setTagName(questionInfoMap.get(moduleDetail.getQuestionId()).getTagName());
-            }else {
+            } else {
                 getModuleDetailInfoDTO.setRelationModuleName(moduleInfoMap.get(moduleDetail.getModuleId()).getName());
             }
             getModuleDetailInfoDTOList.add(getModuleDetailInfoDTO);
@@ -277,22 +276,22 @@ public class ModuleInfoFacade extends ModuleInfoServiceImpl {
      * @param getModuleInfoOneVO
      * @return
      */
-    public GetModuleInfoOneDTO getModuleInfoOne(GetModuleInfoOneVO getModuleInfoOneVO){
+    public GetModuleInfoOneDTO getModuleInfoOne(GetModuleInfoOneVO getModuleInfoOneVO) {
         GetModuleInfoOneDTO getModuleInfoOneDTO = new GetModuleInfoOneDTO();
         //获取模板信息
         QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
-        moduleInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
-            .eq("id",getModuleInfoOneVO.getModuleId());
-        ModuleInfo moduleInfo= this.getOne(moduleInfoQueryWrapper);
+        moduleInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
+                .eq("id", getModuleInfoOneVO.getModuleId());
+        ModuleInfo moduleInfo = this.getOne(moduleInfoQueryWrapper);
         //获取模板类型名称
         QueryWrapper<DictionaryInfo> dictionaryInfoQueryWrapper = new QueryWrapper<>();
-        dictionaryInfoQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey());
+        dictionaryInfoQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
         List<DictionaryInfo> dictionaryInfoList = dictionaryFacade.list(dictionaryInfoQueryWrapper);
-        Map<String,DictionaryInfo> dictionaryInfoMap = new HashMap<>();
-        for (DictionaryInfo dictionaryInfo:dictionaryInfoList) {
-            dictionaryInfoMap.put(dictionaryInfo.getVal(),dictionaryInfo);
+        Map<String, DictionaryInfo> dictionaryInfoMap = new HashMap<>();
+        for (DictionaryInfo dictionaryInfo : dictionaryInfoList) {
+            dictionaryInfoMap.put(dictionaryInfo.getVal(), dictionaryInfo);
         }
-        BeanUtil.copyProperties(moduleInfo,getModuleInfoOneDTO);
+        BeanUtil.copyProperties(moduleInfo, getModuleInfoOneDTO);
         getModuleInfoOneDTO.setAscriptionName(dictionaryInfoMap.get(String.valueOf(moduleInfo.getType())).getName());
         return getModuleInfoOneDTO;
     }