薪资档案定薪调薪适配多个扣缴义务人
This commit is contained in:
parent
a721898d3d
commit
d1770aadbb
|
|
@ -53,6 +53,7 @@ import org.apache.poi.ss.usermodel.Sheet;
|
|||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
|
@ -356,13 +357,20 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
List<Object> header = Lists.newArrayList();
|
||||
header.add(SalaryI18nUtil.getI18nLabel(85429, "姓名"));
|
||||
header.add(SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人"));
|
||||
header.add(SalaryI18nUtil.getI18nLabel(85904, "生效日期"));
|
||||
if (isSalaryItemAdjust) {
|
||||
header.add(SalaryI18nUtil.getI18nLabel(85904, "生效日期"));
|
||||
}
|
||||
if (isTaxAgentAdjust || isSalaryItemAdjust) {
|
||||
header.add(SalaryI18nUtil.getI18nLabel(85431, "调整原因"));
|
||||
}
|
||||
header.add(SalaryI18nUtil.getI18nLabel(86185, "部门"));
|
||||
header.add(SalaryI18nUtil.getI18nLabel(86186, "手机号"));
|
||||
header.add(SalaryI18nUtil.getI18nLabel(91075, "状态"));
|
||||
if (isInit) {
|
||||
header.add(SalaryI18nUtil.getI18nLabel(91075, "起始发薪日期"));
|
||||
header.add(SalaryI18nUtil.getI18nLabel(91075, "最后发薪日期"));
|
||||
}
|
||||
|
||||
if (isInit || isSalaryItemAdjust) {
|
||||
for (SalaryItemPO salaryItem : salaryItems) {
|
||||
header.add(salaryItem.getName());
|
||||
|
|
@ -380,15 +388,21 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
List<Map<String, Object>> listMaps = buildSalaryArchiveData(salaryArchives, taxAgentList, salaryItems, Boolean.FALSE);
|
||||
listMaps.forEach(e -> {
|
||||
List<Object> row = new ArrayList<>();
|
||||
row.add(e.get("username").toString());
|
||||
row.add(e.get("taxAgentName").toString());
|
||||
row.add(Util.null2String(e.get("username")));
|
||||
row.add(Util.null2String(e.get("taxAgentName")));
|
||||
if (isTaxAgentAdjust || isSalaryItemAdjust) {
|
||||
row.add(isTaxAgentAdjust ? e.get("taxAgentEffectiveTime") : "");
|
||||
}
|
||||
row.add("");
|
||||
row.add(e.get("departmentName").toString());
|
||||
row.add(e.get("mobile") == null ? "" : e.get("mobile").toString());
|
||||
row.add(e.get("employeeStatus").toString());
|
||||
if (isSalaryItemAdjust) {
|
||||
row.add("");
|
||||
}
|
||||
row.add(Util.null2String(e.get("departmentName")));
|
||||
row.add(Util.null2String(e.get("mobile")));
|
||||
row.add(Util.null2String(e.get("employeeStatus")));
|
||||
if (isInit) {
|
||||
row.add(Util.null2String(e.get("payStartDate")));
|
||||
row.add(Util.null2String(e.get("payEndDate")));
|
||||
}
|
||||
// 调薪
|
||||
if (isInit || isSalaryItemAdjust) {
|
||||
// 薪资项目数据
|
||||
|
|
@ -404,11 +418,10 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
// 4.注释
|
||||
List<ExcelComment> excelComments = Lists.newArrayList();
|
||||
excelComments.add(new ExcelComment(0, 0, 3, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
||||
if (isInit || isTaxAgentAdjust) {
|
||||
excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
||||
excelComments.add(new ExcelComment(1, 0, 4, 2, SalaryI18nUtil.getI18nLabel(100344, "必填")));
|
||||
if (isSalaryItemAdjust) {
|
||||
excelComments.add(new ExcelComment(2, 0, 5, 2, SalaryI18nUtil.getI18nLabel(100458, "必填,格式样例为'2022-01-01'、'2022/1/1'")));
|
||||
}
|
||||
excelComments.add(new ExcelComment(2, 0, 5, 2, SalaryI18nUtil.getI18nLabel(100458, "必填,格式样例为'2022-01-01'、'2022/1/1'")));
|
||||
|
||||
//调整个税扣缴义务人
|
||||
if (isTaxAgentAdjust) {
|
||||
excelComments.add(new ExcelComment(3, 0, 6, 2, SalaryI18nUtil.getI18nLabel(100952, "必填,可填写如:调动,变更,入职,离职,其他,初始化")));
|
||||
|
|
@ -416,6 +429,9 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
} else if (isSalaryItemAdjust) {
|
||||
excelComments.add(new ExcelComment(3, 0, 6, 2, SalaryI18nUtil.getI18nLabel(100953, "必填,可填写如:入职,转正,调薪,调岗调薪,离职,其他,初始化")));
|
||||
}
|
||||
if (isInit) {
|
||||
excelComments.add(new ExcelComment(5, 0, 8, 2, SalaryI18nUtil.getI18nLabel(100458, "必填,格式样例为'2022-01-01'、'2022/1/1'")));
|
||||
}
|
||||
XSSFWorkbook book = ExcelUtil.genWorkbookV2(rows, sheetName, excelComments);
|
||||
return book;
|
||||
|
||||
|
|
@ -526,13 +542,6 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
// 用于(调薪和调整个税扣缴义务人)的相同employeeId时取第一条记录,如果是初始化导入则有重复
|
||||
List<Long> allEmployeeIds = Lists.newArrayList();
|
||||
|
||||
int effectiveTimeIndex = 0;
|
||||
for (int j = 0; j < headers.size(); j++) {
|
||||
if (headers.get(j).equals(SalaryI18nUtil.getI18nLabel(85904, "生效日期"))) {
|
||||
effectiveTimeIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 错误sheet数据
|
||||
List<Map<String, Object>> errorData = new ArrayList<>();
|
||||
// 错误提示
|
||||
|
|
@ -543,7 +552,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
Map<String, Object> map = data.get(i);
|
||||
map.put("index", i + 2);
|
||||
// 3.校验行内容
|
||||
boolean isError = singleRowCheck(importType, allEmployeeIds, map, headers, effectiveTimeIndex, excelComments, errorCount, importHandleParam);
|
||||
boolean isError = singleRowCheck(importType, allEmployeeIds, map, headers, excelComments, errorCount, importHandleParam);
|
||||
|
||||
if (isError) {
|
||||
errorCount += 1;
|
||||
|
|
@ -706,7 +715,6 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", "该员工的薪资档案记录有误,请检查");
|
||||
excelComments.add(errorMessageMap);
|
||||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(101723, "该员工的薪资档案记录有误,请检查"), finalErrorCount.get() + 1, finalErrorCount.get() + 1, 0, 0);
|
||||
finalErrorCount.addAndGet(1);
|
||||
errorData.add(e.getRow());
|
||||
finalSuccessCount.addAndGet(-1);
|
||||
|
|
@ -716,7 +724,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
} else {
|
||||
int nums = sames.size();
|
||||
// 1.生效时间不可重复
|
||||
List<String> effectiveTimeList = sames.stream().map(m -> Optional.ofNullable(m.getRow().get("effectiveTime")).orElse("").toString()).distinct().collect(Collectors.toList());
|
||||
List<String> effectiveTimeList = sames.stream().map(m -> Optional.ofNullable(m.getRow().get("payStartDate")).orElse("").toString()).distinct().collect(Collectors.toList());
|
||||
// 2.个税扣缴义务人和薪资项目共同决定是否重复
|
||||
List<String> rowSameList = sames.stream().map(m -> {
|
||||
Map<String, Object> row = m.getRow();
|
||||
|
|
@ -724,14 +732,13 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
String salaryItem = Optional.ofNullable(row.get("salaryItemVal")).orElse("").toString();
|
||||
return taxAgent + salaryItem;
|
||||
}).distinct().collect(Collectors.toList());
|
||||
if (effectiveTimeList.size() != nums || rowSameList.size() != nums) {
|
||||
if (/** effectiveTimeList.size() != nums || */ rowSameList.size() != nums) {
|
||||
sames.forEach(e -> {
|
||||
if (!e.isError()) {
|
||||
e.setError(Boolean.TRUE);
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", "该员工的薪资档案记录有误");
|
||||
excelComments.add(errorMessageMap);
|
||||
// salaryBatchService.createExcelComment(excelComments, SalaryI18nUtil.getI18nLabel(101723, "该员工的薪资档案记录有误,请检查"), finalErrorCount.get() + 1, finalErrorCount.get() + 1, 0, 0);
|
||||
finalErrorCount.addAndGet(1);
|
||||
errorData.add(e.getRow());
|
||||
finalSuccessCount.addAndGet(-1);
|
||||
|
|
@ -776,7 +783,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
* @param importHandleParam
|
||||
* @return
|
||||
*/
|
||||
private boolean singleRowCheck(String importType, List<Long> allEmployeeIds, Map<String, Object> map, List<String> headers, int effectiveTimeIndex,
|
||||
private boolean singleRowCheck(String importType, List<Long> allEmployeeIds, Map<String, Object> map, List<String> headers,
|
||||
List<Map<String, String>> excelComments, int errorCount, SalaryArchiveImportHandleParam importHandleParam) {
|
||||
boolean isError = false;
|
||||
|
||||
|
|
@ -787,6 +794,8 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
String userNameI18n = SalaryI18nUtil.getI18nLabel(85429, "姓名");
|
||||
String taxAgentI18n = SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人");
|
||||
String effectiveTimeI18n = SalaryI18nUtil.getI18nLabel(85904, "生效日期");
|
||||
String payStartDateI18n = SalaryI18nUtil.getI18nLabel(85904, "起始发薪日期");
|
||||
String payEndDateI18n = SalaryI18nUtil.getI18nLabel(85904, "最后发薪日期");
|
||||
String adjustReasonI18n = SalaryI18nUtil.getI18nLabel(85431, "调整原因");
|
||||
String rowindex = "第" + map.get("index") + "行";
|
||||
// 1.姓名
|
||||
|
|
@ -843,8 +852,21 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
adjustReason = SalaryArchiveItemAdjustReasonEnum.getValueByDefaultLabel(Optional.ofNullable(map.get(adjustReasonI18n)).orElse("").toString());
|
||||
}
|
||||
|
||||
// 5.起始发薪日期
|
||||
String payStartDateCellVal = Optional.ofNullable(map.get(payStartDateI18n)).orElse("").toString().replaceAll(" 00:00:00", "");
|
||||
// 免得失败后,会追加 00:00:00
|
||||
map.put(payStartDateI18n, payStartDateCellVal);
|
||||
map.put("payStartDate", payStartDateCellVal);
|
||||
Date payStartDate = SalaryDateUtil.checkDay(payStartDateCellVal) ? dateStrToLocalDate(payStartDateCellVal) : null;
|
||||
// 6.最后发薪日期
|
||||
String payEndDateCellVal = Optional.ofNullable(map.get(payEndDateI18n)).orElse("").toString().replaceAll(" 00:00:00", "");
|
||||
// 免得失败后,会追加 00:00:00
|
||||
map.put(payEndDateI18n, payEndDateCellVal);
|
||||
map.put("payEndDate", payEndDateCellVal);
|
||||
Date payEndDate = SalaryDateUtil.checkDay(payEndDateCellVal) ? dateStrToLocalDate(payEndDateCellVal) : null;
|
||||
|
||||
// 构建薪资档案
|
||||
SalaryArchivePO finalSalaryArchive = buildSalaryArchive(isInit, employeeId, taxAgentId, importHandleParam);
|
||||
SalaryArchivePO finalSalaryArchive = buildSalaryArchive(isInit, payStartDate, payEndDate, employeeId, taxAgentId, importHandleParam);
|
||||
|
||||
for (int j = 0; j < headers.size(); j++) {
|
||||
String key = headers.get(j);
|
||||
|
|
@ -855,7 +877,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
(userNameI18n.equals(key)
|
||||
// 个税扣缴义务人列判空(初始化导入或调整个税扣缴义务人)
|
||||
|| (taxAgentI18n.equals(key) && (isInit || isTaxAgentAdjust))
|
||||
|| effectiveTimeI18n.equals(key)
|
||||
|| (effectiveTimeI18n.equals(key) && isSalaryItemAdjust)
|
||||
// 调整原因列判空(调薪或调整个税扣缴义务人)
|
||||
|| (adjustReasonI18n.equals(key) && (isTaxAgentAdjust || isSalaryItemAdjust)));
|
||||
// 判空
|
||||
|
|
@ -870,17 +892,25 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
errorMessageMap.put("message", rowindex + key + "不能为空");
|
||||
excelComments.add(errorMessageMap);
|
||||
}
|
||||
if (effectiveTimeI18n.equals(key) && StringUtils.isEmpty(cellVal)) {
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", rowindex + key + "不能为空");
|
||||
excelComments.add(errorMessageMap);
|
||||
}
|
||||
// 调整原因列判空(调薪或调整个税扣缴义务人)
|
||||
if ((adjustReasonI18n.equals(key) && (isTaxAgentAdjust || isSalaryItemAdjust)) && StringUtils.isEmpty(cellVal)) {
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", rowindex + key + "不能为空");
|
||||
excelComments.add(errorMessageMap);
|
||||
}
|
||||
//调薪生效时间不能为空
|
||||
if (isSalaryItemAdjust && effectiveTimeI18n.equals(key) && StringUtils.isEmpty(cellVal)){
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", rowindex + key + "不能为空");
|
||||
excelComments.add(errorMessageMap);
|
||||
}
|
||||
//定薪起始时间不能为空
|
||||
if (isInit && payStartDateI18n.equals(key) && StringUtils.isEmpty(cellVal)){
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
errorMessageMap.put("message", rowindex + key + "不能为空");
|
||||
excelComments.add(errorMessageMap);
|
||||
}
|
||||
|
||||
if (isEmpty) {
|
||||
isError = true;
|
||||
}
|
||||
|
|
@ -908,7 +938,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
importHandleParam.setEmployeeId(employeeId);
|
||||
} else if (!isEmpty && taxAgentI18n.equals(key) && (isInit || isTaxAgentAdjust)) {
|
||||
// 2.个税扣缴义务人列处理(初始化导入或调整个税扣缴义务人)
|
||||
isError = handleTaxAgent(isError, isInit, effectiveTimeIndex, excelComments, errorCount, j, taxAgentId, effectiveTime, finalSalaryArchive, adjustReason, importHandleParam, map);
|
||||
isError = handleTaxAgent(isError, isInit, excelComments, errorCount, j, taxAgentId, effectiveTime, finalSalaryArchive, adjustReason, importHandleParam, map);
|
||||
} else if (!isEmpty && effectiveTimeI18n.equals(key) && effectiveTime == null) {
|
||||
// 3.生效时间处理
|
||||
Map<String, String> errorMessageMap = Maps.newHashMap();
|
||||
|
|
@ -925,10 +955,14 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
// 5.薪资项目列处理(初始化导入或调薪)
|
||||
} else {
|
||||
// 薪资项目数据
|
||||
if(isInit){
|
||||
effectiveTime = payStartDate;
|
||||
}
|
||||
if (effectiveTime == null || finalSalaryArchive == null || !(isInit || isSalaryItemAdjust)) {
|
||||
continue;
|
||||
}
|
||||
isError = handleSalaryItem(isError, isInit, effectiveTimeIndex, excelComments, errorCount, j,
|
||||
|
||||
isError = handleSalaryItem(isError, isInit, excelComments,
|
||||
effectiveTime, finalSalaryArchive, adjustReason, importHandleParam, key, cellVal, map);
|
||||
|
||||
}
|
||||
|
|
@ -936,7 +970,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
return isError;
|
||||
}
|
||||
|
||||
private SalaryArchivePO buildSalaryArchive(boolean isInit, Long employeeId, Long taxAgentId, SalaryArchiveImportHandleParam importHandleParam) {
|
||||
private SalaryArchivePO buildSalaryArchive(boolean isInit, Date payStartDate,Date payEndDate,Long employeeId, Long taxAgentId, SalaryArchiveImportHandleParam importHandleParam) {
|
||||
Optional<SalaryArchiveListDTO> optionalSA = importHandleParam.getSalaryArchives().stream().filter(p -> p.getEmployeeId().equals(employeeId) && p.getTaxAgentId().equals(taxAgentId)).findFirst();
|
||||
SalaryArchivePO salaryArchive = null;
|
||||
if (optionalSA.isPresent()) {
|
||||
|
|
@ -946,12 +980,16 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
salaryArchive.setId(sa.getId());
|
||||
salaryArchive.setEmployeeId(sa.getEmployeeId());
|
||||
salaryArchive.setTaxAgentId(sa.getTaxAgentId());
|
||||
salaryArchive.setPayStartDate(payStartDate);
|
||||
salaryArchive.setPayEndDate(payEndDate);
|
||||
} else if (employeeId != null && isInit) {
|
||||
// 新增档案
|
||||
salaryArchive = SalaryArchivePO.builder()
|
||||
.id(IdGenerator.generate())
|
||||
.employeeId(employeeId)
|
||||
.taxAgentId(taxAgentId)
|
||||
.payStartDate(payStartDate)
|
||||
.payEndDate(payEndDate)
|
||||
.createTime(importHandleParam.getNowTime())
|
||||
.updateTime(importHandleParam.getNowTime())
|
||||
.creator((long) user.getUID())
|
||||
|
|
@ -977,7 +1015,7 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
* @param importHandleParam
|
||||
* @return
|
||||
*/
|
||||
private boolean handleTaxAgent(boolean isError, boolean isInit, int effectiveTimeIndex,
|
||||
private boolean handleTaxAgent(boolean isError, boolean isInit,
|
||||
List<Map<String, String>> excelComments, int errorCount, int j,
|
||||
Long taxAgentId, Date effectiveTime, SalaryArchivePO finalSalaryArchive, String taxAgentAdjustReason, SalaryArchiveImportHandleParam importHandleParam, Map<String, Object> map) {
|
||||
String rowindex = "第" + map.get("index") + "行";
|
||||
|
|
@ -1118,8 +1156,6 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
*
|
||||
* @param isError
|
||||
* @param excelComments
|
||||
* @param errorCount
|
||||
* @param j
|
||||
* @param effectiveTime
|
||||
* @param finalSalaryArchive
|
||||
* @param salaryItemAdjustReason
|
||||
|
|
@ -1127,8 +1163,8 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
* @param cellVal
|
||||
* @return
|
||||
*/
|
||||
private boolean handleSalaryItem(boolean isError, boolean isInit, int effectiveTimeIndex,
|
||||
List<Map<String, String>> excelComments, int errorCount, int j,
|
||||
private boolean handleSalaryItem(boolean isError, boolean isInit,
|
||||
List<Map<String, String>> excelComments,
|
||||
Date effectiveTime, SalaryArchivePO finalSalaryArchive, String salaryItemAdjustReason, SalaryArchiveImportHandleParam importHandleParam,
|
||||
String key, String cellVal, Map<String, Object> map) {
|
||||
String rowindex = "第" + map.get("index") + "行";
|
||||
|
|
@ -1311,13 +1347,15 @@ public class SalaryArchiveServiceImpl extends Service implements SalaryArchiveSe
|
|||
String userNameI18n = SalaryI18nUtil.getI18nLabel(85429, "姓名");
|
||||
String taxAgentI18n = SalaryI18nUtil.getI18nLabel(86184, "个税扣缴义务人");
|
||||
String effectiveTimeI18n = SalaryI18nUtil.getI18nLabel(85904, "生效日期");
|
||||
String payStartDateI18n = SalaryI18nUtil.getI18nLabel(85904, "起始发薪日期");
|
||||
String payEndDateI18n = SalaryI18nUtil.getI18nLabel(85904, "最后发薪日期");
|
||||
String adjustReasonI18n = SalaryI18nUtil.getI18nLabel(85431, "调整原因");
|
||||
|
||||
List<String> mustHeaders = Lists.newArrayList();
|
||||
if (isInit) {
|
||||
mustHeaders.add(userNameI18n);
|
||||
mustHeaders.add(taxAgentI18n);
|
||||
mustHeaders.add(effectiveTimeI18n);
|
||||
mustHeaders.add(payStartDateI18n);
|
||||
} else if (isTaxAgentAdjust) {
|
||||
mustHeaders.add(userNameI18n);
|
||||
mustHeaders.add(taxAgentI18n);
|
||||
|
|
|
|||
Loading…
Reference in New Issue