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.
113 lines
4.2 KiB
113 lines
4.2 KiB
3 years ago
|
/*
|
||
|
* Copyright (C), 2018-2021
|
||
|
* Project: starter
|
||
|
* FileName: DeptTableDataModel
|
||
|
* Author: fr.open
|
||
|
* Date: 2021/12/16 8:35
|
||
|
*/
|
||
|
package com.fr.plugin.icjb.data;
|
||
|
|
||
|
import com.fanruan.api.design.DesignKit;
|
||
|
import com.fanruan.api.log.LogKit;
|
||
|
import com.fr.general.ComparatorUtils;
|
||
|
import com.fr.general.http.HttpToolbox;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.log.FineLoggerFactory;
|
||
|
import com.fr.plugin.context.PluginContexts;
|
||
|
import com.fr.stable.ParameterProvider;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* <Function Description><br>
|
||
|
* <DeptTableDataModel>
|
||
|
*
|
||
|
* @author fr.open
|
||
|
* @since 1.0.0
|
||
|
*/
|
||
|
public class DeptTableDataModel extends WebTableDataModel {
|
||
|
private static final long serialVersionUID = 7967179724805496262L;
|
||
|
|
||
|
public DeptTableDataModel(ParameterProvider[] parameters) {
|
||
|
super(parameters);
|
||
|
this.columnNames = new String[]{"createDate", "updateDate", "status", "treeSort", "officeCode", "officeName", "parentCode", "parentCodes"};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void init() {
|
||
|
if (!PluginContexts.currentContext().isAvailable()) {
|
||
|
LogKit.error(DesignKit.i18nText("Plugin-icjb_Licence_Expired"));
|
||
|
return;
|
||
|
}
|
||
|
if (this.valueList != null) {
|
||
|
return;
|
||
|
}
|
||
|
this.valueList = new ArrayList();
|
||
|
// 域名
|
||
|
this.host = this.parameters[0].getValue().toString();
|
||
|
// 登录名(盟拓方提供)
|
||
|
String code = this.parameters[1].getValue().toString();
|
||
|
// 密钥固定分配:Qazxsw4321)
|
||
|
String secret = this.parameters[2].getValue().toString();
|
||
|
// 第三方应用分配的唯一标识(盟拓方提供)
|
||
|
String clientId = this.parameters[3].getValue().toString();
|
||
|
// 开始日期
|
||
|
String startDate = this.parameters[4].getValue().toString();
|
||
|
// 结束日期
|
||
|
String endDate = this.parameters[5].getValue().toString();
|
||
|
|
||
|
try {
|
||
|
String accessToken = this.getAccessToken(code, secret, clientId);
|
||
|
JSONArray deptInfo = getDeptInfo(accessToken, startDate, endDate);
|
||
|
addFRDeptInfo2List(deptInfo);
|
||
|
} catch (IOException e) {
|
||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 人员获取
|
||
|
*
|
||
|
* @param accessToken
|
||
|
* @param startDate
|
||
|
* @param endDate
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
|
private JSONArray getDeptInfo(String accessToken, String startDate, String endDate) throws IOException {
|
||
|
JSONObject resultJson;
|
||
|
Map<String, String> header = new HashMap<>();
|
||
|
header.put("Authorization", "Bearer " + accessToken);
|
||
|
Map<String, String> params = new HashMap<>();
|
||
|
params.put("startDate", startDate);
|
||
|
params.put("endDate", endDate);
|
||
|
String result = HttpToolbox.get(this.host + "sync/open-api/office-list", params, header);
|
||
|
FineLoggerFactory.getLogger().info("icjb-DeptTableDataModel-getDeptInfo-result:{}", result);
|
||
|
if (StringUtils.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("code"))) {
|
||
|
return resultJson.getJSONArray("data");
|
||
|
}
|
||
|
throw new RuntimeException("DeptTableDataModel getDeptInfo 获取结果异常");
|
||
|
}
|
||
|
|
||
|
private void addFRDeptInfo2List(JSONArray deptInfo) {
|
||
|
ArrayList<String> frDeptInfo;
|
||
|
for (Object o : deptInfo) {
|
||
|
JSONObject userInfo = (JSONObject) o;
|
||
|
frDeptInfo = new ArrayList<>();
|
||
|
frDeptInfo.add(userInfo.getString("createDate"));
|
||
|
frDeptInfo.add(userInfo.getString("updateDate"));
|
||
|
frDeptInfo.add(userInfo.getString("status"));
|
||
|
frDeptInfo.add(userInfo.getString("treeSort"));
|
||
|
frDeptInfo.add(userInfo.getString("officeCode"));
|
||
|
frDeptInfo.add(userInfo.getString("officeName"));
|
||
|
frDeptInfo.add(userInfo.getString("parentCode"));
|
||
|
frDeptInfo.add(userInfo.getString("parentCodes"));
|
||
|
this.valueList.add(frDeptInfo.toArray());
|
||
|
}
|
||
|
}
|
||
|
}
|