登录、权限管理完善

This commit is contained in:
lhx
2025-11-14 11:44:11 +08:00
parent 14d07eab3e
commit 10f1237a3b
31 changed files with 799 additions and 1408 deletions

1
.gitignore vendored
View File

@@ -31,7 +31,6 @@ build/
### VS Code ###
.vscode/
*/*.log
/logs/
*.cmd

File diff suppressed because it is too large Load Diff

View File

@@ -57,6 +57,10 @@ public class ResponseResult {
return new ResponseResult(code, message, null);
}
public static ResponseResult error(ResultCode resultCode) {
return new ResponseResult(resultCode.getCode(), resultCode.getDesc(), null);
}
public static ResponseResult success() {
return new ResponseResult(SUCCESS.getCode(), SUCCESS.getDesc(), null);
}

View File

@@ -11,17 +11,17 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//@Configuration
//@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
//public class SaTokenConfigure implements WebMvcConfigurer {
//
// @Override
// public void addInterceptors(InterceptorRegistry registry) {
// registry.addInterceptor(new SaInterceptor(h -> {
//
// SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
// SaRouter.match("/project/**").check(StpUtil::checkLogin);
// })).addPathPatterns("/**");
// }
//
//}
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
public class SaTokenConfigure implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SaInterceptor(h -> {
SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
SaRouter.match("/project/**").check(StpUtil::checkLogin);
})).addPathPatterns("/**");
}
}

View File

@@ -1,46 +1,46 @@
//package com.dc.dc_project.config;
//
//import cn.dev33.satoken.stp.StpInterface;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.dc.dc_project.model.pojo.Role;
//import com.dc.dc_project.model.pojo.UserRole;
//import com.dc.dc_project.service.RoleService;
//import com.dc.dc_project.service.UserRoleService;
//import lombok.RequiredArgsConstructor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import java.util.List;
//
///**
// * 权限加载接口实现类
// */
//@Component
//@RequiredArgsConstructor(onConstructor_ = {@Autowired})
//public class StpInterfaceImpl implements StpInterface {
//
// @Autowired
// private UserRoleService userRoleService;
//
// @Autowired
// private RoleService roleService;
// /**
// * 返回一个账号所拥有的权限码集合
// */
// @Override
// public List<String> getPermissionList(Object loginId, String loginType) {
// LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, Long.valueOf(loginId.toString()));
// List<Long> roleIds = userRoleService.list(lambdaQueryWrapper).stream().map(UserRole::getRoleId).toList();
// return roleService.list(new LambdaQueryWrapper<Role>().in(Role::getId, roleIds)).stream().map(Role::getCode).toList();
// }
//
// /**
// * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
// */
// @Override
// public List<String> getRoleList(Object loginId, String loginType) {
// LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, Long.valueOf(loginId.toString()));
// List<Long> roleIds = userRoleService.list(lambdaQueryWrapper).stream().map(UserRole::getRoleId).toList();
// return roleService.list(new LambdaQueryWrapper<Role>().in(Role::getId, roleIds)).stream().map(Role::getCode).toList();
// }
//
//}
package com.dc.dc_project.config;
import cn.dev33.satoken.stp.StpInterface;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dc.dc_project.model.pojo.Role;
import com.dc.dc_project.model.pojo.UserRole;
import com.dc.dc_project.service.RoleService;
import com.dc.dc_project.service.UserRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* 权限加载接口实现类
*/
@Component
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class StpInterfaceImpl implements StpInterface {
@Autowired
private UserRoleService userRoleService;
@Autowired
private RoleService roleService;
/**
* 返回一个账号所拥有的权限码集合
*/
@Override
public List<String> getPermissionList(Object loginId, String loginType) {
LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, Long.valueOf(loginId.toString()));
List<Long> roleIds = userRoleService.list(lambdaQueryWrapper).stream().map(UserRole::getRoleId).toList();
return roleService.list(new LambdaQueryWrapper<Role>().in(Role::getId, roleIds)).stream().map(Role::getCode).toList();
}
/**
* 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
*/
@Override
public List<String> getRoleList(Object loginId, String loginType) {
LambdaQueryWrapper<UserRole> lambdaQueryWrapper = new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, Long.valueOf(loginId.toString()));
List<Long> roleIds = userRoleService.list(lambdaQueryWrapper).stream().map(UserRole::getRoleId).toList();
return roleService.list(new LambdaQueryWrapper<Role>().in(Role::getId, roleIds)).stream().map(Role::getCode).toList();
}
}

