| | |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.vo.EamEquipmentTree; |
| | | import org.jeecg.modules.eam.vo.EquipmentSearchResult; |
| | | //import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | //import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | import org.jeecg.modules.system.entity.BaseFactory; |
| | | import org.jeecg.modules.system.entity.EamBaseRepairDepart; |
| | | import org.jeecg.modules.system.service.IBaseFactoryService; |
| | | import org.jeecg.modules.system.service.IEamBaseRepairDepartService; |
| | | import org.jeecgframework.poi.excel.ExcelImportUtil; |
| | | import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import org.apache.commons.lang3.time.DateUtils; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.function.Consumer; |
| | | import java.util.stream.Collectors; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | |
| | | /** |
| | | * @Description: 设备台账 |
| | |
| | | private TranslateDictTextUtils translateDictTextUtils; |
| | | @Autowired |
| | | private IBaseFactoryService baseFactoryService; |
| | | |
| | | @Autowired |
| | | private IEamBaseRepairDepartService eamBaseRepairDepartService; |
| | | /** |
| | | * 分页列表查询 |
| | | * |
| | |
| | | equipmentList.forEach(item -> { |
| | | EamEquipmentDto eamEquipmentDto = new EamEquipmentDto(); |
| | | BeanUtils.copyProperties(item,eamEquipmentDto); |
| | | if (eamEquipmentDto.getFactoryOrgCode().length()==12){ |
| | | eamEquipmentDto.setFactoryOrgCode( |
| | | baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode()) |
| | | +"/"+baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getGqfactoryOrgCode())+"/"+ |
| | | baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode())); |
| | | }else { |
| | | eamEquipmentDto.setFactoryOrgCode( |
| | | baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getZxfactoryOrgCode()) |
| | | +"/"+ baseFactoryService.factoryDataNameByOrgCode(eamEquipmentDto.getFactoryOrgCode())); |
| | | } |
| | | if (eamEquipmentDto.getEquipmentWeight()!=null){ |
| | | eamEquipmentDto.setEquipmentWeightStr(eamEquipmentDto.getEquipmentWeight().toEngineeringString()); |
| | | } |
| | | eamEquipmentDtos.add(eamEquipmentDto); |
| | | }); |
| | | // Step.3 AutoPoi 导出Excel |
| | |
| | | }else { |
| | | eamEquipment.setFactoryOrgCode(baseFactory.getOrgCode()); |
| | | } |
| | | EamBaseRepairDepart eamBaseRepairDepart=eamBaseRepairDepartService.searchCenterByKeyWord(eamEquipment.getRepairDepartOrgCode()); |
| | | if(eamBaseRepairDepart==null){ |
| | | sb.append(String.format("维修班组信息[%s]不存在,无法导入\n\r", eamEquipment.getRepairDepartOrgCode())); |
| | | continue; |
| | | }else { |
| | | eamEquipment.setRepairDepartOrgCode(eamBaseRepairDepart.getOrgCode()); |
| | | } |
| | | // 字段校验与填充 |
| | | if (StringUtils.isNotBlank(eamEquipment.getLeaveFactory())) { |
| | | String leaveFactoryStr = eamEquipment.getLeaveFactory(); |
| | | try { |
| | | // 定义支持解析的日期格式 |
| | | String[] parsePatterns = { |
| | | "yyyy/MM/dd", "yyyy-MM-dd", "yyyyMMdd" |
| | | }; |
| | | // 格式1: 包含分隔符的日期格式 (如2025/07/30, 2025-07-30等) |
| | | if (leaveFactoryStr.contains("/") || leaveFactoryStr.contains("-") || |
| | | (leaveFactoryStr.length() == 8 && leaveFactoryStr.matches("\\d{8}"))) { |
| | | |
| | | // 使用指定的格式数组解析日期 |
| | | Date leaveFactoryDate = DateUtils.parseDate(leaveFactoryStr, parsePatterns); |
| | | eamEquipment.setLeaveFactoryDate(leaveFactoryDate); |
| | | } else { |
| | | log.warn("离开工厂日期格式无效: {}", leaveFactoryStr); |
| | | } |
| | | } catch (ParseException e) { |
| | | log.error("日期解析失败: {}", leaveFactoryStr, e); |
| | | } |
| | | } |
| | | // 计算三保日期 |
| | | if (eamEquipment.getNextThirdMaintenance() != null && |
| | | eamEquipment.getThirdMaintenancePeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | eamEquipment.getNextThirdMaintenance(), |
| | | eamEquipment.getThirdMaintenancePeriod(), |
| | | newDate -> eamEquipment.setNextThirdMaintenance(newDate), |
| | | latestDate -> eamEquipment.setLatestThirdMaintenance(latestDate) |
| | | ); |
| | | } |
| | | |
| | | // 计算技术状态鉴定日期 |
| | | if (eamEquipment.getNextTechnologyCheck() != null && |
| | | eamEquipment.getTechnologyCheckPeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | eamEquipment.getNextTechnologyCheck(), |
| | | eamEquipment.getTechnologyCheckPeriod(), |
| | | newDate -> eamEquipment.setNextTechnologyCheck(newDate), |
| | | latestDate -> eamEquipment.setLatestTechnologyCheck(latestDate) |
| | | ); |
| | | } |
| | | EamEquipment equipment = eamEquipmentService.saveEquipment(eamEquipment); |
| | | if (equipment == null) { |
| | | //保存失败,跳过本次循环 |
| | | sb.append(String.format("设备编码[%s]保存失败,无法导入\n\r", eamEquipment.getEquipmentCode())); |
| | | continue; |
| | | } |
| | | EamEquipmentExtend eamEquipmentExtend=new EamEquipmentExtend(); |
| | | BeanUtils.copyProperties(eamEquipmentExtend,equipment); |
| | | eamEquipmentExtendService.save(eamEquipmentExtend); |
| | | } |
| | | log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒"); |
| | | //update-end-author:taoyan date:20190528 for:批量插入数据 |
| | |
| | | @GetMapping(value = "/asyncLoadEquipment") |
| | | public Result<?> asyncLoadEquipment(@RequestParam(name="keyword",required = false) String keyword, |
| | | @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, |
| | | @RequestParam(name="id",required = false) String id) { |
| | | List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id); |
| | | return Result.ok(resultList); |
| | | @RequestParam(name="id",required = false) String id, |
| | | @RequestParam(name="factoryOrgCode",required = false) String factoryOrgCode) { |
| | | List<EquipmentSearchResult> resultList = eamEquipmentService.asyncLoadEquipment(keyword, pageSize, id, factoryOrgCode); |
| | | List<JSONObject> items = new ArrayList<>(); |
| | | try { |
| | | for(EquipmentSearchResult vo : resultList) { |
| | | String json = objectMapper.writeValueAsString(vo); |
| | | JSONObject item = JSONObject.parseObject(json, Feature.OrderedField); |
| | | translateDictTextUtils.translateField("factoryOrgCode", vo.getFactoryOrgCode(), item, "eam_base_factory,factory_name,org_code"); |
| | | items.add(item); |
| | | } |
| | | return Result.OK(items); |
| | | }catch (Exception e) { |
| | | return Result.error("数据转译失败!"); |
| | | } |
| | | } |
| | | |
| | | // 日期计算工具方法 |
| | | private void calculateMaintenanceDates(Date nextDate, Integer periodYears, |
| | | Consumer<Date> setNextMaintenance, |
| | | Consumer<Date> setLatestMaintenance) { |
| | | if (nextDate == null || periodYears == null || periodYears <= 0) { |
| | | return; |
| | | } |
| | | |
| | | // 转换为Java 8日期类型 |
| | | LocalDate nextLocal = nextDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | LocalDate today = LocalDate.now(); |
| | | |
| | | // 确保有效的计算周期 |
| | | int period = Math.max(1, periodYears); // 防止传入0或负值 |
| | | |
| | | if (nextLocal.isAfter(today)) { |
| | | // 未过期:计算最近维护日期 |
| | | setLatestMaintenance.accept( |
| | | Date.from(nextLocal.minusYears(period).atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | } else { |
| | | // 已过期:计算新的下次维护日期 |
| | | while (!nextLocal.isAfter(today)) { |
| | | nextLocal = nextLocal.plusYears(period); |
| | | } |
| | | |
| | | // 设置新日期 |
| | | setNextMaintenance.accept( |
| | | Date.from(nextLocal.atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | |
| | | // 计算最近维护日期 |
| | | setLatestMaintenance.accept( |
| | | Date.from(nextLocal.minusYears(period).atStartOfDay() |
| | | .atZone(ZoneId.systemDefault()).toInstant()) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | } |