From fe81eb39c7402082f54e6aaee491efbcbb1aa50a Mon Sep 17 00:00:00 2001
From: linwe <872216996@qq.com>
Date: Wed, 15 May 2024 13:13:40 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.java                 |    4 
 src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.xml             |   17 +
 src/main/java/org/springblade/modules/house/excel/ImportHouseholdExcel.java             |  219 ++++++++++++++++++
 src/main/java/org/springblade/modules/house/service/IUserHouseLabelService.java         |    7 
 src/main/java/org/springblade/modules/house/service/impl/UserHouseLabelServiceImpl.java |   17 +
 src/main/java/org/springblade/modules/house/service/IHouseService.java                  |    7 
 src/main/resources/application-test.yml                                                 |    2 
 /dev/null                                                                               |  169 --------------
 src/main/java/org/springblade/modules/house/controller/HouseholdController.java         |   62 ++++
 src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml                  |    2 
 src/main/java/org/springblade/modules/house/excel/HouseHoldImporter.java                |   21 -
 src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.java            |    8 
 src/main/java/org/springblade/modules/house/service/IHouseholdService.java              |    6 
 src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java      |  154 +++++++++++
 14 files changed, 477 insertions(+), 218 deletions(-)

diff --git a/src/main/java/org/springblade/modules/house/controller/HouseholdController.java b/src/main/java/org/springblade/modules/house/controller/HouseholdController.java
index cf113ed..9006d60 100644
--- a/src/main/java/org/springblade/modules/house/controller/HouseholdController.java
+++ b/src/main/java/org/springblade/modules/house/controller/HouseholdController.java
@@ -21,7 +21,6 @@
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
-import liquibase.pro.packaged.S;
 import lombok.AllArgsConstructor;
 import org.springblade.common.node.TreeIntegerNode;
 import org.springblade.core.boot.ctrl.BladeController;
@@ -35,7 +34,7 @@
 import org.springblade.core.tool.jackson.JsonUtil;
 import org.springblade.core.tool.utils.DateUtil;
 import org.springblade.modules.house.entity.HouseholdEntity;
-import org.springblade.modules.house.excel.HouseHoldExcel;
+import org.springblade.modules.house.excel.ImportHouseholdExcel;
 import org.springblade.modules.house.excel.HouseHoldImporter;
 import org.springblade.modules.house.service.IHouseholdService;
 import org.springblade.modules.house.vo.HouseholdVO;
