yujian
2019-03-12 f0fc7d2684ee50b885b7003bb06eb1663cfbaa7f
fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
@@ -6,6 +6,7 @@
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@@ -21,6 +22,7 @@
import com.yeshi.fanli.entity.admin.OrderAdmin;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.count.TaoBaoOrderCountService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
@@ -52,7 +54,45 @@
   
   @Resource
   private TaoBaoOrderService taoBaoOrderService;
   @Resource
   private TaoBaoOrderCountService taoBaoOrderCountService;
   /**
    * 统计历史订单-淘宝订单
    * @param callback
    * @param request
    * @param out
    */
   @RequestMapping(value = "countTaoBaoOrder")
   public void countTaoBaoOrder(String callback, HttpServletRequest request, PrintWriter out) {
      try {
         Map<String, Object> countByOdrerType = taoBaoOrderCountService.countByOdrerType();
         JSONObject data = new JSONObject();
         data.put("typeOrder", countByOdrerType);
         // 统计今日 未失效订单数量 相同订单号合并为一单
         int todayOrder = taoBaoOrderCountService.countToday();
         // 统计昨日 未失效订单数量 相同订单号合并为一单
         int yesterdayOrder = taoBaoOrderCountService.countYesterday();
         data.put("todayOrder", todayOrder);
         data.put("yesterdayOrder", yesterdayOrder);
         data.put("genzong", yesterdayOrder);
         data.put("yesterdayOrder", yesterdayOrder);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("统计失败"));
         e.printStackTrace();
      }
   }
   
   @RequestMapping(value = "getOrderList", method = RequestMethod.POST)
