增加重复插入机制 允许 多次重复执行 不会出现数据重复
This commit is contained in:
parent
8464884288
commit
8831100cc4
|
|
@ -239,6 +239,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* @param date 统计日期
|
||||
*/
|
||||
public void createReportData(String corpId,Date date) {
|
||||
// 先删除当天已存在的数据,避免重复
|
||||
LambdaQueryWrapper<CustomerStatisticsData> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(CustomerStatisticsData::getCorpId, corpId)
|
||||
.eq(CustomerStatisticsData::getCurDate, date);
|
||||
dataMapper.delete(deleteWrapper);
|
||||
|
||||
// 重新计算并插入当天数据
|
||||
List<CustomerStatisticsData> oneDateData = calculateStatistics(corpId,date);
|
||||
oneDateData.forEach(item->{
|
||||
dataMapper.insert(item);
|
||||
|
|
@ -267,9 +274,14 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
item.setCorpId(corpId); // 设置企业ID
|
||||
cacheDepartMap.put(item.getId(), departmentDetail);
|
||||
parentCacheMap.put(item.getId(), item.getParentid());
|
||||
//保存部门数据
|
||||
//保存部门数据(支持重复调用:存在则更新,不存在则插入)
|
||||
CorpDepartment existingDept = departmentMapper.selectById(item.getId());
|
||||
if (existingDept != null) {
|
||||
departmentMapper.updateById(item);
|
||||
} else {
|
||||
departmentMapper.insert(item);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("存储部门数据失败!");
|
||||
}
|
||||
|
|
@ -283,7 +295,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
oneUser.setDepartId(item.getId());
|
||||
oneUser.setDepartmentName(getDepartmentFullPath(item.getId(), cacheDepartMap, parentCacheMap));
|
||||
oneUser.setCorpId(corpId); // 设置企业ID
|
||||
//保存用户数据(支持重复调用:存在则更新,不存在则插入)
|
||||
CorpUser existingUser = userMapper.selectById(oneUser.getUserid());
|
||||
if (existingUser != null) {
|
||||
userMapper.updateById(oneUser);
|
||||
} else {
|
||||
userMapper.insert(oneUser);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
@ -317,6 +335,13 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
* @param date 统计日期
|
||||
*/
|
||||
public void createDepartmentReportData(String corpId,Date date) {
|
||||
// 先删除当天已存在的数据,避免重复
|
||||
LambdaQueryWrapper<DepartmentStatisticsData> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(DepartmentStatisticsData::getCorpId, corpId)
|
||||
.eq(DepartmentStatisticsData::getStatDate, date);
|
||||
departmentStatisticsDataMapper.delete(deleteWrapper);
|
||||
|
||||
// 重新计算并插入当天数据
|
||||
List<DepartmentStatisticsData> oneDateData = calculateDepartmentStatistics(corpId,date);
|
||||
oneDateData.forEach(item -> {
|
||||
departmentStatisticsDataMapper.insert(item);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,13 @@ public class WecomTagService {
|
|||
groupDomain.setCreateTime(new Date(tagGroup.getCreateTime() * 1000));
|
||||
groupDomain.setOrderNo(tagGroup.getOrder());
|
||||
groupDomain.setCorpId(corpId); // 设置企业ID
|
||||
//保存标签组(支持重复调用:存在则更新,不存在则插入)
|
||||
WecomTagGroupDomain existingGroup = wecomTagGroupMapper.selectById(groupDomain.getTagGroupId());
|
||||
if (existingGroup != null) {
|
||||
wecomTagGroupMapper.updateById(groupDomain);
|
||||
} else {
|
||||
wecomTagGroupMapper.insert(groupDomain);
|
||||
}
|
||||
// 保存标签
|
||||
List<WecomTag> tagList = tagGroup.getTag();
|
||||
if (tagList != null && !tagList.isEmpty()) {
|
||||
|
|
@ -67,11 +73,16 @@ public class WecomTagService {
|
|||
tagDomain.setSyncTime(new Date());
|
||||
tagDomain.setCorpId(corpId); // 设置企业ID
|
||||
|
||||
// 插入标签
|
||||
// 插入标签(支持重复调用:存在则更新,不存在则插入)
|
||||
WecomTagDomain existingTag = wecomTagMapper.selectById(tagDomain.getTagId());
|
||||
if (existingTag != null) {
|
||||
wecomTagMapper.updateById(tagDomain);
|
||||
} else {
|
||||
wecomTagMapper.insert(tagDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
Loading…
Reference in New Issue