Commit 9e532cdf by guojuxing

账号分组接口

parent 471c788b
package com.gic.auth.dao.mapper;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.entity.TabSysAccountGroup;
import org.apache.ibatis.annotations.Param;
......
package com.gic.auth.dao.mapper;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.dto.AccountGroupRelDTO;
import com.gic.auth.entity.TabSysAccountGroupRel;
import org.apache.ibatis.annotations.Param;
......@@ -118,5 +119,7 @@ public interface TabSysAccountGroupRelMapper {
* @param accountGroupId

* @return java.util.List<com.gic.auth.entity.TabSysAccountGroupRel>


 */
List<TabSysAccountGroupRel> listByAccountGroupId(@Param("accountGroupId") Integer accountGroupId);
List<TabSysAccountGroupRel> listByAccountGroupId(@Param("accountGroupId") Integer accountGroupId, @Param("type") Integer type);
List<AccountGroupListDTO> groupByAccountGroupId(@Param("list") List<Integer> accountGroupId);
}
\ No newline at end of file
......@@ -105,7 +105,8 @@ public interface TabSysUserMapper {
* @Description:

 * @author guojuxing
* @param userIdList

* @param search
* @return java.util.List<com.gic.auth.entity.TabSysUser>


 */
List<TabSysUser> listUserNotInIdList(@Param("ids") List<Integer> userIdList);
List<TabSysUser> listUserNotInIdList(@Param("ids") List<Integer> userIdList, @Param("search") String search);
}
\ No newline at end of file
package com.gic.auth.service;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.dto.AccountGroupRelDTO;
import com.gic.auth.entity.TabSysAccountGroupRel;
......@@ -78,4 +79,16 @@ public interface AccountGroupRelService {
* @return java.util.List<com.gic.auth.entity.TabSysAccountGroupRel>


 */
List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId);
List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId, Integer type);
/**
* 求分组组员数量
* @Title: groupByAccountGroupId

* @Description:

 * @author guojuxing
* @param accountGroupId

* @return java.util.List<com.gic.auth.dto.AccountGroupListDTO>


 */
