From 09eebe843bfa610784ba3fdd6765099293b8e676 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Wed, 4 Sep 2019 09:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=B3=BB=E7=BB=9F=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/plugin/IApiConsts.java | 5 + .../controller/apis/user/UserController.java | 15 ++- .../controller/routes/RouteController.java | 4 + .../routes/user/UserRouteController.java | 18 ++- .../oauth/service/user/IUserService.java | 10 ++ .../service/user/impl/UserServiceImpl.java | 13 +++ .../resources/templates/user/user-detail.html | 109 ++++++++++++++++++ .../main/resources/templates/tree/tree.html | 3 + .../config/properties/SystemProperties.java | 56 +++++++++ .../cm/common/constants/ISystemConstant.java | 4 + .../cm/common/token/app/AppTokenManager.java | 8 +- .../cm/common/token/app/entity/AppToken.java | 13 ++- 12 files changed, 250 insertions(+), 8 deletions(-) create mode 100644 cloud-common-plugin-oauth/src/main/resources/templates/user/user-detail.html create mode 100644 cloud-common/src/main/java/com/cm/common/config/properties/SystemProperties.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 3602fed..977612b 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 @@ -68,4 +68,9 @@ public interface IApiConsts { * 获取用户职位列表 */ String LIST_USER_POSITION = "%s/resource/position/listuserposition/%s"; + + /** + * 用户详情 + */ + String GET_USER_DETAIL = "%s/resource/user/getuserdetail/%s"; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java index 9857990..6e7744d 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/user/UserController.java @@ -1,6 +1,7 @@ package com.cm.common.plugin.oauth.controller.apis.user; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.AccessTokenException; @@ -127,4 +128,16 @@ public class UserController extends AbstractController { return userService.listUserDepartmentUserByPosition(params); } -} + @ApiOperation(value = "用户详情", notes = "用户详情接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("getuserdetail/{userId}") + public JSONObject getUserDetail(@PathVariable("userId") String userId) throws SearchException, AccessTokenException { + Map params = getParams(); + params.put("userId", userId); + return userService.getUserDetail(params); + } + +} \ No newline at end of file diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/RouteController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/RouteController.java index 1c2b4fd..805b585 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/RouteController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/RouteController.java @@ -2,6 +2,7 @@ package com.cm.common.plugin.oauth.controller.routes; import com.cm.common.component.SecurityComponent; import com.cm.common.config.properties.OauthProperties; +import com.cm.common.config.properties.SystemProperties; import com.cm.common.exception.SearchException; import com.cm.common.pojo.bos.UserInfoBO; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,8 @@ public class RouteController { private SecurityComponent securityComponent; @Autowired private OauthProperties oauthProperties; + @Autowired + private SystemProperties systemProperties; /** * 首页 @@ -35,6 +38,7 @@ public class RouteController { UserInfoBO userInfoBO = securityComponent.getCurrentUser(); mv.addObject("userUsername", userInfoBO.getUserUsername()); mv.addObject("oauthServer", oauthProperties.getOauthServer()); + mv.addObject("title", systemProperties.getTitle()); return mv; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java index 7f757de..e133103 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/routes/user/UserRouteController.java @@ -2,6 +2,10 @@ package com.cm.common.plugin.oauth.controller.routes.user; import com.cm.common.base.AbstractController; import com.cm.common.constants.ISystemConstant; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,19 +21,23 @@ import org.springframework.web.servlet.ModelAndView; * @Date: 2019-07-29 21:22 * @Version: 1.0 **/ +@Api(tags = ISystemConstant.ROUTE_TAGS_PREFIX + "用户管理") @Controller @RequestMapping(ISystemConstant.ROUTE_PREFIX + "/user") public class UserRouteController extends AbstractController { - /** - * 部门用户页面 - * - * @return - */ + @ApiOperation(value = "部门用户页面", notes = "部门用户页面接口") @GetMapping("departmentuser") public ModelAndView departmentUser() { ModelAndView mv = new ModelAndView("user/select-department-user"); return mv; } + @ApiOperation(value = "用户详情页面", notes = "用户详情页面接口") + @GetMapping("userdetail") + public ModelAndView userDetail() { + ModelAndView mv = new ModelAndView("user/user-detail.html"); + return mv; + } + } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java index d251333..d3ac9bb 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/IUserService.java @@ -1,6 +1,7 @@ package com.cm.common.plugin.oauth.service.user; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.cm.common.exception.AccessTokenException; import com.cm.common.exception.SearchException; @@ -97,4 +98,13 @@ public interface IUserService { */ JSONArray listUserDepartmentUserByPosition(Map params) throws AccessTokenException, SearchException; + /** + * 用户详情接口 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONObject getUserDetail(Map params) throws AccessTokenException, SearchException; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java index 79babb9..a89919b 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/user/impl/UserServiceImpl.java @@ -1,6 +1,7 @@ package com.cm.common.plugin.oauth.service.user.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; @@ -128,4 +129,16 @@ public class UserServiceImpl extends AbstractService implements IUserService { } return JSONArray.parseArray(result); } + + @Override + public JSONObject getUserDetail(Map params) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.GET_USER_DETAIL, apiPathProperties.getUserCenter(), params.get("userId").toString()), params); + if (result == null) { + throw new AccessTokenException("认证失败"); + } + if (result.isEmpty()) { + throw new SearchException("获取人员列表失败"); + } + return JSONObject.parseObject(result); + } } diff --git a/cloud-common-plugin-oauth/src/main/resources/templates/user/user-detail.html b/cloud-common-plugin-oauth/src/main/resources/templates/user/user-detail.html new file mode 100644 index 0000000..4dc8265 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/resources/templates/user/user-detail.html @@ -0,0 +1,109 @@ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
用户名{{userDetail.userUsername}}
姓 名{{userDetail.userName}}
电 话{{userDetail.userPhone == '' ? '无' : userDetail.userPhone}}
邮 箱{{userDetail.userEmail == '' ? '无' : userDetail.userEmail}}
角 色 + + {{role.roleName}} + + +
部 门 + + {{department.departmentName}} + + +
职 位 + + {{position.positionName}} + + +
所属组 + + {{group.groupName}} + + +
+
+ + + + + + + + \ No newline at end of file diff --git a/cloud-common-plugin/src/main/resources/templates/tree/tree.html b/cloud-common-plugin/src/main/resources/templates/tree/tree.html index 5e96015..2b13208 100644 --- a/cloud-common-plugin/src/main/resources/templates/tree/tree.html +++ b/cloud-common-plugin/src/main/resources/templates/tree/tree.html @@ -95,6 +95,9 @@ function initSelectNodes() { showSelectNodes(); var nodes = zTree.getNodes(); + if(nodes.length == 0) { + top.DialogBox.msg('暂无数据'); + } for(var i = 0, item = nodes[i]; item = nodes[i++];) { for(var j = 0, node = selectedNodes[j]; node = selectedNodes[j++];) { if(item[selectTree.primaryKey] == node[selectTree.primaryKey]) { diff --git a/cloud-common/src/main/java/com/cm/common/config/properties/SystemProperties.java b/cloud-common/src/main/java/com/cm/common/config/properties/SystemProperties.java new file mode 100644 index 0000000..0a70e7c --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/config/properties/SystemProperties.java @@ -0,0 +1,56 @@ +package com.cm.common.config.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: SystemProperties + * @Description: 系统配置 + * @Author: WangGeng + * @Date: 2019/9/3 10:14 上午 + * @Version: 1.0 + **/ +@Component +@ConfigurationProperties(prefix = "server") +public class SystemProperties { + + private Integer port; + private String url; + private String title; + private String loginPageName; + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public String getUrl() { + return url == null ? "" : url.trim(); + } + + public void setUrl(String url) { + this.url = url; + } + + public String getTitle() { + return title == null ? "" : title.trim(); + } + + public void setTitle(String title) { + this.title = title; + } + + public String getLoginPageName() { + return loginPageName == null ? "" : loginPageName.trim(); + } + + public void setLoginPageName(String loginPageName) { + this.loginPageName = loginPageName; + } +} diff --git a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java index 7a2aeba..5a53427 100644 --- a/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java +++ b/cloud-common/src/main/java/com/cm/common/constants/ISystemConstant.java @@ -20,6 +20,10 @@ public interface ISystemConstant { * APP接口前缀 */ String API_TAGS_APP_PREFIX = "APP接口-"; + /** + * 路由接口前缀 + */ + String ROUTE_TAGS_PREFIX = "路由接口-"; /** * api前缀 */ diff --git a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java index c3e1b8a..b578429 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/AppTokenManager.java @@ -61,11 +61,17 @@ public class AppTokenManager { * @param token * @param appTokenUser */ - public void addToken(String token, AppTokenUser appTokenUser) { + public synchronized void addToken(String token, AppTokenUser appTokenUser) { AppToken appToken = new AppToken(); appToken.setToken(token); appToken.setLastTime(System.currentTimeMillis()); appToken.setAppTokenUser(appTokenUser); + for (Map.Entry kvs : tokens.entrySet()) { + if (StringUtils.equals(appTokenUser.getId(), kvs.getValue().getUserId())) { + tokens.remove(kvs.getValue().getToken()); + break; + } + } tokens.put(token, appToken); } diff --git a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java index 904c2ef..fdbe603 100644 --- a/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java +++ b/cloud-common/src/main/java/com/cm/common/token/app/entity/AppToken.java @@ -14,6 +14,7 @@ public class AppToken { private String token; private long lastTime; + private String userId; private AppTokenUser appTokenUser; public String getToken() { @@ -32,6 +33,14 @@ public class AppToken { this.lastTime = lastTime; } + public String getUserId() { + return userId == null ? "" : userId.trim(); + } + + public void setUserId(String userId) { + this.userId = userId; + } + public AppTokenUser getAppTokenUser() { return appTokenUser; } @@ -47,7 +56,9 @@ public class AppToken { .append("\"").append(token).append("\""); sb.append(",\"lastTime\":") .append(lastTime); - sb.append(",\"tokenUser\":") + sb.append(",\"userId\":") + .append("\"").append(userId).append("\""); + sb.append(",\"appTokenUser\":") .append(appTokenUser); sb.append('}'); return sb.toString();