yujian
2019-01-16 e5ade1fdbd87e085f5be5460c6e3f0adb47704e6
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;
@@ -30,7 +32,6 @@
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import com.yeshi.fanli.vo.order.TaoBaoOrderVO;
@Controller
@RequestMapping("admin/new/api/v1/order")
@@ -53,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)
@@ -68,9 +107,8 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   
   /**
    * 淘宝订单
    * 查询所有用户订单列表
    * @param callback
    * @param pageIndex
    * @param pageSize
@@ -83,16 +121,25 @@
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getTBOrder")
   public void getTBOrder(String callback, Integer pageIndex, Integer keyType,
         String key, Integer state, String startTime, String endTime,  PrintWriter 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) {
@@ -100,46 +147,24 @@
      }
      try {
         long count = 0;
         int pageSize = Constant.PAGE_SIZE;
         List<TaoBaoOrderVO> listVO = null;
         if (key != null && key.trim().length() > 0 && keyType == 2) {
            // 查询列表
            List<CommonOrderVO> list = commonOrderService.listQueryByUid((pageIndex - 1) * pageSize, pageSize ,
                  Long.parseLong(key), state, null, null, null, startTime, endTime, null);
            if (list == null || list.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
               return;
            }
            // 统计总数
            count = commonOrderService.countQueryByUid(Long.parseLong(key), state, null, null, null, startTime, endTime, null);
         } else {
            List<TaoBaoOrderVO> listQuery = taoBaoOrderService.listQuery((pageIndex - 1) * pageSize, pageSize, key, startTime, endTime, state);
            if (listQuery == null || listQuery.size() == 0) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
               return;
            }
            count= taoBaoOrderService.countQuery(key, startTime, endTime, state);
         }
         // 查询列表
         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", listVO);
         data.put("result_list", list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
@@ -150,9 +175,23 @@
         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) {
@@ -229,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);
@@ -284,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 = "总计";
@@ -301,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);
@@ -387,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("系统异常"));
@@ -477,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);
@@ -515,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));
@@ -575,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) {
@@ -646,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();
      }
   }
@@ -691,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;
   }
}