|
@@ -8,6 +8,9 @@ import com.huaxu.dto.UserGroupDto;
|
|
|
import com.huaxu.entity.*;
|
|
|
import com.huaxu.model.LoginUser;
|
|
|
import com.huaxu.service.UserGroupService;
|
|
|
+import com.huaxu.service.UserService;
|
|
|
+import com.huaxu.util.ByteArrayUtils;
|
|
|
+import com.huaxu.util.RedisUtil;
|
|
|
import com.huaxu.util.UserUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -31,6 +34,10 @@ public class UserGroupServiceImpl implements UserGroupService {
|
|
|
private GroupUserMapper groupUserMapper;
|
|
|
@Autowired
|
|
|
private UserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserService userService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
|
|
|
|
|
@@ -106,6 +113,39 @@ public class UserGroupServiceImpl implements UserGroupService {
|
|
|
|
|
|
LoginUser currentUser = UserUtil.getCurrentUser();
|
|
|
userGroup.setUpdateBy(currentUser.getUsername());
|
|
|
+ List<UserEntity> usersByUserGroup = userGroupMapper.findUsersByUserGroup(userGroup);
|
|
|
+ List<Long>userIds=new ArrayList<>();
|
|
|
+ List<UserRoleEntity>userRoleEntities=new ArrayList<>();
|
|
|
+
|
|
|
+ usersByUserGroup.forEach(userEntity -> {
|
|
|
+ UserEntity updateUserEntity=new UserEntity();
|
|
|
+ updateUserEntity.setId(userEntity.getId());
|
|
|
+ updateUserEntity.setEnableState(userGroup.getGroupState()+"");
|
|
|
+ userService.updateUserById(updateUserEntity);
|
|
|
+ if (userGroup.getGroupState()==0) {
|
|
|
+ String roleKey = "disableUser:" + userEntity.getId();
|
|
|
+ redisUtil.setExpire(roleKey.getBytes(), ByteArrayUtils.objectToBytes("1").get(), 60 * 60 * 24);//15分钟过期
|
|
|
+
|
|
|
+ }
|
|
|
+ if (userGroup.getGroupState()==1) {
|
|
|
+ String roleKey = "disableUser:" + userEntity.getId();
|
|
|
+ redisUtil.del(roleKey.getBytes());
|
|
|
+ }
|
|
|
+ userIds.add(userEntity.getId());
|
|
|
+ UserRoleEntity userRoleEntity=new UserRoleEntity();
|
|
|
+ Long id=Long.valueOf(userGroup.getRoleId()+"");
|
|
|
+ userRoleEntity.setRoleId(id);
|
|
|
+ userRoleEntity.setUserId(id);
|
|
|
+ userRoleEntity.setStatus(1);
|
|
|
+ userRoleEntities.add(userRoleEntity);
|
|
|
+ });
|
|
|
+ if(userIds.size()>0){
|
|
|
+ UserGroupDto userGroupDto=new UserGroupDto();
|
|
|
+ userGroupDto.setGroupId(userGroup.getId());
|
|
|
+ userGroupDto.setOrginUserIds(userIds);
|
|
|
+ userGroupMapper.deleteUserRoles(userGroupDto);
|
|
|
+ userGroupMapper.batchInsertRoles(userRoleEntities);
|
|
|
+ }
|
|
|
return this.userGroupMapper.update(userGroup);
|
|
|
}
|
|
|
|
|
@@ -128,7 +168,7 @@ public class UserGroupServiceImpl implements UserGroupService {
|
|
|
userGroup.setId(id);
|
|
|
userGroup.setStatus(0);
|
|
|
userGroupMapper.update(userGroup);
|
|
|
-
|
|
|
+ userGroupMapper.deleteUserGroupRelations(userGroup);
|
|
|
|
|
|
});
|
|
|
|