yujian
2019-01-14 b42e88afc77b0d40ea8bbad87df6cc22d03414e1
fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
@@ -33,6 +33,7 @@
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.entity.admin.UserInfoAdmin;
import com.yeshi.fanli.entity.bus.user.AccountDetails;
import com.yeshi.fanli.entity.bus.user.Extract;
@@ -658,8 +659,6 @@
            return;
         }
         
         //double sumMoney = userInfoService.querySumMoney(key, userType, days, startTime, endTime);
         long count = userInfoService.queryCount(key, userType, days, startTime, endTime);
         int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
@@ -1189,42 +1188,99 @@
    * @param endTime   2018-12-01 
    * @param out
    */
   @RequestMapping(value = "getSameDayUserByChannel")
   public void getSameDayUserByChannel(String callback, String channelArray, Integer dateType,
   @RequestMapping(value = "getNewUserCharts")
   public void getNewUserCharts(String callback, String channelArray, Integer dateType,
       String year, String startTime, String endTime, PrintWriter out) {
      
      validateParams(callback, channelArray, dateType,year,startTime,endTime,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<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());
         if (list == null || list.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("参数格式不正确"));
            return;
         }
         Object objectDate = null;
         List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
         
         JSONArray array = new JSONArray();
         for (String channel: list) {
            JSONObject channelData = new JSONObject();
            List<Object> resultList = userActiveLogService.countSameDayByChannel(channel, dateType, year, startTime, endTime);
            if (resultList == null) {
               resultList = new ArrayList<Object>();
         JSONArray line_list = new JSONArray();
         for (String channel : channelList) {
            List<Map<String, Object>> list = userInfoCountService.countNewUserByDate(channel,
                  dateType, year, startTime, endTime);
            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(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));
         }
         
         JSONObject data = new JSONObject();
         data.put("result_list", array);
         data.put("line_list", line_list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
@@ -1243,11 +1299,9 @@
    * @param endTime   2018-12-01 
    * @param out
    */
   @RequestMapping(value = "getBuyProportion")
   public void getBuyProportion(String callback, String channelArray, Integer dateType,
   @RequestMapping(value = "getTodayBuyRate")
   public void getTodayBuyRate(String callback, String channelArray, Integer dateType,
       String year, String startTime, String endTime, Integer orderNum, PrintWriter out) {
      validateParams(callback, channelArray, dateType,year,startTime,endTime,out);
      
      if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
         startTime = null;
@@ -1268,7 +1322,9 @@
         for (String channel: list) {
            JSONObject channelData = new JSONObject();
            List<Object> resultList = userActiveLogService.getBuyProportion(channel, dateType, year, startTime, endTime, orderNum);
            List<Object> resultList = null;
                  //userActiveLogService.getBuyProportion(channel, dateType, year, startTime, endTime, orderNum);
            if (resultList == null) {
               resultList = new ArrayList<Object>();
            }
@@ -1329,8 +1385,8 @@
            JSONObject channelData = new JSONObject();
            
            List<Map<String, Object>> resultList = userActiveLogService.countOneWeekUserInfo(channel,
                  startTime, endTime, orderNum);
            List<Map<String, Object>> resultList = null;
                  //userActiveLogService.countOneWeekUserInfo(channel,    startTime, endTime, orderNum);
            if (resultList == null) {
               resultList = new ArrayList<Map<String, Object>>();
@@ -1382,96 +1438,4 @@
      
   }
   
   /**
    * 统计历史新增用户
    * @param callback
    * @param dateType 类型  1日  2月  3年
    * @param year 2018
    * @param startTime 2018-12-01
    * @param endTime   2018-12-01
    * @param out
    */
   @RequestMapping(value = "getHistoryNewUser")
   public void getHistoryNewUser(String callback, Integer dateType, String year, String startTime,
         String endTime, PrintWriter out) {
      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;
      }
      try {
         List<Object> resultList = userInfoCountService.countNewUserByDate(dateType, year, startTime, endTime);
         if (resultList == null) {
            resultList = new ArrayList<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);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   public void validateParams(String callback, String channelArray, Integer dateType,
          String year, String startTime, String endTime, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(channelArray)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择统计对应名称"));
         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;
      }
   }
}