weaver-hrm-salary/src/com/engine/salary/service/impl/AttendQuoteServiceImpl.java

177 lines
8.9 KiB
Java
Raw Normal View History

2022-03-11 11:08:50 +08:00
package com.engine.salary.service.impl;
2022-05-05 10:35:58 +08:00
import com.engine.common.util.ServiceUtil;
2022-03-11 11:08:50 +08:00
import com.engine.core.impl.Service;
2022-03-15 09:55:58 +08:00
import com.engine.salary.biz.AttendQuoteBiz;
import com.engine.salary.biz.AttendQuoteDataBiz;
2022-03-15 14:18:04 +08:00
import com.engine.salary.biz.AttendQuoteDataValueBiz;
2024-02-21 18:19:02 +08:00
import com.engine.salary.config.SalaryElogConfig;
2022-03-15 09:55:58 +08:00
import com.engine.salary.entity.datacollection.dto.AttendQuoteListDTO;
import com.engine.salary.entity.datacollection.param.AttendQuoteDataQueryParam;
import com.engine.salary.entity.datacollection.param.AttendQuoteQueryParam;
import com.engine.salary.entity.datacollection.po.AttendQuoteDataPO;
2024-02-21 18:19:02 +08:00
import com.engine.salary.entity.datacollection.po.AttendQuotePO;
2022-05-05 10:35:58 +08:00
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
2022-06-07 15:43:22 +08:00
import com.engine.salary.entity.salarysob.po.SalarySobPO;
2022-05-05 10:35:58 +08:00
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
2022-03-15 09:55:58 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
2022-04-21 14:15:56 +08:00
import com.engine.salary.mapper.datacollection.AttendQuoteMapper;
2022-03-11 11:08:50 +08:00
import com.engine.salary.service.AttendQuoteService;
2022-05-05 10:35:58 +08:00
import com.engine.salary.service.SalaryAcctRecordService;
2022-06-07 15:43:22 +08:00
import com.engine.salary.service.SalarySobService;
import com.engine.salary.service.TaxAgentService;
2022-05-05 10:35:58 +08:00
import com.engine.salary.util.SalaryDateUtil;
2022-06-07 15:43:22 +08:00
import com.engine.salary.util.SalaryEntityUtil;
2024-02-21 18:19:02 +08:00
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.SalaryLoggerUtil;
2022-04-21 14:15:56 +08:00
import com.engine.salary.util.db.MapperProxyFactory;
import com.engine.salary.util.page.PageInfo;
2022-05-25 13:10:03 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
2022-03-15 09:55:58 +08:00
import org.apache.commons.collections4.CollectionUtils;
2022-06-07 15:43:22 +08:00
import org.apache.commons.lang3.math.NumberUtils;
2022-05-05 10:35:58 +08:00
import weaver.hrm.User;
2022-03-11 11:08:50 +08:00
2022-05-05 10:35:58 +08:00
import java.time.LocalDate;
import java.time.YearMonth;
2023-06-16 13:33:38 +08:00
import java.util.*;
2022-05-05 10:35:58 +08:00
import java.util.concurrent.atomic.AtomicReference;
2022-03-15 09:55:58 +08:00
import java.util.stream.Collectors;
2022-03-11 11:08:50 +08:00
public class AttendQuoteServiceImpl extends Service implements AttendQuoteService {
2022-03-15 14:18:04 +08:00
private AttendQuoteBiz biz = new AttendQuoteBiz();
private AttendQuoteDataBiz dataBiz = new AttendQuoteDataBiz();
private AttendQuoteDataValueBiz dataValueBiz = new AttendQuoteDataValueBiz();
2022-05-05 10:35:58 +08:00
2022-04-21 14:15:56 +08:00
private AttendQuoteMapper getAttendQuoteMapper() {
return MapperProxyFactory.getProxy(AttendQuoteMapper.class);
}
2022-03-15 09:55:58 +08:00
2022-05-05 10:35:58 +08:00
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
2022-06-07 15:43:22 +08:00
return ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
}
private SalarySobService getSalarySobService(User user) {
return ServiceUtil.getService(SalarySobServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
2022-05-05 10:35:58 +08:00
}
2022-04-21 14:15:56 +08:00
@Override
public PageInfo<AttendQuoteListDTO> listPage(AttendQuoteQueryParam queryParam) {
2022-06-09 17:45:28 +08:00
List<String> declareMonth = queryParam.getSalaryYearMonth();
2023-06-16 13:33:38 +08:00
// SalaryAcctRecordPO queryRecordParam = new SalaryAcctRecordPO();
2022-06-09 17:45:28 +08:00
if (CollectionUtils.isNotEmpty(declareMonth)) {
queryParam.setSalaryYearMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
2022-06-24 18:05:08 +08:00
queryParam.setSalaryYearMonthDate(declareMonth.stream().map(e -> e + "-01 00:00:00").map(SalaryDateUtil::dateStrToLocalTime).collect(Collectors.toList()));
2023-06-16 13:33:38 +08:00
// LocalDateRange salaryMonth = LocalDateRange.builder().fromDate(SalaryDateUtil.dateStrToLocalDate(declareMonth.get(0)+"-01 00:00:00"))
// .endDate(SalaryDateUtil.dateStrToLocalTime(declareMonth.get(1)+"-01 00:00:00")).build();
// queryRecordParam.setSalaryMonths(salaryMonth);
2022-06-09 17:45:28 +08:00
}
2022-06-07 15:43:22 +08:00
2022-06-09 17:45:28 +08:00
long currentEmployeeId = user.getUID();
2022-06-07 15:43:22 +08:00
Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId);
if (needAuth) {
List<SalarySobPO> salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO);
Set<Long> salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId);
2022-06-09 17:45:28 +08:00
if (CollectionUtils.isEmpty(salarySobIds)) {
return new PageInfo<>(AttendQuoteListDTO.class);
}
2022-06-07 15:43:22 +08:00
queryParam.setSalarySobIds(salarySobIds);
2023-06-16 13:33:38 +08:00
// queryRecordParam.setSalarySobIds(salarySobIds);
2022-06-07 15:43:22 +08:00
}
2023-06-16 11:49:23 +08:00
// 获取已经归档的记录
2023-06-16 13:33:38 +08:00
// List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listSome(queryRecordParam);
// List<String> archivedRecords = salaryAcctRecordPOS.stream().filter(PO -> PO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue())
// .map(PO -> SalaryDateUtil.getFormatYearMonth(PO.getSalaryMonth()) + PO.getSalarySobId())
// .collect(Collectors.toList());
2023-06-16 11:49:23 +08:00
2022-04-21 14:15:56 +08:00
List<AttendQuoteListDTO> list = getAttendQuoteMapper().list(queryParam);
2023-06-16 13:33:38 +08:00
// list.stream().forEach(DTO -> DTO.setCanDelete( !archivedRecords.contains( (SalaryDateUtil.getFormatYearMonth(DTO.getSalaryYearMonth()) + DTO.getSalarySobId().toString()) ) ));
2023-06-16 11:49:23 +08:00
2022-12-12 10:25:55 +08:00
return SalaryPageUtil.buildPage(queryParam.getCurrent(), queryParam.getPageSize(),
list, AttendQuoteListDTO.class);
2022-04-21 14:15:56 +08:00
}
2022-03-15 09:55:58 +08:00
@Override
public String delete(Collection<Long> ids) {
if (CollectionUtils.isEmpty(ids)) {
throw new SalaryRunTimeException("参数错误");
}
List<AttendQuoteListDTO> attendQuotes = biz.list(AttendQuoteQueryParam.builder().ids(ids).build());
if (CollectionUtils.isEmpty(attendQuotes)) {
throw new SalaryRunTimeException("要删除的数据不存在或已删除");
}
List<AttendQuoteListDTO> accountingAttendQuotes = attendQuotes.stream().filter(e -> e.getSalaryAccountingStatus().equals(1)).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(accountingAttendQuotes)) {
throw new SalaryRunTimeException("已经核算完成的数据不能删除");
}
2023-06-16 13:33:38 +08:00
List<SalaryAcctRecordPO> salaryAcctRecordPOS = getSalaryAcctRecordService(user).listSome(SalaryAcctRecordPO.builder().salarySobId(attendQuotes.get(0).getSalarySobId())
.salaryMonth(attendQuotes.get(0).getSalaryYearMonth()).build());
Optional<SalaryAcctRecordPO> haveArchived = salaryAcctRecordPOS.stream().filter(PO -> PO.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue()).findFirst();
if(haveArchived.isPresent()){
throw new SalaryRunTimeException("已经核算完成的数据不能删除");
}
2022-03-15 09:55:58 +08:00
List<Long> unAccountingIds = attendQuotes.stream().filter(e -> e.getSalaryAccountingStatus().equals(0)).map(AttendQuoteListDTO::getId).collect(Collectors.toList());
// 1.删除未核算的考勤引用
biz.deleteByIds(unAccountingIds);
List<AttendQuoteDataPO> attendQuoteDatas = dataBiz.listSome(AttendQuoteDataQueryParam.builder().unAccountingIds(unAccountingIds).build());
// 2.删除考核引用对应的考核数据
dataBiz.deleteByAttendQuoteIds(unAccountingIds);
// 3.删除考核数据对应的考核值
2022-03-15 14:18:04 +08:00
List<Long> attendQuoteDataIds = attendQuoteDatas.stream().map(AttendQuoteDataPO::getId).collect(Collectors.toList());
2022-06-30 14:21:29 +08:00
if (CollectionUtils.isNotEmpty(attendQuoteDataIds)) {
dataValueBiz.deleteByAttendQuoteDataIds(attendQuoteDataIds);
}
2022-03-15 09:55:58 +08:00
2024-02-21 18:19:02 +08:00
// 记录日志
attendQuotes.forEach(e -> {
SalaryLoggerUtil.recordDeleteSingleLog(SalaryElogConfig.attendQuoteLoggerTemplate,
e.getId(),
SalaryI18nUtil.getI18nLabel(0, SalaryDateUtil.getFormatYearMonth(e.getSalaryYearMonth()) + " " + e.getSalarySobName()),
SalaryI18nUtil.getI18nLabel(0, "删除考勤引用"),
SalaryI18nUtil.getI18nLabel(0, "删除考勤引用") +
"[" + SalaryI18nUtil.getI18nLabel(0, "薪资所属月") + "" + e.getSalaryYearMonth() + "" +
SalaryI18nUtil.getI18nLabel(0, "关联账套") + "" + e.getSalarySobName() + "]",
e,
user);
});
2022-03-15 09:55:58 +08:00
return null;
}
2022-05-05 10:35:58 +08:00
@Override
public Boolean checkOperation(YearMonth salaryYearMonth, Long salarySobId) {
// 已经核算过的不可操作
List<SalaryAcctRecordPO> salaryAcctRecords = getSalaryAcctRecordService(user).listBySalarySobIds(Collections.singletonList(salarySobId));
AtomicReference<Boolean> isEnableOperation = new AtomicReference<>(Boolean.TRUE);
salaryAcctRecords.forEach(e -> {
boolean isAccounted = e.getSalaryMonth().equals(SalaryDateUtil.localDateToDate(LocalDate.of(salaryYearMonth.getYear(), salaryYearMonth.getMonth(), 1)))
&& e.getStatus() > SalaryAcctRecordStatusEnum.NOT_ARCHIVED.getValue();
if (isAccounted) {
isEnableOperation.set(Boolean.FALSE);
}
});
return isEnableOperation.get();
}
2024-02-21 18:19:02 +08:00
@Override
public AttendQuotePO getById(Long id) {
if (id == null) {
return null;
}
return getAttendQuoteMapper().getById(id);
}
2022-03-11 11:08:50 +08:00
}