@@ -46,8 +45,8 @@
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 住户 控制器
@@ -226,26 +225,69 @@
 	}
 
 	/**
-	 * 导入用户
+	 * 导入住户
 	 */
 	@PostMapping("import-household")
 	@ApiOperationSupport(order = 12)
 	@ApiOperation(value = "导入住户", notes = "传入excel")
 	public R importUser(MultipartFile file, Integer isCovered) {
-		HouseHoldImporter houseHoldImporter = new HouseHoldImporter(householdService, isCovered == 1);
-		ExcelUtil.save(file, houseHoldImporter, HouseHoldExcel.class);
-		return R.success("操作成功");
+		String data = householdService.importUserHouseHold(ExcelUtil.read(file, ImportHouseholdExcel.class),isCovered==1);
+		return R.data(200,data,null);
 	}
 
 	/**
-	 * 导出用户
+	 * 导出住户
 	 */
 	@GetMapping("export-household")
 	@ApiOperationSupport(order = 13)
 	@ApiOperation(value = "导出住户", notes = "传入user")
 	public void exportUser(HouseholdVO household, HttpServletResponse response) {
-		List<HouseHoldExcel> list = householdService.export(household);
-		ExcelUtil.export(response, "住户户数据" + DateUtil.time(), "住户数据表", list, HouseHoldExcel.class);
+		List<ImportHouseholdExcel> list = householdService.export(household);
+		ExcelUtil.export(response, "住户户数据" + DateUtil.time(), "住户数据表", list, ImportHouseholdExcel.class);
+	}
+
+	/**
+	 * 模板下載
+	 */
+	@GetMapping("/export-template")
+	@ApiOperationSupport(order = 15)
+	@ApiOperation(value = "模板下載", notes = "传入response")
+	public void exportUser(HttpServletResponse response) {
+		List<ImportHouseholdExcel> list = new ArrayList<>();
+		ImportHouseholdExcel houseHoldExcel = new ImportHouseholdExcel();
+		// 设置模板数据
+		houseHoldExcel.setHouseCode("Afdsfdasf5421********411214");
+		houseHoldExcel.setName("张三");
+		houseHoldExcel.setGender("1");
+		houseHoldExcel.setPhoneNumber("13112341234");
+		houseHoldExcel.setBirthday("2001-01-01");
+		houseHoldExcel.setIdCard("360*************0001");
+		houseHoldExcel.setOtherContact("13112341234");
+		houseHoldExcel.setRelationship("1");
+		houseHoldExcel.setIsPrimaryContact("1");
+		houseHoldExcel.setResidentialStatus("1");
+		houseHoldExcel.setEthnicity("1");
+		houseHoldExcel.setHukouRegistration("江西上饶****");
+		houseHoldExcel.setCurrentAddress("江西上饶****");
+		houseHoldExcel.setPartyEmber("2");
+		houseHoldExcel.setEducation("21");
+		houseHoldExcel.setOccupation("***");
+		houseHoldExcel.setEmployer("***单位");
+		houseHoldExcel.setCmpyRegAddr("江西上饶****");
+		houseHoldExcel.setWorkStatus("1");
+		houseHoldExcel.setMaritalStatus("1");
+		houseHoldExcel.setReligiousBelief("***");
+		houseHoldExcel.setHealthStatus("1");
+		houseHoldExcel.setGoOutWhere("去***");
+		houseHoldExcel.setGoOutAddr("回老家");
+		houseHoldExcel.setGoOutTime("2024-01-01");
+		houseHoldExcel.setGoOutAddr("江西上饶********");
+		houseHoldExcel.setCardNumber("赣*****");
+		houseHoldExcel.setVolunteerOrg("信州义警");
+		houseHoldExcel.setRemark("*****");
+		houseHoldExcel.setLabelName("普通群众");
+		list.add(houseHoldExcel);
+		ExcelUtil.export(response, "住户数据模板", "住户数据表", list, ImportHouseholdExcel.class);
 	}
 
 
diff --git a/src/main/java/org/springblade/modules/house/excel/HouseHoldExcel.java b/src/main/java/org/springblade/modules/house/excel/HouseHoldExcel.java
deleted file mode 100644
index 37261a5..0000000
--- a/src/main/java/org/springblade/modules/house/excel/HouseHoldExcel.java
+++ /dev/null
@@ -1,169 +0,0 @@
-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 io.swagger.annotations.ApiModelProperty;
-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.util.Date;
-
-/**
- * UserExcel
- *
- * @author Chill
- */
-@Data
-@ColumnWidth(25)
-@HeadRowHeight(20)
-@ContentRowHeight(18)
-public class HouseHoldExcel implements Serializable {
-
-	private static final long serialVersionUID = 2L;
-
-	/**
-	 * 门牌地址编码
-	 */
-	@ColumnWidth(25)
-	@ExcelProperty( "门牌地址编码")
-	private String houseCode;
-
-	/** 姓名 */
-	@ColumnWidth(15)
-	@ExcelProperty( "姓名")
-	private String name;
-
-	/** 手机号 */
-	@ColumnWidth(15)
-	@ExcelProperty( "手机号")
-	private String phoneNumber;
-
-	/** 小区名称 */
-	@ColumnWidth(15)
-	@ExcelProperty( "小区名称")
-	private String aoiName;
-
-	/** 角色  */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "角色",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "roleType")
-	private String roleType;
-
-	/** 与角色关系(业主,父子,其他) */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "与角色关系",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "roleRelation")
-	private String relationship;
-
-	/** 是否主要联系人 1:是  0:否 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "是否主要联系人",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "primaryContactType")
-	private String isPrimaryContact;
-
-	/** 居住状态 1: 是  0:否 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "居住状态",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "residentialStatusType")
-	private String residentialStatus;
-
-	/** 性别 1: 男 0:女  2: 未知 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "性别",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "sex")
-	private String gender;
-
-	/** 生日 */
-	@ColumnWidth(15)
-	@ExcelProperty( "生日")
-	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
-	private Date birthday;
-
-	/** 身份证 */
-	@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)
-	@ExcelDictItem(type = "nationType")
-	private String ethnicity;
-
-	/** 学历 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "学历",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "educationType")
-	private String education;
-
-	/** 户籍登记地 */
-	@ColumnWidth(15)
-	@ExcelProperty( "户籍登记地")
-	private String hukouRegistration;
-
-	/** 工作状态 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "工作状态",converter = ExcelDictConverter.class)
-	@ExcelDictItem(type = "workStatusType")
-	private String workStatus;
-
-	/** 工作单位 */
-	@ColumnWidth(15)
-	@ExcelProperty( "工作单位")
-	private String employer;
-
-	/** 婚姻状态 */
-	@ColumnWidth(15)
-	@ExcelProperty( value = "婚姻状态",converter = ExcelDictConverter.class)
-	@ExcelDictItem(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)
-	@ExcelDictItem(type = "partyEmberType")
-	private String partyEmber;
-
-	/** 备注 */
-	@ColumnWidth(15)
-	@ExcelProperty( "备注")
-	private String remark;
-
-}
-
diff --git a/src/main/java/org/springblade/modules/house/excel/HouseHoldImporter.java b/src/main/java/org/springblade/modules/house/excel/HouseHoldImporter.java
index 0823881..146e632 100644
--- a/src/main/java/org/springblade/modules/house/excel/HouseHoldImporter.java
+++ b/src/main/java/org/springblade/modules/house/excel/HouseHoldImporter.java
@@ -1,25 +1,8 @@
-/*
- *      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.IHouseholdService;
-
 import java.util.List;
 
 /**
@@ -28,13 +11,13 @@
  * @author Chill
  */
 @RequiredArgsConstructor
