Commit 9c371859 authored by 赵啸非's avatar 赵啸非

添加区域树结构

parent 8427e455
......@@ -51,4 +51,14 @@ public interface AreaService extends ICRUDCacheService<AreaEntity,Long> {
* @return
*/
List<AreaTreeSelect> getListByParentId(String parentId, Context context);
/**
* 获取当前节点所有子节点
* @param rootId
* @param context
* @return
*/
List<AreaTreeSelect> getListByRootId(Long rootId, Context context);
}
\ No newline at end of file
......@@ -31,16 +31,15 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
private SiteService siteService;
@Override
public void putCache(String key, AreaEntity data) {
super.putCache(key, data);
//加载孩子关系
if("True".equalsIgnoreCase(data.getHaveSonArea())){
List<Long> collect = this.find(new AreaQuery().pid(data.getIid())).stream().map(AreaEntity::getId).collect(Collectors.toList());
if ("True".equalsIgnoreCase(data.getHaveSonArea())) {
List<AreaEntity> collect = this.find(new AreaQuery().pid(data.getIid())).stream().collect(Collectors.toList());
String childKey = super.getCacheName() + ":" + key;
cacheService.del(childKey);
cacheService.lpush(childKey,collect);
cacheService.lpush(childKey, collect);
}
}
......@@ -181,6 +180,32 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
return collect;
}
@Override
public List<AreaTreeSelect> getListByRootId(Long rootId, Context context) {
if (ObjectUtils.isEmpty(rootId)) {
rootId = 0L;
}
AreaEntity areaEntity = this.getCache(rootId.toString());
AreaTreeSelect areaTreeSelect = new AreaTreeSelect(areaEntity);
List<AreaTreeSelect> list = this.cacheService.lrange(super.getCacheName() + ":" + areaEntity.getId(), AreaEntity.class).stream().map(item -> new AreaTreeSelect(item)).collect(Collectors.toList());
list.stream().forEach(areaTreeSelect1 -> {
rebuildList(areaTreeSelect1);
});
areaTreeSelect.setChildren(list);
List<AreaTreeSelect> areaTreeSelectList = new ArrayList<>();
areaTreeSelectList.add(areaTreeSelect);
return areaTreeSelectList;
}
private void rebuildList(AreaTreeSelect areaTreeSelect) {
List<AreaTreeSelect> list = this.cacheService.lrange(super.getCacheName() + ":" + areaTreeSelect.getId(), AreaEntity.class).stream().map(item -> new AreaTreeSelect(item)).collect(Collectors.toList());
areaTreeSelect.setChildren(list);
}
/**
* 递归列表
......@@ -216,5 +241,4 @@ public class AreaServiceImpl extends AbstractCRUDCacheServiceImpl<AreaDao, AreaE
}
}
\ No newline at end of file
......@@ -98,4 +98,29 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
}
/**
* 根据parentId查询子信息
*/
@GetMapping(value = "getListByRootId")
@UnAuth
public String getListByRootId(Long rootId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
List<AreaTreeSelect> treeList = this.service.getListByRootId(rootId, getContext());
model.put(KEY_RESULT_DATA, treeList);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc + "【成功】");
} catch (Exception e) {
log.error("根据rootId查询子信息错误", e);
this.doException(request, busiDesc, model, e);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, e.getMessage());
}
return ret.toJSONString();
}
}
\ 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