120 lines
5.7 KiB
Java
120 lines
5.7 KiB
Java
package com.engine.salary.service.impl;
|
||
|
||
import com.engine.common.util.ServiceUtil;
|
||
import com.engine.core.impl.Service;
|
||
import com.engine.salary.biz.AttendQuoteBiz;
|
||
import com.engine.salary.biz.AttendQuoteDataBiz;
|
||
import com.engine.salary.biz.AttendQuoteDataValueBiz;
|
||
import com.engine.salary.cmd.datacollection.AttendQuoteListCmd;
|
||
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;
|
||
import com.engine.salary.entity.salaryacct.po.SalaryAcctRecordPO;
|
||
import com.engine.salary.enums.salaryaccounting.SalaryAcctRecordStatusEnum;
|
||
import com.engine.salary.exception.SalaryRunTimeException;
|
||
import com.engine.salary.mapper.datacollection.AttendQuoteMapper;
|
||
import com.engine.salary.service.AttendQuoteService;
|
||
import com.engine.salary.service.SalaryAcctRecordService;
|
||
import com.engine.salary.util.SalaryDateUtil;
|
||
import com.engine.salary.util.db.MapperProxyFactory;
|
||
import com.engine.salary.util.page.PageInfo;
|
||
import com.engine.salary.util.page.SalaryPageUtil;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import weaver.hrm.User;
|
||
|
||
import java.time.LocalDate;
|
||
import java.time.YearMonth;
|
||
import java.util.Collection;
|
||
import java.util.Collections;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.concurrent.atomic.AtomicReference;
|
||
import java.util.stream.Collectors;
|
||
|
||
public class AttendQuoteServiceImpl extends Service implements AttendQuoteService {
|
||
|
||
private AttendQuoteBiz biz = new AttendQuoteBiz();
|
||
private AttendQuoteDataBiz dataBiz = new AttendQuoteDataBiz();
|
||
private AttendQuoteDataValueBiz dataValueBiz = new AttendQuoteDataValueBiz();
|
||
|
||
private AttendQuoteMapper getAttendQuoteMapper() {
|
||
return MapperProxyFactory.getProxy(AttendQuoteMapper.class);
|
||
}
|
||
|
||
private SalaryAcctRecordService getSalaryAcctRecordService(User user) {
|
||
return (SalaryAcctRecordService) ServiceUtil.getService(SalaryAcctRecordServiceImpl.class, user);
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> list(Map<String, Object> params) {
|
||
return commandExecutor.execute(new AttendQuoteListCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public PageInfo<AttendQuoteListDTO> listPage(AttendQuoteQueryParam queryParam) {
|
||
SalaryPageUtil.start(queryParam.getCurrent(), queryParam.getPageSize());
|
||
List<AttendQuoteListDTO> list = getAttendQuoteMapper().list(queryParam);
|
||
return new PageInfo<>(list, AttendQuoteListDTO.class);
|
||
}
|
||
|
||
@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.删除考核数据对应的考核值
|
||
List<Long> attendQuoteDataIds = attendQuoteDatas.stream().map(AttendQuoteDataPO::getId).collect(Collectors.toList());
|
||
dataValueBiz.deleteByAttendQuoteDataIds(attendQuoteDataIds);
|
||
|
||
//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;
|
||
}
|
||
|
||
|
||
@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();
|
||
}
|
||
|
||
|
||
}
|