Browse Source

房屋导出再次调整

release
jianjun 3 years ago
parent
commit
768664bb95
  1. 37
      epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/IcHouseListResultDTO.java
  2. 58
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java
  3. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java
  4. 2
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/HouseInfoModel.java
  5. 6
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java
  6. 129
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  7. BIN
      epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx
  8. BIN
      epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx
  9. 48
      epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml

37
epmet-module/gov-org/gov-org-client/src/main/java/com/epmet/dto/result/IcHouseListResultDTO.java

@ -1,6 +1,7 @@
package com.epmet.dto.result;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
@ -16,23 +17,43 @@ public class IcHouseListResultDTO implements Serializable {
private static final long serialVersionUID = 4963952996288796744L;
private String houseId;
private String ownerPhone;
private String purpose;
private String doorName;
private String houseType;
private String unitNum;
private String agencyId;
private String buildingId;
private String houseName;
private String buildingName;
private String rentFlag;
private String ownerName;
private String neighborHoodId;
private String purposeKey;
private String neighborHoodName;
private String unitNumKey;
@Excel(name = "所属组织")
private String agencyName;
@Excel(name = "所属网格")
private String gridName;
@Excel(name = "所属小区")
private String neighborHoodName;
@Excel(name = "所属楼栋")
private String buildingName;
@Excel(name = "单元号")
private String unitNum;
@Excel(name = "房屋类型")
private String houseType;
@Excel(name = "房屋用途")
private String purpose;
@Excel(name = "是否出租")
private Integer rentFlagKey;
@Excel(name = "房主姓名")
private String ownerName;
@Excel(name = "房主电话")
private String ownerPhone;
@Excel(name = "房主身份证")
private String ownerIdCard;
private String gridId;
private String houseTypeKey;
private Integer rentFlagKey;
}

58
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java

