| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | @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); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 升版 |
| | | * |
| | | * @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 |
| | |
| | | @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("作废成功!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | @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("批量删除成功!"); |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | if (CellType.NUMERIC.equals(period.getCellType())) { |
| | | request.setMaintenancePeriod((int) period.getNumericCellValue()); |
| | | } else { |
| | | //默认点检周期 1 |
| | | request.setMaintenancePeriod(1); |
| | | request.setMaintenancePeriod(null); |
| | | } |
| | | //文件编码 |
| | | Cell fileCode = row.getCell(8); |