浏览代码

fix:物料rfid校验

wang.sq@aliyun.com 1 天之前
父节点
当前提交
5b3d48937e

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/TaskService.java

@@ -83,6 +83,8 @@ public interface TaskService extends SuperService<TTask> {
 
     R releaseClamp(Map<String, Object> map);
 
+    R checkMaterialsRfid(Map<String, Object> map);
+
     R procesRfid(Map<String, Object> map);
 
     public TTask assignResource(TTask task,Map<Long,BomProcedure>bpMap);

+ 143 - 55
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/TaskServiceImpl.java

@@ -1483,6 +1483,143 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
         return R.success();
     }
 
+    @Override
+    public R checkMaterialsRfid(Map<String, Object> map) {
+        R<Boolean> retuMsg = R.success().setMsg("200");
+
+        R rfid = this.findRfid(map, false);
+        if(!rfid.getIsSuccess()){
+            return retuMsg.setMsg(rfid.getMsg());
+        }
+        // 比对rfid与数据子盘号是否一致
+        Long decimal = Long.parseLong(rfid.getData().toString());
+        Tray tray = trayService.getOne(Wraps.<Tray>lbQ().eq(Tray::getId, Long.parseLong(map.get("trayId").toString())).last("limit 1"));
+        if(Objects.isNull(tray)){
+            return retuMsg.setMsg("没有查询到工装信息");
+        }
+
+        try {
+            if(decimal!=Long.parseLong(tray.getCode())){
+                return retuMsg.setMsg("比较RFID失败,应为:"+ tray.getCode() +";实际为:"+ decimal);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            return retuMsg.setMsg("比较RFID失败,应为:"+ tray.getCode() +";实际为:"+ decimal);
+        }
+
+        return retuMsg;
+    }
+
+
+    /**
+     *
+     * @param map 参数
+     * @param reversal 是否把得到的数据逆转 ,true是,false 否
+     * @return
+     */
+    private R findRfid(Map<String, Object> map, boolean reversal){
+        /**
+         * 1、调用rfid接口获取rfid,如果没数据返回
+         * 2、根据rfid查询对刀仪表,确认此刀是符合进线要求的,
+         */
+
+        // 根据设备id查询设备信息 进行推送
+        Productionresource productionresource = productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getCode,map.get("code")));
+        if(productionresource == null){
+            return R.fail("没有查询到需求设备");
+        }
+
+        ZZone zZone = zoneService.getById(Long.parseLong(map.get("zoneId").toString()));
+        String url1 = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(zZone.getNo() + "_plc").toString());
+        String url = url1 + "/api/findRfidData";
+
+        //Rfid
+        JSONObject object = new JSONObject();
+        object.put("mode","LAUPT");
+        JSONObject rfidObj = new JSONObject();
+        rfidObj.put("url", productionresource.getIp());
+        rfidObj.put("port", productionresource.getPort());
+        rfidObj.put("taskId", System.currentTimeMillis()+"1");
+        rfidObj.put("taskNodeId", System.currentTimeMillis()+"1");
+        rfidObj.put("data", object);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+        HttpEntity<String> formEntity = new HttpEntity<String>(rfidObj.toJSONString(), headers);
+
+        String s = null;
+        if(imcsTOccsEnable){
+            s = restTemplate.postForObject(url, formEntity, String.class);
+        }else {
+            s="{\"taskID\":\"1872123464509292544\",\"taskNodeID\":\"1872123575505080322\",\"result\":\"true\",\"resultMsg\":\"执行成功\",\"concurrency\":\"false\",\"data\":null,\"returnData\":{\"par1\":\"001A000000\"}}\n";
+        }
+
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        // 把机床下刀的数据同步过来,以保证二次入库,数据正确写入,只有在从机床出刀的时候才执行此代码
+        if(jsonObject.getString("result") ==null || jsonObject.getString("result").equals("false")){
+            return R.fail("调用ccs,获取rfid失败");
+        }
+        JSONObject returnData = jsonObject.getJSONObject("returnData");
+        String par1 = returnData.getString("par1");
+        if(par1.equals("0")){
+            return R.fail("请读取刀具RFID");
+        }
+        if(par1.length()<6){
+            return R.fail("RFID读取错误请检查");
+        }
+        String s1 = StringUtil.isNotEmpty(par1) ? par1.substring(2, 6):par1 ;
+        if(reversal){// 是否反转
+            // 反转
+            String hexStr = CutterFile.reverseByTwoCharsGroup(s1);
+
+            // 转为10进制
+            Long decimal = Long.parseLong(hexStr, 16);
+            return R.success(decimal);
+        }else {
+            return R.success(s1);
+        }
+
+    }
+
+    private R rfidReset(Map<String, Object> map){
+        /**
+         * 1、调用rfid接口获取rfid,如果没数据返回
+         * 2、根据rfid查询对刀仪表,确认此刀是符合进线要求的,
+         */
+
+        // 根据设备id查询设备信息 进行推送
+        Productionresource productionresource = productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getCode,map.get("code")));
+        if(productionresource == null){
+            return R.fail("没有查询到需求设备");
+        }
+
+        ZZone zZone = zoneService.getById(Long.parseLong(map.get("zoneId").toString()));
+        String url1 = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(zZone.getNo() + "_plc").toString());
+        String url = url1 + "/api/rfidReset";
+
+        //LAUPT 刀具rfid
+        JSONObject object = new JSONObject();
+        object.put("mode","LAUPT");
+        JSONObject rfidObj = new JSONObject();
+        rfidObj.put("url", productionresource.getIp());
+        rfidObj.put("port", productionresource.getPort());
+        rfidObj.put("taskId", System.currentTimeMillis()+"1");
+        rfidObj.put("taskNodeId", System.currentTimeMillis()+"1");
+        rfidObj.put("data", object);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
+        HttpEntity<String> formEntity = new HttpEntity<String>(rfidObj.toJSONString(), headers);
+
+        String s = null;
+        if(imcsTOccsEnable){
+            s = restTemplate.postForObject(url, formEntity, String.class);
+        }
+
+        return R.success();
+    }
+
+
     @Override
     public R procesRfid(Map<String, Object> map){
         // TODO 先读取rfid内容是否有子盘信息
@@ -1668,58 +1805,12 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
          * 1、调用rfid接口获取rfid,如果没数据返回
          * 2、根据rfid查询对刀仪表,确认此刀是符合进线要求的,
          */
-
-        // 根据设备id查询设备信息 进行推送
-        Productionresource productionresource = productionresourceBizMapper.selectOne(Wraps.<Productionresource>lbQ().eq(Productionresource::getCode,map.get("code")));
-        if(productionresource == null){
-            return R.fail("没有查询到需求设备");
+        R rfid = this.findRfid(map,true);
+        if(!rfid.getIsSuccess()){
+            return rfid;
         }
+        Long decimal = Long.parseLong(rfid.getData().toString());
 
-        ZZone zZone = zoneService.getById(Long.parseLong(map.get("zoneId").toString()));
-        String url1 = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(zZone.getNo() + "_plc").toString());
-        String url = url1 + "/api/findRfidData";
-
-        //LAUPT 刀具rfid
-        JSONObject object = new JSONObject();
-        object.put("mode","LAUPT");
-        JSONObject rfidObj = new JSONObject();
-        rfidObj.put("url", productionresource.getIp());
-        rfidObj.put("port", productionresource.getPort());
-        rfidObj.put("taskId", System.currentTimeMillis()+"1");
-        rfidObj.put("taskNodeId", System.currentTimeMillis()+"1");
-        rfidObj.put("data", object);
-
-        HttpHeaders headers = new HttpHeaders();
-        headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
-        HttpEntity<String> formEntity = new HttpEntity<String>(rfidObj.toJSONString(), headers);
-
-        String s = null;
-        if(imcsTOccsEnable){
-            s = restTemplate.postForObject(url, formEntity, String.class);
-        }else {
-            s="{\"taskID\":\"1872123464509292544\",\"taskNodeID\":\"1872123575505080322\",\"result\":\"true\",\"resultMsg\":\"执行成功\",\"concurrency\":\"false\",\"data\":null,\"returnData\":{\"par1\":\"001A000000\"}}\n";
-        }
-
-        JSONObject jsonObject = JSONObject.parseObject(s);
-        // 把机床下刀的数据同步过来,以保证二次入库,数据正确写入,只有在从机床出刀的时候才执行此代码
-        if(jsonObject.getString("result") ==null || jsonObject.getString("result").equals("false")){
-            return R.fail("调用ccs,获取rfid失败");
-        }
-        JSONObject returnData = jsonObject.getJSONObject("returnData");
-        String par1 = returnData.getString("par1");
-        if(par1.equals("0")){
-            return R.fail("请读取刀具RFID");
-        }
-        if(par1.length()<6){
-            return R.fail("RFID读取错误请检查");
-        }
-        String s1 = StringUtil.isNotEmpty(par1) ? par1.substring(2, 6):par1 ;
-
-        // 反转
-        String hexStr = CutterFile.reverseByTwoCharsGroup(s1);
-
-        // 转为10进制
-        Long decimal = Long.parseLong(hexStr, 16);
 
         // 根据读取的rfid检测对刀数据是否已经对刀过
         CutterTestDataEntity cutterTestData = cutterTestDataMapper.selectOne(Wraps.<CutterTestDataEntity>lbQ().eq(CutterTestDataEntity::getCutterT, decimal.toString()).
@@ -1733,11 +1824,8 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
             return R.fail("缺失基础刀具信息,刀柄号:"+decimal);
         }
 
-        // 数据复位
-        if(imcsTOccsEnable){
-            url = url1 + "/api/rfidReset";
-            restTemplate.postForObject(url, formEntity, String.class);
-        }
+        //rfid数据复位
+        this.rfidReset(map);
 
         // 刀具校验,确认在库位中没有此刀具
         List<Storge> listStorgeByGoodsID = storgeService.findListStorgeByGoodsID(cuttingTool.getId());

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/dao/TrayMapper.java

@@ -30,4 +30,6 @@ public interface TrayMapper extends SuperMapper<Tray> {
 
     List<Tray> selectUsersByIds(@Param("ids") List<Long> ids, @Param("storgeIds") List<Long> storgeIds);
 
+    List<Tray> getGoodSByStorgeId(Long storgeIds);
+
 }

+ 2 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/TrayService.java

@@ -53,4 +53,6 @@ public interface TrayService extends SuperService<Tray> {
     List<Tray> selectUsersByIds(List<Long> ids);
 
     List<Tray> selectByStorgeId(List<Long> ids);
+
+    List<Tray> getGoodSByStorgeId(Long storgeId);
 }

+ 8 - 3
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionReadyCenter/service/impl/TrayServiceImpl.java

@@ -207,9 +207,9 @@ public class TrayServiceImpl extends SuperServiceImpl<TrayMapper, Tray> implemen
 
     @Override
     public Boolean check(TraySaveDTO model) {
-        if (null!=model.getName()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getName, model.getName())) > 0;
-        if (null!=model.getNo()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getNo, model.getNo())) > 0;
-        if (null!=model.getCode()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getCode, model.getCode())) > 0;
+        if (null!=model.getName()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getName, model.getName()).ne(Tray::getId, model.getId())) > 0;
+        if (null!=model.getNo()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getNo, model.getNo()).ne(Tray::getId, model.getId())) > 0;
+        if (null!=model.getCode()) return super.count(Wraps.<Tray>lbQ().eq(Tray::getCode, model.getCode()).ne(Tray::getId, model.getId())) > 0;
         return false;
     }
 
