weaver-hrm-salary/src/com/engine/salary/service/impl/DeductionAmountServiceImpl....

255 lines
12 KiB
Java
Raw Normal View History

package com.engine.salary.service.impl;
2025-03-14 15:56:28 +08:00
import cn.hutool.core.collection.CollUtil;
import com.engine.core.impl.Service;
2025-03-12 13:55:59 +08:00
import com.engine.salary.component.PageInfo;
2025-03-11 11:15:08 +08:00
import com.engine.salary.constant.SalaryDefaultTenantConstant;
2025-03-19 15:26:06 +08:00
import com.engine.salary.constant.SzyhApiConstant;
2025-03-12 13:55:59 +08:00
import com.engine.salary.entity.deductionamount.dto.DeductionAmountDTO;
2025-03-14 15:56:28 +08:00
import com.engine.salary.entity.deductionamount.param.*;
import com.engine.salary.entity.deductionamount.po.DeductionAmountPO;
2025-03-19 15:26:06 +08:00
import com.engine.salary.entity.deductionamount.po.DeductionAmountRecordPO;
import com.engine.salary.entity.employeedeclare.po.EmployeeDeclarePO;
2025-03-12 13:55:59 +08:00
import com.engine.salary.enums.SalaryOnOffEnum;
import com.engine.salary.enums.employeedeclare.CardTypeEnum;
2025-03-19 15:26:06 +08:00
import com.engine.salary.enums.employeedeclare.DeclareStatusEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.mapper.deductionamount.DeductionAmountMapper;
2025-03-19 15:26:06 +08:00
import com.engine.salary.mapper.deductionamount.DeductionAmountRecordMapper;
import com.engine.salary.mapper.employeedeclare.EmployeeDeclareMapper;
import com.engine.salary.remote.tax.client.DeductionAmountClient;
2025-03-12 13:55:59 +08:00
import com.engine.salary.remote.tax.request.deductionAmount.ConfirmPreDeductRequest;
2025-03-19 15:26:06 +08:00
import com.engine.salary.remote.tax.response.deductionAmount.ConfirmFeedbackResponse;
import com.engine.salary.service.DeductionAmountService;
import com.engine.salary.util.SalaryEntityUtil;
2025-03-19 15:26:06 +08:00
import com.engine.salary.util.SalaryI18nUtil;
2025-03-17 18:59:16 +08:00
import com.engine.salary.util.db.IdGenerator;
import com.engine.salary.util.db.MapperProxyFactory;
2025-03-12 13:55:59 +08:00
import com.engine.salary.util.page.SalaryPageUtil;
import com.engine.salary.util.valid.ValidUtil;
import lombok.extern.slf4j.Slf4j;
2025-03-11 11:15:08 +08:00
import org.apache.commons.lang3.math.NumberUtils;
2025-03-11 11:15:08 +08:00
import java.util.Date;
import java.util.List;
2025-03-19 15:26:06 +08:00
import java.util.Map;
import java.util.stream.Collectors;
/**
* 年收入不足6万元的纳税人暂不预扣预缴税款扣除名单
* <p>Copyright: Copyright (c) 2023</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Slf4j
public class DeductionAmountServiceImpl extends Service implements DeductionAmountService {
2025-03-19 15:26:06 +08:00
private DeductionAmountRecordMapper getDeductionAmountRecordMapper() {
return MapperProxyFactory.getProxy(DeductionAmountRecordMapper.class);
}
private DeductionAmountMapper getDeductionAmountMapper() {
return MapperProxyFactory.getProxy(DeductionAmountMapper.class);
}
private EmployeeDeclareMapper getEmployeeDeclareMapper() {
return MapperProxyFactory.getProxy(EmployeeDeclareMapper.class);
}
2025-03-12 13:55:59 +08:00
@Override
2025-03-12 13:55:59 +08:00
public PageInfo<DeductionAmountDTO> list(DeductionAmountListParam param) {
ValidUtil.doValidator(param);
List<DeductionAmountPO> deductionAmountPOS = getDeductionAmountMapper().listSome(DeductionAmountPO.builder().year(param.getYear()).taxAgentId(param.getTaxAgentId()).build());
2025-03-19 15:26:06 +08:00
List<DeductionAmountDTO> list = deductionAmountPOS.stream()
.map(deductionAmountPO -> DeductionAmountDTO.builder()
.id(deductionAmountPO.getId())
.taxAgentId(deductionAmountPO.getEmployeeId())
.year(deductionAmountPO.getYear())
.employeeId(deductionAmountPO.getEmployeeId())
.employeeName(deductionAmountPO.getEmployeeName())
.employeeType(deductionAmountPO.getEmployeeType())
.jobNum(deductionAmountPO.getJobNum())
.nationality(deductionAmountPO.getNationality())
.cardNum(deductionAmountPO.getCardNum())
.cardType(deductionAmountPO.getCardType())
.declareStatus(deductionAmountPO.getDeclareStatus())
.declareErrorMsg(deductionAmountPO.getDeclareErrorMsg())
.deductFlag(deductionAmountPO.getDeductFlag())
.successfullyDeclared(deductionAmountPO.getSuccessfullyDeclared())
.creator(deductionAmountPO.getCreator())
.createTime(deductionAmountPO.getCreateTime())
.updateTime(deductionAmountPO.getUpdateTime())
.build())
.collect(Collectors.toList());
2025-03-12 13:55:59 +08:00
2025-03-14 15:56:28 +08:00
return SalaryPageUtil.buildPage(param.getCurrent(), param.getPageSize(), list, DeductionAmountDTO.class);
}
@Override
public void add(DeductionAmountAddParam param) {
ValidUtil.doValidator(param);
//已存在
List<DeductionAmountPO> deductionAmountPOS = getDeductionAmountMapper().listSome(DeductionAmountPO.builder().taxAgentId(param.getTaxAgentId()).year(param.getYear()).build());
List<Long> oldIds = SalaryEntityUtil.properties(deductionAmountPOS, DeductionAmountPO::getEmployeeId, Collectors.toList());
//本次新增
List<Long> employeeDeclareIds = param.getEmployeeDeclareIds();
List<EmployeeDeclarePO> employeeDeclarePOS = getEmployeeDeclareMapper().listSome(EmployeeDeclarePO.builder().ids(employeeDeclareIds).build());
2025-03-11 11:15:08 +08:00
Date now = new Date();
employeeDeclarePOS.stream()
.filter(employeeDeclarePO -> !oldIds.contains(employeeDeclarePO.getEmployeeId()))
2025-03-12 13:55:59 +08:00
.map(employeeDeclarePO -> DeductionAmountPO.builder()
2025-03-17 18:59:16 +08:00
.id(IdGenerator.generate())
.taxAgentId(employeeDeclarePO.getTaxAgentId())
2025-03-12 13:55:59 +08:00
.year(param.getYear())
.employeeId(employeeDeclarePO.getEmployeeId())
.employeeName(employeeDeclarePO.getEmployeeName())
.employeeType(employeeDeclarePO.getEmployeeType())
.jobNum(employeeDeclarePO.getJobNum())
.cardNum(employeeDeclarePO.getCardNum())
.cardType(employeeDeclarePO.getCardType())
.nationality(employeeDeclarePO.getNationality())
2025-03-19 15:26:06 +08:00
.declareStatus(DeclareStatusEnum.NOT_DECLARE.getValue())
.deductFlag(SalaryOnOffEnum.OFF.getValue())
.successfullyDeclared(SalaryOnOffEnum.OFF.getValue())
2025-03-12 13:55:59 +08:00
.creator((long) user.getUID())
.createTime(now)
.updateTime(now)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.deleteType(NumberUtils.INTEGER_ZERO)
.build())
.forEach(deductionAmountPO -> getDeductionAmountMapper().insertIgnoreNull(deductionAmountPO));
}
2025-03-19 16:25:42 +08:00
@Override
public void edit(DeductionAmountEditParam param) {
ValidUtil.doValidator(param);
DeductionAmountPO po = getDeductionAmountMapper().getById(param.getId());
if (po == null) {
throw new SalaryRunTimeException("扣除名单不存在");
}
po.setDeductFlag(param.getDeductFlag());
getDeductionAmountMapper().updateIgnoreNull(po);
}
2025-03-14 15:56:28 +08:00
@Override
public void delete(DeductionAmountDeleteParam param) {
if (CollUtil.isEmpty(param.getIds())) {
return;
}
param.getIds().forEach(id -> {
getDeductionAmountMapper().delete(DeductionAmountPO.builder().id(id).build());
});
}
2025-03-12 13:55:59 +08:00
@Override
public Object query(DeductionAmountOnlineQueryParam param) {
Long taxAgentId = param.getTaxAgentId();
DeductionAmountClient deductionAmountClient = new DeductionAmountClient(taxAgentId);
return deductionAmountClient.query(param.getYear());
}
@Override
2025-03-19 15:26:06 +08:00
public String confirm(DeductionAmountConfirmParam param) {
2025-03-12 13:55:59 +08:00
ValidUtil.doValidator(param);
Long taxAgentId = param.getTaxAgentId();
String year = param.getYear();
List<DeductionAmountPO> deductionAmountPOS = getDeductionAmountMapper().listSome(DeductionAmountPO.builder().taxAgentId(taxAgentId).year(year).build());
List<ConfirmPreDeductRequest.kczg> kczglb = deductionAmountPOS.stream()
.map(deductionAmountPO -> {
ConfirmPreDeductRequest.kczg kczg = new ConfirmPreDeductRequest.kczg();
kczg.setXm(deductionAmountPO.getEmployeeName());
kczg.setZzhm(deductionAmountPO.getCardNum());
kczg.setZzlx(CardTypeEnum.getByValue(deductionAmountPO.getCardType()).getDefaultLabel());
kczg.setGj(deductionAmountPO.getNationality());
kczg.setKcbs(SalaryOnOffEnum.parseByValue(deductionAmountPO.getDeductFlag()).getDefaultLabel());
return kczg;
}).collect(Collectors.toList());
DeductionAmountClient deductionAmountClient = new DeductionAmountClient(taxAgentId);
2025-03-19 15:26:06 +08:00
String requestId = deductionAmountClient.confirm(year, kczglb);
//更新状态
deductionAmountPOS.forEach(deductionAmountPO -> {
deductionAmountPO.setDeclareStatus(DeclareStatusEnum.DECLARING.getValue());
getDeductionAmountMapper().updateIgnoreNull(deductionAmountPO);
});
//插入记录
getDeductionAmountRecordMapper().deleteByTaxAgentIdAndYear(taxAgentId, year);
DeductionAmountRecordPO recordPO = DeductionAmountRecordPO.builder()
.id(IdGenerator.generate())
.taxAgentId(taxAgentId)
.year(year)
.requestId(requestId)
.creator((long) user.getUID())
.createTime(new Date())
.updateTime(new Date())
.deleteType(NumberUtils.INTEGER_ZERO)
.tenantKey(SalaryDefaultTenantConstant.DEFAULT_TENANT_KEY)
.build();
getDeductionAmountRecordMapper().insertIgnoreNull(recordPO);
return requestId;
2025-03-17 18:59:16 +08:00
}
@Override
2025-03-19 15:26:06 +08:00
public String feedback(DeductionAmountFeedBackParam param) {
Long taxAgentId = param.getTaxAgentId();
String year = param.getYear();
DeductionAmountRecordPO recordPO = getDeductionAmountRecordMapper().getByTaxAgentIdAndYear(taxAgentId, year);
if (recordPO == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175337, "请先点击报送扣除名单,再点击反馈"));
}
String requestId = recordPO.getRequestId();
DeductionAmountClient deductionAmountClient = new DeductionAmountClient(taxAgentId);
ConfirmFeedbackResponse feedback = deductionAmountClient.feedback(requestId);
if (feedback == null || feedback.getHead() == null) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(95828, "服务异常,请稍后重试"));
}
// 如果税友返回错误信息
String code = feedback.getHead().getCode();
if (SzyhApiConstant.HANDLING_CODE.equals(code) || SzyhApiConstant.TASK_HANDLING_CODE.equals(code)) {
//进行中的任务,重试
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175337, "任务还在处理中,请稍后点击反馈"));
}
if (!SzyhApiConstant.SUCCESS_CODE.equals(code)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(95828, feedback.getHead().getMsg()));
}
List<DeductionAmountPO> deductionAmountPOS = getDeductionAmountMapper().listSome(DeductionAmountPO.builder().taxAgentId(taxAgentId).year(year).build());
List<ConfirmFeedbackResponse.Body.kcqrsb> kcqrsblb = feedback.getBody().getKcqrsblb();
Map<String, String> failMap = SalaryEntityUtil.convert2Map(kcqrsblb, ConfirmFeedbackResponse.Body.kcqrsb::getZzhm, ConfirmFeedbackResponse.Body.kcqrsb::getSbyy);
deductionAmountPOS.forEach(deductionAmountPO -> {
String cardNum = deductionAmountPO.getCardNum();
if (failMap.containsKey(cardNum)) {
deductionAmountPO.setDeclareStatus(DeclareStatusEnum.DECLARE_FAIL.getValue());
deductionAmountPO.setDeclareErrorMsg(failMap.get(cardNum));
} else {
deductionAmountPO.setDeclareStatus(DeclareStatusEnum.DECLARE_SUCCESS.getValue());
deductionAmountPO.setSuccessfullyDeclared(SalaryOnOffEnum.ON.getValue());
}
getDeductionAmountMapper().updateIgnoreNull(deductionAmountPO);
});
return String.format("成功%s条失败%s条", feedback.getBody().getCgrs(), feedback.getBody().getSbrs());
2025-03-17 18:59:16 +08:00
}
}