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.*; 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实现 * @author 江蹄蹄 * @date 2024/11/19 16:07 */ @Service public class YwPatrolLineServiceImpl implements YwPatrolLineService { @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 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(); } @Override public void deleteById(Integer id, LoginUserInfo user) { ywPatrolLineMapper.deleteById(id); } @Override public void delete(YwPatrolLine ywPatrolLine) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(ywPatrolLine); ywPatrolLineMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids, LoginUserInfo user) { if (CollectionUtils.isEmpty(ids)) { return; } ywPatrolLineMapper.deleteBatchIds(ids); } @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().lambda() .eq(YwLinePoint::getLineId,ywPatrolLine.getId())); //循环处理 子集数据 List 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 public void updateByIdInBatch(List ywPatrolLines) { if (CollectionUtils.isEmpty(ywPatrolLines)) { return; } for (YwPatrolLine ywPatrolLine: ywPatrolLines) { this.updateById(ywPatrolLine); } } @Override public YwPatrolLine findById(Integer id) { return ywPatrolLineMapper.selectById(id); } @Override public YwPatrolLine getDetail(Integer id) { YwPatrolLine ywPatrolLine = ywPatrolLineMapper.selectById(id); List ywLinePointList = ywLinePointMapper.selectJoinList(YwLinePoint.class,new MPJLambdaWrapper() .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 wrapper = new QueryWrapper<>(ywPatrolLine); return ywPatrolLineMapper.selectOne(wrapper); } @Override public List findList(YwPatrolLine ywPatrolLine) { QueryWrapper wrapper = new QueryWrapper<>(ywPatrolLine); return ywPatrolLineMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper(); Utils.MP.blankToNull(pageWrap.getModel()); 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 public long count(YwPatrolLine ywPatrolLine) { QueryWrapper wrapper = new QueryWrapper<>(ywPatrolLine); return ywPatrolLineMapper.selectCount(wrapper); } }