修改浏览记录
This commit is contained in:
parent
2f0d44ae76
commit
bc44e11fd9
BIN
cert.png
BIN
cert.png
Binary file not shown.
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 165 KiB |
@ -117,29 +117,27 @@ public class UserCaseReadController extends BaseController {
|
||||
Page<UserCollectClinicalVideoDto> page = new Page<>(request.getPage(), request.getPageSize());
|
||||
|
||||
// 获取文章数据
|
||||
IPage<UserCollectClinicalVideoDto> resultPage = userCollectClinicalVideoDao.getUserCollectClinicalVideoSearchPage(
|
||||
IPage<UserCaseReadDto> resultPage = userCaseReadDao.getUserCaseReadVideoSearchPage(
|
||||
page,
|
||||
request.getKeyword(),
|
||||
request.getHospitalId(),
|
||||
request.getDoctorId(),
|
||||
userId
|
||||
);
|
||||
|
||||
for (UserCollectClinicalVideoDto dto : resultPage.getRecords()) {
|
||||
UserCollectClinicalVideoDto.DataDto data = dto.getData();
|
||||
List<UserCollectClinicalVideoDto.DataAuthorDto> dataAuthors = new ArrayList<>();
|
||||
for (UserCaseReadDto dto : resultPage.getRecords()) {
|
||||
UserCaseReadDto.DataDto data = dto.getData();
|
||||
List<UserCaseReadDto.DataAuthorDto> dataAuthors = new ArrayList<>();
|
||||
|
||||
// 查找作者
|
||||
LambdaQueryWrapper<CaseClinicalVideoAuthorModel> authorQueryWrapper = new LambdaQueryWrapper<>();
|
||||
authorQueryWrapper.eq(CaseClinicalVideoAuthorModel::getVideoId, dto.getId());
|
||||
List<CaseClinicalVideoAuthorModel> caseClinicalVideoAuthors = caseClinicalVideoAuthorDao.selectList(authorQueryWrapper);
|
||||
for (CaseClinicalVideoAuthorModel author : caseClinicalVideoAuthors) {
|
||||
UserCollectClinicalVideoDto.DataAuthorDto dataAuthor = new UserCollectClinicalVideoDto.DataAuthorDto();
|
||||
UserCaseReadDto.DataAuthorDto dataAuthor = new UserCaseReadDto.DataAuthorDto();
|
||||
|
||||
// 查询医生
|
||||
CaseClinicalDoctorModel caseClinicalDoctor = caseClinicalDoctorDao.selectById(author.getDoctorId());
|
||||
|
||||
dataAuthor.setDoctorName(caseClinicalDoctor.getDoctorName());
|
||||
|
||||
dataAuthors.add(dataAuthor);
|
||||
}
|
||||
|
||||
@ -155,17 +153,15 @@ public class UserCaseReadController extends BaseController {
|
||||
Page<UserCollectExchangeDto> page = new Page<>(request.getPage(), request.getPageSize());
|
||||
|
||||
// 获取文章数据
|
||||
IPage<UserCollectExchangeDto> resultPage = userCollectExchangeDao.getUserCollectExchangeSearchPage(
|
||||
IPage<UserCaseReadDto> resultPage = userCaseReadDao.getUserCaseReadVideoSearchPage(
|
||||
page,
|
||||
request.getKeyword(),
|
||||
request.getHospitalId(),
|
||||
request.getDoctorId(),
|
||||
userId
|
||||
);
|
||||
|
||||
for (UserCollectExchangeDto dto : resultPage.getRecords()) {
|
||||
UserCollectExchangeDto.DataDto data = dto.getData();
|
||||
List<UserCollectExchangeDto.DataAuthorDto> dataAuthors = new ArrayList<>();
|
||||
for (UserCaseReadDto dto : resultPage.getRecords()) {
|
||||
UserCaseReadDto.DataDto data = dto.getData();
|
||||
List<UserCaseReadDto.DataAuthorDto> dataAuthors = new ArrayList<>();
|
||||
|
||||
UserModel user = userDao.selectById(Long.valueOf(userId));
|
||||
if (user == null) {
|
||||
@ -178,7 +174,7 @@ public class UserCaseReadController extends BaseController {
|
||||
return Response.error();
|
||||
}
|
||||
|
||||
UserCollectExchangeDto.DataAuthorDto dataAuthor = new UserCollectExchangeDto.DataAuthorDto();
|
||||
UserCaseReadDto.DataAuthorDto dataAuthor = new UserCaseReadDto.DataAuthorDto();
|
||||
dataAuthor.setDoctorName(user.getUserName());
|
||||
dataAuthor.setHospitalName(basicHospital.getHospitalName());
|
||||
dataAuthors.add(dataAuthor);
|
||||
|
||||
@ -20,6 +20,8 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.Year;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class UserController extends BaseController {
|
||||
@ -164,7 +166,7 @@ public class UserController extends BaseController {
|
||||
try {
|
||||
String avt = "src/main/resources/static/cert/avt.png";
|
||||
String sealPath = "src/main/resources/static/cert/seal.png";
|
||||
String certificateNo = "123456";
|
||||
String certificateNo = "GDXZALK" + String.valueOf(Year.now().getValue()) + "123456";
|
||||
String name = "吴从兴";
|
||||
String content = "您的案例《儿童肾上腺危象一例》经评议,被肝胆相照临床病例库收录,特发此";
|
||||
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.example.caseData.service;
|
||||
|
||||
import com.example.caseData.config.AppConfig;
|
||||
import com.example.caseData.config.EnvConfig;
|
||||
import com.example.caseData.exception.BusinessException;
|
||||
import com.example.caseData.extend.aliyun.Oss;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@ -13,9 +16,13 @@ import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Service
|
||||
public class CertService {
|
||||
@Resource
|
||||
private EnvConfig envConfig;
|
||||
|
||||
// 生成证书
|
||||
public String createCert(String avatarPath,
|
||||
String sealPath,
|
||||
@ -28,54 +35,79 @@ public class CertService {
|
||||
|
||||
Graphics2D g2d = (Graphics2D) background.getGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// 设置字体
|
||||
Font font = new Font("Arial", Font.PLAIN, 24);
|
||||
g2d.setFont(font);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
// 1. 添加证书编号
|
||||
g2d.drawString(certificateNo, 180, 294);
|
||||
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(avatarPath));
|
||||
int size = 100; // 目标大小
|
||||
int size = 116; // 目标大小
|
||||
BufferedImage circleAvatar = createCircularImage(avatar, size);
|
||||
g2d.drawImage(circleAvatar, 290, 380, null);
|
||||
g2d.drawImage(circleAvatar, 465, 620, null);
|
||||
|
||||
// 3. 添加姓名
|
||||
g2d.drawString(name, 330, 524);
|
||||
font = new Font("Microsoft YaHei", Font.PLAIN, 40); // 可根据模板调整大小
|
||||
g2d.setFont(font);
|
||||
|
||||
customColor = Color.decode("#111827");
|
||||
g2d.setColor(customColor);
|
||||
g2d.drawString(name, 465, 790);
|
||||
|
||||
// 4. 添加证书内容
|
||||
g2d.drawString(content, 120, 574);
|
||||
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());
|
||||
g2d.drawString(currentDate, 390, 874);
|
||||
|
||||
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, 100, 100); // 调整印章大小
|
||||
g2d.drawImage(seal, 300, 750, null);
|
||||
seal = resize(seal, 264, 264); // 调整印章大小
|
||||
g2d.drawImage(seal, 645, 1150, null);
|
||||
|
||||
// 释放资源
|
||||
g2d.dispose();
|
||||
|
||||
// === 将图片转为 byte[] ===
|
||||
// ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
// ImageIO.write(background, "png", os);
|
||||
// byte[] imageBytes = os.toByteArray();
|
||||
// String fileName = "dev/static/images/" + "测试" + ".png";
|
||||
// boolean uploaded = Oss.putObject(fileName, imageBytes);
|
||||
// if (uploaded) {
|
||||
// // 返回可访问的 URL(假设你有自定义域名)
|
||||
// // 格式:http://你的域名/文件名
|
||||
// return fileName;
|
||||
// }
|
||||
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!");
|
||||
// ImageIO.write(background, "png", new File("cert.png"));
|
||||
// System.out.println("Certificate generated successfully!");
|
||||
} catch (IOException e) {
|
||||
throw new BusinessException(e.getMessage());
|
||||
}
|
||||
@ -105,4 +137,25 @@ public class CertService {
|
||||
return dimg;
|
||||
}
|
||||
|
||||
// 绘制带自动换行的字符串
|
||||
private static void drawStringWithLineBreak(Graphics2D g2d, String text, int x, int y, int maxWidth, Font font) {
|
||||
FontMetrics fm = g2d.getFontMetrics(font);
|
||||
StringBuilder line = new StringBuilder();
|
||||
String[] words = text.split("");
|
||||
|
||||
for (String word : words) {
|
||||
int lineWidth = fm.stringWidth(line + word);
|
||||
if (lineWidth < maxWidth) {
|
||||
line.append(word);
|
||||
} else {
|
||||
g2d.drawString(line.toString(), x, y);
|
||||
y += fm.getHeight();
|
||||
line = new StringBuilder(word);
|
||||
}
|
||||
}
|
||||
if (!line.isEmpty()) {
|
||||
g2d.drawString(line.toString(), x, y);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.example.caseData.service;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.example.caseData.config.EnvConfig;
|
||||
import com.example.caseData.dao.BasicHospitalDao;
|
||||
import com.example.caseData.dao.CaseClinicalDoctorDao;
|
||||
import com.example.caseData.dao.CaseClinicalRecordScoreDao;
|
||||
@ -20,6 +21,7 @@ import com.example.caseData.request.UserRequest.ReportUserScoreRequest;
|
||||
import com.example.caseData.utils.JwtUtil;
|
||||
import com.example.caseData.utils.Replace;
|
||||
import com.example.caseData.utils.StringToInt;
|
||||
import com.example.caseData.config.EnvConfig;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -71,6 +73,9 @@ public class UserService {
|
||||
@Resource
|
||||
private Score score;
|
||||
|
||||
@Resource
|
||||
private EnvConfig envConfig;
|
||||
|
||||
/**
|
||||
* 用户登陆-手机号
|
||||
* @return UserModel
|
||||
@ -156,7 +161,7 @@ public class UserService {
|
||||
user.setUnionId("");
|
||||
user.setSex(0);
|
||||
if (data.getPhoto() != null) {
|
||||
String ossPath = UserService.handleUserImage(data.getImg_host() + data.getPhoto());
|
||||
String ossPath = handleUserImage(data.getImg_host() + data.getPhoto());
|
||||
user.setAvatar(ossPath);
|
||||
}else{
|
||||
user.setAvatar("");
|
||||
@ -193,7 +198,7 @@ public class UserService {
|
||||
|
||||
if (data.getPhoto() != null) {
|
||||
try {
|
||||
String ossPath = UserService.handleUserImage(data.getImg_host() + data.getPhoto());
|
||||
String ossPath = handleUserImage(data.getImg_host() + data.getPhoto());
|
||||
user.setAvatar(ossPath);
|
||||
}catch (Exception e){
|
||||
// 不处理
|
||||
@ -389,7 +394,7 @@ public class UserService {
|
||||
* @param wxAvatarUrl 微信头像地址
|
||||
* @return OSS 路径(以 / 开头),如 /user/avatar/202507301530123456.png
|
||||
*/
|
||||
public static String handleUserImage(String wxAvatarUrl) {
|
||||
public String handleUserImage(String wxAvatarUrl) {
|
||||
if (wxAvatarUrl == null || wxAvatarUrl.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@ -425,7 +430,13 @@ public class UserService {
|
||||
String dateTimeStr = LocalDateTime.now()
|
||||
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
|
||||
int randomSuffix = new Random().nextInt(9000) + 1000;
|
||||
String ossPath = "dev/static/images/" + dateTimeStr + randomSuffix + ".png";
|
||||
|
||||
String ossPath = "";
|
||||
if (Objects.equals(envConfig.getActive(), "dev")){
|
||||
ossPath = "dev/static/images/" + dateTimeStr + randomSuffix + ".png";
|
||||
}else{
|
||||
ossPath = "prod/static/images/" + dateTimeStr + randomSuffix + ".png";
|
||||
}
|
||||
|
||||
// 3. 上传 OSS
|
||||
boolean success = Oss.putObject(ossPath, imageBytes);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user