Browse Source

open

master
pioneer 2 years ago
commit
d94749731a
  1. 6
      README.md
  2. BIN
      lib/finekit-10.0.jar
  3. BIN
      lib/gson-2.8.6.jar
  4. 28
      plugin.xml
  5. 25
      src/main/java/com/fr/plugin/third/party/jsdjjed/FeishuManagerComponent.java
  6. 33
      src/main/java/com/fr/plugin/third/party/jsdjjed/FeishuManagerSystemOption.java
  7. 41
      src/main/java/com/fr/plugin/third/party/jsdjjed/OutputPluginLifecycleMonitor.java
  8. 386
      src/main/java/com/fr/plugin/third/party/jsdjjed/Utils.java
  9. 40
      src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigAccessBridge.java
  10. 16
      src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigDao.java
  11. 138
      src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigData.java
  12. 87
      src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigEntity.java
  13. 498
      src/main/java/com/fr/plugin/third/party/jsdjjed/config/AppDataConfig.java
  14. 687
      src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuApp.java
  15. 55
      src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuChatGroupBean.java
  16. 63
      src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuLoginUserBean.java
  17. 29
      src/main/java/com/fr/plugin/third/party/jsdjjed/handle/ImageOutputFormat.java
  18. 23
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/CustomHttpHandlerProvider.java
  19. 22
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/CustomURLAliasProvider.java
  20. 566
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/SessionGlobalRequestFilterProvider.java
  21. 62
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/AddAppHttpHandler.java
  22. 62
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/DeleteAppHttpHandler.java
  23. 60
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/EditAppHttpHandler.java
  24. 64
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/ForbidAppHttpHandler.java
  25. 97
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryAppConfigHttpHandler.java
  26. 71
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryAppHttpHandler.java
  27. 91
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryChatGroupsHttpHandler.java
  28. 105
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/SaveAppConfigHttpHandler.java
  29. 46
      src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/SynchronizeSourceHttpHandler.java
  30. 410
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/AppMessagePushHandler.java
  31. 154
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/bean/OutputAppMessagePush.java
  32. 47
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/components/FileDef.java
  33. 19
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/components/JsAndCssBridge.java
  34. 131
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/entity/AppMessagePushEntity.java
  35. 24
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/formula/FeishuOutputFormula.java
  36. 22
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/formula/FormulaCalculator.java
  37. 16
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/provider/AppMessagePushDao.java
  38. 40
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/provider/DBAccessProvider.java
  39. 111
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/utils/PlaceholderResolver.java
  40. 35
      src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/utils/PropertiesUtils.java
  41. 140
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/AES.java
  42. 129
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/DateUtil.java
  43. 88
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/GZIPUtils.java
  44. 129
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/JsonHelper.java
  45. 51
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/Md5.java
  46. 451
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpClient.java
  47. 94
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequest.java
  48. 19
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestBytes.java
  49. 22
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestKV.java
  50. 67
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestParams.java
  51. 40
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraser.java
  52. 44
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserBytes.java
  53. 71
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserKV.java
  54. 46
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserString.java
  55. 19
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestString.java
  56. 113
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponse.java
  57. 32
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseBytes.java
  58. 19
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseBytesPraser.java
  59. 32
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponsePraser.java
  60. 33
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseString.java
  61. 30
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseStringPraser.java
  62. 69
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResultCode.java
  63. 47
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsParams.java
  64. 21
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestBytes.java
  65. 23
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestKV.java
  66. 21
      src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestString.java
  67. 46
      src/main/java/com/fr/plugin/third/party/jsdjjed/web/MainFilesComponent.java
  68. 19
      src/main/java/com/fr/plugin/third/party/jsdjjed/web/MainWebResourceProvider.java
  69. 2464
      src/main/resources/com/fr/plugin/third/party/jsdjjed/feishu.js
  70. 263
      src/main/resources/com/fr/plugin/third/party/jsdjjed/message.js
  71. 1
      src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/h5-js-sdk-1.5.12.js
  72. 36
      src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/login.html
  73. 24
      src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/runworkhelp.js
  74. 10
      src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/vconsole.min.js

6
README.md

@ -0,0 +1,6 @@
# open-JSD-9943
JSD-9943 私有版本飞书集成\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。

BIN
lib/finekit-10.0.jar

Binary file not shown.

BIN
lib/gson-2.8.6.jar

Binary file not shown.

28
plugin.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.plugin.third.party.jsdjjed</id>
<name><![CDATA[飞书登录集成与定时任务_EK]]></name>
<active>yes</active>
<version>1.0.37</version>
<env-version>10.0</env-version>
<jartime>2019-01-01</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[
]]></change-notes>
<lifecycle-monitor class="com.fr.plugin.third.party.jsdjjed.OutputPluginLifecycleMonitor"/>
<extra-core>
<DBAccessProvider class="com.fr.plugin.third.party.jsdjjed.app.config.AppConfigAccessBridge"/>
</extra-core>
<extra-decision>
<OutputFormulaProvider class="com.fr.plugin.third.party.jsdjjed.schedule.formula.FeishuOutputFormula"/>
<OutputFormulaExtractorProvider class="com.fr.plugin.third.party.jsdjjed.schedule.formula.FormulaCalculator"/>
<HttpHandlerProvider class="com.fr.plugin.third.party.jsdjjed.http.CustomHttpHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.third.party.jsdjjed.http.CustomURLAliasProvider"/>
<GlobalRequestFilterProvider class="com.fr.plugin.third.party.jsdjjed.http.SessionGlobalRequestFilterProvider"/>
<SystemOptionProvider class="com.fr.plugin.third.party.jsdjjed.FeishuManagerSystemOption"/>
<WebResourceProvider class="com.fr.plugin.third.party.jsdjjed.schedule.components.JsAndCssBridge"/>
<DecisionDBAccessProvider class="com.fr.plugin.third.party.jsdjjed.schedule.provider.DBAccessProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.third.party.jsdjjed.OutputPluginLifecycleMonitor"/>
</plugin>

25
src/main/java/com/fr/plugin/third/party/jsdjjed/FeishuManagerComponent.java

@ -0,0 +1,25 @@
package com.fr.plugin.third.party.jsdjjed;
import com.fr.web.struct.Component;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class FeishuManagerComponent extends Component {
public static FeishuManagerComponent KEY = new FeishuManagerComponent();
private FeishuManagerComponent(){
}
@Override
public ScriptPath script() {
return ScriptPath.build("/com/fr/plugin/third/party/jsdjjed/feishu.js");
}
@Override
public StylePath style() {
return StylePath.build("/com/fr/plugin/third/party/jsdjjed/feishu.css");
}
}

33
src/main/java/com/fr/plugin/third/party/jsdjjed/FeishuManagerSystemOption.java

@ -0,0 +1,33 @@
package com.fr.plugin.third.party.jsdjjed;
import com.fr.decision.fun.impl.AbstractSystemOptionProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class FeishuManagerSystemOption extends AbstractSystemOptionProvider {
@Override
public String id() {
return "decision-jsdjjed-feishu-manager";
}
@Override
public String displayName() {
return "飞书管理";
}
@Override
public int sortIndex() {
return 2;
}
@Override
public Atom attach() {
return MainComponent.KEY;
}
@Override
public Atom client() {
return FeishuManagerComponent.KEY;
}
}

41
src/main/java/com/fr/plugin/third/party/jsdjjed/OutputPluginLifecycleMonitor.java

@ -0,0 +1,41 @@
package com.fr.plugin.third.party.jsdjjed;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.plugin.third.party.jsdjjed.handle.ImageOutputFormat;
import com.fr.plugin.third.party.jsdjjed.schedule.AppMessagePushHandler;
import com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush;
import com.fr.plugin.third.party.jsdjjed.schedule.entity.AppMessagePushEntity;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.schedule.extension.report.job.output.BaseOutputFormat;
import com.fr.schedule.feature.ScheduleOutputActionEntityRegister;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.stable.fun.Authorize;
/**
* 配置信息初始化
*/
@EnableMetrics
public class OutputPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.third.party.jsdjjed", text = "plugin-jsdjjed", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
BaseOutputFormat.registerOutputFormat(new ImageOutputFormat());
AppDataConfig.getInstance();
OutputActionHandler.registerHandler(new AppMessagePushHandler(), OutputAppMessagePush.class.getName());
ScheduleOutputActionEntityRegister.getInstance().addClass(AppMessagePushEntity.class);
}
@Override
public void beforeStop(PluginContext pluginContext) {
BaseOutputFormat.removeOutputFormat(ImageOutputFormat.FORMAT_IMAGE);
OutputActionHandler.removeOutputHandler(OutputAppMessagePush.class.getName());
ScheduleOutputActionEntityRegister.getInstance().removeClass(AppMessagePushEntity.class);
}
}

386
src/main/java/com/fr/plugin/third/party/jsdjjed/Utils.java

@ -0,0 +1,386 @@
package com.fr.plugin.third.party.jsdjjed;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.authority.data.User;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.json.JSONObject;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.entity.mime.MultipartEntityBuilder;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.ssl.SSLContextBuilder;
import com.fr.third.org.apache.http.ssl.TrustStrategy;
import com.fr.third.org.apache.http.util.EntityUtils;
import com.fr.third.springframework.web.util.UriUtils;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.UUID;
public class Utils {
public static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
public static RequestConfig REQUEST_CONFIG = RequestConfig.custom()
.setConnectionRequestTimeout(30000)
.setSocketTimeout(30000) // 服务端相应超时
.setConnectTimeout(30000) // 建立socket链接超时时间
.build();
public static CloseableHttpClient createSslHttpClient() {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
return HttpClients.custom()
.setSSLSocketFactory(sslsf)
.build();
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
return HttpClients.createDefault();
}
public static CloseableHttpClient createDefaultHttpClient() {
CloseableHttpClient httpClient = HttpClients.custom()
.build();
return httpClient;
}
public static synchronized CloseableHttpClient createHttpClient(String url) {
CloseableHttpClient httpClient = null;
if (StringKit.isEmpty(url)) {
httpClient = createDefaultHttpClient();
return httpClient;
}
if (url.startsWith("https://")) {
httpClient = createSslHttpClient();
return httpClient;
}
httpClient = createDefaultHttpClient();
return httpClient;
}
/**
* 获取响应内容
*
* @param response
* @return
* @throws IOException
*/
public static String getResponseBodyContent(CloseableHttpResponse response) throws IOException {
if (response == null) {
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
return "";
}
String content = EntityUtils.toString(httpEntity, "UTF-8");
return content;
}
public static synchronized String createHttpGetContent(CloseableHttpClient httpClient, String url, String basicAuth, String contentType) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url))) {
return "";
}
LogKit.info("http请求链接:" + url);
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
if (StringKit.isNotEmpty(basicAuth)) {
httpGet.addHeader("Authorization", basicAuth);
}
if (StringKit.isNotEmpty(contentType)) {
httpGet.addHeader("Content-Type", contentType);
}
httpGet.setConfig(Utils.REQUEST_CONFIG);
CloseableHttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
String responseContent = getResponseBodyContent(response);
LogKit.info("http响应内容:\n" + responseContent);
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.error("http请求出错,http status:" + statusCode);
return "";
}
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.error("http请求出错,http响应内容为空");
return "";
}
return responseContent;
}
public static String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent, String basicAuth, String contentType) throws IOException {
return createHttpPostContent(httpClient, url, bodyContent, null, basicAuth, contentType);
}
public static String createHttpPostContent(CloseableHttpClient httpClient, String url, MultipartEntityBuilder multipartEntityBuilder, String basicAuth, String contentType) throws IOException {
return createHttpPostContent(httpClient, url, "", multipartEntityBuilder, basicAuth, contentType);
}
public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent, MultipartEntityBuilder multipartEntityBuilder, String basicAuth, String contentType) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url))) {
return "";
}
LogKit.info("http请求链接:" + url);
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
httpPost.setConfig(Utils.REQUEST_CONFIG);
if (StringKit.isNotEmpty(basicAuth)) {
httpPost.addHeader("Authorization", basicAuth);
}
if (StringKit.isNotEmpty(contentType)) {
httpPost.addHeader("Content-Type", contentType);
}
if (StringKit.isNotEmpty(bodyContent)) {
LogKit.info("http请求内容:\n" + bodyContent);
StringEntity bodyEntity = new StringEntity(bodyContent, "UTF-8");
httpPost.setEntity(bodyEntity);
}
if (multipartEntityBuilder != null) {
httpPost.setEntity(multipartEntityBuilder.build());
}
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseContent = getResponseBodyContent(response);
LogKit.info("http响应内容:\n" + responseContent);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.error("http请求出错,http status:" + statusCode);
return "";
}
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.error("http请求出错,http响应内容为空");
return "";
}
return responseContent;
}
public static String createHttpGetContent(CloseableHttpClient httpClient, String url, String contentType) throws IOException {
return createHttpGetContent(httpClient, url, "", contentType);
}
public static String createHttpGetContentWithHttpClient(String url, String basicAuth, String contentType) throws IOException {
CloseableHttpClient httpClient = Utils.createHttpClient(url);
String content = createHttpGetContent(httpClient, url, basicAuth, contentType);
httpClient.close();
return content;
}
public static String createHttpGetContentWithHttpClient(String url) throws IOException {
return createHttpGetContentWithHttpClient(url, "", "");
}
public static String createHttpPostContentWithHttpClient(String url, String bodyContent, String contentType) throws IOException {
return createHttpPostContentWithHttpClient(url, bodyContent, "", contentType);
}
public static String createHttpPostContentWithHttpClient(String url, String bodyContent, String basicAuth, String contentType) throws IOException {
CloseableHttpClient httpClient = Utils.createHttpClient(url);
String content = createHttpPostContent(httpClient, url, bodyContent, basicAuth, contentType);
httpClient.close();
return content;
}
public static String createHttpPostContentWithHttpClient(String url, MultipartEntityBuilder multipartEntityBuilder, String contentType) throws IOException {
return createHttpPostContentWithHttpClient(url, multipartEntityBuilder, "", contentType);
}
public static String createHttpPostContentWithHttpClient(String url, MultipartEntityBuilder multipartEntityBuilder, String basicAuth, String contentType) throws IOException {
CloseableHttpClient httpClient = Utils.createHttpClient(url);
String content = createHttpPostContent(httpClient, url, multipartEntityBuilder, basicAuth, contentType);
httpClient.close();
return content;
}
public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent, String contentType) throws IOException {
return createHttpPostContent(httpClient, url, bodyContent, "", contentType);
}
public static String getRequestUrl(HttpServletRequest req) {
if (req == null) {
return "";
}
String url = req.getRequestURL().toString();
return url;
}
/**
* 获取完整请求链接
*
* @param req 请求
* @return
*/
public static String getFullRequestUrl(HttpServletRequest req) {
if (req == null) {
return "";
}
String url = req.getRequestURL().toString();
String queryUrl = req.getQueryString();
if ((queryUrl == null) || "null".equalsIgnoreCase(queryUrl)) {
queryUrl = "";
} else {
queryUrl = "?" + queryUrl;
}
String fullUrl = url + queryUrl;
return fullUrl;
}
public static boolean isDecisionLoginRequest(HttpServletRequest req) {
if (req == null) {
return false;
}
if (!"GET".equalsIgnoreCase(req.getMethod())) {
return false;
}
String url = req.getRequestURL().toString();
if (url.endsWith("/decision/login") || url.endsWith("/decision/login/")) {
return true;
}
return false;
}
/**
* 重定向
*
* @param res
* @param url
*/
public static void sendRedirect(HttpServletResponse res, String url) {
if ((res == null) || (StringKit.isEmpty(url))) {
return;
}
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
public static synchronized String getUuid() {
String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}
/**
* 通过用户名删除用户,管理员用户无法删除
*
* @param username 用户名
* @return
* @throws Exception
*/
public static int deleteUsersByUsername(String username) throws Exception {
if (StringUtils.isEmpty(username)) {
return 0;
}
User user = UserService.getInstance().getUserByUserName(username);
if (user == null) {
return 0;
}
String userId = user.getId();
List<String> adminUserIds = UserService.getInstance().getAdminUserIdList();
if ((adminUserIds != null) && (adminUserIds.size() >= 1) && (adminUserIds.contains(userId))) {
return 0;
}
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return UserService.getInstance().deleteUsers(userUpdateBean);
}
public static int deleteUsersByUsernames(List<String> usernames) throws Exception {
if ((usernames == null) || (usernames.size() <= 0)) {
return 0;
}
String username;
int totalCount = 0, count;
for (int i = 0, max = usernames.size() - 1; i <= max; i++) {
username = usernames.get(i);
count = deleteUsersByUsername(username);
totalCount = totalCount + count;
}
return totalCount;
}
public static void editRealNameByUsername(String username, String realName) throws Exception {
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(realName)) {
return;
}
User user = UserService.getInstance().getUserByUserName(username);
if (user == null) {
return;
}
UserBean userBean = new UserBean(user.getEmail(), user.isEnable(), user.getMobile(), realName, user.getUserName(), user.getId());
UserService.getInstance().editAccount(username, userBean);
}
public static JSONObject getSuccessResultJson() {
return getResultJson("success", "");
}
public static JSONObject getFailuresResultJson() {
return getResultJson("failure", "");
}
public static JSONObject getFailuresResultJson(String msg) {
return getResultJson("failure", msg);
}
public static JSONObject getResultJson(String status, String msg) {
JSONObject json = new JSONObject();
json.put("status", status);
json.put("msg", msg);
return json;
}
public static String encodeUrlWithUtf8(String value) {
if ((value == null) || (value.length() <= 0)) {
return "";
}
/*String path = "/" + value;
URI uri = new URI("http", "a", path, null);
String tempValue = uri.toASCIIString();
String encodedValue = tempValue.substring(9);*/
String tempValue = "";
try {
tempValue = UriUtils.encodeQueryParam(value, "UTF-8");
return tempValue;
} catch (Exception e) {
LogKit.error("Utils.encodeUrlWithUtf8:" + e.getMessage(), e);
tempValue = value;
}
return tempValue;
}
}

40
src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigAccessBridge.java

@ -0,0 +1,40 @@
package com.fr.plugin.third.party.jsdjjed.app.config;
import com.fr.db.fun.impl.AbstractDBAccessProvider;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
import com.fr.stable.fun.Authorize;
@Authorize(callSignKey = "com.fr.plugin.third.party.jsdjjed")
public class AppConfigAccessBridge extends AbstractDBAccessProvider {
private static DBAccessor dbAccessor = null;
public static DBAccessor getDbAccessor() {
return dbAccessor;
}
@Override
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
new DAOProvider() {
@Override
public Class getEntityClass() {
return AppConfigEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return AppConfigDao.class;
}
}
};
}
@Override
public void onDBAvailable(DBAccessor dbAccessor) {
AppConfigAccessBridge.dbAccessor = dbAccessor;
}
}

16
src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigDao.java

@ -0,0 +1,16 @@
package com.fr.plugin.third.party.jsdjjed.app.config;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
public class AppConfigDao extends BaseDAO<AppConfigEntity> {
public AppConfigDao(DAOSession daoSession) {
super(daoSession);
}
@Override
protected Class<AppConfigEntity> getEntityClass() {
return AppConfigEntity.class;
}
}

138
src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigData.java

@ -0,0 +1,138 @@
package com.fr.plugin.third.party.jsdjjed.app.config;
import com.fanruan.api.query.QueryConditionKit;
import com.fanruan.api.query.RestrictionKit;
import com.fanruan.api.util.StringKit;
import com.fr.stable.db.action.DBAction;
import com.fr.stable.db.dao.DAOContext;
import com.fr.third.org.apache.commons.collections4.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class AppConfigData {
public static synchronized List<AppConfigEntity> queryAllAppConfigData() throws Exception {
List<AppConfigEntity> entities = AppConfigAccessBridge.getDbAccessor().runQueryAction(new DBAction<List<AppConfigEntity>>() {
@Override
public List<AppConfigEntity> run(DAOContext daoContext) throws Exception {
return daoContext.getDAO(AppConfigDao.class).find(QueryConditionKit.newQueryCondition());
}
});
if (CollectionUtils.isEmpty(entities)) {
return new ArrayList<>();
}
return entities;
}
public static synchronized AppConfigEntity queryAppConfigDataWithId(String id) throws Exception {
AppConfigEntity entity = AppConfigAccessBridge.getDbAccessor().runQueryAction(new DBAction<AppConfigEntity>() {
@Override
public AppConfigEntity run(DAOContext daoContext) throws Exception {
return daoContext.getDAO(AppConfigDao.class).getById(id);
}
});
return entity;
}
public static synchronized List<AppConfigEntity> queryAppConfigDataWithConfigId(String configId) throws Exception {
List<AppConfigEntity> entities = AppConfigAccessBridge.getDbAccessor().runQueryAction(new DBAction<List<AppConfigEntity>>() {
@Override
public List<AppConfigEntity> run(DAOContext daoContext) throws Exception {
return daoContext.getDAO(AppConfigDao.class).find(QueryConditionKit.newQueryCondition().addRestriction(RestrictionKit.eq("configId", configId)));
}
});
return entities;
}
public static synchronized AppConfigEntity queryAppConfigDataWithLogin() throws Exception {
List<AppConfigEntity> entities = queryAppConfigDatasWithLogin();
if (CollectionUtils.isEmpty(entities)) {
return null;
}
return entities.get(0);
}
public static synchronized List<AppConfigEntity> queryAppConfigDatasWithLogin() throws Exception {
List<AppConfigEntity> entities = AppConfigAccessBridge.getDbAccessor().runQueryAction(new DBAction<List<AppConfigEntity>>() {
@Override
public List<AppConfigEntity> run(DAOContext daoContext) throws Exception {
return daoContext.getDAO(AppConfigDao.class).find(QueryConditionKit.newQueryCondition().addRestriction(RestrictionKit.eq("login", 1)));
}
});
return entities;
}
public static AppConfigEntity queryAppConfigDataWithConfigIdAndOnlyOne(String id) throws Exception {
List<AppConfigEntity> entities = queryAppConfigDataWithConfigId(id);
if (CollectionUtils.isEmpty(entities)) {
return null;
}
AppConfigEntity entity = entities.get(0);
return entity;
}
public static boolean isAppConfigDataExistsWithConfigId(String configId) throws Exception {
return isAppConfigDataExistsWithConfigId(configId,"");
}
public static boolean isAppConfigDataExistsWithConfigId(String configId, String id) throws Exception {
AppConfigEntity entity = queryAppConfigDataWithConfigIdAndOnlyOne(configId);
if (entity == null) {
return false;
}
if (StringKit.isNotEmpty(id) && StringKit.equals(id, entity.getId())) {
return false;
}
return true;
}
public static synchronized AppConfigEntity addAppConfigData(AppConfigEntity appConfigEntity) throws Exception {
AppConfigEntity resultEntity = AppConfigAccessBridge.getDbAccessor().runDMLAction(new DBAction<AppConfigEntity>() {
@Override
public AppConfigEntity run(DAOContext daoContext) throws Exception {
AppConfigEntity entity = appConfigEntity;
entity.setId(UUID.randomUUID().toString());
daoContext.getDAO(AppConfigDao.class).add(entity);
return entity;
}
});
return resultEntity;
}
public static synchronized void updateAppConfigData(AppConfigEntity appConfigEntity) throws Exception {
AppConfigAccessBridge.getDbAccessor().runDMLAction(new DBAction<Boolean>() {
@Override
public Boolean run(DAOContext daoContext) throws Exception {
daoContext.getDAO(AppConfigDao.class).update(appConfigEntity);
return true;
}
});
}
public static synchronized AppConfigEntity deleteAppConfigDataWithId(String id) throws Exception {
AppConfigEntity appConfigEntity = queryAppConfigDataWithId(id);
if (appConfigEntity == null) {
return null;
}
AppConfigEntity resultEntity = AppConfigAccessBridge.getDbAccessor().runDMLAction(new DBAction<AppConfigEntity>() {
@Override
public AppConfigEntity run(DAOContext daoContext) throws Exception {
daoContext.getDAO(AppConfigDao.class).remove(appConfigEntity.getId());
return appConfigEntity;
}
});
return resultEntity;
}
public static synchronized AppConfigEntity deleteAppConfigDataWithConfigId(String configId) throws Exception {
AppConfigEntity appConfigEntity = queryAppConfigDataWithConfigIdAndOnlyOne(configId);
if (appConfigEntity == null) {
return null;
}
return deleteAppConfigDataWithId(appConfigEntity.getId());
}
}

87
src/main/java/com/fr/plugin/third/party/jsdjjed/app/config/AppConfigEntity.java

@ -0,0 +1,87 @@
package com.fr.plugin.third.party.jsdjjed.app.config;
import com.fr.stable.AssistUtils;
import com.fr.stable.db.entity.BaseEntity;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
@Entity
@Table(name = "jsdjjed_feishu_config")
public class AppConfigEntity extends BaseEntity {
@Column(name = "config_id")
private String configId;
@Column(name = "notes")
private String notes;
@Column(name = "app_id")
private String appId;
@Column(name = "app_secret")
private String appSecret;
@Column(name = "login_map")
private String loginMap;
@Column(name = "login")
private int login;
public AppConfigEntity() {
}
public String getConfigId() {
return configId;
}
public void setConfigId(String configId) {
this.configId = configId;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAppSecret() {
return appSecret;
}
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
public int getLogin() {
return login;
}
public void setLogin(int login) {
this.login = login;
}
public String getLoginMap() {
return loginMap;
}
public void setLoginMap(String loginMap) {
this.loginMap = loginMap;
}
@Override
public String toString() {
return AssistUtils.toString(this);
}
}

498
src/main/java/com/fr/plugin/third/party/jsdjjed/config/AppDataConfig.java

@ -0,0 +1,498 @@
package com.fr.plugin.third.party.jsdjjed.config;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import java.util.HashMap;
import java.util.Map;
public class AppDataConfig extends DefaultConfiguration {
public String getNameSpace() {
return this.getClass().getName();
}
private static volatile AppDataConfig config = null;
public static AppDataConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(AppDataConfig.class);
}
return config;
}
private static volatile Map<String, String> URL_MAP = new HashMap<>();
public synchronized static void addMapUrl(String key, String url) {
URL_MAP.put(key, url);
}
public synchronized static String getMapUrl(String key) {
if (!URL_MAP.containsKey(key)) {
return "";
}
String url = URL_MAP.get(key);
URL_MAP.remove(key);
return url;
}
private Conf<String> frUrl = Holders.simple("");
private Conf<String> accessTokenUrl = Holders.simple("https://xxx/open-apis/auth/v3/app_access_token/internal");
private Conf<String> codeUserUrl = Holders.simple("https://xxx/open-apis/authen/v1/access_token");
private Conf<String> chatGroupsUrl = Holders.simple("https://xxx/open-apis/im/v1/chats");
private Conf<String> usersUrl = Holders.simple("https://xxx/open-apis/user/v1/batch_get_id");
private Conf<String> sendMessageUrl = Holders.simple("https://xxx/open-apis/im/v1/messages");
private Conf<String> sendBatchMessageUrl = Holders.simple("https://xxx/open-apis/message/v4/batch_send");
private Conf<String> uploadImageUrl = Holders.simple("https://xxx/open-apis/im/v1/images");
private Conf<String> uploadFileUrl = Holders.simple("https://xxx/open-apis/im/v1/files");
private Conf<String> authorizeUrl = Holders.simple("https://xxx/open-apis/authen/v1/index");
private Conf<Boolean> accessTokenUrlEscbOption = Holders.simple(true);
private Conf<Boolean> codeUserUrlEscbOption = Holders.simple(true);
private Conf<Boolean> chatGroupsUrlEscbOption = Holders.simple(true);
private Conf<Boolean> usersUrlEscbOption = Holders.simple(true);
private Conf<Boolean> sendMessageUrlEscbOption = Holders.simple(true);
private Conf<Boolean> sendBatchMessageUrlEscbOption = Holders.simple(true);
private Conf<Boolean> uploadImageUrlEscbOption = Holders.simple(false);
private Conf<Boolean> uploadFileUrlEscbOption = Holders.simple(false);
private Conf<Boolean> authorizeUrlEscbOption = Holders.simple(false);
private Conf<String> accessTokenUrlEscbCode = Holders.simple("xxx.app.app_access_token");
private Conf<String> codeUserUrlEscbCode = Holders.simple("xxx.app.get_user_accessToken");
private Conf<String> chatGroupsUrlEscbCode = Holders.simple("xxx.app.get_chat_v4_list");
private Conf<String> usersUrlEscbCode = Holders.simple("xxx.app.lark_batch_get_id");
private Conf<String> sendMessageUrlEscbCode = Holders.simple("xxx.app.feishu_send_message");
private Conf<String> sendBatchMessageUrlEscbCode = Holders.simple("xxx.app.feishu_batch_send");
private Conf<String> uploadImageUrlEscbCode = Holders.simple("");
private Conf<String> uploadFileUrlEscbCode = Holders.simple("");
private Conf<String> authorizeUrlEscbCode = Holders.simple("");
private Conf<String> accessTokenUrlEscbVersion = Holders.simple("1.0");
private Conf<String> codeUserUrlEscbVersion = Holders.simple("1.0");
private Conf<String> chatGroupsUrlEscbVersion = Holders.simple("1.0");
private Conf<String> usersUrlEscbVersion = Holders.simple("1.0");
private Conf<String> sendMessageUrlEscbVersion = Holders.simple("2.0");
private Conf<String> sendBatchMessageUrlEscbVersion = Holders.simple("1.0");
private Conf<String> uploadImageUrlEscbVersion = Holders.simple("");
private Conf<String> uploadFileUrlEscbVersion = Holders.simple("");
private Conf<String> authorizeUrlEscbVersion = Holders.simple("");
private Conf<String> escbUrl = Holders.simple("http://xxxxxx/ecsb/gw/cls/rf");
private Conf<String> escbAppCode = Holders.simple("xx");
private Conf<String> escbAppToken = Holders.simple("xxx");
private Conf<String> escbOrgCode = Holders.simple("xxx");
private Conf<String> escbSysCode = Holders.simple("xxx");
@Identifier(value = "loginTypeNameParameter", name = "登录类型参数名称", description = "", status = Status.HIDE)
private Conf<String> loginTypeNameParameter = Holders.simple("loginType");
@Identifier(value = "loginTypeValue", name = "登录类型值", description = "", status = Status.HIDE)
private Conf<String> loginTypeValue = Holders.simple("oauth");
public String getLoginTypeNameParameter() {
return loginTypeNameParameter.get();
}
public void setLoginTypeNameParameter(String loginTypeNameParameter) {
this.loginTypeNameParameter.set(loginTypeNameParameter);
}
public String getLoginTypeValue() {
return loginTypeValue.get();
}
public void setLoginTypeValue(String loginTypeValue) {
this.loginTypeValue.set(loginTypeValue);
}
public String getFrUrl() {
return frUrl.get();
}
public void setFrUrl(String frUrl) {
this.frUrl.set(frUrl);
}
public String getAccessTokenUrl() {
return accessTokenUrl.get();
}
public void setAccessTokenUrl(String accessTokenUrl) {
this.accessTokenUrl.set(accessTokenUrl);
}
public String getCodeUserUrl() {
return codeUserUrl.get();
}
public void setCodeUserUrl(String codeUserUrl) {
this.codeUserUrl.set(codeUserUrl);
}
public String getChatGroupsUrl() {
return chatGroupsUrl.get();
}
public void setChatGroupsUrl(String chatGroupsUrl) {
this.chatGroupsUrl.set(chatGroupsUrl);
}
public String getUsersUrl() {
return usersUrl.get();
}
public void setUsersUrl(String usersUrl) {
this.usersUrl.set(usersUrl);
}
public String getSendMessageUrl() {
return sendMessageUrl.get();
}
public void setSendMessageUrl(String sendMessageUrl) {
this.sendMessageUrl.set(sendMessageUrl);
}
public String getSendBatchMessageUrl() {
return sendBatchMessageUrl.get();
}
public void setSendBatchMessageUrl(String sendBatchMessageUrl) {
this.sendBatchMessageUrl.set(sendBatchMessageUrl);
}
public String getUploadImageUrl() {
return uploadImageUrl.get();
}
public void setUploadImageUrl(String uploadImageUrl) {
this.uploadImageUrl.set(uploadImageUrl);
}
public String getUploadFileUrl() {
return uploadFileUrl.get();
}
public void setUploadFileUrl(String uploadFileUrl) {
this.uploadFileUrl.set(uploadFileUrl);
}
public String getAuthorizeUrl() {
return authorizeUrl.get();
}
public void setAuthorizeUrl(String authorizeUrl) {
this.authorizeUrl.set(authorizeUrl);
}
public Boolean isAccessTokenUrlEscbOption() {
return accessTokenUrlEscbOption.get();
}
public void setAccessTokenUrlEscbOption(Boolean accessTokenUrlEscbOption) {
this.accessTokenUrlEscbOption.set(accessTokenUrlEscbOption);
}
public Boolean isCodeUserUrlEscbOption() {
return codeUserUrlEscbOption.get();
}
public void setCodeUserUrlEscbOption(Boolean codeUserUrlEscbOption) {
this.codeUserUrlEscbOption.set(codeUserUrlEscbOption);
}
public Boolean isChatGroupsUrlEscbOption() {
return chatGroupsUrlEscbOption.get();
}
public void setChatGroupsUrlEscbOption(Boolean chatGroupsUrlEscbOption) {
this.chatGroupsUrlEscbOption.set(chatGroupsUrlEscbOption);
}
public Boolean isUsersUrlEscbOption() {
return usersUrlEscbOption.get();
}
public void setUsersUrlEscbOption(Boolean usersUrlEscbOption) {
this.usersUrlEscbOption.set(usersUrlEscbOption);
}
public Boolean isSendMessageUrlEscbOption() {
return sendMessageUrlEscbOption.get();
}
public void setSendMessageUrlEscbOption(Boolean sendMessageUrlEscbOption) {
this.sendMessageUrlEscbOption.set(sendMessageUrlEscbOption);
}
public Boolean isSendBatchMessageUrlEscbOption() {
return sendBatchMessageUrlEscbOption.get();
}
public void setSendBatchMessageUrlEscbOption(Boolean sendBatchMessageUrlEscbOption) {
this.sendBatchMessageUrlEscbOption.set(sendBatchMessageUrlEscbOption);
}
public Boolean isUploadImageUrlEscbOption() {
return uploadImageUrlEscbOption.get();
}
public void setUploadImageUrlEscbOption(Boolean uploadImageUrlEscbOption) {
this.uploadImageUrlEscbOption.set(uploadImageUrlEscbOption);
}
public Boolean isUploadFileUrlEscbOption() {
return uploadFileUrlEscbOption.get();
}
public void setUploadFileUrlEscbOption(Boolean uploadFileUrlEscbOption) {
this.uploadFileUrlEscbOption.set(uploadFileUrlEscbOption);
}
public Boolean isAuthorizeUrlEscbOption() {
return authorizeUrlEscbOption.get();
}
public void setAuthorizeUrlEscbOption(Boolean authorizeUrlEscbOption) {
this.authorizeUrlEscbOption.set(authorizeUrlEscbOption);
}
public String getAccessTokenUrlEscbCode() {
return accessTokenUrlEscbCode.get();
}
public void setAccessTokenUrlEscbCode(String accessTokenUrlEscbCode) {
this.accessTokenUrlEscbCode.set(accessTokenUrlEscbCode);
}
public String getCodeUserUrlEscbCode() {
return codeUserUrlEscbCode.get();
}
public void setCodeUserUrlEscbCode(String codeUserUrlEscbCode) {
this.codeUserUrlEscbCode.set(codeUserUrlEscbCode);
}
public String getChatGroupsUrlEscbCode() {
return chatGroupsUrlEscbCode.get();
}
public void setChatGroupsUrlEscbCode(String chatGroupsUrlEscbCode) {
this.chatGroupsUrlEscbCode.set(chatGroupsUrlEscbCode);
}
public String getUsersUrlEscbCode() {
return usersUrlEscbCode.get();
}
public void setUsersUrlEscbCode(String usersUrlEscbCode) {
this.usersUrlEscbCode.set(usersUrlEscbCode);
}
public String getSendMessageUrlEscbCode() {
return sendMessageUrlEscbCode.get();
}
public void setSendMessageUrlEscbCode(String sendMessageUrlEscbCode) {
this.sendMessageUrlEscbCode.set(sendMessageUrlEscbCode);
}
public String getSendBatchMessageUrlEscbCode() {
return sendBatchMessageUrlEscbCode.get();
}
public void setSendBatchMessageUrlEscbCode(String sendBatchMessageUrlEscbCode) {
this.sendBatchMessageUrlEscbCode.set(sendBatchMessageUrlEscbCode);
}
public String getUploadImageUrlEscbCode() {
return uploadImageUrlEscbCode.get();
}
public void setUploadImageUrlEscbCode(String uploadImageUrlEscbCode) {
this.uploadImageUrlEscbCode.set(uploadImageUrlEscbCode);
}
public String getUploadFileUrlEscbCode() {
return uploadFileUrlEscbCode.get();
}
public void setUploadFileUrlEscbCode(String uploadFileUrlEscbCode) {
this.uploadFileUrlEscbCode.set(uploadFileUrlEscbCode);
}
public String getAuthorizeUrlEscbCode() {
return authorizeUrlEscbCode.get();
}
public void setAuthorizeUrlEscbCode(String authorizeUrlEscbCode) {
this.authorizeUrlEscbCode.set(authorizeUrlEscbCode);
}
public String getAccessTokenUrlEscbVersion() {
return accessTokenUrlEscbVersion.get();
}
public void setAccessTokenUrlEscbVersion(String accessTokenUrlEscbVersion) {
this.accessTokenUrlEscbVersion.set(accessTokenUrlEscbVersion);
}
public String getCodeUserUrlEscbVersion() {
return codeUserUrlEscbVersion.get();
}
public void setCodeUserUrlEscbVersion(String codeUserUrlEscbVersion) {
this.codeUserUrlEscbVersion.set(codeUserUrlEscbVersion);
}
public String getChatGroupsUrlEscbVersion() {
return chatGroupsUrlEscbVersion.get();
}
public void setChatGroupsUrlEscbVersion(String chatGroupsUrlEscbVersion) {
this.chatGroupsUrlEscbVersion.set(chatGroupsUrlEscbVersion);
}
public String getUsersUrlEscbVersion() {
return usersUrlEscbVersion.get();
}
public void setUsersUrlEscbVersion(String usersUrlEscbVersion) {
this.usersUrlEscbVersion.set(usersUrlEscbVersion);
}
public String getSendMessageUrlEscbVersion() {
return sendMessageUrlEscbVersion.get();
}
public void setSendMessageUrlEscbVersion(String sendMessageUrlEscbVersion) {
this.sendMessageUrlEscbVersion.set(sendMessageUrlEscbVersion);
}
public String getSendBatchMessageUrlEscbVersion() {
return sendBatchMessageUrlEscbVersion.get();
}
public void setSendBatchMessageUrlEscbVersion(String sendBatchMessageUrlEscbVersion) {
this.sendBatchMessageUrlEscbVersion.set(sendBatchMessageUrlEscbVersion);
}
public String getUploadImageUrlEscbVersion() {
return uploadImageUrlEscbVersion.get();
}
public void setUploadImageUrlEscbVersion(String uploadImageUrlEscbVersion) {
this.uploadImageUrlEscbVersion.set(uploadImageUrlEscbVersion);
}
public String getUploadFileUrlEscbVersion() {
return uploadFileUrlEscbVersion.get();
}
public void setUploadFileUrlEscbVersion(String uploadFileUrlEscbVersion) {
this.uploadFileUrlEscbVersion.set(uploadFileUrlEscbVersion);
}
public String getAuthorizeUrlEscbVersion() {
return authorizeUrlEscbVersion.get();
}
public void setAuthorizeUrlEscbVersion(String authorizeUrlEscbVersion) {
this.authorizeUrlEscbVersion.set(authorizeUrlEscbVersion);
}
public String getEscbUrl() {
return escbUrl.get();
}
public void setEscbUrl(String escbUrl) {
this.escbUrl.set(escbUrl);
}
public String getEscbAppCode() {
return escbAppCode.get();
}
public void setEscbAppCode(String escbAppCode) {
this.escbAppCode.set(escbAppCode);
}
public String getEscbAppToken() {
return escbAppToken.get();
}
public void setEscbAppToken(String escbAppToken) {
this.escbAppToken.set(escbAppToken);
}
public String getEscbOrgCode() {
return escbOrgCode.get();
}
public void setEscbOrgCode(String escbOrgCode) {
this.escbOrgCode.set(escbOrgCode);
}
public String getEscbSysCode() {
return escbSysCode.get();
}
public void setEscbSysCode(String escbSysCode) {
this.escbSysCode.set(escbSysCode);
}
@Override
public Object clone() throws CloneNotSupportedException {
AppDataConfig cloned = (AppDataConfig) super.clone();
cloned.loginTypeNameParameter = (Conf<String>) loginTypeNameParameter.clone();
cloned.loginTypeValue = (Conf<String>) loginTypeValue.clone();
cloned.accessTokenUrl = (Conf<String>) accessTokenUrl.clone();
cloned.frUrl = (Conf<String>) frUrl.clone();
cloned.codeUserUrl = (Conf<String>) codeUserUrl.clone();
cloned.chatGroupsUrl = (Conf<String>) chatGroupsUrl.clone();
cloned.sendMessageUrl = (Conf<String>) sendMessageUrl.clone();
cloned.uploadImageUrl = (Conf<String>) uploadImageUrl.clone();
cloned.uploadFileUrl = (Conf<String>) uploadFileUrl.clone();
cloned.usersUrl = (Conf<String>) usersUrl.clone();
cloned.sendBatchMessageUrl = (Conf<String>) sendBatchMessageUrl.clone();
cloned.authorizeUrl = (Conf<String>) authorizeUrl.clone();
cloned.accessTokenUrlEscbOption = (Conf<Boolean>) accessTokenUrlEscbOption.clone();
cloned.codeUserUrlEscbOption = (Conf<Boolean>) codeUserUrlEscbOption.clone();
cloned.chatGroupsUrlEscbOption = (Conf<Boolean>) chatGroupsUrlEscbOption.clone();
cloned.usersUrlEscbOption = (Conf<Boolean>) usersUrlEscbOption.clone();
cloned.sendMessageUrlEscbOption = (Conf<Boolean>) sendMessageUrlEscbOption.clone();
cloned.sendBatchMessageUrlEscbOption = (Conf<Boolean>) sendBatchMessageUrlEscbOption.clone();
cloned.uploadImageUrlEscbOption = (Conf<Boolean>) uploadImageUrlEscbOption.clone();
cloned.uploadFileUrlEscbOption = (Conf<Boolean>) uploadFileUrlEscbOption.clone();
cloned.authorizeUrlEscbOption = (Conf<Boolean>) authorizeUrlEscbOption.clone();
cloned.accessTokenUrlEscbCode = (Conf<String>) accessTokenUrlEscbCode.clone();
cloned.codeUserUrlEscbCode = (Conf<String>) codeUserUrlEscbCode.clone();
cloned.chatGroupsUrlEscbCode = (Conf<String>) chatGroupsUrlEscbCode.clone();
cloned.usersUrlEscbCode = (Conf<String>) usersUrlEscbCode.clone();
cloned.sendMessageUrlEscbCode = (Conf<String>) sendMessageUrlEscbCode.clone();
cloned.sendBatchMessageUrlEscbCode = (Conf<String>) sendBatchMessageUrlEscbCode.clone();
cloned.uploadImageUrlEscbCode = (Conf<String>) uploadImageUrlEscbCode.clone();
cloned.uploadFileUrlEscbCode = (Conf<String>) uploadFileUrlEscbCode.clone();
cloned.authorizeUrlEscbCode = (Conf<String>) authorizeUrlEscbCode.clone();
cloned.accessTokenUrlEscbVersion = (Conf<String>) accessTokenUrlEscbVersion.clone();
cloned.codeUserUrlEscbVersion = (Conf<String>) codeUserUrlEscbVersion.clone();
cloned.chatGroupsUrlEscbVersion = (Conf<String>) chatGroupsUrlEscbVersion.clone();
cloned.usersUrlEscbVersion = (Conf<String>) usersUrlEscbVersion.clone();
cloned.sendMessageUrlEscbVersion = (Conf<String>) sendMessageUrlEscbVersion.clone();
cloned.sendBatchMessageUrlEscbVersion = (Conf<String>) sendBatchMessageUrlEscbVersion.clone();
cloned.uploadImageUrlEscbVersion = (Conf<String>) uploadImageUrlEscbVersion.clone();
cloned.uploadFileUrlEscbVersion = (Conf<String>) uploadFileUrlEscbVersion.clone();
cloned.authorizeUrlEscbVersion = (Conf<String>) authorizeUrlEscbVersion.clone();
cloned.escbUrl = (Conf<String>) escbUrl.clone();
cloned.escbAppCode = (Conf<String>) escbAppCode.clone();
cloned.escbAppToken = (Conf<String>) escbAppToken.clone();
cloned.escbOrgCode = (Conf<String>) escbOrgCode.clone();
cloned.escbSysCode = (Conf<String>) escbSysCode.clone();
return cloned;
}
}

