修改了图片

This commit is contained in:
wucongxing8150 2025-08-01 09:32:47 +08:00
parent 329d7c91ff
commit 462318b5ec
4 changed files with 94 additions and 3 deletions

View File

@ -15,6 +15,7 @@ import com.example.caseData.model.*;
import com.example.caseData.model.UserCollectClinicalVideoModel;
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoApp;
import com.example.caseData.request.CaseClinicalVideoRequest.addClinicalVideoComment;
import com.example.caseData.utils.ImageUtil;
import com.example.caseData.utils.Replace;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Resource;
@ -878,7 +879,17 @@ public class CaseClinicalVideoService {
}
// 下载头像
byte[] avatarByte = Oss.getObjectToByte(caseClinicalDoctor.getAvatar().replaceFirst("^/+", ""));
byte[] avatarByte = new byte[0];
if (caseClinicalDoctor.getAvatar() != null) {
avatarByte = Oss.getObjectToByte(caseClinicalDoctor.getAvatar().replaceFirst("^/+", ""));
}else{
try {
avatarByte = ImageUtil.readImageToBytes("src/main/resources/static/cert/avatar.png");
} catch (Exception e) {
throw new BusinessException("-1", e.getMessage());
}
}
if (avatarByte == null) {
throw new BusinessException("-1", "无法完成此操作");
}
@ -896,15 +907,76 @@ public class CaseClinicalVideoService {
// 已存在的
for (CaseClinicalVideoAuthorModel b : existsList){
// 如果现有作者的唯一标识为空
if (b.getCaseClinicalDoctor().getDoctorIden() == null || b.getCaseClinicalDoctor().getDoctorIden().isEmpty()) {
CaseClinicalDoctorModel caseClinicalDoctor = b.getCaseClinicalDoctor();
if (b.getCaseClinicalDoctor().getDoctorIden() == null || caseClinicalDoctor.getDoctorIden().isEmpty()) {
for (addClinicalVideoApp.Author a : r.getAuthor()){
// 检测医生姓名+医院唯一标识
String akey = a.getDoctorName() + a.getHospitalIden();
String bkey = b.getCaseClinicalDoctor().getDoctorName() + b.getCaseClinicalDoctor().getBasicHospital().getHospitalIden();
String bkey = b.getCaseClinicalDoctor().getDoctorName() + caseClinicalDoctor.getBasicHospital().getHospitalIden();
if (akey.equals(bkey)){
// 相等
b.getCaseClinicalDoctor().setDoctorIden(a.getDoctorIden());
caseClinicalDoctorDao.updateById(b.getCaseClinicalDoctor());
CaseClinicalVideoAuthorModel caseClinicalVideoAuthor = new CaseClinicalVideoAuthorModel();
caseClinicalVideoAuthor.setVideoId(caseClinicalVideo.getVideoId());
caseClinicalVideoAuthor.setDoctorId(String.valueOf(caseClinicalDoctor.getDoctorId()));
caseClinicalVideoAuthorDao.insert(caseClinicalVideoAuthor);
LocalDateTime lastPushDate = caseClinicalVideoDao.selectLastVideoPushDateByDoctorId(caseClinicalDoctor.getDoctorId());
// 新增作者统计
caseClinicalService.IncStatsCaseClinicalDoctor(String.valueOf(caseClinicalDoctor.getDoctorId()),2,lastPushDate);
// 新增医院统计
caseClinicalService.IncStatsCaseClinicalHospital(String.valueOf(caseClinicalDoctor.getHospitalId()),2,lastPushDate);
// 生成用户证书-文章/视频
if (qrCodeByte == null || qrCodeByte.length == 0) {
// 生成二维码图片
if (caseClinicalVideo.getShareQrcode() == null){
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", "无法完成此操作");
}
}
}
// 下载头像
byte[] avatarByte = new byte[0];
if (caseClinicalDoctor.getAvatar() != null) {
avatarByte = Oss.getObjectToByte(caseClinicalDoctor.getAvatar().replaceFirst("^/+", ""));
}else{
try {
avatarByte = ImageUtil.readImageToBytes("src/main/resources/static/cert/avatar.png");
} catch (Exception e) {
throw new BusinessException("-1", e.getMessage());
}
}
if (avatarByte == null) {
throw new BusinessException("-1", "无法完成此操作");
}
userService.CreateUserCert(
String.valueOf(caseClinicalVideo.getVideoId()),
2,
String.valueOf(caseClinicalDoctor.getDoctorId()),
qrCodeByte,
avatarByte
);
}
}
}

View File

@ -0,0 +1,19 @@
package com.example.caseData.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class ImageUtil {
public static byte[] readImageToBytes(String imagePath) throws IOException {
File file = new File(imagePath);
try (FileInputStream fis = new FileInputStream(file)) {
byte[] bytes = new byte[(int) file.length()];
int read = fis.read(bytes);
if (read != bytes.length) {
throw new IOException("读取文件长度不一致");
}
return bytes;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB