Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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("----------统计以前的数据完成(老版本)-------");
    }*/
}