Fancy
2024-10-18 404ca5b447c5d20bdaf83faef88aea76f9db583c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.dy.pmsTest;
 
import com.dy.common.webUtil.BaseResponse;
import com.dy.pmsTest.tcpClient.TcpClUnit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.nio.charset.StandardCharsets;
 
/**
 * @Author: liurunyu
 * @Date: 2024/8/16 14:48
 * @Description
 */
@Slf4j
@RestController
@RequestMapping(path="ctrl")
public class TestCtrl {
 
    @PostMapping(path = "sendMs")
    public BaseResponse<String> sendMs(String txt) {
        BaseResponse<String> rt = new BaseResponse<>() ;
        if(txt != null && !txt.trim().equals("")){
            txt = txt + "\n" ;
            byte[] bs = txt.getBytes(StandardCharsets.UTF_8) ;
            TcpClUnit.session.write(bs) ;
            rt.setCode("1") ;
            rt.setMsg("已经发送数据:" + txt) ;
            rt.setSuccess(true) ;
        }else{
            rt.setCode("1") ;
            rt.setMsg("请输入数据") ;
            rt.setSuccess(false) ;
        }
        return rt ;
    }
}