实现参数保存后自动触发项目重打标
This commit is contained in:
@@ -116,6 +116,7 @@ public class CcdiModelParamServiceImpl implements ICcdiModelParamService {
|
||||
}
|
||||
|
||||
String username = SecurityUtils.getUsername();
|
||||
int updatedCount = 0;
|
||||
for (ModelParamSaveDTO.ParamValueItem item : saveDTO.getParams()) {
|
||||
int updated = modelParamMapper.updateParamValue(
|
||||
projectId,
|
||||
@@ -126,9 +127,12 @@ public class CcdiModelParamServiceImpl implements ICcdiModelParamService {
|
||||
);
|
||||
if (updated == 0) {
|
||||
log.warn("参数不存在或未更新,paramCode={}", item.getParamCode());
|
||||
continue;
|
||||
}
|
||||
updatedCount += updated;
|
||||
}
|
||||
|
||||
submitAutoRebuildIfNeeded(projectId, updatedCount);
|
||||
} catch (ServiceException e) {
|
||||
// 业务异常,直接抛出
|
||||
throw e;
|
||||
@@ -218,11 +222,7 @@ public class CcdiModelParamServiceImpl implements ICcdiModelParamService {
|
||||
if (!updateList.isEmpty()) {
|
||||
modelParamMapper.batchUpdateParamValues(updateList);
|
||||
log.info("批量更新参数成功, count={}", updateList.size());
|
||||
if (projectId > 0) {
|
||||
bankTagService.submitAutoRebuild(projectId, TriggerType.AUTO_PARAM_CHANGE);
|
||||
log.info("项目参数保存成功,已触发流水自动重打标: projectId={}, updatedCount={}",
|
||||
projectId, updateList.size());
|
||||
}
|
||||
submitAutoRebuildIfNeeded(projectId, updateList.size());
|
||||
}
|
||||
} catch (ServiceException e) {
|
||||
throw e;
|
||||
@@ -300,4 +300,13 @@ public class CcdiModelParamServiceImpl implements ICcdiModelParamService {
|
||||
target.setUpdateBy(username);
|
||||
return target;
|
||||
}
|
||||
|
||||
private void submitAutoRebuildIfNeeded(Long projectId, int updatedCount) {
|
||||
if (projectId == null || projectId <= 0 || updatedCount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bankTagService.submitAutoRebuild(projectId, TriggerType.AUTO_PARAM_CHANGE);
|
||||
log.info("项目参数保存成功,已触发流水自动重打标: projectId={}, updatedCount={}", projectId, updatedCount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,16 @@ class CcdiBankTagServiceImplTest {
|
||||
@Mock
|
||||
private ICcdiProjectService projectService;
|
||||
|
||||
@Mock
|
||||
private ProjectBankTagRebuildCoordinator coordinator;
|
||||
|
||||
@Test
|
||||
void submitAutoRebuild_shouldKeepAutoParamChangeTriggerType() {
|
||||
service.submitAutoRebuild(40L, TriggerType.AUTO_PARAM_CHANGE);
|
||||
|
||||
verify(coordinator).submitAuto(40L, TriggerType.AUTO_PARAM_CHANGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rebuildProject_shouldDeleteOldResultsBeforeSubmittingRuleTasks() {
|
||||
ReflectionTestUtils.setField(service, "tagRuleExecutor", (Executor) Runnable::run);
|
||||
|
||||
@@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
@@ -154,6 +155,58 @@ class CcdiModelParamServiceImplTest {
|
||||
verify(bankTagService).submitAutoRebuild(40L, TriggerType.AUTO_PARAM_CHANGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveParams_shouldSubmitAutoRebuildAfterProjectParamsUpdated() {
|
||||
CcdiProject project = new CcdiProject();
|
||||
project.setProjectId(40L);
|
||||
project.setConfigType("custom");
|
||||
when(projectMapper.selectById(40L)).thenReturn(project);
|
||||
when(modelParamMapper.updateParamValue(40L, "LARGE_TRANSACTION", "SINGLE_TRANSACTION_AMOUNT", "2000", "admin"))
|
||||
.thenReturn(1);
|
||||
|
||||
ModelParamSaveDTO saveDTO = new ModelParamSaveDTO();
|
||||
saveDTO.setProjectId(40L);
|
||||
saveDTO.setModelCode("LARGE_TRANSACTION");
|
||||
ModelParamSaveDTO.ParamValueItem item = new ModelParamSaveDTO.ParamValueItem();
|
||||
item.setParamCode("SINGLE_TRANSACTION_AMOUNT");
|
||||
item.setParamValue("2000");
|
||||
saveDTO.setParams(List.of(item));
|
||||
|
||||
try (MockedStatic<SecurityUtils> mocked = mockStatic(SecurityUtils.class)) {
|
||||
mocked.when(SecurityUtils::getUsername).thenReturn("admin");
|
||||
|
||||
service.saveParams(saveDTO);
|
||||
}
|
||||
|
||||
verify(bankTagService).submitAutoRebuild(40L, TriggerType.AUTO_PARAM_CHANGE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveParams_shouldNotSubmitAutoRebuildWhenNoProjectParamUpdated() {
|
||||
CcdiProject project = new CcdiProject();
|
||||
project.setProjectId(40L);
|
||||
project.setConfigType("custom");
|
||||
when(projectMapper.selectById(40L)).thenReturn(project);
|
||||
when(modelParamMapper.updateParamValue(40L, "LARGE_TRANSACTION", "SINGLE_TRANSACTION_AMOUNT", "2000", "admin"))
|
||||
.thenReturn(0);
|
||||
|
||||
ModelParamSaveDTO saveDTO = new ModelParamSaveDTO();
|
||||
saveDTO.setProjectId(40L);
|
||||
saveDTO.setModelCode("LARGE_TRANSACTION");
|
||||
ModelParamSaveDTO.ParamValueItem item = new ModelParamSaveDTO.ParamValueItem();
|
||||
item.setParamCode("SINGLE_TRANSACTION_AMOUNT");
|
||||
item.setParamValue("2000");
|
||||
saveDTO.setParams(List.of(item));
|
||||
|
||||
try (MockedStatic<SecurityUtils> mocked = mockStatic(SecurityUtils.class)) {
|
||||
mocked.when(SecurityUtils::getUsername).thenReturn("admin");
|
||||
|
||||
service.saveParams(saveDTO);
|
||||
}
|
||||
|
||||
verify(bankTagService, never()).submitAutoRebuild(anyLong(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveAllParams_shouldNotSubmitAutoRebuildForGlobalDefaults() {
|
||||
ModelParamSaveAllDTO saveAllDTO = buildSaveAllDto();
|
||||
|
||||
Reference in New Issue
Block a user