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

73 lines
3.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.taxagent.response.SzyhResponseHead;
import com.engine.salary.entity.taxpayment.dto.TaxWithheldVoucherResultDTO;
import com.engine.salary.entity.taxpayment.param.TaxPaymentQueryParam;
import com.engine.salary.entity.taxpayment.response.WithheldVoucherResponse;
import com.engine.salary.enums.salarysob.DeclareReportTypeEnum;
import com.engine.salary.enums.taxdeclaration.TaxPaymentServiceTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.remote.tax.client.TaxPaymentClient;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.*;
/**
* 完税证明
* <p>Copyright: Copyright (c) 2023</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
@Slf4j
public class TaxPaymentWithheldVoucherServiceImpl extends AbstractTaxPaymentService {
@Override
public Integer getServiceType() {
return TaxPaymentServiceTypeEnum.WITHHELD_VOUCHER.getValue();
}
@Override
public TaxWithheldVoucherResultDTO getWithheldVoucher(TaxPaymentQueryParam param) {
TempWrapper tempWrapper = checkBeforeGetRequestIdResponse(param);
TaxPaymentClient taxPaymentClient = new TaxPaymentClient(param.getTaxAgentId());
Map<String, Object> requestParam = DataCollectionBO.getApiBaseQueryParams(tempWrapper.getTaxReturnPO(), tempWrapper.getTaxAgentPO().getName(), SalaryDateUtil.getFormatYYYYMM(param.getTaxYearMonth()));
WithheldVoucherResponse queryResponse = taxPaymentClient.getWithheldVoucher(requestParam);
// 校验请求结果
String responseCode = Optional.ofNullable(queryResponse).map(WithheldVoucherResponse::getHead).map(SzyhResponseHead::getCode).orElse(null);
WithheldVoucherResponse.Feedback feedback = Optional.ofNullable(queryResponse).map(WithheldVoucherResponse::getBody).map(body -> {
if (DeclareReportTypeEnum.COMPREHENSIVE_INCOME.getValue().equals(param.getReportType())) {
return body.getZhsd();
} else if (DeclareReportTypeEnum.CLASSIFIED_INCOME.getValue().equals(param.getReportType())) {
return body.getFlsd();
} else if (DeclareReportTypeEnum.NONRESIDENT_INCOME.getValue().equals(param.getReportType())) {
return body.getFjmsd();
} else {
return body.getXsgsd();
}
}).orElse(null);
if (!SzyhApiConstant.SUCCESS_CODE.equals(responseCode) || Objects.isNull(feedback)) {
log.info("getWithheldVoucher code error{}", JSON.toJSONString(queryResponse));
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(95828, "税局接口异常,请稍后重试"));
}
Integer status = SalaryEntityUtil.getIntValue(feedback.getJkzt(), -1);
if (status.equals(1)) {
log.info("getWithheldVoucher status error{}", JSON.toJSONString(queryResponse));
throw new SalaryRunTimeException(feedback.getJksbyy());
}
List<TaxWithheldVoucherResultDTO.Voucher> vouchers = new ArrayList<>();
for (int i = 1; i <= feedback.getWszmlb().size(); i++) {
vouchers.add(new TaxWithheldVoucherResultDTO.Voucher(SalaryI18nUtil.getI18nLabel(184013, "完税证明") + i, feedback.getWszmlb().get(i - 1)));
}
return new TaxWithheldVoucherResultDTO().setVouchers(vouchers);
}
}