feat(新增): 部门表CURD和部分修改

This commit is contained in:
Bunny 2024-10-04 10:43:44 +08:00
parent a3e6cd9e15
commit f3b7846c5f
19 changed files with 640 additions and 21 deletions

View File

@ -10,17 +10,17 @@ import java.util.Collections;
public class AdminCodeGenerator {
// 数据连接
public static final String sqlHost = "jdbc:mysql://106.15.251.123:3305/bunny_docs?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
public static final String sqlHost = "jdbc:mysql://192.168.3.98:3304/auth_admin?serverTimezone=GMT%2B8&useSSL=false&characterEncoding=utf-8&allowPublicKeyRetrieval=true";
// 作者名称
public static final String author = "Bunny";
// 公共路径
public static final String outputDir = "D:\\MyFolder\\Bunny\\BunnyBBS\\BunnyBBS-server-admin\\service";
// public static final String outputDir = "D:\\Project\\web\\PC\\BunnyNote\\BunnyBBS-server-admin\\service";
// public static final String outputDir = "D:\\MyFolder\\Bunny\\BunnyBBS\\BunnyBBS-server-admin\\service";
public static final String outputDir = "D:\\Project\\web\\PC\\auth\\auth-server-java\\service";
// 实体类名称
public static final String entity = "Bunny";
public static void main(String[] args) {
Generation("system_menu_icon");
Generation("sys_dept", "sys_user_dept");
}
/**
@ -41,17 +41,17 @@ public class AdminCodeGenerator {
})
.packageConfig(builder -> builder.entity(entity)// 实体类包名
// 父包名如果为空将下面子包名必须写全部 否则就只需写子包名
.parent("cn.bunny.service.admin")
.controller("controller.main.system")// 控制层包名
.mapper("mapper.main.system")// mapper层包名
.service("service.main.system")// service层包名
.serviceImpl("service.system.impl")// service实现类包名
.parent("cn.bunny.services")
.controller("controller")// 控制层包名
.mapper("mapper")// mapper层包名
.service("service")// service层包名
.serviceImpl("service·impl")// service实现类包名
// 自定义mapper.xml文件输出目录
.pathInfo(Collections.singletonMap(OutputFile.xml, outputDir + "/src/main/resources/mapper/main/system")))
.pathInfo(Collections.singletonMap(OutputFile.xml, outputDir + "/src/main/resources/mapper")))
.strategyConfig(builder -> {
// 设置要生成的表名
builder.addInclude(tableName)
//.addTablePrefix("sys_")// 设置表前缀过滤
.addTablePrefix("sys_")
.entityBuilder()
.enableLombok()
.enableChainModel()

View File

@ -3,11 +3,11 @@ package cn.bunny.common.generator.generator;
import cn.bunny.common.generator.entity.BaseField;
import cn.bunny.common.generator.entity.BaseResultMap;
import cn.bunny.common.generator.utils.GeneratorCodeUtils;
import cn.bunny.dao.dto.system.user.AdminUserAddDto;
import cn.bunny.dao.dto.system.user.AdminUserDto;
import cn.bunny.dao.dto.system.user.AdminUserUpdateDto;
import cn.bunny.dao.entity.system.AdminUser;
import cn.bunny.dao.vo.system.user.AdminUserVo;
import cn.bunny.dao.dto.system.dept.DeptAddDto;
import cn.bunny.dao.dto.system.dept.DeptDto;
import cn.bunny.dao.dto.system.dept.DeptUpdateDto;
import cn.bunny.dao.entity.system.Dept;
import cn.bunny.dao.vo.system.dept.DeptVo;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.base.CaseFormat;
import io.swagger.v3.oas.annotations.media.Schema;
@ -51,11 +51,11 @@ public class WebGeneratorCode {
public static String resourceMapperPath = "D:\\Project\\web\\PC\\auth\\auth-server-java\\service\\src\\main\\resources\\mapper\\";
public static void main(String[] args) throws Exception {
Class<?> originalClass = AdminUser.class;
Class<?> dtoClass = AdminUserDto.class;
Class<?> addDtoClass = AdminUserAddDto.class;
Class<?> updateDtoClass = AdminUserUpdateDto.class;
Class<?> voClass = AdminUserVo.class;
Class<?> originalClass = Dept.class;
Class<?> dtoClass = DeptDto.class;
Class<?> addDtoClass = DeptAddDto.class;
Class<?> updateDtoClass = DeptUpdateDto.class;
Class<?> voClass = DeptVo.class;
// 设置velocity资源加载器
Properties prop = new Properties();

View File

@ -0,0 +1,35 @@
package cn.bunny.dao.dto.system.dept;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "DeptAddDto对象", title = "部门", description = "部门管理")
public class DeptAddDto {
@Schema(name = "parentId", title = "父级id")
private String parentId;
@Schema(name = "managerId", title = "管理者id")
@NotBlank(message = "管理者id不能为空")
private String managerId;
@Schema(name = "deptName", title = "部门名称")
@NotBlank(message = "部门名称不能为空")
private String deptName;
@Schema(name = "summary", title = "部门简介")
private String summary;
@Schema(name = "remarks", title = "备注信息")
private String remarks;
}

View File

@ -0,0 +1,32 @@
package cn.bunny.dao.dto.system.dept;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "DeptDto对象", title = "部门", description = "部门管理")
public class DeptDto {
@Schema(name = "parentId", title = "父级id")
private String parentId;
@Schema(name = "managerId", title = "管理者id")
private String managerId;
@Schema(name = "deptName", title = "部门名称")
private String deptName;
@Schema(name = "summary", title = "部门简介")
private String summary;
@Schema(name = "remarks", title = "备注信息")
private String remarks;
}

View File

@ -0,0 +1,40 @@
package cn.bunny.dao.dto.system.dept;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "DeptUpdateDto对象", title = "部门", description = "部门管理")
public class DeptUpdateDto {
@Schema(name = "id", title = "主键")
@NotNull(message = "id不能为空")
private Long id;
@Schema(name = "parentId", title = "父级id")
private String parentId;
@Schema(name = "managerId", title = "管理者id")
@NotBlank(message = "管理者id不能为空")
private String managerId;
@Schema(name = "deptName", title = "部门名称")
@NotBlank(message = "部门名称不能为空")
private String deptName;
@Schema(name = "summary", title = "部门简介")
private String summary;
@Schema(name = "remarks", title = "备注信息")
private String remarks;
}

View File

@ -21,6 +21,7 @@ import lombok.experimental.Accessors;
@TableName("sys_user")
@Schema(name = "AdminUser对象", title = "用户信息", description = "用户信息")
public class AdminUser extends BaseEntity {
@Schema(name = "username", title = "用户名")
private String username;
@ -53,5 +54,6 @@ public class AdminUser extends BaseEntity {
@Schema(name = "status", title = "状态", description = "1:禁用 0:正常")
private Boolean status;
}

View File

@ -0,0 +1,41 @@
package cn.bunny.dao.entity.system;
import cn.bunny.dao.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* <p>
* 部门表
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_dept")
@Schema(name = "Dept对象", title = "部门", description = "部门管理")
public class Dept extends BaseEntity {
@Schema(name = "parentId", title = "父级id")
private String parentId;
@Schema(name = "managerId", title = "管理者id")
private String managerId;
@Schema(name = "deptName", title = "部门名称")
private String deptName;
@Schema(name = "summary", title = "部门简介")
private String summary;
@Schema(name = "remarks", title = "备注信息")
private String remarks;
}

View File

@ -0,0 +1,31 @@
package cn.bunny.dao.entity.system;
import cn.bunny.dao.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
/**
* <p>
* 部门用户关系表
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_user_dept")
@Schema(name = "UserDept对象", title = "部门用户关系表", description = "部门用户关系管理")
public class UserDept extends BaseEntity {
@Schema(name = "userId", title = "用户id")
private String userId;
@Schema(name = "deptId", title = "部门id")
private String deptId;
}

View File

@ -0,0 +1,30 @@
package cn.bunny.dao.vo.system.dept;
import cn.bunny.dao.vo.BaseVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Schema(name = "DeptVo对象", title = "部门", description = "部门管理")
public class DeptVo extends BaseVo {
@Schema(name = "parentId", title = "父级id")
private String parentId;
@Schema(name = "managerId", title = "管理者id")
private String managerId;
@Schema(name = "deptName", title = "部门名称")
private String deptName;
@Schema(name = "summary", title = "部门简介")
private String summary;
@Schema(name = "remarks", title = "备注信息")
private String remarks;
}

View File

@ -0,0 +1,72 @@
package cn.bunny.services.controller;
import cn.bunny.dao.dto.system.dept.DeptAddDto;
import cn.bunny.dao.dto.system.dept.DeptDto;
import cn.bunny.dao.dto.system.dept.DeptUpdateDto;
import cn.bunny.dao.entity.system.Dept;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.Result;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.system.dept.DeptVo;
import cn.bunny.services.service.DeptService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import java.util.List;
/**
* <p>
* 部门表 前端控制器
* </p>
*
* @author Bunny
* @since 2024-10-04 10:39:08
*/
@Tag(name = "部门", description = "部门相关接口")
@RestController
@RequestMapping("admin/dept")
public class DeptController {
@Autowired
private DeptService deptService;
@Operation(summary = "分页查询部门", description = "分页查询部门")
@GetMapping("getDeptList/{page}/{limit}")
public Mono<Result<PageResult<DeptVo>>> getDeptList(
@Parameter(name = "page", description = "当前页", required = true)
@PathVariable("page") Integer page,
@Parameter(name = "limit", description = "每页记录数", required = true)
@PathVariable("limit") Integer limit,
DeptDto dto) {
Page<Dept> pageParams = new Page<>(page, limit);
PageResult<DeptVo> pageResult = deptService.getDeptList(pageParams, dto);
return Mono.just(Result.success(pageResult));
}
@Operation(summary = "添加部门", description = "添加部门")
@PostMapping("addDept")
public Mono<Result<String>> addDept(@Valid @RequestBody DeptAddDto dto) {
deptService.addDept(dto);
return Mono.just(Result.success(ResultCodeEnum.ADD_SUCCESS));
}
@Operation(summary = "更新部门", description = "更新部门")
@PutMapping("updateDept")
public Mono<Result<String>> updateDept(@Valid @RequestBody DeptUpdateDto dto) {
deptService.updateDept(dto);
return Mono.just(Result.success(ResultCodeEnum.UPDATE_SUCCESS));
}
@Operation(summary = "删除部门", description = "删除部门")
@DeleteMapping("deleteDept")
public Mono<Result<String>> deleteDept(@RequestBody List<Long> ids) {
deptService.deleteDept(ids);
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
}
}

View File

@ -0,0 +1,18 @@
package cn.bunny.services.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 部门用户关系表 前端控制器
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
@RestController
@RequestMapping("admin/userDept")
public class UserDeptController {
}

View File

@ -0,0 +1,39 @@
package cn.bunny.services.mapper;
import cn.bunny.dao.dto.system.dept.DeptDto;
import cn.bunny.dao.entity.system.Dept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* 部门 Mapper 接口
* </p>
*
* @author Bunny
* @since 2024-10-04 10:39:08
*/
@Mapper
public interface DeptMapper extends BaseMapper<Dept> {
/**
* * 分页查询部门内容
*
* @param pageParams 部门分页参数
* @param dto 部门查询表单
* @return 部门分页结果
*/
IPage<Dept> selectListByPage(@Param("page") Page<Dept> pageParams, @Param("dto") DeptDto dto);
/**
* 物理删除部门
*
* @param ids 删除 id 列表
*/
void deleteBatchIdsWithPhysics(List<Long> ids);
}

View File

@ -0,0 +1,18 @@
package cn.bunny.services.mapper;
import cn.bunny.dao.entity.system.UserDept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* 部门用户关系表 Mapper 接口
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
@Mapper
public interface UserDeptMapper extends BaseMapper<UserDept> {
}

View File

@ -0,0 +1,52 @@
package cn.bunny.services.service;
import cn.bunny.dao.dto.system.dept.DeptAddDto;
import cn.bunny.dao.dto.system.dept.DeptDto;
import cn.bunny.dao.dto.system.dept.DeptUpdateDto;
import cn.bunny.dao.entity.system.Dept;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.system.dept.DeptVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.Valid;
import java.util.List;
/**
* <p>
* 部门 服务类
* </p>
*
* @author Bunny
* @since 2024-10-04 10:39:08
*/
public interface DeptService extends IService<Dept> {
/**
* * 获取部门列表
*
* @return 部门返回列表
*/
PageResult<DeptVo> getDeptList(Page<Dept> pageParams, DeptDto dto);
/**
* * 添加部门
*
* @param dto 添加表单
*/
void addDept(@Valid DeptAddDto dto);
/**
* * 更新部门
*
* @param dto 更新表单
*/
void updateDept(@Valid DeptUpdateDto dto);
/**
* * 删除|批量删除部门类型
*
* @param ids 删除id列表
*/
void deleteDept(List<Long> ids);
}

View File

@ -0,0 +1,16 @@
package cn.bunny.services.service;
import cn.bunny.dao.entity.system.UserDept;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 部门用户关系表 服务类
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
public interface UserDeptService extends IService<UserDept> {
}

View File

@ -0,0 +1,92 @@
package cn.bunny.services.service.impl;
import cn.bunny.dao.dto.system.dept.DeptAddDto;
import cn.bunny.dao.dto.system.dept.DeptDto;
import cn.bunny.dao.dto.system.dept.DeptUpdateDto;
import cn.bunny.dao.entity.system.Dept;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.system.dept.DeptVo;
import cn.bunny.services.mapper.DeptMapper;
import cn.bunny.services.service.DeptService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 部门 服务实现类
* </p>
*
* @author Bunny
* @since 2024-10-04 10:39:08
*/
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
/**
* * 部门 服务实现类
*
* @param pageParams 部门分页查询page对象
* @param dto 部门分页查询对象
* @return 查询分页部门返回对象
*/
@Override
public PageResult<DeptVo> getDeptList(Page<Dept> pageParams, DeptDto dto) {
// 分页查询菜单图标
IPage<Dept> page = baseMapper.selectListByPage(pageParams, dto);
List<DeptVo> voList = page.getRecords().stream().map(Dept -> {
DeptVo DeptVo = new DeptVo();
BeanUtils.copyProperties(Dept, DeptVo);
return DeptVo;
}).toList();
return PageResult.<DeptVo>builder()
.list(voList)
.pageNo(page.getCurrent())
.pageSize(page.getSize())
.total(page.getTotal())
.build();
}
/**
* 添加部门
*
* @param dto 部门添加
*/
@Override
public void addDept(@Valid DeptAddDto dto) {
// 保存数据
Dept dept = new Dept();
BeanUtils.copyProperties(dto, dept);
save(dept);
}
/**
* 更新部门
*
* @param dto 部门更新
*/
@Override
public void updateDept(@Valid DeptUpdateDto dto) {
// 更新内容
Dept dept = new Dept();
BeanUtils.copyProperties(dto, dept);
updateById(dept);
}
/**
* 删除|批量删除部门
*
* @param ids 删除id列表
*/
@Override
public void deleteDept(List<Long> ids) {
baseMapper.deleteBatchIdsWithPhysics(ids);
}
}

