package com.crm.globex.controller.callback;

import com.alibaba.fastjson.JSON;
import com.crm.globex.service.AccountApplyPasswordResetService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.entity.manager.callback.AccountPasswordCallbackEntity;
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/password")
public class CallbackUpdatePasswordController {

    @Autowired
    private AccountApplyPasswordResetService accountApplyPasswordResetService;

    @JmsListener(destination = Constants.USER_RECORD_PASSWORD_UPDATE_CALLBACK)
    public void callbackAutomaticDealChange(String content) throws Exception {
        AccountPasswordCallbackEntity callbackEntity = JSON.parseObject(content, AccountPasswordCallbackEntity.class);
        if (callbackEntity == null) {
            System.out.println("回调数据异常:" + content);
        }
        switch (callbackEntity.getData().getRouteType()) {
            case Constants.USER_RECORD_MASTER_PASSWORD_REST_UPDATE:
                accountApplyPasswordResetService.callbackAutomaticDealRest(callbackEntity);
                break;
            default:
                break;
        }
    }
}