687
src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuApp.java

@ -0,0 +1,687 @@
package com.fr.plugin.third.party.jsdjjed.feishu;
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.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.third.org.apache.commons.collections4.CollectionUtils;
import com.fr.third.org.apache.commons.lang3.time.DateFormatUtils;
import com.fr.third.org.apache.http.entity.ContentType;
import com.fr.third.org.apache.http.entity.mime.HttpMultipartMode;
import com.fr.third.org.apache.http.entity.mime.MultipartEntityBuilder;
import com.fr.third.org.apache.http.entity.mime.content.FileBody;
import com.fr.third.org.apache.http.entity.mime.content.InputStreamBody;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.*;
public class FeishuApp {
/**
* 获取消息类型
*
* @param type
* @return
*/
public static String getMsgType(String type) {
if ("post".equalsIgnoreCase(type)) {
return "post";
}
return "text";
}
public static String getMsgTypeNotes(String type) {
if ("post".equalsIgnoreCase(type)) {
return "富文本";
}
return "文本";
}
/**
* 获取发送类型
*
* @param type
* @return
*/
public static String getSendType(String type) {
if ("file".equalsIgnoreCase(type)) {
return "file";
}
if ("message_file".equalsIgnoreCase(type)) {
return "message_file";
}
return "message";
}
public static String getSendTypeNotes(String type) {
if ("file".equalsIgnoreCase(type)) {
return "文件";
}
if ("message_file".equalsIgnoreCase(type)) {
return "消息与文件";
}
return "消息";
}
public static boolean isSendMessage(String type) {
if ("message".equalsIgnoreCase(type)) {
return true;
}
if ("message_file".equalsIgnoreCase(type)) {
return true;
}
return false;
}
public static boolean isSendFile(String type) {
if ("file".equalsIgnoreCase(type)) {
return true;
}
if ("message_file".equalsIgnoreCase(type)) {
return true;
}
return false;
}
/**
* 获取 app_access_token企业自建应用
*
* @param appId
* @param appSecret
* @return
*/
public synchronized static String createAppAccessToken(String appId, String appSecret) throws IOException {
if (StringKit.isEmpty(appId) || StringKit.isEmpty(appSecret)) {
return "";
}
JSONObject bodyJson = new JSONObject();
bodyJson.put("app_id", appId);
bodyJson.put("app_secret", appSecret);
String url = "https://open.feishu.cn/open-apis/auth/v3/app_access_token/internal";
String configUrl = AppDataConfig.getInstance().getAccessTokenUrl();
url = getRealValue(url, configUrl);
url = getEscbUrl("accessTokenUrl", url);
String content = Utils.createHttpPostContentWithHttpClient(url, bodyJson.toString(), "application/json; charset=utf-8");
if (StringKit.isEmpty(content)) {
return "";
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return "";
}
String token = contentJson.getString("app_access_token");
return token;
}
/**
* 获取登录用户身份
*
* @param codeValue
* @param accessToken
* @return
* @throws IOException
*/
public synchronized static FeishuLoginUserBean getLoginUserInfo(String codeValue, String accessToken) throws IOException {
if (StringKit.isEmpty(codeValue) || StringKit.isEmpty(accessToken)) {
return null;
}
JSONObject bodyJson = new JSONObject();
bodyJson.put("grant_type", "authorization_code");
bodyJson.put("code", codeValue);
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/authen/v1/access_token";
String configUrl = AppDataConfig.getInstance().getCodeUserUrl();
url = getRealValue(url, configUrl);
String content = Utils.createHttpPostContentWithHttpClient(url, bodyJson.toString(), authorizationValue, "application/json; charset=utf-8");
if (StringKit.isEmpty(content)) {
return null;
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return null;
}
JSONObject dataJson = contentJson.getJSONObject("data");
FeishuLoginUserBean userBean = new FeishuLoginUserBean();
userBean.setUserId(dataJson.getString("user_id", ""));
userBean.setName(dataJson.getString("name", ""));
userBean.setEnName(dataJson.getString("en_name", ""));
userBean.setMobile(dataJson.getString("mobile", ""));
return userBean;
}
/**
* 获取用户或机器人所在的群列表
*
* @param accessToken
* @return
* @throws IOException
*/
public synchronized static List<FeishuChatGroupBean> getChatGroups(String accessToken) throws IOException {
List<FeishuChatGroupBean> chatGroups = new ArrayList<>();
if (StringKit.isEmpty(accessToken)) {
return chatGroups;
}
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/im/v1/chats";
String configUrl = AppDataConfig.getInstance().getChatGroupsUrl();
url = getRealValue(url, configUrl) + "?page_size=100";
url = getEscbUrl("chatGroupsUrl", url) + "&page_size=100";
String content = Utils.createHttpGetContentWithHttpClient(url, authorizationValue, "application/json; charset=utf-8");
if (StringKit.isEmpty(content)) {
return chatGroups;
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return chatGroups;
}
JSONObject dataJson = contentJson.getJSONObject("data");
if (!contentJson.containsKey("data")) {
return chatGroups;
}
if (dataJson == null) {
return chatGroups;
}
if ((!dataJson.containsKey("items")) && (!dataJson.containsKey("groups"))) {
return chatGroups;
}
JSONArray itemJsons = null;
if (dataJson.containsKey("items")) {
itemJsons = dataJson.getJSONArray("items");
}
if (dataJson.containsKey("groups")) {
itemJsons = dataJson.getJSONArray("groups");
}
if ((dataJson == null) || (itemJsons.size() <= 0)) {
return chatGroups;
}
JSONObject itemJson;
FeishuChatGroupBean chatGroupBean;
for (int i = 0, max = itemJsons.size() - 1; i <= max; i++) {
itemJson = itemJsons.getJSONObject(i);
chatGroupBean = new FeishuChatGroupBean();
chatGroupBean.setChatId(itemJson.getString("chat_id", ""));
chatGroupBean.setName(itemJson.getString("name", ""));
chatGroupBean.setDescription(itemJson.getString("description", ""));
chatGroupBean.setTenantKey(itemJson.getString("tenant_key", ""));
chatGroups.add(chatGroupBean);
}
return chatGroups;
}
/**
* 使用手机号或邮箱获取用户 ID
*
* @param emailSet
* @param mobileSet
* @param accessToken
* @return
* @throws IOException
*/
public synchronized static List<String> getFeishuUserId(Set<String> emailSet, Set<String> mobileSet, String accessToken) throws IOException {
List<String> feishuUserIds = new ArrayList<>();
if (StringKit.isEmpty(accessToken)) {
return feishuUserIds;
}
if (CollectionUtils.isEmpty(emailSet) && CollectionUtils.isEmpty(mobileSet)) {
return feishuUserIds;
}
String emailsContent = getUrlParams("emails", emailSet);
String mobilesContent = getUrlParams("mobiles", mobileSet);
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/user/v1/batch_get_id";
String configUrl = AppDataConfig.getInstance().getUsersUrl();
url = getRealValue(url, configUrl);
url = getEscbUrl("usersUrl", url);
int flag = 0;
if (StringKit.isNotEmpty(emailsContent)) {
if (url.indexOf("?") > 0) {
url = url + "&" + emailsContent;
} else {
url = url + "?" + emailsContent;
}
flag++;
}
if (StringKit.isNotEmpty(mobilesContent)) {
if (url.indexOf("?") > 0) {
url = url + "&" + mobilesContent;
} else {
url = url + "?" + mobilesContent;
}
flag++;
}
if (flag == 0) {
return feishuUserIds;
}
String content = Utils.createHttpGetContentWithHttpClient(url, authorizationValue, "application/json; charset=utf-8");
if (StringKit.isEmpty(content)) {
return feishuUserIds;
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return feishuUserIds;
}
JSONObject dataJson = contentJson.getJSONObject("data");
if (dataJson == null) {
return feishuUserIds;
}
Set<String> userIdSet = new HashSet<>();
if (dataJson.containsKey("email_users")) {
JSONObject emailUsersJson = dataJson.getJSONObject("email_users");
userIdSet.addAll(getUserIdsByJson(emailUsersJson));
}
if (dataJson.containsKey("mobile_users")) {
JSONObject mobileUsersJson = dataJson.getJSONObject("mobile_users");
userIdSet.addAll(getUserIdsByJson(mobileUsersJson));
}
feishuUserIds.addAll(userIdSet);
return feishuUserIds;
}
/**
* 上传图片
*
* @param imageInputStream
* @param accessToken
* @return
* @throws IOException
*/
public synchronized static JSONObject uploadImage(InputStream imageInputStream, String accessToken) throws IOException {
JSONObject fileJson = new JSONObject();
if (StringKit.isEmpty(accessToken) || (imageInputStream == null)) {
return fileJson;
}
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/open-apis/im/v1/images";
String configUrl = AppDataConfig.getInstance().getUploadImageUrl();
url = getRealValue(url, configUrl);
url = getEscbUrl("uploadImageUrl", url);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.addTextBody("image_type", "message");
multipartEntityBuilder.addPart("image", new InputStreamBody(imageInputStream, "image.png"));
String content = Utils.createHttpPostContentWithHttpClient(url, multipartEntityBuilder, authorizationValue, "");
if (StringKit.isEmpty(content)) {
return fileJson;
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return fileJson;
}
JSONObject dataJson = contentJson.getJSONObject("data");
if (dataJson == null) {
return fileJson;
}
return dataJson;
}
/**
* 上传文件
*
* @param fileType
* @param fileName
* @param fileInputStream
* @param accessToken
* @return
* @throws IOException
*/
public synchronized static JSONObject uploadFile(String fileType, String fileName, InputStream fileInputStream, String accessToken) throws IOException {
JSONObject fileJson = new JSONObject();
if (StringKit.isEmpty(accessToken) || StringKit.isEmpty(fileName) || (fileInputStream == null)) {
return fileJson;
}
String fileTypeValue = StringKit.trim(fileType);
if (StringKit.isEmpty(fileTypeValue)) {
fileTypeValue = "stream";
} else {
fileTypeValue = fileTypeValue.toLowerCase();
String[] defaultFileTypes = {"opus", "mp4", "pdf", "doc", "xls", "ppt", "stream"};
int flag = 0;
for (int i = 0, max = defaultFileTypes.length - 1; i <= max; i++) {
if (StringKit.equals(fileTypeValue, defaultFileTypes[i])) {
flag++;
break;
}
}
if (flag == 0) {
fileTypeValue = "stream";
}
}
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/open-apis/im/v1/files";
String configUrl = AppDataConfig.getInstance().getUploadFileUrl();
url = getRealValue(url, configUrl);
url = getEscbUrl("uploadFileUrl", url);
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.addTextBody("file_type", fileTypeValue,ContentType.create("text/plain",Charset.forName("UTF-8")));
multipartEntityBuilder.addTextBody("file_name", fileName,ContentType.create("text/plain",Charset.forName("UTF-8")));
multipartEntityBuilder.addBinaryBody("file", fileInputStream);
String content = Utils.createHttpPostContentWithHttpClient(url, multipartEntityBuilder, authorizationValue, "");
if (StringKit.isEmpty(content)) {
return fileJson;
}
JSONObject contentJson = new JSONObject(content);
int code = contentJson.getInt("code");
if (code != 0) {
return fileJson;
}
JSONObject dataJson = contentJson.getJSONObject("data");
if (dataJson == null) {
return fileJson;
}
return dataJson;
}
public static boolean isValidFileJson(JSONObject fileJson) {
if (fileJson == null) {
return false;
}
if (fileJson.containsKey("file_key")) {
return true;
}
return false;
}
public static boolean isValidImageJson(JSONObject fileJson) {
if (fileJson == null) {
return false;
}
if (fileJson.containsKey("image_key")) {
return true;
}
return false;
}
/**
* 发送消息
*
* @param receiveIdType
* @param receiveId
* @param msgContent
* @param msgType
* @param accessToken
* @throws IOException
*/
public synchronized static void sendMessage(String receiveIdType, String receiveId, String msgContent, String msgType, String accessToken) throws IOException {
if (StringKit.isEmpty(receiveIdType) || StringKit.isEmpty(receiveId) || StringKit.isEmpty(msgContent) || StringKit.isEmpty(msgType) || StringKit.isEmpty(accessToken)) {
return;
}
JSONObject bodyJson = new JSONObject();
//bodyJson.put("receive_id_type", receiveIdType);
bodyJson.put("receive_id", receiveId);
bodyJson.put("content", msgContent);
bodyJson.put("msg_type", msgType);
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/im/v1/messages";
String configUrl = AppDataConfig.getInstance().getSendMessageUrl();
url = getRealValue(url, configUrl) + "?receive_id_type=" + receiveIdType;
url = getEscbUrl("sendMessageUrl", url) + "&receive_id_type=" + receiveIdType;
String content = Utils.createHttpPostContentWithHttpClient(url, bodyJson.toString(), authorizationValue, "application/json; charset=utf-8");
}
/**
* 发送文本消息
*
* @param receiveIdType
* @param receiveId
* @param textContent
* @param accessToken
* @throws IOException
*/
public static void sendMessageWithText(String receiveIdType, String receiveId, String textContent, String accessToken) throws IOException {
JSONObject textJson = new JSONObject();
textJson.put("text", textContent);
sendMessage(receiveIdType, receiveId, textJson.toString(), "text", accessToken);
}
/**
* 发送群文本消息
*
* @param chatId
* @param textContent
* @param accessToken
* @throws IOException
*/
public static void sendGroupMessageWithText(String chatId, String textContent, String accessToken) throws IOException {
sendMessageWithText("chat_id", chatId, textContent, accessToken);
}
public static void sendMessageWithImage(String receiveIdType, String receiveId, String imageContent, String accessToken) throws IOException {
sendMessage(receiveIdType, receiveId, imageContent, "image", accessToken);
}
public static void sendGroupMessageWithImage(String chatId, String imageContent, String accessToken) throws IOException {
sendMessageWithImage("chat_id", chatId, imageContent, accessToken);
}
public static void sendMessageWithFile(String receiveIdType, String receiveId, String fileContent, String accessToken) throws IOException {
sendMessage(receiveIdType, receiveId, fileContent, "file", accessToken);
}
public static void sendMessageWithFileByUserId(String receiveId, String fileContent, String accessToken) throws IOException {
sendMessage("user_id", receiveId, fileContent, "file", accessToken);
}
public static void sendGroupMessageWithFile(String chatId, String fileContent, String accessToken) throws IOException {
sendMessageWithFile("chat_id", chatId, fileContent, accessToken);
}
public synchronized static void sendBatchMessage(List<String> userIds, String msgContent, String msgType, String accessToken) throws IOException {
if (CollectionUtils.isEmpty(userIds) || StringKit.isEmpty(msgContent) || StringKit.isEmpty(msgType) || StringKit.isEmpty(accessToken)) {
return;
}
JSONArray userIdJsons = new JSONArray();
for (int i = 0, max = userIds.size() - 1; i <= max; i++) {
userIdJsons.add(userIds.get(i));
}
JSONObject bodyJson = new JSONObject();
bodyJson.put("content", new JSONObject(msgContent));
bodyJson.put("msg_type", msgType);
bodyJson.put("user_ids", userIdJsons);
String authorizationValue = "Bearer " + accessToken;
String url = "https://open.feishu.cn/open-apis/message/v4/batch_send";
String configUrl = AppDataConfig.getInstance().getSendBatchMessageUrl();
url = getRealValue(url, configUrl);
url = getEscbUrl("sendBatchMessageUrl", url);
String content = Utils.createHttpPostContentWithHttpClient(url, bodyJson.toString(), authorizationValue, "application/json; charset=utf-8");
}
private static String getEscbUrl(String type, String originalUrl) {
boolean escbOption = false;
String escbCode = "";
String escbVersion = "";
if ("accessTokenUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isAccessTokenUrlEscbOption();
escbCode = AppDataConfig.getInstance().getAccessTokenUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getAccessTokenUrlEscbVersion();
} else if ("codeUserUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isCodeUserUrlEscbOption();
escbCode = AppDataConfig.getInstance().getCodeUserUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getCodeUserUrlEscbVersion();
} else if ("chatGroupsUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isChatGroupsUrlEscbOption();
escbCode = AppDataConfig.getInstance().getChatGroupsUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getChatGroupsUrlEscbVersion();
} else if ("usersUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isUsersUrlEscbOption();
escbCode = AppDataConfig.getInstance().getUsersUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getUsersUrlEscbVersion();
} else if ("sendMessageUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isSendMessageUrlEscbOption();
escbCode = AppDataConfig.getInstance().getSendMessageUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getSendMessageUrlEscbVersion();
} else if ("sendBatchMessageUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isSendBatchMessageUrlEscbOption();
escbCode = AppDataConfig.getInstance().getSendBatchMessageUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getSendBatchMessageUrlEscbVersion();
} else if ("uploadImageUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isUploadImageUrlEscbOption();
escbCode = AppDataConfig.getInstance().getUploadImageUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getUploadImageUrlEscbVersion();
} else if ("uploadFileUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isUploadFileUrlEscbOption();
escbCode = AppDataConfig.getInstance().getUploadFileUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getUploadFileUrlEscbVersion();
} else if ("authorizeUrl".equals(type)) {
escbOption = AppDataConfig.getInstance().isAuthorizeUrlEscbOption();
escbCode = AppDataConfig.getInstance().getAuthorizeUrlEscbCode();
escbVersion = AppDataConfig.getInstance().getAuthorizeUrlEscbVersion();
} else {
return originalUrl;
}
if ((!escbOption) || StringKit.isEmpty(escbCode)) {
return originalUrl;
}
if (StringKit.isEmpty(escbVersion)) {
escbVersion = "1.0";
}
String ssdpValue = "Api_ID=" + escbCode
+ "&Api_Version=" + escbVersion
+ "&App_Sub_ID=" + AppDataConfig.getInstance().getEscbAppCode()
+ "&App_Token=" + AppDataConfig.getInstance().getEscbAppToken()
+ "&Partner_ID=" + AppDataConfig.getInstance().getEscbOrgCode()
+ "&Sign=NO_SIGN"
+ "&Sys_ID=" + AppDataConfig.getInstance().getEscbSysCode()
+ "&Time_Stamp=" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss:SSS")
+ "&User_Token=";
LogKit.info("飞书集成," + type + ",ssdp:" + ssdpValue);
Base64.Encoder encoder = Base64.getEncoder();
String url = AppDataConfig.getInstance().getEscbUrl() + "?ssdp=" + new String(encoder.encode(ssdpValue.getBytes()));
LogKit.info("飞书集成,ssdp url:" + url);
return url;
}
public static void sendBatchMessageWithText(List<String> userIds, String textContent, String accessToken) throws IOException {
JSONObject textJson = new JSONObject();
textJson.put("text", textContent);
sendBatchMessage(userIds, textJson.toString(), "text", accessToken);
}
public static void sendBatchMessageWithRichText(List<String> userIds, String textContent, String accessToken) throws IOException {
JSONObject textJson = new JSONObject();
textJson.put("post", new JSONObject(textContent));
sendBatchMessage(userIds, textJson.toString(), "post", accessToken);
}
public static void sendBatchMessageWithImage(List<String> userIds, String imageContent, String accessToken) throws IOException {
sendBatchMessage(userIds, imageContent, "image", accessToken);
}
public static void sendBatchMessageWithFile(List<String> userIds, String fileContent, String accessToken) throws IOException {
//sendBatchMessage(userIds, fileContent, "file", accessToken);
//批量发送不支持发送文件
if (CollectionUtils.isEmpty(userIds)) {
return;
}
for (int i = 0, max = userIds.size() - 1; i <= max; i++) {
sendMessageWithFileByUserId(userIds.get(i), fileContent, accessToken);
}
}
private static List<String> getUserIdsByJson(JSONObject dataJson) {
List<String> userIds = new ArrayList<>();
if (dataJson == null) {
return userIds;
}
Set<String> fieldNames = dataJson.fieldNames();
if (CollectionUtils.isEmpty(fieldNames)) {
return userIds;
}
JSONArray tempJsons;
JSONObject tempJson;
for (String fieldName : fieldNames) {
tempJsons = dataJson.getJSONArray(fieldName);
if ((tempJsons == null) || (tempJsons.size() <= 0)) {
continue;
}
for (int i = 0, max = tempJsons.size() - 1; i <= max; i++) {
tempJson = tempJsons.getJSONObject(i);
userIds.add(tempJson.getString("user_id"));
}
}
return userIds;
}
private static String getUrlParams(String paramName, Set<String> valueSet) {
if (StringKit.isEmpty(paramName) || CollectionUtils.isEmpty(valueSet)) {
return "";
}
List<String> values = new ArrayList<>();
values.addAll(valueSet);
String paramsContent = "";
String value;
int count = 0;
for (int i = 0, max = values.size() - 1; i <= max; i++) {
if (count >= 1) {
paramsContent = paramsContent + "&";
}
value = values.get(i);
if (StringKit.isEmpty(value)) {
continue;
}
paramsContent = paramsContent + paramName + "=" + value;
count++;
}
return paramsContent;
}
private static String getRealValue(String value, String value1) {
String tempValue = StringKit.trim(value1);
if (StringKit.isEmpty(tempValue)) {
return value;
}
return tempValue;
}
}

