|
@@ -1,259 +0,0 @@
|
|
|
-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.client.UserServiceClient;
|
|
|
-import com.diagbot.dto.GetAllDeptsDTO;
|
|
|
-import com.diagbot.dto.GetDeptInfoDTO;
|
|
|
-import com.diagbot.dto.GetDeptNameDTO;
|
|
|
-import com.diagbot.dto.GetQuestionUsualAndTypeDTO;
|
|
|
-import com.diagbot.dto.RespDTO;
|
|
|
-import com.diagbot.entity.DeptInfo;
|
|
|
-import com.diagbot.entity.ModuleDetail;
|
|
|
-import com.diagbot.entity.ModuleInfo;
|
|
|
-import com.diagbot.entity.QuestionUsual;
|
|
|
-import com.diagbot.enums.IsDeleteEnum;
|
|
|
-import com.diagbot.exception.CommonErrorCode;
|
|
|
-import com.diagbot.exception.CommonException;
|
|
|
-import com.diagbot.service.impl.DeptInfoServiceImpl;
|
|
|
-import com.diagbot.util.BeanUtil;
|
|
|
-import com.diagbot.util.DateUtil;
|
|
|
-import com.diagbot.util.ListUtil;
|
|
|
-import com.diagbot.util.UserUtils;
|
|
|
-import com.diagbot.vo.AddDeptInfoVO;
|
|
|
-import com.diagbot.vo.DeleteDeptInfoVO;
|
|
|
-import com.diagbot.vo.GetAllDeptsVO;
|
|
|
-import com.diagbot.vo.GetDeptInfoDetialsVO;
|
|
|
-import com.diagbot.vo.GetDeptInfoVO;
|
|
|
-import com.diagbot.vo.GetQuestionUsualAndTypeVO;
|
|
|
-import com.diagbot.vo.UpdateDeptInfoVO;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description:
|
|
|
- * @Author:zhaops
|
|
|
- * @time: 2018/11/22 11:44
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class DeptInfoFacade extends DeptInfoServiceImpl {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private UserServiceClient userServiceClient;
|
|
|
- @Autowired
|
|
|
- private QuestionUsualFacade questionUsualFacade;
|
|
|
- @Autowired
|
|
|
- ModuleInfoFacade moduleInfoFacade;
|
|
|
- @Autowired
|
|
|
- ModuleDetailFacade moduleDetailFacade;
|
|
|
- /**
|
|
|
- * 添加科室信息
|
|
|
- *
|
|
|
- * @param addDeptInfoVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean addDeptInfo(AddDeptInfoVO addDeptInfoVO) {
|
|
|
- //判断科室是否重名
|
|
|
- QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- queryWrapper.eq("name", addDeptInfoVO.getName());
|
|
|
- if (this.count(queryWrapper) > 0) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "添加失败,科室已存在");
|
|
|
- }
|
|
|
- //添加科室
|
|
|
- DeptInfo deptInfo = new DeptInfo();
|
|
|
- BeanUtil.copyProperties(addDeptInfoVO, deptInfo);
|
|
|
- Date now = DateUtil.now();
|
|
|
- String userId = UserUtils.getCurrentPrincipleID();
|
|
|
- deptInfo.setCreator(userId);
|
|
|
- deptInfo.setGmtCreate(now);
|
|
|
- deptInfo.setGmtModified(now);
|
|
|
- deptInfo.setModifier(userId);
|
|
|
- this.save(deptInfo);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改科室信息
|
|
|
- *
|
|
|
- * @param updateDeptInfoVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean updateDeptInfo(UpdateDeptInfoVO updateDeptInfoVO) {
|
|
|
- //判断科室是否已被删除
|
|
|
- if(deptInfoIsDeletedStatus(Long.parseLong(updateDeptInfoVO.getId()))){
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS,
|
|
|
- "科室已删除");
|
|
|
- }
|
|
|
- //判断科室是否重名
|
|
|
- Boolean boole = false;
|
|
|
- QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .notIn("id",updateDeptInfoVO.getId());
|
|
|
- List<DeptInfo> deptInfoList = this.list(queryWrapper);
|
|
|
- for (DeptInfo deptInfo: deptInfoList) {
|
|
|
- if(updateDeptInfoVO.getName().equals(deptInfo.getName())){
|
|
|
- boole = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if(boole){
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS,
|
|
|
- "科室名称重复");
|
|
|
- }
|
|
|
- //修改操作
|
|
|
- DeptInfo deptInfo = this.getById(updateDeptInfoVO.getId());
|
|
|
- BeanUtil.copyProperties(updateDeptInfoVO, deptInfo);
|
|
|
- deptInfo.setModifier(UserUtils.getCurrentPrincipleID());
|
|
|
- deptInfo.setGmtModified(DateUtil.now());
|
|
|
- this.updateById(deptInfo);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 删除科室信息
|
|
|
- *
|
|
|
- * @param deleteDeptInfoVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean deleteDeptInfo(DeleteDeptInfoVO deleteDeptInfoVO) {
|
|
|
- Date now = DateUtil.now();
|
|
|
- String person = UserUtils.getCurrentPrincipleID();
|
|
|
- //判断科室是否已被删除
|
|
|
- if(deptInfoIsDeletedStatus(Long.parseLong(deleteDeptInfoVO.getId()))){
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS,
|
|
|
- "科室已删除");
|
|
|
- }
|
|
|
- QueryWrapper<QuestionUsual> questionUsualQueryWrapper = new QueryWrapper<>();
|
|
|
- questionUsualQueryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .eq("dept_id",deleteDeptInfoVO.getId());
|
|
|
- if(questionUsualFacade.count(questionUsualQueryWrapper) > 0){
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS,
|
|
|
- "与常用标签关联未删除");
|
|
|
- }
|
|
|
- //删除操作
|
|
|
- DeptInfo deptInfo = new DeptInfo();
|
|
|
- deptInfo.setId(Long.parseLong(deleteDeptInfoVO.getId()));
|
|
|
- deptInfo.setModifier(person);
|
|
|
- deptInfo.setIsDeleted(IsDeleteEnum.Y.getKey());
|
|
|
- deptInfo.setGmtModified(now);
|
|
|
- this.updateById(deptInfo);
|
|
|
- //删除慢病模板
|
|
|
- QueryWrapper<ModuleInfo> moduleInfoQueryWrapper = new QueryWrapper<>();
|
|
|
- moduleInfoQueryWrapper.eq("relation_id",deleteDeptInfoVO.getId())
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- List<ModuleInfo> moduleInfoList = moduleInfoFacade.list(moduleInfoQueryWrapper);
|
|
|
- List<Long> moduleIds = moduleInfoList.stream().map(ModuleInfo::getId).collect(Collectors.toList());
|
|
|
- moduleInfoFacade.update(new ModuleInfo(), new UpdateWrapper<ModuleInfo>()
|
|
|
- .in("id", moduleIds)
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .set("gmt_modified", now)
|
|
|
- .set("modifier", person)
|
|
|
- .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
- //删除模板明细
|
|
|
- moduleDetailFacade.update(new ModuleDetail(), new UpdateWrapper<ModuleDetail>()
|
|
|
- .in("module_id", moduleIds)
|
|
|
- .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .set("gmt_modified", now)
|
|
|
- .set("modifier", person)
|
|
|
- .set("is_deleted", IsDeleteEnum.Y.getKey()));
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取科室信息
|
|
|
- *
|
|
|
- * @param getDeptInfoVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public IPage<GetDeptInfoDTO> getDeptInfo(GetDeptInfoVO getDeptInfoVO) {
|
|
|
- IPage<GetDeptInfoDTO> iPage = this.getDeptInfos(getDeptInfoVO);
|
|
|
- RespDTO<Map<String, String>> respDTO = new RespDTO<>();
|
|
|
- if (ListUtil.isNotEmpty(iPage.getRecords())) {
|
|
|
- List<String> ids = new ArrayList<>();
|
|
|
- for (GetDeptInfoDTO getDeptInfoDTO : iPage.getRecords()) {
|
|
|
- ids.add(getDeptInfoDTO.getModifier());
|
|
|
- }
|
|
|
- //获取用户信息
|
|
|
- respDTO = userServiceClient.getUserInfoByIds(ids);
|
|
|
- if (respDTO == null || !CommonErrorCode.OK.getCode().equals(respDTO.code)) {
|
|
|
- throw new CommonException(CommonErrorCode.RPC_ERROR,
|
|
|
- "获取用户信息失败");
|
|
|
- }
|
|
|
- //将用户信息放入实体
|
|
|
- for (GetDeptInfoDTO getDeptInfoDTO : iPage.getRecords()) {
|
|
|
- getDeptInfoDTO.setUserName(respDTO.data.get(getDeptInfoDTO.getModifier()));
|
|
|
- }
|
|
|
- }
|
|
|
- return iPage;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 常用标签维护获取科室名称
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<GetDeptNameDTO> getAllDeptInfo(GetQuestionUsualAndTypeVO getQuestionUsualAndTypeVO) {
|
|
|
- //查询当前类型已经添加过得常用标签所关联的科室
|
|
|
- List<GetQuestionUsualAndTypeDTO> getQuestionUsualAndTypeDTOS = questionUsualFacade.getQuestionUsualByDeptIds(getQuestionUsualAndTypeVO);
|
|
|
- List<Long> deptIds = getQuestionUsualAndTypeDTOS.stream().map(getQuestionUsualAndTypeDTO -> getQuestionUsualAndTypeDTO.getDeptId()).collect(Collectors.toList());
|
|
|
- //查询科室信息过滤掉已经添加过得科室
|
|
|
- QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .notIn("id",deptIds);
|
|
|
- List<DeptInfo> deptInfoList = this.list(queryWrapper);
|
|
|
- List<GetDeptNameDTO> getDeptNameDTOS = BeanUtil.listCopyTo(deptInfoList,GetDeptNameDTO.class);
|
|
|
- return getDeptNameDTOS;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 科室维护详情
|
|
|
- *
|
|
|
- * @param getDeptInfoDetialsVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public DeptInfo getDeptInfoDetials(GetDeptInfoDetialsVO getDeptInfoDetialsVO) {
|
|
|
- QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted",IsDeleteEnum.N.getKey())
|
|
|
- .eq("id",getDeptInfoDetialsVO.getId());
|
|
|
- DeptInfo deptInfo = this.getOne(queryWrapper);
|
|
|
- if(deptInfo == null){
|
|
|
- throw new CommonException(CommonErrorCode.NOT_EXISTS,
|
|
|
- "科室信息不存在");
|
|
|
- }
|
|
|
- return deptInfo;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 判断科室是否被删除
|
|
|
- *
|
|
|
- * @param deptId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Boolean deptInfoIsDeletedStatus(Long deptId){
|
|
|
- QueryWrapper<DeptInfo> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted",IsDeleteEnum.Y.getKey());
|
|
|
- queryWrapper.eq("id",deptId);
|
|
|
- return this.count(queryWrapper) > 0 ? true:false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取所有科室
|
|
|
- * @param getAllDeptsVO
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<GetAllDeptsDTO> getAllDepts(GetAllDeptsVO getAllDeptsVO){
|
|
|
- QueryWrapper<DeptInfo> deptInfoQe = new QueryWrapper<>();
|
|
|
- deptInfoQe.eq("is_deleted",IsDeleteEnum.N.getKey());
|
|
|
- deptInfoQe.like("name", getAllDeptsVO.getName());
|
|
|
- return BeanUtil.listCopyTo(list(deptInfoQe), GetAllDeptsDTO.class);
|
|
|
- }
|
|
|
-
|
|
|
-}
|