UDPClient.java
2 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.huaheng.api.Weighing.controller;
import com.huaheng.api.Weighing.server.UDPServer;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.shipment.kuaidiHeader.domain.KuaidiHeader;
import com.huaheng.pc.shipment.kuaidiHeader.service.KuaidiHeaderService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.ip.udp.UnicastSendingMessageHandler;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.IOException;
/**
* @ClassName UDPClient
* @Description TODO
* @Author Administrator
* @Date 2020/12/215:08
*/
@RestController
@RequestMapping("/api/UDPClient")
public class UDPClient {
private static final Logger
logger = LoggerFactory.getLogger(UDPClient.class);
@Resource
private KuaidiHeaderService kuaidiHeaderService;
@PostMapping("/haha")
@ResponseBody
public void ICSComputationUnit() throws IOException {
String message ="776006167051546,0.71";
UnicastSendingMessageHandler unicastSendingMessageHandler = new UnicastSendingMessageHandler("172.16.2.10", 8900);
// UnicastSendingMessageHandler unicastSendingMessageHandler = new UnicastSendingMessageHandler("172.16.29.88", 8800);
logger.info("发送UDP: {}"+ message);
unicastSendingMessageHandler.handleMessage(MessageBuilder.withPayload(message).build());
logger.info("发送成功");
}
@PostMapping("/test")
@ResponseBody
public AjaxResult test(@RequestBody ShipmentHeader shipmentHeader) throws IOException {
KuaidiHeader kuaidiHeader = new KuaidiHeader();
kuaidiHeader.setOrderBill("AA2021");
kuaidiHeader.setFromCode("AA2021");
kuaidiHeader.setCreated(shipmentHeader.getCreated());
kuaidiHeaderService.saveU8Kuaidi(kuaidiHeader);
return AjaxResult.success("成功");
}
}