55
src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuChatGroupBean.java

@ -0,0 +1,55 @@
package com.fr.plugin.third.party.jsdjjed.feishu;
import java.io.Serializable;
public class FeishuChatGroupBean implements Serializable {
/**
* 群组 ID chat_id
*/
private String chatId;
/**
* 群名称
*/
private String name;
/**
* 群描述
*/
private String description;
/**
* tenant_key
*/
private String tenantKey;
public String getChatId() {
return chatId;
}
public void setChatId(String chatId) {
this.chatId = chatId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTenantKey() {
return tenantKey;
}
public void setTenantKey(String tenantKey) {
this.tenantKey = tenantKey;
}
}

63
src/main/java/com/fr/plugin/third/party/jsdjjed/feishu/FeishuLoginUserBean.java

@ -0,0 +1,63 @@
package com.fr.plugin.third.party.jsdjjed.feishu;
import com.fanruan.api.util.StringKit;
import java.io.Serializable;
public class FeishuLoginUserBean implements Serializable {
/**
* 用户 user_id
*/
private String userId;
/**
* 用户姓名
*/
private String name;
/**
* 用户英文名称
*/
private String enName;
/**
* 用户手机号
*/
private String mobile;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEnName() {
return enName;
}
public void setEnName(String enName) {
this.enName = enName;
}
public String getMobile() {
return mobile;
}
public void setMobile(String value) {
if (StringKit.isEmpty(value)) {
this.mobile = "";
}
if (value.startsWith("+86")) {
value = value.substring(3);
}
this.mobile = value;
}
}

29
src/main/java/com/fr/plugin/third/party/jsdjjed/handle/ImageOutputFormat.java

@ -0,0 +1,29 @@
package com.fr.plugin.third.party.jsdjjed.handle;
import com.fr.general.ReportDeclareRecordType;
import com.fr.io.exporter.ScaledImageExporter;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.schedule.extension.report.job.output.BaseOutputFormat;
import java.io.OutputStream;
public class ImageOutputFormat extends BaseOutputFormat {
public static final int FORMAT_IMAGE = 4096;
public int getFormat() {
return FORMAT_IMAGE;
}
public String getFileSuffix() {
return ".png";
}
public void flush(OutputStream outputStream, ResultWorkBook resultWorkBook) throws Exception {
ScaledImageExporter exporter = new ScaledImageExporter(ReportDeclareRecordType.EXPORT_TYPE_IMAGE_PNG.getTypeString(), 96);
exporter.export(outputStream, resultWorkBook);
}
}

23
src/main/java/com/fr/plugin/third/party/jsdjjed/http/CustomHttpHandlerProvider.java

@ -0,0 +1,23 @@
package com.fr.plugin.third.party.jsdjjed.http;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.plugin.third.party.jsdjjed.http.app.*;
public class CustomHttpHandlerProvider extends AbstractHttpHandlerProvider {
@Override
public BaseHttpHandler[] registerHandlers() {
return new BaseHttpHandler[]{
new AddAppHttpHandler(),
new DeleteAppHttpHandler(),
new EditAppHttpHandler(),
new QueryAppHttpHandler(),
new ForbidAppHttpHandler(),
new QueryAppConfigHttpHandler(),
new SaveAppConfigHttpHandler(),
new QueryChatGroupsHttpHandler(),
new SynchronizeSourceHttpHandler()
};
}
}

22
src/main/java/com/fr/plugin/third/party/jsdjjed/http/CustomURLAliasProvider.java

@ -0,0 +1,22 @@
package com.fr.plugin.third.party.jsdjjed.http;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class CustomURLAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/jsdjjed/add/app", "/jsdjjed/add/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/delete/app", "/jsdjjed/delete/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/edit/app", "/jsdjjed/edit/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/query/app", "/jsdjjed/query/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/forbid/app", "/jsdjjed/forbid/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/query/config/app", "/jsdjjed/query/config/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/save/config/app", "/jsdjjed/save/config/app", true),
URLAliasFactory.createPluginAlias("/jsdjjed/query/chat/group", "/jsdjjed/query/chat/group", true),
URLAliasFactory.createPluginAlias("/jsdjjed/synchronize/source", "/jsdjjed/synchronize/source", true),
};
}
}

566
src/main/java/com/fr/plugin/third/party/jsdjjed/http/SessionGlobalRequestFilterProvider.java

@ -0,0 +1,566 @@
package com.fr.plugin.third.party.jsdjjed.http;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.query.QueryConditionKit;
import com.fanruan.api.query.RestrictionKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.decision.webservice.v10.login.LoginService;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.general.ComparatorUtils;
import com.fr.plugin.context.PluginContexts;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.plugin.third.party.jsdjjed.feishu.FeishuApp;
import com.fr.plugin.third.party.jsdjjed.feishu.FeishuLoginUserBean;
import com.fr.stable.query.condition.QueryCondition;
import com.fr.web.utils.WebUtils;
import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
public class SessionGlobalRequestFilterProvider extends AbstractGlobalRequestFilterProvider {
private static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
@Override
public String filterName() {
return "ttt.com.fr.plugin.third.party.jsdjjed";
}
@Override
public String[] urlPatterns() {
return new String[]{"/decision", "/decision/*"};
}
@Override
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) {
try {
String fullUrl = Utils.getFullRequestUrl(req);
String method = req.getMethod();
LogKit.info("飞书登录集成,记录访问地址:" + method + " " + fullUrl);
if (!"GET".equalsIgnoreCase(method)) {
filterChain.doFilter(req, res);
return;
}
String reqUrl = Utils.getRequestUrl(req);
if (Utils.isDecisionLoginRequest(req)) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("/remote/") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("terminal=H5") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("__device__=") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("/weixin/") >= 0) {
filterChain.doFilter(req, res);
return;
}
if (reqUrl.indexOf("/dingtalk/") >= 0) {
filterChain.doFilter(req, res);
return;
}
String state;
if (isAllowLoginWithParameter(req)) {
reqUrl = getRequestUrl(req);
state = UUID.randomUUID().toString();
AppDataConfig.getInstance().addMapUrl(state, reqUrl);
String tempUrl = getFullAuthorizeUrl(state);
LogKit.info("飞书登录集成,请求认证地址:" + tempUrl);
sendRedirect(res, tempUrl);
return;
}
if (isAllowLoginWithLightApp(req)) {
reqUrl = getRequestUrl(req);
state = UUID.randomUUID().toString();
AppDataConfig.getInstance().addMapUrl(state, reqUrl);
LogKit.info("飞书登录集成,报表轻应用跳转");
AppConfigEntity appConfigEntity = AppConfigData.queryAppConfigDataWithLogin();
if (appConfigEntity == null) {
LogKit.info("飞书登录集成,报表轻应用跳转,没有获取到登录飞书凭证");
filterChain.doFilter(req, res);
return;
}
String loginContent = "<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
"<head>\n" +
" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>\n" +
" <title>数据决策系统</title>\n" +
" <script type=\"text/javascript\"\n" +
" src=\"/webroot/decision/file?path=/com/fr/plugin/third/party/jsdjjed/sdk/h5-js-sdk-1.5.12.js&type=plain&parser=plain\"></script>\n" +
" <script type=\"text/javascript\"\n" +
" src=\"/webroot/decision/file?path=/com/fr/plugin/third/party/jsdjjed/sdk/runworkhelp.js&type=plain&parser=plain\"></script>\n" +
" <script type=\"text/javascript\"\n" +
" src=\"/webroot/decision/file?path=/com/fr/plugin/third/party/jsdjjed/sdk/vconsole.min.js&type=plain&parser=plain\"></script>\n" +
"</head>\n" +
"<body>\n" +
"<h2>轻应用跳转中,请稍等...</h2>\n" +
//"<button onclick=\"test()\">测试</button>"+
"<script type=\"text/javascript\">\n" +
" var runWorkH5 = new window.runworkHelp.RunWorkH5({\n" +
" env: \"uat\",\n" +
" devUser: \"xm\",\n" +
" isLocal: false,\n" +
" appId: \"" + appConfigEntity.getAppId() + "\",\n" +
" appSecret: \"" + appConfigEntity.getAppSecret() + "\",\n" +
" isHrInfo: true,\n" +
" isCross: true\n" +
" });\n" +
" runWorkH5.initReady().then(() => {\n" +
" if (runWorkH5.user && runWorkH5.user.user_id) {\n" +
" var state = \"" + state + "\";\n" +
" window.location = \"/webroot/decision?login=feishu&light_app_id=\" + runWorkH5.user.user_id + \"&state=\" + state;\n" +
" }\n" +
"else {\n" +
"document.write('<h3>获取user_id出错,请联系管理员</h3>');\n" +
"}" +
" });\n" +
"function test(){ \n" +
"\n" +
" var vConsole = new window.VConsole();\n" +
" \n" +
" vConsole.show();\n" +
"console.log('Hello world');\n" +
" debugger;\n" +
" var runWorkH5 = new window.runworkHelp.RunWorkH5({\n" +
" env: \"uat\",\n" +
" devUser: \"xm\",\n" +
" isLocal: false,\n" +
" appId: \"" + appConfigEntity.getAppId() + "\",\n" +
" appSecret: \"" + appConfigEntity.getAppSecret() + "\",\n" +
" isHrInfo: true,\n" +
" isCross: true\n" +
" });\n" +
"\t\n" +
"vConsole.log(runWorkH5);\t\n" +
" runWorkH5.initReady().then(() => {\n" +
" debugger;\n" +
"vConsole.log(runWorkH5);\n" +
"if (runWorkH5.user && runWorkH5.user.user_id) {\n" +
"document.write('<h3>runWorkH5.user.user_id:'+runWorkH5.user.user_id+'</h3>');\n" +
"}\n" +
"\n" +
"if (runWorkH5.user && runWorkH5.user.name) {\n" +
"document.write('<h3>runWorkH5.user.name:'+runWorkH5.user.name+'</h3>');\n" +
"}\n" +
"\n" +
"if (runWorkH5.user && runWorkH5.user.en_name) {\n" +
"document.write('<h3>runWorkH5.user.en_name:'+runWorkH5.user.en_name+'</h3>');\n" +
"}\n" +
"\n" +
"if (runWorkH5.user && runWorkH5.user.open_id) {\n" +
"document.write('<h3>runWorkH5.user.open_id:'+runWorkH5.user.open_id+'</h3>');\n" +
"} });\n" +
"\n" +
"}" +
"</script>\n" +
"</body>\n" +
"</html>\n";
res.setContentType("text/html;charset=UTF-8");
WebUtils.printAsString(res, loginContent);
res.setStatus(200);
return;
}
String loginUsername = getOauthLoginUsername(req);
if (StringKit.isEmpty(loginUsername)) {
filterChain.doFilter(req, res);
return;
}
LogKit.info("飞书登录集成,用户名:" + loginUsername);
User user = UserService.getInstance().getUserByUserName(loginUsername);
boolean tipsOption = false;
String tipsContent = "";
if (user == null) {
tipsOption = true;
LogKit.info("飞书登录集成,用户名:" + loginUsername + "在报表平台不存在");
tipsContent = "在报表服务器上不存在";
} else if (!user.isEnable()) {
tipsOption = true;
LogKit.info("飞书登录集成,用户名:" + loginUsername + "在报表平台上被禁用");
tipsContent = "在报表平台上被禁用";
}
//添加认证
if (!PluginContexts.currentContext().isAvailable()) {
tipsOption = true;
LogKit.error("飞书登录集成插件试用过期, 请购买许可证");
tipsContent = "飞书登录集成插件试用过期, 请购买许可证";
}
if (tipsOption) {
String jumpContent = "<!doctype html>\n" +
"<head>\n" +
" <meta charset=\"utf-8\" />\n" +
" <title>提示</title>\n" +
"\t\n" +
"<script type=\"text/javascript\">\n" +
"window.onload=function(){\n" +
" alert(\"用户:" + loginUsername + tipsContent + ",请联系管理员!\");\n" +
" window.location = \"" + AppDataConfig.getInstance().getFrUrl() + "\";\n" +
"}\n" +
"</script>\t\n" +
"</head>\n" +
"<body>\n" +
" <div style=\"width: 100%;height:200px; line-height: 200px;font-size:30px;vertical-align:middle;text-align:center\">\n" +
" <span id=\"show\"></span>\n" +
" </div>\n" +
"</body>\n" +
"</html>";
res.setContentType("text/html;charset=UTF-8");
WebUtils.printAsString(res, jumpContent);
res.setStatus(200);
return;
}
loginUsername = user.getUserName();
LogKit.info("飞书登录集成,报表平台用户名:" + loginUsername);
String loginToken = LoginService.getInstance().login(req, res, loginUsername);
req.setAttribute("fine_auth_token", loginToken);
String reqUrl1 = getRealUrl(req);
if (StringKit.isNotEmpty(reqUrl1) && (!StringKit.equals(reqUrl1, fullUrl))) {
sendRedirect(res, reqUrl1);
return;
}
filterChain.doFilter(req, res);
} catch (Exception e) {
LogKit.error("飞书登录集成出错," + e.getMessage(), e);
}
}
private String getRealUrl(HttpServletRequest req) {
if (req == null) {
return "";
}
String state = WebUtils.getHTTPRequestParameter(req, "state");
if (StringKit.isEmpty(state)) {
return "";
}
String url = AppDataConfig.getInstance().getMapUrl(state);
url = addLoginPara(url);
return url;
}
private String addLoginPara(String url) {
if (StringKit.isEmpty(url)) {
return "";
}
if ((url.indexOf("&login=feishu") >= 0) || (url.indexOf("?login=feishu") >= 0)) {
return url;
}
if (url.indexOf("?") >= 0) {
url = url + "&login=feishu";
return url;
}
url = url + "?login=feishu";
return url;
}
private String getFullAuthorizeUrl(String state) throws Exception {
AppConfigEntity configEntity = AppConfigData.queryAppConfigDataWithLogin();
if (configEntity == null) {
LogKit.error("飞书登录集成,没有登录验证的应用凭证信息0");
return "";
}
AppDataConfig config = AppDataConfig.getInstance();
String tempUrl = config.getFrUrl();
String url = config.getAuthorizeUrl() + "?app_id=" + configEntity.getAppId() + "&redirect_uri=" + tempUrl + "&state=" + state;
LogKit.info("飞书登录集成,请求用户授权地址:" + url);
return url;
}
private String getOauthLoginUsername(HttpServletRequest req) throws Exception {
if (req == null) {
return "";
}
String lightAppId = StringKit.trim(WebUtils.getHTTPRequestParameter(req, "light_app_id"));
if (StringKit.isNotEmpty(lightAppId)) {
lightAppId = lightAppId.toUpperCase();
return lightAppId;
}
String oAuthCode = WebUtils.getHTTPRequestParameter(req, "code");
if (StringKit.isEmpty(oAuthCode)) {
return "";
}
LogKit.info("飞书登录集成,OAuth Code:" + oAuthCode);
AppConfigEntity configEntity = AppConfigData.queryAppConfigDataWithLogin();
if (configEntity == null) {
LogKit.error("飞书登录集成,没有登录验证的应用凭证信息1");
return "";
}
String accessToken = FeishuApp.createAppAccessToken(configEntity.getAppId(), configEntity.getAppSecret());
if (StringKit.isEmpty(accessToken)) {
LogKit.error("飞书登录集成,获取app_access_token为空");
return "";
}
FeishuLoginUserBean loginUserBean = FeishuApp.getLoginUserInfo(oAuthCode, accessToken);
if (loginUserBean == null) {
LogKit.error("飞书登录集成,获取登录信息为空");
return "";
}
String loginMap = configEntity.getLoginMap();
QueryCondition queryCondition = getUserQueryCondition(loginMap, loginUserBean);
if (queryCondition == null) {
LogKit.error("飞书登录集成,用户信息没有有效的映射匹配");
return "";
}
List<User> perfectMatchUsers = AuthorityContext.getInstance().getUserController().find(queryCondition);
if ((perfectMatchUsers == null) || (perfectMatchUsers.size() <= 0)) {
LogKit.error("飞书登录集成,没有匹配到用户信息");
return "";
}
if (perfectMatchUsers.size() >= 2) {
LogKit.error("飞书登录集成,匹配到多个用户信息");
return "";
}
User user = perfectMatchUsers.get(0);
String username = user.getUserName();
return username;
}
private QueryCondition getUserQueryCondition(String loginMap, FeishuLoginUserBean loginUserBean) {
if (StringKit.isEmpty(loginMap)) {
loginMap = "name";
}
Set<String> usernameValues = new HashSet<>();
String[] loginNames = loginMap.split(",");
String loginName;
String mobile = "";
for (int i = 0, max = loginNames.length - 1; i <= max; i++) {
loginName = StringKit.trim(loginNames[i]);
if (StringKit.isEmpty(loginName)) {
continue;
}
if (StringKit.equalsIgnoreCase("name", loginName) && StringKit.isNotEmpty(loginUserBean.getName())) {
usernameValues.add(loginUserBean.getName());
} else if (StringKit.equalsIgnoreCase("en_name", loginName) && StringKit.isNotEmpty(loginUserBean.getEnName())) {
usernameValues.add(loginUserBean.getEnName());
} else if (StringKit.equalsIgnoreCase("user_id", loginName) && StringKit.isNotEmpty(loginUserBean.getUserId())) {
usernameValues.add(loginUserBean.getUserId());
usernameValues.add(loginUserBean.getUserId().toUpperCase());
} else if (StringKit.equalsIgnoreCase("mobile", loginName) && StringKit.isNotEmpty(loginUserBean.getMobile())) {
mobile = loginUserBean.getMobile();
}
}
int queryCount = 0;
QueryCondition queryCondition = QueryConditionKit.newQueryCondition();
if (usernameValues.size() >= 1) {
queryCount++;
queryCondition.addRestriction(RestrictionKit.in("userName", usernameValues));
}
if (StringKit.isNotEmpty(mobile)) {
queryCount++;
queryCondition.addRestriction(RestrictionKit.eq("mobile", mobile));
}
if (queryCount <= 0) {
return null;
}
return queryCondition;
}
public synchronized static String getSysTime() {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Date date = new Date();
String nowData = format.format(date);
return nowData;
}
private void sendRedirect(HttpServletResponse res, String url) {
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
private String getRequestUrl(HttpServletRequest req) {
String fullUrl = req.getRequestURL().toString();
fullUrl = getRealUrl(fullUrl);
Map<String, String[]> paraMap = req.getParameterMap();
String paraName;
String[] paraValues;
String loginTypeParaName = AppDataConfig.getInstance().getLoginTypeNameParameter();
String queryStr = "";
for (Map.Entry<String, String[]> entry : paraMap.entrySet()) {
paraName = entry.getKey();
if (ComparatorUtils.equals(paraName, loginTypeParaName)) {
continue;
}
if (ComparatorUtils.equals(paraName, "code")) {
continue;
}
if (ComparatorUtils.equals(paraName, "state")) {
continue;
}
if (ComparatorUtils.equals(paraName, "login_type")) {
continue;
}
if (ComparatorUtils.equals(paraName, "light_app")) {
continue;
}
paraValues = entry.getValue();
queryStr = addParaToQuery(queryStr, paraName, paraValues);
}
if (StringKit.isEmpty(queryStr)) {
return fullUrl;
}
fullUrl = fullUrl + "?" + queryStr;
return fullUrl;
}
private String getRealUrl(String url) {
if (StringKit.isEmpty(url)) {
return url;
}
int index = url.indexOf("/decision");
if (index < 0) {
return url;
}
String tempUrl = AppDataConfig.getInstance().getFrUrl() + url.substring(index + "/decision".length());
return tempUrl;
}
private String addParaToQuery(String query, String paraName, String[] paraValues) {
if (StringKit.isEmpty(paraName)) {
return query;
}
String fullQuery = query;
if ((paraValues == null) || (paraValues.length <= 0)) {
if (StringKit.isNotEmpty(fullQuery)) {
fullQuery = fullQuery + "&";
}
fullQuery = fullQuery + paraName + "=";
return fullQuery;
}
for (int i = 0, max = paraValues.length - 1; i <= max; i++) {
if (StringKit.isNotEmpty(fullQuery)) {
fullQuery = fullQuery + "&";
}
fullQuery = fullQuery + paraName + "=" + Utils.encodeUrlWithUtf8(paraValues[i]);
}
return fullQuery;
}
private boolean isAllowLoginWithParameter(HttpServletRequest req) {
if (req == null) {
return false;
}
String loginTypeNameParameter = "login_type";
String loginTypeConfigValue = "feishu";
if (StringKit.isEmpty(loginTypeNameParameter) || StringKit.isEmpty(loginTypeConfigValue)) {
return false;
}
String loginTypeValue = WebUtils.getHTTPRequestParameter(req, loginTypeNameParameter);
return ComparatorUtils.equalsIgnoreCase(loginTypeConfigValue, loginTypeValue);
}
private boolean isAllowLoginWithLightApp(HttpServletRequest req) {
if (req == null) {
return false;
}
String loginTypeNameParameter = "light_app";
String loginTypeConfigValue = "feishu";
if (StringKit.isEmpty(loginTypeNameParameter) || StringKit.isEmpty(loginTypeConfigValue)) {
return false;
}
String loginTypeValue = WebUtils.getHTTPRequestParameter(req, loginTypeNameParameter);
return ComparatorUtils.equalsIgnoreCase(loginTypeConfigValue, loginTypeValue);
}
private boolean isReportRequest(HttpServletRequest req) {
if (req == null) {
return false;
}
if (!"GET".equalsIgnoreCase(req.getMethod())) {
return false;
}
String url = req.getRequestURL().toString();
if (url.endsWith("/decision") || url.endsWith("/decision/")) {
return true;
}
if ((url.indexOf("/decision/") >= 0) && (url.indexOf("/entry/access/") >= 0)) {
return true;
}
String viewlet = WebUtils.getHTTPRequestParameter(req, "viewlet");
if ((url.indexOf("/decision/view/report") >= 0) && (StringKit.isNotEmpty(viewlet))) {
return true;
}
if ((url.indexOf("/decision/view/form") >= 0) && (StringKit.isNotEmpty(viewlet))) {
return true;
}
return false;
}
private boolean isOauthCodeRequest(HttpServletRequest req) throws IOException {
if (req == null) {
return false;
}
if (!"GET".equalsIgnoreCase(req.getMethod())) {
return false;
}
String oAuthCode = WebUtils.getHTTPRequestParameter(req, "code");
if (StringKit.isNotEmpty(oAuthCode)) {
return true;
}
return false;
}
private boolean isNoAuthRequest(HttpServletRequest req) throws IOException {
if (req == null) {
return false;
}
if (!"GET".equalsIgnoreCase(req.getMethod())) {
return false;
}
String oAuthCode = WebUtils.getHTTPRequestParameter(req, "loginType");
if (StringKit.equalsIgnoreCase("noauth", oAuthCode)) {
return true;
}
return false;
}
}

