yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
@@ -5,6 +5,7 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@@ -14,6 +15,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -25,10 +27,14 @@
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
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.entity.admin.UserInfoAdmin;
import com.yeshi.fanli.entity.bus.user.AccountDetails;
import com.yeshi.fanli.entity.bus.user.Extract;
import com.yeshi.fanli.entity.bus.user.HongBao;
import com.yeshi.fanli.entity.bus.user.MoneyRecord;
@@ -50,6 +56,7 @@
import com.yeshi.fanli.service.inter.user.ExtractService;
import com.yeshi.fanli.service.inter.user.MoneyRecordService;
import com.yeshi.fanli.service.inter.user.ScanHistoryService;
import com.yeshi.fanli.service.inter.user.UserActiveLogService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.tag.PageEntity;
import com.yeshi.fanli.util.Constant;
@@ -57,7 +64,6 @@
import com.yeshi.fanli.util.HongBaoUtil;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
import org.yeshi.utils.JsonUtil;
@Controller
@RequestMapping("admin/new/api/v1/user")
@@ -103,6 +109,9 @@
   
   @Resource
   private UserInfoCountService userInfoCountService;
   @Resource
   private UserActiveLogService userActiveLogService;
   
   @RequestMapping(value = "getUserList", method = RequestMethod.POST)
