package com.crm.globex.controller.callback;

import com.alibaba.fastjson.JSON;
import com.crm.globex.service.CustomLoginAssetManagementService;
import com.crm.globex.service.CustomLoginDemoService;
import com.crm.globex.service.CustomLoginFirmOfferService;
import com.crm.globex.service.CustomLoginService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.entity.manager.callback.AccountUpdateCallbackEntity;
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;

/**
 * 修改manger用户信息manger回调处理
 *
 * @Author: houn
 * @Date: 2020/11/15 11:39
 * @Description:
 */
@RestController
@RequestMapping("/callback/update/user")
public class CallbackUpdateUserController {

    @Autowired
    private CustomLoginService customLoginService;
    @Autowired
    private CustomLoginFirmOfferService customLoginFirmOfferService;
    @Autowired
    private CustomLoginAssetManagementService customLoginAssetManagementService;
    @Autowired
    private CustomLoginDemoService customLoginDemoService;


    @JmsListener(destination = Constants.USER_RECORD_UPDATE_CALLBACK)
    public void callbackAutomaticUpdateUser(String content) throws Exception {
        AccountUpdateCallbackEntity callbackEntity = JSON.parseObject(content, AccountUpdateCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.USER_RECORD_UPDATE:
                customLoginService.callbackAutomaticAccount(callbackEntity);
                break;
            case Constants.FIRM_OFFER_USER_RECORD_UPDATE:
                customLoginFirmOfferService.callbackAutomaticAccount(callbackEntity);
                break;
            default:
                break;
        }
    }

    @JmsListener(destination = Constants.DEMO_USER_RECORD_UPDATE_CALLBACK)
    public void callbackDemoAutomaticUpdateUser(String content) throws Exception {
        AccountUpdateCallbackEntity callbackEntity = JSON.parseObject(content, AccountUpdateCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {

            case Constants.DEMO_USER_RECORD_UPDATE:
                customLoginDemoService.callbackAutomaticAccount(callbackEntity);
                break;
        }
    }
}
