♻️ Refactoring code. 优化APP模块相关查询

This commit is contained in:
lbw committed 2023-06-24 16:03:49 +08:00
1 parent 20b566852f
commit 8cbbadf500
8 files changed
+60 -13

No files matched your search

+1 -1
View File
@@ -31,7 +31,7 @@ CREATE TABLE `config_info` (
-- ----------------------------
-- Records of config_info
-- ----------------------------
INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', '# 配置文件加密根密码\njasypt:\n encryptor:\n password: pigx\n algorithm: PBEWithMD5AndDES\n iv-generator-classname: org.jasypt.iv.NoIvGenerator\n\n\nspring:\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n eager: true\n transport:\n dashboard: pigx-sentinel:5020\n\n# 端点对外暴露\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\' \n endpoint:\n restart:\n enabled: true\n health:\n show-details: ALWAYS\n# feign 相关配置\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 20000\n readTimeout: 20000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n\n#开启灰度\ngray:\n rule:\n enabled: true\n\n# mybatis-plus 配置\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n capitalMode: true\n banner: false\n db-config:\n id-type: auto\n select-strategy: not_empty\n insert-strategy: not_empty\n update-strategy: not_null\n type-handlers-package: com.pig4cloud.pigx.common.data.handler\n configuration:\n jdbc-type-for-null: \'null\'\n call-setters-on-nulls: true', '53bcac9e21a6f521f2a70b8031443dd2', '2022-12-16 10:44:25', '2023-02-28 14:16:11', 'nacos', '0:0:0:0:0:0:0:1', '', '', '', '', '', 'yaml', '', '');
INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', '# 配置文件加密根密码\njasypt:\n encryptor:\n password: pigx\n algorithm: PBEWithMD5AndDES\n iv-generator-classname: org.jasypt.iv.NoIvGenerator\n\n\nspring:\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n eager: true\n transport:\n dashboard: pigx-sentinel:5020\n\n# 端点对外暴露\nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\' \n endpoint:\n restart:\n enabled: true\n health:\n show-details: ALWAYS\n# feign 相关配置\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 20000\n readTimeout: 20000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n\n#开启灰度\ngray:\n rule:\n enabled: true\n\n# mybatis-plus 配置\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n capitalMode: true\n banner: false\n db-config:\n id-type: auto\n select-strategy: not_empty\n insert-strategy: not_empty\n update-strategy: not_null\n type-handlers-package: com.pig4cloud.pigx.common.data.handler\n configuration:\n jdbc-type-for-null: \'null\'\n call-setters-on-nulls: true\n\n\n# oauth2 资源服务器相关配置\nsecurity:\n oauth2:\n client:\n ignore-urls:\n - /css/**\n - /error\n - /actuator/**\n - /v2/api-docs\n resource:\n loadBalanced: true\n token-info-uri: http://pigx-auth/oauth/check_token', '41188788db4fb8406536c4f8b95093a2', '2022-12-16 10:44:25', '2023-01-01 20:03:14', 'nacos', '127.0.0.1', '', '', '', '', '', 'yaml', '', '');
INSERT INTO `config_info` VALUES (2, 'pigx-auth-dev.yml', 'DEFAULT_GROUP', '# 数据源\nspring:\n freemarker:\n allow-request-override: false\n allow-session-override: false\n cache: true\n charset: UTF-8\n check-template-location: true\n content-type: text/html\n enabled: true\n expose-request-attributes: false\n expose-session-attributes: false\n expose-spring-macro-helpers: true\n prefer-file-system-access: true\n suffix: .ftl\n template-loader-path: classpath:/templates/', '74f53b71c7799aa754da75662378b93c', '2022-12-16 10:44:25', '2022-12-16 10:44:25', NULL, '0:0:0:0:0:0:0:1', '', '', NULL, NULL, NULL, 'yaml', NULL, '');
INSERT INTO `config_info` VALUES (3, 'pigx-codegen-dev.yml', 'DEFAULT_GROUP', '# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL_USER:root}\n password: ${MYSQL_PWD:root}\n url: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_codegen}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true\n resources:\n static-locations: classpath:/static/,classpath:/views/\n\n# 租户表维护\npigx:\n tenant:\n column: tenant_id\n tables:\n - gen_datasource_conf\n - gen_form_conf\n - gen_template\n - gen_group\n', '765e72c9ff3b0a4504ea4703fbdd7859', '2022-12-16 10:44:25', '2023-04-07 14:14:25', 'nacos', '127.0.0.1', '', '', '', '', '', 'yaml', '', '');
INSERT INTO `config_info` VALUES (4, 'pigx-daemon-elastic-job-dev.yml', 'DEFAULT_GROUP', '# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL_USER:root}\n password: ${MYSQL_PWD:root}\n url: jdbc:mysql://${MYSQL_HOST:pigx-mysql}:${MYSQL_PORT:3306}/${MYSQL_DB:pigxx_job}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true', '09996f46e0b80d7b2aa320ef4cb31c82', '2022-12-16 10:44:25', '2023-04-07 14:14:50', 'nacos', '127.0.0.1', '', '', '', '', '', 'yaml', '', '');
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldNameConstants;
import java.time.LocalDateTime;
@@ -15,6 +16,7 @@ import java.time.LocalDateTime;
* @date 2023-06-07 16:32:35
*/
@Data
@FieldNameConstants
@TableName("app_article")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "文章资讯")
@@ -123,4 +125,10 @@ public class AppArticleEntity extends Model<AppArticleEntity> {
@TableField(exist = false)
private boolean collect;
/**
* 分类名称
*/
@TableField(exist = false)
private String cname;
}
@@ -48,7 +48,8 @@ public class AppArticleCollectController {
public R getAppArticleCollectPage(@ParameterObject Page page) {
MPJLambdaWrapper<AppArticleCollectEntity> wrapper = new MPJLambdaWrapper<AppArticleCollectEntity>()
.selectAll(AppArticleCollectEntity.class).select(AppArticleEntity::getTitle)
.leftJoin(AppArticleEntity.class, AppArticleEntity::getId, AppArticleCollectEntity::getArticleId);
.leftJoin(AppArticleEntity.class, AppArticleEntity::getId, AppArticleCollectEntity::getArticleId)
.eq(AppArticleCollectEntity::getUserId, SecurityUtils.getUser().getId());
return R.ok(appArticleCollectService.selectJoinListPage(page, AppArticleCollectEntity.class, wrapper));
}
@@ -72,9 +73,7 @@ public class AppArticleCollectController {
@SysLog("新增文章收藏表")
@PostMapping
public R save(@RequestBody AppArticleCollectEntity appArticleCollect) {
Long id = SecurityUtils.getUser().getId();
appArticleCollect.setUserId(id);
return R.ok(appArticleCollectService.save(appArticleCollect));
return R.ok(appArticleCollectService.saveArticleCollect(appArticleCollect));
}
/**
@@ -1,8 +1,6 @@
package com.pig4cloud.pigx.app.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.app.api.entity.AppArticleEntity;
@@ -21,7 +19,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 文章资讯
@@ -48,11 +45,7 @@ public class AppArticleController {
@Inner(value = false)
@GetMapping("/page")
public R getAppArticlePage(@ParameterObject Page page, @ParameterObject AppArticleEntity appArticle) {
LambdaQueryWrapper<AppArticleEntity> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(appArticle.getAuthor()), AppArticleEntity::getAuthor, appArticle.getAuthor());
wrapper.like(StrUtil.isNotBlank(appArticle.getTitle()), AppArticleEntity::getTitle, appArticle.getTitle());
wrapper.eq(Objects.nonNull(appArticle.getCid()), AppArticleEntity::getCid, appArticle.getCid());
return R.ok(appArticleService.page(page, wrapper));
return R.ok(appArticleService.pageAndCname(page, appArticle));
}
/**
@@ -5,4 +5,6 @@ import com.pig4cloud.pigx.app.api.entity.AppArticleCollectEntity;
public interface AppArticleCollectService extends MPJBaseService<AppArticleCollectEntity> {
Boolean saveArticleCollect(AppArticleCollectEntity appArticleCollect);
}
@@ -1,5 +1,6 @@
package com.pig4cloud.pigx.app.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.app.api.entity.AppArticleEntity;
@@ -12,4 +13,12 @@ public interface AppArticleService extends IService<AppArticleEntity> {
*/
AppArticleEntity getArticleAndIncrById(Long id, Long userId);
/**
* 分页查询文章列表 包含分类名称
* @param page 分页参数
* @param appArticle 文章查询条件
* @return
*/
Page pageAndCname(Page page, AppArticleEntity appArticle);
}
@@ -1,9 +1,11 @@
package com.pig4cloud.pigx.app.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.app.api.entity.AppArticleCollectEntity;
import com.pig4cloud.pigx.app.mapper.AppArticleCollectMapper;
import com.pig4cloud.pigx.app.service.AppArticleCollectService;
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
import org.springframework.stereotype.Service;
/**
@@ -16,4 +18,16 @@ import org.springframework.stereotype.Service;
public class AppArticleCollectServiceImpl extends ServiceImpl<AppArticleCollectMapper, AppArticleCollectEntity>
implements AppArticleCollectService {
@Override
public Boolean saveArticleCollect(AppArticleCollectEntity appArticleCollect) {
Long id = SecurityUtils.getUser().getId();
appArticleCollect.setUserId(id);
this.saveOrUpdate(appArticleCollect,
Wrappers.<AppArticleCollectEntity>lambdaQuery().eq(AppArticleCollectEntity::getUserId, id)
.eq(AppArticleCollectEntity::getArticleId, appArticleCollect.getArticleId()));
return Boolean.TRUE;
}
}
@@ -1,7 +1,11 @@
package com.pig4cloud.pigx.app.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.pig4cloud.pigx.app.api.entity.AppArticleCategoryEntity;
import com.pig4cloud.pigx.app.api.entity.AppArticleCollectEntity;
import com.pig4cloud.pigx.app.api.entity.AppArticleEntity;
import com.pig4cloud.pigx.app.mapper.AppArticleCollectMapper;
@@ -50,4 +54,22 @@ public class AppArticleServiceImpl extends ServiceImpl<AppArticleMapper, AppArti
return appArticleEntity;
}
/**
* 分页查询文章列表 包含分类名称
* @param page 分页参数
* @param appArticle 文章查询条件
* @return
*/
@Override
public Page pageAndCname(Page page, AppArticleEntity appArticle) {
MPJLambdaWrapper<AppArticleEntity> wrapper = new MPJLambdaWrapper<>();
wrapper.selectAll(AppArticleEntity.class)
.selectAs(AppArticleCategoryEntity::getName, AppArticleEntity.Fields.cname)
.leftJoin(AppArticleCategoryEntity.class, AppArticleCategoryEntity::getId, AppArticleEntity::getCid)
.like(StrUtil.isNotBlank(appArticle.getAuthor()), AppArticleEntity::getAuthor, appArticle.getAuthor())
.like(StrUtil.isNotBlank(appArticle.getTitle()), AppArticleEntity::getTitle, appArticle.getTitle())
.eq(Objects.nonNull(appArticle.getCid()), AppArticleEntity::getCid, appArticle.getCid());
return this.page(page, wrapper);
}
}