考勤引用多个账套

This commit is contained in:
Harryxzy 2024-08-06 16:54:19 +08:00
parent ff00de206c
commit dd18cf5191
7 changed files with 84 additions and 71 deletions

View File

@ -7,6 +7,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.YearMonth;
import java.util.List;
/**
* 考勤引用是否可以操作参数
@ -30,5 +31,5 @@ public class AttendQuoteCheckOperationParam {
//关联账套id
@DataCheck(require = true, message = "关联账套id必传")
private Long salarySobId;
private List<Long> salarySobIds;
}

View File

@ -6,9 +6,11 @@ import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Collection;
import java.util.List;
/**
* 数据采集-考勤引用数据同步参数
@ -28,7 +30,7 @@ public class AttendQuoteDataSyncParam {
private String salaryYearMonth;
//关联账套id
private Long salarySobId;
private List<Long> salarySobIds;
//账套外人员主键id
private Collection<Long> employeeIds;
@ -43,7 +45,7 @@ public class AttendQuoteDataSyncParam {
if (StringUtils.isEmpty(saveParam.getSalaryYearMonth())) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100294, "薪资所属月必传"));
}
if (saveParam.getSalarySobId() == null) {
if (CollectionUtils.isEmpty(saveParam.getSalarySobIds())) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100295, "薪资账套必传"));
}
}

View File

@ -7,6 +7,7 @@ import com.engine.salary.util.page.PageInfo;
import java.time.YearMonth;
import java.util.Collection;
import java.util.List;
public interface AttendQuoteService {
@ -31,10 +32,10 @@ public interface AttendQuoteService {
* 检查是否可以操作
*
* @param salaryYearMonth
* @param salarySobId
* @param salarySobIds
* @return
*/
Boolean checkOperation(YearMonth salaryYearMonth, Long salarySobId);
Boolean checkOperation(YearMonth salaryYearMonth, List<Long> salarySobIds);
AttendQuotePO getById(Long id);

View File