@@ -649,8 +658,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);
@@ -681,12 +688,8 @@
   @RequestMapping(value = "countInfo")
   public void countInfo(String callback, PrintWriter out) {
      try {
         // 总用户
         long countTotal = userInfoCountService.countNewUser(null, null);
         // 今日新增
         long countToday = userInfoCountService.countNewUser(1, null);
         // 本月新增
         long countMonth = userInfoCountService.countNewUser(null, 1);
         JSONObject data = new JSONObject();
         
         // 总数-普通用户
         long countNormal = userInfoCountService.countRank(0);
@@ -697,27 +700,43 @@
         // 总数-金用户
         long countGold = userInfoCountService.countRank(3);
         
         // 统计所有总金额
         double countTotalMoney = userInfoCountService.countAllMoney(null);
         // 统计所有可提现金额
         String minMoney = configService.get(Constant.EXTRACT_MIN_MONEY);
         if (minMoney == null)
            minMoney = "20";
         double min = Double.parseDouble(minMoney);
         double countCanAssets = userInfoCountService.countAllMoney(min);
         JSONObject data = new JSONObject();
         data.put("countTotal", countTotal);
         data.put("countToday", countToday);
         data.put("countMonth", countMonth);
         data.put("countNormal", countNormal);
         data.put("countCuprum", countCuprum);
         data.put("countSilver", countSilver);
         data.put("countGold", countGold);
         /*
         // 统计所有总金额
         BigDecimal countTotalMoney = userInfoCountService.countAllMoney(null);
         // 统计所有可提现金额
         String minMoney = configService.get(Constant.EXTRACT_MIN_MONEY);
         if (minMoney == null) {
            minMoney = "20";
         }
         double min = Double.parseDouble(minMoney);
         BigDecimal countCanAssets = userInfoCountService.countAllMoney(min);
         data.put("countTotalMoney", countTotalMoney);
         data.put("countCanAssets", countCanAssets);
         */
         // 累计用户数量
         long totalUser = userInfoCountService.countNewUser(null, null);
         // 流失用户数量(180天未使用登录并且无任何资金流动的账号数量)
         long loseUser = userInfoCountService.countLoseUser(180);
         // 累计有购买用户数
         long orderUser = userInfoCountService.countHasOrderUser();
         data.put("totalUser", totalUser);
         data.put("loseUser", loseUser);
         data.put("orderUser", orderUser);
         // 今日新增用户数量
         long todayUser = userInfoCountService.countNewUser(1, null);
         // 本月新增用户数量
         long monthUser = userInfoCountService.countNewUser(null, 1);
         data.put("todayUser", todayUser);
         data.put("monthUser", monthUser);
         
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
         
@@ -1024,10 +1043,445 @@
      }
   }
   
   public static void main(String[] args) {
   /**
    * 队员关系
    * @param pageIndex
    * @param key
    * @param state
    * @param startTime
    * @param endTime
    * @param out
    */
   @RequestMapping(value = "getRelationList")
   public void getRelationList(String callback, Integer pageIndex, Integer pageSize, Long uid, Integer type,
         Integer state, String startTime, String endTime, PrintWriter out) {
      
      java.lang.System.out.println(java.lang.System.currentTimeMillis());
      if (pageIndex == null || pageIndex < 1) {
         pageIndex = 1;
      }
      if (pageSize == null || pageSize < 1) {
         pageSize = Constant.PAGE_SIZE;
      }
      try {
         if (!StringUtil.isNullOrEmpty(endTime)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date enddate = sdf.parse(endTime);
            Calendar c = Calendar.getInstance();
            c.setTime(enddate);
            c.add(Calendar.DAY_OF_MONTH, 1);// 今天+1天
            endTime = sdf.format(c.getTime());
         }
         List<ThreeSale> listQuery = null;
         if (type == 0) {
            // 上级用户
            if (uid == null) {
               JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询上级需输入用户id"));
               return;
            }
            listQuery = threeSaleService.listSuperiorQuery((pageIndex - 1) * pageSize, pageSize, state, uid);
         } else if (type == 1) {
            // 一级用户
            listQuery = threeSaleService.listFirstTeamQuery((pageIndex - 1) * pageSize, pageSize, uid,
                  state, startTime, endTime);
         } else if (type == 2) {
            // 二级用户
            listQuery = threeSaleService.listSecondTeamQuery((pageIndex - 1) * pageSize, pageSize, uid,
                  state, startTime, endTime);
         }
         if (listQuery == null || listQuery.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
         }
         for (ThreeSale threeSale: listQuery) {
            Integer expire = threeSale.getExpire();
            if (threeSale.getState()) {
               threeSale.setExpire(1); // 邀请成功
            } else {
               if (expire != null && expire == 1) {
                  threeSale.setExpire(2); // 邀请失效
               } else {
                  threeSale.setExpire(0);// 已邀请
               }
            }
         }
         long count = 0;
         if (type == 0) {
            // 上级用户
            count = threeSaleService.countSuperiorQuery(state, uid);
         } else if (type == 1) {
            // 一级用户
            count = threeSaleService.countFirstTeamQuery(uid, state, startTime, endTime);
         } else if (type == 2) {
            // 二级用户
            count = threeSaleService.countSecondTeamQuery(uid, state, startTime, endTime);
         }
         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", listQuery);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
         e.printStackTrace();
      }
   }
   
   
}
   /**
    * 用户账户明细
    * @param callback
    * @param pageIndex
    * @param pageSize
    * @param id
    * @param out
    */
   @RequestMapping(value = "getAccountDetails")
   public void getAccountDetails(String callback, Integer pageIndex,Integer pageSize, Long uid, PrintWriter out) {
      if (pageIndex == null || pageIndex < 1) {
         pageIndex = 1;
      }
      if (pageSize == null || pageSize < 1) {
         pageSize = Constant.PAGE_SIZE;
      }
      if (uid == null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请传递正确数据"));
         return;
      }
      try {
         List<AccountDetails> detailsList = accountDetailsService.findAccountDetailsList(uid, pageIndex);
         if (detailsList == null || detailsList.size() == 0) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
            return;
         }
         int count = accountDetailsService.getCount(uid);
         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", GsonUtil.toJsonExpose(detailsList));
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         e.printStackTrace();
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
      }
   }
   /**
    * 根据渠道   统计当日新增用户数量
    * @param channelArray 名字数组
    * @param dateType 类型  1日  2月  3年
    * @param year 2018
    * @param startTime 2018-12-01
    * @param endTime   2018-12-01
    * @param out
    */
   @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 {
         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 = userInfoCountService.countNewUserByDate(channel,
                  dateType, year, startTime, endTime);
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
            }
            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));
         }
         data.put("line_list", line_list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 根据渠道   统计当日新增用户数量
    * @param channelArray 名字数组
    * @param dateType 类型  1日  2月  3年
    * @param year 2018
    * @param startTime 2018-12-01
    * @param endTime   2018-12-01
    * @param out
    */
   @RequestMapping(value = "getTodayBuyRate")
   public void getTodayBuyRate(String callback, String channelArray, Integer dateType,
       String year, String startTime, String endTime, Integer orderNum, PrintWriter out) {
      String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
      if (validateMsg != null) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
         return;
      }
      if (dateType == 2 && StringUtil.isNullOrEmpty(year)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请输入年份"));
         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();
         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 = userInfoCountService.getTodayBuyRate(channel, dateType,
                  year, startTime, endTime);
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
            }
            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));
         }
         data.put("line_list", line_list);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   /**
    * 当周产生3单的新增用户概率
    * @param callback
    * @param channelArray 渠道名称
    * @param startTime
    * @param endTime
    * @param orderNum 订单数量
    * @param out
    */
   @RequestMapping(value = "getWeekBuyRate")
   public void getWeekBuyRate(String callback, String channelArray, String startTime, String endTime,
         Integer orderNum, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(startTime) || StringUtil.isNullOrEmpty(endTime)) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("当周订单统计对应时间区域不能为空"));
         return;
      }
      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 (orderNum < 1) {
         orderNum = 1;
      }
      try {
         Gson gson = new Gson();
         List<String> dateList = AdminUtils.getDateList(1, startTime, endTime, null);
         JSONArray line_list = new JSONArray();
         for (String channel : channelList) {
            List<Object> list = userInfoCountService.getWeekBuyRate(channel, startTime, endTime,
                  orderNum, dateList);
            if ("all".equalsIgnoreCase(channel)) {
               channel = "总计";
            }
            JSONObject innerList = new JSONObject();
            innerList.put("name", channel);
            innerList.put("data", gson.toJson(list));
            line_list.add(innerList);
         }
         JSONObject data = new JSONObject();
         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("操作异常"));
         e.printStackTrace();
      }
   }
}