Bläddra i källkod

Merge branch 'master' of http://git.izouma.com/xiongzhu/raex_back into dev-meta

sunkean 3 år sedan
förälder
incheckning
9b65bbab3e

+ 11 - 0
pom.xml

@@ -568,6 +568,17 @@
             <artifactId>qr-terminal</artifactId>
             <version>1.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>core</artifactId>
+            <version>3.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.zxing</groupId>
+            <artifactId>javase</artifactId>
+            <version>3.3.0</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 2 - 0
src/main/java/com/izouma/nineth/listener/OrderNotifyListener.java

@@ -4,6 +4,7 @@ import com.izouma.nineth.domain.PhotoAsset;
 import com.izouma.nineth.event.OrderNotifyEvent;
 import com.izouma.nineth.service.*;
 import lombok.AllArgsConstructor;
+import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.spring.annotation.ConsumeMode;
 import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
@@ -28,6 +29,7 @@ public class OrderNotifyListener implements RocketMQListener<OrderNotifyEvent> {
     private PhotoAssetService   photoAssetService;
     private DomainOrderService  domainOrderService;
 
+    @SneakyThrows
     @Override
     public void onMessage(OrderNotifyEvent e) {
         if (e.getType() == null) {

+ 1 - 2
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -4,7 +4,6 @@ import com.izouma.nineth.domain.Asset;
 import com.izouma.nineth.dto.FuAssetDTO;
 import com.izouma.nineth.enums.AssetSource;
 import com.izouma.nineth.enums.AssetStatus;
-import com.izouma.nineth.enums.CollectionSource;
 import com.izouma.nineth.enums.CollectionType;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -141,7 +140,7 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
     @Query("select count(id) from Asset where status = ?2 and name like ?1")
     Long countDestroyed(String name, AssetStatus status);
 
-    @Query("select count(id) from Asset where name like ?1 and status = 'NORMAL' and ownerId <> 1435297")
+    @Query("select count(id) from Asset where name like ?1 and status in ('NORMAL','TRADING','GIFTING','MINTING','AUCTIONING','AUCTION_TRADING','DESTROYING') and ownerId <> 1435297")
     Long countNameLikeNotDestroyed(String name);
 
     @Query(value = "SELECT count(a.id) from asset a where a.name LIKE ?1 and status = 'NORMAL' and owner_id = ?2", nativeQuery = true)

+ 1 - 1
src/main/java/com/izouma/nineth/repo/OrderRepo.java

@@ -70,7 +70,7 @@ public interface OrderRepo extends JpaRepository<Order, Long>, JpaSpecificationE
     List<Order> findByCreatedAtBetweenAndSourceAndStatusIn(LocalDateTime start, LocalDateTime end, CollectionSource source, Collection<OrderStatus> statuses);
 
     @Query(nativeQuery = true, value = "select o.user_id  from order_info o " +
-            " WHERE o.created_at < ?2 and o.created_at > ?1 and o.status = 'CANCELLED' " +
+            " WHERE o.created_at < ?1 and o.created_at > ?2 and ( o.status = 'NOT_PAID' OR o.status = 'CANCELLED')" +
             "GROUP BY o.user_id " +
             "HAVING count(*) > 2")
     List<Long> checkBlackList(LocalDateTime start, LocalDateTime end);

+ 102 - 11
src/main/java/com/izouma/nineth/service/DomainOrderService.java

@@ -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;
+    }
+
 }

+ 4 - 1
src/main/java/com/izouma/nineth/service/OrderPayService.java

@@ -5,6 +5,7 @@ import com.alipay.api.AlipayApiException;
 import com.alipay.api.AlipayClient;
 import com.alipay.api.request.AlipayTradePrecreateRequest;
 import com.alipay.api.response.AlipayTradePrecreateResponse;
+import com.google.zxing.WriterException;
 import com.izouma.nineth.config.AlipayProperties;
 import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.config.GeneralProperties;
@@ -26,6 +27,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
+import java.awt.*;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
@@ -935,7 +938,7 @@ public class OrderPayService {
                 order.getUserId(), identityAuth.getRealName(), identityAuth.getIdNo());
     }
 
