admin
2022-10-28 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff
app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornSettleServiceImpl.java
@@ -1,5 +1,6 @@
package com.yeshi.makemoney.app.service.impl.goldcorn;
import com.google.gson.Gson;
import com.ks.lib.common.exception.ParamsException;
import com.ks.push.exception.BPushTaskException;
import com.yeshi.makemoney.app.dto.mq.GoldCornSettleMQMsg;
@@ -25,13 +26,17 @@
import com.yeshi.makemoney.app.utils.factory.msg.UserMsgFactory;
import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil;
import com.yeshi.makemoney.app.utils.mq.CMQManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.ThreadUtil;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -44,6 +49,7 @@
 */
@Service
public class GoldCornSettleServiceImpl implements GoldCornSettleService {
    Logger settleLogger = LoggerFactory.getLogger("settleLog");
    @Resource
    private GoldCornGetRecordService goldCornGetRecordService;
@@ -70,7 +76,7 @@
    private GoldCornSettleRecordService goldCornSettleRecordService;
    @Override
    public void startSettle(Date date, String remarks, SystemEnum system) throws GoldCornSettleRecordException, ParamsException {
    public void startSettle(Date date, String remarks, SystemEnum system) throws Exception {
        String day = GoldCornUtil.getFormatDay(date);
        if (GoldCornUtil.convertFormatDay(day).getTime() >= GoldCornUtil.convertFormatDay(GoldCornUtil.getFormatDay(new Date())).getTime()) {
@@ -98,19 +104,25 @@
        record.setCornNum(numMap.get(day));
        record.setTotalMoney(new BigDecimal(0));
        goldCornSettleRecordService.add(record);
        long count = goldCornGetRecordService.countUidsByDay(day);
        int pageSize = 1000;
        record.setUserCount(count);
        record.setSettledUserCount(0L);
        goldCornSettleRecordService.add(record);
        int pageSize = 16;
        int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
        for (int i = 0; i < page; i++) {
            List<Long> list = goldCornGetRecordService.getUidsByDay(day, i + 1, pageSize);
            List<Long> list = goldCornGetRecordService.getUidsByDay(record.getDay(), i + 1, pageSize);
            List<GoldCornSettleMQMsg> msgList = new ArrayList<>();
            for (Long uid : list) {
                //加入到CMQ
                CMQManager.getInstance().addGoldCornSettleMsg(new GoldCornSettleMQMsg(record.getId(), uid, day, System.currentTimeMillis()));
                GoldCornSettleMQMsg msg = new GoldCornSettleMQMsg(record.getId(), uid, day, System.currentTimeMillis());
                msgList.add(msg);
                settleLogger.info("加入结算队列:{}", new Gson().toJson(msg));
            }
            //加入到CMQ
            CMQManager.getInstance().addGoldCornSettleMsg(msgList);
        }
    }
@@ -120,6 +132,11 @@
        long cornNum = goldCornGetRecordService.getGoldCornByDay(uid, GoldCornUtil.convertFormatDay(day));
        //金币数量
        GoldCornConsumeRecord record = GoldCornConsumeRecordFactory.createExchange(uid, day, (int) cornNum, rate, settleId);
        if (goldCornConsumeRecordService.get(record.getId()) != null) {
            //已经结算过了
            return;
        }
        try {
            UserMoneyRecord moneyRecord = UserMoneyRecordFactory.createGoldCornExchange(record);
            userMoneyService.addUserMoney(moneyRecord);