| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.apache.poi.xwpf.usermodel.*; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.api.vo.Result; |
| | | import org.jeecg.common.aspect.annotation.AutoLog; |
| | |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.eam.entity.*; |
| | | import org.jeecg.modules.eam.service.*; |
| | | import org.jeecgframework.poi.excel.entity.ImportParams; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private IMaintenanceStandardWorkInstructionService maintenanceStandardWorkInstructionService; |
| | | |
| | | @Autowired |
| | | private IMaintenanceProjectService maintenanceProjectService; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private IdentityService sysIdentityService; |
| | | @Autowired |
| | | @Lazy |
| | | private IMaintenanceProjectCategoryService maintenanceProjectCategoryService; |
| | | @Lazy |
| | | @Autowired |
| | | private IMaintenanceCycleService maintenanceCycleService; |
| | | |
| | | |
| | | |
| | |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
| | | public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
| | | return super.importExcel(request, response, MaintenanceStandard.class); |
| | | @RequestMapping(value = "/importExcelOfTwoMaintenance", method = RequestMethod.POST) |
| | | public Result<?> importExcelOfTwoMaintenance(HttpServletRequest request, HttpServletResponse response) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | LoginUser user= (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | String exceptionInfo = ""; |
| | | int exceptionNum = 0; |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | try { |
| | | InputStream fis = file.getInputStream(); |
| | | XWPFDocument document = new XWPFDocument(fis); |
| | | XWPFParagraph mainTitleParagraph = document.getParagraphs().get(0); |
| | | if (mainTitleParagraph != null) { |
| | | // 获取主标题文本内容 |
| | | String mainTitle = mainTitleParagraph.getText(); |
| | | if(mainTitle.equals("生产设备二级保养规范")){ |
| | | for (XWPFTable table : document.getTables()) { |
| | | // 遍历表格中的所有行 |
| | | int rowNumber = 0; |
| | | String equipmentNum = ""; |
| | | Equipment equipment = null; |
| | | MaintenanceStandard maintenanceStandard = null; |
| | | XWPFTableRow row0= table.getRow(0); |
| | | if(ObjectUtils.isNotNull(row0)){ |
| | | XWPFTableCell cellEquipmentNum = row0.getCell(3); |
| | | if(ObjectUtils.isNotNull(cellEquipmentNum)){ |
| | | equipmentNum =cellEquipmentNum.getText(); |
| | | equipment = equipmentService.getOne(new QueryWrapper<Equipment>().eq("num",equipmentNum).eq("del_flag",0),false); |
| | | if(ObjectUtils.isNotNull(equipment)){ |
| | | maintenanceStandard = maintenanceStandardService.getOne(new QueryWrapper<MaintenanceStandard>().eq("version_status",2).eq("del_flag",0).eq("equipment_id",equipment.getId()),false); |
| | | if(ObjectUtils.isNull(maintenanceStandard)){ |
| | | maintenanceStandard = new MaintenanceStandard(); |
| | | maintenanceStandard.setNum(sysIdentityService.getNumByTypeAndLength("DailyMaintenanceStandard",4)); |
| | | maintenanceStandard.setEquipmentId(equipment.getId()); |
| | | maintenanceStandard.setAssignMode("1"); |
| | | maintenanceStandard.setVersion("1.0"); |
| | | maintenanceStandard.setVersionStatus("2"); |
| | | maintenanceStandardService.save(maintenanceStandard); |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | for (XWPFTableRow row : table.getRows()) { |
| | | XWPFTableCell cell0 = row.getCell(0); |
| | | XWPFTableCell cell2 = row.getCell(2); |
| | | if(rowNumber>3){ |
| | | String role = getMergedCellValue(cell0); |
| | | String projectName = cell2.getText(); |
| | | MaintenanceStandardDetail maintenanceStandardDetail = new MaintenanceStandardDetail(); |
| | | MaintenanceProjectCategory maintenanceProjectCategory = maintenanceProjectCategoryService.getOne(new QueryWrapper<MaintenanceProjectCategory>().eq("name","二级保养").eq("del_flag",0),false); |
| | | if(ObjectUtils.isNotNull(maintenanceProjectCategory)){ |
| | | MaintenanceProject maintenanceProject = maintenanceProjectService.getOne(new QueryWrapper<MaintenanceProject>().eq("name",projectName).eq("del_flag",0).eq("maintenance_project_category_id",maintenanceProjectCategory.getId()),false); |
| | | MaintenanceCycle maintenanceCycle = maintenanceCycleService.getOne(new QueryWrapper<MaintenanceCycle>().eq("name","6月").eq("version_status",2).eq("del_flag",0),false); |
| | | if (!ObjectUtils.isNotNull(maintenanceProject)) { |
| | | maintenanceProject = new MaintenanceProject(); |
| | | maintenanceProject.setNum(sysIdentityService.getNumByTypeAndLength("MainOfTwo", 4)); |
| | | maintenanceProject.setName(projectName); |
| | | maintenanceProject.setMaintenanceProjectCategoryId(maintenanceProjectCategory.getId()); |
| | | maintenanceProject.setDelFlag(0); |
| | | maintenanceProjectService.save(maintenanceProject); |
| | | } |
| | | maintenanceStandardDetail.setMaintenanceProjectId(maintenanceProject.getId()); |
| | | if(role.equals("维修人员保养内容")){ |
| | | maintenanceStandardDetail.setMaintenanceRole("maintenance"); |
| | | } else if(role.equals("操作人员保养内容")){ |
| | | maintenanceStandardDetail.setMaintenanceRole("operator"); |
| | | } |
| | | if(ObjectUtils.isNotNull(maintenanceCycle)){ |
| | | maintenanceStandardDetail.setMaintenanceCycleId(maintenanceCycle.getId()); |
| | | } |
| | | maintenanceStandardDetailService.save(maintenanceStandardDetail); |
| | | } |
| | | |
| | | } |
| | | rowNumber++; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | System.out.println("无法解析该文件"); |
| | | } |
| | | |
| | | fis.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return Result.error("文件导入失败!"); |
| | | } |
| | | /** |
| | | * 通过excel导入数据 |
| | | * |
| | | * @param request |
| | | * @param response |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/importExcelOfThreeMaintenance", method = RequestMethod.POST) |
| | | public Result<?> importExcelOfThreeMaintenance(HttpServletRequest request, HttpServletResponse response) { |
| | | MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; |
| | | LoginUser user= (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | Map<String, MultipartFile> fileMap = multipartRequest.getFileMap(); |
| | | String exceptionInfo = ""; |
| | | int exceptionNum = 0; |
| | | for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) { |
| | | MultipartFile file = entity.getValue(); |
| | | try { |
| | | InputStream fis = file.getInputStream(); |
| | | XWPFDocument document = new XWPFDocument(fis); |
| | | XWPFParagraph mainTitleParagraph = document.getParagraphs().get(0); |
| | | if (mainTitleParagraph != null) { |
| | | // 获取主标题文本内容 |
| | | String mainTitle = mainTitleParagraph.getText(); |
| | | if(mainTitle.equals("生产设备三级保养规范")){ |
| | | for (XWPFTable table : document.getTables()) { |
| | | // 遍历表格中的所有行 |
| | | int rowNumber = 0; |
| | | String equipmentNum = ""; |
| | | Equipment equipment = null; |
| | | MaintenanceStandard maintenanceStandard = null; |
| | | XWPFTableRow row0= table.getRow(0); |
| | | if(ObjectUtils.isNotNull(row0)){ |
| | | XWPFTableCell cellEquipmentNum = row0.getCell(3); |
| | | if(ObjectUtils.isNotNull(cellEquipmentNum)){ |
| | | equipmentNum =cellEquipmentNum.getText(); |
| | | equipment = equipmentService.getOne(new QueryWrapper<Equipment>().eq("num",equipmentNum).eq("del_flag",0),false); |
| | | if(ObjectUtils.isNotNull(equipment)){ |
| | | maintenanceStandard = maintenanceStandardService.getOne(new QueryWrapper<MaintenanceStandard>().eq("version_status",2).eq("del_flag",0).eq("equipment_id",equipment.getId()),false); |
| | | if(ObjectUtils.isNull(maintenanceStandard)){ |
| | | maintenanceStandard = new MaintenanceStandard(); |
| | | maintenanceStandard.setNum(sysIdentityService.getNumByTypeAndLength("DailyMaintenanceStandard",4)); |
| | | maintenanceStandard.setEquipmentId(equipment.getId()); |
| | | maintenanceStandard.setAssignMode("1"); |
| | | maintenanceStandard.setVersion("1.0"); |
| | | maintenanceStandard.setVersionStatus("2"); |
| | | maintenanceStandardService.save(maintenanceStandard); |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | } |
| | | else { |
| | | continue; |
| | | } |
| | | for (XWPFTableRow row : table.getRows()) { |
| | | XWPFTableCell cell0 = row.getCell(0); |
| | | XWPFTableCell cell1 = row.getCell(1); |
| | | XWPFTableCell cell2 = row.getCell(2); |
| | | if(rowNumber>2){ |
| | | String location = getMergedCellValue(cell0); |
| | | String projectName = cell1.getText(); |
| | | String projectStandard = cell2.getText(); |
| | | MaintenanceStandardDetail maintenanceStandardDetail = new MaintenanceStandardDetail(); |
| | | MaintenanceProjectCategory maintenanceProjectCategory = maintenanceProjectCategoryService.getOne(new QueryWrapper<MaintenanceProjectCategory>().eq("name","三级保养").eq("del_flag",0),false); |
| | | if(ObjectUtils.isNotNull(maintenanceProjectCategory)){ |
| | | MaintenanceProject maintenanceProject = maintenanceProjectService.getOne(new QueryWrapper<MaintenanceProject>().eq("name",projectName).eq("standard",projectStandard).eq("del_flag",0).eq("maintenance_project_category_id",maintenanceProjectCategory.getId()),false); |
| | | MaintenanceCycle maintenanceCycle = null; |
| | | if(equipment.getEquipmentImportanceId().equals("A")){ |
| | | maintenanceCycle = maintenanceCycleService.getOne(new QueryWrapper<MaintenanceCycle>().eq("name","3年").eq("version_status",2).eq("del_flag",0),false); |
| | | }else { |
| | | maintenanceCycle = maintenanceCycleService.getOne(new QueryWrapper<MaintenanceCycle>().eq("name","4年").eq("version_status",2).eq("del_flag",0),false); |
| | | } |
| | | if (!ObjectUtils.isNotNull(maintenanceProject)) { |
| | | maintenanceProject = new MaintenanceProject(); |
| | | maintenanceProject.setNum(sysIdentityService.getNumByTypeAndLength("MainOfTwo", 4)); |
| | | maintenanceProject.setName(projectName); |
| | | maintenanceProject.setLocation(location); |
| | | maintenanceProject.setMaintenanceProjectCategoryId(maintenanceProjectCategory.getId()); |
| | | maintenanceProject.setDelFlag(0); |
| | | maintenanceProjectService.save(maintenanceProject); |
| | | } |
| | | maintenanceStandardDetail.setMaintenanceProjectId(maintenanceProject.getId()); |
| | | maintenanceStandardDetail.setLocation(location); |
| | | maintenanceStandardDetail.setMaintenanceCycleId(maintenanceCycle.getId()); |
| | | maintenanceStandardDetailService.save(maintenanceStandardDetail); |
| | | } |
| | | |
| | | } |
| | | rowNumber++; |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | System.out.println("无法解析该文件"); |
| | | } |
| | | |
| | | fis.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | return Result.error("文件导入失败!"); |
| | | } |
| | | |
| | | /** |
| | |
| | | return Result.error("审核失败!"); |
| | | } |
| | | } |
| | | // 获取合并单元格的值 |
| | | private String getMergedCellValue(XWPFTableCell cell) { |
| | | // 对于合并单元格,获取第一个段落的文本作为合并单元格的值 |
| | | return cell.getParagraphs().get(0).getText(); |
| | | } |
| | | |
| | | } |