Commit b67407bb by weiss

1

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