Commit 400a4a03 authored by 赵啸非's avatar 赵啸非

修改区域树查询

parent 47c21f43
package com.mortals.xhx.module.area.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
......@@ -19,7 +20,6 @@ import java.util.List;
import java.util.Map;
/**
*
* 区域
*
* @author zxfei
......@@ -27,24 +27,24 @@ import java.util.Map;
*/
@RestController
@RequestMapping("area")
public class AreaController extends BaseCRUDJsonBodyMappingController<AreaService,AreaEntity,Long> {
public class AreaController extends BaseCRUDJsonBodyMappingController<AreaService, AreaEntity, Long> {
@Autowired
private ParamService paramService;
public AreaController(){
super.setModuleDesc( "区域");
public AreaController() {
super.setModuleDesc("区域");
}
@Override
protected void init( Map<String, Object> model, Context context) {
this.addDict(model, "haveSonArea", paramService.getParamBySecondOrganize("Area","haveSonArea"));
this.addDict(model, "haveSonDept", paramService.getParamBySecondOrganize("Area","haveSonDept"));
this.addDict(model, "haveGetDept", paramService.getParamBySecondOrganize("Area","haveGetDept"));
this.addDict(model, "haveGetMatterList", paramService.getParamBySecondOrganize("Area","haveGetMatterList"));
this.addDict(model, "areaLevel", paramService.getParamBySecondOrganize("Area","areaLevel"));
this.addDict(model, "status", paramService.getParamBySecondOrganize("Area","status"));
super.init( model, context);
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "haveSonArea", paramService.getParamBySecondOrganize("Area", "haveSonArea"));
this.addDict(model, "haveSonDept", paramService.getParamBySecondOrganize("Area", "haveSonDept"));
this.addDict(model, "haveGetDept", paramService.getParamBySecondOrganize("Area", "haveGetDept"));
this.addDict(model, "haveGetMatterList", paramService.getParamBySecondOrganize("Area", "haveGetMatterList"));
this.addDict(model, "areaLevel", paramService.getParamBySecondOrganize("Area", "areaLevel"));
this.addDict(model, "status", paramService.getParamBySecondOrganize("Area", "status"));
super.init(model, context);
}
......@@ -52,11 +52,12 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
* 获取站点下拉树列表
*/
@PostMapping("treeselect")
@UnAuth
public String treeselect() {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
int code=VALUE_RESULT_SUCCESS;
int code = VALUE_RESULT_SUCCESS;
try {
List<AreaEntity> list = this.service.find(new AreaQuery());
List<AreaTreeSelect> treeSelects = this.service.buildAreaTreeSelect(list);
......@@ -79,13 +80,13 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
public String getListByParentId(String parentId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc()+"子节点";
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
List<AreaTreeSelect> treeList = this.service.getListByParentId(parentId, getContext());
model.put(KEY_RESULT_DATA,treeList);
model.put(KEY_RESULT_DATA, treeList);
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_DATA, model);
recordSysLog(request, busiDesc+"【成功】");
recordSysLog(request, busiDesc + "【成功】");
} catch (Exception e) {
log.error("根据parentId查询子信息错误", e);
this.doException(request, busiDesc, model, e);
......
......@@ -50,6 +50,15 @@ public interface IApiAreaFeign extends IFeign {
@GetMapping(value = "/area/getListByParentId")
String getListByParentId(@RequestParam(value = "parentId") String parentId);
/**
* 查看区域列表信息
*
* @return
*/
@PostMapping(value = "/area/treeselect")
String treeselect();
}
......@@ -88,6 +97,14 @@ class AreaFeignFallbackFactory implements FallbackFactory<IApiAreaFeign> {
failResp.setMsg("暂时无法获取区域信息,请稍后再试!");
return JSON.toJSONString(failResp);
}
@Override
public String treeselect() {
ApiResp<String> failResp = new ApiResp<>();
failResp.setCode(ApiRespCodeEnum.FAILED.getValue());
failResp.setMsg("暂时无法获取区域信息,请稍后再试!");
return JSON.toJSONString(failResp);
}
};
}
}
......
......@@ -2588,13 +2588,14 @@ dict|object|字典对象
参数名称|类型|备注|必填|其它
---|---|---|---|---
page|Integer|当前页|否|-
size|Integer|每页条数|否|-
name|String|区域名称|否|-
size|Integer|每页条数|否|-1查询所有
name|String|区域名称|否|模糊查询前后添加%%
areaCode|String|区域编码|否|模糊查询前后添加%%
**请求样例:**
```
{
"name":"zt2h08",
"name":"%zt2h08%",
"page":1,
"size":10
}
......@@ -2731,9 +2732,7 @@ parentId|String|区域树父id|是|0为树的顶层节点
**请求样例:**
```
http://localhost/area/getListByParentId?parentId=549
```
**响应参数:**
......@@ -2764,7 +2763,7 @@ data|object|数据对象|-
**内容类型:** application/json;charset=utf-8
**简要描述:** 返回所有区域信息
**简要描述:** 返回所有区域信息,树结构,数据量巨大
**请求参数:**
......@@ -2773,7 +2772,6 @@ data|object|数据对象|-
**请求样例:**
```
http://localhost/area/treeselect
```
......
......@@ -17,31 +17,6 @@ import java.util.List;
*/
public interface AreaService extends ICRUDService<AreaEntity, Long> {
/**
* 是否存在区域节点
*
* @param areaId 区域ID
* @return 结果
*/
boolean hasChildByAreaId(String areaId);
/**
* 查询区域数据
*
* @param area 区域
* @return 区域集合
*/
List<AreaEntity> selectAreaList(AreaEntity area);
/**
* 构建前端所需要下拉树结构
*
* @param areaList 区域列表
* @return 下拉树结构列表
*/
List<AreaTreeSelect> buildAreaTreeSelect(List<AreaEntity> areaList);
/**
......@@ -71,4 +46,13 @@ public interface AreaService extends ICRUDService<AreaEntity, Long> {
*/
String list(AreaEntity query, Context context);
/**
* 查询区域树(全节点)
* @param query
* @param context
* @return
*/
String treeselect(Context context);
}
\ No newline at end of file
......@@ -75,69 +75,16 @@ public class AreaServiceImpl extends AbstractCRUDServiceImpl<AreaDao, AreaEntity
return resp;
}
@Override
public boolean hasChildByAreaId(String areaId) {
List<AreaEntity> list = this.find(new AreaQuery().pid(areaId));
return list.size() > 0 ? true : false;
}
@Override
public List<AreaEntity> selectAreaList(AreaEntity area) {
return this.find(new AreaQuery());
}
@Override
public List<AreaTreeSelect> buildAreaTreeSelect(List<AreaEntity> list) {
List<AreaEntity> returnList = new ArrayList<>();
List<Long> tempList = list.stream().map(AreaEntity::getId).collect(Collectors.toList());
for (AreaEntity areaEntity : list) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(areaEntity.getPid())) {
recursionFn(list, areaEntity);
returnList.add(areaEntity);
}
}
if (returnList.isEmpty()) {
returnList = list;
}
return returnList.stream().map(AreaTreeSelect::new).collect(Collectors.toList());
}
/**
* 递归列表
*/
private void recursionFn(List<AreaEntity> list, AreaEntity t) {
// 得到子节点列表
List<AreaEntity> childList = getChildList(list, t);
t.setChildren(childList);
for (AreaEntity tChild : childList) {
if (hasChild(list, tChild)) {
recursionFn(list, tChild);
}
}
}
/**
* 得到子节点列表
*/
private List<AreaEntity> getChildList(List<AreaEntity> list, AreaEntity t) {
return list.stream().map(item -> {
if (!ObjectUtils.isEmpty(item.getPid()) && item.getPid() == t.getIid()) {
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
public String treeselect(Context context) {
log.info("treeselectReq==");
String resp = apiAreaFeign.treeselect();
ApiResp apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取区域列表树数据失败:" + apiResp.getMsg());
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<AreaEntity> list, AreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
//log.info("treeselectResp=>{}", resp);
return resp;
}
}
\ No newline at end of file
......@@ -55,7 +55,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
String busiDesc = "查看" + this.getModuleDesc();
Context context = this.getContext();
try {
String token = authTokenService.getToken(request);
String resp = this.service.viewArea(id, context);
this.recordSysLog(this.request, busiDesc + " 【成功】");
return resp;
......@@ -73,7 +72,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
try {
String token = authTokenService.getToken(request);
String resp = this.service.list(query, context);
recordSysLog(request, busiDesc + " 【成功】");
return resp;
......@@ -89,21 +87,16 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
@PostMapping("treeselect")
public String treeselect() {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
int code = VALUE_RESULT_SUCCESS;
try {
List<AreaEntity> list = this.service.find(new AreaQuery());
List<AreaTreeSelect> treeSelects = this.service.buildAreaTreeSelect(list);
model.put(KEY_RESULT_DATA, treeSelects);
String resp = this.service.treeselect(context);
recordSysLog(request, busiDesc + " 【成功】");
return resp;
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
return this.createFailJsonResp(e.getMessage() == null ? "系统异常" : e.getMessage());
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
......@@ -116,7 +109,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
String token = authTokenService.getToken(request);
String retStr = this.service.getListByParentId(parentId, getContext());
recordSysLog(request, busiDesc + "【成功】");
return retStr;
......
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