| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | |
| | | import org.jeecg.common.system.base.controller.JeecgController; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.constant.BusinessCodeConst; |
| | | |
| | | import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; |
| | |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardService; |
| | | import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo; |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Description: 保养标准 |
| | |
| | | private IEamMaintenanceStandardService eamMaintenanceStandardService; |
| | | @Autowired |
| | | private ISysBusinessCodeRuleService businessCodeRuleService; |
| | | @Autowired |
| | | private IEamEquipmentService eamEquipmentService; |
| | | |
| | | /** |
| | | * 流程启动,保存对应的数据 |
| | |
| | | @ApiOperation(value = "保养标准-流程启动保存对应的数据", notes = "保养标准-流程启动保存对应的数据") |
| | | @GetMapping(value = "/saveEamMaintenanceStandardProcess") |
| | | public Result<?> saveEamMaintenanceStandardProcess(String id) { |
| | | // 校验领取权限 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | if (!BusinessCodeConst.PCR0002.equals(user.getPost())) { |
| | | return Result.error("填报失败,没有填报权限!,需维修工提交"); |
| | | } |
| | | return eamMaintenanceStandardService.saveEamMaintenanceStandardProcess(id); |
| | | } |
| | | |
| | |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | String fileName = file.getOriginalFilename(); |
| | | Result<?> importResult=eamMaintenanceStandardService.importPointInspectionExcel(file); |
| | | Result<?> importResult=eamMaintenanceStandardService.importPointInspectionExcel(file,null); |
| | | if (importResult.isSuccess()) { |
| | | successCount++; |
| | | } else { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 二保导入 |
| | | */ |
| | | */ |
| | | @PostMapping("/importSecondMaintenanceStandard") |
| | | public Result<?> importSecondMaintenanceStandard(HttpServletRequest request) { |
| | | try { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Map<String, String> results = new LinkedHashMap<>(); |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | |
| | | // 统计导入结果 |
| | | int successCount = 0; |
| | | int failureCount = 0; |
| | | |
| | | int totalFiles = fileMap.size(); |
| | | List<String> successFileNames = new ArrayList<>(); |
| | | List<String> failedFileNames = new ArrayList<>(); |
| | | Map<String, String> failedFiles = new LinkedHashMap<>(); |
| | | int successDeviceCount = 0; |
| | | List<String> notFoundCodes = new ArrayList<>(); |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | String fileName = file.getOriginalFilename(); |
| | | Result<?> importResult=eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND"); |
| | | if (importResult.isSuccess()) { |
| | | successCount++; |
| | | } else { |
| | | results.put(fileName, importResult.getMessage()); |
| | | failureCount++; |
| | | } |
| | | Result<?> importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", null); |
| | | successDeviceCount = getSuccessDeviceCount(successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes, fileName, importResult); |
| | | } |
| | | |
| | | // 构建最终响应 |
| | | return getResult(results, fileMap.size(), successCount, failureCount); |
| | | |
| | | // 构建响应 |
| | | return getResult(totalFiles, successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes); |
| | | } catch (Exception e) { |
| | | log.error("导入处理异常", e); |
| | | return Result.error("导入处理失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @NotNull |
| | | private Result<?> getResult(int totalFiles, List<String> successFileNames, List<String> failedFileNames, Map<String, String> failedFiles, int successDeviceCount, List<String> notFoundCodes) { |
| | | if (!failedFiles.isEmpty()) { |
| | | String errorMsg = String.format("失败文件数:%d,失败文件名:%s,失败原因:%s", |
| | | totalFiles, |
| | | String.join(",", failedFileNames), |
| | | failedFiles.entrySet().stream() |
| | | .map(e -> e.getKey() + ":" + e.getValue()) |
| | | .collect(Collectors.joining(";"))); |
| | | return Result.error(errorMsg); |
| | | } |
| | | |
| | | if (!notFoundCodes.isEmpty()) { |
| | | return Result.ok(String.format("成功导入文件数:%d,文件名:%s,成功导入设备数:%d,未找到的设备编码:%s", |
| | | totalFiles, |
| | | String.join(",", successFileNames), |
| | | successDeviceCount, |
| | | String.join(",", notFoundCodes))); |
| | | } |
| | | |
| | | return Result.ok(String.format("成功导入文件数:%d,文件名:%s,成功导入设备数:%d", |
| | | totalFiles, |
| | | String.join(",", successFileNames), |
| | | successDeviceCount)); |
| | | } |
| | | |
| | | private int getSuccessDeviceCount(List<String> successFileNames, List<String> failedFileNames, Map<String, String> failedFiles, int successDeviceCount, List<String> notFoundCodes, String fileName, Result<?> importResult) { |
| | | if (importResult.isSuccess()) { |
| | | successFileNames.add(fileName); |
| | | String message = importResult.getMessage(); |
| | | // 提取设备数 |
| | | Pattern devicePattern = Pattern.compile("设备数:(\\d+)"); |
| | | Matcher deviceMatcher = devicePattern.matcher(message); |
| | | if (deviceMatcher.find()) { |
| | | successDeviceCount += Integer.parseInt(deviceMatcher.group(1)); |
| | | } |
| | | // 检查未找到的设备编码 |
| | | if (message.contains("以下设备编码未找到")) { |
| | | int colonIndex = message.indexOf(":", message.indexOf("以下设备编码未找到")); |
| | | if (colonIndex != -1) { |
| | | String notFoundPart = message.substring(colonIndex + 1).replaceAll("[。;,]", ""); |
| | | notFoundCodes.addAll(Arrays.asList(notFoundPart.split("\\s*,\\s*"))); |
| | | } |
| | | } |
| | | } else { |
| | | failedFileNames.add(fileName); |
| | | failedFiles.put(fileName, importResult.getMessage()); |
| | | } |
| | | return successDeviceCount; |
| | | } |
| | | |
| | | /** |
| | |
| | | public Result<?> importThirdMaintenanceStandard(HttpServletRequest request) { |
| | | try { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | Map<String, String> results = new LinkedHashMap<>(); |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | |
| | | // 统计导入结果 |
| | | int successCount = 0; |
| | | int failureCount = 0; |
| | | |
| | | int totalFiles = fileMap.size(); |
| | | List<String> successFileNames = new ArrayList<>(); |
| | | List<String> failedFileNames = new ArrayList<>(); |
| | | Map<String, String> failedFiles = new LinkedHashMap<>(); |
| | | int successDeviceCount = 0; |
| | | List<String> notFoundCodes = new ArrayList<>(); |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | String fileName = file.getOriginalFilename(); |
| | | Result<?> importResult= eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD"); |
| | | if (importResult.isSuccess()) { |
| | | successCount++; |
| | | } else { |
| | | results.put(fileName, importResult.getMessage()); |
| | | failureCount++; |
| | | } |
| | | Result<?> importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", null); |
| | | successDeviceCount = getSuccessDeviceCount(successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes, fileName, importResult); |
| | | } |
| | | |
| | | // 构建最终响应 |
| | | return getResult(results, fileMap.size(), successCount, failureCount); |
| | | |
| | | // 构建响应 |
| | | return getResult(totalFiles, successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes); |
| | | } catch (Exception e) { |
| | | log.error("导入处理异常", e); |
| | | return Result.error("导入处理失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 升版导入 |
| | | */ |
| | | @PostMapping(value = "/importUpgrade") |
| | | public Result<?> importUpgrade(String id, MultipartFile file) { |
| | | EamMaintenanceStandard eamMaintenanceStandard = eamMaintenanceStandardService.getById(id); |
| | | if (eamMaintenanceStandard == null) { |
| | | return Result.error("请选择需要升版的保养标准"); |
| | | } else { |
| | | switch (eamMaintenanceStandard.getMaintenanceCategory()) { |
| | | case "POINT_INSPECTION": |
| | | //点检升版导入 |
| | | return eamMaintenanceStandardService.importPointInspectionExcel(file,id); |
| | | case "SECOND_MAINTENANCE": |
| | | //二保升版导入 |
| | | return eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND",id); |
| | | case "THIRD_MAINTENANCE": |
| | | //三保升版导入 |
| | | return eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD",id); |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return Result.error("升版导入失败"); |
| | | } |
| | | |
| | | private Result<?> getResult(Map<String, String> results, int fileCount, int successCount, int failureCount) { |
| | | List<String> response = new ArrayList<>(); |
| | | response.add("总文件数:" + fileCount); |