excel批量导入 --renpc
This commit is contained in:
parent
6c17114a5a
commit
01d006b60c
@ -0,0 +1,41 @@
|
||||
package com.cm.population.controller.api.residential;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.cm.population.PopulationApplication;
|
||||
import com.cm.population.pojo.vos.residential.ReadExcelResidentialModel;
|
||||
import com.cm.population.service.building.IBuildingService;
|
||||
import com.cm.population.service.building.impl.BuildingServiceImpl;
|
||||
import com.cm.population.service.residential.IResidentialService;
|
||||
import com.cm.population.service.residential.impl.ResidentialServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ReadExcelController {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String fileName = "C:\\Users\\29492\\Desktop\\稀土路街道小区楼宇批量导入模板.xlsx";
|
||||
List<Object> list = EasyExcel.read(fileName, ReadExcelResidentialModel.class,
|
||||
new AnalysisEventListener<ReadExcelResidentialModel>() {
|
||||
|
||||
@Override
|
||||
public void invoke(ReadExcelResidentialModel data, AnalysisContext context) {
|
||||
if (!data.getCommunity().equals("社区")) {
|
||||
System.out.println(data.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 这里可以在所有数据都被读取完毕后执行一些操作
|
||||
}
|
||||
}).sheet().doReadSync();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.cm.population.controller.api.residential;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.cm.common.annotation.CheckRequestBodyAnnotation;
|
||||
import com.cm.common.base.AbstractController;
|
||||
@ -16,21 +19,22 @@ import com.cm.common.result.SuccessResultList;
|
||||
import com.cm.population.config.properties.ProjectProperties;
|
||||
import com.cm.population.pojo.dtos.community.CommunityDTO;
|
||||
import com.cm.population.pojo.dtos.residential.ResidentialDTO;
|
||||
import com.cm.population.pojo.vos.building.BuildingVO;
|
||||
import com.cm.population.pojo.vos.residential.ReadExcelResidentialModel;
|
||||
import com.cm.population.pojo.vos.residential.ResidentialVO;
|
||||
import com.cm.population.service.building.IBuildingService;
|
||||
import com.cm.population.service.residential.IResidentialService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @ClassName: ResidentialController
|
||||
@ -48,6 +52,8 @@ public class ResidentialController extends AbstractController {
|
||||
private IResidentialService residentialService;
|
||||
@Autowired
|
||||
private ProjectProperties projectProperties;
|
||||
@Autowired
|
||||
private IBuildingService buildingService;
|
||||
|
||||
@ApiOperation(value = "新增小区管理", notes = "新增小区管理接口")
|
||||
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
|
||||
@ -181,4 +187,55 @@ public class ResidentialController extends AbstractController {
|
||||
return communityDTOList;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "新增小区管理", notes = "新增小区管理接口")
|
||||
@GetMapping("excel")
|
||||
public SuccessResult excel() {
|
||||
String fileName = "C:\\Users\\29492\\Desktop\\稀土路街道小区楼宇批量导入模板.xlsx";
|
||||
List<Object> list = EasyExcel.read(fileName, ReadExcelResidentialModel.class,
|
||||
new AnalysisEventListener<ReadExcelResidentialModel>() {
|
||||
|
||||
@Override
|
||||
public void invoke(ReadExcelResidentialModel data, AnalysisContext context) {
|
||||
System.out.println(data.toString());
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (!data.getCommunity().equals("社区")) {
|
||||
// 先查找当前小区是否存在,不存在则新增
|
||||
params.put("streetName", data.getStreet());
|
||||
params.put("communityName", data.getCommunity());
|
||||
params.put("name", data.getResidential());
|
||||
List<ResidentialDTO> residentialDTOList = residentialService.list(params);
|
||||
if(CollectionUtils.isEmpty(residentialDTOList)) {
|
||||
ResidentialVO residentialVO = new ResidentialVO();
|
||||
residentialVO.setStreetName(data.getStreet());
|
||||
residentialVO.setCommunityName(data.getCommunity());
|
||||
residentialVO.setName(data.getResidential());
|
||||
residentialService.save(residentialVO);
|
||||
}
|
||||
|
||||
// 插入楼栋信息,获取小区信息
|
||||
List<ResidentialDTO> residentialDTOList1 = residentialService.list(params);
|
||||
if(!CollectionUtils.isEmpty(residentialDTOList)) {
|
||||
BuildingVO buildingVO = new BuildingVO();
|
||||
buildingVO.setStreetName(data.getStreet());
|
||||
buildingVO.setCommunityName(data.getCommunity());
|
||||
buildingVO.setResidentialId(residentialDTOList1.get(0).getResidentialId());
|
||||
buildingVO.setResidentialName(residentialDTOList1.get(0).getName());
|
||||
buildingVO.setName(data.getName());
|
||||
buildingVO.setBuildNum(data.getBuildingNum());
|
||||
buildingVO.setUnitNum(data.getUnit());
|
||||
buildingVO.setFloorsNum(data.getFloor());
|
||||
buildingService.save(buildingVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 这里可以在所有数据都被读取完毕后执行一些操作
|
||||
}
|
||||
}).sheet().doReadSync();
|
||||
|
||||
return new SuccessResult();
|
||||
}
|
||||
|
||||
}
|
@ -27,11 +27,11 @@ public class BuildingDTO {
|
||||
@ApiModelProperty(name = "name", value = "楼排名称")
|
||||
private String name;
|
||||
@ApiModelProperty(name = "buildNum", value = "楼/排号")
|
||||
private Integer buildNum;
|
||||
private String buildNum;
|
||||
@ApiModelProperty(name = "floorsNum", value = "楼层数")
|
||||
private Integer floorsNum;
|
||||
private String floorsNum;
|
||||
@ApiModelProperty(name = "unitNum", value = "单元/排数")
|
||||
private Integer unitNum;
|
||||
private String unitNum;
|
||||
@ApiModelProperty(name = "address", value = "详细地址")
|
||||
private String address;
|
||||
@ApiModelProperty(name = "longitude", value = "经度")
|
||||
@ -103,27 +103,27 @@ public class BuildingDTO {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getBuildNum() {
|
||||
return buildNum == null ? 0 : buildNum;
|
||||
public String getBuildNum() {
|
||||
return buildNum;
|
||||
}
|
||||
|
||||
public void setBuildNum(Integer buildNum) {
|
||||
public void setBuildNum(String buildNum) {
|
||||
this.buildNum = buildNum;
|
||||
}
|
||||
|
||||
public Integer getFloorsNum() {
|
||||
return floorsNum == null ? 0 : floorsNum;
|
||||
public String getFloorsNum() {
|
||||
return floorsNum;
|
||||
}
|
||||
|
||||
public void setFloorsNum(Integer floorsNum) {
|
||||
public void setFloorsNum(String floorsNum) {
|
||||
this.floorsNum = floorsNum;
|
||||
}
|
||||
|
||||
public Integer getUnitNum() {
|
||||
public String getUnitNum() {
|
||||
return unitNum;
|
||||
}
|
||||
|
||||
public void setUnitNum(Integer unitNum) {
|
||||
public void setUnitNum(String unitNum) {
|
||||
this.unitNum = unitNum;
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,11 @@ public class HouseDTO {
|
||||
@ApiModelProperty(name = "affiliationUnit", value = "所在单元/列")
|
||||
private Integer affiliationUnit;
|
||||
@ApiModelProperty(name = "unitNum", value = "单元/排数")
|
||||
private Integer unitNum;
|
||||
private String unitNum;
|
||||
@ApiModelProperty(name = "affiliationFloors", value = "所在层/院")
|
||||
private Integer affiliationFloors;
|
||||
@ApiModelProperty(name = "floorsNum", value = "楼层数")
|
||||
private Integer floorsNum;
|
||||
private String floorsNum;
|
||||
@ApiModelProperty(name = "houseNum", value = "门牌号")
|
||||
private Integer houseNum;
|
||||
@ApiModelProperty(name = "categoryId", value = "房屋类别")
|
||||
@ -194,13 +194,6 @@ public class HouseDTO {
|
||||
this.affiliationUnit = affiliationUnit;
|
||||
}
|
||||
|
||||
public Integer getUnitNum() {
|
||||
return unitNum;
|
||||
}
|
||||
|
||||
public void setUnitNum(Integer unitNum) {
|
||||
this.unitNum = unitNum;
|
||||
}
|
||||
|
||||
public Integer getAffiliationFloors() {
|
||||
return affiliationFloors;
|
||||
@ -210,11 +203,19 @@ public class HouseDTO {
|
||||
this.affiliationFloors = affiliationFloors;
|
||||
}
|
||||
|
||||
public Integer getFloorsNum() {
|
||||
public String getUnitNum() {
|
||||
return unitNum;
|
||||
}
|
||||
|
||||
public void setUnitNum(String unitNum) {
|
||||
this.unitNum = unitNum;
|
||||
}
|
||||
|
||||
public String getFloorsNum() {
|
||||
return floorsNum;
|
||||
}
|
||||
|
||||
public void setFloorsNum(Integer floorsNum) {
|
||||
public void setFloorsNum(String floorsNum) {
|
||||
this.floorsNum = floorsNum;
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,13 @@ public class BuildingVO {
|
||||
private String name;
|
||||
@ApiModelProperty(name = "buildNum", value = "楼/排号")
|
||||
@CheckNumberAnnotation(name = "楼/排号")
|
||||
private Integer buildNum;
|
||||
private String buildNum;
|
||||
@ApiModelProperty(name = "floorsNum", value = "楼层数")
|
||||
@CheckNumberAnnotation(name = "楼层数")
|
||||
private Integer floorsNum;
|
||||
private String floorsNum;
|
||||
@ApiModelProperty(name = "unitNum", value = "单元/排数")
|
||||
@CheckNumberAnnotation(name = "单元/排数")
|
||||
private Integer unitNum;
|
||||
private String unitNum;
|
||||
@ApiModelProperty(name = "address", value = "详细地址")
|
||||
private String address;
|
||||
@ApiModelProperty(name = "longitude", value = "经度")
|
||||
@ -87,27 +87,27 @@ public class BuildingVO {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getBuildNum() {
|
||||
return buildNum == null ? 0 : buildNum;
|
||||
public String getBuildNum() {
|
||||
return buildNum;
|
||||
}
|
||||
|
||||
public void setBuildNum(Integer buildNum) {
|
||||
public void setBuildNum(String buildNum) {
|
||||
this.buildNum = buildNum;
|
||||
}
|
||||
|
||||
public Integer getFloorsNum() {
|
||||
return floorsNum == null ? 0 : floorsNum;
|
||||
public String getFloorsNum() {
|
||||
return floorsNum;
|
||||
}
|
||||
|
||||
public void setFloorsNum(Integer floorsNum) {
|
||||
public void setFloorsNum(String floorsNum) {
|
||||
this.floorsNum = floorsNum;
|
||||
}
|
||||
|
||||
public Integer getUnitNum() {
|
||||
public String getUnitNum() {
|
||||
return unitNum;
|
||||
}
|
||||
|
||||
public void setUnitNum(Integer unitNum) {
|
||||
public void setUnitNum(String unitNum) {
|
||||
this.unitNum = unitNum;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class HouseVO {
|
||||
private String buildingName;
|
||||
@ApiModelProperty(name = "affiliationUnit", value = "所在单元/列")
|
||||
@CheckNumberAnnotation(name = "所在单元/列")
|
||||
private Integer affiliationUnit;
|
||||
private String affiliationUnit;
|
||||
@ApiModelProperty(name = "affiliationFloors", value = "所在层/院")
|
||||
@CheckNumberAnnotation(name = "所在层/院")
|
||||
private String affiliationFloors;
|
||||
@ -167,11 +167,11 @@ public class HouseVO {
|
||||
this.buildingName = buildingName;
|
||||
}
|
||||
|
||||
public Integer getAffiliationUnit() {
|
||||
return affiliationUnit == null ? 0 : affiliationUnit;
|
||||
public String getAffiliationUnit() {
|
||||
return affiliationUnit;
|
||||
}
|
||||
|
||||
public void setAffiliationUnit(Integer affiliationUnit) {
|
||||
public void setAffiliationUnit(String affiliationUnit) {
|
||||
this.affiliationUnit = affiliationUnit;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.cm.population.pojo.vos.residential;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: ResidentialVO
|
||||
* @Description: 小区管理
|
||||
* @Author: CodeFactory
|
||||
* @Date: 2023-10-25 14:52:32
|
||||
* @Version: 3.0
|
||||
**/
|
||||
@ApiModel
|
||||
public class ReadExcelBuildingModel {
|
||||
|
||||
@ExcelProperty(value = "街道", index = 3)
|
||||
private String name;
|
||||
@ExcelProperty(value = "社区",index = 4)
|
||||
private String buildingNum;
|
||||
@ExcelProperty(value = "小区",index = 5)
|
||||
private String unit;
|
||||
@ExcelProperty(value = "小区",index = 6)
|
||||
private String floor;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getBuildingNum() {
|
||||
return buildingNum;
|
||||
}
|
||||
|
||||
public void setBuildingNum(String buildingNum) {
|
||||
this.buildingNum = buildingNum;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getFloor() {
|
||||
return floor;
|
||||
}
|
||||
|
||||
public void setFloor(String floor) {
|
||||
this.floor = floor;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.cm.population.pojo.vos.residential;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @ClassName: ResidentialVO
|
||||
* @Description: 小区管理
|
||||
* @Author: CodeFactory
|
||||
* @Date: 2023-10-25 14:52:32
|
||||
* @Version: 3.0
|
||||
**/
|
||||
@ApiModel
|
||||
public class ReadExcelResidentialModel {
|
||||
|
||||
@ExcelProperty(value = "街道", index = 0)
|
||||
private String street;
|
||||
@ExcelProperty(value = "社区",index = 1)
|
||||
private String community;
|
||||
@ExcelProperty(value = "小区",index = 2)
|
||||
private String residential;
|
||||
@ExcelProperty(value = "街道", index = 3)
|
||||
private String name;
|
||||
@ExcelProperty(value = "社区",index = 4)
|
||||
private String buildingNum;
|
||||
@ExcelProperty(value = "小区",index = 5)
|
||||
private String unit;
|
||||
@ExcelProperty(value = "小区",index = 6)
|
||||
private String floor;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public String getCommunity() {
|
||||
return community;
|
||||
}
|
||||
|
||||
public void setCommunity(String community) {
|
||||
this.community = community;
|
||||
}
|
||||
|
||||
public String getResidential() {
|
||||
return residential;
|
||||
}
|
||||
|
||||
public void setResidential(String residential) {
|
||||
this.residential = residential;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getBuildingNum() {
|
||||
return buildingNum;
|
||||
}
|
||||
|
||||
public void setBuildingNum(String buildingNum) {
|
||||
this.buildingNum = buildingNum;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
public String getFloor() {
|
||||
return floor;
|
||||
}
|
||||
|
||||
public void setFloor(String floor) {
|
||||
this.floor = floor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ReadExcelResidentialModel{" +
|
||||
"street='" + street + '\'' +
|
||||
", community='" + community + '\'' +
|
||||
", residential='" + residential + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", buildingNum='" + buildingNum + '\'' +
|
||||
", unit='" + unit + '\'' +
|
||||
", floor='" + floor + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -263,8 +263,8 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
||||
// 获取楼栋信息
|
||||
BuildingDTO buildingDTO = buildingService.get(params.get("buildingId").toString());
|
||||
if (null != buildingDTO) {
|
||||
Integer floorsNum = buildingDTO.getFloorsNum();
|
||||
Integer unitNum = buildingDTO.getUnitNum();
|
||||
Integer floorsNum = Integer.valueOf(buildingDTO.getFloorsNum());
|
||||
Integer unitNum = Integer.valueOf(buildingDTO.getUnitNum());
|
||||
|
||||
batchHouseDTO.setFloorCount(floorsNum.toString());
|
||||
batchHouseDTO.setUnitCount(unitNum.toString());
|
||||
@ -370,7 +370,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
||||
insertHouseVO.setBuildingId(buildingId);
|
||||
insertHouseVO.setBuildingName(buildingDTO.getName());
|
||||
|
||||
insertHouseVO.setAffiliationUnit(Integer.valueOf(batchVO.getUnitValue()));
|
||||
insertHouseVO.setAffiliationUnit(batchVO.getUnitValue());
|
||||
insertHouseVO.setAffiliationFloors(floorVO.getFloorValue());
|
||||
insertHouseVO.setHouseNum(houseVO.getHouseValue());
|
||||
saveReturnId(token, insertHouseVO);
|
||||
@ -389,9 +389,9 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
||||
BuildingDTO buildingDTO = buildingService.get(buildingId);
|
||||
if (null != buildingDTO) {
|
||||
// 楼层数
|
||||
int floorsNum = buildingDTO.getFloorsNum();
|
||||
int floorsNum = Integer.valueOf(buildingDTO.getFloorsNum());
|
||||
// 单元数
|
||||
int unitNum = buildingDTO.getUnitNum();
|
||||
int unitNum = Integer.valueOf(buildingDTO.getUnitNum());
|
||||
|
||||
int houseCount = autoHouseDTO.getFloorUnitHouseCount();
|
||||
|
||||
@ -409,7 +409,7 @@ public class HouseServiceImpl extends AbstractService implements IHouseService {
|
||||
houseVO.setBuildingName(buildingDTO.getName());
|
||||
|
||||
// 房屋信息:单元、楼层、房号
|
||||
houseVO.setAffiliationUnit(unit);
|
||||
houseVO.setAffiliationUnit("" + unit);
|
||||
houseVO.setAffiliationFloors(String.valueOf(floor));
|
||||
for (int house = 1; house <= houseCount; house++) {
|
||||
houseVO.setHouseNum(floor + "0" + house);
|
||||
|
Loading…
Reference in New Issue
Block a user