This commit is contained in:
JiyangTang 2024-03-08 18:40:47 +08:00
parent acff6b1cd8
commit c93ff88e0e
19 changed files with 272 additions and 23 deletions

View File

@ -0,0 +1,33 @@
package top.baogutang.admin.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.baogutang.admin.domain.res.NoticeLogRes;
import top.baogutang.admin.services.INoticeLogService;
import top.baogutang.common.constants.NoticeTypeEnum;
import top.baogutang.common.domain.PageUtil;
import top.baogutang.common.domain.Results;
import javax.annotation.Resource;
/**
* @description:
* @author: nikooh
* @date: 2024/02/22 : 11:49
*/
@RequestMapping("api/v1/notice")
@RestController
public class NoticeController {
@Resource
private INoticeLogService noticeLogService;
@GetMapping("/page")
public Results<PageUtil<NoticeLogRes>> pageQuery(@RequestParam(name = "pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(name = "pageSize", required = false, defaultValue = "20") Integer pageSize,
@RequestParam(name = "noticeType", required = false) NoticeTypeEnum noticeType) {
return Results.ok(noticeLogService.queryPage(pageNum, pageSize, noticeType));
}
}

View File

@ -0,0 +1,32 @@
package top.baogutang.admin.domain.req;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import top.baogutang.common.constants.NoticeTypeEnum;
import top.baogutang.common.domain.PageParam;
import java.io.Serializable;
/**
* @description:
* @author: nikooh
* @date: 2024/02/22 : 13:55
*/
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor
public class NoticeLogQueryParam extends PageParam implements Serializable {
private static final long serialVersionUID = 4745304392774888914L;
private NoticeTypeEnum noticeType;
public NoticeLogQueryParam(Integer pageNum, Integer pageSize, NoticeTypeEnum noticeType) {
this.setPageNum(pageNum);
this.setPageSize(pageSize);
this.noticeType = noticeType;
}
}

View File

@ -0,0 +1,58 @@
package top.baogutang.admin.domain.res;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @description:
* @author: nikooh
* @date: 2024/02/22 : 11:53
*/
@Data
public class NoticeLogRes implements Serializable {
private static final long serialVersionUID = 8076035880845304425L;
private Long id;
/**
* 公告
*/
private String noticeType;
private Long noticeId;
/**
* 标题
*/
private String title;
/**
* 类型
*/
private String type;
/**
* 封面
*/
private String cover;
/**
* 创作者
*/
private String noticeCreator;
/**
* 内容
*/
private String detailUrl;
/**
* 创建时间
*/
private Date noticeCreatedAt;
private Date createTime;
}

View File

@ -14,7 +14,7 @@ import top.baogutang.admin.services.INoticeLogService;
import top.baogutang.admin.services.IWxMsgPushService;
import top.baogutang.admin.utils.DingTalkMsgPushUtils;
import top.baogutang.common.constants.NoticeTypeEnum;
import top.baogutang.common.domain.Page;
import top.baogutang.common.domain.PageUtil;
import top.baogutang.common.domain.Results;
import top.baogutang.common.properties.WxMsgPushProperties;
import top.baogutang.common.utils.OkHttpUtil;
@ -58,7 +58,7 @@ public class NoticeSchedule {
public void edgeNotice() {
Arrays.stream(NoticeTypeEnum.values())
.forEach(noticeType -> {
Results<Page<AnnouncementsDto>> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference<Results<Page<AnnouncementsDto>>>() {
Results<PageUtil<AnnouncementsDto>> results = OkHttpUtil.get(noticeType.getListUrl(), null, null, new TypeReference<Results<PageUtil<AnnouncementsDto>>>() {
});
log.info(">>>>>>>>>>请求获取:{}公告返回数据:{}<<<<<<<<<<", noticeType.getDesc(), JSON.toJSONString(results));
if (Objects.isNull(results)) {

View File

@ -1,7 +1,10 @@
package top.baogutang.admin.services;
import top.baogutang.admin.dao.entity.NoticeLogEntity;
import top.baogutang.admin.domain.res.NoticeLogRes;
import top.baogutang.common.constants.NoticeTypeEnum;
import top.baogutang.common.domain.PageUtil;
import top.baogutang.common.domain.Results;
import java.util.Date;
import java.util.List;
@ -35,5 +38,7 @@ public interface INoticeLogService {
* @return notice数据
*/
List<NoticeLogEntity> queryLogByConditions(Long noticeId, NoticeTypeEnum noticeType);
PageUtil<NoticeLogRes> queryPage(Integer pageNum, Integer pageSize, NoticeTypeEnum noticeType);
}

View File

@ -1,19 +1,26 @@
package top.baogutang.admin.services.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.baogutang.admin.dao.entity.NoticeLogEntity;
import top.baogutang.admin.dao.mapper.NoticeLogMapper;
import top.baogutang.admin.domain.req.NoticeLogQueryParam;
import top.baogutang.admin.domain.res.NoticeLogRes;
import top.baogutang.admin.services.INoticeLogService;
import top.baogutang.common.constants.NoticeTypeEnum;
import top.baogutang.common.domain.PageUtil;
import top.baogutang.common.utils.MyBatisPlusPageUtil;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @description:
@ -51,4 +58,19 @@ public class NoticeLogServiceImpl extends ServiceImpl<NoticeLogMapper, NoticeLog
.eq(NoticeLogEntity::getDeleted, Boolean.FALSE)
.list();
}
@Override
public PageUtil<NoticeLogRes> queryPage(Integer pageNum, Integer pageSize, NoticeTypeEnum noticeType) {
NoticeLogQueryParam queryParam = new NoticeLogQueryParam(pageNum, pageSize, noticeType);
return MyBatisPlusPageUtil.page(page -> noticeLogMapper.selectPage(page, Wrappers.lambdaQuery(NoticeLogEntity.class)
.eq(Objects.nonNull(queryParam.getNoticeType()), NoticeLogEntity::getNoticeType, queryParam.getNoticeType().getDesc())
.eq(NoticeLogEntity::getDeleted, Boolean.FALSE)
.orderByDesc(NoticeLogEntity::getCreateTime)), queryParam, this::geneResFromEntity);
}
private NoticeLogRes geneResFromEntity(NoticeLogEntity noticeLogEntity) {
NoticeLogRes noticeLogRes = new NoticeLogRes();
BeanUtils.copyProperties(noticeLogEntity, noticeLogRes);
return noticeLogRes;
}
}

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: 1877a228-6bff-46b9-a442-829473c3adc7
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: fe5388cc-76bc-44d6-ba20-034f97c567e5
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 42.51.4.235:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 42.51.4.235:8848
server-addr: 180.97.221.51:8848
namespace: 7e44b734-781d-4c21-a524-4bad1557d95f
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: 1877a228-6bff-46b9-a442-829473c3adc7
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: fe5388cc-76bc-44d6-ba20-034f97c567e5
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 42.51.4.235:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 42.51.4.235:8848
server-addr: 180.97.221.51:8848
namespace: 7e44b734-781d-4c21-a524-4bad1557d95f
file-extension: yml
refresh-enabled: true

View File

@ -33,9 +33,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<!-- redis 缓存操作 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<exclusions>
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@ -70,6 +70,8 @@ public enum ErrorCodeEnum {
E_EXEC_SCRIPT_ERROR(81011037, "脚本执行失败"),
E_PAGE_QUERY_ERROR(81011038, "分页查询异常"),
;
private final int code;

View File

@ -0,0 +1,41 @@
package top.baogutang.common.domain;
import lombok.Data;
import java.io.Serializable;
/**
* @description:
* @author: nikooh
* @date: 2024/02/22 : 11:22
*/
@Data
public class PageParam implements Serializable {
private static final long serialVersionUID = 5353838683455028860L;
private Integer pageNum;
private Integer pageSize;
public Integer getPageNum() {
pageNum = pageNum == null ? 1 : pageNum;
return pageNum;
}
public void setPageNum(Integer pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
if (pageSize == null || pageSize > 100) {
pageSize = 10;
}
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
}

View File

@ -17,17 +17,17 @@ import java.util.List;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Page<T> implements Serializable {
public class PageUtil<T> implements Serializable {
private static final long serialVersionUID = 7521438130006292396L;
private Integer totalCount;
private Long currPage;
private Integer pageSize;
private Long pageSize;
private Integer totalPage;
private Long totalCount;
private Integer currPage;
private Long totalPage;
private List<T> list;
}

View File

@ -0,0 +1,45 @@
package top.baogutang.common.utils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import top.baogutang.common.domain.PageParam;
import top.baogutang.common.domain.PageUtil;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
/**
* @description:
* @author: nikooh
* @date: 2024/02/22 : 11:21
*/
@Slf4j
public class MyBatisPlusPageUtil {
private MyBatisPlusPageUtil() {
// private constructor
}
/**
* general method of paging query
*
* @param queryFunction page query function
* @param pageParam page param
* @param beanCastFunction bean cast function
* @param <T> entity class
* @param <U> query parameter
* @param <R> return bean
* @return pageUtils
*/
public static <T, U extends PageParam, R> PageUtil<R> page(UnaryOperator<Page<T>> queryFunction, U pageParam, Function<T, R> beanCastFunction) {
Page<T> pageReq = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
Page<T> pageRes = queryFunction.apply(pageReq);
List<R> rPageRes = pageRes.getRecords().stream()
.map(beanCastFunction)
.collect(Collectors.toList());
return new PageUtil<>(pageRes.getCurrent(), pageRes.getSize(), pageRes.getTotal(), pageRes.getPages(), rPageRes);
}
}

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: 1877a228-6bff-46b9-a442-829473c3adc7
file-extension: yml
refresh-enabled: true

View File

@ -4,9 +4,9 @@ spring:
cloud:
nacos:
discovery:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
config:
server-addr: 222.186.131.30:8848
server-addr: 180.97.221.51:8848
namespace: fe5388cc-76bc-44d6-ba20-034f97c567e5
file-extension: yml
refresh-enabled: true