Explorar o código

滑台逻辑beta版

yejian %!s(int64=2) %!d(string=hai) anos
pai
achega
4f16aabab8

+ 61 - 2
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java

@@ -28,6 +28,7 @@ import com.github.zuihou.business.productionReadyCenter.entity.BBom;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
 import com.github.zuihou.business.productionReadyCenter.service.AAutoNodeLogService;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureProductionresourceService;
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
 import com.github.zuihou.business.productionResourceCenter.dao.ResourceAutoCodeMapper;
@@ -148,6 +149,9 @@ public class TaskWorkNode {
     @Autowired
     private ExternalApiService externalApiService;
 
+    @Autowired
+    private BomProcedureService bomProcedureService;
+
     //总控端口
     private final String ZK_port = "120";
 
@@ -392,8 +396,23 @@ public class TaskWorkNode {
                                         storgeService.unlockStorgeList(storgeList);
                                     }
                                     msgUtil.pushToNextMq(taskNode,3);
-
                                 }else{
+
+                                    String zoneType = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.ZONE_TYPE).toString());
+                                    if(zoneType.equals(ParameterKey.ZONE_YJ)){
+                                        if("3".equals(taskNode.getNodeType()) || "5".equals(taskNode.getNodeType())){
+                                            // 云箭三坐标启动不由总控系统发起,节点跳过执行
+                                            specialCallBackMyselfFlag = true;
+                                            String jsonParam = getRequestParam(conMap);
+                                            //缓存执行当前节点传参
+                                            msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonParam);
+                                            JSONObject ret = new JSONObject();
+                                            ret.put("result","true");
+                                            returnData = ret.toJSONString();
+                                        }
+                                    }
+
+                                    // 打标业务无需放
                                     if("打标业务".equals(resourceBusiness.getName()) && "SendServoStacker".equals(method)){
                                         specialCallBackMyselfFlag = true;
                                         String jsonParam = getRequestParam(conMap);
@@ -1249,7 +1268,47 @@ public class TaskWorkNode {
                     if("1".equals(beforTaskNode.getFindAgvFlag())){
                         targetList = productionresourcePositionService.getFreeProductionAgvResourcePositionByIds(new String[] {resourceId.toString()});
                     }else{
-                        targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                        String zoneType = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.ZONE_TYPE).toString());
+                        if(zoneType.equals(ParameterKey.ZONE_YJ)){
+                            TTask task = taskMapper.selectById(taskNode.getTaskId());
+                            BomProcedure procedure = bomProcedureService.getById(task.getProcedureId());
+                            // 判断是工件坐标系还是质量测量
+                            if("1".equals(procedure.getThreeDimensionalConf()) || "1".equals(procedure.getThreeDimensionalDeviationConf())){
+                                // 质量检测
+                                // 查询三坐标滑台是否可用,通过接口查询
+                                //组装接口参数
+                                HttpHeaders headers = new HttpHeaders();
+                                headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+                                JSONObject jsonObject = new JSONObject();
+                                jsonObject.put("taskId", String.valueOf(taskNode.getTaskId()));
+                                jsonObject.put("taskNodeId", String.valueOf(taskNode.getId()));
+                                Map<String, String> plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
+                                jsonObject.put("url",plcInfo.get("url"));
+                                jsonObject.put("port",plcInfo.get("port"));
+
+                                //缓存执行当前节点传参
+                                msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonObject.toJSONString());
+                                HttpEntity<String> formEntity = new HttpEntity<String>(jsonObject.toJSONString(), headers);
+                                //动态调用接口和新增指令执行时间
+                                String paramKey = zZone.getNo() + "_plc";
+                                String instructionUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(paramKey).toString());
+                                String requestUrl = instructionUrl + "/api/" + "QueryThreeCoordinatesFreePos";
+                                String canPutInfo = restTemplate.postForObject(requestUrl, formEntity, String.class);
+
+                                JSONObject canPutInfoObject = JSONObject.parseObject(canPutInfo);
+                                if("false".equals(canPutInfoObject.getString("result"))){
+                                    targetList = null;
+                                }else{
+                                    String putLocation = canPutInfoObject.getString("result");
+                                    String putPoint = DictionaryKey.ZEISS_LOCATION.get(putLocation);
+                                    targetList = productionresourcePositionService.list(Wraps.<ProductionresourcePosition>lbQ().eq(ProductionresourcePosition::getResourceId, taskNode.getResourceId()).eq(ProductionresourcePosition::getPointId,putPoint));
+                                }
+                            }else{
+                                targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                            }
+                        }else{
+                            targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                        }
                     }
                     logger.info("线边库逻辑节点{},查找目标设备可用信息{}",taskNode.getId(),targetList);
                     if(CollectionUtil.isNotEmpty(targetList)){

+ 50 - 5
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/RobotNodeServiceImpl.java

@@ -29,6 +29,7 @@ import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureTrayMapp
 import com.github.zuihou.business.productionReadyCenter.entity.BBom;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureTray;
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureTrayService;
 import com.github.zuihou.business.productionResourceCenter.dao.*;
 import com.github.zuihou.business.productionResourceCenter.entity.*;
@@ -48,12 +49,13 @@ import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 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.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
@@ -116,6 +118,10 @@ public class RobotNodeServiceImpl implements NodeOperationService {
 
     @Autowired
     private AgvHikOrderInfoService agvHikOrderInfoService;
+    @Autowired
+    private BomProcedureService bomProcedureService;
+    @Autowired
+    private RestTemplate restTemplate;
 
     private Map<String, Object> map = Maps.newHashMap();
 
@@ -856,7 +862,46 @@ public class RobotNodeServiceImpl implements NodeOperationService {
             }else{
                 //目标设备
                 if(resourceId!=null){
-                    targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                    String zoneType = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.ZONE_TYPE).toString());
+                    if(zoneType.equals(ParameterKey.ZONE_YJ)){
+                        TTask task = tTaskMapper.selectById(taskNode.getTaskId());
+                        BomProcedure procedure = bomProcedureService.getById(task.getProcedureId());
+                        // 判断是工件坐标系还是质量测量
+                        if("1".equals(procedure.getThreeDimensionalConf()) || "1".equals(procedure.getThreeDimensionalDeviationConf())){
+                            // 质量检测
+                            // 查询三坐标滑台是否可用,通过接口查询
+                            //组装接口参数
+                            HttpHeaders headers = new HttpHeaders();
+                            headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+                            JSONObject jsonObject = new JSONObject();
+                            jsonObject.put("taskId", String.valueOf(taskNode.getTaskId()));
+                            jsonObject.put("taskNodeId", String.valueOf(taskNode.getId()));
+                            Map<String, String> plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
+                            jsonObject.put("url",plcInfo.get("url"));
+                            jsonObject.put("port",plcInfo.get("port"));
+
+                            //缓存执行当前节点传参
+                            msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId(), jsonObject.toJSONString());
+                            HttpEntity<String> formEntity = new HttpEntity<String>(jsonObject.toJSONString(), headers);
+                            //动态调用接口和新增指令执行时间
+                            String requestUrl = instructionUrl + "/api/" + "QueryThreeCoordinatesFreePos";
+                            String canPutInfo = restTemplate.postForObject(requestUrl, formEntity, String.class);
+
+                            JSONObject canPutInfoObject = JSONObject.parseObject(canPutInfo);
+                            if("false".equals(canPutInfoObject.getString("result"))){
+                                targetList = null;
+                            }else{
+                                String putLocation = canPutInfoObject.getString("result");
+                                String putPoint = DictionaryKey.ZEISS_LOCATION.get(putLocation);
+                                targetList = productionresourcePositionService.list(Wraps.<ProductionresourcePosition>lbQ().eq(ProductionresourcePosition::getResourceId, taskNode.getResourceId()).eq(ProductionresourcePosition::getPointId,putPoint));
+                            }
+                        }else{
+                            targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                        }
+                    }else{
+                        targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {resourceId.toString()});
+                    }
+
                     if(CollectionUtil.isNotEmpty(targetList)){
                         targetStorge = storgeService.getById(targetList.get(0).getStorgeId());
                         returnMap.put("storeResourceId",targetList.get(0).getResourceId());

+ 234 - 119
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/MsgUtil.java

@@ -27,6 +27,13 @@ import com.github.zuihou.common.constant.DictionaryKey;
 import com.github.zuihou.common.constant.ParameterKey;
 import com.github.zuihou.common.util.SmbShareFileUtil;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -42,6 +49,8 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
+import java.io.*;
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -61,6 +70,8 @@ public class MsgUtil implements ApplicationContextAware {
     private String fileIp;
     @Value("${zuihou.smb.filePath}")
     private String filePath;
+    @Value("${zuihou.file.storage-path}")
+    private String uploadFolder;
 
     @Resource
     private RedisTemplate<String,Object> redisTemplate;
@@ -156,7 +167,7 @@ public class MsgUtil implements ApplicationContextAware {
         //把推送把下一个节点丢到MQ。
         JSONObject jsonObject = new JSONObject();
 
-        if(n<taskNodeList.size()-1){//尚未执行到最后一个
+        if(n<taskNodeList.size()-1){ //尚未执行到最后一个
             TaskNode nextTaskNode = taskNodeList.get(n+1);
 
             String zoneType = (null == redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)redis_get(ParameterKey.PARAMETERS)).get(ParameterKey.ZONE_TYPE).toString());
@@ -278,125 +289,208 @@ public class MsgUtil implements ApplicationContextAware {
                     }
                 }
             }else if (zoneType.equals(ParameterKey.ZONE_YJ)){
+
+                Order order = orderMapper.selectById(task.getOrderId());
+                Plan plan = planMapper.selectById(task.getPlanId());
+                BBom bom = bBomMapper.selectById(task.getBomId());
+
+                //
+
                 //如果是三坐标检测
-//                if("3".equals(nextTaskNode.getNodeType())){
-//                    // TODO 后续改成动态拼接
-//                    //组装接口参数
-//                    ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId,taskNode.getResourceId()));
-//                    long zoneId = zoneProductionresource.getZoneId();
-//                    ZZone zZone = zoneService.getById(zoneId);
-//                    Map<String, String> plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
-//
-//                    HttpHeaders headers = new HttpHeaders();
-//                    headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
-//                    JSONObject jsonParam = new JSONObject();
-//                    jsonParam.put("tagname","DB200.38");
-//                    jsonParam.put("ip",plcInfo.get("url"));
-//                    HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam.toJSONString(), headers);
-//
-//                    //动态调用接口和新增指令执行时间
-//                    plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
-//                    String paramKey = zZone.getNo() + "_plc";
-//                    String plcUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(paramKey).toString());
-//                    // TODO 改成虚拟端口,后续删除
-//                    plcUrl = plcUrl.replace("8081","8083");
-//
-//
-//                    String instructionUrl = plcUrl + "/api/GetTagValue";
-//                    System.out.println("instructionUrl=" + instructionUrl);
-//                    System.out.println("jsonParam=" + jsonParam);
-//                    String returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
-//
-//                    // TODO modify by yejian on 20220525 for 添加三坐标模拟
-//                    Random random = new Random();
-//                    Boolean measuringFlag = random.nextBoolean();
-////                int measuringResult = measuringFlag ? 0 : 1;
-//                    int measuringResult = 1;
-//                    String measuringResultFile = filePath + taskNode.getCompleteBatchNo() + "_" + task.getProcedureNo() + ".csv";
-//                    List<String> fileContents = new ArrayList<>();
-//                    OrderQuality orderQuality = new OrderQuality();
-//                    TTaskTestUnqualifiedBom taskTestUnqualifiedBom =  new TTaskTestUnqualifiedBom();
-//
-//                    TWorkpiece workpiece = workpieceMapper.selectOne(Wraps.<TWorkpiece>lbQ().eq(TWorkpiece::getCompleteBatchNo,task.getCompleteBatchNo()));
-//                    logger.info("三坐标测量结果{}", measuringResult);
-//                    if(measuringResult == 0){
-//                        fileContents.add("OK");
-//                        orderQuality.setOkFlag("OK");
-//                        workpiece.setTestResult("1");
-//                        taskTestUnqualifiedBom.setTestResult("1");
-//                    }else{
-//                        fileContents.add("NG");
-//                        orderQuality.setOkFlag("NG");
-//                        workpiece.setTestResult("0");
-//                        taskTestUnqualifiedBom.setTestResult("0");
-//                    }
-//                    SmbShareFileUtil.writeShareFileContent(measuringResultFile,fileContents,userName,password,fileIp);
-//                    Order order = orderMapper.selectById(task.getOrderId());
-//                    Plan plan = planMapper.selectById(task.getPlanId());
-//                    BBom bom = bBomMapper.selectById(task.getBomId());
-//
-//                    orderQuality.setOrderNo(order.getOrderNo());
-//                    orderQuality.setOrderId(order.getId());
-//                    orderQuality.setTaskId(task.getId());
-//                    orderQuality.setWorkpieceId(task.getCompleteBatchNo());
-//                    orderQuality.setWorkpieceName(bom.getName());
-//                    orderQuality.setProcedureId(task.getProcedureId());
-//                    orderQuality.setProcedureName(task.getProcedureName());
-//                    orderQuality.setMeasuringType(1);
-//                    orderQuality.setMeasuringReport(measuringResultFile);
-//                    orderQualityMapper.insert(orderQuality);
-//
-//                    taskTestUnqualifiedBom.setTaskId(task.getId());
-//                    taskTestUnqualifiedBom.setTaskNo(task.getTaskNo());
-//                    taskTestUnqualifiedBom.setOrderId(order.getId());
-//                    taskTestUnqualifiedBom.setOrderNo(order.getOrderNo());
-//                    taskTestUnqualifiedBom.setPlanId(plan.getId());
-//                    taskTestUnqualifiedBom.setPlanNo(plan.getPlanNo());
-//                    taskTestUnqualifiedBom.setProcedureId(task.getProcedureId());
-//                    taskTestUnqualifiedBom.setBomId(task.getBomId());
-//                    taskTestUnqualifiedBom.setBomName(bom.getName());
-//                    taskTestUnqualifiedBom.setUniqueCode(workpiece.getUniqueCode());
-//                    taskTestUnqualifiedBom.setBomNum(1);
-//                    taskTestUnqualifiedBomMapper.insert(taskTestUnqualifiedBom);
-//
-//                    workpieceMapper.updateById(workpiece);
-//
-//
-//                    if(1 == measuringResult){
-//                        logger.info("三坐标测量失败直接下料");
-//
-//                        // 清楚当前节点工序的redis暂存值
-//                        List<TaskNode> operationTaskNodes = taskNodeService.list(Wraps.<TaskNode>lbQ().eq(TaskNode::getTaskId, taskNode.getTaskId()));
-//                        List<Long> operationTaskNodeIds = operationTaskNodes.stream().map(operationTaskNode -> operationTaskNode.getId()).collect(Collectors.toList());
-//                        for(Long operationTaskNodeId : operationTaskNodeIds){
-//                            // 清除redis里面的内容
-//                            msgUtil.redis_del(YunjianConstant.YUNJIAN_CALLBACK_PARAM + "_" + operationTaskNodeId);
-//                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_JXS + operationTaskNodeId);
-//                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + operationTaskNodeId);
-//                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_XBK_FLAG + operationTaskNodeId);
-//                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + operationTaskNodeId);
-//                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + operationTaskNodeId);
-//                            msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE + "_" + operationTaskNodeId);
-//                        }
-//
-//                        //获取下料工序
-//                        List<BomProcedure> bomProcedureList = bomProcedureService.list(Wraps.<BomProcedure>lbQ().eq(BomProcedure::getBomId,task.getBomId()).eq(BomProcedure::getType,"下料").orderByAsc(BomProcedure::getSort));
-//                        if(CollectionUtil.isNotEmpty(bomProcedureList)){
-//                            //获取下料序的第一个节点
-//                            List<TaskNode> taskNodes = taskNodeService.list(Wraps.<TaskNode>lbQ().eq(TaskNode::getProcedureId,bomProcedureList.get(0).getId()).eq(TaskNode::getCompleteBatchNo,task.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort));
-//                            if(CollectionUtil.isNotEmpty(taskNodes)){
-//                                jsonObject.put("taskNodeId",taskNodes.get(0).getId());
-//                                //强制下线
-//                                jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
-//                                dynamicRabbitMq.sendMsg(taskNode.getResourceId().toString(),jsonObject.toString());
-//                                return;
-//                            }
-//                        }
-//                    }
-//                }else if ("5".equals(nextTaskNode.getNodeType())){
-//                    // 工件坐标系检测
-//                    String measuringResultFile = filePath + taskNode.getCompleteBatchNo() + "_" + task.getProcedureNo() + ".xlxs";
-//                }
+                if("3".equals(nextTaskNode.getNodeType())){
+                    // TODO 后续改成动态拼接
+                    //组装接口参数
+                    ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId,taskNode.getResourceId()));
+                    long zoneId = zoneProductionresource.getZoneId();
+                    ZZone zZone = zoneService.getById(zoneId);
+                    Map<String, String> plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
+
+                    HttpHeaders headers = new HttpHeaders();
+                    headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+                    JSONObject jsonParam = new JSONObject();
+                    jsonParam.put("tagname","DB200.38");
+                    jsonParam.put("ip",plcInfo.get("url"));
+                    HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam.toJSONString(), headers);
+
+                    //动态调用接口和新增指令执行时间
+                    plcInfo = DictionaryKey.PLC_CATEGORY.get(zZone.getNo());
+                    String paramKey = zZone.getNo() + "_plc";
+                    String plcUrl = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(paramKey).toString());
+                    // TODO 改成虚拟端口,后续删除
+                    plcUrl = plcUrl.replace("8081","8083");
+
+
+                    String instructionUrl = plcUrl + "/api/GetTagValue";
+                    System.out.println("instructionUrl=" + instructionUrl);
+                    System.out.println("jsonParam=" + jsonParam);
+                    String returnData = restTemplate.postForObject(instructionUrl, formEntity, String.class);
+
+                    // TODO modify by yejian on 20220525 for 添加三坐标模拟
+                    Random random = new Random();
+                    Boolean measuringFlag = random.nextBoolean();
+//                int measuringResult = measuringFlag ? 0 : 1;
+                    int measuringResult = 1;
+                    String measuringResultFile = filePath + taskNode.getCompleteBatchNo() + "_" + task.getProcedureNo() + ".csv";
+                    List<String> fileContents = new ArrayList<>();
+                    OrderQuality orderQuality = new OrderQuality();
+                    TTaskTestUnqualifiedBom taskTestUnqualifiedBom =  new TTaskTestUnqualifiedBom();
+
+                    TWorkpiece workpiece = workpieceMapper.selectOne(Wraps.<TWorkpiece>lbQ().eq(TWorkpiece::getCompleteBatchNo,task.getCompleteBatchNo()));
+                    logger.info("三坐标测量结果{}", measuringResult);
+                    if(measuringResult == 0){
+                        fileContents.add("OK");
+                        orderQuality.setOkFlag("OK");
+                        workpiece.setTestResult("1");
+                        taskTestUnqualifiedBom.setTestResult("1");
+                    }else{
+                        fileContents.add("NG");
+                        orderQuality.setOkFlag("NG");
+                        workpiece.setTestResult("0");
+                        taskTestUnqualifiedBom.setTestResult("0");
+                    }
+                    SmbShareFileUtil.writeShareFileContent(measuringResultFile,fileContents,userName,password,fileIp);
+
+
+                    orderQuality.setOrderNo(order.getOrderNo());
+                    orderQuality.setOrderId(order.getId());
+                    orderQuality.setTaskId(task.getId());
+                    orderQuality.setWorkpieceId(task.getCompleteBatchNo());
+                    orderQuality.setWorkpieceName(bom.getName());
+                    orderQuality.setProcedureId(task.getProcedureId());
+                    orderQuality.setProcedureName(task.getProcedureName());
+                    orderQuality.setMeasuringType(1);
+                    orderQuality.setMeasuringReport(measuringResultFile);
+                    orderQualityMapper.insert(orderQuality);
+
+                    taskTestUnqualifiedBom.setTaskId(task.getId());
+                    taskTestUnqualifiedBom.setTaskNo(task.getTaskNo());
+                    taskTestUnqualifiedBom.setOrderId(order.getId());
+                    taskTestUnqualifiedBom.setOrderNo(order.getOrderNo());
+                    taskTestUnqualifiedBom.setPlanId(plan.getId());
+                    taskTestUnqualifiedBom.setPlanNo(plan.getPlanNo());
+                    taskTestUnqualifiedBom.setProcedureId(task.getProcedureId());
+                    taskTestUnqualifiedBom.setBomId(task.getBomId());
+                    taskTestUnqualifiedBom.setBomName(bom.getName());
+                    taskTestUnqualifiedBom.setUniqueCode(workpiece.getUniqueCode());
+                    taskTestUnqualifiedBom.setBomNum(1);
+                    taskTestUnqualifiedBomMapper.insert(taskTestUnqualifiedBom);
+
+                    workpieceMapper.updateById(workpiece);
+
+
+                    if(1 == measuringResult){
+                        logger.info("三坐标测量失败直接下料");
+
+                        // 清楚当前节点工序的redis暂存值
+                        List<TaskNode> operationTaskNodes = taskNodeService.list(Wraps.<TaskNode>lbQ().eq(TaskNode::getTaskId, taskNode.getTaskId()));
+                        List<Long> operationTaskNodeIds = operationTaskNodes.stream().map(operationTaskNode -> operationTaskNode.getId()).collect(Collectors.toList());
+                        for(Long operationTaskNodeId : operationTaskNodeIds){
+                            // 清除redis里面的内容
+                            msgUtil.redis_del(YunjianConstant.YUNJIAN_CALLBACK_PARAM + "_" + operationTaskNodeId);
+                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_JXS + operationTaskNodeId);
+                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + operationTaskNodeId);
+                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_XBK_FLAG + operationTaskNodeId);
+                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + operationTaskNodeId);
+                            msgUtil.redis_del(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + operationTaskNodeId);
+                            msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE + "_" + operationTaskNodeId);
+                        }
+
+                        //获取下料工序
+                        List<BomProcedure> bomProcedureList = bomProcedureService.list(Wraps.<BomProcedure>lbQ().eq(BomProcedure::getBomId,task.getBomId()).eq(BomProcedure::getType,"下料").orderByAsc(BomProcedure::getSort));
+                        if(CollectionUtil.isNotEmpty(bomProcedureList)){
+                            //获取下料序的第一个节点
+                            List<TaskNode> taskNodes = taskNodeService.list(Wraps.<TaskNode>lbQ().eq(TaskNode::getProcedureId,bomProcedureList.get(0).getId()).eq(TaskNode::getCompleteBatchNo,task.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort));
+                            if(CollectionUtil.isNotEmpty(taskNodes)){
+                                jsonObject.put("taskNodeId",taskNodes.get(0).getId());
+                                //强制下线
+                                jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
+                                dynamicRabbitMq.sendMsg(taskNode.getResourceId().toString(),jsonObject.toString());
+                                return;
+                            }
+                        }
+                    }
+                }else if ("5".equals(nextTaskNode.getNodeType())){
+                    // 工件坐标系检测
+                    String nginxRemoteFilePath = "";
+                    String findFileName = taskNode.getCompleteBatchNo()+ "_" + task.getProcedureNo();
+                    List list = new ArrayList<>();
+                    if(StringUtils.isNotBlank(findFileName)){
+                        // 远程下载报告文件到本地
+                        String downloadFileName = SmbShareFileUtil.findMeasuringFilesAndDownload(fileIp,userName,password,filePath,findFileName,uploadFolder);
+
+                        if (StringUtils.isNotBlank(downloadFileName)) {
+                            nginxRemoteFilePath = uploadFolder + File.separator + downloadFileName;
+                            // 读取nginx远程本地测量报告解析
+                            InputStream in = null;
+                            try {
+                                in = new FileInputStream(nginxRemoteFilePath);
+                                Workbook work = this.getWorkbook(in, nginxRemoteFilePath);
+                                if (null == work) {
+                                    throw new Exception("创建Excel工作薄为空!");
+                                }
+                                Sheet sheet = null;
+                                Row row = null;
+                                Cell cell = null;
+
+                                for (int i = 0; i < work.getNumberOfSheets(); i++) {
+                                    sheet = work.getSheetAt(i);
+                                    if (sheet == null) {
+                                        continue;
+                                    }
+
+                                    for (int j = sheet.getFirstRowNum(); j <= sheet.getLastRowNum(); j++) {
+                                        row = sheet.getRow(j);
+                                        if (row == null || row.getFirstCellNum() == j) {
+                                            continue;
+                                        }
+
+                                        List<Object> li = new ArrayList<>();
+                                        for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
+                                            cell = row.getCell(y);
+                                            li.add(cell);
+                                        }
+                                        list.add(li);
+                                    }
+                                    in.close();
+                                }
+                                work.close();
+                            } catch (Exception e) {
+                                e.printStackTrace();
+                            }finally {
+                                if (null != in){
+                                    try {
+                                        in.close();
+                                    } catch (IOException e) {
+                                        e.printStackTrace();
+                                    }
+                                }
+                            }
+                        }
+                        // TODO 遍历解析测量文件内容并入库保存,根据最终测量报告修改
+                        if (list.size() == 18) {
+                            // 读取三坐标工件坐标系每根轴偏移量
+                            BigDecimal xOffset = new BigDecimal(list.get(13).toString());
+                            BigDecimal yOffset = new BigDecimal(list.get(14).toString());
+                            BigDecimal zOffset = new BigDecimal(list.get(15).toString());
+                            BigDecimal aOffset = new BigDecimal(list.get(16).toString());
+                            BigDecimal bOffset = new BigDecimal(list.get(17).toString());
+                            OrderQuality orderQuality = new OrderQuality();
+                            orderQuality.setOrderNo(order.getOrderNo());
+                            orderQuality.setOrderId(order.getId());
+                            orderQuality.setTaskId(task.getId());
+                            orderQuality.setWorkpieceId(task.getCompleteBatchNo());
+                            orderQuality.setWorkpieceName(bom.getName());
+                            orderQuality.setProcedureId(task.getProcedureId());
+                            orderQuality.setProcedureName(task.getProcedureName());
+                            orderQuality.setExactXaxisOffset(xOffset);
+                            orderQuality.setExactYaxisOffset(yOffset);
+                            orderQuality.setExactZaxisOffset(zOffset);
+                            orderQuality.setExactAaxisOffset(aOffset);
+                            orderQuality.setExactBaxisOffset(bOffset);
+                            orderQualityMapper.insert(orderQuality);
+                        }
+                    }
+                }
             }
 
             //如果切换成了手动档,则只把当前工序走完
