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

185 lines
6.4 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 {
/**
* 代理API网关nginx服务器ip端口
*/
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");
private static BaseBean baseBean = new BaseBean();
/**
* 构建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);
baseBean.writeLog("body==" + body);
baseBean.writeLog("response==" + response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equalsIgnoreCase(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");
baseBean.writeLog("body==" + body);
baseBean.writeLog("response==" + response);
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equalsIgnoreCase(msg)) {
return;
}
throw new RuntimeException(msg);
}
/**
* 获取部门组织唯一标识
*
* @param departmentMark
* @param departmentCode
* @param pageNo
* @param pageSize
* @return
* @throws Exception
*/
public static String getOrgIndexCode(String departmentMark, String departmentCode, int pageNo, int pageSize) throws Exception {
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", "/artemis/api/resource/v2/org/advance/orgList");
}
};
OrgListRequest orgListRequest = new OrgListRequest();
orgListRequest.setOrgName(departmentMark);
orgListRequest.setPageNo(pageNo);
orgListRequest.setPageSize(pageSize);
String body = JSON.toJSONString(orgListRequest);
String response = ArtemisHttpUtil.doPostStringArtemis(getConfig(), path, body, null, null, "application/json");
baseBean.writeLog("departmentCode==" + departmentCode + ",body==" + body);
baseBean.writeLog("response==" + response);
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equalsIgnoreCase(msg)) {
JSONObject data = jsonObject.getJSONObject("data");
JSONArray list = data.getJSONArray("list");
// 遍历List 通过部门编号获取组织代码
if (list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
JSONObject item = list.getJSONObject(i);
if (departmentCode.equals(item.getString("organizationCode"))) {
return item.getString("orgIndexCode");
}
}
// 当前页未匹配到,获取下一页的数据匹配
return getOrgIndexCode(departmentMark, departmentCode, pageNo + 1, pageSize);
}
// 未匹配到,返回空
return "";
} else {
throw new RuntimeException(msg);
}
}
/**
* 获取人员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");
baseBean.writeLog("body==" + body);
baseBean.writeLog("response==" + response);
String personId = "";
JSONObject jsonObject = JSON.parseObject(response);
String code = jsonObject.getString("code");
String msg = jsonObject.getString("msg");
if ("0".equals(code) && "SUCCESS".equalsIgnoreCase(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;
}
}