yujian
2019-10-16 c91ccd847a5c31391ddd41b3e464bc2ca02b7ac6
fanli/src/main/java/com/yeshi/fanli/controller/admin/ExtractAdminController.java
@@ -1,8 +1,10 @@
package com.yeshi.fanli.controller.admin;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -13,12 +15,18 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.yeshi.utils.CsvUtil;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.IPUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.entity.wx.RedPackRecord;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -1028,5 +1036,105 @@
         e.printStackTrace();
      }
   }
   @RequestMapping(value = "downAutoExtractTxt")
   public void downAutoExtractTxt(String callback, HttpServletResponse response, PrintWriter out) {
      try {
         List<String> list = extractService.getAutoExtractOpenIds();
         if (list == null || list.size() <= 1) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无用户满足自动提现条件"));
            return;
         }
         String filepath = "自动提现OpenId "+ java.lang.System.currentTimeMillis() + ".txt";
         response.reset();
          response.setContentType("application/octet-stream");
          String fileName= URLDecoder.decode(filepath,"utf-8");
          response.addHeader("Content-Disposition","attachment;"+ "filename=\"" +URLEncoder.encode(fileName, "utf-8") + "\"");
         StringBuilder sb = new StringBuilder();
         for(String t:list){
            sb.append(t+"\r\n");
         }
         String opid_str = sb.toString();
         if (!StringUtil.isNullOrEmpty(opid_str) && opid_str.endsWith("\r\n")) {
            opid_str = opid_str.substring(0, opid_str.length() - 2);
         }
          OutputStream os = response.getOutputStream();
            byte[] byt = opid_str.getBytes();
            os.write(byt);
            os.flush();
          os.close();
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
   @RequestMapping(value = "uploadExcel", method = RequestMethod.POST)
   public void uploadExcel(@RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
      if (file == null) {
         out.print(JsonUtil.loadFalseResult("上传文件不能为空!"));
         return;
      }
      try {
         List<RedPackRecord> list = CsvUtil.getCsvData(file, RedPackRecord.class);
         extractService.updateManualExtractRecord(list);
         out.print(JsonUtil.loadTrueResult("上传成功"));
      } catch (ExtractException e) {
         out.print(JsonUtil.loadFalseResult(e.getMsg()));
      } catch (Exception e) {
         e.printStackTrace();
         out.print(JsonUtil.loadFalseResult("上传失败"));
      }
   }
   @RequestMapping(value = "preAutoUser")
   public void preAutoUser(String callback, Integer pageIndex, Integer pageSize, PrintWriter out) {
      try {
         List<UserInfo> list = extractService.preAutoUser();
         if (list == null || list.isEmpty()) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无用户满足自动提现条件"));
            return;
         }
         if (pageIndex == null || pageIndex < 1) {
            pageIndex = 1;
         }
         if (pageSize == null || pageSize < 1) {
            pageSize = Constant.PAGE_SIZE;
         }
         int count = list.size();
         int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
         PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
         List<UserInfo> listResult = null;
         if (pageIndex < totalPage) {
            int start = (pageIndex - 1) * pageSize;
            listResult = list.subList(start, start + pageSize);
         } else if (pageIndex == totalPage) {
             listResult = list.subList((pageIndex - 1) * pageSize, list.size());
         } else {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("没有更多了"));
            return;
         }
         JSONObject data = new JSONObject();
         data.put("pe", pe);
         data.put("result_list", listResult);
         JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
         e.printStackTrace();
      }
   }
}