Commit 990fb7b6 authored by duanruiming's avatar duanruiming

[udpate] 辖区分组逻辑优化

parent d2925aa3
......@@ -4,7 +4,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.wanji.feign.pojo.result.JsonViewObject;
import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.service.SituationDetectionService;
import net.wanji.web.vo.situationDetection.*;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -170,10 +169,10 @@ public class SituationDetectionController extends BaseController {
@ApiOperation(value = "辖区分组", notes = "辖区分组")
@GetMapping("/jurisdictionTree")
public JsonViewObject jurisdictionTree() {
List<AreaTreePO> areaTreePOS = situationDetectionService.jurisdictionTree();
public JsonViewObject jurisdictionTree(Integer areaId) {
List<JurisdictionAreaVO> result = situationDetectionService.jurisdictionTree(areaId);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(areaTreePOS);
return jsonViewObject.success(result);
}
@ApiOperation(value = "查询区域列表", notes = "查询区域列表")
......
......@@ -34,6 +34,4 @@ public interface TBaseAreaInfoMapper extends BaseMapper<TBaseAreaInfo> {
List<AreaTreePO> selectAreaTree();
List<AreaTreePO> selectJurisdictionArea();
}
package net.wanji.web.service;
import net.wanji.web.vo.situationDetection.SignalOperationModeVO;
import net.wanji.web.entity.TBaseCrossInfo;
import net.wanji.web.entity.TDeviceStatusLog;
import net.wanji.web.po.AreaTreePO;
import net.wanji.web.vo.situationDetection.*;
import java.text.ParseException;
......@@ -38,7 +36,7 @@ public interface SituationDetectionService {
TBaseCrossInfo selectCrossInfoById(String signalId);
List<AreaTreePO> jurisdictionTree();
List<JurisdictionAreaVO> jurisdictionTree(Integer areaId);
List<AreaListVO> selectAreaList(Integer areaId);
......
......@@ -402,26 +402,45 @@ public class SituationDetectionServiceImpl implements SituationDetectionService
}
@Override
public List<AreaTreePO> jurisdictionTree() {
// 行政列表
List<AreaTreePO> areaTreePOS = tBaseCrossInfoService.areaTree();
List<AreaTreePO> resultList = areaTreePOS.stream().filter(areaTreePO -> areaTreePO.getChildren() != null).collect(Collectors.toList());
public List<JurisdictionAreaVO> jurisdictionTree(Integer areaId) {
List<JurisdictionAreaVO> resultList = new ArrayList<>();
// 辖区构建
List<AreaTreePO> jurisdictionAreaList = tBaseAreaInfoMapper.selectJurisdictionArea();
jurisdictionAreaList.forEach(areaTreePO -> areaTreePO.setLevel(3));
Map<Integer, List<AreaTreePO>> parentCodeListMap = jurisdictionAreaList.stream().collect(Collectors.groupingBy(AreaTreePO::getParentCode));
for (AreaTreePO areaTreePO : resultList) {
areaTreePO.setLevel(1);
List<AreaTreePO> childrenList = areaTreePO.getChildren();
for (AreaTreePO child : childrenList) {
Integer areaCode = child.getAreaCode();
child.setLevel(2);
if (!parentCodeListMap.isEmpty() && parentCodeListMap.containsKey(areaCode)) {
child.setChildren(parentCodeListMap.get(areaCode));
LambdaQueryWrapper<TBaseAreaInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(TBaseAreaInfo::getType, 2);
List<TBaseAreaInfo> tBaseAreaInfos = tBaseAreaInfoMapper.selectList(queryWrapper);
LambdaQueryWrapper<TBaseAreaCross> crossQuery = new LambdaQueryWrapper<>();
List<TBaseAreaCross> tBaseAreaCrosses = tBaseAreaCrossMapper.selectList(crossQuery);
LambdaQueryWrapper<TBaseCrossInfo> crossInfoQuery = new LambdaQueryWrapper<>();
List<TBaseCrossInfo> tBaseCrossInfos = tBaseCrossInfoMapper.selectList(crossInfoQuery);
Map<Integer, List<TBaseAreaCross>> areaIdMap = tBaseAreaCrosses.stream().collect(Collectors.groupingBy(TBaseAreaCross::getAreaId));
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;
}
......
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 @@
select id, code areaCode, name areaName, parent_code parentCode
from t_base_area_info where type = 1
</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>
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