注册卡片消息处理器

于相涌/robot_optimize
YXY 1 year ago
parent 10824d0a70
commit 02ed694178

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

@ -14,8 +14,8 @@
font-size: 24px; font-size: 24px;
text-align: center; text-align: center;
line-height: 30px; line-height: 30px;
padding: 20px 0; /*padding: 10px 0;*/
padding-top: 30px; /*padding-top: 30px;*/
} }
.content_class { .content_class {
@ -24,61 +24,71 @@
margin: 0px 10%; margin: 0px 10%;
} }
table{ table{
height:700px height:620px
} }
.sign { .sign {
margin-left: 70%; position: absolute;
top: 140px;
right: 22px;
/*margin-left: 400px;*/
} }
.bigRow{ .bigRow{
height: 180px; height: 160px;
}
.title{
margin-left: 12%;
width: 550px;
height: auto;
} }
</style> </style>
</head> </head>
<body> <body>
<img class="title" src="title.png" alt="表头"/>
<div class="mybody"> <div class="mybody">
<h1>课程反馈表</h1> <h1>课程反馈表</h1>
<div class="content_class"> <div class="content_class">
<span class="sign">日期: &nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;&nbsp;日</span>
<table border="1" width="600" cellspacing="0" cellpadding="0"> <table border="1" width="600" cellspacing="0" cellpadding="0">
<tr> <tr>
<td>专业 Program</td> <td>&nbsp;专业 Program</td>
<td>${program!}</td> <td>${program!}</td>
<td>学生姓名 Name</td> <td>&nbsp;学生姓名 Name</td>
<td>${studentName!}</td> <td>${studentName!}</td>
</tr> </tr>
<tr> <tr>
<td>上课时间</td> <td>&nbsp;上课时间</td>
<td>${startClassTime!}</td> <td>${startClassTime!}</td>
<td rowspan="2">授课老师 Tutor</td> <td rowspan="2">&nbsp;授课老师 Tutor</td>
<td rowspan="2">${tutor!}</td> <td rowspan="2">${tutor!}</td>
</tr> </tr>
<tr> <tr>
<td>下课时间</td> <td>&nbsp;下课时间</td>
<td>${endClassTime!}</td> <td>${endClassTime!}</td>
</tr> </tr>
<tr colspan="4" class="bigRow"> <tr colspan="4" class="bigRow">
<td>作业完成情况 <br /> <td>&nbsp;作业完成情况 <br />
Feedback</td> &nbsp;Feedback</td>
<td colspan="4"><b>评分 ${feedbackScore}</b><br/>${feedback!}</td> <td colspan="4"><b>评分 ${feedbackScore}</b><br/>${feedback!}</td>
</tr> </tr>
<tr colspan="4" class="bigRow"> <tr colspan="4" class="bigRow">
<td>课堂表现 <br /> <td>&nbsp;课堂表现 <br />
Performance</td> &nbsp;Performance</td>
<td colspan="4"><b>评分 ${performanceScore}</b><br/>${performance!}</td> <td colspan="4"><b>评分 ${performanceScore}</b><br/>${performance!}</td>
</tr> </tr>
<tr colspan="4" class="bigRow"> <tr colspan="4" class="bigRow">
<td>课堂内容 <br /> <td>&nbsp;课堂内容 <br />
Content</td> &nbsp;Content</td>
<td colspan="4">${content!}</td> <td colspan="4">${content!}</td>
</tr> </tr>
<tr colspan="4" class="bigRow"> <tr colspan="4" class="bigRow">
<td>课后作业 <br /> <td>&nbsp;课后作业 <br />
Work</td> &nbsp;Work</td>
<td colspan="4">${work!}</td> <td colspan="4">${work!}</td>
</tr> </tr>
</table> </table>
<span class="sign">学生签字:</span>
</div> </div>
</div> </div>

