|
|
@@ -22,6 +22,7 @@ import java.util.*;
|
|
|
@Service
|
|
|
public class RepairApprovalWriteBackService {
|
|
|
private static final String SYNC_SUCCESS = "全部成功";
|
|
|
+ private static final String SUMMARY_STATUS_DRAFT = "暂存";
|
|
|
private static final String APPROVAL_SYNC_PARTIAL = "部分失败";
|
|
|
private static final String REPAIR_SUMMARY_PARTIAL = "部分成功";
|
|
|
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
|
|
@@ -46,6 +47,7 @@ public class RepairApprovalWriteBackService {
|
|
|
|
|
|
@Autowired private YDClient ydClient;
|
|
|
@Autowired private WHConf whConf;
|
|
|
+ @Autowired private WorkHoursCalcService workHoursCalcService;
|
|
|
|
|
|
public ApprovalWriteBackResult writeBack(String instanceId, int result) {
|
|
|
Map form = queryProcessData(instanceId);
|
|
|
@@ -119,11 +121,11 @@ public class RepairApprovalWriteBackService {
|
|
|
final String sourceDay = entry.getKey();
|
|
|
final double sourceHours = entry.getValue();
|
|
|
completedSteps = runStep(other, instanceId, totalSteps, completedSteps, stepIndex++,
|
|
|
- () -> adjustRequired(user, sourceDay, -sourceHours));
|
|
|
+ () -> adjustRequired(user, sourceDay, -sourceHours, true));
|
|
|
}
|
|
|
final double submittedHours = dayTotals.values().stream().mapToDouble(Double::doubleValue).sum();
|
|
|
runStep(other, instanceId, totalSteps, completedSteps, stepIndex,
|
|
|
- () -> adjustRequired(user, submitDay, submittedHours));
|
|
|
+ () -> adjustRequired(user, submitDay, submittedHours, false));
|
|
|
}
|
|
|
|
|
|
private int runStep(boolean other, String instanceId, int totalSteps, int completedSteps,
|
|
|
@@ -327,6 +329,12 @@ public class RepairApprovalWriteBackService {
|
|
|
return "暂存";
|
|
|
}
|
|
|
|
|
|
+ static void putDraftSummaryStatus(Map<String, Object> update, String statusField) {
|
|
|
+ McException.assertAccessException(StringUtils.isBlank(statusField),
|
|
|
+ "工时汇总审批状态字段未配置");
|
|
|
+ update.put(statusField, SUMMARY_STATUS_DRAFT);
|
|
|
+ }
|
|
|
+
|
|
|
private void updateOriginalSubmissionDay(String submitDay, String user, List<Row> rows) {
|
|
|
List<Map> found = query(whConf.getFormUuidWorkHoursSummary(), map(ORIG_USER,user,ORIG_DAY,submitDay));
|
|
|
Map<String,Object> update = new LinkedHashMap<>();
|
|
|
@@ -334,6 +342,7 @@ public class RepairApprovalWriteBackService {
|
|
|
update.put(ORIG_USER,user); update.put(ORIG_DAY,submitDay);
|
|
|
update.put("textField_mmbffvda",submitDay.substring(0,6)); update.put("textField_mmbffvd9",user);
|
|
|
update.put("employeeField_mmacxew4",Collections.singletonList(user)); update.put("dateField_mmbffvd8",parseDay(submitDay)); update.put("dateField_mmacxewf",parseDay(submitDay.substring(0,6)+"01"));
|
|
|
+ putDraftSummaryStatus(update, whConf.getSummaryApprovalStatusField());
|
|
|
update.put("tableField_mmczo634", childChanges(rows, true));
|
|
|
update.put("tableField_mmczo63h", childChanges(rows, false));
|
|
|
update.put("tableField_mmeakgid", childChanges(rows, null));
|
|
|
@@ -355,11 +364,24 @@ public class RepairApprovalWriteBackService {
|
|
|
() -> verifyOriginalSubmissionDay(user, submitDay, update));
|
|
|
}
|
|
|
|
|
|
- private void adjustRequired(String user,String day,double delta){
|
|
|
+ private void adjustRequired(String user, String day, double delta, boolean sourceDay) {
|
|
|
McException.assertAccessException(StringUtils.isBlank(whConf.getFormUuidRequiredHours()), "应报工时表未配置");
|
|
|
McException.assertAccessException(StringUtils.isBlank(user), "应报工时员工不能为空");
|
|
|
long ts=parseDay(day); Map<String,Object> search=map(REQUIRED_USER,Collections.singletonList(user),REQUIRED_DAY,Arrays.asList(ts,ts+86400000L-1));
|
|
|
List<Map> found=query(whConf.getFormUuidRequiredHours(),search);
|
|
|
+ if (shouldSkipMissingRequiredRecord(sourceDay, found.size())) {
|
|
|
+ // fixme 应报工时只生成工作日;周末/休息日补填没有来源记录时无需调减。
|
|
|
+ log.info("[补填审批回写] 来源日无应报工时记录,跳过调减 userId={} day={}", user, day);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!sourceDay && found.isEmpty()) {
|
|
|
+ Map<String, Object> created = workHoursCalcService.syncOneEmployeeOneDayForRepair(
|
|
|
+ user, LocalDate.parse(day, DAY));
|
|
|
+ McException.assertAccessException(!Boolean.TRUE.equals(created.get("success")),
|
|
|
+ "补填提交日应报工时创建失败 userId=" + user + ", day=" + day
|
|
|
+ + ", error=" + text(created.get("error")));
|
|
|
+ found = query(whConf.getFormUuidRequiredHours(), search);
|
|
|
+ }
|
|
|
McException.assertAccessException(found.size() != 1,
|
|
|
"应报工时记录不存在或重复 userId=" + user + ", day=" + day);
|
|
|
Map item=found.get(0); Map fd=(Map)item.get("formData"); if(fd==null) fd=item;
|
|
|
@@ -374,6 +396,10 @@ public class RepairApprovalWriteBackService {
|
|
|
() -> verifyRequiredHours(targetId, user, day, expectedHours));
|
|
|
}
|
|
|
|
|
|
+ static boolean shouldSkipMissingRequiredRecord(boolean sourceDay, int matchedRecords) {
|
|
|
+ return sourceDay && matchedRecords == 0;
|
|
|
+ }
|
|
|
+
|
|
|
private void verifyOriginalSubmissionDay(String user, String day, Map<String, Object> expected) {
|
|
|
List<Map> found = query(whConf.getFormUuidWorkHoursSummary(), map(ORIG_USER, user, ORIG_DAY, day));
|
|
|
McException.assertAccessException(found.size() != 1,
|