2026-4-30:
1.后端代码2次更新
This commit is contained in:
@@ -67,6 +67,12 @@
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springdoc</groupId>-->
|
||||
<!-- <artifactId>springdoc-openapi-starter-common</artifactId>-->
|
||||
<!-- <version>2.3.0</version>-->
|
||||
<!-- <scope>compile</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 工具类 -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -79,10 +85,7 @@
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
@@ -92,6 +95,12 @@
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- modbus4j 核心依赖(Java8+,Spring Boot2/3均兼容) -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.infiniteautomation</groupId>-->
|
||||
<!-- <artifactId>modbus4j</artifactId>-->
|
||||
<!-- <version>3.0.3</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- 测试依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -3,9 +3,11 @@ package com.rczn;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan(value = "com.rczn.*")
|
||||
@EnableScheduling
|
||||
public class RcznAdminApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.rczn.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@@ -17,4 +21,25 @@ public class CorsConfig implements WebMvcConfigurer {
|
||||
.allowCredentials(true) // 允许携带Cookie
|
||||
.maxAge(3600); // 预检请求缓存1小时
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
// 1. 允许前端源(不要用*,和withCredentials=true配合需指定具体源,或用allowedOriginPatterns)
|
||||
config.addAllowedOriginPattern("*");
|
||||
// 2. 允许携带凭证(和前端withCredentials=true对应)
|
||||
config.setAllowCredentials(true);
|
||||
// 3. 允许所有请求方法(包含OPTIONS)
|
||||
config.addAllowedMethod("*");
|
||||
// 4. 允许所有请求头(包含Authorization)
|
||||
config.addAllowedHeader("*");
|
||||
// 5. 预检请求缓存时间(减少OPTIONS请求次数)
|
||||
config.setMaxAge(3600L);
|
||||
|
||||
// 配置生效路径
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.system.domain.ManageLog;
|
||||
import com.rczn.system.service.ManageLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/manage-log")
|
||||
@Tag(name = "操作日志管理", description = "操作日志增删改查+分页查询接口")
|
||||
public class ManageLogController {
|
||||
|
||||
@Autowired
|
||||
private ManageLogService manageLogService;
|
||||
|
||||
/**
|
||||
* 分页查询日志
|
||||
*/
|
||||
@GetMapping(value = "/listPage", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "分页查询操作日志", description = "支持多条件筛选,空条件自动忽略")
|
||||
@Parameters({
|
||||
@Parameter(name = "pageNum", description = "页码(必填)", required = true, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "pageSize", description = "每页条数(必填)", required = true, example = "10", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "logName", description = "日志名称(可选,模糊查询)", required = false, example = "登录操作", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "logType", description = "日志类型(可选,精准查询)", required = false, example = "LOGIN", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "createId", description = "创建人ID(可选)", required = false, example = "1", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "logWritetimeStart", description = "日志开始时间(可选,格式:yyyy-MM-dd HH:mm:ss)", required = false, example = "2025-01-01 00:00:00", in = ParameterIn.QUERY),
|
||||
@Parameter(name = "logWritetimeEnd", description = "日志结束时间(可选,格式:yyyy-MM-dd HH:mm:ss)", required = false, example = "2025-12-31 23:59:59", in = ParameterIn.QUERY)
|
||||
})
|
||||
public Result<PageBean<ManageLog>> getLogPage(
|
||||
@RequestParam Integer pageNum,
|
||||
@RequestParam Integer pageSize,
|
||||
@RequestParam(required = false) String logName,
|
||||
@RequestParam(required = false) String logType,
|
||||
@RequestParam(required = false) Long createId,
|
||||
@RequestParam(required = false) LocalDateTime logWritetimeStart,
|
||||
@RequestParam(required = false) LocalDateTime logWritetimeEnd) {
|
||||
|
||||
// 构建查询条件(空字段自动忽略)
|
||||
ManageLog query = new ManageLog();
|
||||
query.setLogName(logName);
|
||||
query.setLogType(logType);
|
||||
query.setCreateId(createId);
|
||||
// 扩展字段:用于时间范围查询(实体类无需新增字段,MyBatis 支持直接取参)
|
||||
query.setStartTime(logWritetimeStart); // 实际用 logWritetimeStart,这里仅为传递参数
|
||||
query.setEndTime(logWritetimeEnd);
|
||||
|
||||
PageBean<ManageLog> pageBean = manageLogService.selectPage(pageNum, pageSize, query);
|
||||
return Result.success(pageBean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 ID 查询日志
|
||||
*/
|
||||
@GetMapping(value = "/getById/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "查询单个操作日志", description = "按日志ID查询详情")
|
||||
public Result getLogById(@PathVariable Long id) {
|
||||
ManageLog log = manageLogService.selectById(id);
|
||||
return log != null ? Result.success(log) : Result.error("日志不存在或已删除");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增操作日志
|
||||
*/
|
||||
@PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "新增操作日志", description = "日志名称、类型为必填项,其他字段可选")
|
||||
public Result addLog(@RequestBody ManageLog manageLog) {
|
||||
try {
|
||||
Long logId = manageLogService.insert(manageLog);
|
||||
return Result.success("日志新增成功");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新操作日志
|
||||
*/
|
||||
@PutMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "更新操作日志", description = "需传入日志ID,其他字段非空则更新")
|
||||
public Result updateLog(@RequestBody ManageLog manageLog) {
|
||||
try {
|
||||
Boolean success = manageLogService.update(manageLog);
|
||||
return success ? Result.success( "日志更新成功") : Result.error("更新失败(日志不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除操作日志
|
||||
*/
|
||||
@DeleteMapping(value = "/del/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@Operation(summary = "删除操作日志", description = "逻辑删除(设置delSign=1,不物理删除)")
|
||||
public Result deleteLog(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(required = false) Long updateId) {
|
||||
try {
|
||||
Boolean success = manageLogService.deleteById(id, updateId);
|
||||
return success ? Result.success("日志删除成功") : Result.error("删除失败(日志不存在或已删除)");
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,12 +22,8 @@ import java.util.List;
|
||||
@Tag(name = "角色管理", description = "角色增删改查接口(支持分页+多条件查询+编码唯一性校验)")
|
||||
public class RoleController {
|
||||
|
||||
private final RoleService roleService;
|
||||
|
||||
// 构造器注入
|
||||
public RoleController(RoleService roleService) {
|
||||
this.roleService = roleService;
|
||||
}
|
||||
@Autowired
|
||||
RoleService roleService;
|
||||
|
||||
/**
|
||||
* 1. 分页查询角色(多条件模糊查询)
|
||||
|
||||
@@ -1,18 +1,33 @@
|
||||
package com.rczn.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonAppend;
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.domain.Result;
|
||||
import com.rczn.rcznautoplc.domain.ManageLog;
|
||||
import com.rczn.rcznautoplc.domain.RecordInfo;
|
||||
import com.rczn.rcznautoplc.service.ManageLogService;
|
||||
import com.rczn.rcznautoplc.service.RecordInfoService;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.User;
|
||||
import com.rczn.system.service.UserService;
|
||||
import com.rczn.utils.JwtUtil;
|
||||
import com.rczn.utils.Md5Util;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户管理 CRUD API(MyBatis+PageHelper 实现)
|
||||
@@ -117,4 +132,108 @@ public class UserController {
|
||||
Boolean success = userService.deleteById(id);
|
||||
return success ? Result.success("删除用户成功") : Result.error("删除失败(用户不存在)");
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/register")
|
||||
@Operation(summary = "注册", description = "用户名必须是2-16位的字母、数字、下划线或减号")
|
||||
public Result register(@Pattern(regexp = "^[a-zA-Z0-9_-]{2,16}$", message = "用户名必须是2-16位的字母、数字、下划线或减号")
|
||||
@Parameter(
|
||||
name = "username",
|
||||
description = "用户名"
|
||||
)
|
||||
@RequestParam
|
||||
String username,
|
||||
@Parameter(
|
||||
name = "password",
|
||||
description = "密码..."
|
||||
)
|
||||
@RequestParam
|
||||
String password) {
|
||||
//查询数据库是否有该用户
|
||||
User user = userService.findeUserByUsername(username);
|
||||
//注册
|
||||
if (user == null) {
|
||||
//如果用户不存在,则注册
|
||||
int result = userService.register(username, password);
|
||||
return Result.success("用户注册成功");
|
||||
} else {
|
||||
//用户存在,返回错误信息
|
||||
return Result.error("该用户名已存在!");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/getUserByUsername")
|
||||
public Result getUserByUsername(String username) {
|
||||
User user = userService.findeUserByUsername(username);
|
||||
if (user == null) {
|
||||
return Result.error("该用户不存在!");
|
||||
} else {
|
||||
return Result.success(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ManageLogService manageLogService;
|
||||
|
||||
@PostMapping("/login")
|
||||
@Operation(summary = "用户登录接口",description = "根据用户名和密码登录,返回JWT Token")
|
||||
public Result login(
|
||||
@Parameter(
|
||||
name = "username",
|
||||
description = "登录用户名(2-16位的字母、数字、下划线或减号)",
|
||||
required = true, // 标记为必填参数
|
||||
example = "string"
|
||||
)
|
||||
@RequestParam
|
||||
String username,
|
||||
@Parameter(
|
||||
name = "password",
|
||||
description = "登录密码",
|
||||
required = true
|
||||
)
|
||||
@RequestParam
|
||||
String password) {
|
||||
|
||||
//TODO 登录逻辑
|
||||
//查询数据库是否有该用户
|
||||
User user = userService.findeUserByUsername(username);
|
||||
//登录
|
||||
if (user == null) {
|
||||
//如果用户不存在,返回错误信息
|
||||
return Result.error("该用户不存在!");
|
||||
} else {
|
||||
//校验密码:
|
||||
String encryptPassword = user.getPassword();
|
||||
if (encryptPassword.equals(password)) {
|
||||
//登录成功,增加登录日志:
|
||||
LocalDateTime loginTime = LocalDateTime.now();
|
||||
ManageLog info = new ManageLog();
|
||||
info.setCreateId(user.getId());
|
||||
info.setLogName("登录日志");
|
||||
info.setLogType("登录日志");//1:登录日志、2:SOP操作日志、3:基础数据操作日志
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("用户名:").append(user.getUserName()).append(",登录操作时间:").append(loginTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
info.setLogContent(stringBuilder.toString());
|
||||
info.setCreateTime(loginTime);
|
||||
manageLogService.insert(info);
|
||||
|
||||
// if (Md5Util.checkPassword(password, encryptPassword)) {
|
||||
//生产token
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put("id", user.getId());
|
||||
claims.put("username", user.getUserName());
|
||||
//获取权限列表:
|
||||
List<Permission> permissions = userService.findUserPermissions(user.getId());
|
||||
List<String> permissionList = permissions.stream().map(Permission::getPermissionCode).collect(Collectors.toList());
|
||||
claims.put("permissions", permissionList);
|
||||
String jwtToken = JwtUtil.genToken(claims);
|
||||
//密码正确,返回成功信息
|
||||
return Result.success(jwtToken);
|
||||
} else {
|
||||
//密码错误,返回错误信息
|
||||
return Result.error("密码错误!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package com.rczn.system.domain;
|
||||
|
||||
import com.rczn.domain.BaseBean;
|
||||
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ManageLog extends BaseBean {
|
||||
private String logName;
|
||||
|
||||
private String logType;
|
||||
|
||||
private LocalDateTime logWritetime;
|
||||
|
||||
private String logContent;
|
||||
|
||||
public ManageLog() {
|
||||
}
|
||||
|
||||
public ManageLog(Long id, Long createId, LocalDateTime createTime, Long updateId, LocalDateTime updateTime, boolean delSign, String remark) {
|
||||
super(id, createId, createTime, updateId, updateTime, delSign, remark);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ManageLog{" +
|
||||
"logName='" + logName + '\'' +
|
||||
", logType='" + logType + '\'' +
|
||||
", logWritetime=" + logWritetime +
|
||||
", logContent='" + logContent + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getLogName() {
|
||||
return logName;
|
||||
}
|
||||
|
||||
public void setLogName(String logName) {
|
||||
this.logName = logName;
|
||||
}
|
||||
|
||||
public String getLogType() {
|
||||
return logType;
|
||||
}
|
||||
|
||||
public void setLogType(String logType) {
|
||||
this.logType = logType;
|
||||
}
|
||||
|
||||
public LocalDateTime getLogWritetime() {
|
||||
return logWritetime;
|
||||
}
|
||||
|
||||
public void setLogWritetime(LocalDateTime logWritetime) {
|
||||
this.logWritetime = logWritetime;
|
||||
}
|
||||
|
||||
public String getLogContent() {
|
||||
return logContent;
|
||||
}
|
||||
|
||||
public void setLogContent(String logContent) {
|
||||
this.logContent = logContent;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,31 @@
|
||||
package com.rczn.system.domain;
|
||||
|
||||
import com.rczn.domain.BaseBean;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class Permission extends BaseBean {
|
||||
import java.util.List;
|
||||
|
||||
public class Permission extends BaseBean{
|
||||
|
||||
private Integer parentId;
|
||||
private String permissionName;
|
||||
private String permissionCode;
|
||||
|
||||
private String permissionCode;}
|
||||
// 树形结构子节点 ✅
|
||||
private List<Permission> children;
|
||||
|
||||
// getter & setter
|
||||
public Integer getParentId() { return parentId; }
|
||||
public void setParentId(Integer parentId) { this.parentId = parentId; }
|
||||
public String getPermissionName() { return permissionName; }
|
||||
public void setPermissionName(String permissionName) { this.permissionName = permissionName; }
|
||||
public String getPermissionCode() { return permissionCode; }
|
||||
public void setPermissionCode(String permissionCode) { this.permissionCode = permissionCode; }
|
||||
|
||||
// children
|
||||
public List<Permission> getChildren() {
|
||||
return children;
|
||||
}
|
||||
public void setChildren(List<Permission> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
import com.rczn.system.domain.ManageLog;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper // 标记为 MyBatis Mapper 接口,确保被 Spring 扫描
|
||||
public interface ManageLogMapper {
|
||||
// 新增日志(支持空字段,空字段用数据库默认值)
|
||||
int insert(ManageLog manageLog);
|
||||
|
||||
// 逻辑删除日志(按 ID,设置 delSign=1)
|
||||
int deleteById(Long id);
|
||||
|
||||
// 更新日志(仅更新非空字段,空字段不更新)
|
||||
int update(ManageLog manageLog);
|
||||
|
||||
// 按 ID 查询日志(仅查未删除数据)
|
||||
ManageLog selectById(Long id);
|
||||
|
||||
// 分页查询日志(支持按字段筛选,空字段忽略条件)
|
||||
List<ManageLog> selectPage(ManageLog manageLog);
|
||||
|
||||
// 查询分页总数(与分页查询条件一致)
|
||||
Long selectTotal(ManageLog manageLog);
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.rczn.system.mapper;
|
||||
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.User;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@@ -31,4 +34,10 @@ public interface UserMapper {
|
||||
@Param("sex") Integer sex,
|
||||
@Param("delSign") Boolean delSign
|
||||
);
|
||||
|
||||
@Select("SELECT * FROM sys_user WHERE user_name = #{userName}")
|
||||
User selectByUsername(String userName);
|
||||
|
||||
//根据用户id,查询出对应的权限列表
|
||||
List<Permission> findUserPermissions(Long userId);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.ManageLog;
|
||||
|
||||
public interface ManageLogService {
|
||||
// 新增日志
|
||||
Long insert(ManageLog manageLog);
|
||||
|
||||
// 逻辑删除日志
|
||||
Boolean deleteById(Long id, Long updateId);
|
||||
|
||||
// 更新日志(仅更新非空字段)
|
||||
Boolean update(ManageLog manageLog);
|
||||
|
||||
// 按 ID 查询日志
|
||||
ManageLog selectById(Long id);
|
||||
|
||||
// 分页查询日志(支持多条件筛选)
|
||||
PageBean<ManageLog> selectPage(Integer pageNum, Integer pageSize, ManageLog manageLog);
|
||||
}
|
||||
@@ -11,6 +11,13 @@ public interface UserRoleService {
|
||||
Boolean deleteByRoleId(Integer roleId);
|
||||
UserRole selectById(Long id);
|
||||
List<UserRole> selectByUserId(Integer userId);
|
||||
|
||||
/**
|
||||
* Selects user roles by the given role ID
|
||||
*
|
||||
* @param roleId The ID of the role to search for
|
||||
* @return List of UserRole objects associated with the given role ID
|
||||
*/
|
||||
List<UserRole> selectByRoleId(Integer roleId);
|
||||
PageBean<UserRole> selectPage(Integer pageNum, Integer pageSize, Integer userId, Integer roleId);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.rczn.system.service;
|
||||
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.User;
|
||||
|
||||
import java.util.List;
|
||||
@@ -53,4 +54,25 @@ public interface UserService {
|
||||
* @return 是否删除成功(true/false)
|
||||
*/
|
||||
Boolean deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 6. 根据用户名查询用户
|
||||
* @param username 用户名
|
||||
* @return 用户实体
|
||||
*/
|
||||
User findeUserByUsername(String username);
|
||||
|
||||
/**
|
||||
* 7. 注册用户
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
*/
|
||||
int register(String username, String password);
|
||||
|
||||
/**
|
||||
* 根据用户id查询出关联的用户权限对象列表,
|
||||
* 表直接的关系是:
|
||||
* 用户表(user)--用户权限表(user_role)--权限表(role)-- 权限资源表(role_resource)--资源表(resource)
|
||||
*/
|
||||
List<Permission> findUserPermissions(Long userId);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
package com.rczn.system.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.ManageLog;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.rczn.system.domain.Position;
|
||||
import com.rczn.system.mapper.ManageLogMapper;
|
||||
import com.rczn.system.service.ManageLogService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ManageLogServiceImpl implements ManageLogService {
|
||||
|
||||
@Autowired
|
||||
private ManageLogMapper manageLogMapper;
|
||||
|
||||
@Override
|
||||
public Long insert(ManageLog manageLog) {
|
||||
// 校验必填字段(日志名称和类型为必填)
|
||||
Assert.notNull(manageLog.getLogName(), "日志名称不能为空");
|
||||
Assert.notNull(manageLog.getLogType(), "日志类型不能为空");
|
||||
|
||||
//补充日志时间
|
||||
if (manageLog.getLogWritetime() == null) {
|
||||
manageLog.setLogWritetime(LocalDateTime.now());
|
||||
}
|
||||
// TODO 补充日志创建人信息
|
||||
// manageLog.setCreateId(null);
|
||||
manageLog.setCreateTime(LocalDateTime.now());
|
||||
int rows = manageLogMapper.insert(manageLog);
|
||||
return rows > 0 ? manageLog.getId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteById(Long id, Long updateId) {
|
||||
Assert.notNull(id, "日志ID不能为空");
|
||||
int rows = manageLogMapper.deleteById(id);
|
||||
return rows > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(ManageLog manageLog) {
|
||||
Assert.notNull(manageLog.getId(), "日志ID不能为空");
|
||||
//如果更新时间为空,则自动更新
|
||||
if (manageLog.getUpdateTime() == null) {
|
||||
manageLog.setUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
// TODO 补充日志更新人信息
|
||||
// manageLog.setUpdateId(null);
|
||||
int rows = manageLogMapper.update(manageLog);
|
||||
return rows > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManageLog selectById(Long id) {
|
||||
Assert.notNull(id, "日志ID不能为空");
|
||||
return manageLogMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageBean<ManageLog> selectPage(Integer pageNum, Integer pageSize, ManageLog manageLog) {
|
||||
// 校验分页参数
|
||||
Assert.notNull(pageNum, "页码不能为空");
|
||||
Assert.notNull(pageSize, "每页条数不能为空");
|
||||
Assert.isTrue(pageNum > 0, "页码必须大于0");
|
||||
Assert.isTrue(pageSize > 0 && pageSize <= 100000, "每页条数必须在1-10000之间");
|
||||
|
||||
// PageHelper 分页(自动拦截查询,添加 LIMIT 条件)
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<ManageLog> logList = manageLogMapper.selectPage(manageLog);
|
||||
Page<ManageLog> page = (Page<ManageLog>) logList;
|
||||
|
||||
PageBean<ManageLog> pageBean = new PageBean<>();
|
||||
pageBean.setTotal(page.getTotal());
|
||||
pageBean.setItems(page.getResult());
|
||||
|
||||
// 封装PageBean返回
|
||||
return pageBean;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.rczn.system.service.impl;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.Position;
|
||||
import com.rczn.system.domain.UserRole;
|
||||
import com.rczn.system.mapper.UserRoleMapper;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.rczn.system.service.impl;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.rczn.domain.PageBean;
|
||||
import com.rczn.system.domain.Permission;
|
||||
import com.rczn.system.domain.User;
|
||||
import com.rczn.system.mapper.UserMapper;
|
||||
import com.rczn.system.service.UserService;
|
||||
@@ -90,4 +91,41 @@ public class UserServiceImpl implements UserService {
|
||||
int rows = userMapper.deleteById(id,null);
|
||||
return rows > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 6. 根据用户名查询用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @return 用户实体
|
||||
*/
|
||||
@Override
|
||||
public User findeUserByUsername(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 7. 注册用户
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
*/
|
||||
@Override
|
||||
public int register(String username, String password) {
|
||||
User user = new User();
|
||||
user.setUserName(username);
|
||||
user.setPassword(password);
|
||||
return userMapper.insert(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户id查询出关联的用户权限对象列表,
|
||||
* 表直接的关系是:
|
||||
* 用户表(user)--用户权限表(user_role)--权限表(role)-- 权限资源表(role_resource)--资源表(resource)
|
||||
*
|
||||
* @param userId
|
||||
*/
|
||||
@Override
|
||||
public List<Permission> findUserPermissions(Long userId) {
|
||||
return userMapper.findUserPermissions(userId);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ spring:
|
||||
# 数据源配置(MySQL 8.x)
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://47.116.126.33:3306/rc_autoplc_program?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
url: jdbc:mysql://47.116.126.33:3306/rc_autoplc_program?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&allowMultiQueries=true
|
||||
username: nianke
|
||||
password: Jy@.niankeCrm2025
|
||||
# 解决跨域(可选,配合之前的CorsConfig)
|
||||
@@ -42,11 +42,12 @@ spring:
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true # 下划线转驼峰
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 关键:SQL 打印到控制台
|
||||
log-prefix: "[MyBatis] " # 可选:日志前缀,便于区分 SQL 日志
|
||||
default-statement-timeout: 30 # 可选:SQL 执行超时时间(秒)
|
||||
mapper-locations: classpath:mapper/**/*.xml # 补充:指定Mapper.xml文件路径(必加)
|
||||
type-aliases-package: com.rczn.**.domain # 补充:实体类别名包(可选)
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 关键:SQL 打印到控制台
|
||||
log-prefix: "[MyBatis] " # 可选:日志前缀,便于区分 SQL 日志
|
||||
default-statement-timeout: 30 # 可选:SQL 执行超时时间(秒)
|
||||
|
||||
|
||||
# HikariCP 连接池配置(关键)
|
||||
hikari:
|
||||
@@ -66,22 +67,22 @@ pagehelper:
|
||||
support-methods-arguments: true # 支持通过 Mapper 接口参数传递分页参数
|
||||
params: count=countSql # 分页参数名映射
|
||||
|
||||
|
||||
# SpringDoc OpenAPI 3 核心配置(适配Spring Boot 3.x)
|
||||
springdoc:
|
||||
packages-to-scan: com.rczn # 扫描的基础包(Controller所在包)
|
||||
api-docs:
|
||||
enabled: true # 启用/v3/api-docs接口
|
||||
path: /v3/api-docs # OpenAPI JSON数据路径(默认)
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html # 自定义Swagger UI访问路径(兼容Spring Boot 2.x习惯)
|
||||
tags-sorter: alpha # 标签字母排序
|
||||
operations-sorter: alpha # 接口字母排序
|
||||
disable-swagger-default-url: true # 禁用默认PetStore示例
|
||||
default-flat-param-object: false # 禁用扁平参数对象
|
||||
paths-to-exclude: /error, /actuator/** # 排除错误接口/监控接口(可选)
|
||||
|
||||
# OpenAPI文档基础信息(中文正常显示)
|
||||
#
|
||||
## SpringDoc OpenAPI 3 核心配置(适配Spring Boot 3.x)
|
||||
#springdoc:
|
||||
# packages-to-scan: com.rczn # 扫描的基础包(Controller所在包)
|
||||
# api-docs:
|
||||
# enabled: true # 启用/v3/api-docs接口
|
||||
# path: /v3/api-docs # OpenAPI JSON数据路径(默认)
|
||||
# swagger-ui:
|
||||
# path: /swagger-ui.html # 自定义Swagger UI访问路径(兼容Spring Boot 2.x习惯)
|
||||
# tags-sorter: alpha # 标签字母排序
|
||||
# operations-sorter: alpha # 接口字母排序
|
||||
# disable-swagger-default-url: true # 禁用默认PetStore示例
|
||||
# default-flat-param-object: false # 禁用扁平参数对象
|
||||
# paths-to-exclude: /error, /actuator/** # 排除错误接口/监控接口(可选)
|
||||
#
|
||||
## OpenAPI文档基础信息(中文正常显示)
|
||||
openapi:
|
||||
info:
|
||||
title: XX自动化编程系统API文档
|
||||
@@ -96,6 +97,40 @@ openapi:
|
||||
- url: http://47.116.126.33:9090 # 测试环境地址
|
||||
description: 测试环境
|
||||
|
||||
|
||||
# SpringDoc + Knife4j 核心配置
|
||||
springdoc:
|
||||
packages-to-scan: com.rczn # 扫描Controller所在包
|
||||
api-docs:
|
||||
enabled: true
|
||||
path: /v3/api-docs
|
||||
swagger-ui:
|
||||
tags-sorter: alpha
|
||||
operations-sorter: alpha
|
||||
paths-to-exclude: /error, /actuator/**
|
||||
|
||||
# Knife4j增强配置(可选,开启中文UI)
|
||||
knife4j:
|
||||
enable: true
|
||||
setting:
|
||||
language: zh_cn # 中文界面
|
||||
enable-swagger-models: true # 显示模型
|
||||
enable-document-manage: false # 关闭文档管理(开发环境)
|
||||
|
||||
# OpenAPI文档信息
|
||||
#openapi:
|
||||
# info:
|
||||
# title: XX自动化编程系统API文档
|
||||
# description: SpringBoot 3.x + Knife4j + OpenAPI 3 接口文档
|
||||
# version: 1.0.0
|
||||
# contact:
|
||||
# name: 研发组
|
||||
# email: xxx@xxx.com
|
||||
# servers:
|
||||
# - url: http://localhost:9090
|
||||
# description: 本地开发环境
|
||||
# - url: http://47.116.126.33:9090
|
||||
# description: 测试环境
|
||||
# Spring Boot 日志核心配置
|
||||
logging:
|
||||
# 1. 全局日志级别(可细化到包/类)
|
||||
|
||||
@@ -1,175 +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.rczn.system.mapper.ManageLogMapper">
|
||||
|
||||
<!-- 公共字段(BaseBean 继承的字段) -->
|
||||
<sql id="baseColumn">
|
||||
id, create_id, create_time, update_id, update_time, del_sign, remark
|
||||
</sql>
|
||||
|
||||
<!-- ManageLog 专属字段 -->
|
||||
<sql id="logColumn">
|
||||
log_name, log_type, log_writetime, log_content
|
||||
</sql>
|
||||
|
||||
<!-- 结果集映射(关联数据库列与实体类字段) -->
|
||||
<resultMap id="LogResultMap" type="com.rczn.system.domain.ManageLog">
|
||||
<!-- 公共字段映射 -->
|
||||
<id column="id" property="id"/>
|
||||
<result column="create_id" property="createId"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_id" property="updateId"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="del_sign" property="delSign"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<!-- 专属字段映射 -->
|
||||
<result column="log_name" property="logName"/>
|
||||
<result column="log_type" property="logType"/>
|
||||
<result column="log_writetime" property="logWritetime"/>
|
||||
<result column="log_content" property="logContent"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 1. 新增日志(空字段忽略,用数据库默认值) -->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO sys_manage_log (
|
||||
<trim suffixOverrides=",">
|
||||
<!-- 专属字段 -->
|
||||
<if test="logName != null and logName != ''"> log_name,</if>
|
||||
<if test="logType != null and logType != ''"> log_type,</if>
|
||||
<if test="logWritetime != null"> log_writetime,</if>
|
||||
<if test="logContent != null and logContent != ''"> log_content,</if>
|
||||
<!-- 公共字段 -->
|
||||
<if test="createId != null"> create_id,</if>
|
||||
<if test="createTime != null"> create_time,</if>
|
||||
<if test="updateId != null"> update_id,</if>
|
||||
<if test="updateTime != null"> update_time,</if>
|
||||
<if test="delSign != null"> del_sign,</if>
|
||||
<if test="remark != null and remark != ''"> remark,</if>
|
||||
</trim>
|
||||
) VALUES (
|
||||
<trim suffixOverrides=",">
|
||||
<!-- 专属字段:空字段传递 null,数据库设默认值 -->
|
||||
<if test="logName != null and logName != ''">#{logName},</if>
|
||||
<if test="logType != null and logType != ''">#{logType},</if>
|
||||
<if test="logWritetime != null">#{logWritetime},</if>
|
||||
<if test="logContent != null and logContent != ''">#{logContent},</if>
|
||||
<!-- 公共字段:空字段传递 null,数据库设默认值 -->
|
||||
<if test="createId != null">#{createId},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateId != null">#{updateId},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="delSign != null">#{delSign},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
</trim>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 2. 更新日志(仅更新非空字段) -->
|
||||
<update id="update">
|
||||
UPDATE sys_manage_log
|
||||
<set>
|
||||
<!-- 专属字段:非空才更新 -->
|
||||
<if test="logName != null and logName != ''">log_name = #{logName},</if>
|
||||
<if test="logType != null and logType != ''">log_type = #{logType},</if>
|
||||
<if test="logWritetime != null">log_writetime = #{logWritetime},</if>
|
||||
<if test="logContent != null and logContent != ''">log_content = #{logContent},</if>
|
||||
<!-- 公共字段:非空才更新 -->
|
||||
<if test="updateId != null">update_id = #{updateId},</if>
|
||||
<if test="remark != null and remark != ''">remark = #{remark},</if>
|
||||
<if test="delSign != null">del_sign = #{delSign},</if>
|
||||
<!-- 强制更新时间为当前时间 -->
|
||||
update_time = NOW()
|
||||
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
AND del_sign = 0 <!-- 仅更新未删除的数据 -->
|
||||
</update>
|
||||
|
||||
<!-- 3. 逻辑删除日志 -->
|
||||
<delete id="deleteById">
|
||||
UPDATE sys_manage_log
|
||||
SET
|
||||
del_sign = 1,
|
||||
update_time = NOW(),
|
||||
<if test="updateId != null">update_id = #{updateId}</if>
|
||||
WHERE id = #{id}
|
||||
AND del_sign = 0 <!-- 避免重复删除 -->
|
||||
</delete>
|
||||
|
||||
<!-- 4. 按 ID 查询日志 -->
|
||||
<select id="selectById" resultMap="LogResultMap">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="logColumn"/>
|
||||
FROM sys_manage_log
|
||||
WHERE id = #{id}
|
||||
AND del_sign = 0 <!-- 仅查未删除数据 -->
|
||||
</select>
|
||||
|
||||
<!-- 5. 分页查询日志(空字段忽略条件) -->
|
||||
<select id="selectPage" resultMap="LogResultMap" parameterType="com.rczn.system.domain.ManageLog">
|
||||
SELECT
|
||||
<include refid="baseColumn"/>,
|
||||
<include refid="logColumn"/>
|
||||
FROM sys_manage_log
|
||||
<where>
|
||||
<!-- 默认查未删除数据,传 delSign=1 可查已删除 -->
|
||||
<if test="delSign == null">
|
||||
AND del_sign = 0
|
||||
</if>
|
||||
<if test="delSign != null">
|
||||
AND del_sign = #{delSign}
|
||||
</if>
|
||||
<!-- 日志名称:模糊查询,空字段忽略 -->
|
||||
<if test="logName != null and logName != ''">
|
||||
AND log_name LIKE CONCAT('%', #{logName}, '%')
|
||||
</if>
|
||||
<!-- 日志类型:精准查询,空字段忽略 -->
|
||||
<if test="logType != null and logType != ''">
|
||||
AND log_type = #{logType}
|
||||
</if>
|
||||
<!-- 日志写入时间:范围查询(可选,空字段忽略) -->
|
||||
<if test="startTime != null">
|
||||
AND log_writetime >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND log_writetime <= #{endTime}
|
||||
</if>
|
||||
<!-- 创建人ID:精准查询,空字段忽略 -->
|
||||
<if test="createId != null">
|
||||
AND create_id = #{createId}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY log_writetime DESC <!-- 按日志写入时间倒序 -->
|
||||
</select>
|
||||
|
||||
<!-- 6. 查询分页总数(与分页查询条件一致) -->
|
||||
<select id="selectTotal" resultType="java.lang.Long" parameterType="com.rczn.system.domain.ManageLog">
|
||||
SELECT COUNT(*)
|
||||
FROM sys_manage_log
|
||||
<where>
|
||||
<if test="delSign == null">
|
||||
AND del_sign = 0
|
||||
</if>
|
||||
<if test="delSign != null">
|
||||
AND del_sign = #{delSign}
|
||||
</if>
|
||||
<if test="logName != null and logName != ''">
|
||||
AND log_name LIKE CONCAT('%', #{logName}, '%')
|
||||
</if>
|
||||
<if test="logType != null and logType != ''">
|
||||
AND log_type = #{logType}
|
||||
</if>
|
||||
<if test="logWritetimeStart != null">
|
||||
AND log_writetime >= #{logWritetimeStart}
|
||||
</if>
|
||||
<if test="logWritetimeEnd != null">
|
||||
AND log_writetime <= #{logWritetimeEnd}
|
||||
</if>
|
||||
<if test="createId != null">
|
||||
AND create_id = #{createId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -198,5 +198,24 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="findUserPermissions" resultType="com.rczn.system.domain.Permission">
|
||||
SELECT
|
||||
p.*
|
||||
FROM
|
||||
sys_user u
|
||||
JOIN
|
||||
sys_user_role ur ON u.id = ur.user_id
|
||||
JOIN
|
||||
sys_role r ON ur.role_id = r.id
|
||||
JOIN
|
||||
sys_role_permission rp ON r.id = rp.role_id
|
||||
JOIN
|
||||
sys_permission p ON rp.permission_id = p.id
|
||||
WHERE
|
||||
u.id = #{userId}
|
||||
AND u.del_sign = 0
|
||||
AND r.del_sign = 0
|
||||
AND p.del_sign = 0;
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user