package com.engine.salary.service.impl; import com.alibaba.fastjson.JSON; import com.engine.salary.constant.SzyhApiConstant; import com.engine.salary.entity.datacollection.bo.DataCollectionBO; import com.engine.salary.entity.datacollection.response.QuerySpecialAmountResponse; import com.engine.salary.entity.taxagent.po.TaxAgentTaxReturnPO; import com.engine.salary.entity.taxagent.response.SzyhResponseHead; import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationApiConfigPO; import com.engine.salary.entity.taxdeclaration.po.TaxDeclareRecordPO; import com.engine.salary.entity.taxpayment.dto.TaxAgreementFeedbackResultDTO; import com.engine.salary.entity.taxpayment.dto.TaxAmountFormDTO; import com.engine.salary.entity.taxpayment.dto.TaxFeedbackResultDTO; import com.engine.salary.entity.taxpayment.param.TaxPaymentQueryParam; import com.engine.salary.entity.taxpayment.po.TaxPaymentRequestPO; import com.engine.salary.entity.taxpayment.response.BaseResponse; import com.engine.salary.entity.taxpayment.response.WithholdingFeedbackResponse; import com.engine.salary.enums.SalaryOnOffEnum; import com.engine.salary.enums.taxdeclaration.TaxPaymentServiceTypeEnum; import com.engine.salary.enums.taxdeclaration.TaxPaymentStatusEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.util.*; import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; import java.util.Map; import java.util.Optional; /** * 三方缴款 *
Copyright: Copyright (c) 2023
*Company: 泛微软件
* * @author qiantao * @version 1.0 **/ @Slf4j public class TaxPaymentWithholdingServiceImpl extends AbstractTaxPaymentService { @Override public TaxFeedbackResultDTO getFeedback(TaxPaymentQueryParam param) { WithholdingFeedbackResponse feedbackResponse = (WithholdingFeedbackResponse) checkBeforeGetFeedbackResponse(param); // 校验请求结果 String responseCode = Optional.ofNullable(feedbackResponse).map(WithholdingFeedbackResponse::getHead).map(SzyhResponseHead::getCode).orElse(null); String msg = Optional.ofNullable(feedbackResponse).map(WithholdingFeedbackResponse::getHead).map(SzyhResponseHead::getMsg).orElse(null); if (SzyhApiConstant.HANDLING_CODE.equals(responseCode)) { // 如果接口仍在处理中,则继续轮询 throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175337, "缴款还在处理中,请稍后点击缴款反馈")); } // 获取返回的人员信息列表 if (!SzyhApiConstant.SUCCESS_CODE.equals(responseCode)) { log.info("getAgreementQueryFeedbackResponse not success: {}", JSON.toJSONString(feedbackResponse)); throw new SalaryRunTimeException(msg); } WithholdingFeedbackResponse.Feedback feedback = Optional.of(feedbackResponse) .map(WithholdingFeedbackResponse::getBody) .map(WithholdingFeedbackResponse.Body::getZhsdjk) .orElse(null); if (feedback == null) { log.info("getAgreementQueryFeedbackResponse empty data error: {}", JSON.toJSONString(feedbackResponse)); throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175338, "税局接口错误,未返回有效数据")); } TaxAmountFormDTO taxAmountFormDTO = queryTaxAmount(param); // 判断缴款状态是否成功 Integer paymentStatus = SalaryEntityUtil.getIntValue(feedback.getJkzt(), -1); TaxPaymentStatusEnum paymentStatusEnum = SalaryEnumUtil.enumMatchByValue(paymentStatus, TaxPaymentStatusEnum.class); if (paymentStatusEnum != TaxPaymentStatusEnum.SUCCESS) { throw new SalaryRunTimeException(String.format("缴款失败,失败原因:%s,申报状态:%s", feedback.getJksbyy(), feedback.getSbzt())); } // 累计实缴金额 BigDecimal totalPaid = feedback.getKkfhlb().stream().map(e -> new BigDecimal(e.getSjse())).reduce(BigDecimal.ZERO, BigDecimal::add); // 更新个税申报记录状态为已缴款 TaxDeclareRecordPO taxDeclareRecord = updateTaxDeclareRecord(param, totalPaid); // 更新缴款请求为已反馈 updateTaxPaymentRequest(param); BigDecimal otherAmount = totalPaid.subtract(SalaryEntityUtil.empty2Zero(taxDeclareRecord.getTaxPurePaidAmount())); return new TaxAgreementFeedbackResultDTO() .setPayAmount(SalaryEntityUtil.thousandthConvert(totalPaid.toString())) .setOtherAmount(SalaryEntityUtil.thousandthConvert(otherAmount.toString())) .setPersonNum(taxAmountFormDTO.getPersonNum()); } @Override public Integer getServiceType() { return TaxPaymentServiceTypeEnum.WITHHOLDING_PAY.getValue(); } protected