| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.dromara.common.core.constant.DictConstants; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.eims.domain.EimsEqu; |
| | | import org.dromara.eims.domain.EimsInspectRecord; |
| | | import org.dromara.eims.domain.vo.EimsInspectRecordVo; |
| | | import org.dromara.eims.mapper.EimsEquMapper; |
| | | import org.dromara.eims.mapper.EimsInspectRecordMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.dromara.eims.domain.bo.EimsInspectStBo; |
| | |
| | | import org.dromara.eims.service.IEimsInspectStService; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | |
| | | public class EimsInspectStServiceImpl implements IEimsInspectStService { |
| | | |
| | | private final EimsInspectStMapper baseMapper; |
| | | private final EimsEquMapper equMapper; |
| | | private final EimsInspectRecordMapper recordMapper; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public EimsInspectStVo queryById(Long id){ |
| | | return baseMapper.selectVoById(id); |
| | | EimsInspectStVo stVo = baseMapper.selectVoById(id); |
| | | if(stVo!=null&&stVo.getEquId()!=null){ |
| | | EimsEqu eimsEqu = equMapper.selectById(stVo.getEquId()); |
| | | stVo.setEquName(eimsEqu.getEquName()); |
| | | stVo.setAssetNo(eimsEqu.getAssetNo()); |
| | | } |
| | | // fillStDataSingle(stVo); |
| | | return stVo; |
| | | } |
| | | |
| | | @Override |
| | | public EimsInspectStVo queryByStId(String stId) { |
| | | QueryWrapper<EimsInspectSt> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("st_id", stId); |
| | | EimsInspectStVo stVo = baseMapper.selectVoOne(queryWrapper); |
| | | if(stVo!=null&&stVo.getEquId()!=null){ |
| | | EimsEqu eimsEqu = equMapper.selectById(stVo.getEquId()); |
| | | stVo.setEquName(eimsEqu.getEquName()); |
| | | stVo.setAssetNo(eimsEqu.getAssetNo()); |
| | | } |
| | | // fillStDataSingle(stVo); |
| | | return stVo; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @param stVo type Day-日视图 Month-月视图 |
| | | * @param |
| | | */ |
| | | private void fillStDataSingle(EimsInspectStVo stVo) { |
| | | |
| | | LambdaQueryWrapper<EimsInspectRecord> recordLqw = Wrappers.lambdaQuery(); |
| | | recordLqw.eq(EimsInspectRecord::getEquId, stVo.getEquId()); |
| | | LocalDate planTime = stVo.getPlanTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | // 月视图查询范围 |
| | | LocalDate startOfMonth = planTime.with(TemporalAdjusters.firstDayOfMonth()); |
| | | LocalDate endOfMonth = planTime.with(TemporalAdjusters.lastDayOfMonth()); |
| | | |
| | | // 日视图查询范围 |
| | | if(stVo.getType().equals("Day")){ |
| | | recordLqw.between(EimsInspectRecord::getPlanTime, planTime, planTime); |
| | | }else { |
| | | // 月视图查询范围 |
| | | recordLqw.between(EimsInspectRecord::getPlanTime, startOfMonth, endOfMonth); |
| | | } |
| | | |
| | | |
| | | // 执行查询 |
| | | List<EimsInspectRecordVo> recordList = recordMapper.selectVoList(recordLqw); |
| | | // TODO 根据字典eims_inspect_status |
| | | Map<String, Long> cMap = recordList.stream() |
| | | .filter(order -> List.of("0", "1").contains(order.getStatus())) |
| | | .collect(Collectors.groupingBy(EimsInspectRecordVo::getStatus, Collectors.counting())); |
| | | // TODO 根据字典eims_inspect_result |
| | | Map<String, Long> rMap = recordList.stream() |
| | | .filter(order ->order.getInspResult()!=null && List.of("1", "2").contains(order.getInspResult())) |
| | | .collect(Collectors.groupingBy(EimsInspectRecordVo::getInspResult, Collectors.counting())); |
| | | |
| | | stVo.setRecordCount(recordList.size()); |
| | | stVo.setUnCheckCount(cMap.getOrDefault("0", 0L).intValue()); |
| | | stVo.setCheckCount(cMap.getOrDefault("1", 0L).intValue()); |
| | | |
| | | stVo.setNormalNum(rMap.getOrDefault("1", 0L).intValue()); |
| | | stVo.setAbNormalNum(rMap.getOrDefault("2", 0L).intValue()); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public TableDataInfo<EimsInspectStVo> queryPageList(EimsInspectStBo bo, PageQuery pageQuery) { |
| | | // 月视图 |
| | | if(bo.getViewMode().equals("Month")){ |
| | | bo.setType(bo.getViewMode()); |
| | | QueryWrapper<EimsInspectSt> qw = buildWrapper(bo); |
| | | Page<EimsInspectStVo> result = baseMapper.selectInspStList(pageQuery.build(), qw); |
| | | // 填充数据 |
| | | fillStData(result); |
| | | fillStData(result,bo.getViewMode()); |
| | | return TableDataInfo.build(result); |
| | | // 日视图 |
| | | }else if(bo.getViewMode().equals("Day")){ |
| | | Page<EimsInspectStVo> result = recordMapper.selectInspRecordDayList(pageQuery.build(), buildGroupWrapper(bo)); |
| | | return TableDataInfo.build(result); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | private void fillStData(Page<EimsInspectStVo> result) { |
| | | /** |
| | | * |
| | | * @param result |
| | | * @param type Day-日视图 Month-月视图 |
| | | */ |
| | | private void fillStData(Page<EimsInspectStVo> result,String type) { |
| | | List<EimsInspectStVo> records = result.getRecords(); |
| | | for (int i = 0; i < records.size(); i++) { |
| | | EimsInspectStVo stVo = records.get(i); |
| | |
| | | LambdaQueryWrapper<EimsInspectRecord> recordLqw = Wrappers.lambdaQuery(); |
| | | recordLqw.eq(EimsInspectRecord::getEquId, stVo.getEquId()); |
| | | LocalDate planTime = stVo.getPlanTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | // 月视图查询范围 |
| | | LocalDate startOfMonth = planTime.with(TemporalAdjusters.firstDayOfMonth()); |
| | | LocalDate endOfMonth = planTime.with(TemporalAdjusters.lastDayOfMonth()); |
| | | recordLqw.between(EimsInspectRecord::getPlanTime, startOfMonth, endOfMonth); |
| | | |
| | | // 日视图查询范围 |
| | | if(type.equals("Day")){ |
| | | recordLqw.between(EimsInspectRecord::getPlanTime, planTime, planTime); |
| | | }else { |
| | | // 月视图查询范围 |
| | | recordLqw.between(EimsInspectRecord::getPlanTime, startOfMonth, endOfMonth); |
| | | } |
| | | |
| | | |
| | | // 执行查询 |
| | | List<EimsInspectRecordVo> recordList = recordMapper.selectVoList(recordLqw); |
| | | // TODO 根据字典eims_inspect_status |
| | |
| | | // TODO 根据字典eims_inspect_result |
| | | Map<String, Long> rMap = recordList.stream() |
| | | .filter(order ->order.getInspResult()!=null && List.of("1", "2").contains(order.getInspResult())) |
| | | .collect(Collectors.groupingBy(EimsInspectRecordVo::getStatus, Collectors.counting())); |
| | | .collect(Collectors.groupingBy(EimsInspectRecordVo::getInspResult, Collectors.counting())); |
| | | |
| | | stVo.setRecordCount(recordList.size()); |
| | | stVo.setUnCheckCount(cMap.getOrDefault("0", 0L).intValue()); |
| | |
| | | qw.like(StringUtils.isNotBlank(bo.getTitle()), "st.title", bo.getTitle()); |
| | | qw.like(StringUtils.isNotBlank(bo.getEquName()), "equ.equ_name", bo.getEquName()); |
| | | qw.like(StringUtils.isNotBlank(bo.getAssetNo()), "equ.asset_no", bo.getAssetNo()); |
| | | if(bo.getPlanTime()!=null&&bo.getViewMode() != null && bo.getViewMode().equals("Day")){ |
| | | qw.eq("DATE_FORMAT(st.plan_time, '%Y-%m-%d')", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,bo.getPlanTime())); |
| | | }else if(bo.getPlanTime()!=null&&bo.getViewMode() != null && bo.getViewMode().equals("Month")){ |
| | | qw.eq("DATE_FORMAT(st.plan_time, '%Y-%m')", DateUtils.parseDateToStr(DateUtils.YYYY_MM,bo.getPlanTime())); |
| | | } |
| | | qw.eq( "st.type", bo.getType()); |
| | | qw.between(params.get("beginPlanTime") != null && params.get("endPlanTime") != null, |
| | | "st.plan_time", params.get("beginPlanTime"), params.get("endPlanTime")); |
| | | if (params.get("searchValue") != null && StringUtils.isNotBlank(params.get("searchValue").toString())) { |
| | | qw.and(wq -> wq.like("st.title", params.get("searchValue")) |
| | | .or().like("equ.equ_name", params.get("searchValue")) |
| | | .or().like("equ.asset_no", params.get("searchValue")) |
| | | ); |
| | | } |
| | | qw.eq(bo.getInspUser() != null, "st.maint_user", bo.getInspUser()); |
| | | qw.eq(bo.getVerifyUser() != null, "st.verify_user", bo.getVerifyUser()); |
| | | qw.eq(bo.getStatus() != null, "st.status", bo.getStatus()); |
| | | qw.eq(bo.getUpdateBy() != null, "st.update_by", bo.getUpdateBy()); |
| | | qw.orderByDesc( "st.create_time"); |
| | | return qw; |
| | | } |
| | |
| | | public Boolean updateByBo(EimsInspectStBo bo) { |
| | | EimsInspectSt update = MapstructUtils.convert(bo, EimsInspectSt.class); |
| | | |
| | | if(bo.getVerifyUser()!=null){ |
| | | EimsInspectSt st = baseMapper.selectById(bo.getId()); |
| | | String status = st.getStatus(); |
| | | if(status==null || status.equals(DictConstants.MAINT_ORDER_ST_STATUS_DETAIL.N)){ |
| | | if(update.getVerifyTime()==null) update.setStatus(DictConstants.MAINT_ORDER_ST_STATUS_DETAIL.Y); |
| | | if(update.getVerifyTime()==null) update.setVerifyTime(new Date()); |
| | | } |
| | | } |
| | | // if(bo.getVerifyUser()!=null){ |
| | | // EimsInspectSt st = baseMapper.selectById(bo.getId()); |
| | | // String status = st.getStatus(); |
| | | // if(status==null || status.equals(DictConstants.MAINT_ORDER_ST_STATUS_DETAIL.N)){ |
| | | // if(update.getVerifyTime()==null) update.setStatus(DictConstants.MAINT_ORDER_ST_STATUS_DETAIL.Y); |
| | | // if(update.getVerifyTime()==null) update.setVerifyTime(new Date()); |
| | | // } |
| | | // } |
| | | validEntityBeforeSave(update); |
| | | return baseMapper.updateById(update) > 0; |
| | | } |