Commit 854e05a4 LN

1568中车SP对接修改

1 个父辈 23014017
......@@ -3,6 +3,7 @@ package com.neotel.smfcore.core.solder.util;
import com.google.common.base.Strings;
import com.neotel.smfcore.common.exception.ValidateException;
import com.neotel.smfcore.common.utils.Constants;
import com.neotel.smfcore.core.api.SmfApi;
import com.neotel.smfcore.core.barcode.enums.SOLDER_STATUS;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
......@@ -18,6 +19,7 @@ import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.core.system.service.dao.IDataLogDao;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.custom.zhongcheSp1568.ZhongCheSPApi;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -43,6 +45,8 @@ public class SolderBoxCache {
@Value("${sp.disStirring:}")
private String disStirring="";
@Value("${api.taskNotifyUrl:}")
protected String taskNotifyUrl = "";
@Autowired
private DataCache dataCache;
@Autowired
......@@ -101,6 +105,10 @@ public class SolderBoxCache {
}
@Autowired
protected SmfApi smfApi;
@Autowired
private ZhongCheSPApi zhongCheSPApi;
public void runTimer(){
Collection<Storage> allStorage = dataCache.getAllStorage().values();
for (Storage storage : allStorage) {
......@@ -132,28 +140,27 @@ public class SolderBoxCache {
}
}else if(isInStatus(barcode,SOLDER_STATUS.REWARMING)){
//回温中,看回温是否完成
if(now - barcode.getStartWarmTime() >= barcode.getWarmTime() * 60 *1000){
if(now - barcode.getStartWarmTime() >= barcode.getWarmTime() * 60 *1000) {
//回温完成,更改状态为待搅拌
if(disStirring.trim().equalsIgnoreCase("true")){
if (disStirring.trim().equalsIgnoreCase("true")) {
log.info(barcode.getBarcode() + "到达回温时间,当前已配置为禁用搅拌功能,修改状态为待出库");
barcode.setSolderStatus(SOLDER_STATUS.TO_BE_OUT.name());
}
else if(barcode.getMixTime() <= 0){
} else if (barcode.getMixTime() <= 0) {
log.info(barcode.getBarcode() + "到达回温时间,搅拌时间为0,修改状态为待出库");
barcode.setSolderStatus(SOLDER_STATUS.TO_BE_OUT.name());
}else{
} else {
//判断是否自动开始搅拌
Boolean autoStartMixed=dataCache.getCache(Constants.CACHE_SP_AUTO_START_MIXED);
if(autoStartMixed==null){
autoStartMixed=false;
//判断是否自动开始搅拌
Boolean autoStartMixed = dataCache.getCache(Constants.CACHE_SP_AUTO_START_MIXED);
if (autoStartMixed == null) {
autoStartMixed = false;
}
if(autoStartMixed){
if (autoStartMixed) {
log.info(barcode.getBarcode() + "到达回温时间,已配置CACHE_SP_AUTO_START_MIXED=true,自动开始搅拌,修改状态=TO_BE_MIXED");
barcode.setSolderStatus(SOLDER_STATUS.TO_BE_MIXED.name());
}else{
} else {
log.info(barcode.getBarcode() + "到达回温时间,修改状态为等待搅拌,待手动开始搅拌后再开始搅拌");
barcode.setSolderStatus(SOLDER_STATUS.WAIT_MIXED.name());
}
......@@ -164,6 +171,11 @@ public class SolderBoxCache {
storagePos.setBarcode(barcode);
storagePosManager.save(storagePos);
//通知
if (zhongCheSPApi.isForThisApi(smfApi.getApiName())) {
zhongCheSPApi.SPStatusChange(taskNotifyUrl, "HW_END", barcode, new Date());
}
}
}else if(isInStatus(barcode,SOLDER_STATUS.TO_BE_MIXED)){
//待搅拌,生成搅拌任务
......
......@@ -291,19 +291,17 @@ public class ZhongCheSPApi extends BaseSmfApiListener {
Barcode barcode = barcodeManager.findByBarcode(task.getBarcode());
String rsType = null;
if(!task.isFinished()){
//只有结束的任务才更新
return false ;
}
// if(!task.isFinished()){
// //只有结束的任务才更新
// return false ;
// }
if(barcode==null) {
log.error("TaskStatusChange, 任务=" + task.getBarcode() + "/" + task.getPosName() + " 未找到条码暂不处理: ");
return false;
}
if (task.isCheckOutTask()) {
// 领用 - 暂不支持,需要根据业务逻辑确定具体的操作类型
// log.warn("TaskStatusChange: 领用操作暂不支持,需要进一步确认业务逻辑");
return false;
} else if (task.isPutInTask()) {
} else if (task.isPutInTask()&&task.isFinished()) {
StoragePos pos = storagePosManager.getByPosName(task.getPosName());
if(pos==null) {
log.error("TaskStatusChange, 任务=" + task.getBarcode() + "/" + task.getPosName() + " 未找到库位暂不处理 ");
......@@ -313,15 +311,15 @@ public class ZhongCheSPApi extends BaseSmfApiListener {
// 入库到冷藏区
rsType = "LC"; // 冷藏
}
} else if (task.isRewarmTakingTask()) {
// 回温取料 - 可能是回温开始
rsType = "HW_BEGIN"; // 回温开始
} else if (task.isRewarmPuttingTask()) {
// 回温放料 - 可能是回温结束
rsType = "HW_END"; // 回温结束
}else if(task.isMixTask()){
} else if (task.isRewarmPuttingTask()&&task.isFinished()) {
rsType = "HW_BEGIN"; // 已放到回温区,回温开始
}
else if(task.isMixTask()&&task.isExecuting()){
rsType = "JB_BEGIN"; // 搅拌任务开始执行,搅拌开始
}
else if(task.isMixTask()&&task.isFinished()){
// 搅拌结束: JB_END
rsType = "JB_END"; // 搅拌结束
rsType = "JB_END"; // 搅拌任务完成,搅拌结束
}
// 可以根据具体业务需求添加搅拌相关的逻辑
......@@ -332,13 +330,20 @@ public class ZhongCheSPApi extends BaseSmfApiListener {
log.warn("TaskStatusChange: 未找到对应的操作类型,task类型: " + task.getType());
return false;
}
return SPStatusChange(url,rsType,barcode,task.getUpdateDate());
}
public boolean SPStatusChange(String url, String rsType,Barcode barcode,Date updateTime) {
if(ObjectUtil.isEmpty(url)){
return false;
}
try {
// 构建请求数据使用Map
Map<String, Object> request = new HashMap<>();
request.put("docType", "UPDATE_RS_MSG");
request.put("updateType", "UPDATE");
// 构建data数组
List<Map<String, Object>> dataList = new ArrayList<>();
Map<String, Object> dataItem = new HashMap<>();
......@@ -346,24 +351,24 @@ public class ZhongCheSPApi extends BaseSmfApiListener {
dataItem.put("lpn", barcode.getBarcode()); // 使用条码作为LPN
dataItem.put("mtrl_code", barcode.getPartNumber()); // 使用条码中的物料编码
dataItem.put("rs_qty", barcode.getAmount()); // 默认数量为1,可根据实际业务调整
// 格式化时间为 YYYY-MM-DD HH:mm:ss
String time = DateUtil.toDateString(task.getUpdateDate(), "yyyy-MM-dd HH:mm:ss");
String time = DateUtil.toDateString(updateTime, "yyyy-MM-dd HH:mm:ss");
dataItem.put("zzzc_rs_date", time);
// 如果是冷藏操作,需要传生产日期
if ("LC".equals(rsType)&&ObjectUtil.isNotEmpty(barcode.getProduceDate())) {
if ("LC".equals(rsType) && ObjectUtil.isNotEmpty(barcode.getProduceDate())) {
// 这里需要根据实际业务获取生产日期,暂时使用当前日期
dataItem.put("mf_date", DateUtil.toDateString(barcode.getProduceDate(), "yyyy-MM-dd HH:mm:ss"));
}
dataList.add(dataItem);
request.put("data", dataList);
log.info("TaskStatusChange, url=" + url + ",发送数据=" + JsonUtil.toJsonStr(request));
String result = HttpHelper.postJson(url, request);
log.info("TaskStatusChange, url=" + url + ",收到数据=" + result);
// 解析响应使用Map
Map<String, Object> response = JsonUtil.toMap(result);
if (response != null) {
......@@ -380,12 +385,13 @@ public class ZhongCheSPApi extends BaseSmfApiListener {
log.error("TaskStatusChange 响应解析失败");
return false;
}
} catch (ApiException apiException) {
log.error("TaskStatusChange, url=" + url + " apiException: " + apiException.getMessage());
} catch (Exception exception) {
log.error("TaskStatusChange, url=" + url + " exception: " + exception.getMessage());
}
return false;
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!