7 changed files with 130 additions and 3 deletions
@ -0,0 +1,8 @@ |
|||||
|
package com.project.ding.application; |
||||
|
|
||||
|
public interface AdminWhitrListApplicationService { |
||||
|
/** |
||||
|
* 查询用户职位为经理、主管、总监的用户,添加进白名单 |
||||
|
*/ |
||||
|
int addManagersToAdminWhiteList(); |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
package com.project.ding.application.impl; |
||||
|
|
||||
|
import com.project.ding.application.AdminWhitrListApplicationService; |
||||
|
import com.project.ding.domain.entity.AdminWhiteListEntity; |
||||
|
import com.project.ding.domain.entity.UserEntity; |
||||
|
import com.project.ding.domain.service.AdminWhitrListBaseService; |
||||
|
import com.project.ding.mapper.AdminWhiteListMapper; |
||||
|
import com.project.ding.mapper.DepartmentMapper; |
||||
|
import com.project.ding.mapper.UserMapper; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
import java.util.List; |
||||
|
import java.util.Set; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@Service |
||||
|
@Slf4j |
||||
|
public class AdminWhitrListApplicationServiceImpl implements AdminWhitrListApplicationService { |
||||
|
@Autowired |
||||
|
private UserMapper userMapper; |
||||
|
@Autowired |
||||
|
private AdminWhiteListMapper adminWhiteListMapper; |
||||
|
@Autowired |
||||
|
private AdminWhitrListBaseService adminWhitrListBaseService; |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
public int addManagersToAdminWhiteList() { |
||||
|
// 查询 title 包含经理、主管、总监的用户
|
||||
|
List<UserEntity> userEntityList = userMapper.selectUsersByTitleKeywords(); |
||||
|
|
||||
|
if (userEntityList == null || userEntityList.isEmpty()) { |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
//查询白名单用户
|
||||
|
List<AdminWhiteListEntity> adminWhiteListEntities = adminWhiteListMapper.selectList(null); |
||||
|
// 提取已存在的 userId 集合
|
||||
|
Set<String> existingUserIds = adminWhiteListEntities.stream() |
||||
|
.map(AdminWhiteListEntity::getUserId) |
||||
|
.collect(Collectors.toSet()); |
||||
|
|
||||
|
// 过滤掉已存在的用户
|
||||
|
List<AdminWhiteListEntity> toSaveList = userEntityList.stream() |
||||
|
.filter(user -> !existingUserIds.contains(user.getId())) |
||||
|
.map(user -> { |
||||
|
AdminWhiteListEntity whiteList = new AdminWhiteListEntity(); |
||||
|
whiteList.setUserId(user.getId()); |
||||
|
whiteList.setUserName(user.getName()); |
||||
|
return whiteList; |
||||
|
}) |
||||
|
.collect(Collectors.toList()); |
||||
|
|
||||
|
if (toSaveList.isEmpty()) { |
||||
|
log.info("所有用户已在白名单中,无需添加"); |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
//新增
|
||||
|
adminWhitrListBaseService.saveBatch(toSaveList); |
||||
|
log.info("成功添加 " + toSaveList.size() + " 人到 admin 白名单"); |
||||
|
|
||||
|
return toSaveList.size(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
package com.project.ding.controller; |
||||
|
|
||||
|
import com.project.base.domain.result.Result; |
||||
|
import com.project.ding.application.AdminWhitrListApplicationService; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
@Slf4j |
||||
|
@RequestMapping("/api/admin/adminWhitr") |
||||
|
public class AdminWhitrListController { |
||||
|
|
||||
|
@Autowired |
||||
|
private AdminWhitrListApplicationService adminWhitrApplicationService; |
||||
|
|
||||
|
@PostMapping("/addAdmin") |
||||
|
public Result addAdmin(){ |
||||
|
int count = adminWhitrApplicationService.addManagersToAdminWhiteList(); |
||||
|
return Result.success("已将" + count + "名管理人员加入 admin 白名单"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
package com.project.ding.domain.service; |
||||
|
|
||||
|
import com.project.base.domain.service.IBaseService; |
||||
|
import com.project.ding.domain.entity.AdminWhiteListEntity; |
||||
|
|
||||
|
public interface AdminWhitrListBaseService extends IBaseService<AdminWhiteListEntity> { |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package com.project.ding.domain.service.impl; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
|
import com.project.base.domain.service.IBaseService; |
||||
|
import com.project.ding.domain.entity.AdminWhiteListEntity; |
||||
|
import com.project.ding.domain.service.AdminWhitrListBaseService; |
||||
|
import com.project.ding.mapper.AdminWhiteListMapper; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
|
||||
|
@Service |
||||
|
public class AdminWhitrListBaseServiceImpl extends ServiceImpl<AdminWhiteListMapper, AdminWhiteListEntity> implements AdminWhitrListBaseService { |
||||
|
} |
||||
Loading…
Reference in new issue