feat: ASW-47 user 接口开发
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.geedge.asw.common.util;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
|
|
||||||
|
public class HttpContextUtils {
|
||||||
|
|
||||||
|
public static HttpServletRequest getHttpServletRequest() {
|
||||||
|
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
82
src/main/java/net/geedge/asw/common/util/IPUtils.java
Normal file
82
src/main/java/net/geedge/asw/common/util/IPUtils.java
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
|
||||||
|
*
|
||||||
|
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.geedge.asw.common.util;
|
||||||
|
|
||||||
|
import cn.hutool.log.Log;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IP地址
|
||||||
|
*
|
||||||
|
* @author Mark sunlightcs@gmail.com
|
||||||
|
*/
|
||||||
|
public class IPUtils {
|
||||||
|
private static Log logger = Log.get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取IP地址
|
||||||
|
*
|
||||||
|
* 使用Nginx等反向代理软件, 则不能通过request.getRemoteAddr()获取IP地址
|
||||||
|
* 如果使用了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP地址,X-Forwarded-For中第一个非unknown的有效IP字符串,则为真实IP地址
|
||||||
|
*/
|
||||||
|
public static String getIpAddr(HttpServletRequest request) {
|
||||||
|
String ip = null;
|
||||||
|
try {
|
||||||
|
ip = request.getHeader("x-forwarded-for");
|
||||||
|
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) {
|
||||||
|
ip = request.getRemoteAddr();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("IPUtils ERROR ",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// //使用代理,则获取第一个IP地址
|
||||||
|
// if(StringUtils.isEmpty(ip) && ip.length() > 15) {
|
||||||
|
// if(ip.indexOf(",") > 0) {
|
||||||
|
// ip = ip.substring(0, ip.indexOf(","));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 功能:判断一个IP是不是在一个网段下的
|
||||||
|
* 格式:isInRange("192.168.8.3", "192.168.9.10/22");
|
||||||
|
*/
|
||||||
|
public static boolean isInRange(String ip, String cidr) {
|
||||||
|
String[] ips = ip.split("\\.");
|
||||||
|
int ipAddr = (Integer.parseInt(ips[0]) << 24)
|
||||||
|
| (Integer.parseInt(ips[1]) << 16)
|
||||||
|
| (Integer.parseInt(ips[2]) << 8) | Integer.parseInt(ips[3]);
|
||||||
|
int type = Integer.parseInt(cidr.replaceAll(".*/", ""));
|
||||||
|
int mask = 0xFFFFFFFF << (32 - type);
|
||||||
|
String cidrIp = cidr.replaceAll("/.*", "");
|
||||||
|
String[] cidrIps = cidrIp.split("\\.");
|
||||||
|
int cidrIpAddr = (Integer.parseInt(cidrIps[0]) << 24)
|
||||||
|
| (Integer.parseInt(cidrIps[1]) << 16)
|
||||||
|
| (Integer.parseInt(cidrIps[2]) << 8)
|
||||||
|
| Integer.parseInt(cidrIps[3]);
|
||||||
|
|
||||||
|
return (ipAddr & mask) == (cidrIpAddr & mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,10 @@ public enum RCode {
|
|||||||
ROLE_ID_CANNOT_EMPTY(100010, "role id cannot be empty"),// 权限 ID 不能为空
|
ROLE_ID_CANNOT_EMPTY(100010, "role id cannot be empty"),// 权限 ID 不能为空
|
||||||
USER_NOT_EXIST(100011, "user does not exist"),
|
USER_NOT_EXIST(100011, "user does not exist"),
|
||||||
ROLE_NOT_EXIST(100012, "role does not exist"),
|
ROLE_NOT_EXIST(100012, "role does not exist"),
|
||||||
|
SYS_USER_NAME_CANNOT_EMPTY(100013, "username cannot be empty"),
|
||||||
|
SYS_ACCESS_LEVEL_CANNOT_EMPTY(100014, "accessLevel cannot be empty"),
|
||||||
|
SYS_WORKSPACE_ROLES_CANNOT_EMPTY(100015, "workspaceRoles cannot be empty"),
|
||||||
|
SYS_USER_BUILT_IN(100016, "Built-in user are not allowed to delete or update"),
|
||||||
|
|
||||||
|
|
||||||
// Application
|
// Application
|
||||||
@@ -59,6 +63,7 @@ public enum RCode {
|
|||||||
WORKSPACE_CANNOT_DELETE(401007, "Built-in workspace cannot be deleted"),
|
WORKSPACE_CANNOT_DELETE(401007, "Built-in workspace cannot be deleted"),
|
||||||
WORKSPACE_VISIBILITY_ERROR(401008, "workspace visibility error"),
|
WORKSPACE_VISIBILITY_ERROR(401008, "workspace visibility error"),
|
||||||
WORKSPACE_BUILT_IN(401009, "Built-in workspace cannot be update"),
|
WORKSPACE_BUILT_IN(401009, "Built-in workspace cannot be update"),
|
||||||
|
WORKSPACE_NOT_EXIST(401010, "Workspace does not exist"),
|
||||||
|
|
||||||
//PCAP
|
//PCAP
|
||||||
PCAP_UPLOAD_WEB_SHARK_ERROR(501001, "web shark upload pcap error"),
|
PCAP_UPLOAD_WEB_SHARK_ERROR(501001, "web shark upload pcap error"),
|
||||||
|
|||||||
@@ -2,20 +2,17 @@ package net.geedge.asw.module.sys.controller;
|
|||||||
|
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import net.geedge.asw.common.util.*;
|
import net.geedge.asw.common.util.*;
|
||||||
import net.geedge.asw.module.sys.entity.SysRoleEntity;
|
|
||||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||||
import net.geedge.asw.module.sys.entity.SysUserRoleEntity;
|
|
||||||
import net.geedge.asw.module.sys.service.ISysRoleService;
|
|
||||||
import net.geedge.asw.module.sys.service.ISysUserRoleService;
|
|
||||||
import net.geedge.asw.module.sys.service.ISysUserService;
|
import net.geedge.asw.module.sys.service.ISysUserService;
|
||||||
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
|
import net.geedge.asw.module.workspace.service.IWorkspaceMemberService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/user")
|
@RequestMapping("/api/v1/user")
|
||||||
@@ -24,80 +21,63 @@ public class SysUserController {
|
|||||||
private static final Log log = Log.get();
|
private static final Log log = Log.get();
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysUserService userService;
|
private ISysUserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysRoleService roleService;
|
private IWorkspaceMemberService workspaceMemberService;
|
||||||
@Autowired
|
|
||||||
private ISysUserRoleService uerRoleService;
|
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public R detail(@PathVariable("id") String id) {
|
public R detail(@PathVariable("id") String id) {
|
||||||
SysUserEntity entity = userService.getById(id);
|
SysUserEntity entity = userService.getById(id);
|
||||||
if (T.ObjectUtil.isNotNull(entity)) {
|
if (T.ObjectUtil.isNotNull(entity)) {
|
||||||
entity.setPwd(null);
|
entity.setPwd(null);
|
||||||
List<SysUserRoleEntity> userRoleList = uerRoleService.list(new LambdaQueryWrapper<SysUserRoleEntity>().eq(SysUserRoleEntity::getUserId, entity.getId()));
|
Map params = T.MapUtil.builder("userId", id).build();
|
||||||
if (T.CollUtil.isNotEmpty(userRoleList)) {
|
List<WorkspaceMemberEntity> workspaceMemberEntityList = workspaceMemberService.queryList(params);
|
||||||
List<String> roleIds = userRoleList.stream().map(SysUserRoleEntity::getRoleId).collect(Collectors.toList());
|
entity.setWorkspaceRoles(workspaceMemberEntityList);
|
||||||
List<SysRoleEntity> roleList = roleService.listByIds(roleIds);
|
SysUserEntity createUser = userService.getOne(new LambdaQueryWrapper<SysUserEntity>().eq(SysUserEntity::getCreateUserId, entity.getCreateUserId()));
|
||||||
entity.setRoles(roleList);
|
createUser.setPwd(null);
|
||||||
}
|
entity.setCreateUser(createUser);
|
||||||
|
SysUserEntity updateUser = userService.getOne(new LambdaQueryWrapper<SysUserEntity>().eq(SysUserEntity::getUpdateUserId, entity.getUpdateUserId()));
|
||||||
|
updateUser.setPwd(null);
|
||||||
|
entity.setUpdateUser(updateUser);
|
||||||
}
|
}
|
||||||
return R.ok().putData("record", entity);
|
return R.ok().putData("record", entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public R list(String ids, String q,
|
public R list(@RequestParam Map<String, Object> params) {
|
||||||
@RequestParam(defaultValue = "1") Integer current,
|
Page<SysUserEntity> page = userService.queryList(params);
|
||||||
@RequestParam(defaultValue = "20") Integer size,
|
|
||||||
@RequestParam(defaultValue = "name") String orderBy) {
|
|
||||||
QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
|
|
||||||
// 不查询 pwd 列
|
|
||||||
queryWrapper.select(SysUserEntity.class, entity -> !entity.getColumn().equals("pwd"));
|
|
||||||
queryWrapper.in(T.StrUtil.isNotEmpty(ids), "id", T.StrUtil.split(ids, ','));
|
|
||||||
if (T.StrUtil.isNotBlank(q)) {
|
|
||||||
queryWrapper.and(wrapper -> wrapper.like("name", q).or().like("user_name", q));
|
|
||||||
}
|
|
||||||
Page<SysUserEntity> page = Page.of(current, size);
|
|
||||||
page.addOrder(T.PageUtil.decodeOrderByStr(orderBy));
|
|
||||||
page = userService.page(page, queryWrapper);
|
|
||||||
return R.ok(page);
|
return R.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public R add(@RequestBody SysUserEntity entity) {
|
public R add(@RequestBody SysUserEntity entity) {
|
||||||
T.VerifyUtil.is(entity).notNull().and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
T.VerifyUtil.is(entity).notNull()
|
||||||
.and(entity.getUserName()).notEmpty().and(entity.getPwd()).notEmpty();
|
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||||
SysUserEntity one = userService.getOne(
|
.and(entity.getUserName()).notEmpty(RCode.SYS_USER_NAME_CANNOT_EMPTY)
|
||||||
new QueryWrapper<SysUserEntity>().lambda().eq(SysUserEntity::getUserName, entity.getUserName()));
|
.and(entity.getAccessLevel()).notEmpty(RCode.SYS_ACCESS_LEVEL_CANNOT_EMPTY)
|
||||||
if (T.ObjectUtil.isNotNull(one)) {
|
.and(entity.getWorkspaceRoles()).notEmpty(RCode.SYS_WORKSPACE_ROLES_CANNOT_EMPTY);
|
||||||
throw ASWException.builder().rcode(RCode.SYS_DUPLICATE_RECORD).build();
|
|
||||||
}
|
userService.saveUser(entity);
|
||||||
// 密码加密
|
|
||||||
entity.setPwd(T.AesUtil.encrypt(entity.getPwd(), Constants.AES_KEY));
|
|
||||||
entity.setCreateTimestamp(T.DateUtil.current());
|
|
||||||
userService.saveOrUpdateUser(entity);
|
|
||||||
return R.ok().putData("id", entity.getId());
|
return R.ok().putData("id", entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public R update(@RequestBody SysUserEntity entity) {
|
public R update(@RequestBody SysUserEntity entity) {
|
||||||
T.VerifyUtil.is(entity).notNull().and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY);
|
T.VerifyUtil.is(entity).notNull()
|
||||||
if (T.StrUtil.isNotBlank(entity.getPwd())) {
|
.and(entity.getId()).notEmpty(RCode.ID_CANNOT_EMPTY)
|
||||||
// 密码加密
|
.and(entity.getName()).notEmpty(RCode.NAME_CANNOT_EMPTY)
|
||||||
entity.setPwd(T.AesUtil.encrypt(entity.getPwd(), Constants.AES_KEY));
|
.and(entity.getUserName()).notEmpty(RCode.SYS_USER_NAME_CANNOT_EMPTY)
|
||||||
} else {
|
.and(entity.getAccessLevel()).notEmpty(RCode.SYS_ACCESS_LEVEL_CANNOT_EMPTY)
|
||||||
entity.setPwd(null);
|
.and(entity.getWorkspaceRoles()).notEmpty(RCode.SYS_WORKSPACE_ROLES_CANNOT_EMPTY);
|
||||||
}
|
userService.updateUser(entity);
|
||||||
entity.setUserName(null);// username 不允许修改
|
|
||||||
entity.setCreateTimestamp(null);
|
|
||||||
userService.saveOrUpdateUser(entity);
|
|
||||||
return R.ok().putData("id", entity.getId());
|
return R.ok().putData("id", entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
public R delete(String[] ids) {
|
public R delete(String ids) {
|
||||||
T.VerifyUtil.is(ids).notEmpty();
|
T.VerifyUtil.is(ids).notEmpty();
|
||||||
userService.removeBatchByIds(T.ListUtil.of(ids));
|
userService.delete(ids);
|
||||||
log.info("delete user, ids: {}", T.ArrayUtil.toString(ids));
|
log.info("delete user, ids: {}", ids);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
package net.geedge.asw.module.sys.dao;
|
package net.geedge.asw.module.sys.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SysUserDao extends BaseMapper<SysUserEntity>{
|
public interface SysUserDao extends BaseMapper<SysUserEntity>{
|
||||||
|
|
||||||
|
List<SysUserEntity> queryList(Page page, Map params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("sys_user")
|
@TableName("sys_user")
|
||||||
@@ -23,13 +24,31 @@ public class SysUserEntity {
|
|||||||
|
|
||||||
private String pwd;
|
private String pwd;
|
||||||
|
|
||||||
@TableField(exist = false)
|
|
||||||
private String roleIds;
|
|
||||||
|
|
||||||
@TableField(exist = false)
|
|
||||||
private List<SysRoleEntity> roles;
|
|
||||||
|
|
||||||
private String accessLevel;
|
private String accessLevel;
|
||||||
|
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
private String lastLoginIp;
|
||||||
|
|
||||||
|
private Long lastLoginTimestamp;
|
||||||
|
|
||||||
|
private String createUserId;
|
||||||
|
|
||||||
|
private String updateUserId;
|
||||||
|
|
||||||
private Long createTimestamp;
|
private Long createTimestamp;
|
||||||
|
|
||||||
|
private Long updateTimestamp;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private List<WorkspaceMemberEntity> workspaceRoles;
|
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private SysUserEntity createUser;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private SysUserEntity updateUser;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package net.geedge.asw.module.sys.service;
|
package net.geedge.asw.module.sys.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ISysUserService extends IService<SysUserEntity>{
|
public interface ISysUserService extends IService<SysUserEntity>{
|
||||||
|
|
||||||
public void saveOrUpdateUser(SysUserEntity entity);
|
void updateUser(SysUserEntity entity);
|
||||||
|
|
||||||
|
Page<SysUserEntity> queryList(Map params);
|
||||||
|
|
||||||
|
void saveUser(SysUserEntity entity);
|
||||||
|
|
||||||
|
void delete(String ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,18 @@ package net.geedge.asw.module.sys.service.impl;
|
|||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
import cn.hutool.core.collection.ListUtil;
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.lang.Pair;
|
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.log.Log;
|
import cn.hutool.log.Log;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import net.geedge.asw.common.util.ASWException;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import net.geedge.asw.common.util.Constants;
|
import net.geedge.asw.common.util.*;
|
||||||
import net.geedge.asw.common.util.RCode;
|
|
||||||
import net.geedge.asw.common.util.T;
|
|
||||||
import net.geedge.asw.module.sys.dao.SysRoleDao;
|
import net.geedge.asw.module.sys.dao.SysRoleDao;
|
||||||
import net.geedge.asw.module.sys.dao.SysUserDao;
|
import net.geedge.asw.module.sys.dao.SysUserDao;
|
||||||
import net.geedge.asw.module.sys.entity.SysMenuEntity;
|
import net.geedge.asw.module.sys.entity.SysMenuEntity;
|
||||||
import net.geedge.asw.module.sys.entity.SysRoleEntity;
|
import net.geedge.asw.module.sys.entity.SysRoleEntity;
|
||||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||||
import net.geedge.asw.module.sys.service.ISysAuthService;
|
import net.geedge.asw.module.sys.service.ISysAuthService;
|
||||||
import net.geedge.asw.module.workbook.entity.WorkbookMemberEntity;
|
|
||||||
import net.geedge.asw.module.workbook.service.IWorkbookMemberService;
|
|
||||||
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||||
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
import net.geedge.asw.module.workspace.service.IWorkspaceMemberService;
|
import net.geedge.asw.module.workspace.service.IWorkspaceMemberService;
|
||||||
@@ -26,7 +21,6 @@ import net.geedge.asw.module.workspace.service.IWorkspaceService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -58,6 +52,12 @@ public class SysAuthServiceImpl implements ISysAuthService {
|
|||||||
throw ASWException.builder().rcode(RCode.SYS_USER_PWD_ERROR).build();
|
throw ASWException.builder().rcode(RCode.SYS_USER_PWD_ERROR).build();
|
||||||
}
|
}
|
||||||
StpUtil.login(userEntity.getId());
|
StpUtil.login(userEntity.getId());
|
||||||
|
|
||||||
|
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
|
||||||
|
userEntity.setLastLoginTimestamp(System.currentTimeMillis());
|
||||||
|
// 设置IP地址
|
||||||
|
userEntity.setLastLoginIp(IPUtils.getIpAddr(request));
|
||||||
|
userDao.updateById(userEntity);
|
||||||
log.info("user login success, userName: {}", userName);
|
log.info("user login success, userName: {}", userName);
|
||||||
return userEntity;
|
return userEntity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,38 +1,152 @@
|
|||||||
package net.geedge.asw.module.sys.service.impl;
|
package net.geedge.asw.module.sys.service.impl;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import net.geedge.asw.common.util.ASWException;
|
||||||
|
import net.geedge.asw.common.util.Constants;
|
||||||
|
import net.geedge.asw.common.util.RCode;
|
||||||
import net.geedge.asw.common.util.T;
|
import net.geedge.asw.common.util.T;
|
||||||
import net.geedge.asw.module.sys.dao.SysUserDao;
|
import net.geedge.asw.module.sys.dao.SysUserDao;
|
||||||
|
import net.geedge.asw.module.sys.entity.SysRoleEntity;
|
||||||
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
import net.geedge.asw.module.sys.entity.SysUserEntity;
|
||||||
import net.geedge.asw.module.sys.entity.SysUserRoleEntity;
|
import net.geedge.asw.module.sys.service.ISysRoleService;
|
||||||
import net.geedge.asw.module.sys.service.ISysUserService;
|
import net.geedge.asw.module.sys.service.ISysUserService;
|
||||||
|
import net.geedge.asw.module.workspace.entity.WorkspaceEntity;
|
||||||
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
|
import net.geedge.asw.module.workspace.service.IWorkspaceMemberService;
|
||||||
|
import net.geedge.asw.module.workspace.service.IWorkspaceService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements ISysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> implements ISysUserService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysUserRoleServiceImpl userRoleService;
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWorkspaceMemberService workspaceMemberService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IWorkspaceService workspaceService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<SysUserEntity> queryList(Map params) {
|
||||||
|
|
||||||
|
Page page = T.PageUtil.getPage(params);
|
||||||
|
List<SysUserEntity> jobList = this.getBaseMapper().queryList(page, params);
|
||||||
|
page.setRecords(jobList);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveOrUpdateUser(SysUserEntity entity) {
|
public void updateUser(SysUserEntity entity) {
|
||||||
if (T.StrUtil.isNotBlank(entity.getId())) {
|
|
||||||
userRoleService.remove(new QueryWrapper<SysUserRoleEntity>().eq("user_id", entity.getId()));
|
SysUserEntity user = this.getById(StpUtil.getLoginIdAsString());
|
||||||
}
|
if (!T.StrUtil.equalsIgnoreCase(user.getAccessLevel(), "administrator")){
|
||||||
// 保存 user
|
throw ASWException.builder().rcode(RCode.SYS_NO_AUTH).build();
|
||||||
this.saveOrUpdate(entity);
|
|
||||||
// 保存 user role关系
|
|
||||||
List<SysUserRoleEntity> urList = T.ListUtil.list(false);
|
|
||||||
for (String roleId : T.StrUtil.split(entity.getRoleIds(), ",")) {
|
|
||||||
urList.add(SysUserRoleEntity.builder().roleId(roleId).userId(entity.getId()).build());
|
|
||||||
}
|
|
||||||
userRoleService.saveBatch(urList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (T.StrUtil.equalsIgnoreCase(entity.getId(), "admin")){
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_USER_BUILT_IN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUserEntity one = this.getOne(
|
||||||
|
new QueryWrapper<SysUserEntity>().lambda().eq(SysUserEntity::getUserName, entity.getUserName()));
|
||||||
|
if (T.ObjectUtil.isNotNull(one) && !T.StrUtil.equals(entity.getId(), one.getId())) {
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_DUPLICATE_RECORD).build();
|
||||||
|
}
|
||||||
|
// 密码加密
|
||||||
|
if (T.StrUtil.isNotEmpty(entity.getPwd())){
|
||||||
|
entity.setPwd(T.AesUtil.encrypt(entity.getPwd(), Constants.AES_KEY));
|
||||||
|
}
|
||||||
|
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
|
|
||||||
|
// 保存 user
|
||||||
|
this.updateById(entity);
|
||||||
|
|
||||||
|
// save workspace member
|
||||||
|
this.saveWorkspaceRole(entity.getWorkspaceRoles(), entity.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void saveUser(SysUserEntity entity) {
|
||||||
|
SysUserEntity user = this.getById(StpUtil.getLoginIdAsString());
|
||||||
|
if (!T.StrUtil.equalsIgnoreCase(user.getAccessLevel(), "administrator")){
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_NO_AUTH).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
SysUserEntity one = this.getOne(
|
||||||
|
new QueryWrapper<SysUserEntity>().lambda().eq(SysUserEntity::getUserName, entity.getUserName()));
|
||||||
|
if (T.ObjectUtil.isNotNull(one)) {
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_DUPLICATE_RECORD).build();
|
||||||
|
}
|
||||||
|
// 密码加密
|
||||||
|
entity.setPwd(T.AesUtil.encrypt(entity.getPwd(), Constants.AES_KEY));
|
||||||
|
entity.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
entity.setUpdateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
entity.setCreateTimestamp(System.currentTimeMillis());
|
||||||
|
entity.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
|
|
||||||
|
// 以当前时间为最后登陆时间
|
||||||
|
entity.setLastLoginTimestamp(System.currentTimeMillis());
|
||||||
|
// save user
|
||||||
|
this.save(entity);
|
||||||
|
|
||||||
|
// save workspace member
|
||||||
|
this.saveWorkspaceRole(entity.getWorkspaceRoles(), entity.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveWorkspaceRole(List<WorkspaceMemberEntity> workspaceRoles, String userId) {
|
||||||
|
|
||||||
|
List<WorkspaceEntity> workspaceEntityList = workspaceService.list();
|
||||||
|
List<SysRoleEntity> roleEntityList = roleService.list();
|
||||||
|
List<String> workspaceIds = workspaceEntityList.stream().map(x -> x.getId()).toList();
|
||||||
|
List<String> roleIds = roleEntityList.stream().map(x -> x.getId()).toList();
|
||||||
|
|
||||||
|
for (WorkspaceMemberEntity workspaceRole : workspaceRoles) {
|
||||||
|
WorkspaceEntity workspace = workspaceRole.getWorkspace();
|
||||||
|
if (!workspaceIds.contains(workspace.getId())){
|
||||||
|
throw ASWException.builder().rcode(RCode.WORKSPACE_NOT_EXIST).build();
|
||||||
|
}
|
||||||
|
SysRoleEntity role = workspaceRole.getRole();
|
||||||
|
if (!roleIds.contains(role.getId())){
|
||||||
|
throw ASWException.builder().rcode(RCode.ROLE_NOT_EXIST).build();
|
||||||
|
}
|
||||||
|
workspaceRole.setUserId(userId);
|
||||||
|
workspaceRole.setWorkspaceId(workspace.getId());
|
||||||
|
workspaceRole.setRoleId(role.getId());
|
||||||
|
workspaceRole.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||||
|
workspaceRole.setCreateTimestamp(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getUserId, userId));
|
||||||
|
workspaceMemberService.saveBatch(workspaceRoles);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void delete(String ids) {
|
||||||
|
SysUserEntity user = this.getById(StpUtil.getLoginIdAsString());
|
||||||
|
if (!T.StrUtil.equalsIgnoreCase(user.getAccessLevel(), "administrator")){
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_NO_AUTH).build();
|
||||||
|
}
|
||||||
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
|
if (idList.contains("admin")){
|
||||||
|
throw ASWException.builder().rcode(RCode.SYS_NO_AUTH).build();
|
||||||
|
}
|
||||||
|
this.removeBatchByIds(idList);
|
||||||
|
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().in(WorkspaceMemberEntity::getUserId, idList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public class WorkspaceController {
|
|||||||
public R save(@RequestBody WorkspaceEntity workspace) {
|
public R save(@RequestBody WorkspaceEntity workspace) {
|
||||||
VerifyUtil.is(workspace).notNull()
|
VerifyUtil.is(workspace).notNull()
|
||||||
.and(workspace.getName()).notEmpty(RCode.WORKSPACE_NAME_CANNOT_EMPTY)
|
.and(workspace.getName()).notEmpty(RCode.WORKSPACE_NAME_CANNOT_EMPTY)
|
||||||
|
.and(workspace.getMembers()).notEmpty(RCode.WORKSPACE_MEMBER_CANNOT_EMPTY)
|
||||||
.and(workspace.getVisibility()).notEmpty(RCode.WORKSPACE_VISIBILITY_CANNOT_EMPTY);
|
.and(workspace.getVisibility()).notEmpty(RCode.WORKSPACE_VISIBILITY_CANNOT_EMPTY);
|
||||||
|
|
||||||
WorkspaceEntity workspaceEntity = workspaceService.saveWorkspace(workspace);
|
WorkspaceEntity workspaceEntity = workspaceService.saveWorkspace(workspace);
|
||||||
@@ -70,6 +71,7 @@ public class WorkspaceController {
|
|||||||
VerifyUtil.is(workspace).notNull()
|
VerifyUtil.is(workspace).notNull()
|
||||||
.and(workspace.getId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY)
|
.and(workspace.getId()).notEmpty(RCode.WORKSPACE_ID_CANNOT_EMPTY)
|
||||||
.and(workspace.getName()).notEmpty(RCode.WORKSPACE_NAME_CANNOT_EMPTY)
|
.and(workspace.getName()).notEmpty(RCode.WORKSPACE_NAME_CANNOT_EMPTY)
|
||||||
|
.and(workspace.getMembers()).notEmpty(RCode.WORKSPACE_MEMBER_CANNOT_EMPTY)
|
||||||
.and(workspace.getVisibility()).notEmpty(RCode.WORKSPACE_VISIBILITY_CANNOT_EMPTY);
|
.and(workspace.getVisibility()).notEmpty(RCode.WORKSPACE_VISIBILITY_CANNOT_EMPTY);
|
||||||
|
|
||||||
WorkspaceEntity workspaceEntity = workspaceService.updateWorkspace(workspace);
|
WorkspaceEntity workspaceEntity = workspaceService.updateWorkspace(workspace);
|
||||||
@@ -86,7 +88,9 @@ public class WorkspaceController {
|
|||||||
|
|
||||||
@GetMapping("/{workspaceId}/member")
|
@GetMapping("/{workspaceId}/member")
|
||||||
public R getMember(@PathVariable String workspaceId) {
|
public R getMember(@PathVariable String workspaceId) {
|
||||||
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(workspaceId);
|
|
||||||
|
Map params = T.MapUtil.builder("workspaceId", workspaceId).build();
|
||||||
|
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(params);
|
||||||
return R.ok().putData("record", memberEntityList);
|
return R.ok().putData("record", memberEntityList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ package net.geedge.asw.module.workspace.dao;
|
|||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface WorkspaceMemberDao extends BaseMapper<WorkspaceMemberEntity> {
|
public interface WorkspaceMemberDao extends BaseMapper<WorkspaceMemberEntity> {
|
||||||
|
|
||||||
List<WorkspaceMemberEntity> queryList(String workspaceId);
|
List<WorkspaceMemberEntity> queryList(@Param("params") Map params);
|
||||||
}
|
}
|
||||||
@@ -28,4 +28,7 @@ public class WorkspaceMemberEntity {
|
|||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private SysUserEntity createUser;
|
private SysUserEntity createUser;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private WorkspaceEntity workspace;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,11 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
import net.geedge.asw.module.workspace.entity.WorkspaceMemberEntity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface IWorkspaceMemberService extends IService<WorkspaceMemberEntity>{
|
public interface IWorkspaceMemberService extends IService<WorkspaceMemberEntity>{
|
||||||
|
|
||||||
List<WorkspaceMemberEntity> queryList(String workspaceId);
|
List<WorkspaceMemberEntity> queryList(Map params);
|
||||||
|
|
||||||
List<WorkspaceMemberEntity> saveMember(String workspaceId ,List<WorkspaceMemberEntity> workspaces);
|
List<WorkspaceMemberEntity> saveMember(String workspaceId ,List<WorkspaceMemberEntity> workspaces);
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class WorkspaceMemberServiceImpl extends ServiceImpl<WorkspaceMemberDao, WorkspaceMemberEntity> implements IWorkspaceMemberService {
|
public class WorkspaceMemberServiceImpl extends ServiceImpl<WorkspaceMemberDao, WorkspaceMemberEntity> implements IWorkspaceMemberService {
|
||||||
@@ -30,8 +31,8 @@ public class WorkspaceMemberServiceImpl extends ServiceImpl<WorkspaceMemberDao,
|
|||||||
private ISysRoleService roleService;
|
private ISysRoleService roleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WorkspaceMemberEntity> queryList(String workspaceId) {
|
public List<WorkspaceMemberEntity> queryList(Map params) {
|
||||||
List<WorkspaceMemberEntity> list = this.baseMapper.queryList(workspaceId);
|
List<WorkspaceMemberEntity> list = this.baseMapper.queryList(params);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,8 @@ public class WorkspaceMemberServiceImpl extends ServiceImpl<WorkspaceMemberDao,
|
|||||||
public List<WorkspaceMemberEntity> saveMember(String workspaceId, List<WorkspaceMemberEntity> workspaces) {
|
public List<WorkspaceMemberEntity> saveMember(String workspaceId, List<WorkspaceMemberEntity> workspaces) {
|
||||||
validateInfo(workspaceId, workspaces);
|
validateInfo(workspaceId, workspaces);
|
||||||
workspaceMemberService.saveBatch(workspaces);
|
workspaceMemberService.saveBatch(workspaces);
|
||||||
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(workspaceId);
|
Map params = T.MapUtil.builder("workspaceId", workspaceId).build();
|
||||||
|
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(params);
|
||||||
return memberEntityList;
|
return memberEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +50,8 @@ public class WorkspaceMemberServiceImpl extends ServiceImpl<WorkspaceMemberDao,
|
|||||||
validateInfo(workspaceId, workspaces);
|
validateInfo(workspaceId, workspaces);
|
||||||
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId));
|
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getWorkspaceId, workspaceId));
|
||||||
workspaceMemberService.saveBatch(workspaces);
|
workspaceMemberService.saveBatch(workspaces);
|
||||||
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(workspaceId);
|
Map params = T.MapUtil.builder("workspaceId", workspaceId).build();
|
||||||
|
List<WorkspaceMemberEntity> memberEntityList = workspaceMemberService.queryList(params);
|
||||||
return memberEntityList;
|
return memberEntityList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceDao, WorkspaceEnt
|
|||||||
workspace.setUpdateTimestamp(System.currentTimeMillis());
|
workspace.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
workspaceService.save(workspace);
|
workspaceService.save(workspace);
|
||||||
|
|
||||||
if (T.CollectionUtil.isNotEmpty(workspace.getMembers())) {
|
|
||||||
List<WorkspaceMemberEntity> members = workspace.getMembers();
|
List<WorkspaceMemberEntity> members = workspace.getMembers();
|
||||||
members.stream().forEach(x -> {
|
members.stream().forEach(x -> {
|
||||||
x.setWorkspaceId(workspace.getId());
|
x.setWorkspaceId(workspace.getId());
|
||||||
@@ -56,7 +55,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceDao, WorkspaceEnt
|
|||||||
x.setCreateUserId(StpUtil.getLoginIdAsString());
|
x.setCreateUserId(StpUtil.getLoginIdAsString());
|
||||||
});
|
});
|
||||||
workspaceMemberService.saveBatch(members);
|
workspaceMemberService.saveBatch(members);
|
||||||
}
|
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +67,6 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceDao, WorkspaceEnt
|
|||||||
workspace.setUpdateTimestamp(System.currentTimeMillis());
|
workspace.setUpdateTimestamp(System.currentTimeMillis());
|
||||||
workspaceService.updateById(workspace);
|
workspaceService.updateById(workspace);
|
||||||
|
|
||||||
if (T.CollectionUtil.isNotEmpty(workspace.getMembers())) {
|
|
||||||
List<WorkspaceMemberEntity> members = workspace.getMembers();
|
List<WorkspaceMemberEntity> members = workspace.getMembers();
|
||||||
members.stream().forEach(x -> {
|
members.stream().forEach(x -> {
|
||||||
x.setWorkspaceId(workspace.getId());
|
x.setWorkspaceId(workspace.getId());
|
||||||
@@ -77,7 +75,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceDao, WorkspaceEnt
|
|||||||
});
|
});
|
||||||
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getWorkspaceId, workspace.getId()));
|
workspaceMemberService.remove(new LambdaQueryWrapper<WorkspaceMemberEntity>().eq(WorkspaceMemberEntity::getWorkspaceId, workspace.getId()));
|
||||||
workspaceMemberService.saveBatch(members);
|
workspaceMemberService.saveBatch(members);
|
||||||
}
|
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,12 +92,9 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceDao, WorkspaceEnt
|
|||||||
|
|
||||||
private void validateWorkspaceInfo(WorkspaceEntity workspace, boolean isUpdate) {
|
private void validateWorkspaceInfo(WorkspaceEntity workspace, boolean isUpdate) {
|
||||||
|
|
||||||
if (!Constants.VISIBILITY_LIST.contains(workspace.getVisibility())) {
|
if (!T.StrUtil.equalsIgnoreCase(workspace.getVisibility(), "private")) {
|
||||||
throw new ASWException(RCode.WORKSPACE_VISIBILITY_ERROR);
|
throw new ASWException(RCode.WORKSPACE_VISIBILITY_ERROR);
|
||||||
}
|
}
|
||||||
if (T.StrUtil.equals(workspace.getVisibility(), "private") && T.CollectionUtil.isEmpty(workspace.getMembers())) {
|
|
||||||
throw new ASWException(RCode.WORKSPACE_USER_CANNOT_EMPTY);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<WorkspaceEntity> list = workspaceService.list(new LambdaQueryWrapper<WorkspaceEntity>().eq(WorkspaceEntity::getName, workspace.getName()));
|
List<WorkspaceEntity> list = workspaceService.list(new LambdaQueryWrapper<WorkspaceEntity>().eq(WorkspaceEntity::getName, workspace.getName()));
|
||||||
if (!isUpdate && T.CollectionUtil.isNotEmpty(list)) {
|
if (!isUpdate && T.CollectionUtil.isNotEmpty(list)) {
|
||||||
|
|||||||
55
src/main/resources/db/mapper/sys/SysUserMapper.xml
Normal file
55
src/main/resources/db/mapper/sys/SysUserMapper.xml
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?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="net.geedge.asw.module.sys.dao.SysUserDao">
|
||||||
|
<resultMap id="userList" type="net.geedge.asw.module.sys.entity.SysUserEntity">
|
||||||
|
<result property="id" column="id"/>
|
||||||
|
<result property="name" column="name"/>
|
||||||
|
<result property="userName" column="user_name"/>
|
||||||
|
<result property="accessLevel" column="access_level"/>
|
||||||
|
<result property="language" column="language"/>
|
||||||
|
<result property="lastLoginIp" column="last_login_ip"/>
|
||||||
|
<result property="lastLoginTimestamp" column="last_login_timestamp"/>
|
||||||
|
<result property="createUserId" column="create_user_id"/>
|
||||||
|
<result property="updateUserId" column="update_user_id"/>
|
||||||
|
<result property="createTimestamp" column="create_timestamp"/>
|
||||||
|
<result property="updateTimestamp" column="update_timestamp"/>
|
||||||
|
|
||||||
|
<association property="createUser" columnPrefix="cu_" javaType="net.geedge.asw.module.sys.entity.SysUserEntity">
|
||||||
|
<id property="id" column="id"/>
|
||||||
|
<result property="name" column="name"/>
|
||||||
|
</association>
|
||||||
|
|
||||||
|
<association property="updateUser" columnPrefix="uu_" javaType="net.geedge.asw.module.sys.entity.SysUserEntity">
|
||||||
|
<id property="id" column="id"/>
|
||||||
|
<result property="name" column="name"/>
|
||||||
|
</association>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<select id="queryList" resultMap="userList">
|
||||||
|
SELECT
|
||||||
|
su.*,
|
||||||
|
cu.id as cu_id,
|
||||||
|
cu.name as cu_name,
|
||||||
|
uu.id as uu_id,
|
||||||
|
uu.id as uu_name
|
||||||
|
FROM
|
||||||
|
sys_user su
|
||||||
|
left join sys_user cu on su.create_user_id = cu.id
|
||||||
|
left join sys_user uu on su.update_user_id = uu.id
|
||||||
|
<where>
|
||||||
|
<if test="params.ids != null and params.ids != ''">
|
||||||
|
su.id in
|
||||||
|
<foreach item="id" collection="params.ids.split(',')" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="params.q != null and params.q != ''">
|
||||||
|
AND ( locate(#{params.q}, su.name) OR locate(#{params.q}, su.user_name) )
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
<if test="params.orderBy == null or params.orderBy == ''">
|
||||||
|
ORDER BY su.id
|
||||||
|
</if>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -25,6 +25,11 @@
|
|||||||
<result property="name" column="name"/>
|
<result property="name" column="name"/>
|
||||||
</association>
|
</association>
|
||||||
|
|
||||||
|
<association property="workspace" columnPrefix="w_" javaType="net.geedge.asw.module.workspace.entity.WorkspaceEntity">
|
||||||
|
<id property="id" column="id"/>
|
||||||
|
<result property="name" column="name"/>
|
||||||
|
</association>
|
||||||
|
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="queryList" resultMap="workspaceMemberResultMap">
|
<select id="queryList" resultMap="workspaceMemberResultMap">
|
||||||
SELECT
|
SELECT
|
||||||
@@ -34,15 +39,22 @@
|
|||||||
su.id AS su_id,
|
su.id AS su_id,
|
||||||
su.name AS su_name,
|
su.name AS su_name,
|
||||||
sr.id AS sr_id,
|
sr.id AS sr_id,
|
||||||
sr.name AS sr_name
|
sr.name AS sr_name,
|
||||||
|
ws.id AS w_id,
|
||||||
|
ws.name AS w_name
|
||||||
FROM
|
FROM
|
||||||
workspace_member wm
|
workspace_member wm
|
||||||
LEFT JOIN sys_user cu ON wm.create_user_id = cu.id
|
LEFT JOIN sys_user cu ON wm.create_user_id = cu.id
|
||||||
LEFT JOIN sys_user su ON wm.user_id = su.id
|
LEFT JOIN sys_user su ON wm.user_id = su.id
|
||||||
LEFT JOIN sys_role sr ON wm.role_id = sr.id
|
LEFT JOIN sys_role sr ON wm.role_id = sr.id
|
||||||
|
LEFT JOIN workspace ws ON wm.workspace_id = ws.id
|
||||||
<where>
|
<where>
|
||||||
<if test="workspaceId != null and workspaceId != ''">
|
<if test="params.workspaceId != null and params.workspaceId != ''">
|
||||||
wm.workspace_id = #{workspaceId}
|
wm.workspace_id = #{params.workspaceId}
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="params.userId != null and params.userId != ''">
|
||||||
|
wm.user_id = #{params.userId}
|
||||||
</if>
|
</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -93,5 +93,16 @@ INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_
|
|||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (143, '501001', 'PCAP_UPLOAD_WEB_SHARK_ERROR', 'pcap 上传失败', 'zh', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (143, '501001', 'PCAP_UPLOAD_WEB_SHARK_ERROR', 'pcap 上传失败', 'zh', '', 'admin', 1724030366000);
|
||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (145, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', 'application package name format error', 'en', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (145, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', 'application package name format error', 'en', '', 'admin', 1724030366000);
|
||||||
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (147, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', '应用安装包名称格式错误', 'zh', '', 'admin', 1724030366000);
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (147, '201009', 'APP_PACKAGE_NAME_FORMAT_ERROR', '应用安装包名称格式错误', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (149, '100013', 'SYS_USER_NAME_CANNOT_EMPTY', 'username cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (151, '100013', 'SYS_USER_NAME_CANNOT_EMPTY', '用户名称不能为空', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (153, '100014', 'SYS_ACCESS_LEVEL_CANNOT_EMPTY', 'accessLevel cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (155, '100014', 'SYS_ACCESS_LEVEL_CANNOT_EMPTY', '访问级别不能为空', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (157, '100015', 'SYS_WORKSPACE_ROLES_CANNOT_EMPTY', 'workspaceRoles cannot be empty', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (159, '100015', 'SYS_WORKSPACE_ROLES_CANNOT_EMPTY', '工作空间用户与权限不能为空', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (161, '100016', 'SYS_USER_BUILT_IN', 'Built-in user are not allowed to delete or update', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (163, '100016', 'SYS_USER_BUILT_IN', '内置用户不允许删除或更新', 'zh', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (165, '401010', 'WORKSPACE_NOT_EXIST', 'Workspace does not exist', 'en', '', 'admin', 1724030366000);
|
||||||
|
INSERT INTO `sys_i18n`(`id`, `name`, `code`, `value`, `lang`, `remark`, `update_user_id`, `update_timestamp`) VALUES (167, '401010', 'WORKSPACE_NOT_EXIST', '工作空间不存在', 'zh', '', 'admin', 1724030366000);
|
||||||
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
|
|||||||
@@ -9,13 +9,19 @@ CREATE TABLE `sys_user` (
|
|||||||
`user_name` varchar(255) NOT NULL,
|
`user_name` varchar(255) NOT NULL,
|
||||||
`pwd` varchar(255) NOT NULL,
|
`pwd` varchar(255) NOT NULL,
|
||||||
`access_level` varchar(255) NOT NULL,
|
`access_level` varchar(255) NOT NULL,
|
||||||
`create_timestamp` bigint(20) NOT NULL,
|
`language` VARCHAR(256) NOT NULL DEFAULT 'en' COMMENT '语言',
|
||||||
|
`last_login_ip` VARCHAR(256) NOT NULL DEFAULT '' COMMENT '最后登录IP',
|
||||||
|
`last_login_timestamp` BIGINT(20) NOT NULL COMMENT '最后登录时间',
|
||||||
|
`create_timestamp` BIGINT(20) NOT NULL COMMENT '创建时间戳',
|
||||||
|
`update_timestamp` BIGINT(20) NOT NULL COMMENT '更新时间戳',
|
||||||
|
`create_user_id` VARCHAR(64) NOT NULL COMMENT '创建人id',
|
||||||
|
`update_user_id` VARCHAR(64) NOT NULL COMMENT '更新人id',
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `idx_user_name` (`user_name`) USING BTREE,
|
UNIQUE KEY `idx_user_name` (`user_name`) USING BTREE,
|
||||||
KEY `idx_name` (`name`) USING BTREE
|
KEY `idx_name` (`name`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
-- 添加内置用户
|
-- 添加内置用户
|
||||||
INSERT INTO `sys_user`(`id`, `name`, `user_name`, `pwd`, `access_level`, `create_timestamp`) VALUES ('admin', 'admin', 'admin', 'ad9d757e620d5d9cd8e32c3dbcf37525', 'administrator', UNIX_TIMESTAMP(NOW())*1000);
|
INSERT INTO `sys_user`(`id`, `name`, `user_name`, `pwd`, `access_level`, `language`, `last_login_ip`, `last_login_timestamp`, `create_timestamp`, `update_timestamp`, `create_user_id`, `update_user_id`) VALUES ('admin', 'admin', 'admin', 'ad9d757e620d5d9cd8e32c3dbcf37525', 'administrator', 'en', '', UNIX_TIMESTAMP(NOW())*1000, UNIX_TIMESTAMP(NOW())*1000, UNIX_TIMESTAMP(NOW())*1000, 'admin', 'admin');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1、新增 sys_role 表
|
* 1、新增 sys_role 表
|
||||||
@@ -394,7 +400,7 @@ CREATE TABLE `workspace` (
|
|||||||
KEY `idx_name` (`name`) USING BTREE
|
KEY `idx_name` (`name`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
INSERT INTO `workspace` (`id`, `name`, `tags`, `visibility`, `description`, `create_timestamp`, `update_timestamp`, `create_user_id`, `update_user_id`) VALUES ('1', 'default', '', 'public', '', 1722482392000, 1722482392000, 'admin', 'admin');
|
INSERT INTO `workspace` (`id`, `name`, `tags`, `visibility`, `description`, `create_timestamp`, `update_timestamp`, `create_user_id`, `update_user_id`) VALUES ('1', 'default', '', 'private', '', 1722482392000, 1722482392000, 'admin', 'admin');
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `workspace_member`;
|
DROP TABLE IF EXISTS `workspace_member`;
|
||||||
CREATE TABLE `workspace_member` (
|
CREATE TABLE `workspace_member` (
|
||||||
@@ -407,3 +413,5 @@ CREATE TABLE `workspace_member` (
|
|||||||
KEY `idx_user_id` (`user_id`) USING BTREE,
|
KEY `idx_user_id` (`user_id`) USING BTREE,
|
||||||
KEY `idx_role_id` (`role_id`) USING BTREE
|
KEY `idx_role_id` (`role_id`) USING BTREE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
INSERT INTO `workspace_member` (`workspace_id`, `user_id`, `role_id`, `create_timestamp`, `create_user_id`) VALUES ('1', 'admin', 'admin', 1724291229000, 'admin');
|
||||||
|
|||||||
Reference in New Issue
Block a user