UDPClient.java 2 KB
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("成功");
    }
}