You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.2 KiB
91 lines
3.2 KiB
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; |
|
} |
|
}
|
|
|