Browse Source
# Conflicts: # epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java # epmet-module/gov-org/gov-org-server/src/main/resources/excel/house_template.xlsx # epmet-module/gov-org/gov-org-server/src/main/resources/excel/neighbor_template.xlsx # epmet-module/gov-org/gov-org-server/src/main/resources/excel/yantai/community_building_manager_import_temp.xlsxdev
52 changed files with 1675 additions and 111 deletions
@ -0,0 +1,75 @@ |
|||
package com.epmet.excel; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelProperty; |
|||
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 核酸检测信息导入excel数据 |
|||
*/ |
|||
@Data |
|||
public class CustomerStaffImportExcelData { |
|||
|
|||
@NotBlank(message = "姓名为必填项") |
|||
@ExcelProperty("姓名※") |
|||
private String name; |
|||
|
|||
@NotBlank(message = "手机号为必填项") |
|||
@ExcelProperty("联系电话※") |
|||
@Length(max = 15, message = "手机号长度不正确,应小于15位") |
|||
private String mobile; |
|||
|
|||
@NotBlank(message = "身份证号为必填项") |
|||
@ExcelProperty("身份证号※") |
|||
@Length(max = 18, message = "证身份证号长度不正确,应小于18位") |
|||
private String idCard; |
|||
|
|||
@ExcelProperty("村居委员职务") |
|||
private String viliagePosition; |
|||
|
|||
@ExcelProperty("党组织职务") |
|||
private String partyPosition; |
|||
|
|||
@NotBlank(message = "居住地址为必填项") |
|||
@ExcelProperty("居住地址※") |
|||
private String address; |
|||
|
|||
@NotBlank(message = "文化程度为必填项") |
|||
@ExcelProperty("文化程度※") |
|||
private String cultureName; |
|||
|
|||
@NotBlank(message = "性别为必填项") |
|||
@ExcelProperty("性别※") |
|||
private String genderName; |
|||
|
|||
@NotBlank(message = "专兼职为必填项") |
|||
@ExcelProperty("专兼职※") |
|||
private String workTypeName; |
|||
|
|||
@NotBlank(message = "工作职责为必填项") |
|||
@ExcelProperty("工作职责※") |
|||
private String duty; |
|||
|
|||
@ExcelProperty("备注") |
|||
private String remark; |
|||
|
|||
@Data |
|||
public static class RowRemarkMessage { |
|||
|
|||
@ColumnWidth(60) |
|||
@ExcelProperty("姓名") |
|||
private String name; |
|||
|
|||
@ColumnWidth(60) |
|||
@ExcelProperty("联系电话") |
|||
private String mobile; |
|||
|
|||
@ColumnWidth(60) |
|||
@ExcelProperty("错误信息") |
|||
private String errorInfo; |
|||
} |
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
package com.epmet.excel.handler; |
|||
|
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.epmet.commons.tools.constant.NumConstant; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.ValidateException; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.utils.ObjectUtil; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.result.CommunityBuildingManagerDTO; |
|||
import com.epmet.excel.yt.CommunityBuildingManagerImportExcelData; |
|||
import com.epmet.service.impl.CommunityBuildingManagerServiceImpl; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections4.CollectionUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2023/5/9 16:26 |
|||
*/ |
|||
@Slf4j |
|||
public class CommunityBuildingManagerImportListener implements ReadListener<CommunityBuildingManagerImportExcelData> { |
|||
|
|||
// 最大条数阈值
|
|||
public static final int MAX_THRESHOLD = 200; |
|||
private Map<String, String> gridMap; |
|||
private String customerId; |
|||
private String staffId; |
|||
private String agencyId; |
|||
private String districtId; |
|||
private String streetId; |
|||
private String rediPrex; |
|||
private CommunityBuildingManagerServiceImpl communityBuildingManagerService; |
|||
// 错误项列表
|
|||
private List<CommunityBuildingManagerImportExcelData.ErrorRow> errorRows = new ArrayList<>(); |
|||
// 要插入的数据
|
|||
private List<CommunityBuildingManagerDTO> excelDataList = new ArrayList<>(); |
|||
|
|||
public CommunityBuildingManagerImportListener(Map<String, String> gridMap,String customerId, String staffId, String agencyId, String districtId, String streetId, String rediPrex, CommunityBuildingManagerServiceImpl communityBuildingManagerService) { |
|||
this.gridMap=gridMap; |
|||
this.customerId = customerId; |
|||
this.staffId = staffId; |
|||
this.agencyId=agencyId; |
|||
this.districtId=districtId; |
|||
this.streetId=streetId; |
|||
this.rediPrex=rediPrex; |
|||
this.communityBuildingManagerService = communityBuildingManagerService; |
|||
} |
|||
|
|||
|
|||
@Override |
|||
public void invoke(CommunityBuildingManagerImportExcelData data, AnalysisContext analysisContext) { |
|||
try { |
|||
// log.warn("有数据吗?"+JSON.toJSONString(data));
|
|||
// 不能为空先校验数据
|
|||
ValidatorUtils.validateEntity(data); |
|||
// 去除空格
|
|||
ObjectUtil.objectToTrim(data); |
|||
|
|||
CommunityBuildingManagerDTO communityBuildingManagerDTO = ConvertUtils.sourceToTarget(data, CommunityBuildingManagerDTO.class); |
|||
communityBuildingManagerDTO.setCustomerId(customerId); |
|||
communityBuildingManagerDTO.setCommunityId(agencyId); |
|||
communityBuildingManagerDTO.setType("单元长".equals(data.getTypeName()) ? NumConstant.ONE_STR : NumConstant.ZERO_STR); |
|||
excelDataList.add(communityBuildingManagerDTO); |
|||
if (excelDataList.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else if (e instanceof EpmetException) { |
|||
errorMsg = ((EpmetException) e).getMsg(); |
|||
} else { |
|||
errorMsg = "未知错误"; |
|||
log.error("【楼长单元长ic_property_management导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
CommunityBuildingManagerImportExcelData.ErrorRow errorRow = ConvertUtils.sourceToTarget(data, CommunityBuildingManagerImportExcelData.ErrorRow.class); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
if (CollectionUtils.isNotEmpty(excelDataList)) { |
|||
communityBuildingManagerService.handleImportExcelData(gridMap,customerId,staffId,agencyId, districtId, streetId,rediPrex,excelDataList,this); |
|||
} |
|||
} finally { |
|||
excelDataList.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<CommunityBuildingManagerImportExcelData.ErrorRow> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,202 @@ |
|||
package com.epmet.excel.handler; |
|||
|
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.ValidateException; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.form.AddStaffV2FromDTO; |
|||
import com.epmet.excel.CustomerStaffImportExcelData; |
|||
import com.epmet.service.impl.StaffServiceImpl; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 核酸检测excel导入监听器 |
|||
*/ |
|||
@Data |
|||
@Slf4j |
|||
public class CustomerStaffImportListener implements ReadListener<CustomerStaffImportExcelData> { |
|||
|
|||
/** |
|||
* 最大条数阈值 |
|||
*/ |
|||
public static final int MAX_THRESHOLD = 200; |
|||
|
|||
private String currentUserId; |
|||
|
|||
private String currentCustomerId; |
|||
|
|||
private String currentOrgType; |
|||
|
|||
private String currentOrgId; |
|||
|
|||
private CustomerStaffImportExcelData dataB; |
|||
|
|||
|
|||
/** |
|||
* 数据 |
|||
*/ |
|||
private List<AddStaffV2FromDTO> datas = new ArrayList<>(); |
|||
|
|||
/** |
|||
* 错误项列表 |
|||
*/ |
|||
private List<CustomerStaffImportExcelData.RowRemarkMessage> errorRows = new ArrayList<>(); |
|||
/** |
|||
* 其他被标记出来的列表列表 |
|||
*/ |
|||
private List<CustomerStaffImportExcelData.RowRemarkMessage> otherRows = new ArrayList<>(); |
|||
|
|||
private StaffServiceImpl staffService; |
|||
|
|||
public CustomerStaffImportListener(String currentUserId, String currentCustomerId, String currentOrgType,String currentOrgId,StaffServiceImpl staffService) { |
|||
this.currentUserId = currentUserId; |
|||
this.currentCustomerId = currentCustomerId; |
|||
this.staffService = staffService; |
|||
this.currentOrgType = currentOrgType; |
|||
this.currentOrgId = currentOrgId; |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(CustomerStaffImportExcelData data, AnalysisContext context) { |
|||
|
|||
try { |
|||
|
|||
dataB = data; |
|||
// 先校验数据
|
|||
ValidatorUtils.validateEntity(data); |
|||
|
|||
AddStaffV2FromDTO fromDTO = ConvertUtils.sourceToTarget(data, AddStaffV2FromDTO.class); |
|||
|
|||
fromDTO.setCustomerId(currentCustomerId); |
|||
//因为添加的是工作人员,这里写死吧!
|
|||
fromDTO.setApp("gov"); |
|||
fromDTO.setClient("wxmp"); |
|||
//当前登录用户
|
|||
fromDTO.setCurrentUserId(currentUserId); |
|||
fromDTO.setOrgId(currentOrgId); |
|||
fromDTO.setOrgType(currentOrgType); |
|||
|
|||
if (StringUtils.isNotBlank(data.getWorkTypeName())){ |
|||
if (data.getWorkTypeName().equals("专职")){ |
|||
fromDTO.setWorkType("fulltime"); |
|||
} |
|||
if (data.getWorkTypeName().equals("兼职")){ |
|||
fromDTO.setWorkType("parttime"); |
|||
} |
|||
} |
|||
|
|||
if (StringUtils.isNotBlank(data.getGenderName())){ |
|||
if (data.getGenderName().equals("男")){ |
|||
fromDTO.setGender(1); |
|||
} |
|||
if (data.getGenderName().equals("女")){ |
|||
fromDTO.setGender(2); |
|||
} |
|||
if (data.getGenderName().equals("未知")){ |
|||
fromDTO.setGender(0); |
|||
} |
|||
} |
|||
//0小学及文盲,1初中,2高中,3大专,4本科,5硕士,6博士,7中专
|
|||
if (StringUtils.isNotBlank(data.getCultureName())){ |
|||
if (data.getCultureName().equals("小学及文盲")){ |
|||
fromDTO.setCulture("0"); |
|||
} |
|||
if (data.getCultureName().equals("初中")){ |
|||
fromDTO.setCulture("1"); |
|||
} |
|||
if (data.getCultureName().equals("高中")){ |
|||
fromDTO.setCulture("2"); |
|||
} |
|||
if (data.getCultureName().equals("大专")){ |
|||
fromDTO.setCulture("3"); |
|||
} |
|||
if (data.getCultureName().equals("本科")){ |
|||
fromDTO.setCulture("4"); |
|||
} |
|||
if (data.getCultureName().equals("硕士")){ |
|||
fromDTO.setCulture("5"); |
|||
} |
|||
if (data.getCultureName().equals("博士")){ |
|||
fromDTO.setCulture("6"); |
|||
} |
|||
} |
|||
|
|||
|
|||
datas.add(fromDTO); |
|||
|
|||
if (datas.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else { |
|||
log.error("【客户信息导入】出错:{}", e.getStackTrace()); |
|||
errorMsg = ((EpmetException)e).getInternalMsg(); |
|||
log.error("【客户信息导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
|
|||
CustomerStaffImportExcelData.RowRemarkMessage errorRow = new CustomerStaffImportExcelData.RowRemarkMessage(); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRow.setName(data.getName()); |
|||
errorRow.setMobile(data.getMobile()); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
try { |
|||
execPersist(); |
|||
}catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else { |
|||
log.error("【客户信息导入】出错:{}", e.getStackTrace()); |
|||
errorMsg = ((EpmetException)e).getInternalMsg(); |
|||
log.error("【客户信息导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
|
|||
CustomerStaffImportExcelData.RowRemarkMessage errorRow = new CustomerStaffImportExcelData.RowRemarkMessage(); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRow.setName(dataB.getName()); |
|||
errorRow.setMobile(dataB.getMobile()); |
|||
errorRows.add(errorRow); |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
if (datas != null && datas.size() > 0) { |
|||
// icNatService.batchPersist(datas, this);
|
|||
staffService.exportAdd(datas,this); |
|||
} |
|||
}finally { |
|||
datas.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* @return |
|||
*/ |
|||
public List<CustomerStaffImportExcelData.RowRemarkMessage> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
} |
|||
@ -0,0 +1,116 @@ |
|||
package com.epmet.excel.yt; |
|||
|
|||
import com.alibaba.excel.annotation.ExcelProperty; |
|||
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
|||
import lombok.Data; |
|||
import org.hibernate.validator.constraints.Length; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2023/5/9 16:13 |
|||
*/ |
|||
@Data |
|||
public class CommunityBuildingManagerImportExcelData { |
|||
|
|||
/** |
|||
* 姓名 |
|||
*/ |
|||
@ExcelProperty(value = "*姓名") |
|||
@Length(max = 50, message = "姓名最多输入50字") |
|||
@NotBlank(message = "姓名不能为空") |
|||
private String name; |
|||
|
|||
/** |
|||
* 联系电话 |
|||
*/ |
|||
@ExcelProperty(value = "*联系电话") |
|||
@Length(max = 50, message = "联系电话最多输入50字") |
|||
@NotBlank(message = "联系电话不能为空") |
|||
private String phone; |
|||
|
|||
/** |
|||
* 身份证号 |
|||
*/ |
|||
@ExcelProperty(value = "*身份证号") |
|||
@Length(max = 50, message = "身份证号最多输入50字") |
|||
@NotBlank(message = "身份证号不能为空") |
|||
private String idCard; |
|||
|
|||
/** |
|||
* 类型:0楼长;1单元长 |
|||
*/ |
|||
@ExcelProperty(value = "*类型") |
|||
@NotBlank(message = "类型不能为空") |
|||
private String typeName; |
|||
|
|||
@ExcelProperty(value = "*所属网格") |
|||
@NotBlank(message = "所属网格不能为空") |
|||
private String gridName; |
|||
|
|||
@ExcelProperty(value = "*所属小区") |
|||
@NotBlank(message = "所属小区不能为空") |
|||
private String viliageName; |
|||
|
|||
@ExcelProperty(value = "*楼栋") |
|||
@NotBlank(message = "楼栋不能为空") |
|||
private String buildingName; |
|||
|
|||
@ExcelProperty(value = "单元") |
|||
private String unitName; |
|||
|
|||
@Data |
|||
public static class ErrorRow { |
|||
/** |
|||
* 姓名 |
|||
*/ |
|||
@ExcelProperty(value = "*姓名") |
|||
@ColumnWidth(20) |
|||
private String name; |
|||
|
|||
/** |
|||
* 联系电话 |
|||
*/ |
|||
@ExcelProperty(value = "*联系电话") |
|||
@ColumnWidth(20) |
|||
private String phone; |
|||
|
|||
/** |
|||
* 身份证号 |
|||
*/ |
|||
@ExcelProperty(value = "*身份证号") |
|||
@ColumnWidth(25) |
|||
private String idCard; |
|||
|
|||
/** |
|||
* 类型:0楼长;1单元长 |
|||
*/ |
|||
@ExcelProperty(value = "*类型") |
|||
@ColumnWidth(15) |
|||
private String typeName; |
|||
|
|||
@ExcelProperty(value = "*所属网格") |
|||
@ColumnWidth(30) |
|||
private String gridName; |
|||
|
|||
@ExcelProperty(value = "*所属小区") |
|||
@ColumnWidth(30) |
|||
private String viliageName; |
|||
|
|||
@ExcelProperty(value = "*楼栋") |
|||
@ColumnWidth(20) |
|||
private String buildingName; |
|||
|
|||
@ExcelProperty(value = "单元") |
|||
@ColumnWidth(20) |
|||
private String unitName; |
|||
|
|||
@ColumnWidth(60) |
|||
@ExcelProperty("错误信息") |
|||
private String errorInfo; |
|||
} |
|||
|
|||
} |
|||
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue