修改了同步视频2
This commit is contained in:
parent
f2ede0d149
commit
4930e7245f
BIN
cert.png
BIN
cert.png
Binary file not shown.
|
Before Width: | Height: | Size: 165 KiB After Width: | Height: | Size: 216 KiB |
@ -164,16 +164,16 @@ public class UserController extends BaseController {
|
||||
@GetMapping("/user/test")
|
||||
public Response<T> getUser() {
|
||||
try {
|
||||
// byte[] qrCodeByte = new byte[0];
|
||||
//
|
||||
// // 生成证书
|
||||
// String avt = "src/main/resources/static/cert/avt.png";
|
||||
// String sealPath = "src/main/resources/static/cert/seal.png";
|
||||
// String certificateNo = "GDXZALK" + String.valueOf(Year.now().getValue()) + "123456";
|
||||
// String name = "吴从兴";
|
||||
// String content = "您的案例《儿童肾上腺危象一例》经评议,被肝胆相照临床病例库收录,特发此";
|
||||
//
|
||||
// certService.createCert(avt,sealPath,certificateNo,name,content,qrCodeByte);
|
||||
byte[] qrCodeByte = new byte[0];
|
||||
|
||||
// 生成证书
|
||||
String avt = "src/main/resources/static/cert/avt.png";
|
||||
String sealPath = "src/main/resources/static/cert/seal.png";
|
||||
String certificateNo = "GDXZALK" + String.valueOf(Year.now().getValue()) + "123456";
|
||||
String name = "吴从兴";
|
||||
String content = "您的案例《儿童肾上腺危象一例》经评议,被肝胆相照临床病例库收录,特发此";
|
||||
|
||||
certService.createCertTest(sealPath,certificateNo,name,content);
|
||||
|
||||
// 生成用户分享二维码-文章/视频
|
||||
// userService.CreateUserCaseClinicalContentUnlimitedQrcode(String.valueOf(1),1);
|
||||
|
||||
@ -76,7 +76,7 @@ public class WxMaServiceUtils {
|
||||
int width = 430;
|
||||
boolean autoColor = true;
|
||||
WxMaCodeLineColor lineColor = new WxMaCodeLineColor();
|
||||
boolean isHyaline = false;
|
||||
boolean isHyaline = true;
|
||||
|
||||
try {
|
||||
WxMaQrcodeService qrcodeService = wxMaService.getQrcodeService();
|
||||
|
||||
@ -856,16 +856,25 @@ public class CaseClinicalVideoService {
|
||||
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,lastPushDate);
|
||||
|
||||
// 生成用户证书-文章/视频
|
||||
if(qrCodeByte == null){
|
||||
// 下载二维码图片
|
||||
if (qrCodeByte == null || qrCodeByte.length == 0) {
|
||||
// 生成二维码图片
|
||||
if (caseClinicalVideo.getShareQrcode() == null){
|
||||
throw new BusinessException("-1", "无法完成此操作");
|
||||
try {
|
||||
// 生成用户分享二维码-文章/视频
|
||||
qrCodeByte = userService.CreateUserCaseClinicalUnlimitedQrcode(String.valueOf(caseClinicalVideo.getVideoId()),2);
|
||||
} catch (Exception e) {
|
||||
// 不处理
|
||||
throw new BusinessException("-1", "无法完成此操作");
|
||||
}
|
||||
}else{
|
||||
// 下载二维码图片
|
||||
qrCodeByte = Oss.getObjectToByte(caseClinicalVideo.getShareQrcode().replaceFirst("^/+", ""));
|
||||
if (qrCodeByte == null) {
|
||||
throw new BusinessException("-1", "无法完成此操作");
|
||||
}
|
||||
}
|
||||
|
||||
qrCodeByte = Oss.getObjectToByte(caseClinicalVideo.getShareQrcode().replaceFirst("^/+", ""));
|
||||
if (qrCodeByte == null) {
|
||||
throw new BusinessException("-1", "无法完成此操作");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 下载头像
|
||||
|
||||
@ -88,8 +88,8 @@ public class CertService {
|
||||
|
||||
// 6. 添加小程序二维码
|
||||
BufferedImage wechatMa = ImageIO.read(new ByteArrayInputStream(qrCodeByte));
|
||||
wechatMa = resize(wechatMa, 264, 264); // 调整印章大小
|
||||
g2d.drawImage(wechatMa, 645, 1150, null);
|
||||
wechatMa = resize(wechatMa, 205, 205); // 调整印章大小
|
||||
g2d.drawImage(wechatMa, 80, 1450, null);
|
||||
|
||||
// 释放资源
|
||||
g2d.dispose();
|
||||
@ -110,7 +110,7 @@ public class CertService {
|
||||
if (uploaded) {
|
||||
// 返回可访问的 URL(假设你有自定义域名)
|
||||
// 格式:http://你的域名/文件名
|
||||
return fileName;
|
||||
return "/" + fileName;
|
||||
}
|
||||
|
||||
// // 保存最终的证书图片
|
||||
@ -123,6 +123,104 @@ public class CertService {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 生成证书
|
||||
public String createCertTest(
|
||||
String sealPath,
|
||||
String certificateNo,
|
||||
String name,
|
||||
String content
|
||||
){
|
||||
try {
|
||||
// 加载背景模板图片
|
||||
BufferedImage background = ImageIO.read(new File("src/main/resources/static/cert/template.png"));
|
||||
|
||||
Graphics2D g2d = (Graphics2D) background.getGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
// 1. 添加证书编号
|
||||
Font font = new Font("Microsoft YaHei", Font.PLAIN, 40); // 可根据模板调整大小
|
||||
g2d.setFont(font);
|
||||
|
||||
Color customColor = Color.decode("#008983");
|
||||
g2d.setColor(customColor);
|
||||
g2d.drawString(certificateNo, 285, 570);
|
||||
|
||||
// 2. 处理并添加头像
|
||||
BufferedImage avatar = ImageIO.read(new File("src/main/resources/static/cert/avt.png"));
|
||||
int size = 116; // 目标大小
|
||||
BufferedImage circleAvatar = createCircularImage(avatar, size);
|
||||
g2d.drawImage(circleAvatar, 465, 620, null);
|
||||
|
||||
// 3. 添加姓名
|
||||
font = new Font("Microsoft YaHei", Font.PLAIN, 40); // 可根据模板调整大小
|
||||
g2d.setFont(font);
|
||||
|
||||
customColor = Color.decode("#111827");
|
||||
g2d.setColor(customColor);
|
||||
g2d.drawString(name, 465, 790);
|
||||
|
||||
// 4. 添加证书内容
|
||||
font = new Font("Microsoft YaHei", Font.PLAIN, 48); // 可根据模板调整大小
|
||||
g2d.setFont(font);
|
||||
|
||||
customColor = Color.decode("#111827");
|
||||
g2d.setColor(customColor);
|
||||
drawStringWithLineBreak(g2d, content, 185, 880, 700, font); // 自动换行绘制文本
|
||||
|
||||
// 5. 添加日期
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||
String currentDate = sdf.format(new Date());
|
||||
|
||||
font = new Font("Microsoft YaHei", Font.PLAIN, 34); // 可根据模板调整大小
|
||||
g2d.setFont(font);
|
||||
|
||||
customColor = Color.decode("#111827");
|
||||
g2d.setColor(customColor);
|
||||
g2d.drawString(currentDate, 700, 1277);
|
||||
|
||||
// 6. 添加印章
|
||||
BufferedImage seal = ImageIO.read(new File(sealPath));
|
||||
seal = resize(seal, 264, 264); // 调整印章大小
|
||||
g2d.drawImage(seal, 645, 1150, null);
|
||||
|
||||
// 6. 添加小程序二维码
|
||||
BufferedImage wechatMa = ImageIO.read(new File("src/main/resources/static/cert/weChatMa.png"));
|
||||
wechatMa = resize(wechatMa, 205, 205); // 调整印章大小
|
||||
g2d.drawImage(wechatMa, 80, 1450, null);
|
||||
|
||||
// 释放资源
|
||||
g2d.dispose();
|
||||
|
||||
// === 将图片转为 byte[] ===
|
||||
// ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
// ImageIO.write(background, "png", os);
|
||||
// byte[] imageBytes = os.toByteArray();
|
||||
//
|
||||
// String fileName = "";
|
||||
// if (Objects.equals(envConfig.getActive(), "dev")){
|
||||
// fileName = "dev/static/images/" + certificateNo + ".png";
|
||||
// }else{
|
||||
// fileName = "prod/static/images/" + certificateNo + ".png";
|
||||
// }
|
||||
//
|
||||
// boolean uploaded = Oss.putObject(fileName, imageBytes);
|
||||
// if (uploaded) {
|
||||
// // 返回可访问的 URL(假设你有自定义域名)
|
||||
// // 格式:http://你的域名/文件名
|
||||
// return "/" + fileName;
|
||||
// }
|
||||
|
||||
// // 保存最终的证书图片
|
||||
ImageIO.write(background, "png", new File("cert.png"));
|
||||
System.out.println("Certificate generated successfully!");
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static BufferedImage createCircularImage(BufferedImage originalImg, int size) {
|
||||
BufferedImage outputImage = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2 = outputImage.createGraphics();
|
||||
|
||||
BIN
src/main/resources/static/cert/weChatMa.png
Normal file
BIN
src/main/resources/static/cert/weChatMa.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 129 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
Loading…
x
Reference in New Issue
Block a user