From 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 28 十月 2022 16:55:02 +0800 Subject: [PATCH] 批量添加结算消息 --- app/src/main/java/com/yeshi/makemoney/app/controller/admin/goldcorn/GoldCornSettleRecordAdminController.java | 91 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 77 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/controller/admin/goldcorn/GoldCornSettleRecordAdminController.java b/app/src/main/java/com/yeshi/makemoney/app/controller/admin/goldcorn/GoldCornSettleRecordAdminController.java index d422f20..118692b 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/controller/admin/goldcorn/GoldCornSettleRecordAdminController.java +++ b/app/src/main/java/com/yeshi/makemoney/app/controller/admin/goldcorn/GoldCornSettleRecordAdminController.java @@ -2,9 +2,15 @@ import com.google.gson.*; import com.ks.lib.common.exception.ParamsException; +import com.yeshi.makemoney.app.dto.mq.GoldCornSettleMQMsg; +import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType; import com.yeshi.makemoney.app.exception.goldcorn.GoldCornSettleRecordException; +import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornConsumeRecordService; +import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService; import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornSettleService; +import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornConsumeRecordQuery; import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil; +import com.yeshi.makemoney.app.utils.mq.CMQManager; import com.yeshi.makemoney.app.vo.AcceptAdminData; import net.sf.json.JSONArray; import net.sf.json.JSONObject; @@ -19,6 +25,8 @@ import javax.annotation.Resource; import javax.servlet.http.HttpSession; import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -36,19 +44,27 @@ @Resource private GoldCornSettleService goldCornSettleService; + @Resource + private GoldCornConsumeRecordService goldCornConsumeRecordService; + + @Resource + private GoldCornGetRecordService goldCornGetRecordService; + + private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + + @Override + public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { + return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm")); + } + }).create(); + @ResponseBody @RequestMapping("list") public String list(GoldCornSettleRecordQuery query, int page, int limit) { List<GoldCornSettleRecord> list = goldCornSettleRecordService.list(query, page, limit); long count = goldCornSettleRecordService.count(query); JSONObject data = new JSONObject(); - Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { - @Override - public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { - return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm")); - } - }).create(); data.put("list", gson.toJson(list)); data.put("count", count); @@ -82,6 +98,9 @@ } catch (ParamsException e) { e.printStackTrace(); return JsonUtil.loadFalseResult(e.getMessage()); + } catch (Exception e) { + e.printStackTrace(); + return JsonUtil.loadFalseResult(e.getMessage()); } } @@ -100,20 +119,64 @@ @ResponseBody - @RequestMapping("update") - public String update(GoldCornSettleRecord bean, HttpSession session) { - if (bean.getId() == null) { + @RequestMapping("refresh") + public String refresh(String id, AcceptAdminData acceptAdminData) { + if (id == null) { return JsonUtil.loadFalseResult("ID涓嶈兘涓虹┖"); - } + + GoldCornSettleRecord record = goldCornSettleRecordService.get(id); + if (record == null) { + return JsonUtil.loadFalseResult("璁板綍涓嶅瓨鍦�"); + } + + GoldCornConsumeRecordQuery query = new GoldCornConsumeRecordQuery(); + query.setType(GoldCornConsumeType.changeMoney); + query.setEventId(id); + + BigDecimal money = goldCornConsumeRecordService.sumMoney(query); + Long userCount = goldCornConsumeRecordService.count(query); + + GoldCornSettleRecord update = new GoldCornSettleRecord(); + update.setId(id); + update.setTotalMoney(money); + update.setSettledUserCount(userCount); + goldCornSettleRecordService.update(update); + record.setTotalMoney(money); + record.setSettledUserCount(userCount); + return JsonUtil.loadTrueResult(gson.toJson(record)); + } + + + @ResponseBody + @RequestMapping("retry") + public String retry(String id, AcceptAdminData acceptAdminData) { + if (id == null) { + return JsonUtil.loadFalseResult("ID涓嶈兘涓虹┖"); + } + + GoldCornSettleRecord record = goldCornSettleRecordService.get(id); + if (record == null) { + return JsonUtil.loadFalseResult("璁板綍涓嶅瓨鍦�"); + } + + long count = goldCornGetRecordService.countUidsByDay(record.getDay()); + int pageSize = 16; + int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); try { - goldCornSettleRecordService.update(bean); + for (int i = 0; i < page; i++) { + List<Long> list = goldCornGetRecordService.getUidsByDay(record.getDay(), i + 1, pageSize); + List<GoldCornSettleMQMsg> msgList = new ArrayList<>(); + for (Long uid : list) { + msgList.add(new GoldCornSettleMQMsg(record.getId(), uid, record.getDay(), System.currentTimeMillis())); + } + //鍔犲叆鍒癈MQ + CMQManager.getInstance().addGoldCornSettleMsg(msgList); + } } catch (Exception e) { return JsonUtil.loadFalseResult(e.getMessage()); - } - return JsonUtil.loadTrueResult(""); - + return JsonUtil.loadTrueResult(gson.toJson(record)); } -- Gitblit v1.8.0