admin
2019-12-06 cd637932a970e7935b17d41568fe89c92775bccc
fanli/src/main/java/com/yeshi/fanli/controller/admin/LostOrderAdminController.java
@@ -7,23 +7,25 @@
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.controller.admin.utils.AdminUtils;
import com.yeshi.fanli.dto.ChartTDO;
import com.yeshi.fanli.entity.bus.user.LostOrder;
import com.yeshi.fanli.entity.bus.user.Order;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.service.inter.order.LostOrderService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.GsonUtil;
import com.yeshi.fanli.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("admin/new/api/v1/lostOrder")
@@ -32,49 +34,6 @@
   @Resource
   private LostOrderService lostOrderService;
   @RequestMapping("findLostOrderList")
   public void findLostOrderList(int page, String key, PrintWriter out) {
      List<LostOrder> list = lostOrderService.findLostOrderList(key, page);
      int count = lostOrderService.getCount(key);
      PageEntity pe = new PageEntity(page, Constant.PAGE_SIZE, count);
      JSONObject data = new JSONObject();
      data.put("pe", pe);
      data.put("lostOrderList", GsonUtil.toJsonByUserAp(list));
      out.print(JsonUtil.loadTrueResult(data));
   }
   @RequestMapping("pass")
   public void pass(long id, PrintWriter out) {
      LostOrder lostOrder = lostOrderService.getOne(id);
      if (lostOrder == null) {
         out.print(JsonUtil.loadFalseResult("不存在该查询订单"));
         return;
      }
      if (lostOrder.getState() != 0) {
         out.print(JsonUtil.loadFalseResult("该订单已处理"));
         return;
      }
      lostOrderService.pass(lostOrder);
      out.print(JsonUtil.loadTrueResult(""));
   }
   @RequestMapping("reject")
   public void reject(long id,String reason, PrintWriter out) {
      LostOrder lostOrder = lostOrderService.getOne(id);
      if (lostOrder == null) {
         out.print(JsonUtil.loadFalseResult("不存在该查询订单"));
         return;
      }
      if (lostOrder.getState() != 0) {
         out.print(JsonUtil.loadFalseResult("该订单已处理"));
         return;
      }
      lostOrder.setRemake(reason);
      lostOrderService.reject(lostOrder);
      out.print(JsonUtil.loadTrueResult(""));
   }
   /**
    * 新版后台 列表查询
    * @param callback
@@ -84,7 +43,7 @@
    */
   @RequestMapping("query")
   public void query(String callback, Integer pageIndex, Integer pageSize, String key, Integer state, 
         Integer handleType, PrintWriter out) {
         Integer handleType, Integer type, PrintWriter out) {
      
      if (pageIndex == null || pageIndex < 0){
         pageIndex = 1;
@@ -96,7 +55,7 @@
      
      try {
         
         List<LostOrder> list = lostOrderService.listQuery((pageIndex - 1) * pageSize, pageSize, key, state, handleType);
         List<LostOrder> list = lostOrderService.listQuery((pageIndex - 1) * pageSize, pageSize, key, state, handleType, type);
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无更多数据"));
            return;
@@ -105,12 +64,35 @@
         
         for (LostOrder lostOrder: list) {
            
            Integer stateOrder = lostOrder.getState();
            Integer resultCode = lostOrder.getResultCode();
            if (stateOrder != null && stateOrder == 1 && resultCode!= null) {
               switch(resultCode) {
                  case 1:
                     lostOrder.setRemake("等待爬取中");
                     break;
                  case 2:
                     lostOrder.setRemake("处理成功");
                     break;
                  case 3:
                     lostOrder.setState(2);
                     lostOrder.setRemake("处理失败");
                     break;
                  default:
                     break;
               }
            } else if (stateOrder != null && stateOrder == 2) {
               lostOrder.setRemake("已拒绝");
            }
            Order order = lostOrder.getOrder();
            if (order == null) {
               lostOrder.setOrder(new Order());
            }
            UserInfo userInfo = lostOrder.getUserInfo();
            
            UserInfo userInfo = lostOrder.getUserInfo();
            if (userInfo == null) {
               lostOrder.setUserInfo(new UserInfo());
            } else {
@@ -122,7 +104,7 @@
            }
         }
         
         long count = lostOrderService.countQuery(key, state, handleType);
         long count = lostOrderService.countQuery(key, state, handleType, type);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         
@@ -219,34 +201,6 @@
   }
   
   
   /**
    * 验证统计信息参数
    * @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;
   }
   /**
    * 统计提现申请总次数
@@ -259,45 +213,95 @@
    * @param out
    */
   @RequestMapping(value = "getLostNum")
   public void getLostNum(String callback, Integer dateType, Integer state, String year, String startTime,
         String endTime, PrintWriter out) {
      String validateMsg = validateParams(dateType, startTime, endTime);
   public void getLostNum(String callback, Integer dateType, String stateArray, String year,
         String startTime, String endTime, PrintWriter out) {
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
      }
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
         endTime = null;
      }
      List<Integer> channelList = null;
      if (stateArray != null && stateArray.trim().length() > 0) {
         Gson gson = new Gson();
         channelList = gson.fromJson(stateArray, new TypeToken<ArrayList<Integer>>() {}.getType());
      }
      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 {
         if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
            startTime = null;
            endTime = null;
         JSONArray line_list = new JSONArray();
         if (channelList == null || channelList.size() == 0) {
         } else {
            for (Integer state : channelList) {
               List<ChartTDO> list = lostOrderService.countLostNum(dateType, state, year,
                     startTime, endTime);
               JSONObject innerList = new JSONObject();
               if (state == 1) {
                  innerList.put("name", "未处理");
               } else if (state == 2) {
                  innerList.put("name", "成功");
               } else if (state == 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);
            }
         }
         List<Map<String, Object>> resultList =lostOrderService.countLostNum(dateType, state, 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);
         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("系统异常"));
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   
   /**
@@ -313,38 +317,70 @@
   public void getAppealMoney(String callback, Integer dateType, 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;
      }
      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);
      try {
         if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
            startTime = null;
            endTime = null;
         }
         List<Map<String, Object>> resultList =lostOrderService.countAppealMoney(dateType, year, startTime, endTime);
         if (resultList == null) {
            resultList = new ArrayList<Map<String,Object>>();
         }
         JSONArray line_list = new JSONArray();
         List<ChartTDO> list = lostOrderService.countAppealMoney(dateType, year, startTime, endTime);
         JSONObject innerList = new JSONObject();
         innerList.put("name", "金额");
         innerList.put("data_list", resultList);
         JSONArray outList = new JSONArray();
         outList.add(innerList);
         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();
         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) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }