|
|
@@ -8,9 +8,9 @@ import com.github.zuihou.base.R;
|
|
|
import com.github.zuihou.base.service.SuperServiceImpl;
|
|
|
import com.github.zuihou.business.edgeLibrary.dao.StorgeMapper;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
|
+import com.github.zuihou.business.externalApi.dto.ManualInfo;
|
|
|
import com.github.zuihou.business.mq.HandModeWorkNode;
|
|
|
import com.github.zuihou.business.operationManagementCenter.dao.WorkpieceMapper;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.entity.OrderQuality;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TWorkpiece;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
|
|
|
@@ -28,22 +28,24 @@ import com.github.zuihou.business.productionResourceCenter.entity.Productionreso
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ZZone;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ZZoneProductionresource;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
|
|
|
+import com.github.zuihou.business.util.ManualTaskOperatorUtil;
|
|
|
+import com.github.zuihou.business.util.MsgUtil;
|
|
|
import com.github.zuihou.common.util.StringUtil;
|
|
|
import com.github.zuihou.context.BaseContextHandler;
|
|
|
import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static java.util.stream.Collectors.groupingBy;
|
|
|
-import static java.util.stream.Collectors.mapping;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -88,6 +90,26 @@ public class WorkpieceServiceImpl extends SuperServiceImpl<WorkpieceMapper, TWor
|
|
|
@Autowired
|
|
|
private ZZoneProductionresourceMapper zZoneProductionresourceMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+ @Autowired
|
|
|
+ private MsgUtil msgUtil;
|
|
|
+
|
|
|
+ private static LinkedList<String> robotTaskNodes = new LinkedList<>();
|
|
|
+ static {
|
|
|
+ robotTaskNodes.add("move");
|
|
|
+ robotTaskNodes.add("get");
|
|
|
+ robotTaskNodes.add("put");
|
|
|
+ robotTaskNodes.add("move");
|
|
|
+ robotTaskNodes.add("get");
|
|
|
+ robotTaskNodes.add("put");
|
|
|
+ }
|
|
|
+ private static LinkedList<String> robotNoMoveTaskNodes = new LinkedList<String>();
|
|
|
+ static {
|
|
|
+ robotNoMoveTaskNodes.add("get");
|
|
|
+ robotNoMoveTaskNodes.add("put");
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<TWorkpiece> pageList(IPage page, LbqWrapper<TWorkpiece> wrapper) {
|
|
|
return baseMapper.pageList(page, wrapper);
|
|
|
@@ -200,82 +222,97 @@ public class WorkpieceServiceImpl extends SuperServiceImpl<WorkpieceMapper, TWor
|
|
|
zZoneWrapper.eq("status",1);
|
|
|
List<ZZone> zZones = zZoneMapper.selectList(zZoneWrapper);
|
|
|
Map<String, Object> retStockInfo = new HashMap<String, Object>();
|
|
|
+ List<Map> returnList = new ArrayList<>();
|
|
|
+
|
|
|
+ zZoneWrapper = new QueryWrapper<ZZone>();
|
|
|
+ zZoneWrapper.like("name","保障");
|
|
|
+ ZZone safeguardZone = zZoneMapper.selectOne(zZoneWrapper);
|
|
|
+
|
|
|
+ List<ZZoneProductionresource> safeguardResources = zZoneProductionresourceMapper.selectList(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getZoneId,safeguardZone.getId()));
|
|
|
+ List<Long> safeguardResourceLists = safeguardResources.stream().map(p -> p.getResourceId()).collect(Collectors.toList());
|
|
|
+
|
|
|
for(ZZone zZone : zZones){
|
|
|
+
|
|
|
// TODO 代码先判断死,后面再调整映射关系优化
|
|
|
+ String zZoneName = zZone.getName();
|
|
|
+ String zZoneCode = "";
|
|
|
+ if(zZoneName.contains("舱体")){
|
|
|
+ zZoneCode = "capsule";
|
|
|
+ }else if(zZoneName.contains("框体")){
|
|
|
+ zZoneCode = "framework";
|
|
|
+ }else{
|
|
|
+ zZoneCode = "safeguard";
|
|
|
+ }
|
|
|
// 查询产线设备
|
|
|
List<ZZoneProductionresource> zZoneProductionresources = zZoneProductionresourceMapper.selectList(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getZoneId,zZone.getId()));
|
|
|
- // 遍历产线设备
|
|
|
- List zonePoints = new ArrayList();
|
|
|
|
|
|
for(ZZoneProductionresource zZoneProductionresource : zZoneProductionresources){
|
|
|
- Map map = new HashMap();
|
|
|
- map.put("resourceId",zZoneProductionresource.getResourceId());
|
|
|
- List<ProductionresourcePosition> list = productionresourcePositionMapper.getProductlineStockInfo(map);
|
|
|
- Map<String, List<ProductionresourcePosition>> pointMap = list.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
|
|
|
- Map<String, Object> resourcePoint = new HashMap<>();
|
|
|
- List<Map> returnList = new ArrayList<>();
|
|
|
- for(String key : pointMap.keySet()){
|
|
|
- Map returnMap = new HashMap();
|
|
|
- List<ProductionresourcePosition> subList = pointMap.get(key);
|
|
|
- if(CollectionUtil.isEmpty(subList)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- ProductionresourcePosition position0 = subList.get(0);
|
|
|
- returnMap.put("pointId",key);
|
|
|
- returnMap.put("storgeId",position0.getStorgeId());
|
|
|
- returnMap.put("name",position0.getName());
|
|
|
- returnMap.put("lockStatus",position0.getLockStatus());
|
|
|
- returnMap.put("resourceId",position0.getResourceId());
|
|
|
- List<Map>l = new ArrayList<>();
|
|
|
- for(ProductionresourcePosition p:subList){
|
|
|
- if(p.getGoodsId()!=null){
|
|
|
- Map m = new HashMap();
|
|
|
- m.put("goodsName",p.getGoodsName());
|
|
|
- m.put("goodsId",p.getGoodsId());
|
|
|
- m.put("uniqueCode",p.getUniqueCode());
|
|
|
- m.put("storgeId",p.getStorgeId());
|
|
|
- m.put("category",p.getCategory());
|
|
|
- if("5".equals(p.getCategory())){//如果是托板。
|
|
|
- List<Map> childL = new ArrayList<>();
|
|
|
- //根据托盘ID,找到对应的点位
|
|
|
- Map queryMap = new HashMap();
|
|
|
- queryMap.put("plateId",p.getGoodsId()==null?"":p.getGoodsId().toString());
|
|
|
- List<ProductionresourcePosition> childList = productionresourcePositionMapper.getProductlineStockInfo(queryMap);
|
|
|
- for(ProductionresourcePosition c:childList){
|
|
|
- Map childMap = new HashMap();
|
|
|
- childMap.put("pointId",c.getPointId());
|
|
|
- childMap.put("goodsName",c.getGoodsName());
|
|
|
- childMap.put("goodsId",c.getGoodsId());
|
|
|
- childMap.put("storgeId",c.getStorgeId());
|
|
|
- childMap.put("category",c.getCategory());
|
|
|
- childL.add(childMap);
|
|
|
- }
|
|
|
- m.put("childList",childL);
|
|
|
- }
|
|
|
- l.add(m);
|
|
|
+ if(("capsule".equals(zZoneCode) || "framework".equals(zZoneCode)) && !safeguardResourceLists.contains(zZoneProductionresource.getResourceId())){
|
|
|
+
|
|
|
+ processStockInfo(returnList, zZoneCode, zZoneProductionresource);
|
|
|
+ }else if("safeguard".equals(zZoneCode)){
|
|
|
+ processStockInfo(returnList, zZoneCode, zZoneProductionresource);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ retStockInfo.put("data",returnList);
|
|
|
+ return retStockInfo;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processStockInfo(List<Map> returnList, String zZoneCode, ZZoneProductionresource zZoneProductionresource) {
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("resourceId", zZoneProductionresource.getResourceId());
|
|
|
+ List<ProductionresourcePosition> list = productionresourcePositionMapper.getProductlineStockInfo(map);
|
|
|
+ Map<String, List<ProductionresourcePosition>> pointMap = list.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
|
|
|
+ for (String key : pointMap.keySet()) {
|
|
|
+ Map returnMap = new HashMap();
|
|
|
+ List<ProductionresourcePosition> subList = pointMap.get(key);
|
|
|
+ if (CollectionUtil.isEmpty(subList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ ProductionresourcePosition position0 = subList.get(0);
|
|
|
+ returnMap.put("unitename", zZoneCode);
|
|
|
+ returnMap.put("pointId", key);
|
|
|
+ returnMap.put("storgeId", position0.getStorgeId());
|
|
|
+ returnMap.put("name", position0.getName());
|
|
|
+ returnMap.put("lockStatus", position0.getLockStatus());
|
|
|
+ returnMap.put("resourceId", position0.getResourceId());
|
|
|
+ List<Map> l = new ArrayList<>();
|
|
|
+ for (ProductionresourcePosition p : subList) {
|
|
|
+ if (p.getGoodsId() != null) {
|
|
|
+ Map m = new HashMap();
|
|
|
+ m.put("goodsName", p.getGoodsName());
|
|
|
+ m.put("goodsId", p.getGoodsId());
|
|
|
+ m.put("uniqueCode", p.getUniqueCode());
|
|
|
+ m.put("storgeId", p.getStorgeId());
|
|
|
+ m.put("category", p.getCategory());
|
|
|
+ if ("5".equals(p.getCategory())) {//如果是托板。
|
|
|
+ List<Map> childL = new ArrayList<>();
|
|
|
+ //根据托盘ID,找到对应的点位
|
|
|
+ Map queryMap = new HashMap();
|
|
|
+ queryMap.put("plateId", p.getGoodsId() == null ? "" : p.getGoodsId().toString());
|
|
|
+ List<ProductionresourcePosition> childList = productionresourcePositionMapper.getProductlineStockInfo(queryMap);
|
|
|
+ for (ProductionresourcePosition c : childList) {
|
|
|
+ Map childMap = new HashMap();
|
|
|
+ childMap.put("pointId", c.getPointId());
|
|
|
+ childMap.put("goodsName", c.getGoodsName());
|
|
|
+ childMap.put("goodsId", c.getGoodsId());
|
|
|
+ childMap.put("storgeId", c.getStorgeId());
|
|
|
+ childMap.put("category", c.getCategory());
|
|
|
+ childL.add(childMap);
|
|
|
}
|
|
|
+ m.put("childList", childL);
|
|
|
}
|
|
|
- if(CollectionUtil.isNotEmpty(l)){
|
|
|
- returnMap.put("goodsList",l);
|
|
|
- }
|
|
|
- returnList.add(returnMap);
|
|
|
+ l.add(m);
|
|
|
}
|
|
|
-
|
|
|
- resourcePoint.put(zZoneProductionresource.getResourceId().toString(), returnList);
|
|
|
- zonePoints.add(resourcePoint);
|
|
|
}
|
|
|
-
|
|
|
- String zZoneName = zZone.getName();
|
|
|
- if(zZoneName.contains("生产单元")){
|
|
|
- retStockInfo.put("capsule",zonePoints);
|
|
|
- }else if(zZoneName.contains("柔性")){
|
|
|
- retStockInfo.put("framework",zonePoints);
|
|
|
- }else{
|
|
|
- retStockInfo.put("safeguard",zonePoints);
|
|
|
+ if (CollectionUtil.isNotEmpty(l)) {
|
|
|
+ returnMap.put("goodsList", l);
|
|
|
}
|
|
|
+ returnList.add(returnMap);
|
|
|
}
|
|
|
- return retStockInfo;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -294,7 +331,8 @@ public class WorkpieceServiceImpl extends SuperServiceImpl<WorkpieceMapper, TWor
|
|
|
callBackJson.put("srcPosition",startPointId);
|
|
|
callBackJson.put("targetPostion",endPointId);
|
|
|
callBackJson.put("goodsId",goodsId);
|
|
|
- return taskNodeService.handModeStock(callBackJson).getData();
|
|
|
+// return taskNodeService.handModeStock(callBackJson).getData();
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -402,4 +440,55 @@ public class WorkpieceServiceImpl extends SuperServiceImpl<WorkpieceMapper, TWor
|
|
|
}
|
|
|
return tWorkpiece;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R executeManualTask(ManualInfo manualInfo) throws Exception {
|
|
|
+
|
|
|
+ // 查找当前任务所属产线,并且找出产线所需运输设备的点位及占用状态
|
|
|
+ String unit = manualInfo.getDeviceUnit();
|
|
|
+ if("capsule".equals(unit)){
|
|
|
+ // 舱体(智能单元)
|
|
|
+ }else if("framework".equals(unit)){
|
|
|
+ // 框体(柔性线)
|
|
|
+ }else if("safeguard".equals(unit)){
|
|
|
+ // 保障平台(质量中心)
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,Object> processInfo = ManualTaskOperatorUtil.judgeFirstProcessInfo(robotTaskNodes, robotNoMoveTaskNodes,manualInfo);
|
|
|
+ JSONObject returnDataObject = new JSONObject();
|
|
|
+
|
|
|
+ // 组装参数
|
|
|
+ String returnData = "";
|
|
|
+ //组装接口参数
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
+
|
|
|
+ //回调参数构建
|
|
|
+ String jsonParam = ManualTaskOperatorUtil.getRequestParam(processInfo.get("location").toString(),manualInfo,processInfo.get("deviceUrl").toString(),processInfo.get("devicePort").toString());
|
|
|
+
|
|
|
+ HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
|
|
|
+ //调用接口
|
|
|
+ try {
|
|
|
+ returnData = restTemplate.postForObject(processInfo.get("hostSyetemTaskUrl").toString(), formEntity, String.class);
|
|
|
+ returnDataObject = JSONObject.parseObject(returnData);
|
|
|
+ log.error("调用上位机执行指令返回" + returnData);
|
|
|
+ if("true".equals(returnDataObject.get("result"))){
|
|
|
+ // 放入redis,方便回调的时候判断是否是最后一个结点,如果是最后一个结点不在做任何逻辑,更新相应的库位信息
|
|
|
+ Map<String, Object> currentTask = new HashMap<String, Object>();
|
|
|
+ List<String> taskNodes = (List<String>) processInfo.get("taskNodes");
|
|
|
+ currentTask.put("taskNodes",taskNodes);
|
|
|
+ currentTask.put("taskInfo",manualInfo);
|
|
|
+ JSONObject redisTask = new JSONObject();
|
|
|
+ redisTask.putAll(currentTask);
|
|
|
+ msgUtil.redis_set(manualInfo.getManualId(),redisTask.toJSONString());
|
|
|
+ }else{
|
|
|
+ return R.fail(returnDataObject.getString("msg"));
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("调用接口发生异常" + e.getMessage());
|
|
|
+ return R.fail(returnDataObject.getString("msg"));
|
|
|
+ }
|
|
|
+ return R.success(returnDataObject);
|
|
|
+ }
|
|
|
}
|