@ -334,7 +334,7 @@ public class AttendQuoteDataServiceImpl extends Service implements AttendQuoteDa
@Override
public String syncAttendQuoteData(AttendQuoteDataSyncParam syncParam) {
AttendQuoteDataSyncParam.checkParam(syncParam);
Long salarySobId = syncParam.getSalarySobId();
List<Long> salarySobIds = syncParam.getSalarySobIds();
String salaryYearMonth = syncParam.getSalaryYearMonth();
int year = Integer.parseInt(salaryYearMonth.split("-")[0]);
int month = Integer.parseInt(salaryYearMonth.split("-")[1]);
@ -348,77 +348,85 @@ public class AttendQuoteDataServiceImpl extends Service implements AttendQuoteDa
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100366, "请先设置同步字段"));
}
// 获取薪资账套
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(syncParam.getSalarySobId(), YearMonth.of(year, month));
String errorMsg = "";
for (Long salarySobId : salarySobIds) {
// 获取薪资账套
SalarySobCycleDTO salarySobCycleDTO = getSalarySobService(user).getSalarySobCycle(salarySobId, YearMonth.of(year, month));
SalarySobPO salarySobPO = getSalarySobService(user).getById(salarySobId);
// 根据薪资账套查询人员
List<DataCollectionEmployee> salaryEmployees = getSalaryEmployeeService(user).listBySalarySobId(salarySobId);
if (CollectionUtils.isEmpty(salaryEmployees)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100367, "薪资账套没有人员"));
}
// 根据薪资账套查询薪资周期
SalarySobPO salarySobPO = getSalarySobService(user).getById(salarySobId);
Long taxAgentId = salarySobPO.getTaxAgentId();
// 根据薪资账套查询人员
List<DataCollectionEmployee> salaryEmployees = getSalaryEmployeeService(user).listBySalarySobId(salarySobId);
if (CollectionUtils.isEmpty(salaryEmployees)) {
errorMsg = errorMsg + "" + salarySobPO.getName() + "】薪资账套没有人员; ";
} else {
// 根据薪资账套查询薪资周期
Long taxAgentId = salarySobPO.getTaxAgentId();
// 查询薪资档案获取人员的个税扣缴义务人
List<Long> employeeIds = SalaryEntityUtil.properties(salaryEmployees, DataCollectionEmployee::getEmployeeId, Collectors.toList());
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
// 转换成薪资核算人员po
Date salaryDate = SalaryDateUtil.dateStrToLocalTime(salaryYearMonth + "-01");
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2Employee(salaryEmployees, SalaryAcctRecordPO.builder().salarySobId(salarySobId).salaryMonth(salaryDate).build(), salaryArchiveDataDTOS, (long) user.getUID());
// 查询薪资档案获取人员的个税扣缴义务人
List<Long> employeeIds = SalaryEntityUtil.properties(salaryEmployees, DataCollectionEmployee::getEmployeeId, Collectors.toList());
List<SalaryArchiveDataDTO> salaryArchiveDataDTOS = getSalaryArchiveService(user).getSalaryArchiveTaxAgentData(salarySobCycleDTO.getSalaryCycle(), employeeIds, taxAgentId);
// 转换成薪资核算人员po
Date salaryDate = SalaryDateUtil.dateStrToLocalTime(salaryYearMonth + "-01");
List<SalaryAcctEmployeePO> salaryAcctEmployeePOS = SalaryAcctEmployeeBO.convert2Employee(salaryEmployees, SalaryAcctRecordPO.builder().salarySobId(salarySobId).salaryMonth(salaryDate).build(), salaryArchiveDataDTOS, (long) user.getUID());
//过滤掉不属于当前账套扣缴义务人的人员
employeeIds = salaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
//过滤掉不属于当前账套扣缴义务人的人员
employeeIds = salaryAcctEmployeePOS.stream().filter(po -> Objects.equals(taxAgentId, po.getTaxAgentId())).map(SalaryAcctEmployeePO::getEmployeeId).collect(Collectors.toList());
// 4.获取考勤模块数据
List<Map<String, Object>> attendQuoteSyncData = getAttendQuoteDataFromRemoteAttend(salarySobCycleDTO.getAttendCycle(), employeeIds, attendQuoteFields);
List<AttendQuoteDataPO> pos = new ArrayList<>();
List<AttendQuoteDataValuePO> values = new ArrayList<>();
// 5.考勤引用数据处理
Date now = new Date();
if (CollectionUtils.isNotEmpty(attendQuoteSyncData)) {
// 4.获取考勤模块数据
List<Map<String, Object>> attendQuoteSyncData = getAttendQuoteDataFromRemoteAttend(salarySobCycleDTO.getAttendCycle(), employeeIds, attendQuoteFields);
List<AttendQuoteDataPO> pos = new ArrayList<>();
List<AttendQuoteDataValuePO> values = new ArrayList<>();
// 5.考勤引用数据处理
Date now = new Date();
if (CollectionUtils.isNotEmpty(attendQuoteSyncData)) {
// 3.生成考勤引用
AttendQuotePO attendQuote = getAttendQuote(AttendQuoteSourceTypeEnum.QUOTE, salarySobId, year, month, syncParam.getDescription());
// 3.生成考勤引用
AttendQuotePO attendQuote = getAttendQuote(AttendQuoteSourceTypeEnum.QUOTE, salarySobId, year, month, syncParam.getDescription());
for (Long employeeId : employeeIds) {
AttendQuoteDataPO po = new AttendQuoteDataPO();
po.setId(IdGenerator.generate());
po.setCreateTime(now);
po.setUpdateTime(now);
po.setCreator((long) user.getUID());
po.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY);
// 考勤引用表的主键id
po.setAttendQuoteId(attendQuote.getId());
po.setEmployeeId(employeeId);
pos.add(po);
for (Map<String, Object> attendQuoteData : attendQuoteSyncData) {
if (!Objects.isNull(attendQuoteData.get("employeeId")) &&
!Objects.isNull(employeeId) &&
!Objects.isNull(attendQuoteData.get("attendQuoteFieldId")) &&
attendQuoteData.get("employeeId").toString().equals(employeeId.toString())) {
values.add(AttendQuoteDataValuePO.builder()
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.employeeId(employeeId)
.attendQuoteId(attendQuote.getId())
.attendQuoteDataId(po.getId())
.attendQuoteFieldId(Long.valueOf(attendQuoteData.get("attendQuoteFieldId").toString()))
.dataValue(Utils.null2String(attendQuoteData.get("dataValue")))
.build());
for (Long employeeId : employeeIds) {
AttendQuoteDataPO po = new AttendQuoteDataPO();
po.setId(IdGenerator.generate());
po.setCreateTime(now);
po.setUpdateTime(now);
po.setCreator((long) user.getUID());
po.setTenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY);
// 考勤引用表的主键id
po.setAttendQuoteId(attendQuote.getId());
po.setEmployeeId(employeeId);
pos.add(po);
for (Map<String, Object> attendQuoteData : attendQuoteSyncData) {
if (!Objects.isNull(attendQuoteData.get("employeeId")) &&
!Objects.isNull(employeeId) &&
!Objects.isNull(attendQuoteData.get("attendQuoteFieldId")) &&
attendQuoteData.get("employeeId").toString().equals(employeeId.toString())) {
values.add(AttendQuoteDataValuePO.builder()
.createTime(now)
.updateTime(now)
.creator((long) user.getUID())
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.employeeId(employeeId)
.attendQuoteId(attendQuote.getId())
.attendQuoteDataId(po.getId())
.attendQuoteFieldId(Long.valueOf(attendQuoteData.get("attendQuoteFieldId").toString()))
.dataValue(Utils.null2String(attendQuoteData.get("dataValue")))
.build());
}
}
}
// 6.数据落库处理
handleDataToDB(attendQuote.getId(), pos, values);
// 记录日志
recordLog(attendQuote);
} else {
errorMsg = errorMsg + "" + salarySobPO.getName() + "" + "暂无考勤数据可以同步; ";
}
}
}
// 6.数据落库处理
handleDataToDB(attendQuote.getId(), pos, values);
// 记录日志
recordLog(attendQuote);
} else {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100368, "暂无考勤数据可以同步"));
if (StringUtils.isNotBlank(errorMsg)) {
throw new SalaryRunTimeException(errorMsg);
}
return null;
}

