Commit 57b39e6a 孙克

SO21476增加入库时读取D:/remain/文件夹中唯一码进行数量修改

1 个父辈 0c20753d
package com.neotel.smfcore.custom.so21476;
import cn.hutool.core.io.FileUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.JsonUtil;
import com.neotel.smfcore.core.api.bean.ApiResult;
import com.neotel.smfcore.core.api.bean.CodeValidateParam;
import com.neotel.smfcore.core.api.listener.DefaultSmfApiListener;
import com.neotel.smfcore.core.barcode.service.manager.IComponentManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
import com.neotel.smfcore.core.barcode.service.po.Component;
import com.neotel.smfcore.core.barcode.utils.CodeResolve;
import com.neotel.smfcore.core.system.service.po.DataLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class ReplaceQtyApiHandler extends DefaultSmfApiListener {
/**
*
api:
#name: SO21476
#inCheckUrl: /Volumes/E/项目文件/21476&SO1442DUO
*/
@Override
public boolean isForThisApi(String apiName) {
return apiName != null && apiName.equalsIgnoreCase("SO21476");
}
@Override
public Barcode canPutInAfterResolve(String inCheckUrl, CodeValidateParam params, Barcode barcode) throws ValidateException {
try {
String remainQty = "";
File folder = new File(inCheckUrl);
File[] uidFiles = folder.listFiles();
String uidPrefix = barcode.getBarcode() + "@";
for (File uidFile : uidFiles) {
if(uidFile.getName().startsWith(uidPrefix)){
log.info("查找到["+barcode.getBarcode()+"]对应的文件:" + uidFile.getAbsolutePath()+",开始读取");
List<String> contentLines = FileUtil.readLines(uidFile, "UTF-8");
for (int i = 0; i < contentLines.size(); i++) {
String line = contentLines.get(i);
if(line.startsWith("PartsName,Comment,PartsLotID,Remain,")){
String nextLine = contentLines.get(i+1);
String[] parts = nextLine.split(",");
if (parts.length > 3) {
remainQty = parts[3].trim(); // Taking the 4th element which is Remain
}
break;
}
}
break;
}
}
if(remainQty.isEmpty()){
log.info("未解析出["+barcode.getBarcode()+"]的剩余数量");
}else{
log.info("从文件中解析出["+barcode.getBarcode()+"]的剩余数量为:" + remainQty+"使用此数量入库");
int qty = Integer.valueOf(remainQty);
if(qty > 0){
barcode.setAmount(qty);
}
barcode = barcodeManager.saveBarcode(barcode);
return barcode;
}
} catch (Exception e) {
log.error("入库修改数量接口出错:" + e.getMessage());
throw new ValidateException("smfcore.mesApi.inCheck.error","修改数量出错:" + e.getMessage());
}
return null;
}
}
...@@ -2,8 +2,8 @@ server: ...@@ -2,8 +2,8 @@ server:
port: 8800 port: 8800
api: api:
name: name: SO21476
inCheckUrl: inCheckUrl: D:\remain\
outNotifyUrl: outNotifyUrl:
inNotifyUrl: inNotifyUrl:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!