List<AccountGroupListDTO> groupByAccountGroupId(List<Integer> accountGroupId);
}
package com.gic.auth.service;
import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.entity.TabSysAccountGroup;
import java.util.List;
......
......@@ -98,5 +98,5 @@ public interface UserService {
* @param userIdList

* @return java.util.List<com.gic.auth.entity.TabSysUser>


 */
List<TabSysUser> listUserNotInIdList(List<Integer> userIdList);
List<TabSysUser> listUserNotInIdList(List<Integer> userIdList, String search);
}
......@@ -2,6 +2,7 @@ package com.gic.auth.service.impl;
import com.gic.auth.constant.AccountGroupMemberTypeEnum;
import com.gic.auth.dao.mapper.TabSysAccountGroupRelMapper;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.dto.AccountGroupRelDTO;
import com.gic.auth.entity.TabSysAccountGroupRel;
import com.gic.auth.service.AccountGroupRelService;
......@@ -62,6 +63,16 @@ public class AccountGroupRelServiceImpl implements AccountGroupRelService{
@Override
public List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId) {
return tabSysAccountGroupRelMapper.listByAccountGroupId(accountGroupId);
return tabSysAccountGroupRelMapper.listByAccountGroupId(accountGroupId, null);
}
@Override
public List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId, Integer type) {
return tabSysAccountGroupRelMapper.listByAccountGroupId(accountGroupId, type);
}
@Override
public List<AccountGroupListDTO> groupByAccountGroupId(List<Integer> accountGroupId) {
return tabSysAccountGroupRelMapper.groupByAccountGroupId(accountGroupId);
}
}
......@@ -3,6 +3,7 @@ package com.gic.auth.service.impl;
import java.util.Date;
import java.util.List;
import com.gic.auth.dto.AccountGroupListDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......
......@@ -106,7 +106,7 @@ public class UserServiceImpl implements UserService {
}
@Override
public List<TabSysUser> listUserNotInIdList(List<Integer> userIdList) {
return tabSysUserMapper.listUserNotInIdList(userIdList);
public List<TabSysUser> listUserNotInIdList(List<Integer> userIdList, String search) {
return tabSysUserMapper.listUserNotInIdList(userIdList, search);
}
}
package com.gic.auth.service.outer.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import com.gic.auth.dto.AccountGroupListDTO;
import com.gic.auth.dto.AccountGroupRelDTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -75,7 +74,24 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
public ServiceResponse<List<AccountGroupDTO>> listAccountGroupByEnterpriseId(Integer enterpriseId) {
List<TabSysAccountGroup> list = accountGroupService.listAccountGroupByEnterpriseId(enterpriseId);
if (CollectionUtils.isNotEmpty(list)) {
return ServiceResponse.success(EntityUtil.changeEntityListNew(AccountGroupDTO.class, list));
//求分组下的组员数量值
List<Integer> accountGroupIdList = new ArrayList<>(list.size());
for (TabSysAccountGroup temp : list) {
accountGroupIdList.add(temp.getAccountGroupId());
}
List<AccountGroupListDTO> accountGroupListDTOList = accountGroupRelService
.groupByAccountGroupId(accountGroupIdList);
Map<String, Integer> map = new HashMap<>(16);
if (CollectionUtils.isNotEmpty(accountGroupListDTOList)) {
for (AccountGroupListDTO dto : accountGroupListDTOList) {
map.put(dto.getAccountGroupId().toString(), dto.getMemberCount());
}
}
List<AccountGroupDTO> result = EntityUtil.changeEntityListNew(AccountGroupDTO.class, list);
for (AccountGroupDTO temp : result) {
temp.setMemberCount(map.get(temp.getAccountGroupId().toString()));
}
return ServiceResponse.success(result);
}
return ServiceResponse.success(new ArrayList<>());
}
......@@ -105,7 +121,8 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
}
@Override
public ServiceResponse<List<AccountGroupMemberDTO>> listNotInAccountGroupByAccountGroupId(Integer accountGroupId) {
public ServiceResponse<List<AccountGroupMemberDTO>> listNotInAccountGroupByAccountGroupId(Integer accountGroupId,
String search) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
......@@ -113,13 +130,14 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
List<AccountGroupMemberDTO> result = new ArrayList<>();
List<TabSysAccountGroupRel> list = listByAccountGroupId(accountGroupId);
//查询管理员列表
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, false));
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, false, search));
//todo 查询协作人列表
return ServiceResponse.success(result);
}
@Override
public ServiceResponse<List<AccountGroupMemberDTO>> listInAccountGroupByAccountGroupId(Integer accountGroupId) {
public ServiceResponse<List<AccountGroupMemberDTO>> listInAccountGroupByAccountGroupId(Integer accountGroupId,
String search) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
......@@ -127,7 +145,7 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
List<AccountGroupMemberDTO> result = new ArrayList<>();
List<TabSysAccountGroupRel> list = listByAccountGroupId(accountGroupId);
//查询管理员列表
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, true));
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, true, search));
//todo 查询协作人列表
return ServiceResponse.success(result);
......@@ -138,7 +156,8 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
public ServiceResponse<Void> saveAccountGroupRelFetch(List<AccountGroupMemberDTO> list) {
if (CollectionUtils.isNotEmpty(list)) {
//逻辑删除之前的数据,先删后增
accountGroupRelService.deleteByAccountGroupId(list.get(0).getAccountGroupId());
//accountGroupRelService.deleteByAccountGroupId(list.get(0).getAccountGroupId());
//暂时不删除,因为是批量新增部分,而不是全部,所以不需要删除之前的数据
List<AccountGroupRelDTO> result = new ArrayList<>(list.size());
Date now = new Date();
for (AccountGroupMemberDTO dto : list) {
......@@ -168,7 +187,8 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
@Override
public ServiceResponse<Void> groupingOfCollaborator(List<Integer> collaboratorIdList, List<Integer> accountGroupId,
Integer enterpriseId) {
return grouping(collaboratorIdList, accountGroupId, enterpriseId, AccountGroupMemberTypeEnum.COLLABORATOR.getCode());
return grouping(collaboratorIdList, accountGroupId, enterpriseId,
AccountGroupMemberTypeEnum.COLLABORATOR.getCode());
}
/**
......@@ -202,14 +222,14 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
* @return
*/
private List<AccountGroupMemberDTO> getMemberOfUser(int type, List<TabSysAccountGroupRel> accountGroupRelList,
boolean isIn) {
boolean isIn, String search) {
List<Integer> userIdList = getUserIdList(type, accountGroupRelList);
List<TabSysUser> userList;
//查询管理员列表
if (isIn) {
userList = userService.listUserByIdList(userIdList);
} else {
userList = userService.listUserNotInIdList(userIdList);
userList = userService.listUserNotInIdList(userIdList, search);
}
return userToMember(userList);
}
......@@ -229,8 +249,8 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService {
return result;
}
private ServiceResponse<Void> grouping(List<Integer> userIdList, List<Integer> accountGroupId,
Integer enterpriseId, int type) {
private ServiceResponse<Void> grouping(List<Integer> userIdList, List<Integer> accountGroupId, Integer enterpriseId,
int type) {
//先删除
accountGroupRelService.deleteByUserId(userIdList, type);
Date now = new Date();
......
......@@ -319,6 +319,18 @@ public class UserApiServiceImpl implements UserApiService {
@Override
public ServiceResponse<Page<UserListDTO>> pageUser(UserListQO params) {
if (params.getAccountGroupId() != null) {
//查询分组下的管理员列表
List<TabSysAccountGroupRel> list = accountGroupRelService.listByAccountGroupId(params.getAccountGroupId());
if (CollectionUtils.isNotEmpty(list)) {
List<Integer> userIdList = new ArrayList<>(list.size());
for (TabSysAccountGroupRel temp : list) {
userIdList.add(temp.getUserId());
}
params.setUserIdList(userIdList);
}
}
com.github.pagehelper.Page page = userService.pageUser(params);
Page<UserListDTO> resultPage = PageHelperUtils.changePageHelperToCurrentPage(page);
return ServiceResponse.success(resultPage);
......
......@@ -199,6 +199,23 @@
<include refid="Base_Column_List" />
from tab_sys_account_group_rel
where account_group_id = #{accountGroupId}
<if test="type != null">
and type = #{type}
</if>
and status = 1
</select>
<select id="groupByAccountGroupId" resultType="com.gic.auth.dto.AccountGroupListDTO">
select account_group_id accountGroupId,
count(user_id) memberCount
from tab_sys_account_group_rel
where status = 1
<if test="list != null and list.size() > 0">
and account_group_id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
group by account_group_id
</select>
</mapper>
\ No newline at end of file
......@@ -250,6 +250,12 @@
<if test="resourceId != null">
and c.resource_id = #{resourceId}
</if>
<if test="userIdList != null and userIdList.size() > 0">
and a.user_id in
<foreach collection="userIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY a.user_id
......@@ -272,7 +278,7 @@
<if test="enterpriseId != null ">
and enterprise_id = #{enterpriseId}
</if>
<if test="null != ids">
<if test="null != ids and ids.size() > 0">
and user_id not in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
......@@ -307,6 +313,9 @@
<include refid="Base_Column_List" />
from tab_sys_user
where status = 1
<if test="search != null and search != '' ">
and ( user_name like concat('%', #{search}, '%') or phone_number like concat('%', #{search}, '%') )
</if>
<if test="ids != null and ids.size() > 0">
and user_id not in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
......
package com.gic.auth.web.controller;
import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import com.alibaba.fastjson.JSON;
import com.gic.auth.dto.AccountGroupMemberDTO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gic.auth.constant.AccountGroupMemberTypeEnum;
import com.gic.auth.constant.SignConstants;
import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.service.AccountGroupApiService;
import com.gic.auth.web.vo.AccountGroupListVO;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.utils.ResultControllerUtils;
import com.gic.enterprise.utils.UserDetailUtils;
@RestController
@RequestMapping("/account-group")
@Validated
public class AccountGroupController {
private final static Logger LOGGER = LogManager.getLogger(AccountGroupApiService.class);
@Autowired
......@@ -55,4 +68,63 @@ public class AccountGroupController {
public RestResponse sortAccountGroup(Integer accountGroupId, Integer sort) {
return ResultControllerUtils.commonResult(accountGroupApiService.sort(accountGroupId, sort));
}
/**
* 不在分组下的组员
* @Title: memberNotInGroup

* @Description:

 * @author guojuxing
* @param accountGroupId

* @return com.gic.commons.webapi.reponse.RestResponse


 */
@RequestMapping("/member-not-in-group")
public RestResponse memberNotInGroup(Integer accountGroupId, String search) {
return ResultControllerUtils
.commonResult(accountGroupApiService.listNotInAccountGroupByAccountGroupId(accountGroupId, search));
}
@RequestMapping("/member-in-group")
public RestResponse memberInGroup(Integer accountGroupId, String search) {
return ResultControllerUtils
.commonResult(accountGroupApiService.listInAccountGroupByAccountGroupId(accountGroupId, search));
}
@RequestMapping("/grouping")
public RestResponse grouping(@NotBlank(message = "账号分组ID不能为空") String accountGroupIds,
@NotBlank(message = "组员ID不能为空") String userIds, @NotNull(message = "组员类型不能为空") Integer type) {
String[] accountGroupIdArr = accountGroupIds.split(SignConstants.COMMA);
String[] userIdArr = userIds.split(SignConstants.COMMA);
List<Integer> accountGroupIdList = new ArrayList<>(accountGroupIdArr.length);
for (String str : accountGroupIdArr) {
accountGroupIdList.add(Integer.parseInt(str));
}
List<Integer> userIdList = new ArrayList<>(userIdArr.length);
for (String str : userIdArr) {
userIdList.add(Integer.parseInt(str));
}
Integer enterpriseId = UserDetailUtils.getUserDetail().getEnterpriseId();
if (type.intValue() == AccountGroupMemberTypeEnum.ADMIN.getCode()) {
return ResultControllerUtils
.commonResult(accountGroupApiService.groupingOfUser(userIdList, accountGroupIdList, enterpriseId));
} else if (type.intValue() == AccountGroupMemberTypeEnum.COLLABORATOR.getCode()) {
return ResultControllerUtils.commonResult(
accountGroupApiService.groupingOfCollaborator(userIdList, accountGroupIdList, enterpriseId));
}
return RestResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "组员类型错误");
}
/**
* 批量新增组员 ,必须有 必须有分组ID、管理员/协作人ID、类型
* @Title: addGroupMember

* @Description:

 * @author guojuxing
* @param memberArr

* @return com.gic.commons.webapi.reponse.RestResponse


 */
@RequestMapping("/add-group-member")
public RestResponse addGroupMember(String memberArr) {
List<AccountGroupMemberDTO> list = JSON.parseArray(memberArr, AccountGroupMemberDTO.class);
return ResultControllerUtils
.commonResult(accountGroupApiService.saveAccountGroupRelFetch(list));
}
}
......@@ -18,6 +18,8 @@ public class AccountGroupListVO implements Serializable{
private Integer enterpriseId;
private Integer memberCount;
public Integer getAccountGroupId() {
return accountGroupId;
}
......@@ -41,4 +43,12 @@ public class AccountGroupListVO implements Serializable{
public void setEnterpriseId(Integer enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Integer getMemberCount() {
return memberCount;
}
public void setMemberCount(Integer memberCount) {
this.memberCount = memberCount;
}
}
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