|
|
|
|
@ -8,6 +8,7 @@ import com.zhehekeji.web.config.ConfigProperties;
|
|
|
|
|
import com.zhehekeji.web.entity.*;
|
|
|
|
|
import com.zhehekeji.web.lib.*;
|
|
|
|
|
import com.zhehekeji.web.mapper.*;
|
|
|
|
|
import com.zhehekeji.web.pojo.AlgorithmPojo;
|
|
|
|
|
import com.zhehekeji.web.pojo.OrderVO;
|
|
|
|
|
import com.zhehekeji.web.pojo.camera.CameraPtzPojo;
|
|
|
|
|
import com.zhehekeji.web.pojo.stock.StockStatus;
|
|
|
|
|
@ -20,6 +21,7 @@ import com.zhehekeji.web.service.client.TransmissionPojo;
|
|
|
|
|
import com.zhehekeji.web.service.client.TransmissionType;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecDataInfo;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecInfo;
|
|
|
|
|
import com.zhehekeji.web.service.ksec.KsecNettyClient;
|
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
@ -663,7 +665,7 @@ public class PlcService {
|
|
|
|
|
|
|
|
|
|
Lock lock = new ReentrantLock();
|
|
|
|
|
|
|
|
|
|
public void check(PlcCmdInfo plcCmdInfo, KsecDataInfo dataInfo) {
|
|
|
|
|
public boolean check(PlcCmdInfo plcCmdInfo, KsecDataInfo dataInfo) {
|
|
|
|
|
Street street = streetService.getStreetByPlcId(dataInfo.getSRMNumber());
|
|
|
|
|
|
|
|
|
|
//开始盘点具体货位
|
|
|
|
|
@ -683,7 +685,6 @@ public class PlcService {
|
|
|
|
|
checkLog.setWmsCount(dataInfo.getQuantity());
|
|
|
|
|
checkLog.setWmsCategory(dataInfo.getTypeNum());
|
|
|
|
|
|
|
|
|
|
checkLogMapper.insert(checkLog);
|
|
|
|
|
//如果存在则清空表
|
|
|
|
|
if (stockMapper.selectCount(new QueryWrapper<Stock>().eq("lotnum", checkLog.getLotnum())) == 0) {
|
|
|
|
|
stockMapper.delete(new QueryWrapper<Stock>().ne("lotnum", checkLog.getLotnum()));
|
|
|
|
|
@ -710,43 +711,66 @@ public class PlcService {
|
|
|
|
|
if(stock.getCategory().length() == 6) {
|
|
|
|
|
stock.setStatus(StockStatus.PENDING.getStatus());
|
|
|
|
|
}
|
|
|
|
|
stock.setExportTime(LocalDateTime.now());
|
|
|
|
|
if (stock.getId() == null) {
|
|
|
|
|
stockMapper.insert(stock);
|
|
|
|
|
} else stockMapper.updateById(stock);
|
|
|
|
|
TransmissionPojo transmissionPojo = new TransmissionPojo(checkLog, street);
|
|
|
|
|
if (ClientChanel.get(dataInfo.getSRMNumber()) != null) {
|
|
|
|
|
ClientChanel.get(dataInfo.getSRMNumber()).writeAndFlush(transmissionPojo.toString(TransmissionType.ST));
|
|
|
|
|
} else {
|
|
|
|
|
log.error("未找到对应plc" + transmissionPojo.toString());
|
|
|
|
|
}
|
|
|
|
|
//取货完成进行拍照
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
//不为其他状态进入队列
|
|
|
|
|
if (lock.tryLock()) {
|
|
|
|
|
//队列中没有任务,发送取图指令
|
|
|
|
|
//只采用队列,队列中有数据则自动发送
|
|
|
|
|
//模拟随行
|
|
|
|
|
if (configProperties.isInventorySimulationFollow() ) {
|
|
|
|
|
TransmissionPojo transmissionPojoFollow = new TransmissionPojo(street, transmissionPojo.getRow(),transmissionPojo.getColumn(),transmissionPojo.getDirection(), "");
|
|
|
|
|
String s = (transmissionPojoFollow).toString(TransmissionType.GPS);
|
|
|
|
|
//进行品规识别,完成进行拍照
|
|
|
|
|
if( stock.getCategory() != null && "20".equals(stock.getCategory())) {
|
|
|
|
|
checkLog.setStatus(StockStatus.OTHER.getStatus());
|
|
|
|
|
stock.setStatus(StockStatus.OTHER.getStatus());
|
|
|
|
|
}
|
|
|
|
|
AlgorithmPojo algorithmPojo = sendHttp(street,stock.getDirection(),dataInfo.getTypeNum());
|
|
|
|
|
if (algorithmPojo!=null){
|
|
|
|
|
if (algorithmPojo.getResult()){
|
|
|
|
|
checkLog.setStatus(StockStatus.SUCCESS.getStatus());
|
|
|
|
|
stock.setStatus(StockStatus.SUCCESS.getStatus());
|
|
|
|
|
stock.setCategory(dataInfo.getTypeNum());
|
|
|
|
|
|
|
|
|
|
//放置到队列中,等待取图返回后删除
|
|
|
|
|
GetPhotoDelayExecutor.addCameraDelayTask(street.getPlcId(), s, configProperties.getQueueSpanTime(),transmissionPojoFollow);
|
|
|
|
|
checkLog.setCategory(dataInfo.getTypeNum());
|
|
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
checkLog.setStatus(StockStatus.ERROR.getStatus());
|
|
|
|
|
stock.setStatus(StockStatus.ERROR.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//放置到队列中,等待取图返回后删除
|
|
|
|
|
GetPhotoDelayExecutor.addCameraDelayTask(street.getPlcId(), transmissionPojo.toString(TransmissionType.GPS), configProperties.getQueueSpanTime(),transmissionPojo);
|
|
|
|
|
}
|
|
|
|
|
checkLog.setPic("http://"+street.getPlcIp()+":9007/pic/"+algorithmPojo.getDeterminePath());
|
|
|
|
|
stock.setCheckPic("http://"+street.getPlcIp()+":9007/pic/"+algorithmPojo.getDeterminePath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("取图命令 error", e);
|
|
|
|
|
} finally {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
log.info("盘点完成");
|
|
|
|
|
}
|
|
|
|
|
checkLogMapper.insert(checkLog);
|
|
|
|
|
stock.setExportTime(LocalDateTime.now());
|
|
|
|
|
if (stock.getId() == null) {
|
|
|
|
|
stockMapper.insert(stock);
|
|
|
|
|
} else stockMapper.updateById(stock);
|
|
|
|
|
if (algorithmPojo != null) {
|
|
|
|
|
return algorithmPojo.getResult();
|
|
|
|
|
}else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
// //不为其他状态进入队列
|
|
|
|
|
// if (lock.tryLock()) {
|
|
|
|
|
// //队列中没有任务,发送取图指令
|
|
|
|
|
// //只采用队列,队列中有数据则自动发送
|
|
|
|
|
// //模拟随行
|
|
|
|
|
// if (configProperties.isInventorySimulationFollow() ) {
|
|
|
|
|
// TransmissionPojo transmissionPojoFollow = new TransmissionPojo(street, transmissionPojo.getRow(),transmissionPojo.getColumn(),transmissionPojo.getDirection(), "");
|
|
|
|
|
// String s = (transmissionPojoFollow).toString(TransmissionType.GPS);
|
|
|
|
|
//
|
|
|
|
|
// //放置到队列中,等待取图返回后删除
|
|
|
|
|
// GetPhotoDelayExecutor.addCameraDelayTask(street.getPlcId(), s, configProperties.getQueueSpanTime(),transmissionPojoFollow);
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// //放置到队列中,等待取图返回后删除
|
|
|
|
|
// GetPhotoDelayExecutor.addCameraDelayTask(street.getPlcId(), transmissionPojo.toString(TransmissionType.GPS), configProperties.getQueueSpanTime(),transmissionPojo);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// log.error("取图命令 error", e);
|
|
|
|
|
// } finally {
|
|
|
|
|
// lock.unlock();
|
|
|
|
|
// log.info("盘点完成");
|
|
|
|
|
// }
|
|
|
|
|
// ClientChanel.get(dataInfo.getSRMNumber()).writeAndFlush();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -780,6 +804,30 @@ public class PlcService {
|
|
|
|
|
checkLogMapper.updateById(checkLog);
|
|
|
|
|
stockMapper.updateById(stock);
|
|
|
|
|
}
|
|
|
|
|
public static AlgorithmPojo sendHttp(Street street,Integer direction , String category ){
|
|
|
|
|
// 创建RestTemplate实例
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
|
|
// 定义请求URL
|
|
|
|
|
String url = "http://"+street.getPlcIp()+":8097/hik/distinguish?streetNumber={streetNumber}&direction={direction}&category={category}";
|
|
|
|
|
|
|
|
|
|
// 定义请求参数
|
|
|
|
|
// 替换为实际的category
|
|
|
|
|
|
|
|
|
|
// 发送GET请求并获取响应
|
|
|
|
|
ResponseEntity<AlgorithmPojo> response = restTemplate.getForEntity(url, AlgorithmPojo.class, street.getPlcId(),direction, category);
|
|
|
|
|
|
|
|
|
|
// 输出响应结果
|
|
|
|
|
if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
|
|
|
|
|
|
|
System.out.println("Distinguish result: " + response);
|
|
|
|
|
return response.getBody();
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("Failed to get response. Status code: " + response.getStatusCode());
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int sendHttp(String streetNumber,PlcCmdInfo plcCmdInfo, KsecDataInfo dataInfo){
|
|
|
|
|
Street street = streetService.getStreetByPlcId(streetNumber);
|
|
|
|
|
@ -787,13 +835,14 @@ public class PlcService {
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
|
|
|
|
|
// 定义 URL
|
|
|
|
|
String url = "http://"+street.getPlcIp()+":8097/category/getBoxCount";
|
|
|
|
|
String url = "http://"+street.getPlcIp()+":8097/category/getBoxCountByCategory?streetId={streetNumber}&category={category}";
|
|
|
|
|
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
int count = 0;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
// 发起 GET 请求
|
|
|
|
|
ResponseEntity<Integer> response = restTemplate.getForEntity(url, Integer.class);
|
|
|
|
|
ResponseEntity<Integer> response = restTemplate.getForEntity(url, Integer.class,streetNumber,plcCmdInfo.getCategoryName());
|
|
|
|
|
count = response.getBody();
|
|
|
|
|
flag = true;
|
|
|
|
|
|
|
|
|
|
|