View File

@@ -0,0 +1,64 @@
package com.dc.dc_project.config.exception;
import com.dc.dc_project.common.ResultCode;
import com.dc.dc_project.common.ResultCode.*;
import lombok.Data;
import static com.dc.dc_project.common.ResultCode.ERROR_DEFAULT;
import static com.dc.dc_project.common.ResultCode.ERROR;
/**
* @author blue
* @description: 异常返回类
* @date 2021/7/19 10:40
*/
@Data
public class BusinessException extends RuntimeException{
private static final long serialVersionUID = 6401507641198338287L;
/** 异常代码 */
protected Integer code;
/** 异常消息 */
protected String message;
public BusinessException() {
super();
}
public BusinessException(ResultCode resultCode) {
super(resultCode.getDesc());
this.code = resultCode.getCode();
this.message = resultCode.getDesc();
}
public BusinessException(String msg) {
super(msg);
this.code = ERROR_DEFAULT.getCode();
this.message = msg;
}
public BusinessException(Integer code, String msg) {
super(msg);
this.code = code;
this.message = msg;
}
public BusinessException(Integer code, String msg, Throwable cause) {
super(msg, cause);
this.code = code;
this.message = msg;
}
public BusinessException(Throwable cause) {
super(cause);
this.code = ERROR.getCode();
this.message = cause.getMessage();
}
@Override
public String toString() {
return "errorCode: " + code + ", message: " + message;
}
}

View File

@@ -0,0 +1,75 @@
package com.dc.dc_project.config.exception;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import com.dc.dc_project.common.ResponseResult;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import static com.dc.dc_project.common.ResultCode.*;
/**
* @author blue
* @date 2022/3/11
* @apiNote
*/
@ControllerAdvice(basePackages = "com.liy")
public class GlobalException {
private static final Logger logger = LoggerFactory.getLogger(GlobalException.class);
// 业务异常
@ExceptionHandler(BusinessException.class)
@ResponseBody
public ResponseResult BusinessExceptionHandler(BusinessException ex) {
if (ex.getCode() != -1) {
logger.error("code : " + ex.getCode() + " msg : " + ex.getMessage(), ex);
}
if(StringUtils.isBlank(ex.getLocalizedMessage())||StringUtils.isBlank(ex.getMessage())){
return ResponseResult.error(ERROR.getCode(), ERROR.getDesc());
}
return ResponseResult.error(ex.getCode(), ex.getMessage());
}
// Assert业务异常
@ExceptionHandler(IllegalArgumentException.class)
@ResponseBody
public ResponseResult AssertExceptionHandler(IllegalArgumentException ex) {
logger.error( " msg : " + ex.getMessage(), ex);
if(StringUtils.isBlank(ex.getLocalizedMessage())){
return ResponseResult.error(ERROR.getCode(),ERROR.getDesc());
}
return ResponseResult.error(ex.getMessage());
}
// 登录异常
@ExceptionHandler(NotLoginException.class)
@ResponseBody
public ResponseResult NotLoginExceptionHandler(NotLoginException ex) {
logger.error( " msg : " + ex.getMessage(), ex);
return ResponseResult.error(NOT_LOGIN.getCode(),NOT_LOGIN.getDesc());
}
// 权限异常
@ExceptionHandler(NotPermissionException.class)
@ResponseBody
public ResponseResult NotPermissionExceptionHandler(NotPermissionException ex) {
logger.error( " msg : " + ex.getMessage(), ex);
return ResponseResult.error(NO_PERMISSION.getCode(),"无此权限:" + ex.getCode());
}
// java异常异常
@ExceptionHandler(Exception.class)
@ResponseBody
public ResponseResult ExceptionHandler(Exception ex) {
logger.error( " msg : " + ex.getMessage(), ex);
if(StringUtils.isBlank(ex.getLocalizedMessage())){
return ResponseResult.error(ERROR.getCode(),ERROR.getDesc());
}
return ResponseResult.error(ERROR_DEFAULT.getDesc());
}
}

View File

@@ -0,0 +1,35 @@
package com.dc.dc_project.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.user.LoginDto;
import com.dc.dc_project.model.pojo.User;
import com.dc.dc_project.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class AuthController {
private final UserService userService;
@PostMapping("/login")
ResponseResult login(@RequestBody @Valid LoginDto loginDto) {
return userService.login(loginDto);
}
@GetMapping("/logout")
ResponseResult logout() {
Long userId = StpUtil.getLoginIdAsLong();
StpUtil.logout();
return ResponseResult.success(true);
}
}

