package com.crm.manager.controller;

import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.manager.dao.mapper.UserInfoDao;
import com.crm.manager.service.UserInfoService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.manager.callback.AccountCallbackEntity;
import com.crm.rely.backend.core.entity.user.info.UserInfoUpdateLangEntity;
import com.crm.rely.backend.service.MqSendService;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: crm-backend
 * @description:
 * @author: houn
 * @create: 2019-07-25 15:57
 */
@Log4j
@RestController
@RequestMapping("/test")
public class TestController extends BaseLoginController {

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private UserInfoDao userInfoDao;

    @Autowired
    private MqSendService mqSendService;

    @PostMapping("/test1")
    public BaseResultDto test1() throws Exception {
        return BaseResultDto.success(userInfoDao.getOne(20090L));
    }

    @PostMapping("/test2")
    public BaseResultDto test2() throws Exception {

        UserInfoUpdateLangEntity entity = new UserInfoUpdateLangEntity();
        entity.setId(20090L);
        entity.setLang("en");
        userInfoService.updateLang(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/mq")
    public BaseResultDto testMq(@RequestBody AccountCallbackEntity entity) throws Exception {
        mqSendService.send(Constants.USER_RECORD_CREATE_CALLBACK, entity);
        return BaseResultDto.success();
    }

}
