作者 钟来

飞书excel文档操作接口

... ... @@ -111,4 +111,21 @@ public class FeishuUtil {
}
return null;
}
public static String getFeishuExcelSheet(String tenant_access_token,String spreadsheetToken,String ranges,String valueRenderOption,String dateTimeRenderOption,String user_id_type)
{
String url = "https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/"+spreadsheetToken+"/values_batch_get?ranges="+ranges+"&valueRenderOption="+valueRenderOption+"&dateTimeRenderOption="+dateTimeRenderOption+"&user_id_type="+user_id_type;
try {
String str = HttpUtils.get(url, builder -> {
builder.addHeader("Content-Type", "application/json");
builder.addHeader("Authorization", "Bearer " + tenant_access_token);
});
return str;
} catch (IOException e) {
logger.error("查询飞书表数据异常",e);
}
return null;
}
}
... ...
package com.zhonglai.luhui.device.analysis.comm.db.mode;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhonglai.luhui.device.domain.IotThingsModel;
import com.zhonglai.luhui.redis.service.RedisService;
... ... @@ -80,11 +81,15 @@ public class TerminalDataThingsModeService {
*/
public IotThingsModel getIotThingsModel(String mqtt_username,String identifier)
{
if(redisService.hHashKey(deviceTypeKeyPath+mqtt_username,identifier))
{
return JSONObject.parseObject(JSONObject.toJSONString(redisService.hget(deviceTypeKeyPath+mqtt_username,identifier)),IotThingsModel.class);
Object raw = redisService.hget(deviceTypeKeyPath+mqtt_username,identifier);
if (raw == null) return null;
String json;
if (raw instanceof String) {
json = (String) raw;
} else {
json = JSON.toJSONString(raw);
}
return null;
return JSON.parseObject(json, IotThingsModel.class);
}
/**
... ...
... ... @@ -100,6 +100,15 @@ public class TestController {
"}";
}
@ApiOperation("获取飞书excel表格数据")
@RequestMapping(value = "getFeishuExcelSheet")
public String getFeishuExcelSheet(String spreadsheetToken,String ranges,String valueRenderOption,String dateTimeRenderOption,String user_id_type) throws IOException {
String str = FeishuUtil.getFeishuExcelSheet(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),
spreadsheetToken,ranges,valueRenderOption,dateTimeRenderOption,user_id_type);
System.out.println(str);
return str;
}
@ApiOperation("重写Highcharts导出")
@RequestMapping(value = "getFeishuTable")
public void getFeishuTable(HttpServletRequest request, HttpServletResponse response) throws IOException {
... ... @@ -160,14 +169,8 @@ public class TestController {
}
public static void main(String[] args) {
JSONArray sort = new JSONArray();
JSONObject field_name = new JSONObject();
field_name.put("field_name","记录时间");
sort.add(field_name);
Map<String,Object> body = new HashMap<>();
body.put("sort",sort);
String str = FeishuUtil.getFeishuTable(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),"OcUYbxkuCakxYlsbrEUcXyqKnbf","tblo4dUsFjWXAt8U",body);
String str = FeishuUtil.getFeishuExcelSheet(FeishuUtil.gettenant_access_token("cli_a88a14d3b279d01c","Z3hpYKHeR1yR2aiv6Rp0mcnwKvehkzmT"),
"C0JFs1rTchILbEt7Pg3cCnt6ngc","0hZoRZ","ToString","FormattedString","open_id");
System.out.println(str);
}
... ...