jiangping
2024-11-26 f1864f6d2d85b49fc901b22e9f6759a5d0fb360b
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.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.Date;
import java.util.List;
import java.util.Objects;
/**
 * 运维巡检路线信息表Service实现
@@ -28,9 +37,40 @@
    @Autowired
    private YwPatrolLineMapper ywPatrolLineMapper;
    @Autowired
    private YwLinePointMapper ywLinePointMapper;
    @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();
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
            || Objects.isNull(ywLinePoint.getPointId())
            || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
            ywLinePoint.setLineId(ywLinePoint.getId());
        }
        ywLinePointMapper.insert(ywLinePointList);
        return ywPatrolLine.getId();
    }
@@ -55,7 +95,34 @@
    @Override
    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();
        for (YwLinePoint ywLinePoint:ywLinePointList) {
            if(Objects.isNull(ywLinePoint)
                    || Objects.isNull(ywLinePoint.getPointId())
                    || Objects.isNull(ywLinePoint.getNeedScancode())
            ){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"巡检点配置错误");
            }
            ywLinePoint.setLineId(ywLinePoint.getId());
            ywLinePoint.setCreateDate(new Date());
            ywLinePoint.setCreator(loginUserInfo.getId());
            ywLinePoint.setIsdeleted(Constants.ZERO);
        }
        ywLinePointMapper.insert(ywLinePointList);
    }
    @Override
@@ -73,6 +140,25 @@
        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)
                .leftJoin(YwPatrolLine.class,YwPatrolLine::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 +174,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