View File

@ -0,0 +1,20 @@
package cn.bunny.services.service.impl;
import cn.bunny.dao.entity.system.UserDept;
import cn.bunny.services.mapper.UserDeptMapper;
import cn.bunny.services.service.UserDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 部门用户关系表 服务实现类
* </p>
*
* @author Bunny
* @since 2024-10-04
*/
@Service
public class UserDeptServiceImpl extends ServiceImpl<UserDeptMapper, UserDept> implements UserDeptService {
}

View File

@ -0,0 +1,59 @@
<?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="cn.bunny.services.mapper.DeptMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.Dept">
<id column="id" property="id"/>
<id column="create_time" property="createTime"/>
<id column="update_time" property="updateTime"/>
<id column="create_user" property="createUser"/>
<id column="update_user" property="updateUser"/>
<id column="is_deleted" property="isDeleted"/>
<id column="parent_id" property="parentId"/>
<id column="manager_id" property="managerId"/>
<id column="dept_name" property="deptName"/>
<id column="summary" property="summary"/>
<id column="remarks" property="remarks"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, create_time, update_time, create_user, update_user, is_deleted, parent_id, manager_id, dept_name, summary, remarks
</sql>
<!-- 分页查询部门内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.system.Dept">
select <include refid="Base_Column_List"/>
from sys_dept
<where>
<if test="dto.parentId != null and dto.parentId != ''">
parent_id like CONCAT('%',#{dto.parentId},'%')
</if>
<if test="dto.managerId != null and dto.managerId != ''">
manager_id like CONCAT('%',#{dto.managerId},'%')
</if>
<if test="dto.deptName != null and dto.deptName != ''">
dept_name like CONCAT('%',#{dto.deptName},'%')
</if>
<if test="dto.summary != null and dto.summary != ''">
summary like CONCAT('%',#{dto.summary},'%')
</if>
<if test="dto.remarks != null and dto.remarks != ''">
remarks like CONCAT('%',#{dto.remarks},'%')
</if>
</where>
order by update_time
</select>
<!-- 物理删除部门 -->
<delete id="deleteBatchIdsWithPhysics">
delete
from sys_dept
where id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -0,0 +1,22 @@
<?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="cn.bunny.services.mapper.UserDeptMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.UserDept">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="dept_id" property="deptId"/>
<result column="create_time" property="createTime"/>
<result column="update_time" property="updateTime"/>
<result column="create_user" property="createUser"/>
<result column="update_user" property="updateUser"/>
<result column="is_deleted" property="isDeleted"/>
</resultMap>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, user_id, dept_id, create_time, update_time, create_user, update_user, is_deleted
</sql>
</mapper>