forked from luyan/epmet-cloud-lingshan
12 changed files with 612 additions and 44 deletions
@ -0,0 +1,68 @@ |
|||
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 Date viliagePosition; |
|||
|
|||
@ExcelProperty("党组织职务") |
|||
private Date 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 errorInfo; |
|||
} |
|||
} |
@ -0,0 +1,178 @@ |
|||
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 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 { |
|||
// 先校验数据
|
|||
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); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
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; |
|||
} |
|||
} |
Binary file not shown.
Loading…
Reference in new issue