You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
5.6 KiB
131 lines
5.6 KiB
/* |
|
* Copyright (C), 2018-2021 |
|
* Project: starter |
|
* FileName: WechatTableDataModel |
|
* Author: Louis |
|
* Date: 2021/12/8 19:09 |
|
*/ |
|
package com.fr.plugin.icgq.data; |
|
|
|
import com.fanruan.api.design.DesignKit; |
|
import com.fanruan.api.log.LogKit; |
|
import com.fanruan.api.util.StringKit; |
|
import com.fr.json.JSONArray; |
|
import com.fr.json.JSONObject; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.plugin.context.PluginContexts; |
|
import com.fr.plugin.icgq.kit.HttpKit; |
|
import com.fr.stable.ParameterProvider; |
|
import com.fr.third.org.apache.http.entity.StringEntity; |
|
|
|
import java.io.IOException; |
|
import java.util.ArrayList; |
|
import java.util.HashMap; |
|
import java.util.Map; |
|
|
|
/** |
|
* <Function Description><br> |
|
* <UsersTableDataModel> |
|
* |
|
* @author fr.open |
|
* @since 1.0.0 |
|
*/ |
|
public class UsersTableDataModel extends WebTableDataModel { |
|
private static final long serialVersionUID = 8191435706966886501L; |
|
public static final String ACCOUNT_LIST = "/esc-idm/api/v1/account/list"; |
|
public static final String APP_ACCOUNT_ACCOUNT_UUID = "app_account__account_uuid"; |
|
public static final String APP_ACCOUNT_ACCOUNT_NO = "app_account__account_no"; |
|
public static final String APP_ACCOUNT_ACCOUNT_NAME = "app_account__account_name"; |
|
public static final String REQUEST_LOG_ACTION_FLAG = "request_log__action_flag"; |
|
public static final String REQUEST_LOG_ID = "request_log__id"; |
|
public static final String IDT_USER_USER_NAME = "idt_user__user_name"; |
|
public static final String IDT_USER_EMAIL = "idt_user__email"; |
|
public static final String IDT_USER_USER_EMAIL = "idt_user__user_email"; |
|
public static final String IDT_USER_WORK_NO = "idt_user__work_no"; |
|
public static final String IDT_USER_MOBILE = "idt_user__mobile"; |
|
public static final String IDT_ORG_NAME = "idt_org__name"; |
|
public static final String IDT_JOB_NAME = "idt_job__name"; |
|
|
|
public UsersTableDataModel(ParameterProvider[] parameters) { |
|
super(parameters); |
|
this.columnNames = new String[]{APP_ACCOUNT_ACCOUNT_UUID, APP_ACCOUNT_ACCOUNT_NO, APP_ACCOUNT_ACCOUNT_NAME, REQUEST_LOG_ACTION_FLAG, REQUEST_LOG_ID, IDT_USER_USER_NAME, IDT_USER_EMAIL, IDT_USER_USER_EMAIL, IDT_USER_MOBILE, IDT_USER_WORK_NO, IDT_ORG_NAME, IDT_JOB_NAME}; |
|
} |
|
|
|
@Override |
|
protected void init() { |
|
if (!PluginContexts.currentContext().isAvailable()) { |
|
LogKit.error(DesignKit.i18nText("Plugin-icgq_Licence_Expired")); |
|
return; |
|
} |
|
if (this.valueList != null) { |
|
return; |
|
} |
|
this.valueList = new ArrayList(); |
|
// 域名 |
|
this.host = this.parameters[0].getValue().toString(); |
|
// 登录名(盟拓方提供) |
|
String clientId = this.parameters[1].getValue().toString(); |
|
// 密钥固定分配) |
|
String secret = this.parameters[2].getValue().toString(); |
|
// 开始日期 |
|
String startTime = this.parameters[3].getValue().toString(); |
|
|
|
try { |
|
String accessToken = this.getAccessToken(clientId, secret); |
|
JSONArray usersInfo = getUserInfo(accessToken, startTime); |
|
addFRUserInfo2List(usersInfo); |
|
} catch (IOException e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
} |
|
} |
|
|
|
/** |
|
* 人员获取 |
|
* |
|
* @param accessToken |
|
* @param startTime |
|
* @return |
|
* @throws IOException |
|
*/ |
|
private JSONArray getUserInfo(String accessToken, String startTime) throws IOException { |
|
Map<String, String> header = new HashMap<>(); |
|
header.put("Content-Type", "application/json;charset=UTF-8"); |
|
header.put("Authorization", accessToken); |
|
JSONObject params = JSONObject.create(); |
|
params.put("size", "3000"); |
|
params.put("page", "1"); |
|
if (StringKit.isNotBlank(startTime)) { |
|
params.put("startTime", startTime); |
|
} |
|
StringEntity stringEntity = new StringEntity(params.encode(), "UTF-8"); |
|
String response = HttpKit.executeAndParse(com.fanruan.api.net.http.rs.HttpRequest.custom() |
|
.url(this.host + ACCOUNT_LIST).post(stringEntity).headers(header).build()); |
|
FineLoggerFactory.getLogger().info("icgq-UsersTableDataModel-getUserInfo-response:{}", response); |
|
JSONObject responseJo = new JSONObject(response); |
|
if (StringKit.equals(responseJo.getString("code"), "0")) { |
|
return responseJo.getJSONObject("data").getJSONArray("list"); |
|
} |
|
return JSONArray.create(); |
|
} |
|
|
|
private void addFRUserInfo2List(JSONArray usersInfo) { |
|
ArrayList<String> frUserInfo; |
|
for (Object o : usersInfo) { |
|
JSONObject userInfo = (JSONObject) o; |
|
frUserInfo = new ArrayList<>(); |
|
frUserInfo.add(userInfo.getString(APP_ACCOUNT_ACCOUNT_UUID)); |
|
frUserInfo.add(userInfo.getString(APP_ACCOUNT_ACCOUNT_NO)); |
|
frUserInfo.add(userInfo.getString(APP_ACCOUNT_ACCOUNT_NAME)); |
|
frUserInfo.add(userInfo.getString(REQUEST_LOG_ACTION_FLAG)); |
|
frUserInfo.add(userInfo.getString(REQUEST_LOG_ID)); |
|
frUserInfo.add(userInfo.getString(IDT_USER_USER_NAME)); |
|
frUserInfo.add(userInfo.getString(IDT_USER_EMAIL)); |
|
frUserInfo.add(userInfo.getString(IDT_USER_USER_EMAIL)); |
|
frUserInfo.add(userInfo.getString(IDT_USER_WORK_NO)); |
|
frUserInfo.add(userInfo.getString(IDT_USER_MOBILE)); |
|
frUserInfo.add(userInfo.getString(IDT_ORG_NAME)); |
|
frUserInfo.add(userInfo.getString(IDT_JOB_NAME)); |
|
this.valueList.add(frUserInfo.toArray()); |
|
} |
|
} |
|
} |