修改调用任务时报错的问题
This commit is contained in:
parent
e9d0b0921c
commit
61d640da2b
|
|
@ -4,6 +4,7 @@ import com.ruoyi.excel.wecom.domain.*;
|
|||
import com.ruoyi.excel.wecom.enums.AddWayEnum;
|
||||
import com.ruoyi.excel.wecom.mapper.*;
|
||||
import com.ruoyi.excel.wecom.model.WecomCustomer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -15,6 +16,7 @@ import java.util.stream.Collectors;
|
|||
* 客户导出服务类
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CustomerExportService {
|
||||
|
||||
@Autowired
|
||||
|
|
@ -48,31 +50,31 @@ public class CustomerExportService {
|
|||
*/
|
||||
@PostConstruct
|
||||
public void initCache() {
|
||||
System.out.println("开始初始化缓存数据...");
|
||||
log.debug("开始初始化缓存数据...");
|
||||
|
||||
// 1. 加载用户数据
|
||||
List<CorpUser> userList = corpUserMapper.selectList(null);
|
||||
userIdToUserMap = userList.stream()
|
||||
.collect(Collectors.toMap(CorpUser::getUserid, user -> user, (v1, v2) -> v1));
|
||||
System.out.println("已加载 " + userIdToUserMap.size() + " 个用户");
|
||||
log.debug("已加载 " + userIdToUserMap.size() + " 个用户");
|
||||
|
||||
// 2. 加载部门数据
|
||||
List<CorpDepartment> departmentList = corpDepartmentMapper.selectList(null);
|
||||
departmentIdToNameMap = departmentList.stream()
|
||||
.collect(Collectors.toMap(CorpDepartment::getId, CorpDepartment::getName, (v1, v2) -> v1));
|
||||
System.out.println("已加载 " + departmentIdToNameMap.size() + " 个部门");
|
||||
log.debug("已加载 " + departmentIdToNameMap.size() + " 个部门");
|
||||
|
||||
// 3. 加载标签数据
|
||||
List<WecomTagDomain> tagList = wecomTagMapper.selectList(null);
|
||||
tagIdToTagMap = tagList.stream()
|
||||
.collect(Collectors.toMap(WecomTagDomain::getTagId, tag -> tag, (v1, v2) -> v1));
|
||||
System.out.println("已加载 " + tagIdToTagMap.size() + " 个标签");
|
||||
log.debug("已加载 " + tagIdToTagMap.size() + " 个标签");
|
||||
|
||||
// 4. 加载标签组数据
|
||||
List<WecomTagGroupDomain> tagGroupList = wecomTagGroupMapper.selectList(null);
|
||||
tagGroupIdToGroupMap = tagGroupList.stream()
|
||||
.collect(Collectors.toMap(WecomTagGroupDomain::getTagGroupId, group -> group, (v1, v2) -> v1));
|
||||
System.out.println("已加载 " + tagGroupIdToGroupMap.size() + " 个标签组");
|
||||
log.debug("已加载 " + tagGroupIdToGroupMap.size() + " 个标签组");
|
||||
|
||||
// 5. 构建标签组到标签列表的映射
|
||||
for (WecomTagDomain tag : tagList) {
|
||||
|
|
@ -80,7 +82,7 @@ public class CustomerExportService {
|
|||
tagGroupIdToTagsMap.computeIfAbsent(groupId, k -> new ArrayList<>()).add(tag);
|
||||
}
|
||||
|
||||
System.out.println("缓存初始化完成!");
|
||||
log.debug("缓存初始化完成!");
|
||||
}
|
||||
|
||||
public List<Date> getAllDate(String corpId) {
|
||||
|
|
@ -98,7 +100,7 @@ public class CustomerExportService {
|
|||
*/
|
||||
public int handleData(String corpId,List<WecomCustomer> customerList) {
|
||||
if (customerList == null || customerList.isEmpty()) {
|
||||
System.out.println("客户列表为空,无需处理");
|
||||
log.debug("客户列表为空,无需处理");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +108,7 @@ public class CustomerExportService {
|
|||
int insertCount = 0;
|
||||
int updateCount = 0;
|
||||
int unchangedCount = 0;
|
||||
System.out.println("开始处理 " + customerList.size() + " 个客户数据...");
|
||||
log.info("开始处理 " + customerList.size() + " 个客户数据...");
|
||||
|
||||
for (WecomCustomer customer : customerList) {
|
||||
try {
|
||||
|
|
@ -130,7 +132,7 @@ public class CustomerExportService {
|
|||
|
||||
insertCount++;
|
||||
successCount++;
|
||||
System.out.println("新增客户: " + exportData.getCustomerName());
|
||||
log.debug("新增客户: " + exportData.getCustomerName());
|
||||
} else {
|
||||
// 检查数据是否发生变更
|
||||
boolean hasChanged = changeTrackingService.hasDataChanged(existingData.getId(), exportData);
|
||||
|
|
@ -145,26 +147,26 @@ public class CustomerExportService {
|
|||
|
||||
updateCount++;
|
||||
successCount++;
|
||||
System.out.println("更新客户: " + exportData.getCustomerName() + " (数据已变更)");
|
||||
log.debug("更新客户: " + exportData.getCustomerName() + " (数据已变更)");
|
||||
} else {
|
||||
// 数据未变更,跳过更新
|
||||
unchangedCount++;
|
||||
System.out.println("跳过客户: " + exportData.getCustomerName() + " (数据未变更)");
|
||||
log.debug("跳过客户: " + exportData.getCustomerName() + " (数据未变更)");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("处理客户数据失败: " + e.getMessage());
|
||||
log.error("处理客户数据失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("数据处理完成!");
|
||||
System.out.println("总计: " + customerList.size() + " 条");
|
||||
System.out.println("新增: " + insertCount + " 条");
|
||||
System.out.println("更新: " + updateCount + " 条");
|
||||
System.out.println("未变更: " + unchangedCount + " 条");
|
||||
System.out.println("成功: " + successCount + " 条");
|
||||
log.info("数据处理完成!");
|
||||
log.info("总计: " + customerList.size() + " 条");
|
||||
log.info("新增: " + insertCount + " 条");
|
||||
log.info("更新: " + updateCount + " 条");
|
||||
log.info("未变更: " + unchangedCount + " 条");
|
||||
log.info("成功: " + successCount + " 条");
|
||||
return successCount;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.ruoyi.quartz.task;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ruoyi.excel.wecom.domain.CorpInfo;
|
||||
import com.ruoyi.excel.wecom.helper.HandleAllData;
|
||||
import com.ruoyi.excel.wecom.mapper.CorpInfoMapper;
|
||||
|
|
@ -7,7 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -38,24 +40,23 @@ public class WeComTask {
|
|||
}
|
||||
|
||||
public void createCurDateCustomerReport() throws IOException {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateStr = simpleDateFormat.format(date);
|
||||
System.out.println("计算" + dateStr + "流量看板数据");
|
||||
Date from = Date.from(LocalDate.now().atStartOfDay()
|
||||
.atZone(ZoneId.systemDefault()).toInstant());
|
||||
System.out.println("计算" + JSON.toJSONString(from) + "流量看板数据");
|
||||
List<CorpInfo> corpInfos = corpInfoMapper.selectCorpInfoList(new CorpInfo());
|
||||
corpInfos.forEach(item->{
|
||||
handleAllData.createReportData(item.getCorpId(),new Date(dateStr));
|
||||
handleAllData.createReportData(item.getCorpId(), from);
|
||||
});
|
||||
}
|
||||
|
||||
public void createCurDateDepartmentReportData() throws IOException {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String dateStr = simpleDateFormat.format(date);
|
||||
System.out.println("计算" + dateStr + "销售看板数据");
|
||||
Date from = Date.from(LocalDate.now().atStartOfDay()
|
||||
.atZone(ZoneId.systemDefault()).toInstant());
|
||||
System.out.println("计算" + JSON.toJSONString(from) + "销售看板数据");
|
||||
List<CorpInfo> corpInfos = corpInfoMapper.selectCorpInfoList(new CorpInfo());
|
||||
corpInfos.forEach(item->{
|
||||
handleAllData.createDepartmentReportData(item.getCorpId(),new Date(dateStr));
|
||||
handleAllData.createDepartmentReportData(item.getCorpId(),Date.from(LocalDate.now().atStartOfDay()
|
||||
.atZone(ZoneId.systemDefault()).toInstant()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue