Commit c6ee4a92 by guojuxing

账号分组接口

parent 972f7180
......@@ -85,6 +85,9 @@ public interface TabSysAccountGroupRelMapper {

 */
void deleteByUserId(@Param("userId") Integer userId,@Param("type") Integer type);
void deleteByUserIdList(@Param("userIdList") List<Integer> userIdList, @Param("type") Integer type);
/**
* 查询用户分组列表数据
* @Title: listByUserId

......@@ -106,4 +109,14 @@ public interface TabSysAccountGroupRelMapper {
* @return void


 */
void deleteByAccountGroupIdAndUserId(@Param("userId")Integer userId,@Param("accountGroupId") Integer accountGroupId,@Param("type") Integer type);
/**
* 查询分组下的组员列表数据
* @Title: listByAccountGroupId

* @Description:

 * @author guojuxing
* @param accountGroupId

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


 */
List<TabSysAccountGroupRel> listByAccountGroupId(@Param("accountGroupId") Integer accountGroupId);
}
\ No newline at end of file
......@@ -97,5 +97,15 @@ public interface TabSysUserMapper {
Integer countUserByUserIds(@Param("ids") List<Integer> userIdList);
List<TabSysUser> listUserByIdList(@Param("ids")List<Integer> userIdList);
List<TabSysUser> listUserByIdList(@Param("ids") List<Integer> userIdList);
/**
* 查询不在范围内的用户
* @Title: listUserNotInIdList

* @Description:

 * @author guojuxing
* @param userIdList

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


 */
List<TabSysUser> listUserNotInIdList(@Param("ids") List<Integer> userIdList);
}
\ No newline at end of file
......@@ -44,6 +44,8 @@ public interface AccountGroupRelService {

 */
void deleteByUserId(Integer userId, Integer type);
void deleteByUserId(List<Integer> userId, Integer type);
/**
* 用户所在分组列表数据
* @Title: listByUserId

......@@ -66,4 +68,14 @@ public interface AccountGroupRelService {
* @return void


 */
void deleteByAccountGroupIdAndUserId(Integer userId, Integer accountGroupId, Integer type);
/**
* 查询分组下的组员
* @Title: listByAccountGroupId

* @Description:

 * @author guojuxing
* @param accountGroupId

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


 */
List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId);
}
......@@ -89,4 +89,14 @@ public interface UserService {
* @return java.util.List<com.gic.auth.entity.TabSysUser>


 */
List<TabSysUser> listUserByIdList(List<Integer> userIdList);
/**
* 查询不在范围内的用户
* @Title: listUserNotInIdList

* @Description:

 * @author guojuxing
* @param userIdList

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


 */
List<TabSysUser> listUserNotInIdList(List<Integer> userIdList);
}
......@@ -20,6 +20,7 @@ public class AccountGroupRelServiceImpl implements AccountGroupRelService{
tabSysAccountGroupRelMapper.insertForeach(list);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteByAccountGroupId(Integer accountGroupId) {
tabSysAccountGroupRelMapper.deleteByAccountGroupId(accountGroupId);
......@@ -34,6 +35,15 @@ public class AccountGroupRelServiceImpl implements AccountGroupRelService{
tabSysAccountGroupRelMapper.deleteByUserId(userId, type);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void deleteByUserId(List<Integer> userId, Integer type) {
if (type == null) {
type = AccountGroupMemberTypeEnum.ADMIN.getCode();
}
tabSysAccountGroupRelMapper.deleteByUserIdList(userId, type);
}
@Override
public List<TabSysAccountGroupRel> listByUserId(Integer userId, Integer type) {
if (type == null) {
......@@ -49,4 +59,9 @@ public class AccountGroupRelServiceImpl implements AccountGroupRelService{
}
tabSysAccountGroupRelMapper.deleteByAccountGroupIdAndUserId(userId, accountGroupId, type);
}
@Override
public List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId) {
return tabSysAccountGroupRelMapper.listByAccountGroupId(accountGroupId);
}
}
......@@ -104,4 +104,9 @@ public class UserServiceImpl implements UserService {
public List<TabSysUser> listUserByIdList(List<Integer> userIdList) {
return tabSysUserMapper.listUserByIdList(userIdList);
}
@Override
public List<TabSysUser> listUserNotInIdList(List<Integer> userIdList) {
return tabSysUserMapper.listUserNotInIdList(userIdList);
}
}
package com.gic.auth.service.outer.impl;
import com.gic.auth.entity.TabSysAccountGroup;
import com.gic.auth.service.AccountGroupRelService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.error.ErrorCode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.gic.auth.dto.AccountGroupRelDTO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.auth.constant.AccountGroupMemberTypeEnum;
import com.gic.auth.dto.AccountGroupDTO;
import com.gic.auth.dto.AccountGroupMemberDTO;
import com.gic.auth.entity.TabSysAccountGroup;
import com.gic.auth.entity.TabSysAccountGroupRel;
import com.gic.auth.entity.TabSysUser;
import com.gic.auth.service.AccountGroupApiService;
import com.gic.auth.service.AccountGroupRelService;
import com.gic.auth.service.AccountGroupService;
import com.gic.auth.service.UserService;
import com.gic.commons.util.EntityUtil;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.utils.valid.ValidParamsUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service("accountGroupApiService")
public class AccountGroupApiServiceImpl implements AccountGroupApiService{
public class AccountGroupApiServiceImpl implements AccountGroupApiService {
@Autowired
private AccountGroupService accountGroupService;
@Autowired
private AccountGroupRelService accountGroupRelService;
@Autowired
private UserService userService;
@Override
public ServiceResponse<Integer> save(AccountGroupDTO dto) {
//参数校验
......@@ -51,7 +61,8 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
if (!paramValid.isSuccess()) {
return paramValid;
}
if (accountGroupService.isAccountGroupNameRepeat(dto.getEnterpriseId(), dto.getAccountGroupId(), dto.getAccountGroupName())) {
if (accountGroupService.isAccountGroupNameRepeat(dto.getEnterpriseId(), dto.getAccountGroupId(),
dto.getAccountGroupName())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组名称不能重复");
}
dto.setEnterpriseId(record.getEnterpriseId());
......@@ -92,4 +103,152 @@ public class AccountGroupApiServiceImpl implements AccountGroupApiService{
accountGroupService.setSort(record, sort);
return ServiceResponse.success();
}
@Override
public ServiceResponse<List<AccountGroupMemberDTO>> listNotInAccountGroupByAccountGroupId(Integer accountGroupId) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
}
List<AccountGroupMemberDTO> result = new ArrayList<>();
List<TabSysAccountGroupRel> list = listByAccountGroupId(accountGroupId);
//查询管理员列表
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, false));
//todo 查询协作人列表
return ServiceResponse.success(result);
}
@Override
public ServiceResponse<List<AccountGroupMemberDTO>> listInAccountGroupByAccountGroupId(Integer accountGroupId) {
TabSysAccountGroup record = accountGroupService.getById(accountGroupId);
if (record == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "账号分组id有误,查无数据");
}
List<AccountGroupMemberDTO> result = new ArrayList<>();
List<TabSysAccountGroupRel> list = listByAccountGroupId(accountGroupId);
//查询管理员列表
result.addAll(getMemberOfUser(AccountGroupMemberTypeEnum.ADMIN.getCode(), list, true));
//todo 查询协作人列表
return ServiceResponse.success(result);
}
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse<Void> saveAccountGroupRelFetch(List<AccountGroupMemberDTO> list) {
if (CollectionUtils.isNotEmpty(list)) {
//逻辑删除之前的数据,先删后增
accountGroupRelService.deleteByAccountGroupId(list.get(0).getAccountGroupId());
List<AccountGroupRelDTO> result = new ArrayList<>(list.size());
Date now = new Date();
for (AccountGroupMemberDTO dto : list) {
AccountGroupRelDTO temp = new AccountGroupRelDTO();
temp.setStatus(1);
temp.setAccountGroupId(dto.getAccountGroupId());
temp.setCreateTime(now);
temp.setUpdateTime(now);
temp.setUserId(dto.getUserId());
temp.setType(dto.getType());
temp.setEnterpriseId(dto.getEnterpriseId());
result.add(temp);
}
accountGroupRelService.insertFetch(result);
}
return ServiceResponse.success();
}
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse<Void> groupingOfUser(List<Integer> userIdList, List<Integer> accountGroupId,
Integer enterpriseId) {
return grouping(userIdList, accountGroupId, enterpriseId, AccountGroupMemberTypeEnum.ADMIN.getCode());
}
@Transactional(rollbackFor = Exception.class)
@Override
public ServiceResponse<Void> groupingOfCollaborator(List<Integer> collaboratorIdList, List<Integer> accountGroupId,
Integer enterpriseId) {
return grouping(collaboratorIdList, accountGroupId, enterpriseId, AccountGroupMemberTypeEnum.COLLABORATOR.getCode());
}
/**
* 查询分组下的组员列表数据
* @param accountGroupId
* @return
*/
private List<TabSysAccountGroupRel> listByAccountGroupId(Integer accountGroupId) {
return accountGroupRelService.listByAccountGroupId(accountGroupId);
}
private List<Integer> getUserIdList(int type, List<TabSysAccountGroupRel> accountGroupRelList) {
List<Integer> userIdList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(accountGroupRelList)) {
for (TabSysAccountGroupRel rel : accountGroupRelList) {
if (rel.getType().intValue() == type) {
userIdList.add(rel.getUserId());
} else if (rel.getType().intValue() == type) {
userIdList.add(rel.getUserId());
}
}
}
return userIdList;
}
/**
* 获取管理员列表
* @param type
* @param accountGroupRelList
* @param isIn 是否在分组内
* @return
*/
private List<AccountGroupMemberDTO> getMemberOfUser(int type, List<TabSysAccountGroupRel> accountGroupRelList,
boolean isIn) {
List<Integer> userIdList = getUserIdList(type, accountGroupRelList);
List<TabSysUser> userList;
//查询管理员列表
if (isIn) {
userList = userService.listUserByIdList(userIdList);
} else {
userList = userService.listUserNotInIdList(userIdList);
}
return userToMember(userList);
}
private List<AccountGroupMemberDTO> userToMember(List<TabSysUser> userList) {
List<AccountGroupMemberDTO> result = new ArrayList<>();
if (CollectionUtils.isNotEmpty(userList)) {
for (TabSysUser user : userList) {
AccountGroupMemberDTO dto = new AccountGroupMemberDTO();
dto.setMemberName(user.getUserName());
dto.setUserId(user.getUserId());
dto.setPhone(user.getPhoneNumber());
dto.setType(AccountGroupMemberTypeEnum.ADMIN.getCode());
result.add(dto);
}
}
return result;
}
private ServiceResponse<Void> grouping(List<Integer> userIdList, List<Integer> accountGroupId,
Integer enterpriseId, int type) {
//先删除
accountGroupRelService.deleteByUserId(userIdList, type);
Date now = new Date();
for (Integer groupId : accountGroupId) {
List<AccountGroupRelDTO> result = new ArrayList<>();
for (Integer userId : userIdList) {
AccountGroupRelDTO temp = new AccountGroupRelDTO();
temp.setStatus(1);
temp.setAccountGroupId(groupId);
temp.setCreateTime(now);
temp.setUpdateTime(now);
temp.setUserId(userId);
temp.setType(type);
temp.setEnterpriseId(enterpriseId);
result.add(temp);
}
accountGroupRelService.insertFetch(result);
}
return ServiceResponse.success();
}
}
......@@ -163,6 +163,19 @@
and type = #{type}
</update>
<update id="deleteByUserIdList">
update tab_sys_account_group_rel
set status = 0
where status = 1
<if test="userIdList != null and userIdList.size() > 0">
and user_id in
<foreach collection="userIdList" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
and type = #{type}
</update>
<select id="listByUserId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
......@@ -180,4 +193,12 @@
and account_group_id = #{accountGroupId}
and type = #{type}
</update>
<select id="listByAccountGroupId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_account_group_rel
where account_group_id = #{accountGroupId}
and status = 1
</select>
</mapper>
\ No newline at end of file
......@@ -301,4 +301,17 @@
</foreach>
</if>
</select>
<select id="listUserNotInIdList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tab_sys_user
where status = 1
<if test="ids != null and ids.size() > 0">
and user_id not in
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</select>
</mapper>
\ No newline at end of file
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