123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- package com.lantone.daqe.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.lantone.common.enums.IsDeleteEnum;
- import com.lantone.common.exception.Asserts;
- import com.lantone.common.util.BeanUtil;
- import com.lantone.common.util.DateUtil;
- import com.lantone.common.util.ListUtil;
- import com.lantone.common.util.SysUserUtils;
- import com.lantone.daqe.dto.GetRegularPageDTO;
- import com.lantone.daqe.entity.ColumnVerify;
- import com.lantone.daqe.entity.RegularInfo;
- import com.lantone.daqe.entity.RegularMapping;
- import com.lantone.daqe.entity.RegularResult;
- import com.lantone.daqe.enums.ColumnVerifyTypeEnum;
- import com.lantone.daqe.facade.base.ColumnVerifyFacade;
- import com.lantone.daqe.facade.base.RegularInfoFacade;
- import com.lantone.daqe.facade.base.RegularMappingFacade;
- import com.lantone.daqe.facade.base.RegularResultFacade;
- import com.lantone.daqe.vo.AddRegularVO;
- import com.lantone.daqe.vo.DelRegularByIdVO;
- import com.lantone.daqe.vo.GetRegularPageVO;
- import com.lantone.daqe.vo.UpRegularByIdVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * @Description: 正则式维护-业务处理类
- * @author: songxl
- * @time: 2022/3/4 10:39
- */
- @Component
- public class RegularManagementFacade {
- @Autowired
- private RegularInfoFacade regularInfoFacade;
- @Autowired
- private RegularResultFacade regularResultFacade;
- @Autowired
- private RegularMappingFacade regularMappingFacade;
- @Autowired
- private ColumnVerifyFacade columnVerifyFacade;
- /**
- * 获取正则式维护分页列表
- *
- * @param getRegularPageVO
- * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.lantone.daqe.dto.GetRegularPageDTO>
- */
- public IPage<GetRegularPageDTO> getRegularPage(GetRegularPageVO getRegularPageVO) {
- QueryWrapper<RegularInfo> wrapper = new QueryWrapper();
- wrapper.like("name", getRegularPageVO.getName());
- regularInfoFacade.list(wrapper);
- return regularInfoFacade.getBaseMapper().getRegularPage(getRegularPageVO);
- }
- /**
- * 新增正则式 业务处理
- *
- * @param addRegularVO
- * @return 是否新增成功
- */
- public Boolean addRegular(AddRegularVO addRegularVO) {
- RegularInfo regularInfo = new RegularInfo();
- BeanUtils.copyProperties(addRegularVO, regularInfo);
- if (regularInfoFacade.isExist(regularInfo)) {
- Asserts.fail("该正则式已存在!");
- }
- regularInfo.setCreator(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
- regularInfo.setGmtCreate(DateUtil.now());
- return regularInfoFacade.save(regularInfo);
- }
- /**
- * 通过id修改正则式
- *
- * @param upRegularByIdVO
- * @return 是否修改成功
- */
- public Boolean upRegularById(UpRegularByIdVO upRegularByIdVO) {
- if (regularInfoFacade.getById(upRegularByIdVO.getId()) == null) {
- Asserts.fail("该正则式不存在!");
- }
- //修改正则式
- RegularInfo regularInfo = new RegularInfo();
- BeanUtil.copyProperties(upRegularByIdVO, regularInfo);
- regularInfo.setModifier(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
- regularInfo.setGmtModified(DateUtil.now());
- //修改表字段的正则式校验结果表中的正则式
- //先获取正则维护关联表id
- List<Long> regularMappingIdList = getRegularMappingId(upRegularByIdVO.getId());
- if (regularInfoFacade.updateById(regularInfo)) {
- if (ListUtil.isNotEmpty(regularMappingIdList)) {
- return columnVerifyFacade.update(new UpdateWrapper<ColumnVerify>()
- .in("verify_id", regularMappingIdList)
- .eq("is_deleted", IsDeleteEnum.N.getKey())
- .eq("type", ColumnVerifyTypeEnum.REGULAR_TYPE.getKey())
- .set("verify_val", upRegularByIdVO.getName())
- .set("modifier", SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple())
- .set("gmt_modified", DateUtil.now()));
- }
- return true;
- }
- return false;
- }
- /**
- * 通过id删除正则式
- *
- * @param delRegularByIdVO
- * @return 是否删除成功
- */
- public Boolean delRegularById(DelRegularByIdVO delRegularByIdVO) {
- Boolean flag = false;
- for (Long id : delRegularByIdVO.getIds()) {
- flag = delRegularById(id, delRegularByIdVO.getHospitalId());
- }
- return flag;
- }
- /**
- * 通过id删除正则式
- *
- * @param id
- * @param hospitalId
- * @Return java.lang.Boolean
- */
- private Boolean delRegularById(Long id, Long hospitalId) {
- if (regularInfoFacade.getById(id) == null) {
- Asserts.fail("该正则式不存在!");
- }
- RegularInfo regularInfo = new RegularInfo();
- regularInfo.setId(id);
- regularInfo.setModifier(SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple());
- regularInfo.setGmtModified(DateUtil.now());
- regularInfo.setIsDeleted(IsDeleteEnum.Y.getKey());
- if (regularInfoFacade.updateById(regularInfo)) {
- //先获取正则维护关联表id
- List<Long> regularMappingIdList = getRegularMappingId(id);
- //删除表字段的实际值与正则式关联关系
- if (regularMappingFacade.remove(new UpdateWrapper<RegularMapping>()
- .eq("regular_id", id)
- .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
- return columnVerifyFacade.remove(new UpdateWrapper<ColumnVerify>()
- .in("verify_id", regularMappingIdList)
- .eq("type", ColumnVerifyTypeEnum.REGULAR_TYPE.getKey())
- .eq("is_deleted", IsDeleteEnum.N.getKey()));
- }
- //删除表字段的正则式校验结果表中的正则式
- // return regularResultFacade.update(new UpdateWrapper<RegularResult>()
- // .eq(hospitalId != null, "hospital_id", hospitalId)
- // .eq("regular_id", id)
- // .eq("is_deleted", IsDeleteEnum.N.getKey())
- // .set("modifier", SysUserUtils.getCurrentPrinciple() == null ? "0" : SysUserUtils.getCurrentPrinciple())
- // .set("gmt_modified", DateUtil.now())
- // .set("is_deleted", IsDeleteEnum.Y.getKey()));
- }
- return false;
- }
- /**
- * 根据正则id获取正则维护表id集合
- *
- * @param id
- * @return: 正则维护表id集合
- */
- public List<Long> getRegularMappingId(Long id) {
- List<Long> regularMappingIdList = new ArrayList<>();
- List<RegularMapping> regularMappingList = regularMappingFacade.getBaseMapper().selectList(new QueryWrapper<RegularMapping>()
- .eq("regular_id", id)
- .eq("is_deleted", IsDeleteEnum.N.getKey())
- );
- if (ListUtil.isNotEmpty(regularMappingList)) {
- for (RegularMapping regularMapping : regularMappingList) {
- regularMappingIdList.add(regularMapping.getId());
- }
- }
- return regularMappingIdList;
- }
- }
|