| package com.xzx.gc.order.service;  | 
|   | 
| import cn.hutool.core.collection.CollUtil;  | 
| import com.xzx.gc.common.utils.RedisUtil;  | 
| import com.xzx.gc.common.utils.SpringUtil;  | 
| import com.xzx.gc.model.admin.EchartModel;  | 
| import com.xzx.gc.model.admin.ItemRateModel;  | 
| import com.xzx.gc.order.mapper.EchartConsoleMapper;  | 
| import com.xzx.gc.order.mapper.UserLoginInfoMapper;  | 
| import com.xzx.gc.util.DoubleUtil;  | 
| import lombok.extern.slf4j.Slf4j;  | 
| 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 java.text.DecimalFormat;  | 
| import java.text.SimpleDateFormat;  | 
| import java.util.*;  | 
|   | 
| /**  | 
|  * 图表数据  | 
|  */  | 
| @Service  | 
| @Slf4j  | 
| @EnableScheduling  | 
| @Configuration  | 
| public class EchartService {  | 
|   | 
|     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  | 
|     private UserLoginInfoMapper userLoginInfoMapper;  | 
|   | 
|   | 
|     @Autowired  | 
|     EchartConsoleMapper dao;  | 
|   | 
|     @Autowired  | 
|     RedisUtil redisService;  | 
|   | 
|     public Map<String, Object> queryData(int page, int limit){  | 
|   | 
|         // 统计top数据  | 
|         EchartModel em = getTopData();  | 
|         // 按周查询统计第二栏数据  | 
|         Map<String, Object> weekMap = queryWeek();  | 
|         // 按月查询统计第二栏数据  | 
|         Map<String, Object> monthMap = queryMonth();  | 
|         // 查询仓库数据  | 
|         List<EchartModel> storageList = getStorageData(page, limit );  | 
|         // 查询物品类型的总量和占比  | 
|         Map<String, Object> itemRateDate = getItemRateDate();  | 
|         // 获取15天数据  | 
|         List<EchartModel> list = query15daydata();  | 
|   | 
|   | 
|         Map<String, Object> mx = new HashMap<>();  | 
|   | 
|         mx.put("topdata", em);  | 
|         mx.put("weekMap", weekMap);  | 
|         mx.put("monthMap", monthMap);  | 
|         mx.put("storageList", storageList);  | 
|         mx.put("itemtypeMap", itemRateDate);  | 
|         mx.put("15daydata", list);  | 
|   | 
|         //查询分类下所有入库的金额  | 
| //        String s = dao.querySumReclayMoney();  | 
| //        mx.put("reclyMoney",Convert.toBigDecimal(s));  | 
|   | 
|         return mx;  | 
|     }  | 
|   | 
|     /**  | 
|      * 获取15的数据  | 
|      * @return  | 
|      */  | 
|     List<EchartModel> query15daydata(){  | 
|         Date date = new Date();  | 
|         String startTime = dateX(date, -15)+ " 00:00:00";  | 
|         String endTime = sdf2.format(date) + " 23:59:59";  | 
|         List<EchartModel> list = dao.query15daydata(startTime, endTime);  | 
|         List<String> timelist = new ArrayList<>();  | 
|         for (int i = 0; i < 15; i++){  | 
|             timelist.add(dateX(date, -i));  | 
|         }  | 
|         boolean b = true;  | 
|         for(String time : timelist){  | 
|             b = true;  | 
|             for(EchartModel em : list){  | 
|                 if(time.equals(em.getCreateTime())){  | 
|                     b = false;  | 
|                     break;  | 
|                 }  | 
|             }  | 
|             if(b){  | 
|                 EchartModel echartModel = new EchartModel();  | 
|                 echartModel.setMoneyCount(0.0);  | 
|                 echartModel.setWeightCount(0.0);  | 
|                 echartModel.setUserCount(0);  | 
|                 echartModel.setStorageWeightCount(0.0);  | 
|                 echartModel.setStorageMoneyCount(0.0);  | 
|                 echartModel.setCreateTime(time);  | 
|                 list.add(echartModel);  | 
|             }  | 
|         }  | 
|         for(EchartModel ex : list){  | 
|             ex.setStorageWeightCount((double) Math.round(ex.getStorageWeightCount() * 100) / 100);  | 
|             ex.setWeightCount((double) Math.round(ex.getWeightCount() * 100) / 100);  | 
|         }  | 
|         list.sort((x, y) ->x.getCreateTime().compareTo(y.getCreateTime()));  | 
|         return list;  | 
|     }  | 
|   | 
|     Map<String, Object> getItemRateDate(){  | 
|         ItemRateModel model = new ItemRateModel();  | 
|         // 查询全部  | 
|         List<ItemRateModel> allList = dao.queryItemtype(model);  | 
|         allList = itemRateOp(allList, model);  | 
|         Date date = new Date();  | 
|         // 查询当年  | 
|         model.setStartTime(sdf4.format(date) + "-01-01 00:00:00");  | 
|         model.setEndTime(sdf4.format(date) + "-12-30 23:59:59");  | 
|         List<ItemRateModel> yearList = dao.queryItemtype(model);  | 
|         yearList = itemRateOp(yearList, model);  | 
|         // 查询当月  | 
|         model.setStartTime(sdf5.format(date) + "-01 00:00:00");  | 
|         model.setEndTime(sdf5.format(date) + "-30 23:59:59");  | 
|         List<ItemRateModel> monthList = dao.queryItemtype(model);  | 
|         monthList = itemRateOp(monthList, model);  | 
|         Map<String, Object> m = new HashMap<>();  | 
|         m.put("all", allList);  | 
|         m.put("year", yearList);  | 
|         m.put("month", monthList);  | 
|         if(CollUtil.isEmpty(monthList)){  | 
|             List<ItemRateModel> monthList2 = dao.queryItemtypeEmpty(model);  | 
|             m.put("month", monthList2);  | 
|         }  | 
|         return m;  | 
|     }  | 
|   | 
|     List<ItemRateModel> itemRateOp(List<ItemRateModel> list, ItemRateModel model){  | 
|         for(ItemRateModel irm : list){  | 
|             model.setStorageMoney(irm.getStorageMoney()+model.getStorageMoney());  | 
|             model.setStorageWeight(irm.getStorageWeight()+ model.getStorageWeight());  | 
|         }  | 
|         for(ItemRateModel irm : list){  | 
|             irm.setMoneyRage(DoubleUtil.divide(irm.getStorageMoney(), model.getStorageMoney()));  | 
|             irm.setWeightRage(DoubleUtil.divide(irm.getStorageWeight(), model.getStorageWeight()));  | 
|         }  | 
|         return list;  | 
|     }  | 
|   | 
|     List<EchartModel> getStorageData(int page, int limit){  | 
|         EchartModel echartModel = new EchartModel();  | 
|         echartModel.setPage(page);  | 
|         echartModel.setLimit(limit);  | 
|         // 查询入库总金额和入库总重量  | 
|         List<EchartModel> list = dao.queryDataByStorageId(echartModel);  | 
|         // 查询上周总数  | 
|         Map<String, Date> map = getLastWeek(7);  | 
|         echartModel.setStartTime(sdf2.format(map.get("monday"))+" 00:00:00");  | 
|         echartModel.setEndTime(sdf2.format(map.get("sunday"))+" 23:59:59");  | 
|         List<EchartModel> em = dao.queryDataByStorageId(echartModel);  | 
|         // 查询上上周的  | 
|         map = getLastWeek(14);  | 
|         echartModel.setStartTime(sdf2.format(map.get("monday"))+" 00:00:00");  | 
|         echartModel.setEndTime(sdf2.format(map.get("sunday"))+" 23:59:59");  | 
|         List<EchartModel> em1 = dao.queryDataByStorageId(echartModel);  | 
|         List<Map<String, Object>> temp = new ArrayList<>();  | 
|         for(EchartModel ex : em){  | 
|             for(EchartModel exx : em1){  | 
|                 if(ex.getSysStorageId().equals(exx.getSysStorageId())){  | 
|                     Map<String, Object> m  = new HashMap<>();  | 
|                     m.put("moneyRate", DoubleUtil.divide(ex.getStorageMoneyCount()-exx.getStorageMoneyCount(),exx.getStorageMoneyCount()));  | 
|                     m.put("weightRate", DoubleUtil.divide(ex.getStorageWeightCount()-exx.getStorageWeightCount(),exx.getStorageWeightCount()));  | 
|                     m.put("storage", ex.getSysStorageId());  | 
|                     temp.add(m);  | 
|                 }  | 
|             }  | 
|         }  | 
|   | 
|         for(EchartModel ex : list){  | 
|             for(Map<String, Object> li : temp){  | 
|                 if(li.get("storage").equals(ex.getSysStorageId())){  | 
|                     ex.setStorageMoneyWeekRate(Double.parseDouble(li.get("moneyRate").toString()));  | 
|                     break;  | 
|                 }  | 
|             }  | 
|   | 
|             ex.setStorageWeightCount((double) Math.round(ex.getStorageWeightCount() * 100) / 100);  | 
|         }  | 
|   | 
|         return list;  | 
|     }  | 
|   | 
|     /**  | 
|      * 获取顶部数据  | 
|      * @return  | 
|      */  | 
|     EchartModel getTopData(){  | 
|         EchartModel echartModel = new EchartModel();  | 
|         // 查询总的  | 
|         EchartModel em1 = dao.queryData(echartModel);  | 
|         // 查询今日的  | 
|         Date date = new Date();  | 
|         echartModel.setStartTime(sdf2.format(date) + " 00:00:00");  | 
|         echartModel.setEndTime(sdf2.format(date) + " 23:59:59");  | 
|         EchartModel em2 = dao.queryData(echartModel);  | 
|         DecimalFormat df = new DecimalFormat("#.00");  | 
|   | 
|         if(null!=em2){  | 
|             em1.setStorageMoneyDayCount(em2.getStorageMoneyCount());  | 
|             em1.setVisitCount(em2.getVisitCount());  | 
|             df.format(em2.getStorageWeightCount());  | 
|             em1.setStorageWeightDayCount(Double.parseDouble(df.format(em2.getStorageWeightCount())));  | 
|   | 
|         }else{  | 
|             em1.setStorageMoneyDayCount(Double.parseDouble("0"));  | 
|             em1.setVisitCount(0);  | 
|             em1.setStorageWeightDayCount(0);  | 
|         }  | 
|         //查询日活  | 
|       /*  Map<String,Object> dayCountMap = cuserConsoleDao.queryUserDayCount();  | 
|         if(null!=dayCountMap.get("userDayCount")){  | 
|             em1.setVisitCount(Integer.parseInt(dayCountMap.get("userDayCount").toString()));  | 
|         }*/  | 
|         //只要用户下了单则统计出来  | 
|         //em1.setOrderDayCount(em2.getOrderCount());  | 
|         String dayOrderCount = dao.queryOrderDayCount(echartModel);  | 
|         if(null!=dayOrderCount&&!"".equals(dayOrderCount)){  | 
|             em1.setOrderDayCount(Integer.parseInt(dayOrderCount));  | 
|   | 
|         }else{  | 
|             em1.setOrderDayCount(0);  | 
|         }  | 
|   | 
|         // 查询昨天的  | 
|         String s = dateX(date, -1);  | 
|         echartModel.setStartTime(s + " 00:00:00");  | 
|         echartModel.setEndTime(s + " 23:59:59");  | 
|         EchartModel em3 = dao.queryData(echartModel);  | 
|         // 查询前天的  | 
|         s = dateX(date, -2);  | 
|         echartModel.setStartTime(s + " 00:00:00");  | 
|         echartModel.setEndTime(s + " 23:59:59");  | 
|         EchartModel em4 = dao.queryData(echartModel);  | 
|         // 计算日环比增长率  | 
|         if(null!=em3){  | 
|             em1.setStorageMoneyDayRate(DoubleUtil.divide(em3.getStorageMoneyCount()-em4.getStorageMoneyCount(), em4.getStorageMoneyCount()));  | 
|   | 
|         }else{  | 
|             em1.setStorageMoneyDayRate(0);  | 
|         }  | 
|         // 查询上周的  | 
|         Map<String, Date> map = getLastWeek(7);  | 
|         echartModel.setStartTime(sdf2.format(map.get("monday"))+" 00:00:00");  | 
|         echartModel.setEndTime(sdf2.format(map.get("sunday"))+" 23:59:59");  | 
|         EchartModel em5 = dao.queryData(echartModel);  | 
|         // 查询上上周的  | 
|         map = getLastWeek(14);  | 
|         echartModel.setStartTime(sdf2.format(map.get("monday"))+" 00:00:00");  | 
|         echartModel.setEndTime(sdf2.format(map.get("sunday"))+" 23:59:59");  | 
|         if(null!=em5){  | 
|             EchartModel em6 = dao.queryData(echartModel);  | 
|             // 计算周环比增长  | 
|             em1.setStorageMoneyWeekRate(DoubleUtil.divide(em5.getStorageMoneyCount()-em6.getStorageMoneyCount(),em6.getStorageMoneyCount()));  | 
|   | 
|         }  | 
|   | 
|         // 计算日增长率  | 
|   | 
|         em1.setWeightCount((double) Math.round(em1.getWeightCount() * 100) / 100);  | 
|         em1.setStorageWeightCount((double) Math.round(em1.getStorageWeightCount() * 100) / 100);  | 
|   | 
|   | 
|         return em1;  | 
|     }  | 
|   | 
|     Map<String, Object> queryWeek(){  | 
|         List<Map<String, Date>> list = new ArrayList<>();  | 
|         for(int i = 0, h = 7; i <= 12; i++){  | 
|             list.add(getLastWeek(h * i));  | 
|         }  | 
|         EchartModel echartModel = new EchartModel();  | 
|         // 用户数据集合  | 
|         List<Map<String, String>> userList = new ArrayList<>();  | 
|         // 活跃量集合  | 
|         List<Map<String, String>> visitList = new ArrayList<>();  | 
|         // 订单量集合  | 
|         List<Map<String, String>> orderCountList = new ArrayList<>();  | 
|         // 订单金额总数集合  | 
|         List<Map<String, String>> orderMoneyCountList = new ArrayList<>();  | 
|         // 入库金额总数集合  | 
|         List<Map<String, String>> storageMoneyCountList = new ArrayList<>();  | 
|         // 订单重量总数集合  | 
|         List<Map<String, String>> orderWeightCountList = new ArrayList<>();  | 
|         // 入库重量总数集合  | 
|         List<Map<String, String>> storageWeightCountList = new ArrayList<>();  | 
|   | 
|   | 
|         for(Map<String, Date> map : list){  | 
|             echartModel.setStartTime(sdf2.format(map.get("monday"))+" 00:00:00");  | 
|             echartModel.setEndTime(sdf2.format(map.get("sunday"))+" 23:59:59");  | 
|             EchartModel em = dao.queryData(echartModel);  | 
|   | 
|   | 
|             if(null!=em){  | 
|                 Map<String, String> m = new HashMap<>();  | 
|                 m.put("time", sdf2.format(map.get("monday")));  | 
|                 m.put("data", em.getUserCount()+"");  | 
|                 userList.add(m);  | 
|                 Map<String, String> m2 = new HashMap<>();  | 
|                 m2.put("time", sdf2.format(map.get("monday")));  | 
|                 m2.put("data", weekVistNum(sdf2.format(map.get("monday")),sdf2.format(map.get("sunday"))));  | 
|                 visitList.add(m2);  | 
|   | 
|                 Map<String, String> m3 = new HashMap<>();  | 
|                 m3.put("time", sdf2.format(map.get("monday")));  | 
|                 m3.put("data", em.getOrderCount()+"");  | 
|                 orderCountList.add(m3);  | 
|   | 
|                 Map<String, String> m4 = new HashMap<>();  | 
|                 m4.put("time", sdf2.format(map.get("monday")));  | 
|                 m4.put("data", DoubleUtil.roundTwo(em.getMoneyCount()+""));  | 
|                 orderMoneyCountList.add(m4);  | 
|   | 
|                 Map<String, String> m5 = new HashMap<>();  | 
|                 m5.put("time", sdf2.format(map.get("monday")));  | 
|                 m5.put("data", DoubleUtil.roundTwo(em.getStorageMoneyCount()+""));  | 
|   | 
|                 storageMoneyCountList.add(m5);  | 
|   | 
|                 Map<String, String> m6 = new HashMap<>();  | 
|                 m6.put("time", sdf2.format(map.get("monday")));  | 
|                 m6.put("data", DoubleUtil.roundThree(em.getWeightCount()+""));  | 
|                 orderWeightCountList.add(m6);  | 
|   | 
|                 Map<String, String> m7 = new HashMap<>();  | 
|                 m7.put("time", sdf2.format(map.get("monday")));  | 
|                 m7.put("data", DoubleUtil.roundThree(em.getStorageWeightCount()+""));  | 
|                 storageWeightCountList.add(m7);  | 
|             }else{  | 
|                 //m.put("data", "");  | 
|             }  | 
|   | 
|   | 
|   | 
|         }  | 
|         Map<String, Object> m = new HashMap<>();  | 
|         m.put("userCountWeek", userList);  | 
|         m.put("visitCountWeek", visitList);  | 
|         m.put("orderCountWeek", orderCountList);  | 
|         m.put("orderMoneyCountWeek", orderMoneyCountList);  | 
|         m.put("storageMoneyCountWeek", storageMoneyCountList);  | 
|         m.put("orderWeightCountWeek", orderWeightCountList);  | 
|         m.put("storageWeightCountWeek", storageWeightCountList);  | 
|         return m;  | 
|     }  | 
|   | 
|   | 
|   | 
|     Map<String, Object> queryMonth(){  | 
|         List<Map<String, String>> list = new ArrayList<>();  | 
|         String[] latest12Month = getLatest12Month();  | 
|         for(String s : latest12Month){  | 
|             Map<String, String> m = new HashMap<>();  | 
|             m.put("monday", s + "-01 00:00:00");  | 
|             m.put("sunday", s + "-31 23:59:59");  | 
|             list.add(m);  | 
|         }  | 
|   | 
|   | 
|         EchartModel echartModel = new EchartModel();  | 
|         // 用户数据集合  | 
|         List<Map<String, String>> userList = new ArrayList<>();  | 
|         // 活跃量集合  | 
|         List<Map<String, String>> visitList = new ArrayList<>();  | 
|         // 订单量集合  | 
|         List<Map<String, String>> orderCountList = new ArrayList<>();  | 
|         // 订单金额总数集合  | 
|         List<Map<String, String>> orderMoneyCountList = new ArrayList<>();  | 
|         // 入库金额总数集合  | 
|         List<Map<String, String>> storageMoneyCountList = new ArrayList<>();  | 
|         // 订单重量总数集合  | 
|         List<Map<String, String>> orderWeightCountList = new ArrayList<>();  | 
|         // 入库重量总数集合  | 
|         List<Map<String, String>> storageWeightCountList = new ArrayList<>();  | 
|   | 
|         for(Map<String, String> map : list){  | 
|             echartModel.setStartTime(map.get("monday"));  | 
|             echartModel.setEndTime(map.get("sunday"));  | 
|             EchartModel em = dao.queryData(echartModel);  | 
|             if(null!=em){  | 
|                 Map<String, String> m = new HashMap<>();  | 
|                 m.put("time", map.get("monday").split(" ")[0]);  | 
|                 m.put("data", em.getUserCount()+"");  | 
|                 userList.add(m);  | 
|   | 
|                 Map<String, String> m2 = new HashMap<>();  | 
|                 m2.put("time", map.get("monday").split(" ")[0]);  | 
|                 m2.put("data", weekVistNum(map.get("monday").split(" ")[0],map.get("sunday").split(" ")[0]));  | 
|                 visitList.add(m2);  | 
|   | 
|                 Map<String, String> m3 = new HashMap<>();  | 
|                 m3.put("time", map.get("monday").split(" ")[0]);  | 
|                 m3.put("data", em.getOrderCount()+"");  | 
|                 orderCountList.add(m3);  | 
|   | 
|                 Map<String, String> m4 = new HashMap<>();  | 
|                 m4.put("time", map.get("monday").split(" ")[0]);  | 
|                 m4.put("data", em.getMoneyCount()+"");  | 
|                 orderMoneyCountList.add(m4);  | 
|   | 
|                 Map<String, String> m5 = new HashMap<>();  | 
|                 m5.put("time", map.get("monday").split(" ")[0]);  | 
|                 m5.put("data", em.getStorageMoneyCount()+"");  | 
|                 storageMoneyCountList.add(m5);  | 
|   | 
|                 Map<String, String> m6 = new HashMap<>();  | 
|                 m6.put("time", map.get("monday").split(" ")[0]);  | 
|                 m6.put("data", em.getWeightCount()+"");  | 
|                 orderWeightCountList.add(m6);  | 
|   | 
|                 Map<String, String> m7 = new HashMap<>();  | 
|                 m7.put("time", map.get("monday").split(" ")[0]);  | 
|                 m7.put("data", em.getStorageWeightCount()+"");  | 
|                 storageWeightCountList.add(m7);  | 
|             }  | 
|   | 
|         }  | 
|         Map<String, Object> m = new HashMap<>();  | 
|         m.put("userCountMonth", userList);  | 
|         m.put("visitCountMonth", visitList);  | 
|         m.put("orderCountMonth", orderCountList);  | 
|         m.put("orderMoneyCountMonth", orderMoneyCountList);  | 
|         m.put("storageMoneyCountMonth", storageMoneyCountList);  | 
|         m.put("orderWeightCountMonth", orderWeightCountList);  | 
|         m.put("storageWeightCountMonth", storageWeightCountList);  | 
|         return m;  | 
|     }  | 
|   | 
|     String weekVistNum(String startTime,String endTime){  | 
|         String haveVisit = dao.haveVisitLog(startTime,endTime);  | 
|         List<EchartModel> weekVistNum = null;  | 
|         if(null!=haveVisit&&!"".equals(haveVisit)){  | 
|             weekVistNum = dao.weekVistNum(startTime,endTime);  | 
|         }  | 
|         if(null!=weekVistNum){  | 
|             return weekVistNum.size()+"";  | 
|   | 
|         }else{  | 
|             return "0";  | 
|         }  | 
|     }  | 
|   | 
|   | 
|     /**  | 
|      * 获取前面的时间  | 
|      * @param date  | 
|      * @param days -1为前一天,-2为前2天,以此类推  | 
|      * @return  | 
|      */  | 
|     String dateX(Date date, int days){  | 
|         Calendar c = Calendar.getInstance();  | 
|         c.setTime(date);  | 
|         c.add(Calendar.DAY_OF_MONTH, days);  | 
|         Date yesterday = c.getTime();  | 
|         return sdf2.format(yesterday);  | 
|     }  | 
|   | 
|     Map<String, Date> getLastWeek(int days) {  | 
|         Map<String, Date> map = new HashMap<String, Date>();  | 
|         Calendar cal = Calendar.getInstance();  | 
|         int n = cal.get(Calendar.DAY_OF_WEEK) - 1;  | 
|         if (n == 0) {  | 
|             n = 7;  | 
|         }  | 
|         // 上周一的日期  | 
|         cal.add(Calendar.DATE, -(days + (n - 1)));  | 
|         Date monday = cal.getTime();  | 
|         map.put("monday", monday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date tuesday = cal.getTime();  | 
|         map.put("tuesday", tuesday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date wednesday = cal.getTime();  | 
|         map.put("wednesday", wednesday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date thursday = cal.getTime();  | 
|         map.put("thursday", thursday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date friday = cal.getTime();  | 
|         map.put("friday", friday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date saturday = cal.getTime();  | 
|         map.put("saturday", saturday);  | 
|   | 
|         cal.add(Calendar.DATE, 1);  | 
|         Date sunday = cal.getTime();  | 
|         map.put("sunday", sunday);  | 
|         return map;  | 
|     }  | 
|   | 
|     static String[] getLatest12Month(){  | 
|         String[] latest12Months = new String[12];  | 
|         Calendar cal = Calendar.getInstance();  | 
|         //要先+1,才能把本月的算进去  | 
|         cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)+1);  | 
|         for(int i=0; i<12; i++){  | 
|             //逐次往前推1个月  | 
|             cal.set(Calendar.MONTH, cal.get(Calendar.MONTH)-1);  | 
|             latest12Months[11-i] = cal.get(Calendar.YEAR)+ "-" +fillZero(cal.get(Calendar.MONTH)+1);  | 
|         }  | 
|         return latest12Months;  | 
|     }  | 
|     static String fillZero(int i){  | 
|         String month = "";  | 
|         if(i<10){  | 
|             month = "0" + i;  | 
|         }else{  | 
|             month = String.valueOf(i);  | 
|         }  | 
|         return month;  | 
|     }  | 
|   | 
|     /**  | 
|      * 每60分钟执行一次  | 
|      */  | 
|     @Scheduled(cron = "${charsTime}")  | 
|     public void index() throws Exception{  | 
|   | 
|         if(SpringUtil.isProd()) {  | 
|             Integer integer = dao.qeuryConfigInfo("ECHAR_X");  | 
|             if (integer == null) {  | 
|                 log.info("----------字典值配置ECHAR_X=0--------");  | 
|             }  | 
|   | 
|             if (integer == 1) {  | 
|                 // 第一次启动  | 
|                 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) {  | 
|                 // 第二次启动  | 
|                 // 查询最后一条数据的时间  | 
|                 String time = dao.queryTime();  | 
|                 log.debug("查询最后一条数据的时间===" + time);  | 
|                 //为保持时间一致,获取数据库时间。  | 
|                 String dbTime = dao.queryDbTime();  | 
|                 startEchar(time, dbTime, 1);  | 
|             }  | 
|         }  | 
|     }  | 
|   | 
|   | 
|   | 
|     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";  | 
|         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 = userLoginInfoMapper.queryUserDayCount1();  | 
|         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);  | 
|     }  | 
|   | 
|   | 
|   | 
|   | 
|   | 
| }  | 
|   | 
|   |