电子标签读取线程
This commit is contained in:
@@ -102,14 +102,16 @@ public class ToWmsServiceImpl implements IToWmsService {
|
|||||||
if(mydoJobs.isEmpty()){
|
if(mydoJobs.isEmpty()){
|
||||||
return AjaxResult.warn(MessageUtils.message("warn.message"));
|
return AjaxResult.warn(MessageUtils.message("warn.message"));
|
||||||
}
|
}
|
||||||
MydoJob mydoJob = mydoJobs.get(0);
|
|
||||||
if ("1".equals(mydoJob.getExecutionPhase())){
|
for (MydoJob mydoJob : mydoJobs) {
|
||||||
mydoJob.setExecutionPhase("2");
|
if ("1".equals(mydoJob.getExecutionPhase())){
|
||||||
mydoJob.setTrayCode(param.getTrayCode());
|
mydoJob.setExecutionPhase("2");
|
||||||
mydoJob.setStatus("2");
|
mydoJob.setTrayCode(param.getTrayCode());
|
||||||
mydoJobService.updateMydoJob(mydoJob);
|
mydoJob.setStatus("2");
|
||||||
|
mydoJobService.updateMydoJob(mydoJob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return AjaxResult.success(mydoJob);
|
return AjaxResult.success(mydoJobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
import com.ruoyi.job.mydojob.domain.MydoJob;
|
import com.ruoyi.job.mydojob.domain.MydoJob;
|
||||||
import com.ruoyi.job.mydojob.service.IMydoJobService;
|
import com.ruoyi.job.mydojob.service.IMydoJobService;
|
||||||
|
import com.ruoyi.out.tagTask.thread.TagReadThread;
|
||||||
import com.ruoyi.out.tagTask.util.ElectronicTagClient;
|
import com.ruoyi.out.tagTask.util.ElectronicTagClient;
|
||||||
import com.ruoyi.pda.domain.TrayCodeMakeSure;
|
import com.ruoyi.pda.domain.TrayCodeMakeSure;
|
||||||
import com.ruoyi.pda.domain.TrayCodeMsg;
|
import com.ruoyi.pda.domain.TrayCodeMsg;
|
||||||
@@ -130,26 +131,7 @@ public class TagTaskServiceImpl implements ITagTaskService {
|
|||||||
List<TagTask> tagTaskList = tagGroup.get(tagId);
|
List<TagTask> tagTaskList = tagGroup.get(tagId);
|
||||||
if (CollUtil.isNotEmpty(tagTaskList)) {
|
if (CollUtil.isNotEmpty(tagTaskList)) {
|
||||||
|
|
||||||
if (tagTaskList.stream().allMatch(x -> "2".equals(x.getStatus()))) {
|
if (!tagTaskList.stream().allMatch(x -> "2".equals(x.getStatus()))) {
|
||||||
//全部拣选完成 灭灯逻辑
|
|
||||||
//灭灯
|
|
||||||
boolean b = sendDzbqOff(basTag);
|
|
||||||
log.info("灭灯:{}", b);
|
|
||||||
if (b) {
|
|
||||||
//出库确认
|
|
||||||
TrayCodeMakeSure trayCodeMakeSure = new TrayCodeMakeSure();
|
|
||||||
trayCodeMakeSure.setTrayCode(basTag.getTrayCode());
|
|
||||||
AjaxResult ajaxResult = pdaService.outMakeSure(trayCodeMakeSure);
|
|
||||||
if (ajaxResult.isSuccess()){
|
|
||||||
//删除标签绑定信息
|
|
||||||
basTag.setSendCompleted("0");
|
|
||||||
basTag.setTrayCode("");
|
|
||||||
basTagService.updateBasTag(basTag);
|
|
||||||
//删除tagList
|
|
||||||
tagTaskMapper.deleteTagTaskByIds(tagTaskList.stream().map(TagTask::getId).toArray(Long[]::new));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Optional<TagTask> first = tagTaskList.stream().filter(x -> "1".equals(x.getStatus())).findFirst();
|
Optional<TagTask> first = tagTaskList.stream().filter(x -> "1".equals(x.getStatus())).findFirst();
|
||||||
if (first.isPresent()) {
|
if (first.isPresent()) {
|
||||||
TagTask tagTask = first.get();
|
TagTask tagTask = first.get();
|
||||||
@@ -165,8 +147,8 @@ public class TagTaskServiceImpl implements ITagTaskService {
|
|||||||
tagTask.setStatus("1");
|
tagTask.setStatus("1");
|
||||||
tagTaskMapper.updateTagTask(tagTask);
|
tagTaskMapper.updateTagTask(tagTask);
|
||||||
log.info("下发电子标签:ip:" + basTag.getIp() + ",id:" + basTag.getId() + "数量:" + basTag.getCurNum());
|
log.info("下发电子标签:ip:" + basTag.getIp() + ",id:" + basTag.getId() + "数量:" + basTag.getCurNum());
|
||||||
} else {
|
//开线程一直读取电子标签数据
|
||||||
sendMsgDzbq(basTag,tagTask);
|
new Thread(new TagReadThread(tagTaskMapper,basTagService,pdaService)).start();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info(e.getMessage(), e.getMessage());
|
log.info(e.getMessage(), e.getMessage());
|
||||||
@@ -177,49 +159,6 @@ public class TagTaskServiceImpl implements ITagTaskService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//查询所有下发的任务
|
|
||||||
tagTaskParam = new TagTask();
|
|
||||||
tagTaskParam.setStatus("1");
|
|
||||||
allTagTasks = tagTaskMapper.selectTagTaskList(tagTaskParam);
|
|
||||||
if (CollUtil.isNotEmpty(allTagTasks)) {
|
|
||||||
Map<Long, List<TagTask>> tagGroup = allTagTasks.stream().collect(Collectors.groupingBy(TagTask::getTagId));
|
|
||||||
for (Long tagId : tagGroup.keySet()) {
|
|
||||||
BasTag basTag = basTagService.selectBasTagById(tagId);
|
|
||||||
Socket socket = getSocket(basTag);
|
|
||||||
try {
|
|
||||||
/** 接收电子标签指令 */
|
|
||||||
String content = ElectronicTagClient.receiveHexData(socket,3000);//读取值
|
|
||||||
if (!content.isEmpty()) {
|
|
||||||
log.info("读取电子标签值:" + content);
|
|
||||||
}
|
|
||||||
for (TagTask tagTask : tagGroup.get(tagId)) {
|
|
||||||
//将拍灯指令整理成数组
|
|
||||||
String[] split = content.split("5A");
|
|
||||||
for (String s : split) {
|
|
||||||
if (s.length() == 10) {
|
|
||||||
String type = s.substring(4, 6);//指令类型 01是下发成功反馈 12是拍灭绿灯指令
|
|
||||||
if ("12".equals(type)) {
|
|
||||||
//12为 绿色拍灯指令
|
|
||||||
int address = new BigInteger(s.substring(2, 4), 16).intValue();
|
|
||||||
if (address == basTag.getId()) {
|
|
||||||
//更新当前子任务状态
|
|
||||||
tagTask.setStatus("2");
|
|
||||||
tagTaskMapper.updateTagTask(tagTask);
|
|
||||||
log.info("更新任务状态:" + tagTask.getProductId() + ",id:" + tagTask.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package com.ruoyi.out.tagTask.thread;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import com.ruoyi.bas.tag.domain.BasTag;
|
||||||
|
import com.ruoyi.bas.tag.service.IBasTagService;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import com.ruoyi.out.tagTask.domain.TagTask;
|
||||||
|
import com.ruoyi.out.tagTask.mapper.TagTaskMapper;
|
||||||
|
import com.ruoyi.out.tagTask.util.ElectronicTagClient;
|
||||||
|
import com.ruoyi.pda.domain.TrayCodeMakeSure;
|
||||||
|
import com.ruoyi.pda.service.PdaService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class TagReadThread implements Runnable{
|
||||||
|
|
||||||
|
private TagTaskMapper tagTaskMapper;
|
||||||
|
private IBasTagService basTagService;
|
||||||
|
private PdaService pdaService;
|
||||||
|
|
||||||
|
public TagReadThread(TagTaskMapper tagTaskMapper, IBasTagService basTagService,PdaService pdaService) {
|
||||||
|
this.tagTaskMapper = tagTaskMapper;
|
||||||
|
this.basTagService = basTagService;
|
||||||
|
this.pdaService = pdaService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
//查询所有下发的任务
|
||||||
|
TagTask tagTaskParam = new TagTask();
|
||||||
|
tagTaskParam.setStatus("1");
|
||||||
|
List<TagTask> allTagTasks = tagTaskMapper.selectTagTaskList(tagTaskParam);
|
||||||
|
if (CollUtil.isNotEmpty(allTagTasks)) {
|
||||||
|
Map<Long, List<TagTask>> tagGroup = allTagTasks.stream().collect(Collectors.groupingBy(TagTask::getTagId));
|
||||||
|
for (Long tagId : tagGroup.keySet()) {
|
||||||
|
BasTag basTag = basTagService.selectBasTagById(tagId);
|
||||||
|
try (Socket socket = getSocket(basTag)){
|
||||||
|
/** 接收电子标签指令 */
|
||||||
|
String content = ElectronicTagClient.receiveHexData(socket,0);//读取值
|
||||||
|
if (!content.isEmpty()) {
|
||||||
|
System.out.println("读取电子标签值:" + content);
|
||||||
|
}
|
||||||
|
for (TagTask tagTask : tagGroup.get(tagId)) {
|
||||||
|
//将拍灯指令整理成数组
|
||||||
|
String[] split = content.split("5A");
|
||||||
|
for (String s : split) {
|
||||||
|
if (s.length() == 10) {
|
||||||
|
String type = s.substring(4, 6);//指令类型 01是下发成功反馈 12是拍灭绿灯指令
|
||||||
|
if ("12".equals(type)) {
|
||||||
|
//12为 绿色拍灯指令
|
||||||
|
int address = new BigInteger(s.substring(2, 4), 16).intValue();
|
||||||
|
if (address == basTag.getId()) {
|
||||||
|
//更新当前子任务状态
|
||||||
|
tagTask.setStatus("2");
|
||||||
|
tagTaskMapper.updateTagTask(tagTask);
|
||||||
|
System.out.println("更新任务状态:" + tagTask.getProductId() + ",id:" + tagTask.getId());
|
||||||
|
TagTask param = new TagTask();
|
||||||
|
param.setTagId(tagId);
|
||||||
|
List<TagTask> tagTasks = tagTaskMapper.selectTagTaskList(param);
|
||||||
|
if (CollUtil.isNotEmpty(tagTasks)){
|
||||||
|
if (tagTasks.stream().allMatch(x-> "2".equals(x.getStatus()))){
|
||||||
|
//全部拣选完成 灭灯逻辑
|
||||||
|
//灭灯
|
||||||
|
boolean b = sendDzbqOff(basTag);
|
||||||
|
if (b) {
|
||||||
|
//出库确认
|
||||||
|
TrayCodeMakeSure trayCodeMakeSure = new TrayCodeMakeSure();
|
||||||
|
trayCodeMakeSure.setTrayCode(basTag.getTrayCode());
|
||||||
|
AjaxResult ajaxResult = pdaService.outMakeSure(trayCodeMakeSure);
|
||||||
|
if (ajaxResult.isSuccess()){
|
||||||
|
//删除标签绑定信息
|
||||||
|
basTag.setSendCompleted("0");
|
||||||
|
basTag.setTrayCode("");
|
||||||
|
basTagService.updateBasTag(basTag);
|
||||||
|
//删除tagList
|
||||||
|
tagTaskMapper.deleteTagTaskByIds(tagTasks.stream().map(TagTask::getId).toArray(Long[]::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取socket
|
||||||
|
*
|
||||||
|
* @param basTag
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Socket getSocket(BasTag basTag) {
|
||||||
|
try {
|
||||||
|
return new Socket(basTag.getIp(), 20108);
|
||||||
|
}catch (Exception e){
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 灭灯
|
||||||
|
*
|
||||||
|
* @param basTag
|
||||||
|
*/
|
||||||
|
public boolean sendDzbqOff(BasTag basTag) throws IOException {
|
||||||
|
int address = Convert.toInt(basTag.getId());
|
||||||
|
Socket socket = getSocket(basTag);
|
||||||
|
int x7 = (address + 0x10 + 0x03 + 0xe8 + 0x03 + 0xe8) % 256;//累加 校验
|
||||||
|
return ElectronicTagClient.sendHexData( socket,"FA " + String.format("%02x", address) + " 10 00 03 e8 03 e8 " + String.format("%02x", x7) + " AF");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,7 +62,7 @@ public class ElectronicTagClient {
|
|||||||
* @throws IOException 如果发生I/O错误或超时
|
* @throws IOException 如果发生I/O错误或超时
|
||||||
*/
|
*/
|
||||||
public static String receiveHexData(Socket socket, int timeoutMillis) throws IOException {
|
public static String receiveHexData(Socket socket, int timeoutMillis) throws IOException {
|
||||||
socket.setSoTimeout(timeoutMillis);
|
//socket.setSoTimeout(timeoutMillis);
|
||||||
InputStream input = socket.getInputStream();
|
InputStream input = socket.getInputStream();
|
||||||
|
|
||||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export default {
|
|||||||
this.getListData()
|
this.getListData()
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
this.getListData()
|
this.getListData()
|
||||||
}, 5000)
|
}, 30000)
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.timer) {
|
if (this.timer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user