You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
weaver-develop/src/weaver/interfaces/thwl/action/sdk/ArtemisUtil.java

158 lines
5.2 KiB
Java

package weaver.interfaces.thwl.action.sdk;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import weaver.general.BaseBean;
import java.util.HashMap;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/14
* @version: 1.0
*/
public class ArtemisUtil {
/**
* APInginxip
*/
private static final String HOST = new BaseBean().getPropValue("artemisSdk", "host");
/**
* appkey
*/
private static final String APP_KEY = new BaseBean().getPropValue("artemisSdk", "appKey");
/**
* appSecret
*/
private static final String APP_SECRET = new BaseBean().getPropValue("artemisSdk", "appSecret");
/**
* config
* @return
*/
private static ArtemisConfig getConfig() {
ArtemisConfig config = new ArtemisConfig();
config.setHost(HOST);
config.setAppKey(APP_KEY);
config.setAppSecret(APP_SECRET);
return config;
}
/**
*
* @param addRequest
* @throws Exception
*/
public static void personSingleAdd(AddRequest addRequest) throws Exception {
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", "/artemis/api/resource/v2/person/single/add");
}
};
String body = JSON.toJSONString(addRequest);
String response = ArtemisHttpUtil.doPostStringArtemis(getConfig(), path, body, null, null, "application/json");
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equals(msg)) {
return;
}
throw new RuntimeException(msg);
}
/**
*
* @param updateRequest
* @throws Exception
*/
public static void personSingleUpdate(UpdateRequest updateRequest) throws Exception {
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", "/artemis/api/resource/v1/person/single/update");
}
};
String body = JSON.toJSONString(updateRequest);
String response = ArtemisHttpUtil.doPostStringArtemis(getConfig(), path, body, null, null, "application/json");
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equals(msg)) {
return;
}
throw new RuntimeException(msg);
}
/**
*
*
* @param orgInfo
* @return
*/
public static String getOrgIndexCode(OrgInfoRequest orgInfo) throws Exception {
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", "/artemis/api/resource/v1/org/orgIndexCodes/orgInfo");
}
};
String body = JSON.toJSONString(orgInfo);
String response = ArtemisHttpUtil.doPostStringArtemis(getConfig(), path, body, null, null, "application/json");
String orgIndexCode = "";
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equals(msg)) {
JSONObject data = jsonObject.getJSONObject("data");
JSONArray list = data.getJSONArray("list");
int total = data.getIntValue("total");
if (total > 0) {
JSONObject info = list.getJSONObject(0);
orgIndexCode = info.getString("orgIndexCode");
}
} else {
throw new RuntimeException(msg);
}
return orgIndexCode;
}
/**
* ID
*
* @param personInfoRequest
* @return
*/
public static String getPersonId(PersonInfoRequest personInfoRequest) throws Exception {
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", "/artemis/api/resource/v1/person/condition/personInfo");
}
};
String body = JSON.toJSONString(personInfoRequest);
String response = ArtemisHttpUtil.doPostStringArtemis(getConfig(), path, body, null, null, "application/json");
String personId = "";
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equals(msg)) {
JSONObject data = jsonObject.getJSONObject("data");
JSONArray list = data.getJSONArray("list");
int total = data.getIntValue("total");
if (total > 0) {
JSONObject info = list.getJSONObject(0);
personId = info.getString("personId");
}
} else {
throw new RuntimeException(msg);
}
return personId;
}
}