View File

@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface OrgMapper extends BaseMapper<Org> {
Long getOrgIdByPersonnelId(Long id);
}

View File

@@ -2,6 +2,7 @@ package com.dc.dc_project.mapper;
import com.dc.dc_project.model.pojo.Personnel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dc.dc_project.model.vo.PersonnelVo;
/**
* @author ADMIN
@@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface PersonnelMapper extends BaseMapper<Personnel> {
PersonnelVo getVoByUserId(Long id);
}

View File

@@ -1,7 +1,7 @@
package com.dc.dc_project.mapper;
import com.dc.dc_project.model.pojo.RoleOrg;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dc.dc_project.model.pojo.PersonnelOrg;
/**
* @author ADMIN
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @createDate 2025-11-12 09:41:21
* @Entity generator.pojo.RoleOrg
*/
public interface RoleOrgMapper extends BaseMapper<RoleOrg> {
public interface PersonnelOrgMapper extends BaseMapper<PersonnelOrg> {
}

View File

@@ -3,6 +3,8 @@ package com.dc.dc_project.mapper;
import com.dc.dc_project.model.pojo.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
/**
* @author ADMIN
* @description 针对表【sys_role(系统角色表)】的数据库操作Mapper
@@ -11,6 +13,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
*/
public interface RoleMapper extends BaseMapper<Role> {
List<Role> getRolesByUserId(Long userId);
}

View File

@@ -1,5 +1,6 @@
package com.dc.dc_project.mapper;
import com.dc.dc_project.model.dto.user.LoginDto;
import com.dc.dc_project.model.pojo.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

View File

@@ -0,0 +1,15 @@
package com.dc.dc_project.model.dto.user;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.NonNull;
import java.io.Serializable;
@Data
public class LoginDto implements Serializable{
@NotBlank(message = "手机号不能为空")
private Long phone;
@NotBlank(message = "密码不能为空")
private String password;
}

View File

@@ -21,12 +21,6 @@ public class Personnel {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 所属组织(公司/项目/试验室ID
*/
@TableField(value = "org_id")
private Long orgId;
/**
* 关联系统用户ID可为空
*/
@@ -99,76 +93,5 @@ public class Personnel {
@TableField(value = "is_deleted")
private Integer isDeleted;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Personnel other = (Personnel) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getPosition() == null ? other.getPosition() == null : this.getPosition().equals(other.getPosition()))
&& (this.getContactPhone() == null ? other.getContactPhone() == null : this.getContactPhone().equals(other.getContactPhone()))
&& (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
&& (this.getMainResponsibility() == null ? other.getMainResponsibility() == null : this.getMainResponsibility().equals(other.getMainResponsibility()))
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getCreatedBy() == null ? other.getCreatedBy() == null : this.getCreatedBy().equals(other.getCreatedBy()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getOrgId() == null) ? 0 : getOrgId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getPosition() == null) ? 0 : getPosition().hashCode());
result = prime * result + ((getContactPhone() == null) ? 0 : getContactPhone().hashCode());
result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
result = prime * result + ((getMainResponsibility() == null) ? 0 : getMainResponsibility().hashCode());
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getCreatedBy() == null) ? 0 : getCreatedBy().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", orgId=").append(orgId);
sb.append(", userId=").append(userId);
sb.append(", name=").append(name);
sb.append(", position=").append(position);
sb.append(", contactPhone=").append(contactPhone);
sb.append(", email=").append(email);
sb.append(", mainResponsibility=").append(mainResponsibility);
sb.append(", remark=").append(remark);
sb.append(", status=").append(status);
sb.append(", createdBy=").append(createdBy);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", isDeleted=").append(isDeleted);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,48 @@
package com.dc.dc_project.model.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 角色-组织关系表
*/
@TableName(value ="sys_personnel_org")
@Data
public class PersonnelOrg {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 角色ID
*/
@TableField(value = "personnel_id")
private Long personnelId;
/**
* 组织ID作用范围
*/
@TableField(value = "org_id")
private Long orgId;
/**
* 创建时间
*/
@TableField(value = "created_at")
private LocalDateTime createdAt;
/**
* 创建人
*/
@TableField(value = "created_by")
private String createdBy;
}

