package com.msg.controller;

import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.model.ResponseData;
import com.hai.service.WebSocket;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping(value = "/websocket")
@Api(value = "订单推送")
public class HighMegController {

    @Autowired
    private WebSocket webSocket;

    private static Logger log = LoggerFactory.getLogger(HighMegController.class);

    @RequestMapping(value = "/websocket", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "websocket")
    public ResponseData websocket(@RequestBody JSONObject object) {
        try {


            if (StringUtils.isBlank(object.getString("userId")) ||
            StringUtils.isBlank(object.getString("message"))
            ) {
                log.error("websocket error!", "参数错误");
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }

            webSocket.SenderMessage(object.getString("userId") , object.getString("message"));
            return ResponseMsgUtil.success("成功");

        } catch (Exception e) {
            log.error("HighOrderController --> unionStagingPay() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

}