@@ -228,8 +268,8 @@
    *            2018-12-01
    * @param out
    */
   @RequestMapping(value = "getOderChannelCharts")
   public void getOderChannelCharts(String callback, String channelArray, Integer dateType, Integer type,
   @RequestMapping(value = "get24HOderChannelCharts")
   public void get24HOderChannelCharts(String callback, String channelArray, Integer dateType,
         String year, String startTime, String endTime, PrintWriter out) {
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
@@ -283,14 +323,10 @@
         List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
         JSONArray line_list = new JSONArray();
         for (String channel : channelList) {
            List<Map<String, Object>> list = null;
            if (type == 1) {
               list = hongBaoService.count24HOderByChannel(channel, dateType, year, startTime, endTime);
            List<Map<String, Object>> list = hongBaoV2CountService.count24HOderByChannel(channel, dateType, year, startTime, endTime);
            } else if (type == 2) {
               list = hongBaoService.countHistoryOderByChannel(channel, dateType, year, startTime, endTime);
            }
            
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
@@ -300,7 +336,7 @@
            innerList.put("name", channel);
            if (dateType != 3) {
               innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateList, list)));
               innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
            } else {
               // 年视图
               Map<String, Object> map = AdminUtils.yearsDataFactory(list);
@@ -386,7 +422,7 @@
      
      try {
         
         JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
         JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 2);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
@@ -476,7 +512,7 @@
         innerList.put("name", channel);
         if (dateType != 3) {
            innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateList, list)));
            innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
         } else {
            // 年视图
            Map<String, Object> map = AdminUtils.yearsDataFactory(list);
@@ -514,44 +550,101 @@
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getTypeRate")
   public void getTypeRate(String callback, Integer dateType, Integer type, String year,
   @RequestMapping(value = "getTypeNumber")
   public void getTypeNumber(String callback, Integer dateType, String typeArray, String year,
         String startTime, String endTime, PrintWriter out) {
      
      if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择正确时间区间"));
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
      }
      
      if (type == null || dateType ==null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("视图类型、订单类型不能为空"));
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
         endTime = null;
      }
      List<Integer> channelList = null;
      if (typeArray != null && typeArray.trim().length() > 0) {
         Gson gson = new Gson();
         channelList = gson.fromJson(typeArray, new TypeToken<ArrayList<Integer>>() {}.getType());
      }
      if (channelList == null || channelList.size() == 0) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("订单类型不能为空"));
         return;
      }
      if (dateType == 1 && year != null) {
         year = null; // 设置为空
      } else if (dateType == 2) {
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      } else if (dateType == 3) {
         if (year != null)
            year = null;
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      }
      Gson gson = new Gson();
      Object objectDate = null;
      List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
      
      try {
         List<Map<String, Object>> resultList = hongBaoV2CountService.getProportionByType(dateType,
               type, year, startTime, endTime);
         
         if (resultList == null) {
            resultList = new ArrayList<Map<String, Object>>();
         JSONArray line_list = new JSONArray();
         for (Integer type : channelList) {
            List<Map<String, Object>> list = hongBaoV2CountService.countHongBaoType(dateType,
                  type, year, startTime, endTime);
            JSONObject innerList = new JSONObject();
            if (type == 1) {
               innerList.put("name", "返利订单");
            } else if (type == 2) {
               innerList.put("name", "分享订单");
            } else if (type == 3) {
               innerList.put("name", "邀请订单");
            }
            if (dateType != 3) {
               innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
            } else {
               // 年视图
               Map<String, Object> map = AdminUtils.yearsDataFactory(list);
               if (objectDate == null) {
                  objectDate = map.get("date");
               }
               innerList.put("data", gson.toJson(map.get("value")));
            }
            line_list.add(innerList);
         }
         JSONObject innerList = new JSONObject();
         if (type == 1) {
            innerList.put("name", "返利订单");
         } else if (type == 2) {
            innerList.put("name", "分享订单");
         } else if (type == 3) {
            innerList.put("name", "邀请订单");
         }
         innerList.put("data_list", resultList);
         JSONArray outList = new JSONArray();
         outList.add(innerList);
         JSONObject data = new JSONObject();
         data.put("result_list", outList);
         if (objectDate != null) {
            data.put("xAxis_list", gson.toJson(objectDate));
         } else {
            data.put("xAxis_list", gson.toJson(dateList));
         }
         data.put("line_list", line_list);
         
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
@@ -574,30 +667,69 @@
   public void getTrackAccuracyRate(String callback, Integer dateType, String year,
         String startTime, String endTime, PrintWriter out) {
      
      if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择正确时间区间"));
         return;
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
         endTime = null;
      }
      if (dateType == 1 && year != null) {
         year = null; // 设置为空
      } else if (dateType == 2) {
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      } else if (dateType == 3) {
         if (year != null)
            year = null;
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      }
      
      try {
         List<Map<String, Object>> resultList = commonOrderCountService.getTrackAccuracyRate(dateType,
         Gson gson = new Gson();
         Object objectDate = null;
         List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
         JSONArray line_list = new JSONArray();
         List<Map<String, Object>> list = commonOrderCountService.getTrackAccuracyRate(dateType,
                year, startTime, endTime);
         
         if (resultList == null) {
            resultList = new ArrayList<Map<String, Object>>();
         JSONObject innerList = new JSONObject();
         innerList.put("name", "总计");
         if (dateType != 3) {
            innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
         } else {
            // 年视图
            Map<String, Object> map = AdminUtils.yearsDataFactory(list);
            if (objectDate == null) {
               objectDate = map.get("date");
            }
            innerList.put("data", gson.toJson(map.get("value")));
         }
         
         JSONObject innerList = new JSONObject();
         innerList.put("name", "准确率");
         innerList.put("data_list", resultList);
         JSONArray outList = new JSONArray();
         outList.add(innerList);
         line_list.add(innerList);
         JSONObject data = new JSONObject();
         data.put("result_list", outList);
         if (objectDate != null) {
            data.put("xAxis_list", gson.toJson(objectDate));
         } else {
            data.put("xAxis_list", gson.toJson(dateList));
         }
         
         data.put("line_list", line_list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
@@ -645,33 +777,17 @@
   public void getWeiQaunOrderNumber(String callback, Integer dateType, String year,
         String startTime, String endTime, PrintWriter out) {
      
      if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择正确时间区间"));
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
      }
      try {
         List<Map<String, Object>> resultList = commonOrderCountService.countWeiQaunOrderNumber(dateType,
                year, startTime, endTime);
         if (resultList == null) {
            resultList = new ArrayList<Map<String, Object>>();
         }
         JSONObject innerList = new JSONObject();
         innerList.put("name", "数量");
         innerList.put("data_list", resultList);
         JSONArray outList = new JSONArray();
         outList.add(innerList);
         JSONObject data = new JSONObject();
         data.put("result_list", outList);
         JSONObject data = countWeiQaunOrder(dateType, year, startTime,  endTime, 1);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
@@ -690,34 +806,103 @@
   public void getWeiQaunOrderMoney(String callback, Integer dateType, String year,
         String startTime, String endTime, PrintWriter out) {
      
      if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择正确时间区间"));
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
      }
      try {
         List<Map<String, Object>> resultList = commonOrderCountService.countWeiQaunOrderMoney(dateType,
                year, startTime, endTime);
         if (resultList == null) {
            resultList = new ArrayList<Map<String, Object>>();
         }
         JSONObject innerList = new JSONObject();
         innerList.put("name", "金额");
         innerList.put("data_list", resultList);
         JSONArray outList = new JSONArray();
         outList.add(innerList);
         JSONObject data = new JSONObject();
         data.put("result_list", outList);
         JSONObject data = countWeiQaunOrder(dateType, year, startTime,  endTime, 2);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
   
   /**
    * 统计红包信息
    * @param channelArray
    * @param dateType
    * @param state
    * @param year
    * @param startTime
    * @param endTime
    * @return
    * @throws Exception
    */
   public JSONObject countWeiQaunOrder(Integer dateType, String year, String startTime,
         String endTime, int countType) throws Exception {
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
         endTime = null;
      }
      if (dateType == 1 && year != null) {
         year = null; // 设置为空
      } else if (dateType == 2) {
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      } else if (dateType == 3) {
         if (year != null)
            year = null;
         if (startTime != null)
            startTime = null;
         if (endTime != null)
            endTime = null;
      }
      Gson gson = new Gson();
      Object objectDate = null;
      List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
      JSONArray line_list = new JSONArray();
      List<Map<String, Object>> list = null;
      if (countType == 1 ) {
         list = commonOrderCountService.countWeiQaunOrderNumber(dateType, year, startTime, endTime);
      } else if (countType == 2) {
         list = commonOrderCountService.countWeiQaunOrderMoney(dateType, year, startTime, endTime);
      }
      JSONObject innerList = new JSONObject();
      innerList.put("name", "总计");
      if (dateType != 3) {
         innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
      } else {
         // 年视图
         Map<String, Object> map = AdminUtils.yearsDataFactory(list);
         if (objectDate == null) {
            objectDate = map.get("date");
         }
         innerList.put("data", gson.toJson(map.get("value")));
      }
      line_list.add(innerList);
      JSONObject data = new JSONObject();
      if (objectDate != null) {
         data.put("xAxis_list", gson.toJson(objectDate));
      } else {
         data.put("xAxis_list", gson.toJson(dateList));
      }
      data.put("line_list", line_list);
      return data;
   }
}