123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package com.diagbot.facade;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.diagbot.dto.PlanDetailDTO;
- import com.diagbot.dto.PlanInfoPagesDTO;
- import com.diagbot.entity.Plan;
- import com.diagbot.enums.IsDeleteEnum;
- import com.diagbot.enums.StatusEnum;
- import com.diagbot.exception.CommonErrorCode;
- import com.diagbot.exception.CommonException;
- import com.diagbot.service.impl.PlanServiceImpl;
- import com.diagbot.util.BeanUtil;
- import com.diagbot.util.DateUtil;
- import com.diagbot.util.EntityUtil;
- import com.diagbot.util.ListUtil;
- import com.diagbot.util.UserUtils;
- import com.diagbot.vo.HospitalPlanCancelVO;
- import com.diagbot.vo.HospitalPlanPageVO;
- import com.diagbot.vo.HospitalPlanSaveVO;
- import com.diagbot.vo.PlanRevStopVO;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author wangfeng
- * @Description:
- * @date 2020-08-07 10:29
- */
- @Component
- public class PlanFacade extends PlanServiceImpl {
- @Autowired
- PlanDetailFacade planDetailFacade;
- /**
- * @param hospitalPlanSaveVO
- * @return
- */
- public boolean savePlanInfoDatas(HospitalPlanSaveVO hospitalPlanSaveVO) {
- Date now = DateUtil.now();
- boolean res = false;
- // 校验名称是否相同
- int count = this.count(new QueryWrapper<Plan>()
- .eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("hospital_id", hospitalPlanSaveVO.getHospitalId())
- .eq("plan_name", hospitalPlanSaveVO.getPlanName())
- .eq("plan_code", hospitalPlanSaveVO.getPlanCode())
- .ne("id", hospitalPlanSaveVO.getId() == null ? -1 : hospitalPlanSaveVO.getId()));
- if (count > 0) {
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "相同【医院】下,方案名称已存在");
- }
- if (hospitalPlanSaveVO.getId() != null) {
- UpdateWrapper<Plan> planQuery = new UpdateWrapper<>();
- planQuery.eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("id", hospitalPlanSaveVO.getId())
- .set("gmt_modified",now)
- .set("gmt_create", now)
- .set("creator",UserUtils.getCurrentPrincipleID())
- .set("modifier",UserUtils.getCurrentPrincipleID())
- .set("hospital_id", hospitalPlanSaveVO.getHospitalId())
- .set("plan_name", hospitalPlanSaveVO.getPlanName())
- .set("plan_code", hospitalPlanSaveVO.getPlanCode())
- .set("plan_status", StatusEnum.Enable.getKey());
- res = update(new Plan(), planQuery);
- } else {
- Plan plan = new Plan();
- BeanUtil.copyProperties(hospitalPlanSaveVO, plan);
- plan.setGmtCreate(now);
- plan.setGmtModified(now);
- plan.setCreator(UserUtils.getCurrentPrincipleID());
- plan.setModifier(UserUtils.getCurrentPrincipleID());
- res = this.save(plan);
- }
- return res;
- }
- public IPage<PlanInfoPagesDTO> getPlanInfoPage(HospitalPlanPageVO hospitalPlanPageVO) {
- IPage<PlanInfoPagesDTO> data = getPlanInfoPageAll(hospitalPlanPageVO);
- List<PlanInfoPagesDTO> planInfos = data.getRecords();
- // 取版本id查明细
- List<Long> ids = new ArrayList<>();
- if (planInfos != null) {
- // 当查出的数据不为空时,取到版本id,再去版本明细表中查询详细的信息
- for (PlanInfoPagesDTO planInfo : planInfos) {
- ids.add(planInfo.getId());
- }
- // 获取明细信息
- List<PlanDetailDTO> PlanDetailDatas = planDetailFacade.getByPlanIds(ids);
- Map<Long, List<PlanDetailDTO>> map = new HashMap<>();
- // 获取所有用户开通的产品信息
- map = EntityUtil.makeEntityListMap(PlanDetailDatas, "planId");
- if (map.size() > 0) {
- for (PlanInfoPagesDTO planInfo : planInfos) {
- List<PlanDetailDTO> planDetails = map.get(planInfo.getId());
- if (ListUtil.isNotEmpty(planDetails)) {
- planInfo.setPlanDetails(planDetails);
- }
- }
- }
- }
- return data.setRecords(planInfos);
- }
- public boolean cancelPlanData(HospitalPlanCancelVO hospitalPlanCancelVO) {
- boolean res = false;
- // 1.先判断数据是否存在有效
- checkPlan(hospitalPlanCancelVO.getPlanId());
- UpdateWrapper<Plan> planNew = new UpdateWrapper<>();
- planNew
- .eq("id", hospitalPlanCancelVO.getPlanId())
- .eq("is_deleted", IsDeleteEnum.N.getKey())
- .set("is_deleted", IsDeleteEnum.Y.getKey())
- .set("modifier", UserUtils.getCurrentPrincipleID())
- .set("gmt_modified", DateUtil.now());
- res = update(new Plan(), planNew);
- return res;
- }
- public boolean revStopPlan(PlanRevStopVO planRevStopVO) {
- checkPlan(planRevStopVO.getId());
- UpdateWrapper<Plan> planNew = new UpdateWrapper<>();
- planNew
- .eq("id", planRevStopVO.getId())
- .eq("is_deleted", IsDeleteEnum.N.getKey())
- .set("plan_status", planRevStopVO.getStatus())
- .set("modifier", UserUtils.getCurrentPrincipleID())
- .set("gmt_modified", DateUtil.now());
- return update(new Plan(), planNew);
- }
- /**
- * 判断数据是否存在有效
- *
- * @param id
- */
- private Plan checkPlan(Long id) {
- // 1.先判断数据是否存在有效
- QueryWrapper<Plan> PlanFand = new QueryWrapper<>();
- PlanFand.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("id", id);
- Plan plan = getOne(PlanFand, false);
- if (null == plan) {
- throw new CommonException(CommonErrorCode.NOT_EXISTS, "该数据不存在");
- }
- return plan;
- }
- }
|