|
@@ -0,0 +1,136 @@
|
|
|
+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.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
|
|
|
+import com.ruoyi.common.core.page.PagePlus;
|
|
|
+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.bo.GRoadSectionInspectionBo;
|
|
|
+import com.ruoyi.gas.domain.bo.GRoadSectionInspectionPhotoBo;
|
|
|
+import com.ruoyi.gas.domain.vo.GRoadSectionInspectionVo;
|
|
|
+import com.ruoyi.gas.mapper.GRoadSectionInspectionMapper;
|
|
|
+import com.ruoyi.gas.service.IGRoadSectionInspectionPhotoService;
|
|
|
+import com.ruoyi.gas.service.IGRoadSectionInspectionService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 路段巡查Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2024-03-06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class GRoadSectionInspectionServiceImpl extends ServicePlusImpl<GRoadSectionInspectionMapper, GRoadSectionInspection, GRoadSectionInspectionVo> implements IGRoadSectionInspectionService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public GRoadSectionInspectionVo queryById(Long id) {
|
|
|
+ GRoadSectionInspectionVo voById = getVoById(id);
|
|
|
+ voById.setPhotoList(baseMapper.getPhoto(voById.getId()));
|
|
|
+ return voById;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<GRoadSectionInspectionVo> queryPageList(GRoadSectionInspectionBo bo) {
|
|
|
+ PagePlus<GRoadSectionInspection, GRoadSectionInspectionVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
|
|
|
+ TableDataInfo<GRoadSectionInspectionVo> tableDataInfo = PageUtils.buildDataInfo(result);
|
|
|
+ tableDataInfo.getRows().forEach(item -> item.setPhotoList(baseMapper.getPhoto(item.getId())));
|
|
|
+ return tableDataInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GRoadSectionInspectionVo> queryList(GRoadSectionInspectionBo bo) {
|
|
|
+ return listVo(buildQueryWrapper(bo));
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<GRoadSectionInspection> buildQueryWrapper(GRoadSectionInspectionBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<GRoadSectionInspection> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getSectionName()), GRoadSectionInspection::getSectionName, bo.getSectionName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getSamplingMeterCount()), GRoadSectionInspection::getSamplingMeterCount, bo.getSamplingMeterCount());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getFindProblem()), GRoadSectionInspection::getFindProblem, bo.getFindProblem());
|
|
|
+ lqw.eq(bo.getFindTime() != null, GRoadSectionInspection::getFindTime, bo.getFindTime());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IGRoadSectionInspectionPhotoService service;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(GRoadSectionInspectionBo bo) {
|
|
|
+ GRoadSectionInspection add = BeanUtil.toBean(bo, GRoadSectionInspection.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++) {
|
|
|
+ GRoadSectionInspectionPhotoBo photo = new GRoadSectionInspectionPhotoBo();
|
|
|
+ photo.setParentId(bo.getId());
|
|
|
+ photo.setPicUrl(bo.getPhotoList().get(i));
|
|
|
+ service.insertByBo(photo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(GRoadSectionInspectionBo bo) {
|
|
|
+ GRoadSectionInspection update = BeanUtil.toBean(bo, GRoadSectionInspection.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))) {
|
|
|
+ //添加照片
|
|
|
+ GRoadSectionInspectionPhotoBo photo = new GRoadSectionInspectionPhotoBo();
|
|
|
+ photo.setParentId(bo.getId());
|
|
|
+ photo.setPicUrl(inslist.get(i));
|
|
|
+ service.insertByBo(photo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(GRoadSectionInspection entity) {
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if (isValid) {
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return removeByIds(ids);
|
|
|
+ }
|
|
|
+}
|