View File

@@ -69,61 +69,4 @@ public class Role {
@TableField(value = "is_deleted")
private Integer isDeleted;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Role other = (Role) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getCode() == null ? other.getCode() == null : this.getCode().equals(other.getCode()))
&& (this.getLevel() == null ? other.getLevel() == null : this.getLevel().equals(other.getLevel()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
result = prime * result + ((getLevel() == null) ? 0 : getLevel().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", name=").append(name);
sb.append(", code=").append(code);
sb.append(", level=").append(level);
sb.append(", status=").append(status);
sb.append(", description=").append(description);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", isDeleted=").append(isDeleted);
sb.append("]");
return sb.toString();
}
}

View File

@@ -1,93 +0,0 @@
package com.dc.dc_project.model.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 角色-组织关系表
* @TableName sys_role_org
*/
@TableName(value ="sys_role_org")
@Data
public class RoleOrg {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 角色ID
*/
@TableField(value = "role_id")
private Long roleId;
/**
* 组织ID作用范围
*/
@TableField(value = "org_id")
private Long orgId;
/**
* 创建时间
*/
@TableField(value = "created_at")
private LocalDateTime createdAt;
/**
* 创建人
*/
@TableField(value = "created_by")
private String createdBy;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
RoleOrg other = (RoleOrg) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getRoleId() == null ? other.getRoleId() == null : this.getRoleId().equals(other.getRoleId()))
&& (this.getOrgId() == null ? other.getOrgId() == null : this.getOrgId().equals(other.getOrgId()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getCreatedBy() == null ? other.getCreatedBy() == null : this.getCreatedBy().equals(other.getCreatedBy()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getRoleId() == null) ? 0 : getRoleId().hashCode());
result = prime * result + ((getOrgId() == null) ? 0 : getOrgId().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getCreatedBy() == null) ? 0 : getCreatedBy().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", roleId=").append(roleId);
sb.append(", orgId=").append(orgId);
sb.append(", createdAt=").append(createdAt);
sb.append(", createdBy=").append(createdBy);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,174 @@
package com.dc.dc_project.model.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 系统权限表(菜单/接口控制)
* @TableName sys_permission
*/
@TableName(value ="sys_permission")
@Data
public class PermissionVo {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 上级权限ID形成权限树
*/
@TableField(value = "parent_id")
private Long parentId;
/**
* 权限名称
*/
@TableField(value = "name")
private String name;
/**
* 权限编码(如 system:user:view
*/
@TableField(value = "code")
private String code;
/**
* 权限类型1=目录2=菜单3=按钮/接口)
*/
@TableField(value = "type")
private Integer type;
/**
* 前端路径或接口地址
*/
@TableField(value = "path")
private String path;
/**
* HTTP方法GET/POST/PUT/DELETE
*/
@TableField(value = "method")
private String method;
/**
* 图标(菜单类)
*/
@TableField(value = "icon")
private String icon;
/**
* 排序号
*/
@TableField(value = "sort_order")
private Integer sortOrder;
/**
* 状态0=停用1=启用)
*/
@TableField(value = "status")
private Integer status;
/**
* 备注
*/
@TableField(value = "remark")
private String remark;
/**
* 创建时间
*/
@TableField(value = "created_at")
private LocalDateTime createdAt;
/**
* 更新时间
*/
@TableField(value = "updated_at")
private LocalDateTime updatedAt;
/**
* 逻辑删除标志
*/
@TableField(value = "is_deleted")
private Integer isDeleted;
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
PermissionVo other = (PermissionVo) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getParentId() == null ? other.getParentId() == null : this.getParentId().equals(other.getParentId()))
&& (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
&& (this.getCode() == null ? other.getCode() == null : this.getCode().equals(other.getCode()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()))
&& (this.getPath() == null ? other.getPath() == null : this.getPath().equals(other.getPath()))
&& (this.getMethod() == null ? other.getMethod() == null : this.getMethod().equals(other.getMethod()))
&& (this.getIcon() == null ? other.getIcon() == null : this.getIcon().equals(other.getIcon()))
&& (this.getSortOrder() == null ? other.getSortOrder() == null : this.getSortOrder().equals(other.getSortOrder()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark()))
&& (this.getCreatedAt() == null ? other.getCreatedAt() == null : this.getCreatedAt().equals(other.getCreatedAt()))
&& (this.getUpdatedAt() == null ? other.getUpdatedAt() == null : this.getUpdatedAt().equals(other.getUpdatedAt()))
&& (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getParentId() == null) ? 0 : getParentId().hashCode());
result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
result = prime * result + ((getPath() == null) ? 0 : getPath().hashCode());
result = prime * result + ((getMethod() == null) ? 0 : getMethod().hashCode());
result = prime * result + ((getIcon() == null) ? 0 : getIcon().hashCode());
result = prime * result + ((getSortOrder() == null) ? 0 : getSortOrder().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode());
result = prime * result + ((getCreatedAt() == null) ? 0 : getCreatedAt().hashCode());
result = prime * result + ((getUpdatedAt() == null) ? 0 : getUpdatedAt().hashCode());
result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", parentId=").append(parentId);
sb.append(", name=").append(name);
sb.append(", code=").append(code);
sb.append(", type=").append(type);
sb.append(", path=").append(path);
sb.append(", method=").append(method);
sb.append(", icon=").append(icon);
sb.append(", sortOrder=").append(sortOrder);
sb.append(", status=").append(status);
sb.append(", remark=").append(remark);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);
sb.append(", isDeleted=").append(isDeleted);
sb.append("]");
return sb.toString();
}
}

