package com.house365.web;

import com.google.common.base.Strings;
import com.house365.beans.dto.MessageDTO;
import com.house365.service.interfaces.MessageClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Date: 2017/3/24</p>
 *
 * @author XN
 * @version 1.0
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("message")
public class MessageController {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    MessageClient messageClient;

    @RequestMapping(value = "send", method = RequestMethod.POST)
    @ResponseBody
    public void send(
        @RequestParam(value = "corpId") String corpId, @RequestParam(value = "secret") String secret, MessageDTO message
    ) {
        //不同类型具体参数处理
        if (!Strings.isNullOrEmpty(message.getMsgtype())) {
            switch (message.getMsgtype()) {
                case "text":
                    messageClient.sendText(corpId, secret, message);
                    break;
                case "textcard":
                    messageClient.sendCardText(corpId, secret, message);
                    break;
                default:
                    break;
            }
        }
    }


}
