60 changed files with 802 additions and 150 deletions
@ -0,0 +1,112 @@ |
|||
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.constant.StrConstant; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.entity.CustomerAgencyEntity; |
|||
import com.epmet.entity.CustomerDepartmentEntity; |
|||
import com.epmet.excel.yt.DeptImportExcelDTO; |
|||
import com.epmet.service.CustomerDepartmentService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections4.CollectionUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2023/4/26 16:11 |
|||
*/ |
|||
@Slf4j |
|||
public class DeptExcelImportListener implements ReadListener<DeptImportExcelDTO> { |
|||
//最大条数阈值
|
|||
public static final int MAX_THRESHOLD = 200; |
|||
private String customerId; |
|||
private String staffId; |
|||
private CustomerAgencyEntity agencyEntity; |
|||
/** |
|||
* 当前操作用户 |
|||
*/ |
|||
//要插入的数据
|
|||
private List<CustomerDepartmentEntity> insertDatas = new ArrayList<>(); |
|||
//错误项列表
|
|||
private List<DeptImportExcelDTO.ErrorRow> errorRows = new ArrayList<>(); |
|||
private CustomerDepartmentService departmentService; |
|||
public DeptExcelImportListener(String loginUserCustomerId, String loginUserId, CustomerAgencyEntity agencyEntity, CustomerDepartmentService departmentService) { |
|||
this.customerId = loginUserCustomerId; |
|||
this.staffId = loginUserId; |
|||
this.agencyEntity = agencyEntity; |
|||
this.departmentService = departmentService; |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(DeptImportExcelDTO data, AnalysisContext analysisContext) { |
|||
try { |
|||
ValidatorUtils.validateEntity(data); |
|||
//当前组织下,是否存在该部门
|
|||
departmentService.checkUnqiueName(agencyEntity.getId(),data.getDepartmentName(),null); |
|||
CustomerDepartmentEntity entity = ConvertUtils.sourceToTarget(data, CustomerDepartmentEntity.class); |
|||
entity.setCustomerId(customerId); |
|||
entity.setAgencyId(agencyEntity.getId()); |
|||
entity.setCreatedBy(staffId); |
|||
entity.setUpdatedBy(staffId); |
|||
entity.setTotalUser(NumConstant.ZERO); |
|||
entity.setAreaCode(StringUtils.isNotBlank(agencyEntity.getAreaCode())?agencyEntity.getAreaCode(): StrConstant.EPMETY_STR); |
|||
entity.setDepartmentDuty(StrConstant.EPMETY_STR); |
|||
entity.setDeptType("duty"); |
|||
insertDatas.add(entity); |
|||
if (insertDatas.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if(e instanceof EpmetException){ |
|||
errorMsg=((EpmetException) e).getMsg(); |
|||
}else { |
|||
errorMsg = "未知错误"; |
|||
log.error("【部门导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
DeptImportExcelDTO.ErrorRow errorRow = ConvertUtils.sourceToTarget(data,DeptImportExcelDTO.ErrorRow.class); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
if (CollectionUtils.isNotEmpty(insertDatas)) { |
|||
departmentService.insertBatch(insertDatas); |
|||
} |
|||
|
|||
} finally { |
|||
insertDatas.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<DeptImportExcelDTO.ErrorRow> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
|
|||
} |
|||
|
@ -0,0 +1,72 @@ |
|||
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/4/26 15:59 |
|||
*/ |
|||
@Data |
|||
public class DeptImportExcelDTO { |
|||
/** |
|||
* 部门名称 |
|||
*/ |
|||
@NotBlank(message = "部门名称不能为空") |
|||
@Length(max = 50, message = "部门名称不能超过50个字") |
|||
@ExcelProperty(value = "*部门名称") |
|||
private String departmentName; |
|||
|
|||
/** |
|||
* 组织编码 |
|||
*/ |
|||
@ExcelProperty(value = "组织编码") |
|||
private String code; |
|||
/** |
|||
* 负责人 |
|||
*/ |
|||
@ExcelProperty(value = "联系人") |
|||
private String contacts; |
|||
/** |
|||
* 联系电话 |
|||
*/ |
|||
@ExcelProperty(value = "联系电话") |
|||
private String mobile; |
|||
|
|||
@Data |
|||
public static class ErrorRow { |
|||
@ColumnWidth(50) |
|||
@ExcelProperty(value = "*部门名称") |
|||
private String departmentName; |
|||
|
|||
/** |
|||
* 组织编码 |
|||
*/ |
|||
@ColumnWidth(20) |
|||
@ExcelProperty(value = "组织编码") |
|||
private String code; |
|||
/** |
|||
* 负责人 |
|||
*/ |
|||
@ColumnWidth(20) |
|||
@ExcelProperty(value = "联系人") |
|||
private String contacts; |
|||
|
|||
/** |
|||
* 联系电话 |
|||
*/ |
|||
@ColumnWidth(20) |
|||
@ExcelProperty(value = "联系电话") |
|||
private String mobile; |
|||
|
|||
@ColumnWidth(50) |
|||
@ExcelProperty("错误信息") |
|||
private String errorInfo; |
|||
} |
|||
} |
|||
|
Binary file not shown.
@ -0,0 +1,35 @@ |
|||
package com.epmet.remote; |
|||
|
|||
import com.epmet.commons.tools.constant.ServiceConstant; |
|||
import com.epmet.commons.tools.feign.ResultDataResolver; |
|||
import com.epmet.commons.tools.utils.EpmetRequestHolder; |
|||
import com.epmet.dto.form.LoginUserDetailsFormDTO; |
|||
import com.epmet.dto.result.LoginUserDetailsResultDTO; |
|||
import com.epmet.feign.EpmetUserOpenFeignClient; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* epmet用户远程服务工具 |
|||
*/ |
|||
@Component |
|||
public class EpmetUserRemoteService implements ResultDataResolver { |
|||
|
|||
@Autowired |
|||
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|||
|
|||
/** |
|||
* 查询当前登录用户信息 |
|||
* @return |
|||
*/ |
|||
public LoginUserDetailsResultDTO getLoginUserDetails() { |
|||
// 不传组织id,则基于当前组织查询
|
|||
LoginUserDetailsFormDTO loinUserForm = new LoginUserDetailsFormDTO(); |
|||
loinUserForm.setApp(EpmetRequestHolder.getLoginUserApp()); |
|||
loinUserForm.setClient(EpmetRequestHolder.getLoginUserClient()); |
|||
loinUserForm.setUserId(EpmetRequestHolder.getLoginUserId()); |
|||
LoginUserDetailsResultDTO loginUserDetailsResultDTO = getResultDataOrThrowsException(epmetUserOpenFeignClient.getLoginUserDetails(loinUserForm), ServiceConstant.GOV_ORG_SERVER, |
|||
null, null, "查询当前工作人员所属组织信息失败"); |
|||
return loginUserDetailsResultDTO; |
|||
} |
|||
} |
Loading…
Reference in new issue