Compare commits
2 Commits
d4dcc3c5dd
...
f336cf7ae6
| Author | SHA1 | Date |
|---|---|---|
|
|
f336cf7ae6 | |
|
|
143d6b6146 |
|
|
@ -1,8 +1,12 @@
|
|||
package com.nflg.wms.admin.controller;
|
||||
|
||||
import com.nflg.wms.admin.pojo.request.UserAddLdapQO;
|
||||
import com.nflg.wms.admin.service.LDAPControllerService;
|
||||
import com.nflg.wms.admin.service.UserControllerService;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.PageData;
|
||||
import com.nflg.wms.common.pojo.dto.LdapDepartmentDTO;
|
||||
import com.nflg.wms.common.pojo.dto.LdapUserDTO;
|
||||
import com.nflg.wms.common.pojo.dto.UserDTO;
|
||||
import com.nflg.wms.common.pojo.qo.*;
|
||||
import com.nflg.wms.common.pojo.vo.RoleSimpleVO;
|
||||
|
|
@ -11,6 +15,7 @@ import com.nflg.wms.starter.BaseController;
|
|||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -26,6 +31,9 @@ public class UserController extends BaseController {
|
|||
@Resource
|
||||
private UserControllerService userControllerService;
|
||||
|
||||
@Resource
|
||||
private LDAPControllerService ldapControllerService;
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
*/
|
||||
|
|
@ -108,14 +116,14 @@ public class UserController extends BaseController {
|
|||
return ApiResult.success(userControllerService.search(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从LDAP同步用户
|
||||
*/
|
||||
@PostMapping("syncFromLdap")
|
||||
public ApiResult<Void> syncFromLdap() {
|
||||
userControllerService.syncFromLdap();
|
||||
return ApiResult.success();
|
||||
}
|
||||
// /**
|
||||
// * 从LDAP同步用户
|
||||
// */
|
||||
// @PostMapping("syncFromLdap")
|
||||
// public ApiResult<Void> syncFromLdap() {
|
||||
// userControllerService.syncFromLdap();
|
||||
// return ApiResult.success();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 发送忘记密码邮件
|
||||
|
|
@ -134,4 +142,32 @@ public class UserController extends BaseController {
|
|||
public ApiResult<UserDTO> getUserInfo() {
|
||||
return ApiResult.success(userControllerService.getUserInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取LDAP部门
|
||||
* @param ldapId LDAP表id
|
||||
*/
|
||||
@GetMapping("getLdapDepartments")
|
||||
public ApiResult<LdapDepartmentDTO> getLdapDepartments(@RequestParam Long ldapId){
|
||||
return ApiResult.success(ldapControllerService.searchAdSimple(ldapId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取LDAP用户
|
||||
* @param ldapId LDAP表id
|
||||
* @param distinguishedName 部门的distinguishedName
|
||||
*/
|
||||
@GetMapping("getLdapUsers")
|
||||
public ApiResult<List<LdapUserDTO>> getLdapUsers(@RequestParam Long ldapId, @RequestParam String distinguishedName){
|
||||
return ApiResult.success(ldapControllerService.getUsers(ldapId,distinguishedName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从LDAP添加用户
|
||||
*/
|
||||
@PostMapping("addLdapUser")
|
||||
public ApiResult<Void> addLdapUser(@Valid @RequestBody @NotEmpty List<UserAddLdapQO> users) {
|
||||
userControllerService.addLdapUsers(users);
|
||||
return ApiResult.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.nflg.wms.admin.pojo.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserAddLdapQO {
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* ad表id
|
||||
*/
|
||||
@NotNull
|
||||
private Long ldapId;
|
||||
|
||||
/**
|
||||
* 用户工号
|
||||
*/
|
||||
@NotBlank
|
||||
private String userCode;
|
||||
|
||||
/**
|
||||
* 用户DN
|
||||
*/
|
||||
@NotBlank
|
||||
private String distinguishedName;
|
||||
|
||||
/**
|
||||
* 部门DN
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String departmentDistinguishedName;
|
||||
|
||||
public String getDepartmentDistinguishedName() {
|
||||
return distinguishedName.substring(distinguishedName.indexOf(",") + 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.nflg.wms.admin.pojo.vo;
|
||||
|
||||
import com.nflg.wms.common.pojo.dto.LdapUserDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class LdapDepartmentVO {
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private String distinguishedName;
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
*/
|
||||
private List<LdapUserDTO> users;
|
||||
|
||||
private List<LdapDepartmentVO> children;
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ public class LdapScheduledTask {
|
|||
ads.forEach(ad -> {
|
||||
if (StrUtil.isBlank(ad.getNextSyncDate()) || StrUtil.equals(date, ad.getNextSyncDate())) {
|
||||
departmentControllerService.syncFromLdap(ad);
|
||||
userControllerService.syncFromLdap(ad);
|
||||
// userControllerService.syncFromLdap(ad);
|
||||
adSyncService.lambdaUpdate()
|
||||
.eq(AdSync::getId, ad.getSyncId())
|
||||
.set(AdSync::getNextSyncDate, LocalDate.now().plusDays(ad.getInterval()).format(DATE_FORMATTER))
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.nflg.wms.admin.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.wms.common.pojo.dto.AdDTO;
|
||||
import com.nflg.wms.common.pojo.dto.LdapDepartmentDTO;
|
||||
import com.nflg.wms.common.pojo.dto.LdapUserDTO;
|
||||
import com.nflg.wms.common.pojo.qo.EnableQO;
|
||||
import com.nflg.wms.common.pojo.qo.LDAPAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.LDAPUpdateQO;
|
||||
|
|
@ -12,8 +14,10 @@ import com.nflg.wms.common.pojo.vo.AdSyncVO;
|
|||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.Ad;
|
||||
import com.nflg.wms.repository.entity.User;
|
||||
import com.nflg.wms.repository.service.IAdService;
|
||||
import com.nflg.wms.repository.service.IAdSyncService;
|
||||
import com.nflg.wms.repository.service.IUserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
|
@ -21,6 +25,7 @@ import org.springframework.stereotype.Component;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Component
|
||||
|
|
@ -36,7 +41,7 @@ public class LDAPControllerService {
|
|||
private DepartmentControllerService departmentControllerService;
|
||||
|
||||
@Resource
|
||||
private UserControllerService userControllerService;
|
||||
private IUserService userService;
|
||||
|
||||
public void add(@Valid LDAPAddQO request) {
|
||||
Ad ad = Convert.convert(Ad.class, request);
|
||||
|
|
@ -73,7 +78,7 @@ public class LDAPControllerService {
|
|||
AdDTO ad = adService.getInfo(id);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(ad)).throwMessage("数据不存在");
|
||||
departmentControllerService.syncFromLdap(ad);
|
||||
userControllerService.syncFromLdap(ad);
|
||||
// userControllerService.syncFromLdap(ad);
|
||||
}
|
||||
|
||||
public IPage<Ad> search(@Valid PageQO request) {
|
||||
|
|
@ -93,4 +98,19 @@ public class LDAPControllerService {
|
|||
ldapService.init(ad.getServer(), ad.getPort(), ad.getUserName(), ad.getUserPwd(), ad.getOu(), ad.getTimeout());
|
||||
return ldapService.getDepartmentTree("",true);
|
||||
}
|
||||
|
||||
public List<LdapUserDTO> getUsers(Long id,String distinguishedName){
|
||||
AdDTO ad = adService.getInfo(id);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(ad)).throwMessage("数据不存在");
|
||||
LdapService ldapService = new LdapService();
|
||||
ldapService.init(ad.getServer(), ad.getPort(), ad.getUserName(), ad.getUserPwd(), ad.getOu(), ad.getTimeout());
|
||||
List<LdapUserDTO> users=ldapService.getUsers(distinguishedName);
|
||||
if (CollectionUtil.isEmpty(users)){
|
||||
return null;
|
||||
}
|
||||
List<User> dbUsers = userService.list();
|
||||
return users.stream()
|
||||
.filter(user -> dbUsers.stream().noneMatch(dbUser -> dbUser.getUserCode().equals(user.getUserCode())))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,24 @@ public class LdapService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除 DN 中的 baseDn 后缀,得到相对路径
|
||||
*/
|
||||
private String toRelativeDn(String dn) {
|
||||
if (StrUtil.isBlank(dn) || StrUtil.isBlank(baseDn)) {
|
||||
return dn;
|
||||
}
|
||||
// 忽略大小写比较并去除末尾的 baseDn 部分
|
||||
String dnLower = dn.toLowerCase();
|
||||
String baseDnLower = baseDn.toLowerCase();
|
||||
if (dnLower.endsWith("," + baseDnLower)) {
|
||||
return dn.substring(0, dn.length() - baseDn.length() - 1);
|
||||
} else if (dnLower.equals(baseDnLower)) {
|
||||
return "";
|
||||
}
|
||||
return dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有用户
|
||||
* @return 所有用户
|
||||
|
|
@ -135,9 +153,10 @@ public class LdapService {
|
|||
public List<LdapUserDTO> getUsers(String searchBaseDn) {
|
||||
ldapTemplate.setIgnorePartialResultException(true);
|
||||
log.info("开始获取用户信息");
|
||||
String relativeDn = toRelativeDn(searchBaseDn);
|
||||
LdapQuery query = LdapQueryBuilder.query()
|
||||
.base(searchBaseDn)
|
||||
.searchScope(SearchScope.SUBTREE)
|
||||
.base(relativeDn)
|
||||
.searchScope(SearchScope.ONELEVEL)
|
||||
.where("objectClass").is("person");
|
||||
List<LdapUserDTO> users = ldapTemplate.search(
|
||||
query,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.nflg.wms.admin.service;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.promeg.pinyinhelper.Pinyin;
|
||||
import com.nflg.wms.common.constant.Constant;
|
||||
import com.nflg.wms.common.pojo.qo.*;
|
||||
import com.nflg.wms.common.pojo.vo.RoleVO;
|
||||
import com.nflg.wms.common.pojo.vo.UserVO;
|
||||
|
|
@ -36,10 +37,10 @@ public class RoleControllerService {
|
|||
private IUserRoleMapService userRoleMapService;
|
||||
|
||||
public void addRole(RoleAddQO request) {
|
||||
if (StrUtil.isBlank(request.getCode())){
|
||||
if (StrUtil.isBlank(request.getCode())) {
|
||||
request.setCode(toPinYin(request.getName()));
|
||||
}
|
||||
roleService.add(request, UserUtil.getUserName());
|
||||
roleService.add(request, UserUtil.getUserId(), UserUtil.getUserName());
|
||||
}
|
||||
|
||||
public void updateRole(RoleUpdateQO request) {
|
||||
|
|
@ -48,6 +49,9 @@ public class RoleControllerService {
|
|||
}
|
||||
|
||||
public IPage<RoleVO> searchRoles(RoleSearchQO request) {
|
||||
if (!UserUtil.getRoles().contains(Constant.SUPER_ADMIN)) {
|
||||
request.setUserId(UserUtil.getUserId());
|
||||
}
|
||||
return roleService.search(request);
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +72,7 @@ public class RoleControllerService {
|
|||
return userRoleMapService.getAuthorizeUser(roleId);
|
||||
}
|
||||
|
||||
private String toPinYin(String str){
|
||||
private String toPinYin(String str) {
|
||||
StringBuilder pinyin = new StringBuilder();
|
||||
for (char c : str.toCharArray()) {
|
||||
if (Pinyin.isChinese(c)) {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,14 @@ import cn.hutool.core.util.RandomUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.wms.admin.pojo.request.UserAddLdapQO;
|
||||
import com.nflg.wms.common.constant.Constant;
|
||||
import com.nflg.wms.common.constant.STATE;
|
||||
import com.nflg.wms.common.exception.NflgException;
|
||||
import com.nflg.wms.common.pojo.ApiResult;
|
||||
import com.nflg.wms.common.pojo.dto.*;
|
||||
import com.nflg.wms.common.pojo.dto.SupplierExcelDTO;
|
||||
import com.nflg.wms.common.pojo.dto.SupplierExcelExportDTO;
|
||||
import com.nflg.wms.common.pojo.dto.UserDTO;
|
||||
import com.nflg.wms.common.pojo.qo.*;
|
||||
import com.nflg.wms.common.pojo.vo.RoleSimpleVO;
|
||||
import com.nflg.wms.common.pojo.vo.UserSupplierItemVO;
|
||||
|
|
@ -181,6 +184,9 @@ public class UserControllerService {
|
|||
if (Objects.nonNull(request.getDeptId())) {
|
||||
request.setDeptIds(deptService.getWithChildren(request.getDeptId()));
|
||||
}
|
||||
if (!UserUtil.getRoles().contains(Constant.SUPER_ADMIN)) {
|
||||
request.setCreateById(UserUtil.getUserId());
|
||||
}
|
||||
IPage<UserVO> pu = uService.search(request);
|
||||
pu.getRecords().forEach(userVO -> userVO.setRoles(userRoleMapService.getAuthorizeRole(userVO.getId())));
|
||||
return pu;
|
||||
|
|
@ -192,77 +198,77 @@ public class UserControllerService {
|
|||
uService.enable(request.getId(), request.getEnable());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void syncFromLdap() {
|
||||
List<AdDTO> ads = adService.getList();
|
||||
ads.parallelStream().forEach(this::syncFromLdap);
|
||||
}
|
||||
// @Transactional
|
||||
// public void syncFromLdap() {
|
||||
// List<AdDTO> ads = adService.getList();
|
||||
// ads.parallelStream().forEach(this::syncFromLdap);
|
||||
// }
|
||||
|
||||
@Transactional
|
||||
public void syncFromLdap(AdDTO ad) {
|
||||
LdapService ldapService = new LdapService();
|
||||
ldapService.init(ad.getServer(), ad.getPort(), ad.getUserName(), ad.getUserPwd(), ad.getOu(), ad.getTimeout());
|
||||
List<LdapUserDTO> users = ldapService.getUsers(ad.getMapFrom());
|
||||
List<User> uforAdd = new ArrayList<>();
|
||||
List<User> uforUpdate = new ArrayList<>();
|
||||
List<UserInterior> uiforAdd = new ArrayList<>();
|
||||
List<UserInterior> uiforUpdate = new ArrayList<>();
|
||||
for (LdapUserDTO user : users) {
|
||||
long deptId;
|
||||
if (ad.getType() == 3) {
|
||||
deptId = ad.getMapTo();
|
||||
} else {
|
||||
Department department = deptService.lambdaQuery().eq(Department::getSource, 1).eq(Department::getSourceId, user.getDepartmentDistinguishedName()).one();
|
||||
if (Objects.isNull(department)) {
|
||||
log.error("部门不存在:{}", user.getDepartmentDistinguishedName());
|
||||
continue;
|
||||
}
|
||||
deptId = department.getId();
|
||||
}
|
||||
User u = uService.lambdaQuery().eq(User::getSource, 1).eq(User::getSourceId, user.getDistinguishedName()).one();
|
||||
if (Objects.isNull(u)) {
|
||||
u = new User()
|
||||
.setId(IdUtil.getSnowflakeNextId())
|
||||
.setUserName(user.getName())
|
||||
.setUserCode(user.getUserCode())
|
||||
.setSource(1)
|
||||
.setSourceId(user.getDistinguishedName())
|
||||
.setPassword("")
|
||||
.setAdId(ad.getId())
|
||||
.setMustResetPwd(false)
|
||||
.setRemark("从LDAP同步")
|
||||
.setCreateBy("自动同步")
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
uforAdd.add(u);
|
||||
uiforAdd.add(new UserInterior()
|
||||
.setUserId(u.getId())
|
||||
.setDeptId(deptId));
|
||||
} else {
|
||||
UserInterior ui = userInteriorService.lambdaQuery().eq(UserInterior::getUserId, u.getId()).one();
|
||||
if (!Objects.equals(ui.getDeptId(), deptId))
|
||||
ui.setDeptId(deptId);
|
||||
uforUpdate.add(new User()
|
||||
.setId(u.getId())
|
||||
.setUserName(user.getName())
|
||||
.setUserCode(user.getUserCode())
|
||||
.setUpdateBy("自动同步")
|
||||
.setUpdateTime(LocalDateTime.now()));
|
||||
uiforUpdate.add(ui);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(uforAdd)) {
|
||||
uService.saveBatch(uforAdd);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(uforUpdate)) {
|
||||
uService.updateBatchById(uforUpdate);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(uiforAdd)) {
|
||||
userInteriorService.saveBatch(uiforAdd);
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(uiforUpdate)) {
|
||||
userInteriorService.updateBatchById(uiforUpdate);
|
||||
}
|
||||
}
|
||||
// @Transactional
|
||||
// public void syncFromLdap(AdDTO ad) {
|
||||
// LdapService ldapService = new LdapService();
|
||||
// ldapService.init(ad.getServer(), ad.getPort(), ad.getUserName(), ad.getUserPwd(), ad.getOu(), ad.getTimeout());
|
||||
// List<LdapUserDTO> users = ldapService.getUsers(ad.getMapFrom());
|
||||
// List<User> uforAdd = new ArrayList<>();
|
||||
// List<User> uforUpdate = new ArrayList<>();
|
||||
// List<UserInterior> uiforAdd = new ArrayList<>();
|
||||
// List<UserInterior> uiforUpdate = new ArrayList<>();
|
||||
// for (LdapUserDTO user : users) {
|
||||
// long deptId;
|
||||
// if (ad.getType() == 3) {
|
||||
// deptId = ad.getMapTo();
|
||||
// } else {
|
||||
// Department department = deptService.lambdaQuery().eq(Department::getSource, 1).eq(Department::getSourceId, user.getDepartmentDistinguishedName()).one();
|
||||
// if (Objects.isNull(department)) {
|
||||
// log.error("部门不存在:{}", user.getDepartmentDistinguishedName());
|
||||
// continue;
|
||||
// }
|
||||
// deptId = department.getId();
|
||||
// }
|
||||
// User u = uService.lambdaQuery().eq(User::getSource, 1).eq(User::getSourceId, user.getDistinguishedName()).one();
|
||||
// if (Objects.isNull(u)) {
|
||||
// u = new User()
|
||||
// .setId(IdUtil.getSnowflakeNextId())
|
||||
// .setUserName(user.getName())
|
||||
// .setUserCode(user.getUserCode())
|
||||
// .setSource(1)
|
||||
// .setSourceId(user.getDistinguishedName())
|
||||
// .setPassword("")
|
||||
// .setAdId(ad.getId())
|
||||
// .setMustResetPwd(false)
|
||||
// .setRemark("从LDAP同步")
|
||||
// .setCreateBy("自动同步")
|
||||
// .setCreateTime(LocalDateTime.now());
|
||||
// uforAdd.add(u);
|
||||
// uiforAdd.add(new UserInterior()
|
||||
// .setUserId(u.getId())
|
||||
// .setDeptId(deptId));
|
||||
// } else {
|
||||
// UserInterior ui = userInteriorService.lambdaQuery().eq(UserInterior::getUserId, u.getId()).one();
|
||||
// if (!Objects.equals(ui.getDeptId(), deptId))
|
||||
// ui.setDeptId(deptId);
|
||||
// uforUpdate.add(new User()
|
||||
// .setId(u.getId())
|
||||
// .setUserName(user.getName())
|
||||
// .setUserCode(user.getUserCode())
|
||||
// .setUpdateBy("自动同步")
|
||||
// .setUpdateTime(LocalDateTime.now()));
|
||||
// uiforUpdate.add(ui);
|
||||
// }
|
||||
// }
|
||||
// if (CollectionUtil.isNotEmpty(uforAdd)) {
|
||||
// uService.saveBatch(uforAdd);
|
||||
// }
|
||||
// if (CollectionUtil.isNotEmpty(uforUpdate)) {
|
||||
// uService.updateBatchById(uforUpdate);
|
||||
// }
|
||||
// if (CollectionUtil.isNotEmpty(uiforAdd)) {
|
||||
// userInteriorService.saveBatch(uiforAdd);
|
||||
// }
|
||||
// if (CollectionUtil.isNotEmpty(uiforUpdate)) {
|
||||
// userInteriorService.updateBatchById(uiforUpdate);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void resetPassword(@Valid UserResetPasswordQO request) {
|
||||
User user = uService.getById(request.getId());
|
||||
|
|
@ -761,4 +767,40 @@ public class UserControllerService {
|
|||
.addSheet(new ListSheet<>(datas))
|
||||
.writeTo(response.getOutputStream());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addLdapUsers(List<UserAddLdapQO> ldapUsers) {
|
||||
List<User> users = new ArrayList<>();
|
||||
List<UserInterior> userInteriors = new ArrayList<>();
|
||||
List<Department> departments = deptService.lambdaQuery()
|
||||
.eq(Department::getSource, 1)
|
||||
.in(Department::getSourceId, ldapUsers.stream().map(UserAddLdapQO::getDepartmentDistinguishedName).collect(Collectors.toSet()))
|
||||
.list();
|
||||
ldapUsers.forEach(userAddLdapQO -> {
|
||||
Department department = departments.stream()
|
||||
.filter(it -> it.getSourceId().equals(userAddLdapQO.getDepartmentDistinguishedName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
VUtil.trueThrowBusinessError(Objects.isNull(department)).throwMessage("部门不存在");
|
||||
User user = new User()
|
||||
.setId(IdUtil.getSnowflakeNextId())
|
||||
.setUserCode(userAddLdapQO.getUserCode())
|
||||
.setUserName(userAddLdapQO.getName())
|
||||
.setEnableMustResetPwd(false)
|
||||
.setMustResetPwd(false)
|
||||
.setSource(1)
|
||||
.setSourceId(userAddLdapQO.getDistinguishedName())
|
||||
.setRemark("LDAP用户")
|
||||
.setLanguageCode(Constant.DEFAULT_LANGUAGE_CODE)
|
||||
.setCreateBy(UserUtil.getUserName())
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
users.add(user);
|
||||
userInteriors.add(new UserInterior()
|
||||
.setUserId(user.getId())
|
||||
.setDeptId(department.getId())
|
||||
);
|
||||
});
|
||||
uService.saveBatch(users);
|
||||
userInteriorService.saveBatch(userInteriors);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,6 @@ public class Constant {
|
|||
public static String DICTIONARY_SUPPLIERS_CATEGORY = "SuppliersCategory";
|
||||
|
||||
public static String LOGIN_EXTRA_PURCHASING_GROUP = "purchasing_group";
|
||||
|
||||
public static String SUPER_ADMIN = "SuperAdmin";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.nflg.wms.common.pojo.qo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
|
@ -8,4 +9,7 @@ import lombok.EqualsAndHashCode;
|
|||
public class RoleSearchQO extends PageQO{
|
||||
|
||||
private String name;
|
||||
|
||||
@JsonIgnore
|
||||
private Long userId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,7 @@ public class UserSearchQO extends SearchBaseQO {
|
|||
*/
|
||||
@JsonIgnore
|
||||
private Set<Long> deptIds;
|
||||
|
||||
@JsonIgnore
|
||||
private Long createById;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ package com.nflg.wms.repository.entity;
|
|||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色
|
||||
|
|
@ -41,6 +42,16 @@ public class Role implements Serializable {
|
|||
*/
|
||||
private Boolean enable;
|
||||
|
||||
/**
|
||||
* 类型,0:普通角色;1:业务管理员
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createById;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -59,6 +59,11 @@ public class User implements Serializable {
|
|||
*/
|
||||
private Integer state;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
private Long createById;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ import com.nflg.wms.common.pojo.qo.RoleUpdateQO;
|
|||
import com.nflg.wms.common.pojo.vo.MenuVO;
|
||||
import com.nflg.wms.common.pojo.vo.RoleVO;
|
||||
import com.nflg.wms.repository.entity.Role;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -25,13 +22,13 @@ import java.util.List;
|
|||
*/
|
||||
public interface IRoleService extends IService<Role> {
|
||||
|
||||
void add(@Valid RoleAddQO request,@NotBlank String userName);
|
||||
void add(RoleAddQO request,Long userId,String userName);
|
||||
|
||||
void update(@Valid RoleUpdateQO request, @NotBlank String userName);
|
||||
void update(RoleUpdateQO request, String userName);
|
||||
|
||||
IPage<RoleVO> search(@Valid RoleSearchQO request);
|
||||
IPage<RoleVO> search(RoleSearchQO request);
|
||||
|
||||
void enable(@Valid EnableQO request, String userName);
|
||||
void enable(EnableQO request, String userName);
|
||||
|
||||
List<MenuVO> getMenusByRoleCodes(@Valid @NotNull Long serviceId, Long userId);
|
||||
List<MenuVO> getMenusByRoleCodes(Long serviceId, Long userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.nflg.wms.common.constant.Constant;
|
||||
import com.nflg.wms.common.pojo.qo.EnableMenuQO;
|
||||
import com.nflg.wms.common.pojo.qo.MenuAddQO;
|
||||
import com.nflg.wms.common.pojo.qo.MenuSearchQO;
|
||||
|
|
@ -14,15 +15,15 @@ import com.nflg.wms.common.pojo.qo.MenuUpdateQO;
|
|||
import com.nflg.wms.common.pojo.vo.ButtonVO;
|
||||
import com.nflg.wms.common.pojo.vo.MenuAuthorizeVO;
|
||||
import com.nflg.wms.common.pojo.vo.MenuVO;
|
||||
import com.nflg.wms.common.pojo.vo.RoleVO;
|
||||
import com.nflg.wms.common.util.UserUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.Menu;
|
||||
import com.nflg.wms.repository.entity.MenuButton;
|
||||
import com.nflg.wms.repository.entity.RoleButtonMap;
|
||||
import com.nflg.wms.repository.entity.RoleMenuMap;
|
||||
import com.nflg.wms.repository.mapper.MenuMapper;
|
||||
import com.nflg.wms.repository.service.IMenuButtonService;
|
||||
import com.nflg.wms.repository.service.IMenuService;
|
||||
import com.nflg.wms.repository.service.IRoleButtonMapService;
|
||||
import com.nflg.wms.repository.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -47,6 +48,12 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
|||
@Resource
|
||||
private IRoleButtonMapService roleButtonMapService;
|
||||
|
||||
@Resource
|
||||
private IUserRoleMapService userRoleMapService;
|
||||
|
||||
@Resource
|
||||
private IRoleMenuMapService roleMenuMapService;
|
||||
|
||||
@Override
|
||||
public List<MenuAuthorizeVO> getMenuForAuthorize(Long roleId) {
|
||||
List<Menu> datas = lambdaQuery()
|
||||
|
|
@ -63,6 +70,16 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
|||
@Override
|
||||
public List<MenuAuthorizeVO> getNodeForAuthorize(Long roleId) {
|
||||
List<MenuAuthorizeVO> nodes = baseMapper.getAllDataForAuthorize(roleId);
|
||||
if (!UserUtil.getRoles().contains(Constant.SUPER_ADMIN)){
|
||||
List<RoleVO> userRoles=userRoleMapService.getRoleList(UserUtil.getUserId());
|
||||
List<Long> menuIds =roleMenuMapService.lambdaQuery()
|
||||
.in(RoleMenuMap::getRoleId, userRoles.stream().map(RoleVO::getId).collect(Collectors.toList()))
|
||||
.list()
|
||||
.stream()
|
||||
.map(RoleMenuMap::getMenuId)
|
||||
.toList();
|
||||
nodes.removeIf(v -> !menuIds.contains(v.getId()));
|
||||
}
|
||||
List<MenuAuthorizeVO> rootNodes = nodes.stream().filter(v ->
|
||||
v.getType() == 1 && v.getParentId() == 0
|
||||
).toList();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import com.nflg.wms.common.pojo.qo.RoleSearchQO;
|
|||
import com.nflg.wms.common.pojo.qo.RoleUpdateQO;
|
||||
import com.nflg.wms.common.pojo.vo.MenuVO;
|
||||
import com.nflg.wms.common.pojo.vo.RoleVO;
|
||||
import com.nflg.wms.common.util.BeanUtil;
|
||||
import com.nflg.wms.common.util.VUtil;
|
||||
import com.nflg.wms.repository.entity.Menu;
|
||||
import com.nflg.wms.repository.entity.Role;
|
||||
|
|
@ -45,11 +44,12 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
|||
|
||||
@Transactional
|
||||
@Override
|
||||
public void add(RoleAddQO request, String userName) {
|
||||
public void add(RoleAddQO request,Long userId, String userName) {
|
||||
Role role = new Role()
|
||||
.setCode(request.getCode())
|
||||
.setName(request.getName())
|
||||
.setEnable(request.getEnable())
|
||||
.setCreateById(userId)
|
||||
.setCreateBy(userName)
|
||||
.setCreateTime(LocalDateTime.now());
|
||||
save(role);
|
||||
|
|
|
|||
|
|
@ -22,26 +22,16 @@
|
|||
</select>
|
||||
|
||||
<select id="getAllDataForAuthorize" resultType="com.nflg.wms.common.pojo.vo.MenuAuthorizeVO">
|
||||
select id,
|
||||
parent_id,
|
||||
"name",
|
||||
CONCAT('menu-', id) as key,
|
||||
sort,
|
||||
1 as type,
|
||||
case when b.menu_id is null then false else true end as selected
|
||||
select id,parent_id,"name",CONCAT('menu-', id) as key,sort,1 as type
|
||||
,case when b.menu_id is null then false else true end as selected
|
||||
from menu a
|
||||
left join (select menu_id from role_menu_map where role_id = #{roleId}) b on a.id = b.menu_id
|
||||
left join (select menu_id from role_menu_map where role_id = #{roleId}) b on a.id = b.menu_id
|
||||
where "enable" = true
|
||||
UNION
|
||||
select id,
|
||||
menu_id,
|
||||
"name",
|
||||
CONCAT('button-', id) as key,
|
||||
sort,
|
||||
2 as type,
|
||||
case when b.button_id is null then false else true end as selected
|
||||
select id,menu_id,"name",CONCAT('button-', id) as key,sort,2 as type
|
||||
,case when b.button_id is null then false else true end as selected
|
||||
from menu_button a
|
||||
left join (select button_id from role_button_map where role_id = #{roleId}) b on a.id = b.button_id
|
||||
left join (select button_id from role_button_map where role_id = #{roleId}) b on a.id = b.button_id
|
||||
where "enable" = true
|
||||
order by sort;
|
||||
</select>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
SELECT *
|
||||
FROM role
|
||||
<where>
|
||||
<if test="request.userId != null">
|
||||
AND create_by_id = #{request.userId}
|
||||
</if>
|
||||
<if test="request.name != null and request.name != ''">
|
||||
AND name ilike CONCAT('%',#{request.name},'%')
|
||||
</if>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@
|
|||
select vu.*
|
||||
from v_user_interior vu
|
||||
<where>
|
||||
<if test="request.createById != null">
|
||||
and vu.create_by_id = #{request.createById}
|
||||
</if>
|
||||
<if test="request.deptIds!=null">
|
||||
and vu.dept_id in
|
||||
<foreach item="item" collection="request.deptIds" separator="," close=")" open="(">
|
||||
|
|
|
|||
Loading…
Reference in New Issue