|
|
@@ -97,15 +97,19 @@ public class FlowImportController {
|
|
|
+ java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("MMddHHmm"));
|
|
|
|
|
|
List<Long> instanceIds = new ArrayList<>();
|
|
|
+ List<String> failReasons = new ArrayList<>();
|
|
|
int successCount = 0;
|
|
|
int updateCount = 0;
|
|
|
for (int i = 0; i < rows.size(); i++) {
|
|
|
+ int rowNo = i + 2; // Excel 第 1 行是表头,数据行从第 2 行开始
|
|
|
Map<String, Object> row = rows.get(i);
|
|
|
@SuppressWarnings("unchecked")
|
|
|
Map<String, Object> formData = (Map<String, Object>) row.get("formData");
|
|
|
String nodeName = (String) row.get("nodeName");
|
|
|
Long ownerId = (Long) row.get("ownerId");
|
|
|
+ String ownerName = (String) row.get("ownerName");
|
|
|
if (Objects.isNull(ownerId)) {
|
|
|
+ failReasons.add("第" + rowNo + "行:未找到用户【" + ownerName + "】");
|
|
|
continue;
|
|
|
}
|
|
|
String bizValue = (String) row.get("bizValue");
|
|
|
@@ -113,45 +117,55 @@ public class FlowImportController {
|
|
|
Long effectiveOwnerId = null;
|
|
|
if (isAdmin) {
|
|
|
effectiveOwnerId = ownerId;
|
|
|
- } else if (ownerId.equals(loginUser.getUserId())) {
|
|
|
+ } else if (loginUser != null && ownerId.equals(loginUser.getUserId())) {
|
|
|
effectiveOwnerId = ownerId;
|
|
|
}
|
|
|
- if (effectiveOwnerId == null) continue;
|
|
|
+ if (effectiveOwnerId == null) {
|
|
|
+ failReasons.add("第" + rowNo + "行:无权为【" + ownerName + "】导入流程");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- if (bizValue != null && !bizValue.isBlank()) {
|
|
|
- ProcessInstance existing = this.processInstanceMapper.selectByInstanceNo(bizValue);
|
|
|
- if (existing != null) {
|
|
|
- this.processInstanceService.updateFormData(
|
|
|
- existing.getId(), mapper.writeValueAsString(formData), nodeName);
|
|
|
- instanceIds.add(existing.getId());
|
|
|
- updateCount++;
|
|
|
- continue;
|
|
|
+ try {
|
|
|
+ if (bizValue != null && !bizValue.isBlank()) {
|
|
|
+ ProcessInstance existing = this.processInstanceMapper.selectByInstanceNo(bizValue);
|
|
|
+ if (existing != null) {
|
|
|
+ this.processInstanceService.updateFormData(
|
|
|
+ existing.getId(), mapper.writeValueAsString(formData), nodeName);
|
|
|
+ instanceIds.add(existing.getId());
|
|
|
+ updateCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- StartProcessDTO dto = new StartProcessDTO();
|
|
|
- dto.setProcessDefinitionId(definitionId);
|
|
|
- dto.setTitle(titlePrefix + "-" + (i + 1));
|
|
|
- dto.setFormData(mapper.writeValueAsString(formData));
|
|
|
- if (bizValue != null && !bizValue.isBlank()) {
|
|
|
- dto.setInstanceNo(bizValue);
|
|
|
- }
|
|
|
- dto.setApplicantId(effectiveOwnerId);
|
|
|
+ StartProcessDTO dto = new StartProcessDTO();
|
|
|
+ dto.setProcessDefinitionId(definitionId);
|
|
|
+ dto.setTitle(titlePrefix + "-" + (i + 1));
|
|
|
+ dto.setFormData(mapper.writeValueAsString(formData));
|
|
|
+ if (bizValue != null && !bizValue.isBlank()) {
|
|
|
+ dto.setInstanceNo(bizValue);
|
|
|
+ }
|
|
|
+ dto.setApplicantId(effectiveOwnerId);
|
|
|
|
|
|
- Long instanceId;
|
|
|
- if (nodeName != null && !nodeName.isBlank()) {
|
|
|
- instanceId = this.processInstanceService.startProcessAtNode(dto, nodeName);
|
|
|
- } else {
|
|
|
- instanceId = this.processInstanceService.startProcess(dto);
|
|
|
+ Long instanceId;
|
|
|
+ if (nodeName != null && !nodeName.isBlank()) {
|
|
|
+ instanceId = this.processInstanceService.startProcessAtNode(dto, nodeName);
|
|
|
+ } else {
|
|
|
+ instanceId = this.processInstanceService.startProcess(dto);
|
|
|
+ }
|
|
|
+ instanceIds.add(instanceId);
|
|
|
+ successCount++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ String msg = e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName();
|
|
|
+ failReasons.add("第" + rowNo + "行:" + msg);
|
|
|
}
|
|
|
- instanceIds.add(instanceId);
|
|
|
- successCount++;
|
|
|
}
|
|
|
|
|
|
Map<String, Object> response = new LinkedHashMap<>();
|
|
|
response.put("total", rows.size());
|
|
|
response.put("successCount", successCount);
|
|
|
response.put("updateCount", updateCount);
|
|
|
+ response.put("failCount", failReasons.size());
|
|
|
+ response.put("failReasons", failReasons);
|
|
|
response.put("instanceIds", instanceIds);
|
|
|
return Result.ok(response);
|
|
|
} catch (com.fasterxml.jackson.core.JsonProcessingException e) {
|