From a0aad1d28e49b0d53221f0c841e9cf8823436d50 Mon Sep 17 00:00:00 2001 From: dk <1260500659@qq.com> Date: Sun, 19 Jul 2026 18:18:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(workreport):=20=E7=BB=9F=E4=B8=80=E6=9C=88?= =?UTF-8?q?=E6=8A=A5=E6=9C=9F=E9=97=B4=E9=94=AE=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/WorkReportCommonService.java | 15 +++- .../WorkReportCommonServicePeriodKeyTest.java | 73 +++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 rdms-project/rdms-project-boot/src/test/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonServicePeriodKeyTest.java diff --git a/rdms-project/rdms-project-boot/src/main/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonService.java b/rdms-project/rdms-project-boot/src/main/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonService.java index 8ddc5a9..12bc461 100644 --- a/rdms-project/rdms-project-boot/src/main/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonService.java +++ b/rdms-project/rdms-project-boot/src/main/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonService.java @@ -603,7 +603,7 @@ public class WorkReportCommonService { } public List listMonthlyReportsForSignOff(Collection reporterIds, String periodMonth) { - return monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, periodMonth, + return monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, normalizeMonthlyPeriodKey(periodMonth), List.of(WorkReportConstants.STATUS_APPROVED)); } @@ -670,7 +670,8 @@ public class WorkReportCommonService { } 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) { throw exception(ErrorCodeConstants.PERFORMANCE_SHEET_MONTHLY_REPORT_NOT_EXISTS); } @@ -1912,6 +1913,16 @@ public class WorkReportCommonService { || 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) { if (userId == null) { return null; diff --git a/rdms-project/rdms-project-boot/src/test/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonServicePeriodKeyTest.java b/rdms-project/rdms-project-boot/src/test/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonServicePeriodKeyTest.java new file mode 100644 index 0000000..51ade4a --- /dev/null +++ b/rdms-project/rdms-project-boot/src/test/java/com/njcn/rdms/module/project/service/workreport/common/WorkReportCommonServicePeriodKeyTest.java @@ -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 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 expectedReports = List.of(report); + when(monthlyReportMapper.selectListByReporterIdsAndPeriodKey(reporterIds, expectedPeriodKey, + List.of(WorkReportConstants.STATUS_APPROVED))).thenReturn(expectedReports); + + List 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 updateCaptor = + ArgumentCaptor.forClass(MonthlyReportApprovalRecordDO.class); + verify(monthlyReportApprovalRecordMapper).updateById(updateCaptor.capture()); + assertEquals(approvalRecord.getId(), updateCaptor.getValue().getId()); + assertEquals(performanceResult, updateCaptor.getValue().getPerformanceResult()); + } +}