Commit 990fb7b6 authored by duanruiming's avatar duanruiming

[udpate] 辖区分组逻辑优化

parent d2925aa3
...@@ -4,7 +4,6 @@ import io.swagger.annotations.Api; ...@@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import net.wanji.feign.pojo.result.JsonViewObject; import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.web.entity.TDeviceStatusLog; import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.service.SituationDetectionService; import net.wanji.web.service.SituationDetectionService;
import net.wanji.web.vo.situationDetection.*; import net.wanji.web.vo.situationDetection.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -170,10 +169,10 @@ public class SituationDetectionController extends BaseController { ...@@ -170,10 +169,10 @@ public class SituationDetectionController extends BaseController {
@ApiOperation(value = "辖区分组", notes = "辖区分组") @ApiOperation(value = "辖区分组", notes = "辖区分组")
@GetMapping("/jurisdictionTree") @GetMapping("/jurisdictionTree")
public JsonViewObject jurisdictionTree() { public JsonViewObject jurisdictionTree(Integer areaId) {
List<AreaTreePO> areaTreePOS = situationDetectionService.jurisdictionTree(); List<JurisdictionAreaVO> result = situationDetectionService.jurisdictionTree(areaId);
JsonViewObject jsonViewObject = JsonViewObject.newInstance(); JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(areaTreePOS); return jsonViewObject.success(result);
} }
@ApiOperation(value = "查询区域列表", notes = "查询区域列表") @ApiOperation(value = "查询区域列表", notes = "查询区域列表")
......
...@@ -34,6 +34,4 @@ public interface TBaseAreaInfoMapper extends BaseMapper<TBaseAreaInfo> { ...@@ -34,6 +34,4 @@ public interface TBaseAreaInfoMapper extends BaseMapper<TBaseAreaInfo> {
List<AreaTreePO> selectAreaTree(); List<AreaTreePO> selectAreaTree();
List<AreaTreePO> selectJurisdictionArea();
} }
package net.wanji.web.service; package net.wanji.web.service;
import net.wanji.web.vo.situationDetection.SignalOperationModeVO;
import net.wanji.web.entity.TBaseCrossInfo; import net.wanji.web.entity.TBaseCrossInfo;
import net.wanji.web.entity.TDeviceStatusLog; import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.vo.situationDetection.*; import net.wanji.web.vo.situationDetection.*;
import java.text.ParseException; import java.text.ParseException;
...@@ -38,7 +36,7 @@ public interface SituationDetectionService { ...@@ -38,7 +36,7 @@ public interface SituationDetectionService {
TBaseCrossInfo selectCrossInfoById(String signalId); TBaseCrossInfo selectCrossInfoById(String signalId);
List<AreaTreePO> jurisdictionTree(); List<JurisdictionAreaVO> jurisdictionTree(Integer areaId);
List<AreaListVO> selectAreaList(Integer areaId); List<AreaListVO> selectAreaList(Integer areaId);
......
...@@ -402,26 +402,45 @@ public class SituationDetectionServiceImpl implements SituationDetectionService ...@@ -402,26 +402,45 @@ public class SituationDetectionServiceImpl implements SituationDetectionService
} }
@Override @Override
public List<AreaTreePO> jurisdictionTree() { public List<JurisdictionAreaVO> jurisdictionTree(Integer areaId) {
// 行政列表 List<JurisdictionAreaVO> resultList = new ArrayList<>();
List<AreaTreePO> areaTreePOS = tBaseCrossInfoService.areaTree();
List<AreaTreePO> resultList = areaTreePOS.stream().filter(areaTreePO -> areaTreePO.getChildren() != null).collect(Collectors.toList());
// 辖区构建 // 辖区构建
List<AreaTreePO> jurisdictionAreaList = tBaseAreaInfoMapper.selectJurisdictionArea(); LambdaQueryWrapper<TBaseAreaInfo> queryWrapper = new LambdaQueryWrapper<>();
jurisdictionAreaList.forEach(areaTreePO -> areaTreePO.setLevel(3)); queryWrapper.eq(TBaseAreaInfo::getType, 2);
Map<Integer, List<AreaTreePO>> parentCodeListMap = jurisdictionAreaList.stream().collect(Collectors.groupingBy(AreaTreePO::getParentCode)); List<TBaseAreaInfo> tBaseAreaInfos = tBaseAreaInfoMapper.selectList(queryWrapper);
for (AreaTreePO areaTreePO : resultList) { LambdaQueryWrapper<TBaseAreaCross> crossQuery = new LambdaQueryWrapper<>();
areaTreePO.setLevel(1); List<TBaseAreaCross> tBaseAreaCrosses = tBaseAreaCrossMapper.selectList(crossQuery);
List<AreaTreePO> childrenList = areaTreePO.getChildren();
for (AreaTreePO child : childrenList) { LambdaQueryWrapper<TBaseCrossInfo> crossInfoQuery = new LambdaQueryWrapper<>();
Integer areaCode = child.getAreaCode(); List<TBaseCrossInfo> tBaseCrossInfos = tBaseCrossInfoMapper.selectList(crossInfoQuery);
child.setLevel(2);
if (!parentCodeListMap.isEmpty() && parentCodeListMap.containsKey(areaCode)) { Map<Integer, List<TBaseAreaCross>> areaIdMap = tBaseAreaCrosses.stream().collect(Collectors.groupingBy(TBaseAreaCross::getAreaId));
child.setChildren(parentCodeListMap.get(areaCode)); for (TBaseAreaInfo tBaseAreaInfo : tBaseAreaInfos) {
JurisdictionAreaVO jurisdictionAreaVO = new JurisdictionAreaVO();
Integer currentAreaId = tBaseAreaInfo.getCode();
jurisdictionAreaVO.setAreaId(currentAreaId);
jurisdictionAreaVO.setAreaName(tBaseAreaInfo.getName());
List<TBaseCrossInfo> crossInfoList = new ArrayList<>();
if (!areaIdMap.isEmpty()) {
List<TBaseAreaCross> areaCrossList = areaIdMap.get(currentAreaId);
if (!CollectionUtils.isEmpty(areaCrossList)) {
List<String> crossList = areaCrossList.stream().map(TBaseAreaCross::getCrossId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(tBaseCrossInfos)) {
for (TBaseCrossInfo tBaseCrossInfo : tBaseCrossInfos) {
if (crossList.contains(tBaseCrossInfo.getId())) {
crossInfoList.add(tBaseCrossInfo);
}
} }
} }
} }
}
jurisdictionAreaVO.setCrossInfoList(crossInfoList);
resultList.add(jurisdictionAreaVO);
}
return resultList; return resultList;
} }
......
package net.wanji.web.vo.situationDetection;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.web.entity.TBaseCrossInfo;
import java.util.List;
/**
* @author duanruiming
* @date 2023/02/07 18:52
*/
@Data
@ApiModel(value = "辖区实体")
public class JurisdictionAreaVO {
@ApiModelProperty(value = "辖区编号")
private Integer areaId;
@ApiModelProperty(value = "辖区名称")
private String areaName;
@ApiModelProperty(value = "路口信息列表")
private List<TBaseCrossInfo> crossInfoList;
}
...@@ -160,10 +160,5 @@ ...@@ -160,10 +160,5 @@
select id, code areaCode, name areaName, parent_code parentCode select id, code areaCode, name areaName, parent_code parentCode
from t_base_area_info where type = 1 from t_base_area_info where type = 1
</select> </select>
<!-- 查询交警辖区 -->
<select id="selectJurisdictionArea" resultType="net.wanji.web.po.AreaTreePO">
select id, code areaCode, name areaName, parent_code parentCode
from t_base_area_info where type = 2
</select>
</mapper> </mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment