|
@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
|
+import com.github.zuihou.business.edgeLibrary.service.StorgeService;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TTask;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ResourceAutoCodeMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
|
|
@@ -27,6 +29,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.locks.Condition;
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -43,7 +47,7 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
private ProductionresourcePositionService productionresourcePositionService;
|
|
|
|
|
|
@Autowired
|
|
|
- private ResourceAutoCodeMapper resourceAutoCodeMapper;
|
|
|
+ private TaskNodeService taskNodeService;
|
|
|
|
|
|
private String[] jbwArr;
|
|
|
|
|
@@ -53,6 +57,11 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
|
|
|
private List<ProductionresourcePosition> jbwList;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StorgeService storgeService;
|
|
|
+
|
|
|
+ private final ReentrantLock lock = new ReentrantLock(true);
|
|
|
+ private final Condition condition = lock.newCondition();
|
|
|
|
|
|
@Override
|
|
|
public void initResource(TaskNode taskNode, TTask task, Map dataMap) {
|
|
@@ -65,17 +74,17 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
}
|
|
|
}
|
|
|
//初始化默认设定(后期动态获取)
|
|
|
- xbkArr = new String[]{DemoLineConstant.NODE_RESOURCE_ZLZX_XBK};
|
|
|
+ xbkArr = dataMap.get("bizType")!=null? new String[]{dataMap.get("bizType").toString()}: new String[]{DemoLineConstant.NODE_RESOURCE_ZLZX_XBK};
|
|
|
xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(xbkArr);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map checkCondition(TaskNode taskNode, TTask task, Map<String, Object> dataMap) {
|
|
|
- //判断
|
|
|
ResourceAutoCode resourceAutoCode = taskNode.getAutoNode();
|
|
|
String command = resourceAutoCode.getCommand();
|
|
|
String moduleName = dataMap.get("moduleName") == null ? "" : dataMap.get("moduleName").toString();
|
|
|
boolean bool = true;
|
|
|
+ Storge storge = null;
|
|
|
//List<ModuleInstruction> instructions = dataMap.get("instructions") == null ? Lists.newArrayList() : (List<ModuleInstruction>)dataMap.get("instructions");
|
|
|
switch(moduleName){
|
|
|
case "WMS":
|
|
@@ -90,40 +99,75 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
bool = productionresourcePosition!=null ? true : false;
|
|
|
//更新后续节点设备ID
|
|
|
if(bool){
|
|
|
- ResourceAutoCode autoCode = new ResourceAutoCode();
|
|
|
- autoCode.setWeight(resourceAutoCode.getWeight()+ 1);
|
|
|
- autoCode.setBusinessId(autoCode.getBusinessId());
|
|
|
- ResourceAutoCode nextAutoCode = resourceAutoCodeMapper.getNextCode(autoCode);
|
|
|
- if(nextAutoCode!=null && !nextAutoCode.isFinal()){
|
|
|
- nextAutoCode.setResourceId(productionresourcePosition.getResourceId());
|
|
|
- resourceAutoCodeMapper.updateById(nextAutoCode);
|
|
|
+ TaskNode nextCode = taskNodeService.getNextNTaskNode(taskNode, 1);
|
|
|
+ //锁定后续节点
|
|
|
+ if(nextCode!=null && nextCode.getResourceId() == 0L) {
|
|
|
+ //锁定后续接驳位
|
|
|
+ nextCode.setResourceId(productionresourcePosition.getResourceId());
|
|
|
+ taskNodeService.updateById(nextCode);
|
|
|
}
|
|
|
+ //锁定点位
|
|
|
+ storge = storgeService.getById(productionresourcePosition.getStorgeId());
|
|
|
+ if("1".equals(storge.getLockStatus())) {
|
|
|
+ storge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ //同步更新库位锁定
|
|
|
+ this.syncStorage(storge, true, nextCode.getId());
|
|
|
+ map.put("toStorge", storge);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
else if("WMS_IN".equals(command)){
|
|
|
//获取当前节点设备ID
|
|
|
- String resourceId = resourceAutoCode.getResourceId().toString();
|
|
|
+ long resourceId = taskNode.getResourceId();
|
|
|
ProductionresourcePosition resourcePosition = productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getResourceId, resourceId));
|
|
|
- bool = resourcePosition.getLockStatus() == "1" && resourcePosition.getStatus() == "1";
|
|
|
- //判断是否存有产品 待定
|
|
|
+ bool = resourcePosition.getLockStatus() == "1" && resourcePosition.getStatus() == "1" && resourcePosition.getHaveGoods() == "1";
|
|
|
|
|
|
- if(!bool){
|
|
|
- map.put("msg", DictionaryKey.NodeException.NO_RESROURCE);
|
|
|
+ if(bool){
|
|
|
+ storge = storgeService.getById(resourcePosition.getStorgeId());
|
|
|
+ this.syncStorage(storge, false, null);
|
|
|
+ map.put("fromStorge", storge);
|
|
|
+ }else{
|
|
|
+ map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
|
|
|
}
|
|
|
}
|
|
|
map.put("result", bool);
|
|
|
break;
|
|
|
}
|
|
|
+ map.put("command", command);
|
|
|
map.put("moduleName", moduleName);
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map operation(JSONObject jsonObject, JSONObject bizJsonObject, Map<String, Object> map) {
|
|
|
+ //调用接口执行操作指令
|
|
|
+ String moduleName = map.get("moduleName") == null ? "" : map.get("moduleName").toString();
|
|
|
+ String command = map.get("command") == null ? "" : map.get("command").toString();
|
|
|
+ TTask task = (TTask) map.get("task");
|
|
|
+ switch(moduleName) {
|
|
|
+ case "WMS":
|
|
|
+ jsonObject.put("jobType", command);
|
|
|
+ if("WMS_OUT".equals(command)){
|
|
|
+ //毛坯出库
|
|
|
+ jsonObject.put("goodsId", task.getMeterialId());
|
|
|
+ }else{
|
|
|
+ //成品入库
|
|
|
+ jsonObject.put("goodsId", task.getBomId());
|
|
|
+ }
|
|
|
+ Storge fstorge = (Storge) map.get("fromStorge");
|
|
|
+ Storge tstorge = (Storge) map.get("toStorge");
|
|
|
+ bizJsonObject.put("srcPosition", fstorge == null ? "" : fstorge.getId().toString());
|
|
|
+ bizJsonObject.put("targetPosition", tstorge == null ? "" : tstorge.getId().toString());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //调用指令操作 处理返回值 待定
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- return null;
|
|
|
+ map.put("jsonObject", jsonObject);
|
|
|
+ map.put("bizJsonObject", bizJsonObject);
|
|
|
+ return map;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -131,10 +175,6 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void move(Storge fromStorge, Storge toStorage) {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 设备动态逻辑判断处理
|
|
@@ -144,22 +184,26 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
* @return
|
|
|
*/
|
|
|
private ProductionresourcePosition logical(List<ProductionresourcePosition> deviceList, boolean useXbk){
|
|
|
- boolean bool = true;
|
|
|
//设备不存在
|
|
|
if(deviceList == null || deviceList.size() == 0){
|
|
|
- map.put("msg", DictionaryKey.NodeException.NO_RESROURCE);
|
|
|
+ map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
|
|
|
return null;
|
|
|
}
|
|
|
- deviceList = deviceList.stream().filter(position->position.getStatus() =="1" && position.getLockStatus()=="0").collect(Collectors.toList());
|
|
|
+ deviceList = deviceList.stream().filter(position->position.getStatus()=="1" && position.getLockStatus()=="1").collect(Collectors.toList());
|
|
|
//设备被锁定
|
|
|
- if(deviceList == null || deviceList.size() == 0){
|
|
|
+ if(deviceList.size() == 0) {
|
|
|
+ if(useXbk){
|
|
|
+ if(xbkList.size() == 0){
|
|
|
+ map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return xbkList.get(0);
|
|
|
+ }
|
|
|
map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
|
|
|
return null;
|
|
|
}
|
|
|
- //线边库判断处理
|
|
|
- if(useXbk){
|
|
|
+ //设备托盘、夹具条件不满足 待定
|
|
|
|
|
|
- }
|
|
|
return deviceList.get(0);
|
|
|
}
|
|
|
|
|
@@ -176,4 +220,34 @@ public class OtherNodeServiceImpl implements NodeOperationService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 库位处理
|
|
|
+ *
|
|
|
+ * @param storge
|
|
|
+ * @param isLock
|
|
|
+ * @param storgeId
|
|
|
+ */
|
|
|
+ private void syncStorage(Storge storge, boolean isLock, Long storgeId){
|
|
|
+ lock.lock();
|
|
|
+ try {
|
|
|
+ if(isLock){
|
|
|
+ if (storge == null){
|
|
|
+ //等待
|
|
|
+ condition.await();
|
|
|
+ }
|
|
|
+ storgeService.lockStorge(storge, storgeId);
|
|
|
+ }else{
|
|
|
+ if(storge == null || storge.getLockStatus() == "1"){
|
|
|
+ condition.await();
|
|
|
+ }
|
|
|
+ storgeService.unlockStorge(storge);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(InterruptedException ex){
|
|
|
+ ex.getStackTrace();
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|