From 4788f8d86807296a3dce75b5dd428c0a8d5828db Mon Sep 17 00:00:00 2001 From: hyingbo <1363390067@qq.com> Date: 星期五, 25 七月 2025 17:12:39 +0800 Subject: [PATCH] 分类字典设置上级是否存在子节点修改 --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java | 317 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 309 insertions(+), 8 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java index d153584..48d0bef 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java @@ -1,7 +1,6 @@ package org.jeecg.modules.eam.controller; import cn.hutool.core.collection.CollectionUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; @@ -16,13 +15,17 @@ import org.jeecg.common.api.vo.FileUploadResult; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.base.controller.JeecgController; -import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.util.FileUtil; import org.jeecg.modules.eam.constant.BusinessCodeConst; import org.jeecg.modules.eam.constant.MaintenanceCategoryEnum; +import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum; import org.jeecg.modules.eam.dto.MaintenanceStandardImport; +import org.jeecg.modules.eam.dto.SecondMaintenanceStandardImport; +import org.jeecg.modules.eam.dto.ThirdMaintenanceStandardImport; +import org.jeecg.modules.eam.dto.WeekMaintenanceStandardImport; import org.jeecg.modules.eam.entity.EamEquipment; import org.jeecg.modules.eam.entity.EamMaintenanceStandard; import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail; @@ -42,8 +45,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.*; import java.util.stream.Collectors; @@ -80,9 +81,9 @@ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) { - QueryWrapper<EamMaintenanceStandard> queryWrapper = QueryGenerator.initQueryWrapper(eamMaintenanceStandard, req.getParameterMap()); +// QueryWrapper<EamMaintenanceStandard> queryWrapper = QueryGenerator.initQueryWrapper(eamMaintenanceStandard, req.getParameterMap()); Page<EamMaintenanceStandard> page = new Page<EamMaintenanceStandard>(pageNo, pageSize); - IPage<EamMaintenanceStandard> pageList = eamMaintenanceStandardService.page(page, queryWrapper); + IPage<EamMaintenanceStandard> pageList = eamMaintenanceStandardService.queryPageList(page, eamMaintenanceStandard); return Result.OK(pageList); } @@ -135,6 +136,48 @@ } /** + * 鍗囩増 + * + * @param standardRequest + * @return + */ + @AutoLog(value = "淇濆吇鏍囧噯-鍗囩増") + @ApiOperation(value = "淇濆吇鏍囧噯-鍗囩増", notes = "淇濆吇鏍囧噯-鍗囩増") + @RequestMapping(value = "/upgrade", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result<?> upgrade(@RequestBody EamMaintenanceStandardRequest standardRequest) { + if (standardRequest == null) { + return Result.error("娣诲姞鐨勫璞′笉鑳戒负绌猴紒"); + } + if (CollectionUtil.isEmpty(standardRequest.getTableDetailList())) { + return Result.error("淇濆吇椤逛笉鑳戒负绌猴紒"); + } + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); + standardRequest.setStandardCode(codeSeq); + boolean b = eamMaintenanceStandardService.upgradeMaintenanceStandard(standardRequest); + if (!b) { + return Result.error("鍗囩増澶辫触锛�"); + } + return Result.OK("鍗囩増鎴愬姛!"); + } + + /** + * 鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯 + * @param keyword 璁惧缂栧彿 + * @param maintenanceCategory 淇濆吇绫诲瀷 + * @return + */ + @AutoLog(value = "淇濆吇鏍囧噯-鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯") + @ApiOperation(value = "淇濆吇鏍囧噯-鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯", notes = "淇濆吇鏍囧噯-鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯") + @GetMapping(value = "/listByUser") + public Result<?> listByUser(@RequestParam(name = "keyword", required = false) String keyword, + @RequestParam(name = "equipmentId", required = false) String equipmentId, + @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, + @RequestParam(name = "maintenanceCategory", required = false) String maintenanceCategory) { + List<EamMaintenanceStandard> list = eamMaintenanceStandardService.queryListByKeywordAndCategory(keyword, equipmentId, pageSize, maintenanceCategory); + return Result.OK(list); + } + + /** * 閫氳繃id鍒犻櫎 * * @param id @@ -144,8 +187,30 @@ @ApiOperation(value = "淇濆吇鏍囧噯-閫氳繃id鍒犻櫎", notes = "淇濆吇鏍囧噯-閫氳繃id鍒犻櫎") @DeleteMapping(value = "/delete") public Result<?> delete(@RequestParam(name = "id", required = true) String id) { - eamMaintenanceStandardService.removeById(id); + EamMaintenanceStandard entity = eamMaintenanceStandardService.getById(id); + if (entity != null) { + entity.setDelFlag(CommonConstant.DEL_FLAG_1); + eamMaintenanceStandardService.updateById(entity); + } return Result.OK("鍒犻櫎鎴愬姛!"); + } + + /** + * 閫氳繃id浣滃簾 + * + * @param id + * @return + */ + @AutoLog(value = "淇濆吇鏍囧噯-浣滃簾") + @ApiOperation(value = "淇濆吇鏍囧噯-浣滃簾", notes = "淇濆吇鏍囧噯-浣滃簾") + @DeleteMapping(value = "/abolish") + public Result<?> abolish(@RequestParam(name = "id", required = true) String id) { + EamMaintenanceStandard entity = eamMaintenanceStandardService.getById(id); + if (entity != null) { + entity.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name()); + eamMaintenanceStandardService.updateById(entity); + } + return Result.OK("浣滃簾鎴愬姛!"); } /** @@ -158,7 +223,14 @@ @ApiOperation(value = "淇濆吇鏍囧噯-鎵归噺鍒犻櫎", notes = "淇濆吇鏍囧噯-鎵归噺鍒犻櫎") @DeleteMapping(value = "/deleteBatch") public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { - this.eamMaintenanceStandardService.removeByIds(Arrays.asList(ids.split(","))); + List<String> list = Arrays.asList(ids.split(",")); + list.forEach(id -> { + EamMaintenanceStandard entity = eamMaintenanceStandardService.getById(id); + if (entity != null) { + entity.setDelFlag(CommonConstant.DEL_FLAG_1); + eamMaintenanceStandardService.updateById(entity); + } + }); return Result.OK("鎵归噺鍒犻櫎鎴愬姛锛�"); } @@ -219,6 +291,180 @@ standardRequest.setEquipmentId(equipment.getId()); //璇诲彇淇濆吇鏄庣粏鍐呭 List<MaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), MaintenanceStandardImport.class, params); + //鏄庣粏椤� + List<EamMaintenanceStandardDetail> tableList = list.stream().map(EamMaintenanceStandardDetail::new).collect(Collectors.toList()); + standardRequest.setTableDetailList(tableList); + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); + standardRequest.setStandardCode(codeSeq); + boolean b = eamMaintenanceStandardService.addMaintenanceStandard(standardRequest); + if (!b) { + log.error("淇濆瓨澶辫触锛� {}", standardRequest.getEquipmentCode()); + } + } catch (Exception e) { + //update-begin-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + String msg = e.getMessage(); + log.error("鏂囦欢 {} 澶勭悊寮傚父锛� {}", file.getOriginalFilename(), msg, e); + //update-end-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + return Result.ok("鏂囦欢瀵煎叆瀹屾垚锛�"); + } + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/weekMaintenanceImportExcel", method = RequestMethod.POST) + public Result<?> weekMaintenanceImportExcel(HttpServletRequest request, HttpServletResponse response) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); + for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { + // 鑾峰彇涓婁紶鏂囦欢瀵硅薄 + MultipartFile file = entity.getValue(); + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setSheetNum(1); + params.setNeedSave(true); + EamMaintenanceStandardRequest standardRequest = new EamMaintenanceStandardRequest(); + try { + //璇诲彇璁惧缂栧彿锛屽浘鐗囩瓑 + readWeekExcel(file, standardRequest); + EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standardRequest.getEquipmentCode()); + if(equipment == null) { + log.error("璁惧涓嶅瓨鍦細{}", standardRequest.getEquipmentCode()); + continue; + } + standardRequest.setStandardName(standardRequest.getEquipmentName() + "鍛ㄤ繚鏍囧噯"); + standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.WEEK_MAINTENANCE.name()); + standardRequest.setEquipmentId(equipment.getId()); + //璇诲彇淇濆吇鏄庣粏鍐呭 + List<WeekMaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), WeekMaintenanceStandardImport.class, params); + //鏄庣粏椤� + List<EamMaintenanceStandardDetail> tableList = list.stream().map(EamMaintenanceStandardDetail::new).collect(Collectors.toList()); + standardRequest.setTableDetailList(tableList); + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); + standardRequest.setStandardCode(codeSeq); + boolean b = eamMaintenanceStandardService.addMaintenanceStandard(standardRequest); + if (!b) { + log.error("淇濆瓨澶辫触锛� {}", standardRequest.getEquipmentCode()); + } + } catch (Exception e) { + //update-begin-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + String msg = e.getMessage(); + log.error("鏂囦欢 {} 澶勭悊寮傚父锛� {}", file.getOriginalFilename(), msg, e); + //update-end-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + return Result.ok("鏂囦欢瀵煎叆瀹屾垚锛�"); + } + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/secondMaintenanceImportExcel", method = RequestMethod.POST) + public Result<?> secondMaintenanceImportExcel(HttpServletRequest request, HttpServletResponse response) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); + for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { + // 鑾峰彇涓婁紶鏂囦欢瀵硅薄 + MultipartFile file = entity.getValue(); + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setSheetNum(1); + params.setNeedSave(true); + EamMaintenanceStandardRequest standardRequest = new EamMaintenanceStandardRequest(); + try { + //璇诲彇璁惧缂栧彿锛屽浘鐗囩瓑 + readWeekExcel(file, standardRequest); + EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standardRequest.getEquipmentCode()); + if(equipment == null) { + log.error("璁惧涓嶅瓨鍦細{}", standardRequest.getEquipmentCode()); + continue; + } + standardRequest.setStandardName(standardRequest.getEquipmentName() + "浜屼繚鏍囧噯"); + standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.SECOND_MAINTENANCE.name()); + standardRequest.setEquipmentId(equipment.getId()); + //璇诲彇淇濆吇鏄庣粏鍐呭 + List<SecondMaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), SecondMaintenanceStandardImport.class, params); + //鏄庣粏椤� + List<EamMaintenanceStandardDetail> tableList = list.stream().map(EamMaintenanceStandardDetail::new).collect(Collectors.toList()); + standardRequest.setTableDetailList(tableList); + String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE); + standardRequest.setStandardCode(codeSeq); + boolean b = eamMaintenanceStandardService.addMaintenanceStandard(standardRequest); + if (!b) { + log.error("淇濆瓨澶辫触锛� {}", standardRequest.getEquipmentCode()); + } + } catch (Exception e) { + //update-begin-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + String msg = e.getMessage(); + log.error("鏂囦欢 {} 澶勭悊寮傚父锛� {}", file.getOriginalFilename(), msg, e); + //update-end-author:taoyan date:20211124 for: 瀵煎叆鏁版嵁閲嶅澧炲姞鎻愮ず + } finally { + try { + file.getInputStream().close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + return Result.ok("鏂囦欢瀵煎叆瀹屾垚锛�"); + } + + /** + * 閫氳繃excel瀵煎叆鏁版嵁 + * + * @param request + * @param response + * @return + */ + @RequestMapping(value = "/thirdMaintenanceImportExcel", method = RequestMethod.POST) + public Result<?> thirdMaintenanceImportExcel(HttpServletRequest request, HttpServletResponse response) { + MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); + for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { + // 鑾峰彇涓婁紶鏂囦欢瀵硅薄 + MultipartFile file = entity.getValue(); + ImportParams params = new ImportParams(); + params.setTitleRows(2); + params.setHeadRows(1); + params.setSheetNum(1); + params.setNeedSave(true); + EamMaintenanceStandardRequest standardRequest = new EamMaintenanceStandardRequest(); + try { + //璇诲彇璁惧缂栧彿锛屽浘鐗囩瓑 + readWeekExcel(file, standardRequest); + EamEquipment equipment = eamEquipmentService.selectByEquipmentCode(standardRequest.getEquipmentCode()); + if(equipment == null) { + log.error("璁惧涓嶅瓨鍦細{}", standardRequest.getEquipmentCode()); + continue; + } + standardRequest.setStandardName(standardRequest.getEquipmentName() + "涓変繚鏍囧噯"); + standardRequest.setMaintenanceCategory(MaintenanceCategoryEnum.THIRD_MAINTENANCE.name()); + standardRequest.setEquipmentId(equipment.getId()); + //璇诲彇淇濆吇鏄庣粏鍐呭 + List<ThirdMaintenanceStandardImport> list = ExcelImportUtil.importExcel(file.getInputStream(), ThirdMaintenanceStandardImport.class, params); //鏄庣粏椤� List<EamMaintenanceStandardDetail> tableList = list.stream().map(EamMaintenanceStandardDetail::new).collect(Collectors.toList()); standardRequest.setTableDetailList(tableList); @@ -322,4 +568,59 @@ log.error("璇诲彇Excel淇℃伅澶辫触锛歿}", e.getMessage(), e); } } + + /** + * 璇诲彇Excel 绗竴琛岋紝 绗簩琛岀殑淇℃伅 + * @param file + * @param request + */ + public void readWeekExcel(MultipartFile file, EamMaintenanceStandardRequest request) { + Workbook book = null; + boolean isXSSFWorkbook = false; + try { + book = WorkbookFactory.create(file.getInputStream()); + if (book instanceof XSSFWorkbook) { + isXSSFWorkbook = true; + } + + Sheet sheet = book.getSheetAt(0); + //绗竴琛岃鍙� + Row row = sheet.getRow(0); + //璁惧缂栫爜 + Cell equipmentCode = row.getCell(10); + if(CellType.NUMERIC.equals(equipmentCode.getCellType())) { + request.setEquipmentCode(String.valueOf((int) equipmentCode.getNumericCellValue())); + }else if(CellType.STRING.equals(equipmentCode.getCellType())) { + request.setEquipmentCode(equipmentCode.getStringCellValue()); + } + if (StringUtils.isBlank(request.getEquipmentCode())) { + throw new JeecgBootException("Excel銆� " + file.getOriginalFilename() + "銆戞病鏈夎鍙栧埌璁惧缂栧彿锛屽鍏ュけ璐ワ紒"); + } + //鍒濆鏃ユ湡 + Cell initialDate = row.getCell(6); + if (DateUtil.isCellDateFormatted(initialDate)) { + request.setInitialDate(initialDate.getDateCellValue()); + } else { + request.setInitialDate(new Date()); + } + //璁惧鍚嶇О + Cell equipmentName = row.getCell(8); + request.setEquipmentName(equipmentName.getStringCellValue()); + + //绗簩琛岃鍙� + row = sheet.getRow(1); + //淇濆吇鍛ㄦ湡 + Cell period = row.getCell(6); + if (CellType.NUMERIC.equals(period.getCellType())) { + request.setMaintenancePeriod((int) period.getNumericCellValue()); + } else { + request.setMaintenancePeriod(null); + } + //鏂囦欢缂栫爜 + Cell fileCode = row.getCell(8); + request.setFileCode(fileCode.getStringCellValue()); + } catch (Exception e) { + log.error("璇诲彇Excel淇℃伅澶辫触锛歿}", e.getMessage(), e); + } + } } -- Gitblit v1.9.3