feat:用户-部门
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
package com.xiang.xservice.auth.api.code;
|
||||||
|
|
||||||
|
import com.xiang.xservice.basic.exception.code.BaseErrorCode;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:27
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum Code03DeptErrorCode implements BaseErrorCode {
|
||||||
|
|
||||||
|
DEPT_NOT_EXISTS("A1000301", "部门不存在"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||||
|
|
||||||
public class DeptAddRequest {
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
|
||||||
|
public class DeptAddRequest extends BaseRequest {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||||
|
|
||||||
public class DeptQueryRequest {
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
|
||||||
|
public class DeptQueryRequest extends BaseRequest {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||||
|
|
||||||
public class DeptUpdateRequest {
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
|
||||||
|
public class DeptUpdateRequest extends BaseRequest {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,16 @@
|
|||||||
package com.xiang.xservice.auth.api.dto.req.dept;
|
package com.xiang.xservice.auth.api.dto.req.dept;
|
||||||
|
|
||||||
public class DeptUserUpdateRequest {
|
import com.xiang.xservice.basic.common.req.BaseRequest;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class DeptUserUpdateRequest extends BaseRequest {
|
||||||
|
private Long deptId;
|
||||||
|
private List<Long> userIds;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
|||||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||||
|
import com.xiang.xservice.auth.service.service.XDeptService;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -25,6 +26,8 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DeptController {
|
public class DeptController {
|
||||||
|
|
||||||
|
private final XDeptService deptService;
|
||||||
@PostMapping("/private/dept/list")
|
@PostMapping("/private/dept/list")
|
||||||
public Result<DeptDTO> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
public Result<DeptDTO> getDeptList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") DeptQueryRequest request) {
|
||||||
return Result.success(new DeptDTO());
|
return Result.success(new DeptDTO());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import com.xiang.xservice.auth.api.dto.req.role.RoleQueryRequest;
|
|||||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.role.RoleUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.req.role.RoleUserUpdateRequest;
|
import com.xiang.xservice.auth.api.dto.req.role.RoleUserUpdateRequest;
|
||||||
import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
||||||
import com.xiang.xservice.auth.service.service.RoleService;
|
import com.xiang.xservice.auth.service.service.XRoleService;
|
||||||
import com.xiang.xservice.basic.common.resp.Result;
|
import com.xiang.xservice.basic.common.resp.Result;
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RoleController {
|
public class RoleController {
|
||||||
|
|
||||||
private final RoleService roleService;
|
private final XRoleService roleService;
|
||||||
|
|
||||||
@PostMapping("/private/role/list")
|
@PostMapping("/private/role/list")
|
||||||
public Result<RoleDTO> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
public Result<RoleDTO> getRoleList(@RequestBody @Valid @NotNull(message = "请求参数不能为空") RoleQueryRequest request) {
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ spring:
|
|||||||
primary: master
|
primary: master
|
||||||
datasource:
|
datasource:
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://rm-bp1j371yx9d9894ewbo.mysql.rds.aliyuncs.com:3306/xservice-user?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
url: jdbc:mysql://rm-bp15t34gqx62jm069ro.mysql.rds.aliyuncs.com:3306/xservice-user?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
|
||||||
username: root
|
username: root
|
||||||
password: xb#UWqnhH24&XpX
|
password: xb#UWqnhH24&XpX
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
sshConnect: false
|
sshConnect: false
|
||||||
redis:
|
redis:
|
||||||
host: r-bp1dqqbzlfw04fldp3pd.redis.rds.aliyuncs.com
|
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||||
port: 6379
|
port: 6379
|
||||||
password: Admin@123 # 如果无密码可以省略
|
password: Admin@123 # 如果无密码可以省略
|
||||||
database: 0
|
database: 0
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.xiang.xservice.auth.service.convert;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XDept;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:54
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring")
|
||||||
|
public interface XDeptConvert {
|
||||||
|
XDeptConvert INSTANCE = Mappers.getMapper(XDeptConvert.class);
|
||||||
|
|
||||||
|
XDept toDO(DeptQueryRequest request);
|
||||||
|
XDept toDO(DeptAddRequest request);
|
||||||
|
XDept toDO(DeptUpdateRequest request);
|
||||||
|
|
||||||
|
DeptDTO toDTO(XDept dept);
|
||||||
|
List<DeptDTO> toDTOList(List<XDept> dept);
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:42
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class XDept implements Serializable {
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父类id
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路径
|
||||||
|
*/
|
||||||
|
private String treePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序
|
||||||
|
*/
|
||||||
|
private Integer sortNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createdTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime updatedTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改人
|
||||||
|
*/
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标识(0:未删除 1:已删除)
|
||||||
|
*/
|
||||||
|
private Integer delFlag;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.xiang.xservice.auth.service.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:44
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class XUserDept {
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private Long deptId;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.service.entity.XDept;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:40
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface XDeptMapper {
|
||||||
|
|
||||||
|
int insert(XDept record);
|
||||||
|
int update(XDept record);
|
||||||
|
int delBatch(@Param("ids") List<Long> ids, @Param("time") LocalDateTime time, @Param("operator") String operator);
|
||||||
|
List<XDept> getDeptList(XDept record);
|
||||||
|
XDept getDeptById(Long id);
|
||||||
|
List<XDept> getDeptByIds(@Param("ids") List<Long> ids);
|
||||||
|
List<XDept> getDeptByparentId(@Param("parentId") Long parentId);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.xiang.xservice.auth.service.repository.mapper;
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
import com.xiang.xservice.auth.service.entity.XRole;
|
import com.xiang.xservice.auth.service.entity.XRole;
|
||||||
import com.xiang.xservice.auth.service.entity.XUserRole;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -19,5 +18,4 @@ public interface XRoleMapper {
|
|||||||
List<XRole> getRoleList(XRole record);
|
List<XRole> getRoleList(XRole record);
|
||||||
XRole getRoleById(Long id);
|
XRole getRoleById(Long id);
|
||||||
List<XRole> getRoleByIds(@Param("ids") List<Long> ids);
|
List<XRole> getRoleByIds(@Param("ids") List<Long> ids);
|
||||||
int addBatch(List<XUserRole> list);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.xiang.xservice.auth.service.repository.mapper;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.service.entity.XUserDept;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 17:04
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
@Repository
|
||||||
|
public interface XUserDeptMapper {
|
||||||
|
int addBatch(List<XUserDept> list);
|
||||||
|
|
||||||
|
int delByDeptId(Long deptId);
|
||||||
|
}
|
||||||
@@ -16,4 +16,6 @@ public interface XUserRoleMapper {
|
|||||||
int delByUserId(@Param("userId") Long userId);
|
int delByUserId(@Param("userId") Long userId);
|
||||||
|
|
||||||
int delByRoleIds(@Param("list") List<Long> roleIds);
|
int delByRoleIds(@Param("list") List<Long> roleIds);
|
||||||
|
|
||||||
|
int addBatch(List<XUserRole> list);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.xiang.xservice.auth.service.service;
|
||||||
|
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:36
|
||||||
|
*/
|
||||||
|
public interface XDeptService {
|
||||||
|
List<DeptDTO> getDeptList(DeptQueryRequest request);
|
||||||
|
|
||||||
|
DeptDTO getDeptInfo(Long id);
|
||||||
|
|
||||||
|
Boolean addDept(DeptAddRequest request);
|
||||||
|
|
||||||
|
Boolean updateDept(DeptUpdateRequest request);
|
||||||
|
|
||||||
|
Boolean delDept(List<Long> ids);
|
||||||
|
|
||||||
|
Boolean setUserDept(DeptUserUpdateRequest request);
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import com.xiang.xservice.auth.api.dto.resp.RoleDTO;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface RoleService {
|
public interface XRoleService {
|
||||||
List<RoleDTO> getRoleList(RoleQueryRequest request);
|
List<RoleDTO> getRoleList(RoleQueryRequest request);
|
||||||
|
|
||||||
RoleDTO getRoleInfo(Long id);
|
RoleDTO getRoleInfo(Long id);
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
package com.xiang.xservice.auth.service.service.impl;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.xiang.xservice.auth.api.code.Code03DeptErrorCode;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptAddRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptQueryRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUpdateRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.req.dept.DeptUserUpdateRequest;
|
||||||
|
import com.xiang.xservice.auth.api.dto.resp.DeptDTO;
|
||||||
|
import com.xiang.xservice.auth.service.convert.XDeptConvert;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XDept;
|
||||||
|
import com.xiang.xservice.auth.service.entity.XUserDept;
|
||||||
|
import com.xiang.xservice.auth.service.repository.mapper.XDeptMapper;
|
||||||
|
import com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper;
|
||||||
|
import com.xiang.xservice.auth.service.service.XDeptService;
|
||||||
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: xiang
|
||||||
|
* @Date: 2025-08-29 16:39
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class XDeptServiceImpl implements XDeptService {
|
||||||
|
|
||||||
|
private final static int BATCH_SIZE = 500;
|
||||||
|
private final XDeptMapper deptMapper;
|
||||||
|
private final XDeptConvert deptConvert;
|
||||||
|
private final XUserDeptMapper userDeptMapper;
|
||||||
|
@Override
|
||||||
|
public List<DeptDTO> getDeptList(DeptQueryRequest request) {
|
||||||
|
return deptConvert.toDTOList(deptMapper.getDeptList(deptConvert.toDO(request)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeptDTO getDeptInfo(Long id) {
|
||||||
|
return deptConvert.toDTO(deptMapper.getDeptById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean addDept(DeptAddRequest request) {
|
||||||
|
XDept dept = deptConvert.toDO(request);
|
||||||
|
return deptMapper.insert(dept) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateDept(DeptUpdateRequest request) {
|
||||||
|
XDept dept = deptConvert.toDO(request);
|
||||||
|
dept.setCreateBy(request.getOperator());
|
||||||
|
dept.setUpdateBy(request.getOperator());
|
||||||
|
return deptMapper.update(dept) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delDept(List<Long> ids) {
|
||||||
|
return deptMapper.delBatch(ids, LocalDateTime.now(), "admin") > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean setUserDept(DeptUserUpdateRequest request) {
|
||||||
|
XDept dept = deptMapper.getDeptById(request.getDeptId());
|
||||||
|
if (Objects.isNull(dept)) {
|
||||||
|
log.error("查询部门信息不存在!部门id:{}", request.getDeptId());
|
||||||
|
throw new BusinessException(Code03DeptErrorCode.DEPT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
List<XUserDept> result = Lists.newArrayList();
|
||||||
|
for (Long userId : request.getUserIds()) {
|
||||||
|
XUserDept userDept = new XUserDept();
|
||||||
|
userDept.setDeptId(request.getDeptId());
|
||||||
|
userDept.setUserId(userId);
|
||||||
|
result.add(userDept);
|
||||||
|
}
|
||||||
|
boolean flag = true;
|
||||||
|
if (userDeptMapper.delByDeptId(request.getDeptId()) <= 0) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(result)) {
|
||||||
|
if (result.size() > BATCH_SIZE) {
|
||||||
|
List<List<XUserDept>> partition = Lists.partition(result, BATCH_SIZE);
|
||||||
|
for (List<XUserDept> list : partition) {
|
||||||
|
if (userDeptMapper.addBatch(list) <= 0) {
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return userDeptMapper.addBatch(result) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,23 +11,27 @@ import com.xiang.xservice.auth.service.convert.XRoleConvert;
|
|||||||
import com.xiang.xservice.auth.service.entity.XRole;
|
import com.xiang.xservice.auth.service.entity.XRole;
|
||||||
import com.xiang.xservice.auth.service.entity.XUserRole;
|
import com.xiang.xservice.auth.service.entity.XUserRole;
|
||||||
import com.xiang.xservice.auth.service.repository.mapper.XRoleMapper;
|
import com.xiang.xservice.auth.service.repository.mapper.XRoleMapper;
|
||||||
import com.xiang.xservice.auth.service.service.RoleService;
|
import com.xiang.xservice.auth.service.repository.mapper.XUserRoleMapper;
|
||||||
|
import com.xiang.xservice.auth.service.service.XRoleService;
|
||||||
import com.xiang.xservice.basic.exception.BusinessException;
|
import com.xiang.xservice.basic.exception.BusinessException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class XRoleServiceImpl implements RoleService {
|
public class XRoleServiceImpl implements XRoleService {
|
||||||
private final static int BATCH_SIZE = 500;
|
private final static int BATCH_SIZE = 500;
|
||||||
private final XRoleMapper roleMapper;
|
private final XRoleMapper roleMapper;
|
||||||
|
private final XUserRoleMapper userRoleMapper;
|
||||||
private final XRoleConvert roleConvert;
|
private final XRoleConvert roleConvert;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,6 +71,7 @@ public class XRoleServiceImpl implements RoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean setUserRole(RoleUserUpdateRequest request) {
|
public Boolean setUserRole(RoleUserUpdateRequest request) {
|
||||||
XRole role = roleMapper.getRoleById(request.getRoleId());
|
XRole role = roleMapper.getRoleById(request.getRoleId());
|
||||||
if (Objects.isNull(role)) {
|
if (Objects.isNull(role)) {
|
||||||
@@ -80,17 +85,20 @@ public class XRoleServiceImpl implements RoleService {
|
|||||||
xUserRole.setUserId(userId);
|
xUserRole.setUserId(userId);
|
||||||
params.add(xUserRole);
|
params.add(xUserRole);
|
||||||
}
|
}
|
||||||
Boolean flag = Boolean.TRUE;
|
boolean flag = Boolean.TRUE;
|
||||||
|
if (userRoleMapper.delByRoleIds(Collections.singletonList(request.getRoleId())) <= 0) {
|
||||||
|
return Boolean.FALSE;
|
||||||
|
}
|
||||||
if (CollectionUtils.isNotEmpty(params)) {
|
if (CollectionUtils.isNotEmpty(params)) {
|
||||||
if (params.size() > BATCH_SIZE) {
|
if (params.size() > BATCH_SIZE) {
|
||||||
List<List<XUserRole>> partition = Lists.partition(params, BATCH_SIZE);
|
List<List<XUserRole>> partition = Lists.partition(params, BATCH_SIZE);
|
||||||
for (List<XUserRole> list : partition) {
|
for (List<XUserRole> list : partition) {
|
||||||
if (roleMapper.addBatch(list) <= 0) {
|
if (userRoleMapper.addBatch(list) <= 0) {
|
||||||
flag = false;
|
flag = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return roleMapper.addBatch(params) > 0;
|
return userRoleMapper.addBatch(params) > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return flag;
|
return flag;
|
||||||
|
|||||||
146
xs-service/src/main/resources/mapper/user/XDeptMapper.xml
Normal file
146
xs-service/src/main/resources/mapper/user/XDeptMapper.xml
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XDeptMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XUserDept" >
|
||||||
|
<result column="name" property="name" />
|
||||||
|
<result column="parent_id" property="parentId" />
|
||||||
|
<result column="tree_path" property="treePath" />
|
||||||
|
<result column="sort_no" property="sortNo" />
|
||||||
|
<result column="created_time" property="createdTime" />
|
||||||
|
<result column="create_by" property="createBy" />
|
||||||
|
<result column="updated_time" property="updatedTime" />
|
||||||
|
<result column="update_by" property="updateBy" />
|
||||||
|
<result column="del_flag" property="delFlag" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
name,
|
||||||
|
parent_id,
|
||||||
|
tree_path,
|
||||||
|
sort_no,
|
||||||
|
created_time,
|
||||||
|
create_by,
|
||||||
|
updated_time,
|
||||||
|
update_by,
|
||||||
|
del_flag
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.xiang.xservice.auth.service.entity.XUserDept">
|
||||||
|
INSERT INTO x_dept
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="null != name and '' != name">
|
||||||
|
name,
|
||||||
|
</if>
|
||||||
|
<if test="null != parentId ">
|
||||||
|
parent_id,
|
||||||
|
</if>
|
||||||
|
<if test="null != treePath and '' != treePath">
|
||||||
|
tree_path,
|
||||||
|
</if>
|
||||||
|
<if test="null != sortNo ">
|
||||||
|
sort_no,
|
||||||
|
</if>
|
||||||
|
<if test="null != createdTime ">
|
||||||
|
created_time,
|
||||||
|
</if>
|
||||||
|
<if test="null != createBy and '' != createBy">
|
||||||
|
create_by,
|
||||||
|
</if>
|
||||||
|
<if test="null != updatedTime ">
|
||||||
|
updated_time,
|
||||||
|
</if>
|
||||||
|
<if test="null != updateBy and '' != updateBy">
|
||||||
|
update_by,
|
||||||
|
</if>
|
||||||
|
<if test="null != delFlag ">
|
||||||
|
del_flag
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="null != name and '' != name">
|
||||||
|
#{name},
|
||||||
|
</if>
|
||||||
|
<if test="null != parentId ">
|
||||||
|
#{parentId},
|
||||||
|
</if>
|
||||||
|
<if test="null != treePath and '' != treePath">
|
||||||
|
#{treePath},
|
||||||
|
</if>
|
||||||
|
<if test="null != sortNo ">
|
||||||
|
#{sortNo},
|
||||||
|
</if>
|
||||||
|
<if test="null != createdTime ">
|
||||||
|
#{createdTime},
|
||||||
|
</if>
|
||||||
|
<if test="null != createBy and '' != createBy">
|
||||||
|
#{createBy},
|
||||||
|
</if>
|
||||||
|
<if test="null != updatedTime ">
|
||||||
|
#{updatedTime},
|
||||||
|
</if>
|
||||||
|
<if test="null != updateBy and '' != updateBy">
|
||||||
|
#{updateBy},
|
||||||
|
</if>
|
||||||
|
<if test="null != delFlag ">
|
||||||
|
#{delFlag}
|
||||||
|
</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="delBatch" >
|
||||||
|
update x_dept
|
||||||
|
SET del_flag = 1, updated_time = now(), update_by = #{updateBy}
|
||||||
|
WHERE id IN
|
||||||
|
<foreach item="item" collection="ids" separator="," open="(" close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="update" parameterType="com.xiang.xservice.auth.service.entity.XUserDept">
|
||||||
|
UPDATE x_dept
|
||||||
|
<set>
|
||||||
|
<if test="null != name and '' != name">name = #{name},</if>
|
||||||
|
<if test="null != parentId ">parent_id = #{parentId},</if>
|
||||||
|
<if test="null != treePath and '' != treePath">tree_path = #{treePath},</if>
|
||||||
|
<if test="null != sortNo ">sort_no = #{sortNo},</if>
|
||||||
|
<if test="null != createdTime ">created_time = #{createdTime},</if>
|
||||||
|
<if test="null != createBy and '' != createBy">create_by = #{createBy},</if>
|
||||||
|
<if test="null != updatedTime ">updated_time = #{updatedTime},</if>
|
||||||
|
<if test="null != updateBy and '' != updateBy">update_by = #{updateBy},</if>
|
||||||
|
<if test="null != delFlag ">del_flag = #{delFlag}</if>
|
||||||
|
</set>
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<select id="getDeptList" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_dept
|
||||||
|
<trim prefix="AND">
|
||||||
|
<where>
|
||||||
|
del_flag = 0
|
||||||
|
<if test="name != null and name != ''">AND name = #{name}</if>
|
||||||
|
</where>
|
||||||
|
</trim>
|
||||||
|
</select>
|
||||||
|
<select id="getDeptById" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_dept
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
<select id="getDeptByIds" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_dept
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
<select id="getDeptByparentId" resultMap="BaseResultMap">
|
||||||
|
select <include refid="Base_Column_List"/>
|
||||||
|
from x_dept
|
||||||
|
where parent_id = #{parentId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -90,12 +90,7 @@
|
|||||||
</if>
|
</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
<insert id="addBatch">
|
|
||||||
insert into x_role(user_id, role_id) values
|
|
||||||
<foreach collection="list" item="item" separator=",">
|
|
||||||
(#{item.userId}, #{item.roleId})
|
|
||||||
</foreach>
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="delBatch" >
|
<update id="delBatch" >
|
||||||
update x_role set del_flag = 0, update_time = #{time}, update_by = #{operator} where id in
|
update x_role set del_flag = 0, update_time = #{time}, update_by = #{operator} where id in
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.xiang.xservice.auth.service.repository.mapper.XUserDeptMapper">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.xiang.xservice.auth.service.entity.XUserDept" >
|
||||||
|
<result column="user_id" property="userId" />
|
||||||
|
<result column="dept_id" property="deptId" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
user_id,
|
||||||
|
dept_id
|
||||||
|
</sql>
|
||||||
|
<insert id="addBatch">
|
||||||
|
insert into x_user_data_scope_dept(user_id, dept_id) values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(#{item.userId}, #{item.deptId})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<delete id="delByDeptId">
|
||||||
|
delete from x_user_data_scope_dept where dept_id = #{deptId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
<delete id="delByUserId">
|
<delete id="delByUserId">
|
||||||
delete from x_user_role where user_id = #{userId}
|
delete from x_user_role where user_id = #{userId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<delete id="delByRoleIds">
|
<delete id="delByRoleIds">
|
||||||
delete from x_user_role where role_id in
|
delete from x_user_role where role_id in
|
||||||
<foreach collection="list" item="id" open="(" close=")" separator=",">
|
<foreach collection="list" item="id" open="(" close=")" separator=",">
|
||||||
@@ -30,5 +31,12 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<insert id="addBatch">
|
||||||
|
insert into x_user_role(user_id, role_id) values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(#{item.userId}, #{item.roleId})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user