@@ -453,6 +547,27 @@ public class MsgUtil implements ApplicationContextAware {
         }
     }
 
+    /**
+     * 判断文件格式
+     *
+     * @param inStr
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    private Workbook getWorkbook(InputStream inStr, String fileName) throws Exception {
+        Workbook workbook = null;
+        String fileType = fileName.substring(fileName.lastIndexOf("."));
+        if (".xls".equals(fileType)) {
+            workbook = new HSSFWorkbook(inStr);
+        } else if (".xlsx".equals(fileType)) {
+            workbook = new XSSFWorkbook(inStr);
+        } else {
+            throw new Exception("请上传excel文件!");
+        }
+        return workbook;
+    }
+
     /**
      * 缓存位线边库逻辑消息推送
      * @param taskNode

+ 117 - 11
imcs-admin-boot/imcs-common/src/main/java/com/github/zuihou/common/util/SmbShareFileUtil.java

@@ -1,15 +1,15 @@
 package com.github.zuihou.common.util;
 
-import cn.hutool.core.date.DateUtil;
 import jcifs.smb.NtlmPasswordAuthentication;
 import jcifs.smb.SmbFile;
 import jcifs.smb.SmbFileInputStream;
 import jcifs.smb.SmbFileOutputStream;
 
 import java.io.*;
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * 提供共享文件夹的操作的通用程序
@@ -53,12 +53,13 @@ public class SmbShareFileUtil {
      * @param shareFile 共享文件路径
      * @return
      */
-    public static List<String> readShareFileContent(String shareFile){
+    public static List<String> readShareFileContent(String shareFile,String userName,String password,String fileIp){
         List<String> shareFileContents = new ArrayList<String>();
         InputStream in = null ;
         BufferedReader bufferedReader = null;
+        NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication(fileIp, userName, password);
         try{
-            in = new BufferedInputStream(new SmbFileInputStream(shareFile));
+            in = new BufferedInputStream(new SmbFileInputStream(new SmbFile(shareFile,auth )));
             bufferedReader = new BufferedReader(new InputStreamReader(in));
             // 按行读取订单结果文件
             String str = null;
@@ -127,6 +128,51 @@ public class SmbShareFileUtil {
         return downloadFlag;
     }
 
+    /**
+     * 将远程文件内容读取到本都
+     * @param shareFile 共享文件路径
+     * @return
+     */
+    public static boolean downLoadShareFileContent(String downLoadpath,String shareFile,String userName,String password,String ip){
+        boolean downloadFlag = false;
+        InputStream in = null ;
+        FileOutputStream os = null;
+        try{
+            NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication(ip, userName, password);
+            SmbFile smbFile = new SmbFile(shareFile,auth);
+            smbFile.connect();
+            if(smbFile.exists()){
+                File downLoadFile = new File(downLoadpath);
+                int length = smbFile.getContentLength();// 得到文件的大小
+                in = new SmbFileInputStream(shareFile);
+                os = new FileOutputStream(downLoadFile);
+                int len =0;
+                byte[] bytes = new byte[1024];
+                while( (len=in.read(bytes)) > 0){
+                    os.write(bytes,0,len);
+                }
+                os.flush();
+                downloadFlag = true;
+            }
+        }catch(Exception e){
+            e.printStackTrace();
+        }finally {
+            try{
+                if(null != os){
+                    os.close();
+                }
+                if(null != in){
+                    in.close();
+                }
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+
+        }
+
+        return downloadFlag;
+    }
+
     /**
      * 遍历远程访问文件夹
      * @param remotePath
@@ -197,6 +243,63 @@ public class SmbShareFileUtil {
         }
     }
 
+    /**
+     * 查找遍历三坐标测量结果
+     * @return
+     */
+    public static String findMeasuringFiles(String ip, String userName, String password, String url, String findFileName){
+        NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication(ip, userName, password);
+        String returnFileName = "";
+        SmbFile file = null;
+        try {
+            file = new SmbFile(url,auth);
+            file.connect();
+            if(file.exists()){
+                SmbFile[] files = file.listFiles();
+                for(SmbFile f : files){
+                    if(f.getName().contains(findFileName)){
+                        returnFileName = f.getName();
+                        break;
+                    }
+                }
+                return returnFileName;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    /**
+     * 查找遍历三坐标测量结果
+     * @return
+     */
+    public static String findMeasuringFilesAndDownload(String ip, String userName, String password, String url, String findFileName, String dowmLoadPath){
+        NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication(ip, userName, password);
+        SmbFile file = null;
+        boolean downloadFlag = false;
+        String downloadFileName = "";
+        try {
+            file = new SmbFile(url,auth);
+            file.connect();
+            if(file.exists()){
+                SmbFile[] files = file.listFiles();
+                for(SmbFile f : files){
+                    if(f.getName().contains(findFileName)){
+                        downloadFlag = downLoadShareFileContent(dowmLoadPath+f.getName(),f);
+                        if(downloadFlag){
+                            downloadFileName = f.getName();
+                        }
+                        break;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return downloadFileName;
+    }
+
     /**
      * 在共享文件夹下面创建目录
      * @param ip
@@ -220,7 +323,8 @@ public class SmbShareFileUtil {
 
     public static void main(String[] args) {
         String ip="192.168.170.23";
-        String url="smb://192.168.170.23/measuring/1111.csv";
+        String url="smb://192.168.170.23/measuring/";
+//        String url="smb://192.168.170.23/measuring/abcd-1234.csv";
         String name="measuring";
         String password="Imcs@123456";
 //        NtlmPasswordAuthentication auth =new NtlmPasswordAuthentication(ip, name, password);
@@ -238,13 +342,15 @@ public class SmbShareFileUtil {
 //            }
 //        } catch (Exception e) {
 //            e.printStackTrace();
-////        }
+//        }
 //        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
 //        System.out.println(Date.parse("2021-12-23"));
 //        System.out.println( DateUtil.beginOfMonth(new Date()).dayOfMonth());
 //        System.out.println( DateUtil.endOfMonth(new Date()).dayOfMonth());
-        List<String> content = new ArrayList<>();
-        content.add("OK");
-        writeShareFileContent(url,content,name,password,ip);
+//        List<String> content = new ArrayList<>();
+//        content.add("OK");
+//        writeShareFileContent(url,content,name,password,ip);
+
+        findMeasuringFilesAndDownload(ip,name,password,url,"1d3e5efda0ef4036b9204d31d8813131_OP40","C:/data/projects/uploadfile/file/");
     }
 }