GValveWellInspectionServiceImpl.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package com.ruoyi.gas.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
  7. import com.ruoyi.common.core.page.TableDataInfo;
  8. import com.ruoyi.common.utils.PageUtils;
  9. import com.ruoyi.common.utils.StringUtils;
  10. import com.ruoyi.gas.domain.GRoadSectionInspection;
  11. import com.ruoyi.gas.domain.GValveWellInspection;
  12. import com.ruoyi.gas.domain.bo.BatchReviewBo;
  13. import com.ruoyi.gas.domain.bo.GValveWellInspectionBo;
  14. import com.ruoyi.gas.domain.bo.GValveWellInspectionPhotoBo;
  15. import com.ruoyi.gas.domain.vo.GValveWellInspectionVo;
  16. import com.ruoyi.gas.domain.vo.GValveWellInspectionVos;
  17. import com.ruoyi.gas.mapper.GValveWellInspectionMapper;
  18. import com.ruoyi.gas.mapper.GValveWellPositionMapper;
  19. import com.ruoyi.gas.service.IGValveWellInspectionPhotoService;
  20. import com.ruoyi.gas.service.IGValveWellInspectionService;
  21. import lombok.RequiredArgsConstructor;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import java.util.ArrayList;
  25. import java.util.Collection;
  26. import java.util.List;
  27. import java.util.Map;
  28. import java.util.stream.Collectors;
  29. /**
  30. * 阀井巡查Service业务层处理
  31. *
  32. * @author ruoyi
  33. * @date 2024-03-18
  34. */
  35. @Service
  36. @RequiredArgsConstructor
  37. public class GValveWellInspectionServiceImpl extends ServicePlusImpl<GValveWellInspectionMapper, GValveWellInspection, GValveWellInspectionVo> implements IGValveWellInspectionService {
  38. private final GValveWellPositionMapper positionMapper;
  39. @Override
  40. public Boolean batchReview(BatchReviewBo bo) {
  41. Collection<GValveWellInspection> boxList = new ArrayList<>();
  42. bo.getUids().forEach(item -> {
  43. GValveWellInspection gValveWellInspection = new GValveWellInspection();
  44. gValveWellInspection.setId(item);
  45. gValveWellInspection.setProcessStatus(bo.getProcessStatus());
  46. gValveWellInspection.setProcessComments(bo.getRemarks());
  47. boxList.add(gValveWellInspection);
  48. });
  49. return updateBatchById(boxList);
  50. }
  51. @Override
  52. public GValveWellInspectionVo queryById(Long id){
  53. GValveWellInspectionVo voById = getVoById(id);
  54. voById.setPhotoList(baseMapper.getPhoto(voById.getId()));
  55. voById.setPosition(positionMapper.selectById(voById.getPositionId()));
  56. return voById;
  57. }
  58. @Override
  59. public TableDataInfo<GValveWellInspectionVos> queryPageList(GValveWellInspectionBo bo) {
  60. Page<GValveWellInspectionVos> page = new Page<>(bo.getPageNum(), bo.getPageSize());
  61. Page<GValveWellInspectionVos> list = baseMapper.getList(bo, page);
  62. list.getRecords().forEach(item -> item.setPhotoList(baseMapper.getPhoto(item.getId())));
  63. return PageUtils.buildDataInfo(list);
  64. }
  65. @Override
  66. public List<GValveWellInspectionVo> queryList(GValveWellInspectionBo bo) {
  67. return listVo(buildQueryWrapper(bo));
  68. }
  69. private LambdaQueryWrapper<GValveWellInspection> buildQueryWrapper(GValveWellInspectionBo bo) {
  70. Map<String, Object> params = bo.getParams();
  71. LambdaQueryWrapper<GValveWellInspection> lqw = Wrappers.lambdaQuery();
  72. lqw.orderByDesc(GValveWellInspection::getCreateTime);
  73. lqw.eq(bo.getPositionId() != null, GValveWellInspection::getPositionId, bo.getPositionId());
  74. lqw.eq(bo.getValveWellName() != null, GValveWellInspection::getPositionId, bo.getValveWellName());
  75. lqw.eq(StringUtils.isNotBlank(bo.getDiscoverProblems()), GValveWellInspection::getDiscoverProblems, bo.getDiscoverProblems());
  76. lqw.eq(bo.getDiscoverTime() != null, GValveWellInspection::getDiscoverTime, bo.getDiscoverTime());
  77. return lqw;
  78. }
  79. @Autowired
  80. private IGValveWellInspectionPhotoService service;
  81. @Override
  82. public Boolean insertByBo(GValveWellInspectionBo bo) {
  83. GValveWellInspection add = BeanUtil.toBean(bo, GValveWellInspection.class);
  84. validEntityBeforeSave(add);
  85. boolean flag = save(add);
  86. if (flag) {
  87. bo.setId(add.getId());
  88. //添加照片
  89. List<String> piclist = bo.getPhotoList();
  90. if (piclist != null) {
  91. for (int i = 0; i < bo.getPhotoList().size(); i++) {
  92. GValveWellInspectionPhotoBo photo = new GValveWellInspectionPhotoBo();
  93. photo.setParentId(bo.getId());
  94. photo.setPicUrl(bo.getPhotoList().get(i));
  95. service.insertByBo(photo);
  96. }
  97. }
  98. }
  99. return flag;
  100. }
  101. @Override
  102. public Boolean updateByBo(GValveWellInspectionBo bo) {
  103. GValveWellInspection update = BeanUtil.toBean(bo, GValveWellInspection.class);
  104. validEntityBeforeSave(update);
  105. List<String> piclist = bo.getPhotoList();
  106. if (piclist != null) {
  107. //原有的照片
  108. List<String> photolist = baseMapper.getPhoto(bo.getId());
  109. //原有的照片不在新传的照片里
  110. List<String> dellist = photolist.stream().filter(i -> !piclist.contains(i)).collect(Collectors.toList());
  111. //删除照片
  112. if (dellist.size() > 0) {
  113. service.deleteByUrl(bo.getId(), dellist);
  114. }
  115. //新传的照片不在原有的照片里
  116. List<String> inslist = piclist.stream().filter(i -> !photolist.contains(i)).collect(Collectors.toList());
  117. if (inslist.size() > 0) {
  118. for (int i = 0; i < inslist.size(); i++) {
  119. if (StringUtils.isNotEmpty(inslist.get(i))) {
  120. //添加照片
  121. GValveWellInspectionPhotoBo photo = new GValveWellInspectionPhotoBo();
  122. photo.setParentId(bo.getId());
  123. photo.setPicUrl(inslist.get(i));
  124. service.insertByBo(photo);
  125. }
  126. }
  127. }
  128. }
  129. return updateById(update);
  130. }
  131. /**
  132. * 保存前的数据校验
  133. *
  134. * @param entity 实体类数据
  135. */
  136. private void validEntityBeforeSave(GValveWellInspection entity){
  137. //TODO 做一些数据校验,如唯一约束
  138. }
  139. @Override
  140. public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
  141. if(isValid){
  142. //TODO 做一些业务上的校验,判断是否需要校验
  143. }
  144. return removeByIds(ids);
  145. }
  146. }