盘点lotnum批次号保存

taiwan-lingli-new
yiming 4 years ago
parent 6851ad02a9
commit c4dca6d40f

@ -0,0 +1,59 @@
package com.zhehekeji.common.util;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
@Slf4j
public class FileUtil {
public static void save(String text,String path){
//判断文件是否存在
File file = new File(path);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(text.getBytes());
fileOutputStream.close();
log.info("write text success :{}",text);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String getText(String path){
File file = new File(path);
if(file.exists()){
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[1024];//定义字节长度
int len = 0;
String txt = null;
while ((len = fileInputStream.read(bytes)) != -1) {//与文件读取出来的长度比较,内部有数据读完是-1,所以不等于-1
txt = new String(bytes, 0, len);//从0取到有数据的末尾
}
fileInputStream.close();
return txt;
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
public static void main(String[] args) {
String path = "./lotnum_now";
save("www",path);
getText(path);
}
}

@ -1,5 +1,6 @@
package com.zhehekeji.web.service;
import com.zhehekeji.common.util.FileUtil;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.entity.Camera;
import com.zhehekeji.web.entity.Street;
@ -12,6 +13,7 @@ import com.zhehekeji.web.lib.joyware.NetSDKLib;
import com.zhehekeji.web.mapper.CameraMapper;
import com.zhehekeji.web.mapper.SensorGunMapper;
import com.zhehekeji.web.mapper.StreetMapper;
import com.zhehekeji.web.service.ksec.KsecDecoder;
import com.zhehekeji.web.service.ksec.KsecNettyClient;
import com.zhehekeji.web.service.robotic.NettyClient;
import com.zhehekeji.web.service.sick.SickNettyClient;
@ -78,6 +80,10 @@ public class InitService implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
String lotnum = FileUtil.getText("lastLotnum");
if(lotnum != null){
KsecDecoder.setLastLotnum(lotnum);
}
//球机登录
List<Camera> cameras = cameraMapper.selectByMap(new HashMap<>(0));
cameras.forEach(camera -> {

@ -1,6 +1,7 @@
package com.zhehekeji.web.service.ksec;
import com.alibaba.fastjson.JSONObject;
import com.zhehekeji.common.util.FileUtil;
import com.zhehekeji.web.entity.Stock;
import com.zhehekeji.web.pojo.Cmd;
import com.zhehekeji.web.service.GoodsActionTimes;
@ -24,6 +25,10 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
private static final Logger tcpLogger = LoggerFactory.getLogger("tcp");
public static void setLastLotnum(String lotnum){
lastLotnum = lotnum;
}
private static String lastLotnum;
private PlcService plcService;
@ -109,6 +114,7 @@ public class KsecDecoder extends DelimiterBasedFrameDecoder {
if(!StringUtils.isEmpty(lotnum) && !lotnum.equals(lastLotnum)){
//需要把stock表truncate
FileUtil.save(lotnum,"lastLotnum");
tcpLogger.info("truncate table ,last lotnum:{},new lotnum:{}",lastLotnum,lotnum);
plcService.truncateStock();
lastLotnum = lotnum;

@ -1,6 +1,7 @@
package com.zhehekeji.web.service.ksec;
import com.zhehekeji.common.util.FileUtil;
import com.zhehekeji.web.config.ConfigProperties;
import com.zhehekeji.web.service.PlcService;
import io.netty.bootstrap.Bootstrap;
@ -32,6 +33,7 @@ public class KsecNettyClient {
private static Channel channel;
public void createClient(ConfigProperties.KSEC ksec) throws InterruptedException {
if (StringUtils.isEmpty(ksec.getIp()) || ksec.getPort() == null) {
return;
}

Loading…
Cancel
Save