62
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/AddAppHttpHandler.java

@ -0,0 +1,62 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*/
public class AddAppHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/jsdjjed/add/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String repBody = IOUtils.inputStream2String(req.getInputStream(), "UTF-8");
if (StringKit.isEmpty(repBody)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("请求内容为空"));
return;
}
JSONObject reqJson = new JSONObject(repBody);
AppConfigEntity appConfigEntity = reqJson.mapTo(AppConfigEntity.class);
appConfigEntity.setConfigId(toLowerCase(appConfigEntity.getConfigId()));
if (AppConfigData.isAppConfigDataExistsWithConfigId(appConfigEntity.getConfigId())) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("应用唯一标识已存在"));
return;
}
AppConfigData.addAppConfigData(appConfigEntity);
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
}
private String toLowerCase(String value) {
if (StringKit.isEmpty(value)) {
return "";
}
return value.toLowerCase();
}
}

62
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/DeleteAppHttpHandler.java

@ -0,0 +1,62 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*/
public class DeleteAppHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.DELETE;
}
@Override
public String getPath() {
return "/jsdjjed/delete/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String repBody = IOUtils.inputStream2String(req.getInputStream(), "UTF-8");
if (StringKit.isEmpty(repBody)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("请求内容为空"));
return;
}
JSONObject removeJson = new JSONObject(repBody);
JSONArray idJsons = removeJson.getJSONArray("removeUserIds");
if ((idJsons == null) || (idJsons.size() <= 0)) {
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
return;
}
String id;
int size = idJsons.size();
for (int i = 0, max = size - 1; i <= max; i++) {
id = idJsons.getString(i);
AppConfigData.deleteAppConfigDataWithId(id);
}
String resultContent = "{\"data\":{\"count\":" + size + "},\"stauts\":\"success\"}";
WebUtils.printAsString(res, resultContent);
}
}

60
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/EditAppHttpHandler.java

@ -0,0 +1,60 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class EditAppHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.PUT;
}
@Override
public String getPath() {
return "/jsdjjed/edit/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String repBody = IOUtils.inputStream2String(req.getInputStream(), "UTF-8");
if (StringKit.isEmpty(repBody)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("请求内容为空"));
return;
}
JSONObject reqJson = new JSONObject(repBody);
AppConfigEntity appConfigEntity = reqJson.mapTo(AppConfigEntity.class);
if (AppConfigData.isAppConfigDataExistsWithConfigId(appConfigEntity.getConfigId(), appConfigEntity.getId())) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("应用唯一标识已存在"));
return;
}
AppConfigEntity entity = AppConfigData.queryAppConfigDataWithConfigIdAndOnlyOne(appConfigEntity.getConfigId());
if (entity == null) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("应用唯一标识不存在"));
return;
}
appConfigEntity.setLogin(entity.getLogin());
AppConfigData.updateAppConfigData(appConfigEntity);
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
}
}

64
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/ForbidAppHttpHandler.java

@ -0,0 +1,64 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*/
public class ForbidAppHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.PUT;
}
@Override
public String getPath() {
return "/jsdjjed/forbid/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String repBody = IOUtils.inputStream2String(req.getInputStream(), "UTF-8");
if (StringKit.isEmpty(repBody)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("请求内容为空"));
return;
}
JSONObject forbidJson = new JSONObject(repBody);
boolean enable = forbidJson.getBoolean("enable");
String id = forbidJson.getString("id");
int login = 0;
if (enable) {
login = 1;
}
AppConfigEntity entity = AppConfigData.queryAppConfigDataWithId(id);
if (entity == null) {
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
return;
}
entity.setLogin(login);
AppConfigData.updateAppConfigData(entity);
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
}
}

97
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryAppConfigHttpHandler.java

@ -0,0 +1,97 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
*
*/
public class QueryAppConfigHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/jsdjjed/query/config/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
JSONObject dataJson = getConfigJsonData();
WebUtils.printAsJSON(res, dataJson);
}
private JSONObject getConfigJsonData() {
JSONObject dataJson = new JSONObject();
dataJson.put("frUrl", AppDataConfig.getInstance().getFrUrl());
dataJson.put("accessTokenUrl", AppDataConfig.getInstance().getAccessTokenUrl());
dataJson.put("codeUserUrl", AppDataConfig.getInstance().getCodeUserUrl());
dataJson.put("chatGroupsUrl", AppDataConfig.getInstance().getChatGroupsUrl());
dataJson.put("usersUrl", AppDataConfig.getInstance().getUsersUrl());
dataJson.put("sendMessageUrl", AppDataConfig.getInstance().getSendMessageUrl());
dataJson.put("sendBatchMessageUrl", AppDataConfig.getInstance().getSendBatchMessageUrl());
dataJson.put("uploadImageUrl", AppDataConfig.getInstance().getUploadImageUrl());
dataJson.put("uploadFileUrl", AppDataConfig.getInstance().getUploadFileUrl());
dataJson.put("authorizeUrl", AppDataConfig.getInstance().getAuthorizeUrl());
dataJson.put("accessTokenUrlEscbOption", AppDataConfig.getInstance().isAccessTokenUrlEscbOption());
dataJson.put("codeUserUrlEscbOption", AppDataConfig.getInstance().isCodeUserUrlEscbOption());
dataJson.put("chatGroupsUrlEscbOption", AppDataConfig.getInstance().isChatGroupsUrlEscbOption());
dataJson.put("usersUrlEscbOption", AppDataConfig.getInstance().isUsersUrlEscbOption());
dataJson.put("sendMessageUrlEscbOption", AppDataConfig.getInstance().isSendMessageUrlEscbOption());
dataJson.put("sendBatchMessageUrlEscbOption", AppDataConfig.getInstance().isSendBatchMessageUrlEscbOption());
dataJson.put("uploadImageUrlEscbOption", AppDataConfig.getInstance().isUploadImageUrlEscbOption());
dataJson.put("uploadFileUrlEscbOption", AppDataConfig.getInstance().isUploadFileUrlEscbOption());
dataJson.put("authorizeUrlEscbOption", AppDataConfig.getInstance().isAuthorizeUrlEscbOption());
dataJson.put("accessTokenUrlEscbCode", AppDataConfig.getInstance().getAccessTokenUrlEscbCode());
dataJson.put("codeUserUrlEscbCode", AppDataConfig.getInstance().getCodeUserUrlEscbCode());
dataJson.put("chatGroupsUrlEscbCode", AppDataConfig.getInstance().getChatGroupsUrlEscbCode());
dataJson.put("usersUrlEscbCode", AppDataConfig.getInstance().getUsersUrlEscbCode());
dataJson.put("sendMessageUrlEscbCode", AppDataConfig.getInstance().getSendMessageUrlEscbCode());
dataJson.put("sendBatchMessageUrlEscbCode", AppDataConfig.getInstance().getSendBatchMessageUrlEscbCode());
dataJson.put("uploadImageUrlEscbCode", AppDataConfig.getInstance().getUploadImageUrlEscbCode());
dataJson.put("uploadFileUrlEscbCode", AppDataConfig.getInstance().getUploadFileUrlEscbCode());
dataJson.put("authorizeUrlEscbCode", AppDataConfig.getInstance().getAuthorizeUrlEscbCode());
dataJson.put("accessTokenUrlEscbVersion", AppDataConfig.getInstance().getAccessTokenUrlEscbVersion());
dataJson.put("codeUserUrlEscbVersion", AppDataConfig.getInstance().getCodeUserUrlEscbVersion());
dataJson.put("chatGroupsUrlEscbVersion", AppDataConfig.getInstance().getChatGroupsUrlEscbVersion());
dataJson.put("usersUrlEscbVersion", AppDataConfig.getInstance().getUsersUrlEscbVersion());
dataJson.put("sendMessageUrlEscbVersion", AppDataConfig.getInstance().getSendMessageUrlEscbVersion());
dataJson.put("sendBatchMessageUrlEscbVersion", AppDataConfig.getInstance().getSendBatchMessageUrlEscbVersion());
dataJson.put("uploadImageUrlEscbVersion", AppDataConfig.getInstance().getUploadImageUrlEscbVersion());
dataJson.put("uploadFileUrlEscbVersion", AppDataConfig.getInstance().getUploadFileUrlEscbVersion());
dataJson.put("authorizeUrlEscbVersion", AppDataConfig.getInstance().getAuthorizeUrlEscbVersion());
dataJson.put("escbUrl", AppDataConfig.getInstance().getEscbUrl());
dataJson.put("escbAppCode", AppDataConfig.getInstance().getEscbAppCode());
dataJson.put("escbAppToken", AppDataConfig.getInstance().getEscbAppToken());
dataJson.put("escbOrgCode", AppDataConfig.getInstance().getEscbOrgCode());
dataJson.put("escbSysCode", AppDataConfig.getInstance().getEscbSysCode());
dataJson.put("page", 1);
JSONObject json = Utils.getSuccessResultJson();
json.put("data", dataJson);
return json;
}
}

71
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryAppHttpHandler.java

@ -0,0 +1,71 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
*
*/
public class QueryAppHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/jsdjjed/query/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
List<AppConfigEntity> entities = AppConfigData.queryAllAppConfigData();
JSONObject dataJson = createJsonData(entities);
WebUtils.printAsJSON(res, dataJson);
}
private JSONObject createJsonData(List<AppConfigEntity> entities) {
int total = entities.size();
JSONArray itemsJsons = new JSONArray();
AppConfigEntity entity;
JSONObject itemsJson;
for (int i = 0, max = total - 1; i <= max; i++) {
entity = entities.get(i);
itemsJson = JSONObject.mapFrom(entity);
if (entity.getLogin() == 1) {
itemsJson.put("enable", true);
} else {
itemsJson.put("enable", false);
}
itemsJson.put("show", entity.getConfigId() + "_" + entity.getNotes());
itemsJsons.add(itemsJson);
}
JSONObject dataJson = new JSONObject();
dataJson.put("total", total);
dataJson.put("page", 1);
dataJson.put("items", itemsJsons);
JSONObject json = new JSONObject();
json.put("data", dataJson);
return json;
}
}

91
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/QueryChatGroupsHttpHandler.java

@ -0,0 +1,91 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.plugin.third.party.jsdjjed.feishu.FeishuApp;
import com.fr.plugin.third.party.jsdjjed.feishu.FeishuChatGroupBean;
import com.fr.third.org.apache.commons.collections4.CollectionUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
*
*/
public class QueryChatGroupsHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/jsdjjed/query/chat/group";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String configId = WebUtils.getHTTPRequestParameter(req, "config_id");
if (StringKit.isEmpty(configId)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("应用唯一标识为空"));
return;
}
JSONObject dataJson = createJsonData(configId);
WebUtils.printAsJSON(res, dataJson);
}
private JSONObject createJsonData(String configId) throws Exception {
AppConfigEntity configEntity = AppConfigData.queryAppConfigDataWithConfigIdAndOnlyOne(configId);
if (configEntity == null) {
return Utils.getFailuresResultJson("应用唯一标识无效,没有对应配置信息");
}
String appId = configEntity.getAppId();
String appSecret = configEntity.getAppSecret();
String accessToken = FeishuApp.createAppAccessToken(appId, appSecret);
if (StringKit.isEmpty(accessToken)) {
return Utils.getFailuresResultJson("获取app_access_token为空");
}
List<FeishuChatGroupBean> chatGroupBeans = FeishuApp.getChatGroups(accessToken);
if (CollectionUtils.isEmpty(chatGroupBeans)) {
return Utils.getFailuresResultJson("获取群列表为空");
}
int total = chatGroupBeans.size();
JSONArray itemsJsons = new JSONArray();
FeishuChatGroupBean entity;
JSONObject itemsJson;
String show;
for (int i = 0, max = total - 1; i <= max; i++) {
entity = chatGroupBeans.get(i);
itemsJson = JSONObject.mapFrom(entity);
show = entity.getName() + "_" + entity.getChatId();
itemsJson.put("show", show);
itemsJsons.add(itemsJson);
}
JSONObject dataJson = new JSONObject();
dataJson.put("total", total);
dataJson.put("page", 1);
dataJson.put("items", itemsJsons);
JSONObject json = Utils.getSuccessResultJson();
json.put("data", dataJson);
return json;
}
}

105
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/SaveAppConfigHttpHandler.java

@ -0,0 +1,105 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SaveAppConfigHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.PUT;
}
@Override
public String getPath() {
return "/jsdjjed/save/config/app";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String repBody = IOUtils.inputStream2String(req.getInputStream(), "UTF-8");
if (StringKit.isEmpty(repBody)) {
WebUtils.printAsJSON(res, Utils.getFailuresResultJson("请求内容为空"));
return;
}
JSONObject reqJson = new JSONObject(repBody);
String frUrl = reqJson.getString("frUrl", "");
String accessTokenUrl = reqJson.getString("accessTokenUrl", "");
String codeUserUrl = reqJson.getString("codeUserUrl", "");
String chatGroupsUrl = reqJson.getString("chatGroupsUrl", "");
String usersUrl = reqJson.getString("usersUrl", "");
String sendMessageUrl = reqJson.getString("sendMessageUrl", "");
String sendBatchMessageUrl = reqJson.getString("sendBatchMessageUrl", "");
String uploadImageUrl = reqJson.getString("uploadImageUrl", "");
String uploadFileUrl = reqJson.getString("uploadFileUrl", "");
String authorizeUrl = reqJson.getString("authorizeUrl", "");
AppDataConfig.getInstance().setFrUrl(frUrl);
AppDataConfig.getInstance().setAccessTokenUrl(accessTokenUrl);
AppDataConfig.getInstance().setCodeUserUrl(codeUserUrl);
AppDataConfig.getInstance().setChatGroupsUrl(chatGroupsUrl);
AppDataConfig.getInstance().setUsersUrl(usersUrl);
AppDataConfig.getInstance().setSendMessageUrl(sendMessageUrl);
AppDataConfig.getInstance().setSendBatchMessageUrl(sendBatchMessageUrl);
AppDataConfig.getInstance().setUploadImageUrl(uploadImageUrl);
AppDataConfig.getInstance().setUploadFileUrl(uploadFileUrl);
AppDataConfig.getInstance().setAuthorizeUrl(authorizeUrl);
AppDataConfig.getInstance().setAccessTokenUrlEscbOption(reqJson.getBoolean("accessTokenUrlEscbOption"));
AppDataConfig.getInstance().setCodeUserUrlEscbOption(reqJson.getBoolean("codeUserUrlEscbOption"));
AppDataConfig.getInstance().setChatGroupsUrlEscbOption(reqJson.getBoolean("chatGroupsUrlEscbOption"));
AppDataConfig.getInstance().setUsersUrlEscbOption(reqJson.getBoolean("usersUrlEscbOption"));
AppDataConfig.getInstance().setSendMessageUrlEscbOption(reqJson.getBoolean("sendMessageUrlEscbOption"));
AppDataConfig.getInstance().setSendBatchMessageUrlEscbOption(reqJson.getBoolean("sendBatchMessageUrlEscbOption"));
AppDataConfig.getInstance().setUploadImageUrlEscbOption(reqJson.getBoolean("uploadImageUrlEscbOption"));
AppDataConfig.getInstance().setUploadFileUrlEscbOption(reqJson.getBoolean("uploadFileUrlEscbOption"));
AppDataConfig.getInstance().setAuthorizeUrlEscbOption(reqJson.getBoolean("authorizeUrlEscbOption"));
AppDataConfig.getInstance().setAccessTokenUrlEscbCode(reqJson.getString("accessTokenUrlEscbCode",""));
AppDataConfig.getInstance().setCodeUserUrlEscbCode(reqJson.getString("codeUserUrlEscbCode",""));
AppDataConfig.getInstance().setChatGroupsUrlEscbCode(reqJson.getString("chatGroupsUrlEscbCode",""));
AppDataConfig.getInstance().setUsersUrlEscbCode(reqJson.getString("usersUrlEscbCode",""));
AppDataConfig.getInstance().setSendMessageUrlEscbCode(reqJson.getString("sendMessageUrlEscbCode",""));
AppDataConfig.getInstance().setSendBatchMessageUrlEscbCode(reqJson.getString("sendBatchMessageUrlEscbCode",""));
AppDataConfig.getInstance().setUploadImageUrlEscbCode(reqJson.getString("uploadImageUrlEscbCode",""));
AppDataConfig.getInstance().setUploadFileUrlEscbCode(reqJson.getString("uploadFileUrlEscbCode",""));
AppDataConfig.getInstance().setAuthorizeUrlEscbCode(reqJson.getString("authorizeUrlEscbCode",""));
AppDataConfig.getInstance().setAccessTokenUrlEscbVersion(reqJson.getString("accessTokenUrlEscbVersion",""));
AppDataConfig.getInstance().setCodeUserUrlEscbVersion(reqJson.getString("codeUserUrlEscbVersion",""));
AppDataConfig.getInstance().setChatGroupsUrlEscbVersion(reqJson.getString("chatGroupsUrlEscbVersion",""));
AppDataConfig.getInstance().setUsersUrlEscbVersion(reqJson.getString("usersUrlEscbVersion",""));
AppDataConfig.getInstance().setSendMessageUrlEscbVersion(reqJson.getString("sendMessageUrlEscbVersion",""));
AppDataConfig.getInstance().setSendBatchMessageUrlEscbVersion(reqJson.getString("sendBatchMessageUrlEscbVersion",""));
AppDataConfig.getInstance().setUploadImageUrlEscbVersion(reqJson.getString("uploadImageUrlEscbVersion",""));
AppDataConfig.getInstance().setUploadFileUrlEscbVersion(reqJson.getString("uploadFileUrlEscbVersion",""));
AppDataConfig.getInstance().setAuthorizeUrlEscbVersion(reqJson.getString("authorizeUrlEscbVersion",""));
AppDataConfig.getInstance().setEscbUrl(reqJson.getString("escbUrl",""));
AppDataConfig.getInstance().setEscbAppCode(reqJson.getString("escbAppCode",""));
AppDataConfig.getInstance().setEscbAppToken(reqJson.getString("escbAppToken",""));
AppDataConfig.getInstance().setEscbOrgCode(reqJson.getString("escbOrgCode",""));
AppDataConfig.getInstance().setEscbSysCode(reqJson.getString("escbSysCode",""));
WebUtils.printAsJSON(res, Utils.getSuccessResultJson());
}
}

46
src/main/java/com/fr/plugin/third/party/jsdjjed/http/app/SynchronizeSourceHttpHandler.java

@ -0,0 +1,46 @@
package com.fr.plugin.third.party.jsdjjed.http.app;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdjjed.Utils;
import com.fr.plugin.third.party.jsdjjed.config.AppDataConfig;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
*/
public class SynchronizeSourceHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.GET;
}
@Override
public String getPath() {
return "/jsdjjed/synchronize/source";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
JSONObject dataJson = getConfigJsonData();
WebUtils.printAsJSON(res, dataJson);
}
private JSONObject getConfigJsonData() {
JSONObject dataJson = new JSONObject("{\"data\":{\"type\":0}}");
return dataJson;
}
}

410
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/AppMessagePushHandler.java

