jiangping
2025-06-06 a2299a6d4a6f99e9c11132138f5d3e9ec68f03ea
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwPatrolLineServiceImpl.java
@@ -1,21 +1,30 @@
package com.doumee.service.business.impl;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.YwLinePointMapper;
import com.doumee.dao.business.YwPatrolLineMapper;
import com.doumee.dao.business.model.YwPatrolLine;
import com.doumee.dao.business.YwPatrolSchemeMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.YwPatrolLineService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 运维巡检路线信息表Service实现
@@ -28,14 +37,57 @@
    @Autowired
    private YwPatrolLineMapper ywPatrolLineMapper;
    @Autowired
    private YwLinePointMapper ywLinePointMapper;
    @Autowired
    private YwPatrolSchemeMapper ywPatrolSchemeMapper;
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public Integer create(YwPatrolLine ywPatrolLine) {
        if(Objects.isNull(ywPatrolLine)
        || StringUtils.isBlank(ywPatrolLine.getName())
        || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
        ywPatrolLine.setCreateDate(new Date());
        ywPatrolLine.setCreator(loginUserInfo.getId());
        ywPatrolLine.setIsdeleted(Constants.ZERO);
        ywPatrolLine.setStatus(Constants.ZERO);
        ywPatrolLineMapper.insert(ywPatrolLine);
        //循环处理 子集数据
        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
        //是否存在相同数据
        Set<Integer> setIds = new HashSet<Integer>(ywLinePointList.stream().map(i->i.getPointId()).collect(Collectors.toList()));
        if(setIds.size()!=ywLinePointList.size()){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在相同巡检点!");
        }
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
            || Objects.isNull(ywLinePoint.getPointId())
            || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setId(null);
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
            ywLinePoint.setLineId(ywPatrolLine.getId());
        }
        ywLinePointMapper.insert(ywLinePointList);
        return ywPatrolLine.getId();
    }
    @Override
    public void deleteById(Integer id, LoginUserInfo user) {
        //查询是否存在巡检计划
        if(ywPatrolSchemeMapper.selectCount(new QueryWrapper<YwPatrolScheme>().lambda().eq(YwPatrolScheme::getIsdeleted, Constants.ZERO)
                .eq(YwPatrolScheme::getLineId,id))>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前巡检线路已被使用,无法删除");
        };
        ywPatrolLineMapper.deleteById(id);
    }
@@ -54,9 +106,52 @@
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void updateById(YwPatrolLine ywPatrolLine) {
        if(Objects.isNull(ywPatrolLine)
                || StringUtils.isBlank(ywPatrolLine.getName())
                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywPatrolLine.getLinePointList())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = ywPatrolLine.getLoginUserInfo();
        ywPatrolLine.setEditDate(new Date());
        ywPatrolLine.setEditor(loginUserInfo.getId());
        ywPatrolLineMapper.updateById(ywPatrolLine);
        //删除子数据
        ywLinePointMapper.delete(new QueryWrapper<YwLinePoint>().lambda()
                .eq(YwLinePoint::getLineId,ywPatrolLine.getId()));
        //循环处理 子集数据
        List<YwLinePoint> ywLinePointList = ywPatrolLine.getLinePointList();
        //是否存在相同数据
        Set<Integer> setIds = new HashSet<Integer>(ywLinePointList.stream().map(i->i.getPointId()).collect(Collectors.toList()));
        if(setIds.size()!=ywLinePointList.size()){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在相同巡检点!");
        }
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
                    || Objects.isNull(ywLinePoint.getPointId())
                    || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setId(null);
            ywLinePoint.setLineId(ywPatrolLine.getId());
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
        }
        ywLinePointMapper.insert(ywLinePointList);
    }
    @Override
    public void updateStatusById(YwPatrolLine ywPatrolLine) {
        YwPatrolLine model = new YwPatrolLine();
        model.setId(ywPatrolLine.getId());
        model.setStatus(ywPatrolLine.getStatus());
        ywPatrolLineMapper.updateById(model);
    }
    @Override
    public void updateByIdInBatch(List<YwPatrolLine> ywPatrolLines) {
@@ -73,6 +168,26 @@
        return ywPatrolLineMapper.selectById(id);
    }
    @Override
    public YwPatrolLine getDetail(Integer id) {
        YwPatrolLine ywPatrolLine =  ywPatrolLineMapper.selectById(id);
        List<YwLinePoint> ywLinePointList = ywLinePointMapper.selectJoinList(YwLinePoint.class,new MPJLambdaWrapper<YwLinePoint>()
                .selectAll(YwLinePoint.class)
                .selectAs(YwPatrolPoint::getName,YwLinePoint::getPointName)
                .selectAs(YwPatrolPoint::getCode,YwLinePoint::getCode)
                .leftJoin(YwPatrolPoint.class,YwPatrolPoint::getId,YwLinePoint::getPointId)
                .eq(YwLinePoint::getLineId,id)
                .orderByAsc(YwLinePoint::getSortnum)
        );
        ywPatrolLine.setLinePointList(ywLinePointList);
        return ywPatrolLine;
    }
    @Override
    public YwPatrolLine findOne(YwPatrolLine ywPatrolLine) {
        QueryWrapper<YwPatrolLine> wrapper = new QueryWrapper<>(ywPatrolLine);
@@ -88,51 +203,17 @@
    @Override
    public PageData<YwPatrolLine> findPage(PageWrap<YwPatrolLine> pageWrap) {
        IPage<YwPatrolLine> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<YwPatrolLine> queryWrapper = new QueryWrapper<>();
        MPJLambdaWrapper<YwPatrolLine> queryWrapper = new MPJLambdaWrapper<YwPatrolLine>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(YwPatrolLine::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(YwPatrolLine::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(YwPatrolLine::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(YwPatrolLine::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getImgurl() != null) {
            queryWrapper.lambda().eq(YwPatrolLine::getImgurl, pageWrap.getModel().getImgurl());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(ywPatrolLineMapper.selectPage(page, queryWrapper));
        YwPatrolLine model = pageWrap.getModel();
        queryWrapper.selectAll(YwPatrolLine.class)
                .select(" ( select count(1) from  yw_line_point y where y.LINE_ID = t.id ) as lineAmount ")
                .like(Objects.nonNull(model)&&StringUtils.isNotBlank(model.getName()),YwPatrolLine::getName,model.getName())
                .eq(YwPatrolLine::getIsdeleted,Constants.ZERO)
                .orderByDesc(YwPatrolLine::getCreateDate)
        ;
        IPage iPage = ywPatrolLineMapper.selectJoinPage(page,YwPatrolLine.class,queryWrapper);
        return PageData.from(iPage);
    }
    @Override