Merge branch 'develop' of gitee.com:youlaiorg/youlai-boot

This commit is contained in:
ray
2024-07-21 22:13:13 +08:00
53 changed files with 989 additions and 1188 deletions

View File

@@ -0,0 +1,9 @@
### 代码生成器配置
generator:
## 模板配置
templateConfigs:
Controller:
## 模板路径
templatePath: templates/generator/controller.java.vm
## 包名
packageName: controller

View File

@@ -2,4 +2,6 @@ spring:
application:
name: youlai-boot
profiles:
active: dev
active: dev
include:
- generator

View File

@@ -0,0 +1,43 @@
<?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.youlai.system.mapper.DatabaseMapper">
<!-- 查询数据库表分页 -->
<select id="getTablePage" resultType="com.youlai.system.model.vo.TablePageVO">
SELECT
TABLE_NAME ,
TABLE_COMMENT ,
TABLE_COLLATION,
ENGINE,
CREATE_TIME
FROM
information_schema.tables
WHERE
TABLE_SCHEMA = (SELECT DATABASE())
AND table_type = 'BASE TABLE'
<if test="queryParams.keywords != null and queryParams.keywords.trim() neq ''">
AND TABLE_NAME LIKE CONCAT('%',#{queryParams.keywords},'%')
</if>
ORDER BY
CREATE_TIME DESC
</select>
<select id="getTableColumns" resultType="com.youlai.system.model.vo.TableColumnVO">
SELECT
COLUMN_NAME,
DATA_TYPE,
COLUMN_COMMENT,
CASE COLUMN_KEY WHEN 'PRI' THEN 1 ELSE 0 END AS isPrimaryKey,
IS_NULLABLE,
CHARACTER_MAXIMUM_LENGTH,
CHARACTER_SET_NAME,
COLLATION_NAME
FROM
information_schema.columns
WHERE
TABLE_SCHEMA = (SELECT DATABASE())
AND TABLE_NAME = #{tableName}
</select>
</mapper>

View File

@@ -0,0 +1,72 @@
package ${package}.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ${package}.model.form.${entityName}Form;
import ${package}.model.query.${entityName}PageQuery;
import ${package}.model.vo.${entityName}PageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.common.result.PageResult;
import com.youlai.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
/**
* $!{tableComment} 前端控制器
*
* @author ${author}
* @since ${date}
*/
@Tag(name = "${tableComment}接口")
@RestController
@RequestMapping("/api/v1/${lowerFirstEntityName}s")
@RequiredArgsConstructor
public class ${entityName}Controller {
private final ${entityName}Serivie ${lowerFirstEntityName}Service;
@Operation(summary = "$!{tableComment}分页列表")
@GetMapping("/page")
public PageResult<${entityName}PageVO> get${entityName}Page(${entityName}PageQuery queryParams ) {
IPage<${entityName}PageVO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
return PageResult.success(result);
}
@Operation(summary = "新增$!{tableComment}")
@PostMapping
public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
return Result.judge(result);
}
@Operation(summary = "$!{tableComment}表单数据")
@GetMapping("/{id}/form")
public Result<${entityName}Form> get${entityName}Form(
@Parameter(description = "$!{tableComment}ID") @PathVariable Long id
) {
${entityName}Form formData = ${lowerFirstEntityName}Service.get${entityName}FormData(id);
return Result.success(formData);
}
@Operation(summary = "修改$!{tableComment}")
@PutMapping(value = "/{id}")
public Result update${entityName}(@Parameter(description = "$!{tableComment}ID") @PathVariable Long id,
@RequestBody @Validated ${entityName}Form formData) {
boolean result = ${lowerFirstEntityName}Service.update${entityName}(id, formData);
return Result.judge(result);
}
@Operation(summary = "删除$!{tableComment}")
@DeleteMapping("/{ids}")
public Result delete${entityName}s(
@Parameter(description = "$!{tableComment}ID多个以英文逗号(,)分割") @PathVariable String ids
) {
boolean result = ${lowerFirstEntityName}Service.delete${entityName}s(ids);
return Result.judge(result);
}
}

View File

@@ -0,0 +1,20 @@
package ${package}.converter;
import org.mapstruct.Mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package}.model.entity.${entityName};
import ${package}.model.form.${entityName}Form;
/**
* $!{tableComment}转换器
*
* @author ${author}
* @since ${date}
*/
@Mapper(componentModel = "spring")
public interface ${entityName}Converter{
${entityName}Form toForm(${entityName} entity);
${entityName} toEntity(${entityName}Form entity);
}

View File

@@ -0,0 +1,35 @@
package ${package}.model.entity;
import lombok.Getter;
import lombok.Setter;
#if(${hasLocalDateTime})
import java.time.LocalDateTime;
#end
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import com.baomidou.mybatisplus.annotation.TableName;
import com.youlai.system.common.base.BaseEntity;
/**
* $!{tableComment}实体对象
*
* @author ${author}
* @since ${date}
*/
@Getter
@Setter
@TableName("${tableName}")
public class ${entityName} extends BaseEntity {
private static final long serialVersionUID = 1L;
#foreach($field in ${table.fields})
#if("$!field.comment" != "")
/**
* ${field.comment}
*/
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -0,0 +1,37 @@
package ${package}.model.form;
import java.io.Serial;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
#if(${hasLocalDateTime})
import java.time.LocalDateTime;
#end
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
/**
* $!{tableComment} 表单对象
*
* @author ${author}
* @since ${date}
*/
@Getter
@Setter
@Schema(description = "$!{tableComment}表单对象")
public class ${entityName}Form implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -0,0 +1,27 @@
package ${package}.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import ${package}.model.entity.${entityName};
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package}.model.query.${entityName}Query;
import org.apache.ibatis.annotations.Mapper;
/**
* $!{tableComment} 数据库访问层
*
* @author ${author}
* @since ${date}
*/
@Mapper
public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
/**
* 获取$!{tableComment}分页数据
*
* @param page 分页对象
* @param queryParams 查询参数
* @return
*/
Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams);
}

