From b6373daa40c3dc17ca107f3666fd252f3b6b0778 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 03 一月 2025 18:34:52 +0800
Subject: [PATCH] 代码

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TInformationController.java |  137 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 98 insertions(+), 39 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 1866ba8..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
@@ -31,9 +31,11 @@
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -54,6 +56,8 @@
     private TTechnicalTitleService tTechnicalTitleService;
     @Resource
     private TTitleMajorService majorService;
+    @Resource
+    private TLevelService levelService;
     @Resource
     private TokenService tokenService;
     @Resource
@@ -95,25 +99,80 @@
     @PostMapping(value = "/list")
     public R<Page<TInformation>> list(@RequestBody InformationQuery informationQuery) {
         Long userId = tokenService.getLoginUser().getUserId();
+        Page<TInformation> page;
+        if(StringUtils.isEmpty(informationQuery.getProvinceName())){
+            if (informationQuery.getSortType()==1){
+                page = informationService.lambdaQuery()
+                        .like(!StringUtils.isEmpty(informationQuery.getInformationName()), TInformation::getInformationName, informationQuery.getInformationName())
+                        .eq(informationQuery.getRegionId() != null, TInformation::getRegionId, informationQuery.getRegionId())
+                        .eq(informationQuery.getTechnicalId() != null, TInformation::getTechnicalId, informationQuery.getTechnicalId())
+                        .eq(informationQuery.getMajorId() != null, TInformation::getMajorId, informationQuery.getMajorId())
+                        .eq(informationQuery.getLevel() != null, TInformation::getLevel, informationQuery.getLevel())
+                        .eq(informationQuery.getFree()!=null&&informationQuery.getFree() == 1, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .ne(informationQuery.getFree()!=null&&informationQuery.getFree() == 2, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .orderByDesc(TInformation::getCreateTime)
+                        .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
+            }else {
+                page = informationService.lambdaQuery()
+                        .like(!StringUtils.isEmpty(informationQuery.getInformationName()), TInformation::getInformationName, informationQuery.getInformationName())
+                        .eq(informationQuery.getRegionId() != null, TInformation::getRegionId, informationQuery.getRegionId())
+                        .eq(informationQuery.getTechnicalId() != null, TInformation::getTechnicalId, informationQuery.getTechnicalId())
+                        .eq(informationQuery.getMajorId() != null, TInformation::getMajorId, informationQuery.getMajorId())
+                        .eq(informationQuery.getLevel() != null, TInformation::getLevel, informationQuery.getLevel())
+                        .eq(informationQuery.getFree()!=null&&informationQuery.getFree() == 1, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .ne(informationQuery.getFree()!=null&&informationQuery.getFree() == 2, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .orderByDesc(TInformation::getCommitteeSort)
+                        .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
+            }
+        }else {
+            List<TRegion> list;
+            // 查询省份下的市
+            if(informationQuery.getProvinceName().equals("直辖市")){
+                List<String> cityList = new ArrayList<>();
+                cityList.add("北京市");
+                cityList.add("天津市");
+                cityList.add("重庆市");
+                cityList.add("上海市");
+                list = regionService.lambdaQuery().in(TRegion::getProvinceName, cityList).list();
+            }else {
+                list = regionService.lambdaQuery().eq(TRegion::getProvinceName, informationQuery.getProvinceName()).list();
+            }
+            List<Integer> ids = list.stream().map(TRegion::getId).collect(Collectors.toList());
+            if (informationQuery.getSortType()==1){
+                page = informationService.lambdaQuery()
+                        .like(!StringUtils.isEmpty(informationQuery.getInformationName()), TInformation::getInformationName, informationQuery.getInformationName())
+                        .in( TInformation::getRegionId, ids)
+                        .eq(informationQuery.getTechnicalId() != null, TInformation::getTechnicalId, informationQuery.getTechnicalId())
+                        .eq(informationQuery.getMajorId() != null, TInformation::getMajorId, informationQuery.getMajorId())
+                        .eq(informationQuery.getLevel() != null, TInformation::getLevel, informationQuery.getLevel())
+                        .eq(informationQuery.getFree()!=null&&informationQuery.getFree() == 1, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .ne(informationQuery.getFree()!=null&&informationQuery.getFree() == 2, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .orderByDesc(TInformation::getCreateTime)
+                        .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
+            }else {
+                page = informationService.lambdaQuery()
+                        .like(!StringUtils.isEmpty(informationQuery.getInformationName()), TInformation::getInformationName, informationQuery.getInformationName())
+                        .in( TInformation::getRegionId, ids)
+                        .eq(informationQuery.getTechnicalId() != null, TInformation::getTechnicalId, informationQuery.getTechnicalId())
+                        .eq(informationQuery.getMajorId() != null, TInformation::getMajorId, informationQuery.getMajorId())
+                        .eq(informationQuery.getLevel() != null, TInformation::getLevel, informationQuery.getLevel())
+                        .eq(informationQuery.getFree()!=null&&informationQuery.getFree() == 1, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .ne(informationQuery.getFree()!=null&&informationQuery.getFree() == 2, TInformation::getInformationPrice, BigDecimal.ZERO)
+                        .orderByDesc(TInformation::getCommitteeSort)
+                        .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
+            }
+        }
 
-        Page<TInformation> page = informationService.lambdaQuery()
-                .like(!StringUtils.isEmpty(informationQuery.getInformationName()), TInformation::getInformationName, informationQuery.getInformationName())
-                .eq(informationQuery.getRegionId() != null, TInformation::getRegionId, informationQuery.getRegionId())
-                .eq(informationQuery.getTechnicalId() != null, TInformation::getTechnicalId, informationQuery.getTechnicalId())
-                .eq(informationQuery.getMajorId() != null, TInformation::getMajorId, informationQuery.getMajorId())
-                .eq(informationQuery.getLevel() != null, TInformation::getLevel, informationQuery.getLevel())
-                .eq(informationQuery.getFree()!=null&&informationQuery.getFree() == 1, TInformation::getInformationPrice, BigDecimal.ZERO)
-                .ne(informationQuery.getFree()!=null&&informationQuery.getFree() == 2, TInformation::getInformationPrice, BigDecimal.ZERO)
-                .orderByDesc(TInformation::getCommitteeSort)
-                .page(Page.of(informationQuery.getPageNum(), informationQuery.getPageSize()));
         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);
@@ -143,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();
     }
 
@@ -159,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());
+        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);
@@ -182,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);
 
         }
@@ -206,18 +265,18 @@
     @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("http://www.zhipingwang.com.cn:8081/call-back/buy");
+            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();
             amount.setTotal(i);
             prepayRequest.setAmount(amount);
@@ -243,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);
@@ -257,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