feat(web): 新增 BaseController 基类并优化代码生成模板

- 添加 BaseController 基类,包含常用方法如获取登录用户、租户ID等
- 实现统一的 ApiResult 返回结果处理方法
- 添加请求参数空字符串转 null 的处理逻辑- 新增方法参数类型转换异常的统一处理机制
- 更新代码生成器模板,将 ID 类型从 Integer 改为 Long
- 修改代码生成器配置,使用新的 BaseController 替代 SimpleBaseController
- 优化 HTTP 请求头获取逻辑,支持大小写兼容的 AppId 获取方式
This commit is contained in:
2025-10-16 20:29:43 +08:00
parent ed6bb2772f
commit d92b81ab55
7 changed files with 432 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
package com.gxwebsoft.clinic.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.clinic.service.ClinicAppointmentService;
import com.gxwebsoft.clinic.entity.ClinicAppointment;
import com.gxwebsoft.clinic.param.ClinicAppointmentParam;
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.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 挂号控制器
*
* @author 科技小王子
* @since 2025-10-16 20:26:59
*/
@Tag(name = "挂号管理")
@RestController
@RequestMapping("/api/clinic/clinic-appointment")
public class ClinicAppointmentController extends BaseController {
@Resource
private ClinicAppointmentService clinicAppointmentService;
@PreAuthorize("hasAuthority('clinic:clinicAppointment:list')")
@Operation(summary = "分页查询挂号")
@GetMapping("/page")
public ApiResult<PageResult<ClinicAppointment>> page(ClinicAppointmentParam param) {
// 使用关联查询
return success(clinicAppointmentService.pageRel(param));
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:list')")
@Operation(summary = "查询全部挂号")
@GetMapping()
public ApiResult<List<ClinicAppointment>> list(ClinicAppointmentParam param) {
// 使用关联查询
return success(clinicAppointmentService.listRel(param));
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:list')")
@Operation(summary = "根据id查询挂号")
@GetMapping("/{id}")
public ApiResult<ClinicAppointment> get(@PathVariable("id") Long id) {
// 使用关联查询
return success(clinicAppointmentService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:save')")
@OperationLog
@Operation(summary = "添加挂号")
@PostMapping()
public ApiResult<?> save(@RequestBody ClinicAppointment clinicAppointment) {
// 记录当前登录用户id
// User loginUser = getLoginUser();
// if (loginUser != null) {
// clinicAppointment.setUserId(loginUser.getUserId());
// }
if (clinicAppointmentService.save(clinicAppointment)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:update')")
@OperationLog
@Operation(summary = "修改挂号")
@PutMapping()
public ApiResult<?> update(@RequestBody ClinicAppointment clinicAppointment) {
if (clinicAppointmentService.updateById(clinicAppointment)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:remove')")
@OperationLog
@Operation(summary = "删除挂号")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (clinicAppointmentService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:save')")
@OperationLog
@Operation(summary = "批量添加挂号")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<ClinicAppointment> list) {
if (clinicAppointmentService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:update')")
@OperationLog
@Operation(summary = "批量修改挂号")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<ClinicAppointment> batchParam) {
if (batchParam.update(clinicAppointmentService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('clinic:clinicAppointment:remove')")
@OperationLog
@Operation(summary = "批量删除挂号")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (clinicAppointmentService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,60 @@
package com.gxwebsoft.clinic.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 挂号
*
* @author 科技小王子
* @since 2025-10-16 20:26:59
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "ClinicAppointment对象", description = "挂号")
public class ClinicAppointment implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "主键ID")
@TableId(value = "id", type = IdType.AUTO)
private Long id;
@Schema(description = "类型")
private Integer type;
@Schema(description = "就诊原因")
private String reason;
@Schema(description = "挂号时间")
private LocalDateTime evaluateTime;
@Schema(description = "医生")
private Integer doctorId;
@Schema(description = "患者")
private Integer userId;
@Schema(description = "备注")
private String comments;
@Schema(description = "排序号")
private Integer sortNumber;
@Schema(description = "是否删除")
private Integer isDelete;
@Schema(description = "租户id")
private Integer tenantId;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "修改时间")
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.clinic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.clinic.entity.ClinicAppointment;
import com.gxwebsoft.clinic.param.ClinicAppointmentParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 挂号Mapper
*
* @author 科技小王子
* @since 2025-10-16 20:26:59
*/
public interface ClinicAppointmentMapper extends BaseMapper<ClinicAppointment> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<ClinicAppointment>
*/
List<ClinicAppointment> selectPageRel(@Param("page") IPage<ClinicAppointment> page,
@Param("param") ClinicAppointmentParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<ClinicAppointment> selectListRel(@Param("param") ClinicAppointmentParam param);
}

View File

@@ -0,0 +1,60 @@
<?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.gxwebsoft.clinic.mapper.ClinicAppointmentMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM clinic_appointment a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.reason != null">
AND a.reason LIKE CONCAT('%', #{param.reason}, '%')
</if>
<if test="param.evaluateTime != null">
AND a.evaluate_time LIKE CONCAT('%', #{param.evaluateTime}, '%')
</if>
<if test="param.doctorId != null">
AND a.doctor_id = #{param.doctorId}
</if>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.comments != null">
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.isDelete != null">
AND a.is_delete = #{param.isDelete}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.clinic.entity.ClinicAppointment">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.clinic.entity.ClinicAppointment">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -0,0 +1,58 @@
package com.gxwebsoft.clinic.param;
import java.math.BigDecimal;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 挂号查询参数
*
* @author 科技小王子
* @since 2025-10-16 20:26:59
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "ClinicAppointmentParam对象", description = "挂号查询参数")
public class ClinicAppointmentParam extends BaseParam {
private static final long serialVersionUID = 1L;
@Schema(description = "主键ID")
@QueryField(type = QueryType.EQ)
private Long id;
@Schema(description = "类型")
@QueryField(type = QueryType.EQ)
private Integer type;
@Schema(description = "就诊原因")
private String reason;
@Schema(description = "挂号时间")
private String evaluateTime;
@Schema(description = "医生")
@QueryField(type = QueryType.EQ)
private Integer doctorId;
@Schema(description = "患者")
@QueryField(type = QueryType.EQ)
private Integer userId;
@Schema(description = "备注")
private String comments;
@Schema(description = "排序号")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
@Schema(description = "是否删除")
@QueryField(type = QueryType.EQ)
private Integer isDelete;
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.clinic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.clinic.entity.ClinicAppointment;
import com.gxwebsoft.clinic.param.ClinicAppointmentParam;
import java.util.List;
/**
* 挂号Service
*
* @author 科技小王子
* @since 2025-10-16 20:26:59
*/
public interface ClinicAppointmentService extends IService<ClinicAppointment> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<ClinicAppointment>
*/
PageResult<ClinicAppointment> pageRel(ClinicAppointmentParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<ClinicAppointment>
*/
List<ClinicAppointment> listRel(ClinicAppointmentParam param);
/**
* 根据id查询
*
* @param id 主键ID
* @return ClinicAppointment
*/
ClinicAppointment getByIdRel(Long id);
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.clinic.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.mapper.ClinicAppointmentMapper;
import com.gxwebsoft.clinic.service.ClinicAppointmentService;
import com.gxwebsoft.clinic.entity.ClinicAppointment;
import com.gxwebsoft.clinic.param.ClinicAppointmentParam;
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-10-16 20:26:59
*/
@Service
public class ClinicAppointmentServiceImpl extends ServiceImpl<ClinicAppointmentMapper, ClinicAppointment> implements ClinicAppointmentService {
@Override
public PageResult<ClinicAppointment> pageRel(ClinicAppointmentParam param) {
PageParam<ClinicAppointment, ClinicAppointmentParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time desc");
List<ClinicAppointment> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<ClinicAppointment> listRel(ClinicAppointmentParam param) {
List<ClinicAppointment> list = baseMapper.selectListRel(param);
// 排序
PageParam<ClinicAppointment, ClinicAppointmentParam> page = new PageParam<>();
page.setDefaultOrder("sort_number asc, create_time desc");
return page.sortRecords(list);
}
@Override
public ClinicAppointment getByIdRel(Long id) {
ClinicAppointmentParam param = new ClinicAppointmentParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}