Commit 02a0ebf0 authored by tianyiming's avatar tianyiming

优化管辖机构和行政区划树

parent 3b0203cc
...@@ -21,8 +21,10 @@ public interface IEquipmentCategoryService { ...@@ -21,8 +21,10 @@ public interface IEquipmentCategoryService {
int createSupervisorCode(Map<String,Object> map,String record); int createSupervisorCode(Map<String,Object> map,String record);
List<LinkedHashMap> getTree();
List<LinkedHashMap> creatTree(); List<LinkedHashMap> creatTree();
// List<LinkedHashMap> getRegion(String level, String parentId);
List<LinkedHashMap> getRegion(String level, String parentId); List<LinkedHashMap> getRegion(String level, String parentId);
Map<String,Object> getCategoryAndDefineByRecord(String rowId); Map<String,Object> getCategoryAndDefineByRecord(String rowId);
......
...@@ -194,15 +194,15 @@ public class EquipmentCategoryController extends BaseController { ...@@ -194,15 +194,15 @@ public class EquipmentCategoryController extends BaseController {
/** /**
* 获取行政区划 * 获取管辖分局树
* *
* @return * @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/creatTree") @GetMapping(value = "/creatTree")
@ApiOperation(httpMethod = "GET", value = "获取行政区划", notes = "获取行政区划") @ApiOperation(httpMethod = "GET", value = "获取管辖分局树", notes = "获取管辖分局树")
public ResponseModel<Object> creatTree() { public ResponseModel<Object> creatTree() {
return ResponseHelper.buildResponse(equipmentCategoryService.creatTree()); return ResponseHelper.buildResponse(equipmentCategoryService.getTree());
} }
...@@ -234,13 +234,13 @@ public class EquipmentCategoryController extends BaseController { ...@@ -234,13 +234,13 @@ public class EquipmentCategoryController extends BaseController {
/** /**
* 生成管辖分局树 * 获取行政区划
* *
* @return * @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "getRegion") @GetMapping(value = "getRegion")
@ApiOperation(httpMethod = "GET", value = "生成管辖分局树", notes = "生成管辖分局树") @ApiOperation(httpMethod = "GET", value = "获取行政区划", notes = "获取行政区划")
public ResponseModel<Object> getRegion(@RequestParam(value = "level", required = false) String level, public ResponseModel<Object> getRegion(@RequestParam(value = "level", required = false) String level,
@RequestParam(value = "parentId", required = false) String parentId) { @RequestParam(value = "parentId", required = false) String parentId) {
return ResponseHelper.buildResponse(equipmentCategoryService.getRegion(level,parentId)); return ResponseHelper.buildResponse(equipmentCategoryService.getRegion(level,parentId));
......
package com.yeejoin.amos.boot.module.tzs.biz.listener;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.service.IEquipmentCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.component.emq.EmqxListener;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
@Component
@EnableScheduling
@Slf4j
public class PlatformUserTopicMessage extends EmqxListener {
@Resource
protected EmqKeeper emqKeeper;
@Value("${amos.operation.log}")
private String amosOperationLog;
@PostConstruct
void init() throws Exception {
emqKeeper.subscript(amosOperationLog, 1, this);
}
@Value("${amos.agency.code}")
String amosAgencyCode;
@Autowired
RedisUtils redisUtil;
@Value("${amos.system.user.product:AMOS_STUDIO_WEB}")
String product;
@Value("${amos.system.user.app-key:AMOS_STUDIO}")
String appKey;
@Autowired
IEquipmentCategoryService equipmentCategoryService;
@Override
public void processMessage(String topic, MqttMessage message) {
RequestContext.setAppKey(appKey);
RequestContext.setProduct(product);
RequestContext.setToken(String.valueOf(redisUtil.get("platform_token")));
JSONObject jsonObject = JSON.parseObject(message.toString());
JSONObject result = jsonObject.getJSONObject("result");
JSONObject dataResult = result.getJSONObject("result");
String path = result.getString("path");
String agencyCode = jsonObject.getString("agencyCode");
if (!amosAgencyCode.equals(agencyCode)) {
return;
}
try {
if (StringUtils.isNotEmpty(path)) {
if (path.contains("company") && !"company".equals(dataResult.get("level"))) {
equipmentCategoryService.creatTree();
}
}
} catch (Exception e) {
log.info("平台同步消息失败:{}", e.getMessage());
e.printStackTrace();
}
log.info("平台推送消息同步完成");
}
}
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquInfoDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.CategoryOtherInfo; import com.yeejoin.amos.boot.module.tzs.api.entity.CategoryOtherInfo;
...@@ -30,6 +31,7 @@ import org.typroject.tyboot.core.rdbms.service.BaseService; ...@@ -30,6 +31,7 @@ import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* 装备分类服务实现类 * 装备分类服务实现类
...@@ -54,6 +56,18 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -54,6 +56,18 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
@Autowired @Autowired
IdxFeignService idxFeignService; IdxFeignService idxFeignService;
@Value("${regulator.unit.code}")
private String code;
@Autowired
private RedisUtils redisUtils;
//管辖机构redis缓存key
private static final String REGULATOR_UNIT_TREE = "REGULATOR_UNIT_TREE";
//行政区划redis缓存key
private static final String PROVINCE = "PROVINCE";
private static final String CITY = "CITY";
private static final String REGION = "REGION";
/** /**
* 分页查询 * 分页查询
...@@ -137,7 +151,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -137,7 +151,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
equipList = map.get("EQU_LIST").toString(); equipList = map.get("EQU_LIST").toString();
} else { } else {
EquInfoDto equInfoDto = categoryOtherInfoMapper.selectEquipInfo(record); EquInfoDto equInfoDto = categoryOtherInfoMapper.selectEquipInfo(record);
if("6035".equals(equInfoDto.getStatus())){ if ("6035".equals(equInfoDto.getStatus())) {
//判断这条数据是否已经有电梯96333码和监管码 //判断这条数据是否已经有电梯96333码和监管码
//如果都有则直接返回 //如果都有则直接返回
if (ObjectUtils.isEmpty(equInfoDto.getSupervisor()) || ObjectUtils.isEmpty(equInfoDto.getCode())) { if (ObjectUtils.isEmpty(equInfoDto.getSupervisor()) || ObjectUtils.isEmpty(equInfoDto.getCode())) {
...@@ -148,7 +162,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -148,7 +162,7 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
} else { } else {
return 0; return 0;
} }
}else { } else {
return 0; return 0;
} }
} }
...@@ -164,38 +178,104 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -164,38 +178,104 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
} }
@Override @Override
public List<LinkedHashMap> getTree() {
List<LinkedHashMap> result = (List<LinkedHashMap>) redisUtils.get(REGULATOR_UNIT_TREE);
//判断redis是否存在管辖机构树
if (!ObjectUtils.isEmpty(result)) {
// 有直接返回
return result;
} else {
// 没有则去调用平台fegin接口生成并存储redis
return creatTree();
}
}
@Override
public List<LinkedHashMap> creatTree() { public List<LinkedHashMap> creatTree() {
FeignClientResult tree = privilegeFeginService.tree(); FeignClientResult tree = privilegeFeginService.tree();
List<LinkedHashMap> result = (List<LinkedHashMap>) tree.getResult(); List<LinkedHashMap> result = (List<LinkedHashMap>) tree.getResult();
List<LinkedHashMap> treeData = deleteTreeData(result, null); List<LinkedHashMap> treeData = deleteRegulatorTreeData(result);
List<LinkedHashMap> resultTree = new ArrayList<>(); List<LinkedHashMap> resultTree = treeData.stream().filter(e -> code.equals(e.get("orgCode"))).collect(Collectors.toList());
resultTree.add(treeData.get(5)); redisUtils.set(REGULATOR_UNIT_TREE, resultTree);
return resultTree; return resultTree;
} }
/**
* 删除管辖机构树中level为使用单位的数据
*
* @param result 管辖机构树
* @return 筛选过滤后不包含使用单位的管辖机构树
*/
private List<LinkedHashMap> deleteRegulatorTreeData(List<LinkedHashMap> result) {
Iterator it = result.iterator();
while (it.hasNext()) {
LinkedHashMap e = (LinkedHashMap) it.next();
//删除使用单位
if ("company".equals(e.get("level"))) {
it.remove();
}
if (!ObjectUtils.isEmpty(e.get("children"))) {
deleteRegulatorTreeData((List<LinkedHashMap>) e.get("children"));
}
}
return result;
}
@Override @Override
public List<LinkedHashMap> getRegion(String level, String parentId) { public List<LinkedHashMap> getRegion(String level, String parentId) {
List<LinkedHashMap> list = new ArrayList<>(); List<LinkedHashMap> list = new ArrayList<>();
if (ObjectUtils.isEmpty(parentId)) { if (ObjectUtils.isEmpty(parentId)) {
FeignClientResult result = privilegeFeginService.getProvince(level); list = (List<LinkedHashMap>) redisUtils.get(PROVINCE);
list = (List<LinkedHashMap>) result.getResult(); return ObjectUtils.isEmpty(list) ? getProvinceList(level) : list;
list.get(0).put("sequenceNbr", list.get(0).get("regionCode"));
} else { } else {
FeignClientResult tree = privilegeFeginService.getTree(); String regionCode = parentId.split("_")[0];
List<LinkedHashMap> result = (List<LinkedHashMap>) tree.getResult(); Map<String, Object> map = regionCode.endsWith("0000") ? (Map<String, Object>) redisUtils.get(CITY) : (Map<String, Object>) redisUtils.get(REGION);
if(parentId.contains("_")){ if (ObjectUtils.isEmpty(map)) {
String[] s = parentId.split("_"); map = getRegionList();
parentId = s[0]; }
list = (List<LinkedHashMap>)map.get(regionCode);
return list;
}
}
public Map<String,Object> getRegionList() {
Map<String,Object> map1 = new HashMap<>();
List<LinkedHashMap> cityList = new ArrayList<>();
FeignClientResult tree = privilegeFeginService.getTree();
List<LinkedHashMap> result = (List<LinkedHashMap>) tree.getResult();
String regionCode = ((List<LinkedHashMap>) privilegeFeginService.getProvince("1").getResult()).get(0).get("regionCode").toString();
cityList = deleteTreeData(result, regionCode);
Map<String, Object> cityMap = new HashMap<>();
cityMap.put(regionCode, cityList);
map1.put(regionCode, cityList);
redisUtils.set(CITY, cityMap);
if (!ObjectUtils.isEmpty(cityList)) {
List<LinkedHashMap> region = (List<LinkedHashMap>)privilegeFeginService.getTree().getResult();
Map<String, Object> map = new HashMap<>();
for (LinkedHashMap linkedHashMap : cityList) {
List<LinkedHashMap> regionList = deleteTreeData(region, linkedHashMap.get("regionCode").toString());
map.put(linkedHashMap.get("regionCode").toString(), regionList);
map1.put(linkedHashMap.get("regionCode").toString(), regionList);
} }
list = deleteTreeData(result, parentId); redisUtils.set(REGION, map);
} }
return map1;
}
public List<LinkedHashMap> getProvinceList(String level) {
List<LinkedHashMap> list = new ArrayList<>();
FeignClientResult result = privilegeFeginService.getProvince(level);
list = (List<LinkedHashMap>) result.getResult();
list.get(0).put("sequenceNbr", list.get(0).get("regionCode"));
redisUtils.set(PROVINCE, list);
return list; return list;
} }
@Override @Override
public Map<String, Object> getCategoryAndDefineByRecord(String record) { public Map<String, Object> getCategoryAndDefineByRecord(String record) {
if(ObjectUtils.isEmpty(record)){ if (ObjectUtils.isEmpty(record)) {
return null; return null;
} }
return equipmentCategoryMapper.getCategoryAndDefineByRecord(record); return equipmentCategoryMapper.getCategoryAndDefineByRecord(record);
...@@ -203,35 +283,21 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD ...@@ -203,35 +283,21 @@ public class EquipmentCategoryServiceImpl extends BaseService<EquipmentCategoryD
private List<LinkedHashMap> deleteTreeData(List<LinkedHashMap> result, String type) { private List<LinkedHashMap> deleteTreeData(List<LinkedHashMap> result, String type) {
Iterator it = result.iterator(); Iterator it = result.iterator();
if (ObjectUtils.isEmpty(type)) { List<LinkedHashMap> list = new ArrayList<>();
while (it.hasNext()) { while (it.hasNext()) {
LinkedHashMap e = (LinkedHashMap) it.next(); LinkedHashMap e = (LinkedHashMap) it.next();
//删除使用单位 //修改数据
if ("company".equals(e.get("level"))) { if (type.equals(e.get("parentRegionCode").toString())) {
it.remove(); e.put("children", null);
} e.put("sequenceNbr", e.get("regionCode"));
if (!ObjectUtils.isEmpty(e.get("children"))) { list.add(e);
deleteTreeData((List<LinkedHashMap>) e.get("children"), null);
}
} }
return result; if (!ObjectUtils.isEmpty(e.get("children"))) {
} else { List<LinkedHashMap> children = deleteTreeData((List<LinkedHashMap>) e.get("children"), type);
List<LinkedHashMap> list = new ArrayList<>(); list.addAll(children);
while (it.hasNext()) {
LinkedHashMap e = (LinkedHashMap) it.next();
//修改数据
if (type.equals(e.get("parentRegionCode").toString())) {
e.put("children", null);
e.put("sequenceNbr", e.get("regionCode"));
list.add(e);
}
if (!ObjectUtils.isEmpty(e.get("children"))) {
List<LinkedHashMap> children = deleteTreeData((List<LinkedHashMap>) e.get("children"), type);
list.addAll(children);
}
} }
return list;
} }
return list;
} }
/** /**
......
...@@ -148,4 +148,11 @@ amos.system.user.password=a1234567 ...@@ -148,4 +148,11 @@ amos.system.user.password=a1234567
amos.system.user.app-key=AMOS_STUDIO amos.system.user.app-key=AMOS_STUDIO
amos.system.user.product=AMOS_STUDIO_WEB amos.system.user.product=AMOS_STUDIO_WEB
## ??????????????topic
amos.operation.log=/amos/operation/log
amos.agency.code=tzs
## ?????orgCode
regulator.unit.code=50
spring.main.allow-bean-definition-overriding=true spring.main.allow-bean-definition-overriding=true
\ No newline at end of file
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