Commit a130a3fa authored by wanghao's avatar wanghao

1 托盘 根据 业务调整 增加 序号字段。

2 托盘 提交绑定后,再提交绑定会 重复添加数据问题调整。
parent 055017cd
......@@ -105,7 +105,7 @@ public class PalletDeviceBindingController extends BaseController
*/
@PostMapping ("/batchAdd")
public AjaxResult batchAdd(@RequestBody List<PalletDeviceBinding> palletDeviceBindings){
return toAjax(palletDeviceBindingService.batchInsertPalletDeviceBinding(palletDeviceBindings));
return AjaxResult.success(palletDeviceBindingService.batchInsertPalletDeviceBinding(palletDeviceBindings));
}
/**
......
......@@ -44,6 +44,11 @@ public class PalletDeviceBinding extends BaseEntity
*/
private Integer index;
/**
* 顺序号
*/
private Integer number;
/** 绑定时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "绑定时间", width = 30, dateFormat = "yyyy-MM-dd")
......@@ -264,6 +269,14 @@ public class PalletDeviceBinding extends BaseEntity
this.fTrayCode = fTrayCode;
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -73,6 +73,11 @@ public interface RobotArmCommandMapper
*/
List<RobotArmCommand> selectPendingUnloadingCommands();
/**
* 同时获取待执行的上料指令(type=0)和下料指令(type=1),各1条
* @return 包含上料、下料指令的列表(最多2条,顺序:上料在前,下料在后)
*/
List<RobotArmCommand> selectPendingLoadUnloadCommands();
/**
* 删除机械臂指令
*
......
......@@ -41,7 +41,7 @@ public interface IPalletDeviceBindingService
public AjaxResult resetAll(Long trayId);
public int batchInsertPalletDeviceBinding(List<PalletDeviceBinding> palletDeviceBindingList);
public List<PalletDeviceBinding> batchInsertPalletDeviceBinding(List<PalletDeviceBinding> palletDeviceBindingList);
public int batchUpdateDeviceCode(List<PalletDeviceBinding> palletDeviceBindingList);
......
......@@ -106,7 +106,7 @@ public class PalletDeviceBindingServiceImpl implements IPalletDeviceBindingServi
* @return 结果
*/
@Override
public int batchInsertPalletDeviceBinding(List<PalletDeviceBinding> palletDeviceBindingList) {
public List<PalletDeviceBinding> batchInsertPalletDeviceBinding(List<PalletDeviceBinding> palletDeviceBindingList) {
palletDeviceBindingList.forEach(palletDeviceBinding -> {
palletDeviceBinding.setUpdateTime(DateUtils.getNowDate());
palletDeviceBinding.setCreateTime(DateUtils.getNowDate());
......@@ -117,8 +117,11 @@ public class PalletDeviceBindingServiceImpl implements IPalletDeviceBindingServi
tTrayInfo.setfTrayId(palletDeviceBindingList.get(0).getTrayId());
tTrayInfo.setfStatus("4");
tTrayInfoMapper.updateStatusByTrayId(tTrayInfo);
return palletDeviceBindingMapper.batchInsertPalletDeviceBinding(palletDeviceBindingList);
int i = palletDeviceBindingMapper.batchInsertPalletDeviceBinding(palletDeviceBindingList);
if(i <= 0) {
throw new RuntimeException("添加失败");
}
return palletDeviceBindingList;
}
@Override
......
......@@ -15,9 +15,7 @@ import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.core.redis.RedisCache;
import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TEquipmentInfo;
import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.domain.TTrayInfo;
import com.zehong.system.domain.*;
import com.zehong.system.mapper.*;
import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.netty.handler.NettyUdpServerHandler;
......@@ -31,7 +29,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import com.zehong.system.domain.RobotArmCommand;
import com.zehong.system.service.IRobotArmCommandService;
import org.springframework.transaction.annotation.Transactional;
......@@ -101,47 +98,89 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
if (cacheObject != null) {
priority = (String) cacheObject;
}
// // 1. 处理待执行的上料指令
// List<RobotArmCommand> loadingCommands =
// robotArmCommandMapper.selectPendingLoadingCommands();
// // 2. 处理待执行的下料指令
// List<RobotArmCommand> unloadingCommands =
// robotArmCommandMapper.selectPendingUnloadingCommands();
// 合并查询:同时获取上料、下料各1条待执行指令
List<RobotArmCommand> pendingCommands = robotArmCommandMapper.selectPendingLoadUnloadCommands();
String feedConveyorIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.FEED_CONVEYOR_IP_AND_PORT);
String feedIp ;
int feedPort ;
if (StringUtils.isNotBlank(feedConveyorIpAndPort)) {
String[] split = feedConveyorIpAndPort.split(":");
feedIp = split[0];
feedPort = Integer.parseInt(split[1]);
// 1. 处理待执行的上料指令
List<RobotArmCommand> loadingCommands =
robotArmCommandMapper.selectPendingLoadingCommands();
if (!loadingCommands.isEmpty() && "loading".equals(priority)) {
String outLetBeltIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.OUT_LET_BELT_IP_AND_PORT);
String outLetBeltIp;
int outLetBeltPort;
// 区分上料、下料指令(根据f_type)
RobotArmCommand loadingCommand = null;
RobotArmCommand unloadingCommand = null;
for (RobotArmCommand command : pendingCommands) {
if ("0".equals(command.getType())) { // 上料指令(type=0)
loadingCommand = command;
} else if ("1".equals(command.getType())) { // 下料指令(type=1)
unloadingCommand = command;
}
}
if(StringUtils.isNotBlank(feedConveyorIpAndPort) && StringUtils.isNotBlank(outLetBeltIpAndPort)) {
String[] splitFeed = feedConveyorIpAndPort.split(":");
feedIp = splitFeed[0];
feedPort = Integer.parseInt(splitFeed[1]);
String[] splitOut = outLetBeltIpAndPort.split(":");
outLetBeltIp = splitOut[0];
outLetBeltPort = Integer.parseInt(splitOut[1]);
if((loadingCommand != null && "loading".equals(priority)) ||
(unloadingCommand == null && loadingCommand != null && "unloading".equals(priority))) {
// 传送带检测先去掉
boolean[] roboticArmEntryConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(feedIp,feedPort);
boolean[] roboticArmEntryConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(feedIp,feedPort);
log.info("机械臂入口 conveyor 0状态: " + roboticArmEntryConveyorData[0]);
log.info("机械臂入口 conveyor 1状态: " + roboticArmEntryConveyorData[1]);
if(roboticArmEntryConveyorData[1]) {
sendCommand(loadingCommands.get(0), "LOAD");
return;
sendCommand(loadingCommand, "LOAD");
}
}
}
String outLetBeltIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.OUT_LET_BELT_IP_AND_PORT);
String outLetBeltIp;
int outLetBeltPort;
if (StringUtils.isNotBlank(outLetBeltIpAndPort)) {
String[] split = outLetBeltIpAndPort.split(":");
outLetBeltIp = split[0];
outLetBeltPort = Integer.parseInt(split[1]);
// 2. 处理待执行的下料指令
List<RobotArmCommand> unloadingCommands =
robotArmCommandMapper.selectPendingUnloadingCommands();
if (!unloadingCommands.isEmpty()) {
} else if(unloadingCommand != null) {
boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(outLetBeltIp,outLetBeltPort);
if(roboticArmExitConveyorData[0]) {
log.info("开始处理下料指令: {}", unloadingCommands.get(0));
sendCommand(unloadingCommands.get(0), "UNLOAD");
log.info("开始处理下料指令: {}", unloadingCommand);
sendCommand(unloadingCommand, "UNLOAD");
}
}
}
// if (StringUtils.isNotBlank(feedConveyorIpAndPort)) {
// String[] split = feedConveyorIpAndPort.split(":");
// feedIp = split[0];
// feedPort = Integer.parseInt(split[1]);
// if ((!loadingCommands.isEmpty() && "loading".equals(priority)) ||
// (unloadingCommands.isEmpty() && !loadingCommands.isEmpty() &&"unloading".equals(priority))) {
// // 传送带检测先去掉
// boolean[] roboticArmEntryConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(feedIp,feedPort);
//
// log.info("机械臂入口 conveyor 0状态: " + roboticArmEntryConveyorData[0]);
// log.info("机械臂入口 conveyor 1状态: " + roboticArmEntryConveyorData[1]);
// if(roboticArmEntryConveyorData[1]) {
// sendCommand(loadingCommands.get(0), "LOAD");
// return;
// }
// }
// }
//
// if (StringUtils.isNotBlank(outLetBeltIpAndPort)) {
// String[] split = outLetBeltIpAndPort.split(":");
// outLetBeltIp = split[0];
// outLetBeltPort = Integer.parseInt(split[1]);
// if (!unloadingCommands.isEmpty()) {
// boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(outLetBeltIp,outLetBeltPort);
// if(roboticArmExitConveyorData[0]) {
// log.info("开始处理下料指令: {}", unloadingCommands.get(0));
// sendCommand(unloadingCommands.get(0), "UNLOAD");
// }
// }
// }
}
......@@ -308,7 +347,7 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
String storeyCode = command.getStoreyCode();
String equitmentCode;
Integer registerOffset;
int registerOffset;
if(storeyCode.contains("-")) {
log.info("storeyCode.contains(\"-\")");
String[] parts = storeyCode.split("-");
......
......@@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="row" column="f_row" />
<result property="col" column="f_col" />
<result property="index" column="f_index" />
<result property="number" column="f_number" />
<result property="bindingTime" column="f_binding_time" />
<result property="unbindingTime" column="f_unbinding_time" />
<result property="createTime" column="f_create_time" />
......@@ -35,6 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
palDeviceBinding.f_row,
palDeviceBinding.f_col,
palDeviceBinding.f_index,
palDeviceBinding.f_number,
palDeviceBinding.f_binding_time,
palDeviceBinding.f_unbinding_time,
palDeviceBinding.f_create_time,
......@@ -69,6 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="row != null "> and palDeviceBinding.f_row = #{row}</if>
<if test="col != null "> and palDeviceBinding.f_col = #{col}</if>
<if test="index != null "> and palDeviceBinding.f_index = #{index}</if>
<if test="number != null "> and palDeviceBinding.f_number = #{number}</if>
<if test="bindingTime != null "> and palDeviceBinding.f_binding_time = #{bindingTime}</if>
<if test="unbindingTime != null "> and palDeviceBinding.f_unbinding_time = #{unbindingTime}</if>
<if test="createTime != null "> and palDeviceBinding.f_create_time = #{createTime}</if>
......@@ -93,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
f_row,
f_col,
f_index,
f_number,
f_binding_time,
f_unbinding_time,
f_create_time,
......@@ -117,13 +121,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<insert id="batchInsertPalletDeviceBinding" parameterType="list">
insert into t_pallet_device_binding (f_tray_id, f_device_code,f_row,f_col,f_index,f_binding_time,f_binding_time,
<insert id="batchInsertPalletDeviceBinding" parameterType="list" useGeneratedKeys="true" keyProperty="palletDeviceBindingId">
insert into t_pallet_device_binding (f_tray_id, f_device_code,f_row,f_col,f_index,f_number,f_binding_time,
f_create_time,f_status)
values
<foreach collection="palletDeviceBindingList" item="item" index="index" separator=",">
(
#{item.trayId}, #{item.deviceCode}, #{item.row}, #{item.col}, #{item.index},#{item.bindingTime},
#{item.trayId}, #{item.deviceCode}, #{item.row}, #{item.col},#{item.index},#{item.number},
#{item.bindingTime},#{item.createTime},#{item.status}
)
</foreach>
......@@ -153,6 +157,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="row != null">f_row,</if>
<if test="col != null">f_col,</if>
<if test="index != null">f_index,</if>
<if test="number != null">f_number,</if>
<if test="bindingTime != null">f_binding_time,</if>
<if test="unbindingTime != null">f_unbinding_time,</if>
<if test="createTime != null">f_create_time,</if>
......@@ -164,6 +169,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="row != null">#{row},</if>
<if test="col != null">#{col},</if>
<if test="index != null">#{index},</if>
<if test="number != null">#{number},</if>
<if test="bindingTime != null">#{bindingTime},</if>
<if test="unbindingTime != null">#{unbindingTime},</if>
<if test="createTime != null">#{createTime},</if>
......@@ -195,6 +201,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="row != null">f_row = #{row},</if>
<if test="col != null">f_col = #{col},</if>
<if test="index != null">f_index = #{index},</if>
<if test="number != null">f_number = #{number},</if>
<if test="bindingTime != null">f_binding_time = #{bindingTime},</if>
<if test="unbindingTime != null">f_unbinding_time = #{unbindingTime},</if>
<if test="createTime != null">f_create_time = #{createTime},</if>
......
......@@ -152,6 +152,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ORDER BY f_create_time ASC
LIMIT 1
</select>
<!-- 同时获取待执行的上料指令(type=0)和下料指令(type=1),各1条 -->
<select id="selectPendingLoadUnloadCommands" resultMap="RobotArmCommandResult">
<!-- 子查询1:上料指令(type=0),取最早创建的1条 -->
SELECT * FROM (
<include refid="selectRobotArmCommandVo"/>
WHERE f_type = '0' AND f_status = '1'
ORDER BY f_create_time ASC
LIMIT 1
) AS loading
UNION ALL
<!-- 子查询2:下料指令(type=1),取最早创建的1条 -->
SELECT * FROM (
<include refid="selectRobotArmCommandVo"/>
WHERE f_type = '1' AND f_status = '1'
ORDER BY f_create_time ASC
LIMIT 1
) AS unloading
</select>
<delete id="deleteRobotArmCommandById" parameterType="Long">
delete from t_robot_arm_command where f_robot_arm_command_id = #{robotArmCommandId}
</delete>
......
......@@ -178,12 +178,31 @@ export default {
initialAbnormalCount: 0,
// 设备矩阵数据 (8x9 = 72个设备)
devices: Array(72).fill().map((_, i) => ({
index: i + 1,
deviceCode: '',
row: Math.floor(i / 9) + 1,
col: (i % 9) + 1
})),
devices: Array(72).fill().map((_, i) => {
const row = Math.floor(i / 9) + 1; // 1-8行
const col = (i % 9) + 1; // 1-9列
let number;
// 计算当前行的起始数字
const rowStart = (row - 1) * 9 + 1;
const rowEnd = row * 9;
if (row % 2 === 1) {
// 奇数行:从左到右递增(1-9, 19-27, 37-45, 55-63)
number = rowStart + (col - 1);
} else {
// 偶数行:从右到左递增(18-10, 36-28, 54-46, 72-64)
number = rowEnd - (col - 1);
}
return {
index: i + 1,
number: number,
deviceCode: '',
row: row,
col: col
}
}),
// 当前激活的单元格
activeCell: 0,
......@@ -274,13 +293,32 @@ export default {
} else {
// 初始化设备矩阵数据 (8x9 = 72个设备)
this.devices = Array(72).fill().map((_, i) => ({
index: i + 1,
trayId: this.fTrayId,
deviceCode: '',
row: Math.floor(i / 9) + 1,
col: (i % 9) + 1
}))
this.devices = Array(72).fill().map((_, i) => {
const row = Math.floor(i / 9) + 1; // 1-8行
const col = (i % 9) + 1; // 1-9列
let number;
// 计算当前行的起始数字
const rowStart = (row - 1) * 9 + 1;
const rowEnd = row * 9;
if (row % 2 === 1) {
// 奇数行:从左到右递增(1-9, 19-27, 37-45, 55-63)
number = rowStart + (col - 1);
} else {
// 偶数行:从右到左递增(18-10, 36-28, 54-46, 72-64)
number = rowEnd - (col - 1);
}
return {
trayId: this.fTrayId,
index: i + 1,
number: number,
deviceCode: '',
row: row,
col: col
}
})
}
})
},
......@@ -434,6 +472,8 @@ export default {
if(palletDeviceBindingId == null) {
batchAdd(this.devices).then(res => {
if (res.code === 200) {
this.devices = res.data;
this.trayStatus = '4';
this.msgSuccess("绑定成功");
} else {
this.msgError("绑定失败");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment