yujian
2020-04-27 885083450a1d48336337cf07fe1de24d70d3aa2b
数据统计
4个文件已修改
1171 ■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java 1132 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/hongbao/HongBaoV2CountMapper.xml 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderCountMapper.xml 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountOrderServiceImpl.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java
@@ -2,7 +2,6 @@
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -17,9 +16,6 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.controller.admin.utils.AdminUtils;
import com.yeshi.fanli.entity.admin.count.CountOrderInfo;
import com.yeshi.fanli.entity.admin.count.CountOrderTrackRate;
import com.yeshi.fanli.entity.admin.count.CountUserInfo;
import com.yeshi.fanli.entity.admin.count.DailyCountCoupon;
import com.yeshi.fanli.entity.admin.count.DailyCountMoments;
import com.yeshi.fanli.entity.admin.count.DailyCountOrder;
@@ -28,8 +24,6 @@
import com.yeshi.fanli.service.inter.count.DailyCountMomentsService;
import com.yeshi.fanli.service.inter.count.DailyCountOrderService;
import com.yeshi.fanli.service.inter.count.DailyCountUserService;
import com.yeshi.fanli.service.inter.count.UserInfoCountService;
import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
@@ -40,12 +34,6 @@
@Controller
@RequestMapping("admin/new/api/v1/countCharts")
public class CountChartsAdminController {
    @Resource
    private UserInfoCountService userInfoCountService;
    @Resource
    private CommonOrderCountService commonOrderCountService;
    
