|
@@ -0,0 +1,98 @@
|
|
|
+package com.github.zuihou.business.controller.externalApi;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.zuihou.base.R;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.Productionresource;
|
|
|
+import com.github.zuihou.business.util.MsgUtil;
|
|
|
+import com.github.zuihou.common.util.StringUtil;
|
|
|
+import com.github.zuihou.context.BaseContextHandler;
|
|
|
+import com.github.zuihou.log.annotation.SysLog;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("/mes")
|
|
|
+@Api(value = "MesController", tags = "测量")
|
|
|
+@SysLog(enabled = true)
|
|
|
+public class MesController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MsgUtil msgUtil;
|
|
|
+
|
|
|
+ @ApiOperation(value = "站内机床数据采集接口", notes = "站内机床数据采集接口")
|
|
|
+ @PostMapping("/dataCollector")
|
|
|
+ public R dataCollector(@RequestBody Map<String, Object> params) {
|
|
|
+ log.warn("【站内机床数据采集】MES请求参数:{}",JSONObject.toJSONString(params));
|
|
|
+ BaseContextHandler.setTenant("0000");
|
|
|
+ String resourceIp = params.getOrDefault("resourceIp","").toString();
|
|
|
+
|
|
|
+ if(StringUtil.isEmpty(resourceIp)){
|
|
|
+ return R.fail("请求参数中未包含设备IP");
|
|
|
+ }
|
|
|
+
|
|
|
+ String ccsUrl="http://localhost:9000/DeviceApi";
|
|
|
+
|
|
|
+ JSONObject jsonParam = new JSONObject();
|
|
|
+ jsonParam.put("serverUrl",resourceIp);
|
|
|
+ jsonParam.put("ip",resourceIp);
|
|
|
+ jsonParam.put("port","4840");
|
|
|
+ jsonParam.put("deviceType","Mazaka");
|
|
|
+ jsonParam.put("type","Collect");
|
|
|
+
|
|
|
+ String resultData = msgUtil.httpForPost(ccsUrl, jsonParam.toString());
|
|
|
+ if(StringUtil.isEmpty(resultData)){
|
|
|
+ return R.fail("上位机服务异常");
|
|
|
+ }
|
|
|
+ JSONObject returnObj = JSONObject.parseObject(resultData);
|
|
|
+
|
|
|
+ if("1".equals(returnObj.getString("code"))){
|
|
|
+ return R.fail(returnObj.getString("msg"));
|
|
|
+ }
|
|
|
+ String runDatasInfoStr = returnObj.getString("runDatasInfo");
|
|
|
+ JSONObject collectObj = new JSONObject();
|
|
|
+ if(StringUtil.isNotEmpty(runDatasInfoStr)){
|
|
|
+ JSONObject runDatasInfo = JSONObject.parseObject(runDatasInfoStr);
|
|
|
+ collectObj.put("ncSysTime",new Date()); //系统时间
|
|
|
+ collectObj.put("ncModel",runDatasInfo.get("ncModel")); //cnc型号
|
|
|
+ collectObj.put("machineCoordinate",runDatasInfo.get("machineCoordinate")); //机械坐标
|
|
|
+ collectObj.put("absoluteCoordinate",runDatasInfo.get("absoluteCoordinate")); //绝对坐标
|
|
|
+ collectObj.put("relativeCoordinate",runDatasInfo.get("relativeCoordinate")); //相对坐标
|
|
|
+ collectObj.put("spindleLoad",runDatasInfo.get("spindleLoad")); //主轴负载
|
|
|
+ collectObj.put("feedAxisLoad",runDatasInfo.get("feedAxisLoad")); //进给轴负载
|
|
|
+ collectObj.put("servoLoad",runDatasInfo.get("servoLoad")); //伺服负载
|
|
|
+ collectObj.put("workMode",runDatasInfo.get("runMode")); //工作模式
|
|
|
+ collectObj.put("powerOnTime",runDatasInfo.get("powerOnTime")); //开机时间
|
|
|
+ collectObj.put("ncRunTime",runDatasInfo.get("ncRunTime")); //循环启动时间
|
|
|
+ collectObj.put("workState",runDatasInfo.get("runStatus")); //工作状态
|
|
|
+ collectObj.put("mainProg",runDatasInfo.get("mainProg")); //主程序号
|
|
|
+ collectObj.put("partsCount",runDatasInfo.get("partsCount")); //工件数
|
|
|
+ collectObj.put("currentToolNo",runDatasInfo.get("currentToolNo")); //当前刀号
|
|
|
+ collectObj.put("actFeedSpeed",runDatasInfo.get("actFeedSpeed")); //进给速度
|
|
|
+ collectObj.put("feedRateOvr",runDatasInfo.get("feedRateOvr")); //进给倍率
|
|
|
+ collectObj.put("spindleRateOvr",runDatasInfo.get("spindleRateOvr")); //主轴倍率
|
|
|
+ collectObj.put("actSpindleSpeed",runDatasInfo.get("actSpindleSpeed")); //主轴速度
|
|
|
+ }
|
|
|
+
|
|
|
+ String toolsData = returnObj.getString("toolsData");
|
|
|
+ if(StringUtil.isNotEmpty(toolsData)){
|
|
|
+ collectObj.put("tools",JSONArray.parseArray(toolsData)); //机床刀具列表清单
|
|
|
+ }
|
|
|
+
|
|
|
+ collectObj.put("alarms",returnObj.get("errorsInfo")); //报警数据
|
|
|
+ return R.success(collectObj);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|