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

145 lines
6.8 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;
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;
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;
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;
2022-06-08 16:36:50 +08:00
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
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();
if (CollectionUtils.isNotEmpty(declareMonth)) {
queryParam.setSalaryYearMonth(declareMonth.stream().map(e -> e + "-01 00:00:00").collect(Collectors.toList()));
}
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);
}
2022-05-25 13:10:03 +08:00
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
2022-04-21 14:15:56 +08:00
List<AttendQuoteListDTO> list = getAttendQuoteMapper().list(queryParam);
2022-05-05 10:35:58 +08:00
return new PageInfo<>(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("已经核算完成的数据不能删除");
}
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());
dataValueBiz.deleteByAttendQuoteDataIds(attendQuoteDataIds);
2022-03-15 09:55:58 +08:00
//todo 日志
// attendQuotes.forEach(e -> {
// SalaryLoggerUtil.recordDeleteSingleLog(attendQuoteLoggerTemplate,
// e.getId(),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 85367, "考勤引用"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100412, "删除考勤引用"),
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100412, "删除考勤引用") +
// "[" + SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 87614, "薪资所属月") + "" + e.getSalaryYearMonth() + "" +
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 87615, "关联账套") + "" + e.getSalarySobName() + "]",
// e);
// });
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();
}
2022-03-11 11:08:50 +08:00
}