From ca070436770f715572405880cfe548c02f639c73 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 01 一月 2025 10:08:31 +0800
Subject: [PATCH] 代码修改

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java |   58 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java
index c8c0a3d..f479889 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java
@@ -164,13 +164,15 @@
         }
 
         Set<Long> cacheSet = redisCache.getCacheSet("INFORMATION:" + userId);
-
+        List<TRegion> regions = regionService.lambdaQuery().list();
+        List<TTechnicalTitle> tTechnicalTitles = tTechnicalTitleService.lambdaQuery().list();
+        List<TTitleMajor> tTitleMajors = majorService.lambdaQuery().list();
         for (TInformation record : page.getRecords()) {
-            TRegion byId = regionService.getById(record.getRegionId());
-            record.setRegionName(byId.getProvinceName()+"-"+byId.getName());
-            TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId());
-            TTitleMajor byId2 = majorService.getById(record.getMajorId());
-            record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName());
+            TRegion region = regions.stream().filter(e -> e.getId().equals(record.getRegionId())).findFirst().orElse(null);
+            TTechnicalTitle tTechnicalTitle = tTechnicalTitles.stream().filter(e -> e.getId().equals(record.getTechnicalId())).findFirst().orElse(null);
+            TTitleMajor tTitleMajor = tTitleMajors.stream().filter(e -> e.getId().equals(record.getMajorId())).findFirst().orElse(null);
+            record.setRegionName(region.getProvinceName()+"-"+region.getName());
+            record.setTechnicalName(tTechnicalTitle.getTitileName()+"-"+tTitleMajor.getMajorName());
             if (cacheSet!=null){
                 if (cacheSet.contains(record.getId())){
                     record.setIsCollect(1);
@@ -200,9 +202,9 @@
     @ApiOperation(value = "下载累计次数",tags = {"web资料查询"})
     @PostMapping(value = "/downland")
     public R downland(@RequestParam Long id) {
-        TInformation byId = informationService.getById(id);
-        byId.setDownlandNum(byId.getDownlandNum()+1);
-        informationService.updateById(byId);
+        TInformation information = informationService.getById(id);
+        information.setDownlandNum(information.getDownlandNum()+1);
+        informationService.updateById(information);
         return R.ok();
     }
 
@@ -216,11 +218,11 @@
         TInformation record = informationService.getById(id);
         Set<Long> cacheSet = redisCache.getCacheSet("INFORMATION:" + userId);
 
-        TRegion byId = regionService.getById(record.getRegionId());
-        record.setRegionName(byId.getProvinceName()+"-"+byId.getName());
-        TTechnicalTitle byId1 = tTechnicalTitleService.getById(record.getTechnicalId());
-        TTitleMajor byId2 = majorService.getById(record.getMajorId());
-        record.setTechnicalName(byId1.getTitileName()+"-"+byId2.getMajorName()+"-"+record.getLevel());
+        TRegion region = regionService.getById(record.getRegionId());
+        record.setRegionName(region.getProvinceName()+"-"+region.getName());
+        TTechnicalTitle technicalTitle = tTechnicalTitleService.getById(record.getTechnicalId());
+        TTitleMajor titleMajor = majorService.getById(record.getMajorId());
+        record.setTechnicalName(technicalTitle.getTitileName()+"-"+titleMajor.getMajorName()+"-"+record.getLevel());
         if (cacheSet!=null){
             if (cacheSet.contains(record.getId())){
                 record.setIsCollect(1);
@@ -239,17 +241,17 @@
     @PostMapping(value = "/create")
     public R buy( @RequestParam Long id) throws AlipayApiException {
         Long userId = tokenService.getLoginUser().getUserId();
-        TInformation byId = informationService.getById(id);
+        TInformation information = informationService.getById(id);
         String code = "ZL" + WeChatUtil.generateTradeNumber();
         TOrder order = new TOrder();
         order.setCode(code);
         order.setUserId(userId);
         order.setGoodType(2);
         order.setGoodId(id);
-        order.setOrderAmount(byId.getInformationPrice());
-        order.setPaymentAmount(byId.getInformationPrice());
+        order.setOrderAmount(information.getInformationPrice());
+        order.setPaymentAmount(information.getInformationPrice());
 
-        if (byId.getInformationPrice().compareTo(new BigDecimal(0))==0){
+        if (information.getInformationPrice().compareTo(new BigDecimal(0))==0){
             order.setPaymentStatus(2);
 
         }
@@ -263,16 +265,16 @@
     @ApiOperation(value = "购买资料",tags = {"web资料查询"})
     @PostMapping(value = "/buy")
     public R buy(@RequestParam Integer type, @RequestParam Long orderId) throws AlipayApiException {
-        TOrder byId = orderService.getById(orderId);
-        int i = byId.getPaymentAmount().multiply(BigDecimal.valueOf(100)).intValue();
-        TOrder byId1 = orderService.getById(orderId);
+        TOrder order = orderService.getById(orderId);
+        int i = order.getPaymentAmount().multiply(BigDecimal.valueOf(100)).intValue();
+        TOrder tOrder = orderService.getById(orderId);
         if (type == 1) {
             Long userId = tokenService.getLoginUser().getUserId();
 
             com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest prepayRequest = new com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest();
             prepayRequest.setAppid(weChatConfig.appId);
             prepayRequest.setMchid(weChatConfig.merchantId);
-            prepayRequest.setOutTradeNo(byId1.getCode());
+            prepayRequest.setOutTradeNo(tOrder.getCode());
             prepayRequest.setDescription("购买资料");
             prepayRequest.setNotifyUrl("https://0ifzoxq2516g.guyubao.com/call-back/buy");
             com.wechat.pay.java.service.payments.nativepay.model.Amount amount = new com.wechat.pay.java.service.payments.nativepay.model.Amount();
@@ -300,7 +302,7 @@
             }
             return null;
         } else {
-            String qrCode = AlipayTradePagePay.pay("购买资料",byId1.getCode(),byId.getPaymentAmount().toString());
+            String qrCode = AlipayTradePagePay.pay("购买资料",tOrder.getCode(),order.getPaymentAmount().toString());
 
             PayDto payDto = new PayDto();
             payDto.setOrderId(orderId);
@@ -314,12 +316,12 @@
                         while (num <= 30) {
                             int min = 2000;
                             Thread.sleep(min);
-                            Boolean check = AlipayTradeQuery.check(byId.getCode());
+                            Boolean check = AlipayTradeQuery.check(order.getCode());
                             if (check){
-                                byId.setPaymentStatus(2);
-                                byId.setPaymentType(2);
-                                byId.setPayTime(LocalDateTime.now());
-                                orderService.updateById(byId);
+                                order.setPaymentStatus(2);
+                                order.setPaymentType(2);
+                                order.setPayTime(LocalDateTime.now());
+                                orderService.updateById(order);
                             }else {
                                 num++;
                             }

--
Gitblit v1.7.1