Browse Source

数据删除 分批处理

master
sunyuchao 4 years ago
parent
commit
0072644c84
  1. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeDetailedDao.java
  2. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeRecordDao.java
  3. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeDetailedService.java
  4. 6
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeDetailedServiceImpl.java
  5. 11
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java
  6. 3
      epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeDetailedDao.xml
  7. 5
      epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeRecordDao.xml

4
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeDetailedDao.java

@ -22,6 +22,8 @@ import com.epmet.entity.IcUserChangeDetailedEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 变更明细表
[一条变更记录对应多条人员类别数据]
@ -36,5 +38,5 @@ public interface IcUserChangeDetailedDao extends BaseDao<IcUserChangeDetailedEnt
* @Author sun
* @Description 删除客户是新增类型的变更明细历史数据
**/
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type);
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type, @Param("icUserIds") List<String> icUserIds);
}

2
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/IcUserChangeRecordDao.java

@ -48,5 +48,5 @@ public interface IcUserChangeRecordDao extends BaseDao<IcUserChangeRecordEntity>
* @Author sun
* @Description 删除客户是新增类型的变更历史数据
**/
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type);
void delByCustomerId(@Param("customerId") String customerId, @Param("type") String type, @Param("icUserIds") List<String> icUserIds);
}

5
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcUserChangeDetailedService.java

@ -19,6 +19,9 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.entity.IcUserChangeDetailedEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 变更明细表
@ -33,5 +36,5 @@ public interface IcUserChangeDetailedService extends BaseService<IcUserChangeDet
* @Author sun
* @Description 删除客户是新增类型的变更明细历史数据
**/
void delByCustomerId(String customerId, String type);
void delByCustomerId(String customerId, String type, List<String> icUserIds);
}

6
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeDetailedServiceImpl.java

@ -23,6 +23,8 @@ import com.epmet.entity.IcUserChangeDetailedEntity;
import com.epmet.service.IcUserChangeDetailedService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 变更明细表
[一条变更记录对应多条人员类别数据]
@ -38,7 +40,7 @@ public class IcUserChangeDetailedServiceImpl extends BaseServiceImpl<IcUserChang
* @Description 删除客户是新增类型的变更明细历史数据
**/
@Override
public void delByCustomerId(String customerId, String type) {
baseDao.delByCustomerId(customerId, type);
public void delByCustomerId(String customerId, String type, List<String> icUserIds) {
baseDao.delByCustomerId(customerId, type, icUserIds);
}
}

11
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcUserChangeRecordServiceImpl.java

@ -44,6 +44,7 @@ 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;
@ -246,8 +247,14 @@ public class IcUserChangeRecordServiceImpl extends BaseServiceImpl<IcUserChangeR
}
} while (icUserList.size() == NumConstant.ONE_THOUSAND);
//4.批量新增数据,先删后增【只删除新增节点的历史数据】
baseDao.delByCustomerId(customerId, "add");
icUserChangeDetailedService.delByCustomerId(customerId, "add");
//4-1.删除待处理的人员数据【这类人是指在变更记录表中不存在新增节点数据的人】
List<String> icUserIdList = changeList.stream().map(IcUserChangeRecordEntity::getIcUserId).collect(Collectors.toList());
List<List<String>> partition = ListUtils.partition(icUserIdList, NumConstant.FIVE_HUNDRED);
partition.forEach(part -> {
baseDao.delByCustomerId(customerId, "add", part);
icUserChangeDetailedService.delByCustomerId(customerId, "add", part);
});
log.info("初始变更记录数据,总条数->" + changeList.size());
icUserChangeRecordService.insertBatch(changeList);
log.info("初始变更记录明细数据,总条数->" + detailedList.size());

3
epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeDetailedDao.xml

@ -10,6 +10,9 @@
WHERE
CUSTOMER_ID = #{customerId}
AND type = #{type}
<foreach collection="icUserIds" item="icUserId" open="AND ic_user_id IN (" separator="," close=")">
#{icUserId}
</foreach>
</delete>
</mapper>

5
epmet-user/epmet-user-server/src/main/resources/mapper/IcUserChangeRecordDao.xml

@ -64,8 +64,11 @@
FROM
ic_user_change_record
WHERE
CUSTOMER_ID = #{customerId}
customer_id = #{customerId}
AND type = #{type}
<foreach collection="icUserIds" item="icUserId" open="AND ic_user_id IN (" separator="," close=")">
#{icUserId}
</foreach>
</delete>
</mapper>
Loading…
Cancel
Save