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