Commit 67329427 LN

锡膏料仓接口

1 个父辈 1ea87e8f
...@@ -13,6 +13,8 @@ public class DateUtil { ...@@ -13,6 +13,8 @@ public class DateUtil {
private static Log log = LogFactory.getLog(DateUtil.class); private static Log log = LogFactory.getLog(DateUtil.class);
private static final String TIME_PATTERN = "HH:mm"; private static final String TIME_PATTERN = "HH:mm";
public static final String DATE_PATTERN="yyyy-MM-dd HH:mm:ss";
/** /**
* Checkstyle rule: utility classes should not have public constructor * Checkstyle rule: utility classes should not have public constructor
*/ */
......
...@@ -58,6 +58,13 @@ public class SmfApi { ...@@ -58,6 +58,13 @@ public class SmfApi {
@Value("${api.outNotifyUrl:}") @Value("${api.outNotifyUrl:}")
protected String outNotifyUrl = ""; protected String outNotifyUrl = "";
/**
* 其他任务状态通知
*/
@Value("${api.taskNotifyUrl:}")
protected String taskNotifyUrl = "";
@Value("${api.orderNotifyUrl:}") @Value("${api.orderNotifyUrl:}")
protected String orderNotifyUrl = ""; protected String orderNotifyUrl = "";
...@@ -85,6 +92,7 @@ public class SmfApi { ...@@ -85,6 +92,7 @@ public class SmfApi {
codeResolveUrl = dataCache.getConfigCache("api.codeResolveUrl",codeResolveUrl); codeResolveUrl = dataCache.getConfigCache("api.codeResolveUrl",codeResolveUrl);
inNotifyUrl = dataCache.getConfigCache("api.inNotifyUrl",inNotifyUrl); inNotifyUrl = dataCache.getConfigCache("api.inNotifyUrl",inNotifyUrl);
outNotifyUrl = dataCache.getConfigCache("api.outNotifyUrl",outNotifyUrl); outNotifyUrl = dataCache.getConfigCache("api.outNotifyUrl",outNotifyUrl);
taskNotifyUrl=dataCache.getConfigCache("api.taskNotifyUrl",taskNotifyUrl);
orderNotifyUrl = dataCache.getConfigCache("api.orderNotifyUrl",orderNotifyUrl); orderNotifyUrl = dataCache.getConfigCache("api.orderNotifyUrl",orderNotifyUrl);
fetchInListUrl = dataCache.getConfigCache("api.fetchInListUrl",fetchInListUrl); fetchInListUrl = dataCache.getConfigCache("api.fetchInListUrl",fetchInListUrl);
fetchOrderUrl = dataCache.getConfigCache("api.fetchOrderUrl",fetchOrderUrl); fetchOrderUrl = dataCache.getConfigCache("api.fetchOrderUrl",fetchOrderUrl);
...@@ -116,6 +124,10 @@ public class SmfApi { ...@@ -116,6 +124,10 @@ public class SmfApi {
if(isUrlExist(outNotifyUrl)){ if(isUrlExist(outNotifyUrl)){
apiListener.outTaskStatusChange(outNotifyUrl,task); apiListener.outTaskStatusChange(outNotifyUrl,task);
} }
}else{
if(isUrlExist(taskNotifyUrl)){
apiListener.otherTaskStatusChange(taskNotifyUrl,task);
}
} }
} }
} }
......
...@@ -84,6 +84,10 @@ public abstract class BaseSmfApiListener implements ISmfApiListener { ...@@ -84,6 +84,10 @@ public abstract class BaseSmfApiListener implements ISmfApiListener {
public void outTaskStatusChange(String outNotifyUrl, DataLog task){ public void outTaskStatusChange(String outNotifyUrl, DataLog task){
} }
@Override
public void otherTaskStatusChange(String taskNotifyUrl, DataLog task) {
}
@Override @Override
public Barcode canPutInAfterResolve(String inCheckUrl, CodeValidateParam params, Barcode barcode) throws ValidateException { public Barcode canPutInAfterResolve(String inCheckUrl, CodeValidateParam params, Barcode barcode) throws ValidateException {
...@@ -122,4 +126,16 @@ public abstract class BaseSmfApiListener implements ISmfApiListener { ...@@ -122,4 +126,16 @@ public abstract class BaseSmfApiListener implements ISmfApiListener {
return data.toString(); return data.toString();
} }
} }
protected Integer getIntData(Map<String, Object> dataMap, String dataKey,Integer defValue) {
Object data = dataMap.get(dataKey);
if (data == null) {
return defValue;
} else {
if(Strings.isNotBlank(data.toString())){
int value = Integer.valueOf(data.toString());
return value;
}
}
return defValue;
}
} }
...@@ -24,6 +24,12 @@ public interface ISmfApiListener { ...@@ -24,6 +24,12 @@ public interface ISmfApiListener {
*/ */
void outTaskStatusChange(String outNotifyUrl, DataLog task); void outTaskStatusChange(String outNotifyUrl, DataLog task);
/**
* 其他类型任务状态改变通知
* @param taskNotifyUrl
* @param task
*/
void otherTaskStatusChange(String taskNotifyUrl, DataLog task);
/** /**
* 是否可入库验证 * 是否可入库验证
......
package com.neotel.smfcore.custom.sp;
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.BaseSmfApiListener;
import com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager;
import com.neotel.smfcore.core.barcode.service.po.Barcode;
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.util.*;
@Service
@Slf4j
public class SpApi extends BaseSmfApiListener {
@Autowired
IBarcodeManager barcodeManager;
@Override
public boolean isForThisApi(String apiName) {
return apiName != null && apiName.equalsIgnoreCase("sp");
}
@Override
public Barcode canPutInAfterResolve(String inCheckUrl, CodeValidateParam params, Barcode barcode) throws ValidateException {
Map<String, Object> paramMap = new HashMap<>();
//锡膏发送 fullCode和weight
paramMap.put("fullCode", barcode.getFullCode());
paramMap.put("weight", barcode.getAmount());
try {
log.info(barcode.getBarcode() + "入库验证,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.postJson(inCheckUrl, paramMap);
log.info(barcode.getBarcode() + "入库验证返回" + result);
ApiResult apiResult = JsonUtil.toObj(result, ApiResult.class);
if (apiResult.isOk()) {
Map<String, Object> dataMap = (Map<String, Object>) apiResult.getData();
String reelId = getData(dataMap, "reelId");
if (Strings.isNotBlank(reelId)) {
barcode.setBarcode(reelId);
}
String partNum = getData(dataMap, "partNum");
if (Strings.isNotBlank(partNum)) {
barcode.setPartNumber(partNum);
}
Integer weight = getIntData(dataMap, "weight", 0);
if (weight > 0) {
barcode.setAmount(weight);
}
Integer mixTime = getIntData(dataMap, "mixTime", 0);
if (mixTime > 0) {
barcode.setMixTime(mixTime * 60);
}
Integer warmTime = getIntData(dataMap, "warmTime", 0);
if (warmTime > 0) {
barcode.setWarmTime(warmTime);
}
String produceDateStr = getData(dataMap, "produceDate");
if (Strings.isNotBlank(produceDateStr)) {
Date produceDate = DateUtil.toDate(produceDateStr, "yyyy-MM-dd HH:mm:ss");
barcode.setProduceDate(produceDate);
}
String expireDateStr = getData(dataMap, "expireDate");
if (Strings.isNotBlank(expireDateStr)) {
Date expireDate = DateUtil.toDate(expireDateStr, "yyyy-MM-dd HH:mm:ss");
barcode.setExpireDate(expireDate);
}
barcode = barcodeManager.saveBarcode(barcode);
return barcode;
} else {
throw new ValidateException("smfcore.mesApi.inCheck.ng", "MES验证失败:" + apiResult.getMsg());
}
} catch (Exception e) {
log.error("入库验证接口出错:" + e.getMessage());
throw new ValidateException("smfcore.mesApi.inCheck.error", "MES验证出错:" + e.getMessage());
}
}
@Override
public void inTaskStatusChange(String inNotifyUrl, DataLog task){
if(task.isFinished()){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("reelId",task.getBarcode());
paramMap.put("location",task.getPosName());
Barcode barcode = barcodeManager.findByBarcode(task.getBarcode());
String fullCode = "";
if(barcode != null){
fullCode = barcode.getFullCode();
}
paramMap.put("fullCode",fullCode);
try {
log.info(task.getBarcode() + "入库通知,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.postJson(inNotifyUrl, paramMap);
log.info(task.getBarcode() + "入库通知返回" + result);
} catch (Exception e) {
log.error("入库通知接口出错:" + e.getMessage());
}
}
}
@Override
public void outTaskStatusChange(String outNotifyUrl, DataLog task){
if(task.isFinished()){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("reelId",task.getBarcode());
paramMap.put("partNum",task.getPartNumber());
paramMap.put("weight",task.getNum() );
paramMap.put("location",task.getPosName());
String status="OUTEND";
paramMap.put("status",status);
Barcode barcode = barcodeManager.findByBarcode(task.getBarcode());
paramMap.put("mixTime",barcode.getMixTime()/60);
paramMap.put("warmTime",barcode.getWarmTime());
Object mixSpeed=barcode.getAppendData("mixingSpeed");
if(mixSpeed!=null) {
Float speed = Float.parseFloat(mixSpeed.toString());
Float rSpeed = speed * 1.5F;
paramMap.put("mixSpeed", speed.toString());
paramMap.put("mixRSpeed", rSpeed.toString());
}
paramMap.put("currTime",DateUtil.toDateString(new Date(),"yyyy-MM-dd HH:mm:ss"));
try {
log.info(task.getBarcode() + "出库通知,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.postJson(outNotifyUrl, paramMap);
log.info(task.getBarcode() + "出库通知返回" + result);
} catch (Exception e) {
log.error("出库通知接口出错:" + e.getMessage());
}
}
}
@Override
public void otherTaskStatusChange(String taskNotifyUrl, DataLog task) {
String status="";
if(task.isCheckOutTask() ){
status="OUTEND";
}else if(task.isRewarmPuttingTask() ){
status="REWARMING";
}else if(task.isMixTask() ){
status="MIXING";
}else{
return;
}
if(task.isFinished()){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("reelId",task.getBarcode());
paramMap.put("partNum",task.getPartNumber());
paramMap.put("weight",task.getNum() );
paramMap.put("location",task.getPosName());
paramMap.put("status",status);
Barcode barcode = barcodeManager.findByBarcode(task.getBarcode());
paramMap.put("mixTime",barcode.getMixTime()/60);
paramMap.put("warmTime",barcode.getWarmTime());
Object mixSpeed=barcode.getAppendData("mixingSpeed");
if(mixSpeed!=null) {
Float speed = Float.parseFloat(mixSpeed.toString());
Float rSpeed = speed * 1.5F;
paramMap.put("mixSpeed", speed.toString());
paramMap.put("mixRSpeed", rSpeed.toString());
}
paramMap.put("currTime",DateUtil.toDateString(new Date(),"yyyy-MM-dd HH:mm:ss"));
try {
log.info(task.getBarcode() + "出库通知,参数" + JsonUtil.toJsonStr(paramMap));
String result = HttpHelper.postJson(taskNotifyUrl, paramMap);
log.info(task.getBarcode() + "出库通知返回" + result);
} catch (Exception e) {
log.error("出库通知接口出错:" + e.getMessage());
}
}
}
}
package com.neotel.smfcore.custom.sp;
import cn.hutool.core.util.ObjectUtil;
import com.neotel.smfcore.common.bean.ResultBean;
import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.JsonUtil;
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;
import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.manager.IStoragePosManager;
import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.storage.service.po.StoragePos;
import com.neotel.smfcore.security.annotation.AnonymousAccess;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@Slf4j
@RestController
@RequestMapping("/rest/api")
public class SpController {
@Autowired
private DataCache dataCache;
@Autowired
private IStoragePosManager storagePosManager;
@Autowired
private IBarcodeManager barcodeManager;
@ApiOperation("6.1.锡膏出库")
@RequestMapping("/spOut")
@AnonymousAccess
public ResultBean spOut(@RequestBody List<Map<String, Object>> paramList) {
log.info("{}收到数据为:{}", "锡膏出库 spOut", JsonUtil.toJsonStr(paramList));
try {
if (paramList.isEmpty()) {
return ResultBean.newErrorResult(1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"reelId"});
}
for (Map<String, Object> paramMap : paramList) {
if (paramMap.get("reelId") == null) {
return ResultBean.newErrorResult(1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"reelId"});
}
if (paramMap.get("needTime") == null) {
return ResultBean.newErrorResult(1, "smfcore.valueCanotNull", "{0}不能为空", new String[]{"needTime"});
}
String reelId = paramMap.get("reelId").toString();
String needTime = paramMap.get("needTime").toString();
Date outDate = DateUtil.toDate(needTime, DateUtil.DATE_PATTERN);
Integer mixTime = 0;
Integer warmTime = 0;
if (paramMap.get("mixTime") != null) {
mixTime = Integer.parseInt(paramMap.get("mixTime").toString());
}
if (paramMap.get("warmTime") != null) {
warmTime = Integer.parseInt(paramMap.get("warmTime").toString());
}
Locale locale = new Locale("en", "US");
StoragePos pos = storagePosManager.getByBarcode(reelId);
if (pos == null) {
log.error("锡膏出库 spOut ,料仓中未找到reelID:" + reelId);
return ResultBean.newErrorResult(1, "smfcore.queryPos.cannotFindBarcode", "cannot find barcode [" + reelId + "] In storage", new String[]{reelId});
}
String sStatus = pos.getBarcode().getSolderStatus();
if (sStatus.equals(SOLDER_STATUS.RETREAT_STORAGE.name()) || sStatus.equals(SOLDER_STATUS.UNDER_REFRIGERATION.name()) || sStatus.equals(SOLDER_STATUS.NONE.name())) {
} else {
log.error("锡膏出库 spOut , reelID:" + reelId + " 出库失败,当前状态:" + sStatus);
return ResultBean.newErrorResult(1, "smfcore.queryPos.solderOutFail", " [" + reelId + "] checkOut fail,currStatus [" + sStatus + "]", new String[]{reelId, sStatus});
}
Storage storage = dataCache.getStorageById(pos.getStorageId());
//需要定时出库;
setOutDate(pos, outDate, mixTime, warmTime);
}
return ResultBean.newOkResult("");
} catch (Exception ex) {
log.error("锡膏出库 spOut 处理出错:" + ex.toString());
return ResultBean.newErrorResult(1, "smfcore.error", "出错:{0}", new String[]{ex.toString()});
}
}
private void setOutDate( StoragePos pos, Date outDate,Integer mixTime,Integer warmTime ) {
Barcode barcode = pos.getBarcode();
if (barcode != null) {
log.info("设定仓位【" + pos.getPosName() + "】中的锡膏[" + barcode.getBarcode() + "]出库时间:"
+ DateUtil.toDateTimeString(outDate) + ",mixTime=" + mixTime + ",warmTime=" + warmTime);
barcode.setSolderStatus(SOLDER_STATUS.TO_BE_REWARM.name());
barcode.setNeedOutDate(outDate);
barcode.setMixTime(mixTime * 60);
barcode.setWarmTime(warmTime);
barcodeManager.save(barcode);
pos.setBarcode(barcode);
storagePosManager.save(pos);
}
}
@ApiOperation("6.2 获取锡膏实时库存")
@RequestMapping("/spInventory")
@AnonymousAccess
public ResultBean spInventory(@RequestBody Map<String, List<String>> paramMap) {
List<String> partNums = paramMap.get("partNums");
List<String> reelIds = paramMap.get("reelIds");
List<String> cids = paramMap.get("towerIds");
List<String> storageIds = new ArrayList<>();
if(cids != null){
for (String cid : cids) {
Storage storage = dataCache.getStorage(cid);
if(storage != null){
storageIds.add(storage.getId());
}
}
}
List<StoragePos> storagePosList = storagePosManager.findByBarcodesAndPartNums(storageIds, partNums, reelIds);
if (storagePosList != null) {
List<Map<String, Object>> resultMapList = new ArrayList<>();
for (StoragePos storagePos : storagePosList) {
Barcode barcode = storagePos.getBarcode();
if (barcode != null) {
// UNDER_REFRIGERATION/REWARMING/TO_BE_OUT
String status=barcode.getSolderStatus();
if(status.equals(SOLDER_STATUS.UNDER_REFRIGERATION.name())||status.equals(SOLDER_STATUS.REWARMING.name())||status.equals(SOLDER_STATUS.TO_BE_OUT.name())) {
} else{
continue;
}
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("reelId", barcode.getBarcode());
resultMap.put("parmNum", barcode.getPartNumber());
resultMap.put("weight", barcode.getAmount());
resultMap.put("status",status);
if(ObjectUtil.isNotEmpty(barcode.getPutInDate())) {
resultMap.put("checkInTime", DateUtil.toDateString(barcode.getPutInDate(), DateUtil.DATE_PATTERN));
}
if(ObjectUtil.isNotEmpty(barcode.getExpireDate())) {
resultMap.put("expireDate", DateUtil.toDateString(barcode.getExpireDate(), "yyyy-MM-dd"));
}
resultMap.put("towerId", storagePos.getStorageId());
resultMap.put("location", storagePos.getPosName());
resultMapList.add(resultMap);
}
}
return ResultBean.newOkResult(resultMapList);
}
return ResultBean.newErrorResult(1, "", "未找到实时库存信息");
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!