动态管理修改及加盟商资格面试
This commit is contained in:
@@ -86,6 +86,18 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<!-- TRTC 生成 userSig 依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.github.tencentyun</groupId>
|
||||
<artifactId>tls-sig-api-v2</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
<!-- OpenPDF -->
|
||||
<dependency>
|
||||
<groupId>com.github.librepdf</groupId>
|
||||
<artifactId>openpdf</artifactId>
|
||||
<version>1.3.30</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -44,6 +44,8 @@ public enum ErrorCodeEnum {
|
||||
USER_GROUP_NAME_EXIST(1021076, "用户分组名称已存在", null),
|
||||
USER_GROUP_NOT_EXIST(1021077, "用户分组不存在", null),
|
||||
GET_INFO_ERROR(1021078, "获取信息异常", null),
|
||||
|
||||
INTERVIEW_ENTER_FAIL(1021101, "进入面试间失败", null),
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import com.lowagie.text.Document;
|
||||
import com.lowagie.text.Font;
|
||||
import com.lowagie.text.Image;
|
||||
import com.lowagie.text.Paragraph;
|
||||
import com.lowagie.text.pdf.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 使用 OpenPDF 封装的 pdf 工具类
|
||||
*/
|
||||
public class PDFUtils {
|
||||
|
||||
private static final int[] A4Size = {595, 842};
|
||||
|
||||
/**
|
||||
* 设置 pdf 背景图片(A4)
|
||||
* 每页都需要单独设置
|
||||
*/
|
||||
public static void setBackgroundImgA4(Document document, Image image) {
|
||||
//图片顶格
|
||||
image.setAbsolutePosition(0, 0);
|
||||
//填满 A4 大小的页面
|
||||
image.scaleAbsolute(A4Size[0], A4Size[1]);
|
||||
document.add(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 pdf 背景图片
|
||||
* 每页都需要单独设置
|
||||
*/
|
||||
public static void setBackgroundImg(Document document, Image image, int width, int height) {
|
||||
//图片顶格
|
||||
image.setAbsolutePosition(0, 0);
|
||||
image.scaleAbsolute(width, height);
|
||||
document.add(image);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文本放在 pdf 的绝对位置上来抠模板(不指定字体,默认为 OpenPDF 自带的 STSong-Light Normal)
|
||||
* @param reader PdfReader 流
|
||||
* @param outputStream 输出流
|
||||
* @param x 左边距
|
||||
* @param y 下边距
|
||||
* @param content 要插入的文本
|
||||
* @param fontSize 字体大小
|
||||
* @param color 文本颜色
|
||||
*/
|
||||
public static void putParagraphAbsolutely(PdfReader reader, OutputStream outputStream, float x, float y, String content, float fontSize, Color color) {
|
||||
try {
|
||||
BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
|
||||
addContent(reader, outputStream, content, x, y, baseFont, fontSize, 0, color);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定字体的文本绝对位置插入方法
|
||||
* @param reader PdfReader 流
|
||||
* @param outputStream 输出流
|
||||
* @param x 左边距
|
||||
* @param y 下边距
|
||||
* @param content 要插入的文本
|
||||
* @param baseFont 字体设置(如果不使用 OpenPDF 自带的字体,就需要将字体文件放在项目路径下)
|
||||
* 自定义字体方式
|
||||
* ttf 字体
|
||||
* 1. BaseFont baseFont = BaseFont.createFont("arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
* ttc 字体(包含了两种字体,所以需要选择 0 或 1)
|
||||
* 2. BaseFont baseFont = BaseFont.createFont("simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
|
||||
* @param fontSize 字体大小
|
||||
* @param fontStyle 字体风格()
|
||||
* NORMAL = 0; BOLD = 1; ITALIC = 2; UNDERLINE = 4; STRIKETHRU = 8; BOLDITALIC = BOLD | ITALIC;
|
||||
* @param color 字体颜色
|
||||
*/
|
||||
public static void putParagraphAbsolutely(PdfReader reader, OutputStream outputStream, float x, float y, String content, BaseFont baseFont, float fontSize, int fontStyle, Color color) {
|
||||
addContent(reader, outputStream, content, x, y, baseFont, fontSize, fontStyle, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入文本的 raw 方法
|
||||
* @param reader PDF 读取流
|
||||
* @param outputStream 输出流
|
||||
* @param content 插入文本
|
||||
* @param x 左边距
|
||||
* @param y 下边距
|
||||
* @param baseFont 字体和编码设置
|
||||
* @param fontSize 字体大小
|
||||
* @param fontStyle 字体风格
|
||||
* @param color 字体颜色
|
||||
*/
|
||||
private static void addContent(PdfReader reader, OutputStream outputStream, String content, float x, float y, BaseFont baseFont, float fontSize, int fontStyle, Color color) {
|
||||
try {
|
||||
//生成 paragraph 并放在正确位置
|
||||
//抠模板
|
||||
PdfStamper stamper = new PdfStamper(reader, outputStream);
|
||||
PdfContentByte over = stamper.getOverContent(1);
|
||||
Font font = new Font(baseFont, fontSize, fontStyle, color);
|
||||
Paragraph insertContent = new Paragraph(content, font);
|
||||
|
||||
ColumnText columnText = new ColumnText(over);
|
||||
// llx 和 urx 最小的值决定离左边的距离. lly 和 ury 最大的值决定离下边的距离
|
||||
columnText.setSimpleColumn(x, y, Float.MAX_VALUE, Float.MIN_VALUE);
|
||||
columnText.addElement(insertContent);
|
||||
columnText.go();
|
||||
stamper.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.lowagie.text.Document;
|
||||
import com.lowagie.text.Image;
|
||||
import com.lowagie.text.pdf.PdfReader;
|
||||
import com.lowagie.text.pdf.PdfWriter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
//生成资格面试通过函的工具
|
||||
public class PassLetterUtils {
|
||||
|
||||
/**
|
||||
* 生成通过函的方法
|
||||
* 返回通过函编码
|
||||
* @param partnerName 加盟商姓名
|
||||
* @param verifyCity 审批城市
|
||||
* @param passTime 审批通过时间
|
||||
*/
|
||||
public static String genPassLetter(String partnerName, String passCode, String verifyCity, DateTime passTime) {
|
||||
String randomNum = RandomUtil.randomNumbers(5);
|
||||
if (ObjectUtil.isEmpty(passCode)) {
|
||||
passCode = "HSAY" + DateUtil.format(passTime, "yyMMdd") + "-" + randomNum;
|
||||
}
|
||||
String passTimeStr = DateUtil.format(passTime, "yyyy年MM月dd日");
|
||||
Document document = new Document();
|
||||
try {
|
||||
//1. 创建 pdf document
|
||||
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
FileOutputStream outputStream = new FileOutputStream("passLetter.pdf");
|
||||
PdfWriter.getInstance(document, outputStream);
|
||||
document.open();
|
||||
|
||||
//2. 添加背景图片
|
||||
Image img = Image.getInstance(PassLetterUtils.class.getResource("/static/passLetterBg.jpg").toString());
|
||||
PDFUtils.setBackgroundImgA4(document, img);
|
||||
document.close();
|
||||
|
||||
//3. 填写通过函模板信息
|
||||
addContentToPdf(partnerName + " 先生/女士", 122, 640);
|
||||
addContentToPdf(passCode, 122, 558);
|
||||
addContentToPdf(verifyCity, 155, 494);
|
||||
addContentToPdf("60天", 135, 450);
|
||||
addContentToPdf(passTimeStr, 393, 152);
|
||||
return passCode;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void addContentToPdf(String content, float x, float y) {
|
||||
try {
|
||||
PdfReader pdfReader = new PdfReader(Files.newInputStream(Paths.get("passLetter.pdf")));
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get("passLetter.pdf"));
|
||||
PDFUtils.putParagraphAbsolutely(pdfReader, outputStream, x, y, content, 20, new Color(255, 82,25));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import com.tencentyun.TLSSigAPIv2;
|
||||
|
||||
/**
|
||||
* 腾讯实时音视频TRTC工具类
|
||||
*/
|
||||
public class TRTCUtils {
|
||||
|
||||
/**
|
||||
* 默认过期时间 30 s
|
||||
*/
|
||||
private static final Long expired = 30L;
|
||||
|
||||
/**
|
||||
* 生成 userSig 用于进入会议
|
||||
* 详见 https://cloud.tencent.com/document/product/647/17275#.E8.B0.83.E8.AF.95.E8.B7.91.E9.80.9A.E9.98.B6.E6.AE.B5.E5.A6.82.E4.BD.95.E8.AE.A1.E7.AE.97-UserSig.EF.BC.9F
|
||||
*/
|
||||
public static String genUserSig(Long sdkAppId, String key, String userId) {
|
||||
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, key);
|
||||
return tlsSigAPIv2.genUserSig(userId, expired);
|
||||
}
|
||||
|
||||
public static String genUserSig(Long sdkAppId, String key, String userId, Long expiredTime) {
|
||||
TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, key);
|
||||
return tlsSigAPIv2.genUserSig(userId, expiredTime);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user