|  |  |  | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.YwLinePointMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.YwPatrolLineMapper; | 
|---|
|  |  |  | 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 org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Objects; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 运维巡检路线信息表Service实现 | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwLinePointMapper ywLinePointMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwPatrolSchemeMapper ywPatrolSchemeMapper; | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public Integer create(YwPatrolLine ywPatrolLine) { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()) | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public void updateById(YwPatrolLine ywPatrolLine) { | 
|---|
|  |  |  | if(Objects.isNull(ywPatrolLine) | 
|---|
|  |  |  | || StringUtils.isBlank(ywPatrolLine.getName()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .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()) | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(ywPatrolLines)) { | 
|---|
|  |  |  | return; | 
|---|