yujian
2019-03-25 31f64845425a6ca1b6003ba77d01bafdbdacb8e2
fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
@@ -6,9 +6,7 @@
import java.util.Map;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -21,7 +19,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.hongbao.HongBaoService;
import com.yeshi.fanli.service.inter.count.TaoBaoOrderCountService;
import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.OrderService;
@@ -31,6 +29,9 @@
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("admin/new/api/v1/order")
public class OrderAdminController {
@@ -38,8 +39,6 @@
   @Resource
   private OrderService orderService;
   @Resource
   private HongBaoService hongBaoService;
   @Resource
   private HongBaoV2CountService hongBaoV2CountService;
@@ -52,20 +51,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) {
   @RequestMapping(value = "getOrderList", method = RequestMethod.POST)
   public void getOrderList(int pageIndex, String key, PrintWriter out) {
      List<OrderAdmin> orderAdminList = hongBaoService.getOrderAdminList(pageIndex, key);
      int count = orderService.getCount(key);
      int totalPage = count % Constant.PAGE_SIZE == 0 ? count / Constant.PAGE_SIZE : count / Constant.PAGE_SIZE + 1;
      PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count, totalPage);
      JSONObject data = new JSONObject();
      data.put("pe", pe);
      data.put("orderList", JsonUtil.getSimpleGsonWithDateAndSerialization().toJson(orderAdminList));
      out.print(JsonUtil.loadTrueResult(data));
      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();
      }
   }
   
   /**
    * 查询所有用户订单列表
@@ -627,30 +651,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) {
@@ -698,33 +761,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();
      }
   }
@@ -743,34 +790,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;
   }
}