@ -1,10 +1,7 @@
package com.ruoyi.common.utils; package com.ruoyi.common.utils;
import cn.hutool.core.io.resource.ClassPathResource;
import cn.hutool.core.io.resource.Resource;
import com.itextpdf.text.BaseColor; import com.itextpdf.text.BaseColor;
import com.itextpdf.text.DocumentException; import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image; import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.*; import com.itextpdf.text.pdf.*;
import freemarker.template.Configuration; import freemarker.template.Configuration;
@ -14,7 +11,10 @@ import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.xhtmlrenderer.pdf.ITextRenderer; import org.xhtmlrenderer.pdf.ITextRenderer;
import java.io.*; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Locale; import java.util.Locale;
/** /**
@ -26,7 +26,7 @@ import java.util.Locale;
public class PdfUtils { public class PdfUtils {
private final static String TEMPLATE_BASE_PATH = "/template/";//存放文件模板的地址 private final static String TEMPLATE_BASE_PATH = "/template/";//存放文件模板的地址
private final static String IMG_BASE_PATH = "/photo/";//存放图片文件的地址logo图片、机构公章等 private final static String IMG_BASE_PATH = "photo/";//存放图片文件的地址logo图片、机构公章等
private final static String DEFAULT_FONT = "font/simsun.ttc";//默认字体资源文件([宋体][simsun.ttc] private final static String DEFAULT_FONT = "font/simsun.ttc";//默认字体资源文件([宋体][simsun.ttc]
private final static String ENCODING = "UTF-8";//指定编码 private final static String ENCODING = "UTF-8";//指定编码
@ -45,6 +45,7 @@ public class PdfUtils {
return System.getProperty("user.dir") + "/" + fileName; return System.getProperty("user.dir") + "/" + fileName;
} }
private FileOutputStream getOutputStream(String fileName) throws IOException { private FileOutputStream getOutputStream(String fileName) throws IOException {
String path = getPath(fileName); String path = getPath(fileName);
File file = new File(path); File file = new File(path);
@ -82,6 +83,9 @@ public class PdfUtils {
String html = writer.toString(); String html = writer.toString();
// 把html代码传入渲染器中 // 把html代码传入渲染器中
renderer.setDocumentFromString(html); renderer.setDocumentFromString(html);
String imgUrl = "file:"+templatePath + IMG_BASE_PATH;
renderer.getSharedContext().setBaseURL(imgUrl);
// renderer.getSharedContext().setBaseURL("file:/D:/study/workspace/RuoYi-flowable/ruoyi-admin/target/classes/photo/");
renderer.layout(); renderer.layout();
renderer.createPDF(fileOutputStream, false); renderer.createPDF(fileOutputStream, false);
renderer.finishPDF(); renderer.finishPDF();
@ -132,8 +136,8 @@ public class PdfUtils {
if (picFilePath != null || !"".contentEquals(picFilePath)) { if (picFilePath != null || !"".contentEquals(picFilePath)) {
// 设置图片水印 // 设置图片水印
Image image = Image.getInstance(picFilePath); Image image = Image.getInstance(picFilePath);
image.setAbsolutePosition(100f, 250f); image.setAbsolutePosition(0f, -70f);
image.scaleAbsolute(500, 500); // 自定义大小 image.scaleAbsolute(650, 900); // 自定义大小
watermark.setGState(gs); // 设置透明度 watermark.setGState(gs); // 设置透明度
watermark.addImage(image); // 添加水印图片 watermark.addImage(image); // 添加水印图片
} }

@ -0,0 +1,61 @@
package com.ruoyi.flyingbook.LarkHelper;
import com.lark.oapi.service.drive.v1.enums.ParentTypeEnum;
import com.lark.oapi.service.drive.v1.model.UploadAllFileReq;
import com.lark.oapi.service.drive.v1.model.UploadAllFileReqBody;
import com.lark.oapi.service.drive.v1.model.UploadAllFileResp;
import com.lark.oapi.service.drive.v1.model.UploadAllFileRespBody;
import com.ruoyi.flyingbook.domain.lark.LarkFileRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.File;
/**
* @author yuxiangyong
* @create 2023-03-12 18:10
*/
@Slf4j
@Component
public class LarkFileHelper extends LarkHelper {
public static void main(String[] args) throws Exception {
LarkFileHelper fileHelper = new LarkFileHelper();
LarkFileRequest fileRequest = new LarkFileRequest(appId, secret, new File(""), "text.pdf", 1024,"adwd");
UploadAllFileRespBody resp = fileHelper.uploadFile(fileRequest);
int i = 0;
}
/**
*
* @return
*/
public UploadAllFileRespBody uploadFile(LarkFileRequest request) {
try {
UploadAllFileResp uploadAllFileResp = buildClient(request)
.drive()
.file()
.uploadAll(
UploadAllFileReq.newBuilder()
.uploadAllFileReqBody(
UploadAllFileReqBody.newBuilder()
.file(request.getFile())
.fileName(request.getFileName())
.parentNode(request.getParentNode())
.parentType(ParentTypeEnum.EXPLORER.getValue())
.size(request.getFileSize())
.build()
)
.build()
);
if (uploadAllFileResp.getCode() == 0){
return uploadAllFileResp.getData();
}else {
throw new RuntimeException(uploadAllFileResp.getMsg());
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
}

@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
@Slf4j @Slf4j
@ -27,12 +29,12 @@ public class EdiController extends BaseController {
/** /**
* *
*/ */
// @PostMapping("/sync2Table") @PostMapping("/sync2Table")
// public EdiResponseVo sync2Table(@RequestBody SyncToTableRequest request) { public EdiResponseVo sync2Table(@RequestBody SyncToTableRequest request) {
// return ediOperateService.sync2Table(request); return ediOperateService.sync2Table(request);
// } }
@RequestMapping("sync2Table") @RequestMapping("/createPdf")
public void exportPdfDemo(@RequestParam("param")String param) throws Exception{ public void exportPdfDemo(@RequestParam("param")String param) throws Exception{
CourseFeedbackTemplateDto resultDTO = new CourseFeedbackTemplateDto(); CourseFeedbackTemplateDto resultDTO = new CourseFeedbackTemplateDto();
resultDTO.setProgram("program"); resultDTO.setProgram("program");

@ -1,46 +0,0 @@
package com.ruoyi.flyingbook.controller;
import com.lark.oapi.service.drive.v1.DriveService;
import com.lark.oapi.service.drive.v1.model.P2FileBitableFieldChangedV1;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.event.EventDispatcher;
import com.lark.oapi.sdk.servlet.ext.ServletAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@RestController
public class EventControllers {
//1. 注册消息处理器
private final EventDispatcher EVENT_DISPATCHER = EventDispatcher.newBuilder("xJJE7c2rlHzDCk2uPZk77fQNJFtXgTW3",
"ND2ANZB8F7NplUqcrmKD530lDRFssNWJ")
.onP2FileBitableFieldChangedV1(new DriveService.P2FileBitableFieldChangedV1Handler(){
@Override
public void handle(P2FileBitableFieldChangedV1 p2FileBitableFieldChangedV1) throws Exception {
System.out.println(Jsons.DEFAULT.toJson(p2FileBitableFieldChangedV1));
System.out.println(p2FileBitableFieldChangedV1.getRequestId());
}
})
.build();
//2. 注入 ServletAdapter 实例
@Autowired
private ServletAdapter servletAdapter;
//3. 创建路由处理器
@PostMapping("/approval2")
public void event(HttpServletRequest request, HttpServletResponse response)
throws Throwable {
//3.1 回调扩展包提供的事件回调处理器
servletAdapter.handleEvent(request, response, EVENT_DISPATCHER);
}
}

@ -0,0 +1,40 @@
package com.ruoyi.flyingbook.controller;
import com.alibaba.fastjson.JSONObject;
import com.lark.oapi.card.CardActionHandler;
import com.lark.oapi.card.model.CardAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.sdk.servlet.ext.ServletAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j
@RestController
public class RobotController {
//1. 注册卡片处理器
private final CardActionHandler CARD_ACTION_HANDLER = CardActionHandler.newBuilder("xJJE7c2rlHzDCk2uPZk77fQNJFtXgTW3", "ND2ANZB8F7NplUqcrmKD530lDRFssNWJ",
new CardActionHandler.ICardHandler() {
@Override
public Object handle(CardAction cardAction) {
System.out.println(JSONObject.toJSONString(cardAction));
return cardAction.getChallenge();
}
}).build();
@Autowired
private ServletAdapter servletAdapter;
//3. 注册服务路由
@RequestMapping("/robot/callback")
public void card(HttpServletRequest request, HttpServletResponse response)
throws Throwable {
//3.1 回调扩展包卡片行为处理回调
servletAdapter.handleCardAction(request, response, CARD_ACTION_HANDLER);
}
}

@ -0,0 +1,31 @@
package com.ruoyi.flyingbook.domain.lark;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.File;
import java.util.Date;
import java.util.List;
/**
* @author yuxiangyong
* @create 2023-03-18 1:05
*/
@Data
@NoArgsConstructor
public class LarkFileRequest extends LarkRequest{
private File file;
private String fileName;
private Integer fileSize;
private String parentNode;
public LarkFileRequest(String appId, String appSecret, File file, String fileName, Integer fileSize, String parentNode) {
super(appId, appSecret);
this.file = file;
this.fileName = fileName;
this.fileSize = fileSize;
this.parentNode = parentNode;
}
}

@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求 // 过滤请求
.authorizeRequests() .authorizeRequests()
// 对于登录login 验证码captchaImage 允许匿名访问 // 对于登录login 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/captchaImage", "/approval","/syncEmail","/scheduledReminders", "/approval2", "/sync2Table").anonymous() .antMatchers("/login", "/captchaImage", "/approval","/syncEmail","/scheduledReminders", "/approval2", "/sync2Table", "/createPdf").anonymous()
.antMatchers( .antMatchers(
HttpMethod.GET, HttpMethod.GET,
"/*.html", "/*.html",

Loading…
Cancel
Save