| | |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.TimeZone; |
| | | import java.util.function.Consumer; |
| | | |
| | | import org.jeecg.common.constant.SymbolConstant; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | calendar.add(Calendar.YEAR, year); |
| | | return calendar.getTime(); |
| | | } |
| | | |
| | | /** |
| | | * 检查日期是否在今天或之前(忽略时间部分) |
| | | */ |
| | | public static boolean isBeforeOrEqualToday(Date targetDate) { |
| | | if (targetDate == null) return false; |
| | | |
| | | Calendar calTarget = Calendar.getInstance(); |
| | | calTarget.setTime(targetDate); |
| | | clearTime(calTarget); |
| | | |
| | | Calendar calToday = Calendar.getInstance(); |
| | | clearTime(calToday); |
| | | |
| | | return !calTarget.after(calToday); |
| | | } |
| | | |
| | | private static void clearTime(Calendar cal) { |
| | | cal.set(Calendar.HOUR_OF_DAY, 0); |
| | | cal.set(Calendar.MINUTE, 0); |
| | | cal.set(Calendar.SECOND, 0); |
| | | cal.set(Calendar.MILLISECOND, 0); |
| | | } |
| | | |
| | | public static 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()) |
| | | ); |
| | | } |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty(value = "主键") |
| | | private java.lang.String id; |
| | | /**创建人*/ |
| | | @Excel(name = "创建人", width = 15) |
| | | @ApiModelProperty(value = "创建人") |
| | | private java.lang.String createBy; |
| | | /**创建时间*/ |
| | | @ApiModelProperty(value = "创建时间") |
| | | private java.util.Date createTime; |
| | | /**更新人*/ |
| | | @Excel(name = "更新人", width = 15) |
| | | @ApiModelProperty(value = "更新人") |
| | | private java.lang.String updateBy; |
| | | /**更新时间*/ |
| | | @ApiModelProperty(value = "更新时间") |
| | | private java.util.Date updateTime; |
| | | /**删除标记*/ |
| | | @Excel(name = "删除标记", width = 15) |
| | | @ApiModelProperty(value = "删除标记") |
| | | private java.lang.Integer delFlag; |
| | | /**设备统一编号*/ |
| | | @Excel(name = "设备统一编号", width = 15) |
| | | @ApiModelProperty(value = "设备统一编号") |
| | | private java.lang.String equipmentCode; |
| | | /**使用部门*/ |
| | | @Excel(name = "生产单位", width = 15,dictTable = "eam_base_factory",dicText = "factory_name",dicCode = "org_code") |
| | | @ApiModelProperty(value = "生产单位") |
| | | @Dict(dictTable = "eam_base_factory",dicText = "factory_name",dicCode = "org_code") |
| | | private java.lang.String factoryOrgCode; |
| | | |
| | | /**设备名称*/ |
| | | @Excel(name = "设备名称", width = 15) |
| | | @ApiModelProperty(value = "设备名称") |
| | | private java.lang.String equipmentName; |
| | | /**使用部门*/ |
| | | @Excel(name = "使用部门", width = 15) |
| | | @ApiModelProperty(value = "使用部门") |
| | | @Dict(dictTable = "eam_base_factory",dicText = "factory_name",dicCode = "org_code") |
| | | private java.lang.String factoryOrgCode; |
| | | |
| | | /**设备型号*/ |
| | | @Excel(name = "设备型号", width = 15) |
| | | @ApiModelProperty(value = "设备型号") |
| | | private java.lang.String equipmentModel; |
| | | /**统一编号*/ |
| | | @Excel(name = "统一编号", width = 15) |
| | | @ApiModelProperty(value = "统一编号") |
| | | private java.lang.String equipmentCode; |
| | | |
| | | /**保养日期*/ |
| | | @Excel(name = "保养日期", width = 15,format = "yyyy-MM-dd") |
| | | @ApiModelProperty(value = "保养日期") |
| | | @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") |
| | | @DateTimeFormat(pattern = "yyyy-MM-dd") |
| | |
| | | package org.jeecg.modules.eam.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamThirdMaintenanceWorkPlanSheet; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @Description: “三级保养工作计划单 |
| | |
| | | public interface IEamThirdMaintenanceWorkPlanSheetService extends IService<EamThirdMaintenanceWorkPlanSheet> { |
| | | |
| | | /** |
| | | * 通过设备编号,保养日期查询 |
| | | * @param equipmentCode,maintenanceDate |
| | | * @return |
| | | */ |
| | | EamThirdMaintenanceWorkPlanSheet getByEquipmentCodeAndMaintenanceDate(String equipmentCode, Date maintenanceDate); |
| | | |
| | | /** |
| | | * 新增 |
| | | * @param eamThirdMaintenanceWorkPlanSheet |
| | | * @return |
| | | */ |
| | | boolean add(EamThirdMaintenanceWorkPlanSheet eamThirdMaintenanceWorkPlanSheet); |
| | | |
| | | /** |
| | | * existsByEquipmentAndDate |
| | | * @param equipmentCode |
| | | * @param maintenanceDate |
| | | * @return |
| | | */ |
| | | boolean existsByEquipmentAndDate(String equipmentCode, Date maintenanceDate); |
| | | |
| | | /** |
| | | * 处理保养日期变更(增删改查) |
| | | */ |
| | | void processMaintenanceDateChange(EamEquipment equipment, Date oldDate, Date newDate); |
| | | |
| | | /** |
| | | * 创建保养计划 |
| | | */ |
| | | void createMaintenancePlan(EamEquipment equipment, Date maintenanceDate); |
| | | } |
| | |
| | | } |
| | | |
| | | EamEquipment eamEquipment = eamEquipmentMapper.selectById(equipmentId); |
| | | EamThirdMaintenanceWorkPlanSheet eamThirdMaintenanceWorkPlanSheet=new EamThirdMaintenanceWorkPlanSheet(); |
| | | BeanUtils.copyProperties(eamEquipment,eamThirdMaintenanceWorkPlanSheet); |
| | | eamThirdMaintenanceWorkPlanSheet.setId(null); |
| | | eamThirdMaintenanceWorkPlanSheet.setMaintenanceDate(eamEquipment.getLatestThirdMaintenance()); |
| | | eamThirdMaintenanceWorkPlanSheetService.add(eamThirdMaintenanceWorkPlanSheet); |
| | | |
| | | eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, entity.getLatestThirdMaintenance()); |
| | | eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, entity.getNextThirdMaintenance()); |
| | | return this.getBaseMapper().updateById(entity) > 0; |
| | | } |
| | | |
| | |
| | | private IBaseFactoryService baseFactoryService; |
| | | @Autowired |
| | | private IEamThirdMaintenanceWorkPlanSheetService eamThirdMaintenanceWorkPlanSheetService; |
| | | @Autowired |
| | | private IEamEquipmentExtendService iEamEquipmentExtendService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | eamEquipmentExtend.setRepairStatus(EquipmentRepairStatus.NORMAL.name()); |
| | | equipmentExtendService.save(eamEquipmentExtend); |
| | | |
| | | //三保 |
| | | EamThirdMaintenanceWorkPlanSheet eamThirdMaintenanceWorkPlanSheet=new EamThirdMaintenanceWorkPlanSheet(); |
| | | BeanUtils.copyProperties(eamEquipment,eamThirdMaintenanceWorkPlanSheet); |
| | | eamThirdMaintenanceWorkPlanSheet.setId(null); |
| | | eamThirdMaintenanceWorkPlanSheet.setMaintenanceDate(eamEquipment.getLatestThirdMaintenance()); |
| | | eamThirdMaintenanceWorkPlanSheetService.add(eamThirdMaintenanceWorkPlanSheet); |
| | | // 处理三保保养计划(不再进行日期比较) |
| | | eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, eamEquipment.getLatestThirdMaintenance()); |
| | | eamThirdMaintenanceWorkPlanSheetService.createMaintenancePlan(eamEquipment, eamEquipment.getNextThirdMaintenance()); |
| | | |
| | | //插入设备履历 @EquipmentHistoryLog |
| | | return eamEquipment; |
| | |
| | | */ |
| | | @Override |
| | | public EamEquipment updateEquipment(EamEquipment eamEquipment){ |
| | | if (eamEquipment == null) { |
| | | return null; |
| | | if (eamEquipment == null) return null; |
| | | |
| | | if (eamEquipment.getNextThirdMaintenance() != null && |
| | | eamEquipment.getThirdMaintenancePeriod() != null) { |
| | | |
| | | org.jeecg.common.util.DateUtils.calculateMaintenanceDates( |
| | | eamEquipment.getNextThirdMaintenance(), |
| | | eamEquipment.getThirdMaintenancePeriod(), |
| | | newDate -> eamEquipment.setNextThirdMaintenance(newDate), |
| | | latestDate -> eamEquipment.setLatestThirdMaintenance(latestDate) |
| | | ); |
| | | } |
| | | |
| | | // 获取旧数据 |
| | | EamEquipmentExtend old = iEamEquipmentExtendService.getById(eamEquipment.getId()); |
| | | if (old == null) return null; |
| | | |
| | | // 提取新旧日期避免重复访问 |
| | | Date newLatest = eamEquipment.getLatestThirdMaintenance(); |
| | | Date newNext = eamEquipment.getNextThirdMaintenance(); |
| | | Date oldLatest = old.getLatestThirdMaintenance(); |
| | | Date oldNext = old.getNextThirdMaintenance(); |
| | | |
| | | // 处理保养日期变更 |
| | | eamThirdMaintenanceWorkPlanSheetService.processMaintenanceDateChange(eamEquipment, oldLatest, newLatest); |
| | | eamThirdMaintenanceWorkPlanSheetService.processMaintenanceDateChange(eamEquipment, oldNext, newNext); |
| | | |
| | | // 更新主表和扩展表 |
| | | eamEquipmentMapper.updateById(eamEquipment); |
| | | EamEquipmentExtend eamEquipmentExtend = new EamEquipmentExtend(); |
| | | BeanUtils.copyProperties(eamEquipment, eamEquipmentExtend); |
| | |
| | | package org.jeecg.modules.eam.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.modules.eam.constant.HfTemplateCategoryEnum; |
| | | import org.jeecg.modules.eam.entity.EamBaseHFCode; |
| | | import org.jeecg.modules.eam.entity.EamEquipment; |
| | | import org.jeecg.modules.eam.entity.EamThirdMaintenanceWorkPlanSheet; |
| | | import org.jeecg.modules.eam.mapper.EamThirdMaintenanceWorkPlanSheetMapper; |
| | | import org.jeecg.modules.eam.service.IEamBaseHFCodeService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: “三级保养工作计划单 |
| | |
| | | private IEamBaseHFCodeService hfCodeService; |
| | | |
| | | /** |
| | | * 通过设备编号,保养日期查询 |
| | | * @param equipmentCode,maintenanceDate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public EamThirdMaintenanceWorkPlanSheet getByEquipmentCodeAndMaintenanceDate(String equipmentCode, java.util.Date maintenanceDate){ |
| | | List<EamThirdMaintenanceWorkPlanSheet> list = this.baseMapper.selectList(new QueryWrapper<EamThirdMaintenanceWorkPlanSheet>() |
| | | .eq("equipment_code",equipmentCode).eq("maintenance_date",maintenanceDate)); |
| | | if(list == null || list.isEmpty()) { |
| | | return null; |
| | | }else { |
| | | return list.get(0); |
| | | } |
| | | } |
| | | /** |
| | | * 新增 |
| | | * @param eamThirdMaintenanceWorkPlanSheet |
| | | * @return |
| | |
| | | throw new JeecgBootException("未配置三级保养工作计划单的HF编码,添加失败!"); |
| | | } |
| | | eamThirdMaintenanceWorkPlanSheet.setHfCode(eamBaseHFCode.getHfCode()); |
| | | eamThirdMaintenanceWorkPlanSheet.setDelFlag(0); |
| | | return super.save(eamThirdMaintenanceWorkPlanSheet); |
| | | } |
| | | |
| | | /** |
| | | * existsByEquipmentAndDate |
| | | * @param equipmentCode |
| | | * @param maintenanceDate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean existsByEquipmentAndDate(String equipmentCode, Date maintenanceDate){ |
| | | List<EamThirdMaintenanceWorkPlanSheet> list = this.baseMapper.selectList(new QueryWrapper<EamThirdMaintenanceWorkPlanSheet>() |
| | | .eq("equipment_code",equipmentCode).eq("maintenance_date",maintenanceDate)); |
| | | return list != null && !list.isEmpty(); |
| | | } |
| | | |
| | | /** |
| | | * 处理保养日期变更(增删改查) |
| | | */ |
| | | @Override |
| | | public void processMaintenanceDateChange(EamEquipment equipment, Date oldDate, Date newDate) { |
| | | String equipmentCode = equipment.getEquipmentCode(); |
| | | //日期从有值变为null → 删除计划 |
| | | if (oldDate != null && newDate == null) { |
| | | deleteMaintenancePlan(equipmentCode, oldDate); |
| | | } |
| | | //日期从null变为有值 → 新增计划 |
| | | else if (oldDate == null && newDate != null) { |
| | | createMaintenancePlan(equipment, newDate); |
| | | } |
| | | //日期值发生变化 → 更新计划日期 |
| | | else if (oldDate != null && !oldDate.equals(newDate)) { |
| | | updateMaintenancePlanDate(equipmentCode, oldDate, newDate,equipment); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建保养计划 |
| | | */ |
| | | @Override |
| | | public void createMaintenancePlan(EamEquipment equipment, Date maintenanceDate) { |
| | | if (maintenanceDate == null) return; |
| | | // 避免重复创建 |
| | | if (this.existsByEquipmentAndDate( |
| | | equipment.getEquipmentCode(), maintenanceDate)) { |
| | | return; |
| | | } |
| | | EamThirdMaintenanceWorkPlanSheet plan = new EamThirdMaintenanceWorkPlanSheet(); |
| | | plan.setEquipmentCode(equipment.getEquipmentCode()); |
| | | plan.setEquipmentName(equipment.getEquipmentName()); |
| | | plan.setFactoryOrgCode(equipment.getFactoryOrgCode()); |
| | | plan.setEquipmentModel(equipment.getEquipmentModel()); |
| | | plan.setMaintenanceDate(maintenanceDate); |
| | | this.add(plan); |
| | | } |
| | | |
| | | /** |
| | | * 更新保养计划日期 |
| | | */ |
| | | private void updateMaintenancePlanDate(String equipmentCode, Date oldDate, Date newDate,EamEquipment equipment) { |
| | | EamThirdMaintenanceWorkPlanSheet plan = this |
| | | .getByEquipmentCodeAndMaintenanceDate(equipmentCode, oldDate); |
| | | |
| | | if (plan != null) { |
| | | plan.setMaintenanceDate(newDate); |
| | | this.updateById(plan); |
| | | }else { |
| | | createMaintenancePlan(equipment, newDate); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除保养计划 |
| | | */ |
| | | private void deleteMaintenancePlan(String equipmentCode, Date date) { |
| | | EamThirdMaintenanceWorkPlanSheet plan = this |
| | | .getByEquipmentCodeAndMaintenanceDate(equipmentCode, date); |
| | | |
| | | if (plan != null) { |
| | | this.removeById(plan.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (eamEquipment.getNextThirdMaintenance() != null && |
| | | eamEquipment.getThirdMaintenancePeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | org.jeecg.common.util.DateUtils.calculateMaintenanceDates( |
| | | eamEquipment.getNextThirdMaintenance(), |
| | | eamEquipment.getThirdMaintenancePeriod(), |
| | | newDate -> eamEquipment.setNextThirdMaintenance(newDate), |
| | |
| | | if (eamEquipment.getNextTechnologyCheck() != null && |
| | | eamEquipment.getTechnologyCheckPeriod() != null) { |
| | | |
| | | calculateMaintenanceDates( |
| | | org.jeecg.common.util.DateUtils.calculateMaintenanceDates( |
| | | eamEquipment.getNextTechnologyCheck(), |
| | | eamEquipment.getTechnologyCheckPeriod(), |
| | | newDate -> eamEquipment.setNextTechnologyCheck(newDate), |
| | |
| | | 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()) |
| | | ); |
| | | } |
| | | } |
| | | |
| | |
| | | import org.jeecg.modules.eam.entity.EamMaintenanceStandard; |
| | | |
| | | import org.jeecg.modules.eam.request.EamMaintenanceStandardRequest; |
| | | import org.jeecg.modules.eam.service.IEamEquipmentService; |
| | | import org.jeecg.modules.eam.service.IEamMaintenanceStandardService; |
| | | import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo; |
| | | import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; |
| | |
| | | eamThirdMaintenanceOrderIPage=this.baseMapper.queryPageList(page,queryWrapper.clone().like("maintenance_date", nextNextMonth)); |
| | | break; |
| | | default: |
| | | break; |
| | | return eamThirdMaintenanceOrderIPage; |
| | | } |
| | | eamThirdMaintenanceOrderIPage.getRecords().forEach(eamThirdMaintenanceOrder -> { |
| | | eamThirdMaintenanceOrder.setTechnologyStatus(eamEquipmentExtendService.getById(eamThirdMaintenanceOrder.getEquipmentId()).getTechnologyStatus()); |