View File

@ -151,9 +151,9 @@ public class AttendQuoteServiceImpl extends Service implements AttendQuoteServic
@Override
public Boolean checkOperation(YearMonth salaryYearMonth, Long salarySobId) {
public Boolean checkOperation(YearMonth salaryYearMonth, List<Long> salarySobIds) {
// 已经核算过的不可操作
List<SalaryAcctRecordPO> salaryAcctRecords = getSalaryAcctRecordService(user).listBySalarySobIds(Collections.singletonList(salarySobId));
List<SalaryAcctRecordPO> salaryAcctRecords = getSalaryAcctRecordService(user).listBySalarySobIds(salarySobIds);
AtomicReference<Boolean> isEnableOperation = new AtomicReference<>(Boolean.TRUE);
salaryAcctRecords.forEach(e -> {
boolean isAccounted = e.getSalaryMonth().equals(SalaryDateUtil.localDateToDate(LocalDate.of(salaryYearMonth.getYear(), salaryYearMonth.getMonth(), 1)))

View File

@ -15,6 +15,7 @@ import weaver.hrm.User;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -60,7 +61,7 @@ public class AutoSyncAttendQuoteJob extends BaseCronJob {
salarySobList.stream().forEach(sob -> {
// 校验是否可以操作
Boolean canSync = getAttendQuoteWrapper(tempUser).checkOperation(AttendQuoteCheckOperationParam.builder()
.salarySobId(sob.getId())
.salarySobIds(Collections.singletonList(sob.getId()))
.salaryYearMonthStr(dateStr)
.build());
if (canSync) {
@ -68,7 +69,7 @@ public class AutoSyncAttendQuoteJob extends BaseCronJob {
try {
baseBean.writeLog("自动同步考勤数据开始:"+ sob.getId()+","+dateStr);
getAttendQuoteDataWrapper(tempUser).syncAttendQuoteData(AttendQuoteDataSyncParam.builder()
.salarySobId(sob.getId())
.salarySobIds(Collections.singletonList(sob.getId()))
.salaryYearMonth(dateStr)
.build());
baseBean.writeLog("自动同步考勤数据结束:"+ sob.getId()+","+dateStr);

View File

@ -107,7 +107,7 @@ public class AttendQuoteWrapper extends Service {
String salaryYearMonthStr = checkOperationParam.getSalaryYearMonthStr();
YearMonth yearMonth = SalaryDateUtil.String2YearMonth(salaryYearMonthStr);
checkOperationParam.setSalaryYearMonth(yearMonth);
return getAttendQuoteService(user).checkOperation(checkOperationParam.getSalaryYearMonth(), checkOperationParam.getSalarySobId());
return getAttendQuoteService(user).checkOperation(checkOperationParam.getSalaryYearMonth(), checkOperationParam.getSalarySobIds());
}
/**