From 1ef193e70749e3e7ae1eb7531ebbdd5181971984 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Fri, 1 Apr 2022 10:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E8=B0=83=E6=95=B4=E5=BC=95?= =?UTF-8?q?=E8=B5=B7=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/controller/IcNatController.java | 14 ++++ .../src/main/java/com/epmet/dao/IcNatDao.java | 2 +- .../java/com/epmet/dao/IcNatRelationDao.java | 8 ++- .../java/com/epmet/service/IcNatService.java | 6 ++ .../epmet/service/impl/IcNatServiceImpl.java | 70 +++++++++++-------- .../resources/mapper/IcNatRelationDao.xml | 9 +++ 6 files changed, 78 insertions(+), 31 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java index d6ff6b6af7..4de76d5b64 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcNatController.java @@ -155,6 +155,20 @@ public class IcNatController implements ResultDataResolver { return new Result(); } + /** + * @Author sun + * @Description 【核酸】核酸检测信息取消同步 + **/ + @NoRepeatSubmit + @PostMapping("cancelsynchro") + public Result cancelSynchro(@LoginUser TokenDto tokenDto, @RequestBody MyNatListFormDTO formDTO) { + ValidatorUtils.validateEntity(formDTO, MyNatListFormDTO.Synchro.class); + formDTO.setCustomerId(tokenDto.getCustomerId()); + formDTO.setUserId(tokenDto.getUserId()); + icNucleinService.cancelSynchro(formDTO); + return new Result<>(); + } + /** * 导入excel * @return diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java index 550e1371fb..adaa191b1a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatDao.java @@ -40,7 +40,7 @@ public interface IcNatDao extends BaseDao { /** * @Author sun - * @Description 删除/取消同步操作--物理删除业务数据 + * @Description 删除操作--物理删除业务数据 **/ int delById(@Param("icNatId") String icNatId); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatRelationDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatRelationDao.java index 27b20bcfaf..0b37f87121 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatRelationDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcNatRelationDao.java @@ -3,6 +3,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.IcNatRelationEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; /** * 核酸记录关系表 @@ -12,5 +13,10 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface IcNatRelationDao extends BaseDao { - + + /** + * @Author sun + * @Description 关系数据删除--物理删除 + **/ + int delRelation(@Param("icNatId") String icNatId, @Param("agencyId") String agencyId); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java index e7239524bb..450bee8592 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcNatService.java @@ -64,6 +64,12 @@ public interface IcNatService extends BaseService { **/ void synchro(MyNatListFormDTO formDTO); + /** + * @Author sun + * @Description 【核酸】核酸检测信息取消同步 + **/ + void cancelSynchro(MyNatListFormDTO formDTO); + /** * 执行Excel导入 * @param filePath diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java index 734d31b40c..264d89f873 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcNatServiceImpl.java @@ -102,14 +102,14 @@ public class IcNatServiceImpl extends BaseServiceImpl imp } //2.新增核酸基础信息数据 IcNatEntity entity = ConvertUtils.sourceToTarget(formDTO, IcNatEntity.class); - if(StringUtils.isNotBlank(formDTO.getUserId())){ + if (StringUtils.isNotBlank(formDTO.getUserId())) { entity.setIsResiUser("1"); } insert(entity); //3.核酸记录关系表新增与组织的关系数据 IcNatRelationEntity relationEntity = ConvertUtils.sourceToTarget(formDTO, IcNatRelationEntity.class); relationEntity.setIcNatId(entity.getId()); - relationEntity.setPids(StringUtils.isNotBlank(agencyInfo.getPids())?agencyInfo.getPids()+":"+formDTO.getAgencyId():agencyInfo.getPids()); + relationEntity.setPids(StringUtils.isNotBlank(agencyInfo.getPids()) ? agencyInfo.getPids() + ":" + formDTO.getAgencyId() : formDTO.getAgencyId()); icNatRelationDao.insert(relationEntity); //3.新增通知表信息 @@ -215,17 +215,7 @@ public class IcNatServiceImpl extends BaseServiceImpl imp log.error(String.format("数据修改失败,核酸记录Id->%s", formDTO.getIcNatId())); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "核酸记录修改失败"); } - - //2.更新与组织的关系表数据 - AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getAgencyId()); - if (null == agencyInfo) { - throw new RenException(String.format("获取组织缓存信息失败%s", formDTO.getAgencyId())); - } - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(IcNatRelationEntity::getIcNatId, formDTO.getIcNatId()); - IcNatRelationEntity relationEntity = ConvertUtils.sourceToTarget(formDTO, IcNatRelationEntity.class); - relationEntity.setPids(StringUtils.isNotBlank(agencyInfo.getPids()) ? agencyInfo.getPids() + ":" + formDTO.getAgencyId() : agencyInfo.getPids()); - icNatRelationDao.update(relationEntity, wrapper); + //修改只涉及到基础信息的修改 不会修改关系数据 关系表不涉及更新 //3.新增通知表信息 if (CollectionUtils.isNotEmpty(formDTO.getChannel())) { @@ -240,7 +230,6 @@ public class IcNatServiceImpl extends BaseServiceImpl imp dto.setStaffId(formDTO.getStaffId()); icNoticeService.sendNotice(dto); } - } /** @@ -250,11 +239,13 @@ public class IcNatServiceImpl extends BaseServiceImpl imp @Override @Transactional(rollbackFor = Exception.class) public void del(MyNatListFormDTO formDTO) { - //1.物理删除业务数据 + //1.确定删除则需要删除基础数据以及所有可能存在的关系数据,物理删除业务数据 if (baseDao.delById(formDTO.getIcNatId()) < NumConstant.ONE) { - log.error(String.format("数据删除/取消同步失败,核酸记录Id->%s", formDTO.getIcNatId())); + log.error(String.format("数据删除失败,核酸记录Id->%s", formDTO.getIcNatId())); throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "数据操作失败"); } + //关系数据删除 + icNatRelationDao.delRelation(formDTO.getIcNatId(), null); } /** @@ -264,25 +255,46 @@ public class IcNatServiceImpl extends BaseServiceImpl imp @Override @Transactional(rollbackFor = Exception.class) public void synchro(MyNatListFormDTO formDTO) { + //1.检验核酸基础信息是否存在 + IcNatEntity entity = baseDao.selectById(formDTO.getIcNatId()); + if (null == entity) { + log.error(String.format("核酸记录数据不存在同步失败,核酸记录Id->%s", formDTO.getIcNatId())); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "数据同步失败,核酸记录数据不存在"); + } + //获取工作人员缓存数据 + CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); + if (null == staffInfo) { + throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); + } + //2.不管是否已存在关系数据都是先删后增 + icNatRelationDao.delRelation(formDTO.getIcNatId(), null); + //3.新增关系数据 + IcNatRelationEntity relationEntity = new IcNatRelationEntity(); + relationEntity.setCustomerId(formDTO.getCustomerId()); + relationEntity.setIcNatId(formDTO.getIcNatId()); + relationEntity.setAgencyId(staffInfo.getAgencyId()); + relationEntity.setPids(StringUtils.isNotBlank(staffInfo.getAgencyPIds())?staffInfo.getAgencyPIds()+":"+formDTO.getAgencyId():staffInfo.getAgencyId()); + relationEntity.setUserType("synchro"); + icNatRelationDao.insert(relationEntity); + } + + /** + * @Author sun + * @Description 【核酸】核酸检测信息取消同步 + **/ + @Override + @Transactional(rollbackFor = Exception.class) + public void cancelSynchro(MyNatListFormDTO formDTO) { //1.获取工作人员缓存数据 CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getUserId()); if (null == staffInfo) { throw new EpmetException(String.format("查询工作人员%s缓存信息失败...", formDTO.getUserId())); } - //1.根据核酸记录Id查询业务数据并进行必要校验 - IcNatEntity entity = baseDao.selectById(formDTO.getIcNatId()); - if (null == entity || staffInfo.getAgencyId().equals(entity.getAgencyId()) - || (!"import".equals(entity.getUserType()) && !"synchro".equals(entity.getUserType()))) { - log.error(String.format("数据同步失败,核酸记录Id->%s", formDTO.getIcNatId())); - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "数据同步失败,不是导入数据或非本组织数据"); + //1.物理删除关系数据 + if (icNatRelationDao.delRelation(formDTO.getIcNatId(), staffInfo.getAgencyId()) < NumConstant.ONE) { + log.error(String.format("数据取消同步失败,核酸记录Id->%s", formDTO.getIcNatId())); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "取消同步操作失败"); } - - //3.待同步组织新增业务数据 - entity.setId(""); - entity.setAgencyId(staffInfo.getAgencyId()); - entity.setPids(staffInfo.getAgencyPIds()); - entity.setUserType("synchro"); - insert(entity); } @Async diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatRelationDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatRelationDao.xml index b9ebe8f3b0..1857d13df7 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatRelationDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatRelationDao.xml @@ -3,5 +3,14 @@ + + DELETE + FROM ic_nat_relation + WHERE + ic_nat_id = #{icNatId} + + AND AGENCY_ID = #{agencyId} + + \ No newline at end of file