消息队列存储数据
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "cos.client.accessKey",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for cos.client.accessKey."
|
||||
},
|
||||
{
|
||||
"name": "cos.client.secretKey",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for cos.client.secretKey."
|
||||
},
|
||||
{
|
||||
"name": "cos.client.region",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for cos.client.region."
|
||||
},
|
||||
{
|
||||
"name": "cos.client.bucket",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for cos.client.bucket."
|
||||
},
|
||||
{
|
||||
"name": "wx.open.appId",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for wx.open.appId."
|
||||
},
|
||||
{
|
||||
"name": "wx.open.appSecret",
|
||||
"type": "java.lang.String",
|
||||
"description": "Description for wx.open.appSecret."
|
||||
}
|
||||
]
|
||||
}
|
||||
46
src/main/resources/application-prod.yml
Normal file
46
src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
# 线上配置文件
|
||||
# @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
# @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
server:
|
||||
port: 8101
|
||||
spring:
|
||||
# 数据库配置
|
||||
# todo 需替换配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?rewriteBatchedStatements=true
|
||||
username: root
|
||||
password: 123asd
|
||||
# Redis 配置
|
||||
# todo 需替换配置
|
||||
redis:
|
||||
database: 1
|
||||
host: localhost
|
||||
port: 6379
|
||||
timeout: 5000
|
||||
password: 123456
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
listener:
|
||||
simple:
|
||||
acknowledge-mode: manual
|
||||
# Elasticsearch 配置
|
||||
# todo 需替换配置
|
||||
elasticsearch:
|
||||
uris: http://localhost:9200
|
||||
username: root
|
||||
password: 123456
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
# 生产环境关闭日志
|
||||
log-impl: ''
|
||||
# 接口文档配置
|
||||
knife4j:
|
||||
basic:
|
||||
enable: true
|
||||
username: root
|
||||
password: 123456
|
||||
|
||||
36
src/main/resources/application-test.yml
Normal file
36
src/main/resources/application-test.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
# 测试配置文件
|
||||
# @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
# @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
server:
|
||||
port: 8101
|
||||
spring:
|
||||
# 数据库配置
|
||||
# todo 需替换配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/ruoyi-vue-pro?rewriteBatchedStatements=true
|
||||
username: root
|
||||
password: 123asd
|
||||
# Redis 配置
|
||||
# todo 需替换配置
|
||||
redis:
|
||||
database: 1
|
||||
host: localhost
|
||||
port: 6379
|
||||
timeout: 5000
|
||||
password: 123456
|
||||
# Elasticsearch 配置
|
||||
# todo 需替换配置
|
||||
elasticsearch:
|
||||
uris: http://localhost:9200
|
||||
username: root
|
||||
password: 123456
|
||||
rabbitmq:
|
||||
host: localhost
|
||||
port: 5672
|
||||
username: guest
|
||||
password: guest
|
||||
listener:
|
||||
simple:
|
||||
acknowledge-mode: manual
|
||||
|
||||
113
src/main/resources/application.yml
Normal file
113
src/main/resources/application.yml
Normal file
@@ -0,0 +1,113 @@
|
||||
# 公共配置文件
|
||||
# @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
# @from <a href="https://yupi.icu">编程导航知识星球</a>
|
||||
spring:
|
||||
application:
|
||||
name: springboot-init
|
||||
# 默认 dev 环境
|
||||
profiles:
|
||||
active: test
|
||||
# 支持 swagger3
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher
|
||||
# session 配置
|
||||
session:
|
||||
# todo 取消注释开启分布式 session(须先配置 Redis)
|
||||
# store-type: redis
|
||||
# 30 天过期
|
||||
timeout: 2592000
|
||||
# 数据库配置
|
||||
# todo 需替换配置
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/my_db
|
||||
username: root
|
||||
password: 123asd
|
||||
jackson:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
# Redis 配置
|
||||
# todo 需替换配置,然后取消注释
|
||||
# redis:
|
||||
# database: 1
|
||||
# host: localhost
|
||||
# port: 6379
|
||||
# timeout: 5000
|
||||
# password: 123456
|
||||
# Elasticsearch 配置
|
||||
# todo 需替换配置,然后取消注释
|
||||
# elasticsearch:
|
||||
# uris: http://localhost:9200
|
||||
# username: root
|
||||
# password: 123456
|
||||
# 文件上传
|
||||
servlet:
|
||||
multipart:
|
||||
# 大小限制
|
||||
max-file-size: 10MB
|
||||
server:
|
||||
address: 0.0.0.0
|
||||
port: 8101
|
||||
servlet:
|
||||
context-path: /api
|
||||
# cookie 30 天过期
|
||||
session:
|
||||
cookie:
|
||||
max-age: 2592000
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: false
|
||||
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
default-executor-type: batch
|
||||
|
||||
|
||||
global-config:
|
||||
db-config:
|
||||
logic-delete-field: isDelete # 全局逻辑删除的实体字段名
|
||||
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
|
||||
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
|
||||
# 微信相关
|
||||
wx:
|
||||
# 微信公众平台
|
||||
# todo 需替换配置
|
||||
mp:
|
||||
token: xxx
|
||||
aesKey: xxx
|
||||
appId: xxx
|
||||
secret: xxx
|
||||
config-storage:
|
||||
http-client-type: HttpClient
|
||||
key-prefix: wx
|
||||
redis:
|
||||
host: 127.0.0.1
|
||||
port: 6379
|
||||
type: Memory
|
||||
# 微信开放平台
|
||||
# todo 需替换配置
|
||||
open:
|
||||
appId: xxx
|
||||
appSecret: xxx
|
||||
# 对象存储
|
||||
# todo 需替换配置
|
||||
cos:
|
||||
client:
|
||||
accessKey: xxx
|
||||
secretKey: xxx
|
||||
region: xxx
|
||||
bucket: xxx
|
||||
# 接口文档配置
|
||||
knife4j:
|
||||
enable: true
|
||||
openapi:
|
||||
title: "接口文档"
|
||||
version: 1.0
|
||||
group:
|
||||
default:
|
||||
api-rule: package
|
||||
api-rule-resources:
|
||||
- com.yupi.springbootinit.controller
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
apache:
|
||||
ibatis: off
|
||||
2
src/main/resources/banner.txt
Normal file
2
src/main/resources/banner.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
by 程序员鱼皮:https://github.com/liyupi
|
||||
可能是最好的编程学习圈子:https://yupi.icu
|
||||
226
src/main/resources/mapper/NewHostsMapper.xml
Normal file
226
src/main/resources/mapper/NewHostsMapper.xml
Normal file
@@ -0,0 +1,226 @@
|
||||
<?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.yupi.springbootinit.mapper.NewHostsMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.NewHosts">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table new_hosts-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="hosts_id" jdbcType="VARCHAR" property="hostsId" />
|
||||
<result column="hosts_level" jdbcType="VARCHAR" property="hostsLevel" />
|
||||
<result column="hosts_coins" jdbcType="INTEGER" property="hostsCoins" />
|
||||
<result column="Invitation_type" jdbcType="INTEGER" property="invitationType" />
|
||||
<result column="fans" jdbcType="INTEGER" property="fans" />
|
||||
<result column="fllowernum" jdbcType="INTEGER" property="fllowernum" />
|
||||
<result column="yesterday_coins" jdbcType="INTEGER" property="yesterdayCoins" />
|
||||
<result column="country" jdbcType="VARCHAR" property="country" />
|
||||
<result column="hosts_kind" jdbcType="VARCHAR" property="hostsKind" />
|
||||
<result column="tenant_id" jdbcType="BIGINT" property="tenantId" />
|
||||
<result column="creator" jdbcType="INTEGER" property="creator" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="updater" jdbcType="VARCHAR" property="updater" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, hosts_id, hosts_level, hosts_coins, Invitation_type, fans, fllowernum, yesterday_coins,
|
||||
country, hosts_kind, tenant_id, creator, create_time, updater, update_time
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
|
||||
<!--@mbg.generated-->
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from new_hosts
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||
<!--@mbg.generated-->
|
||||
delete from new_hosts
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</delete>
|
||||
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yupi.springbootinit.model.entity.NewHosts" useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into new_hosts (hosts_id, hosts_level, hosts_coins,
|
||||
Invitation_type, fans, fllowernum,
|
||||
yesterday_coins, country, hosts_kind,
|
||||
tenant_id, creator, create_time,
|
||||
updater, update_time)
|
||||
values (#{hostsId,jdbcType=VARCHAR}, #{hostsLevel,jdbcType=VARCHAR}, #{hostsCoins,jdbcType=INTEGER},
|
||||
#{invitationType,jdbcType=INTEGER}, #{fans,jdbcType=INTEGER}, #{fllowernum,jdbcType=INTEGER},
|
||||
#{yesterdayCoins,jdbcType=INTEGER}, #{country,jdbcType=VARCHAR}, #{hostsKind,jdbcType=VARCHAR},
|
||||
#{tenantId,jdbcType=BIGINT}, #{creator,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
|
||||
#{updater,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP})
|
||||
</insert>
|
||||
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yupi.springbootinit.model.entity.NewHosts" useGeneratedKeys="true">
|
||||
<!--@mbg.generated-->
|
||||
insert into new_hosts
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="hostsId != null">
|
||||
hosts_id,
|
||||
</if>
|
||||
<if test="hostsLevel != null">
|
||||
hosts_level,
|
||||
</if>
|
||||
<if test="hostsCoins != null">
|
||||
hosts_coins,
|
||||
</if>
|
||||
<if test="invitationType != null">
|
||||
Invitation_type,
|
||||
</if>
|
||||
<if test="fans != null">
|
||||
fans,
|
||||
</if>
|
||||
<if test="fllowernum != null">
|
||||
fllowernum,
|
||||
</if>
|
||||
<if test="yesterdayCoins != null">
|
||||
yesterday_coins,
|
||||
</if>
|
||||
<if test="country != null">
|
||||
country,
|
||||
</if>
|
||||
<if test="hostsKind != null">
|
||||
hosts_kind,
|
||||
</if>
|
||||
<if test="tenantId != null">
|
||||
tenant_id,
|
||||
</if>
|
||||
<if test="creator != null">
|
||||
creator,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
updater,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="hostsId != null">
|
||||
#{hostsId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsLevel != null">
|
||||
#{hostsLevel,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsCoins != null">
|
||||
#{hostsCoins,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="invitationType != null">
|
||||
#{invitationType,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fans != null">
|
||||
#{fans,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fllowernum != null">
|
||||
#{fllowernum,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="yesterdayCoins != null">
|
||||
#{yesterdayCoins,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="country != null">
|
||||
#{country,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsKind != null">
|
||||
#{hostsKind,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="tenantId != null">
|
||||
#{tenantId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="creator != null">
|
||||
#{creator,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
#{updater,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
#{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.yupi.springbootinit.model.entity.NewHosts">
|
||||
<!--@mbg.generated-->
|
||||
update new_hosts
|
||||
<set>
|
||||
<if test="hostsId != null">
|
||||
hosts_id = #{hostsId,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsLevel != null">
|
||||
hosts_level = #{hostsLevel,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsCoins != null">
|
||||
hosts_coins = #{hostsCoins,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="invitationType != null">
|
||||
Invitation_type = #{invitationType,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fans != null">
|
||||
fans = #{fans,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="fllowernum != null">
|
||||
fllowernum = #{fllowernum,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="yesterdayCoins != null">
|
||||
yesterday_coins = #{yesterdayCoins,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="country != null">
|
||||
country = #{country,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="hostsKind != null">
|
||||
hosts_kind = #{hostsKind,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="tenantId != null">
|
||||
tenant_id = #{tenantId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="creator != null">
|
||||
creator = #{creator,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updater != null">
|
||||
updater = #{updater,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.yupi.springbootinit.model.entity.NewHosts">
|
||||
<!--@mbg.generated-->
|
||||
update new_hosts
|
||||
set hosts_id = #{hostsId,jdbcType=VARCHAR},
|
||||
hosts_level = #{hostsLevel,jdbcType=VARCHAR},
|
||||
hosts_coins = #{hostsCoins,jdbcType=INTEGER},
|
||||
Invitation_type = #{invitationType,jdbcType=INTEGER},
|
||||
fans = #{fans,jdbcType=INTEGER},
|
||||
fllowernum = #{fllowernum,jdbcType=INTEGER},
|
||||
yesterday_coins = #{yesterdayCoins,jdbcType=INTEGER},
|
||||
country = #{country,jdbcType=VARCHAR},
|
||||
hosts_kind = #{hostsKind,jdbcType=VARCHAR},
|
||||
tenant_id = #{tenantId,jdbcType=BIGINT},
|
||||
creator = #{creator,jdbcType=INTEGER},
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
updater = #{updater,jdbcType=VARCHAR},
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map">
|
||||
<!--@mbg.generated-->
|
||||
insert into new_hosts
|
||||
(hosts_id, hosts_level, hosts_coins, Invitation_type, fans, fllowernum, yesterday_coins,
|
||||
country, hosts_kind, tenant_id, creator)
|
||||
values
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(#{item.hostsId,jdbcType=VARCHAR}, #{item.hostsLevel,jdbcType=VARCHAR}, #{item.hostsCoins,jdbcType=INTEGER},
|
||||
#{item.invitationType,jdbcType=INTEGER}, #{item.fans,jdbcType=INTEGER}, #{item.fllowernum,jdbcType=INTEGER},
|
||||
#{item.yesterdayCoins,jdbcType=INTEGER}, #{item.country,jdbcType=VARCHAR}, #{item.hostsKind,jdbcType=VARCHAR},
|
||||
#{item.tenantId,jdbcType=BIGINT}, #{item.creator,jdbcType=INTEGER})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
29
src/main/resources/mapper/PostFavourMapper.xml
Normal file
29
src/main/resources/mapper/PostFavourMapper.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- @author <a href="https://github.com/liyupi">程序员鱼皮</a> -->
|
||||
<!-- @from <a href="https://yupi.icu">编程导航知识星球</a> -->
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yupi.springbootinit.mapper.PostFavourMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.PostFavour">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="postId" column="postId" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,postId,userId,
|
||||
createTime,updateTime
|
||||
</sql>
|
||||
|
||||
<select id="listFavourPostByPage"
|
||||
resultType="com.yupi.springbootinit.model.entity.Post">
|
||||
select p.*
|
||||
from post p
|
||||
join (select postId from post_favour where userId = #{favourUserId}) pf
|
||||
on p.id = pf.postId ${ew.customSqlSegment}
|
||||
</select>
|
||||
</mapper>
|
||||
33
src/main/resources/mapper/PostMapper.xml
Normal file
33
src/main/resources/mapper/PostMapper.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- @author <a href="https://github.com/liyupi">程序员鱼皮</a> -->
|
||||
<!-- @from <a href="https://yupi.icu">编程导航知识星球</a> -->
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yupi.springbootinit.mapper.PostMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.Post">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="content" column="content" jdbcType="VARCHAR"/>
|
||||
<result property="tags" column="tags" jdbcType="VARCHAR"/>
|
||||
<result property="thumbNum" column="thumbNum" jdbcType="BIGINT"/>
|
||||
<result property="favourNum" column="favourNum" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="isDelete" column="isDelete" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,title,content,tags,
|
||||
thumbNum,favourNum,userId,
|
||||
createTime,updateTime,isDelete
|
||||
</sql>
|
||||
|
||||
<select id="listPostWithDelete" resultType="com.yupi.springbootinit.model.entity.Post">
|
||||
select *
|
||||
from post
|
||||
where updateTime >= #{minUpdateTime}
|
||||
</select>
|
||||
</mapper>
|
||||
21
src/main/resources/mapper/PostThumbMapper.xml
Normal file
21
src/main/resources/mapper/PostThumbMapper.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- @author <a href="https://github.com/liyupi">程序员鱼皮</a> -->
|
||||
<!-- @from <a href="https://yupi.icu">编程导航知识星球</a> -->
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yupi.springbootinit.mapper.PostThumbMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.PostThumb">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="postId" column="postId" jdbcType="BIGINT"/>
|
||||
<result property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,postId,
|
||||
userId,createTime,updateTime
|
||||
</sql>
|
||||
</mapper>
|
||||
26
src/main/resources/mapper/UserMapper.xml
Normal file
26
src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- @author <a href="https://github.com/liyupi">程序员鱼皮</a> -->
|
||||
<!-- @from <a href="https://yupi.icu">编程导航知识星球</a> -->
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yupi.springbootinit.mapper.UserMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yupi.springbootinit.model.entity.User">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="unionId" column="unionId" jdbcType="VARCHAR"/>
|
||||
<result property="mpOpenId" column="mpOpenId" jdbcType="VARCHAR"/>
|
||||
<result property="userName" column="userName" jdbcType="VARCHAR"/>
|
||||
<result property="userAvatar" column="userAvatar" jdbcType="VARCHAR"/>
|
||||
<result property="userProfile" column="userProfile" jdbcType="VARCHAR"/>
|
||||
<result property="userRole" column="userRole" jdbcType="VARCHAR"/>
|
||||
<result property="createTime" column="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="updateTime" column="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result property="isDelete" column="isDelete" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,unionId,mpOpenId,
|
||||
userName,userAvatar,userProfile,
|
||||
userRole,createTime,updateTime,isDelete
|
||||
</sql>
|
||||
</mapper>
|
||||
239
src/main/resources/templates/TemplateController.java.ftl
Normal file
239
src/main/resources/templates/TemplateController.java.ftl
Normal file
@@ -0,0 +1,239 @@
|
||||
package ${packageName}.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${packageName}.annotation.AuthCheck;
|
||||
import ${packageName}.common.BaseResponse;
|
||||
import ${packageName}.common.DeleteRequest;
|
||||
import ${packageName}.common.ErrorCode;
|
||||
import ${packageName}.common.ResultUtils;
|
||||
import ${packageName}.constant.UserConstant;
|
||||
import ${packageName}.exception.BusinessException;
|
||||
import ${packageName}.exception.ThrowUtils;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}AddRequest;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}EditRequest;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}QueryRequest;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}UpdateRequest;
|
||||
import ${packageName}.model.entity.${upperDataKey};
|
||||
import ${packageName}.model.entity.User;
|
||||
import ${packageName}.model.vo.${upperDataKey}VO;
|
||||
import ${packageName}.service.${upperDataKey}Service;
|
||||
import ${packageName}.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* ${dataName}接口
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${dataKey}")
|
||||
@Slf4j
|
||||
public class ${upperDataKey}Controller {
|
||||
|
||||
@Resource
|
||||
private ${upperDataKey}Service ${dataKey}Service;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
// region 增删改查
|
||||
|
||||
/**
|
||||
* 创建${dataName}
|
||||
*
|
||||
* @param ${dataKey}AddRequest
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public BaseResponse<Long> add${upperDataKey}(@RequestBody ${upperDataKey}AddRequest ${dataKey}AddRequest, HttpServletRequest request) {
|
||||
ThrowUtils.throwIf(${dataKey}AddRequest == null, ErrorCode.PARAMS_ERROR);
|
||||
// todo 在此处将实体类和 DTO 进行转换
|
||||
${upperDataKey} ${dataKey} = new ${upperDataKey}();
|
||||
BeanUtils.copyProperties(${dataKey}AddRequest, ${dataKey});
|
||||
// 数据校验
|
||||
${dataKey}Service.valid${upperDataKey}(${dataKey}, true);
|
||||
// todo 填充默认值
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
${dataKey}.setUserId(loginUser.getId());
|
||||
// 写入数据库
|
||||
boolean result = ${dataKey}Service.save(${dataKey});
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
// 返回新写入的数据 id
|
||||
long new${upperDataKey}Id = ${dataKey}.getId();
|
||||
return ResultUtils.success(new${upperDataKey}Id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除${dataName}
|
||||
*
|
||||
* @param deleteRequest
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public BaseResponse<Boolean> delete${upperDataKey}(@RequestBody DeleteRequest deleteRequest, HttpServletRequest request) {
|
||||
if (deleteRequest == null || deleteRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
User user = userService.getLoginUser(request);
|
||||
long id = deleteRequest.getId();
|
||||
// 判断是否存在
|
||||
${upperDataKey} old${upperDataKey} = ${dataKey}Service.getById(id);
|
||||
ThrowUtils.throwIf(old${upperDataKey} == null, ErrorCode.NOT_FOUND_ERROR);
|
||||
// 仅本人或管理员可删除
|
||||
if (!old${upperDataKey}.getUserId().equals(user.getId()) && !userService.isAdmin(request)) {
|
||||
throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
|
||||
}
|
||||
// 操作数据库
|
||||
boolean result = ${dataKey}Service.removeById(id);
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新${dataName}(仅管理员可用)
|
||||
*
|
||||
* @param ${dataKey}UpdateRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Boolean> update${upperDataKey}(@RequestBody ${upperDataKey}UpdateRequest ${dataKey}UpdateRequest) {
|
||||
if (${dataKey}UpdateRequest == null || ${dataKey}UpdateRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
// todo 在此处将实体类和 DTO 进行转换
|
||||
${upperDataKey} ${dataKey} = new ${upperDataKey}();
|
||||
BeanUtils.copyProperties(${dataKey}UpdateRequest, ${dataKey});
|
||||
// 数据校验
|
||||
${dataKey}Service.valid${upperDataKey}(${dataKey}, false);
|
||||
// 判断是否存在
|
||||
long id = ${dataKey}UpdateRequest.getId();
|
||||
${upperDataKey} old${upperDataKey} = ${dataKey}Service.getById(id);
|
||||
ThrowUtils.throwIf(old${upperDataKey} == null, ErrorCode.NOT_FOUND_ERROR);
|
||||
// 操作数据库
|
||||
boolean result = ${dataKey}Service.updateById(${dataKey});
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 id 获取${dataName}(封装类)
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/get/vo")
|
||||
public BaseResponse<${upperDataKey}VO> get${upperDataKey}VOById(long id, HttpServletRequest request) {
|
||||
ThrowUtils.throwIf(id <= 0, ErrorCode.PARAMS_ERROR);
|
||||
// 查询数据库
|
||||
${upperDataKey} ${dataKey} = ${dataKey}Service.getById(id);
|
||||
ThrowUtils.throwIf(${dataKey} == null, ErrorCode.NOT_FOUND_ERROR);
|
||||
// 获取封装类
|
||||
return ResultUtils.success(${dataKey}Service.get${upperDataKey}VO(${dataKey}, request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取${dataName}列表(仅管理员可用)
|
||||
*
|
||||
* @param ${dataKey}QueryRequest
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list/page")
|
||||
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
|
||||
public BaseResponse<Page<${upperDataKey}>> list${upperDataKey}ByPage(@RequestBody ${upperDataKey}QueryRequest ${dataKey}QueryRequest) {
|
||||
long current = ${dataKey}QueryRequest.getCurrent();
|
||||
long size = ${dataKey}QueryRequest.getPageSize();
|
||||
// 查询数据库
|
||||
Page<${upperDataKey}> ${dataKey}Page = ${dataKey}Service.page(new Page<>(current, size),
|
||||
${dataKey}Service.getQueryWrapper(${dataKey}QueryRequest));
|
||||
return ResultUtils.success(${dataKey}Page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取${dataName}列表(封装类)
|
||||
*
|
||||
* @param ${dataKey}QueryRequest
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/list/page/vo")
|
||||
public BaseResponse<Page<${upperDataKey}VO>> list${upperDataKey}VOByPage(@RequestBody ${upperDataKey}QueryRequest ${dataKey}QueryRequest,
|
||||
HttpServletRequest request) {
|
||||
long current = ${dataKey}QueryRequest.getCurrent();
|
||||
long size = ${dataKey}QueryRequest.getPageSize();
|
||||
// 限制爬虫
|
||||
ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
|
||||
// 查询数据库
|
||||
Page<${upperDataKey}> ${dataKey}Page = ${dataKey}Service.page(new Page<>(current, size),
|
||||
${dataKey}Service.getQueryWrapper(${dataKey}QueryRequest));
|
||||
// 获取封装类
|
||||
return ResultUtils.success(${dataKey}Service.get${upperDataKey}VOPage(${dataKey}Page, request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取当前登录用户创建的${dataName}列表
|
||||
*
|
||||
* @param ${dataKey}QueryRequest
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/my/list/page/vo")
|
||||
public BaseResponse<Page<${upperDataKey}VO>> listMy${upperDataKey}VOByPage(@RequestBody ${upperDataKey}QueryRequest ${dataKey}QueryRequest,
|
||||
HttpServletRequest request) {
|
||||
ThrowUtils.throwIf(${dataKey}QueryRequest == null, ErrorCode.PARAMS_ERROR);
|
||||
// 补充查询条件,只查询当前登录用户的数据
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
${dataKey}QueryRequest.setUserId(loginUser.getId());
|
||||
long current = ${dataKey}QueryRequest.getCurrent();
|
||||
long size = ${dataKey}QueryRequest.getPageSize();
|
||||
// 限制爬虫
|
||||
ThrowUtils.throwIf(size > 20, ErrorCode.PARAMS_ERROR);
|
||||
// 查询数据库
|
||||
Page<${upperDataKey}> ${dataKey}Page = ${dataKey}Service.page(new Page<>(current, size),
|
||||
${dataKey}Service.getQueryWrapper(${dataKey}QueryRequest));
|
||||
// 获取封装类
|
||||
return ResultUtils.success(${dataKey}Service.get${upperDataKey}VOPage(${dataKey}Page, request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑${dataName}(给用户使用)
|
||||
*
|
||||
* @param ${dataKey}EditRequest
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/edit")
|
||||
public BaseResponse<Boolean> edit${upperDataKey}(@RequestBody ${upperDataKey}EditRequest ${dataKey}EditRequest, HttpServletRequest request) {
|
||||
if (${dataKey}EditRequest == null || ${dataKey}EditRequest.getId() <= 0) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
// todo 在此处将实体类和 DTO 进行转换
|
||||
${upperDataKey} ${dataKey} = new ${upperDataKey}();
|
||||
BeanUtils.copyProperties(${dataKey}EditRequest, ${dataKey});
|
||||
// 数据校验
|
||||
${dataKey}Service.valid${upperDataKey}(${dataKey}, false);
|
||||
User loginUser = userService.getLoginUser(request);
|
||||
// 判断是否存在
|
||||
long id = ${dataKey}EditRequest.getId();
|
||||
${upperDataKey} old${upperDataKey} = ${dataKey}Service.getById(id);
|
||||
ThrowUtils.throwIf(old${upperDataKey} == null, ErrorCode.NOT_FOUND_ERROR);
|
||||
// 仅本人或管理员可编辑
|
||||
if (!old${upperDataKey}.getUserId().equals(loginUser.getId()) && !userService.isAdmin(loginUser)) {
|
||||
throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
|
||||
}
|
||||
// 操作数据库
|
||||
boolean result = ${dataKey}Service.updateById(${dataKey});
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
|
||||
return ResultUtils.success(true);
|
||||
}
|
||||
|
||||
// endregion
|
||||
}
|
||||
53
src/main/resources/templates/TemplateService.java.ftl
Normal file
53
src/main/resources/templates/TemplateService.java.ftl
Normal file
@@ -0,0 +1,53 @@
|
||||
package ${packageName}.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}QueryRequest;
|
||||
import ${packageName}.model.entity.${upperDataKey};
|
||||
import ${packageName}.model.vo.${upperDataKey}VO;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* ${dataName}服务
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
public interface ${upperDataKey}Service extends IService<${upperDataKey}> {
|
||||
|
||||
/**
|
||||
* 校验数据
|
||||
*
|
||||
* @param ${dataKey}
|
||||
* @param add 对创建的数据进行校验
|
||||
*/
|
||||
void valid${upperDataKey}(${upperDataKey} ${dataKey}, boolean add);
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*
|
||||
* @param ${dataKey}QueryRequest
|
||||
* @return
|
||||
*/
|
||||
QueryWrapper<${upperDataKey}> getQueryWrapper(${upperDataKey}QueryRequest ${dataKey}QueryRequest);
|
||||
|
||||
/**
|
||||
* 获取${dataName}封装
|
||||
*
|
||||
* @param ${dataKey}
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
${upperDataKey}VO get${upperDataKey}VO(${upperDataKey} ${dataKey}, HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* 分页获取${dataName}封装
|
||||
*
|
||||
* @param ${dataKey}Page
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
Page<${upperDataKey}VO> get${upperDataKey}VOPage(Page<${upperDataKey}> ${dataKey}Page, HttpServletRequest request);
|
||||
}
|
||||
224
src/main/resources/templates/TemplateServiceImpl.java.ftl
Normal file
224
src/main/resources/templates/TemplateServiceImpl.java.ftl
Normal file
@@ -0,0 +1,224 @@
|
||||
package ${packageName}.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import ${packageName}.common.ErrorCode;
|
||||
import ${packageName}.constant.CommonConstant;
|
||||
import ${packageName}.exception.ThrowUtils;
|
||||
import ${packageName}.mapper.${upperDataKey}Mapper;
|
||||
import ${packageName}.model.dto.${dataKey}.${upperDataKey}QueryRequest;
|
||||
import ${packageName}.model.entity.${upperDataKey};
|
||||
import ${packageName}.model.entity.${upperDataKey}Favour;
|
||||
import ${packageName}.model.entity.${upperDataKey}Thumb;
|
||||
import ${packageName}.model.entity.User;
|
||||
import ${packageName}.model.vo.${upperDataKey}VO;
|
||||
import ${packageName}.model.vo.UserVO;
|
||||
import ${packageName}.service.${upperDataKey}Service;
|
||||
import ${packageName}.service.UserService;
|
||||
import ${packageName}.utils.SqlUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* ${dataName}服务实现
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ${upperDataKey}ServiceImpl extends ServiceImpl<${upperDataKey}Mapper, ${upperDataKey}> implements ${upperDataKey}Service {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 校验数据
|
||||
*
|
||||
* @param ${dataKey}
|
||||
* @param add 对创建的数据进行校验
|
||||
*/
|
||||
@Override
|
||||
public void valid${upperDataKey}(${upperDataKey} ${dataKey}, boolean add) {
|
||||
ThrowUtils.throwIf(${dataKey} == null, ErrorCode.PARAMS_ERROR);
|
||||
// todo 从对象中取值
|
||||
String title = ${dataKey}.getTitle();
|
||||
// 创建数据时,参数不能为空
|
||||
if (add) {
|
||||
// todo 补充校验规则
|
||||
ThrowUtils.throwIf(StringUtils.isBlank(title), ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
// 修改数据时,有参数则校验
|
||||
// todo 补充校验规则
|
||||
if (StringUtils.isNotBlank(title)) {
|
||||
ThrowUtils.throwIf(title.length() > 80, ErrorCode.PARAMS_ERROR, "标题过长");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件
|
||||
*
|
||||
* @param ${dataKey}QueryRequest
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public QueryWrapper<${upperDataKey}> getQueryWrapper(${upperDataKey}QueryRequest ${dataKey}QueryRequest) {
|
||||
QueryWrapper<${upperDataKey}> queryWrapper = new QueryWrapper<>();
|
||||
if (${dataKey}QueryRequest == null) {
|
||||
return queryWrapper;
|
||||
}
|
||||
// todo 从对象中取值
|
||||
Long id = ${dataKey}QueryRequest.getId();
|
||||
Long notId = ${dataKey}QueryRequest.getNotId();
|
||||
String title = ${dataKey}QueryRequest.getTitle();
|
||||
String content = ${dataKey}QueryRequest.getContent();
|
||||
String searchText = ${dataKey}QueryRequest.getSearchText();
|
||||
String sortField = ${dataKey}QueryRequest.getSortField();
|
||||
String sortOrder = ${dataKey}QueryRequest.getSortOrder();
|
||||
List<String> tagList = ${dataKey}QueryRequest.getTags();
|
||||
Long userId = ${dataKey}QueryRequest.getUserId();
|
||||
// todo 补充需要的查询条件
|
||||
// 从多字段中搜索
|
||||
if (StringUtils.isNotBlank(searchText)) {
|
||||
// 需要拼接查询条件
|
||||
queryWrapper.and(qw -> qw.like("title", searchText).or().like("content", searchText));
|
||||
}
|
||||
// 模糊查询
|
||||
queryWrapper.like(StringUtils.isNotBlank(title), "title", title);
|
||||
queryWrapper.like(StringUtils.isNotBlank(content), "content", content);
|
||||
// JSON 数组查询
|
||||
if (CollUtil.isNotEmpty(tagList)) {
|
||||
for (String tag : tagList) {
|
||||
queryWrapper.like("tags", "\"" + tag + "\"");
|
||||
}
|
||||
}
|
||||
// 精确查询
|
||||
queryWrapper.ne(ObjectUtils.isNotEmpty(notId), "id", notId);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
|
||||
queryWrapper.eq(ObjectUtils.isNotEmpty(userId), "userId", userId);
|
||||
// 排序规则
|
||||
queryWrapper.orderBy(SqlUtils.validSortField(sortField),
|
||||
sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
|
||||
sortField);
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取${dataName}封装
|
||||
*
|
||||
* @param ${dataKey}
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ${upperDataKey}VO get${upperDataKey}VO(${upperDataKey} ${dataKey}, HttpServletRequest request) {
|
||||
// 对象转封装类
|
||||
${upperDataKey}VO ${dataKey}VO = ${upperDataKey}VO.objToVo(${dataKey});
|
||||
|
||||
// todo 可以根据需要为封装对象补充值,不需要的内容可以删除
|
||||
// region 可选
|
||||
// 1. 关联查询用户信息
|
||||
Long userId = ${dataKey}.getUserId();
|
||||
User user = null;
|
||||
if (userId != null && userId > 0) {
|
||||
user = userService.getById(userId);
|
||||
}
|
||||
UserVO userVO = userService.getUserVO(user);
|
||||
${dataKey}VO.setUser(userVO);
|
||||
// 2. 已登录,获取用户点赞、收藏状态
|
||||
long ${dataKey}Id = ${dataKey}.getId();
|
||||
User loginUser = userService.getLoginUserPermitNull(request);
|
||||
if (loginUser != null) {
|
||||
// 获取点赞
|
||||
QueryWrapper<${upperDataKey}Thumb> ${dataKey}ThumbQueryWrapper = new QueryWrapper<>();
|
||||
${dataKey}ThumbQueryWrapper.in("${dataKey}Id", ${dataKey}Id);
|
||||
${dataKey}ThumbQueryWrapper.eq("userId", loginUser.getId());
|
||||
${upperDataKey}Thumb ${dataKey}Thumb = ${dataKey}ThumbMapper.selectOne(${dataKey}ThumbQueryWrapper);
|
||||
${dataKey}VO.setHasThumb(${dataKey}Thumb != null);
|
||||
// 获取收藏
|
||||
QueryWrapper<${upperDataKey}Favour> ${dataKey}FavourQueryWrapper = new QueryWrapper<>();
|
||||
${dataKey}FavourQueryWrapper.in("${dataKey}Id", ${dataKey}Id);
|
||||
${dataKey}FavourQueryWrapper.eq("userId", loginUser.getId());
|
||||
${upperDataKey}Favour ${dataKey}Favour = ${dataKey}FavourMapper.selectOne(${dataKey}FavourQueryWrapper);
|
||||
${dataKey}VO.setHasFavour(${dataKey}Favour != null);
|
||||
}
|
||||
// endregion
|
||||
|
||||
return ${dataKey}VO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取${dataName}封装
|
||||
*
|
||||
* @param ${dataKey}Page
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Page<${upperDataKey}VO> get${upperDataKey}VOPage(Page<${upperDataKey}> ${dataKey}Page, HttpServletRequest request) {
|
||||
List<${upperDataKey}> ${dataKey}List = ${dataKey}Page.getRecords();
|
||||
Page<${upperDataKey}VO> ${dataKey}VOPage = new Page<>(${dataKey}Page.getCurrent(), ${dataKey}Page.getSize(), ${dataKey}Page.getTotal());
|
||||
if (CollUtil.isEmpty(${dataKey}List)) {
|
||||
return ${dataKey}VOPage;
|
||||
}
|
||||
// 对象列表 => 封装对象列表
|
||||
List<${upperDataKey}VO> ${dataKey}VOList = ${dataKey}List.stream().map(${dataKey} -> {
|
||||
return ${upperDataKey}VO.objToVo(${dataKey});
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// todo 可以根据需要为封装对象补充值,不需要的内容可以删除
|
||||
// region 可选
|
||||
// 1. 关联查询用户信息
|
||||
Set<Long> userIdSet = ${dataKey}List.stream().map(${upperDataKey}::getUserId).collect(Collectors.toSet());
|
||||
Map<Long, List<User>> userIdUserListMap = userService.listByIds(userIdSet).stream()
|
||||
.collect(Collectors.groupingBy(User::getId));
|
||||
// 2. 已登录,获取用户点赞、收藏状态
|
||||
Map<Long, Boolean> ${dataKey}IdHasThumbMap = new HashMap<>();
|
||||
Map<Long, Boolean> ${dataKey}IdHasFavourMap = new HashMap<>();
|
||||
User loginUser = userService.getLoginUserPermitNull(request);
|
||||
if (loginUser != null) {
|
||||
Set<Long> ${dataKey}IdSet = ${dataKey}List.stream().map(${upperDataKey}::getId).collect(Collectors.toSet());
|
||||
loginUser = userService.getLoginUser(request);
|
||||
// 获取点赞
|
||||
QueryWrapper<${upperDataKey}Thumb> ${dataKey}ThumbQueryWrapper = new QueryWrapper<>();
|
||||
${dataKey}ThumbQueryWrapper.in("${dataKey}Id", ${dataKey}IdSet);
|
||||
${dataKey}ThumbQueryWrapper.eq("userId", loginUser.getId());
|
||||
List<${upperDataKey}Thumb> ${dataKey}${upperDataKey}ThumbList = ${dataKey}ThumbMapper.selectList(${dataKey}ThumbQueryWrapper);
|
||||
${dataKey}${upperDataKey}ThumbList.forEach(${dataKey}${upperDataKey}Thumb -> ${dataKey}IdHasThumbMap.put(${dataKey}${upperDataKey}Thumb.get${upperDataKey}Id(), true));
|
||||
// 获取收藏
|
||||
QueryWrapper<${upperDataKey}Favour> ${dataKey}FavourQueryWrapper = new QueryWrapper<>();
|
||||
${dataKey}FavourQueryWrapper.in("${dataKey}Id", ${dataKey}IdSet);
|
||||
${dataKey}FavourQueryWrapper.eq("userId", loginUser.getId());
|
||||
List<${upperDataKey}Favour> ${dataKey}FavourList = ${dataKey}FavourMapper.selectList(${dataKey}FavourQueryWrapper);
|
||||
${dataKey}FavourList.forEach(${dataKey}Favour -> ${dataKey}IdHasFavourMap.put(${dataKey}Favour.get${upperDataKey}Id(), true));
|
||||
}
|
||||
// 填充信息
|
||||
${dataKey}VOList.forEach(${dataKey}VO -> {
|
||||
Long userId = ${dataKey}VO.getUserId();
|
||||
User user = null;
|
||||
if (userIdUserListMap.containsKey(userId)) {
|
||||
user = userIdUserListMap.get(userId).get(0);
|
||||
}
|
||||
${dataKey}VO.setUser(userService.getUserVO(user));
|
||||
${dataKey}VO.setHasThumb(${dataKey}IdHasThumbMap.getOrDefault(${dataKey}VO.getId(), false));
|
||||
${dataKey}VO.setHasFavour(${dataKey}IdHasFavourMap.getOrDefault(${dataKey}VO.getId(), false));
|
||||
});
|
||||
// endregion
|
||||
|
||||
${dataKey}VOPage.setRecords(${dataKey}VOList);
|
||||
return ${dataKey}VOPage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package ${packageName}.model.dto.${dataKey};
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 创建${dataName}请求
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@Data
|
||||
public class ${upperDataKey}AddRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ${packageName}.model.dto.${dataKey};
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 编辑${dataName}请求
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@Data
|
||||
public class ${upperDataKey}EditRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package ${packageName}.model.dto.${dataKey};
|
||||
|
||||
import ${packageName}.common.PageRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 查询${dataName}请求
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ${upperDataKey}QueryRequest extends PageRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long notId;
|
||||
|
||||
/**
|
||||
* 搜索词
|
||||
*/
|
||||
private String searchText;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
|
||||
/**
|
||||
* 创建用户 id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ${packageName}.model.dto.${dataKey};
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 更新${dataName}请求
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@Data
|
||||
public class ${upperDataKey}UpdateRequest implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tags;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
93
src/main/resources/templates/model/TemplateVO.java.ftl
Normal file
93
src/main/resources/templates/model/TemplateVO.java.ftl
Normal file
@@ -0,0 +1,93 @@
|
||||
package ${packageName}.model.vo;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import ${packageName}.model.entity.${upperDataKey};
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${dataName}视图
|
||||
*
|
||||
* @author <a href="https://github.com/liyupi">程序员鱼皮</a>
|
||||
* @from <a href="https://www.code-nav.cn">编程导航学习圈</a>
|
||||
*/
|
||||
@Data
|
||||
public class ${upperDataKey}VO implements Serializable {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 创建用户 id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 标签列表
|
||||
*/
|
||||
private List<String> tagList;
|
||||
|
||||
/**
|
||||
* 创建用户信息
|
||||
*/
|
||||
private UserVO user;
|
||||
|
||||
/**
|
||||
* 封装类转对象
|
||||
*
|
||||
* @param ${dataKey}VO
|
||||
* @return
|
||||
*/
|
||||
public static ${upperDataKey} voToObj(${upperDataKey}VO ${dataKey}VO) {
|
||||
if (${dataKey}VO == null) {
|
||||
return null;
|
||||
}
|
||||
${upperDataKey} ${dataKey} = new ${upperDataKey}();
|
||||
BeanUtils.copyProperties(${dataKey}VO, ${dataKey});
|
||||
List<String> tagList = ${dataKey}VO.getTagList();
|
||||
${dataKey}.setTags(JSONUtil.toJsonStr(tagList));
|
||||
return ${dataKey};
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转封装类
|
||||
*
|
||||
* @param ${dataKey}
|
||||
* @return
|
||||
*/
|
||||
public static ${upperDataKey}VO objToVo(${upperDataKey} ${dataKey}) {
|
||||
if (${dataKey} == null) {
|
||||
return null;
|
||||
}
|
||||
${upperDataKey}VO ${dataKey}VO = new ${upperDataKey}VO();
|
||||
BeanUtils.copyProperties(${dataKey}, ${dataKey}VO);
|
||||
${dataKey}VO.setTagList(JSONUtil.toList(${dataKey}.getTags(), String.class));
|
||||
return ${dataKey}VO;
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/test_excel.xlsx
Normal file
BIN
src/main/resources/test_excel.xlsx
Normal file
Binary file not shown.
Reference in New Issue
Block a user