添加公共统计接口
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user