143 lines
5.5 KiB
Java
143 lines
5.5 KiB
Java
package com.engine.salary.service.impl;
|
||
|
||
import com.engine.core.impl.Service;
|
||
import com.engine.salary.biz.TaxAgentBiz;
|
||
import com.engine.salary.cmd.TaxAgent.*;
|
||
import com.engine.salary.entity.datacollection.AddUpDeduction;
|
||
import com.engine.salary.entity.datacollection.AddUpSituation;
|
||
import com.engine.salary.entity.datacollection.po.OtherDeductionPO;
|
||
import com.engine.salary.entity.salaryarchive.po.SalaryArchiveTaxAgentPO;
|
||
import com.engine.salary.entity.taxrate.TaxAgent;
|
||
import com.engine.salary.entity.taxrate.param.TaxAgentQueryParam;
|
||
import com.engine.salary.exception.SalaryRunTimeException;
|
||
import com.engine.salary.mapper.TaxAgentMapper;
|
||
import com.engine.salary.mapper.archive.SalaryArchiveTaxAgentMapper;
|
||
import com.engine.salary.mapper.datacollection.AddUpDeductionMapper;
|
||
import com.engine.salary.mapper.datacollection.AddUpSituationMapper;
|
||
import com.engine.salary.mapper.datacollection.OtherDeductionMapper;
|
||
import com.engine.salary.service.TaxAgentService;
|
||
import com.engine.salary.util.SalaryI18nUtil;
|
||
import com.engine.salary.util.db.MapperProxyFactory;
|
||
import org.apache.commons.collections4.CollectionUtils;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
|
||
import java.util.Collection;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
public class TaxAgentServiceImpl extends Service implements TaxAgentService {
|
||
|
||
private SalaryArchiveTaxAgentMapper getSalaryArchiveTaxAgentMapper() {
|
||
return MapperProxyFactory.getProxy(SalaryArchiveTaxAgentMapper.class);
|
||
}
|
||
|
||
private AddUpDeductionMapper getAddUpDeductionMapper() {
|
||
return MapperProxyFactory.getProxy(AddUpDeductionMapper.class);
|
||
}
|
||
|
||
private OtherDeductionMapper getOtherDeductionMapper() {
|
||
return MapperProxyFactory.getProxy(OtherDeductionMapper.class);
|
||
}
|
||
|
||
private AddUpSituationMapper getAddUpSituationMapper() {
|
||
return MapperProxyFactory.getProxy(AddUpSituationMapper.class);
|
||
}
|
||
|
||
private TaxAgentMapper getTaxAgentMapper() {
|
||
return MapperProxyFactory.getProxy(TaxAgentMapper.class);
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> list(Map<String, Object> params) {
|
||
return commandExecutor.execute(new TaxAgentListCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> getForm(Map<String, Object> params) {
|
||
return commandExecutor.execute(new TaxAgentGetFromCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> save(Map<String, Object> params) {
|
||
return commandExecutor.execute(new TaxAgentSaveCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public Map<String, Object> update(Map<String, Object> params) {
|
||
return commandExecutor.execute(new TaxAgentUpdateCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public String delete(Collection<Long> ids) {
|
||
|
||
List<TaxAgent> taxAgents = getTaxAgentMapper().listBySome(TaxAgentQueryParam.builder().ids(ids).build());
|
||
if (CollectionUtils.isEmpty(taxAgents)) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(85382, "要删除的个税扣缴义务人在不存在或已删除"));
|
||
}
|
||
|
||
// 正在使用的记录不允许删除
|
||
boolean checkUsed = checkUsed(ids);
|
||
if (checkUsed) {
|
||
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100570, "正在使用的记录不允许删除"));
|
||
}
|
||
|
||
getTaxAgentMapper().deleteByIds(ids);
|
||
// // 记录日志
|
||
// taxAgents.forEach(e -> SalaryLoggerUtil.recordDeleteSingleLog(taxAgentLoggerTemplate,
|
||
// e.getId(),
|
||
// e.getName(),
|
||
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100546, "删除个税扣缴义务人"),
|
||
// SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100546, "删除个税扣缴义务人") + ":" + e.getName(),
|
||
// e));
|
||
|
||
return StringUtils.EMPTY;
|
||
}
|
||
|
||
/**
|
||
* 检查正在被使用的记录
|
||
*
|
||
* @param ids
|
||
* @return
|
||
*/
|
||
private boolean checkUsed(Collection<Long> ids) {
|
||
// 被薪资档案引用
|
||
List<SalaryArchiveTaxAgentPO> salaryArchiveTaxAgentList = getSalaryArchiveTaxAgentMapper().listSome(SalaryArchiveTaxAgentPO.builder().taxAgentIds(ids).build());
|
||
if (CollectionUtils.isNotEmpty(salaryArchiveTaxAgentList)) {
|
||
return Boolean.TRUE;
|
||
}
|
||
// 被累计专项附加扣除引用
|
||
List<AddUpDeduction> addUpDeductionList = getAddUpDeductionMapper().listSome(AddUpDeduction.builder().taxAgentIds(ids).build());
|
||
if (CollectionUtils.isNotEmpty(addUpDeductionList)) {
|
||
return Boolean.TRUE;
|
||
}
|
||
// 被其他免税扣除引用
|
||
List<OtherDeductionPO> otherDeductionList = getOtherDeductionMapper().listSome(OtherDeductionPO.builder().taxAgentIds(ids).build());
|
||
if (CollectionUtils.isNotEmpty(otherDeductionList)) {
|
||
return Boolean.TRUE;
|
||
}
|
||
// 被往期累计情况引用
|
||
List<AddUpSituation> addUpSituationList = getAddUpSituationMapper().listSome(AddUpSituation.builder().taxAgentIds(ids).build());
|
||
if (CollectionUtils.isNotEmpty(addUpSituationList)) {
|
||
return Boolean.TRUE;
|
||
}
|
||
|
||
return Boolean.FALSE;
|
||
}
|
||
|
||
|
||
@Override
|
||
public Map<String, Object> selectList(Map<String, Object> params) {
|
||
return commandExecutor.execute(new TaxAgentSelectListCmd(params, user));
|
||
}
|
||
|
||
@Override
|
||
public Collection<TaxAgent> findAll() {
|
||
return new TaxAgentBiz().listAll();
|
||
}
|
||
|
||
@Override
|
||
public TaxAgent getById(Long id) {
|
||
return getTaxAgentMapper().getById(id);
|
||
}
|
||
}
|