新增角色列表查询

This commit is contained in:
wenc000 2020-01-09 17:56:11 +08:00
parent 0d7caf1781
commit 2bed48c670
5 changed files with 148 additions and 0 deletions

View File

@ -118,4 +118,8 @@ public interface IApiConsts {
* 部门zTree
*/
String LIST_ZTREE_DEPARTMENT = "%s/resource/department/listztreedepartment";
/**
* 角色zTree
*/
String LIST_ZTREE_ROLE = "%s/resource/role/listztreerole";
}

View File

@ -0,0 +1,53 @@
package com.cm.common.plugin.oauth.controller.apis.role;
import com.alibaba.fastjson.JSONArray;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.oauth.service.role.IRoleService;
import com.cm.common.pojo.dtos.ZTreeDTO;
import com.cm.common.result.ErrorResult;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: RoleController
* @Description: 角色管理
* @Author: WangGeng
* @Date: 2020/1/9 17:04
* @Version: 1.0
**/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "职位管理")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/role")
public class RoleController extends AbstractController {
@Autowired
private IRoleService roleService;
@ApiOperation(value = "zTree列表", notes = "zTree列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "上级ID", paramType = "form", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listztreerole")
public JSONArray listZTreeRole() throws SearchException {
Map<String, Object> params = requestParams();
String roleParentId = "0";
if (!StringUtils.isBlank(params.get("id") == null ? null : params.get("id").toString())) {
roleParentId = params.get("id").toString();
}
return roleService.listZTreeRole(roleParentId);
}
}

View File

@ -0,0 +1,20 @@
package com.cm.common.plugin.oauth.service.role;
import com.alibaba.fastjson.JSONArray;
import com.cm.common.pojo.dtos.ZTreeDTO;
import java.util.List;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: IRoleService
* @Description: 角色管理
* @Author: WangGeng
* @Date: 2020/1/9 17:12
* @Version: 1.0
**/
public interface IRoleService {
JSONArray listZTreeRole(String roleParentId);
}

View File

@ -0,0 +1,57 @@
package com.cm.common.plugin.oauth.service.role.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cm.common.base.AbstractService;
import com.cm.common.config.properties.ApiPathProperties;
import com.cm.common.exception.AccessTokenException;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.IApiConsts;
import com.cm.common.plugin.oauth.service.role.IRoleService;
import com.cm.common.plugin.oauth.token.ClientTokenManager;
import com.cm.common.plugin.utils.RestTemplateUtil;
import com.cm.common.pojo.dtos.ZTreeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.OAuth2ClientProperties;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: RoleServiceImpl
* @Description: 角色管理
* @Author: WangGeng
* @Date: 2020/1/9 17:13
* @Version: 1.0
**/
@Service
public class RoleServiceImpl extends AbstractService implements IRoleService {
@Autowired
private OAuth2ClientProperties oAuth2ClientProperties;
@Autowired
private ApiPathProperties apiPathProperties;
@Autowired
private RestTemplateUtil restTemplateUtil;
@Override
public JSONArray listZTreeRole(String roleParentId) {
Map<String, Object> params = new HashMap<>(1);
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
params.put("id", roleParentId);
String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_ZTREE_ROLE, apiPathProperties.getUserCenter()), params);
if (result == null) {
throw new AccessTokenException("认证失败");
}
if (result.isEmpty()) {
throw new SearchException("获取列表失败");
}
return JSONArray.parseArray(result);
}
}

View File

@ -0,0 +1,14 @@
package com.cm.common.pojo.vos.kv;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: KeyValueVO
* @Description: 键值对
* @Author: WangGeng
* @Date: 2020/1/9 14:40
* @Version: 1.0
**/
public class KeyValueVO {
}