@ -0,0 +1,410 @@
package com.fr.plugin.third.party.jsdjjed.schedule;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.DataSetFunctionParameterMapNameSpace;
import com.fr.base.TemplateUtils;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginContexts;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigData;
import com.fr.plugin.third.party.jsdjjed.app.config.AppConfigEntity;
import com.fr.plugin.third.party.jsdjjed.feishu.FeishuApp;
import com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush;
import com.fr.schedule.base.constant.ScheduleConstants;
import com.fr.schedule.extension.report.job.output.BaseOutputFormat;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import com.fr.third.org.apache.commons.collections4.CollectionUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class AppMessagePushHandler extends OutputActionHandler<OutputAppMessagePush> {
@Override
public void doAction(OutputAppMessagePush action, Map<String, Object> map) throws Exception {
LogKit.info("飞书发送消息,开发发送任务........");
String configId = action.getConfigId();
if (StringKit.isEmpty(configId)) {
return;
}
//添加认证
if (!PluginContexts.currentContext().isAvailable()) {
LogKit.error("飞书登录集成插件试用过期,飞书发送消息, 请购买许可证");
}
AppConfigEntity configEntity = AppConfigData.queryAppConfigDataWithConfigIdAndOnlyOne(configId);
if (configEntity == null) {
return;
}
LogKit.info("飞书发送消息,获取token........");
String appAccessToken = FeishuApp.createAppAccessToken(configEntity.getAppId(), configEntity.getAppSecret());
if (StringKit.isEmpty(appAccessToken)) {
LogKit.error("飞书发送消息,获取app_access_token为空");
return;
}
LogKit.info("飞书发送消息,获取飞书用户和群........");
List<String> feishuUserIds = getFeishuUserIds(map);
String chatGroupId = action.getChatGroupId();
if ("empty_group".equalsIgnoreCase(chatGroupId)) {
chatGroupId = "";
}
if (CollectionUtils.isEmpty(feishuUserIds) && StringKit.isEmpty(chatGroupId)) {
LogKit.error("飞书发送消息,飞书用户ID和群ID都为空");
return;
}
String msgType = FeishuApp.getMsgType(action.getFeishuMsgType());
String sendType = FeishuApp.getSendType(action.getFeishuSendType());
LogKit.info("飞书发送消息,消息类型:" + FeishuApp.getMsgTypeNotes(msgType));
LogKit.info("飞书发送消息,发送类型:" + FeishuApp.getSendTypeNotes(sendType));
if (FeishuApp.isSendMessage(sendType)) {
LogKit.info("飞书发送消息,生成发送文本........");
Calculator cal = Calculator.createCalculator();
String content = action.getContent();
String msgContent = TemplateUtils.renderTpl(cal, content);
LogKit.info("飞书发送消息,发送文本:" + msgContent);
LogKit.info("飞书发送消息,发送文本消息........");
if (StringKit.isNotEmpty(chatGroupId) && StringKit.isNotEmpty(msgContent)) {
LogKit.info("飞书发送消息,发送群文本消息........");
if ("text".equals(msgType)) {
FeishuApp.sendGroupMessageWithText(chatGroupId, msgContent, appAccessToken);
} else {
FeishuApp.sendMessage("chat_id", chatGroupId, msgContent, "post", appAccessToken);
}
}
if (CollectionUtils.isNotEmpty(feishuUserIds) && StringKit.isNotEmpty(msgContent)) {
LogKit.info("飞书发送消息,发送个人文本消息........");
if ("text".equals(msgType)) {
FeishuApp.sendBatchMessageWithText(feishuUserIds, msgContent, appAccessToken);
} else {
FeishuApp.sendBatchMessageWithRichText(feishuUserIds, msgContent, appAccessToken);
}
}
}
if (FeishuApp.isSendFile(sendType)) {
LogKit.info("飞书发送消息,发送文件消息........");
JSONObject commonUploadJson = getUploadFileJson(action, map, appAccessToken);
if (FeishuApp.isValidFileJson(commonUploadJson)) {
if (StringKit.isNotEmpty(chatGroupId)) {
LogKit.info("飞书发送消息,发送群文件消息........");
FeishuApp.sendGroupMessageWithFile(chatGroupId, commonUploadJson.toString(), appAccessToken);
}
} else if (FeishuApp.isValidImageJson(commonUploadJson)) {
if (StringKit.isNotEmpty(chatGroupId)) {
LogKit.info("飞书发送消息,发送群图片消息........");
FeishuApp.sendGroupMessageWithImage(chatGroupId, commonUploadJson.toString(), appAccessToken);
}
}
if (CollectionUtils.isNotEmpty(feishuUserIds)) {
List<String> userIds = getTaskUserIds(map);
String feishuUserId, userId;
List<String> sendUserIds = new ArrayList<>();
JSONObject uploadJson;
List<String> tempFeishuUserIds = new ArrayList<>();
for (int i = 0, max = userIds.size() - 1; i <= max; i++) {
userId = userIds.get(i);
feishuUserId = toLower(userId);
if (sendUserIds.contains(feishuUserId)) {
continue;
}
tempFeishuUserIds.clear();
tempFeishuUserIds.add(feishuUserId);
uploadJson = getUserUploadFileJson(action, map, appAccessToken, userId);
if ((!FeishuApp.isValidFileJson(uploadJson)) && (!FeishuApp.isValidImageJson(uploadJson))) {
uploadJson = commonUploadJson;
}
if (FeishuApp.isValidFileJson(uploadJson)) {
if (CollectionUtils.isNotEmpty(tempFeishuUserIds)) {
LogKit.info("飞书发送消息,发送个人文件消息........");
FeishuApp.sendBatchMessageWithFile(tempFeishuUserIds, uploadJson.toString(), appAccessToken);
}
} else if (FeishuApp.isValidImageJson(uploadJson)) {
if (CollectionUtils.isNotEmpty(tempFeishuUserIds)) {
LogKit.info("飞书发送消息,发送个人图片消息........");
FeishuApp.sendBatchMessageWithImage(tempFeishuUserIds, uploadJson.toString(), appAccessToken);
}
}
sendUserIds.add(feishuUserId);
}
}
}
LogKit.info("飞书发送消息,结束发送任务........");
}
private JSONObject getUserUploadFileJson(OutputAppMessagePush action, Map<String, Object> map, String appAccessToken, String userId) throws IOException {
JSONObject fileJson = new JSONObject();
String fileType = getFileType(action);
if (StringKit.isEmpty(fileType)) {
return fileJson;
}
String filePath = getUploadFilePath(action, map);
String fileName = getUploadFileName(filePath);
String userFilePath = getUserUploadFilePath(action, map, userId, fileName);
if (StringKit.isEmpty(userFilePath)) {
return fileJson;
}
InputStream fileInputStream = getUploadFileInputStream(userFilePath);
if (fileInputStream == null) {
return fileJson;
}
if ("png".equals(fileType)) {
fileJson = FeishuApp.uploadImage(fileInputStream, appAccessToken);
return fileJson;
}
fileJson = FeishuApp.uploadFile(fileType, fileName, fileInputStream, appAccessToken);
return fileJson;
}
private String getUserUploadFilePath(OutputAppMessagePush action, Map<String, Object> map, String userId, String fileName) {
String fileType = getFileType(action);
if (StringKit.isEmpty(fileType)) {
return "";
}
String fileSuffix = "." + fileType;
if (StringKit.isEmpty(fileSuffix)) {
return "";
}
String tempFilePath = String.valueOf(map.get(ScheduleConstants.SAVE_DIRECTORY_WITHOUT_USERNAME));
if (StringKit.isEmpty(tempFilePath)) {
return "";
}
String filePath = tempFilePath.substring(0, tempFilePath.lastIndexOf("/")) + "/" + userId + "/" + fileName;
if (StringKit.isNotEmpty(filePath) && ResourceIOUtils.exist(filePath)) {
return filePath;
}
return "";
}
private JSONObject getUploadFileJson(OutputAppMessagePush action, Map<String, Object> map, String appAccessToken) throws IOException {
JSONObject fileJson = new JSONObject();
String fileType = getFileType(action);
if (StringKit.isEmpty(fileType)) {
return fileJson;
}
String filePath = getUploadFilePath(action, map);
InputStream fileInputStream = getUploadFileInputStream(filePath);
if (fileInputStream == null) {
return fileJson;
}
if ("png".equals(fileType)) {
fileJson = FeishuApp.uploadImage(fileInputStream, appAccessToken);
return fileJson;
}
String fileName = getUploadFileName(filePath);
fileJson = FeishuApp.uploadFile(fileType, fileName, fileInputStream, appAccessToken);
return fileJson;
}
private String getFileType(OutputAppMessagePush action) {
if (action == null) {
return "";
}
if (action.getType() != 3) {
return "";
}
BaseOutputFormat outputFormat = BaseOutputFormat.fromInteger(action.getMediaId());
if (outputFormat == null) {
return "";
}
String fileSuffix = StringKit.trim(outputFormat.getFileSuffix());
if (StringKit.isEmpty(fileSuffix)) {
return "";
}
String type = "";
if (fileSuffix.startsWith(".")) {
type = fileSuffix.substring(1);
}
type = StringKit.trim(type);
return type;
}
private String getUploadFilePath(OutputAppMessagePush action, Map<String, Object> map) {
String fileType = getFileType(action);
if (StringKit.isEmpty(fileType)) {
return "";
}
String fileSuffix = "." + fileType;
if (StringKit.isEmpty(fileSuffix)) {
return "";
}
String[] filePaths = (String[]) map.get(ScheduleConstants.OUTPUT_FILES);
if ((filePaths == null) || (filePaths.length <= 0)) {
return "";
}
String filePath;
for (int i = 0, max = filePaths.length - 1; i <= max; i++) {
filePath = filePaths[i];
if (StringKit.isNotEmpty(filePath) && filePath.endsWith(fileSuffix) && ResourceIOUtils.exist(filePath)) {
return filePath;
}
}
return "";
}
private String getUploadFileName(String filePath) {
if (StringKit.isEmpty(filePath)) {
return "";
}
String name = ResourceIOUtils.getName(filePath);
return name;
}
private InputStream getUploadFileInputStream(String filePath) {
if (StringKit.isEmpty(filePath)) {
return null;
}
if (ResourceIOUtils.exist(filePath)) {
InputStream in = ResourceIOUtils.read(filePath);
return in;
}
return null;
}
private List<String> getTaskUserIds(Map<String, Object> map) throws Exception {
if ((map == null) || (map.size() <= 0)) {
return new ArrayList<>();
}
String[] scheduleUserNames = (String[]) map.get(ScheduleConstants.USERNAMES);
String scheduleUserName = (String) map.get(ScheduleConstants.USERNAME);
Set<String> userSet = new HashSet();
String tempUserName = StringKit.trim(scheduleUserName);
if (StringKit.isNotEmpty(tempUserName)) {
userSet.add(tempUserName);
}
if ((scheduleUserNames != null) && (scheduleUserNames.length >= 1)) {
for (int i = 0, max = scheduleUserNames.length - 1; i <= max; i++) {
tempUserName = StringKit.trim(scheduleUserNames[i]);
if (StringKit.isNotEmpty(tempUserName)) {
userSet.add(tempUserName);
}
}
}
if (userSet.size() <= 0) {
return new ArrayList<>();
}
List<String> userId = new ArrayList<>();
userId.addAll(userSet);
return userId;
}
private List<String> getFeishuUserIds(Map<String, Object> map) throws Exception {
if ((map == null) || (map.size() <= 0)) {
return new ArrayList<>();
}
String[] scheduleUserNames = (String[]) map.get(ScheduleConstants.USERNAMES);
String scheduleUserName = (String) map.get(ScheduleConstants.USERNAME);
Set<String> userSet = new HashSet();
String tempUserName = toLower(scheduleUserName);
if (StringKit.isNotEmpty(tempUserName)) {
userSet.add(tempUserName);
}
if ((scheduleUserNames != null) && (scheduleUserNames.length >= 1)) {
for (int i = 0, max = scheduleUserNames.length - 1; i <= max; i++) {
tempUserName = toLower(scheduleUserNames[i]);
if (StringKit.isNotEmpty(tempUserName)) {
userSet.add(tempUserName);
}
}
}
if (userSet.size() <= 0) {
return new ArrayList<>();
}
List<String> userId = new ArrayList<>();
userId.addAll(userSet);
return userId;
}
private String toLower(String value) {
if (StringKit.isEmpty(value)) {
return "";
}
String tempValue = StringKit.trim(value.toLowerCase());
if (StringKit.isEmpty(tempValue)) {
return "";
}
return tempValue;
}
private List<String> getFeishuUserId(String appAccessToken, Map<String, Object> map) throws Exception {
if (StringKit.isEmpty(appAccessToken)) {
return new ArrayList<>();
}
if ((map == null) || (map.size() <= 0)) {
return new ArrayList<>();
}
String[] scheduleUserNames = (String[]) map.get(ScheduleConstants.USERNAMES);
String scheduleUserName = (String) map.get(ScheduleConstants.USERNAME);
Set<String> userSet = new HashSet();
if (StringUtils.isNotBlank(scheduleUserName)) {
userSet.add(scheduleUserName);
}
if ((scheduleUserNames != null) && (scheduleUserNames.length >= 1)) {
userSet.addAll(Arrays.asList(scheduleUserNames));
}
List<User> userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.in("userName", userSet)));
if ((userList == null) || (userList.size() <= 0)) {
return new ArrayList<>();
}
Set<String> emailSet = new HashSet();
Set<String> mobileSet = new HashSet();
User user;
String email, mobile;
for (int i = 0, max = userList.size() - 1; i <= max; i++) {
user = userList.get(i);
email = StringKit.trim(user.getEmail());
if (StringKit.isNotEmpty(email)) {
emailSet.add(email);
}
mobile = StringKit.trim(user.getMobile());
if (StringKit.isNotEmpty(mobile)) {
mobileSet.add(mobile);
}
}
if ((emailSet.size() <= 0) && (mobileSet.size() <= 0)) {
return new ArrayList<>();
}
List<String> feishuUserIds = FeishuApp.getFeishuUserId(emailSet, mobileSet, appAccessToken);
return feishuUserIds;
}
}

154
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/bean/OutputAppMessagePush.java