@@ -222,4 +222,9 @@ public class TrayServiceImpl extends SuperServiceImpl<TrayMapper, Tray> implemen
     public List<Tray> selectByStorgeId(List<Long> storgeIds) {
         return baseMapper.selectUsersByIds(null,storgeIds);
     }
+
+    @Override
+    public List<Tray> getGoodSByStorgeId(Long storgeId) {
+        return baseMapper.getGoodSByStorgeId(storgeId);
+    }
 }

+ 14 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/strategy/impl/CacheRobotStrategy.java

@@ -23,6 +23,8 @@ import com.github.zuihou.business.productionReadyCenter.dao.BBomMapper;
 import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureMapper;
 import com.github.zuihou.business.productionReadyCenter.entity.BBom;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
+import com.github.zuihou.business.productionReadyCenter.entity.Tray;
+import com.github.zuihou.business.productionReadyCenter.service.TrayService;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
 import com.github.zuihou.business.productionResourceCenter.dao.ZZoneProductionresourceMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
@@ -100,6 +102,8 @@ public class CacheRobotStrategy implements RobotStrategy {
 
     @Autowired
     private BomProcedureMapper bomProcedureMapper;
+    @Autowired
+    private TrayService trayService;
 
     @Override
     public Map robotInfo(TaskNode taskNode, String zoneName) {
@@ -171,6 +175,7 @@ public class CacheRobotStrategy implements RobotStrategy {
         return putMap;
     }
 
+
     @Override
     public Map robotPut(Map returnMap, TaskNode taskNode, Storge startStorge, Storge targetStorge, List<ProductionresourcePosition> robotList, String targetXbk, Long targetStorgeResourceId) {
 
@@ -342,17 +347,26 @@ public class CacheRobotStrategy implements RobotStrategy {
         }
 
         // 根据起始点位,获取点位属于的类型
+        String rfid = null;
         Productionresource locationStorgeType  = null;
         Productionresource ltargetStorgeType = null;
         if(!startStorge.getPointId().isEmpty()){
             locationStorgeType = productionresourceService.findOneByPointId(startStorge.getPointId());
+            List<Tray> goodSByStorgeId = trayService.getGoodSByStorgeId(startStorge.getId());
+            if(!goodSByStorgeId.isEmpty()){
+                rfid = goodSByStorgeId.get(0).getCode();
+            }
         }
         if(!targetStorge.getPointId().isEmpty()){
             ltargetStorgeType = productionresourceService.findOneByPointId(targetStorge.getPointId());
         }
 
+        // 查询子盘号,写入rfid
+
+
         //满足条件--机器人空闲,设备或线边库有一个空闲
         Map locationMap = new HashMap();
+        locationMap.put("rfid", rfid);
         locationMap.put("locationDevice", locationStorgeType==null?"": locationStorgeType.getCode());  //当前区域
         locationMap.put("destLocationDevice", ltargetStorgeType ==null?"": ltargetStorgeType.getCode());  //目的区域
         locationMap.put("location", startStorge.getPointId());  //零件当前位置

+ 10 - 0
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/productionReadyCenter/TrayMapper.xml

@@ -73,4 +73,14 @@
 
     </select>
 
+    <select id="getGoodSByStorgeId" resultType="com.github.zuihou.business.productionReadyCenter.entity.Tray" parameterType="Long">
+        SELECT
+            *
+        FROM
+            `imcs_t_tray` m
+            LEFT JOIN imcs_s_stock_info s ON m.id = s.goods_id
+        WHERE
+            s.storge_id =#{storgeId}
+    </select>
+
 </mapper>

+ 7 - 0
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/TaskController.java

@@ -213,6 +213,13 @@ public class TaskController extends SuperController<TaskService, Long, TTask, TT
         return baseService.releaseClamp(map);
     }
 
+    @ApiOperation(value = "物料rfid内容检测是否满足", notes = "物料rfid内容检测是否满足")
+    @PostMapping("/checkMaterialsRfid")
+    public R checkMaterialsRfid(@RequestBody Map<String,Object> map) {
+        log.info("rfid内容检测是否满足,请求参数{}",map);
+        return baseService.checkMaterialsRfid(map);
+    }
+
     @ApiOperation(value = "rfid内容处理", notes = "rfid内容处理")
     @PostMapping("/procesRfid")
     public R procesRfid(@RequestBody Map<String,Object> map) {

+ 2 - 0
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/dto/TraySaveDTO.java

@@ -50,6 +50,8 @@ public class TraySaveDTO implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
+    private String id;
+
     /**
      * 名称
      */