| src/main/java/org/springblade/common/excel/ExcelDictConverter.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/doorplateAddress/service/impl/DoorplateAddressServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/controller/HouseController.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/entity/HouseEntity.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/excel/HouseAndHoldExcel.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/excel/HouseAndHoldImporter.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/service/IHouseService.java | ●●●●● patch | view | raw | blame | history | |
| src/main/java/org/springblade/modules/house/service/impl/HouseServiceImpl.java | ●●●●● patch | view | raw | blame | history |
src/main/java/org/springblade/common/excel/ExcelDictConverter.java
@@ -5,6 +5,8 @@ import com.alibaba.excel.metadata.CellData; import com.alibaba.excel.metadata.GlobalConfiguration; import com.alibaba.excel.metadata.property.ExcelContentProperty; import com.github.xiaoymin.knife4j.core.util.StrUtil; import org.springblade.common.cache.DictBizCache; import org.springblade.common.utils.SpringUtils; import org.springblade.modules.system.entity.DictBiz; import org.springblade.modules.system.service.IDictBizService; @@ -32,9 +34,37 @@ return CellDataTypeEnum.STRING; } /** * 导入excel 解析到java 对象 * @param cellData * @param excelContentProperty * @param globalConfiguration * @return * @throws Exception */ @Override public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { return null; // 获取字典类型 Field field = excelContentProperty.getField(); ExcelDictItemLabel excel = field.getAnnotation(ExcelDictItemLabel.class); String dictType = excel.type(); // 为空返回 String dictLabel = cellData.getStringValue(); if (StrUtil.isBlank(dictLabel)) { return dictLabel; } // 查询字典 List<DictBiz> list = DictBizCache.getList(dictType); //解析返回 String key = ""; for (DictBiz dictBiz : list) { if (dictBiz.getDictValue().equals(dictLabel)){ key = dictBiz.getDictKey(); break; } } // 返回key return key; } /** @@ -51,13 +81,13 @@ Field field = excelContentProperty.getField(); ExcelDictItem excel = field.getAnnotation(ExcelDictItem.class); String dictType = excel.type(); IDictBizService dictBizService = SpringUtils.getBean(IDictBizService.class); List<DictBiz> list = dictBizService.getList(dictType); List<DictBiz> list = DictBizCache.getList(dictType); String value = ""; //解析返回 for (DictBiz dictBiz : list) { if (dictBiz.getDictKey().equals(dictValue)){ value = dictBiz.getDictValue(); break; } } return new CellData(value); src/main/java/org/springblade/modules/doorplateAddress/service/impl/DoorplateAddressServiceImpl.java
@@ -530,7 +530,7 @@ houseEntity.setDistrictCode(doorplateAddressEntity.getAoiCode()); houseEntity.setDistrictName(doorplateAddressEntity.getAoiName()); houseEntity.setHouseName(doorplateAddressEntity.getAddressName()); houseEntity.setFloor(Integer.parseInt(doorplateAddressEntity.getFloor())); houseEntity.setFloor(doorplateAddressEntity.getFloor()); houseEntity.setBuilding(doorplateAddressEntity.getBuildingName()); houseEntity.setUnit(doorplateAddressEntity.getUnitName()); houseEntity.setRoom(doorplateAddressEntity.getHouseName()); src/main/java/org/springblade/modules/house/controller/HouseController.java
@@ -31,6 +31,8 @@ import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.modules.house.excel.HouseAndHoldExcel; import org.springblade.modules.house.excel.HouseAndHoldImporter; import org.springblade.modules.house.excel.HouseImporter; import org.springblade.modules.house.vo.HouseParam; import org.springblade.modules.house.excel.HouseExcel; @@ -172,7 +174,7 @@ /** * 导入房屋 */ @GetMapping("import-house") @PostMapping("import-house") public R importHouse(MultipartFile file, Integer isCovered) { HouseImporter houseImporter = new HouseImporter(houseService, isCovered == 1); ExcelUtil.save(file, houseImporter, HouseExcel.class); @@ -190,4 +192,15 @@ } /** * 导入房屋及住户/租户人员数据 */ @PostMapping("import-houseAndHold") public R importHouseAndHold(MultipartFile file, Integer isCovered) { HouseAndHoldImporter houseImporter = new HouseAndHoldImporter(houseService, isCovered == 1); ExcelUtil.save(file, houseImporter, HouseAndHoldExcel.class); return R.success("操作成功"); } } src/main/java/org/springblade/modules/house/entity/HouseEntity.java
@@ -99,7 +99,7 @@ * 楼层 */ @ApiModelProperty(value = "楼层") private Integer floor; private String floor; /** * 幢 */ src/main/java/org/springblade/modules/house/excel/HouseAndHoldExcel.java
New file @@ -0,0 +1,192 @@ package org.springblade.modules.house.excel; import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import com.alibaba.excel.annotation.write.style.ContentRowHeight; import com.alibaba.excel.annotation.write.style.HeadRowHeight; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import org.springblade.common.excel.ExcelDictConverter; import org.springblade.common.excel.ExcelDictItem; import org.springblade.common.excel.ExcelDictItemLabel; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; /** * HouseExcel * * @author Chill */ @Data @ColumnWidth(25) @HeadRowHeight(20) @ContentRowHeight(18) public class HouseAndHoldExcel implements Serializable { private static final long serialVersionUID = 2L; /** 门牌地址编码 */ @ExcelProperty( "地址编码") private String houseCode; /** 房屋名称 */ @ExcelProperty( "详细地址") private String houseName; /** 小区 */ @ExcelProperty( "小区") private String districtName; /** 幢 */ @ExcelProperty( "幢") private String building; /** 单元 */ @ExcelProperty( "单元") private String unit; /** 楼层 */ @ExcelProperty( "楼层") private String floor; /** 室 */ @ExcelProperty( "室") private String room; /** 面积 */ @ExcelProperty( "面积") private BigDecimal area; /** 物业单价 */ @ExcelProperty( "物业单价") private BigDecimal propertyPrice; /** 服务到期 */ @ExcelProperty( "服务到期") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date serviceDue; /** 备注 */ @ExcelProperty( "备注") private String remark; /** 姓名 */ @ColumnWidth(15) @ExcelProperty( "姓名") private String name; /** 手机号 */ @ColumnWidth(15) @ExcelProperty( "手机号") private String phoneNumber; /** 角色 */ @ColumnWidth(15) @ExcelProperty( value = "角色",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "roleType") private String roleType; /** 与角色关系(业主,父子,其他) */ @ColumnWidth(15) @ExcelProperty( value = "与角色关系",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "roleRelation") private String relationship; /** 主要联系人 1:是 0:否 */ @ColumnWidth(15) @ExcelProperty( value = "主要联系人",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "primaryContactType") private String isPrimaryContact; /** 居住状态 1: 是 0:否 */ @ColumnWidth(15) @ExcelProperty( value = "居住状态",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "residentialStatusType") private String residentialStatus; /** 身份证 */ @ColumnWidth(15) @ExcelProperty( "身份证") private String idCard; /** 港澳台通行证 */ @ColumnWidth(15) @ExcelProperty( "港澳台通行证") private String hkmtPass; /** 护照 */ @ColumnWidth(15) @ExcelProperty( "护照") private String passport; /** 民族 */ @ColumnWidth(15) @ExcelProperty( value = "民族",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "nationType") private String ethnicity; /** 学历 */ @ColumnWidth(15) @ExcelProperty( value = "学历",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "educationType") private String education; /** 户籍登记地 */ @ColumnWidth(15) @ExcelProperty( "户籍登记地") private String hukouRegistration; /** 工作状态 */ @ColumnWidth(15) @ExcelProperty( value = "工作状态",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "workStatusType") private String workStatus; /** 工作单位 */ @ColumnWidth(15) @ExcelProperty( "工作单位") private String employer; /** 婚姻状态 */ @ColumnWidth(15) @ExcelProperty( value = "婚姻状态",converter = ExcelDictConverter.class) @ExcelDictItemLabel(type = "marriageStatusType") private String maritalStatus; /** 车牌号 */ @ColumnWidth(15) @ExcelProperty( "车牌号") private String cardNumber; // /** 其他联系方式 */ // @ColumnWidth(15) // @ExcelProperty( "其他联系方式") // private String otherContact; // // /** 现居住地址 */ // @ColumnWidth(15) // @ExcelProperty( "现居住地址") // private String currentAddress; // // /** 残疾证 */ // @ColumnWidth(15) // @ExcelProperty( "残疾证") // private String disabilityCert; // // /** 是否党员 1:党员 2:群众 */ // @ColumnWidth(15) // @ExcelProperty( value = "是否党员",converter = ExcelDictConverter.class) // @ExcelDictItemLabel(type = "partyEmberType") // private Integer partyEmber; /** 备注 */ @ColumnWidth(15) @ExcelProperty( "备注") private String remarks; } src/main/java/org/springblade/modules/house/excel/HouseAndHoldImporter.java
New file @@ -0,0 +1,40 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.house.excel; import lombok.RequiredArgsConstructor; import org.springblade.core.excel.support.ExcelImporter; import org.springblade.modules.house.service.IHouseService; import java.util.List; /** * 人房数据导入类 * * @author Chill */ @RequiredArgsConstructor public class HouseAndHoldImporter implements ExcelImporter<HouseAndHoldExcel> { private final IHouseService iHouseService; private final Boolean isCovered; @Override public void save(List<HouseAndHoldExcel> data) { iHouseService.importHouseAndHold(data, isCovered); } } src/main/java/org/springblade/modules/house/service/IHouseService.java
@@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.modules.house.entity.HouseEntity; import org.springblade.modules.house.excel.HouseAndHoldExcel; import org.springblade.modules.house.vo.HouseParam; import org.springblade.modules.house.vo.HouseTree; import org.springblade.modules.house.vo.HouseVO; @@ -67,4 +68,11 @@ * @return */ List<HouseTree> getHouseTree(HouseParam houseParam); /** * 人房数据导入 * @param data * @param isCovered */ void importHouseAndHold(List<HouseAndHoldExcel> data, Boolean isCovered); } src/main/java/org/springblade/modules/house/service/impl/HouseServiceImpl.java
@@ -18,11 +18,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.logging.log4j.util.Strings; import org.springblade.common.utils.NodeTreeUtil; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.modules.grid.service.IGridService; import org.springblade.modules.house.entity.HouseEntity; import org.springblade.modules.house.entity.HouseholdEntity; import org.springblade.modules.house.excel.HouseAndHoldExcel; import org.springblade.modules.house.service.IHouseholdService; import org.springblade.modules.house.vo.HouseParam; import org.springblade.modules.house.vo.HouseTree; import org.springblade.modules.house.vo.HouseVO; @@ -34,6 +38,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Objects; @@ -49,6 +54,9 @@ @Autowired private IGridService gridService; @Autowired private IHouseholdService householdService; @Override public IPage<HouseVO> selectHousePage(IPage<HouseVO> page, HouseVO house) { @@ -132,4 +140,111 @@ } return stringList; } /** * 人房数据导入 * @param data * @param isCovered */ @Override public void importHouseAndHold(List<HouseAndHoldExcel> data, Boolean isCovered) { for (HouseAndHoldExcel houseAndHoldExcel : data) { System.out.println("houseAndHoldExcel = " + houseAndHoldExcel); // 保存房屋数据--一个一个插入,防止一个表格中存在多个地址编号相同的数据 saveHouseData(houseAndHoldExcel); // 保存住户数据(包含标签)--一个一个插入,防止一个表格中存在多个地址编号相同的数据 saveHouseholdData(houseAndHoldExcel); // 保存租户数据 } } /** * 保存房屋数据 * @param houseAndHoldExcel */ private void saveHouseholdData(HouseAndHoldExcel houseAndHoldExcel) { // 查询库中是否已存在 QueryWrapper<HouseEntity> wrapper = new QueryWrapper<>(); wrapper.eq("house_code",houseAndHoldExcel.getHouseCode()) .eq("is_deleted",0); HouseEntity one = getOne(wrapper); // 不存在则插入,存在则不操作 if (null == one){ HouseEntity houseEntity = new HouseEntity(); houseEntity.setHouseCode(houseAndHoldExcel.getHouseCode()); houseEntity.setHouseName(houseAndHoldExcel.getHouseName()); houseEntity.setDistrictName(houseAndHoldExcel.getDistrictName()); houseEntity.setUnit(houseAndHoldExcel.getUnit()); houseEntity.setFloor(houseAndHoldExcel.getFloor()); houseEntity.setRoom(houseAndHoldExcel.getRoom()); houseEntity.setBuilding(houseAndHoldExcel.getBuilding()); houseEntity.setArea(houseAndHoldExcel.getArea()); houseEntity.setPropertyPrice(houseAndHoldExcel.getPropertyPrice()); houseEntity.setServiceDue(houseAndHoldExcel.getServiceDue()); houseEntity.setRemark(houseAndHoldExcel.getRemark()); houseEntity.setCreateTime(new Date()); houseEntity.setCreateUser(AuthUtil.getUserId().toString()); houseEntity.setUpdateTime(new Date()); houseEntity.setUpdateUser(AuthUtil.getUserId().toString()); // 新增 save(houseEntity); } } /** * 保存住户数据 * @param houseAndHoldExcel */ private void saveHouseData(HouseAndHoldExcel houseAndHoldExcel) { // 查询库中是否已存在 QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>(); wrapper.eq("house_code",houseAndHoldExcel.getHouseCode()) .eq("is_deleted",0) .eq("phone_number",houseAndHoldExcel.getPhoneNumber()); HouseholdEntity one = householdService.getOne(wrapper); // 不存在则插入,存在则不操作 if (null == one){ HouseholdEntity householdEntity = new HouseholdEntity(); householdEntity.setHouseCode(houseAndHoldExcel.getHouseCode()); householdEntity.setName(houseAndHoldExcel.getName()); householdEntity.setPhoneNumber(houseAndHoldExcel.getPhoneNumber()); if (!Strings.isBlank(houseAndHoldExcel.getRoleType())){ householdEntity.setRoleType(Integer.parseInt(houseAndHoldExcel.getRoleType())); } if (!Strings.isBlank(houseAndHoldExcel.getRelationship())){ householdEntity.setRelationship(Integer.parseInt(houseAndHoldExcel.getRelationship())); } if (!Strings.isBlank(houseAndHoldExcel.getIsPrimaryContact())){ householdEntity.setIsPrimaryContact(Integer.parseInt(houseAndHoldExcel.getIsPrimaryContact())); } if (!Strings.isBlank(houseAndHoldExcel.getResidentialStatus())){ householdEntity.setResidentialStatus(Integer.parseInt(houseAndHoldExcel.getResidentialStatus())); } householdEntity.setIdCard(houseAndHoldExcel.getIdCard()); householdEntity.setHkmtPass(houseAndHoldExcel.getHkmtPass()); householdEntity.setPassport(houseAndHoldExcel.getPassport()); if (!Strings.isBlank(houseAndHoldExcel.getEthnicity())){ householdEntity.setEthnicity(Integer.parseInt(houseAndHoldExcel.getEthnicity())); } if (!Strings.isBlank(houseAndHoldExcel.getEducation())){ householdEntity.setEducation(Integer.parseInt(houseAndHoldExcel.getEducation())); } householdEntity.setHukouRegistration(houseAndHoldExcel.getHukouRegistration()); if (!Strings.isBlank(houseAndHoldExcel.getWorkStatus())){ householdEntity.setWorkStatus(Integer.parseInt(houseAndHoldExcel.getWorkStatus())); } householdEntity.setEmployer(houseAndHoldExcel.getEmployer()); if (!Strings.isBlank(houseAndHoldExcel.getMaritalStatus())){ householdEntity.setMaritalStatus(Integer.parseInt(houseAndHoldExcel.getMaritalStatus())); } householdEntity.setCardNumber(houseAndHoldExcel.getCardNumber()); householdEntity.setRemark(houseAndHoldExcel.getRemarks()); householdEntity.setCreateTime(new Date()); householdEntity.setCreateUser(AuthUtil.getUserId()); householdEntity.setUpdateTime(new Date()); householdEntity.setUpdateUser(AuthUtil.getUserId()); // 新增 householdService.save(householdEntity); } } }