|
|
@@ -87,9 +87,42 @@ public class ParticipantService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public String createAward(Participant participant, String programmeName, Long awardId) throws IOException, WriterException {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优秀奖生成-按专业
|
|
|
+ *
|
|
|
+ * @param specialtyId
|
|
|
+ * @param parent
|
|
|
+ */
|
|
|
+ public void meritAward(Long awardId, Long specialtyId, boolean parent) {
|
|
|
+ List<Programme> programmes;
|
|
|
+ if (parent) {
|
|
|
+ programmes = programmeRepo.findAllByAwardIdAndParentSpecialtyId(awardId, specialtyId);
|
|
|
+ } else {
|
|
|
+ programmes = programmeRepo.findAllByAwardIdAndSpecialtyId(awardId, specialtyId);
|
|
|
+ }
|
|
|
+ Map<Long, String> programmeMap = programmes.stream()
|
|
|
+ .collect(Collectors.toMap(Programme::getId, Programme::getName));
|
|
|
+ List<Participant> participants = participantRepo.findAllByProgrammeIdIn(programmeMap.keySet());
|
|
|
+ List<Participant> result = new ArrayList<>();
|
|
|
+ participants.forEach(participant -> {
|
|
|
+ if (ObjectUtil.isNull(participant.getAwardImg())) {
|
|
|
+ try {
|
|
|
+ participant.setAwardImg(this.createMeritAward(participant, programmeMap.get(participant.getProgrammeId())));
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("文件找不到", e);
|
|
|
+ } catch (WriterException e) {
|
|
|
+ log.error("生成二维码失败", e);
|
|
|
+ }
|
|
|
+ result.add(participant);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ participantRepo.saveAll(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String createMeritAward(Participant participant, String programmeName) throws IOException, WriterException {
|
|
|
BufferedImage shareImg = ImageIO.read(this.getClass()
|
|
|
- .getResourceAsStream("/static/certificate" + awardId + ".jpeg"));
|
|
|
+ .getResourceAsStream("/static/certificate/certificate.png"));
|
|
|
BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
|
|
|
Graphics2D g = result.createGraphics();
|
|
|
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
@@ -133,7 +166,7 @@ public class ParticipantService {
|
|
|
String name = participant.getName();
|
|
|
g.setFont(font); //设置字体
|
|
|
//设置水印的坐标
|
|
|
- g.drawString(name, 400, 600);
|
|
|
+ g.drawString(name, 400, 607);
|
|
|
|
|
|
|
|
|
// 节目名称
|
|
|
@@ -145,7 +178,7 @@ public class ParticipantService {
|
|
|
g.drawString(body1, 1200, 795);
|
|
|
g.drawString(body2, 1200, 835);
|
|
|
} else {
|
|
|
- g.drawString(programmeName, 1220, 825);
|
|
|
+ g.drawString(programmeName, 1220, 831);
|
|
|
}
|
|
|
|
|
|
g.dispose();
|
|
|
@@ -157,7 +190,7 @@ public class ParticipantService {
|
|
|
.toOutputStream(out);
|
|
|
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
|
|
|
- return storageService.uploadFromInputStream(in, "award/" + awardId + "-" + programmeId + "-" + participant.getId() + ".jpg");
|
|
|
+ return storageService.uploadFromInputStream(in, "award/meritAward-" + programmeId + "-" + participant.getId() + ".jpg");
|
|
|
}
|
|
|
|
|
|
public void awardByProgrammeId(Long programmeId) {
|
|
|
@@ -170,31 +203,35 @@ public class ParticipantService {
|
|
|
// String name = awardRepo.findById(programme.getAwardId()).orElseThrow(new BusinessException("无奖项")).getName();
|
|
|
List<Participant> result = new ArrayList<>();
|
|
|
participants.forEach(participant -> {
|
|
|
- if (ObjectUtil.isNull(participant.getAwardImg())) {
|
|
|
- try {
|
|
|
- participant.setAwardImg(this.createAward(participant, programme.getName(), programme.getAwardId()));
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("文件找不到", e);
|
|
|
- } catch (WriterException e) {
|
|
|
- log.error("生成二维码失败", e);
|
|
|
+// if (ObjectUtil.isNull(participant.getAwardImg())) {
|
|
|
+ try {
|
|
|
+ if (programme.getAwardId().equals(28202L)) {
|
|
|
+ participant.setAwardImg(this.createMeritAward(participant, programme.getName()));
|
|
|
+ } else {
|
|
|
+ participant.setAwardImg(this.createAward(participant, programme.getName(), programme.getAwardId(), programme.getParentSpecialtyId()));
|
|
|
}
|
|
|
- result.add(participant);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("文件找不到", e);
|
|
|
+ } catch (WriterException e) {
|
|
|
+ log.error("生成二维码失败", e);
|
|
|
}
|
|
|
+ result.add(participant);
|
|
|
+// }
|
|
|
});
|
|
|
|
|
|
participantRepo.saveAll(result);
|
|
|
}
|
|
|
|
|
|
- public void awardByAwardId(Long awardId, Long specialtyId, boolean parent) {
|
|
|
+ /**
|
|
|
+ * 一二三等奖-按父专业
|
|
|
+ *
|
|
|
+ * @param awardId
|
|
|
+ * @param specialtyId
|
|
|
+ */
|
|
|
+ public void awardByAwardId(Long awardId, Long specialtyId) {
|
|
|
// String award = awardRepo.findById(awardId).orElseThrow(new BusinessException("无奖项")).getName();
|
|
|
- List<Programme> programmes;
|
|
|
- if (ObjectUtil.isNull(specialtyId)) {
|
|
|
- programmes = programmeRepo.findAllByAwardId(awardId);
|
|
|
- } else if (parent) {
|
|
|
- programmes = programmeRepo.findAllByAwardIdAndParentSpecialtyId(awardId, specialtyId);
|
|
|
- } else {
|
|
|
- programmes = programmeRepo.findAllByAwardIdAndSpecialtyId(awardId, specialtyId);
|
|
|
- }
|
|
|
+ List<Programme> programmes = programmeRepo.findAllByAwardIdAndSpecialtyId(awardId, specialtyId);
|
|
|
Map<Long, String> programmeMap = programmes.stream()
|
|
|
.collect(Collectors.toMap(Programme::getId, Programme::getName));
|
|
|
List<Participant> participants = participantRepo.findAllByProgrammeIdIn(programmeMap.keySet());
|
|
|
@@ -202,7 +239,7 @@ public class ParticipantService {
|
|
|
participants.forEach(participant -> {
|
|
|
if (ObjectUtil.isNull(participant.getAwardImg())) {
|
|
|
try {
|
|
|
- participant.setAwardImg(this.createAward(participant, programmeMap.get(participant.getProgrammeId()), awardId));
|
|
|
+ participant.setAwardImg(this.createAward(participant, programmeMap.get(participant.getProgrammeId()), awardId, specialtyId));
|
|
|
} catch (IOException e) {
|
|
|
log.error("文件找不到", e);
|
|
|
} catch (WriterException e) {
|
|
|
@@ -213,4 +250,73 @@ public class ParticipantService {
|
|
|
});
|
|
|
participantRepo.saveAll(result);
|
|
|
}
|
|
|
+
|
|
|
+ public String createAward(Participant participant, String programmeName, Long awardId, Long specialtyId) throws IOException, WriterException {
|
|
|
+ BufferedImage shareImg = ImageIO.read(this.getClass()
|
|
|
+ .getResourceAsStream("/static/certificate/2021-" + specialtyId + "-" + awardId + ".png"));
|
|
|
+ BufferedImage result = new BufferedImage(2480, 1748, BufferedImage.TYPE_INT_RGB);
|
|
|
+ Graphics2D g = result.createGraphics();
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g.setComposite(AlphaComposite.SrcOver);
|
|
|
+ g.drawImage(shareImg, 0, 0, null);
|
|
|
+
|
|
|
+ // 二维码
|
|
|
+ Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
|
|
+ hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
|
|
+ hints.put(EncodeHintType.MARGIN, 1);
|
|
|
+
|
|
|
+ BitMatrix bitMatrix = new MultiFormatWriter().encode("http://yskj.njlyw.cn:8081/h5?progremmeId=" + participant.getProgrammeId(),
|
|
|
+ BarcodeFormat.QR_CODE, 1000, 1000, hints);
|
|
|
+ BufferedImage code = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
|
|
+
|
|
|
+ BufferedImage avatarImg = new BufferedImage(240, 240, BufferedImage.TYPE_INT_ARGB);
|
|
|
+ Graphics2D g2 = avatarImg.createGraphics();
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ g2.setComposite(AlphaComposite.SrcOver);
|
|
|
+ g2.setBackground(Color.GREEN);
|
|
|
+ g2.drawImage(code, 0, 0, 240, 240, null);
|
|
|
+
|
|
|
+ g.drawImage(avatarImg, 1898, 253, 240, 240, null);
|
|
|
+
|
|
|
+
|
|
|
+ // 文字
|
|
|
+ g.setColor(new Color(48, 52, 82)); //根据图片的背景设置水印颜色
|
|
|
+ // 编号
|
|
|
+ String programmeId = participant.getProgrammeId().toString();
|
|
|
+ Font fontId = new Font("黑体", Font.PLAIN, 35);
|
|
|
+ g.setFont(fontId);
|
|
|
+ g.drawString(programmeId, 2000, 544);
|
|
|
+
|
|
|
+
|
|
|
+ // 姓名
|
|
|
+ Font font = new Font("黑体", Font.BOLD, 60);
|
|
|
+ String name = participant.getName();
|
|
|
+ g.setFont(font); //设置字体
|
|
|
+ //设置水印的坐标
|
|
|
+ g.drawString(name, 400, 601);
|
|
|
+
|
|
|
+
|
|
|
+ // 节目名称
|
|
|
+ if (programmeName.length() < 8) {
|
|
|
+ g.drawString(programmeName, 1300, 834);
|
|
|
+ } else {
|
|
|
+ g.drawString(programmeName, 1180, 834);
|
|
|
+ }
|
|
|
+
|
|
|
+ g.dispose();
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
|
|
|
+ Thumbnails.of(result)
|
|
|
+ .scale(1)
|
|
|
+ .outputQuality(.9f)
|
|
|
+ .outputFormat("jpg")
|
|
|
+ .toOutputStream(out);
|
|
|
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
|
|
|
+
|
|
|
+ return storageService.uploadFromInputStream(in, "award/" + specialtyId + "-" + awardId + "-" + participant.getId() + ".jpg");
|
|
|
+ }
|
|
|
+
|
|
|
}
|