123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package com.ruoyi.gas.service.impl;
- import cn.hutool.core.bean.BeanUtil;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.toolkit.Wrappers;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
- import com.ruoyi.common.core.page.TableDataInfo;
- import com.ruoyi.common.utils.PageUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.gas.domain.GRoadSectionInspection;
- import com.ruoyi.gas.domain.GValveWellInspection;
- import com.ruoyi.gas.domain.bo.BatchReviewBo;
- import com.ruoyi.gas.domain.bo.GValveWellInspectionBo;
- import com.ruoyi.gas.domain.bo.GValveWellInspectionPhotoBo;
- import com.ruoyi.gas.domain.vo.GValveWellInspectionVo;
- import com.ruoyi.gas.domain.vo.GValveWellInspectionVos;
- import com.ruoyi.gas.mapper.GValveWellInspectionMapper;
- import com.ruoyi.gas.mapper.GValveWellPositionMapper;
- import com.ruoyi.gas.service.IGValveWellInspectionPhotoService;
- import com.ruoyi.gas.service.IGValveWellInspectionService;
- import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- /**
- * 阀井巡查Service业务层处理
- *
- * @author ruoyi
- * @date 2024-03-18
- */
- @Service
- @RequiredArgsConstructor
- public class GValveWellInspectionServiceImpl extends ServicePlusImpl<GValveWellInspectionMapper, GValveWellInspection, GValveWellInspectionVo> implements IGValveWellInspectionService {
- private final GValveWellPositionMapper positionMapper;
- @Override
- public Boolean batchReview(BatchReviewBo bo) {
- Collection<GValveWellInspection> boxList = new ArrayList<>();
- bo.getUids().forEach(item -> {
- GValveWellInspection gValveWellInspection = new GValveWellInspection();
- gValveWellInspection.setId(item);
- gValveWellInspection.setProcessStatus(bo.getProcessStatus());
- gValveWellInspection.setProcessComments(bo.getRemarks());
- boxList.add(gValveWellInspection);
- });
- return updateBatchById(boxList);
- }
- @Override
- public GValveWellInspectionVo queryById(Long id){
- GValveWellInspectionVo voById = getVoById(id);
- voById.setPhotoList(baseMapper.getPhoto(voById.getId()));
- voById.setPosition(positionMapper.selectById(voById.getPositionId()));
- return voById;
- }
- @Override
- public TableDataInfo<GValveWellInspectionVos> queryPageList(GValveWellInspectionBo bo) {
- Page<GValveWellInspectionVos> page = new Page<>(bo.getPageNum(), bo.getPageSize());
- Page<GValveWellInspectionVos> list = baseMapper.getList(bo, page);
- list.getRecords().forEach(item -> item.setPhotoList(baseMapper.getPhoto(item.getId())));
- return PageUtils.buildDataInfo(list);
- }
- @Override
- public List<GValveWellInspectionVo> queryList(GValveWellInspectionBo bo) {
- return listVo(buildQueryWrapper(bo));
- }
- private LambdaQueryWrapper<GValveWellInspection> buildQueryWrapper(GValveWellInspectionBo bo) {
- Map<String, Object> params = bo.getParams();
- LambdaQueryWrapper<GValveWellInspection> lqw = Wrappers.lambdaQuery();
- lqw.orderByDesc(GValveWellInspection::getCreateTime);
- lqw.eq(bo.getPositionId() != null, GValveWellInspection::getPositionId, bo.getPositionId());
- lqw.eq(bo.getValveWellName() != null, GValveWellInspection::getPositionId, bo.getValveWellName());
- lqw.eq(StringUtils.isNotBlank(bo.getDiscoverProblems()), GValveWellInspection::getDiscoverProblems, bo.getDiscoverProblems());
- lqw.eq(bo.getDiscoverTime() != null, GValveWellInspection::getDiscoverTime, bo.getDiscoverTime());
- return lqw;
- }
- @Autowired
- private IGValveWellInspectionPhotoService service;
- @Override
- public Boolean insertByBo(GValveWellInspectionBo bo) {
- GValveWellInspection add = BeanUtil.toBean(bo, GValveWellInspection.class);
- validEntityBeforeSave(add);
- boolean flag = save(add);
- if (flag) {
- bo.setId(add.getId());
- //添加照片
- List<String> piclist = bo.getPhotoList();
- if (piclist != null) {
- for (int i = 0; i < bo.getPhotoList().size(); i++) {
- GValveWellInspectionPhotoBo photo = new GValveWellInspectionPhotoBo();
- photo.setParentId(bo.getId());
- photo.setPicUrl(bo.getPhotoList().get(i));
- service.insertByBo(photo);
- }
- }
- }
- return flag;
- }
- @Override
- public Boolean updateByBo(GValveWellInspectionBo bo) {
- GValveWellInspection update = BeanUtil.toBean(bo, GValveWellInspection.class);
- validEntityBeforeSave(update);
- List<String> piclist = bo.getPhotoList();
- if (piclist != null) {
- //原有的照片
- List<String> photolist = baseMapper.getPhoto(bo.getId());
- //原有的照片不在新传的照片里
- List<String> dellist = photolist.stream().filter(i -> !piclist.contains(i)).collect(Collectors.toList());
- //删除照片
- if (dellist.size() > 0) {
- service.deleteByUrl(bo.getId(), dellist);
- }
- //新传的照片不在原有的照片里
- List<String> inslist = piclist.stream().filter(i -> !photolist.contains(i)).collect(Collectors.toList());
- if (inslist.size() > 0) {
- for (int i = 0; i < inslist.size(); i++) {
- if (StringUtils.isNotEmpty(inslist.get(i))) {
- //添加照片
- GValveWellInspectionPhotoBo photo = new GValveWellInspectionPhotoBo();
- photo.setParentId(bo.getId());
- photo.setPicUrl(inslist.get(i));
- service.insertByBo(photo);
- }
- }
- }
- }
- return updateById(update);
- }
- /**
- * 保存前的数据校验
- *
- * @param entity 实体类数据
- */
- private void validEntityBeforeSave(GValveWellInspection entity){
- //TODO 做一些数据校验,如唯一约束
- }
- @Override
- public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
- if(isValid){
- //TODO 做一些业务上的校验,判断是否需要校验
- }
- return removeByIds(ids);
- }
- }
|