添加公共统计接口

This commit is contained in:
zk
2026-07-31 11:01:49 +08:00
parent f4c60efdf2
commit f79a73a0c2
3 changed files with 69 additions and 1 deletions
@@ -1,12 +1,14 @@
package org.jiayunet.controller;
import lombok.AllArgsConstructor;
import org.jiayunet.pojo.dto.recruitAnnouncement.RecruitAnnouncementStatisticsDto;
import org.jiayunet.service.RecruitAnnouncementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.Instant;
import java.util.List;
/**
@@ -23,6 +25,18 @@ public class RecruitAnnouncementController {
private RecruitAnnouncementService recruitAnnouncementService;
/** 查询公告最后更新时间 */
@GetMapping("/lastUpdateTime")
public Instant getLastUpdateTime() {
return recruitAnnouncementService.getLastUpdateTime();
}
/** 统计公告数量(今日新增/本月新增/累计) */
@GetMapping("/statistics")
public RecruitAnnouncementStatisticsDto getStatistics() {
return recruitAnnouncementService.getStatistics();
}
/** 查询公告批次列表(去重) */
@GetMapping("/batch")
public List<String> listBatchName() {
@@ -2,15 +2,22 @@ package org.jiayunet.service;
import lombok.extern.slf4j.Slf4j;
import org.jiayunet.mapper.RecruitAnnouncementBatchMapper;
import org.jiayunet.mapper.RecruitAnnouncementMapper;
import org.jiayunet.mapper.RecruitAnnouncementCategoryMapper;
import org.jiayunet.mapper.RecruitAnnouncementCityMapper;
import org.jiayunet.mapper.RecruitAnnouncementEducationMapper;
import org.jiayunet.mapper.RecruitAnnouncementIndustryMapper;
import org.jiayunet.mapper.RecruitAnnouncementTagMapper;
import org.jiayunet.mapper.RecruitAnnouncementYearMapper;
import org.jiayunet.pojo.dto.recruitAnnouncement.RecruitAnnouncementStatisticsDto;
import org.jiayunet.pojo.vo.RecruitAnnouncementStatisticsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
/**
@@ -27,6 +34,12 @@ import java.util.List;
@Slf4j
public class RecruitAnnouncementService {
/** 统计时间边界所用时区,固定东八区,避免受JVM默认时区影响 */
private static final ZoneId STAT_ZONE = ZoneId.of("Asia/Shanghai");
@Autowired
private RecruitAnnouncementMapper recruitAnnouncementMapper;
@Autowired
private RecruitAnnouncementBatchMapper batchMapper;
@@ -48,6 +61,28 @@ public class RecruitAnnouncementService {
@Autowired
private RecruitAnnouncementYearMapper yearMapper;
/**
* 查询公告最后更新时间
* <p>按id倒序取第一条的创建时间,无数据时返回null</p>
*/
public Instant getLastUpdateTime() {
return recruitAnnouncementMapper.selectLastCreateTime();
}
/**
* 统计公告数量(今日新增/本月新增/累计)
* <p>1. 按东八区算出今日零点、本月1号零点 2. 一次SQL条件聚合出三个计数 3. 转DTO返回</p>
*/
public RecruitAnnouncementStatisticsDto getStatistics() {
LocalDate today = LocalDate.now(STAT_ZONE);
Instant dayStart = today.atStartOfDay(STAT_ZONE).toInstant();
Instant monthStart = today.withDayOfMonth(1).atStartOfDay(STAT_ZONE).toInstant();
RecruitAnnouncementStatisticsVo vo = recruitAnnouncementMapper.selectStatistics(dayStart, monthStart);
RecruitAnnouncementStatisticsDto dto = new RecruitAnnouncementStatisticsDto();
BeanUtils.copyProperties(vo, dto);
return dto;
}
/**
* 查询公告批次列表
* <p>按batch_name分组去重后返回</p>
@@ -1,13 +1,32 @@
package org.jiayunet.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.jiayunet.pojo.po.RecruitAnnouncement;
import org.jiayunet.pojo.vo.RecruitAnnouncementStatisticsVo;
import java.time.Instant;
/**
* 招聘公告Mapper
* 招聘公告主表Mapper
*
* @author zk
*/
@Mapper
public interface RecruitAnnouncementMapper extends CommonMapper<RecruitAnnouncement> {
/**
* 查询最后更新时间
* <p>按id倒序取第一条的创建时间</p>
*/
Instant selectLastCreateTime();
/**
* 统计公告数量(日/月/累计)
* <p>一次扫描算三个计数,保证三个数字来自同一快照;无数据时计数为0</p>
*
* @param dayStart 今日开始时间
* @param monthStart 本月开始时间
*/
RecruitAnnouncementStatisticsVo selectStatistics(@Param("dayStart") Instant dayStart, @Param("monthStart") Instant monthStart);
}