fix(workreport): 统一月报期间键格式化处理
This commit is contained in:
@@ -603,7 +603,7 @@ public class WorkReportCommonService {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user