@ -18,7 +18,6 @@
package com.epmet.controller;
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;
@ -36,7 +35,6 @@ import com.epmet.dto.result.HouseInfoDTO;
import com.epmet.dto.result.IcHouseListResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.dto.result.LoginUserDetailsResultDTO;
import com.epmet.excel.IcHouseExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.service.HouseService;
@ -44,16 +42,14 @@ import com.epmet.util.ExcelPoiUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
@ -170,11 +166,8 @@ public class HouseController implements ResultDataResolver {
*/
@PostMapping("exporttemplate")
public void exportTemplate(HttpServletResponse response) throws Exception {
// ValidatorUtils.validateEntity(ListIcNeighborHoodFormDTO.class);
TemplateExportParams templatePath = new TemplateExportParams("excel/house_template.xlsx");
Map<String, Object> map = new HashMap<>();
map.put("maplist", new ArrayList<IcHouseExcel>());
ExcelPoiUtils.exportExcel(templatePath, map, "房屋信息录入表", response);
ExcelPoiUtils.exportExcel(templatePath, null, "房屋信息录入表", response);
}
@ -188,50 +181,11 @@ public class HouseController implements ResultDataResolver {
@RequestMapping("exporthouseinfo")
public void exporthouseinfo(@RequestBody IcHouseListFormDTO formDTO, HttpServletResponse response) throws Exception {
ValidatorUtils.validateEntity(formDTO);
formDTO.setIsPage(false);
houseService.exportBuildinginfo(formDTO, response);
}
/**
* 导入数据
*
* @param file
* @return
* @throws IOException
*/
@PostMapping("import")
public Result importExcel(@LoginUser TokenDto tokenDTO, @RequestParam("file") MultipartFile file) throws IOException {
String customerId = tokenDTO.getCustomerId();
// String customerId = "123123";
ExcelImportResult<IcHouseExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcHouseExcel.class);
List<IcHouseExcel> failList = importResult.getFailList();
//存放错误数据行号
List<Integer> numList = new ArrayList<>();
if (!CollectionUtils.isEmpty(failList)) {
for (IcHouseExcel entity : failList) {
log.warn("第{}行,{}", entity.getRowNum(), entity.getErrorMsg());//打印失败的行 和失败的信息
numList.add(entity.getRowNum());
}
}
List<IcHouseExcel> result = importResult.getList();
List<Integer> 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("、"));
log.warn(str + "第" + subList + "行未成功!");
return new Result().error(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), str + "第" + subList + "行未成功!");
}
return new Result().ok(str);
}
@PostMapping("queryListHouseInfo")
Result<List<HouseInfoDTO>> queryListHouseInfo(@RequestBody Set<String> houseIds, @RequestParam("customerId") String customerId) {
return new Result<List<HouseInfoDTO>>().ok(houseService.queryListHouseInfo(houseIds, customerId));
@ -240,7 +194,7 @@ public class HouseController implements ResultDataResolver {
@PostMapping("houseimport")
public Result houseImport(@LoginUser TokenDto tokenDTO, @RequestParam("file") MultipartFile file,
@RequestParam("orgId") String orgId,
@RequestParam("orgType") String orgType, HttpServletRequest multipartRequest) {
@RequestParam("orgType") String orgType) {
ImportInfoFormDTO formDTO = new ImportInfoFormDTO();
formDTO.setCustomerId(tokenDTO.getCustomerId());
formDTO.setOrgType(orgType);

3
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/dao/IcHouseDao.java

@ -8,7 +8,6 @@ import com.epmet.dto.result.HousesNameResultDTO;
import com.epmet.dto.result.IcHouseListResultDTO;
import com.epmet.dto.result.NeighborHoodManageDelResultDTO;
import com.epmet.entity.IcHouseEntity;
import com.epmet.excel.IcHouseExcel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -26,8 +25,6 @@ public interface IcHouseDao extends BaseDao<IcHouseEntity> {
List<IcHouseListResultDTO> searchHouseByPage(IcHouseListFormDTO formDTO);
List<IcHouseExcel> searchAllHouse(@Param("house") IcHouseEntity house);
List<HouseInfoDTO> queryHouseInfo(@Param("houseIdList") Set<String> houseIdList);
HouseInfoDTO queryHouseInfoByHouseId(@Param("houseId") String houseId);

2
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/HouseInfoModel.java

@ -38,7 +38,7 @@ public class HouseInfoModel {
@ExcelProperty(value = "房屋用途")
private String purpose;
@ExcelProperty(value = "出租")
@ExcelProperty(value = "房屋状态")
private String rentFlagString;
@ExcelProperty(value = "房主姓名")

6
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java

@ -20,13 +20,12 @@ package com.epmet.service;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.form.IcHouseAddFormDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.IcHouseListFormDTO;
import com.epmet.dto.form.ImportInfoFormDTO;
import com.epmet.dto.form.NeighborHoodManageDelFormDTO;
import com.epmet.dto.result.HouseInfoDTO;
import com.epmet.dto.result.IcHouseListResultDTO;
import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.excel.IcHouseExcel;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
@ -52,9 +51,6 @@ public interface HouseService {
*/
void delHouse(String houseId);
List<Integer> importExcel(String customerId, List<IcHouseExcel> list, String staffId, List<Integer> numList);
PageData<IcHouseListResultDTO> getHouseList(IcHouseListFormDTO formDTO);
void exportBuildinginfo(IcHouseListFormDTO formDTO, HttpServletResponse response) throws Exception;

129
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java

@ -6,7 +6,6 @@ import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.enums.OrgTypeEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
@ -14,7 +13,6 @@ import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.feign.ResultDataResolver;
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.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
@ -35,7 +33,6 @@ import com.epmet.dto.result.ImportTaskCommonResultDTO;
import com.epmet.dto.result.NeighborHoodManageDelResultDTO;
import com.epmet.entity.IcHouseEntity;
import com.epmet.enums.HousePurposeEnums;
import com.epmet.enums.HouseRentFlagEnums;
import com.epmet.enums.HouseTypeEnums;
import com.epmet.excel.IcHouseExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
@ -163,92 +160,6 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
allDelete(formDTO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<Integer> importExcel(String customerId, List<IcHouseExcel> list, String staffId, List<Integer> numList) {
//2021.11.10 需求变更 当前工作人员只能导致自己所属组织下数据,对应不上的数据舍弃【注:需求就这样】 sun
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId);
//组织名称不一样的数据舍弃
Iterator<IcHouseExcel> iterator = list.iterator();
while (iterator.hasNext()) {
IcHouseExcel obj = iterator.next();
if (!obj.getAgencyName().trim().equals(staffInfoCache.getAgencyName())) {
numList.add(obj.getRowNum());
iterator.remove();
}
}
//用于存储匹配不上的数据给前端的提示 如南宁社区不存在
//StringBuffer str = new StringBuffer("");
//end sun
//导入
if(CollectionUtils.isEmpty(list)){
return numList;
}
//获取所有小区 list
// List<String> neighborNameList = list.stream().map(item -> item.getNeighborHoodName()).collect(Collectors.toList());
// List<IcNeighborHoodEntity> neighborHoodList = icNeighborHoodDao.selectList(new QueryWrapper<IcNeighborHoodEntity>().lambda().in(IcNeighborHoodEntity::getNeighborHoodName, neighborNameList));
// Map<String,IcNeighborHoodEntity> neighborHoodMap = neighborHoodList.stream().collect(Collectors.toMap(IcNeighborHoodEntity::getNeighborHoodName, Function.identity(),(key1, key2)->key1));
//获取所有楼宇 list
// List<String> buildingNameList = list.stream().map(item -> item.getBuildingName()).collect(Collectors.toList());
// icBuildingDao.selectList(new QueryWrapper<IcBuildingEntity>().lambda().in(IcBuildingEntity::getBuildingName, buildingNameList).in();
Set<String> neighborNameList = list.stream().map(item -> item.getNeighborHoodName()).collect(Collectors.toSet());
Set<String> buildingNameList = list.stream().map(item -> item.getBuildingName()).collect(Collectors.toSet());
Set<Integer> buildingUnitList = list.stream().map(item -> item.getBuildingUnit()).collect(Collectors.toSet());
List<Map<String,Object>> buildMapList = icBuildingDao.selectListByName(customerId, new ArrayList<String>(neighborNameList),new ArrayList<String>(buildingNameList),new ArrayList<Integer>(buildingUnitList));
//转Map
Map<String,Map<String,Object>> buildMap = new HashMap<>();
buildMapList.forEach(item->{
buildMap.put(item.get("neighborName")+","+item.get("buildingName")+","+item.get("unitNum"),item);
});
//封装数据
List<IcHouseEntity> houseEntityList = new ArrayList<>();
Iterator<IcHouseExcel> iterator1 = list.iterator();
while (iterator1.hasNext()) {
IcHouseExcel icHouseExcel = iterator1.next();
IcHouseEntity entity = new IcHouseEntity();
String uuid = UUID.randomUUID().toString().replace("-", "");
entity.setId(uuid);
entity.setCustomerId(customerId);
Map<String,Object> item = buildMap.get(icHouseExcel.getNeighborHoodName()+","+icHouseExcel.getBuildingName()+","+icHouseExcel.getBuildingUnit());
entity.setNeighborHoodId(String.valueOf(Optional.ofNullable(item).map(u->u.get("neighborId")).orElse("")));
entity.setBuildingId(String.valueOf(Optional.ofNullable(item).map(u->u.get("buildingId")).orElse("")));
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()));
numList.add(icHouseExcel.getRowNum());
iterator1.remove();
continue;
}
entity.setDoorName(icHouseExcel.getDoorName());
entity.setHouseType(HouseTypeEnums.getKeyByValue(icHouseExcel.getHouseType()));
entity.setPurpose(HousePurposeEnums.getKeyByValue(icHouseExcel.getPurpose()));
entity.setRentFlag(HouseRentFlagEnums.getCodeByName(icHouseExcel.getRentFlag()));
entity.setOwnerName(icHouseExcel.getOwnerName());
entity.setOwnerPhone(icHouseExcel.getOwnerPhone());
entity.setOwnerIdCard(icHouseExcel.getOwnerIdCard());
//同一楼栋,单元内,房屋名称唯一
Integer count = icHouseDao.checkDoorNameUq(entity.getNeighborHoodId(), entity.getBuildingId(), entity.getBuildingUnitId(), entity.getDoorName(),null);
if (null != count && count > 0) {
//throw new RenException(EpmetErrorCode.DOOR_NAME_EXITED.getCode(), EpmetErrorCode.DOOR_NAME_EXITED.getMsg());
log.error(EpmetErrorCode.DOOR_NAME_EXITED.getMsg());
numList.add(icHouseExcel.getRowNum());
iterator1.remove();
continue;
}
houseEntityList.add(entity);
}
//3.保存
icHouseService.insertBatch(houseEntityList);
return numList;
}
@Override
public PageData<IcHouseListResultDTO> getHouseList(IcHouseListFormDTO formDTO) {
@ -293,50 +204,14 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
public void exportBuildinginfo(IcHouseListFormDTO formDTO, HttpServletResponse response) throws Exception {
//如果类型是house 查房屋
//导出房屋
List<IcHouseExcel> icHouseExcels = searchAllHouse(formDTO);
PageData<IcHouseListResultDTO> icHouseExcels = getHouseList(formDTO);
TemplateExportParams templatePath = new TemplateExportParams("excel/house_export.xlsx");
Map<String,Object> map = new HashMap<>();
map.put("maplist",icHouseExcels);
map.put("maplist",icHouseExcels.getList());
ExcelPoiUtils.exportExcel(templatePath ,map,"房屋信息录入表",response);
return ;
}
private List<IcHouseExcel> searchAllHouse(IcHouseListFormDTO formDTO) {
//IcNeighborHoodEntity neighbor = ConvertUtils.sourceToTarget(formDTO, IcNeighborHoodEntity.class);
//
//IcBuildingEntity building = ConvertUtils.sourceToTarget(formDTO, IcBuildingEntity.class);
IcHouseEntity house = ConvertUtils.sourceToTarget(formDTO, IcHouseEntity.class);
house.setDelFlag("0");
List<IcHouseExcel> icHouseExcels = icHouseDao.searchAllHouse(house);
icHouseExcels.forEach(item->{
item.setHouseType(HouseTypeEnums.getTypeValue(item.getHouseType()));
item.setPurpose(HousePurposeEnums.getTypeValue(item.getPurpose()));
});
return icHouseExcels;
}
/*private IPage<Map<String, Object>> searchHouse(String buildingId,
String ownerName,
String ownerPhone,
String neighborHoodName,
String buildingName,
Integer pageNo,
Integer pageSize) {
IPage<IcHouseEntity> page = new Page<IcHouseEntity>(pageNo,pageSize);
IPage<Map<String, Object>> mapIPage = icHouseDao.searchHouseByPage(page, buildingId, ownerName, ownerPhone, neighborHoodName, buildingName);
List<Map<String, Object>> records = mapIPage.getRecords();
records.forEach(item->{
item.put("houseType", HouseTypeEnums.getTypeValue(item.get("houseTypeKey")));
item.put("purpose", HousePurposeEnums.getTypeValue(item.get("purposeKey")));
});
return mapIPage;
}*/
@Override
public List<HouseInfoDTO> queryListHouseInfo(Set<String> houseIdList, String customerId) {

BIN
epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_export.xlsx

Binary file not shown.

BIN
epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx

Binary file not shown.

48
epmet-module/gov-org/gov-org-server/src/main/resources/mapper/IcHouseDao.xml

@ -75,15 +75,13 @@
a.HOUSE_NAME as houseName,
c.NEIGHBOR_HOOD_NAME as neighborHoodName,
b.BUILDING_NAME as buildingName,
d.UNIT_NUM as unitNum,
CONCAT(d.UNIT_NUM,'单元') as unitNum,
a.DOOR_NAME as doorName,
(case when a.RENT_FLAG = '0' then '自住'
when a.RENT_FLAG = '1' then '出租'
when a.RENT_FLAG = '2' then '闲置'
else '' end) as rentFlag,
a.OWNER_NAME as ownerName,
/*a.RENT_FLAG as rentFlag,
a.PURPOSE as purpose,*/
a.OWNER_PHONE as ownerPhone,
a.OWNER_ID_CARD as ownerIdCard,
@ -95,11 +93,15 @@
a.PURPOSE as purposeKey,
CAST(a.RENT_FLAG AS CHAR) as rentFlagKey,
c.AGENCY_ID as agencyId,
c.GRID_ID as gridId
ag.ORGANIZATION_NAME agencyName,
c.GRID_ID as gridId,
gr.GRID_NAME
from ic_house a
LEFT JOIN ic_building b on a.BUILDING_ID = b.ID and b.DEL_FLAG = '0'
LEFT JOIN ic_neighbor_hood c on a.NEIGHBOR_HOOD_ID = c.ID and c.DEL_FLAG = '0'
LEFT JOIN ic_building_unit d on a.BUILDING_UNIT_ID = d.ID and d.DEL_FLAG = '0'
LEFT JOIN customer_grid gr on gr.ID = c.GRID_ID and d.DEL_FLAG = '0'
LEFT JOIN customer_agency ag on ag.ID = c.AGENCY_ID and d.DEL_FLAG = '0'
<where>
1 = 1
<if test="pids != null and pids != ''">
@ -145,44 +147,6 @@
CAST(a.DOOR_NAME AS SIGNED),
CONVERT(a.DOOR_NAME using gbk)
</select>
<select id="searchAllHouse" resultType="com.epmet.excel.IcHouseExcel">
select
a.HOUSE_NAME as houseName,
a.DOOR_NAME as doorName,
a.HOUSE_TYPE as houseType,
a.PURPOSE as purpose,
if(a.RENT_FLAG=0,'自住',if(a.RENT_FLAG=1,'出租','闲置')) as rentFlag,
a.OWNER_NAME as ownerName,
a.OWNER_PHONE as ownerPhone,
a.OWNER_ID_CARD as ownerIdCard,
b.BUILDING_NAME as buildingName,
c.NEIGHBOR_HOOD_NAME as neighborHoodName,
d.UNIT_NUM as buildingUnit
from ic_house a
INNER JOIN ic_building b on a.BUILDING_ID = b.ID and b.DEL_FLAG = '0'
INNER JOIN ic_neighbor_hood c on a.NEIGHBOR_HOOD_ID = c.ID and c.DEL_FLAG = '0'
LEFT JOIN ic_building_unit d on a.BUILDING_UNIT_ID = d.ID and d.DEL_FLAG = '0'
<where>
<if test="house.buildingId != null and house.buildingId.trim() != ''">
AND a.BUILDING_ID = #{house.buildingId}
</if>
<if test="house.ownerName != null and house.ownerName.trim() != ''">
AND a.OWNER_NAME like concat('%',#{house.ownerName},'%')
</if>
<if test="house.ownerPhone != null and house.ownerPhone.trim() != ''">
AND a.OWNER_PHONE like concat('%',#{house.ownerPhone},'%')
</if>
<if test="house.delFlag != null and house.delFlag.trim() != ''">
AND a.DEL_FLAG = #{house.delFlag}
</if>
</where>
ORDER BY CONVERT(c.NEIGHBOR_HOOD_NAME using gbk),
CONVERT(b.BUILDING_NAME USING gbk),
CONVERT(d.UNIT_NAME USING gbk),
CAST(a.DOOR_NAME AS SIGNED),
CONVERT(a.DOOR_NAME using gbk)
</select>
<select id="queryHouseInfo" parameterType="map" resultType="com.epmet.dto.result.HouseInfoDTO">
SELECT

Loading…
Cancel
Save