新曾业务bean和相关数据持久化,controller restful 接口

This commit is contained in:
2025-12-26 09:50:10 +08:00
parent 26a6152ecc
commit 281d79b8cd
56 changed files with 2415 additions and 58 deletions

View File

@@ -11,6 +11,8 @@ import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 角色管理 CRUD APIMyBatis+PageHelper 实现)
*/
@@ -47,6 +49,23 @@ public class RoleController {
return Result.success(pageBean);
}
/**
* 1. 分页查询角色(多条件模糊查询)
*/
@GetMapping("/list")
@Operation(summary = "查询角色列表", description = "支持角色名、角色编码模糊查询")
@Parameters({
@Parameter(name = "roleName", description = "角色名(模糊查询,可选)", required = false, example = "管理员", in = ParameterIn.QUERY),
@Parameter(name = "roleCode", description = "角色编码(模糊查询,可选)", required = false, example = "ADMIN", in = ParameterIn.QUERY)
})
public Result getRoleList(
@RequestParam(required = false) String roleName,
@RequestParam(required = false) String roleCode) {
List<Role> list = roleService.selectRoleList( roleName, roleCode);
return Result.success(list);
}
/**
* 2. 根据ID查询单个角色
*/

View File

@@ -12,6 +12,8 @@ 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;
/**
* 用户管理 CRUD APIMyBatis+PageHelper 实现)
*/
@@ -44,6 +46,19 @@ public class UserController {
return Result.success(pageBean);
}
@GetMapping("/list")
@Operation(summary = "查询用户列表", description = "用户名模糊查询,查询全部")
@Parameters({
@Parameter(name = "userName", description = "用户名(模糊查询,可选)", required = false, example = "张三", in = ParameterIn.QUERY)
})
public Result<List<User>> getUserList(
@RequestParam(required = false) String userName) {
// 调用 Service 查询列表
List<User> userList = userService.selectUserList(userName);
return Result.success(userList);
}
/**
* 2. 根据ID查询单个用户
*/

View File

@@ -31,9 +31,7 @@ public interface UserRoleMapper {
// 分页查询所有关联
List<UserRole> selectPage(
@Param("userId") Integer userId,
@Param("roleId") Integer roleId,
@Param("start") Integer start,
@Param("pageSize") Integer pageSize
@Param("roleId") Integer roleId
);
// 查询分页总数

View File

@@ -3,6 +3,8 @@ package com.rczn.system.service;
import com.rczn.domain.PageBean;
import com.rczn.system.domain.Role;
import java.util.List;
/**
* Role 业务逻辑层接口
*/
@@ -47,4 +49,12 @@ public interface RoleService {
* @return 是否删除成功
*/
Boolean deleteById(Long id);
/**
* 根据角色名或角色编码模糊查询角色列表
* @param roleName 角色名(可选)
* @param roleCode 角色编码(可选)
* @return 角色列表
*/
List<Role> selectRoleList(String roleName, String roleCode);
}

View File

@@ -3,6 +3,8 @@ package com.rczn.system.service;
import com.rczn.domain.PageBean;
import com.rczn.system.domain.User;
import java.util.List;
/**
* User 业务逻辑层接口
*/
@@ -17,6 +19,13 @@ public interface UserService {
*/
PageBean<User> selectUserPage(Integer pageNum, Integer pageSize, String userName);
/**
* 1. 查询用户列表(支持用户名模糊查询)
* @param userName 用户名(模糊查询,可选)
* @return 结果listUser
*/
List<User> selectUserList(String userName);
/**
* 2. 根据ID查询单个用户
* @param id 用户ID

View File

@@ -95,4 +95,16 @@ public class RoleServiceImpl implements RoleService {
int rows = roleMapper.deleteById(id);
return rows > 0;
}
/**
* 根据角色名或角色编码模糊查询角色列表
*
* @param roleName 角色名(可选)
* @param roleCode 角色编码(可选)
* @return 角色列表
*/
@Override
public List<Role> selectRoleList(String roleName, String roleCode) {
return roleMapper.selectRolePage(roleName, roleCode);
}
}

View File

@@ -1,6 +1,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.Position;
import com.rczn.system.domain.UserRole;
@@ -72,8 +73,8 @@ public class UserRoleServiceImpl implements UserRoleService {
Assert.isTrue(pageNum > 0, "页码必须大于0");
Assert.isTrue(pageSize > 0 && pageSize <= 100000, "每页条数必须在1-10000之间");
int start = (pageNum - 1) * pageSize;
List<UserRole> items = userRoleMapper.selectPage(userId, roleId, start, pageSize);
PageHelper.startPage(pageNum,pageSize);
List<UserRole> items = userRoleMapper.selectPage(userId, roleId);
Page<UserRole> page = (Page<UserRole>) items;
PageBean<UserRole> pageBean = new PageBean<>();

View File

@@ -45,6 +45,22 @@ public class UserServiceImpl implements UserService {
return pageBean;
}
/**
* 1. 查询用户列表(支持用户名模糊查询)
*
* @param userName 用户名(模糊查询,可选)
* @return 结果listUser
*/
@Override
public List<User> selectUserList(String userName) {
// 2. 执行查询MyBatis 会自动添加 LIMIT 分页)
User user = new User();
user.setUserName(userName);
List<User> userList = userMapper.selectUserPage(user);
return userList;
}
@Override
public User selectById(Long id) {
// 查询不到返回 null后续 Controller 处理)

View File

@@ -69,10 +69,10 @@
UPDATE sys_role
<set>
<if test="roleName != null ">role_name = #{roleName},</if>
<if test="roleCode != null ">role_code = #{roleCode}</if>
<if test="updateId != null ">updateId = NULL,</if>
<if test="updateTime != null ">updateTime = now(),</if>
<if test="remark != null ">remark = NULL,</if>
<if test="roleCode != null ">role_code = #{roleCode},</if>
<if test="updateId != null ">update_id = #{updateId},</if>
<if test="updateTime != null ">update_time = now(),</if>
<if test="remark != null ">remark = #{remark},</if>
</set>
WHERE id = #{id}
</update>

View File

@@ -10,9 +10,9 @@
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
INSERT INTO sys_user_role (
<include refid="userRoleColumn"/>, create_time, update_time, del_sign
<include refid="userRoleColumn"/>,remark, create_time, del_sign
) VALUES (
#{userId}, #{roleId}, NOW(), NOW(), 0
#{userId}, #{roleId}, #{remark},NOW(), 0
)
</insert>
@@ -57,7 +57,6 @@
<if test="userId != null">AND user_id = #{userId}</if>
<if test="roleId != null">AND role_id = #{roleId}</if>
ORDER BY id DESC
LIMIT #{start}, #{pageSize}
</select>
<select id="selectTotal" resultType="java.lang.Integer">