View File

@@ -0,0 +1,113 @@
package com.dc.dc_project.model.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dc.dc_project.model.pojo.Org;
import com.dc.dc_project.model.pojo.Personnel;
import com.dc.dc_project.model.pojo.Role;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import java.time.LocalDateTime;
import java.util.List;
/**
* 人员台账表
* @TableName sys_personnel
*/
@TableName(value ="sys_personnel")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PersonnelVo {
/**
* 主键ID
*/
private Long id;
/**
* 关联系统用户ID可为空
*/
private Long userId;
/**
* 姓名
*/
private String name;
/**
* 职务/岗位(如 检测员、试验室主任)
*/
private String position;
/**
* 联系电话
*/
private String contactPhone;
/**
* 邮箱
*/
private String email;
/**
* 主要负责(自由文本,如 混凝土试验、材料检测)
*/
private String mainResponsibility;
/**
* 备注
*/
private String remark;
/**
* 状态1=在岗,0=离岗)
*/
private Integer status;
/**
* 创建时间
*/
private LocalDateTime createdAt;
/**
* 更新时间
*/
private LocalDateTime updatedAt;
/**
* 逻辑删除
*/
private Integer isDeleted;
private List<Role> roles;
private Long orgId;
private String token;
public static PersonnelVo toVo(Personnel personnel){
PersonnelVo personnelVo = new PersonnelVo();
personnelVo.setId(personnel.getId());
personnelVo.setUserId(personnel.getUserId());
personnelVo.setName(personnel.getName());
personnelVo.setPosition(personnel.getPosition());
personnelVo.setContactPhone(personnel.getContactPhone());
personnelVo.setEmail(personnel.getEmail());
personnelVo.setMainResponsibility(personnel.getMainResponsibility());
personnelVo.setRemark(personnel.getRemark());
personnelVo.setStatus(personnel.getStatus());
personnelVo.setCreatedAt(personnel.getCreatedAt());
personnelVo.setUpdatedAt(personnel.getUpdatedAt());
personnelVo.setIsDeleted(personnel.getIsDeleted());
return personnelVo;
}
}

View File

@@ -0,0 +1,84 @@
package com.dc.dc_project.model.vo;
import com.dc.dc_project.model.pojo.User;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class UserVo {
/**
* 主键ID
*/
private Long id;
/**
* 登录用户名
*/
private String username;
/**
* 真实姓名
*/
private String realName;
/**
* 性别0=未知1=男2=女)
*/
private Integer gender;
/**
* 联系电话
*/
private String phone;
/**
* 邮箱地址
*/
private String email;
/**
* 所属组织ID
*/
private Long orgId;
/**
* 所属组织名称
*/
private String orgName;
/**
* 账户状态0=停用1=启用)
*/
private Integer status;
/**
* 最后登录时间
*/
private LocalDateTime lastLoginTime;
/**
* 备注
*/
private String remark;
/**
* 角色列表
*/
public static UserVo fromUser(User user) {
UserVo userVo = new UserVo();
userVo.setId(user.getId());
userVo.setUsername(user.getUsername());
userVo.setRealName(user.getRealName());
userVo.setGender(user.getGender());
userVo.setPhone(user.getPhone());
userVo.setEmail(user.getEmail());
userVo.setOrgId(user.getOrgId());
userVo.setStatus(user.getStatus());
userVo.setLastLoginTime(user.getLastLoginTime());
userVo.setRemark(user.getRemark());
return userVo;
}
}

