| | |
| | | import com.zy.asrs.service.*; |
| | | import com.zy.asrs.task.AbstractHandler; |
| | | import com.zy.asrs.task.core.ReturnT; |
| | | import com.zy.common.utils.HttpHandler; |
| | | import lombok.Synchronized; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private FlowLogService flowLogService; |
| | | |
| | | @Autowired |
| | | private ReportDataService reportDataService; |
| | | |
| | | |
| | | @Transactional |
| | | public ReturnT<String> completedPutWayWrk(AgvWrkMast agvWrkMast) { |
| | |
| | | } |
| | | |
| | | private void reportMes(AgvWrkMast agvWrkMast, List<AgvWrkDetl> agvWrkDetls) { |
| | | if (!flag) { |
| | | return; |
| | | } |
| | | |
| | | if (Cools.isEmpty(agvWrkDetls)) { |
| | | return; |
| | | } |
| | |
| | | reportMesPakinOrder(agvWrkMast, agvWrkDetls); |
| | | } |
| | | } |
| | | try { |
| | | if (OUT_TYPE_List.contains(agvWrkMast.getIoType())) { |
| | | reportMesPakoutOrder(agvWrkMast, agvWrkDetls); |
| | | } |
| | | if (MOVE_TYPE_List.contains(agvWrkMast.getIoType())) { |
| | | generateMesParam(agvWrkMast, agvWrkDetls); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | if (OUT_TYPE_List.contains(agvWrkMast.getIoType())) { |
| | | reportMesPakoutOrder(agvWrkMast, agvWrkDetls); |
| | | } |
| | | if (MOVE_TYPE_List.contains(agvWrkMast.getIoType())) { |
| | | generateMesParam(agvWrkMast, agvWrkDetls); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | //获取mes token信息 |
| | | private Map<String, Object> getMesTokenInfo() { |
| | | Map<String, String> param = new HashMap<>(); |
| | | param.put("appKey", appKey); |
| | | param.put("appSecret", appSecret); |
| | | // Map<String, String> param = new HashMap<>(); |
| | | // param.put("appKey", appKey); |
| | | // param.put("appSecret", appSecret); |
| | | // |
| | | // JSONObject jsonObject = doHttpRequest(param, null, "获取MesToken", getTokenUrl, getTokenPath, null, "127.0.0.1"); |
| | | // |
| | | // Map<String, Object> headParam = new HashMap<>(); |
| | | // headParam.put("X-AUTH", JSON.parseObject(jsonObject.get("data").toString()).get("appAccessToken").toString()); |
| | | |
| | | JSONObject jsonObject = doHttpRequest(param, null, "获取MesToken", getTokenUrl, getTokenPath, null, "127.0.0.1"); |
| | | |
| | | Map<String, Object> headParam = new HashMap<>(); |
| | | headParam.put("X-AUTH", JSON.parseObject(jsonObject.get("data").toString()).get("appAccessToken").toString()); |
| | | |
| | | return headParam; |
| | | |
| | | // return headParam; |
| | | return null; |
| | | } |
| | | |
| | | //根据楼层默认出库仓位 |
| | |
| | | return null; |
| | | } |
| | | |
| | | private JSONObject doHttpRequest(Object requestParam, Map<String, Object> headParam, String namespace, String url, String path, String appkey, String ip) { |
| | | private void doHttpRequest(Object requestParam, Map<String, Object> headParam, String namespace, String url, String path, String appkey, String ip) { |
| | | //保证上报表 |
| | | ReportData reportData = new ReportData(); |
| | | reportData.setReportJson(JSONObject.toJSONString(requestParam)); |
| | | reportData.setMemo(namespace); |
| | | reportData.setCreateTime(new Date()); |
| | | reportData.setReportType("MES"); |
| | | reportDataService.insert(reportData); |
| | | |
| | | String response = ""; |
| | | boolean success = false; |
| | | |
| | | try { |
| | | response = new HttpHandler.Builder().setUri(url).setPath(path).setTimeout(30, TimeUnit.SECONDS).setHeaders(headParam).setJson(JSONObject.toJSONString(requestParam)).setHttps(true).build().doPost(); |
| | | JSONObject jsonObject = JSON.parseObject(response); |
| | | |
| | | if (Cools.isEmpty(jsonObject.get("code")) || Integer.parseInt(jsonObject.get("code").toString()) != 200) { |
| | | log.info("mes接口调用失败,返回信息:" + jsonObject); |
| | | //TODO 张超 |
| | | throw new CoolException("mes接口调用失败,返回信息:" + jsonObject); |
| | | } |
| | | success = true; |
| | | return jsonObject; |
| | | |
| | | // String succeed = jsonObject.get("succeed").toString(); |
| | | // String response = ""; |
| | | // boolean success = false; |
| | | // |
| | | // int code = Cools.eq("0",succeed) ? 0 : 1; |
| | | // if(code != 200){ |
| | | // throw new CoolException(jsonObject.get("dsc").toString()); |
| | | // try { |
| | | // response = new HttpHandler.Builder().setUri(url).setPath(path).setTimeout(30, TimeUnit.SECONDS).setHeaders(headParam).setJson(JSONObject.toJSONString(requestParam)).setHttps(true).build().doPost(); |
| | | // JSONObject jsonObject = JSON.parseObject(response); |
| | | // |
| | | // if (Cools.isEmpty(jsonObject.get("code")) || Integer.parseInt(jsonObject.get("code").toString()) != 200) { |
| | | // log.info("mes接口调用失败,返回信息:" + jsonObject); |
| | | // //TODO 张超 |
| | | // throw new CoolException("mes接口调用失败,返回信息:" + jsonObject); |
| | | // } |
| | | // success = true; |
| | | |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | throw new CoolException(e.getMessage()); |
| | | } finally { |
| | | apiLogService.save(namespace, url + path, appkey, ip, JSON.toJSONString(JSONObject.toJSONString(requestParam)), response, success); |
| | | } |
| | | // return jsonObject; |
| | | // |
| | | //// String succeed = jsonObject.get("succeed").toString(); |
| | | //// |
| | | //// int code = Cools.eq("0",succeed) ? 0 : 1; |
| | | //// if(code != 200){ |
| | | //// throw new CoolException(jsonObject.get("dsc").toString()); |
| | | //// } |
| | | //// success = true; |
| | | // |
| | | // } catch (Exception e) { |
| | | // log.error(e.getMessage()); |
| | | // throw new CoolException(e.getMessage()); |
| | | // } finally { |
| | | // apiLogService.save(namespace, url + path, appkey, ip, JSON.toJSONString(JSONObject.toJSONString(requestParam)), response, success); |
| | | // } |
| | | |
| | | } |
| | | |