-public class HouseHoldImporter implements ExcelImporter<HouseHoldExcel> {
+public class HouseHoldImporter implements ExcelImporter<ImportHouseholdExcel> {
 
 	private final IHouseholdService iHouseholdService;
 	private final Boolean isCovered;
 
 	@Override
-	public void save(List<HouseHoldExcel> data) {
+	public void save(List<ImportHouseholdExcel> data) {
 		iHouseholdService.importUserHouseHold(data, isCovered);
 	}
 }
diff --git a/src/main/java/org/springblade/modules/house/excel/ImportHouseholdExcel.java b/src/main/java/org/springblade/modules/house/excel/ImportHouseholdExcel.java
new file mode 100644
index 0000000..a477374
--- /dev/null
+++ b/src/main/java/org/springblade/modules/house/excel/ImportHouseholdExcel.java
@@ -0,0 +1,219 @@
+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.util.Date;
+
+/**
+ * ImportHouseHoldExcel
+ *
+ * @author Chill
+ */
+@Data
+@ColumnWidth(25)
+@HeadRowHeight(20)
+@ContentRowHeight(18)
+public class ImportHouseholdExcel implements Serializable {
+
+	private static final long serialVersionUID = 2L;
+
+	/**
+	 * 门牌地址编码
+	 */
+	@ColumnWidth(25)
+	@ExcelProperty( "门牌地址编码")
+	private String houseCode;
+
+	/** 姓名 */
+	@ColumnWidth(15)
+	@ExcelProperty( "姓名*")
+	private String name;
+
+	/** 性别 1: 男 0:女  2: 未知 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "性别",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "sex")
+	@ExcelDictItem(type = "sex")
+	private String gender;
+
+
+	/** 手机号 */
+	@ColumnWidth(15)
+	@ExcelProperty( "手机号*")
+	private String phoneNumber;
+
+	/** 生日 */
+	@ColumnWidth(15)
+	@ExcelProperty( "生日")
+	private String birthday;
+
+	/** 身份证 */
+	@ColumnWidth(15)
+	@ExcelProperty( "身份证号码")
+	private String idCard;
+
+	/** 其他联系方式 */
+	@ColumnWidth(15)
+	@ExcelProperty( "其他联系方式")
+	private String otherContact;
+
+	/** 与业主关系 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "与业主关系*(业主/妻子/丈夫/女儿/儿子/母亲/父亲/.../租户/其他)",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "roleRelation")
+	@ExcelDictItem(type = "roleRelation")
+	private String relationship;
+
+	/** 是否主要联系人 1:是  0:否 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "是否主要联系人",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "primaryContactType")
+	@ExcelDictItem(type = "primaryContactType")
+	private String isPrimaryContact;
+
+	/** 居住状态 1: 是  0:否 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "居住状态",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "residentialStatusType")
+	@ExcelDictItem(type = "residentialStatusType")
+	private String residentialStatus;
+
+	/** 民族 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "民族",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "nationType")
+	@ExcelDictItem(type = "nationType")
+	private String ethnicity;
+
+
+	/** 户籍地址 */
+	@ColumnWidth(15)
+	@ExcelProperty( "户籍地址")
+	private String hukouRegistration;
+
+	/** 现居住地址 */
+	@ColumnWidth(15)
+	@ExcelProperty( "现居住地址")
+	private String currentAddress;
+
+	/** 是否党员  1:党员  2:群众 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "是否党员(党员/群众)",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "partyEmberType")
+	@ExcelDictItem(type = "partyEmberType")
+	private String partyEmber;
+
+	/** 学历 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "学历",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "educationType")
+	@ExcelDictItem(type = "educationType")
+	private String education;
+	/**
+	 * 职业类别
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "职业类别")
+	private String occupation;
+
+	/** 工作单位 */
+	@ColumnWidth(15)
+	@ExcelProperty( "工作单位")
+	private String employer;
+	/**
+	 * 工作单位地址
+	 */
+	@ExcelProperty( "工作单位地址")
+	private String cmpyRegAddr;
+
+	/** 工作状态 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "工作状态(在职/离职/退休/其他)",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "workStatusType")
+	@ExcelDictItem(type = "workStatusType")
+	private String workStatus;
+
+
+	/** 婚姻状态 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "婚姻状态(未婚/已婚/离异/丧偶/其他)",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "marriageStatusType")
+	@ExcelDictItem(type = "marriageStatusType")
+	private String maritalStatus;
+	/**
+	 * 宗教信仰
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "宗教信仰")
+	private String religiousBelief;
+	/**
+	 * 健康状况    业务字典 healthStatus
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( value = "健康状况(健康/良好/较差)",converter = ExcelDictConverter.class)
+	@ExcelDictItemLabel(type = "healthStatus")
+	@ExcelDictItem(type = "healthStatus")
+	private String healthStatus;
+	/**
+	 * 疾病名称
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "疾病名称")
+	private String diseaseName;
+	/**
+	 * 外出去向
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "外出去向")
+	private String goOutWhere;
+	/**
+	 * 外出原因
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "外出原因")
+	private String goOutReason;
+	/**
+	 * 外出时间
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "外出时间")
+//	@JsonFormat(pattern = "yyyy-MM-dd")
+	private String goOutTime;
+
+	/**
+	 * 外出详址
+	 */
+	@ExcelProperty( "外出详址")
+	private String goOutAddr;
+
+	/** 车牌号 */
+	@ColumnWidth(15)
+	@ExcelProperty( "车牌号")
+	private String cardNumber;
+	/**
+	 * 自愿者组织
+	 */
+	@ColumnWidth(15)
+	@ExcelProperty( "自愿者组织")
+	private String volunteerOrg;
+
+	/** 备注 */
+	@ColumnWidth(15)
+	@ExcelProperty( "备注")
+	private String remark;
+
+	/** 备注 */
+	@ColumnWidth(15)
+	@ExcelProperty( "标签")
+	private String labelName;
+
+}
+
diff --git a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.java b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.java
index 4e85451..aa1aee7 100644
--- a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.java
+++ b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.java
@@ -23,7 +23,7 @@
 import org.springblade.common.node.TreeIntegerNode;
 import org.springblade.common.node.TreeStringNode;
 import org.springblade.modules.house.entity.HouseholdEntity;
-import org.springblade.modules.house.excel.HouseHoldExcel;
+import org.springblade.modules.house.excel.ImportHouseholdExcel;
 import org.springblade.modules.house.vo.HouseholdOtherVO;
 import org.springblade.modules.house.vo.HouseholdVO;
 
@@ -90,7 +90,7 @@
 	 * @param household
 	 * @return
 	 */
-	List<HouseHoldExcel> export(@Param("household") HouseholdVO household);
+	List<ImportHouseholdExcel> export(@Param("household") HouseholdVO household);
 
 	Integer statistics(@Param("household") HouseholdVO household,
 					   @Param("isAdministrator") Integer isAdministrator,
diff --git a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
index b1b2729..873fc47 100644
--- a/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
+++ b/src/main/java/org/springblade/modules/house/mapper/HouseholdMapper.xml
@@ -557,7 +557,7 @@
     </select>
 
     <!--导出数据-->
-    <select id="export" resultType="org.springblade.modules.house.excel.HouseHoldExcel">
+    <select id="export" resultType="org.springblade.modules.house.excel.ImportHouseholdExcel">
         select
         jh.house_code houseCode,
         jh.name,jh.phone_number phoneNumber,jh.role_type roleType,jh.relationship relationship,
diff --git a/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.java b/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.java
index d760555..b474b7e 100644
--- a/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.java
+++ b/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.java
@@ -18,6 +18,7 @@
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
 import org.springblade.modules.house.dto.UserHouseLabelDTO;
 import org.springblade.modules.house.entity.UserHouseLabelEntity;
 import org.springblade.modules.house.vo.HouseholdLabelVO;
@@ -46,4 +47,11 @@
 	List<HouseholdLabelVO> statisticalLabels(IPage page, HouseholdLabelVO householdLabel);
 
 	List<HouseholdLabelVO> getCommunityStatisticalLabels(IPage<HouseholdLabelVO> page, HouseholdLabelVO householdLabel);
+
+	/**
+	 * 查询对应的label集合信息
+	 * @param labelName
+	 * @return
+	 */
+    List<UserHouseLabelEntity> getLabelList(@Param("labelNames") String labelName);
 }
diff --git a/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.xml b/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.xml
index 5c014e2..63f04ab 100644
--- a/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.xml
+++ b/src/main/java/org/springblade/modules/house/mapper/UserHouseLabelMapper.xml
@@ -416,5 +416,22 @@
 
     </select>
 
+    <!--查询对应的label集合信息-->
+    <select id="getLabelList" resultType="org.springblade.modules.house.entity.UserHouseLabelEntity">
+        SELECT id as label_id,label_name FROM jczz_label
+        WHERE is_deleted = 0
+        <choose>
+            <when test="labelNames!=null and labelNames!=''">
+                and label_name in
+                <foreach collection="labelNames.split(',')" item="labelName" open="(" separator="," close=")">
+                    #{labelName}
+                </foreach>
+            </when>
+            <otherwise>
+                and label_name = #{labelNames}
+            </otherwise>
+        </choose>
+    </select>
+
 
 </mapper>
diff --git a/src/main/java/org/springblade/modules/house/service/IHouseService.java b/src/main/java/org/springblade/modules/house/service/IHouseService.java
index d9c5256..63bad26 100644
--- a/src/main/java/org/springblade/modules/house/service/IHouseService.java
+++ b/src/main/java/org/springblade/modules/house/service/IHouseService.java
@@ -19,6 +19,7 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 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.excel.HouseExcel;
 import org.springblade.modules.house.vo.HouseParam;
@@ -137,4 +138,10 @@
 	 * @return
 	 */
     boolean initHouseLabelBind(HouseVO house);
+
+	/**
+	 * 保存用户信息
+	 * @param householdEntity
+	 */
+	void saveOrUpdateUser(HouseholdEntity householdEntity);
 }
diff --git a/src/main/java/org/springblade/modules/house/service/IHouseholdService.java b/src/main/java/org/springblade/modules/house/service/IHouseholdService.java
index 8cc5315..eaea7f4 100644
--- a/src/main/java/org/springblade/modules/house/service/IHouseholdService.java
+++ b/src/main/java/org/springblade/modules/house/service/IHouseholdService.java
@@ -21,7 +21,7 @@
 import org.springblade.common.node.TreeIntegerNode;
 import org.springblade.common.node.TreeStringNode;
 import org.springblade.modules.house.entity.HouseholdEntity;
-import org.springblade.modules.house.excel.HouseHoldExcel;
+import org.springblade.modules.house.excel.ImportHouseholdExcel;
 import org.springblade.modules.house.vo.HouseholdVO;
 
 import java.util.List;
@@ -71,9 +71,9 @@
 	 */
 	Object getDetail(HouseholdEntity household);
 
-    List<HouseHoldExcel> export(HouseholdVO household);
+    List<ImportHouseholdExcel> export(HouseholdVO household);
 
-	void importUserHouseHold(List<HouseHoldExcel> data, Boolean isCovered);
+	String importUserHouseHold(List<ImportHouseholdExcel> data, Boolean isCovered);
 
     Integer statistics(Long userId,String neiCode,Integer confirmFlag);
 
diff --git a/src/main/java/org/springblade/modules/house/service/IUserHouseLabelService.java b/src/main/java/org/springblade/modules/house/service/IUserHouseLabelService.java
index f7bba5c..c996893 100644
--- a/src/main/java/org/springblade/modules/house/service/IUserHouseLabelService.java
+++ b/src/main/java/org/springblade/modules/house/service/IUserHouseLabelService.java
@@ -65,4 +65,11 @@
 	 * @return
 	 */
 	boolean saveOrUpdateHouseLabel(UserHouseLabelEntity householdLabel);
+
+	/**
+	 * 查询对应的label集合信息
+	 * @param labelName
+	 * @return
+	 */
+    List<UserHouseLabelEntity> getLabelList(String labelName);
 }
