From 62d031c30f9e6562fa9704d92854cf5a7f133a51 Mon Sep 17 00:00:00 2001 From: Jinyuanyuan <1197651512@qq.com> Date: Fri, 27 Sep 2024 16:18:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HuzhouProjectController.java | 7 ++- .../huzhou/entity/HuzhouProjectinfo.java | 4 ++ .../service/IHuzhouProjectinfoService.java | 2 + .../impl/HuzhouProjectinfoServiceImpl.java | 43 +++++++++++++++++-- .../admin/modules/huzhou/vo/ImportSortOV.java | 16 +++++++ .../admin/modules/huzhou/vo/ShowStageOV.java | 2 + 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ImportSortOV.java diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/HuzhouProjectController.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/HuzhouProjectController.java index 01d7644..5d409cb 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/HuzhouProjectController.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/controller/HuzhouProjectController.java @@ -354,5 +354,10 @@ public class HuzhouProjectController { public Result tryImport( MultipartFile file) throws Exception { projectinfoService.updateTypeByImportFile(file); return Result.ok("更新成功"); - }//测试的时候Body选择form-data,key写file,value选择需要导入的文件 + } + @GetMapping("/importSort") + public Result importSort( MultipartFile file) throws Exception { + projectinfoService.updateSortByImportFile(file); + return Result.ok("更新成功"); + } } diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/entity/HuzhouProjectinfo.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/entity/HuzhouProjectinfo.java index e094965..158924d 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/entity/HuzhouProjectinfo.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/entity/HuzhouProjectinfo.java @@ -155,5 +155,9 @@ public class HuzhouProjectinfo extends BaseEntity { */ private Double urtEstimatedAmount; + /** + * 排序 + */ + private Integer sort; } diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/IHuzhouProjectinfoService.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/IHuzhouProjectinfoService.java index 99b1e62..f1f3d44 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/IHuzhouProjectinfoService.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/IHuzhouProjectinfoService.java @@ -205,5 +205,7 @@ public interface IHuzhouProjectinfoService extends IService { void updateTypeByImportFile (MultipartFile file) throws Exception; + void updateSortByImportFile (MultipartFile file) throws Exception; + } diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouProjectinfoServiceImpl.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouProjectinfoServiceImpl.java index b7b8b0f..871963c 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouProjectinfoServiceImpl.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/service/impl/HuzhouProjectinfoServiceImpl.java @@ -1907,8 +1907,6 @@ public class HuzhouProjectinfoServiceImpl extends ServiceImpl sortedRecord = records.stream().filter(x -> x.getSort() != null).sorted(Comparator.comparingInt(ShowStageOV::getSort)).collect(Collectors.toList()); + List commonRecord = records.stream().filter(x -> x.getSort() == null).collect(Collectors.toList()); + sortedRecord.addAll(commonRecord); //手动分页 int fromIndex = (pageNo - 1) * pageSize; - List currentPageData = records.subList(fromIndex, Math.min(fromIndex + pageSize, records.size())); + List currentPageData = sortedRecord.subList(fromIndex, Math.min(fromIndex + pageSize, records.size())); result.setSize(pageSize).setCurrent(pageNo).setRecords(currentPageData).setTotal(projectAndChildInfoList.size()); return result; } @@ -2034,6 +2035,40 @@ public class HuzhouProjectinfoServiceImpl extends ServiceImpl typeMap = new HashMap<>(); + //表格标题行数,默认0 + importParams.setTitleRows(0); + //是否需要校验上传的Excel + importParams.setNeedVerify(true); + ExcelImportResult result = ExcelImportUtil.importExcelMore(file.getInputStream(), ImportSortOV.class, importParams); + int count=0; + if (!result.getList().isEmpty()) { + for (ImportSortOV request : result.getList()) { + int re; + HuzhouProjectinfo projectInfo = new HuzhouProjectinfo(); + projectInfo.setProjectName(request.getName()); + projectInfo.setSort(request.getSort()); + String projectId=""; + //根据项目名称获取id, + LambdaQueryWrapper query=new LambdaQueryWrapper<>(); + query.eq(HuzhouProjectinfo::getProjectName,request.getName()); + List huzhouProjectinfos = projectinfoMapper.selectList(query); + if (huzhouProjectinfos.size()>0){ + projectId=huzhouProjectinfos.get(0).getId(); + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(HuzhouProjectinfo::getId,projectId); + updateWrapper.set(HuzhouProjectinfo::getSort, request.getSort()); + projectinfoMapper.update(null,updateWrapper); + count=count+1; + } + } + System.out.println("更新成功条数"+count); + for (ImportSortOV request : result.getFailList()) { + System.out.println(request); + } + } - + } } diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ImportSortOV.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ImportSortOV.java new file mode 100644 index 0000000..8ff76f3 --- /dev/null +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ImportSortOV.java @@ -0,0 +1,16 @@ +package com.easy.admin.modules.huzhou.vo; + + +import cn.afterturn.easypoi.excel.annotation.Excel; +import io.swagger.v3.oas.models.security.SecurityScheme; +import lombok.Data; + +@Data +public class ImportSortOV { + + @Excel(name = "项目名称") + private String name; + + @Excel(name = "排序") + private Integer sort; +} diff --git a/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ShowStageOV.java b/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ShowStageOV.java index 4669168..e6d87ce 100644 --- a/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ShowStageOV.java +++ b/huzhou/src/main/java/com/easy/admin/modules/huzhou/vo/ShowStageOV.java @@ -24,6 +24,8 @@ public class ShowStageOV { private String acceptanceStage; + private Integer sort; +