package com.nokia.esb_socket.controller;

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;

import com.nokia.esb_socket.common.http.R;
import com.nokia.esb_socket.pojo.GongdanFK;
import com.nokia.esb_socket.pojo.TousuSheet;
import com.nokia.esb_socket.service.EsbNettyService;
import com.nokia.esb_socket.service.GongDanEsbNettyService;

@RestController
@RequestMapping("/esb/socket")
public class EsbSocketController {

    @Autowired
    private EsbNettyService esbNettyService;

    @Autowired
    private GongDanEsbNettyService gongDanEsbNettyService;

    @PostMapping("/send/toususheet")
    public R sendTousuSheet(@RequestBody TousuSheet tousuSheet) {
        try {
            esbNettyService.send(tousuSheet);
            return R.ok().message("发送成功。");
        } catch (Exception e) {
            return R.error().message(e.getMessage());
        }
    }

    @PostMapping("/send/gongdanfk")
    public R sendGongdanFK(@RequestBody GongdanFK gongdanFK) {
        try {
            gongDanEsbNettyService.send(gongdanFK);
            return R.ok().message("发送成功。");
        } catch (Exception e) {
            return R.error().message(e.getMessage());
        }
    }
}
