admin
2022-10-28 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff
app/src/main/java/com/yeshi/makemoney/app/Application.java
@@ -1,11 +1,17 @@
package com.yeshi.makemoney.app;
import com.google.gson.Gson;
import com.ks.lib.common.exception.ParamsException;
import com.yeshi.makemoney.app.dto.mq.ExtractTransferResultMQMsg;
import com.yeshi.makemoney.app.dto.mq.GoldCornSettleMQMsg;
import com.yeshi.makemoney.app.exception.goldcorn.GoldCornConsumeRecordException;
import com.yeshi.makemoney.app.exception.goldcorn.GoldCornMoneyExchangeRateRecordException;
import com.yeshi.makemoney.app.exception.money.UserMoneyRecordException;
import com.yeshi.makemoney.app.exception.user.UserInfoException;
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornSettleService;
import com.yeshi.makemoney.app.service.inter.money.ExtractService;
import com.yeshi.makemoney.app.utils.Constant;
import com.yeshi.makemoney.app.utils.LogUtil;
import com.yeshi.makemoney.app.utils.mq.CMQManager;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
@@ -36,10 +42,12 @@
@EnableTransactionManagement
//@EnableDubbo(scanBasePackages = "com.ks.push.service.remote")
public class Application implements ApplicationListener<ContextRefreshedEvent> {
    Logger settleLogger= LoggerFactory.getLogger("settleLog");
    private final static Logger logger = LoggerFactory.getLogger(Application.class);
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        logger.info(Constant.wxTransferConfig.toString());
        logger.info("应用启动成功");
    }
@@ -49,10 +57,15 @@
        logger.info("容器加载完毕");
        initMQMsgConsumer();
        initCOS();
        LogUtil.settleLogger.info("test123");
    }
    @Resource
    private GoldCornSettleService goldCornSettleService;
    @Resource
    private ExtractService extractService;
    private void initMQMsgConsumer() {
        final int THREAD_NUM = 3;
@@ -62,24 +75,32 @@
            new JobThreadExecutorServiceImpl().run(new Runnable() {
                @Override
                public void run() {
                    Map<String, GoldCornSettleMQMsg> map = CMQManager.getInstance().consumeGoldCornSettleMsg(10);
                    if (map != null) {
                        for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) {
                            String key = its.next();
                            GoldCornSettleMQMsg msg = map.get(key);
                            try {
                                goldCornSettleService.settle(msg.getUid(), msg.getDay());
                                settleLogger.info("消费结算消息开始:{}",new Gson().toJson(msg));
                                goldCornSettleService.settle(msg.getUid(), msg.getDay(),msg.getSettleId());
                                CMQManager.getInstance().deleteGoldCornSettleMsg(key);
                                settleLogger.info("消费结算消息成功:{}",new Gson().toJson(msg));
                            } catch (UserInfoException e) {
                                e.printStackTrace();
                                settleLogger.error("消费结算消息异常:{} ",new Gson().toJson(msg),e);
                            } catch (GoldCornMoneyExchangeRateRecordException e) {
                                e.printStackTrace();
                                settleLogger.error("消费结算消息异常:{} ",new Gson().toJson(msg),e);
                            } catch (UserMoneyRecordException e) {
                                e.printStackTrace();
                                settleLogger.error("消费结算消息异常:{} ",new Gson().toJson(msg),e);
                            } catch (GoldCornConsumeRecordException e) {
                                e.printStackTrace();
                            }catch (Exception e){
                                settleLogger.error("消费结算消息异常:{} ",new Gson().toJson(msg),e);
                            } catch (Exception e) {
                                e.printStackTrace();
                                settleLogger.error("消费结算消息异常:{} ",new Gson().toJson(msg),e);
                            }
                        }
                    }
@@ -88,6 +109,27 @@
                }
            });
        }
        //处理提现结果
        new JobThreadExecutorServiceImpl().run(new Runnable() {
            @Override
            public void run() {
                Map<String, ExtractTransferResultMQMsg> map = CMQManager.getInstance().consumeExtractResultMsg(1);
                if (map != null) {
                    for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) {
                        String key = its.next();
                        ExtractTransferResultMQMsg msg = map.get(key);
                        try {
                            extractService.processExtractResult(msg);
                            CMQManager.getInstance().deleteExtractResultMsg(key);
                        } catch (ParamsException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        });
    }