Commit 2491521d authored by 赵啸非's avatar 赵啸非

添加站点业务中子业务列表

parent d3003888
package com.mortals.xhx.base.framework.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author: zxfei
* @date: 2022/6/6 15:05
* @description:添加跨域响应
**/
@Component
public class CrossInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
return true;
}
}
...@@ -18,7 +18,7 @@ import java.util.Map; ...@@ -18,7 +18,7 @@ import java.util.Map;
* @author zxfei * @author zxfei
*/ */
//@Configuration //@Configuration
public class FilterConfig { public class FilterConfig {
@Value("${xss.enabled}") @Value("${xss.enabled}")
private String enabled; private String enabled;
......
...@@ -48,6 +48,12 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -48,6 +48,12 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
// 令牌前缀 // 令牌前缀
@Value("${token.prefix:}") @Value("${token.prefix:}")
private String tokenPrefix; private String tokenPrefix;
// redis db
@Value("${spring.redis.database:}")
private Integer db;
@Value("${token.database:1}")
private Integer portalDb;
protected static final Long MILLIS_SECOND = 1000l; protected static final Long MILLIS_SECOND = 1000l;
...@@ -71,6 +77,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -71,6 +77,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
*/ */
@Override @Override
public IUser getLoginUser(HttpServletRequest request) { public IUser getLoginUser(HttpServletRequest request) {
// 获取请求携带的令牌 // 获取请求携带的令牌
String token = getToken(request); String token = getToken(request);
if (StringUtils.isNotEmpty(token)) { if (StringUtils.isNotEmpty(token)) {
...@@ -78,7 +85,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService { ...@@ -78,7 +85,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
Claims claims = parseToken(token); Claims claims = parseToken(token);
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY); String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid); String userKey = getTokenKey(uuid);
//cacheService.select(portalDb);
String userStr = cacheService.get(userKey); String userStr = cacheService.get(userKey);
// cacheService.select(db);
if (StringUtils.isNotEmpty(userStr)) { if (StringUtils.isNotEmpty(userStr)) {
JSONObject userObj = JSON.parseObject(userStr); JSONObject userObj = JSON.parseObject(userStr);
Long userId = userObj.getLongValue("id"); Long userId = userObj.getLongValue("id");
......
package com.mortals.xhx.module.area.service; package com.mortals.xhx.module.area.service;
import com.mortals.framework.service.ICRUDCacheService; import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import java.util.List; import java.util.List;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
/** /**
* AreaService * AreaService
* *
...@@ -50,5 +50,5 @@ public interface AreaService extends ICRUDCacheService<AreaEntity,Long> { ...@@ -50,5 +50,5 @@ public interface AreaService extends ICRUDCacheService<AreaEntity,Long> {
* @param context * @param context
* @return * @return
*/ */
List<AreaTreeSelect> getListByParentId(String parentId,Context context); List<AreaTreeSelect> getListByParentId(String parentId, Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.area.service.impl; package com.mortals.xhx.module.area.service.impl;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.module.site.model.SiteQuery; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.module.site.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.xhx.common.code.SatusEnum; import com.mortals.xhx.common.code.SatusEnum;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.area.dao.AreaDao; import com.mortals.xhx.module.area.dao.AreaDao;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.service.AreaService; import com.mortals.xhx.module.area.service.AreaService;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.*; import java.util.*;
......
...@@ -2,15 +2,12 @@ package com.mortals.xhx.module.area.web; ...@@ -2,15 +2,12 @@ package com.mortals.xhx.module.area.web;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BasePhpCRUDJsonMappingController;
import com.mortals.xhx.base.system.param.service.ParamService; import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.area.model.AreaEntity; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery; import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect; import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.module.area.service.AreaService; import com.mortals.xhx.module.area.service.AreaService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -20,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -20,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* *
* 区域 * 区域
...@@ -36,7 +33,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic ...@@ -36,7 +33,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
private ParamService paramService; private ParamService paramService;
public AreaController(){ public AreaController(){
super.setFormClass(AreaForm.class);
super.setModuleDesc( "区域"); super.setModuleDesc( "区域");
} }
...@@ -51,31 +47,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic ...@@ -51,31 +47,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
super.init( model, context); super.init( model, context);
} }
@PostMapping("list/exclude")
public String excludeList(AreaForm form) {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
String busiDesc = "查询" + this.getModuleDesc();
Long id = form.getId()[0];
int code=VALUE_RESULT_SUCCESS;
try {
List<AreaEntity> collect = this.service.find(new AreaQuery()).stream().map(item -> {
if (item.getId().intValue() == id || ArrayUtils.contains(StringUtils.split(item.getAncestors(), ","), id + "")) {
return null;
}
return item;
}).filter(f -> f != null).collect(Collectors.toList());
model.put("result", collect);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/** /**
* 获取站点下拉树列表 * 获取站点下拉树列表
......
package com.mortals.xhx.module.area.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
/**
* Area
*
* 区域 Form
*
* @author zxfei
* @date 2022-01-12
*/
public class AreaForm extends BaseCRUDFormLong<AreaEntity> {
private AreaEntity entity = new AreaEntity();
private AreaQuery query = new AreaQuery();
public AreaForm(){
}
@Override
public AreaEntity getEntity() {
return entity;
}
public void setArea(AreaEntity entity) {
this.entity = entity;
}
@Override
public AreaQuery getQuery() {
return query;
}
public void setQuery(AreaQuery query) {
this.query = query;
}
}
\ No newline at end of file
...@@ -3,10 +3,8 @@ package com.mortals.xhx.feign.area; ...@@ -3,10 +3,8 @@ package com.mortals.xhx.feign.area;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.feign.IFeign; import com.mortals.xhx.feign.IFeign;
import com.mortals.xhx.feign.req.BaseUserQuery; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.feign.req.BaseUserReq;
import com.mortals.xhx.feign.rsp.ApiResp; import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.feign.rsp.UserRsp;
import feign.hystrix.FallbackFactory; import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
...@@ -22,6 +20,29 @@ import org.springframework.web.bind.annotation.*; ...@@ -22,6 +20,29 @@ import org.springframework.web.bind.annotation.*;
@FeignClient(name = "base-manager", path = "/zwfw", fallback = AreaFeignFallbackFactory.class) @FeignClient(name = "base-manager", path = "/zwfw", fallback = AreaFeignFallbackFactory.class)
public interface IApiAreaFeign extends IFeign { public interface IApiAreaFeign extends IFeign {
/**
* 查看区域列表信息
*
* @param query
* @return
*/
@PostMapping(value = "/area/list")
String list(@RequestBody AreaEntity query,
@RequestHeader(name = "Authorization", required = true) String token);
/**
* 查看区域信息
*
* @param id
* @return
*/
@GetMapping(value = "/area/info")
String viewAreaInfo(@RequestParam(value = "id") Long id,
@RequestHeader(name = "Authorization", required = true) String token);
/** /**
* 查看区域子信息 * 查看区域子信息
* *
...@@ -41,6 +62,26 @@ class AreaFeignFallbackFactory implements FallbackFactory<IApiAreaFeign> { ...@@ -41,6 +62,26 @@ class AreaFeignFallbackFactory implements FallbackFactory<IApiAreaFeign> {
@Override @Override
public IApiAreaFeign create(Throwable t) { public IApiAreaFeign create(Throwable t) {
return new IApiAreaFeign() { return new IApiAreaFeign() {
@Override
public String list(AreaEntity query, String token) {
log.error("暂时无法获取区域列表信息,请稍后再试!query:{},token:{}", JSON.toJSONString(query), token);
log.error(t.getMessage());
ApiResp<String> failResp = new ApiResp<>();
failResp.setCode(ApiRespCodeEnum.FAILED.getValue());
failResp.setMsg("暂时无法获取区域列表信息,请稍后再试!");
return JSON.toJSONString(failResp);
}
@Override
public String viewAreaInfo(Long id, String token) {
log.error("暂时无法获取区域信息,请稍后再试!parentId:{},token:{}", id, token);
log.error(t.getMessage());
ApiResp<String> failResp = new ApiResp<>();
failResp.setCode(ApiRespCodeEnum.FAILED.getValue());
failResp.setMsg("暂时无法获取区域信息,请稍后再试!");
return JSON.toJSONString(failResp);
}
@Override @Override
public String getListByParentId(String parentId, String token) { public String getListByParentId(String parentId, String token) {
log.error("暂时无法获取区域信息,请稍后再试!parentId:{},token:{}", parentId, token); log.error("暂时无法获取区域信息,请稍后再试!parentId:{},token:{}", parentId, token);
......
package com.mortals.xhx.module.area.model; package com.mortals.xhx.module.area.model;
import java.util.List;
import java.util.ArrayList;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.area.model.vo.AreaVo; import com.mortals.xhx.module.area.model.vo.AreaVo;
/** /**
* 区域实体对象 * 区域实体对象
* *
......
package com.mortals.xhx.module.area.model; package com.mortals.xhx.module.area.model;
import java.util.List; import java.util.List;
import com.mortals.xhx.module.area.model.AreaEntity;
/** /**
* 区域查询对象 * 区域查询对象
* *
......
package com.mortals.xhx.module.area.model; package com.mortals.xhx.module.area.model;
import java.util.List;
import java.util.ArrayList;
import com.mortals.framework.common.code.YesNo;
import com.mortals.xhx.module.area.model.vo.AreaVo;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mortals.xhx.module.site.model.SiteEntity;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.util.stream.Collectors; import java.util.ArrayList;
import java.util.List;
/** /**
* 区域前端映射树结构实体类 * 区域前端映射树结构实体类
...@@ -69,13 +63,5 @@ public class AreaTreeSelect implements Serializable { ...@@ -69,13 +63,5 @@ public class AreaTreeSelect implements Serializable {
this.icon = "el-icon-folder"; this.icon = "el-icon-folder";
} }
public AreaTreeSelect(SiteEntity entity) {
this.id = entity.getId().toString();
this.label = entity.getSiteName();
this.isLeaf = true;
this.type = "site";
this.icon = "el-icon-document";
}
} }
\ No newline at end of file
package com.mortals.xhx.module.area.model.vo; package com.mortals.xhx.module.area.model.vo;
import com.mortals.framework.model.BaseEntity;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.area.model.AreaEntity; import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.site.model.SiteEntity;
import lombok.Data; import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* 区域视图对象 * @author: zxfei
* * @date: 2022/6/6 14:58
* @author zxfei * @description:
* @date 2022-01-12 **/
*/
@Data @Data
public class AreaVo extends BaseEntityLong { public class AreaVo extends BaseEntityLong {
/** 子区域 */
private List<AreaEntity> children = new ArrayList<>(); private List<AreaEntity> children = new ArrayList<>();
}
}
\ No newline at end of file
...@@ -2570,6 +2570,242 @@ dict|object|字典对象 ...@@ -2570,6 +2570,242 @@ dict|object|字典对象
} }
``` ```
## 区域
### 查询区域列表
**请求URL:** area/list
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 查询区域
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
page|Integer|当前页|否|-
size|Integer|每页条数|否|-
name|String|区域名称|否|-
**请求样例:**
```
{
"name":"zt2h08",
"page":1,
"size":10
}
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
&emsp;per_page|Integer|每页条数|-
&emsp;total|Integer|总条数|-
&emsp;last_page|Integer|总页数|-
&emsp;current_page|Integer|当前页|-
&emsp;data|array|结果集列表|数组
&emsp;&emsp;id|Long|序号,主键,自增长|-
&emsp;&emsp;ancestors|String|祖级列表,逗号分隔|-
&emsp;&emsp;name|String|区域名称|-
&emsp;&emsp;iid|String|一体化的ID号|-
&emsp;&emsp;parentId|String|一体化的父id|-
&emsp;&emsp;haveSonArea|String|是否有下级区域(True.是,False.否)|-
&emsp;&emsp;haveSonDept|String|是否有下级部门(True.是,False.否)|-
&emsp;&emsp;haveGetDept|String|是否获取部门(true.是,false.否)|-
&emsp;&emsp;haveGetMatterList|String|是否获取事项列表(true.是,false.否)|-
&emsp;&emsp;areaCode|String|区域编码|-
&emsp;&emsp;areaLevel|Integer|区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)|-
&emsp;&emsp;shortName|String|名称简称|-
&emsp;&emsp;domain|String|访问地址|-
&emsp;&emsp;status|Integer|区域状态 (0.停用,1.正常)|-
&emsp;&emsp;createTime|Date|创建时间|-
&emsp;&emsp;createUserId|Long|创建用户|-
&emsp;&emsp;updateTime|Date|修改时间|-
dict|object|字典对象|-
&emsp;haveSonArea|object|字典属性对象,详见附录|-
&emsp;haveSonDept|object|字典属性对象,详见附录|-
&emsp;haveGetDept|object|字典属性对象,详见附录|-
&emsp;haveGetMatterList|object|字典属性对象,详见附录|-
&emsp;areaLevel|object|字典属性对象,详见附录|-
&emsp;status|object|字典属性对象,详见附录|-
**响应消息样例:**
```
{
"code":1,
"data":{
"per_page":10,
"total":0,
"data":[],
"last_page":0,
"current_page":1
},
"query":{
"modelCode":"phxt1",
"modelName":"排号系统"
}
}
```
### 查看区域
**请求URL:** area/info
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 查看区域,返回实例详细信息
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
id|Long|区域ID|是|-
**请求样例:**
```
http://localhost/area/info?id=549
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
&emsp;id|Long|序号,主键,自增长|-
&emsp;ancestors|String|祖级列表,逗号分隔|-
&emsp;name|String|区域名称|-
&emsp;iid|String|一体化的ID号|-
&emsp;parentId|String|一体化的父id|-
&emsp;haveSonArea|String|是否有下级区域(True.是,False.否)|-
&emsp;haveSonDept|String|是否有下级部门(True.是,False.否)|-
&emsp;haveGetDept|String|是否获取部门(true.是,false.否)|-
&emsp;haveGetMatterList|String|是否获取事项列表(true.是,false.否)|-
&emsp;areaCode|String|区域编码|-
&emsp;areaLevel|Integer|区域等级(1.省,2.地市州,3.区县,4.街道,5.社区)|-
&emsp;shortName|String|名称简称|-
&emsp;domain|String|访问地址|-
&emsp;status|Integer|区域状态 (0.停用,1.正常)|-
&emsp;createTime|Date|创建时间|-
&emsp;createUserId|Long|创建用户|-
&emsp;updateTime|Date|修改时间|-
dict|object|字典对象|-
&emsp;haveSonArea|object|字典属性对象,详见附录|-
&emsp;haveSonDept|object|字典属性对象,详见附录|-
&emsp;haveGetDept|object|字典属性对象,详见附录|-
&emsp;haveGetMatterList|object|字典属性对象,详见附录|-
&emsp;areaLevel|object|字典属性对象,详见附录|-
&emsp;status|object|字典属性对象,详见附录|-
**响应消息样例:**
```
```
### 查看区域子信息
**请求URL:** area/getListByParentId
**请求方式:** GET
**内容类型:** application/json;charset=utf-8
**简要描述:** 查看区域,返回实例详细信息
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
parentId|String|区域树父id|是|0为树的顶层节点
**请求样例:**
```
http://localhost/area/getListByParentId?parentId=549
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
&emsp;data|object|数据对象|-
&emsp;&emsp;id|String|节点ID|-
&emsp;&emsp;label|String|节点名称|-
&emsp;&emsp;areaCode|String|区域编码|-
&emsp;&emsp;isLeaf|String|是否叶子节点|-
&emsp;&emsp;type|String|节点类型|type='site'表示站点,type='area'表示区域
&emsp;&emsp;icon|String|图标|-
&emsp;&emsp;children|Arrays|子节点|-
**响应消息样例:**
```
```
### 获取所有区域信息
**请求URL:** area/treeselect
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 返回所有区域信息
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
**请求样例:**
```
http://localhost/area/treeselect
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
&emsp;data|Arrays|数组对象|-
&emsp;&emsp;id|String|节点ID|-
&emsp;&emsp;label|String|节点名称|-
&emsp;&emsp;areaCode|String|区域编码|-
&emsp;&emsp;isLeaf|String|是否叶子节点|-
&emsp;&emsp;type|String|节点类型|-
&emsp;&emsp;icon|String|图标|-
&emsp;&emsp;children|Arrays|子节点|-
**响应消息样例:**
```
{
"code": 1,
"data": {
"id":9986,
}
}
```
## 字典附录 ## 字典附录
### userType ### userType
字典参数key|字典参数值|其它 字典参数key|字典参数值|其它
......
package com.mortals.xhx.base.framework.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author: zxfei
* @date: 2022/6/6 15:05
* @description:添加跨域响应
**/
@Component
public class CrossInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
return true;
}
}
...@@ -84,9 +84,13 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi ...@@ -84,9 +84,13 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
} }
@RequestMapping("logout") @RequestMapping("logout")
public void logout() throws Exception { public String logout() throws Exception {
recordSysLog(request, "退出登录"); recordSysLog(request, "退出登录");
super.removeCurrUser(request); super.removeCurrUser(request);
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户退出系统成功!");
return ret.toJSONString();
} }
@RequestMapping("index") @RequestMapping("index")
......
package com.mortals.xhx.module.area.dao;
import com.mortals.framework.dao.ICRUDDao;
import com.mortals.xhx.module.area.model.AreaEntity;
/**
* 区域Dao
* 区域 DAO接口
*
* @author zxfei
* @date 2022-01-12
*/
public interface AreaDao extends ICRUDDao<AreaEntity,Long>{
}
package com.mortals.xhx.module.area.dao.ibatis;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.dao.AreaDao;
import org.springframework.stereotype.Repository;
/**
* 区域DaoImpl DAO接口
*
* @author zxfei
* @date 2022-01-12
*/
@Repository("areaDao")
public class AreaDaoImpl extends BaseCRUDDaoMybatis<AreaEntity, Long> implements AreaDao {
}
package com.mortals.xhx.module.area.service;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICRUDService;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import java.util.List;
/**
* AreaService
* <p>
* 区域 service接口
*
* @author zxfei
* @date 2022-01-12
*/
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);
/**
* 根据父id查询子节点
*
* @param parentId
* @param context
* @return
*/
String getListByParentId(String parentId,String token, Context context);
/**
* 根据id查询区域详细信息
*
* @param id
* @param context
* @return
*/
String viewArea(Long id,String token, Context context);
/**
* 查询区域列表信息
* @param query
* @param token
* @param context
* @return
*/
String list(AreaEntity query, String token, Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.area.service.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.feign.area.IApiAreaFeign;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.feign.rsp.ApiResp;
import com.mortals.xhx.module.area.dao.AreaDao;
import com.mortals.xhx.module.area.service.AreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* AreaService
* 区域 service实现
*
* @author zxfei
* @date 2022-01-12
*/
@Service("areaService")
@Slf4j
public class AreaServiceImpl extends AbstractCRUDServiceImpl<AreaDao, AreaEntity, Long> implements AreaService {
@Autowired
private IApiAreaFeign apiAreaFeign;
@Override
public String getListByParentId(String parentId, String token, Context context) {
if (ObjectUtils.isEmpty(parentId)) {
parentId = "0";
}
String resp = apiAreaFeign.getListByParentId(parentId, token);
ApiResp apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取区域数据失败:" + apiResp.getMsg());
}
log.info("getListByParentId=>{}", resp);
return resp;
}
@Override
public String viewArea(Long id, String token, Context context) {
String resp = apiAreaFeign.viewAreaInfo(id, token);
ApiResp apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取区域数据失败:" + apiResp.getMsg());
}
log.info("viewArea=>{}", resp);
return resp;
}
@Override
public String list(AreaEntity query, String token, Context context) {
log.info("areaListReq==》{}", JSON.toJSONString(query));
String resp = apiAreaFeign.list(query, token);
ApiResp apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
throw new AppException("获取区域列表数据失败:" + apiResp.getMsg());
}
log.info("listAreaResp=>{}", resp);
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());
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<AreaEntity> list, AreaEntity t) {
return getChildList(list, t).size() > 0 ? true : false;
}
}
\ No newline at end of file
package com.mortals.xhx.module.area.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.area.model.AreaEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.model.AreaTreeSelect;
import com.mortals.xhx.module.area.service.AreaService;
import com.mortals.xhx.module.param.service.ParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 区域
*
* @author zxfei
* @date 2022-01-19
*/
@RestController
@RequestMapping("area")
public class AreaController extends BaseCRUDJsonBodyMappingController<AreaService, AreaEntity, Long> {
@Autowired
private ParamService paramService;
@Autowired
private IAuthTokenService authTokenService;
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);
}
@Override
public String view(Long id) {
if (id == null) {
return this.createFailJsonResp("请选择待查看" + this.getModuleDesc() + "信息");
} else {
String busiDesc = "查看" + this.getModuleDesc();
Context context = this.getContext();
try {
String token = authTokenService.getToken(request);
String resp = this.service.viewArea(id, token, context);
this.recordSysLog(this.request, busiDesc + " 【成功】");
return resp;
} catch (Exception e) {
this.doException(this.request, busiDesc, null, e);
return this.createFailJsonResp(e.getMessage() == null ? "系统异常" : e.getMessage());
}
}
}
@Override
public String list(@RequestBody AreaEntity query) {
Map<String, Object> model = new HashMap<>();
Context context = this.getContext();
String busiDesc = "查询" + this.getModuleDesc();
try {
String token = authTokenService.getToken(request);
String resp = this.service.list(query, token, context);
recordSysLog(request, busiDesc + " 【成功】");
return resp;
} catch (Exception e) {
this.doException(request, busiDesc, model, e);
return this.createFailJsonResp(e.getMessage() == null ? "系统异常" : e.getMessage());
}
}
/**
* 获取站点下拉树列表
*/
@PostMapping("treeselect")
public String treeselect() {
Map<String, Object> model = new HashMap<>();
JSONObject ret = new JSONObject();
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);
recordSysLog(request, busiDesc + " 【成功】");
} catch (Exception e) {
code = VALUE_RESULT_FAILURE;
this.doException(request, busiDesc, model, e);
}
ret.put(KEY_RESULT_DATA, model);
ret.put(KEY_RESULT_CODE, code);
return ret.toJSONString();
}
/**
* 根据parentId查询子信息
*/
@GetMapping(value = "getListByParentId")
public String getListByParentId(String parentId) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
String token = authTokenService.getToken(request);
String retStr = this.service.getListByParentId(parentId, token, getContext());
recordSysLog(request, busiDesc + "【成功】");
return retStr;
} catch (Exception e) {
log.error("根据parentId查询子信息错误", 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