Commit da13cbc1 by zhouhaibao

feat(event): 添加事件记录中的创建者信息字段

- 修改 recordEvent 方法签名,增加 createdBy 参数
- 更新 recordSubmitChangeEvent 方法以传递创建者信息
- 在事件记录中存储 createdBy 字段到数据库
- 调整 H5 页面浏览事件记录方法以保持参数一致性
- 移除过时的单元测试方法
- 在策略服务中传递创建者和更新者信息到事件记录方法
1 parent 75ac22e2
...@@ -27,14 +27,14 @@ public class SopStrategyEventLogService { ...@@ -27,14 +27,14 @@ public class SopStrategyEventLogService {
public static final String EVENT_CODE_H5_PAGE_VIEW = "sop_strategy_h5_marketing_page_view"; public static final String EVENT_CODE_H5_PAGE_VIEW = "sop_strategy_h5_marketing_page_view";
public void recordMenuEntryEvent() { public void recordMenuEntryEvent() {
recordEvent(null, null, "SOP策略", EVENT_CODE_MENU_ENTRY, null); recordEvent(null, null, "SOP策略", EVENT_CODE_MENU_ENTRY, null, null);
} }
public void recordSubmitChangeEvent(Integer strategyId, Long taskId) { public void recordSubmitChangeEvent(Integer strategyId, Long taskId, String createdBy) {
Map<String, Object> eventData = new HashMap<>(); Map<String, Object> eventData = new HashMap<>();
eventData.put("strategyId", strategyId); eventData.put("strategyId", strategyId);
eventData.put("taskId", taskId); eventData.put("taskId", taskId);
recordEvent(strategyId, null, "SOP策略", EVENT_CODE_SUBMIT_CHANGE, eventData); recordEvent(strategyId, null, "SOP策略", EVENT_CODE_SUBMIT_CHANGE, eventData,createdBy);
} }
public void recordH5PageViewEvent(Integer strategyId, Long taskId, public void recordH5PageViewEvent(Integer strategyId, Long taskId,
...@@ -46,11 +46,12 @@ public class SopStrategyEventLogService { ...@@ -46,11 +46,12 @@ public class SopStrategyEventLogService {
eventData.put("storeName", storeName); eventData.put("storeName", storeName);
eventData.put("customerName", customerName); eventData.put("customerName", customerName);
eventData.put("customerPhone", customerPhone); eventData.put("customerPhone", customerPhone);
recordEvent(strategyId, taskId,"SOP策略", EVENT_CODE_H5_PAGE_VIEW, eventData); recordEvent(strategyId, taskId,"SOP策略", EVENT_CODE_H5_PAGE_VIEW, eventData, null);
} }
private void recordEvent(Integer strategyId, private void recordEvent(Integer strategyId,
Long taskId, String eventType, String eventCode, Map<String, Object> eventData) { Long taskId, String eventType, String eventCode, Map<String, Object> eventData,
String createdBy) {
try { try {
SopStrategyEventLog eventLog = new SopStrategyEventLog(); SopStrategyEventLog eventLog = new SopStrategyEventLog();
eventLog.setStrategyId(strategyId); eventLog.setStrategyId(strategyId);
...@@ -65,6 +66,7 @@ public class SopStrategyEventLogService { ...@@ -65,6 +66,7 @@ public class SopStrategyEventLogService {
} }
} }
eventLog.setEventTime(new Date()); eventLog.setEventTime(new Date());
eventLog.setCreatedBy(createdBy);
eventLog.setDeletedFlag("N"); eventLog.setDeletedFlag("N");
sopStrategyEventLogMapper.insertSelective(eventLog); sopStrategyEventLogMapper.insertSelective(eventLog);
log.info("记录埋点事件成功, eventCode:{}, strategyId:{}", log.info("记录埋点事件成功, eventCode:{}, strategyId:{}",
......
...@@ -78,7 +78,7 @@ public class StrategySopService { ...@@ -78,7 +78,7 @@ public class StrategySopService {
saveStrategyBranches(strategyId, request.getBranches(), createdBy); saveStrategyBranches(strategyId, request.getBranches(), createdBy);
sopStrategyEventLogService.recordSubmitChangeEvent(strategyId, null); sopStrategyEventLogService.recordSubmitChangeEvent(strategyId, null,createdBy);
log.info("创建策略成功, strategyId:{}, strategyCode:{}", strategyId, strategyCode); log.info("创建策略成功, strategyId:{}, strategyCode:{}", strategyId, strategyCode);
return strategyId; return strategyId;
} }
...@@ -110,7 +110,7 @@ public class StrategySopService { ...@@ -110,7 +110,7 @@ public class StrategySopService {
sopStrategyBranchMapper.deleteByStrategyId(request.getStrategyId()); sopStrategyBranchMapper.deleteByStrategyId(request.getStrategyId());
saveStrategyBranches(request.getStrategyId(), request.getBranches(), updatedBy); saveStrategyBranches(request.getStrategyId(), request.getBranches(), updatedBy);
sopStrategyEventLogService.recordSubmitChangeEvent(request.getStrategyId(), null); sopStrategyEventLogService.recordSubmitChangeEvent(request.getStrategyId(), null, updatedBy);
sopStrategySnapshotCacheService.evictStrategyCache(request.getStrategyId()); sopStrategySnapshotCacheService.evictStrategyCache(request.getStrategyId());
log.info("更新策略成功, strategyId:{}, version:{}", request.getStrategyId(), strategy.getVersion()); log.info("更新策略成功, strategyId:{}, version:{}", request.getStrategyId(), strategy.getVersion());
return true; return true;
......
...@@ -43,25 +43,6 @@ public class SopStrategyEventLogServiceTest { ...@@ -43,25 +43,6 @@ public class SopStrategyEventLogServiceTest {
} }
@Test @Test
public void testRecordSubmitChangeEvent() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordSubmitChangeEvent(1, 100L);
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordSubmitChangeEvent_NullExecutionRecordId() {
doNothing().when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
sopStrategyEventLogService.recordSubmitChangeEvent(1, null);
verify(sopStrategyEventLogMapper, times(1)).insertSelective(any(SopStrategyEventLog.class));
}
@Test
public void testRecordEvent_Exception() { public void testRecordEvent_Exception() {
doThrow(new RuntimeException("数据库异常")).when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class)); doThrow(new RuntimeException("数据库异常")).when(sopStrategyEventLogMapper).insertSelective(any(SopStrategyEventLog.class));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!