|
@@ -4,16 +4,15 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.github.zuihou.authority.entity.common.Parameter;
|
|
|
+import com.github.zuihou.authority.entity.common.DictionaryItem;
|
|
|
+import com.github.zuihou.authority.service.common.DictionaryItemService;
|
|
|
import com.github.zuihou.base.service.SuperServiceImpl;
|
|
|
-import com.github.zuihou.business.classSchedule.entity.AuthUser;
|
|
|
import com.github.zuihou.business.cutterdata.dao.CutterTestDataMapper;
|
|
|
-import com.github.zuihou.business.cutterdata.dto.CutterTestDataDto;
|
|
|
-import com.github.zuihou.business.cutterdata.dto.CutterTypeContrastEnum;
|
|
|
import com.github.zuihou.business.cutterdata.entity.CutterTestDataEntity;
|
|
|
+import com.github.zuihou.business.cutterdata.entity.CutterTestDataRecordEntity;
|
|
|
+import com.github.zuihou.business.cutterdata.service.CutterTestDataRecodeService;
|
|
|
import com.github.zuihou.business.cutterdata.service.CutterTestDataService;
|
|
|
import com.github.zuihou.business.cutterdata.utils.CutterFile;
|
|
|
-import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TTask;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
import com.github.zuihou.business.productionReadyCenter.entity.CuttingTool;
|
|
@@ -25,7 +24,6 @@ import com.github.zuihou.business.productionResourceCenter.entity.ZZone;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.ZZoneProductionresource;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.ZZoneService;
|
|
|
import com.github.zuihou.business.util.MsgUtil;
|
|
|
-import com.github.zuihou.common.constant.DictionaryKey;
|
|
|
import com.github.zuihou.common.constant.ParameterKey;
|
|
|
import com.github.zuihou.context.BaseContextHandler;
|
|
|
import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
@@ -50,6 +48,7 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Project: imcs-admin-boot
|
|
@@ -89,11 +88,16 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
|
|
|
@Autowired
|
|
|
private ProductionresourceBizMapper productionresourceBizMapper;
|
|
|
+ @Autowired
|
|
|
+ private DictionaryItemService dictionaryItemService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CutterTestDataRecodeService testDataRecodeService;
|
|
|
|
|
|
- private String CheckCUtter="MES_CUTTER:CHECK_CUTTER_HAVE_READ";
|
|
|
+ private String CheckCUtter = "MES_CUTTER:CHECK_CUTTER_HAVE_READ";
|
|
|
|
|
|
@Override
|
|
|
- public String findCutterTestData(CuttingTool cuttingTool){
|
|
|
+ public String findCutterTestData(CuttingTool cuttingTool) {
|
|
|
log.info("===================定时获取机外对刀仪数据start===================");
|
|
|
|
|
|
List<File> needFile = new ArrayList<>();
|
|
@@ -113,12 +117,17 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
List<CutterTestDataEntity> cutterTestDataEntities = new ArrayList<>();
|
|
|
List<String> cutterTs = new ArrayList<>();
|
|
|
|
|
|
+ // 查询刀具类型
|
|
|
+ String[] types = {"CUTTING_TOOL_TYPE"};
|
|
|
+ List<DictionaryItem> dictionaryItems = this.dictionaryItemService.list(types).get(types[0]);
|
|
|
+ Map<String, List<DictionaryItem>> collect = dictionaryItems.stream().collect(Collectors.groupingBy(DictionaryItem::getCode));
|
|
|
+
|
|
|
|
|
|
for (File file : needFile) {
|
|
|
// 比对此文件是不是已经读取过
|
|
|
long lastModifiedTime = file.lastModified();
|
|
|
Object o = msgUtil.redis_get(CheckCUtter);
|
|
|
- if(Objects.nonNull(o) && lastModifiedTime==Long.parseLong(o.toString())){
|
|
|
+ if (Objects.nonNull(o) && lastModifiedTime == Long.parseLong(o.toString())) {
|
|
|
throw new RuntimeException("此刀具已经采集入库");
|
|
|
}
|
|
|
|
|
@@ -129,8 +138,8 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
org.dom4j.Element root = document.getRootElement();
|
|
|
JSONObject json = CutterFile.findXmlData(root);
|
|
|
|
|
|
- if(!cuttingTool.getCuttingToolNo().toString().equals(json.getJSONObject("ToolList").getJSONObject("Tools").getString("PTN"))){
|
|
|
- throw new RuntimeException("刀柄号数据不一致");
|
|
|
+ if (!cuttingTool.getCuttingToolNo().toString().equals(json.getJSONObject("ToolList").getJSONObject("Tools").getString("PTN"))) {
|
|
|
+ throw new RuntimeException("刀柄号数据不一致,rfid刀具号:" + cuttingTool.getCuttingToolNo() + ",对刀刀具号:" + json.getJSONObject("ToolList").getJSONObject("Tools").getString("PTN"));
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -142,13 +151,13 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
build.setCutterT(json.getJSONObject("ToolList").getJSONObject("Tools").getString("PTN"));
|
|
|
build.setCutterTyp(json.getJSONObject("ToolList").getJSONObject("Tools").getString("ToolType"));
|
|
|
|
|
|
- String substring = json.getJSONObject("ToolList").getJSONObject("Tools").getString("ToolType");
|
|
|
- if (Objects.isNull(substring) || CutterTypeContrastEnum.getDncType(substring.substring(0, 1)) == null) { //说明此类型就是主类不是子类
|
|
|
- build.setCutterTypDnc(CutterTypeContrastEnum.getDncType(substring) == null ? "99" : CutterTypeContrastEnum.getDncType(substring));
|
|
|
- build.setCutterTypSubDnc("99");
|
|
|
+ if (!Objects.isNull(build.getCutterTyp()) || !collect.get(build.getCutterTyp()).isEmpty()) { //说明此类型就是主类不是子类
|
|
|
+ String[] split = collect.get(build.getCutterTyp()).get(0).getDescribe().split("-");
|
|
|
+ build.setCutterTypDnc(split[0]);
|
|
|
+ build.setCutterTypSubDnc(split.length == 2 ? split[1] : "");
|
|
|
} else {
|
|
|
- build.setCutterTypDnc(CutterTypeContrastEnum.getDncType(substring.substring(0, 1)));
|
|
|
- build.setCutterTypSubDnc(CutterTypeContrastEnum.getDncType(substring));
|
|
|
+ build.setCutterTypDnc("99");
|
|
|
+ build.setCutterTypSubDnc("99");
|
|
|
}
|
|
|
|
|
|
Double aDouble = json.getJSONObject("ToolList").getJSONObject("Tools").getJSONObject("Sets").getDouble("Length1");
|
|
@@ -198,16 +207,23 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
e.printStackTrace();
|
|
|
throw new RuntimeException("机外对刀仪获取数据失败");
|
|
|
}
|
|
|
-
|
|
|
- BeanUtils.copyProperties(cutterTestDataEntities.get(0),cuttingTool);
|
|
|
-
|
|
|
//此文件写入到redis中,确认已经读取过此文件的数据,不需要重复读取
|
|
|
msgUtil.redis_set(CheckCUtter, lastModifiedTime);
|
|
|
}
|
|
|
|
|
|
for (CutterTestDataEntity cutterTestDataEntity : cutterTestDataEntities) {
|
|
|
- //新增或修改刀具数据
|
|
|
- this.remove(Wraps.<CutterTestDataEntity>lbQ().eq(CutterTestDataEntity::getCutterT, cutterTestDataEntity.getCutterT()));
|
|
|
+ // 把旧的对刀数据添加到历史记录中去
|
|
|
+ CutterTestDataEntity one = this.getOne(Wraps.<CutterTestDataEntity>lbQ().eq(CutterTestDataEntity::getCutterT, cutterTestDataEntity.getCutterT()));
|
|
|
+
|
|
|
+ if(one!=null){
|
|
|
+ CutterTestDataRecordEntity cutterTestDataRecordEntity = CutterTestDataRecordEntity.builder().build();
|
|
|
+ BeanUtils.copyProperties(one, cutterTestDataRecordEntity);
|
|
|
+ cutterTestDataRecordEntity.setId(null);
|
|
|
+ testDataRecodeService.save(cutterTestDataRecordEntity);
|
|
|
+
|
|
|
+ //删除旧的对刀数据
|
|
|
+ this.removeById(one.getId());
|
|
|
+ }
|
|
|
this.save(cutterTestDataEntity);
|
|
|
}
|
|
|
|
|
@@ -217,40 +233,40 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public boolean pushPushToMachine(String destLocationNo, Long cuttingToolNo, TaskNode taskNode, TTask task){
|
|
|
+ public boolean pushPushToMachine(String destLocationNo, Long cuttingToolNo, TaskNode taskNode, TTask task) {
|
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
- queryWrapper.in("status", 2,3, 4);
|
|
|
+ queryWrapper.in("status", 2, 3, 4);
|
|
|
queryWrapper.in("cutter_t", cuttingToolNo);
|
|
|
List<CutterTestDataEntity> list = this.list(queryWrapper);
|
|
|
|
|
|
if (list.isEmpty()) {
|
|
|
- throw new RuntimeException("没有查询到对刀信息,需要的刀柄号:"+ cuttingToolNo);
|
|
|
+ throw new RuntimeException("没有查询到对刀信息,需要的刀柄号:" + cuttingToolNo);
|
|
|
}
|
|
|
|
|
|
CutterTestDataEntity cutterTestDataEntity = list.get(0);
|
|
|
|
|
|
// 根据设备id查询设备信息 进行推送
|
|
|
- Productionresource productionresource = productionresourceBizMapper.selectById(task==null?taskNode.getTargetResourceId() : task.getResourceId());
|
|
|
- if(productionresource == null){
|
|
|
- throw new RuntimeException("没有查询到需求设备,需要的刀柄号:"+ cuttingToolNo);
|
|
|
+ Productionresource productionresource = productionresourceBizMapper.selectById(task == null ? taskNode.getTargetResourceId() : task.getResourceId());
|
|
|
+ if (productionresource == null) {
|
|
|
+ throw new RuntimeException("没有查询到需求设备,需要的刀柄号:" + cuttingToolNo);
|
|
|
}
|
|
|
cutterTestDataEntity.setWriteOrDel("1");
|
|
|
cutterTestDataEntity.setCutterP(destLocationNo);
|
|
|
cutterTestDataEntity.setCutterPIp(cutterTestDataEntity.getCutterPIp());
|
|
|
|
|
|
- ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId,taskNode.getResourceId()));
|
|
|
+ ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId, taskNode.getResourceId()));
|
|
|
Long zoneId = zoneProductionresource.getZoneId();
|
|
|
ZZone zZone = zoneService.getById(zoneId);
|
|
|
- String url = (null == msgUtil.redis_get(ParameterKey.PARAMETERS)? "": ((Map<String,String>)msgUtil.redis_get(ParameterKey.PARAMETERS)).get(zZone.getNo() + "_plc").toString());
|
|
|
+ String url = (null == msgUtil.redis_get(ParameterKey.PARAMETERS) ? "" : ((Map<String, String>) msgUtil.redis_get(ParameterKey.PARAMETERS)).get(zZone.getNo() + "_plc").toString());
|
|
|
url = url + "/api/PushPushToMachine";
|
|
|
|
|
|
JSONObject rfidObj = new JSONObject();
|
|
|
rfidObj.put("url", productionresource.getIp());
|
|
|
rfidObj.put("port", productionresource.getPort());
|
|
|
rfidObj.put("taskId", taskNode.getTaskId().toString());
|
|
|
- rfidObj.put("taskNodeId", taskNode.getTaskId()+"1");
|
|
|
+ rfidObj.put("taskNodeId", taskNode.getTaskId() + "1");
|
|
|
rfidObj.put("data", JSONObject.toJSON(cutterTestDataEntity));
|
|
|
- if(destLocationNo==null || destLocationNo.isEmpty() || Double.parseDouble(destLocationNo)<=0){
|
|
|
+ if (destLocationNo == null || destLocationNo.isEmpty() || Double.parseDouble(destLocationNo) <= 0) {
|
|
|
BeanUtils.copyProperties(new CutterTestDataEntity(), cutterTestDataEntity);
|
|
|
cutterTestDataEntity.setWriteOrDel("2");
|
|
|
|
|
@@ -264,20 +280,20 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
String s = null;
|
|
|
try {
|
|
|
//todo wang.sq 对刀仪数据推送地址释放$需要换地址$
|
|
|
- if(imcsTOccsEnable){
|
|
|
+ if (imcsTOccsEnable) {
|
|
|
s = restTemplate.postForObject(url, formEntity, String.class);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
// 把机床下刀的数据同步过来,以保证二次入库,数据正确写入,只有在从机床出刀的时候才执行此代码
|
|
|
- if(jsonObject.getString("returnData") !=null && !jsonObject.getString("returnData").isEmpty() && cutterTestDataEntity.getWriteOrDel().equals("2")){
|
|
|
+ if (jsonObject.getString("returnData") != null && !jsonObject.getString("returnData").isEmpty() && cutterTestDataEntity.getWriteOrDel().equals("2")) {
|
|
|
CutterTestDataEntity returnData = JSONObject.parseObject(jsonObject.getString("returnData"), CutterTestDataEntity.class);
|
|
|
- BeanUtils.copyProperties(returnData,cutterTestDataEntity);
|
|
|
+ BeanUtils.copyProperties(returnData, cutterTestDataEntity);
|
|
|
}
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
s = "{\"taskID\":\"1\",\"taskNodeID\":\"1\",\"result\":\"true\",\"resultMsg\":\"消费成功\",\"concurrency\":\"false\",\"data\":null}\n";
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
- throw new RuntimeException("调用接口报错:"+ e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("调用接口报错:" + e.getMessage());
|
|
|
}
|
|
|
JSONObject retJson = JSONObject.parseObject(s);
|
|
|
Boolean result = retJson.getBoolean("result");
|
|
@@ -291,7 +307,7 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
//新增或修改刀具数据
|
|
|
this.update(cutterTestDataEntity, queryWrapper2);
|
|
|
return true;
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
cutterTestDataEntity.setStatus(4);
|
|
|
//新增或修改刀具数据
|
|
|
this.update(cutterTestDataEntity, queryWrapper2);
|
|
@@ -326,7 +342,7 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
CutterFile.findFileS(needFile, new ArrayList<>(), new ArrayList<>(), CutterSharedPath, "RFIDWrite.xml");
|
|
|
|
|
|
if (needFile.isEmpty()) {
|
|
|
- throw new BizException("没有找到文件");
|
|
|
+ throw new BizException("没有找到文件,缺失RFID文件");
|
|
|
}
|
|
|
|
|
|
File file = needFile.get(0);
|
|
@@ -340,8 +356,8 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
JSONArray xmlArrayData = CutterFile.findXmlArrayData(root);
|
|
|
for (Object xmlArrayDatum : xmlArrayData) {
|
|
|
JSONObject jsonObject = JSONObject.parseObject(xmlArrayDatum.toString());
|
|
|
- if("刀具号".equals(jsonObject.getString("name"))){
|
|
|
- String segment = jsonObject.getString("Segment").replace(" ","");
|
|
|
+ if ("刀具号".equals(jsonObject.getString("name"))) {
|
|
|
+ String segment = jsonObject.getString("Segment").replace(" ", "");
|
|
|
decimal = Integer.parseInt(segment, 10);
|
|
|
|
|
|
one = cuttingToolService.getOne(Wraps.<CuttingTool>lbQ().eq(CuttingTool::getCuttingToolNo, decimal));
|
|
@@ -357,14 +373,14 @@ public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMa
|
|
|
throw new BizException("机外对刀仪rfid对象文件获取失败");
|
|
|
}
|
|
|
|
|
|
- if(one ==null){
|
|
|
- throw new BizException("基础数据无此刀具号:"+ decimal);
|
|
|
+ if (one == null) {
|
|
|
+ throw new BizException("基础数据无此刀具号:" + decimal);
|
|
|
}
|
|
|
|
|
|
//对刀数据读取
|
|
|
try {
|
|
|
this.findCutterTestData(one);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new BizException(e.getMessage());
|
|
|
}
|