View File

@@ -1,6 +1,7 @@
package com.dc.dc_project.service;
import com.dc.dc_project.model.pojo.RoleOrg;
import com.dc.dc_project.model.pojo.PersonnelOrg;
import com.baomidou.mybatisplus.extension.service.IService;
/**
@@ -8,6 +9,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @description 针对表sys_role_org(角色-组织关系表)的数据库操作Service
* @createDate 2025-11-12 09:41:21
*/
public interface RoleOrgService extends IService<RoleOrg> {
public interface PersonnelOrgService extends IService<PersonnelOrg> {
}

View File

@@ -1,5 +1,7 @@
package com.dc.dc_project.service;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.model.dto.user.LoginDto;
import com.dc.dc_project.model.pojo.User;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.stereotype.Service;
@@ -13,4 +15,10 @@ import org.springframework.stereotype.Service;
@Service
public interface UserService extends IService<User> {
/**
* 登录
* @param loginDto
* @return
*/
ResponseResult login(LoginDto loginDto);
}

View File

@@ -1,9 +1,9 @@
package com.dc.dc_project.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.dc_project.model.pojo.RoleOrg;
import com.dc.dc_project.service.RoleOrgService;
import com.dc.dc_project.mapper.RoleOrgMapper;
import com.dc.dc_project.model.pojo.PersonnelOrg;
import com.dc.dc_project.service.PersonnelOrgService;
import com.dc.dc_project.mapper.PersonnelOrgMapper;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
@@ -14,8 +14,8 @@ import lombok.extern.slf4j.Slf4j;
*/
@Service
@Slf4j
public class RoleOrgServiceImpl extends ServiceImpl<RoleOrgMapper, RoleOrg>
implements RoleOrgService{
public class RoleOrgServiceImpl extends ServiceImpl<PersonnelOrgMapper, PersonnelOrg>
implements PersonnelOrgService {
}

View File

@@ -1,12 +1,27 @@
package com.dc.dc_project.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.dc_project.common.ResponseResult;
import com.dc.dc_project.common.ResultCode;
import com.dc.dc_project.mapper.OrgMapper;
import com.dc.dc_project.mapper.PersonnelMapper;
import com.dc.dc_project.mapper.RoleMapper;
import com.dc.dc_project.model.dto.user.LoginDto;
import com.dc.dc_project.model.pojo.Personnel;
import com.dc.dc_project.model.pojo.User;
import com.dc.dc_project.model.vo.PersonnelVo;
import com.dc.dc_project.service.PersonnelService;
import com.dc.dc_project.service.UserService;
import com.dc.dc_project.mapper.UserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import static com.dc.dc_project.model.vo.PersonnelVo.toVo;
/**
* @author ADMIN
* @description 针对表【sys_user(系统用户表)】的数据库操作Service实现
@@ -14,9 +29,49 @@ import lombok.extern.slf4j.Slf4j;
*/
@Service
@Slf4j
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
implements UserService{
private final PersonnelMapper personnelMapper;
private final PersonnelService personnelService;
private final OrgMapper orgMapper;
private final RoleMapper roleMapper;
@Override
public ResponseResult login(LoginDto loginDto) {
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>()
.eq(User::getPhone, loginDto.getPhone())
.eq(User::getIsDeleted, 0);
User user = baseMapper.selectOne(queryWrapper);
if (user == null) {
return ResponseResult.error(ResultCode.ERROR_USER_NOT_EXIST);
}
if(user.getStatus() == 0){
return ResponseResult.error(ResultCode.DISABLE_ACCOUNT);
}
if (user.getPassword().equals(loginDto.getPassword())) {
LambdaQueryWrapper<Personnel> queryWrapper1 = new LambdaQueryWrapper<Personnel>()
.eq(Personnel::getUserId, user.getId())
.eq(Personnel::getIsDeleted, 0);
Personnel personnel = personnelService.getOne(queryWrapper1);
if(personnel == null){
return ResponseResult.error(ResultCode.ERROR_USER_NOT_EXIST);
}
PersonnelVo personnelVo = toVo(personnel);
personnelVo.setOrgId(orgMapper.getOrgIdByPersonnelId(personnel.getId()));
personnelVo.setRoles(roleMapper.getRolesByUserId(personnel.getUserId()));
try{
StpUtil.login(user.getId());
}catch (Exception e){
log.error(e.getMessage());
}
personnelVo.setToken(StpUtil.getTokenValue());
return ResponseResult.success(personnelVo);
}
return ResponseResult.error(ResultCode.ERROR_PASSWORD);
}
}

View File

@@ -20,7 +20,7 @@ spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://www.yuxindazhineng.com:3306/dc_lab_system?serverTimeZone=CST&allowPublicKeyRetrieval=true&allowMultiQueries=true
url: jdbc:mysql://8.134.75.237:3309/dc_lab_system?serverTimeZone=CST&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: dc_admin
password: DC_yxd_admin@01
mybatis-plus:

View File

@@ -4,21 +4,12 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dc.dc_project.mapper.OrgMapper">
<resultMap id="BaseResultMap" type="com.dc.dc_project.model.pojo.Org">
<id property="id" column="id" />
<result property="parent_id" column="parent_id" />
<result property="name" column="name" />
<result property="type" column="type" />
<result property="code" column="code" />
<result property="sort_order" column="sort_order" />
<result property="remark" column="remark" />
<result property="created_at" column="created_at" />
<result property="updated_at" column="updated_at" />
<result property="is_deleted" column="is_deleted" />
</resultMap>
<sql id="Base_Column_List">
id,parent_id,name,type,code,sort_order,
remark,created_at,updated_at,is_deleted
</sql>
<select id="getOrgIdByPersonnelId" resultType="java.lang.Long">
select so.id from sys_org so where id == (select org_id from sys_personnel_org where personnel_id=#{personnelId})
</select>
</mapper>

View File

@@ -4,26 +4,14 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dc.dc_project.mapper.PersonnelMapper">
<resultMap id="BaseResultMap" type="com.dc.dc_project.model.pojo.Personnel">
<id property="id" column="id" />
<result property="org_id" column="org_id" />
<result property="user_id" column="user_id" />
<result property="name" column="name" />
<result property="position" column="position" />
<result property="contact_phone" column="contact_phone" />
<result property="email" column="email" />
<result property="main_responsibility" column="main_responsibility" />
<result property="remark" column="remark" />
<result property="status" column="status" />
<result property="created_by" column="created_by" />
<result property="created_at" column="created_at" />
<result property="updated_at" column="updated_at" />
<result property="is_deleted" column="is_deleted" />
</resultMap>
<sql id="Base_Column_List">
id,org_id,user_id,name,position,contact_phone,
email,main_responsibility,remark,status,created_by,
created_at,updated_at,is_deleted
</sql>
<select id="getVoByUserId" resultType="com.dc.dc_project.model.vo.PersonnelVo">
</select>
</mapper>

View File

@@ -0,0 +1,11 @@
<?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.dc.dc_project.mapper.PersonnelOrgMapper">
<sql id="Base_Column_List">
id,role_id,org_id,created_at,created_by
</sql>
</mapper>

View File

@@ -4,20 +4,15 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dc.dc_project.mapper.RoleMapper">
<resultMap id="BaseResultMap" type="com.dc.dc_project.model.pojo.Role">
<id property="id" column="id" />
<result property="name" column="name" />
<result property="code" column="code" />
<result property="level" column="level" />
<result property="status" column="status" />
<result property="description" column="description" />
<result property="created_at" column="created_at" />
<result property="updated_at" column="updated_at" />
<result property="is_deleted" column="is_deleted" />
</resultMap>
<sql id="Base_Column_List">
id,name,code,level,status,description,
created_at,updated_at,is_deleted
</sql>
<select id="getRolesByUserId" resultType="com.dc.dc_project.model.pojo.Role">
select * from sys_role where id in (
select role_id from sys_user_role where user_id = #{userId}
)
</select>
</mapper>

View File

@@ -1,18 +0,0 @@
<?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.dc.dc_project.mapper.RoleOrgMapper">
<resultMap id="BaseResultMap" type="com.dc.dc_project.model.pojo.RoleOrg">
<id property="id" column="id" />
<result property="role_id" column="role_id" />
<result property="org_id" column="org_id" />
<result property="created_at" column="created_at" />
<result property="created_by" column="created_by" />
</resultMap>
<sql id="Base_Column_List">
id,role_id,org_id,created_at,created_by
</sql>
</mapper>