Commit 21712f0c authored by 赵啸非's avatar 赵啸非

添加多级查询区域下站点

parent 2359447c
package com.mortals.xhx.base.framework.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
......@@ -12,6 +16,24 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Bean
public CorsFilter corsFilter(){
//初始化配置对象
CorsConfiguration configuration = new CorsConfiguration();
//允许跨域访问的域名
configuration.addAllowedOrigin("*");
// configuration.setAllowCredentials(true); //运行携带cookie
configuration.addAllowedMethod("*"); //代表所有请求方法
configuration.addAllowedHeader("*"); //允许携带任何头信息
//初始化cors配置源对象
UrlBasedCorsConfigurationSource configurationSource=new UrlBasedCorsConfigurationSource();
configurationSource.registerCorsConfiguration("/**",configuration);
//返回CorSfilter实例,参数
return new CorsFilter(configurationSource);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
......
......@@ -12,5 +12,5 @@ import java.util.List;
@Data
public class SitePdu {
/** 区域IdList */
private List<String> areaIDList;
private List<String> areaCodeList;
}
......@@ -471,6 +471,49 @@ msg|String|消息|-
```
### 用户站点授权
**请求URL:** user/siteAuth
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 给用户授权站点
**请求参数:**
参数名称|类型|必填|描述
:---|:---|:---|:-------
userId|Long|是|用户ID
areaCodeList|Arrays|否|所属区域code列表
**请求样例:**
```
{
"userId":2,
"areaCodeList":["510105521000","513400000000"]
}
```
**响应参数:**
参数名称 |参数类型|描述
:---|:---|:------
code|Integer|结果码(-1.失败,1.成功)
msg|String|消息
data|object|数据对象
**响应消息样例:**
```
{
"msg":"新增模块成功",
"code":1,
"data":{}
}
}
```
## 角色信息
### 查询角色信息列表
......
......@@ -62,6 +62,6 @@ public interface AreaService extends ICRUDService<AreaEntity, Long> {
* @param context
* @return
*/
String getFlatSitesByAreaIds(AreaQuery query, Context context);
String getFlatSitesByAreaCodes(AreaQuery query, Context context);
}
\ No newline at end of file
......@@ -9,7 +9,6 @@ import com.mortals.xhx.common.pdu.SitePdu;
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;
......@@ -18,8 +17,6 @@ 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;
/**
......@@ -89,10 +86,10 @@ public class AreaServiceImpl extends AbstractCRUDServiceImpl<AreaDao, AreaEntity
}
@Override
public String getFlatSitesByAreaIds(AreaQuery query, Context context) {
public String getFlatSitesByAreaCodes(AreaQuery query, Context context) {
log.info("getFlatSitesByAreaIds=={}",JSON.toJSONString(query));
SitePdu sitePdu = new SitePdu();
sitePdu.setAreaIDList(query.getIdList().stream().map(item->item.toString()).collect(Collectors.toList()));
sitePdu.setAreaCodeList(query.getAreaCodeList());
String resp = apiAreaFeign.getFlatSitesByAreaIds(sitePdu);
ApiResp apiResp = JSON.parseObject(resp, ApiResp.class);
if (apiResp.getCode() != YesNoEnum.YES.getValue()) {
......
......@@ -123,24 +123,6 @@ public class AreaController extends BaseCRUDJsonBodyMappingController<AreaServic
}
@PostMapping(value = "getFlatSitesByAreaIds")
@UnAuth
public String getFlatSitesByAreaIds(@RequestBody AreaQuery query) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = "查询" + this.getModuleDesc() + "子节点";
try {
String retStr = this.service.getFlatSitesByAreaIds(query, getContext());
recordSysLog(request, busiDesc + "【成功】");
return retStr;
} catch (Exception e) {
log.error("查询站点信息错误", 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
package com.mortals.xhx.module.user.model;
public class UserEntityExt extends UserEntity {
/** 用户已分配角色id,多个角色使用“,”隔开 */
private String roleIds;
/** 用户已分配角色名称,多个角色使用“,”隔开 */
private String roleNames;
public String getRoleIds() {
return roleIds;
}
import lombok.Data;
import java.util.List;
@Data
public class UserEntityExt extends UserEntity {
public void setRoleIds(String roleIds) {
this.roleIds = roleIds;
}
private Long userId;
public String getRoleNames() {
return roleNames;
}
private List<String> areaCodeList;
public void setRoleNames(String roleNames) {
this.roleNames = roleNames;
}
}
......@@ -65,4 +65,7 @@ public interface UserService extends ICRUDService<UserEntity,Long>{
Result<UserEntityExt> findExt(UserEntity params, PageInfo pageInfo, Context context) throws AppException;
void siteAuth(UserEntityExt entityExt,Context context);
}
\ No newline at end of file
......@@ -6,15 +6,12 @@ import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.SecurityUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.menu.model.MenuEntity;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.area.service.AreaService;
import com.mortals.xhx.module.menu.service.MenuService;
import com.mortals.xhx.module.role.model.RoleQuery;
import com.mortals.xhx.module.role.model.RoleUserEntity;
import com.mortals.xhx.module.role.model.RoleUserQuery;
import com.mortals.xhx.module.role.service.RoleService;
import com.mortals.xhx.module.role.service.RoleUserService;
......@@ -46,6 +43,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
private RoleUserService roleUserService;
@Autowired
private RoleService roleService;
@Autowired
private AreaService areaService;
/* @Override
......@@ -81,7 +80,6 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
}
}
@Override
......@@ -95,7 +93,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
throw new AppException("你没有权限执行该操作");
}
this.doHandlerUser(entity);
if(!ObjectUtils.isEmpty(entity.getRoleId())){
if (!ObjectUtils.isEmpty(entity.getRoleId())) {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
roleUserQuery.setRoleIdList(Arrays.asList(Long.parseLong(entity.getRoleId())));
......@@ -180,8 +178,8 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
@Override
public Result<UserEntityExt> findExt(UserEntity params, PageInfo pageInfo, Context context) throws AppException {
UserQuery query = new UserQuery();
BeanUtils.copyProperties(params,query);
if(StringUtils.isNotEmpty(params.getQuery())){
BeanUtils.copyProperties(params, query);
if (StringUtils.isNotEmpty(params.getQuery())) {
StringBuffer condition = new StringBuffer("%");
condition.append(params.getQuery()).append("%");
UserQuery condition1 = new UserQuery();
......@@ -199,14 +197,26 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
orConditionList.add(condition4);
query.setOrConditionList(orConditionList);
}
return getDao().getListExt(query,pageInfo);
return getDao().getListExt(query, pageInfo);
}
@Override
public void siteAuth(UserEntityExt entityExt, Context context) {
if (!ObjectUtils.isEmpty(entityExt.getUserId())) {
throw new AppException("用户ID不能为空!");
}
String siteIds = areaService.getFlatSitesByAreaCodes(new AreaQuery().areaCodeList(entityExt.getAreaCodeList()), context);
UserEntity userEntity = this.get(entityExt.getUserId(), context);
userEntity.setAreaCodes(entityExt.getAreaCodeList().stream().collect(Collectors.joining(",")));
userEntity.setSiteIds(siteIds);
this.update(userEntity, context);
}
@Override
protected void saveAfter(UserEntity entity, Context context) throws AppException {
super.saveAfter(entity, context);
if(!ObjectUtils.isEmpty(entity.getRoleId())){
if (!ObjectUtils.isEmpty(entity.getRoleId())) {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
roleUserQuery.setRoleIdList(Arrays.asList(Long.parseLong(entity.getRoleId())));
......
package com.mortals.xhx.module.user.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.area.model.AreaQuery;
import com.mortals.xhx.module.param.service.ParamService;
import com.mortals.xhx.module.role.model.RoleEntity;
import com.mortals.xhx.module.role.model.RoleQuery;
......@@ -11,6 +13,7 @@ import com.mortals.xhx.module.role.model.RoleUserEntity;
import com.mortals.xhx.module.role.model.RoleUserQuery;
import com.mortals.xhx.module.role.service.RoleService;
import com.mortals.xhx.module.role.service.RoleUserService;
import com.mortals.xhx.module.user.model.UserEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -115,4 +118,28 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
ret.put("data", model);
return ret.toJSONString();
}
/**
* 站点授权
* @param query
* @return
*/
@PostMapping(value = "siteAuth")
public String siteAuth(@RequestBody UserEntityExt query) {
JSONObject ret = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = this.getModuleDesc() + "站点授权";
try {
//String retStr = this.service.getFlatSitesByAreaIds(query, getContext());
recordSysLog(request, busiDesc + "【成功】");
//return retStr;
} catch (Exception e) {
log.error("查询站点信息错误", 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
......@@ -28,5 +28,5 @@ Authorization: {{authToken}}
Content-Type: application/json
{
"idList":[1,2]
"idList":[510105521000,513425000000]
}
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