From 2e1c025c61abbf2669be27d25106118aa8ab3c48 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 25 Oct 2022 11:57:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=A8=E6=9A=82=E6=8F=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/result/RelationAndNatResultDTO.java | 26 ++++++++ .../src/main/java/com/epmet/dao/IcNatDao.java | 20 ++++++ .../impl/DataSyncConfigServiceImpl.java | 1 + .../epmet/service/impl/IcNatServiceImpl.java | 66 +++++++++++++++++-- .../src/main/resources/mapper/IcNatDao.xml | 48 +++++++++++++- .../main/resources/mapper/IcResiUserDao.xml | 2 +- 6 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RelationAndNatResultDTO.java diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RelationAndNatResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RelationAndNatResultDTO.java new file mode 100644 index 0000000000..cc3da4c846 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RelationAndNatResultDTO.java @@ -0,0 +1,26 @@ +package com.epmet.dto.result; + +import com.epmet.commons.tools.constant.NumConstant; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2022/10/25 09:37 + */ +@Data +public class RelationAndNatResultDTO implements Serializable { + private static final long serialVersionUID = 5245015978083295931L; + + private String relationId; + private String natId; + private String staffAgencyIdPath; + private String idCard; + + /** + * 默认不是本辖区居民 + */ + private String isLocalResiUser = NumConstant.ZERO_STR; + +} 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 f21ec91eb3..7b8b0a0ab7 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 @@ -6,7 +6,9 @@ import com.epmet.dto.form.MyNatListFormDTO; import com.epmet.dto.result.MyNatListResultDTO; import com.epmet.dto.result.NatListResultDTO; import com.epmet.dto.result.NatUserInfoResultDTO; +import com.epmet.dto.result.RelationAndNatResultDTO; import com.epmet.entity.IcNatEntity; +import com.epmet.entity.IcResiUserEntity; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -66,4 +68,22 @@ public interface IcNatDao extends BaseDao { void updateBatchNat(@Param("list")List entities); + List getRelationAndNat(); + + List getResiByIdCards(@Param("idCards")List idCards); + + /** + * @Description 批量更新关系 + * @param list + * @Author zxc + * @Date 2022/10/25 10:56 + */ + void updateRelation(@Param("list") List list); + + /** + * @Description 更新的 userType != 'import' + * @Author zxc + * @Date 2022/10/25 11:13 + */ + void updateRelationOther(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java index 7fc6aa2bb6..632e27828b 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/DataSyncConfigServiceImpl.java @@ -557,6 +557,7 @@ public class DataSyncConfigServiceImpl extends BaseServiceImpl imp if (null == agencyInfo) { throw new RenException(String.format("获取组织缓存信息失败%s", formDTO.getAgencyId())); } + CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId()); + if (null == staffInfo){ + throw new EpmetException(String.format("获取工作人员信息失败%s", formDTO.getStaffId())); + } //2.新增核酸基础信息数据 IcNatEntity entity = ConvertUtils.sourceToTarget(formDTO, IcNatEntity.class); if (StringUtils.isNotBlank(formDTO.getUserId())) { @@ -136,9 +141,12 @@ public class IcNatServiceImpl extends BaseServiceImpl imp } insert(entity); //3.核酸记录关系表新增与组织的关系数据 + ResiAndLocalResiResultDTO resiCount = icResiUserDao.getResiCount(formDTO.getAgencyId(), formDTO.getIdCard(), formDTO.getCustomerId()); IcNatRelationEntity relationEntity = ConvertUtils.sourceToTarget(formDTO, IcNatRelationEntity.class); relationEntity.setIcNatId(entity.getId()); - relationEntity.setPids(StringUtils.isNotBlank(agencyInfo.getPids()) ? agencyInfo.getPids() + ":" + formDTO.getAgencyId() : formDTO.getAgencyId()); + relationEntity.setIsLocalResiUser(resiCount.getIsLocal() == NumConstant.ZERO ? NumConstant.ZERO_STR : NumConstant.ONE_STR); + relationEntity.setAgencyId(staffInfo.getAgencyId()); + relationEntity.setPids(StringUtils.isNotBlank(staffInfo.getAgencyPIds()) ? staffInfo.getAgencyPIds() + ":" + staffInfo.getAgencyId() : staffInfo.getAgencyId()); icNatRelationDao.insert(relationEntity); //3.新增通知表信息 @@ -476,7 +484,47 @@ public class IcNatServiceImpl extends BaseServiceImpl imp public void initNatLocal() { Integer no = NumConstant.ONE; Integer size; + // 查询关系表 + do { + // user_type = 'import' + PageInfo pageInfo = PageHelper.startPage(no, NumConstant.ONE_THOUSAND).doSelectPageInfo(() -> baseDao.getRelationAndNat()); + List list = pageInfo.getList(); + size = list.size(); + if (CollectionUtils.isNotEmpty(list)){ + List users = baseDao.getResiByIdCards(list.stream().map(m -> m.getIdCard()).distinct().collect(Collectors.toList())); + if (CollectionUtils.isNotEmpty(users)){ + for (RelationAndNatResultDTO l : list) { + for (IcResiUserEntity u : users) { + if (l.getStaffAgencyIdPath().contains(u.getAgencyId())){ + l.setIsLocalResiUser(NumConstant.ONE_STR); + break; + } + } + } + updateRelation(list,NumConstant.ONE_STR); + } + } + }while (size == NumConstant.ONE_THOUSAND); + // 其他类型的userType直接是居民的组织信息,所以直接赋值 is_local_resi_user = '1' + updateRelation(null,NumConstant.TWO_STR); + } + /** + * @Description 更新核酸关系表 + * @param list + * @param type 1:userType为import;2:除了import + * @Author zxc + * @Date 2022/10/25 10:55 + */ + @Transactional(rollbackFor = Exception.class) + public void updateRelation(List list,String type){ + if (NumConstant.ONE_STR.equals(type)){ + if (CollectionUtils.isNotEmpty(list)){ + baseDao.updateRelation(list); + } + }else { + baseDao.updateRelationOther(); + } } /** @@ -542,6 +590,7 @@ public class IcNatServiceImpl extends BaseServiceImpl imp return; } + // 存在某时间的核酸检测信息 if (resiNat != null) { boolean needUpdate = false; // 有这个人,也是导入的,那就要更新le @@ -593,8 +642,9 @@ public class IcNatServiceImpl extends BaseServiceImpl imp } // 还要创建关系。只有本辖区及下级居民,才建立关系 + // 2022-10-25 修改:导入的都插入关系 if (resi != null) { - createNatRelation(resiNat.getId(), resi.getAgencyId(), resi.getPids()); + createNatRelation(resiNat.getId(), resi.getAgencyId(), agencyPids,agencyId); } return; @@ -609,7 +659,7 @@ public class IcNatServiceImpl extends BaseServiceImpl imp // 还要创建关系。只有本辖区及下级居民,才建立关系 if (resi != null) { - createNatRelation(e.getId(), resi.getAgencyId(), resi.getPids()); + createNatRelation(e.getId(), resi.getAgencyId(), agencyPids,agencyId); } } @@ -649,11 +699,15 @@ public class IcNatServiceImpl extends BaseServiceImpl imp /** * 创建nat关系 * @param natId - * @param currentUserAgencyId + * @param currentUserAgencyId 居民所属组织 + * @param staffAgencyId 工作人员所属组织 + * @param agencyPids 工作人员所属组织路径 */ - private void createNatRelation(String natId, String currentUserAgencyId, String agencyPids) { + private void createNatRelation(String natId, String currentUserAgencyId, String agencyPids,String staffAgencyId) { // 没有关系创建关系,有关系就跳过 + // 2022-10-25 修改:不管是不是本辖区居民,都创建关系,用 is_local_resi_user区分是不是本辖区居民 + // 组织ID都改成工作人员所属组织ID LambdaQueryWrapper query = new LambdaQueryWrapper<>(); query.eq(IcNatRelationEntity::getIcNatId, natId); query.eq(IcNatRelationEntity::getAgencyId, currentUserAgencyId); @@ -666,6 +720,8 @@ public class IcNatServiceImpl extends BaseServiceImpl imp relation.setPids(String.join(":", Arrays.asList(agencyPids, currentUserAgencyId))); relation.setIcNatId(natId); relation.setUserType("import"); + relation.setIsLocalResiUser(agencyPids.contains(currentUserAgencyId) ? NumConstant.ONE_STR : NumConstant.ZERO_STR); icNatRelationDao.insert(relation); } + } diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml index 81b1c78e4f..63f7f4b726 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcNatDao.xml @@ -75,7 +75,7 @@ AND b.sample_time #{sampleEndTime} - AND b.is_local_resi_user = #{isResiUser} + AND a.is_local_resi_user = #{isResiUser} ORDER BY b.nat_time DESC, b.id ASC @@ -169,6 +169,29 @@ + + + + DELETE FROM ic_nat WHERE id = #{icNatId} @@ -222,4 +245,27 @@ ) + + + + UPDATE ic_nat_relation + + + + when ID = #{l.relationId} then #{l.isLocalResiUser} + + + UPDATED_TIME = NOW() + + WHERE ID IN( + + #{l.relationId} + ) + + + UPDATE ic_nat_relation + set IS_LOCAL_RESI_USER = '1', + UPDATED_TIME = NOW() + where user_type != 'import' + diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml index b5f8788719..1203976d6c 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml @@ -1391,7 +1391,7 @@ FROM ic_resi_user WHERE DEL_FLAG = '0' AND `STATUS` = 0 - AND AGENCY_ID = #{agencyId} + AND PIDS LIKE CONCAT('%',#{agencyId},'%') AND ID_CARD = #{idCard}) AS isLocal, COUNT(ID) AS isResi, id as userId