parent
9b5d9912c3
commit
a06e93e518
@ -0,0 +1,73 @@
|
||||
package com.hw.common.core.utils;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @ProjectName:HwMes
|
||||
* @Author:xins
|
||||
* @Date:2024-04-12 13:43
|
||||
* @Version:1.0
|
||||
*/
|
||||
public class SocketUtils {
|
||||
|
||||
public static String sendAndReceive(String host,int port,int readTimeout,String sendMessage) {
|
||||
|
||||
Socket socket = null;
|
||||
try {
|
||||
socket = new Socket(host, port);
|
||||
OutputStream outToServer = socket.getOutputStream();
|
||||
byte[] sendMessageBytes = sendMessage.getBytes();
|
||||
outToServer.write(sendMessageBytes);
|
||||
outToServer.flush();
|
||||
socket.setSoTimeout(readTimeout);
|
||||
|
||||
try {
|
||||
// 获取Socket的输入流
|
||||
InputStream inFromServer = socket.getInputStream();
|
||||
|
||||
// 创建一个足够大的缓冲区来接收数据
|
||||
byte[] buffer = new byte[1024];
|
||||
|
||||
// 从输入流中读取数据
|
||||
int bytesRead;
|
||||
while ((bytesRead = inFromServer.read(buffer)) != -1) {
|
||||
// 处理接收到的数据
|
||||
String receivedMessage = new String(buffer, 0, bytesRead, StandardCharsets.UTF_8);
|
||||
System.out.println("Received feedback from server: " + receivedMessage);
|
||||
return receivedMessage;
|
||||
}
|
||||
} catch (SocketTimeoutException e) {
|
||||
System.err.println("Reading from the socket timed out.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("An I/O error occurred: " + e.getMessage());
|
||||
} finally {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close(); // 在异常情况下也尝试关闭
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to close the socket: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JSONObject assignTaskMessageJson = new JSONObject();
|
||||
assignTaskMessageJson.put("stationNo", 3);
|
||||
assignTaskMessageJson.put("time", System.currentTimeMillis());
|
||||
assignTaskMessageJson.put("materialBarcode", "1111");
|
||||
String host = "10.11.41.121";
|
||||
int port = 5000;
|
||||
int readTimeout = 5000; // 读取超时时间,单位:毫秒
|
||||
sendAndReceive(host, port, readTimeout,assignTaskMessageJson.toString());
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package com.hw.mes.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.hw.common.core.annotation.Excel;
|
||||
import com.hw.common.core.web.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 柜体分配任务信息对象 mes_material_assign_info
|
||||
*
|
||||
* @author xins
|
||||
* @date 2024-04-12
|
||||
*/
|
||||
public class MesMaterialAssignInfo extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 主键标识 */
|
||||
private Long materialAssignInfoId;
|
||||
|
||||
/** 物料条码 */
|
||||
@Excel(name = "物料条码")
|
||||
private String materialBarcode;
|
||||
|
||||
/** 下发工位ID */
|
||||
@Excel(name = "下发工位ID")
|
||||
private Long stationId;
|
||||
|
||||
public void setMaterialAssignInfoId(Long materialAssignInfoId)
|
||||
{
|
||||
this.materialAssignInfoId = materialAssignInfoId;
|
||||
}
|
||||
|
||||
public Long getMaterialAssignInfoId()
|
||||
{
|
||||
return materialAssignInfoId;
|
||||
}
|
||||
public void setMaterialBarcode(String materialBarcode)
|
||||
{
|
||||
this.materialBarcode = materialBarcode;
|
||||
}
|
||||
|
||||
public String getMaterialBarcode()
|
||||
{
|
||||
return materialBarcode;
|
||||
}
|
||||
public void setStationId(Long stationId)
|
||||
{
|
||||
this.stationId = stationId;
|
||||
}
|
||||
|
||||
public Long getStationId()
|
||||
{
|
||||
return stationId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("materialAssignInfoId", getMaterialAssignInfoId())
|
||||
.append("materialBarcode", getMaterialBarcode())
|
||||
.append("stationId", getStationId())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.hw.mes.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.hw.mes.domain.MesMaterialAssignInfo;
|
||||
|
||||
/**
|
||||
* 柜体分配任务信息Mapper接口
|
||||
*
|
||||
* @author xins
|
||||
* @date 2024-04-12
|
||||
*/
|
||||
public interface MesMaterialAssignInfoMapper
|
||||
{
|
||||
/**
|
||||
* 查询柜体分配任务信息
|
||||
*
|
||||
* @param materialAssignInfoId 柜体分配任务信息主键
|
||||
* @return 柜体分配任务信息
|
||||
*/
|
||||
public MesMaterialAssignInfo selectMesMaterialAssignInfoByMaterialAssignInfoId(Long materialAssignInfoId);
|
||||
|
||||
/**
|
||||
* 查询柜体分配任务信息列表
|
||||
*
|
||||
* @param mesMaterialAssignInfo 柜体分配任务信息
|
||||
* @return 柜体分配任务信息集合
|
||||
*/
|
||||
public List<MesMaterialAssignInfo> selectMesMaterialAssignInfoList(MesMaterialAssignInfo mesMaterialAssignInfo);
|
||||
|
||||
/**
|
||||
* 新增柜体分配任务信息
|
||||
*
|
||||
* @param mesMaterialAssignInfo 柜体分配任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertMesMaterialAssignInfo(MesMaterialAssignInfo mesMaterialAssignInfo);
|
||||
|
||||
/**
|
||||
* 修改柜体分配任务信息
|
||||
*
|
||||
* @param mesMaterialAssignInfo 柜体分配任务信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateMesMaterialAssignInfo(MesMaterialAssignInfo mesMaterialAssignInfo);
|
||||
|
||||
/**
|
||||
* 删除柜体分配任务信息
|
||||
*
|
||||
* @param materialAssignInfoId 柜体分配任务信息主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteMesMaterialAssignInfoByMaterialAssignInfoId(Long materialAssignInfoId);
|
||||
|
||||
/**
|
||||
* 批量删除柜体分配任务信息
|
||||
*
|
||||
* @param materialAssignInfoIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteMesMaterialAssignInfoByMaterialAssignInfoIds(Long[] materialAssignInfoIds);
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hw.mes.mapper.MesMaterialAssignInfoMapper">
|
||||
|
||||
<resultMap type="MesMaterialAssignInfo" id="MesMaterialAssignInfoResult">
|
||||
<result property="materialAssignInfoId" column="material_assign_info_id" />
|
||||
<result property="materialBarcode" column="material_barcode" />
|
||||
<result property="stationId" column="station_id" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectMesMaterialAssignInfoVo">
|
||||
select material_assign_info_id, material_barcode, station_id, create_by, create_time from mes_material_assign_info
|
||||
</sql>
|
||||
|
||||
<select id="selectMesMaterialAssignInfoList" parameterType="MesMaterialAssignInfo" resultMap="MesMaterialAssignInfoResult">
|
||||
<include refid="selectMesMaterialAssignInfoVo"/>
|
||||
<where>
|
||||
<if test="materialBarcode != null and materialBarcode != ''"> and material_barcode = #{materialBarcode}</if>
|
||||
<if test="stationId != null "> and station_id = #{stationId}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectMesMaterialAssignInfoByMaterialAssignInfoId" parameterType="Long" resultMap="MesMaterialAssignInfoResult">
|
||||
<include refid="selectMesMaterialAssignInfoVo"/>
|
||||
where material_assign_info_id = #{materialAssignInfoId}
|
||||
</select>
|
||||
|
||||
<insert id="insertMesMaterialAssignInfo" parameterType="MesMaterialAssignInfo" useGeneratedKeys="true" keyProperty="materialAssignInfoId">
|
||||
insert into mes_material_assign_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="materialBarcode != null and materialBarcode != ''">material_barcode,</if>
|
||||
<if test="stationId != null">station_id,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="materialBarcode != null and materialBarcode != ''">#{materialBarcode},</if>
|
||||
<if test="stationId != null">#{stationId},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateMesMaterialAssignInfo" parameterType="MesMaterialAssignInfo">
|
||||
update mes_material_assign_info
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="materialBarcode != null and materialBarcode != ''">material_barcode = #{materialBarcode},</if>
|
||||
<if test="stationId != null">station_id = #{stationId},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
</trim>
|
||||
where material_assign_info_id = #{materialAssignInfoId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteMesMaterialAssignInfoByMaterialAssignInfoId" parameterType="Long">
|
||||
delete from mes_material_assign_info where material_assign_info_id = #{materialAssignInfoId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteMesMaterialAssignInfoByMaterialAssignInfoIds" parameterType="String">
|
||||
delete from mes_material_assign_info where material_assign_info_id in
|
||||
<foreach item="materialAssignInfoId" collection="array" open="(" separator="," close=")">
|
||||
#{materialAssignInfoId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
Loading…
Reference in New Issue