From 2bed48c6704b6e603b544036fa7a60667b8f0229 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Thu, 9 Jan 2020 17:56:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=92=E8=89=B2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/plugin/IApiConsts.java | 4 ++ .../controller/apis/role/RoleController.java | 53 +++++++++++++++++ .../oauth/service/role/IRoleService.java | 20 +++++++ .../service/role/impl/RoleServiceImpl.java | 57 +++++++++++++++++++ .../com/cm/common/pojo/vos/kv/KeyValueVO.java | 14 +++++ 5 files changed, 148 insertions(+) create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/role/RoleController.java create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/IRoleService.java create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/impl/RoleServiceImpl.java create mode 100644 cloud-common/src/main/java/com/cm/common/pojo/vos/kv/KeyValueVO.java diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java index 1f289a7..bf2194a 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java @@ -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"; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/role/RoleController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/role/RoleController.java new file mode 100644 index 0000000..6d3712e --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/role/RoleController.java @@ -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 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); + } + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/IRoleService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/IRoleService.java new file mode 100644 index 0000000..052092e --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/IRoleService.java @@ -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); +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/impl/RoleServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/impl/RoleServiceImpl.java new file mode 100644 index 0000000..526523f --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/role/impl/RoleServiceImpl.java @@ -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 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); + } + +} diff --git a/cloud-common/src/main/java/com/cm/common/pojo/vos/kv/KeyValueVO.java b/cloud-common/src/main/java/com/cm/common/pojo/vos/kv/KeyValueVO.java new file mode 100644 index 0000000..cc39fa6 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/pojo/vos/kv/KeyValueVO.java @@ -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 { +}