MassageMsgCardSerivce.java
2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.pipihelper.project.feishu.service.massage;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.utils.GraphicsGenerationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @Description: TODO
* @author: charles
* @date: 2022年10月15日 16:17
*/
@Service
@Transactional
@Slf4j
public class MassageMsgCardSerivce {
@Autowired
private FeiShuApiService feiShuApiService;
public String genMassageMsgCardForCompany(){
try {
String[][] tableData2 = {{"序号","姓名","部门","时间段","签到"},
{"1","柳双武","技术","15:00-16:00",""}};
byte[] bufferedImage = GraphicsGenerationUtil.bufferedImageToByte(tableData2);
//将图片上传
String imgKey = feiShuApiService.uploadFile("stream", "massageEmployee", null, bufferedImage);
String fileName = String.format("/templates/massage-msg-card.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName), imgKey);
return msgCardContent;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 读取模板文件
* @param file
* @return
*/
public String getInteractiveCardStr(String file){
try {
InputStream in = this.getClass().getResourceAsStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(in);
Stream<String> streamOfString= new BufferedReader(inputStreamReader).lines();
String streamToString = streamOfString.collect(Collectors.joining());
return streamToString;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}