Commit ece92854 authored by hongguangwu's avatar hongguangwu

优化人员档案

parent 8f90990e
......@@ -196,6 +196,7 @@ public class EmployeeExportVO extends BaseEntity {
private LocalDateTime leaveTime;
@ExcelProperty(value = "减档原因")
@ExcelAttribute(name = "减档原因", isDataId = true,dataType = ExcelAttributeConstants.DOWNSHIFT_REASON)
private String leaveReason;
@ExcelProperty(value = "减档备注")
......
......@@ -18,6 +18,8 @@ package com.yifu.cloud.plus.v1.yifu.archives.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttribute;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.ExcelAttributeConstants;
import lombok.Data;
import javax.validation.constraints.Size;
......@@ -31,7 +33,7 @@ import java.io.Serializable;
*/
@Data
@ColumnWidth(30)
public class EmployeeLeaveVO implements Serializable {
public class EmployeeLeaveVO extends RowIndex implements Serializable {
private static final long serialVersionUID = 1L;
......@@ -45,6 +47,7 @@ public class EmployeeLeaveVO implements Serializable {
@ExcelProperty(value = "减档原因")
@Size(max = 32, message = "减档原因不可超过32位")
@ExcelAttribute(name = "减档原因", isDataId = true,dataType = ExcelAttributeConstants.DOWNSHIFT_REASON)
private String leaveReason;
@ExcelProperty(value = "减档备注")
......
......@@ -52,6 +52,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.InputStream;
import java.util.List;
......@@ -342,12 +343,13 @@ public class TEmployeeInfoController {
* @Date: 2022/6/21 19:42
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.lang.String>
**/
@SneakyThrows
@Operation(summary = "批量减档人员档案表temployeeinfo_batch_minus", description = "批量减档人员档案表")
@SysLog("批量减档人员档案表")
@PostMapping("/batchMinusEmployee")
@PreAuthorize("@pms.hasPermission('temployeeinfo_batch_minus')")
public R<List<ErrorMessageVO>> batchMinusEmployee(@RequestExcel List<EmployeeLeaveVO> excelList, BindingResult bindingResult) {
return tEmployeeInfoService.batchMinusEmployee(excelList, bindingResult);
public R<List<ErrorMessageVO>> batchMinusEmployee(@RequestBody MultipartFile file) {
return tEmployeeInfoService.batchMinusEmployee(file.getInputStream());
}
/**
......
......@@ -137,7 +137,7 @@ public interface TEmployeeInfoService extends IService<TEmployeeInfo> {
* @Date: 2022/6/23 17:12
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.pig4cloud.plugin.excel.vo.ErrorMessage>>
**/
R<List<ErrorMessageVO>> batchMinusEmployee(List<EmployeeLeaveVO> excelVOList, BindingResult bindingResult);
R<List<ErrorMessageVO>> batchMinusEmployee(InputStream inputStream);
/**
* @param employeeInfo 档案信息
......
......@@ -343,7 +343,81 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
}
@Override
public R<List<ErrorMessageVO>> batchMinusEmployee(List<EmployeeLeaveVO> excelVOList, BindingResult bindingResult) {
public R<List<ErrorMessageVO>> batchMinusEmployee(InputStream inputStream) {
List<ErrorMessageVO> errorMessageList = new ArrayList<>();
ExcelUtil<EmployeeLeaveVO> util1 = new ExcelUtil<>(EmployeeLeaveVO.class);
// 写法2:
// 匿名内部类 不用额外写一个DemoDataListener
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
try {
EasyExcel.read(inputStream, EmployeeLeaveVO.class, new ReadListener<EmployeeLeaveVO>() {
/**
* 单次缓存的数据量
*/
public static final int BATCH_COUNT = CommonConstants.BATCH_COUNT;
/**
*临时存储
*/
private List<EmployeeLeaveVO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
@Override
public void invoke(EmployeeLeaveVO data, AnalysisContext context) {
ReadRowHolder readRowHolder = context.readRowHolder();
Integer rowIndex = readRowHolder.getRowIndex();
data.setRowIndex(rowIndex + 1);
com.yifu.cloud.plus.v1.yifu.common.core.util.ErrorMessage errorMessage = util1.checkEntity(data, data.getRowIndex());
if (Common.isNotNull(errorMessage)) {
Set<String> errors = new HashSet<>();
errors.add(errorMessage.getMessage());
ErrorMessageVO errorMessageVO = getErrorMessageVO(errorMessage.getLineNum(), CommonConstants.ZERO_INT, "-"
, "-", errors);
errorMessageList.add(errorMessageVO);
} else {
cachedDataList.add(data);
}
if (cachedDataList.size() >= BATCH_COUNT) {
saveData();
// 存储完成清理 list
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
saveData();
}
/**
* 加上存储数据库
*/
private void saveData() {
log.info("{}条数据,开始存储数据库!", cachedDataList.size());
batchMinusEmployeeCore(cachedDataList, errorMessageList);
log.info("存储数据库成功!");
}
}).sheet().doRead();
} catch (Exception e) {
log.error(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR, e);
return R.failed(CommonConstants.IMPORT_DATA_ANALYSIS_ERROR);
}
if (errorMessageList.isEmpty()) {
return R.ok();
} else {
return R.failed(errorMessageList);
}
}
/**
* @param excelVOList
* @param errorMessageList
* @Description: 批量减档-核心
* @Author: hgw
* @Date: 2022/7/11 10:45
* @return: com.yifu.cloud.plus.v1.yifu.common.core.util.R<java.util.List < com.yifu.cloud.plus.v1.yifu.archives.vo.ErrorMessageVO>>
**/
public R<List<ErrorMessageVO>> batchMinusEmployeeCore(List<EmployeeLeaveVO> excelVOList
, List<ErrorMessageVO> errorMessageList) {
if (excelVOList == null || excelVOList.isEmpty()) {
return R.failed(CommonConstants.DATA_CAN_NOT_EMPTY);
}
......@@ -351,7 +425,6 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
if (user == null || Common.isEmpty(user.getId())) {
return R.failed(CommonConstants.PLEASE_LOG_IN);
}
List<ErrorMessageVO> errorMessageList = new ArrayList<>();
ErrorMessageVO errorMessageVO;
Map<Integer, Integer> errorMsgMap = new HashMap<>();
......@@ -1396,7 +1469,7 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
} else {
idCardList.add(excelVOList.get(i).getEmpIdcard());
}
if (Common.isEmpty(excelVOList.get(i).getEmpPhone())) {
if (Common.isNotNull(excelVOList.get(i).getEmpPhone())) {
phoneList.add(excelVOList.get(i).getEmpPhone());
}
if (Common.isEmpty(excelVOList.get(i).getEmpName())) {
......@@ -1487,27 +1560,29 @@ public class TEmployeeInfoServiceImpl extends ServiceImpl<TEmployeeInfoMapper, T
}
// 校验手机号
existEmp = existPhoneMap.get(excel.getEmpPhone());
// 手机号已存在
if (existEmp != null) {
// 非自己使用的
if (!existEmp.getEmpIdcard().equals(excel.getEmpPhone())) {
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_IMPORT_EMP_PHONE_EXIST_ERROR, existEmp.getEmpIdcard()));
}
} else {
// 调用校验服务-校验手机号
TCheckMobile checkMobile = new TCheckMobile();
checkMobile.setMobile(excel.getEmpPhone());
R<TCheckMobile> a = HttpDaprUtil.invokeMethodPost(daprCheckProperties.getAppUrl(), daprCheckProperties.getAppId()
, "/tcheckmobile/inner/checkOneMobile", checkMobile, TCheckMobile.class, SecurityConstants.FROM_IN);
if (a != null && a.getData() != null) {
checkMobile = a.getData();
if (checkMobile != null && Common.isNotNull(checkMobile.getStatus())) {
if (!CommonConstants.ONE_STRING.equals(checkMobile.getStatus())) {
errorMsg.add(checkMobile.getMessage());
if (Common.isNotNull(excel.getEmpPhone())) {
existEmp = existPhoneMap.get(excel.getEmpPhone());
// 手机号已存在
if (existEmp != null) {
// 非自己使用的
if (!existEmp.getEmpIdcard().equals(excel.getEmpPhone())) {
errorMsg.add(MsgUtils.getMessage(ErrorCodes.ARCHIVES_IMPORT_EMP_PHONE_EXIST_ERROR, existEmp.getEmpIdcard()));
}
} else {
// 调用校验服务-校验手机号
TCheckMobile checkMobile = new TCheckMobile();
checkMobile.setMobile(excel.getEmpPhone());
R<TCheckMobile> a = HttpDaprUtil.invokeMethodPost(daprCheckProperties.getAppUrl(), daprCheckProperties.getAppId()
, "/tcheckmobile/inner/checkOneMobile", checkMobile, TCheckMobile.class, SecurityConstants.FROM_IN);
if (a != null && a.getData() != null) {
checkMobile = a.getData();
if (checkMobile != null && Common.isNotNull(checkMobile.getStatus())) {
if (!CommonConstants.ONE_STRING.equals(checkMobile.getStatus())) {
errorMsg.add(checkMobile.getMessage());
}
} else {
errorMsg.add("校验服务错误,请联系管理员!");
}
} else {
errorMsg.add("校验服务错误,请联系管理员!");
}
}
}
......
......@@ -28,6 +28,8 @@ public class ExcelAttributeConstants {
public static final String SOCIAL_ECURITY_STATE = "social_ecurity_state";
// 公积金状态
public static final String FUND_STATUS = "fund_status";
// 减档原因
public static final String DOWNSHIFT_REASON = "downshift_reason";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment