From e2c9fab4823b9a9a8a186951faa5a54d1f57fb1f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 17 十月 2019 14:58:29 +0800 Subject: [PATCH] 订单爬取优化 增加日志类型 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/ExtractAdminController.java | 204 +++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 166 insertions(+), 38 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ExtractAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/ExtractAdminController.java index d25c44e..3bc09fb 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ExtractAdminController.java +++ b/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,18 +15,24 @@ 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; 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.Extract; import com.yeshi.fanli.entity.bus.user.ExtractAuditRecord; import com.yeshi.fanli.entity.bus.user.HongBaoV2; @@ -36,15 +44,14 @@ import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.AdminUserService; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.count.ExtractCountService; import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; import com.yeshi.fanli.service.inter.count.UserInfoCountService; +import com.yeshi.fanli.service.inter.money.extract.ExtractAuditRecordService; +import com.yeshi.fanli.service.inter.money.extract.ExtractCountService; +import com.yeshi.fanli.service.inter.money.extract.ExtractService; +import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService; +import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService; import com.yeshi.fanli.service.inter.push.PushRecordService; -import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService; -import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService; -import com.yeshi.fanli.service.inter.user.AccountMessageService; -import com.yeshi.fanli.service.inter.user.ExtractAuditRecordService; -import com.yeshi.fanli.service.inter.user.ExtractService; import com.yeshi.fanli.tag.PageEntity; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.RedisManager; @@ -71,9 +78,6 @@ private ExtractCountService extractCountService; @Resource - private AccountMessageService accountMessageService; - - @Resource private PushRecordService pushRecordService; @Resource @@ -96,7 +100,6 @@ @Resource private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService; - /** * @@ -131,17 +134,19 @@ // 鏃ュ織璁板綍 if (integer == null) { JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("宸查�氳繃")); - LogHelper.userInfo("[ip:" + IPUtil.getRemotIP(request) + "]" + admin.getName() + "閫氳繃浜哰id=" + id + "]鐨勬彁鐜扮敵璇�!"); + LogHelper + .userInfo("[ip:" + IPUtil.getRemotIP(request) + "]" + admin.getName() + "閫氳繃浜哰id=" + id + "]鐨勬彁鐜扮敵璇�!"); } else if (integer == 1) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇ユ彁鐜拌褰曞凡涓嶅瓨鍦�,璇峰埛鏂�")); - LogHelper.userInfo("[ip:" + IPUtil.getRemotIP(request) + "][绠$悊鍛�:" + admin.getName() + "] 鍚屾剰鎻愮幇id=" + id + "鐨勬彁鐜扮敵璇蜂笉瀛樺湪"); + LogHelper.userInfo( + "[ip:" + IPUtil.getRemotIP(request) + "][绠$悊鍛�:" + admin.getName() + "] 鍚屾剰鎻愮幇id=" + id + "鐨勬彁鐜扮敵璇蜂笉瀛樺湪"); } else { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇ョ敤鎴峰凡琚鐞�,璇峰埛鏂�")); - LogHelper.userInfo("[ip:" + IPUtil.getRemotIP(request) + "][绠$悊鍛�:" + admin.getName() + "] 鍚屾剰鎻愮幇id=" + id + "鐨勬彁鐜扮敵璇风姸鎬佸紓甯�"); + LogHelper.userInfo( + "[ip:" + IPUtil.getRemotIP(request) + "][绠$悊鍛�:" + admin.getName() + "] 鍚屾剰鎻愮幇id=" + id + "鐨勬彁鐜扮敵璇风姸鎬佸紓甯�"); } } - /** * @@ -170,7 +175,6 @@ return; } - try { // 缂栫爜杞崲 reason = URLDecoder.decode(reason, "UTF-8"); @@ -179,7 +183,7 @@ } try { - + extractService.rejectExtract(id, reason, admin);// 鎻愮幇澶辫触 JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎷掔粷鎴愬姛")); @@ -201,7 +205,6 @@ } } - /** * 鑾峰彇浠婃棩鎻愮幇璁板綍锛氫粖鏃ユ�婚銆佹�绘鏁般�佹垚鍔熸鏁般�佸け璐ユ鏁� 鑾峰彇绯荤粺鎻愮幇璁板綍锛氭�婚銆佹�绘鏁� @@ -393,16 +396,39 @@ Extract extract = record.getExtract(); if (extract != null) { Integer extractState = extract.getState(); - if (extractState != null && extractState == 0) { + if (extractState != null && extractState == Extract.STATE_NOT_PROCESS) { UserInfo userInfo = extract.getUserInfo(); if (userInfo != null) { - double countTodayMoney = extractService.countTodayMoney(userInfo.getId()); - if (countTodayMoney >= 100) { + BigDecimal countTodayMoney = extractService.sumTodayApplyMoney(userInfo.getId(), + TimeUtil.getGernalTime(extract.getExtractTime())); + if (countTodayMoney.compareTo(new BigDecimal(100)) > 0) { warnLevel = 1; } } } + } + if (record.getExtraInfo() != null) { + StringBuffer desc = new StringBuffer(); + if (System.currentTimeMillis() > TimeUtil.convertToTimeTemp("2019-06-21", "yyyy-MM-dd")) { + desc.append("澶х瑪璁㈠崟鏁�:" + record.getExtraInfo().getOrderCount50More() + "\n#"); + desc.append("缁存潈璁㈠崟鏁�:" + record.getExtraInfo().getWeiQuanOrderCount() + "\n#"); + desc.append("缁存潈璁㈠崟浣i噾:" + record.getExtraInfo().getWeiQuanOrderFanAmount() + "\n#"); + if (record.getExtraInfo().getOrderCount50More() > 0 + || record.getExtraInfo().getWeiQuanOrderCount() > 1 + || record.getExtraInfo().getWeiQuanOrderFanAmount().compareTo(new BigDecimal(10)) >= 0) + warnLevel = 2; + } else { + if (record.getExtraInfo().getOrderCount50More() > 0 + || record.getExtraInfo().getWeiQuanOrderCount() > 0 + || record.getExtraInfo().getWeiQuanOrderFanAmount().compareTo(new BigDecimal(0)) > 0) + warnLevel = 2; + desc.append("澶т簬50鍏冭鍗�:" + record.getExtraInfo().getOrderCount50More() + "\n#"); + desc.append("缁存潈璁㈠崟鏁�:" + record.getExtraInfo().getWeiQuanOrderCount() + "\n#"); + desc.append("缁存潈璁㈠崟閫�鍥為噾棰�:" + record.getExtraInfo().getWeiQuanOrderFanAmount() + "\n#"); + desc.append("180澶╁畨鍏ㄨ鍗曟暟:" + record.getExtraInfo().getSafeOrderCount()); + } + record.setExtraInfoStr(desc.toString()); } record.setWarnLevel(warnLevel); } @@ -413,6 +439,8 @@ GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.serializeNulls(); + gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss"); + Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); @@ -637,6 +665,18 @@ return; } + for (ExtractAuditRecord record : list) { + + if (record.getExtraInfo() != null) { + StringBuffer desc = new StringBuffer(); + desc.append("澶т簬50鍏冭鍗�:" + record.getExtraInfo().getOrderCount50More() + "\n#"); + desc.append("缁存潈璁㈠崟鏁�:" + record.getExtraInfo().getWeiQuanOrderCount() + "\n#"); + desc.append("缁存潈璁㈠崟閫�鍥為噾棰�:" + record.getExtraInfo().getWeiQuanOrderFanAmount() + "\n#"); + desc.append("180澶╁畨鍏ㄨ鍗曟暟:" + record.getExtraInfo().getSafeOrderCount()); + record.setExtraInfoStr(desc.toString()); + } + } + int count = extractAuditRecordService.getByUidCount(uid); int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1; PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); @@ -716,7 +756,7 @@ } try { - extractService.checkExtract(uid); + extractService.checkExtract(Long.parseLong(uid)); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("璧勯噾姝e父")); } catch (ExtractException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); @@ -790,9 +830,8 @@ innerList.put("name", "椹冲洖鏁�"); } - List<Map<String, Object>> list = extractAuditRecordService.countAuditTotal(state, dateType, year, + List<ChartTDO> list = extractAuditRecordService.countAuditTotal(state, dateType, year, startTime, endTime); - if (dateType != 3) { innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list))); } else { @@ -804,7 +843,6 @@ } innerList.put("data", gson.toJson(map.get("value"))); } - line_list.add(innerList); } @@ -816,9 +854,7 @@ } data.put("line_list", line_list); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); e.printStackTrace(); @@ -844,7 +880,6 @@ @RequestMapping(value = "getExtractApplyMoney") public void getExtractApplyMoney(String callback, 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)); @@ -877,12 +912,10 @@ List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year); Gson gson = new Gson(); - JSONArray line_list = new JSONArray(); - JSONObject innerList = new JSONObject(); innerList.put("name", "鎬昏"); - List<Map<String, Object>> list = extractAuditRecordService.countExtractApplyMoney(null, dateType, year, + List<ChartTDO> list = extractAuditRecordService.countExtractApplyMoney(null, dateType, year, startTime, endTime); if (dateType != 3) { @@ -897,6 +930,7 @@ innerList.put("data", gson.toJson(map.get("value"))); } + JSONArray line_list = new JSONArray(); line_list.add(innerList); JSONObject data = new JSONObject(); @@ -907,9 +941,7 @@ } data.put("line_list", line_list); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); - } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); e.printStackTrace(); @@ -937,7 +969,6 @@ @RequestMapping(value = "getExtractApplyNumber") public void getExtractApplyNumber(String callback, Integer state, 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)); @@ -965,17 +996,15 @@ } try { - Object objectDate = null; + Gson gson = new Gson(); List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year); - Gson gson = new Gson(); - JSONArray line_list = new JSONArray(); JSONObject innerList = new JSONObject(); innerList.put("name", "鎬昏"); - List<Map<String, Object>> list = extractAuditRecordService.countExtractApplyNumber(null, dateType, year, + List<ChartTDO> list = extractAuditRecordService.countExtractApplyNumber(null, dateType, year, startTime, endTime); if (dateType != 3) { @@ -990,6 +1019,7 @@ innerList.put("data", gson.toJson(map.get("value"))); } + JSONArray line_list = new JSONArray(); line_list.add(innerList); JSONObject data = new JSONObject(); @@ -1000,9 +1030,107 @@ } data.put("line_list", line_list); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父")); + 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(); -- Gitblit v1.8.0