Browse Source

ljx:编写分页list兼容若依

ljx 1 month ago
parent
commit
94c3b46328

+ 15 - 2
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/controller/MatchController.java

@@ -1,10 +1,14 @@
 package com.enteprise.matchAnalysis.controller;
 
+import com.enteprise.common.constant.HttpStatus;
 import com.enteprise.common.core.controller.BaseController;
+import com.enteprise.common.core.page.PageDomain;
 import com.enteprise.common.core.page.TableDataInfo;
+import com.enteprise.common.core.page.TableSupport;
 import com.enteprise.matchAnalysis.domain.MatchAna;
 import com.enteprise.matchAnalysis.domain.dto.MatchDto;
 import com.enteprise.matchAnalysis.service.IMatchService;
+import com.github.pagehelper.PageInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.RestController;
 
 import java.util.List;
 
+import static com.enteprise.util.CommonUtil.startPageL;
+
 
 @RestController
 @RequestMapping("/match/match")
@@ -25,8 +31,15 @@ public class MatchController extends BaseController {
     @PostMapping("/list")
     public TableDataInfo analysisGrowthRate(@RequestBody MatchAna matchAna)
     {
-        startPage();
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        Integer pageNum = pageDomain.getPageNum();
+        Integer pageSize = pageDomain.getPageSize();
         List<MatchDto> list = matchService.matchAnalysisList(matchAna);
-        return getDataTable(list);
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(startPageL(list, pageNum, pageSize));
+        rspData.setTotal(new PageInfo(list).getTotal());
+        return rspData;
     }
 }

+ 2 - 3
enteprise-admin/src/main/java/com/enteprise/matchAnalysis/service/impl/MatchServiceImpl.java

@@ -4,17 +4,15 @@ import com.enteprise.base_data_month.domain.EnterpriseBaseDataMonth;
 import com.enteprise.base_data_month.mapper.EnterpriseBaseDataMonthMapper;
 import com.enteprise.base_data_year.domain.EnterpriseBaseDataYear;
 import com.enteprise.base_data_year.mapper.EnterpriseBaseDataYearMapper;
+import com.enteprise.common.utils.PageUtils;
 import com.enteprise.enterprise.domain.Enterprise;
 import com.enteprise.enterprise.dto.EnterpriseDto;
 import com.enteprise.enterprise.mapper.EnterpriseMapper;
-import com.enteprise.growthRate.domain.dto.GrowthRateDto;
 import com.enteprise.industry_run.domain.EnterpriseBaseDataTotal;
 import com.enteprise.industry_run.mapper.EnterpriseBaseDataTotalMapper;
 import com.enteprise.matchAnalysis.domain.MatchAna;
 import com.enteprise.matchAnalysis.domain.dto.MatchDto;
 import com.enteprise.matchAnalysis.service.IMatchService;
-import com.enteprise.season.domain.EnterpriseBaseDataSeason;
-import com.enteprise.season.mapper.EnterpriseBaseDataSeasonMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -53,6 +51,7 @@ public class MatchServiceImpl implements IMatchService {
         enterprise.setCode(matchAna.getCode());
         enterprise.setTypeNum(matchAna.getTypeNum());
         List<EnterpriseDto> enterpriseDtos = sortByNumberInName(enterpriseMapper.selectAllWithType(enterprise));
+        PageUtils.startPage();
         //对应评估类型业务逻辑
         if (dataKey.equals("powerConsume")){
             //用电逻辑,月度指标

+ 31 - 1
enteprise-admin/src/main/java/com/enteprise/util/CommonUtil.java

@@ -49,4 +49,34 @@ public class CommonUtil {
         String numberPart = name.replaceAll("\\D+", ""); // 去掉非数字字符
         return Integer.parseInt(numberPart.isEmpty() ? "0" : numberPart); // 转换为整数,默认返回 0
     }
-}
+
+        public static List startPageL(List list, Integer pageNum, Integer pageSize) {
+            if (list == null) {
+                return null;
+            }
+            if (list.size() == 0) {
+                return null;
+            }
+            Integer count = list.size(); // 记录总数
+            Integer pageCount = 0; // 页数
+            if (count % pageSize == 0) {
+                pageCount = count / pageSize;
+            } else {
+                pageCount = count / pageSize + 1;
+            }
+            int fromIndex = 0; // 开始索引
+            int toIndex = 0; // 结束索引
+            if (pageNum != pageCount) {
+                fromIndex = (pageNum - 1) * pageSize;
+                toIndex = fromIndex + pageSize;
+            } else {
+                fromIndex = (pageNum - 1) * pageSize;
+                toIndex = count;
+            }
+            List pageList = list.subList(fromIndex, toIndex);
+            return pageList;
+        }
+
+    }
+
+