View File

@@ -0,0 +1,29 @@
<?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="${package}.mapper.${entityName}Mapper">
<!-- 获取${tableComment}分页列表 -->
<select id="listPaged${entityName}s" resultType="${package}.model.entity.${entityName}">
SELECT
*
FROM
${tableName}
<where>
is_deleted = 0
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
AND (
name LIKE CONCAT('%',#{queryParams.keywords},'%')
)
</if>
<if test="queryParams.startTime != null">
AND create_time &gt;= #{queryParams.startTime}
</if>
<if test="queryParams.endTime != null">
AND create_time &lt;= #{queryParams.endTime}
</if>
</where>
ORDER BY
create_time DESC
</select>
</mapper>

View File

@@ -0,0 +1,34 @@
package ${package}.model.query;
import com.youlai.common.base.BasePageQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
#if(${hasLocalDateTime})
import java.time.LocalDateTime;
#end
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
/**
* $!{tableComment}分页查询对象
*
* @author ${author}
* @since ${date}
*/
@Schema(description ="$!{tableComment}分页查询对象")
@Getter
@Setter
public class ${entityName}Query extends BasePageQuery {
private static final long serialVersionUID = 1L;
#foreach($field in ${fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}

View File

@@ -0,0 +1,61 @@
package ${package}.Service;
import ${package}.model.entity.${entityName};
import ${package}.model.form.${entityName}Form;
import ${package}.model.query.${entityName}PageQuery;
import ${package}.model.vo.${entityName}PageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* $!{tableComment} 服务类
*
* @author ${author}
* @since ${date}
*/
public interface ${entityName}Service extends IService<${entityName}> {
/**
*$!{tableComment}分页列表
*
* @return
*/
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
/**
* 获取$!{tableComment}表单数据
*
* @param id $!{tableComment}ID
* @return
*/
${entityName}Form get${entityName}FormData(Long id);
/**
* 新增$!{tableComment}
*
* @param formData $!{tableComment}表单对象
* @return
*/
boolean save${entityName}(${entityName}Form formData);
/**
* 修改$!{tableComment}
*
* @param id $!{tableComment}ID
* @param formData $!{tableComment}表单对象
* @return
*/
boolean update${entityName}(Long id, ${entityName}Form formData);
/**
* 删除$!{tableComment}
*
* @param ids $!{tableComment}ID多个以英文逗号(,)分割
* @return
*/
boolean delete${entityName}s(String ids);
}

View File

@@ -0,0 +1,103 @@
package ${package}.service.impl;
import ${package}.model.entity.${entityName};
import ${package}.mapper.${entityName}Mapper;
import ${package}.service.${entityName}Service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ${package}.model.form.${entityName}Form;
import ${package}.model.query.${entityName}Query;
import ${package}.model.vo.${entityName}PageVO;
import ${package}.converter.${entityName}Converter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
/**
* $!{tableComment}服务实现类
*
* @author ${author}
* @since ${date}
*/
@Service
@RequiredArgsConstructor
public class ${table.serviceImplName} extends ServiceImpl<${entityName}Mapper, ${entityName}> implements ${entityName}Service {
private final ${entityName}Converter ${lowerFirstEntityName}Converter;
/**
* 获取$!{tableComment}分页列表
*
* @param queryParams 查询参数
* @return {@link IPage<${entityName}PageVO>} $!{tableComment}分页列表
*/
@Override
public IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams) {
Page<${entityName}VO> pageVO = this.baseMapper.get${entityName}Page(
new Page<>(queryParams.getPageNum(), queryParams.getPageSize()),
queryParams
);
returnv pageVO;
}
/**
* 获取$!{tableComment}表单数据
*
* @param id $!{tableComment}ID
* @return
*/
@Override
public ${entityName}Form get${entityName}FormData(Long id) {
${entityName} entity = this.getById(id);
return ${lowerFirstEntityName}Converter.toForm(entity);
}
/**
* 新增$!{tableComment}
*
* @param formData $!{tableComment}表单对象
* @return
*/
@Override
public boolean save${entityName}(${entityName}Form formData) {
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
return this.save(entity);
}
/**
* 更新$!{tableComment}
*
* @param id $!{tableComment}ID
* @param formData $!{tableComment}表单对象
* @return
*/
@Override
public boolean update${entityName}(Long id,${entityName}Form formData) {
${entityName} entity = ${lowerFirstEntityName}Converter.toEntity(formData);
return this.updateById(entity);
}
/**
* 删除$!{tableComment}
*
* @param ids $!{tableComment}ID多个以英文逗号(,)分割
* @return true|false
*/
@Override
public boolean delete${entityName}s(String ids) {
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{tableComment}数据为空");
// 逻辑删除
List<Long> idList = Arrays.stream(ids.split(","))
.map(Long::parseLong)
.toList();
return this.removeByIds(idList);
}
}

View File

@@ -0,0 +1,37 @@
package ${package}.model.vo;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
#if(${hasLocalDateTime})
import java.time.LocalDateTime;
#end
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
/**
* $!{tableComment} 图对象
*
* @author ${author}
* @since ${date}
*/
@Getter
@Setter
@Schema( description = "$!{tableComment}视图对象")
public class ${entityName}VO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
#foreach($field in ${fields})
#if("$!field.comment" != "")
@Schema(description = "${field.comment}")
#end
private ${field.propertyType} ${field.propertyName};
#end
}