| | |
| | | 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); |
| | | } |
| | | |
| | |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { |
| | | List<String> list = Arrays.asList(ids.split(",")); |
| | | AtomicInteger i = new AtomicInteger(); |
| | | list.forEach(id -> { |
| | | EamMaintenanceStandard entity = eamMaintenanceStandardService.getById(id); |
| | | if (entity != null&&entity.getStandardStatus().equals(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name())) { |
| | | //只删除状态为待提交的 |
| | | i.getAndIncrement(); |
| | | entity.setDelFlag(CommonConstant.DEL_FLAG_1); |
| | | eamMaintenanceStandardService.updateById(entity); |
| | | } |
| | | }); |
| | | return Result.OK("批量删除成功!"); |
| | | return Result.OK("批量删除成功,已删除状态为待提交的保养标准,删除数量为"+i); |
| | | } |
| | | |
| | | /** |
| | |
| | | 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()) { |
| | | results.put(fileName, "成功: " + importResult.getMessage()); |
| | | successCount++; |
| | | } else { |
| | | results.put(fileName, "失败: " + importResult.getMessage()); |
| | | results.put(fileName, importResult.getMessage()); |
| | | failureCount++; |
| | | } |
| | | } |
| | | |
| | | // 构建响应 |
| | | Map<String, Object> response = new HashMap<>(); |
| | | response.put("results", results); |
| | | response.put("totalFiles", fileMap.size()); |
| | | response.put("successCount", successCount); |
| | | response.put("failureCount", failureCount); |
| | | |
| | | if (failureCount == 0) { |
| | | return Result.ok("所有点检文件导入成功"+response); |
| | | } else if (successCount == 0) { |
| | | return Result.error("所有点检文件导入失败", response); |
| | | } else { |
| | | return Result.error("部分点检文件导入失败", response); |
| | | } |
| | | // 构建最终响应 |
| | | return getResult(results, fileMap.size(), successCount, failureCount); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("点检导入处理异常", e); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 二保导入 |
| | | */ |
| | | */ |
| | | @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()) { |
| | | results.put(fileName, "成功: " + importResult.getMessage()); |
| | | successCount++; |
| | | } else { |
| | | results.put(fileName, "失败: " + importResult.getMessage()); |
| | | failureCount++; |
| | | } |
| | | Result<?> importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "SECOND", null); |
| | | successDeviceCount = getSuccessDeviceCount(successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes, fileName, importResult); |
| | | } |
| | | |
| | | // 构建最终响应 |
| | | Map<String, Object> response = new HashMap<>(); |
| | | response.put("results", results); |
| | | response.put("totalFiles", fileMap.size()); |
| | | response.put("successCount", successCount); |
| | | response.put("failureCount", failureCount); |
| | | |
| | | if (failureCount > 0) { |
| | | return Result.error("部分文件导入失败", response); |
| | | } |
| | | |
| | | return Result.ok("所有文件导入成功"+response); |
| | | |
| | | // 构建响应 |
| | | 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()) { |
| | | results.put(fileName, "成功: " + importResult.getMessage()); |
| | | successCount++; |
| | | } else { |
| | | results.put(fileName, "失败: " + importResult.getMessage()); |
| | | failureCount++; |
| | | } |
| | | Result<?> importResult = eamMaintenanceStandardService.importMaintenanceStandard(file, "THIRD", null); |
| | | successDeviceCount = getSuccessDeviceCount(successFileNames, failedFileNames, failedFiles, successDeviceCount, notFoundCodes, fileName, importResult); |
| | | } |
| | | |
| | | // 构建最终响应 |
| | | Map<String, Object> response = new HashMap<>(); |
| | | response.put("results", results); |
| | | response.put("totalFiles", fileMap.size()); |
| | | response.put("successCount", successCount); |
| | | response.put("failureCount", failureCount); |
| | | |
| | | if (failureCount > 0) { |
| | | return Result.error("部分文件导入失败", response); |
| | | } |
| | | |
| | | return Result.ok("所有文件导入成功"+response); |
| | | |
| | | // 构建响应 |
| | | 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); |
| | | response.add("成功数:" + successCount); |
| | | response.add("失败数:" + failureCount); |
| | | if (failureCount > 0) { |
| | | response.add("错误信息:" + results.values()); |
| | | return Result.error("部分文件导入失败:" + response); |
| | | } |
| | | return Result.ok("所有文件导入成功:" + response); |
| | | } |
| | | |
| | | } |