package com.crm.globex.controller.callback;

import com.alibaba.fastjson.JSON;
import com.crm.globex.service.*;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.entity.manager.callback.FinanceCallbackEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 出入金(信用等)回调处理
 *
 * @Author: houn
 * @Date: 2020/11/15 11:39
 * @Description:
 */
@RestController
@RequestMapping("/callback/trade/trans")
public class CallbackTradeTransController {

    @Autowired
    private AccountApplyDemoService accountApplyDemoService;
    @Autowired
    private AccountApplyFirmOfferService accountApplyFirmOfferService;
    @Autowired
    private AccountApplyAssetManagementService accountApplyAssetManagementService;
    @Autowired
    FinanceDepositService financeDepositService;
    @Autowired
    private FinanceTransferService financeTransferService;

    /**
     * live出入金 信用
     *
     * @param content
     * @throws Exception
     */
    @JmsListener(destination = Constants.TRANS_INFO_CALLBACK)
    public void callbackAutomaticTradeTrans(String content) throws Exception {
        FinanceCallbackEntity callbackEntity = JSON.parseObject(content, FinanceCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.TRADE_TRANS_INFO:
                financeDepositService.callbackAutomaticTrade(callbackEntity);
                break;
            case Constants.TRADE_TRANS_TRANSFER_INFO:
                financeTransferService.callbackAutomaticTransferAmount(callbackEntity);
                break;
            case Constants.FIRM_OFFER_TRADE_TRANS_INFO:
                accountApplyFirmOfferService.callbackAutomaticAccountBalance(callbackEntity);
                break;
            case Constants.ASSET_MANAGEMENT_TRADE_TRANS_INFO:
                accountApplyAssetManagementService.callbackAutomaticAccountBalance(callbackEntity);
                break;

            default:
                break;
        }
    }

    @JmsListener(destination = Constants.DEMO_TRADE_TRANS_INFO_CALLBACK)
    public void callbackDemoAutomaticTradeTrans(String content) throws Exception {
        FinanceCallbackEntity callbackEntity = JSON.parseObject(content, FinanceCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.DEMO_TRADE_TRANS_INFO:
                accountApplyDemoService.callbackAutomaticAccountBalance(callbackEntity);
                break;
            default:
                break;
        }
    }

}