@ -0,0 +1,154 @@
package com.fr.plugin.third.party.jsdjjed.schedule.bean;
import com.fr.plugin.third.party.jsdjjed.schedule.entity.AppMessagePushEntity;
import com.fr.schedule.base.bean.output.BaseOutputAction;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
import com.fr.schedule.base.type.RunType;
import com.fr.third.fasterxml.jackson.annotation.JsonSubTypes;
@JsonSubTypes.Type(value = OutputAppMessagePush.class, name = "OutputAppMessagePush")
public class OutputAppMessagePush extends BaseOutputAction {
private int terminal = 64;
private String subject;
private String content;
/**
* 客户端通知 消息类型</br>
* 1:链接消息;2:图文消息;3:文件消息
*/
private int type;
private String configId;
private String chatGroupId;
private String feishuMsgType;
private String feishuSendType;
/**
* 客户端通知 定时结果附件
*/
private int mediaId;
private int runType = RunType.CLIENT_NOTIFICATION.getValue();
//是否受不同用户生成不同附件影响
@Override
public boolean willExecuteByUser() {
return false;
}
//推送类型
@Override
public RunType runType() {
return RunType.CLIENT_NOTIFICATION;
}
@Override
public Class<? extends AbstractScheduleEntity> outputActionEntityClass() {
return AppMessagePushEntity.class;
}
@Override
public AbstractScheduleEntity createOutputActionEntity() {
AppMessagePushEntity entity = new AppMessagePushEntity();
entity.setId(this.getId());
entity.setContent(this.getContent());
entity.setSubject(this.getSubject());
entity.setTerminal(this.getTerminal());
entity.setType(this.getType());
entity.setConfigId(this.getConfigId());
entity.setChatGroupId(this.getChatGroupId());
entity.setMediaId(this.getMediaId());
entity.setFeishuMsgType(this.getFeishuMsgType());
entity.setFeishuSendType(this.getFeishuSendType());
return entity;
}
public int getTerminal() {
return terminal;
}
public void setTerminal(int terminal) {
this.terminal = terminal;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public int getRunType() {
return runType;
}
public void setRunType(int runType) {
this.runType = runType;
}
public String getConfigId() {
return configId;
}
public void setConfigId(String configId) {
this.configId = configId;
}
public String getChatGroupId() {
return chatGroupId;
}
public void setChatGroupId(String chatGroupId) {
this.chatGroupId = chatGroupId;
}
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public String getFeishuMsgType() {
return feishuMsgType;
}
public void setFeishuMsgType(String feishuMsgType) {
this.feishuMsgType = feishuMsgType;
}
public String getFeishuSendType() {
return feishuSendType;
}
public void setFeishuSendType(String feishuSendType) {
this.feishuSendType = feishuSendType;
}
}

47
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/components/FileDef.java

@ -0,0 +1,47 @@
package com.fr.plugin.third.party.jsdjjed.schedule.components;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class FileDef extends Component {
public static final FileDef KEY = new FileDef();
private FileDef(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
@Override
public ScriptPath script(RequestClient client) {
return ScriptPath.build("com/fr/plugin/third/party/jsdjjed/message.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
@Override
public StylePath style(RequestClient client) {
// //如果不需要就直接返回 StylePath.EMPTY;
// return StylePath.build("com/fr/plugin/publiclinksecurty/componet/demo.css");
return StylePath.EMPTY;
}
@Override
public Filter filter() {
return new Filter(){
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/components/JsAndCssBridge.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjjed.schedule.components;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.web.struct.Atom;
@FunctionRecorder
public class JsAndCssBridge extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return MainComponent.KEY;
}
@Override
public Atom client() {
return FileDef.KEY;
}
}

131
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/entity/AppMessagePushEntity.java

@ -0,0 +1,131 @@
package com.fr.plugin.third.party.jsdjjed.schedule.entity;
import com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush;
import com.fr.schedule.base.bean.BaseBean;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
import com.fr.stable.db.constant.EntityConstant;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
@Entity
@Table(name = "jsdjjed_feishu_message_push")
public class AppMessagePushEntity extends AbstractScheduleEntity {
@Column(name = "terminal")
private int terminal = 64;
@Column(name = "media_id")
private int mediaId = -1;
@Column(name = "subject", length = EntityConstant.STRING_LONG_SIZE)
private String subject;
@Column(name = "content", length = EntityConstant.STRING_LONG_SIZE)
private String content;
@Column(name = "type")
private int type;
@Column(name = "config_id")
private String configId;
@Column(name = "chat_group_id", length = EntityConstant.STRING_LONG_SIZE)
private String chatGroupId;
@Column(name = "feishu_msg_type")
private String feishuMsgType;
@Column(name = "feishu_send_type")
private String feishuSendType;
@Override
public BaseBean createBean() {
OutputAppMessagePush outputAppMessagePush = new OutputAppMessagePush();
outputAppMessagePush.setId(this.getId());
outputAppMessagePush.setContent(this.getContent());
outputAppMessagePush.setSubject(this.getSubject());
outputAppMessagePush.setTerminal(this.getTerminal());
outputAppMessagePush.setType(this.getType());
outputAppMessagePush.setConfigId(this.getConfigId());
outputAppMessagePush.setChatGroupId(this.getChatGroupId());
outputAppMessagePush.setMediaId(this.getMediaId());
outputAppMessagePush.setFeishuMsgType(this.getFeishuMsgType());
outputAppMessagePush.setFeishuSendType(this.getFeishuSendType());
return outputAppMessagePush;
}
public int getTerminal() {
return terminal;
}
public void setTerminal(int terminal) {
this.terminal = terminal;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getConfigId() {
return configId;
}
public void setConfigId(String configId) {
this.configId = configId;
}
public String getChatGroupId() {
return chatGroupId;
}
public void setChatGroupId(String chatGroupId) {
this.chatGroupId = chatGroupId;
}
public int getMediaId() {
return mediaId;
}
public void setMediaId(int mediaId) {
this.mediaId = mediaId;
}
public String getFeishuMsgType() {
return feishuMsgType;
}
public void setFeishuMsgType(String feishuMsgType) {
this.feishuMsgType = feishuMsgType;
}
public String getFeishuSendType() {
return feishuSendType;
}
public void setFeishuSendType(String feishuSendType) {
this.feishuSendType = feishuSendType;
}
}

24
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/formula/FeishuOutputFormula.java

@ -0,0 +1,24 @@
package com.fr.plugin.third.party.jsdjjed.schedule.formula;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush;
import com.fr.schedule.base.provider.impl.AbstractOutputFormulaProvider;
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
import java.util.List;
import java.util.Map;
public class FeishuOutputFormula extends AbstractOutputFormulaProvider<OutputAppMessagePush, ResultWorkBook> {
@Override
public void dealWithFormulaParam(OutputAppMessagePush bean, ResultWorkBook workBook, List<Map<String, Object>> param) throws Exception {
Map map = param.get(0);
bean.setSubject(ScheduleParameterUtils.dealWithParameter(bean.getSubject(), map, workBook));
bean.setContent(ScheduleParameterUtils.dealWithParameter(bean.getContent(), map, workBook));
}
@Override
public String getActionClassName() {
return OutputAppMessagePush.class.getName();
}
}

22
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/formula/FormulaCalculator.java

@ -0,0 +1,22 @@
package com.fr.plugin.third.party.jsdjjed.schedule.formula;
import com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush;
import com.fr.schedule.extension.report.job.output.formula.extract.impl.AbstractOutputFormulaExtractorProvider;
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
import java.util.Map;
import java.util.regex.Pattern;
public class FormulaCalculator extends AbstractOutputFormulaExtractorProvider<OutputAppMessagePush> {
@Override
public String getActionClassName() {
return OutputAppMessagePush.class.getName();
}
@Override
public void addFormulaToMap(OutputAppMessagePush bean, Pattern pattern, Map<String, Object> map) {
ScheduleParameterUtils.addFormulaToMap(bean.getSubject(),pattern, map);
ScheduleParameterUtils.addFormulaToMap(bean.getContent(),pattern, map);
}
}

16
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/provider/AppMessagePushDao.java

@ -0,0 +1,16 @@
package com.fr.plugin.third.party.jsdjjed.schedule.provider;
import com.fr.plugin.third.party.jsdjjed.schedule.entity.AppMessagePushEntity;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
public class AppMessagePushDao extends BaseDAO<AppMessagePushEntity> {
public AppMessagePushDao(DAOSession daoSession) {
super(daoSession);
}
// 反回实体类class
protected Class<AppMessagePushEntity> getEntityClass(){
return AppMessagePushEntity.class;
}
}

40
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/provider/DBAccessProvider.java

@ -0,0 +1,40 @@
package com.fr.plugin.third.party.jsdjjed.schedule.provider;
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider;
import com.fr.plugin.third.party.jsdjjed.schedule.entity.AppMessagePushEntity;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
public class DBAccessProvider extends AbstractDecisionDBAccessProvider {
private static DBAccessor dbAccessor = null;
public static DBAccessor getDbAccessor() {
return dbAccessor;
}
@Override
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
new DAOProvider() {
@Override
public Class getEntityClass() {
return AppMessagePushEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return AppMessagePushDao.class;
}
}
};
}
@Override
public void onDBAvailable(DBAccessor dbAccessor) {
DBAccessProvider.dbAccessor = dbAccessor;
}
}

111
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/utils/PlaceholderResolver.java

@ -0,0 +1,111 @@
package com.fr.plugin.third.party.jsdjjed.schedule.utils;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @Author: xx
* @Date: 2020/9/13 11:44
*/
public class PlaceholderResolver {
public static final String TEXT = "这是一个包含日期:${today()}和当前时间:${now()} 的两个公式文本";
/**
* 默认前缀占位符
*/
public static final String DEFAULT_PLACEHOLDER_PREFIX = "${";
/**
* 默认后缀占位符
*/
public static final String DEFAULT_PLACEHOLDER_SUFFIX = "}";
/**
* 默认单例解析器
*/
private static PlaceholderResolver defaultResolver = new PlaceholderResolver();
/**
* 占位符前缀
*/
private String placeholderPrefix = DEFAULT_PLACEHOLDER_PREFIX;
/**
* 占位符后缀
*/
private String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX;
private PlaceholderResolver() {
}
private PlaceholderResolver(String placeholderPrefix, String placeholderSuffix) {
this.placeholderPrefix = placeholderPrefix;
this.placeholderSuffix = placeholderSuffix;
}
/**
* 获取默认的占位符解析器即占位符前缀为"${", 后缀为"}"
*
* @return
*/
public static PlaceholderResolver getDefaultResolver() {
return defaultResolver;
}
public static PlaceholderResolver getResolver(String placeholderPrefix, String placeholderSuffix) {
return new PlaceholderResolver(placeholderPrefix, placeholderSuffix);
}
/**
* 解析带有指定占位符的模板字符串默认占位符为前缀${ 后缀}
* "这是一个包含日期:${today()}和当前时间:${sum(1,2)} 的两个公式文本"
*
* @param content 要解析的带有占位符的模板字符串
* @return
*/
public String resolve(String content) {
int start = content.indexOf(this.placeholderPrefix);
if (start == -1) {
return content;
}
int valueIndex = 0;
StringBuilder resultContent = new StringBuilder(content);
while (start != -1) {
int end = resultContent.indexOf(this.placeholderSuffix);
String place = content.substring(start, end + this.placeholderSuffix.length());
String formula = place.replace(this.placeholderPrefix, "").replace(this.placeholderSuffix, "");
Calculator calculator = Calculator.createCalculator();
String value = StringUtils.EMPTY;
try {
Object o = calculator.evalValue(formula);
if (o!=null){
if (o instanceof Date){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
value = format.format(o);
}else {
value =o.toString();
}
}
} catch (UtilEvalError utilEvalError) {
FineLoggerFactory.getLogger().error(utilEvalError,"JSD:>>calculator formula in text error!",utilEvalError.getMessage());
}
resultContent.replace(start, end + this.placeholderSuffix.length(), value);
start = resultContent.indexOf(this.placeholderPrefix, start + value.length());
}
return resultContent.toString();
}
}

35
src/main/java/com/fr/plugin/third/party/jsdjjed/schedule/utils/PropertiesUtils.java

@ -0,0 +1,35 @@
package com.fr.plugin.third.party.jsdjjed.schedule.utils;
import com.fr.io.utils.ResourceIOUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtils {
//获取配置文件
private static Properties getProperties() {
InputStream is = ResourceIOUtils.read("/resources/minxing_push_message.properties");
Properties properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
FineLoggerFactory.getLogger().error("JSD:>>get properties error! ",e.getMessage());
}
return properties;
}
public static String getPro(String key) {
Properties properties = PropertiesUtils.getProperties();
String value = properties.get(key)==null?"":properties.get(key).toString();
if ( StringUtils.isEmpty(value)) {
FineLoggerFactory.getLogger().error("JSD:>>[{}] is null or empty!",key);
}
return value;
}
}

140
src/main/java/com/fr/plugin/third/party/jsdjjed/util/AES.java

@ -0,0 +1,140 @@
package com.fr.plugin.third.party.jsdjjed.util;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class AES {
public final static String ALGORITHM_AEPP = "AES/ECB/PKCS5Padding";
/**
* AES加密
*
* @param content
* 内容
* @param password
* 密钥
* @param algorithm
* 算法
* @return 加密后数据
*/
public static byte[] encrypt(byte[] content, byte[] password, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"));
return cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES解密
*
* @param content
* 加密内容
* @param password
* 密钥
* @param algorithm
* 算法
* @return 解密后数据
*/
public static byte[] decrypt(byte[] content, byte[] password, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"));
byte[] bytes = cipher.doFinal(content);
return bytes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES加密
*
* @param content
* 内容
* @param password
* 密钥
* @param algorithm
* 算法
* @param ivStr
* 向量
* @return 加密后数据
*/
public static byte[] encrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
IvParameterSpec iv = new IvParameterSpec(ivStr);
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
return cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES解密
*
* @param content
* 加密内容
* @param password
* 密钥
* @param algorithm
* 算法
* @param ivStr
* 向量
* @return 解密后数据
*/
public static byte[] decrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
IvParameterSpec iv = new IvParameterSpec(ivStr);
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
byte[] bytes = cipher.doFinal(content);
return bytes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

129
src/main/java/com/fr/plugin/third/party/jsdjjed/util/DateUtil.java

@ -0,0 +1,129 @@
package com.fr.plugin.third.party.jsdjjed.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class DateUtil {
public static final long ONE_HOUR_TIME_LONG = 3600000;
public static String toString(Date date, String format) {
String dateStr = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
dateStr = sdf.format(date);
} catch (Exception e) {
}
return dateStr;
}
public static Date parseDate(String dateStr, String format) {
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
date = sdf.parse(dateStr);
} catch (Exception e) {
}
return date;
}
/**
* 获取日期当天的最小时间日期,0点
*/
public static Date getMinTimeDateByDate(Date date) {
if (date == null)
return null;
String datestr = toString(date, "yyyyMMdd");
return parseDate(datestr, "yyyyMMdd");
}
/**
* 获取日期当天的最大时间日期,12点整
*/
public static Date getMaxTimeDateByDate(Date date) {
if (date == null)
return null;
String datestr = toString(date, "yyyyMMdd");
Date d = parseDate(datestr, "yyyyMMdd");
return new Date(d.getTime() + 24l * 60l * 60l * 1000l - 1l);
}
public static long subTime(Date startDate, Date endDate) {
return endDate.getTime() - startDate.getTime();
}
/**
* 获取上月第一天最早时间
* @return Date
*/
public static Date getLastMonthFirstDay() {
Calendar cal_1 = Calendar.getInstance();// 获取当前日期
cal_1.setTime(getMinTimeDateByDate(new Date()));
cal_1.add(Calendar.MONTH, -1);
cal_1.set(Calendar.DAY_OF_MONTH, 1);
return cal_1.getTime();
}
/**
* 获取上月最后一天最晚时间
* @return Date
*/
public static Date getLastMonthLastDay() {
Calendar cale = Calendar.getInstance();
cale.setTime(getMinTimeDateByDate(new Date()));
cale.add(Calendar.MONTH, -1);
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
return new Date(cale.getTime().getTime() + 1000l * 60l * 60l * 24l - 1l);
}
/**
* 获取本月第一天最早时间
* @return Date
*/
public static Date getNowMonthFirstDay() {
Calendar cal_1 = Calendar.getInstance();// 获取当前日期
cal_1.setTime(getMinTimeDateByDate(new Date()));
cal_1.add(Calendar.MONTH, 0);
cal_1.set(Calendar.DAY_OF_MONTH, 1);
return cal_1.getTime();
}
/**
* 获取本月最后一天最晚时间
* @return Date
*/
public static Date getNowMonthLastDay() {
Calendar cale = Calendar.getInstance();
cale.setTime(getMinTimeDateByDate(new Date()));
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
return new Date(cale.getTime().getTime() + 1000l * 60l * 60l * 24l - 1l);
}
/**
* 获取本月最后一天
* @return Date
*/
public static Date getTheMonthLastDay(Date date) {
if(date == null){
return null;
}
Calendar cale = Calendar.getInstance();
cale.setTime(date);
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
cale.set(Calendar.HOUR, 0);
cale.set(Calendar.HOUR_OF_DAY, 0);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);
return cale.getTime();
}
}

88
src/main/java/com/fr/plugin/third/party/jsdjjed/util/GZIPUtils.java

@ -0,0 +1,88 @@
package com.fr.plugin.third.party.jsdjjed.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class GZIPUtils {
/**
* 数据压缩传输
*
* @param is
* @param os
* @throws Exception
*/
public static void compressTransfe(byte[] bytes, OutputStream out) throws IOException {
GZIPOutputStream gos = null;
try {
gos = new GZIPOutputStream(out);
gos.write(bytes);
gos.finish();
gos.flush();
} finally{
if(gos != null){
gos.close();
}
}
}
/**
* 数据压缩
*
* @param is
* @param os
* @throws Exception
*/
public static byte[] compress(byte[] bytes) throws IOException {
ByteArrayOutputStream out = null;
GZIPOutputStream gos = null;
try {
out = new ByteArrayOutputStream();
gos = new GZIPOutputStream(out);
gos.write(bytes);
gos.finish();
gos.flush();
} finally{
if(gos != null){
gos.close();
}
if(out != null){
out.close();
}
}
return out.toByteArray();
}
/**
* 数据解压
*
* @param in
* @return
* @throws IOException
*/
public static byte[] decompress(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
GZIPInputStream gin = new GZIPInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int count;
byte data[] = new byte[1024];
while ((count = gin.read(data, 0, 1024)) != -1) {
out.write(data, 0, count);
}
out.flush();
out.close();
gin.close();
return out.toByteArray();
}
}

129
src/main/java/com/fr/plugin/third/party/jsdjjed/util/JsonHelper.java

@ -0,0 +1,129 @@
package com.fr.plugin.third.party.jsdjjed.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.util.HashMap;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class JsonHelper {
private static Map<String,Gson> gsons = new HashMap<String, Gson>();
private static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
static {
gsons.put(DEFAULT_DATE_PATTERN, createGson(DEFAULT_DATE_PATTERN));
}
private static Gson createGson(String datePattern){
return new GsonBuilder().setDateFormat(datePattern).disableHtmlEscaping().serializeNulls().create();
}
public static Gson getGson() {
return gsons.get(DEFAULT_DATE_PATTERN);
}
public static Gson getGson(String datePattern) {
Gson gson = gsons.get(datePattern);
if(gson == null){
gson = createGson(datePattern);
gsons.put(datePattern, gson);
}
return gson;
}
public static GsonBuilder newGsonBuilder() {
return new GsonBuilder();
}
/**
* 将对象转换为json串
*
* @param obj
* @return
*/
public static String toJsonString(Object obj) {
if (obj == null) {
return null;
}
return getGson().toJson(obj);
}
/**
* 将对象转换为json串自定义日期转换规则
*
* @param obj
* @param datePattern
* @return
*/
public static String toJsonString(Object obj, String datePattern) {
if (obj == null) {
return null;
}
return getGson(datePattern).toJson(obj);
}
/**
* 将json串转换为对象
*
* @param clazz
* @param jsonString
* @return
*/
public static <T> T fromJson(Class<T> clazz, String jsonString) {
if (jsonString == null) {
return null;
}
return getGson().fromJson(jsonString, clazz);
}
/**
* 将json串转换为对象
*
* @Type type
* @param jsonString
* @return
*/
public static <T> T fromJson(TypeToken<T> token, String jsonString) {
if (jsonString == null) {
return null;
}
return getGson().fromJson(jsonString, token.getType());
}
/**
* 将json串转换为对象
*
* @Type type
* @param jsonString
* @return
*/
public static <T> T fromJson(TypeToken<T> token, String jsonString, String datePattern) {
if (jsonString == null) {
return null;
}
return getGson(datePattern).fromJson(jsonString, token.getType());
}
/**
* 将json串转换为对象
*
* @param clazz
* @param jsonString
* @return
*/
public static <T> T fromJson(Class<T> clazz, String jsonString, String datePattern) {
if (jsonString == null) {
return null;
}
return getGson(datePattern).fromJson(jsonString, clazz);
}
}

51
src/main/java/com/fr/plugin/third/party/jsdjjed/util/Md5.java

@ -0,0 +1,51 @@
package com.fr.plugin.third.party.jsdjjed.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class Md5 {
/**
* MD5
* @param bytes
* @return
*/
public static String md5(byte[] bytes) {
if (bytes == null || bytes.length == 0)
return null;
String s = null;
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
byte tmp[] = md.digest();
char str[] = new char[16 * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
byte byte0 = tmp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
s = new String(str);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return s;
}
/**
* MD5[16位]
*
* @param bytes
* @return
*/
public static String md5For16(byte[] bytes) {
return md5(bytes).substring(8,24);
}
}

451
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpClient.java

@ -0,0 +1,451 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpClient {
/**
* 链接超时时间(s)
*/
private int httpConnectionTimeOut = 30;
/**
* 数据传输超时时间(s)
*/
private int httpReadTimeOut = 30;
public HttpClient() {
}
/**
*
* @param httpConnectionTimeOut
* 链接超时时间(s)
* @param httpReadTimeOut
* 数据传输超时时间(s)
*/
public HttpClient(int httpConnectionTimeOut, int httpReadTimeOut) {
this.httpConnectionTimeOut = httpConnectionTimeOut;
this.httpReadTimeOut = httpReadTimeOut;
}
/**
* 发送HTTP请求
*
* @param request
* 请求
* @param praser
* 响应解析器
* @return T 响应
*/
public <T> T service(HttpRequest<?> request, HttpResponsePraser<T> praser) {
HttpResultCode code = HttpResultCode.SUCCESS;
if (request.getHttpParams().getUrl() == null || request.getHttpParams().getUrl().length() == 0) {
code = HttpResultCode.ERROR_URL_NULL;
return praser.prase(code, 0, null, null, request.getHttpParams().getCharSet(), null);
}
HttpURLConnection conn = null;
int httpCode = 0;
Map<String, String> headers = null;
List<String> cookies = null;
ByteArrayOutputStream outputStream = null;
try {
String realUrl = this.genUrl(request);
conn = this.createConnection(request, realUrl);
this.fillConnection(conn, request);
this.request(conn, request);
httpCode = conn.getResponseCode();
headers = this.getHeaders(conn, request.getHttpParams().getCharSet());
cookies = this.getCookies(conn, request.getHttpParams().getCharSet());
outputStream = this.getResultOutputStream(conn);
} catch (SocketTimeoutException e) {
code = HttpResultCode.ERROR_TIMEOUT;
e.printStackTrace();
} catch (KeyManagementException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (ProtocolException e) {
code = HttpResultCode.ERROR_METHOD;
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
code = HttpResultCode.ERROR_CHARSET;
e.printStackTrace();
} catch (MalformedURLException e) {
code = HttpResultCode.ERROR_URL;
httpCode = 500;
e.printStackTrace();
} catch (IOException e) {
code = HttpResultCode.ERROR_CONNECT;
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (KeyStoreException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (CertificateException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
T t = null;
try {
t = praser.prase(code, httpCode, headers, cookies, request.getHttpParams().getCharSet(), outputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return t;
}
private <T> String genUrl(HttpRequest<T> request) {
if (request.getHttpParams().getMethod().equalsIgnoreCase("GET")) {
String getprams = request.getContentPraser().praseRqeuestContentToString(request.getHttpParams());
if (getprams != null) {
String url = null;
if (request.getHttpParams().getUrl().indexOf("?") > 0) {
url = request.getHttpParams().getUrl() + "&" + getprams;
} else {
url = request.getHttpParams().getUrl() + "?" + getprams;
}
return url;
} else {
return request.getHttpParams().getUrl();
}
} else {
return request.getHttpParams().getUrl();
}
}
/**
* 获取HTTP响应头
*
* @param conn
* @param charSet
* @return
* @throws UnsupportedEncodingException
*/
private Map<String, String> getHeaders(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
Map<String, String> resultHeaders = new HashMap<String, String>();
Map<String, List<String>> header = conn.getHeaderFields();
if (header != null && header.size() > 0) {
for (Entry<String, List<String>> entry : header.entrySet()) {
if (!"Set-Cookie".equalsIgnoreCase(entry.getKey())) {
String valuer = "";
if (entry.getValue() != null && entry.getValue().size() > 0) {
for (String value : entry.getValue()) {
valuer += new String(value.getBytes("ISO-8859-1"), charSet) + ",";
}
valuer = valuer.substring(0, valuer.length() - 1);
}
resultHeaders.put(entry.getKey(), valuer);
}
}
}
return resultHeaders;
}
/**
* 获取HTTP响应Cookies
*
* @param conn
* @param charSet
* @return
* @throws UnsupportedEncodingException
*/
private List<String> getCookies(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
List<String> resultC = new ArrayList<String>();
List<String> cookies = null;
Map<String, List<String>> header = conn.getHeaderFields();
if (header != null && header.size() > 0) {
cookies = header.get("Set-Cookie");
}
if (cookies != null) {
for (String cookie : cookies) {
resultC.add(new String(cookie.getBytes("ISO-8859-1"), charSet));
}
}
return cookies;
}
/**
* 获取HTTP响应数据流
*
* @param conn
* @return
* @throws IOException
*/
private ByteArrayOutputStream getResultOutputStream(HttpURLConnection conn) throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
InputStream is = conn.getInputStream();
try {
if (is != null) {
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
}
} catch (IOException e) {
throw e;
} finally {
if (is != null) {
is.close();
}
}
return outStream;
}
/**
* 发送Http请求
*
* @param conn
* @param request
* @throws IOException
*/
private <T> void request(HttpURLConnection conn, HttpRequest<T> request) throws IOException {
if (request.getHttpParams().getMethod().equalsIgnoreCase("POST")) {
conn.setDoOutput(true);
// conn.connect();
if (request.getHttpParams().getParams() != null) {
byte[] content = request.getContentPraser().praseRqeuestContentToBytes(request.getHttpParams());
fillHeader(conn, "Content-Length", String.valueOf(request.getContentPraser().praseRqeuestContentLength(request.getHttpParams())));
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(content);
out.flush();
out.close();
}
} else {
conn.connect();
}
}
/**
* 添加请求信息
*
* @param conn
* @param request
* @throws ProtocolException
*/
private void fillConnection(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
this.fillTimeout(conn);
this.filleMethod(conn, request);
this.fillHeaders(conn, request);
this.fillCookies(conn, request);
}
/**
* 添加超时时间
*
* @param conn
*/
private void fillTimeout(HttpURLConnection conn) {
if (httpConnectionTimeOut != 0) {
conn.setConnectTimeout(httpConnectionTimeOut * 1000);
}
if (httpReadTimeOut != 0) {
conn.setReadTimeout(httpReadTimeOut * 1000);
}
}
/**
* 指定HTTP方法
*
* @param conn
* @param request
* @throws ProtocolException
*/
private void filleMethod(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
conn.setRequestMethod(request.getHttpParams().getMethod().toUpperCase());
}
/**
* 添加头信息
*
* @param conn
* @param request
*/
private void fillHeaders(HttpURLConnection conn, HttpRequest<?> request) {
if (request.getHttpParams().getHeaders() != null) {
for (Entry<String, String> entry : request.getHttpParams().getHeaders().entrySet()) {
fillHeader(conn, entry.getKey(), entry.getValue());
}
}
}
/**
* 添加头信息
*
* @param conn
* @param request
*/
private void fillHeader(HttpURLConnection conn, String key, String value) {
conn.setRequestProperty(key, value);
}
/**
* 添加Cookies
*
* @param conn
* @param request
*/
private void fillCookies(HttpURLConnection conn, HttpRequest<?> request) {
if (request.getHttpParams().getCookies() != null) {
conn.setRequestProperty("Cookie", request.getHttpParams().getCookies());
}
}
/**
* 创建Http链接
*
* @param request
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws MalformedURLException
* @throws IOException
* @throws CertificateException
* @throws KeyStoreException
* @throws UnrecoverableKeyException
*/
private HttpURLConnection createConnection(HttpRequest<?> request, String realUrl)
throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, IOException, UnrecoverableKeyException, KeyStoreException, CertificateException {
URL console = new URL(realUrl);
HttpURLConnection conn;
if (request.isHttps()) {
conn = genHttpsConn(console, request);
} else {
conn = (HttpURLConnection) console.openConnection();
}
return conn;
}
private HttpURLConnection genHttpsConn(URL console, HttpRequest<?> request)
throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
SSLContext ctx = getSSLContext(request.getHttpsParams());
HttpsURLConnection sconn = (HttpsURLConnection) console.openConnection();
sconn.setSSLSocketFactory(ctx.getSocketFactory());
sconn.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return sconn;
}
/**
* 获得KeyStore.
*
* @param keyStorePath
* 密钥库路径
* @param password
* 密码
* @return 密钥库
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
* @throws Exception
*/
private KeyStore getKeyStore(HttpsParams params) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
// 实例化密钥库 KeyStore用于存放证书,创建对象时 指定交换数字证书的加密标准
// 指定交换数字证书的加密标准
KeyStore ks = KeyStore.getInstance(params.getAlgorithm());
// 获得密钥库文件流
FileInputStream is = new FileInputStream(params.getKeyStorePath());
// 加载密钥库
ks.load(is, params.getPassword().toCharArray());
// 关闭密钥库文件流
is.close();
return ks;
}
/**
* 获得SSLSocketFactory.
*
* @param password
* 密码
* @param keyStorePath
* 密钥库路径
* @param trustStorePath
* 信任库路径
* @return SSLSocketFactory
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws CertificateException
* @throws KeyStoreException
* @throws UnrecoverableKeyException
* @throws KeyManagementException
* @throws Exception
*/
private SSLContext getSSLContext(HttpsParams params) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
// 实例化SSL上下文
SSLContext ctx = SSLContext.getInstance("TLS");
if (params != null) {
// 实例化密钥库 KeyManager选择证书证明自己的身份
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// 实例化信任库 TrustManager决定是否信任对方的证书
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
// 获得密钥库
KeyStore keyStore = getKeyStore(params);
// 初始化密钥工厂
keyManagerFactory.init(keyStore, params.getPassword().toCharArray());
// 获得信任库
KeyStore trustStore = getKeyStore(params);
// 初始化信任库
trustManagerFactory.init(trustStore);
// 初始化SSL上下文
ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
} else {
ctx.init(null, new TrustManager[] { myX509TrustManager }, new SecureRandom());
}
return ctx;
}
private TrustManager myX509TrustManager = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
};
}

94
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequest.java

@ -0,0 +1,94 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequest<T> {
/**
* http参数
*/
private HttpRequestParams<T> httpParams;
/**
* https参数
*/
private HttpsParams httpsParams;
/**
* 内容解析器
*/
private HttpRequestPraser<T> contentPraser;
/**
* 是否https请求
*/
private boolean isHttps;
/**
*
*/
protected HttpRequest() {
}
/**
*
* @param httpParams
* http参数
* @param contentPraser
* 内容解析器
*/
protected HttpRequest(HttpRequestParams<T> httpParams, HttpRequestPraser<T> contentPraser) {
this.httpParams = httpParams;
this.contentPraser = contentPraser;
this.isHttps = false;
}
/**
*
* @param httpParams
* http参数
* @param httpsParams
* https参数
* @param contentPraser
* 内容解析器
*/
protected HttpRequest(HttpRequestParams<T> httpParams, HttpsParams httpsParams, HttpRequestPraser<T> contentPraser) {
this.httpParams = httpParams;
this.httpsParams = httpsParams;
this.contentPraser = contentPraser;
this.isHttps = true;
}
public boolean isHttps() {
return isHttps;
}
public HttpRequestParams<T> getHttpParams() {
return httpParams;
}
public void setHttpParams(HttpRequestParams<T> httpParams) {
this.httpParams = httpParams;
}
public HttpsParams getHttpsParams() {
return httpsParams;
}
public void setHttpsParams(HttpsParams httpsParams) {
this.httpsParams = httpsParams;
}
public HttpRequestPraser<T> getContentPraser() {
return contentPraser;
}
public void setContentPraser(HttpRequestPraser<T> contentPraser) {
this.contentPraser = contentPraser;
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestBytes.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestBytes extends HttpRequest<byte[]> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestBytes(HttpRequestParams<byte[]> httpParams) {
super(httpParams, new HttpRequestPraserBytes());
}
}

22
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestKV.java

@ -0,0 +1,22 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestKV extends HttpRequest<Map<String, String>> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestKV(HttpRequestParams<Map<String, String>> httpParams) {
super(httpParams, new HttpRequestPraserKV());
}
}

67
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestParams.java

@ -0,0 +1,67 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestParams<T> {
private String url;// URL
private String charSet = "UTF-8";// 编码
private String method = "GET";// Http方法
private Map<String, String> headers;// 头信息
private String cookies;// cookie信息
private T params;// 传输数据
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCharSet() {
return charSet;
}
public void setCharSet(String charSet) {
this.charSet = charSet;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
public String getCookies() {
return cookies;
}
public void setCookies(String cookies) {
this.cookies = cookies;
}
public T getParams() {
return params;
}
public void setParams(T params) {
this.params = params;
}
}

40
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraser.java

@ -0,0 +1,40 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public interface HttpRequestPraser<T> {
/**
* 将请求参数转换为String<br/>
* 主要用于get方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public String praseRqeuestContentToString(HttpRequestParams<T> httpParams);
/**
* 将请求参数转换为byte[]<br/>
* 主要用于post方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public byte[] praseRqeuestContentToBytes(HttpRequestParams<T> httpParams);
/**
* 获取请求参数大小<br/>
* 主要用于post方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public int praseRqeuestContentLength(HttpRequestParams<T> httpParams);
}

44
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserBytes.java

@ -0,0 +1,44 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.UnsupportedEncodingException;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserBytes implements HttpRequestPraser<byte[]> {
/**
* 请求内容字符串
*/
private String contentString;
@Override
public String praseRqeuestContentToString(HttpRequestParams<byte[]> httpParams) {
if (contentString != null) {
return contentString;
}
try {
contentString = new String(httpParams.getParams(), httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return contentString;
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<byte[]> httpParams) {
return httpParams.getParams();
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<byte[]> httpParams) {
if (httpParams.getParams() != null) {
return httpParams.getParams().length;
} else {
return 0;
}
}
}

71
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserKV.java

@ -0,0 +1,71 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserKV implements HttpRequestPraser<Map<String, String>> {
/**
* 请求内容byte数组
*/
private byte[] contentBytes;
/**
* 请求内容字符串
*/
private String contentString;
@Override
public String praseRqeuestContentToString(HttpRequestParams<Map<String, String>> httpParams) {
if (contentString != null) {
return contentString;
}
Map<String, String> params = httpParams.getParams();
if (params == null || params.size() == 0) {
return null;
}
StringBuffer buffer = new StringBuffer();
for (Entry<String, String> entry : params.entrySet()) {
if (entry.getValue() != null) {
buffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
}
String param = buffer.toString();
contentString = param.substring(0, param.length() - 1);
return contentString;
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<Map<String, String>> httpParams) {
if (contentBytes != null) {
return contentBytes;
}
String paramStr = praseRqeuestContentToString(httpParams);
if (paramStr == null) {
return null;
}
try {
contentBytes = paramStr.getBytes(httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return contentBytes;
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<Map<String, String>> httpParams) {
praseRqeuestContentToBytes(httpParams);
if (contentBytes != null) {
return contentBytes.length;
} else {
return 0;
}
}
}

46
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestPraserString.java

@ -0,0 +1,46 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.UnsupportedEncodingException;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserString implements HttpRequestPraser<String> {
/**
* 请求内容byte数组
*/
private byte[] contentBytes;
@Override
public String praseRqeuestContentToString(HttpRequestParams<String> httpParams) {
return httpParams.getParams();
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<String> httpParams) {
if (contentBytes != null) {
return contentBytes;
}
try {
contentBytes = httpParams.getParams().getBytes(httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
contentBytes = null;
}
return contentBytes;
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<String> httpParams) {
praseRqeuestContentToBytes(httpParams);
if (contentBytes != null) {
return contentBytes.length;
} else {
return 0;
}
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpRequestString.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpRequestString extends HttpRequest<String> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestString(HttpRequestParams<String> httpParams) {
super(httpParams, new HttpRequestPraserString());
}
}

113
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponse.java

@ -0,0 +1,113 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpResponse<T> {
/**
* Http 结果代码
*/
private HttpResultCode resultCode;
/**
* Http链接Code
*/
private int httpCode;
/**
* Http响应头
*/
private Map<String, String> headers;
/**
* http响应Cookies
*/
private List<String> cookies;
/**
* http字符集
*/
private String charSet;
/**
* http响应数据
*/
private T result;
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponse(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, T result) {
this.resultCode = resultCode;
this.httpCode = httpCode;
this.headers = headers;
this.cookies = cookies;
this.charSet = charSet;
this.result = result;
}
public HttpResultCode getResultCode() {
return resultCode;
}
public void setResultCode(HttpResultCode resultCode) {
this.resultCode = resultCode;
}
public int getHttpCode() {
return httpCode;
}
public void setHttpCode(int httpCode) {
this.httpCode = httpCode;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
public List<String> getCookies() {
return cookies;
}
public void setCookies(List<String> cookies) {
this.cookies = cookies;
}
public String getCharSet() {
return charSet;
}
public void setCharSet(String charSet) {
this.charSet = charSet;
}
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
}

32
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseBytes.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author hujian
* @Date 2020/9/15
* @Description
**/
public class HttpResponseBytes extends HttpResponse<byte[]> {
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponseBytes(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, byte[] result) {
super(resultCode, httpCode, headers, cookies, charSet, result);
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseBytesPraser.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpResponseBytesPraser implements HttpResponsePraser<HttpResponseBytes> {
@Override
public HttpResponseBytes prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream) {
return new HttpResponseBytes(resultCode, httpCode, headers, cookies, charSet, outputStream == null ? null : outputStream.toByteArray());
}
}

32
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponsePraser.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public interface HttpResponsePraser<T> {
/**
* 解析
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public T prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream);
}

33
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseString.java

@ -0,0 +1,33 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpResponseString extends HttpResponse<String> {
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponseString(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, String result) {
super(resultCode, httpCode, headers, cookies, charSet, result);
}
}

30
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResponseStringPraser.java

@ -0,0 +1,30 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpResponseStringPraser implements HttpResponsePraser<HttpResponseString> {
@Override
public HttpResponseString prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream) {
String st = null;
try {
if(outputStream != null){
byte[] resultBytes = outputStream.toByteArray();
st = new String(resultBytes, charSet);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new HttpResponseString(resultCode, httpCode, headers, cookies, charSet, st);
}
}

69
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpResultCode.java

@ -0,0 +1,69 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public enum HttpResultCode {
SUCCESS("成功", "SUCCESS"), //
ERROR_URL_NULL("URL为空", "ERROR-URL-NULL"), //
ERROR_URL("URL访问失败", "ERROR-URL"), //
ERROR_HTTPS_SSL("HTTPS异常", "ERROR-HTTPS-SSL"), //
ERROR_METHOD("HTTP方法无法识别", "ERROR-METHOD"), //
ERROR_CHARSET("编码错误", "ERROR-CHARSET"), //
ERROR_CONNECT("访问失败", "ERROR-CONNECT"), //
ERROR_TIMEOUT("访问超时", "ERROR-TIMEOUT"), //
;
/**
* 名称
*/
private String name;
/**
* 编码
*/
private String code;
private HttpResultCode(String name, String code) {
this.name = name;
this.code = code;
}
public static String findNameByCode(String code) {
for (HttpResultCode oc : HttpResultCode.values()) {
if (oc.getCode().equals(code)) {
return oc.getName();
}
}
return null;
}
public static String findCodeByName(String name) {
for (HttpResultCode oc : HttpResultCode.values()) {
if (oc.getName().equals(name)) {
return oc.getCode();
}
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

47
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsParams.java

@ -0,0 +1,47 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpsParams {
private String password;// 密钥库密钥
private String keyStorePath;// 密钥库文件地址
private String trustStorePath;// 信任库文件地址
private String algorithm;// 指定交换数字证书的加密标准:JKS
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getKeyStorePath() {
return keyStorePath;
}
public void setKeyStorePath(String keyStorePath) {
this.keyStorePath = keyStorePath;
}
public String getTrustStorePath() {
return trustStorePath;
}
public void setTrustStorePath(String trustStorePath) {
this.trustStorePath = trustStorePath;
}
public String getAlgorithm() {
return algorithm;
}
public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}
}

21
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestBytes.java

@ -0,0 +1,21 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestBytes extends HttpRequest<byte[]> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestBytes(HttpRequestParams<byte[]> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserBytes());
}
}

23
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestKV.java

@ -0,0 +1,23 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
import java.util.Map;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestKV extends HttpRequest<Map<String, String>> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestKV(HttpRequestParams<Map<String, String>> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserKV());
}
}

21
src/main/java/com/fr/plugin/third/party/jsdjjed/util/http/HttpsRequestString.java

@ -0,0 +1,21 @@
package com.fr.plugin.third.party.jsdjjed.util.http;
/**
* @Author xx
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestString extends HttpRequest<String> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestString(HttpRequestParams<String> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserString());
}
}

46
src/main/java/com/fr/plugin/third/party/jsdjjed/web/MainFilesComponent.java

@ -0,0 +1,46 @@
package com.fr.plugin.third.party.jsdjjed.web;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
public class MainFilesComponent extends Component {
public static final MainFilesComponent KEY = new MainFilesComponent();
private MainFilesComponent(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
public ScriptPath script(RequestClient client ) {
//如果不需要就直接返回 ScriptPath.EMPTY
return ScriptPath.build("com/fr/plugin/third/party/jsdjadh/main.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
public StylePath style(RequestClient client ) {
//如果不需要就直接返回 StylePath.EMPTY;
//return StylePath.build("com/fr/plugin/jscssinput/demo/demo.css");
return StylePath.EMPTY;
}
/**
* 通过给定的资源过滤器控制是否加载这个资源
* @return 资源过滤器
*/
public Filter filter() {
return new Filter(){
@Override
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjjed/web/MainWebResourceProvider.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjjed.web;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class MainWebResourceProvider extends AbstractWebResourceProvider {
@Override
public Atom attach() {
//在平台主组件加载时添加我们自己的组件
return MainComponent.KEY;
}
@Override
public Atom client() {
//我们自己要引入的组件
return MainFilesComponent.KEY;
}
}

2464
src/main/resources/com/fr/plugin/third/party/jsdjjed/feishu.js

File diff suppressed because it is too large Load Diff

263
src/main/resources/com/fr/plugin/third/party/jsdjjed/message.js

@ -0,0 +1,263 @@
!(function () {
console.log("123");
BI.config("dec.constant.schedule.task.accessory", function (items) {
items.push({
value: 4096,
text: "图片"
})
return items;
});
var jsdjjedTextValueCombo = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-system-extensible-parameter",
labelWidth: 210,
editorWidth: 180,
value: {}
},
render: function () {
var t = this
, e = this.options
, i = e.value;
return {
type: "bi.vertical_adapt",
items: [{
type: "bi.label",
textAlign: "left",
cls: "dec-font-weight-bold",
text: BI.i18nText(i.name),
title: BI.i18nText(i.name),
width: e.labelWidth
}, {
type: "bi.text_value_combo",
$testId: "dec-system-normal-extensible-text-value-combo",
width: e.editorWidth,
value: i.value,
items: this._createItems(i),
ref: function (e) {
t.textValueCombo = e
},
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
t.fireEvent("EVENT_CHANGE", arguments)
}
}]
}, {
type: "dec.text.bubble.combo",
cls: "help-area",
invisible: !i.description,
text: i.description ? BI.i18nText(i.description) : "",
el: {
type: "bi.icon_button",
$point: "dec-system-normal-extensible",
cls: "detail-font",
width: 35,
height: 24
}
}]
}
},
_createItems: function (e) {
return BI.map(e.items || e.alternatives, function (e, t) {
return BI.extend(t, {
text: BI.isKey(t.text) ? t.text : BI.i18nText(t.key)
})
})
},
getValue: function () {
var e = this.textValueCombo.getValue();
return BI.isNotEmptyArray(e) ? e[0] : "";
},
setValue: function (e) {
this.textValueCombo.setValue(e);
},
populate: function (e) {
this.textValueCombo.populate(e);
}
});
jsdjjedTextValueCombo.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("jsdjjed.text.value.combo", jsdjjedTextValueCombo);
var appMessagePushTerminalType = 64;
//debugger;
Dec.Plugin.OutPutActionProvider.items.push({
version: 1.0,
terminalType: appMessagePushTerminalType,
terminalText: BI.i18nText("飞书推送通知"),
getItem: function () {
var self = this;
return {
type: "bi.vertical",
//width: 540,
height: 100,
vgap: 0,
items: [{
type: "jsdjjed.text.value.combo",
labelWidth: 80,
value: {
name: "应用凭证",
value: "",
//description: BI.i18nText("Dec-System_Week_Begins_Tips"),
//items: BI.Constants.getConstant("dec.constant.system.normal.week.begins")
},
ref: function (e) {
self.appConfigIds = e
},
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
var configId = this.getValue();
//console.log(configId);
self._setChatGroupValue(configId);
}
}]
},
{
type: "jsdjjed.text.value.combo",
labelWidth: 80,
value: {
name: "飞书群",
value: "",
//description: BI.i18nText("Dec-System_Week_Begins_Tips"),
//items: BI.Constants.getConstant("dec.constant.system.normal.week.begins")
},
ref: function (e) {
self.chatGroup = e
}
},
{
type: "jsdjjed.text.value.combo",
labelWidth: 80,
value: {
name: "消息类型",
value: "text",
//description: BI.i18nText("Dec-System_Week_Begins_Tips"),
items: [{text: "文本", value: "text"}, {text: "富文本", value: "post"}]
},
ref: function (e) {
self.feishuMsgType = e
}
},
{
type: "jsdjjed.text.value.combo",
labelWidth: 80,
value: {
name: "发送类型",
value: "message",
//description: BI.i18nText("Dec-System_Week_Begins_Tips"),
items: [{text: "消息", value: "message"}, {text: "文件", value: "file"}, {
text: "消息与文件",
value: "message_file"
}]
},
ref: function (e) {
self.feishuSendType = e
}
}
]
}
},
_setChatGroupValue: function (configId) {
var self = this;
var id = configId || "";
Dec.jsdjjed.reqChatGroup({config_id: id}, function (e) {
var items = BI.map(Dec.jsdjjed.getValidItemsData(e), function (e, t) {
return {text: t.show, value: t.chatId};
});
items.unshift({text: "空", value: "empty_group"});
if (BI.isNotEmptyArray(items)) {
var currentChatGroupId = self._getCurrentChatGroupId();
var chatId = self._getItemContainValue(currentChatGroupId, items);
self.chatGroup.populate(items);
self.chatGroup.setValue(chatId);
}
})
},
setValue: function (v) {
//debugger;
if (v.terminal && v.terminal === appMessagePushTerminalType) {
if ((v.feishuMsgType == undefined) || (v.feishuMsgType == null) || (v.feishuMsgType.length <= 0)) {
v.feishuMsgType = "text";
}
if ((v.feishuSendType == undefined) || (v.feishuSendType == null) || (v.feishuSendType.length <= 0)) {
v.feishuSendType = "message";
}
this.value = v;
this.appConfigIds.setValue(v.configId);
this.chatGroup.setValue(v.chatGroupId);
this.feishuMsgType.setValue(v.feishuMsgType);
this.feishuSendType.setValue(v.feishuSendType);
}
},
getValue: function () {
var self = this;
// actionName最后一个点后面的类名要和这个return的json的字段名一致
return {
OutputAppMessagePush: BI.extend(self.value, {
"@class": "com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush",
actionName: "com.fr.plugin.third.party.jsdjjed.schedule.bean.OutputAppMessagePush",
terminal: appMessagePushTerminalType,
configId: self.appConfigIds.getValue(),
chatGroupId: self.chatGroup.getValue(),
feishuMsgType: self.feishuMsgType.getValue(),
feishuSendType: self.feishuSendType.getValue()
})
}
},
checkValid: function () {
return this.getValue() ? true : false;
},
fireEvent: function (v) {
var self = this;
if (v && v == true) {
Dec.jsdjjed.reqAppsByPage({page: 1}, function (e) {
var items = BI.map(Dec.jsdjjed.getValidItemsData(e), function (e, t) {
return {text: t.show, value: t.configId};
});
if (BI.isNotEmptyArray(items)) {
var currentConfigId = self._getCurrentConfigId();
var configId = self._getItemContainValue(currentConfigId, items);
self.appConfigIds.populate(items);
self.appConfigIds.setValue(configId);
self.appConfigIds.fireEvent("EVENT_CHANGE");
}
})
}
},
_getItemContainValue: function (currentValue, items) {
var tempValue = items[0].value;
if (BI.isEmpty(currentValue)) {
return tempValue;
}
for (var i = 0, max = items.length - 1; i <= max; i++) {
if (currentValue == items[i].value) {
return currentValue;
}
}
return tempValue;
},
_getCurrentConfigId() {
var self = this;
if (self.value && self.value.configId) {
return self.value.configId;
}
return "";
},
_getCurrentChatGroupId() {
var self = this;
if (self.value && self.value.chatGroupId) {
return self.value.chatGroupId;
}
return "";
}
});
})();

1
src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/h5-js-sdk-1.5.12.js

File diff suppressed because one or more lines are too long

36
src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/login.html

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>数据决策系统</title>
<script type="text/javascript"
src="/webroot/decision/file?path=/com/fr/plugin/third/party/jsdjjed/sdk/h5-js-sdk-1.5.12.js&type=plain&parser=plain"></script>
<script type="text/javascript"
src="/webroot/decision/file?path=/com/fr/plugin/third/party/jsdjjed/sdk/runworkhelp.js&type=plain&parser=plain"></script>
</head>
<body>
<h2>报表轻应用跳转</h2>
<script type="text/javascript">
var runWorkH5 = new window.runworkHelp.RunWorkH5({
env: "uat",
devUser: "xm",
isLocal: true,
appId: "cli_a227f7a29b38d08f",
appSecret: "nTuZlTPyEV3vS5FW107giffUOQc712K6",
isHrInfo: true
});
runWorkH5.initReady().then(() => {
//debugger;
//console.log(runWorkH5.user.open_id);
if (runWorkH5.user && runWorkH5.user.open_id) {
var state = "";
window.location = "/webroot/decision?login=feishu&light_app_id=" + runWorkH5.user.open_id + "&state=" + state;
}
});
</script>
</body>
</html>

24
src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/runworkhelp.js

File diff suppressed because one or more lines are too long

10
src/main/resources/com/fr/plugin/third/party/jsdjjed/sdk/vconsole.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save