#
cp
2024-09-18 c6ff506917d173b2cf90948d84a77f86b847ab89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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<String> {
 
    public ReturnT<String> getMesData(String name,String URL,String mesPath, LinkedHashMap<String, Object> combParam){
        if(combParam != null){
            String response = "";
            boolean success = false;
            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);
                }
                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); }
            }
        }
        return SUCCESS;
    }
}