package com.chinaztt.mes.production.util;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.http.HttpRequest;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Map;
|
|
/**
|
* @Description:
|
* @Author: shz
|
* @Date: 2022/6/1 11:09
|
*/
|
@Component
|
public class MouldUtils {
|
@Value("${mould.url}")
|
private String mouldUrl;
|
|
public JSONArray get(Object param, String url) {
|
Map<String, Object> params = BeanUtil.beanToMap(param);
|
String result = HttpRequest.get(mouldUrl + url).form(params).execute().body();
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
JSONArray data = jsonObject.getJSONArray("data");
|
Boolean success = jsonObject.getBoolean("success");
|
if (success == null) {
|
throw new RuntimeException("请求模具处理失败");
|
} else if (!success) {
|
throw new RuntimeException("请求模具处理失败:" + jsonObject.getString("msg"));
|
}
|
return data;
|
}
|
|
public boolean send(Object param, String url) {
|
Map<String, Object> params = BeanUtil.beanToMap(param);
|
String result = HttpRequest.post(mouldUrl + url).form(params).execute().body();
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
Boolean success = jsonObject.getBoolean("success");
|
if (success == null) {
|
throw new RuntimeException("请求模具处理失败");
|
} else if (!success) {
|
throw new RuntimeException("请求模具处理失败:" + jsonObject.getString("msg"));
|
}
|
return true;
|
}
|
}
|