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.
172 lines
5.1 KiB
172 lines
5.1 KiB
3 years ago
|
package com.eco.plugin.xx.bsdsjtb.servertd;
|
||
|
|
||
|
import com.eco.plugin.xx.bsdsjtb.config.PluginSimpleConfig;
|
||
|
import com.eco.plugin.xx.bsdsjtb.utils.FRUtils;
|
||
|
import com.eco.plugin.xx.bsdsjtb.utils.HttpUtils;
|
||
|
import com.eco.plugin.xx.bsdsjtb.utils.Utils;
|
||
|
import com.fr.base.TableData;
|
||
|
import com.fr.data.AbstractDataModel;
|
||
|
import com.fr.general.data.TableDataException;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.context.PluginContexts;
|
||
|
import com.fr.stable.fun.Authorize;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
import java.util.Locale;
|
||
|
|
||
|
@Authorize(callSignKey = "com.eco.plugin.xx.bsdsjtb")
|
||
|
public class UserHttpDataModel extends AbstractDataModel {
|
||
|
private static String[] COLUMN_NAMES = {"ad", "name", "userid","email","dept","password"};
|
||
|
private int rowCount = TableData.RESULT_ALL;
|
||
|
private DatasetData datas = new DatasetData();
|
||
|
|
||
|
public UserHttpDataModel(int count) {
|
||
|
this.rowCount = count;
|
||
|
if (this.rowCount == 0) {
|
||
|
return;
|
||
|
}
|
||
|
queryData();
|
||
|
}
|
||
|
|
||
|
//获取列的数量
|
||
|
@Override
|
||
|
public int getColumnCount() throws TableDataException {
|
||
|
return COLUMN_NAMES.length;
|
||
|
}
|
||
|
|
||
|
//获取列的名称
|
||
|
@Override
|
||
|
public String getColumnName(int i) throws TableDataException {
|
||
|
return COLUMN_NAMES[i];
|
||
|
}
|
||
|
|
||
|
//是否还有行
|
||
|
@Override
|
||
|
public boolean hasRow(int rowIndex) throws TableDataException {
|
||
|
int count = getRowCount();
|
||
|
return rowIndex < count;
|
||
|
}
|
||
|
|
||
|
//获取行数量
|
||
|
@Override
|
||
|
public int getRowCount() throws TableDataException {
|
||
|
if (this.datas == null) {
|
||
|
return 0;
|
||
|
}
|
||
|
List<List<Object>> values = this.datas.getValues();
|
||
|
if (values == null) {
|
||
|
return 0;
|
||
|
}
|
||
|
int count = values.size();
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
//获取数据
|
||
|
@Override
|
||
|
public Object getValueAt(int rowIndex, int columnIndex){
|
||
|
if (this.datas == null) {
|
||
|
return "";
|
||
|
}
|
||
|
List<List<Object>> values = this.datas.getValues();
|
||
|
if ((values == null) || (values.size() <= rowIndex)) {
|
||
|
return "";
|
||
|
}
|
||
|
List<Object> rowValues = values.get(rowIndex);
|
||
|
if ((rowValues == null) || (rowValues.size() <= columnIndex)) {
|
||
|
return "";
|
||
|
}
|
||
|
return rowValues.get(columnIndex);
|
||
|
}
|
||
|
|
||
|
//释放
|
||
|
@Override
|
||
|
public void release() {
|
||
|
this.datas = null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 查询数据
|
||
|
*/
|
||
|
private void queryData() {
|
||
|
if(PluginContexts.currentContext().isAvailable()){
|
||
|
try {
|
||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
|
||
|
JSONArray data = getUserData(psc);
|
||
|
addRowDatas(data);
|
||
|
} catch (Exception e) {
|
||
|
FRUtils.FRLogInfo("数据集获取用户信息,请求出错:"+e.getMessage());
|
||
|
throw new NullPointerException("数据集获取用户信息为空," + e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取token
|
||
|
* @return
|
||
|
*/
|
||
|
private static String getToken(PluginSimpleConfig psc,Long timestamp){
|
||
|
String str = "programid="+psc.getProgramid()+"&programcode="+psc.getProgramcode()+"×tamp="+timestamp;
|
||
|
FRUtils.FRLogInfo("token:"+str);
|
||
|
return Utils.getMd5Str(str).toUpperCase(Locale.ROOT);
|
||
|
}
|
||
|
|
||
|
private static JSONArray getUserData(PluginSimpleConfig psc) {
|
||
|
JSONArray result = new JSONArray();
|
||
|
String url = psc.getUrl();
|
||
|
JSONObject param = new JSONObject();
|
||
|
Long timestamp = System.currentTimeMillis();
|
||
|
param.put("programid",psc.getProgramid());
|
||
|
param.put("timestamp",timestamp);
|
||
|
param.put("signature",getToken(psc,timestamp));
|
||
|
|
||
|
String resultStr = HttpUtils.HttpPostJson(url,param.toString(),null);
|
||
|
|
||
|
if(Utils.isNullStr(resultStr)){
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
JSONObject resultJson = new JSONObject(resultStr);
|
||
|
String code = resultJson.getString("code");
|
||
|
|
||
|
if(!"200".equals(code)){
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
return resultJson.getJSONObject("data").getJsonArray("userInfoList");
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 添加行数据
|
||
|
* @param jsonArray
|
||
|
*/
|
||
|
private void addRowDatas(JSONArray jsonArray) {
|
||
|
if(jsonArray == null || jsonArray.size() <= 0){
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
for(int i =0;i< jsonArray.size();i++){
|
||
|
JSONObject org = jsonArray.getJSONObject(i);
|
||
|
String AD = org.getString("ad").toLowerCase(Locale.ROOT);
|
||
|
String name = org.getString("username");
|
||
|
String userid = org.getString("userid");
|
||
|
String email = org.getString("usermail");
|
||
|
String dept = org.getString("dept");
|
||
|
|
||
|
List<Object> rowDatas = new ArrayList<Object>();
|
||
|
|
||
|
rowDatas.add(AD);
|
||
|
rowDatas.add(name);
|
||
|
rowDatas.add(userid);
|
||
|
rowDatas.add(email);
|
||
|
rowDatas.add(dept);
|
||
|
rowDatas.add("EE3941B225BA898F");
|
||
|
|
||
|
List<List<Object>> values = this.datas.getValues();
|
||
|
values.add(rowDatas);
|
||
|
}
|
||
|
}
|
||
|
}
|