admin
2020-02-18 ddf5db7d31af51fcf697eac0cee7dd46ff73bcc1
fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
@@ -1,7 +1,6 @@
package com.yeshi.fanli.controller.admin;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -22,6 +21,7 @@
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.admin.count.CountUserInfo;
import com.yeshi.fanli.entity.bus.user.BindingAccount;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
@@ -891,99 +891,117 @@
   @RequestMapping(value = "getNewUserCharts")
   public void getNewUserCharts(String callback, String channelArray, Integer dateType, 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<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 {
         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;
         }
         Date beginDate = null;
         Date endDate = null;
         if (dateType == 1) {
            beginDate = TimeUtil.parse(startTime);
            endDate = TimeUtil.parse(endTime);
         } else if (dateType == 2) {
            Calendar calendar=Calendar.getInstance();
            int currentYear = calendar.get(Calendar.YEAR);
            if (!StringUtil.isNullOrEmpty(year)) {
               currentYear = Integer.parseInt(year);
            }
            calendar.clear();
             calendar.set(Calendar.YEAR, currentYear);
             beginDate =calendar.getTime();
            calendar.clear();
            calendar.set(Calendar.YEAR, currentYear);
            calendar.roll(Calendar.DAY_OF_YEAR, -1);
            endDate=calendar.getTime();
         } else if (dateType == 3) {
            beginDate = TimeUtil.parse("2018-01-01");
            endDate = new Date();
         }
         Gson gson = new Gson();
         Object objectDate = null;
         List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
         // 渠道
         List<String> channelList = null;
         if (channelArray != null && channelArray.trim().length() > 0) {
            channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {
            }.getType());
         }
         JSONArray line_list = new JSONArray();
         for (String channel : channelList) {
            List<ChartTDO> list = userInfoCountService.countNewUserByDate(channel, dateType, year,
                  startTime, endTime);
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
         if (channelList != null && channelList.size() > 0) {
            for (String channel : channelList) {
               List<Object> list = getNewUserData(dateList, dateType, beginDate, endDate, channel);
               JSONObject innerList = new JSONObject();
               innerList.put("name", channel);
               innerList.put("data", gson.toJson(list));
               line_list.add(innerList);
            }
         } else {
            List<Object> list = getNewUserData(dateList, dateType, beginDate, endDate, null);
            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")));
            }
            innerList.put("name", "全部");
            innerList.put("data", gson.toJson(list));
            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);
         data.put("xAxis_list", gson.toJson(dateList));
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("系统异常"));
         e.printStackTrace();
      }
   }
   private List<Object> getNewUserData(List<String> dateList, Integer dateType, Date beginDate, Date endDate, String channel) {
      List<Object> list = new ArrayList<>();
      List<CountUserInfo> listHistory = userInfoCountService.getNewUserData(beginDate, endDate, channel);
      for (String date: dateList) {
         int value = 0;
         if (listHistory != null) {
            for (CountUserInfo history: listHistory) {
               if (dateType == 1) {
                  String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
                  if (gernalTime.equalsIgnoreCase(date)) {
                     value += history.getNum();
                     continue;
                  }
               } else if (dateType == 2){
                  String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                  if(gernalTime.startsWith("0")) {
                     gernalTime = gernalTime.substring(1, 2);
                  }
                  if (gernalTime.equalsIgnoreCase(date)) {
                     value +=  history.getNum();
                     continue;
                  }
               } else if (dateType == 3) {
                  String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
                  if (gernalTime.equalsIgnoreCase(date)) {
                     value +=  history.getNum();
                     continue;
                  }
               }
            }
         }
         list.add(value + "");
      }
      return list;
   }
   /**
@@ -1292,6 +1310,9 @@
                     }
                  } else if (dateType == 2){
                     String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
                     if(gernalTime.startsWith("0")) {
                        gernalTime = gernalTime.substring(1, 2);
                     }
                     if (gernalTime.equalsIgnoreCase(date)) {
                        value += history.getNum();
                        continue;