feat: 修改AiVideoReportData的表字段,查询近七天的数据
This commit is contained in:
parent
dba0b2d9ca
commit
a275194cfb
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.ruoyi.common.core.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门统计数据DTO
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class DeptSummaryDTO implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
// 积分
|
||||||
|
private BigDecimal score;
|
||||||
|
// 订单数量
|
||||||
|
private Long orderCount;
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,7 @@ public class AiVideoReportData implements Serializable {
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
/** 积分/分数统计 */
|
/** 积分/分数统计 */
|
||||||
private BigDecimal scoreCount;
|
private BigDecimal score;
|
||||||
|
|
||||||
/** 订单数 */
|
/** 订单数 */
|
||||||
private Long orderCount;
|
private Long orderCount;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,14 @@ package com.ruoyi.ai.mapper;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.ruoyi.ai.domain.AiVideoReportData;
|
import com.ruoyi.ai.domain.AiVideoReportData;
|
||||||
|
import com.ruoyi.common.core.dto.DeptSummaryDTO;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频报表数据 Mapper
|
* 视频报表数据 Mapper
|
||||||
*/
|
*/
|
||||||
public interface AiVideoReportDataMapper extends BaseMapper<AiVideoReportData> {
|
public interface AiVideoReportDataMapper extends BaseMapper<AiVideoReportData> {
|
||||||
|
@Select("SELECT SUM(order_count) as order_count,SUM(score) as score FROM ai_video_report_data " +
|
||||||
|
" where dept_id=#{deptId} and date_key>=#{startHour} and date_key<=#{endHour}")
|
||||||
|
DeptSummaryDTO selectOneDeptSummaryData(Long deptId, String startHour, String endHour);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
package com.ruoyi.ai.service;
|
package com.ruoyi.ai.service;
|
||||||
|
|
||||||
import com.ruoyi.ai.domain.AiVideoReportData;
|
import com.ruoyi.ai.domain.AiVideoReportData;
|
||||||
|
import com.ruoyi.common.core.dto.DeptSummaryDTO;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频报表数据 Service
|
* 视频报表数据 Service
|
||||||
*/
|
*/
|
||||||
public interface IAiVideoReportDataService {
|
public interface IAiVideoReportDataService {
|
||||||
|
|
||||||
AiVideoReportData selectById(Long id);
|
AiVideoReportData selectById(Long id);
|
||||||
|
|
||||||
int insert(AiVideoReportData entity);
|
int insert(AiVideoReportData entity);
|
||||||
|
|
||||||
int updateById(AiVideoReportData entity);
|
DeptSummaryDTO getSevenDayDeptSummaryData(Long deptId);
|
||||||
|
|
||||||
int deleteById(Long id);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,19 @@
|
||||||
package com.ruoyi.ai.service.impl;
|
package com.ruoyi.ai.service.impl;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.ruoyi.ai.domain.AiVideoReportData;
|
import com.ruoyi.ai.domain.AiVideoReportData;
|
||||||
import com.ruoyi.ai.mapper.AiVideoReportDataMapper;
|
import com.ruoyi.ai.mapper.AiVideoReportDataMapper;
|
||||||
import com.ruoyi.ai.service.IAiVideoReportDataService;
|
import com.ruoyi.ai.service.IAiVideoReportDataService;
|
||||||
|
import com.ruoyi.common.core.dto.DeptSummaryDTO;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 视频报表数据 Service 实现
|
* 视频报表数据 Service 实现
|
||||||
|
|
@ -13,26 +21,40 @@ import com.ruoyi.ai.service.IAiVideoReportDataService;
|
||||||
@Service
|
@Service
|
||||||
public class AiVideoReportDataServiceImpl implements IAiVideoReportDataService {
|
public class AiVideoReportDataServiceImpl implements IAiVideoReportDataService {
|
||||||
|
|
||||||
|
/** 与表字段 date_key 一致:yyyy-MM-dd HH(线程安全) */
|
||||||
|
private static final DateTimeFormatter DATE_KEY_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH");
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AiVideoReportDataMapper aiVideoReportDataMapper;
|
private AiVideoReportDataMapper videoReportDataMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AiVideoReportData selectById(Long id) {
|
public AiVideoReportData selectById(Long id) {
|
||||||
return aiVideoReportDataMapper.selectById(id);
|
return videoReportDataMapper.selectById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(AiVideoReportData entity) {
|
public int insert(AiVideoReportData entity) {
|
||||||
return aiVideoReportDataMapper.insert(entity);
|
return videoReportDataMapper.insert(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门近七日汇总数据
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateById(AiVideoReportData entity) {
|
@Cacheable(cacheNames = "dept_summary", key = "#deptId")
|
||||||
return aiVideoReportDataMapper.updateById(entity);
|
public DeptSummaryDTO getSevenDayDeptSummaryData(Long deptId) {
|
||||||
|
Date endTime = new Date();
|
||||||
|
// 获取今天的0点,再减去7天
|
||||||
|
Date todayZero = DateUtils.truncate(endTime, Calendar.DAY_OF_MONTH);
|
||||||
|
Date startTime = DateUtils.addDays(todayZero, -7);
|
||||||
|
|
||||||
|
String startHour = formatDateKey(startTime);
|
||||||
|
String endHour = formatDateKey(endTime);
|
||||||
|
return videoReportDataMapper.selectOneDeptSummaryData(deptId, startHour, endHour);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static String formatDateKey(Date date) {
|
||||||
public int deleteById(Long id) {
|
LocalDateTime ldt = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
|
||||||
return aiVideoReportDataMapper.deleteById(id);
|
return DATE_KEY_FORMAT.format(ldt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,15 @@ CREATE TABLE `ai_video_report_data` (
|
||||||
`date_key` VARCHAR(12) NOT NULL COMMENT '统计时间,到小时(\'%Y-%m-%d %H\')' COLLATE 'utf8mb4_unicode_ci',
|
`date_key` VARCHAR(12) NOT NULL COMMENT '统计时间,到小时(\'%Y-%m-%d %H\')' COLLATE 'utf8mb4_unicode_ci',
|
||||||
`dept_id` BIGINT NOT NULL COMMENT '部门ID',
|
`dept_id` BIGINT NOT NULL COMMENT '部门ID',
|
||||||
`user_id` BIGINT NOT NULL COMMENT '用户ID,用户表的ID,延用其他表设计 ',
|
`user_id` BIGINT NOT NULL COMMENT '用户ID,用户表的ID,延用其他表设计 ',
|
||||||
`score_count` DECIMAL(14,2) NOT NULL DEFAULT '0.00' COMMENT '消耗积分,按任务创建时间统计',
|
`score` DECIMAL(14,2) NOT NULL DEFAULT '0.00' COMMENT '消耗积分,按任务创建时间统计',
|
||||||
`order_count` BIGINT NOT NULL DEFAULT '0' COMMENT '实际订单数,只统计已生成成功的任务',
|
`order_count` BIGINT NOT NULL DEFAULT '0' COMMENT '实际订单数,只统计已生成成功的任务',
|
||||||
`use_tokens` BIGINT NOT NULL DEFAULT '0' COMMENT '三方消耗tokens数量,按任务创建时间统计',
|
`use_tokens` BIGINT NOT NULL DEFAULT '0' COMMENT '三方消耗tokens数量,按任务创建时间统计',
|
||||||
`create_time` DATETIME NULL DEFAULT (now()) COMMENT '创建时间',
|
`create_time` DATETIME NULL DEFAULT (now()) COMMENT '创建时间',
|
||||||
`update_time` DATETIME NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
`update_time` DATETIME NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
UNIQUE INDEX `u_date_dept_user` (`date_key`, `dept_id`, `user_id`) USING BTREE
|
UNIQUE INDEX `u_date_dept_user` (`dept_id`, `date_key`, `user_id`) USING BTREE
|
||||||
)
|
)
|
||||||
COMMENT='AI视频生成统计数据表,作为其他统计报表的数据源'
|
COMMENT='AI视频生成统计数据表,作为其他统计报表的数据源'
|
||||||
COLLATE='utf8mb4_unicode_ci'
|
COLLATE='utf8mb4_unicode_ci'
|
||||||
ENGINE=InnoDB;
|
ENGINE=InnoDB;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue