|
@@ -0,0 +1,119 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.diagbot.dto.PlanDetailDTO;
|
|
|
+import com.diagbot.dto.PlanInfoDefaultDTO;
|
|
|
+import com.diagbot.entity.Plan;
|
|
|
+import com.diagbot.entity.PlanDetail;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.vo.HospitalSetVO;
|
|
|
+import com.diagbot.vo.PlanDefaultVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wangfeng
|
|
|
+ * @Description:
|
|
|
+ * @date 2020-11-20 9:32
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class PlanDefaultFacade {
|
|
|
+ @Autowired
|
|
|
+ PlanDetailFacade planDetailFacade;
|
|
|
+ @Autowired
|
|
|
+ PlanFacade planFacade;
|
|
|
+
|
|
|
+ public Boolean addDefaultPlans(PlanDefaultVO planDefaultVO) {
|
|
|
+ boolean res = false;
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ List<String> planCode = Arrays.asList("plan_default","patientia","info","chief","symptom","other","vital","lis","pacs","diag","doc_advice");
|
|
|
+ if(ListUtil.isEmpty(planCode)){
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "方案编码不能为空!");
|
|
|
+ }
|
|
|
+ for (String str:planCode) {
|
|
|
+ PlanInfoDefaultDTO data = new PlanInfoDefaultDTO();
|
|
|
+ QueryWrapper<Plan> planFand = new QueryWrapper<>();
|
|
|
+ planFand.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("plan_code", str)
|
|
|
+ .eq("hospital_id", -1L);
|
|
|
+ Plan plan = planFacade.getOne(planFand, false);
|
|
|
+ BeanUtil.copyProperties(plan, data);
|
|
|
+ List<Long> planId = new ArrayList<>();
|
|
|
+ planId.add(plan.getId());
|
|
|
+ HospitalSetVO hospitalSetVO = new HospitalSetVO();
|
|
|
+ hospitalSetVO.setHospitalId(-1L);
|
|
|
+ hospitalSetVO.setPlanId(planId);
|
|
|
+ List<PlanDetailDTO> sysSetInfoData = planDetailFacade.getSysSetInfoData(hospitalSetVO);
|
|
|
+ data.setPlanDetailDefault(sysSetInfoData);
|
|
|
+ //先效验改医院下是否存在该方案
|
|
|
+ int countTow = planFacade.count(new QueryWrapper<Plan>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", planDefaultVO.getHospitalId())
|
|
|
+ .eq("plan_code", str));
|
|
|
+ if (countTow > 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, str+"该方案编码已存在");
|
|
|
+ }
|
|
|
+ //保存方案配置
|
|
|
+ if (plan != null) {
|
|
|
+ Plan planDefault = new Plan();
|
|
|
+ planDefault.setHospitalId(planDefaultVO.getHospitalId());
|
|
|
+ planDefault.setPlanCode(plan.getPlanCode());
|
|
|
+ planDefault.setPlanName(plan.getPlanName());
|
|
|
+ planDefault.setPlanStatus(1);
|
|
|
+ planDefault.setRemark("0");
|
|
|
+ planDefault.setModifier("-1");
|
|
|
+ planDefault.setCreator("-1");
|
|
|
+ planDefault.setGmtModified(now);
|
|
|
+ planDefault.setGmtCreate(now);
|
|
|
+ res = planFacade.save(planDefault);
|
|
|
+ if (res) {
|
|
|
+ Long planIdDetail = planDefault.getId();
|
|
|
+ List<PlanDetailDTO> PlanDetailDefault = new ArrayList<>();
|
|
|
+ for (PlanDetailDTO dataDetail : sysSetInfoData) {
|
|
|
+ //先保存父类
|
|
|
+ PlanDetail planDetailParent = new PlanDetail();
|
|
|
+ planDetailParent.setParentId(-1L);
|
|
|
+ planDetailParent.setPlanId(planIdDetail);
|
|
|
+ planDetailParent.setName(dataDetail.getName());
|
|
|
+ planDetailParent.setCode(dataDetail.getCode());
|
|
|
+ planDetailParent.setHospitalId(planDefaultVO.getHospitalId());
|
|
|
+ planDetailParent.setStatus(1);
|
|
|
+ planDetailParent.setOrderNo(dataDetail.getOrderNo());
|
|
|
+ planDetailParent.setNumber(dataDetail.getNumber());
|
|
|
+ res = planDetailFacade.save(planDetailParent);
|
|
|
+ if (res) {
|
|
|
+ Long parentIdSub = planDetailParent.getId();
|
|
|
+ List<PlanDetailDTO> planDetails = dataDetail.getPlanDetails();
|
|
|
+ if (ListUtil.isNotEmpty(planDetails)) {
|
|
|
+ for (PlanDetailDTO detail : planDetails) {
|
|
|
+ //再保存子类
|
|
|
+ PlanDetail planDetailSub = new PlanDetail();
|
|
|
+ planDetailSub.setParentId(parentIdSub);
|
|
|
+ planDetailSub.setPlanId(planIdDetail);
|
|
|
+ planDetailSub.setName(detail.getName());
|
|
|
+ planDetailSub.setCode(detail.getCode());
|
|
|
+ planDetailSub.setHospitalId(planDefaultVO.getHospitalId());
|
|
|
+ planDetailSub.setStatus(1);
|
|
|
+ planDetailSub.setOrderNo(detail.getOrderNo());
|
|
|
+ planDetailSub.setNumber(detail.getNumber());
|
|
|
+ res = planDetailFacade.save(planDetailSub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+}
|