0325-海宁pad走访修改
This commit is contained in:
@@ -4,6 +4,8 @@ import com.ruoyi.group.domain.dto.CustGroupMemberQueryDTO;
|
||||
import com.ruoyi.group.domain.entity.CustGroup;
|
||||
import com.ruoyi.group.domain.entity.CustGroupMember;
|
||||
import com.ruoyi.group.domain.vo.CustGroupMemberVO;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.group.mapper.CustGroupMapper;
|
||||
import com.ruoyi.group.mapper.CustGroupMemberMapper;
|
||||
import com.ruoyi.group.service.ICustGroupService;
|
||||
@@ -43,7 +45,10 @@ public class CustGroupMemberServiceImpl implements ICustGroupMemberService {
|
||||
// 检查客群是否存在
|
||||
CustGroup custGroup = custGroupMapper.selectById(groupId);
|
||||
if (custGroup == null) {
|
||||
return "客群不存在";
|
||||
throw new ServiceException("客群不存在");
|
||||
}
|
||||
if (!SecurityUtils.getUsername().equals(custGroup.getUserName())) {
|
||||
throw new ServiceException("无权限操作该客群");
|
||||
}
|
||||
|
||||
// 删除客户关联
|
||||
@@ -52,6 +57,7 @@ public class CustGroupMemberServiceImpl implements ICustGroupMemberService {
|
||||
if (member != null && member.getGroupId().equals(groupId)) {
|
||||
// 设置手动移除标识
|
||||
member.setManualRemove(1);
|
||||
custGroupMemberMapper.updateById(member);
|
||||
// 逻辑删除
|
||||
custGroupMemberMapper.deleteById(memberId);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.ibs.cmpm.domain.vo.GridCmpmVO;
|
||||
import com.ruoyi.ibs.cmpm.service.GridCmpmService;
|
||||
import com.ruoyi.ibs.draw.mapper.DrawGridCustUserUnbindMapper;
|
||||
import com.ruoyi.ibs.draw.mapper.DrawGridShapeRelateMapper;
|
||||
import com.ruoyi.ibs.grid.service.RegionGridListService;
|
||||
import com.ruoyi.group.domain.dto.CustGroupMemberTemplate;
|
||||
import com.ruoyi.group.domain.dto.CustGroupQueryDTO;
|
||||
@@ -59,7 +59,7 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
private RegionGridListService regionGridListService;
|
||||
|
||||
@Resource
|
||||
private DrawGridCustUserUnbindMapper drawGridCustUserUnbindMapper;
|
||||
private DrawGridShapeRelateMapper drawGridShapeRelateMapper;
|
||||
|
||||
@Resource
|
||||
private TransactionTemplate transactionTemplate;
|
||||
@@ -418,6 +418,8 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
|
||||
log.info("找到 {} 个动态客群需要更新", dynamicGroups.size());
|
||||
Date now = new Date();
|
||||
int successCount = 0;
|
||||
int failureCount = 0;
|
||||
|
||||
for (CustGroup custGroup : dynamicGroups) {
|
||||
// 检查有效期,过期的客群跳过更新
|
||||
@@ -429,22 +431,18 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
|
||||
try {
|
||||
updateDynamicCustGroup(custGroup);
|
||||
successCount++;
|
||||
log.info("动态客群更新成功,客群ID:{},客群名称:{}", custGroup.getId(), custGroup.getGroupName());
|
||||
} catch (Exception e) {
|
||||
failureCount++;
|
||||
log.error("动态客群更新失败,客群ID:{},客群名称:{}", custGroup.getId(), custGroup.getGroupName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("动态客群更新完成,总计:{},成功:{},失败:{}",
|
||||
dynamicGroups.size(),
|
||||
dynamicGroups.stream().filter(g -> {
|
||||
// 假设更新成功的状态设置
|
||||
LambdaQueryWrapper<CustGroup> w = new LambdaQueryWrapper<>();
|
||||
w.eq(CustGroup::getId, g.getId());
|
||||
// 这里简单统计,实际可以通过更精确的方式
|
||||
return true;
|
||||
}).count(),
|
||||
0);
|
||||
successCount,
|
||||
failureCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -655,7 +653,6 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
int batchSize = 1000;
|
||||
int successCount = 0;
|
||||
int skippedCount = 0;
|
||||
int restoredCount = 0;
|
||||
for (int i = 0; i < memberList.size(); i += batchSize) {
|
||||
int endIndex = Math.min(i + batchSize, memberList.size());
|
||||
List<CustGroupMember> batchList = memberList.subList(i, endIndex);
|
||||
@@ -665,30 +662,23 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
custGroupMemberMapper.insert(member);
|
||||
successCount++;
|
||||
} catch (DuplicateKeyException e) {
|
||||
// 客户已存在,检查是否是被手动移除的
|
||||
// 客户已存在(包含被手动移除后保留的记录),直接跳过,避免再次加入客群
|
||||
LambdaQueryWrapper<CustGroupMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CustGroupMember::getGroupId, member.getGroupId())
|
||||
.eq(CustGroupMember::getCustId, member.getCustId())
|
||||
.eq(CustGroupMember::getCustType, member.getCustType());
|
||||
CustGroupMember existMember = custGroupMemberMapper.selectOne(queryWrapper);
|
||||
skippedCount++;
|
||||
if (existMember != null && existMember.getManualRemove() != null && existMember.getManualRemove() == 1) {
|
||||
// 是被手动移除的客户,清除标记并恢复
|
||||
existMember.setManualRemove(0);
|
||||
existMember.setDelFlag(0);
|
||||
existMember.setCustName(member.getCustName());
|
||||
custGroupMemberMapper.updateById(existMember);
|
||||
restoredCount++;
|
||||
log.debug("恢复手动移除的客户:groupId={}, custId={}", member.getGroupId(), member.getCustId());
|
||||
log.debug("客户已被手动移除,跳过重新导入:groupId={}, custId={}", member.getGroupId(), member.getCustId());
|
||||
} else {
|
||||
// 正常存在的客户,跳过
|
||||
skippedCount++;
|
||||
log.debug("客户已存在,跳过:groupId={}, custId={}", member.getGroupId(), member.getCustId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("客群客户导入完成(模板),客群ID:{},成功:{},跳过重复:{},恢复:{}",
|
||||
custGroup.getId(), successCount, skippedCount, restoredCount);
|
||||
log.info("客群客户导入完成(模板),客群ID:{},成功:{},跳过重复:{}",
|
||||
custGroup.getId(), successCount, skippedCount);
|
||||
// 更新创建状态为成功
|
||||
custGroup.setCreateStatus("1");
|
||||
custGroup.setUpdateBy(custGroup.getCreateBy());
|
||||
@@ -747,7 +737,6 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
// 分批批量插入(每批1000条)
|
||||
int batchSize = 1000;
|
||||
int totalInserted = 0;
|
||||
int totalRestored = 0;
|
||||
int totalSkipped = 0;
|
||||
|
||||
for (int i = 0; i < memberList.size(); i += batchSize) {
|
||||
@@ -759,28 +748,13 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
// SQL层面的批量插入
|
||||
custGroupMemberMapper.batchInsertMembers(batchList);
|
||||
|
||||
// 查询本批中被手动移除的客户,需要恢复
|
||||
List<CustGroupMember> toRestore = findManualRemovedToRestore(custGroup.getId(), batchList);
|
||||
if (!toRestore.isEmpty()) {
|
||||
// 恢复被手动移除的客户
|
||||
for (CustGroupMember m : toRestore) {
|
||||
batchList.stream()
|
||||
.filter(b -> b.getCustId().equals(m.getCustId()) && b.getCustType().equals(m.getCustType()))
|
||||
.findFirst()
|
||||
.ifPresent(origin -> m.setCustName(origin.getCustName()));
|
||||
m.setManualRemove(0);
|
||||
custGroupMemberMapper.updateById(m);
|
||||
}
|
||||
log.info("本批恢复被手动移除的客户:{} 条", toRestore.size());
|
||||
totalRestored += toRestore.size();
|
||||
}
|
||||
|
||||
totalInserted += batchList.size() - toRestore.size();
|
||||
totalSkipped += toRestore.size();
|
||||
int manualRemovedCount = countManualRemovedMembers(custGroup.getId(), batchList);
|
||||
totalInserted += batchList.size() - manualRemovedCount;
|
||||
totalSkipped += manualRemovedCount;
|
||||
}
|
||||
|
||||
log.info("客群客户导入完成(网格),客群ID:{},插入:{},恢复:{},跳过:{}",
|
||||
custGroup.getId(), totalInserted, totalRestored, totalSkipped);
|
||||
log.info("客群客户导入完成(网格),客群ID:{},插入:{},跳过:{}",
|
||||
custGroup.getId(), totalInserted, totalSkipped);
|
||||
|
||||
// 更新创建状态为成功
|
||||
custGroup.setCreateStatus("1");
|
||||
@@ -814,29 +788,21 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找需要恢复的被手动移除的客户
|
||||
*
|
||||
* @param groupId 客群ID
|
||||
* @param batchList 本批导入的客户列表
|
||||
* @return 需要恢复的客户列表
|
||||
* 统计本批中被手动移除、因此需要持续排除的客户数量
|
||||
*/
|
||||
private List<CustGroupMember> findManualRemovedToRestore(Long groupId, List<CustGroupMember> batchList) {
|
||||
// 构建本批客户的 (custId, custType) 集合
|
||||
private int countManualRemovedMembers(Long groupId, List<CustGroupMember> batchList) {
|
||||
Set<String> batchKeys = batchList.stream()
|
||||
.map(m -> m.getCustId() + "|" + m.getCustType())
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 查询该客群所有被手动移除的客户
|
||||
LambdaQueryWrapper<CustGroupMember> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CustGroupMember::getGroupId, groupId)
|
||||
.eq(CustGroupMember::getManualRemove, 1)
|
||||
.eq(CustGroupMember::getDelFlag, 0);
|
||||
.eq(CustGroupMember::getManualRemove, 1);
|
||||
List<CustGroupMember> manualRemovedList = custGroupMemberMapper.selectList(queryWrapper);
|
||||
|
||||
// 筛选出本批中需要恢复的
|
||||
return manualRemovedList.stream()
|
||||
return (int) manualRemovedList.stream()
|
||||
.filter(m -> batchKeys.contains(m.getCustId() + "|" + m.getCustType()))
|
||||
.collect(Collectors.toList());
|
||||
.count();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -907,7 +873,7 @@ public class CustGroupServiceImpl implements ICustGroupService {
|
||||
}
|
||||
// 使用 selectCustByDrawGridId 方法(直接在SQL中拼接headId,绕过拦截器)
|
||||
for (Long gridId : gridImportDTO.getDrawGridIds()) {
|
||||
List<RegionCustUser> custUsers = drawGridCustUserUnbindMapper.selectCustByDrawGridId(gridId, headId);
|
||||
List<RegionCustUser> custUsers = drawGridShapeRelateMapper.selectCustByDrawGridId(gridId, headId);
|
||||
if (custUsers != null && !custUsers.isEmpty()) {
|
||||
for (RegionCustUser custUser : custUsers) {
|
||||
CustGroupMember member = new CustGroupMember();
|
||||
|
||||
Reference in New Issue
Block a user