diff --git a/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java b/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
index 9bbb1e9..905645a 100644
--- a/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
+++ b/src/main/java/org/springblade/modules/house/service/impl/HouseholdServiceImpl.java
@@ -16,7 +16,7 @@
  */
 package org.springblade.modules.house.service.impl;
 
-import com.alibaba.fastjson.JSON;
+import cn.hutool.core.util.IdcardUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -29,14 +29,15 @@
 import org.springblade.common.param.CommonParamSet;
 import org.springblade.common.utils.NodeTreeUtil;
 import org.springblade.common.utils.SpringUtils;
-import org.springblade.core.mp.support.Condition;
+import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.house.entity.HouseholdEntity;
 import org.springblade.modules.house.entity.UserHouseLabelEntity;
-import org.springblade.modules.house.excel.HouseHoldExcel;
+import org.springblade.modules.house.excel.ImportHouseholdExcel;
 import org.springblade.modules.house.mapper.HouseholdMapper;
+import org.springblade.modules.house.service.IHouseService;
 import org.springblade.modules.house.service.IHouseholdService;
 import org.springblade.modules.house.service.IUserHouseLabelService;
 import org.springblade.modules.house.vo.HouseholdLabelVO;
@@ -44,7 +45,6 @@
 import org.springblade.modules.house.vo.HouseholdVO;
 import org.springblade.modules.label.entity.LabelEntity;
 import org.springblade.modules.label.service.ILabelService;
