From 5ed2d1c2fdb99ca34c276e98be52956058b851df Mon Sep 17 00:00:00 2001 From: jianjun Date: Fri, 17 Jun 2022 22:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=B1=85=E6=B0=91?= =?UTF-8?q?=E5=8F=98=E6=9B=B4=E8=AE=B0=E5=BD=95=20=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E7=B2=92=E5=BA=A6=E5=8F=8A=E5=88=86=E6=89=B9=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=B2=92=E5=BA=A6=E7=BC=A9=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/IcUserChangeRecordServiceImpl.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java index bc88226da3..5e58019074 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java @@ -17,6 +17,7 @@ package com.epmet.service.impl; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; @@ -45,7 +46,6 @@ import com.epmet.service.IcUserChangeRecordService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -175,7 +175,6 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl"+customerId); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -205,8 +204,7 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl map : icUserList){ //存放一个人的类别为是的变更明细数据 - List subList = new ArrayList<>(); - String changeId = UUID.randomUUID().toString().replaceAll("-", ""); + String changeId = IdWorker.getIdStr(); for (IcResiCategoryStatsConfigDTO dto : categoryListResult.getData()){ if(map.containsKey(dto.getColumnName())&&"1".equals(map.get(dto.getColumnName()))){ detailed = new IcUserChangeDetailedEntity(); @@ -228,12 +226,10 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl NumConstant.ZERO) { - detailedList.addAll(subList); - } + if (!hash.containsKey(map.get("CREATED_BY"))) { CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, map.get("CREATED_BY")); //被删除或被移除的工作人员,名字为空 @@ -257,20 +253,34 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl= NumConstant.FIVE_HUNDRED){ + delAndInsertChangeRecord(customerId, changeList, detailedList); + } } while (icUserList.size() == NumConstant.ONE_THOUSAND); //4.批量新增数据,先删后增【只删除新增节点的历史数据】 //4-1.删除待处理的人员数据【这类人是指在变更记录表中不存在新增节点数据的人】 + //最后再处理一批 + delAndInsertChangeRecord(customerId, changeList, detailedList); + } + + @Transactional(rollbackFor = Exception.class) + public void delAndInsertChangeRecord(String customerId, List changeList, List detailedList) { + if (CollectionUtils.isEmpty(changeList)) { + log.info("customerId:{}初始变更记录数据 已完成!", customerId); + return; + } List icUserIdList = changeList.stream().map(IcUserChangeRecordEntity::getIcUserId).collect(Collectors.toList()); - List> partition = ListUtils.partition(icUserIdList, NumConstant.FIVE_HUNDRED); - partition.forEach(part -> { - baseDao.delByCustomerId(customerId, "add", part); - icUserChangeDetailedService.delByCustomerId(customerId, "add", part); - }); + baseDao.delByCustomerId(customerId, "add", icUserIdList); + icUserChangeDetailedService.delByCustomerId(customerId, "add", icUserIdList); log.info("初始变更记录数据,总条数->" + changeList.size()); icUserChangeRecordService.insertBatch(changeList); log.info("初始变更记录明细数据,总条数->" + detailedList.size()); icUserChangeDetailedService.insertBatch(detailedList); + changeList.clear(); + detailedList.clear(); + icUserIdList.clear(); } }