admin
2022-05-07 15bedcc619b1edb6eb987f9288db7670e5b38c46
app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornSettleServiceImpl.java
@@ -1,6 +1,7 @@
package com.yeshi.makemoney.app.service.impl.goldcorn;
import com.ks.lib.common.exception.ParamsException;
import com.ks.push.exception.BPushTaskException;
import com.yeshi.makemoney.app.dto.mq.GoldCornSettleMQMsg;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType;
@@ -15,13 +16,17 @@
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMoneyExchangeRateRecordService;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornSettleService;
import com.yeshi.makemoney.app.service.inter.money.UserMoneyService;
import com.yeshi.makemoney.app.service.inter.msg.UserMsgNotifyService;
import com.yeshi.makemoney.app.service.inter.user.UserInfoService;
import com.yeshi.makemoney.app.service.manager.PushManager;
import com.yeshi.makemoney.app.utils.factory.UserMoneyRecordFactory;
import com.yeshi.makemoney.app.utils.factory.goldcorn.GoldCornConsumeRecordFactory;
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.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.ThreadUtil;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -53,9 +58,15 @@
    @Resource
    private UserMoneyService userMoneyService;
    @Resource
    private UserMsgNotifyService userMsgNotifyService;
    @Resource
    private PushManager pushManager;
    @Override
    public void startSettle(Date date) {
        String day= GoldCornUtil.getFormatDay(date);
        String day = GoldCornUtil.getFormatDay(date);
        long count = goldCornGetRecordService.countUidsByDay(day);
        int pageSize = 1000;
        int page = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
@@ -70,10 +81,10 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void settle(Long uid, Date day, BigDecimal rate) throws GoldCornConsumeRecordException, UserMoneyRecordException {
        long cornNum = goldCornGetRecordService.getGoldCornByDay(uid, day);
    public void settle(Long uid, String day, BigDecimal rate) throws GoldCornConsumeRecordException, UserMoneyRecordException {
        long cornNum = goldCornGetRecordService.getGoldCornByDay(uid, GoldCornUtil.convertFormatDay(day));
        //金币数量
        GoldCornConsumeRecord record = GoldCornConsumeRecordFactory.createExchange(uid,GoldCornUtil.getFormatDay(day),(int) cornNum,rate);
        GoldCornConsumeRecord record = GoldCornConsumeRecordFactory.createExchange(uid, day, (int) cornNum, rate);
        try {
            UserMoneyRecord moneyRecord = UserMoneyRecordFactory.createGoldCornExchange(record);
            userMoneyService.addUserMoney(moneyRecord);
@@ -81,10 +92,27 @@
            throw new UserMoneyRecordException(e.getCode(), e.getMsg());
        }
        goldCornConsumeRecordService.add(record);
        //消息通知不需要在主线程
        ThreadUtil.run(new Runnable() {
            @Override
            public void run() {
                try {
                    userMsgNotifyService.notify(UserMsgFactory.createGoldCornExchange(record, userMoneyService.getBalance(uid)));
                    //添加站外推送
                    UserInfo user = userInfoService.get(uid);
                    if (user == null) {
                        return;
                    }
                    pushManager.pushGoldCornSettle(user.getSystem(), record.getUid(), Math.abs(record.getCornNum()), record.getMoney());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    @Override
    public void settle(Long uid, Date day) throws UserInfoException, GoldCornMoneyExchangeRateRecordException, UserMoneyRecordException, GoldCornConsumeRecordException {
    public void settle(Long uid, String day) throws UserInfoException, GoldCornMoneyExchangeRateRecordException, UserMoneyRecordException, GoldCornConsumeRecordException {
        UserInfo user = userInfoService.get(uid);
        if (user == null) {
            throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "用户不存在");
@@ -92,7 +120,7 @@
        BigDecimal rate = null;
        try {
            rate = goldCornMoneyExchangeRateRecordService.getRate(GoldCornUtil.getFormatDay(day), user.getSystem(), new Date());
            rate = goldCornMoneyExchangeRateRecordService.getRate(day, user.getSystem(), new Date());
        } catch (ParamsException e) {
            throw new GoldCornMoneyExchangeRateRecordException(GoldCornMoneyExchangeRateRecordException.CODE_PARAMS_NOT_ENOUGH, e.getMsg());
        }