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"); /** * 构建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 path = new HashMap(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 path = new HashMap(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 path = new HashMap(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 path = new HashMap(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; } }