package com.ibeetl.admin.console.service;
|
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.json.JSON;
|
import cn.hutool.json.JSONUtil;
|
import com.ibeetl.admin.console.dao.CuserConsoleDao;
|
import com.ibeetl.admin.console.dao.EchartConsoleDao;
|
import com.ibeetl.admin.console.model.EchartModel;
|
import com.ibeetl.admin.console.model.ItemRateModel;
|
import com.ibeetl.admin.console.util.DoubleUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.text.DecimalFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 图表数据
|
*/
|
@Service
|
public class EchartResumeService {
|
/*static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
|
static SimpleDateFormat sdf6 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
|
static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
static SimpleDateFormat sdf4 = new SimpleDateFormat("yyyy");
|
static SimpleDateFormat sdf5 = new SimpleDateFormat("yyyy-MM");
|
@Autowired
|
EchartConsoleDao dao;
|
@Autowired
|
CuserConsoleDao cuserConsoleDao;
|
@Autowired
|
RedisService redisService;*/
|
// @Scheduled(cron = "0 */60 * * * ?")
|
/* @Scheduled(cron = "${charsTime}")
|
public void index() throws Exception{
|
Integer integer = dao.qeuryConfigInfo("ECHAR_X");
|
if(integer == null){
|
log.info("----------字典值配置ECHAR_X=0--------");
|
}
|
|
if(integer == 1){
|
System.out.println("======"+"我在这11111");
|
// 第一次启动
|
Date d = new Date();
|
String startTime = sdf6.format(d) + ":00";
|
String endTime = sdf6.format(d) + ":59";
|
startEchar(startTime, endTime, 1);
|
dao.updateConfigInfo("ECHAR_X");
|
}else if(integer == 0){
|
}
|
}
|
void startEchar(String startTime, String endTime, int flag){
|
log.info("--------统计任务开始执行: {}----------", sdf3.format(new Date()));
|
Date d = new Date();
|
// String startTime = sdf.format(d) + " :00:00";
|
// String endTime = sdf.format(d) + " :59:59";
|
System.out.println("===="+startTime+"===="+endTime);
|
EchartModel echartModel = moneyEchart(startTime, endTime);
|
EchartModel em = userEchart(startTime, endTime);
|
echartModel.setUserCount(em.getUserCount());
|
em = orderEchart(startTime, endTime);
|
echartModel.setOrderCount(em.getOrderCount());
|
Map<String,Object> dayCountMap = cuserConsoleDao.queryUserDayCount();
|
if(null!=dayCountMap&&null!=dayCountMap.get("userDayCount")){
|
echartModel.setVisitCount(Integer.parseInt(dayCountMap.get("userDayCount").toString()));
|
}
|
List<EchartModel> list = storageEchart(startTime, endTime);
|
if(null!=list&&list.size()>0){
|
for(EchartModel model : list){
|
echartModel.setStorageMoneyCount(model.getStorageMoneyCount());
|
echartModel.setStorageWeightCount(model.getStorageWeightCount());
|
echartModel.setSysStorageId(model.getSysStorageId());
|
if(flag == 0){
|
echartModel.setCreateTime(startTime);
|
echartModel.setDateHours(startTime);
|
}else{
|
echartModel.setCreateTime(sdf3.format(d));
|
echartModel.setDateHours(sdf.format(d)+":00:00");
|
}
|
dao.insertEchart(echartModel);
|
}
|
|
}
|
log.info("--------统计任务结束: {}----------", sdf3.format(new Date()));
|
}*/
|
/**
|
* 金钱统计
|
*/
|
/* EchartModel moneyEchart(String startTime, String endTime){
|
return dao.moneyEchart(startTime, endTime);
|
}*/
|
/**
|
* 用户统计
|
*/
|
/*
|
EchartModel userEchart(String startTime, String endTime){
|
return dao.userEchart(startTime, endTime);
|
}
|
*/
|
/**
|
* 订单统计
|
*/
|
/*
|
EchartModel orderEchart(String startTime, String endTime){
|
return dao.orderEchart(startTime, endTime);
|
}
|
*/
|
/**
|
* 库存统计
|
*/
|
/*List<EchartModel> storageEchart(String startTime, String endTime){
|
return dao.storageEchart(startTime, endTime);
|
}
|
Boolean compareDate(String dataNow,String dateRedis){
|
if(dateRedis.compareTo(dataNow) <= 0){
|
return true;
|
}
|
return false;
|
}
|
*/
|
/**
|
* 统计以前的数据
|
* 这个方法需要延时执行并且只能执行一次
|
*/
|
// @Scheduled(initialDelay = 1000*60*60*2,fixedRate = 1000*60*60*24)
|
/*@Scheduled(cron = "${charsTime}")
|
@Transactional(rollbackFor = {})
|
void indexed() throws Exception{
|
// 获取字典值的数据
|
Integer integer = dao.qeuryConfigInfo("ECHAR_FLAG");
|
if(integer == null || integer == 0){
|
log.info("--------请先配置ECHAR_FLAG的值或此任务已经执行222222--------");
|
return;
|
}
|
// 获取订单里面的第一条数据的时间
|
ItemRateModel order = dao.queryOrder();
|
if(StringUtils.isEmpty(order.getCreateTime())){
|
log.info("-------订单为0,此条件不会执行-------");
|
dao.updateConfigInfo("ECHAR_FLAG");
|
return;
|
}
|
// 获取统计表的第一条数据的时间
|
ItemRateModel model = dao.queryModel();
|
if(model == null){
|
return;
|
}
|
if(StringUtils.isEmpty(model.getCreateTime())){
|
model.setCreateTime(sdf3.format(new Date()));
|
}
|
|
Calendar calendar = Calendar.getInstance();
|
List<ItemRateModel> list = new ArrayList<>();
|
while (true){
|
calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY)-1);
|
String dataNow = sdf3.format(calendar.getTime());
|
if(!compareDate(dataNow, order.getCreateTime())){
|
log.info("----------获取的时间比订单是小,break---------");
|
break;
|
}
|
ItemRateModel irm = new ItemRateModel();
|
irm.setStartTime(sdf.format(calendar.getTime())+":00:00");
|
irm.setEndTime(sdf.format(calendar.getTime()) +":59:59");
|
list.add(irm);
|
}
|
|
log.info("-------统计以前的数据时间集合(老版本)------ {}", list.size());
|
|
for(ItemRateModel im : list){
|
startEchar(im.getStartTime(), im.getEndTime(), 0);
|
}
|
dao.updateConfigInfo("ECHAR_FLAG");
|
log.info("----------统计以前的数据完成(老版本)-------");
|
}*/
|
}
|
|
|