-import org.springblade.modules.label.vo.LabelVO;
 import org.springblade.modules.place.entity.PlaceEntity;
 import org.springblade.modules.place.service.IPlaceService;
 import org.springblade.modules.system.entity.DictBiz;
@@ -56,6 +56,8 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StopWatch;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -299,19 +301,149 @@
 	}
 
 	@Override
-	public List<HouseHoldExcel> export(HouseholdVO household) {
-		List<HouseHoldExcel> userHouseHoldExcels = baseMapper.export(household);
+	public List<ImportHouseholdExcel> export(HouseholdVO household) {
+		List<ImportHouseholdExcel> userHouseHoldExcels = baseMapper.export(household);
 		return userHouseHoldExcels;
 	}
 
 
+	/**
+	 * 导入住户数据
+	 * @param data
+	 * @param isCovered
+	 */
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public void importUserHouseHold(List<HouseHoldExcel> data, Boolean isCovered) {
-		data.forEach(houseHoldExcel -> {
-			HouseholdEntity houseHoldEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class));
-			this.save(houseHoldEntity);
-		});
+	public String importUserHouseHold(List<ImportHouseholdExcel> data, Boolean isCovered) {
+		IHouseService houseService = SpringUtils.getBean(IHouseService.class);
+		int totalNum = data.size();
+		int importNum = 0;
+		int updateNum = 0;
+		int errorNum = 0;
+		for (ImportHouseholdExcel houseHoldExcel : data) {
+			HouseholdEntity householdEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class));
+			// 判断姓名,手机号
+			if (Strings.isBlank(householdEntity.getName()) || Strings.isBlank(householdEntity.getPhoneNumber())){
+				errorNum ++;
+				continue;
+			}
+			// 查询库中是否已存在
+			QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>();
+			wrapper.eq("house_code", householdEntity.getHouseCode())
+				.eq("is_deleted", 0)
+				.eq("phone_number", householdEntity.getPhoneNumber())
+				.eq("name", householdEntity.getName());
+			HouseholdEntity one = this.getOne(wrapper);
+			// 与角色关系
+			if (!Strings.isBlank(houseHoldExcel.getRelationship())) {
+				householdEntity.setRelationship(Integer.parseInt(houseHoldExcel.getRelationship()));
+				// 如果是业主,则需要往用户表插入用户
+				if (householdEntity.getRelationship() == 1) {
+					houseService.saveOrUpdateUser(householdEntity);
+				}
+			}
+			/// 是否主要联系人
+			if (!Strings.isBlank(houseHoldExcel.getIsPrimaryContact())) {
+				householdEntity.setIsPrimaryContact(Integer.parseInt(houseHoldExcel.getIsPrimaryContact()));
+			}
+			// 居住状态
+			if (!Strings.isBlank(houseHoldExcel.getResidentialStatus())) {
+				householdEntity.setResidentialStatus(Integer.parseInt(houseHoldExcel.getResidentialStatus()));
+			}
+			// 性别
+			if (!Strings.isBlank(houseHoldExcel.getGender())) {
+				householdEntity.setGender(Short.parseShort(houseHoldExcel.getGender()));
+			}
+			// 居民身份证
+			if (!Strings.isBlank(houseHoldExcel.getIdCard())) {
+				if (IdcardUtil.isValidCard(houseHoldExcel.getIdCard())) {
+					// 身份证类型为居民身份证
+					householdEntity.setCardType(111);
+				}
+			}
+			// 党员
+			if (!Strings.isBlank(houseHoldExcel.getPartyEmber())) {
+				householdEntity.setPartyEmber(Integer.parseInt(houseHoldExcel.getPartyEmber()));
+			}
+			// 民族
+			if (!Strings.isBlank(houseHoldExcel.getEthnicity())) {
+				householdEntity.setEthnicity(Integer.parseInt(houseHoldExcel.getEthnicity()));
+			}
+			// 学历
+			if (!Strings.isBlank(houseHoldExcel.getEducation())) {
+				householdEntity.setEducation(Integer.parseInt(houseHoldExcel.getEducation()));
+			}
+			// 健康状况
+			if (!Strings.isBlank(houseHoldExcel.getHealthStatus())) {
+				householdEntity.setHealthStatus(Integer.parseInt(houseHoldExcel.getHealthStatus()));
+			}
+			// 工作状态
+			if (!Strings.isBlank(houseHoldExcel.getWorkStatus())) {
+				householdEntity.setWorkStatus(Integer.parseInt(houseHoldExcel.getWorkStatus()));
+			}
+			// 外出时间
+			if (!Strings.isBlank(houseHoldExcel.getGoOutTime())) {
+				try {
+					Date date = new SimpleDateFormat("yyyy-MM-dd").parse(houseHoldExcel.getGoOutTime());
+					householdEntity.setGoOutTime(date);
+				} catch (ParseException e) {
+					e.printStackTrace();
+				}
+			}
+			// 婚姻状态
+			if (!Strings.isBlank(houseHoldExcel.getMaritalStatus())) {
+				householdEntity.setMaritalStatus(Integer.parseInt(houseHoldExcel.getMaritalStatus()));
+			}
+
+			if (one==null){
+				// 新增
+				this.save(householdEntity);
+				importNum++;
+				// 处理标签
+				handleLabel(householdEntity,houseHoldExcel);
+			}else {
+				updateNum++;
+				if (isCovered){
+					// 覆盖更新
+					householdEntity.setId(one.getId());
+					// 更新
+					updateById(householdEntity);
+					importNum++;
+					// 处理标签
+					handleLabel(householdEntity,houseHoldExcel);
+				}
+			}
+		}
+		StringBuilder builder = new StringBuilder("导入完成!");
+		builder.append("其中本次表格共有 ").append(totalNum).append(" 条数据,")
+			.append("成功导入 ").append(importNum).append(" 条数据,")
+			.append("其中有 ").append(updateNum).append(" 条数据已存在。");
+		if (errorNum>0){
+			builder.append("共有 ").append(errorNum).append(" 条数据由于无姓名或手机号信息未导入!");
+		}
+		return builder.toString();
+	}
+
+	/**
+	 * 标签处理
+	 * @param householdEntity
+	 * @param houseHoldExcel
+	 */
+	public void handleLabel(HouseholdEntity householdEntity, ImportHouseholdExcel houseHoldExcel) {
+		if (!Strings.isBlank(houseHoldExcel.getLabelName())){
+			// 查询对应的label集合信息
+			List<UserHouseLabelEntity> userHouseLabelList = userHouseLabelService.getLabelList(houseHoldExcel.getLabelName());
+			if (userHouseLabelList.size()>0){
+				for (UserHouseLabelEntity userHouseLabelEntity : userHouseLabelList) {
+					userHouseLabelEntity.setHouseCode(householdEntity.getHouseCode());
+					userHouseLabelEntity.setHouseholdId(householdEntity.getId());
+					userHouseLabelEntity.setUserId(householdEntity.getAssociatedUserId());
+					userHouseLabelEntity.setLableType(1);
+					userHouseLabelEntity.setColor("green");
+					userHouseLabelService.saveOrUpdateHouseholdLabel(userHouseLabelEntity);
+				}
+			}
+		}
 	}
 
 	/**
diff --git a/src/main/java/org/springblade/modules/house/service/impl/UserHouseLabelServiceImpl.java b/src/main/java/org/springblade/modules/house/service/impl/UserHouseLabelServiceImpl.java
index 3971f67..ee504de 100644
--- a/src/main/java/org/springblade/modules/house/service/impl/UserHouseLabelServiceImpl.java
+++ b/src/main/java/org/springblade/modules/house/service/impl/UserHouseLabelServiceImpl.java
@@ -19,6 +19,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.logging.log4j.util.Strings;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.modules.house.dto.UserHouseLabelDTO;
 import org.springblade.modules.house.entity.UserHouseLabelEntity;
@@ -61,8 +62,10 @@
 	@Override
 	public boolean saveOrUpdateHouseholdLabel(UserHouseLabelEntity householdLabel) {
 		// 查询标签名称
-		LabelEntity labelEntity = labelService.getById(householdLabel.getLabelId());
-		householdLabel.setLabelName(labelEntity.getLabelName());
+		if (!Strings.isBlank(householdLabel.getLabelName())) {
+			LabelEntity labelEntity = labelService.getById(householdLabel.getLabelId());
+			householdLabel.setLabelName(labelEntity.getLabelName());
+		}
 		// 判断同一个住户同一个标签是否已存在,已存在则更新,不存在则新增
 		QueryWrapper<UserHouseLabelEntity> queryWrapper = new QueryWrapper<>();
 		queryWrapper.eq("household_id", householdLabel.getHouseholdId())
@@ -123,4 +126,14 @@
 		// 插入
 		return save(userHouseLabelEntity);
 	}
+
+	/**
+	 * 查询对应的label集合信息
+	 * @param labelName
+	 * @return
+	 */
+	@Override
+	public List<UserHouseLabelEntity> getLabelList(String labelName) {
+		return baseMapper.getLabelList(labelName);
+	}
 }
diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml
index 35a7d54..9623573 100644
--- a/src/main/resources/application-test.yml
+++ b/src/main/resources/application-test.yml
@@ -7,7 +7,7 @@
     host: 127.0.0.1
     port: 6379
     password:
-    database: 0
+    database: 10
     ssl: false
     ##redis 集群环境配置
     #cluster:

--
Gitblit v1.9.3