| | |
| | | qw.eq(bo.getMaintUser() != null, "mp.maint_user", bo.getMaintUser()); |
| | | qw.in(bo.getMaintDept() != null, "mp.maint_dept", getAllDescendantIds(bo.getMaintDept())); |
| | | qw.eq(bo.getStatus() != null, "mp.status", bo.getStatus()); |
| | | qw.orderByDesc("mp.create_time"); |
| | | return qw; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean insertByBo(EimsMaintPlanBo bo) { |
| | | setMaintNextTime(bo); |
| | | //setMaintNextTime(bo); |
| | | EimsMaintPlan add = MapstructUtils.convert(bo, EimsMaintPlan.class); |
| | | validEntityBeforeSave(add); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 计算保养计划下次执行时间 |
| | | */ |
| | | @SneakyThrows |
| | | private void setMaintNextTime(EimsMaintPlanBo bo) { |
| | | Date maintFirstTime = bo.getMaintFirstTime(); |
| | | Date maintLastTime = bo.getMaintLastTime(); |
| | | //下次保养时间计算规则 0-按固定周期 1-按上次保养时间 |
| | | Date nextDate = (maintLastTime != null && bo.getMaintRule().equals(DictConstants.MAINT_TIME_RULE_DETAIL.LAST)) ? maintLastTime :maintFirstTime; |
| | | |
| | | //首次执行时间为空抛出异常 |
| | | if (maintFirstTime == null) { |
| | | throw new Exception("首次执行时间不能为空!"); |
| | | } |
| | | //周期 |
| | | Long maintCycle = bo.getMaintCycle(); |
| | | //单位 1-天 2-周 3-月 4-季 5-年 |
| | | String maintCycleUnit = bo.getMaintCycleUnit(); |
| | | switch (maintCycleUnit) { |
| | | case "1": |
| | | nextDate = DateUtils.addDays(nextDate, maintCycle.intValue()); |
| | | break; |
| | | case "2": |
| | | nextDate = DateUtils.addWeeks(nextDate, maintCycle.intValue()); |
| | | break; |
| | | case "3": |
| | | nextDate = DateUtils.addMonths(nextDate, maintCycle.intValue()); |
| | | break; |
| | | case "4": |
| | | nextDate = DateUtils.addMonths(nextDate, maintCycle.intValue() * 3); |
| | | break; |
| | | case "5": |
| | | nextDate = DateUtils.addYears(nextDate, maintCycle.intValue()); |
| | | break; |
| | | |
| | | } |
| | | bo.setMaintNextTime(nextDate); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 修改保养计划 |