From 554de444b87aab5f93cb1593a8095612cf9479a7 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期二, 09 六月 2020 17:34:30 +0800 Subject: [PATCH] 订单 --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PreviewInfoControllerV2.java | 180 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 138 insertions(+), 42 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PreviewInfoControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PreviewInfoControllerV2.java index fd3361b..168319d 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PreviewInfoControllerV2.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/PreviewInfoControllerV2.java @@ -4,8 +4,11 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; import javax.annotation.Resource; @@ -15,20 +18,28 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import com.yeshi.fanli.dto.push.PushContentDTO; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.user.Extract; +import com.yeshi.fanli.entity.bus.user.PayInfo; import com.yeshi.fanli.entity.bus.user.PreviewInfo; import com.yeshi.fanli.entity.bus.user.PreviewInfo.PreviewEnum; import com.yeshi.fanli.entity.bus.user.UserInfo; +import com.yeshi.fanli.entity.config.push.PushMsgFactory; import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum; import com.yeshi.fanli.entity.order.OrderMoneyDailyCount; +import com.yeshi.fanli.exception.push.PushException; import com.yeshi.fanli.exception.user.PreviewInfoException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.count.HongBaoV2CountService; import com.yeshi.fanli.service.inter.money.UserMoneyDetailService; +import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.order.OrderMoneyDailyCountService; +import com.yeshi.fanli.service.inter.push.PushService; +import com.yeshi.fanli.service.inter.user.PayInfoService; import com.yeshi.fanli.service.inter.user.PreviewInfoService; import com.yeshi.fanli.service.inter.user.UserInfoService; +import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; @@ -52,17 +63,25 @@ @Resource private RedisManager redisManager; - + @Resource private HongBaoV2CountService hongBaoV2CountService; - + @Resource private UserMoneyDetailService userMoneyDetailService; - + @Resource private OrderMoneyDailyCountService orderMoneyDailyCountService; + + @Resource + private CommonOrderService commonOrderService; + + @Resource + private PushService pushService; - + @Resource + private PayInfoService payInfoService; + /** * 淇濆瓨璧勯噾淇℃伅 * @@ -86,7 +105,6 @@ } } - @RequestMapping(value = "getMoneyInfo") public void getMoneyInfo(String callback, AcceptData acceptData, Long uid, PrintWriter out) { MoneyStatisticVO dto = null; @@ -206,7 +224,7 @@ vo.setMonthPredict(cratePredictVO(orderMoneyDailyCountService.query(uid, minDate, maxDate))); return vo; } - + private MoneyPredictVO cratePredictVO(List<OrderMoneyDailyCount> list) { MoneyPredictVO predictVO = new MoneyPredictVO(); predictVO.setMineNum(0); @@ -232,7 +250,7 @@ predictVO.setTotalMoney(predictVO.getMineMoney().add(predictVO.getTeamMoney())); return predictVO; } - + /** * 淇濆瓨鎻愮幇璁板綍 * @@ -251,10 +269,10 @@ } try { previewInfoService.saveExtractRecord(uid, dayTime, money); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇濆瓨鎴愬姛")); } catch (PreviewInfoException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇濆瓨鎴愬姛")); } @RequestMapping(value = "getExtractRecord") @@ -263,14 +281,14 @@ PreviewInfo previewInfo = previewInfoService.get(uid, PreviewEnum.extractRecord); if (previewInfo != null && !StringUtil.isNullOrEmpty(previewInfo.getContent())) { Gson gson = new Gson(); - list = gson.fromJson(previewInfo.getContent(), new TypeToken<ArrayList<Extract>>() {}.getType()); + list = gson.fromJson(previewInfo.getContent(), new TypeToken<ArrayList<Extract>>() { + }.getType()); } - + if (list == null) list = new ArrayList<>(); JSONArray JSONArray = new JSONArray(); - if (list.size() > 0) { for (Extract extract : list) { Date receiveTime = extract.getReceiveTime(); @@ -288,14 +306,13 @@ JSONArray.add(object); } } - JSONObject json = new JSONObject(); json.put("count", JSONArray.size()); json.put("list", JSONArray); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(json)); } - + /** * 鍒犻櫎鎻愮幇璁板綍 * @@ -319,7 +336,7 @@ e.printStackTrace(); } } - + /** * 鍒犻櫎鎻愮幇璁板綍 * @@ -349,7 +366,7 @@ * @param out */ @RequestMapping(value = "saveMineInfo") - public void saveMineInfo(String callback, AcceptData acceptData, MineInfoVO infoVO, PrintWriter out) { + public void saveMineInfo(String callback, AcceptData acceptData, MineInfoVO infoVO, PrintWriter out) { if (infoVO == null || infoVO.getUid() == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); return; @@ -357,22 +374,25 @@ try { previewInfoService.saveMineInfo(infoVO); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇濆瓨鎴愬姛")); + } catch (PreviewInfoException e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { LogHelper.errorDetailInfo(e); JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇濆瓨澶辫触")); } } - + @RequestMapping(value = "getMineInfo") public void getMineInfo(String callback, AcceptData acceptData, Long uid, PrintWriter out) { PreviewInfo previewInfo = previewInfoService.get(uid, PreviewEnum.mineInfo); - if (previewInfo == null || StringUtil.isNullOrEmpty(previewInfo.getContent())) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁")); - return; + MineInfoVO dto = null; + if (previewInfo != null && !StringUtil.isNullOrEmpty(previewInfo.getContent())) { + dto = new Gson().fromJson(previewInfo.getContent(), MineInfoVO.class); } - - MineInfoVO dto = new Gson().fromJson(previewInfo.getContent(), MineInfoVO.class); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(dto)); + + if (dto == null) + dto = new MineInfoVO(); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(dto))); } /** @@ -388,35 +408,43 @@ */ @RequestMapping(value = "saveMoneyArrival") public void saveMoneyArrival(String callback, AcceptData acceptData, Long uid, BigDecimal money, String dayTime, - String orderNo, PrintWriter out) { - if (uid == null) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); - return; - } - + PrintWriter out) { try { - String link = previewInfoService.saveMoneyArrival(uid, money, dayTime, orderNo); + // 鏌ヨ鏈�鏂颁竴鏉℃敮浠樺疂璁㈠崟鍙� + PayInfo payInfo = payInfoService.getNearInfo(); + String orderNo = getAlipayNo(payInfo.getOrderId()); + + String link = previewInfoService.saveMoneyArrival(uid, money, dayTime, orderNo, acceptData.getPlatform()); JSONObject object = new JSONObject(); object.put("link", link); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(object)); - } catch (PreviewInfoException e) { + } catch (PreviewInfoException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { LogHelper.errorDetailInfo(e); - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇濆瓨澶辫触")); + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("棰勮澶辫触")); } } - + private String getAlipayNo(String payNo) { + // 鏇挎崲鍓�8浣� + String newNo = payNo.substring(9, payNo.length()); + newNo = TimeUtil.getyyyyMMdd(java.lang.System.currentTimeMillis()) + newNo; + // 闅忔満鐢熸垚鏇挎崲鍚�6浣� + newNo = newNo.substring(0, payNo.length() - 6); + newNo += (long) ((Math.random() * 9 + 1) * 100000); + return newNo; + } + @RequestMapping(value = "getMoneyArrivalImg") public void getMoneyArrivalImg(String callback, AcceptData acceptData, Long uid, PrintWriter out) { PreviewInfo previewInfo = previewInfoService.get(uid, PreviewEnum.moneyInfo); - if (previewInfo == null || StringUtil.isNullOrEmpty(previewInfo.getContent())) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁")); - return; + String link = null; + if (previewInfo != null && StringUtil.isNullOrEmpty(previewInfo.getContent())) { + link = previewInfo.getContent(); } JSONObject object = new JSONObject(); - object.put("link", previewInfo.getContent()); + object.put("link", link); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(object)); } @@ -429,17 +457,85 @@ * @param out */ @RequestMapping(value = "saveOrderInfo") - public void saveOrderInfo(String callback, AcceptData acceptData, Long uid, Integer type, Integer num, PrintWriter out) { + public void saveOrderInfo(String callback, AcceptData acceptData, Long uid, Integer type, Integer num, + PrintWriter out) { if (uid == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛鏈櫥褰�")); return; } - - if (type == null || num == null) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰畬鍠勬暟鎹�")); + + if (type == null || type < 1 || type > 2) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨璁㈠崟绫诲瀷")); return; } - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇濆瓨鎴愬姛")); + + if (num == null || num <= 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐帹閫佹暟閲�")); + return; + } + + if (num > 50) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏈�澶氭敮鎸�50鏉�")); + return; + } + + // 鑾峰彇鏈�鏂拌鍗曞彿 + String orderNo = commonOrderService.getNewestOrderNoByTaoBao(); + + // 闅忔満璁㈠崟鍙� + List<String> list = getRandomOrderNo(orderNo, num); + // new Thread(new Runnable() { + // + // @Override + // public void run() { + for (String orderId : list) { + PushContentDTO dto = PushMsgFactory.createInviteOrderStatisticed(Constant.SOURCE_TYPE_TAOBAO, orderId, + BigDecimal.ZERO); + try { + pushService.pushZNX(uid, dto.getTitle(), dto.getContent(), null, null); + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (PushException e) { + e.printStackTrace(); + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + // } + // }).start(); + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); + } + + private List<String> getRandomOrderNo(String orderNo, int count) { + String newNo = orderNo.substring(0, 3); + long lenth = orderNo.length() - 3; + + long tempNum = 1; + for (long i = 0; i < lenth - 1; i++) { + tempNum = tempNum * 10; + } + + Set<String> set = new HashSet<>(); + for (int i = 0; i < count; i++) { + int temp = set.size(); + while (set.size() <= temp) { + long randomNum = (long) ((Math.random() * 9 + 1) * tempNum); + set.add(newNo + randomNum); + } + } + + // 杞崲list + List<String> list = new ArrayList<>(); + for (String s : set) { + list.add(s); + } + // 鎺掑簭 + Collections.sort(list); + + return list; } } -- Gitblit v1.8.0