admin
2019-01-11 3758c5dec1b37a58ea2dc2123c90415349dccee3
fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
@@ -1,6 +1,7 @@
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;
@@ -17,14 +18,18 @@
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.OrderAdmin;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
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.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
@Controller
@RequestMapping("admin/new/api/v1/order")
@@ -41,6 +46,10 @@
   
   @Resource
   private CommonOrderCountService commonOrderCountService;
   @Resource
   private CommonOrderService commonOrderService;
   @RequestMapping(value = "getOrderList", method = RequestMethod.POST)
   public void getOrderList(int pageIndex, String key, PrintWriter out) {
@@ -52,6 +61,62 @@
      data.put("pe", pe);
      data.put("orderList", JsonUtil.getSimpleGsonWithDateAndSerialization().toJson(orderAdminList));
      out.print(JsonUtil.loadTrueResult(data));
   }
   @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) {
      if (uid == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("uid不能为空"));
         return;
      }
      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; // 所有类型订单
      }
      try {
         long count = 0;
         // 查询列表
         List<CommonOrderVO> list = commonOrderService.listQueryByUid((pageIndex - 1) * pageSize, pageSize ,
               uid, state, type, orderState, orderNo, startTime, endTime, null);
         if (list != null && list.size() > 0) {
            // 统计总数
            count = commonOrderService.countQueryByUid(uid, state, type, orderState, orderNo, startTime,
                  endTime, null);
         }
         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();
      }
   }
   /**
@@ -199,7 +264,7 @@
      }
      try {
         JSONObject data = countHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
         JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
@@ -222,14 +287,15 @@
   public void getHongBaoMoney(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;
      }
      try {
         JSONObject data = countHongBao( channelArray, dateType, state, year, startTime, endTime, 2);
         JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
@@ -237,6 +303,10 @@
      }
   }
   
   
@@ -251,7 +321,7 @@
    * @return
    * @throws Exception
    */
   public JSONObject countHongBao(String channelArray, Integer dateType, Integer state, String year, String startTime,
   public JSONObject countHistoryHongBao(String channelArray, Integer dateType, Integer state, String year, String startTime,
         String endTime, int countType) throws Exception {
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
@@ -259,6 +329,7 @@
         endTime = null;
      }
      List<String> channelList = null;
      if (channelArray != null && channelArray.trim().length() > 0) {
         Gson gson = new Gson();
@@ -270,34 +341,73 @@
         channelList.add("all");
      }
      JSONArray array = new JSONArray();
      for (String channel : channelList) {
         JSONObject channelData = new JSONObject();
      if (dateType == 1 && year != null) {
         year = null; // 设置为空
      } else if (dateType == 2) {
         if (startTime != null)
            startTime = null;
         
         List<Map<String, Object>> resultList = 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();
      for (String channel : channelList) {
         List<Map<String, Object>> list = null;
         if (countType == 1 ) {
            resultList = hongBaoV2CountService.countHongBaoNum(channel, dateType, state, year,
            list = hongBaoV2CountService.countHongBaoNum(channel, dateType, state, year,
                  startTime, endTime);
         } else if (countType == 2) {
            resultList = hongBaoV2CountService.countHongBaoMoney(channel, dateType, state, year,
            list = hongBaoV2CountService.countHongBaoMoney(channel, dateType, state, year,
                  startTime, endTime);
         }
         if (resultList == null) {
            resultList = new ArrayList<Map<String, Object>>();
         }
         if ("all".equalsIgnoreCase(channel)) {
            channel = "总计";
         }
         channelData.put("name", channel);
         channelData.put("data_list", resultList);
         array.add(channelData);
         JSONObject innerList = new JSONObject();
         innerList.put("name", channel);
         if (dateType != 3) {
            innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(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();
      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);
      
      return data;
   }