Commit b67407bb by weiss

1

1 parent 1c8ae510
......@@ -25,8 +25,7 @@ public class FeiShuConfig {
private String verificationToken;
private String appId;
private String appSecret;
private String fkChatId;
private String fkChatIdTest;
private String ChatId;
private String tableId;
private String peopleTableId;
......
......@@ -82,34 +82,34 @@ public class FeiShuApiService {
return responseEntity.getBody().get("tenant_access_token").toString();
}
/**
* @param /https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create
* @param sendMsg
* @return
*/
public JSONObject sendMsg(String receive_id_type, JSONObject sendMsg) {
System.out.println(sendMsg.toString());
//发送消息
String api = "/im/v1/messages?receive_id_type={receive_id_type}";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken());
headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> requestEntity = new HttpEntity<>(sendMsg.toString(), headers);
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try {
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class, receive_id_type);
if (responseEntity.getBody().getJSONObject("data") == null) {
return null;
}
log.info("消息发送成功,接收人: {}", sendMsg.getString("receive_id"));
return responseEntity.getBody();
} catch (Exception e) {
log.error("飞书:" + api + "接口调用失败" + "\n" + e);
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
// /**
// * @param /https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create
// * @param sendMsg
// * @return
// */
// public JSONObject sendMsg(String receive_id_type, JSONObject sendMsg) {
// System.out.println(sendMsg.toString());
//
// //发送消息
// String api = "/im/v1/messages?receive_id_type={receive_id_type}";
// RestTemplate restTemplate = new RestTemplate();
// HttpHeaders headers = new HttpHeaders();
// headers.set("Authorization", "Bearer " + getTenantToken());
// headers.set("Content-Type", "application/json; charset=utf-8");
// HttpEntity<String> requestEntity = new HttpEntity<>(sendMsg.toString(), headers);
// String url = feiShuConfig.getFeiShuOpenApiHost() + api;
// try {
// ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class, receive_id_type);
// if (responseEntity.getBody().getJSONObject("data") == null) {
// return null;
// }
// log.info("消息发送成功,接收人: {}", sendMsg.getString("receive_id"));
// return responseEntity.getBody();
// } catch (Exception e) {
// log.error("飞书:" + api + "接口调用失败" + "\n" + e);
// throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
// }
// }
@Async
......
package com.pipihelper.project.feishu.service.massage;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.utils.GraphicsGenerationUtil;
......@@ -12,6 +13,8 @@ import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -29,11 +32,11 @@ public class MassageMsgCardSerivce {
private FeiShuApiService feiShuApiService;
public String genMassageMsgCardForCompany(){
public String genMassageMsgCardForCompany(List<List<String>> pushUser){
try {
String[][] tableData2 = {{"序号","姓名","部门","时间段","签到"},
{"1","柳双武","技术","15:00-16:00",""}};
byte[] bufferedImage = GraphicsGenerationUtil.bufferedImageToByte(tableData2);
List<String> title = Arrays.asList("序号","姓名","部门","时间段","签到");
pushUser.add(0,title);
byte[] bufferedImage = GraphicsGenerationUtil.bufferedImageToByte(pushUser);
//将图片上传
String imgKey = feiShuApiService.uploadFile("stream", "massageEmployee", null, bufferedImage);
String fileName = String.format("/templates/massage-msg-card.json");
......
package com.pipihelper.project.feishu.service.massage;
import com.pipihelper.project.feishu.bo.PushPainBO;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.service.FeiShuApiService;
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.util.ArrayList;
import java.util.List;
/**
* @Description: TODO
* @author: charles
......@@ -21,10 +27,29 @@ public class MassageService {
@Autowired
private FeiShuApiService feiShuApiService;
public void sendMassageMsgCardToPiPiChat(List<>){
@Autowired
private FeiShuConfig feiShuConfig;
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList){
List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){
List<String> user = new ArrayList<>();
//给单个用户发送
//构建给大群发送的名单
user.add(pushPainBO.getIndex().toString());
user.add(pushPainBO.getName());
user.add(pushPainBO.getDepartMentName());
user.add(pushPainBO.getTimeRange());
user.add("");
pushUser.add(user);
}
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content);
feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId());
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
}
......
......@@ -5,6 +5,7 @@ import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.util.List;
/**
* @Description: TODO
......@@ -14,17 +15,17 @@ import java.io.FileOutputStream;
public class GraphicsGenerationUtil {
/**
* 生成图片
* @param cellsValue 以二维数组形式存放 表格里面的值
* @param data 以二维数组形式存放 表格里面的值
*/
public static BufferedImage graphicsGeneration(String cellsValue[][]) {
public static BufferedImage graphicsGeneration(List<List<String>> data) {
// 字体大小
int fontTitileSize = 15;
// 横线的行数
int totalrow = cellsValue.length+1;
int totalrow = data.size()+1;
// 竖线的行数
int totalcol = 0;
if (cellsValue[0] != null) {
totalcol = cellsValue[0].length;
if (data.get(0) != null) {
totalcol = data.get(0).size();
}
// 图片宽度
int imageWidth = 1024;
......@@ -61,8 +62,8 @@ public class GraphicsGenerationUtil {
String title = "【指标完成进度】";
graphics.drawString(title, startWidth, startHeight+rowheight-10);
//写入内容
for(int n=0;n<cellsValue.length;n++){
for(int l=0;l<cellsValue[n].length;l++){
for(int n=0;n< data.size();n++){
for(int l = 0; l< data.get(n).size(); l++){
if (n == 0) {
font = new Font("微软雅黑",Font.BOLD,fontTitileSize);
graphics.setFont(font);
......@@ -75,7 +76,7 @@ public class GraphicsGenerationUtil {
graphics.setFont(font);
graphics.setColor(Color.BLACK);
}
graphics.drawString(cellsValue[n][l].toString(), startWidth+colwidth*l+5, startHeight+rowheight*(n+2)-10);
graphics.drawString(data.get(n).get(l).toString(), startWidth+colwidth*l+5, startHeight+rowheight*(n+2)-10);
}
}
return image;
......@@ -83,11 +84,11 @@ public class GraphicsGenerationUtil {
/**
* 将图片保存到指定位置
* @param cellsValue 表格数据
* @param data 表格数据
* @param fileLocation 文件位置
*/
public static void createImage(String cellsValue[][], String fileLocation) {
BufferedImage image = graphicsGeneration(cellsValue);
public static void createImage(List<List<String>> data, String fileLocation) {
BufferedImage image = graphicsGeneration(data);
try {
FileOutputStream fos = new FileOutputStream(fileLocation);
ImageIO.write(image,"png", fos);
......@@ -100,11 +101,11 @@ public class GraphicsGenerationUtil {
/**
* 将图片转byte
* @param cellsValue 表格数据
* @param data 表格数据
*/
public static byte[] bufferedImageToByte(String cellsValue[][]) {
public static byte[] bufferedImageToByte(List<List<String>> data) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedImage image = graphicsGeneration(cellsValue);
BufferedImage image = graphicsGeneration(data);
try {
ImageIO.write(image,"png", byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
......
......@@ -15,7 +15,7 @@ feishu:
verificationToken: ChUEDdWQbyHpHUV6H5fVeL5fOP3HfBE6
appId: cli_a3c2be2801f8500d
appSecret: bw3ZXzSj47DgHT19YT268bcwYVVnRTZD
fkChatId: oc_5124ee21dbdecf5d802f9e9e33dab722
ChatId: oc_5124ee21dbdecf5d802f9e9e33dab722
# 腾讯云配置参数
tx:
......
......@@ -15,7 +15,7 @@ feishu:
verificationToken: iFeLGB7JZQV37zDjIFTw0dUQ0QfFlkm5
appId: cli_a3c0cb967f619013
appSecret: NdqjzD2Bkaif6HyU8KCXGbFJzDhEEimt
fkChatId: oc_5124ee21dbdecf5d802f9e9e33dab722
ChatId: oc_5124ee21dbdecf5d802f9e9e33dab722
# 腾讯云配置参数
tx:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!