diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/ImportInfoFormDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/ImportInfoFormDTO.java new file mode 100644 index 0000000000..33ad356bb1 --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/ImportInfoFormDTO.java @@ -0,0 +1,34 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2022/2/12 10:38 上午 + * @DESC + */ +@Data +public class ImportInfoFormDTO implements Serializable { + + private static final long serialVersionUID = -3978921489168201769L; + + public interface ImportInfoForm{} + + /** + * 选中的组织ID + */ + @NotBlank(message = "orgId不能为空",groups = ImportInfoForm.class) + private String orgId; + + /** + * 组织类型 agency:组织,grid:网格 + */ + @NotBlank(message = "orgType不能为空",groups = ImportInfoForm.class) + private String orgType; + + private String customerId; + private String userId; +} diff --git a/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/InfoByNamesResultDTO.java b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/InfoByNamesResultDTO.java new file mode 100644 index 0000000000..00e92b3ece --- /dev/null +++ b/epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/InfoByNamesResultDTO.java @@ -0,0 +1,31 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2022/2/12 2:15 下午 + * @DESC + */ +@Data +public class InfoByNamesResultDTO implements Serializable { + + private static final long serialVersionUID = 264490056071606346L; + + private String gridId; + private String agencyId; + + private String gridName; + private String agencyName; + + private String pid; + + private String pids; + + private String parentAgencyId; + + private String agencyPids; + +} diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java index fcd64c4658..806faa2240 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java @@ -28,10 +28,13 @@ import com.epmet.commons.tools.validator.group.AddGroup; import com.epmet.commons.tools.validator.group.DefaultGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.dto.IcNeighborHoodDTO; +import com.epmet.dto.form.ImportInfoFormDTO; import com.epmet.service.IcNeighborHoodService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -85,6 +88,18 @@ public class IcNeighborHoodController { return new Result(); } + /** + * @Description 通过ID查询小区信息 + * @Param ids + * @Return {@link Result< List< IcNeighborHoodDTO>>} + * @Author zhaoqifeng + * @Date 2021/11/8 10:46 + */ + @PostMapping("getlistbyids") + public Result> getListByIds(@RequestBody List ids) { + return new Result>().ok(icNeighborHoodService.getListByIds(ids)); + } + /** * @Description 获取网格下小区列表 * @Param dto @@ -98,15 +113,22 @@ public class IcNeighborHoodController { } /** - * @Description 通过ID查询小区信息 - * @Param ids - * @Return {@link Result< List< IcNeighborHoodDTO>>} - * @Author zhaoqifeng - * @Date 2021/11/8 10:46 + * @Description 小区信息导入 + * @param tokenDTO + * @param file + * @author zxc + * @date 2022/2/12 10:47 上午 */ - @PostMapping("getlistbyids") - public Result> getListByIds(@RequestBody List ids) { - return new Result>().ok(icNeighborHoodService.getListByIds(ids)); + @PostMapping("neighborhoodimport") + public Result neighborhoodImport(@LoginUser TokenDto tokenDTO, @RequestParam("file") MultipartFile file, + @RequestParam("orgId")String orgId, + @RequestParam("orgType")String orgType) throws IOException { + ImportInfoFormDTO formDTO = new ImportInfoFormDTO(); + formDTO.setCustomerId(tokenDTO.getCustomerId()); + formDTO.setOrgType(orgType); + formDTO.setOrgId(orgId); + formDTO.setUserId(tokenDTO.getUserId()); + return new Result().ok(icNeighborHoodService.neighborhoodImport(formDTO,file)); } } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java index 7eef403d38..3dcedd5c73 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java @@ -365,4 +365,13 @@ public interface CustomerGridDao extends BaseDao { @Param("operateUserId") String operateUserId); List getStaffGridList(@Param("customerId") String customerId, @Param("orgId") String orgId, @Param("orgType") String orgType); + + /** + * @Description 根据网格名字查询网格信息 + * @param names + * @author zxc + * @date 2022/2/12 2:06 下午 + */ + List selectGridInfoByNames(@Param("names")List names,@Param("customerId")String customerId); + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java index 6e5d0487eb..3203e96854 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java @@ -51,4 +51,14 @@ public interface IcNeighborHoodDao extends BaseDao { Integer checkNameUq(@Param("customerId") String customerId, @Param("neighborHoodName")String neighborHoodName, @Param("neighborId")String neighborId); + + /** + * @Description 根据小区名查询存在小区 + * @param names + * @param customerId + * @author zxc + * @date 2022/2/12 2:59 下午 + */ + List selectNeighborhoodNameByNames(@Param("names")List names,@Param("customerId") String customerId); + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcNeighborHoodEntity.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcNeighborHoodEntity.java index 62489898d2..42dd382d19 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcNeighborHoodEntity.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcNeighborHoodEntity.java @@ -17,6 +17,7 @@ package com.epmet.entity; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.epmet.commons.mybatis.entity.BaseEpmetEntity; @@ -98,4 +99,6 @@ public class IcNeighborHoodEntity extends BaseEpmetEntity { */ private String location; + @TableField(exist = false) + private String gridName; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcNeighborHoodExcel.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcNeighborHoodExcel.java index 72c57047e0..661d166d53 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcNeighborHoodExcel.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcNeighborHoodExcel.java @@ -21,6 +21,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel; import com.epmet.commons.tools.validator.group.AddGroup; import com.epmet.commons.tools.validator.group.UpdateGroup; import com.epmet.util.ExcelVerifyInfo; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import org.hibernate.validator.constraints.Length; @@ -121,4 +122,13 @@ public class IcNeighborHoodExcel extends ExcelVerifyInfo implements Serializable @Length(max=500,message = "不能超过500个字") private String remark; + @JsonIgnore + private Boolean status = false; + + @JsonIgnore + private Boolean existNameStatus = false; + + @JsonIgnore + private Boolean agencyNameStatus = false; + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java index 3592d82175..fa4305de08 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java @@ -20,9 +20,13 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.dto.result.OptionResultDTO; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.IcNeighborHoodDTO; +import com.epmet.dto.form.ImportInfoFormDTO; import com.epmet.entity.IcNeighborHoodEntity; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; import java.util.Map; @@ -112,4 +116,13 @@ public interface IcNeighborHoodService extends BaseService * @Date 2021/11/8 10:45 */ List getListByIds(List ids); + + /** + * @Description 小区信息导入 + * @param formDTO + * @param file + * @author zxc + * @date 2022/2/12 11:11 上午 + */ + Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException; } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java index 3d5b6fa96b..f8f4bf189e 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java @@ -17,30 +17,45 @@ package com.epmet.service.impl; +import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.FieldConstant; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionResultDTO; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.redis.common.CustomerOrgRedis; import com.epmet.commons.tools.redis.common.CustomerStaffRedis; +import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; +import com.epmet.commons.tools.redis.common.bean.GridInfoCache; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; +import com.epmet.constant.CustomerGridConstant; +import com.epmet.dao.CustomerGridDao; import com.epmet.dao.IcNeighborHoodDao; import com.epmet.dto.IcNeighborHoodDTO; +import com.epmet.dto.form.ImportInfoFormDTO; +import com.epmet.dto.result.InfoByNamesResultDTO; import com.epmet.entity.IcNeighborHoodEntity; +import com.epmet.excel.IcBuildingExcel; +import com.epmet.excel.IcNeighborHoodExcel; import com.epmet.service.IcNeighborHoodService; +import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.ListUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.util.*; import java.util.stream.Collectors; /** @@ -53,6 +68,8 @@ import java.util.stream.Collectors; @Service public class IcNeighborHoodServiceImpl extends BaseServiceImpl implements IcNeighborHoodService { + @Autowired + private CustomerGridDao customerGridDao; @Override public PageData page(Map params) { @@ -160,4 +177,152 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class); + List failList = importResult.getFailList(); + //存放错误数据行号 + List numList = new ArrayList<>(); + if(CollectionUtils.isNotEmpty(failList)){ + for ( IcNeighborHoodExcel entity : failList) { + //打印失败的行 和失败的信息 + log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg()); + numList.add(entity.getRowNum()); + } + } + List result =importResult.getList(); + return disposeImportNeighborhood(formDTO,result); + } + + /** + * @Description 根据左侧树选中的层级,可导入对应数据: + * 1. 选中社区可导入该社区下所有小区信息、楼宇信息、房屋信息(没有匹配的小区、楼宇均新增,网格没有对应的不新增); + * 2. 选中网格可导入该网格下所有小区信息、楼宇信息、房屋信息(没有匹配的小区、楼宇均新增); + * 3. 选中小区可导入该小区下所有楼宇信息、房屋信息(没有匹配的楼宇均新增); + * 4. 选中楼宇可导入该楼宇下所有房屋信息。 + * @param formDTO + * @param result + * @author zxc + * @date 2022/2/12 2:02 下午 + */ + public Result disposeImportNeighborhood(ImportInfoFormDTO formDTO, List result){ + if (CollectionUtils.isEmpty(result)){ + return new Result().error(9999,"excel表格内没有数据"); + } + List nums = new ArrayList<>(); + List gridNames = result.stream().map(m -> m.getGridName()).collect(Collectors.toList()); + // 1. 查询数据网格是否存在 + List gridInfos = customerGridDao.selectGridInfoByNames(gridNames, formDTO.getCustomerId()); + if (CollectionUtils.isEmpty(gridInfos)){ + // 网格没有对应的不新增 + for (int i = NumConstant.ONE; i <= result.size(); i++) { + nums.add(i); + } + String str = String.format("共%s条,成功导入%s条。",result.size(),0); + return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); + } + result.forEach(r -> { + for (InfoByNamesResultDTO g : gridInfos) { + if (r.getGridName().equals(g.getGridName())){ + r.setStatus(true); + break; + } + } + }); + Map> groupStatus = result.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getStatus)); + // 只获取能查询到的网格 + List neighborHoods = groupStatus.get(true); + // 2. 查询组织选中组织下存在的小区 + List existNames = baseDao.selectNeighborhoodNameByNames(neighborHoods.stream().map(m -> m.getNeighborHoodName()).collect(Collectors.toList()), formDTO.getCustomerId()); + // 为了显示多少行插入成功,未成功 + result.forEach(r -> { + for (String s : existNames) { + if (r.getNeighborHoodName().equals(s)){ + r.setExistNameStatus(true); + break; + } + } + }); + Map> groupByExistName = neighborHoods.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getExistNameStatus)); + // 获取需要插入的数据 + List needInsert = groupByExistName.get(false); + if (CollectionUtils.isEmpty(needInsert)){ + for (int i = NumConstant.ONE; i <= result.size(); i++) { + nums.add(i); + } + String str = String.format("共%s条,成功导入%s条。",result.size(),0); + return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); + } + if (formDTO.getOrgType().equals(CustomerGridConstant.AGENCY)){ + AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getOrgId()); + if (null == agencyInfo){ + throw new EpmetException("未查询到组织信息..."); + } + needInsert.forEach(n -> { + if (agencyInfo.getOrganizationName().equals(n.getAgencyName())){ + n.setAgencyNameStatus(true); + } + }); + }else { + GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(formDTO.getOrgId()); + if (null == gridInfo){ + throw new EpmetException("未查询到网格信息..."); + } + needInsert.forEach(n -> { + if (gridInfo.getGridName().equals(n.getGridName())){ + n.setAgencyNameStatus(true); + } + }); + } + Map> groupByAgencyNameStatus = needInsert.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getAgencyNameStatus)); + List finalNeedInsert = groupByAgencyNameStatus.get(true); + if (CollectionUtils.isEmpty(finalNeedInsert)){ + for (int i = NumConstant.ONE; i <= result.size(); i++) { + nums.add(i); + } + String str = String.format("共%s条,成功导入%s条。",result.size(),0); + return new Result().error(9999,str +"第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); + } + List entities = ConvertUtils.sourceToTarget(finalNeedInsert, IcNeighborHoodEntity.class); + entities.forEach(e -> { + for (InfoByNamesResultDTO g : gridInfos) { + if (e.getGridName().equals(g.getGridName())){ + e.setAgencyId(g.getAgencyId()); + e.setAgencyPids(g.getAgencyPids()); + e.setCustomerId(formDTO.getCustomerId()); + e.setGridId(g.getGridId()); + e.setParentAgencyId(g.getParentAgencyId()); + break; + } + } + }); + + importInsert(entities); + for (int i = NumConstant.ZERO; i < result.size(); i++) { + if (result.get(i).getStatus() == false || result.get(i).getExistNameStatus() == true || result.get(i).getAgencyNameStatus() == false){ + nums.add(i + NumConstant.ONE); + } + } + String str = String.format("共%s条,成功导入%s条。",result.size(),entities.size()); + if (CollectionUtils.isNotEmpty(nums)){ + return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); + } + return new Result().ok(str); + } + + @Transactional(rollbackFor = Exception.class) + public void importInsert(List entities){ + List> partition = ListUtils.partition(entities, NumConstant.ONE_HUNDRED); + partition.forEach(p -> { + insertBatch(p); + }); + } + } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml index a70cf1d9b6..623ca76ed4 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml @@ -806,4 +806,23 @@ + + + diff --git a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml index 73c23350d7..36daaf0d27 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml +++ b/epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml @@ -214,4 +214,18 @@ and a.id !=#{neighborId} + + +