RegularManagementFacade.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. package com.lantone.daqe.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.lantone.common.enums.IsDeleteEnum;
  6. import com.lantone.common.exception.Asserts;
  7. import com.lantone.common.util.BeanUtil;
  8. import com.lantone.common.util.DateUtil;
  9. import com.lantone.common.util.ListUtil;
  10. import com.lantone.common.util.SysUserUtils;
  11. import com.lantone.daqe.dto.GetRegularPageDTO;
  12. import com.lantone.daqe.entity.ColumnVerify;
  13. import com.lantone.daqe.entity.RegularInfo;
  14. import com.lantone.daqe.entity.RegularMapping;
  15. import com.lantone.daqe.entity.RegularResult;
  16. import com.lantone.daqe.enums.ColumnVerifyTypeEnum;
  17. import com.lantone.daqe.facade.base.ColumnVerifyFacade;
  18. import com.lantone.daqe.facade.base.RegularInfoFacade;
  19. import com.lantone.daqe.facade.base.RegularMappingFacade;
  20. import com.lantone.daqe.facade.base.RegularResultFacade;
  21. import com.lantone.daqe.vo.AddRegularVO;
  22. import com.lantone.daqe.vo.DelRegularByIdVO;
  23. import com.lantone.daqe.vo.GetRegularPageVO;
  24. import com.lantone.daqe.vo.UpRegularByIdVO;
  25. import org.springframework.beans.BeanUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Component;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. /**
  31. * @Description: 正则式维护-业务处理类
  32. * @author: songxl
  33. * @time: 2022/3/4 10:39
  34. */
  35. @Component
  36. public class RegularManagementFacade {
  37. @Autowired
  38. private RegularInfoFacade regularInfoFacade;
  39. @Autowired
  40. private RegularResultFacade regularResultFacade;
  41. @Autowired
  42. private RegularMappingFacade regularMappingFacade;
  43. @Autowired
  44. private ColumnVerifyFacade columnVerifyFacade;
  45. /**
  46. * 获取正则式维护分页列表
  47. *
  48. * @param getRegularPageVO
  49. * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.lantone.daqe.dto.GetRegularPageDTO>
  50. */
  51. public IPage<GetRegularPageDTO> getRegularPage(GetRegularPageVO getRegularPageVO) {
  52. QueryWrapper<RegularInfo> wrapper = new QueryWrapper();
  53. wrapper.like("name", getRegularPageVO.getName());
  54. regularInfoFacade.list(wrapper);
  55. return regularInfoFacade.getBaseMapper().getRegularPage(getRegularPageVO);
  56. }
  57. /**
  58. * 新增正则式 业务处理
  59. *
  60. * @param addRegularVO
  61. * @return 是否新增成功
  62. */
  63. public Boolean addRegular(AddRegularVO addRegularVO) {
  64. RegularInfo regularInfo = new RegularInfo();
  65. BeanUtils.copyProperties(addRegularVO, regularInfo);
  66. if (regularInfoFacade.isExist(regularInfo)) {
  67. Asserts.fail("该正则式已存在!");
  68. }
  69. regularInfo.setCreator(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
  70. regularInfo.setGmtCreate(DateUtil.now());
  71. return regularInfoFacade.save(regularInfo);
  72. }
  73. /**
  74. * 通过id修改正则式
  75. *
  76. * @param upRegularByIdVO
  77. * @return 是否修改成功
  78. */
  79. public Boolean upRegularById(UpRegularByIdVO upRegularByIdVO) {
  80. if (regularInfoFacade.getById(upRegularByIdVO.getId()) == null) {
  81. Asserts.fail("该正则式不存在!");
  82. }
  83. //修改正则式
  84. RegularInfo regularInfo = new RegularInfo();
  85. BeanUtil.copyProperties(upRegularByIdVO, regularInfo);
  86. regularInfo.setModifier(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
  87. regularInfo.setGmtModified(DateUtil.now());
  88. //修改表字段的正则式校验结果表中的正则式
  89. //先获取正则维护关联表id
  90. List<Long> regularMappingIdList = getRegularMappingId(upRegularByIdVO.getId());
  91. if (regularInfoFacade.updateById(regularInfo)) {
  92. if (ListUtil.isNotEmpty(regularMappingIdList)) {
  93. return columnVerifyFacade.update(new UpdateWrapper<ColumnVerify>()
  94. .in("verify_id", regularMappingIdList)
  95. .eq("is_deleted", IsDeleteEnum.N.getKey())
  96. .eq("type", ColumnVerifyTypeEnum.REGULAR_TYPE.getKey())
  97. .set("verify_val", upRegularByIdVO.getName())
  98. .set("modifier", SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple())
  99. .set("gmt_modified", DateUtil.now()));
  100. }
  101. return true;
  102. }
  103. return false;
  104. }
  105. /**
  106. * 通过id删除正则式
  107. *
  108. * @param delRegularByIdVO
  109. * @return 是否删除成功
  110. */
  111. public Boolean delRegularById(DelRegularByIdVO delRegularByIdVO) {
  112. Boolean flag = false;
  113. for (Long id : delRegularByIdVO.getIds()) {
  114. flag = delRegularById(id, delRegularByIdVO.getHospitalId());
  115. }
  116. return flag;
  117. }
  118. /**
  119. * 通过id删除正则式
  120. *
  121. * @param id
  122. * @param hospitalId
  123. * @Return java.lang.Boolean
  124. */
  125. private Boolean delRegularById(Long id, Long hospitalId) {
  126. if (regularInfoFacade.getById(id) == null) {
  127. Asserts.fail("该正则式不存在!");
  128. }
  129. RegularInfo regularInfo = new RegularInfo();
  130. regularInfo.setId(id);
  131. regularInfo.setModifier(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
  132. regularInfo.setGmtModified(DateUtil.now());
  133. regularInfo.setIsDeleted(IsDeleteEnum.Y.getKey());
  134. if (regularInfoFacade.updateById(regularInfo)) {
  135. //先获取正则维护关联表id
  136. List<Long> regularMappingIdList = getRegularMappingId(id);
  137. //删除表字段的实际值与正则式关联关系
  138. if (regularMappingFacade.remove(new UpdateWrapper<RegularMapping>()
  139. .eq("regular_id", id)
  140. .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
  141. return columnVerifyFacade.remove(new UpdateWrapper<ColumnVerify>()
  142. .in("verify_id", regularMappingIdList)
  143. .eq("type", ColumnVerifyTypeEnum.REGULAR_TYPE.getKey())
  144. .eq("is_deleted", IsDeleteEnum.N.getKey()));
  145. }
  146. //删除表字段的正则式校验结果表中的正则式
  147. // return regularResultFacade.update(new UpdateWrapper<RegularResult>()
  148. // .eq(hospitalId != null, "hospital_id", hospitalId)
  149. // .eq("regular_id", id)
  150. // .eq("is_deleted", IsDeleteEnum.N.getKey())
  151. // .set("modifier", SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple())
  152. // .set("gmt_modified", DateUtil.now())
  153. // .set("is_deleted", IsDeleteEnum.Y.getKey()));
  154. }
  155. return false;
  156. }
  157. /**
  158. * 根据正则id获取正则维护表id集合
  159. *
  160. * @param id
  161. * @return: 正则维护表id集合
  162. */
  163. public List<Long> getRegularMappingId(Long id) {
  164. List<Long> regularMappingIdList = new ArrayList<>();
  165. List<RegularMapping> regularMappingList = regularMappingFacade.getBaseMapper().selectList(new QueryWrapper<RegularMapping>()
  166. .eq("regular_id", id)
  167. .eq("is_deleted", IsDeleteEnum.N.getKey())
  168. );
  169. if (ListUtil.isNotEmpty(regularMappingList)) {
  170. for (RegularMapping regularMapping : regularMappingList) {
  171. regularMappingIdList.add(regularMapping.getId());
  172. }
  173. }
  174. return regularMappingIdList;
  175. }
  176. }