|
@@ -1,12 +1,20 @@
|
|
|
package com.slibra.business.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.slibra.business.domain.TCutOffWaterExtra;
|
|
|
+import com.slibra.business.domain.TNeighborhood;
|
|
|
+import com.slibra.business.domain.TPumpingStation;
|
|
|
+import com.slibra.business.mapper.*;
|
|
|
+import com.slibra.business.res.CutOffExtraRes;
|
|
|
import com.slibra.common.utils.DateUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.slibra.business.mapper.TCutOffWaterMapper;
|
|
|
import com.slibra.business.domain.TCutOffWater;
|
|
|
import com.slibra.business.service.ITCutOffWaterService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
@@ -21,6 +29,18 @@ public class TCutOffWaterServiceImpl implements ITCutOffWaterService
|
|
|
@Autowired
|
|
|
private TCutOffWaterMapper tCutOffWaterMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TNeighborhoodMapper tNeighborhoodMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TPumpingStationMapper tPumpingStationMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TPumpingStationNeighbourhoodNumberMapper tPumpingStationNeighbourhoodNumberMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TCutOffWaterExtraMapper tCutOffWaterExtraMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询停水信息
|
|
|
*
|
|
@@ -44,11 +64,54 @@ public class TCutOffWaterServiceImpl implements ITCutOffWaterService
|
|
|
{
|
|
|
List<TCutOffWater> tCutOffWaters = tCutOffWaterMapper.selectTCutOffWaterList(tCutOffWater);
|
|
|
if(!CollectionUtils.isEmpty(tCutOffWaters)){
|
|
|
- //额外返回 停水范围(小区)和 停水状态字段
|
|
|
+ for (TCutOffWater cutOffWater : tCutOffWaters) {
|
|
|
+ //额外返回 停水范围(小区)和 停水状态字段
|
|
|
+ this.addExtra(cutOffWater);
|
|
|
+ }
|
|
|
}
|
|
|
return tCutOffWaters;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 额外返回 泵站-小区列表 停水范围(小区)和 停水状态字段
|
|
|
+ * @param tCutOffWater
|
|
|
+ */
|
|
|
+ private void addExtra(TCutOffWater tCutOffWater) {
|
|
|
+ Long id = tCutOffWater.getId();
|
|
|
+ // 停水状态
|
|
|
+ Date nowDate = DateUtils.getNowDate();
|
|
|
+ Date timeBegin = tCutOffWater.getTimeBegin();
|
|
|
+ Date timeEnd = tCutOffWater.getTimeEnd();
|
|
|
+ if(nowDate.after(timeEnd))
|
|
|
+ tCutOffWater.setStatus(3);
|
|
|
+ if(nowDate.before(timeBegin))
|
|
|
+ tCutOffWater.setStatus(1);
|
|
|
+ if(nowDate.after(timeBegin) && nowDate.before(timeEnd))
|
|
|
+ tCutOffWater.setStatus(2);
|
|
|
+ //停水的所有的小区的名字
|
|
|
+ tCutOffWater.setNeighbourhoodName(this.tCutOffWaterMapper.getDistinctNamesUnionById(id));
|
|
|
+ //泵站-小区列表
|
|
|
+ //获取配置的关联表
|
|
|
+ List<CutOffExtraRes> extraResList = new ArrayList<>();
|
|
|
+ List<TCutOffWaterExtra> tCutOffWaterExtras = this.tCutOffWaterExtraMapper.selectTCutOffWaterExtraList(TCutOffWaterExtra.builder().cutOffWaterId(id).build());
|
|
|
+ if(!CollectionUtils.isEmpty(tCutOffWaterExtras)){
|
|
|
+ for (TCutOffWaterExtra tCutOffWaterExtra : tCutOffWaterExtras) {
|
|
|
+ List<CutOffExtraRes> tempResult = this.tCutOffWaterMapper.selectgetExtraListByPumpingStationIdAndNeighbourhoodId(tCutOffWaterExtra.getPumpingStationId(), tCutOffWaterExtra.getNeighborhoodId());
|
|
|
+ //合并数据(安装小区或者泵站一个维度即可)
|
|
|
+ Map<Long, List<CutOffExtraRes>> collect = tempResult.stream().collect(Collectors.groupingBy(CutOffExtraRes::getPumpingStationId));
|
|
|
+ collect.forEach((key, value) ->{
|
|
|
+ CutOffExtraRes cutOffExtraResTemp = value.get(0);
|
|
|
+ CutOffExtraRes cutOffExtraRes = new CutOffExtraRes();
|
|
|
+ BeanUtils.copyProperties(cutOffExtraResTemp, cutOffExtraRes);
|
|
|
+ cutOffExtraRes.setNeighbourhoodNumberNames(value.stream().map(CutOffExtraRes::getNeighbourhoodNumberNames).collect(Collectors.joining("、")));
|
|
|
+ extraResList.add(cutOffExtraRes);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tCutOffWater.setExtraResList(extraResList);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增停水信息
|
|
|
*
|
|
@@ -56,10 +119,23 @@ public class TCutOffWaterServiceImpl implements ITCutOffWaterService
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public int insertTCutOffWater(TCutOffWater tCutOffWater)
|
|
|
{
|
|
|
tCutOffWater.setCreateTime(DateUtils.getNowDate());
|
|
|
- return tCutOffWaterMapper.insertTCutOffWater(tCutOffWater);
|
|
|
+ int i = tCutOffWaterMapper.insertTCutOffWater(tCutOffWater);
|
|
|
+ //保存关联表
|
|
|
+ List<CutOffExtraRes> extraResList = tCutOffWater.getExtraResList();
|
|
|
+ if(!CollectionUtils.isEmpty(extraResList)){
|
|
|
+ for (CutOffExtraRes cutOffExtraRes : extraResList) {
|
|
|
+ TCutOffWaterExtra tCutOffWaterExtra = new TCutOffWaterExtra();
|
|
|
+ tCutOffWaterExtra.setCutOffWaterId(tCutOffWater.getId());
|
|
|
+ tCutOffWaterExtra.setPumpingStationId(cutOffExtraRes.getPumpingStationId());
|
|
|
+ tCutOffWaterExtra.setNeighborhoodId(cutOffExtraRes.getNeighbourhoodId());
|
|
|
+ this.tCutOffWaterExtraMapper.insertTCutOffWaterExtra(tCutOffWaterExtra);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return i;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -98,4 +174,35 @@ public class TCutOffWaterServiceImpl implements ITCutOffWaterService
|
|
|
{
|
|
|
return tCutOffWaterMapper.deleteTCutOffWaterById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CutOffExtraRes> getExtraListByType(int type, String id) {
|
|
|
+ List<CutOffExtraRes> result = new ArrayList<>();
|
|
|
+ List<CutOffExtraRes> tempResult = new ArrayList<>();
|
|
|
+ //判断类型
|
|
|
+ if(0 == type){//根据泵站添加
|
|
|
+ tempResult = this.tCutOffWaterMapper.selectgetExtraListByPumpingStationId(id);
|
|
|
+ //按照小区分组合并
|
|
|
+ Map<Long, List<CutOffExtraRes>> collect = tempResult.stream().collect(Collectors.groupingBy(CutOffExtraRes::getNeighbourhoodId));
|
|
|
+ collect.forEach((key, value) ->{
|
|
|
+ CutOffExtraRes cutOffExtraResTemp = value.get(0);
|
|
|
+ CutOffExtraRes cutOffExtraRes = new CutOffExtraRes();
|
|
|
+ BeanUtils.copyProperties(cutOffExtraResTemp, cutOffExtraRes);
|
|
|
+ cutOffExtraRes.setNeighbourhoodNumberNames(value.stream().map(CutOffExtraRes::getNeighbourhoodNumberNames).collect(Collectors.joining("、")));
|
|
|
+ result.add(cutOffExtraRes);
|
|
|
+ });
|
|
|
+ }else{//根据小区添加
|
|
|
+ tempResult = this.tCutOffWaterMapper.selectgetExtraListByNeighbourhoodId(id);
|
|
|
+ //按照泵站分组合并
|
|
|
+ Map<Long, List<CutOffExtraRes>> collect = tempResult.stream().collect(Collectors.groupingBy(CutOffExtraRes::getPumpingStationId));
|
|
|
+ collect.forEach((key, value) ->{
|
|
|
+ CutOffExtraRes cutOffExtraResTemp = value.get(0);
|
|
|
+ CutOffExtraRes cutOffExtraRes = new CutOffExtraRes();
|
|
|
+ BeanUtils.copyProperties(cutOffExtraResTemp, cutOffExtraRes);
|
|
|
+ cutOffExtraRes.setNeighbourhoodNumberNames(value.stream().map(CutOffExtraRes::getNeighbourhoodNumberNames).collect(Collectors.joining("、")));
|
|
|
+ result.add(cutOffExtraRes);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|