| | |
| | | import com.aizuda.snailjob.client.job.core.annotation.JobExecutor; |
| | | import com.aizuda.snailjob.client.job.core.dto.JobArgs; |
| | | import com.aizuda.snailjob.client.model.ExecuteResult; |
| | | import com.aizuda.snailjob.common.core.util.JsonUtil; |
| | | import com.aizuda.snailjob.common.log.SnailJobLog; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.eims.domain.*; |
| | | import org.dromara.eims.domain.bo.EimsMaintPlanBo; |
| | | import org.dromara.eims.domain.vo.EimsMaintPlanVo; |
| | | import org.dromara.eims.mapper.EimsMaintOrderMapper; |
| | | import org.dromara.eims.mapper.EimsMaintPlanMapper; |
| | | import org.dromara.eims.service.IEimsMaintOrderService; |
| | | import org.dromara.eims.service.IEimsMaintPlanService; |
| | | import org.dromara.eims.service.IGenerateCodeService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final EimsMaintOrderMapper orderMapper; |
| | | |
| | | |
| | | |
| | | private final EimsMaintPlanMapper planMapper; |
| | | |
| | | private final IGenerateCodeService codeService; |
| | |
| | | // 获取今天日期 |
| | | |
| | | Date today = new Date(); |
| | | LambdaQueryWrapper<EimsMaintPlan> planBoQueryWrapper = Wrappers.lambdaQuery(); |
| | | QueryWrapper<EimsMaintPlan> planBoQueryWrapper = Wrappers.query(); |
| | | // 查询启用的保养计划 |
| | | planBoQueryWrapper.eq(EimsMaintPlan::getStatus, DictConstants.SYS_NORMAL_DISABLE_DETAIL.NORMAL); |
| | | // 过滤没有首次运行时间 |
| | | planBoQueryWrapper.isNotNull(EimsMaintPlan::getMaintFirstTime); |
| | | // 过滤没有下次运行时间 |
| | | planBoQueryWrapper.isNotNull(EimsMaintPlan::getMaintNextTime); |
| | | // 过滤没有保养周期的数据 |
| | | planBoQueryWrapper.isNotNull(EimsMaintPlan::getMaintCycle); |
| | | planBoQueryWrapper.isNotNull(EimsMaintPlan::getMaintCycleUnit); |
| | | planBoQueryWrapper.isNotNull(EimsMaintPlan::getMaintRule); |
| | | |
| | | List<EimsMaintPlanVo> planVoList = planMapper.selectVoList(planBoQueryWrapper); |
| | | planBoQueryWrapper.eq("mp.status", DictConstants.SYS_NORMAL_DISABLE_DETAIL.NORMAL); |
| | | planBoQueryWrapper .eq("equ.status", DictConstants.EIMS_EQU_STATUS_DETAIL.SHIYONG); |
| | | // 过滤下次运行时间等于当天时间的 |
| | | // planBoQueryWrapper.eq("mp.maint_next_time", DateUtils.getDate()); |
| | | // 过滤没有保养周期的数据 |
| | | planBoQueryWrapper.isNotNull("mp.maint_cycle"); |
| | | planBoQueryWrapper.isNotNull("mp.maint_cycle_unit"); |
| | | planBoQueryWrapper.isNotNull("mp.maint_rule"); |
| | | |
| | | List<EimsMaintPlanVo> planVoList = planMapper.selectVoListJoinEqu(planBoQueryWrapper); |
| | | for (int i = 0; i < planVoList.size(); i++) { |
| | | EimsMaintPlanVo planVo = planVoList.get(i); |
| | | // 保养计划add的时候会自动生成下次运行时间 |
| | | Date createOrderTime = planVo.getMaintNextTime(); |
| | | int day = DateUtils.differentDays(today,createOrderTime ); |
| | | Date oldNext = planVo.getMaintNextTime(); |
| | | int day = DateUtils.differentDays(today, oldNext); |
| | | // 如果计划生成工单日期大于今天则不生成工单 |
| | | if (day >= 1) { |
| | | continue; |
| | |
| | | |
| | | // 计算生成工单时间 |
| | | Long maintCycle = planVo.getMaintCycle(); |
| | | String maintRule = planVo.getMaintRule(); |
| | | Date firstTime = planVo.getMaintFirstTime(); |
| | | Date lastTime = planVo.getMaintLastTime(); |
| | | Date nextTime = null; |
| | | Date newNext = null; |
| | | String maintCycleUnit = planVo.getMaintCycleUnit(); |
| | | switch (maintCycleUnit) { |
| | | case DictConstants.MAINT_CYCLE_UNIT_DETAIL.DAY: |
| | | newNext = DateUtils.addDays(oldNext, maintCycle.intValue()); |
| | | break; |
| | | case DictConstants.MAINT_CYCLE_UNIT_DETAIL.WEEK: |
| | | maintCycle *= 7; |
| | | |
| | | newNext = DateUtils.addWeeks(oldNext, maintCycle.intValue()); |
| | | |
| | | break; |
| | | case DictConstants.MAINT_CYCLE_UNIT_DETAIL.MONTH: |
| | | maintCycle *= 30; |
| | | |
| | | newNext = DateUtils.addMonths(oldNext, maintCycle.intValue()); |
| | | |
| | | break; |
| | | case DictConstants.MAINT_CYCLE_UNIT_DETAIL.SEASON: |
| | | maintCycle *= 90; |
| | | newNext = DateUtils.addMonths(oldNext, maintCycle.intValue() * 3); |
| | | |
| | | break; |
| | | case DictConstants.MAINT_CYCLE_UNIT_DETAIL.YEAR: |
| | | maintCycle *= 365; |
| | | |
| | | newNext = DateUtils.addYears(oldNext, maintCycle.intValue()); |
| | | |
| | | break; |
| | | } |
| | | // 首次 |
| | | if (lastTime == null ) { |
| | | nextTime = DateUtils.addDays(createOrderTime, maintCycle.intValue()); |
| | | } else { |
| | | nextTime = DateUtils.addDays(lastTime, maintCycle.intValue()); |
| | | } |
| | | |
| | | EimsMaintOrder order = new EimsMaintOrder(); |
| | | BeanUtils.copyProperties(planVo, order); |
| | | order.setId(null); |
| | | order.setStatus(DictConstants.MAINT_ORDER_STATUS_DETAIL.DAIBAOYANG); |
| | | order.setPlanTime(createOrderTime); |
| | | order.setPlanTime(oldNext); |
| | | order.setPlanId(planVo.getId()); |
| | | order.setMaintName(planVo.getMaintName()); |
| | | order.setMaintCode(codeService.generateCode("BYZD")); |
| | | EimsMaintPlan plan = MapstructUtils.convert(planVo, EimsMaintPlan.class); |
| | | assert plan != null; |
| | | plan.setLastGenerateDate(new Date()); |
| | | plan.setMaintLastTime(createOrderTime); |
| | | plan.setMaintNextTime(nextTime); |
| | | boolean flag = orderMapper.insert(order) > 0; |
| | | plan.setLastOrderDate(new Date()); |
| | | plan.setMaintLastTime(oldNext); |
| | | plan.setMaintNextTime(newNext); |
| | | if(plan.getMaintFirstTime()==null)plan.setMaintFirstTime(oldNext); |
| | | boolean flag = orderMapper.insert(order) > 0; |
| | | //TODO 生成失败,添加异常记录 |
| | | if (!flag) continue; |
| | | planMapper.updateById(plan); |
| | | |
| | | |
| | | |
| | | |
| | | } |