package com.zy.asrs.wms.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.zy.asrs.common.sys.entity.OperateLog; import com.zy.asrs.common.utils.HttpHandler; import com.zy.asrs.common.utils.Utils; import com.zy.asrs.framework.common.SpringUtils; import com.zy.asrs.framework.exception.CoolException; import com.zy.asrs.common.sys.service.OperateLogService; import com.zy.asrs.wms.task.AbstractHandler; import com.zy.asrs.wms.task.core.ReturnT; import lombok.extern.slf4j.Slf4j; import java.util.Date; import java.util.LinkedHashMap; @Slf4j public class PostMesDataUtils extends AbstractHandler { public ReturnT getMesData(String name,String URL,String mesPath, LinkedHashMap combParam){ boolean success = false; if(combParam != null){ String response = ""; try { response = new HttpHandler.Builder() .setUri(URL) .setPath(mesPath + Utils.ncErpDataEncode(combParam)) .build() .doGet(); System.out.println("response:"+response); JSONObject jsonObject = JSON.parseObject(response); JSONArray result = jsonObject.getJSONArray("result"); Object object = result.get(0); JSONObject data = JSON.parseObject(object.toString()); if (data.getBoolean("State")) { //上报成功 success = true; } else { //上报失败 log.error("请求接口失败!!!url:{};request:{};response:{}", URL+"/"+mesPath, JSON.toJSONString(combParam), response); // throw new CoolException("上报"+name); success = false; } // if (jsonObject.getInteger("code").equals(200) || jsonObject.getInteger("Code").equals(200)) { // // } else { // // } } catch (Exception e) { log.error("请求接口失败!!!url:{};request:{};response:{}", URL+"/"+mesPath, JSON.toJSONString(combParam), response); // TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return FAIL.setMsg(e.getMessage()); } finally { try { OperateLogService operateLogService = SpringUtils.getBean(OperateLogService.class); //记录上报数据 OperateLog operateLog = new OperateLog(); operateLog.setAction("上报ERP," + URL + mesPath); operateLog.setRequest(Utils.ncErpDataEncode(combParam)); operateLog.setResponse(response); operateLog.setCreateTime(new Date()); operateLog.setSystem("WMS"); operateLog.setUserId(9527L); operateLog.setIp("127.0.0.1"); operateLogService.save(operateLog); //记录上报数据 OperateLog operateLog1 = new OperateLog(); operateLog1.setAction("上报ERP," + URL + mesPath); operateLog1.setRequest(combParam.toString()); operateLog1.setResponse(response); operateLog1.setCreateTime(new Date()); operateLog1.setSystem("WMS"); operateLog1.setUserId(9527L); operateLog1.setIp("127.0.0.1"); operateLogService.save(operateLog1); } catch (Exception e) { log.error("", e); } } } if (!success){ return FAIL.setMsg("上報失敗"); } return SUCCESS; } }