    @Resource
    private DailyCountCouponService dailyCountCouponService;
@@ -60,846 +48,6 @@
    private DailyCountMomentsService dailyCountMomentsService;
    
    
    private void verifyQueryData(String callback, Integer dateType, String year, String startTime,
            String endTime, PrintWriter out) throws Exception {
        String validateMsg = null;
        if (dateType == null) {
            validateMsg = "请选择视图类型";
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
        if (dateType == 1 && (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime))) {
            validateMsg  = "请选择时间区间";
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
    }
    private Date getBeginDate(Integer dateType, String year, String startTime) throws Exception{
        Date beginDate = null;
        if (dateType == 1) {
            beginDate = TimeUtil.parse(startTime);
        } else if (dateType == 2) {
            Calendar calendar=Calendar.getInstance();
            int currentYear = calendar.get(Calendar.YEAR);
            if (!StringUtil.isNullOrEmpty(year)) {
                currentYear = Integer.parseInt(year);
            }
            calendar.clear();
            calendar.set(Calendar.YEAR, currentYear);
            beginDate =calendar.getTime();
        } else if (dateType == 3) {
            beginDate = TimeUtil.parse("2018-01-01");
        }
        return beginDate;
    }
    private Date getEndDate(Integer dateType, String year, String endTime) throws Exception{
        Date endDate = null;
        if (dateType == 1) {
            endDate = TimeUtil.parse(endTime);
        } else if (dateType == 2) {
            Calendar calendar=Calendar.getInstance();
            int currentYear = calendar.get(Calendar.YEAR);
            if (!StringUtil.isNullOrEmpty(year)) {
                currentYear = Integer.parseInt(year);
            }
            calendar.clear();
            calendar.set(Calendar.YEAR, currentYear);
            calendar.roll(Calendar.DAY_OF_YEAR, -1);
            endDate=calendar.getTime();
        } else if (dateType == 3) {
            endDate = new Date();
        }
        return endDate;
    }
    private List<Object> machineOrderResultNum(List<String> dateList, Integer dateType, List<CountOrderInfo> listHistory) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            int value = 0;
            if (listHistory != null) {
                for (CountOrderInfo history: listHistory) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value += history.getNum();
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value +=  history.getNum();
                            continue;
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value +=  history.getNum();
                            continue;
                        }
                    }
                }
            }
            list.add(value + "");
        }
        return list;
    }
    private List<Object> machineOrderResultMoney(List<String> dateList, Integer dateType, List<CountOrderInfo> listHistory) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            BigDecimal money = new BigDecimal(0);
            if (listHistory != null) {
                for (CountOrderInfo history: listHistory) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (history.getMoney() != null) {
                                money = MoneyBigDecimalUtil.add(money, history.getMoney());
                            }
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date) && history.getMoney() != null) {
                            money = MoneyBigDecimalUtil.add(money, history.getMoney());
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (history.getMoney() != null) {
                                money = MoneyBigDecimalUtil.add(money, history.getMoney());
                            }
                        }
                    }
                }
            }
            list.add(money + "");
        }
        return list;
    }
    private List<Object> machineResultNum(List<String> dateList, Integer dateType, List<CountUserInfo> listHistory) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            int value = 0;
            if (listHistory != null) {
                for (CountUserInfo history: listHistory) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value += history.getNum();
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value +=  history.getNum();
                            continue;
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            value +=  history.getNum();
                            continue;
                        }
                    }
                }
            }
            list.add(value + "");
        }
        return list;
    }
    /**
     * 统计新人下单情况
     * @param callback
     * @param channelArray
     * @param dateType 日期类型
     * @param year
     * @param startTime
     * @param endTime
     * @param countType 统计类型: 1-当日下单 、 2-当周下单、3-当周下3单
     * @param out
     */
    @RequestMapping(value = "getNewUserDownOder")
    public void getNewUserDownOder(String callback, String channelArray, Integer dateType, String year,
            String startTime, String endTime, Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            // 渠道
            List<String> channelList = null;
            if (channelArray != null && channelArray.trim().length() > 4) {
                channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (channelList != null && channelList.size() > 0) {
                for (String channel : channelList) {
                    List<CountUserInfo> listData = null;
                    if (countType == 1) {
                        listData = userInfoCountService.countUserDownOrderByChannelAndToday(channel, beginDate, endDate);
                    } else if (countType == 2) {
                        listData = userInfoCountService.countUseByChannelAndWeekOrder(channel, beginDate, endDate);
                    } else if (countType == 3) {
                        listData = userInfoCountService.countUseByChannelAndWeekThreeOrder(channel, beginDate, endDate);
                    }
                    List<Object> list = machineResultNum(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", channel);
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            } else {
                List<CountUserInfo> listData = null;
                if (countType == 1) {
                    listData = userInfoCountService.countUserDownOrderByChannelAndToday(null, beginDate, endDate);
                } else if (countType == 2) {
                    listData = userInfoCountService.countUseByChannelAndWeekOrder(null, beginDate, endDate);
                } else if (countType == 3) {
                    listData = userInfoCountService.countUseByChannelAndWeekThreeOrder(null, beginDate, endDate);
                }
                List<Object> list = machineResultNum(dateList, dateType, listData);
                JSONObject innerList = new JSONObject();
                innerList.put("name", "全部");
                innerList.put("data", gson.toJson(list));
                line_list.add(innerList);
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     * 统计订单情况
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param countType 1-新用户24小时订单  、  2- 总订单数量
     * @param out
     */
    @RequestMapping(value = "getDownOderNum")
    public void getDownOderNum(String callback, String channelArray, Integer dateType, String year,
            String startTime, String endTime, Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            // 渠道
            List<String> channelList = null;
            if (channelArray != null && channelArray.trim().length() > 4) {
                channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (channelList != null && channelList.size() > 0) {
                for (String channel : channelList) {
                    List<CountOrderInfo> listData = null;
                    if (countType == 1) {
                        listData = userInfoCountService.count24HOderByChannel(channel, beginDate, endDate);
                    } else if (countType == 2) {
                        listData = userInfoCountService.countOderByChannel(channel, beginDate, endDate);
                    }
                    List<Object> list = machineOrderResultNum(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", channel);
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            } else {
                List<CountOrderInfo> listData = null;
                if (countType == 1) {
                    listData = userInfoCountService.count24HOderByChannel(null, beginDate, endDate);
                } else if (countType == 2) {
                    listData = userInfoCountService.countOderByChannel(null, beginDate, endDate);
                }
                List<Object> list = machineOrderResultNum(dateList, dateType, listData);
                JSONObject innerList = new JSONObject();
                innerList.put("name", "全部");
                innerList.put("data", gson.toJson(list));
                line_list.add(innerList);
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     * 统计订单佣金
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param out
     */
    @RequestMapping(value = "getCommissionMoney")
    public void getCommissionMoney(String callback, String channelArray, Integer dateType, String year,
            String startTime, String endTime, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            // 渠道
            List<String> channelList = null;
            if (channelArray != null && channelArray.trim().length() > 4) {
                channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (channelList != null && channelList.size() > 0) {
                for (String channel : channelList) {
                    List<CountOrderInfo> listData = userInfoCountService.countHongBaoByChannel(channel, beginDate, endDate);
                    List<Object> list = machineOrderResultMoney(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", channel);
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            } else {
                List<CountOrderInfo> listData = userInfoCountService.countHongBaoByChannel(null, beginDate, endDate);
                List<Object> list = machineOrderResultMoney(dateList, dateType, listData);
                JSONObject innerList = new JSONObject();
                innerList.put("name", "全部");
                innerList.put("data", gson.toJson(list));
                line_list.add(innerList);
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     *  维权订单  金额、订单号数量
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param out
     */
    @RequestMapping(value = "getWeiQuanOrderInfo")
    public void getWeiQuanOrderInfo(String callback, Integer dateType, String year,
            String startTime, String endTime, Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            JSONArray line_list = new JSONArray();
            List<Object> list = null;
            String name = "";
            if (countType == 1) {
                name = "维权数量";
                List<CountOrderInfo> listData = userInfoCountService.countWeiQuanOrder(beginDate, endDate);
                list = machineOrderResultNum(dateList, dateType, listData);
            } else if (countType == 2) {
                name = "维权金额";
                List<CountOrderInfo> listData = userInfoCountService.countWeiQuanOrderMoney(beginDate, endDate);
                list = machineOrderResultMoney(dateList, dateType, listData);
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", name);
            innerList.put("data", gson.toJson(list));
            line_list.add(innerList);
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     *    订单找回  金额、订单号数量
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param out
     */
    @RequestMapping(value = "getLostOrderInfo")
    public void getLostOrderInfo(String callback, Integer dateType, String year,
            String startTime, String endTime, Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            JSONArray line_list = new JSONArray();
            List<Object> list = null;
            String name = "";
            if (countType == 1) {
                name = "申诉数量";
                List<CountOrderInfo> listData = userInfoCountService.counOrderLastNum(beginDate, endDate);
                list = machineOrderResultNum(dateList, dateType, listData);
            } else if (countType == 2) {
                name = "申诉佣金";
                List<CountOrderInfo> listData = userInfoCountService.counOrderLastMoney(beginDate, endDate);
                list = machineOrderResultMoney(dateList, dateType, listData);
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", name);
            innerList.put("data", gson.toJson(list));
            line_list.add(innerList);
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     *    订单找回  金额、订单号数量
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param out
     */
    @RequestMapping(value = "getOrderCount")
    public void getOrderCount(String callback, Integer dateType, String year, String startTime, String endTime,
            Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            JSONArray line_list = new JSONArray();
            List<Object> list = null;
            String name = "";
            if (countType == 1) {
                name = "单数";
                List<CountOrderInfo> listData = userInfoCountService.counOrderTotalNum(beginDate, endDate);
                list = machineOrderResultNum(dateList, dateType, listData);
            } else if (countType == 2) {
                name = "佣金";
                List<CountOrderInfo> listData = userInfoCountService.counOrderTotalCommission(beginDate, endDate);
                list = machineOrderResultMoney(dateList, dateType, listData);
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", name);
            innerList.put("data", gson.toJson(list));
            line_list.add(innerList);
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     *    订单跟踪率
     * @param callback
     * @param channelArray
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param out
     */
    @RequestMapping(value = "getOrderTrackRate")
    public void getOrderTrackRate(String callback, Integer dateType, String year, String startTime, String endTime,
            Integer countType, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            JSONArray line_list = new JSONArray();
            List<CountOrderTrackRate> listHistory = commonOrderCountService.getOrderTrackRate(countType, beginDate, endDate);
            List<Object> list = new ArrayList<>();
            DecimalFormat df = new DecimalFormat("#.00");
            for (String date: dateList) {
                double proportion = 0;
                if (listHistory != null) {
                    Long upValue = 0L;
                    Long downValue = 0L;
                    for (CountOrderTrackRate history: listHistory) {
                        if (dateType == 1) {
                            String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                            if (gernalTime.equalsIgnoreCase(date)) {
                                if(history.getNum() != null)
                                    upValue = history.getNum();
                                if(history.getTotalNum() != null)
                                    downValue = history.getTotalNum();
                                continue;
                            }
                        } else if (dateType == 2){
                            String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                            if(gernalTime.startsWith("0")) {
                                gernalTime = gernalTime.substring(1, 2);
                            }
                            if (gernalTime.equalsIgnoreCase(date)) {
                                if(history.getNum() != null)
                                    upValue = history.getNum();
                                if(history.getTotalNum() != null)
                                    downValue = history.getTotalNum();
                                continue;
                            }
                        } else if (dateType == 3) {
                            String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                            if (gernalTime.equalsIgnoreCase(date)) {
                                if(history.getNum() != null)
                                    upValue = history.getNum();
                                if(history.getTotalNum() != null)
                                    downValue = history.getTotalNum();
                                continue;
                            }
                        }
                    }
                    if(downValue != 0) {
                        proportion = upValue / (double) downValue;
                    }
                }
                list.add(Double.parseDouble(df.format(proportion * 100)) + "");
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", "跟踪率");
            innerList.put("data", gson.toJson(list));
            line_list.add(innerList);
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    /**
     * 券相关图表数据
     * @param callback
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param type 查询类型
     * @param out
     */
    @RequestMapping(value = "getCouponCharts")
    public void getCouponCharts(String callback, Integer dateType, String year, String startTime, String endTime,
            String typeArray, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            // 渠道
            List<String> typelList = null;
            if (typeArray != null && typeArray.trim().length() > 4) {
                typelList = gson.fromJson(typeArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (typelList != null && typelList.size() > 0) {
                for (String type: typelList) {
                    List<DailyCountCoupon> listData = dailyCountCouponService.getDailyCountList(type, beginDate, endDate);
                    // 处理数据
                    List<Object> list = machineDailyCountCoupon(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", dailyCountCouponService.getTypeEnumDesc(type));
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    private List<Object> machineDailyCountCoupon(List<String> dateList, Integer dateType, List<DailyCountCoupon> listData) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            BigDecimal result = new BigDecimal(0);
            if (listData != null) {
                for (DailyCountCoupon history: listData) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                        }
                    }
                }
            }
            list.add(result);
        }
        return list;
    }
    /**
     * 用户相关图表数据
     * @param callback
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param type 查询类型
     * @param out
     */
    @RequestMapping(value = "getUserCharts")
    public void getUserCharts(String callback, Integer dateType, String year, String startTime, String endTime,
            String typeArray, String channelArray, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            List<String> typelList = null;
            if (typeArray != null && typeArray.trim().length() > 4) {
                typelList = gson.fromJson(typeArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            if (typelList == null || typelList.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递类型错误"));
                return;
            }
            // 渠道
            List<String> channelList = null;
            if (channelArray != null && channelArray.trim().length() > 4) {
                channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (channelList != null && channelList.size() > 0) {
                String type = typelList.get(0);
                for (String channel: channelList) {
                    List<DailyCountUser> listData = dailyCountUserService.getDailyCountList(type, beginDate, endDate, channel);
                    // 处理数据
                    List<Object> list = machineDailyCountUser(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", channel);
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            } else {
                for (String type: typelList) {
                    List<DailyCountUser> listData = dailyCountUserService.getDailyCountList(type, beginDate, endDate, null);
                    // 处理数据
                    List<Object> list = machineDailyCountUser(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", dailyCountUserService.getTypeEnumDesc(type));
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    private List<Object> machineDailyCountUser(List<String> dateList, Integer dateType, List<DailyCountUser> listData) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            BigDecimal result = new BigDecimal(0);
            if (listData != null) {
                 BigDecimal totalDay = new BigDecimal(0);
                 BigDecimal totalValid = new BigDecimal(0);
                for (DailyCountUser history: listData) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (!history.isRate()) {
                                result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            } else {
                                totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
                                totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
                            }
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (!history.isRate()) {
                                result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            } else {
                                totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
                                totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
                            }
                        }
                    }
                }
                // 判断是否计算比例
                if ((dateType == 2 || dateType == 3) && totalDay.compareTo(BigDecimal.valueOf(0)) > 0){
                    result = MoneyBigDecimalUtil.div(totalValid, totalDay);
                    result = MoneyBigDecimalUtil.mul(result, BigDecimal.valueOf(100));
                }
            }
            list.add(result);
        }
        return list;
    }
    
    
    /**
@@ -1035,6 +183,227 @@
    
    
    
    /**
     * 用户相关图表数据
     * @param callback
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param type 查询类型
     * @param out
     */
    @RequestMapping(value = "getUserCharts")
    public void getUserCharts(String callback, Integer dateType, String year, String startTime, String endTime,
            String typeArray, String channelArray, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            List<String> typelList = null;
            if (typeArray != null && typeArray.trim().length() > 4) {
                typelList = gson.fromJson(typeArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            if (typelList == null || typelList.size() == 0) {
                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("传递类型错误"));
                return;
            }
            // 渠道
            List<String> channelList = null;
            if (channelArray != null && channelArray.trim().length() > 4) {
                channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (channelList != null && channelList.size() > 0) {
                String type = typelList.get(0);
                for (String channel: channelList) {
                    List<DailyCountUser> listData = dailyCountUserService.getDailyCountList(type, beginDate, endDate, channel);
                    // 处理数据
                    List<Object> list = machineDailyCountUser(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", channel);
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            } else {
                for (String type: typelList) {
                    List<DailyCountUser> listData = dailyCountUserService.getDailyCountList(type, beginDate, endDate, null);
                    // 处理数据
                    List<Object> list = machineDailyCountUser(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", dailyCountUserService.getTypeEnumDesc(type));
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    private List<Object> machineDailyCountUser(List<String> dateList, Integer dateType, List<DailyCountUser> listData) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            BigDecimal result = new BigDecimal(0);
            if (listData != null) {
                 BigDecimal totalDay = new BigDecimal(0);
                 BigDecimal totalValid = new BigDecimal(0);
                for (DailyCountUser history: listData) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (!history.isRate()) {
                                result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            } else {
                                totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
                                totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
                            }
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            if (!history.isRate()) {
                                result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            } else {
                                totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
                                totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
                            }
                        }
                    }
                }
                // 判断是否计算比例
                if ((dateType == 2 || dateType == 3) && totalDay.compareTo(BigDecimal.valueOf(0)) > 0){
                    result = MoneyBigDecimalUtil.div(totalValid, totalDay);
                    result = MoneyBigDecimalUtil.mul(result, BigDecimal.valueOf(100));
                }
            }
            list.add(result);
        }
        return list;
    }
    /**
     * 券相关图表数据
     * @param callback
     * @param dateType
     * @param year
     * @param startTime
     * @param endTime
     * @param type 查询类型
     * @param out
     */
    @RequestMapping(value = "getCouponCharts")
    public void getCouponCharts(String callback, Integer dateType, String year, String startTime, String endTime,
            String typeArray, PrintWriter out) {
        try {
            // 数据验证处理
            verifyQueryData(callback, dateType, year, startTime, endTime, out);
            Date beginDate = getBeginDate(dateType, year, startTime);
            Date endDate = getEndDate(dateType, year, endTime);
            Gson gson = new Gson();
            List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
            // 渠道
            List<String> typelList = null;
            if (typeArray != null && typeArray.trim().length() > 4) {
                typelList = gson.fromJson(typeArray, new TypeToken<ArrayList<String>>() {}.getType());
            }
            JSONArray line_list = new JSONArray();
            if (typelList != null && typelList.size() > 0) {
                for (String type: typelList) {
                    List<DailyCountCoupon> listData = dailyCountCouponService.getDailyCountList(type, beginDate, endDate);
                    // 处理数据
                    List<Object> list = machineDailyCountCoupon(dateList, dateType, listData);
                    JSONObject innerList = new JSONObject();
                    innerList.put("name", dailyCountCouponService.getTypeEnumDesc(type));
                    innerList.put("data", gson.toJson(list));
                    line_list.add(innerList);
                }
            }
            JSONObject data = new JSONObject();
            data.put("line_list", line_list);
            data.put("xAxis_list", gson.toJson(dateList));
            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
            e.printStackTrace();
        }
    }
    private List<Object> machineDailyCountCoupon(List<String> dateList, Integer dateType, List<DailyCountCoupon> listData) {
        List<Object> list = new ArrayList<>();
        for (String date: dateList) {
            BigDecimal result = new BigDecimal(0);
            if (listData != null) {
                for (DailyCountCoupon history: listData) {
                    if (dateType == 1) {
                        String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                            continue;
                        }
                    } else if (dateType == 2){
                        String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                        if(gernalTime.startsWith("0")) {
                            gernalTime = gernalTime.substring(1, 2);
                        }
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                        }
                    } else if (dateType == 3) {
                        String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                        if (gernalTime.equalsIgnoreCase(date)) {
                            result = MoneyBigDecimalUtil.add(result, history.getTotal());
                        }
                    }
                }
            }
            list.add(result);
        }
        return list;
    }
    @RequestMapping(value = "getMomentsCharts")
    public void getMomentsCharts(String callback, Integer dateType, String year, String startTime, String endTime, 
            String typeArray, PrintWriter out) {
@@ -1115,4 +484,63 @@
        }
        return list;
    }
    private void verifyQueryData(String callback, Integer dateType, String year, String startTime,
            String endTime, PrintWriter out) throws Exception {
        String validateMsg = null;
        if (dateType == null) {
            validateMsg = "请选择视图类型";
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
        if (dateType == 1 && (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime))) {
            validateMsg  = "请选择时间区间";
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
            return;
        }
    }
    private Date getBeginDate(Integer dateType, String year, String startTime) throws Exception{
        Date beginDate = null;
        if (dateType == 1) {
            beginDate = TimeUtil.parse(startTime);
        } else if (dateType == 2) {
            Calendar calendar=Calendar.getInstance();
            int currentYear = calendar.get(Calendar.YEAR);
            if (!StringUtil.isNullOrEmpty(year)) {
                currentYear = Integer.parseInt(year);
            }
            calendar.clear();
            calendar.set(Calendar.YEAR, currentYear);
            beginDate =calendar.getTime();
        } else if (dateType == 3) {
            beginDate = TimeUtil.parse("2018-01-01");
        }
        return beginDate;
    }
    private Date getEndDate(Integer dateType, String year, String endTime) throws Exception{
        Date endDate = null;
        if (dateType == 1) {
            endDate = TimeUtil.parse(endTime);
        } else if (dateType == 2) {
            Calendar calendar=Calendar.getInstance();
            int currentYear = calendar.get(Calendar.YEAR);
            if (!StringUtil.isNullOrEmpty(year)) {
                currentYear = Integer.parseInt(year);
            }
            calendar.clear();
            calendar.set(Calendar.YEAR, currentYear);
            calendar.roll(Calendar.DAY_OF_YEAR, -1);
            endDate=calendar.getTime();
        } else if (dateType == 3) {
            endDate = new Date();
        }
        return endDate;
    }
}
fanli/src/main/java/com/yeshi/fanli/mapping/hongbao/HongBaoV2CountMapper.xml
@@ -392,22 +392,21 @@
    
    
    <select id="countOrderByTypeAndDate" resultType="Long">
        SELECT COUNT(1) FROM (SELECT ho.* FROM yeshi_ec_hongbao_order ho
            LEFT JOIN (SELECT * FROM yeshi_ec_hongbao_v2 v2
            WHERE 1=1
        SELECT COUNT(ho_id) FROM (SELECT ho.`ho_id` FROM yeshi_ec_hongbao_order ho
            LEFT JOIN (SELECT v2.`hb_id`,v2.`hb_pid` FROM yeshi_ec_hongbao_v2 v2
            <if test="orderType == 1"> <!-- 自购订单 -->
                AND (v2.hb_type =1 or v2.hb_type =2)
                WHERE v2.hb_type =1 or v2.hb_type =2
            </if>
            <if test="orderType == 2"> <!-- 分享订单 -->
                AND v2.`hb_type` = 20
                WHERE v2.`hb_type` = 20
            </if>
            <if test="orderType == 3"> <!-- 邀请订单 -->
                AND  v2.`hb_type` = 6
                WHERE  v2.`hb_type` = 6
            </if>
            )hb ON IF(hb.hb_pid IS NULL,hb.hb_id,hb.hb_pid)=ho.`ho_hongbao_id`
        LEFT JOIN yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
        WHERE hb.hb_id IS NOT NULL AND (co.`co_state`=1 OR co.`co_state`=2) 
            AND DATE_FORMAT(co.`co_third_create_time`,'%Y-%m-%d') = #{preDay}
            AND TO_DAYS(co.`co_third_create_time`) = TO_DAYS(#{preDay})
        GROUP BY co.`co_order_no`, co.`co_source_type`)A
    </select>
    
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderCountMapper.xml
@@ -327,23 +327,21 @@
    </select>
    
    <select id="countCommissionByDay" resultMap="CountOrderMap">
    SELECT co_uid AS uid ,commission FROM (
            SELECT SUM(IFNULL(d.`co_eIncome`,d.`co_estimate`)) AS commission,d.`co_uid` FROM `yeshi_ec_common_order` d
            WHERE DATE_FORMAT(d.`co_third_create_time`,'%Y-%m-%d') = #{preDay}   AND (d.`co_state`=1 OR d.`co_state`=2)
            GROUP BY d.`co_order_no`,d.`co_source_type`)A
        GROUP BY co_uid
        SELECT  SUM(IF(d.`co_eIncome` >0,d.`co_eIncome`,d.`co_estimate`)) AS commission,d.co_uid FROM `yeshi_ec_common_order` d
        WHERE TO_DAYS(d.`co_third_create_time`)= TO_DAYS(#{preDay}) AND (d.`co_state`=1 OR d.`co_state`=2)
        GROUP BY d.co_uid
    </select>
    
    <select id="countOderByDate" resultType="Integer">
        SELECT COUNT(1) FROM (SELECT d.`co_id` FROM `yeshi_ec_common_order` d
        WHERE DATE_FORMAT(d.`co_third_create_time`,'%Y-%m-%d') = #{preDay} AND (d.`co_state`=1 OR d.`co_state`=2)
        WHERE TO_DAYS(d.`co_third_create_time`)= TO_DAYS(#{preDay}) AND (d.`co_state`=1 OR d.`co_state`=2)
        GROUP BY d.`co_order_no`,d.`co_source_type`)A
    </select>
    
    
    <select id="countCommissionByDate" resultType="BigDecimal">
        SELECT SUM(IFNULL(d.`co_eIncome`,d.`co_estimate`)) FROM `yeshi_ec_common_order` d
        WHERE TO_DAYS(d.`co_third_create_time`)= TO_DAYS#{preDay}) AND (d.`co_state`=1 OR d.`co_state`=2)
        SELECT SUM(IF(d.`co_eIncome` >0,d.`co_eIncome`,d.`co_estimate`)) FROM `yeshi_ec_common_order` d
        WHERE TO_DAYS(d.`co_third_create_time`)= TO_DAYS(#{preDay}) AND (d.`co_state`=1 OR d.`co_state`=2)
    </select>
    
    <select id="countOderByUidAndLess10" resultType="Integer">
fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountOrderServiceImpl.java
@@ -134,10 +134,12 @@
            lastDate = TimeUtil.parse("2018-01-20");
        }
        long min = DateUtil.dateDiffMin(lastDate, new Date());
        if (min <= 10) { // 10分钟以内不统计
            return;
        }
//        long min = DateUtil.dateDiffMin(lastDate, new Date());
//        if (min <= 10) { // 10分钟以内不统计
//            return;
//        }
        lastDate = TimeUtil.parse("2019-10-01");
        Date today = new Date();
        int betweenDays = DateUtil.daysBetween2(lastDate, today);
@@ -296,7 +298,7 @@
     * @param typeEnum
     * @throws Exception
     */
    private void addChannelOrderMoney(String preDay, DailyCountOrderEnum typeEnum) throws Exception {
    public void addChannelOrderMoney(String preDay, DailyCountOrderEnum typeEnum) throws Exception {
        List<UserInfoRegister> listRegister = null;
        // 查询订单佣金
        List<CountOrderDTO> listOrder = commonOrderCountService.countCommissionByDay(preDay);