| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.SneakyThrows; |
| | | import org.dromara.common.core.constant.DictConstants; |
| | | import org.dromara.common.core.domain.model.LoginUser; |
| | | import org.dromara.common.core.service.MaintOrderService; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | | import org.dromara.eims.domain.EimsMaintPlan; |
| | | import org.dromara.eims.domain.bo.EimsMaintPlanBo; |
| | | import org.dromara.eims.domain.vo.MaintOrdeGroupVo; |
| | | import org.dromara.eims.mapper.EimsMaintPlanMapper; |
| | | import org.dromara.system.domain.SysDept; |
| | | import org.dromara.system.domain.vo.SysDeptVo; |
| | | import org.dromara.system.mapper.SysDeptMapper; |
| | |
| | | import org.dromara.eims.service.IEimsMaintOrderService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 保养工单Service业务层处理 |
| | |
| | | public class EimsMaintOrderServiceImpl implements IEimsMaintOrderService, MaintOrderService { |
| | | |
| | | private final EimsMaintOrderMapper baseMapper; |
| | | private final EimsMaintPlanMapper planMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | |
| | | /** |
| | |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | @Override |
| | | public TableDataInfo<MaintOrdeGroupVo> queryPageGroupList(EimsMaintOrderBo bo, PageQuery pageQuery) { |
| | | Page<MaintOrdeGroupVo> page = baseMapper.selectMaintOrderGroupList(pageQuery.build(), buildGroupWrapper(bo)); |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | | * 查询符合条件的保养工单列表 |
| | | * |
| | |
| | | QueryWrapper<EimsMaintOrder> qw = Wrappers.query(); |
| | | qw.like(StringUtils.isNotBlank(bo.getMaintCode()),"mo.maint_code", bo.getMaintCode()); |
| | | qw.like(bo.getEquName() != null, "equ.equ_name", bo.getEquName()); |
| | | qw.like(bo.getEquId() != null, "equ.equ_id", bo.getEquId()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintType()), "mo.maint_type", bo.getMaintType()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintCycleUnit()), "mo.maint_cycle_unit", bo.getMaintCycleUnit()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintRule()), "mo.maint_rule", bo.getMaintRule()); |
| | | qw.eq(bo.getMaintUser() != null, "mo.maint_user", bo.getMaintUser()); |
| | | qw.in(bo.getMaintDept() != null, "mo.maint_dept", getAllDescendantIds(bo.getMaintDept())); |
| | | qw.eq(bo.getStatus() != null, "mo.status", bo.getStatus()); |
| | | qw.eq(bo.getPlanTime()!=null, |
| | | "mo.plan_time", bo.getPlanTime()); |
| | | qw.orderByDesc("mo.create_time"); |
| | | return qw; |
| | | } |
| | | private QueryWrapper<EimsMaintOrder> buildGroupWrapper(EimsMaintOrderBo bo) { |
| | | Map<String, Object> params = bo.getParams(); |
| | | QueryWrapper<EimsMaintOrder> qw = Wrappers.query(); |
| | | qw.like(StringUtils.isNotBlank(bo.getMaintCode()),"mo.maint_code", bo.getMaintCode()); |
| | | qw.like(bo.getEquName() != null, "equ.equ_name", bo.getEquName()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintType()), "mo.maint_type", bo.getMaintType()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintCycleUnit()), "mo.maint_cycle_unit", bo.getMaintCycleUnit()); |
| | | qw.eq(StringUtils.isNotBlank(bo.getMaintRule()), "mo.maint_rule", bo.getMaintRule()); |
| | | qw.eq(bo.getMaintUser() != null, "mo.maint_user", bo.getMaintUser()); |
| | | qw.in(bo.getMaintDept() != null, "mo.maint_dept", getAllDescendantIds(bo.getMaintDept())); |
| | | qw.eq(bo.getStatus() != null, "mo.status", bo.getStatus()); |
| | | qw.between(params.get("beginPlanTime") != null && params.get("endPlanTime") != null, |
| | | "mo.plan_time", params.get("beginPlanTime"), params.get("endPlanTime")); |
| | | qw.groupBy(Arrays.asList("mo.equ_id","mo.plan_time")); |
| | | qw.orderByDesc("mo.plan_time"); |
| | | return qw; |
| | | } |
| | | |
| | |
| | | * @param bo 保养工单 |
| | | * @return 是否新增成功 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public Boolean insertByBo(EimsMaintOrderBo bo) { |
| | | EimsMaintOrder add = MapstructUtils.convert(bo, EimsMaintOrder.class); |
| | | //通过保养计划生成的数据需要更新保养计划 |
| | | Long planId = bo.getPlanId(); |
| | | if(planId!=null){ |
| | | EimsMaintPlan eimsMaintPlan = planMapper.selectById(planId); |
| | | setMaintNextTime(eimsMaintPlan); |
| | | planMapper.updateById(eimsMaintPlan); |
| | | } |
| | | |
| | | |
| | | |
| | | validEntityBeforeSave(add); |
| | | boolean flag = baseMapper.insert(add) > 0; |
| | | if (flag) { |
| | |
| | | |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 计算保养计划下次执行时间 |
| | | */ |
| | | @SneakyThrows |
| | | private void setMaintNextTime(EimsMaintPlan bo) { |
| | | Date oldNext = bo.getMaintNextTime(); |
| | | //TODO 下次保养时间计算规则 0-按固定周期 1-按上次保养时间 |
| | | Date newNext = null; |
| | | |
| | | //下次次执行时间为空抛出异常 |
| | | if (oldNext == null) { |
| | | throw new Exception("下次保养时间不能为空!"); |
| | | } |
| | | //周期 |
| | | Long maintCycle = bo.getMaintCycle(); |
| | | //单位 1-天 2-周 3-月 4-季 5-年 |
| | | String maintCycleUnit = bo.getMaintCycleUnit(); |
| | | switch (maintCycleUnit) { |
| | | case "1": |
| | | newNext = DateUtils.addDays(oldNext, maintCycle.intValue()); |
| | | break; |
| | | case "2": |
| | | newNext = DateUtils.addWeeks(oldNext, maintCycle.intValue()); |
| | | break; |
| | | case "3": |
| | | newNext = DateUtils.addMonths(oldNext, maintCycle.intValue()); |
| | | break; |
| | | case "4": |
| | | newNext = DateUtils.addMonths(oldNext, maintCycle.intValue() * 3); |
| | | break; |
| | | case "5": |
| | | newNext = DateUtils.addYears(oldNext, maintCycle.intValue()); |
| | | break; |
| | | |
| | | } |
| | | bo.setMaintNextTime(newNext); |
| | | if(bo.getMaintFirstTime()==null){ |
| | | bo.setMaintFirstTime(oldNext); |
| | | } |
| | | bo.setMaintLastTime(oldNext); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public Boolean updateByBo(EimsMaintOrderBo bo) { |
| | | EimsMaintOrder update = MapstructUtils.convert(bo, EimsMaintOrder.class); |
| | | if(bo.getStatus().equals(DictConstants.MAINT_ORDER_STATUS_DETAIL.BAOYANG) && bo.getStartTime() == null){ |
| | | update.setStartTime(new Date()); |
| | | } |
| | | |
| | | EimsMaintOrder old = baseMapper.selectById(bo.getId()); |
| | | if(bo.getStatus().equals(DictConstants.MAINT_ORDER_STATUS_DETAIL.DAIYANZHENG) && bo.getEndTime() == null){ |
| | | update.setEndTime(new Date()); |
| | | } |
| | | |
| | | if(bo.getStatus().equals(DictConstants.MAINT_ORDER_STATUS_DETAIL.WANCHENG) && bo.getVerifyUser() == null){ |
| | | LoginUser loginUser = LoginHelper.getLoginUser(); |
| | | update.setVerifyUser(loginUser.getUserId()); |
| | | } |
| | | |
| | | |
| | | validEntityBeforeSave(update); |
| | | return baseMapper.updateById(update) > 0; |