24 changed files with 1719 additions and 1 deletions
Binary file not shown.
@ -1,3 +1,6 @@ |
|||||||
# open-JSD-9311 |
# open-JSD-9311 |
||||||
|
|
||||||
JSD-9311 企业微信标签用户数据集 |
JSD-9311 企业微信标签用户数据集\ |
||||||
|
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||||
|
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||||
|
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。 |
Binary file not shown.
@ -0,0 +1,26 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<plugin> |
||||||
|
<id>com.fr.plugin.icak.user</id> |
||||||
|
<name><![CDATA[用户数据集插件]]></name> |
||||||
|
<active>yes</active> |
||||||
|
<version>1.3.5</version> |
||||||
|
<env-version>10.0</env-version> |
||||||
|
<jartime>2018-07-31</jartime> |
||||||
|
<vendor>mqh</vendor> |
||||||
|
<description><![CDATA[用户数据集插件]]></description> |
||||||
|
<change-notes><![CDATA[用户数据集插件]]></change-notes> |
||||||
|
<main-package>com.fr.plugin.icak</main-package> |
||||||
|
<prefer-packages> |
||||||
|
<prefer-package>com.fanruan.api</prefer-package> |
||||||
|
</prefer-packages> |
||||||
|
<lifecycle-monitor class="com.fr.plugin.icak.PluginMonitor"/> |
||||||
|
<extra-core> |
||||||
|
<LocaleFinder class="com.fr.plugin.icak.LocaleFinder"/> |
||||||
|
</extra-core> |
||||||
|
<extra-designer> |
||||||
|
<ConnectionProvider class="com.fr.plugin.icak.provider.WechatConnectionDefine"/> |
||||||
|
<TableDataDefineProvider class="com.fr.plugin.icak.provider.WechatTableDataDefine"/> |
||||||
|
<ServerTableDataDefineProvider class="com.fr.plugin.icak.provider.WechatTableDataDefine"/> |
||||||
|
</extra-designer> |
||||||
|
<function-recorder class="com.fr.plugin.icak.LocaleFinder"/> |
||||||
|
</plugin> |
@ -0,0 +1,41 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2015-2019 |
||||||
|
* FileName: Constants |
||||||
|
* Author: Louis |
||||||
|
* Date: 2019/9/4 16:09 |
||||||
|
* Description: Constants |
||||||
|
* History: |
||||||
|
* <author> <time> <version> <desc> |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
|
||||||
|
/** |
||||||
|
* 〈Function Description〉<br> |
||||||
|
* 〈Constants〉 |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class Constants { |
||||||
|
public static final String ICON_PATH = "/com/fr/plugin/icak/images/logo16.png"; |
||||||
|
public static final String ICON_HELP = "/com/fr/plugin/icak/images/help.png"; |
||||||
|
public static final String ICON_PREVIEW = "/com/fr/design/images/m_file/preview.png"; |
||||||
|
public static final String ICON_REFRESH = "/com/fr/design/images/control/refresh.png"; |
||||||
|
public static final String HELP_URL = "https://help.finereport.com/index.php?search-fulltext-title-elasticsearch"; |
||||||
|
public static final String[] SEARCH_OPTIONS = new String[]{ |
||||||
|
DesignKit.i18nText("Plugin-Elasticsearch_Search_Query"), |
||||||
|
DesignKit.i18nText("Plugin-Elasticsearch_Search_Aggregation") |
||||||
|
}; |
||||||
|
public static final String URL_SEPARATOR = ","; |
||||||
|
|
||||||
|
public static final int DEFAULT_DB_INDEX = 0; |
||||||
|
public static final String[] DEFAULT_COLUMN_NAMES = new String[]{"text", "value"}; |
||||||
|
public static final String DATABASE = "database"; |
||||||
|
public static final String QUERY = "query"; |
||||||
|
public static final String SCRIPT = "script"; |
||||||
|
public static final String ORDER = "orderValue"; |
||||||
|
public static final String ENGINE = "engineType"; |
||||||
|
public static final String PARAMETERS = "parameters"; |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2020 |
||||||
|
* Project: starter |
||||||
|
* FileName: LocaleFinder |
||||||
|
* Author: Louis |
||||||
|
* Date: 2020/8/31 22:19 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak; |
||||||
|
|
||||||
|
import com.fr.intelli.record.Focus; |
||||||
|
import com.fr.intelli.record.Original; |
||||||
|
import com.fr.record.analyzer.EnableMetrics; |
||||||
|
import com.fr.stable.fun.Authorize; |
||||||
|
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||||
|
|
||||||
|
import static com.fr.plugin.icak.config.SsoConfig.PLUGIN_ID; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <LocaleFinder> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@EnableMetrics |
||||||
|
@Authorize(callSignKey = PLUGIN_ID) |
||||||
|
public class LocaleFinder extends AbstractLocaleFinder { |
||||||
|
|
||||||
|
@Override |
||||||
|
@Focus(id = PLUGIN_ID, text = "Plugin-icak", source = Original.PLUGIN) |
||||||
|
public String find() { |
||||||
|
return "com/fr/plugin/icak/locale/lang"; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: PluginMonitor |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/3/30 15:10 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak; |
||||||
|
|
||||||
|
import com.fr.plugin.context.PluginContext; |
||||||
|
import com.fr.plugin.icak.config.SsoConfig; |
||||||
|
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <PluginMonitor> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class PluginMonitor extends AbstractPluginLifecycleMonitor { |
||||||
|
public PluginMonitor() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void afterRun(PluginContext pluginContext) { |
||||||
|
SsoConfig.getInstance(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void beforeStop(PluginContext pluginContext) { |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: SsoConfig |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/3/30 9:38 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.config; |
||||||
|
|
||||||
|
import com.fr.config.ConfigContext; |
||||||
|
import com.fr.config.DefaultConfiguration; |
||||||
|
import com.fr.config.Visualization; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <SsoConfig> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
@Visualization(category = "Plugin-icak_Group") |
||||||
|
public class SsoConfig extends DefaultConfiguration { |
||||||
|
public static final String PLUGIN_ID = "com.fr.plugin.icak.user"; |
||||||
|
|
||||||
|
private static volatile SsoConfig config = null; |
||||||
|
// @Identifier(value = "uriBase", name = "Plugin-icak_Config_UriBase", description = "Plugin-icak_Config_UriBase_Description", status = Status.SHOW)
|
||||||
|
// private final Conf<String> uriBase = Holders.simple(StringKit.EMPTY);
|
||||||
|
|
||||||
|
public static SsoConfig getInstance() { |
||||||
|
if (config == null) { |
||||||
|
config = ConfigContext.getConfigInstance(SsoConfig.class); |
||||||
|
} |
||||||
|
return config; |
||||||
|
} |
||||||
|
|
||||||
|
// public String getUriBase() {
|
||||||
|
// return uriBase.get();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setUriBase(String uriBase) {
|
||||||
|
// this.uriBase.set(uriBase);
|
||||||
|
// }
|
||||||
|
} |
@ -0,0 +1,92 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatConnection |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/9 23:25 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.connection; |
||||||
|
|
||||||
|
import com.fanruan.api.conf.HolderKit; |
||||||
|
import com.fanruan.api.data.open.BaseConnection; |
||||||
|
import com.fanruan.api.i18n.I18nKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fanruan.api.util.TypeKit; |
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.data.impl.Connection; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatConnection> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatConnection extends BaseConnection { |
||||||
|
private static final long serialVersionUID = -6677801431870669597L; |
||||||
|
private final Conf<String> corpId = HolderKit.simple(StringKit.EMPTY); |
||||||
|
private final Conf<String> corpSecret = HolderKit.simple(StringKit.EMPTY); |
||||||
|
private final Conf<String> proxy = HolderKit.simple(StringKit.EMPTY); |
||||||
|
|
||||||
|
public WechatConnection() { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void testConnection() throws Exception { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String[] summary(String... args) { |
||||||
|
return super.summary(args); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String connectMessage(boolean status) { |
||||||
|
if (status) { |
||||||
|
return I18nKit.getLocText("Plugin-icak_Connection_Successfully"); |
||||||
|
} else { |
||||||
|
return I18nKit.getLocText("Plugin-icak_Connection_Failed"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void addConnection(List<String> list, String connectionName, Class<? extends Connection>[] acceptTypes) { |
||||||
|
for (Class<? extends com.fr.data.impl.Connection> accept : acceptTypes) { |
||||||
|
if (TypeKit.classInstanceOf(getClass(), accept)) { |
||||||
|
list.add(connectionName); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getDriver() { |
||||||
|
return StringKit.EMPTY; |
||||||
|
} |
||||||
|
|
||||||
|
public String getCorpId() { |
||||||
|
return corpId.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setCorpId(String corpId) { |
||||||
|
this.corpId.set(corpId); |
||||||
|
} |
||||||
|
|
||||||
|
public String getCorpSecret() { |
||||||
|
return corpSecret.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setCorpSecret(String corpSecret) { |
||||||
|
this.corpSecret.set(corpSecret); |
||||||
|
} |
||||||
|
|
||||||
|
public String getProxy() { |
||||||
|
return proxy.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setProxy(String proxy) { |
||||||
|
this.proxy.set(proxy); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatTableData |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/8 16:55 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.data; |
||||||
|
|
||||||
|
import com.fanruan.api.conf.HolderKit; |
||||||
|
import com.fanruan.api.data.ConnectionKit; |
||||||
|
import com.fanruan.api.data.open.BaseTableData; |
||||||
|
import com.fanruan.api.util.AssistKit; |
||||||
|
import com.fanruan.api.util.GeneralKit; |
||||||
|
import com.fanruan.api.xml.XmlKit; |
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.config.Identifier; |
||||||
|
import com.fr.config.holder.Conf; |
||||||
|
import com.fr.data.impl.Connection; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.general.data.DataModel; |
||||||
|
import com.fr.plugin.icak.connection.WechatConnection; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.NameReference; |
||||||
|
import com.fr.stable.xml.XMLPrintWriter; |
||||||
|
import com.fr.stable.xml.XMLableReader; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatTableData> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatTableData extends BaseTableData { |
||||||
|
private static final long serialVersionUID = -7456007025209900779L; |
||||||
|
@Identifier("database") |
||||||
|
private Conf<Connection> database = HolderKit.obj(null, Connection.class); |
||||||
|
@Identifier("searchType") |
||||||
|
private Conf<Integer> searchType = HolderKit.simple(0); |
||||||
|
|
||||||
|
@Override |
||||||
|
public DataModel createDataModel(Calculator calculator) { |
||||||
|
return createDataModel(calculator, TableData.RESULT_ALL); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DataModel createDataModel(Calculator calculator, int rowCount) { |
||||||
|
WechatConnection connection = getConnection(); |
||||||
|
if (ComparatorUtils.equals(this.getSearchType(), 1)) { |
||||||
|
return new WechatTagDataModel(Calculator.processParameters(calculator, super.getParameters(calculator)), connection); |
||||||
|
} else { |
||||||
|
return new WechatTableDataModel(Calculator.processParameters(calculator, super.getParameters(calculator)), connection); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private WechatConnection getConnection() { |
||||||
|
if (database.get() instanceof NameReference) { |
||||||
|
String name = ((NameReference) database.get()).getName(); |
||||||
|
return ConnectionKit.getConnection(name, WechatConnection.class); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void readXML(XMLableReader reader) { |
||||||
|
super.readXML(reader); |
||||||
|
if (reader.isChildNode()) { |
||||||
|
String tmpName = reader.getTagName(); |
||||||
|
if ("Attributes".equals(tmpName)) { |
||||||
|
this.setSearchType(reader.getAttrAsInt("searchType", 0)); |
||||||
|
} else if (com.fr.data.impl.Connection.XML_TAG.equals(tmpName)) { |
||||||
|
if (reader.getAttrAsString("class", null) != null) { |
||||||
|
com.fr.data.impl.Connection con = XmlKit.readXMLConnection(reader); |
||||||
|
this.setDatabase(con); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void writeXML(XMLPrintWriter writer) { |
||||||
|
super.writeXML(writer); |
||||||
|
writer.startTAG("Attributes"); |
||||||
|
writer.attr("searchType", GeneralKit.objectToString(getSearchType())); |
||||||
|
writer.end(); |
||||||
|
if (this.database.get() != null) { |
||||||
|
XmlKit.writeXMLConnection(writer, this.database.get()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object clone() throws CloneNotSupportedException { |
||||||
|
WechatTableData cloned = (WechatTableData) super.clone(); |
||||||
|
cloned.database = (Conf<Connection>) database.clone(); |
||||||
|
cloned.searchType = (Conf<Integer>) searchType.clone(); |
||||||
|
return cloned; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean equals(Object obj) { |
||||||
|
return obj instanceof WechatTableData |
||||||
|
&& AssistKit.equals(database, ((WechatTableData) obj).database) |
||||||
|
&& AssistKit.equals(this.searchType, ((WechatTableData) obj).searchType); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int hashCode() { |
||||||
|
return AssistKit.hashCode(this.database.get(), this.searchType.get()); |
||||||
|
} |
||||||
|
|
||||||
|
public Connection getDatabase() { |
||||||
|
return this.database.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setDatabase(Connection database) { |
||||||
|
this.database.set(database); |
||||||
|
} |
||||||
|
|
||||||
|
public int getSearchType() { |
||||||
|
return this.searchType.get(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSearchType(int searchType) { |
||||||
|
this.searchType.set(searchType); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,255 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatTableDataModel |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/8 19:09 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.data; |
||||||
|
|
||||||
|
import com.fanruan.api.data.open.BaseDataModel; |
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.err.TableDataException; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
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.icak.connection.WechatConnection; |
||||||
|
import com.fr.plugin.icak.utils.SSLClient; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.AssistUtils; |
||||||
|
import com.fr.stable.CodeUtils; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashSet; |
||||||
|
import java.util.Iterator; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatTableDataModel> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatTableDataModel extends BaseDataModel { |
||||||
|
private static final long serialVersionUID = 8191435706966886501L; |
||||||
|
private WechatConnection connection; |
||||||
|
private ParameterProvider[] parameters; |
||||||
|
|
||||||
|
private String[] columnNames; |
||||||
|
private ArrayList valueList = null; |
||||||
|
|
||||||
|
private JSONArray departments; |
||||||
|
private JSONArray departmentsCopy; |
||||||
|
private String proxy = StringKit.EMPTY; |
||||||
|
Set<String> subDepIds; |
||||||
|
|
||||||
|
public WechatTableDataModel(ParameterProvider[] parameters, WechatConnection connection) { |
||||||
|
this.connection = connection; |
||||||
|
this.parameters = parameters; |
||||||
|
this.columnNames = new String[]{"login", "dname", "id", "fid", "empno", "password", "name", "email", "mobile", "title", "titleno", "role"}; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getColumnCount() throws TableDataException { |
||||||
|
return this.columnNames.length; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getColumnName(int colIdx) throws TableDataException { |
||||||
|
return columnNames[colIdx]; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getRowCount() throws TableDataException { |
||||||
|
init(); |
||||||
|
return valueList.size(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getValueAt(int rowIdx, int colIdx) throws TableDataException { |
||||||
|
init(); |
||||||
|
return ((Object[]) valueList.get(rowIdx))[colIdx]; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void release() throws Exception { |
||||||
|
this.parameters = null; |
||||||
|
} |
||||||
|
|
||||||
|
private String getAccessToken(String corpId, String corpSecret) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + corpId + "&corpsecret=" + corpSecret, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson.getString("access_token"); |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getAccessToken 获取结果异常"); |
||||||
|
} |
||||||
|
|
||||||
|
private void init() { |
||||||
|
if (!PluginContexts.currentContext().isAvailable()) { |
||||||
|
LogKit.error(DesignKit.i18nText("Plugin-icak_Licence_Expired")); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (this.valueList != null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this.valueList = new ArrayList(); |
||||||
|
String corpId = this.connection.getCorpId(); |
||||||
|
String corpSecret = this.connection.getCorpSecret(); |
||||||
|
this.proxy = this.connection.getProxy(); |
||||||
|
String rootDepName = StringKit.EMPTY;// 需要筛选的根部门,逗号分隔; 如果为空表示获取应用下绑定的所有部门
|
||||||
|
String rootDepParentId = StringKit.EMPTY;// 根部门的父部门ID,用来构建树结构
|
||||||
|
for (ParameterProvider parameter : this.parameters) { |
||||||
|
if (StringKit.equals(parameter.getName(), "rootDepName")) { |
||||||
|
rootDepName = parameter.getValue().toString(); |
||||||
|
} |
||||||
|
if (StringKit.equals(parameter.getName(), "rootDepParentId")) { |
||||||
|
rootDepParentId = parameter.getValue().toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
String accessToken = getAccessToken(corpId, corpSecret); |
||||||
|
getWeChatDepInfo(accessToken); |
||||||
|
ArrayList<String> rootDepIds = getRootDepId(rootDepName); |
||||||
|
this.subDepIds = new HashSet<>(); |
||||||
|
for (String rootDepId : rootDepIds) { |
||||||
|
setSubDeptInfo(accessToken, rootDepId); |
||||||
|
LogKit.info("icak-WechatTableDataModel-subDepIds:{}", this.subDepIds); |
||||||
|
JSONArray usersInfo = getWeChatUserInfo(accessToken, rootDepId); |
||||||
|
addFRUserInfo2List(usersInfo, rootDepIds, rootDepParentId); |
||||||
|
} |
||||||
|
|
||||||
|
// 检查树结构是否完整
|
||||||
|
addNoneUserDep(rootDepIds, rootDepParentId); |
||||||
|
} |
||||||
|
|
||||||
|
private void getWeChatDepInfo(String accessToken) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + accessToken, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
departments = resultJson.getJSONArray("department"); |
||||||
|
departmentsCopy = departments.copy(); |
||||||
|
return; |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getWeChatDepInfo 获取结果异常"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* departments 返回的结果,parentid:0=公司,1=应用绑定的根部门 |
||||||
|
* |
||||||
|
* @param rootDepName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private ArrayList<String> getRootDepId(String rootDepName) { |
||||||
|
ArrayList<String> depIds = new ArrayList<>(); |
||||||
|
boolean isGetRootDepName = StringKit.isBlank(rootDepName); |
||||||
|
Iterator iterator = departments.iterator(); |
||||||
|
if (isGetRootDepName) { |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depJson = (JSONObject) iterator.next(); |
||||||
|
if (ComparatorUtils.equals(1, depJson.getInt("parentid"))) { |
||||||
|
depIds.add(depJson.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
String[] rootDepNames = rootDepName.split(","); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depJson = (JSONObject) iterator.next(); |
||||||
|
if (ArrayUtils.contains(rootDepNames, depJson.getString("name"))) { |
||||||
|
depIds.add(depJson.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return depIds; |
||||||
|
} |
||||||
|
|
||||||
|
private JSONArray getWeChatUserInfo(String accessToken, String depId) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/user/list?fetch_child=1&access_token=" + accessToken + "&department_id=" + depId, proxy); |
||||||
|
FineLoggerFactory.getLogger().info("icak-WechatTableDataModel-getWeChatUserInfo-result:{}", result); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson.getJSONArray("userlist"); |
||||||
|
} |
||||||
|
return JSONArray.create(); |
||||||
|
} |
||||||
|
|
||||||
|
private void setSubDeptInfo(String accessToken, String rootDepId) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + accessToken + "&id=" + rootDepId, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
for (Object obj : resultJson.getJSONArray("department")) { |
||||||
|
JSONObject dep = (JSONObject) obj; |
||||||
|
this.subDepIds.add(dep.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void addFRUserInfo2List(JSONArray usersInfo, ArrayList<String> rootDepIds, String rootDepParentId) { |
||||||
|
Iterator iterator = usersInfo.iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject userInfo = (JSONObject) iterator.next(); |
||||||
|
JSONArray depIds = userInfo.getJSONArray("department"); |
||||||
|
for (Object depId : depIds) { |
||||||
|
JSONObject dep = getWeChatDepByDepId(String.valueOf(depId)); |
||||||
|
if (!this.subDepIds.contains(String.valueOf(depId))) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
ArrayList frUserInfo = new ArrayList(); |
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(dep.getString("name")); |
||||||
|
frUserInfo.add(depId); // 默认部门ID是 1 2 3 这种, 转成 hashcode
|
||||||
|
frUserInfo.add(rootDepIds.contains(depId) ? rootDepParentId : dep.getString("parentid")); //父部门id
|
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(CodeUtils.md5Encode(userInfo.getString("mobile"), "", "MD5").toUpperCase()); |
||||||
|
frUserInfo.add(userInfo.getString("name")); |
||||||
|
frUserInfo.add(userInfo.getString("email")); |
||||||
|
frUserInfo.add(userInfo.getString("mobile")); |
||||||
|
frUserInfo.add(userInfo.getString("position")); |
||||||
|
frUserInfo.add(AssistUtils.hashCode(userInfo.getString("position"), "pos")); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
valueList.add(frUserInfo.toArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void addNoneUserDep(ArrayList<String> rootDepIds, String rootDepParentId) { |
||||||
|
Iterator iterator = departmentsCopy.iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depInfo = (JSONObject) iterator.next(); |
||||||
|
if (!this.subDepIds.contains(depInfo.getString("id"))) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
ArrayList frUserInfo = new ArrayList(); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(depInfo.getString("name")); |
||||||
|
frUserInfo.add(depInfo.get("id")); // 默认部门ID是 1 2 3 这种, 转成 hashcode
|
||||||
|
frUserInfo.add(rootDepIds.contains(depInfo.getString("id")) ? rootDepParentId : depInfo.getString("parentid")); //父部门id
|
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
valueList.add(frUserInfo.toArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 部门id 获取 部门
|
||||||
|
private JSONObject getWeChatDepByDepId(String depId) { |
||||||
|
for (Object department : departments) { |
||||||
|
JSONObject depJson = (JSONObject) department; |
||||||
|
if (ComparatorUtils.equals(depId, depJson.getString("id"))) { |
||||||
|
departmentsCopy.remove(depJson); |
||||||
|
return depJson; |
||||||
|
} |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getWeChatDepByDepId 为空"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,380 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatTagDataModel |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/14 16:02 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.data; |
||||||
|
|
||||||
|
import com.fanruan.api.data.open.BaseDataModel; |
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.err.TableDataException; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.general.ComparatorUtils; |
||||||
|
import com.fr.json.JSONArray; |
||||||
|
import com.fr.json.JSONObject; |
||||||
|
import com.fr.plugin.context.PluginContexts; |
||||||
|
import com.fr.plugin.icak.connection.WechatConnection; |
||||||
|
import com.fr.plugin.icak.utils.SSLClient; |
||||||
|
import com.fr.stable.ArrayUtils; |
||||||
|
import com.fr.stable.AssistUtils; |
||||||
|
import com.fr.stable.CodeUtils; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
|
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatTagDataModel> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatTagDataModel extends BaseDataModel { |
||||||
|
private static final long serialVersionUID = 8191435706966886501L; |
||||||
|
Set<String> subDepIds; |
||||||
|
private WechatConnection connection; |
||||||
|
private ParameterProvider[] parameters; |
||||||
|
private String[] columnNames; |
||||||
|
private ArrayList valueList = null; |
||||||
|
private JSONArray departments; |
||||||
|
private JSONArray departmentsCopy; |
||||||
|
private String proxy = StringKit.EMPTY; |
||||||
|
private String tagName = StringKit.EMPTY; |
||||||
|
private Map<String, JSONArray> tagUsers; |
||||||
|
|
||||||
|
public WechatTagDataModel(ParameterProvider[] parameters, WechatConnection connection) { |
||||||
|
this.connection = connection; |
||||||
|
this.parameters = parameters; |
||||||
|
this.tagUsers = new HashMap<>(); |
||||||
|
this.columnNames = new String[]{"login", "dname", "id", "fid", "empno", "password", "name", "email", "mobile", "title", "titleno", "role"}; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getColumnCount() throws TableDataException { |
||||||
|
return this.columnNames.length; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getColumnName(int colIdx) throws TableDataException { |
||||||
|
return columnNames[colIdx]; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getRowCount() throws TableDataException { |
||||||
|
init(); |
||||||
|
return valueList.size(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Object getValueAt(int rowIdx, int colIdx) throws TableDataException { |
||||||
|
init(); |
||||||
|
return ((Object[]) valueList.get(rowIdx))[colIdx]; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void release() throws Exception { |
||||||
|
this.parameters = null; |
||||||
|
} |
||||||
|
|
||||||
|
private void init() { |
||||||
|
if (!PluginContexts.currentContext().isAvailable()) { |
||||||
|
LogKit.error(DesignKit.i18nText("Plugin-icak_Licence_Expired")); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (this.valueList != null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
this.valueList = new ArrayList(); |
||||||
|
String corpId = this.connection.getCorpId(); |
||||||
|
String corpSecret = this.connection.getCorpSecret(); |
||||||
|
this.proxy = this.connection.getProxy(); |
||||||
|
String rootDepName = StringKit.EMPTY;// 需要筛选的根部门,逗号分隔; 如果为空表示获取应用下绑定的所有部门
|
||||||
|
String rootDepParentId = StringKit.EMPTY;// 根部门的父部门ID,用来构建树结构
|
||||||
|
this.tagName = StringKit.EMPTY; |
||||||
|
for (ParameterProvider parameter : this.parameters) { |
||||||
|
if (StringKit.equals(parameter.getName(), "rootDepName")) { |
||||||
|
rootDepName = parameter.getValue().toString(); |
||||||
|
} |
||||||
|
if (StringKit.equals(parameter.getName(), "rootDepParentId")) { |
||||||
|
rootDepParentId = parameter.getValue().toString(); |
||||||
|
} |
||||||
|
if (StringKit.equals(parameter.getName(), "tagName")) { |
||||||
|
this.tagName = parameter.getValue().toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
String accessToken = getAccessToken(corpId, corpSecret); |
||||||
|
getWeChatDepInfo(accessToken); |
||||||
|
ArrayList<String> rootDepIds = getRootDepId(rootDepName); |
||||||
|
|
||||||
|
this.subDepIds = new HashSet<>(); |
||||||
|
// LogKit.info("icak-WechatTableDataModel-rootDepIds");
|
||||||
|
for (String rootDepId : rootDepIds) { |
||||||
|
setSubDeptInfo(accessToken, rootDepId); |
||||||
|
} |
||||||
|
// LogKit.info("icak-WechatTableDataModel-subDepIds:{}", this.subDepIds);
|
||||||
|
// 标签用户
|
||||||
|
getUsersByTagName(accessToken, tagName); |
||||||
|
getTagUserInfo(accessToken, rootDepIds, rootDepParentId); |
||||||
|
// 检查树结构是否完整
|
||||||
|
addNoneUserDep(rootDepIds, rootDepParentId); |
||||||
|
} |
||||||
|
|
||||||
|
private void setSubDeptInfo(String accessToken, String rootDepId) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + accessToken + "&id=" + rootDepId, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
for (Object obj : resultJson.getJSONArray("department")) { |
||||||
|
JSONObject dep = (JSONObject) obj; |
||||||
|
this.subDepIds.add(dep.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String getAccessToken(String corpId, String corpSecret) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + corpId + "&corpsecret=" + corpSecret, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson.getString("access_token"); |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getAccessToken 获取结果异常"); |
||||||
|
} |
||||||
|
|
||||||
|
private void getTagUserInfo(String accessToken, ArrayList<String> rootDepIds, String rootDepParentId) { |
||||||
|
JSONObject tagUser; |
||||||
|
JSONArray usersInfo; |
||||||
|
JSONObject userInfo; |
||||||
|
boolean hasUser; |
||||||
|
// 先计算部门下用户
|
||||||
|
JSONArray usersInfoDept = JSONArray.create(); |
||||||
|
for (String rootDepId : rootDepIds) { |
||||||
|
usersInfo = getWeChatUserInfo(accessToken, rootDepId); |
||||||
|
usersInfoDept.addAll(usersInfo); |
||||||
|
} |
||||||
|
for (Map.Entry<String, JSONArray> entry : this.tagUsers.entrySet()) { |
||||||
|
// LogKit.info("icak-WechatTagDataModel-getTagUserInfo-entrySize-old:{}", entry.getValue().length());
|
||||||
|
Iterator<Object> iterator = entry.getValue().iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
tagUser = (JSONObject) iterator.next(); |
||||||
|
hasUser = addTagUserInfo2List(usersInfoDept, rootDepIds, rootDepParentId, entry.getKey(), tagUser.getString("userid")); |
||||||
|
if (hasUser) { |
||||||
|
iterator.remove(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
for (Map.Entry<String, JSONArray> entry : this.tagUsers.entrySet()) { |
||||||
|
// LogKit.info("icak-WechatTagDataModel-getTagUserInfo-entrySize-new:{}", entry.getValue().length());
|
||||||
|
for (Object obj : entry.getValue()) { |
||||||
|
tagUser = (JSONObject) obj; |
||||||
|
userInfo = getUserInfoById(accessToken, tagUser.getString("userid")); |
||||||
|
addTagUserInfo2List(userInfo, rootDepIds, rootDepParentId, entry.getKey()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private JSONArray getWeChatUserInfo(String accessToken, String depId) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/user/list?fetch_child=1&access_token=" + accessToken + "&department_id=" + depId, proxy); |
||||||
|
// FineLoggerFactory.getLogger().info("icak-WechatTableDataModel-getWeChatUserInfo-result:{}", result);
|
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson.getJSONArray("userlist"); |
||||||
|
} |
||||||
|
return JSONArray.create(); |
||||||
|
} |
||||||
|
|
||||||
|
private boolean addTagUserInfo2List(JSONArray usersInfo, ArrayList<String> rootDepIds, String rootDepParentId, String tagName, String userid) { |
||||||
|
JSONObject userInfo; |
||||||
|
JSONArray depIds; |
||||||
|
JSONObject dep; |
||||||
|
ArrayList<Object> frUserInfo; |
||||||
|
for (Object obj : usersInfo) { |
||||||
|
userInfo = (JSONObject) obj; |
||||||
|
if (StringKit.equals(userInfo.getString("userid"), userid)) { |
||||||
|
depIds = userInfo.getJSONArray("department"); |
||||||
|
for (Object depId : depIds) { |
||||||
|
dep = getWeChatDepByDepId(String.valueOf(depId)); |
||||||
|
frUserInfo = new ArrayList<>(); |
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(dep.getString("name")); |
||||||
|
frUserInfo.add(depId); // 默认部门ID是 1 2 3 这种, 转成 hashcode
|
||||||
|
frUserInfo.add(getFID(rootDepIds, String.valueOf(depId), rootDepParentId, dep.getString("parentid"))); //父部门id
|
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(CodeUtils.md5Encode(userInfo.getString("mobile"), "", "MD5").toUpperCase()); |
||||||
|
frUserInfo.add(userInfo.getString("name")); |
||||||
|
frUserInfo.add(userInfo.getString("email", StringKit.EMPTY)); |
||||||
|
frUserInfo.add(userInfo.getString("mobile")); |
||||||
|
frUserInfo.add(userInfo.getString("position")); |
||||||
|
frUserInfo.add(AssistUtils.hashCode(userInfo.getString("position"), "pos")); |
||||||
|
frUserInfo.add(tagName); |
||||||
|
this.valueList.add(frUserInfo.toArray()); |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
private void addTagUserInfo2List(JSONObject userInfo, ArrayList<String> rootDepIds, String rootDepParentId, String tagName) { |
||||||
|
JSONArray depIds = userInfo.getJSONArray("department"); |
||||||
|
JSONObject dep; |
||||||
|
ArrayList<Object> frUserInfo; |
||||||
|
for (Object depId : depIds) { |
||||||
|
dep = getWeChatDepByDepId(String.valueOf(depId)); |
||||||
|
frUserInfo = new ArrayList<>(); |
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(dep.getString("name")); |
||||||
|
frUserInfo.add(depId); // 默认部门ID是 1 2 3 这种, 转成 hashcode
|
||||||
|
frUserInfo.add(getFID(rootDepIds, String.valueOf(depId), rootDepParentId, dep.getString("parentid"))); //父部门id
|
||||||
|
frUserInfo.add(userInfo.getString("userid")); |
||||||
|
frUserInfo.add(CodeUtils.md5Encode(userInfo.getString("mobile"), "", "MD5").toUpperCase()); |
||||||
|
frUserInfo.add(userInfo.getString("name")); |
||||||
|
frUserInfo.add(userInfo.getString("email")); |
||||||
|
frUserInfo.add(userInfo.getString("mobile")); |
||||||
|
frUserInfo.add(userInfo.getString("position")); |
||||||
|
frUserInfo.add(AssistUtils.hashCode(userInfo.getString("position"), "pos")); |
||||||
|
frUserInfo.add(tagName); |
||||||
|
this.valueList.add(frUserInfo.toArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private String getFID(ArrayList<String> rootDepIds, String depId, String rootDepParentId, String parentId) { |
||||||
|
if (rootDepIds.contains(depId)) { |
||||||
|
return rootDepParentId; |
||||||
|
} else if (!this.subDepIds.contains(depId)) { |
||||||
|
return rootDepParentId; |
||||||
|
} |
||||||
|
return parentId; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private JSONObject getUserInfoById(String accessToken, String userid) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&userid=" + userid, proxy); |
||||||
|
// FineLoggerFactory.getLogger().info("icak-WechatTableDataModel-getUserInfoById-result:{}", result);
|
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson; |
||||||
|
} |
||||||
|
return JSONObject.create(); |
||||||
|
} |
||||||
|
|
||||||
|
private void getUsersByTagName(String accessToken, String tagName) { |
||||||
|
if (StringKit.isBlank(tagName)) { |
||||||
|
return; |
||||||
|
} |
||||||
|
JSONObject resultJson; |
||||||
|
ArrayList<String> tagIds = getTagIdByName(accessToken, tagName); |
||||||
|
if (tagIds.isEmpty()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
for (String tagId : tagIds) { |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=" + accessToken + "&tagid=" + tagId, proxy); |
||||||
|
// FineLoggerFactory.getLogger().info("icak-WechatTableDataModel-getUsersByTagName-result:{}", result);
|
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
this.tagUsers.put(resultJson.getString("tagname"), resultJson.getJSONArray("userlist")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private ArrayList<String> getTagIdByName(String accessToken, String tagName) { |
||||||
|
ArrayList<String> tagIds = new ArrayList<>(); |
||||||
|
String[] tagNames = tagName.split(","); |
||||||
|
JSONArray taglist = getWeChatTagList(accessToken); |
||||||
|
JSONObject tag; |
||||||
|
for (Object obj : taglist) { |
||||||
|
tag = (JSONObject) obj; |
||||||
|
if (ArrayUtils.contains(tagNames, tag.getString("tagname"))) { |
||||||
|
tagIds.add(tag.getString("tagid")); |
||||||
|
} |
||||||
|
} |
||||||
|
return tagIds; |
||||||
|
} |
||||||
|
|
||||||
|
private JSONArray getWeChatTagList(String accessToken) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=" + accessToken, proxy); |
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
return resultJson.getJSONArray("taglist"); |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinTagList GetWeixinTagList 获取结果异常"); |
||||||
|
} |
||||||
|
|
||||||
|
private void getWeChatDepInfo(String accessToken) { |
||||||
|
JSONObject resultJson; |
||||||
|
String result = SSLClient.doGet("https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=" + accessToken, proxy); |
||||||
|
// LogKit.info("icak-WechatTagDataModel-getWeChatDepInfo-result:{}", result);
|
||||||
|
if (StringKit.isNotBlank(result) && ComparatorUtils.equals(0, (resultJson = new JSONObject(result)).getInt("errcode"))) { |
||||||
|
departments = resultJson.getJSONArray("department"); |
||||||
|
departmentsCopy = departments.copy(); |
||||||
|
return; |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getWeChatDepInfo 获取结果异常"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* departments 返回的结果,parentid:0=公司,1=应用绑定的根部门 |
||||||
|
* |
||||||
|
* @param rootDepName |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private ArrayList<String> getRootDepId(String rootDepName) { |
||||||
|
ArrayList<String> depIds = new ArrayList<>(); |
||||||
|
boolean isGetRootDepName = StringKit.isBlank(rootDepName); |
||||||
|
Iterator iterator = departments.iterator(); |
||||||
|
if (isGetRootDepName) { |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depJson = (JSONObject) iterator.next(); |
||||||
|
if (ComparatorUtils.equals(1, depJson.getInt("parentid"))) { |
||||||
|
depIds.add(depJson.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
String[] rootDepNames = rootDepName.split(","); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depJson = (JSONObject) iterator.next(); |
||||||
|
if (ArrayUtils.contains(rootDepNames, depJson.getString("name"))) { |
||||||
|
depIds.add(depJson.getString("id")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return depIds; |
||||||
|
} |
||||||
|
|
||||||
|
private void addNoneUserDep(ArrayList<String> rootDepIds, String rootDepParentId) { |
||||||
|
Iterator iterator = departmentsCopy.iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depInfo = (JSONObject) iterator.next(); |
||||||
|
if (!this.subDepIds.contains(depInfo.getString("id"))) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
ArrayList frUserInfo = new ArrayList(); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(depInfo.getString("name")); |
||||||
|
frUserInfo.add(depInfo.get("id")); // 默认部门ID是 1 2 3 这种, 转成 hashcode
|
||||||
|
frUserInfo.add(rootDepIds.contains(depInfo.getString("id")) ? rootDepParentId : depInfo.getString("parentid")); //父部门id
|
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
frUserInfo.add(StringKit.EMPTY); |
||||||
|
valueList.add(frUserInfo.toArray()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 部门id 获取 部门
|
||||||
|
private JSONObject getWeChatDepByDepId(String depId) { |
||||||
|
Iterator iterator = departments.iterator(); |
||||||
|
while (iterator.hasNext()) { |
||||||
|
JSONObject depJson = (JSONObject) iterator.next(); |
||||||
|
if (ComparatorUtils.equals(depId, depJson.getString("id"))) { |
||||||
|
departmentsCopy.remove(depJson); |
||||||
|
return depJson; |
||||||
|
} |
||||||
|
} |
||||||
|
throw new RuntimeException("GetWeixinUserInfo getWeChatDepByDepId 为空"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatConnectionDefine |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/10 8:17 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.provider; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fr.data.impl.Connection; |
||||||
|
import com.fr.design.beans.BasicBeanPane; |
||||||
|
import com.fr.design.fun.impl.AbstractConnectionProvider; |
||||||
|
import com.fr.plugin.context.PluginContexts; |
||||||
|
import com.fr.plugin.icak.connection.WechatConnection; |
||||||
|
import com.fr.plugin.icak.ui.WechatConnectionPane; |
||||||
|
|
||||||
|
import static com.fr.plugin.icak.Constants.ICON_PATH; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatConnectionDefine> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatConnectionDefine extends AbstractConnectionProvider { |
||||||
|
@Override |
||||||
|
public int currentAPILevel() { |
||||||
|
return CURRENT_LEVEL; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String nameForConnection() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Wechat_Connection"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String iconPathForConnection() { |
||||||
|
return ICON_PATH; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends Connection> classForConnection() { |
||||||
|
if (PluginContexts.currentContext().isAvailable()) { |
||||||
|
return WechatConnection.class; |
||||||
|
} else { |
||||||
|
throw new RuntimeException(DesignKit.i18nText("Plugin-icak_Licence_Expired")); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends BasicBeanPane<? extends Connection>> appearanceForConnection() { |
||||||
|
if (PluginContexts.currentContext().isAvailable()) { |
||||||
|
return WechatConnectionPane.class; |
||||||
|
} else { |
||||||
|
throw new RuntimeException(DesignKit.i18nText("Plugin-icak_Licence_Expired")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatTableDataDefine |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/8 16:41 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.provider; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; |
||||||
|
import com.fr.design.fun.ServerTableDataDefineProvider; |
||||||
|
import com.fr.design.fun.impl.AbstractTableDataDefineProvider; |
||||||
|
import com.fr.plugin.icak.data.WechatTableData; |
||||||
|
import com.fr.plugin.icak.ui.WechatTableDataPane; |
||||||
|
|
||||||
|
import static com.fr.plugin.icak.Constants.ICON_PATH; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatTableDataDefine> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatTableDataDefine extends AbstractTableDataDefineProvider implements ServerTableDataDefineProvider { |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends TableData> classForTableData() { |
||||||
|
return WechatTableData.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends TableData> classForInitTableData() { |
||||||
|
return WechatTableData.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Class<? extends AbstractTableDataPane> appearanceForTableData() { |
||||||
|
return WechatTableDataPane.class; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String nameForTableData() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Wechat_Table_Data"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String prefixForTableData() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Wechat_Table_Data"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String iconPathForTableData() { |
||||||
|
return ICON_PATH; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,141 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WebBaseTableDatapane |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/10 8:49 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.ui; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.design.ui.action.UpdateAction; |
||||||
|
import com.fanruan.api.design.ui.component.UIToolbar; |
||||||
|
import com.fanruan.api.design.ui.component.table.UITableEditorPane; |
||||||
|
import com.fanruan.api.design.ui.component.table.action.UITableEditAction; |
||||||
|
import com.fanruan.api.design.ui.component.table.model.ParameterTableModel; |
||||||
|
import com.fanruan.api.design.ui.component.table.model.UITableModelAdapter; |
||||||
|
import com.fanruan.api.design.ui.toolbar.ToolBarDef; |
||||||
|
import com.fanruan.api.design.work.BaseTableDataPane; |
||||||
|
import com.fanruan.api.log.LogKit; |
||||||
|
import com.fanruan.api.util.IOKit; |
||||||
|
import com.fr.base.TableData; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.io.IOException; |
||||||
|
import java.net.URI; |
||||||
|
|
||||||
|
import static com.fr.plugin.icak.Constants.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WebBaseTableDatapane> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public abstract class WebBaseTableDataPane<T extends TableData> extends BaseTableDataPane<T> { |
||||||
|
private static final String PREVIEW_BUTTON = DesignKit.i18nText("Plugin-icak_Preview"); |
||||||
|
private static final String REFRESH_BUTTON = DesignKit.i18nText("Plugin-icak_Refresh"); |
||||||
|
private static final String HELP_BUTTON = DesignKit.i18nText("Plugin-icak_Help"); |
||||||
|
|
||||||
|
protected WebConnectionChosePane chosePane; |
||||||
|
protected UITableEditorPane<ParameterProvider> editorPane; |
||||||
|
|
||||||
|
public WebBaseTableDataPane() { |
||||||
|
this.setLayout(new BorderLayout(4, 4)); |
||||||
|
Box box = new Box(BoxLayout.Y_AXIS); |
||||||
|
JPanel northPane = new JPanel(new BorderLayout(4, 4)); |
||||||
|
JToolBar editToolBar = createToolBar(); |
||||||
|
northPane.add(editToolBar, BorderLayout.CENTER); |
||||||
|
JToolBar editHelpBar = createHelpBar(); |
||||||
|
northPane.add(editHelpBar, BorderLayout.EAST); |
||||||
|
northPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 6, 0)); |
||||||
|
|
||||||
|
UITableModelAdapter<ParameterProvider> model = new ParameterTableModel(); |
||||||
|
editorPane = new UITableEditorPane<ParameterProvider>(model); |
||||||
|
box.add(northPane); |
||||||
|
box.add(createQueryPane()); |
||||||
|
box.add(editorPane); |
||||||
|
JPanel sqlSplitPane = new JPanel(new BorderLayout(4, 4)); |
||||||
|
sqlSplitPane.add(box, BorderLayout.CENTER); |
||||||
|
chosePane = new WebConnectionChosePane(); |
||||||
|
chosePane.setPreferredSize(new Dimension(200, 200)); |
||||||
|
sqlSplitPane.add(chosePane, BorderLayout.WEST); |
||||||
|
this.add(sqlSplitPane, BorderLayout.CENTER); |
||||||
|
} |
||||||
|
|
||||||
|
private JToolBar createToolBar() { |
||||||
|
ToolBarDef toolBarDef = new ToolBarDef(); |
||||||
|
toolBarDef.addShortCut(new WebBaseTableDataPane.PreviewAction()); |
||||||
|
UIToolbar editToolBar = ToolBarDef.createJToolBar(); |
||||||
|
toolBarDef.updateToolBar(editToolBar); |
||||||
|
return editToolBar; |
||||||
|
} |
||||||
|
|
||||||
|
private JToolBar createHelpBar() { |
||||||
|
ToolBarDef helpBarDef = new ToolBarDef(); |
||||||
|
helpBarDef.addShortCut(new WebBaseTableDataPane.HelpAction()); |
||||||
|
UIToolbar editHelpBar = ToolBarDef.createJToolBar(); |
||||||
|
helpBarDef.updateToolBar(editHelpBar); |
||||||
|
return editHelpBar; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Query"); |
||||||
|
} |
||||||
|
|
||||||
|
protected abstract JComponent createQueryPane(); |
||||||
|
|
||||||
|
private void refresh() { |
||||||
|
java.util.List<ParameterProvider> existParameterList = editorPane.update(); |
||||||
|
ParameterProvider[] ps = existParameterList == null ? new ParameterProvider[0] : existParameterList.toArray(new ParameterProvider[0]); |
||||||
|
editorPane.populate(ps); |
||||||
|
} |
||||||
|
|
||||||
|
private class PreviewAction extends UpdateAction { |
||||||
|
public PreviewAction() { |
||||||
|
this.setName(PREVIEW_BUTTON); |
||||||
|
this.setMnemonic('P'); |
||||||
|
this.setSmallIcon(IOKit.readIcon(ICON_PREVIEW)); |
||||||
|
} |
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evt) { |
||||||
|
DesignKit.previewTableData(WebBaseTableDataPane.this.updateBean()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private class HelpAction extends UpdateAction { |
||||||
|
public HelpAction() { |
||||||
|
this.setName(HELP_BUTTON); |
||||||
|
this.setMnemonic('P'); |
||||||
|
this.setSmallIcon(IOKit.readIcon(ICON_HELP)); |
||||||
|
} |
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent evt) { |
||||||
|
try { |
||||||
|
Desktop.getDesktop().browse(URI.create(HELP_URL)); |
||||||
|
} catch (IOException e1) { |
||||||
|
LogKit.error(e1.getMessage(), e1); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected class RefreshAction extends UITableEditAction { |
||||||
|
public RefreshAction() { |
||||||
|
this.setName(REFRESH_BUTTON); |
||||||
|
this.setSmallIcon(IOKit.readIcon(ICON_REFRESH)); |
||||||
|
} |
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
refresh(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void checkEnabled() { |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,51 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WebConnectionChosePane |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/10 8:55 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.ui; |
||||||
|
|
||||||
|
import com.fanruan.api.design.ui.container.BasicPane; |
||||||
|
import com.fanruan.api.design.work.ConnectionComboBoxPanel; |
||||||
|
import com.fr.data.impl.Connection; |
||||||
|
import com.fr.plugin.icak.connection.WechatConnection; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WebConnectionChosePane> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WebConnectionChosePane extends BasicPane { |
||||||
|
private ConnectionComboBoxPanel connectionComboBoxPanel; |
||||||
|
|
||||||
|
public WebConnectionChosePane() { |
||||||
|
setLayout(new BorderLayout(4, 4)); |
||||||
|
connectionComboBoxPanel = new ConnectionComboBoxPanel(Connection.class) { |
||||||
|
protected void filterConnection(Connection connection, String conName, List<String> nameList) { |
||||||
|
connection.addConnection(nameList, conName, new Class[]{WechatConnection.class}); |
||||||
|
} |
||||||
|
}; |
||||||
|
this.add(connectionComboBoxPanel, BorderLayout.NORTH); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return "Choose"; |
||||||
|
} |
||||||
|
|
||||||
|
public String getSelectEsConnectionName() { |
||||||
|
return connectionComboBoxPanel.getSelectedItem(); |
||||||
|
} |
||||||
|
|
||||||
|
public void populateConnection(Connection connection) { |
||||||
|
connectionComboBoxPanel.populate(connection); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,100 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatConnectionPane |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/10 8:23 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.ui; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.design.ui.component.*; |
||||||
|
import com.fanruan.api.design.ui.layout.TableLayoutKit; |
||||||
|
import com.fanruan.api.design.util.GUICoreKit; |
||||||
|
import com.fanruan.api.design.work.DatabaseConnectionPane; |
||||||
|
import com.fanruan.api.util.IOKit; |
||||||
|
import com.fr.plugin.icak.connection.WechatConnection; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.awt.*; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
|
||||||
|
import static com.fr.plugin.icak.Constants.ICON_HELP; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatConnectionPane> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatConnectionPane extends DatabaseConnectionPane<WechatConnection> { |
||||||
|
private UITextField corpIdTextField; |
||||||
|
private UIPasswordField corpSecretTextField; |
||||||
|
private UITextField proxyTextField; |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JPanel mainPanel() { |
||||||
|
JPanel pane = new JPanel(); |
||||||
|
pane.setLayout(new BorderLayout()); |
||||||
|
corpIdTextField = new UITextField(); |
||||||
|
corpSecretTextField = new UIPasswordField(); |
||||||
|
proxyTextField = new UITextField(); |
||||||
|
|
||||||
|
JPanel globalConfigPane = new JPanel(); |
||||||
|
GridLayout gridLayout = new GridLayout(1, 2); |
||||||
|
globalConfigPane.setLayout(gridLayout); |
||||||
|
|
||||||
|
UIButton helpButton = new UIButton(); |
||||||
|
helpButton.setIcon(IOKit.readIcon(ICON_HELP)); |
||||||
|
helpButton.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
JOptionPane.showMessageDialog( |
||||||
|
SwingUtilities.getWindowAncestor(WechatConnectionPane.this), |
||||||
|
DesignKit.i18nText("Plugin-icak_Wechat_Connect_Description"), |
||||||
|
DesignKit.i18nText("Plugin-icak_Wechat_Config_Description"), |
||||||
|
JOptionPane.INFORMATION_MESSAGE |
||||||
|
); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
Component[][] components = new Component[][]{ |
||||||
|
{new UILabel(DesignKit.i18nText("Plugin-icak_Wechat_CorpId")), corpIdTextField}, |
||||||
|
{new UILabel(DesignKit.i18nText("Plugin-icak_Wechat_CorpSecret")), corpSecretTextField}, |
||||||
|
{new UILabel(DesignKit.i18nText("Plugin-icak_Wechat_Proxy")), |
||||||
|
GUICoreKit.createBorderLayoutPane(proxyTextField, BorderLayout.CENTER, helpButton, BorderLayout.EAST)} |
||||||
|
}; |
||||||
|
double p = TableLayoutKit.PREFERRED; |
||||||
|
double[] rowSize = new double[]{p, p, p, p}; |
||||||
|
double[] columnSize = new double[]{p, 400}; |
||||||
|
JPanel settingsUI = TableLayoutKit.createTableLayoutPane(components, rowSize, columnSize); |
||||||
|
settingsUI.setBorder(UITitledBorder.createBorderWithTitle(DesignKit.i18nText("Plugin-icak_Wechat_Connection"))); |
||||||
|
JPanel centerPane = GUICoreKit.createNormalFlowInnerContainerPane(); |
||||||
|
centerPane.add(settingsUI); |
||||||
|
pane.add(centerPane, BorderLayout.CENTER); |
||||||
|
return pane; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void populateSubDatabaseConnectionBean(WechatConnection connection) { |
||||||
|
corpIdTextField.setText(connection.getCorpId()); |
||||||
|
corpSecretTextField.setText(connection.getCorpSecret()); |
||||||
|
proxyTextField.setText(connection.getProxy()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected WechatConnection updateSubDatabaseConnectionBean() { |
||||||
|
WechatConnection connection = new WechatConnection(); |
||||||
|
connection.setCorpId(corpIdTextField.getText()); |
||||||
|
connection.setCorpSecret(String.valueOf(corpSecretTextField.getPassword())); |
||||||
|
connection.setProxy(proxyTextField.getText()); |
||||||
|
return connection; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Wechat_Connection"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatQueryPane |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/14 15:32 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.ui; |
||||||
|
|
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.design.ui.component.UIButtonGroup; |
||||||
|
import com.fanruan.api.design.ui.component.UILabel; |
||||||
|
import com.fanruan.api.design.ui.container.BasicPane; |
||||||
|
import com.fanruan.api.design.ui.layout.TableLayoutKit; |
||||||
|
|
||||||
|
import java.awt.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatQueryPane> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatQueryPane extends BasicPane { |
||||||
|
public static final String[] SEARCH_OPTIONS = new String[]{ |
||||||
|
DesignKit.i18nText("Plugin-icak_Search_Department"), |
||||||
|
DesignKit.i18nText("Plugin-icak_Search_Tag") |
||||||
|
}; |
||||||
|
private UIButtonGroup searchType; |
||||||
|
|
||||||
|
public WechatQueryPane() { |
||||||
|
setLayout(new BorderLayout()); |
||||||
|
searchType = new UIButtonGroup<String[]>(SEARCH_OPTIONS); |
||||||
|
searchType.setSelectedIndex(0); |
||||||
|
Component[][] coms = new Component[][]{ |
||||||
|
{new UILabel(DesignKit.i18nText("Plugin-icak_Search_Type") + ":"), searchType} |
||||||
|
}; |
||||||
|
|
||||||
|
double p = TableLayoutKit.PREFERRED; |
||||||
|
double f = TableLayoutKit.FILL; |
||||||
|
double[] rowSize = {p}; |
||||||
|
double[] columnSize = {p, f}; |
||||||
|
|
||||||
|
add(TableLayoutKit.createTableLayoutPane(coms, rowSize, columnSize)); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Query"); |
||||||
|
} |
||||||
|
|
||||||
|
public int getSearchType() { |
||||||
|
return searchType.getSelectedIndex(); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSearchType(int searchType) { |
||||||
|
this.searchType.setSelectedIndex(searchType); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,71 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: WechatTableDataPane |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/8 19:19 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.ui; |
||||||
|
|
||||||
|
import com.fanruan.api.data.ConnectionKit; |
||||||
|
import com.fanruan.api.design.DesignKit; |
||||||
|
import com.fanruan.api.util.StringKit; |
||||||
|
import com.fr.plugin.icak.data.WechatTableData; |
||||||
|
import com.fr.script.Calculator; |
||||||
|
import com.fr.stable.ParameterProvider; |
||||||
|
|
||||||
|
import javax.swing.*; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <WechatTableDataPane> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class WechatTableDataPane extends WebBaseTableDataPane<WechatTableData> { |
||||||
|
protected WechatQueryPane queryPane; |
||||||
|
|
||||||
|
public WechatTableDataPane() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected JComponent createQueryPane() { |
||||||
|
if (queryPane == null) { |
||||||
|
queryPane = new WechatQueryPane(); |
||||||
|
} |
||||||
|
return queryPane; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void populateBean(WechatTableData data) { |
||||||
|
if (data == null) { |
||||||
|
return; |
||||||
|
} |
||||||
|
Calculator c = Calculator.createCalculator(); |
||||||
|
this.editorPane.populate(data.getParameters(c)); |
||||||
|
this.chosePane.populateConnection(data.getDatabase()); |
||||||
|
this.queryPane.setSearchType(data.getSearchType()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public WechatTableData updateBean() { |
||||||
|
WechatTableData data = new WechatTableData(); |
||||||
|
String connectionName = this.chosePane.getSelectEsConnectionName(); |
||||||
|
if (StringKit.isNotEmpty(connectionName)) { |
||||||
|
data.setDatabase(ConnectionKit.createNameConnection(connectionName)); |
||||||
|
} |
||||||
|
List<ParameterProvider> parameterProviderList = this.editorPane.update(); |
||||||
|
ParameterProvider[] parameters = parameterProviderList.toArray(new ParameterProvider[0]); |
||||||
|
data.setParameters(parameters); |
||||||
|
data.setSearchType(queryPane.getSearchType()); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return DesignKit.i18nText("Plugin-icak_Query"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,93 @@ |
|||||||
|
/* |
||||||
|
* Copyright (C), 2018-2021 |
||||||
|
* Project: starter |
||||||
|
* FileName: SSLClient |
||||||
|
* Author: Louis |
||||||
|
* Date: 2021/12/8 20:09 |
||||||
|
*/ |
||||||
|
package com.fr.plugin.icak.utils; |
||||||
|
|
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.stable.StringUtils; |
||||||
|
import com.fr.third.org.apache.http.HttpEntity; |
||||||
|
import com.fr.third.org.apache.http.HttpHost; |
||||||
|
import com.fr.third.org.apache.http.HttpResponse; |
||||||
|
import com.fr.third.org.apache.http.client.HttpClient; |
||||||
|
import com.fr.third.org.apache.http.client.methods.HttpGet; |
||||||
|
import com.fr.third.org.apache.http.conn.ClientConnectionManager; |
||||||
|
import com.fr.third.org.apache.http.conn.scheme.Scheme; |
||||||
|
import com.fr.third.org.apache.http.conn.scheme.SchemeRegistry; |
||||||
|
import com.fr.third.org.apache.http.conn.ssl.SSLSocketFactory; |
||||||
|
import com.fr.third.org.apache.http.impl.client.DefaultHttpClient; |
||||||
|
import com.fr.third.org.apache.http.util.EntityUtils; |
||||||
|
|
||||||
|
import javax.net.ssl.SSLContext; |
||||||
|
import javax.net.ssl.TrustManager; |
||||||
|
import javax.net.ssl.X509TrustManager; |
||||||
|
import java.net.URI; |
||||||
|
import java.security.cert.CertificateException; |
||||||
|
import java.security.cert.X509Certificate; |
||||||
|
|
||||||
|
/** |
||||||
|
* <Function Description><br> |
||||||
|
* <SSLClient> |
||||||
|
* |
||||||
|
* @author Louis |
||||||
|
* @since 1.0.0 |
||||||
|
*/ |
||||||
|
public class SSLClient extends DefaultHttpClient { |
||||||
|
public SSLClient() throws Exception { |
||||||
|
super(); |
||||||
|
SSLContext ctx = SSLContext.getInstance("TLS"); |
||||||
|
X509TrustManager tm = new X509TrustManager() { |
||||||
|
@Override |
||||||
|
public void checkClientTrusted(X509Certificate[] chain, |
||||||
|
String authType) throws CertificateException { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void checkServerTrusted(X509Certificate[] chain, |
||||||
|
String authType) throws CertificateException { |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public X509Certificate[] getAcceptedIssuers() { |
||||||
|
return null; |
||||||
|
} |
||||||
|
}; |
||||||
|
ctx.init(null, new TrustManager[]{tm}, null); |
||||||
|
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); |
||||||
|
ClientConnectionManager ccm = this.getConnectionManager(); |
||||||
|
SchemeRegistry sr = ccm.getSchemeRegistry(); |
||||||
|
sr.register(new Scheme("https", 443, ssf)); |
||||||
|
} |
||||||
|
|
||||||
|
public static String doGet(String url, String proxyUrl) { |
||||||
|
HttpClient httpClient = null; |
||||||
|
HttpGet httpGet = null; |
||||||
|
HttpResponse response = null; |
||||||
|
String result = null; |
||||||
|
|
||||||
|
try { |
||||||
|
httpClient = new SSLClient(); |
||||||
|
httpGet = new HttpGet(url); |
||||||
|
httpGet.addHeader("Content-Type", "application/json"); |
||||||
|
if (StringUtils.isNotBlank(proxyUrl)) { |
||||||
|
URI proxyUri = new URI(proxyUrl); |
||||||
|
HttpHost proxy = new HttpHost(proxyUri.getHost(), proxyUri.getPort(), proxyUri.getScheme()); |
||||||
|
response = httpClient.execute(proxy, httpGet); |
||||||
|
} else { |
||||||
|
response = httpClient.execute(httpGet); |
||||||
|
} |
||||||
|
if (response != null) { |
||||||
|
HttpEntity resEntity = response.getEntity(); |
||||||
|
if (resEntity != null) { |
||||||
|
result = EntityUtils.toString(resEntity, "UTF-8"); |
||||||
|
} |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error("GetWeChatUserInfo doGet", e); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 817 B |
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,22 @@ |
|||||||
|
Plugin-icak=User DataSet Plugin |
||||||
|
Plugin-icak_Group=User DataSet Plugin |
||||||
|
Plugin-icak_Config_UriBase=Uri Base |
||||||
|
Plugin-icak_Config_UriBase_Description=Uri Base |
||||||
|
Plugin-icak_Licence_Expired=Sso Plugin Licence Expired |
||||||
|
Plugin-icak_Help=Help |
||||||
|
Plugin-icak_Preview=Preview |
||||||
|
Plugin-icak_Refresh=Refresh |
||||||
|
Plugin-icak_Wechat_Connection=Wechat Connection |
||||||
|
Plugin-icak_Wechat_CorpId=Corp Id |
||||||
|
Plugin-icak_Wechat_CorpSecret=Corp Secret |
||||||
|
Plugin-icak_Wechat_Proxy=Proxy |
||||||
|
Plugin-icak_Wechat_Connect_Description=Wechat Connect |
||||||
|
Plugin-icak_Wechat_Config_Description=Wechat Config |
||||||
|
Plugin-icak_Wechat_Table_Data=Wechat TableData |
||||||
|
Plugin-icak_Query=Query |
||||||
|
Plugin-icak_Config=Config |
||||||
|
Plugin-icak_Connection_Successfully=Connection Successfully! |
||||||
|
Plugin-icak_Connection_Failed=Connection Failed! |
||||||
|
Plugin-icak_Search_Type=Search Type |
||||||
|
Plugin-icak_Search_Department=Department |
||||||
|
Plugin-icak_Search_Tag=Tag |
@ -0,0 +1,22 @@ |
|||||||
|
Plugin-icak=\u7528\u6237\u6570\u636E\u96C6\u63D2\u4EF6 |
||||||
|
Plugin-icak_Group=\u7528\u6237\u6570\u636E\u96C6\u63D2\u4EF6 |
||||||
|
Plugin-icak_Config_UriBase=jwt\u6821\u9A8C\u63A5\u53E3\u5730\u5740 |
||||||
|
Plugin-icak_Config_UriBase_Description=jwt\u6821\u9A8C\u63A5\u53E3\u5730\u5740 |
||||||
|
Plugin-icak_Licence_Expired=\u7528\u6237\u6570\u636E\u96C6\u63D2\u4EF6\u8BB8\u53EF\u8FC7\u671F |
||||||
|
Plugin-icak_Help=\u5E2E\u52A9\u6587\u6863 |
||||||
|
Plugin-icak_Preview=\u9884\u89C8 |
||||||
|
Plugin-icak_Refresh=\u5237\u65B0 |
||||||
|
Plugin-icak_Wechat_Connection=\u5FAE\u4FE1\u8FDE\u63A5 |
||||||
|
Plugin-icak_Wechat_CorpId=\u4F01\u4E1AID |
||||||
|
Plugin-icak_Wechat_CorpSecret=\u5E94\u7528\u79D8\u94A5 |
||||||
|
Plugin-icak_Wechat_Proxy=\u4EE3\u7406 |
||||||
|
Plugin-icak_Wechat_Connect_Description=\u5FAE\u4FE1\u8FDE\u63A5\u914D\u7F6E\u8BF4\u660E |
||||||
|
Plugin-icak_Wechat_Config_Description=\u5FAE\u4FE1\u8FDE\u63A5\u914D\u7F6E\u8BF4\u660E |
||||||
|
Plugin-icak_Wechat_Table_Data=\u5FAE\u4FE1\u6570\u636E\u96C6 |
||||||
|
Plugin-icak_Query=\u67E5\u8BE2 |
||||||
|
Plugin-icak_Config=\u914D\u7F6E |
||||||
|
Plugin-icak_Connection_Successfully=\u8FDE\u63A5\u6210\u529F! |
||||||
|
Plugin-icak_Connection_Failed=\u8FDE\u63A5\u5931\u8D25! |
||||||
|
Plugin-icak_Search_Type=\u64CD\u4F5C\u79CD\u7C7B |
||||||
|
Plugin-icak_Search_Department=\u90E8\u95E8 |
||||||
|
Plugin-icak_Search_Tag=\u6807\u7B7E |
Loading…
Reference in new issue