package com.crm.globex.controller.callback;

import com.alibaba.fastjson.JSON;
import com.crm.globex.service.AccountApplyAssetManagementService;
import com.crm.globex.service.AccountApplyDemoService;
import com.crm.globex.service.AccountApplyFirmOfferService;
import com.crm.globex.service.AccountApplyService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.entity.manager.callback.AccountCallbackEntity;
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;

/**
 * 创建manager用户回调处理
 *
 * @Author: houn
 * @Date: 2020/11/15 11:39
 * @Description:
 */
@RestController
@RequestMapping("/callback/create/user")
public class CallbackCreateUserController {
    @Autowired
    private AccountApplyDemoService accountApplyDemoService;
    @Autowired
    private AccountApplyFirmOfferService accountApplyFirmOfferService;
    @Autowired
    private AccountApplyAssetManagementService accountApplyAssetManagementService;
    @Autowired
    private AccountApplyService accountApplyService;

    @JmsListener(destination = Constants.USER_RECORD_CREATE_CALLBACK)
    public void callbackAutomaticCreateUser(String content) throws Exception {
        AccountCallbackEntity callbackEntity = JSON.parseObject(content, AccountCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.USER_RECORD_CREATE:
                accountApplyService.callbackAutomaticAccount(callbackEntity);
                break;
            case Constants.FIRM_OFFER_USER_RECORD_CREATE:
                accountApplyFirmOfferService.callbackAutomaticAccount(callbackEntity);
                break;
            case Constants.ASSET_MANAGEMENT_USER_RECORD_CREATE:
                accountApplyAssetManagementService.callbackAutomaticAccount(callbackEntity);
                break;
            default:
                break;
        }
    }

    @JmsListener(destination = Constants.DEMO_USER_RECORD_CREATE_CALLBACK)
    public void callbackDemoAutomaticCreateUser(String content) throws Exception {
        AccountCallbackEntity callbackEntity = JSON.parseObject(content, AccountCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.DEMO_USER_RECORD_CREATE:
                accountApplyDemoService.callbackAutomaticAccount(callbackEntity);
                break;
        }
    }
}
