fix(workreport): 统一月报期间键格式化处理

This commit is contained in:
dk
2026-07-19 18:18:13 +08:00
parent e207bf0485
commit a0aad1d28e
2 changed files with 86 additions and 2 deletions

View File

@@ -603,7 +603,7 @@ public class WorkReportCommonService {
} }
public List<MonthlyReportDO> listMonthlyReportsForSignOff(Collection<Long> reporterIds, String periodMonth) { public List<MonthlyReportDO> listMonthlyReportsForSignOff(Collection<Long> reporterIds, String periodMonth) {
return monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, periodMonth, return monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, normalizeMonthlyPeriodKey(periodMonth),
List.of(WorkReportConstants.STATUS_APPROVED)); List.of(WorkReportConstants.STATUS_APPROVED));
} }
@@ -670,7 +670,8 @@ public class WorkReportCommonService {
} }
public void syncPerformanceResult(Long reporterId, String periodMonth, String performanceResult) { public void syncPerformanceResult(Long reporterId, String periodMonth, String performanceResult) {
MonthlyReportDO report = monthlyReportMapper.selectByReporterIdAndPeriodKey(reporterId, periodMonth); MonthlyReportDO report = monthlyReportMapper.selectByReporterIdAndPeriodKey(reporterId,
normalizeMonthlyPeriodKey(periodMonth));
if (report == null) { if (report == null) {
throw exception(ErrorCodeConstants.PERFORMANCE_SHEET_MONTHLY_REPORT_NOT_EXISTS); throw exception(ErrorCodeConstants.PERFORMANCE_SHEET_MONTHLY_REPORT_NOT_EXISTS);
} }
@@ -1912,6 +1913,16 @@ public class WorkReportCommonService {
|| SignOffConstants.STATUS_NOT_STARTED.equals(signOffStatus); || SignOffConstants.STATUS_NOT_STARTED.equals(signOffStatus);
} }
private String normalizeMonthlyPeriodKey(String periodMonth) {
String normalized = normalizeRequiredText(periodMonth, "月份不能为空");
if (normalized.startsWith(WorkReportConstants.REPORT_TYPE_MONTHLY + "-")) {
return normalized;
}
LocalDate startDate = LocalDate.parse(normalized + "-01");
LocalDate endDate = startDate.withDayOfMonth(startDate.lengthOfMonth());
return String.format("%s-%s-%s", WorkReportConstants.REPORT_TYPE_MONTHLY, startDate, endDate);
}
private UserSignatureRespDTO getUserSignature(Long userId) { private UserSignatureRespDTO getUserSignature(Long userId) {
if (userId == null) { if (userId == null) {
return null; return null;

View File

@@ -0,0 +1,73 @@
package com.njcn.rdms.module.project.service.workreport.common;
import com.njcn.rdms.framework.test.core.ut.BaseMockitoUnitTest;
import com.njcn.rdms.module.project.constant.WorkReportConstants;
import com.njcn.rdms.module.project.dal.dataobject.workreport.monthly.MonthlyReportApprovalRecordDO;
import com.njcn.rdms.module.project.dal.dataobject.workreport.monthly.MonthlyReportDO;
import com.njcn.rdms.module.project.dal.mysql.workreport.monthly.MonthlyReportApprovalRecordMapper;
import com.njcn.rdms.module.project.dal.mysql.workreport.monthly.MonthlyReportMapper;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.ArgumentCaptor;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class WorkReportCommonServicePeriodKeyTest extends BaseMockitoUnitTest {
@InjectMocks
private WorkReportCommonService workReportCommonService;
@Mock
private MonthlyReportMapper monthlyReportMapper;
@Mock
private MonthlyReportApprovalRecordMapper monthlyReportApprovalRecordMapper;
@Test
void listMonthlyReportsForSignOff_whenPeriodMonth_shouldConvertToMonthlyPeriodKey() {
List<Long> reporterIds = List.of(1001L, 1002L);
String periodMonth = "2026-06";
String expectedPeriodKey = "monthly-2026-06-01-2026-06-30";
MonthlyReportDO report = new MonthlyReportDO();
report.setId(3001L);
List<MonthlyReportDO> expectedReports = List.of(report);
when(monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, expectedPeriodKey,
List.of(WorkReportConstants.STATUS_APPROVED))).thenReturn(expectedReports);
List<MonthlyReportDO> actualReports = workReportCommonService.listMonthlyReportsForSignOff(reporterIds, periodMonth);
assertSame(expectedReports, actualReports);
verify(monthlyReportMapper).selectListByReporterIdsAndPeriodKey(reporterIds, expectedPeriodKey,
List.of(WorkReportConstants.STATUS_APPROVED));
}
@Test
void syncPerformanceResult_whenPeriodMonth_shouldConvertToMonthlyPeriodKeyBeforeLookup() {
Long reporterId = 1001L;
String periodMonth = "2026-06";
String expectedPeriodKey = "monthly-2026-06-01-2026-06-30";
String performanceResult = "95";
MonthlyReportDO report = new MonthlyReportDO();
report.setId(3001L);
MonthlyReportApprovalRecordDO approvalRecord = new MonthlyReportApprovalRecordDO();
approvalRecord.setId(4001L);
when(monthlyReportMapper.selectByReporterIdAndPeriodKey(reporterId, expectedPeriodKey)).thenReturn(report);
when(monthlyReportApprovalRecordMapper.selectLatestApprovedByMonthlyReportId(report.getId()))
.thenReturn(approvalRecord);
workReportCommonService.syncPerformanceResult(reporterId, periodMonth, performanceResult);
ArgumentCaptor<MonthlyReportApprovalRecordDO> updateCaptor =
ArgumentCaptor.forClass(MonthlyReportApprovalRecordDO.class);
verify(monthlyReportApprovalRecordMapper).updateById(updateCaptor.capture());
assertEquals(approvalRecord.getId(), updateCaptor.getValue().getId());
assertEquals(performanceResult, updateCaptor.getValue().getPerformanceResult());
}
}