Browse Source

小区信息导入

dev
zxc 4 years ago
parent
commit
691b65179d
  1. 34
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/form/ImportInfoFormDTO.java
  2. 31
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/InfoByNamesResultDTO.java
  3. 38
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/IcNeighborHoodController.java
  4. 9
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java
  5. 10
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java
  6. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/entity/IcNeighborHoodEntity.java
  7. 10
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/IcNeighborHoodExcel.java
  8. 13
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/IcNeighborHoodService.java
  9. 173
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java
  10. 19
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml
  11. 14
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml

34
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;
}

31
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;
}

38
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<List<IcNeighborHoodDTO>> getListByIds(@RequestBody List<String> ids) {
return new Result<List<IcNeighborHoodDTO>>().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<List<IcNeighborHoodDTO>> getListByIds(@RequestBody List<String> ids) {
return new Result<List<IcNeighborHoodDTO>>().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));
}
}

9
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/CustomerGridDao.java

@ -365,4 +365,13 @@ public interface CustomerGridDao extends BaseDao<CustomerGridEntity> {
@Param("operateUserId") String operateUserId);
List<CustomerStaffGridResultDTO> 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<InfoByNamesResultDTO> selectGridInfoByNames(@Param("names")List<String> names,@Param("customerId")String customerId);
}

10
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcNeighborHoodDao.java

@ -51,4 +51,14 @@ public interface IcNeighborHoodDao extends BaseDao<IcNeighborHoodEntity> {
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<String> selectNeighborhoodNameByNames(@Param("names")List<String> names,@Param("customerId") String customerId);
}

3
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;
}

10
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;
}

13
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<IcNeighborHoodEntity>
* @Date 2021/11/8 10:45
*/
List<IcNeighborHoodDTO> getListByIds(List<String> ids);
/**
* @Description 小区信息导入
* @param formDTO
* @param file
* @author zxc
* @date 2022/2/12 11:11 上午
*/
Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException;
}

173
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<IcNeighborHoodDao, IcNeighborHoodEntity> implements IcNeighborHoodService {
@Autowired
private CustomerGridDao customerGridDao;
@Override
public PageData<IcNeighborHoodDTO> page(Map<String, Object> params) {
@ -160,4 +177,152 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
return ConvertUtils.sourceToTarget(list, IcNeighborHoodDTO.class);
}
/**
* @Description 小区信息导入
* @param formDTO
* @param file
* @author zxc
* @date 2022/2/12 11:11 上午
*/
@Override
public Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException {
ExcelImportResult<IcNeighborHoodExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class);
List<IcNeighborHoodExcel> failList = importResult.getFailList();
//存放错误数据行号
List<Integer> numList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(failList)){
for ( IcNeighborHoodExcel entity : failList) {
//打印失败的行 和失败的信息
log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg());
numList.add(entity.getRowNum());
}
}
List<IcNeighborHoodExcel> 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<IcNeighborHoodExcel> result){
if (CollectionUtils.isEmpty(result)){
return new Result().error(9999,"excel表格内没有数据");
}
List<Integer> nums = new ArrayList<>();
List<String> gridNames = result.stream().map(m -> m.getGridName()).collect(Collectors.toList());
// 1. 查询数据网格是否存在
List<InfoByNamesResultDTO> 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<Boolean, List<IcNeighborHoodExcel>> groupStatus = result.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getStatus));
// 只获取能查询到的网格
List<IcNeighborHoodExcel> neighborHoods = groupStatus.get(true);
// 2. 查询组织选中组织下存在的小区
List<String> 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<Boolean, List<IcNeighborHoodExcel>> groupByExistName = neighborHoods.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getExistNameStatus));
// 获取需要插入的数据
List<IcNeighborHoodExcel> 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<Boolean, List<IcNeighborHoodExcel>> groupByAgencyNameStatus = needInsert.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getAgencyNameStatus));
List<IcNeighborHoodExcel> 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<IcNeighborHoodEntity> 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<IcNeighborHoodEntity> entities){
List<List<IcNeighborHoodEntity>> partition = ListUtils.partition(entities, NumConstant.ONE_HUNDRED);
partition.forEach(p -> {
insertBatch(p);
});
}
}

19
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/CustomerGridDao.xml

@ -806,4 +806,23 @@
</if>
</select>
<!-- 根据网格名字查询网格信息 -->
<select id="selectGridInfoByNames" resultType="com.epmet.dto.result.InfoByNamesResultDTO">
SELECT
g.ID AS gridId,
g.GRID_NAME AS gridName,
a.ID AS agencyId,
a.PID AS parentAgencyId,
a.PIDS AS agencyPids
FROM customer_grid g
INNER JOIN customer_agency a ON (a.ID = g.PID AND a.DEL_FLAG = '0')
WHERE g.DEL_FLAG = 0
AND g.CUSTOMER_ID = #{customerId}
AND g.GRID_NAME IN (
<foreach collection="names" item="n" separator=",">
#{n}
</foreach>
)
</select>
</mapper>

14
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcNeighborHoodDao.xml

@ -214,4 +214,18 @@
and a.id !=#{neighborId}
</if>
</select>
<!-- 根据小区名查询存在小区 -->
<select id="selectNeighborhoodNameByNames" resultType="java.lang.String">
SELECT
NEIGHBOR_HOOD_NAME
FROM ic_neighbor_hood
WHERE DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
AND NEIGHBOR_HOOD_NAME IN (
<foreach collection="names" item="n" separator=",">
#{n}
</foreach>
)
</select>
</mapper>

Loading…
Cancel
Save