From ee0286f85d1b56419c4d09d89e7a332c2f403ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 5 Aug 2025 01:19:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=A0=81=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthorizeCodeController.java | 132 ++++++++++++++++++ .../common/system/entity/AuthorizeCode.java | 55 ++++++++ .../system/mapper/AuthorizeCodeMapper.java | 37 +++++ .../system/mapper/xml/AuthorizeCodeMapper.xml | 47 +++++++ .../system/param/AuthorizeCodeParam.java | 44 ++++++ .../system/service/AuthorizeCodeService.java | 42 ++++++ .../impl/AuthorizeCodeServiceImpl.java | 47 +++++++ .../com/gxwebsoft/generator/SysGenerator.java | 3 +- 8 files changed, 406 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gxwebsoft/common/system/controller/AuthorizeCodeController.java create mode 100644 src/main/java/com/gxwebsoft/common/system/entity/AuthorizeCode.java create mode 100644 src/main/java/com/gxwebsoft/common/system/mapper/AuthorizeCodeMapper.java create mode 100644 src/main/java/com/gxwebsoft/common/system/mapper/xml/AuthorizeCodeMapper.xml create mode 100644 src/main/java/com/gxwebsoft/common/system/param/AuthorizeCodeParam.java create mode 100644 src/main/java/com/gxwebsoft/common/system/service/AuthorizeCodeService.java create mode 100644 src/main/java/com/gxwebsoft/common/system/service/impl/AuthorizeCodeServiceImpl.java diff --git a/src/main/java/com/gxwebsoft/common/system/controller/AuthorizeCodeController.java b/src/main/java/com/gxwebsoft/common/system/controller/AuthorizeCodeController.java new file mode 100644 index 0000000..f4ad432 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/controller/AuthorizeCodeController.java @@ -0,0 +1,132 @@ +package com.gxwebsoft.common.system.controller; + +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.common.system.service.AuthorizeCodeService; +import com.gxwebsoft.common.system.entity.AuthorizeCode; +import com.gxwebsoft.common.system.param.AuthorizeCodeParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 授权码控制器 + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +@Api(tags = "授权码管理") +@RestController +@RequestMapping("/api/common.system/authorize-code") +public class AuthorizeCodeController extends BaseController { + @Resource + private AuthorizeCodeService authorizeCodeService; + + @PreAuthorize("hasAuthority('sys:authorizeCode:list')") + @OperationLog + @ApiOperation("分页查询授权码") + @GetMapping("/page") + public ApiResult> page(AuthorizeCodeParam param) { + // 使用关联查询 + return success(authorizeCodeService.pageRel(param)); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:list')") + @OperationLog + @ApiOperation("查询全部授权码") + @GetMapping() + public ApiResult> list(AuthorizeCodeParam param) { + // 使用关联查询 + return success(authorizeCodeService.listRel(param)); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:list')") + @OperationLog + @ApiOperation("根据id查询授权码") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Integer id) { + // 使用关联查询 + return success(authorizeCodeService.getByIdRel(id)); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:save')") + @OperationLog + @ApiOperation("添加授权码") + @PostMapping() + public ApiResult save(@RequestBody AuthorizeCode authorizeCode) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser != null) { + authorizeCode.setUserId(loginUser.getUserId()); + } + if (authorizeCodeService.save(authorizeCode)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:update')") + @OperationLog + @ApiOperation("修改授权码") + @PutMapping() + public ApiResult update(@RequestBody AuthorizeCode authorizeCode) { + if (authorizeCodeService.updateById(authorizeCode)) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:remove')") + @OperationLog + @ApiOperation("删除授权码") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (authorizeCodeService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:save')") + @OperationLog + @ApiOperation("批量添加授权码") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (authorizeCodeService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:update')") + @OperationLog + @ApiOperation("批量修改授权码") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(authorizeCodeService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @PreAuthorize("hasAuthority('sys:authorizeCode:remove')") + @OperationLog + @ApiOperation("批量删除授权码") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (authorizeCodeService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/common/system/entity/AuthorizeCode.java b/src/main/java/com/gxwebsoft/common/system/entity/AuthorizeCode.java new file mode 100644 index 0000000..7a3f2f0 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/entity/AuthorizeCode.java @@ -0,0 +1,55 @@ +package com.gxwebsoft.common.system.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.TableLogic; +import java.io.Serializable; +import java.util.Date; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 授权码 + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "AuthorizeCode对象", description = "授权码") +@TableName("sys_authorize_code") +public class AuthorizeCode implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "授权码") + private String code; + + @ApiModelProperty(value = "用户ID") + private Integer userId; + + @ApiModelProperty(value = "排序号") + private Integer sortNumber; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @TableLogic + private Integer deleted; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "创建时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/AuthorizeCodeMapper.java b/src/main/java/com/gxwebsoft/common/system/mapper/AuthorizeCodeMapper.java new file mode 100644 index 0000000..8bd7a34 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/AuthorizeCodeMapper.java @@ -0,0 +1,37 @@ +package com.gxwebsoft.common.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.gxwebsoft.common.system.entity.AuthorizeCode; +import com.gxwebsoft.common.system.param.AuthorizeCodeParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 授权码Mapper + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +public interface AuthorizeCodeMapper extends BaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") AuthorizeCodeParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") AuthorizeCodeParam param); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/AuthorizeCodeMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/AuthorizeCodeMapper.xml new file mode 100644 index 0000000..9fec730 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/AuthorizeCodeMapper.xml @@ -0,0 +1,47 @@ + + + + + + + SELECT a.* + FROM sys_authorize_code a + + + AND a.id = #{param.id} + + + AND a.code LIKE CONCAT('%', #{param.code}, '%') + + + AND a.user_id = #{param.userId} + + + AND a.sort_number = #{param.sortNumber} + + + AND a.deleted = #{param.deleted} + + + AND a.deleted = 0 + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/common/system/param/AuthorizeCodeParam.java b/src/main/java/com/gxwebsoft/common/system/param/AuthorizeCodeParam.java new file mode 100644 index 0000000..2b55d64 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/param/AuthorizeCodeParam.java @@ -0,0 +1,44 @@ +package com.gxwebsoft.common.system.param; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 授权码查询参数 + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "AuthorizeCodeParam对象", description = "授权码查询参数") +public class AuthorizeCodeParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @QueryField(type = QueryType.EQ) + private Integer id; + + @ApiModelProperty(value = "授权码") + private String code; + + @ApiModelProperty(value = "用户ID") + @QueryField(type = QueryType.EQ) + private Integer userId; + + @ApiModelProperty(value = "排序号") + @QueryField(type = QueryType.EQ) + private Integer sortNumber; + + @ApiModelProperty(value = "是否删除, 0否, 1是") + @QueryField(type = QueryType.EQ) + private Integer deleted; + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/AuthorizeCodeService.java b/src/main/java/com/gxwebsoft/common/system/service/AuthorizeCodeService.java new file mode 100644 index 0000000..17d3005 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/AuthorizeCodeService.java @@ -0,0 +1,42 @@ +package com.gxwebsoft.common.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.system.entity.AuthorizeCode; +import com.gxwebsoft.common.system.param.AuthorizeCodeParam; + +import java.util.List; + +/** + * 授权码Service + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +public interface AuthorizeCodeService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(AuthorizeCodeParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(AuthorizeCodeParam param); + + /** + * 根据id查询 + * + * @param id id + * @return AuthorizeCode + */ + AuthorizeCode getByIdRel(Integer id); + +} diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/AuthorizeCodeServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/AuthorizeCodeServiceImpl.java new file mode 100644 index 0000000..21d7091 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/AuthorizeCodeServiceImpl.java @@ -0,0 +1,47 @@ +package com.gxwebsoft.common.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gxwebsoft.common.system.mapper.AuthorizeCodeMapper; +import com.gxwebsoft.common.system.service.AuthorizeCodeService; +import com.gxwebsoft.common.system.entity.AuthorizeCode; +import com.gxwebsoft.common.system.param.AuthorizeCodeParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 授权码Service实现 + * + * @author 科技小王子 + * @since 2025-08-05 01:17:27 + */ +@Service +public class AuthorizeCodeServiceImpl extends ServiceImpl implements AuthorizeCodeService { + + @Override + public PageResult pageRel(AuthorizeCodeParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(AuthorizeCodeParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public AuthorizeCode getByIdRel(Integer id) { + AuthorizeCodeParam param = new AuthorizeCodeParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + +} diff --git a/src/test/java/com/gxwebsoft/generator/SysGenerator.java b/src/test/java/com/gxwebsoft/generator/SysGenerator.java index 4b66085..f1662e7 100644 --- a/src/test/java/com/gxwebsoft/generator/SysGenerator.java +++ b/src/test/java/com/gxwebsoft/generator/SysGenerator.java @@ -52,7 +52,8 @@ public class SysGenerator { // "sys_domain", // "sys_company", // "sys_user_verify" -// "sys_user_role" +// "sys_user_role", +// "sys_authorize_code" }; // 需要去除的表前缀 private static final String[] TABLE_PREFIX = new String[]{