|
|
@@ -1,9 +1,9 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
+import com.google.zxing.WriterException;
|
|
|
import com.izouma.nineth.domain.DomainOrder;
|
|
|
import com.izouma.nineth.domain.FileObject;
|
|
|
-import com.izouma.nineth.domain.PhotoAsset;
|
|
|
import com.izouma.nineth.domain.User;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.CollectionStatus;
|
|
|
@@ -12,17 +12,28 @@ import com.izouma.nineth.enums.PayMethod;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.DomainOrderRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
+import com.izouma.nineth.service.storage.StorageService;
|
|
|
+import com.izouma.nineth.utils.ImageUtils;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.data.annotation.Transient;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.print.DocFlavor;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.*;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.List;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -35,6 +46,7 @@ public class DomainOrderService {
|
|
|
private UserRepo userRepo;
|
|
|
private AssetService assetService;
|
|
|
private SysConfigService sysConfigService;
|
|
|
+ private StorageService storageService;
|
|
|
|
|
|
public Page<DomainOrder> all(PageQuery pageQuery) {
|
|
|
return domainOrderRepo
|
|
|
@@ -80,15 +92,12 @@ public class DomainOrderService {
|
|
|
int dotIndex = domain.indexOf(".");
|
|
|
domain = domain.substring(0, dotIndex);
|
|
|
}
|
|
|
- FileObject fileObject = new FileObject();
|
|
|
- fileObject.setName("默认图片");
|
|
|
- fileObject.setType("image/jpeg");
|
|
|
- fileObject.setUrl("https://raex-meta.oss-cn-shenzhen.aliyuncs.com/image/2021-12-17-19-03-38BNAlEhlJ.png");
|
|
|
+
|
|
|
DomainOrder domainOrder = new DomainOrder();
|
|
|
- domainOrder.setPic(Collections.singletonList(fileObject));
|
|
|
+// domainOrder.setPic(Collections.singletonList(fileObject));
|
|
|
domainOrder.setPicName(domain);
|
|
|
domainOrder.setPrice(price);
|
|
|
- domainOrder.setDomainName(domain + ".nft");
|
|
|
+ domainOrder.setDomainName((domain + ".nft").toLowerCase());
|
|
|
domainOrder.setYears(year);
|
|
|
domainOrder.setStatus(CollectionStatus.PENDING);
|
|
|
domainOrder.setOrderStatus(OrderStatus.NOT_PAID);
|
|
|
@@ -150,7 +159,7 @@ public class DomainOrderService {
|
|
|
Map<String, Object> checkResult = check(domain);
|
|
|
if ((Boolean) checkResult.get("result")) {
|
|
|
Map<String, Object> sold = new HashMap<>();
|
|
|
- sold.put("domain", domain + ".nft");
|
|
|
+ sold.put("domain", (domain + ".nft").toLowerCase());
|
|
|
sold.put("sold", false);
|
|
|
recommend.add(sold);
|
|
|
}
|
|
|
@@ -162,7 +171,7 @@ public class DomainOrderService {
|
|
|
|
|
|
used.forEach(domainOrder -> {
|
|
|
Map<String, Object> sold = new HashMap<>();
|
|
|
- sold.put("domain", domainOrder.getDomainName());
|
|
|
+ sold.put("domain", domainOrder.getDomainName().toLowerCase());
|
|
|
sold.put("sold", true);
|
|
|
result.add(sold);
|
|
|
});
|
|
|
@@ -170,13 +179,25 @@ public class DomainOrderService {
|
|
|
}
|
|
|
|
|
|
@Transient
|
|
|
- public void notify(Long id, PayMethod payMethod, String transactionId) {
|
|
|
+ public void notify(Long id, PayMethod payMethod, String transactionId) throws FontFormatException, IOException, WriterException {
|
|
|
DomainOrder domainOrder = domainOrderRepo.findById(id).orElseThrow(new BusinessException("未找到星图"));
|
|
|
if (!domainOrder.getOrderStatus().equals(OrderStatus.NOT_PAID)) {
|
|
|
throw new BusinessException("订单已经处理");
|
|
|
}
|
|
|
+ BufferedImage img = domainImg(domainOrder.getDomainName());
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
+ ImageIO.write(img, "jpg", os);
|
|
|
+ InputStream input = new ByteArrayInputStream(os.toByteArray());
|
|
|
+ String path = "image/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
|
|
|
+ + RandomStringUtils.randomAlphabetic(8) + ".jpg";
|
|
|
+ String realUrl = storageService.uploadFromInputStream(input, path);
|
|
|
+ FileObject fileObject = new FileObject();
|
|
|
+ fileObject.setName(domainOrder.getDomainName());
|
|
|
+ fileObject.setType("image/jpeg");
|
|
|
+ fileObject.setUrl(realUrl);
|
|
|
domainOrder.setOrderStatus(OrderStatus.FINISH);
|
|
|
domainOrder.setPayMethod(payMethod);
|
|
|
+ domainOrder.setPic(Collections.singletonList(fileObject));
|
|
|
domainOrder.setTransactionId(transactionId);
|
|
|
domainOrder.setStatus(CollectionStatus.SUCCESS);
|
|
|
domainOrder.setCreateAssetId(createAsset(domainOrder));
|
|
|
@@ -195,4 +216,74 @@ public class DomainOrderService {
|
|
|
.orElseThrow(new BusinessException("无用户记录")), null, BigDecimal.ZERO, "域名", null, false).getId();
|
|
|
}
|
|
|
|
|
|
+ public BufferedImage domainImg(String domain) throws IOException, FontFormatException, WriterException {
|
|
|
+ String domainName;
|
|
|
+ if (domain.contains(".")) {
|
|
|
+ int dotIndex = domain.indexOf(".");
|
|
|
+ domainName = domain.substring(0, dotIndex);
|
|
|
+ } else {
|
|
|
+ domainName = domain;
|
|
|
+ }
|
|
|
+ InputStream is1 = this.getClass()
|
|
|
+ .getResourceAsStream("/font/Akronim Regular_mianfeiziti1.ttf");
|
|
|
+ Font font1 = Font.createFont(Font.TRUETYPE_FONT, is1);
|
|
|
+ is1.close();
|
|
|
+ InputStream is2 = this.getClass()
|
|
|
+ .getResourceAsStream("/font/VonwaonBitmap_12pxLite.ttf");
|
|
|
+ Font font2 = Font.createFont(Font.TRUETYPE_FONT, is2);
|
|
|
+ is2.close();
|
|
|
+ int length = domainName.length();
|
|
|
+ BufferedImage shareImg;
|
|
|
+ if (length <= 2) {
|
|
|
+ InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_jing.png");
|
|
|
+ shareImg = ImageIO.read(is3);
|
|
|
+ is3.close();
|
|
|
+ } else if (length <= 4) {
|
|
|
+ InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_lv.png");
|
|
|
+ shareImg = ImageIO.read(is3);
|
|
|
+ is3.close();
|
|
|
+ } else {
|
|
|
+ InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_zi.png");
|
|
|
+ shareImg = ImageIO.read(is3);
|
|
|
+ is3.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BufferedImage result = new BufferedImage(shareImg.getWidth(), shareImg.getHeight(), 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);
|
|
|
+
|
|
|
+// BufferedImage avatarImg = ImageUtils.makeRoundedCorner(ImageUtils.scale(ImageIO.read(new URL(user.getAvatar())),
|
|
|
+// 80, 80,
|
|
|
+// ImageUtils.Fit.COVER), 40);
|
|
|
+// g.drawImage(avatarImg, 334, 136, null);
|
|
|
+
|
|
|
+ g.setColor(new Color(255, 255, 255));
|
|
|
+ Font topFont = font1.deriveFont(Font.PLAIN, 240f);
|
|
|
+
|
|
|
+ Font downFont = font2.deriveFont(Font.BOLD, 36f);
|
|
|
+ ImageUtils.drawCenteredString(g, domainName, new Rectangle(0, 243, shareImg
|
|
|
+ .getWidth(), 86), topFont);
|
|
|
+ ImageUtils.drawCenteredString(g, ".NFT", new Rectangle(0, 462, shareImg
|
|
|
+ .getWidth(), 86), topFont);
|
|
|
+ g.setColor(new Color(255, 255, 255));
|
|
|
+ ImageUtils.drawCenteredString(g, domain, new Rectangle(0, 612, shareImg
|
|
|
+ .getWidth(), 12), downFont);
|
|
|
+
|
|
|
+ //二维码
|
|
|
+// QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
|
|
+// Map<EncodeHintType, Object> hints = new HashMap<>();
|
|
|
+// hints.put(EncodeHintType.MARGIN, 2);
|
|
|
+// BitMatrix bitMatrix = qrCodeWriter
|
|
|
+// .encode(env.getProperty("general.host") + "/wx/share?invitor=" + user.getId(),
|
|
|
+// BarcodeFormat.QR_CODE, 252, 252, hints);
|
|
|
+// g.drawImage(MatrixToImageWriter.toBufferedImage(bitMatrix), 250, 386, null);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|