yujian
2019-01-14 b42e88afc77b0d40ea8bbad87df6cc22d03414e1
fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
@@ -1,7 +1,6 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -26,6 +25,7 @@
import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.OrderService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -50,6 +50,10 @@
   @Resource
   private CommonOrderService commonOrderService;
   
   @Resource
   private TaoBaoOrderService taoBaoOrderService;
   @RequestMapping(value = "getOrderList", method = RequestMethod.POST)
   public void getOrderList(int pageIndex, String key, PrintWriter out) {
@@ -63,8 +67,91 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   
   /**
    * 查询所有用户订单列表
    * @param callback
    * @param pageIndex
    * @param pageSize
    * @param uid
    * @param state
    * @param type
    * @param orderState
    * @param orderNo
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getUserOrderList")
   public void getUserOrderList(String callback, Integer pageIndex, Integer pageSize, Integer keyType,
         String key, Integer state, Integer type, Integer orderState, String startTime, String endTime,
         PrintWriter out) {
      if (pageIndex == null || pageIndex < 1) {
         pageIndex = 1;
      }
      if (pageSize == null)
         pageSize = Constant.PAGE_SIZE;
      if (state != null && state == 0) {
         state = null;// 所有状态
      }
      if (type != null && type == 0) {
         type = null; // 所有类型订单
      }
      if (endTime != null && endTime.trim().length() > 0) {
         endTime += " 23:59:59";
      }
      try {
         long count = 0;
         // 查询列表
         List<CommonOrderVO> list = commonOrderService.listQuery((pageIndex - 1) * pageSize, pageSize,
               keyType, key, state, type, orderState, startTime, endTime);
         if (list != null && list.size() > 0) {
            // 统计总数
            count = commonOrderService.countQuery(keyType, key, state, type, orderState, startTime, endTime);
         }
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (CommonOrderException e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   /**
    * 查询订单列表用户uid
    * @param callback
    * @param pageIndex
    * @param pageSize
    * @param uid
    * @param state
    * @param type
    * @param orderState
    * @param orderNo
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getHistoryOrder")
   public void getHistoryOrder(String callback, Integer pageIndex, Integer pageSize, Long uid, Integer state, Integer type, 
         Integer orderState,   String orderNo, String startTime, String endTime, PrintWriter out) {
@@ -87,6 +174,10 @@
      if (type != null && type == 0) {
         type = null; // 所有类型订单
      }
      if (endTime != null && endTime.trim().length() > 0) {
         endTime += " 23:59:59";
      }
      try {
@@ -137,110 +228,106 @@
    *            2018-12-01
    * @param out
    */
   @RequestMapping(value = "getHistoryOderByChannel")
   public void getHistoryOderByChannel(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) {
      if (StringUtil.isNullOrEmpty(channelArray)) {
         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 (dateType == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择排列方式"));
         return;
      }
      if (dateType == 1 && (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime))) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择时间区间"));
         return;
      }
      if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选结束日期"));
         return;
      }
      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;
      }
      List<String> channelList = null;
      if (channelArray != null && channelArray.trim().length() > 0) {
         Gson gson = new Gson();
         channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
      }
      if (channelList == null || channelList.size() == 0) {
         channelList = new ArrayList<String>();
         channelList.add("all");
      }
      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 {
         Gson gson = new Gson();
         List<String> list = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {
         }.getType());
         Object objectDate = null;
         List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("参数格式不正确"));
            return;
         JSONArray line_list = new JSONArray();
         for (String channel : channelList) {
            List<Map<String, Object>> list = hongBaoV2CountService.count24HOderByChannel(channel, dateType, year, startTime, endTime);
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", channel);
            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);
         }
         JSONArray array = new JSONArray();
         for (String channel : list) {
            JSONObject channelData = new JSONObject();
            List<Object> resultList = null;
            if (type == 1) {
               resultList = hongBaoService.count24HOderByChannel(channel, dateType, year, startTime, endTime);
            } else if (type == 2) {
               resultList = hongBaoService.countHistoryOderByChannel(channel, dateType, year, startTime, endTime);
            }
            if (resultList == null) {
               resultList = new ArrayList<Object>();
            }
            channelData.put("name", channel);
            channelData.put("data_list", resultList);
            array.add(channelData);
         }
         JSONObject data = new JSONObject();
         data.put("result_list", array);
         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) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 验证统计信息参数
    * @param shwoType
    * @param startTime
    * @param endTime
    * @return
    */
   public String validateParams(Integer shwoType, String startTime, String endTime) {
      if (shwoType == null) {
         return "请选择视图类型";
      }
      if (shwoType == 1 && (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime))) {
         return "请选择时间区间";
      }
      if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
         return "请选结束日期";
      }
      if (StringUtil.isNullOrEmpty(startTime) && !StringUtil.isNullOrEmpty(endTime)) {
         return "请选起始日期";
      }
      return null;
   }
   
   /**
    * 统计提现申请总次数
@@ -257,7 +344,7 @@
   public void getHongBaoNum(String callback,String channelArray, Integer dateType, Integer state,
         String year, String startTime, String endTime, PrintWriter out) {
      String validateMsg = validateParams(dateType, startTime, endTime);
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
@@ -295,7 +382,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("系统异常"));
@@ -385,7 +472,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);
@@ -423,44 +510,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));