后台定时任务--添加--daily_sys有关数据
This commit is contained in:
parent
d691ce075b
commit
ddbd783f6c
@ -1194,7 +1194,7 @@ public class AppSystemController extends BaseController {
|
||||
UserWork userWork1 = userWorkService.selectUserWorkByWorkId(workId);
|
||||
|
||||
// 避免一些非法操作,
|
||||
if(!Objects.equals(userWork1.getUserId(), getUserId())){
|
||||
if(userWork1.getUserId() != getUserId()){
|
||||
return error("非法操作, 请不要编辑不是自己的作品");
|
||||
}
|
||||
|
||||
|
||||
@ -2,13 +2,13 @@ package com.ruoyi.web.controller.backstage.daily;
|
||||
|
||||
|
||||
import com.ruoyi.system.domain.DailySys;
|
||||
import com.ruoyi.system.service.IDailySysService;
|
||||
import com.ruoyi.system.service.IDailyUserService;
|
||||
import com.ruoyi.system.service.ISysUserStService;
|
||||
import com.ruoyi.system.service.ISysUserWorkCountService;
|
||||
import com.ruoyi.system.domain.dto.DailySourceDto;
|
||||
import com.ruoyi.system.domain.dto.DailyUserDto;
|
||||
import com.ruoyi.system.service.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -27,6 +27,15 @@ public class dailySysServer {
|
||||
@Autowired
|
||||
private IDailySysService dailySysService;
|
||||
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private IUserWorkService userWorkService;
|
||||
|
||||
@Autowired
|
||||
private ISysOrderService sysOrderService;
|
||||
|
||||
|
||||
// 用户每天统计表
|
||||
@Autowired
|
||||
@ -38,6 +47,9 @@ public class dailySysServer {
|
||||
@Autowired
|
||||
private ISysUserWorkCountService sysUserWorkCountService;
|
||||
|
||||
@Autowired
|
||||
private IDailySourceService dailySourceService;
|
||||
|
||||
//计数当前系统用户数量并且插入daily_sys表(日期是昨天)
|
||||
// 每天凌晨2点计算一次
|
||||
// 应该是定时任务, 测试完毕后修改接口类型
|
||||
@ -85,7 +97,7 @@ public class dailySysServer {
|
||||
}
|
||||
}
|
||||
|
||||
//测试统计用户作品总数
|
||||
//测试统计用户作品总数日期是昨天
|
||||
@GetMapping("/UserWorkCount")
|
||||
public void updateUserWorkCount(){
|
||||
|
||||
@ -170,6 +182,164 @@ public class dailySysServer {
|
||||
}
|
||||
|
||||
}
|
||||
// 系统每天任务--
|
||||
// 总的用户数,用户总的在线时长, 用户总的MR在线时长, 总的购买次数,
|
||||
// 总的交互次数, 总的分享次数, 总的作品数, 总的过审作品总数,总的未过审作品总数,
|
||||
// 总的收入, 总的退款, 资源位被购买总数.
|
||||
@Transactional
|
||||
@GetMapping("/dailySys")
|
||||
public void updateDailySys(){
|
||||
LocalDate now = LocalDate.now();
|
||||
// 一天前
|
||||
LocalDate oneDayAgo = now.minusDays(1);
|
||||
|
||||
// 前天的统计daily_sys数据
|
||||
DailySys dailySys = dailySysService.selectDailySysByDate(oneDayAgo.minusDays(1));
|
||||
|
||||
// 如果他为空-----正式运行时一般不会出现这种情况, 但为了防止意外, 先判断下
|
||||
// 找前面一个不为空的daily_sys数据
|
||||
if(dailySys == null){
|
||||
int t = 2;
|
||||
while(dailySys == null){
|
||||
dailySys = dailySysService.selectDailySysByDate(oneDayAgo.minusDays(t));
|
||||
t += 1;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("前一天统计数据日期为:"+dailySys.getDate());
|
||||
|
||||
|
||||
// 每天用户总数
|
||||
Long tUser = sysUserService.getUserCount();
|
||||
System.out.println("当前用户总数为:"+tUser);
|
||||
|
||||
// 每天所有用户总的在线时长--可能会出现总时间为null的情况
|
||||
Long tOnlineTime = dailyUserService.getTotalOnlineTime(oneDayAgo);
|
||||
if(tOnlineTime == null){
|
||||
tOnlineTime = 0L;
|
||||
}
|
||||
|
||||
System.out.println("昨天用户总在线时间为:"+tOnlineTime);
|
||||
|
||||
// 上传内容总数
|
||||
Long tWork = userWorkService.getUserWorkCount("");
|
||||
System.out.println("当前用户作品数量为:"+tWork);
|
||||
|
||||
// 过审总数
|
||||
Long tPassWork = userWorkService.getUserWorkCount("3");
|
||||
System.out.println("当前用户作品过审数量为:"+tPassWork);
|
||||
|
||||
|
||||
// 退回总数
|
||||
Long tBackWork = userWorkService.getUserWorkCount("4");
|
||||
System.out.println("当前用户作品退货数量为:"+tBackWork);
|
||||
|
||||
//每天资源位统计相关
|
||||
DailySourceDto dailySourceDto = dailySourceService.getStDailySource(oneDayAgo);
|
||||
|
||||
if(dailySourceDto == null){
|
||||
dailySourceDto = new DailySourceDto();
|
||||
dailySourceDto.setInteractions(0L);
|
||||
dailySourceDto.setShares(0L);
|
||||
}
|
||||
|
||||
// 互动次数
|
||||
Long interactions = dailySourceDto.getInteractions();
|
||||
if(interactions == null){
|
||||
interactions = 0L;
|
||||
}
|
||||
|
||||
// 分享次数
|
||||
Long shares = dailySourceDto.getShares();
|
||||
if(shares == null){
|
||||
shares = 0L;
|
||||
}
|
||||
|
||||
// 总的互动次数
|
||||
Long tInteractions = dailySys.gettInteractions() + interactions;
|
||||
|
||||
// 总的分享次数
|
||||
Long tShares = dailySys.gettShares() + shares;
|
||||
|
||||
System.out.println("昨天资源位互动次数为:"+interactions+" 昨天资源位分享次数为:"+shares);
|
||||
|
||||
// 每天 收入总额, 从订单sys_order中获取
|
||||
Long tIncome = sysOrderService.getMoneybyDateAndStatus(oneDayAgo);
|
||||
if(tIncome == null){
|
||||
tIncome = 0L;
|
||||
}
|
||||
|
||||
// 每天 退款总额, 从订单中获取
|
||||
Long tRefund = sysOrderService.getRefund(oneDayAgo);
|
||||
if(tRefund == null){
|
||||
tRefund = 0L;
|
||||
}
|
||||
|
||||
System.out.println("昨天收入总额为:"+tIncome+" 昨天退款总额为:"+tRefund);
|
||||
|
||||
// 昨天的统计数据
|
||||
DailySys dailySys1 = new DailySys();
|
||||
dailySys1.setDate(oneDayAgo);
|
||||
dailySys1.settUser(tUser);
|
||||
dailySys1.settOnlineTime(tOnlineTime);
|
||||
dailySys1.settWork(tWork);
|
||||
dailySys1.settPassWork(tPassWork);
|
||||
dailySys1.settBackWork(tBackWork);
|
||||
dailySys1.settIncome(tIncome);
|
||||
dailySys1.settRefund(tRefund);
|
||||
dailySys1.settInteractions(tInteractions);
|
||||
dailySys1.settShares(tShares);
|
||||
// //----------------------------------------------测试注释-------------------------------------------------------
|
||||
// // 插入数据, 这里默认不会重复插入??
|
||||
// int back = dailySysService.insertDailySys(dailySys1);
|
||||
// if(back == 0){
|
||||
// LOGGER.info("插入昨天的统计数据失败");
|
||||
// } else{
|
||||
// LOGGER.info("插入昨天的统计数据成功");
|
||||
// }
|
||||
// //---------------------------------------------测试注释end-----------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// // 总的用户总数
|
||||
// Long tUser = sysUserCountService.getUserCount();
|
||||
//
|
||||
// // 用户总的在线时长
|
||||
// Long tOnlineTime = dailyUserService.getTotalOnlineTime(oneDayAgo);
|
||||
//
|
||||
// // 用户总的MR在线时长
|
||||
// Long tMRTime = dailyUserService.getTotalMRTime(oneDayAgo);
|
||||
|
||||
// //----------------------------------------资源位--------------------------------------------------------------------
|
||||
// // 资源位相关的查询----------成功.
|
||||
// DailySourceDto dailySourceDto = dailySourceService.getStDailySource(oneDayAgo);
|
||||
//
|
||||
// System.out.println("bought:"+dailySourceDto.getBought()+" shares: "+dailySourceDto.getShares()+" inter: "+dailySourceDto.getInteractions()+" mr: "+dailySourceDto.getuMrTime());
|
||||
//
|
||||
// //---------------------------------------资源位相关end-----------------------------------------------------------------------
|
||||
// //---------------------------------------------- 用户相关的查询----------------------------------------------------------------------------------
|
||||
// DailyUserDto dailyUserDto = dailyUserService.getStDailyUser(oneDayAgo);
|
||||
//
|
||||
// System.out.println("tUser:"+dailyUserDto.getOnlineTime()+" tOnlineTime: "+dailyUserDto.getMrTime()+" tMRTime: "+dailyUserDto.getConsumption()+" tWork: "+dailyUserDto.gettWork());
|
||||
//
|
||||
// //-------------------------------------------用户相关查询 end-----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 统计用户每天消费-- daily_user 的 consumption 属性
|
||||
|
||||
// 统计各个地区的MR在线时长
|
||||
|
||||
// 统计每天资源位的互动次数, 分享次数, 被购买总数
|
||||
}
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
|
||||
// 每天资源位统计项目
|
||||
public class DailySourceDto {
|
||||
|
||||
private Long uMrTime;
|
||||
private Long bought;
|
||||
private Long interactions;
|
||||
private Long shares;
|
||||
|
||||
public Long getuMrTime() {
|
||||
return uMrTime;
|
||||
}
|
||||
|
||||
public void setuMrTime(Long uMrTime) {
|
||||
this.uMrTime = uMrTime;
|
||||
}
|
||||
|
||||
public Long getBought() {
|
||||
return bought;
|
||||
}
|
||||
|
||||
public void setBought(Long bought) {
|
||||
this.bought = bought;
|
||||
}
|
||||
|
||||
public Long getInteractions() {
|
||||
return interactions;
|
||||
}
|
||||
|
||||
public void setInteractions(Long interactions) {
|
||||
this.interactions = interactions;
|
||||
}
|
||||
|
||||
public Long getShares() {
|
||||
return shares;
|
||||
}
|
||||
|
||||
public void setShares(Long shares) {
|
||||
this.shares = shares;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
public class DailyUserDto {
|
||||
|
||||
private Long onlineTime;
|
||||
private Long mrTime;
|
||||
private Long consumption;
|
||||
private Long tWork;
|
||||
|
||||
|
||||
public Long getOnlineTime() {
|
||||
return onlineTime;
|
||||
}
|
||||
|
||||
public void setOnlineTime(Long onlineTime) {
|
||||
this.onlineTime = onlineTime;
|
||||
}
|
||||
|
||||
public Long getMrTime() {
|
||||
return mrTime;
|
||||
}
|
||||
|
||||
public void setMrTime(Long mrTime) {
|
||||
this.mrTime = mrTime;
|
||||
}
|
||||
|
||||
public Long getConsumption() {
|
||||
return consumption;
|
||||
}
|
||||
|
||||
public void setConsumption(Long consumption) {
|
||||
this.consumption = consumption;
|
||||
}
|
||||
|
||||
public Long gettWork() {
|
||||
return tWork;
|
||||
}
|
||||
|
||||
public void settWork(Long tWork) {
|
||||
this.tWork = tWork;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,7 +1,10 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.DailySource;
|
||||
import com.ruoyi.system.domain.dto.DailySourceDto;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 资源位每天统计Mapper接口
|
||||
@ -58,4 +61,9 @@ public interface DailySourceMapper
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDailySourceByDailySourceIds(Long[] dailySourceIds);
|
||||
|
||||
/*
|
||||
* 资源位每天统计
|
||||
* */
|
||||
public DailySourceDto getStDailySource(@Param("date") LocalDate date);
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.DailyUser;
|
||||
import com.ruoyi.system.domain.SysUserOnlineTime;
|
||||
import com.ruoyi.system.domain.dto.DailyUserDto;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
@ -71,4 +72,14 @@ public interface DailyUserMapper
|
||||
public Long getTotalOnlineTime(@Param("date") LocalDate date);
|
||||
|
||||
public Long getTotalMRTime(@Param("date") LocalDate date);
|
||||
|
||||
/*
|
||||
* 返回每天资源位总的被购买次数
|
||||
* */
|
||||
public Long getTotalBought(@Param("date") LocalDate date);
|
||||
|
||||
/*
|
||||
* 系统每天统计用户相关信息
|
||||
* */
|
||||
public DailyUserDto getStDailyUser(@Param("date") LocalDate date);
|
||||
}
|
||||
|
||||
@ -70,4 +70,14 @@ public interface SysOrderMapper
|
||||
public List<OrderListDto> getOrderListDto(SysOrder sysOrder);
|
||||
|
||||
public OrderDetailDto getOrderDetailDto(@Param("orderId") Long orderId, @Param("id") Long id);
|
||||
|
||||
/*
|
||||
* 系统每天--根据日期和订单状态 计数收入/退款
|
||||
* */
|
||||
public Long getMoneybyDateAndStatus(@Param("date") LocalDate date);
|
||||
|
||||
/*
|
||||
* 系统每天--根据日期计数退款
|
||||
* */
|
||||
public Long getRefund(@Param("date") LocalDate date);
|
||||
}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.DailySource;
|
||||
import com.ruoyi.system.domain.dto.DailySourceDto;
|
||||
|
||||
/**
|
||||
* 资源位每天统计Service接口
|
||||
@ -58,4 +60,9 @@ public interface IDailySourceService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDailySourceByDailySourceId(Long dailySourceId);
|
||||
|
||||
/*
|
||||
* 资源位每天统计
|
||||
* */
|
||||
public DailySourceDto getStDailySource(LocalDate date);
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.ruoyi.system.service;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.DailyUser;
|
||||
import com.ruoyi.system.domain.dto.DailyUserDto;
|
||||
|
||||
/**
|
||||
* userDailyService接口
|
||||
@ -71,4 +72,15 @@ public interface IDailyUserService
|
||||
* 返回每天用户总的MR在线时间
|
||||
* */
|
||||
public Long getTotalMRTime(LocalDate date);
|
||||
|
||||
/*
|
||||
* 返回每天资源位总的被购买次数
|
||||
* */
|
||||
public Long getTotalBought(LocalDate date);
|
||||
|
||||
/*
|
||||
* 系统每天统计用户相关信息
|
||||
* */
|
||||
public DailyUserDto getStDailyUser(LocalDate date);
|
||||
|
||||
}
|
||||
|
||||
@ -78,4 +78,14 @@ public interface ISysOrderService
|
||||
* 营销管理--获取订单的详细信息
|
||||
* */
|
||||
public OrderDetailDto getOrderDetailDto(Long orderId, Long id);
|
||||
|
||||
/*
|
||||
* 系统每天--根据日期 计数收入
|
||||
* */
|
||||
public Long getMoneybyDateAndStatus(LocalDate date);
|
||||
|
||||
/*
|
||||
* 系统每天--根据日期计数退款
|
||||
* */
|
||||
public Long getRefund(LocalDate date);
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.system.domain.dto.DailySourceDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.DailySourceMapper;
|
||||
@ -90,4 +93,12 @@ public class DailySourceServiceImpl implements IDailySourceService
|
||||
{
|
||||
return dailySourceMapper.deleteDailySourceByDailySourceId(dailySourceId);
|
||||
}
|
||||
|
||||
/*
|
||||
* 资源位每天统计
|
||||
* */
|
||||
@Override
|
||||
public DailySourceDto getStDailySource(LocalDate date){
|
||||
return dailySourceMapper.getStDailySource(date);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.dto.DailyUserDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.DailyUserMapper;
|
||||
@ -110,4 +111,20 @@ public class DailyUserServiceImpl implements IDailyUserService
|
||||
public Long getTotalMRTime(LocalDate date){
|
||||
return dailyUserMapper.getTotalMRTime(date);
|
||||
}
|
||||
|
||||
/*
|
||||
* 返回每天资源位总的被购买次数
|
||||
* */
|
||||
@Override
|
||||
public Long getTotalBought(LocalDate date){
|
||||
return dailyUserMapper.getTotalBought(date);
|
||||
}
|
||||
|
||||
/*
|
||||
* 系统每天统计用户相关信息
|
||||
* */
|
||||
@Override
|
||||
public DailyUserDto getStDailyUser(LocalDate date){
|
||||
return dailyUserMapper.getStDailyUser(date);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,4 +110,19 @@ public class SysOrderServiceImpl implements ISysOrderService
|
||||
public OrderDetailDto getOrderDetailDto(Long orderId, Long id){
|
||||
return sysOrderMapper.getOrderDetailDto(orderId, id);
|
||||
}
|
||||
/*
|
||||
* 系统每天--根据日期和订单状态 计数收入/退款
|
||||
* */
|
||||
@Override
|
||||
public Long getMoneybyDateAndStatus(LocalDate date){
|
||||
return sysOrderMapper.getMoneybyDateAndStatus(date);
|
||||
}
|
||||
|
||||
/*
|
||||
* 系统每天--根据日期计数退款
|
||||
* */
|
||||
@Override
|
||||
public Long getRefund(LocalDate date){
|
||||
return sysOrderMapper.getRefund(date);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="date" column="date" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="DailySourceDtoResult" type="DailySourceDto">
|
||||
<result property="uMrTime" column="u_mr_time" />
|
||||
<result property="bought" column="bought" />
|
||||
<result property="interactions" column="interactions" />
|
||||
<result property="shares" column="shares" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDailySourceVo">
|
||||
select daily_source_id, source_id, u_mr_time, bought, interactions, shares, date from daily_source
|
||||
</sql>
|
||||
@ -34,7 +41,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<include refid="selectDailySourceVo"/>
|
||||
where daily_source_id = #{dailySourceId}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="getStDailySource" resultMap="DailySourceDtoResult">
|
||||
select sum(u_mr_time) u_mr_time, sum(bought) bought, sum(interactions) interactions, sum(shares) shares
|
||||
from daily_source
|
||||
where date = #{date}
|
||||
</select>
|
||||
|
||||
<insert id="insertDailySource" parameterType="DailySource" useGeneratedKeys="true" keyProperty="dailySourceId">
|
||||
insert into daily_source
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
@ -47,6 +47,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<select id="getTotalMRTime" resultType="java.lang.Long">
|
||||
select sum(mr_time) from daily_user where date = #{date}
|
||||
</select>
|
||||
<select id="getTotalBought" resultType="java.lang.Long">
|
||||
select sum(bought) from daily_source where data = #{date}
|
||||
</select>
|
||||
<select id="getStDailyUser" resultType="com.ruoyi.system.domain.dto.DailyUserDto">
|
||||
select sum(online_time) as onlineTime, sum(mr_time) as mrTime, sum(consumption) as consumption, sum(t_work) as tWork from daily_user where date = #{date}
|
||||
</select>
|
||||
|
||||
<insert id="insertDailyUser" parameterType="DailyUser" useGeneratedKeys="true" keyProperty="dailyUserId">
|
||||
insert into daily_user
|
||||
|
||||
@ -117,6 +117,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
left join user_work w on i.work_id = w.work_id
|
||||
where o.order_id = #{orderId} and i.id = #{id}
|
||||
</select>
|
||||
<select id="getMoneybyDateAndStatus" resultType="java.lang.Long">
|
||||
select sum(money)
|
||||
from sys_order
|
||||
where status != '1' and create_time = #{date} and delete_flag = '0'
|
||||
</select>
|
||||
<select id="getRefund" resultType="java.lang.Long">
|
||||
select sum(refund)
|
||||
from sys_order
|
||||
where status = '1' and create_time = #{date} and delete_flag = '0'
|
||||
</select>
|
||||
|
||||
<insert id="insertSysOrder" parameterType="SysOrder" useGeneratedKeys="true" keyProperty="orderId">
|
||||
insert into sys_order
|
||||
|
||||
Loading…
Reference in New Issue
Block a user