作者 钟来

添加飞书参数条件查询

1 package com.ruoyi.common.utils; 1 package com.ruoyi.common.utils;
2 2
  3 +import com.alibaba.fastjson.JSONArray;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
4 import com.google.gson.JsonObject; 5 import com.google.gson.JsonObject;
5 import com.ruoyi.common.utils.html.HttpUtils; 6 import com.ruoyi.common.utils.html.HttpUtils;
@@ -86,14 +87,23 @@ public class FeishuUtil { @@ -86,14 +87,23 @@ public class FeishuUtil {
86 } 87 }
87 } 88 }
88 89
89 - public static String getFeishuTable( String tenant_access_token,String app_token, String table_id) 90 + public static String getFeishuTable( String tenant_access_token,String app_token, String table_id,Map<String,Object> body)
90 { 91 {
91 String url = "https://open.feishu.cn/open-apis/bitable/v1/apps/"+app_token+"/tables/"+table_id+"/records/search"; 92 String url = "https://open.feishu.cn/open-apis/bitable/v1/apps/"+app_token+"/tables/"+table_id+"/records/search";
92 try { 93 try {
  94 +
93 Response response = HttpUtils.postJsonBody(url, builder -> { 95 Response response = HttpUtils.postJsonBody(url, builder -> {
94 builder.addHeader("Content-Type", "application/json"); 96 builder.addHeader("Content-Type", "application/json");
95 - builder.addHeader("Authorization", "Bearer "+tenant_access_token);  
96 - }, null); 97 + builder.addHeader("Authorization", "Bearer " + tenant_access_token);
  98 + }, jsonObject -> {
  99 + if(null != body && body.size() > 0)
  100 + {
  101 + for(String key : body.keySet())
  102 + {
  103 + jsonObject.put(key,body.get(key));
  104 + }
  105 + }
  106 + });
97 String str = response.body().string(); 107 String str = response.body().string();
98 return str; 108 return str;
99 } catch (IOException e) { 109 } catch (IOException e) {
1 package com.zhonglai.luhui.api.controller.test; 1 package com.zhonglai.luhui.api.controller.test;
2 2
  3 +import com.alibaba.fastjson.JSONArray;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
4 import com.google.gson.JsonObject; 5 import com.google.gson.JsonObject;
5 import com.ruoyi.common.core.domain.AjaxResult; 6 import com.ruoyi.common.core.domain.AjaxResult;
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.*; @@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
14 import javax.servlet.http.HttpServletRequest; 15 import javax.servlet.http.HttpServletRequest;
15 import java.io.IOException; 16 import java.io.IOException;
16 import java.util.Enumeration; 17 import java.util.Enumeration;
  18 +import java.util.HashMap;
17 import java.util.Map; 19 import java.util.Map;
18 20
19 @Api(tags = "测试") 21 @Api(tags = "测试")
@@ -76,8 +78,8 @@ public class TestController { @@ -76,8 +78,8 @@ public class TestController {
76 78
77 @ApiOperation("获取飞书多维表格数据") 79 @ApiOperation("获取飞书多维表格数据")
78 @RequestMapping(value = "getFeishuTable/{app_token}/{table_id}") 80 @RequestMapping(value = "getFeishuTable/{app_token}/{table_id}")
79 - public String getFeishuTable(@PathVariable String app_token, @PathVariable String table_id) throws IOException {  
80 - String str = FeishuUtil.getFeishuTable(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),app_token,table_id); 81 + public String getFeishuTable(@PathVariable String app_token, @PathVariable String table_id,@RequestBody HashMap<String,Object> map) throws IOException {
  82 + String str = FeishuUtil.getFeishuTable(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),app_token,table_id,map);
81 if(null != str) 83 if(null != str)
82 { 84 {
83 return str; 85 return str;
@@ -89,10 +91,15 @@ public class TestController { @@ -89,10 +91,15 @@ public class TestController {
89 } 91 }
90 92
91 public static void main(String[] args) { 93 public static void main(String[] args) {
92 - String jsr= "{\"store_id\":0,\"create_time\":\"1746668144\",\"gender\":\"未知\",\"action_type\":3,\"telephone\":\"18061271693\",\"promotion_id\":0,\"clue_source\":5,\"store_pack_id\":0,\"refer_dy_id\":\"2046931013\",\"app_name\":\"暂未获取到\",\"ad_id\":\"0\",\"module_id\":\"1805421364269097\",\"flow_type\":1,\"name\":\"未命名\",\"site_id\":\"0\",\"remark_dict\":{},\"adv_id\":\"0\",\"clue_type\":2,\"location\":\"山东+泰安\",\"id\":\"7501883876034215974\",\"module_name\":\"官方电话\",\"clue_convert_status\":\"外部流量\",\"refer_dy_name\":\"鱼儿乐>智慧渔业系统\"}";  
93 - ClueData clueData = GsonConstructor.get().fromJson(jsr, ClueData.class);  
94 - System.out.println(clueData);  
95 - subData(clueData); 94 + JSONArray sort = new JSONArray();
  95 + JSONObject field_name = new JSONObject();
  96 + field_name.put("field_name","记录时间");
  97 + sort.add(field_name);
  98 +
  99 + Map<String,Object> body = new HashMap<>();
  100 + body.put("sort",sort);
  101 + String str = FeishuUtil.getFeishuTable(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),"OcUYbxkuCakxYlsbrEUcXyqKnbf","tblo4dUsFjWXAt8U",body);
  102 + System.out.println(str);
96 } 103 }
97 104
98 private static void subData(ClueData clueData) 105 private static void subData(ClueData clueData)