-    public void payDomainOrderBalance(Long orderId, Long userId, String tradeCode) {
+    public void payDomainOrderBalance(Long orderId, Long userId, String tradeCode) throws FontFormatException, IOException, WriterException {
         DomainOrder order = domainOrderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在"));
         if (order.getOrderStatus() != OrderStatus.NOT_PAID) {
             throw new BusinessException("订单状态错误");

+ 5 - 3
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -999,12 +999,14 @@ public class OrderService {
         EasyExcel.write(outputStream, MarketSettlement.class).sheet("sheet").doWrite(settlements);
     }
 
-    @Scheduled(cron = "0 0/5 * * * ?")
+    @Scheduled(cron = "0 0/3 * * * ?")
     public void setBlackList() {
         List<Long> userIds = orderRepo
-                .checkBlackList(LocalDateTime.now(), LocalDateTime.now().plusHours(1));
+                .checkBlackList(LocalDateTime.now(), LocalDateTime.now().minusMinutes(30));
         userIds.forEach(userId -> {
-            redisTemplate.opsForValue().set(RedisKeys.BLACK_LIST + userId, 1, Duration.ofSeconds(60 * 60));
+            if (redisTemplate.opsForValue().get(RedisKeys.BLACK_LIST + userId) == null) {
+                redisTemplate.opsForValue().set(RedisKeys.BLACK_LIST + userId, 1, Duration.ofSeconds(60 * 180));
+            }
         });
     }
 

+ 14 - 0
src/main/java/com/izouma/nineth/utils/ImageUtils.java

@@ -4,6 +4,7 @@ import net.coobird.thumbnailator.Thumbnails;
 import org.pngquant.PngQuant;
 
 import javax.imageio.ImageIO;
+import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.FileInputStream;
@@ -55,4 +56,17 @@ public class ImageUtils {
                         .getRemapped(ImageIO.read(new File("/Users/drew/Desktop/1.png"))),
                 "png", new File("/Users/drew/Desktop/2.png"));
     }
+
+    public static void drawCenteredString(Graphics g, String text, Rectangle rect, Font font) {
+        // Get the FontMetrics
+        FontMetrics metrics = g.getFontMetrics(font);
+        // Determine the X coordinate for the text
+        int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2;
+        // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen)
+        int y = rect.y + ((rect.height - metrics.getHeight()) / 2) + metrics.getAscent();
+        // Set the font
+        g.setFont(font);
+        // Draw the String
+        g.drawString(text, x, y);
+    }
 }

+ 36 - 1
src/main/java/com/izouma/nineth/web/OrderPayControllerV2.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.web;
 
+import com.google.zxing.WriterException;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.Order;
 import com.izouma.nineth.enums.OrderStatus;
@@ -18,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import java.awt.*;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.Map;
 
@@ -293,12 +296,44 @@ public class OrderPayControllerV2 {
         return orderPayService.payPicOrderAgreement(id, bindCardId);
     }
 
+    @RequestMapping(value = "/domain/ali")
+    @ResponseBody
+    public String payDomainOrderAli(Long id) {
+        return orderPayService.payDomainAli(id);
+    }
+
+    @RequestMapping(value = "/domain/alipay_wx", method = RequestMethod.GET)
+    public String payDomainOrderAlipayWx(Long id, Model model) {
+        String payUrl = orderPayService.payDomainOrder(id);
+        model.addAttribute("payUrl", payUrl);
+        model.addAttribute("orderId", id);
+        return "AlipayHtml";
+    }
+
+    @RequestMapping(value = "/domain/sandQuick", method = RequestMethod.GET, produces = "text/html")
+    @ResponseBody
+    public String payDomainQuick(@RequestParam Long id) {
+        return orderPayService.payDomainQuick(id);
+    }
+
+    @RequestMapping("/domain/sandQuickBind")
+    @ResponseBody
+    public String payDomainQuickBind(@RequestParam Long id) {
+        return orderPayService.payDomainQuickBind(id);
+    }
+
     @RequestMapping(value = "/domain/balance")
     @ResponseBody
-    public void payDomainOrderBalance(@RequestParam Long id, @RequestParam String tradeCode) {
+    public void payDomainOrderBalance(@RequestParam Long id, @RequestParam String tradeCode) throws FontFormatException, IOException, WriterException {
         orderPayService.payDomainOrderBalance(id, SecurityUtils.getAuthenticatedUser().getId(), tradeCode);
     }
 
+    @RequestMapping(value = "/domain/agreement")
+    @ResponseBody
+    public Map<String, Object> payDomainAgreement(@RequestParam Long id, String bindCardId) {
+        return orderPayService.payDomainOrderAgreement(id, bindCardId);
+    }
+
     @RequestMapping(value = "/tradeAuction/balance")
     @ResponseBody
     public void payTradeAuctionOrderBalance(@RequestParam Long id, @RequestParam String tradeCode) {

BIN
src/main/resources/font/Akronim Regular_mianfeiziti1.ttf


BIN
src/main/resources/font/VonwaonBitmap_12pxLite.ttf


BIN
src/main/resources/static/img/png_jing.png


BIN
src/main/resources/static/img/png_lv.png


BIN
src/main/resources/static/img/png_zi.png