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 a2bfc6a..18aea8e 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 @@ -103,4 +103,14 @@ public interface IApiConsts { * 修改密码 */ String UPDATE_USER_PASSWORD = "%s/resource/user/updateuserpassword"; + + /** + * 部门人员列表(ZTree格式) + */ + String LIST_ZTREE_DEPARTMENT_WITH_USER = "%s/resource/department/listztreedepartmentwithuser"; + + /** + * 部门人员列表 + */ + String LIST_DEPARTMENT_USER_BY_USER_DEPARTMENT_ID = "%s/resource/user/listdepartmentuserbyuserdepartmentid"; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java index 20b8a72..343c402 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/controller/apis/department/DepartmentController.java @@ -11,10 +11,7 @@ import io.swagger.annotations.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Map; @@ -52,4 +49,18 @@ public class DepartmentController extends AbstractController { return departmentService.listDepartments(params); } + @ApiOperation(value = "部门人员列表", notes = "部门人员列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "上级部门ID", paramType = "form") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listztreedepartmentwithuser") + public JSONArray listZTreeDepartmentWithUser(@RequestParam(required = false) String id) { + String departmentParentId = "0"; + if (!StringUtils.isBlank(id)) { + departmentParentId = id; + } + return departmentService.listZTreeDepartmentWithUser(departmentParentId); + } + } 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 d14d782..54c8c79 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 @@ -16,6 +16,7 @@ import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -156,9 +157,21 @@ public class UserController extends AbstractController { @PutMapping("updateuserpassword") @CheckRequestBodyAnnotation public SuccessResult updateUserPassword(@RequestBody Map params) throws ParamsException, SearchException, UpdateException { -// params.put("oldPassword", appChangePasswordVO.getOldPassword()); -// params.put("newPassword", appChangePasswordVO.getNewPassword()); return userService.updateUserPassword(params); } + @ApiOperation(value = "通过用户和部门ID列表获取部门用户列表", notes = "通过用户和部门ID列表获取部门用户列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "selectedUsers", value = "用户和部门ID列表", paramType = "body") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("listdepartmentuserbyuserdepartmentid") + public JSONArray listDepartmentUserByUserDepartmentId(@RequestBody JSONObject params) { + JSONArray selectedUsers = params.getJSONArray("selectedUsers"); + if (selectedUsers == null || selectedUsers.isEmpty()) { + throw new ParamsException("参数列表不能为空"); + } + return userService.listDepartmentUserByUserDepartmentId(params); + } + } \ No newline at end of file diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java index efb18f4..2980961 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java @@ -38,4 +38,14 @@ public interface IDepartmentService { * @throws SearchException */ JSONArray listDepartmentsAllByParentId(String parentId) throws AccessTokenException, SearchException; + + /** + * 部门人员列表 + * + * @param departmentParentId + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listZTreeDepartmentWithUser(String departmentParentId) throws AccessTokenException, SearchException; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java index f4e243f..ae82528 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java @@ -7,6 +7,7 @@ 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.department.IDepartmentService; +import com.cm.common.plugin.oauth.token.ClientTokenManager; import com.cm.common.plugin.utils.RestTemplateUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -36,10 +37,10 @@ public class DepartmentServiceImpl extends AbstractService implements IDepartmen @Override public JSONArray listDepartments(Map params) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_DEPARTMENT, apiPathProperties.getUserCenter(), params.get("parentId").toString()), params); - if(result == null) { + if (result == null) { throw new AccessTokenException("认证失败"); } - if(result.isEmpty()) { + if (result.isEmpty()) { throw new SearchException("获取组织部门列表失败"); } return JSONArray.parseArray(result); @@ -48,12 +49,22 @@ public class DepartmentServiceImpl extends AbstractService implements IDepartmen @Override public JSONArray listDepartmentsAllByParentId(String parentId) throws AccessTokenException, SearchException { String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_ALL_DEPARTMENT, apiPathProperties.getUserCenter(), parentId), new HashMap<>(0)); - if(result == null) { + if (result == null) { throw new AccessTokenException("认证失败"); } - if(result.isEmpty()) { + if (result.isEmpty()) { throw new SearchException("获取组织部门列表失败"); } return JSONArray.parseArray(result); } + + @Override + public JSONArray listZTreeDepartmentWithUser(String departmentParentId) throws AccessTokenException, SearchException { + Map params = new HashMap<>(1); + params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken()); + params.put("id", departmentParentId); + String result = restTemplateUtil.doGetFormNormal(String.format(IApiConsts.LIST_ZTREE_DEPARTMENT_WITH_USER, apiPathProperties.getUserCenter()), params); + searchResourceResult(result, "获取部门人员列表失败"); + return JSONArray.parseArray(result); + } } 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 4f18d95..305ab2d 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 @@ -157,4 +157,14 @@ public interface IUserService { * @throws SearchException */ SuccessResult updateUserPassword(Map params) throws AccessTokenException, SearchException; + + /** + * 通过用户和部门ID列表获取部门用户列表 + * + * @param params + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listDepartmentUserByUserDepartmentId(JSONObject 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 5ee111b..4d38788 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 @@ -137,4 +137,14 @@ public class UserServiceImpl extends AbstractService implements IUserService { return new SuccessResult(); } + @Override + public JSONArray listDepartmentUserByUserDepartmentId(JSONObject jsonObject) throws AccessTokenException, SearchException { + Map params = new HashMap<>(1); + params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken()); + params.put("jsonObjectParams", jsonObject.toJSONString()); + String result = restTemplateUtil.doPostFormNormal(String.format(IApiConsts.LIST_DEPARTMENT_USER_BY_USER_DEPARTMENT_ID, apiPathProperties.getUserCenter()), params); + searchResourceResult(result, "获取部门人员列表失败"); + return JSONArray.parseArray(result); + } + } diff --git a/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html b/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html index 50bcf81..b1157e9 100644 --- a/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html +++ b/cloud-common-plugin/src/main/resources/templates/tree/tree-user.html @@ -65,7 +65,7 @@ }); $('.selector-body-wrapper').css({ marginTop: '5px', - height: height +'px', + height: (height - 10) +'px', border: '1px dotted silver' }); }