PlanFacade.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package com.diagbot.facade;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.diagbot.dto.PlanDetailDTO;
  6. import com.diagbot.dto.PlanInfoPagesDTO;
  7. import com.diagbot.entity.Plan;
  8. import com.diagbot.enums.IsDeleteEnum;
  9. import com.diagbot.enums.StatusEnum;
  10. import com.diagbot.exception.CommonErrorCode;
  11. import com.diagbot.exception.CommonException;
  12. import com.diagbot.service.impl.PlanServiceImpl;
  13. import com.diagbot.util.BeanUtil;
  14. import com.diagbot.util.DateUtil;
  15. import com.diagbot.util.EntityUtil;
  16. import com.diagbot.util.ListUtil;
  17. import com.diagbot.util.UserUtils;
  18. import com.diagbot.vo.HospitalPlanCancelVO;
  19. import com.diagbot.vo.HospitalPlanPageVO;
  20. import com.diagbot.vo.HospitalPlanSaveVO;
  21. import com.diagbot.vo.PlanRevStopVO;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Component;
  24. import java.util.ArrayList;
  25. import java.util.Date;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. /**
  30. * @author wangfeng
  31. * @Description:
  32. * @date 2020-08-07 10:29
  33. */
  34. @Component
  35. public class PlanFacade extends PlanServiceImpl {
  36. @Autowired
  37. PlanDetailFacade planDetailFacade;
  38. /**
  39. * @param hospitalPlanSaveVO
  40. * @return
  41. */
  42. public boolean savePlanInfoDatas(HospitalPlanSaveVO hospitalPlanSaveVO) {
  43. Date now = DateUtil.now();
  44. boolean res = false;
  45. // 校验名称是否相同
  46. int count = this.count(new QueryWrapper<Plan>()
  47. .eq("is_deleted", IsDeleteEnum.N.getKey())
  48. .eq("hospital_id", hospitalPlanSaveVO.getHospitalId())
  49. .eq("plan_name", hospitalPlanSaveVO.getPlanName())
  50. .eq("plan_code", hospitalPlanSaveVO.getPlanCode())
  51. .ne("id", hospitalPlanSaveVO.getId() == null ? -1 : hospitalPlanSaveVO.getId()));
  52. if (count > 0) {
  53. throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "相同【医院】下,方案名称已存在");
  54. }
  55. if (hospitalPlanSaveVO.getId() != null) {
  56. UpdateWrapper<Plan> planQuery = new UpdateWrapper<>();
  57. planQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
  58. .eq("id", hospitalPlanSaveVO.getId())
  59. .set("gmt_modified",now)
  60. .set("gmt_create", now)
  61. .set("creator",UserUtils.getCurrentPrincipleID())
  62. .set("modifier",UserUtils.getCurrentPrincipleID())
  63. .set("hospital_id", hospitalPlanSaveVO.getHospitalId())
  64. .set("plan_name", hospitalPlanSaveVO.getPlanName())
  65. .set("plan_code", hospitalPlanSaveVO.getPlanCode())
  66. .set("plan_status", StatusEnum.Enable.getKey());
  67. res = update(new Plan(), planQuery);
  68. } else {
  69. Plan plan = new Plan();
  70. BeanUtil.copyProperties(hospitalPlanSaveVO, plan);
  71. plan.setGmtCreate(now);
  72. plan.setGmtModified(now);
  73. plan.setCreator(UserUtils.getCurrentPrincipleID());
  74. plan.setModifier(UserUtils.getCurrentPrincipleID());
  75. res = this.save(plan);
  76. }
  77. return res;
  78. }
  79. public IPage<PlanInfoPagesDTO> getPlanInfoPage(HospitalPlanPageVO hospitalPlanPageVO) {
  80. IPage<PlanInfoPagesDTO> data = getPlanInfoPageAll(hospitalPlanPageVO);
  81. List<PlanInfoPagesDTO> planInfos = data.getRecords();
  82. // 取版本id查明细
  83. List<Long> ids = new ArrayList<>();
  84. if (planInfos != null) {
  85. // 当查出的数据不为空时,取到版本id,再去版本明细表中查询详细的信息
  86. for (PlanInfoPagesDTO planInfo : planInfos) {
  87. ids.add(planInfo.getId());
  88. }
  89. // 获取明细信息
  90. List<PlanDetailDTO> PlanDetailDatas = planDetailFacade.getByPlanIds(ids);
  91. Map<Long, List<PlanDetailDTO>> map = new HashMap<>();
  92. // 获取所有用户开通的产品信息
  93. map = EntityUtil.makeEntityListMap(PlanDetailDatas, "planId");
  94. if (map.size() > 0) {
  95. for (PlanInfoPagesDTO planInfo : planInfos) {
  96. List<PlanDetailDTO> planDetails = map.get(planInfo.getId());
  97. if (ListUtil.isNotEmpty(planDetails)) {
  98. planInfo.setPlanDetails(planDetails);
  99. }
  100. }
  101. }
  102. }
  103. return data.setRecords(planInfos);
  104. }
  105. public boolean cancelPlanData(HospitalPlanCancelVO hospitalPlanCancelVO) {
  106. boolean res = false;
  107. // 1.先判断数据是否存在有效
  108. checkPlan(hospitalPlanCancelVO.getPlanId());
  109. UpdateWrapper<Plan> planNew = new UpdateWrapper<>();
  110. planNew
  111. .eq("id", hospitalPlanCancelVO.getPlanId())
  112. .eq("is_deleted", IsDeleteEnum.N.getKey())
  113. .set("is_deleted", IsDeleteEnum.Y.getKey())
  114. .set("modifier", UserUtils.getCurrentPrincipleID())
  115. .set("gmt_modified", DateUtil.now());
  116. res = update(new Plan(), planNew);
  117. return res;
  118. }
  119. public boolean revStopPlan(PlanRevStopVO planRevStopVO) {
  120. checkPlan(planRevStopVO.getId());
  121. UpdateWrapper<Plan> planNew = new UpdateWrapper<>();
  122. planNew
  123. .eq("id", planRevStopVO.getId())
  124. .eq("is_deleted", IsDeleteEnum.N.getKey())
  125. .set("plan_status", planRevStopVO.getStatus())
  126. .set("modifier", UserUtils.getCurrentPrincipleID())
  127. .set("gmt_modified", DateUtil.now());
  128. return update(new Plan(), planNew);
  129. }
  130. /**
  131. * 判断数据是否存在有效
  132. *
  133. * @param id
  134. */
  135. private Plan checkPlan(Long id) {
  136. // 1.先判断数据是否存在有效
  137. QueryWrapper<Plan> PlanFand = new QueryWrapper<>();
  138. PlanFand.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("id", id);
  139. Plan plan = getOne(PlanFand, false);
  140. if (null == plan) {
  141. throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据不存在");
  142. }
  143. return plan;
  144. }
  145. }