diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java index 5b408d1367..f1aac1a9c0 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java @@ -23,6 +23,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; @@ -47,10 +48,8 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** @@ -180,15 +179,24 @@ public class BuildingController { List failList = importResult.getFailList(); + //存放错误数据行号 + List numList = new ArrayList<>(); if(!CollectionUtils.isEmpty(failList)){ for ( IcBuildingExcel entity : failList) { log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg());//打印失败的行 和失败的信息 + numList.add(entity.getRowNum()); } - return new Result().error(8001,failList.get(0).getErrorMsg()); + //return new Result().error(8001,failList.get(0).getErrorMsg()); } List result =importResult.getList(); - - return new Result().ok(buildingService.importExcel(customerId,result,tokenDTO.getUserId())); + List resultList = buildingService.importExcel(customerId,result,tokenDTO.getUserId(),numList); + String str = String.format("共%s条,成功导入%s条。",numList.size()+result.size(),numList.size()+result.size()-resultList.size()); + if(resultList.size()> NumConstant.ZERO){ + Collections.sort(resultList); + String subList = resultList.stream().map(String::valueOf).collect(Collectors.joining("、")); + return new Result().error(9999, str+"第"+subList+"行未成功!"); + } + return new Result().ok(str); } /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java index 1807565cee..a2bb68f09f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java @@ -21,6 +21,7 @@ import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; @@ -42,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; /** @@ -145,15 +147,25 @@ public class HouseController { List failList = importResult.getFailList(); + //存放错误数据行号 + List numList = new ArrayList<>(); if(!CollectionUtils.isEmpty(failList)){ for ( IcHouseExcel entity : failList) { log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg());//打印失败的行 和失败的信息 + numList.add(entity.getRowNum()); } - return new Result().error(8001,failList.get(0).getErrorMsg()); + //return new Result().error(8001,failList.get(0).getErrorMsg()); } List result =importResult.getList(); - return new Result().ok(houseService.importExcel(customerId,result,tokenDTO.getUserId())); + List resultList = houseService.importExcel(customerId,result,tokenDTO.getUserId(),numList); + String str = String.format("共%s条,成功导入%s条。",numList.size()+result.size(),numList.size()+result.size()-resultList.size()); + if(resultList.size()> NumConstant.ZERO){ + Collections.sort(resultList); + String subList = resultList.stream().map(String::valueOf).collect(Collectors.joining("、")); + return new Result().error(9999, str+"第"+subList+"行未成功!"); + } + return new Result().ok(str); } @PostMapping( "queryListHouseInfo") diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java index 11e1f65d6b..cb22dd00f2 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java @@ -22,6 +22,7 @@ import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; @@ -45,10 +46,8 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** @@ -207,16 +206,25 @@ public class NeighborHoodController { // List result = ExcelPoiUtils.importExcel(file, 0, 1, IcNeighborHoodExcel.class); List failList = importResult.getFailList(); + //存放错误数据行号 + List numList = new ArrayList<>(); if(!CollectionUtils.isEmpty(failList)){ for ( IcNeighborHoodExcel entity : failList) { log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg());//打印失败的行 和失败的信息 + numList.add(entity.getRowNum()); } - return new Result().error(8001,failList.get(0).getErrorMsg()); + //return new Result().error(8001,failList.get(0).getErrorMsg()); } List result =importResult.getList(); // log.info(JSON.toJSONString(result)); - neighborHoodService.importExcel(customerId,result,tokenDTO.getUserId()); - return new Result(); + List resultList = neighborHoodService.importExcel(customerId,result,tokenDTO.getUserId(),numList); + String str = String.format("共%s条,成功导入%s条。",numList.size()+result.size(),numList.size()+result.size()-resultList.size()); + if(resultList.size()> NumConstant.ZERO){ + Collections.sort(resultList); + String subList = resultList.stream().map(String::valueOf).collect(Collectors.joining("、")); + return new Result().error(9999, str+"第"+subList+"行未成功!"); + } + return new Result().ok(str); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java index 1a8c8c04e9..405887d709 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java @@ -17,7 +17,6 @@ package com.epmet.service; -import com.epmet.commons.tools.utils.Result; import com.epmet.dto.BuildingTreeLevelDTO; import com.epmet.dto.form.IcBulidingFormDTO; import com.epmet.dto.form.ListIcNeighborHoodFormDTO; @@ -53,7 +52,7 @@ public interface BuildingService { List treeList(String customerId); - Result importExcel(String customerId, List list, String staffId); + List importExcel(String customerId, List list, String staffId, List numList); IcNeighborHoodResultDTO listBuilding(ListIcNeighborHoodFormDTO formDTO); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java index 0fd98dc3df..48ab8c7d1b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java @@ -17,7 +17,6 @@ package com.epmet.service; -import com.epmet.commons.tools.utils.Result; import com.epmet.dto.form.IcHouseFormDTO; import com.epmet.dto.form.ListIcNeighborHoodFormDTO; import com.epmet.dto.result.HouseInfoDTO; @@ -48,7 +47,7 @@ public interface HouseService { void delHouse(String houseId); - Result importExcel(String customerId, List list, String staffId); + List importExcel(String customerId, List list, String staffId, List numList); IcNeighborHoodResultDTO listNeighborhood(ListIcNeighborHoodFormDTO formDTO); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/NeighborHoodService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/NeighborHoodService.java index 266c3b912d..ff1a35f45a 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/NeighborHoodService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/NeighborHoodService.java @@ -52,5 +52,5 @@ public interface NeighborHoodService{ */ void exportNeighborhoodinfo(ListIcNeighborHoodFormDTO formDTO, HttpServletResponse response) throws Exception ; - void importExcel(String customerId,List list,String staffId); + List importExcel(String customerId, List list, String staffId, List numList); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java index 40659b958f..6925d238aa 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java @@ -9,7 +9,6 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.utils.Result; import com.epmet.dao.*; import com.epmet.dto.BuildingTreeLevelDTO; import com.epmet.dto.CustomerStaffAgencyDTO; @@ -210,7 +209,7 @@ public class BuildingServiceImpl implements BuildingService { @Override @Transactional(rollbackFor = Exception.class) - public Result importExcel(String customerId, List list, String staffId) { + public List importExcel(String customerId, List list, String staffId, List numList) { //2021.11.9 需求变更 当前工作人员只能导致自己所属组织下数据,网格名对应不上的数据舍弃【注:需求就这样】 sun CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId); //组织名称不一样的数据舍弃 @@ -218,15 +217,16 @@ public class BuildingServiceImpl implements BuildingService { while (iterator.hasNext()) { IcBuildingExcel obj = iterator.next(); if (!obj.getAgencyName().trim().equals(staffInfoCache.getAgencyName())) { + numList.add(obj.getRowNum()); iterator.remove(); } } //用于存储匹配不上的数据给前端的提示 如南宁社区不存在 - StringBuffer str = new StringBuffer(""); + //StringBuffer str = new StringBuffer(""); //end sun //导入 if(CollectionUtils.isEmpty(list)){ - return new Result(); + return numList; } //查询所有组织和网格根据名字 @@ -252,7 +252,8 @@ public class BuildingServiceImpl implements BuildingService { entity.setCustomerId(customerId); entity.setNeighborHoodId(Optional.ofNullable(neighborHoodMap.get(icBuildingExcel.getNeighborHoodName())).map(u->u.getId()).orElse(""));//neighborHoodMap.get(icBuildingExcel.getNeighborHoodName()).getId() if ("".equals(entity.getNeighborHoodId())) { - str.append("".equals(str) ? icBuildingExcel.getNeighborHoodName() : str.append("、").append(icBuildingExcel.getNeighborHoodName())); + //str.append("".equals(str) ? icBuildingExcel.getNeighborHoodName() : str.append("、").append(icBuildingExcel.getNeighborHoodName())); + numList.add(icBuildingExcel.getRowNum()); continue; } entity.setBuildingName(icBuildingExcel.getBuildingName()); @@ -286,10 +287,10 @@ public class BuildingServiceImpl implements BuildingService { icBuildingService.insertBatch(buildingEntityList); icBuildingUnitService.insertBatch(icBuildingUnitEntityList); - if(!"".equals(str)){ + /* if(!"".equals(str)){ return new Result().error(9999, str.append("不存在").toString()); - } - return new Result(); + }*/ + return numList; } @Override diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java index 2a0ce1465d..ff5dd90ef8 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java @@ -8,7 +8,6 @@ import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.utils.ConvertUtils; -import com.epmet.commons.tools.utils.Result; import com.epmet.dao.IcBuildingDao; import com.epmet.dao.IcBuildingUnitDao; import com.epmet.dao.IcHouseDao; @@ -24,7 +23,6 @@ import com.epmet.entity.IcHouseEntity; import com.epmet.enums.HousePurposeEnums; import com.epmet.enums.HouseRentFlagEnums; import com.epmet.enums.HouseTypeEnums; -import com.epmet.excel.IcBuildingExcel; import com.epmet.excel.IcHouseExcel; import com.epmet.service.HouseService; import com.epmet.service.IcBuildingService; @@ -123,7 +121,8 @@ public class HouseServiceImpl implements HouseService { } @Override - public Result importExcel(String customerId, List list, String staffId) { + @Transactional(rollbackFor = Exception.class) + public List importExcel(String customerId, List list, String staffId, List numList) { //2021.11.10 需求变更 当前工作人员只能导致自己所属组织下数据,对应不上的数据舍弃【注:需求就这样】 sun CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId); //组织名称不一样的数据舍弃 @@ -131,15 +130,16 @@ public class HouseServiceImpl implements HouseService { while (iterator.hasNext()) { IcHouseExcel obj = iterator.next(); if (!obj.getAgencyName().trim().equals(staffInfoCache.getAgencyName())) { + numList.add(obj.getRowNum()); iterator.remove(); } } //用于存储匹配不上的数据给前端的提示 如南宁社区不存在 - StringBuffer str = new StringBuffer(""); + //StringBuffer str = new StringBuffer(""); //end sun //导入 if(CollectionUtils.isEmpty(list)){ - return new Result(); + return numList; } //获取所有小区 list // List neighborNameList = list.stream().map(item -> item.getNeighborHoodName()).collect(Collectors.toList()); @@ -173,7 +173,8 @@ public class HouseServiceImpl implements HouseService { entity.setBuildingUnitId(String.valueOf(Optional.ofNullable(item).map(u->u.get("buildingUnitId")).orElse(""))); entity.setHouseName(icHouseExcel.getBuildingName()+"-"+icHouseExcel.getBuildingUnit()+"-"+icHouseExcel.getDoorName()); if ("".equals(entity.getNeighborHoodId()) || "".equals(entity.getBuildingId()) || "".equals(entity.getBuildingUnitId())) { - str.append("".equals(str) ? icHouseExcel.getBuildingName() + icHouseExcel.getBuildingUnit() : str.append("、").append(icHouseExcel.getBuildingName() + icHouseExcel.getBuildingUnit())); + //str.append("".equals(str) ? icHouseExcel.getBuildingName() + icHouseExcel.getBuildingUnit() : str.append("、").append(icHouseExcel.getBuildingName() + icHouseExcel.getBuildingUnit())); + numList.add(icHouseExcel.getRowNum()); continue; } entity.setDoorName(icHouseExcel.getDoorName()); @@ -193,10 +194,10 @@ public class HouseServiceImpl implements HouseService { //3.保存 icHouseService.insertBatch(houseEntityList); - if(!"".equals(str)){ + /*if(!"".equals(str)){ return new Result().error(9999, str.append("不存在").toString()); - } - return new Result(); + }*/ + return numList; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java index 4e36375890..2e72f0341c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/NeighborHoodServiceImpl.java @@ -240,7 +240,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService { @Override @Transactional(rollbackFor = Exception.class) - public void importExcel(String customerId,List list,String staffId) { + public List importExcel(String customerId,List list,String staffId, List numList) { //2021.11.9 需求变更 当前工作人员只能导致自己所属组织下数据,网格名对应不上的数据舍弃【注:需求就这样】 sun CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId); //组织名称不一样的数据舍弃 @@ -248,6 +248,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService { while (iterator.hasNext()) { IcNeighborHoodExcel obj = iterator.next(); if (!obj.getAgencyName().trim().equals(staffInfoCache.getAgencyName())) { + numList.add(obj.getRowNum()); iterator.remove(); } } @@ -255,7 +256,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService { //导入 if(CollectionUtils.isEmpty(list)){ - return ; + return numList; } //获取所有组织 list List agencyNameList = list.stream().map(item -> item.getAgencyName()).collect(Collectors.toList()); @@ -294,6 +295,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService { entity.setGridId(Optional.ofNullable(gridMap.get(icNeighborHoodExcel.getGridName().trim())).map(u->u.getId()).orElse(""));//gridMap.get(icNeighborHoodExcel.getGridName()).getId() //网格名对应不上的数据舍弃 if ("".equals(entity.getGridId())) { + numList.add(icNeighborHoodExcel.getRowNum()); continue; } entity.setAddress(icNeighborHoodExcel.getAddress()); @@ -312,6 +314,7 @@ public class NeighborHoodServiceImpl implements NeighborHoodService { icNeighborHoodService.insertBatch(neighborHoodEntityList); icNeighborHoodPropertyService.insertBatch(icNeighborHoodPropertyEntityList); + return numList; }