修改定时任务启动时报错的问题
This commit is contained in:
parent
daa0172240
commit
e9d0b0921c
|
|
@ -11,7 +11,6 @@ import com.ruoyi.excel.wecom.model.WecomTagGroup;
|
||||||
import com.ruoyi.excel.wecom.service.CustomerExportService;
|
import com.ruoyi.excel.wecom.service.CustomerExportService;
|
||||||
import com.ruoyi.excel.wecom.service.WecomContactService;
|
import com.ruoyi.excel.wecom.service.WecomContactService;
|
||||||
import com.ruoyi.excel.wecom.service.WecomTagService;
|
import com.ruoyi.excel.wecom.service.WecomTagService;
|
||||||
import com.ruoyi.common.utils.CorpContextHolder;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
|
@ -98,9 +97,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
processBatch(batch,finalCorpId);
|
processBatch(batch,finalCorpId);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("处理批次数据失败: " + e.getMessage(), e);
|
throw new RuntimeException("处理批次数据失败: " + e.getMessage(), e);
|
||||||
} finally {
|
|
||||||
// 清理子线程的上下文
|
|
||||||
CorpContextHolder.clear();
|
|
||||||
}
|
}
|
||||||
}, executorService);
|
}, executorService);
|
||||||
|
|
||||||
|
|
@ -115,7 +111,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -316,7 +311,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
List<WecomTagGroup> tagGroupList = wecomContactService.getCorpTagList(corpId);
|
List<WecomTagGroup> tagGroupList = wecomContactService.getCorpTagList(corpId);
|
||||||
|
|
||||||
// 同步标签库到数据库
|
// 同步标签库到数据库
|
||||||
wecomTagService.syncCorpTagList(tagGroupList);
|
wecomTagService.syncCorpTagList(tagGroupList,corpId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("存储标签数据失败!");
|
throw new RuntimeException("存储标签数据失败!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ public class CustomerDataChangeTrackingService {
|
||||||
* @return 历史记录ID
|
* @return 历史记录ID
|
||||||
*/
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long saveDataChange(Long customerId, CustomerExportData newData, String changeType) {
|
public Long saveDataChange(String cropId,Long customerId, CustomerExportData newData, String changeType) {
|
||||||
if (customerId == null || newData == null) {
|
if (customerId == null || newData == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -192,6 +192,7 @@ public class CustomerDataChangeTrackingService {
|
||||||
// 3. 创建历史记录
|
// 3. 创建历史记录
|
||||||
CustomerExportDataHistory history = new CustomerExportDataHistory();
|
CustomerExportDataHistory history = new CustomerExportDataHistory();
|
||||||
BeanUtils.copyProperties(newData, history);
|
BeanUtils.copyProperties(newData, history);
|
||||||
|
history.setCorpId(cropId);
|
||||||
history.setHistoryId(null); // 清除ID,让数据库自动生成
|
history.setHistoryId(null); // 清除ID,让数据库自动生成
|
||||||
history.setCustomerId(customerId);
|
history.setCustomerId(customerId);
|
||||||
history.setVersion(newVersion);
|
history.setVersion(newVersion);
|
||||||
|
|
@ -208,7 +209,7 @@ public class CustomerDataChangeTrackingService {
|
||||||
CustomerExportDataHistory previousHistory = historyMapper.selectByCustomerIdAndVersion(customerId, newVersion - 1);
|
CustomerExportDataHistory previousHistory = historyMapper.selectByCustomerIdAndVersion(customerId, newVersion - 1);
|
||||||
if (previousHistory != null) {
|
if (previousHistory != null) {
|
||||||
// 比较字段变更
|
// 比较字段变更
|
||||||
List<CustomerDataChangeLog> changeLogs = compareAndGenerateChangeLogs(
|
List<CustomerDataChangeLog> changeLogs = compareAndGenerateChangeLogs(cropId,
|
||||||
history.getHistoryId(), customerId, newVersion, previousHistory, history);
|
history.getHistoryId(), customerId, newVersion, previousHistory, history);
|
||||||
|
|
||||||
// 批量保存变更日志
|
// 批量保存变更日志
|
||||||
|
|
@ -231,7 +232,7 @@ public class CustomerDataChangeTrackingService {
|
||||||
* @param newData 新数据
|
* @param newData 新数据
|
||||||
* @return 变更日志列表
|
* @return 变更日志列表
|
||||||
*/
|
*/
|
||||||
private List<CustomerDataChangeLog> compareAndGenerateChangeLogs(
|
private List<CustomerDataChangeLog> compareAndGenerateChangeLogs(String corpId,
|
||||||
Long historyId, Long customerId, Integer version,
|
Long historyId, Long customerId, Integer version,
|
||||||
CustomerExportDataHistory oldData, CustomerExportDataHistory newData) {
|
CustomerExportDataHistory oldData, CustomerExportDataHistory newData) {
|
||||||
|
|
||||||
|
|
@ -265,6 +266,7 @@ public class CustomerDataChangeTrackingService {
|
||||||
changeLog.setNewValue(newValue != null ? newValue.toString() : null);
|
changeLog.setNewValue(newValue != null ? newValue.toString() : null);
|
||||||
changeLog.setChangeTime(changeTime);
|
changeLog.setChangeTime(changeTime);
|
||||||
changeLog.setVersion(version);
|
changeLog.setVersion(version);
|
||||||
|
changeLog.setCorpId(corpId);
|
||||||
|
|
||||||
changeLogs.add(changeLog);
|
changeLogs.add(changeLog);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public class CustomerExportService {
|
||||||
customerExportDataMapper.insert(exportData);
|
customerExportDataMapper.insert(exportData);
|
||||||
|
|
||||||
// 保存新增记录到历史表
|
// 保存新增记录到历史表
|
||||||
changeTrackingService.saveDataChange(exportData.getId(), exportData, "INSERT");
|
changeTrackingService.saveDataChange(corpId,exportData.getId(), exportData, "INSERT");
|
||||||
|
|
||||||
insertCount++;
|
insertCount++;
|
||||||
successCount++;
|
successCount++;
|
||||||
|
|
@ -141,7 +141,7 @@ public class CustomerExportService {
|
||||||
customerExportDataMapper.updateById(exportData);
|
customerExportDataMapper.updateById(exportData);
|
||||||
|
|
||||||
// 保存变更记录到历史表和变更日志表
|
// 保存变更记录到历史表和变更日志表
|
||||||
changeTrackingService.saveDataChange(existingData.getId(), exportData, "UPDATE");
|
changeTrackingService.saveDataChange(corpId,existingData.getId(), exportData, "UPDATE");
|
||||||
|
|
||||||
updateCount++;
|
updateCount++;
|
||||||
successCount++;
|
successCount++;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import com.ruoyi.excel.wecom.mapper.WecomTagGroupMapper;
|
||||||
import com.ruoyi.excel.wecom.mapper.WecomTagMapper;
|
import com.ruoyi.excel.wecom.mapper.WecomTagMapper;
|
||||||
import com.ruoyi.excel.wecom.model.WecomTag;
|
import com.ruoyi.excel.wecom.model.WecomTag;
|
||||||
import com.ruoyi.excel.wecom.model.WecomTagGroup;
|
import com.ruoyi.excel.wecom.model.WecomTagGroup;
|
||||||
import com.ruoyi.common.utils.CorpContextHolder;
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -35,14 +34,7 @@ public class WecomTagService {
|
||||||
* @param tagGroupList 标签库列表
|
* @param tagGroupList 标签库列表
|
||||||
* @return 同步结果
|
* @return 同步结果
|
||||||
*/
|
*/
|
||||||
public boolean syncCorpTagList(List<WecomTagGroup> tagGroupList) {
|
public boolean syncCorpTagList(List<WecomTagGroup> tagGroupList,String corpId) {
|
||||||
// 从 Redis 获取当前企业ID并设置到上下文
|
|
||||||
String corpId = redisCache.getCacheObject("current_corp_id");
|
|
||||||
if (corpId == null || corpId.trim().isEmpty()) {
|
|
||||||
throw new RuntimeException("未找到当前企业ID,请先切换企业");
|
|
||||||
}
|
|
||||||
CorpContextHolder.setCurrentCorpId(corpId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 遍历标签组列表
|
// 遍历标签组列表
|
||||||
for (WecomTagGroup tagGroup : tagGroupList) {
|
for (WecomTagGroup tagGroup : tagGroupList) {
|
||||||
|
|
@ -87,9 +79,6 @@ public class WecomTagService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
// 清理上下文
|
|
||||||
CorpContextHolder.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,12 @@
|
||||||
<!-- 批量插入变更日志 -->
|
<!-- 批量插入变更日志 -->
|
||||||
<insert id="batchInsert" parameterType="java.util.List">
|
<insert id="batchInsert" parameterType="java.util.List">
|
||||||
INSERT INTO customer_data_change_log (
|
INSERT INTO customer_data_change_log (
|
||||||
|
corp_id,
|
||||||
history_id, customer_id, version, field_name, field_label,
|
history_id, customer_id, version, field_name, field_label,
|
||||||
old_value, new_value, change_time
|
old_value, new_value, change_time
|
||||||
) VALUES
|
) VALUES
|
||||||
<foreach collection="list" item="item" separator=",">
|
<foreach collection="changeLogs" item="item" separator=",">
|
||||||
(
|
(#{item.corpId},
|
||||||
#{item.historyId}, #{item.customerId}, #{item.version},
|
#{item.historyId}, #{item.customerId}, #{item.version},
|
||||||
#{item.fieldName}, #{item.fieldLabel}, #{item.oldValue},
|
#{item.fieldName}, #{item.fieldLabel}, #{item.oldValue},
|
||||||
#{item.newValue}, #{item.changeTime}
|
#{item.newValue}, #{item.changeTime}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue