|
@@ -0,0 +1,231 @@
|
|
|
+package com.github.zuihou.business.cutterdata.service.impl;
|
|
|
+
|
|
|
+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.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.service.CutterTestDataService;
|
|
|
+import com.github.zuihou.business.cutterdata.utils.CutterFile;
|
|
|
+import com.github.zuihou.context.BaseContextHandler;
|
|
|
+import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
+import com.github.zuihou.injection.annonation.InjectionResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dom4j.DocumentException;
|
|
|
+import org.dom4j.io.SAXReader;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+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.io.File;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Project: imcs-admin-boot
|
|
|
+ * @Package: com.github.zuihou.business.cutterdata.service
|
|
|
+ * @Author: Lenovo
|
|
|
+ * @Time: 2024 - 11 - 21 15 : 12
|
|
|
+ * @Description: impl
|
|
|
+ */
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class CutterTestDataServiceImpl extends SuperServiceImpl<CutterTestDataMapper, CutterTestDataEntity> implements CutterTestDataService {
|
|
|
+ // 机外对刀仪共享文件路径
|
|
|
+ @Value("${cutter-shared.file-path}")
|
|
|
+ private String CutterSharedPath;
|
|
|
+
|
|
|
+ @Value("${cutter-shared.file-ip:192.168.0.116}")
|
|
|
+ private String CutterSharedIp;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String findCutterTestData() throws Exception {
|
|
|
+ log.info("===================定时获取机外对刀仪数据start===================");
|
|
|
+
|
|
|
+ List<File> needFile = new ArrayList<>();
|
|
|
+
|
|
|
+ // 判断网络通讯是否正常
|
|
|
+// if (!InetAddress.getByName(CutterSharedIp).isReachable(300)) {
|
|
|
+// System.out.println("网络不通");
|
|
|
+// }
|
|
|
+
|
|
|
+ // 获取需要解析的文件
|
|
|
+ CutterFile.findFileS(needFile, new ArrayList<>(), new ArrayList<>(), CutterSharedPath, "test.xml");
|
|
|
+
|
|
|
+ if (needFile.isEmpty()) {
|
|
|
+ return "需要解析的文件为空";
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CutterTestDataEntity> cutterTestDataEntities = new ArrayList<>();
|
|
|
+ List<String> cutterTs = new ArrayList<>();
|
|
|
+
|
|
|
+ for (File file : needFile) {
|
|
|
+ CutterTestDataEntity build = CutterTestDataEntity.builder().filePath(file.getPath()).build();
|
|
|
+ try {
|
|
|
+ SAXReader saxReader = new SAXReader();
|
|
|
+ org.dom4j.Document document = saxReader.read(file);
|
|
|
+ org.dom4j.Element root = document.getRootElement();
|
|
|
+ JSONObject json = CutterFile.findXmlData(root);
|
|
|
+
|
|
|
+ try {
|
|
|
+ build.setStatus(2);
|
|
|
+ build.setFilePath(file.getPath());
|
|
|
+ ZonedDateTime zonedDateTime = ZonedDateTime.parse(json.getJSONObject("ToolList").getString("DateTime"));
|
|
|
+ build.setFileTime(zonedDateTime.toLocalDateTime().toLocalDate().toString() + " " + zonedDateTime.toLocalDateTime().toLocalTime().toString());
|
|
|
+ build.setCutterName(json.getJSONObject("ToolList").getJSONObject("Tools").getString("Name"));
|
|
|
+ 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 (CutterTypeContrastEnum.getDncType(substring.substring(0, 1)) == null) { //说明此类型就是主类不是子类
|
|
|
+ build.setCutterTypDnc(CutterTypeContrastEnum.getDncType(substring) == null ? "99" : CutterTypeContrastEnum.getDncType(substring));
|
|
|
+ build.setCutterTypSubDnc("99");
|
|
|
+ } else {
|
|
|
+ build.setCutterTypDnc(CutterTypeContrastEnum.getDncType(substring.substring(0, 1)));
|
|
|
+ build.setCutterTypSubDnc(CutterTypeContrastEnum.getDncType(substring));
|
|
|
+ }
|
|
|
+
|
|
|
+ Double aDouble = json.getJSONObject("ToolList").getJSONObject("Tools").getJSONObject("Sets").getDouble("Length1");
|
|
|
+ build.setCutterZl(String.format("%.3f", aDouble));
|
|
|
+
|
|
|
+ Double aDouble1 = json.getJSONObject("ToolList").getJSONObject("Tools").getJSONObject("Sets").getDouble("Diameter1");
|
|
|
+ build.setCutterXl(String.format("%.3f", aDouble1));
|
|
|
+ build.setCutterRs(json.getJSONObject("ToolList").getJSONObject("Tools").getJSONObject("Sets").getString("Radius"));
|
|
|
+
|
|
|
+ JSONArray jsonArray = json.getJSONObject("ToolList").getJSONObject("Tools").getJSONObject("CustomFields").getJSONArray("Field");
|
|
|
+ if (!jsonArray.isEmpty()) {
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
+
|
|
|
+ if ("TO".equals(jsonObject.getString("Name"))) {
|
|
|
+
|
|
|
+ build.setCutterTo(jsonObject.getString("Value"));
|
|
|
+
|
|
|
+ } else if ("ORI".equals(jsonObject.getString("Name"))) {
|
|
|
+
|
|
|
+ build.setCutterOri(jsonObject.getString("Value"));
|
|
|
+
|
|
|
+ } else if ("TIME".equals(jsonObject.getString("Name"))) {
|
|
|
+
|
|
|
+ build.setCutterTime2(jsonObject.getString("Value"));
|
|
|
+
|
|
|
+ } else if ("OVERTIME".equals(jsonObject.getString("Name"))) {
|
|
|
+
|
|
|
+ build.setCutterOverTime(jsonObject.getString("Value"));
|
|
|
+
|
|
|
+ } else if ("PLC".equals(jsonObject.getString("Name"))) {
|
|
|
+
|
|
|
+ build.setCutterPlcBit(jsonObject.getString("Value"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("机外对刀仪字段解析失败");
|
|
|
+ build.setStatus(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ cutterTs.add(build.getCutterT());
|
|
|
+ cutterTestDataEntities.add(build);
|
|
|
+ } catch (DocumentException e) {
|
|
|
+ log.info("机外对刀仪获取数据失败");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (CutterTestDataEntity cutterTestDataEntity : cutterTestDataEntities) {
|
|
|
+ QueryWrapper queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("cutter_name", cutterTestDataEntity.getCutterName());
|
|
|
+ queryWrapper.eq("cutter_t", cutterTestDataEntity.getCutterT());
|
|
|
+ //新增或修改刀具数据
|
|
|
+ this.saveOrUpdate(cutterTestDataEntity, queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("===================定时获取机外对刀仪数据end===================");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String pushPushToMachine() throws Exception {
|
|
|
+ QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
+ queryWrapper.in("status", 2, 4);
|
|
|
+ List<CutterTestDataEntity> list = this.list(queryWrapper);
|
|
|
+
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ return "没有需要上传给机床的对刀数据";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (CutterTestDataEntity cutterTestDataEntity : list) {
|
|
|
+ cutterTestDataEntity.setCutterP("1.40");
|
|
|
+ cutterTestDataEntity.setCutterPIp("192.168.0.101");
|
|
|
+
|
|
|
+ String url = "http://127.0.0.1:8089/api/PushPushToMachine";
|
|
|
+ JSONObject rfidObj = new JSONObject();
|
|
|
+ rfidObj.put("url", "192.168.0.101");
|
|
|
+ rfidObj.put("port", "1900");
|
|
|
+ rfidObj.put("taskId", "12313");
|
|
|
+ rfidObj.put("taskNodeId", "12313123");
|
|
|
+ rfidObj.put("data", JSONObject.toJSON(cutterTestDataEntity));
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
+ HttpEntity<String> formEntity = new HttpEntity<String>(rfidObj.toJSONString(), headers);
|
|
|
+
|
|
|
+ String s = restTemplate.postForObject(url, formEntity, String.class);
|
|
|
+ log.info("============接收到对刀仪数据下发机床的结果数据========={}", s);
|
|
|
+ if (s == null) {
|
|
|
+ cutterTestDataEntity.setStatus(4);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject retJson = JSONObject.parseObject(s);
|
|
|
+
|
|
|
+ String code = retJson.getString("result").trim();
|
|
|
+ cutterTestDataEntity.setStatus(4);
|
|
|
+ if (code.equals("true")) {
|
|
|
+ cutterTestDataEntity.setStatus(3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (CutterTestDataEntity cutterTestDataEntity : list) {
|
|
|
+ QueryWrapper queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.eq("cutter_name", cutterTestDataEntity.getCutterName());
|
|
|
+ queryWrapper2.eq("cutter_t", cutterTestDataEntity.getCutterT());
|
|
|
+ //新增或修改刀具数据
|
|
|
+ this.saveOrUpdate(cutterTestDataEntity, queryWrapper2);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ // 启用属性自动注入
|
|
|
+ @InjectionResult
|
|
|
+ public IPage<CutterTestDataEntity> pageList(IPage page, LbqWrapper<CutterTestDataEntity> wrapper) {
|
|
|
+
|
|
|
+ BaseContextHandler.setTenant("0000");
|
|
|
+ IPage<CutterTestDataEntity> cutterTestDataDtoIPage = baseMapper.pageList(page, wrapper);
|
|
|
+
|
|
|
+
|
|
|
+ return cutterTestDataDtoIPage;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|