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

67 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.po.TaxAgentTaxReturnPO;
import com.engine.salary.entity.taxagent.response.SzyhResponseHead;
import com.engine.salary.entity.taxdeclaration.po.TaxDeclarationApiConfigPO;
import com.engine.salary.entity.taxpayment.dto.TaxWithheldVoucherResultDTO;
import com.engine.salary.entity.taxpayment.param.TaxPaymentQueryParam;
import com.engine.salary.entity.taxpayment.response.BaseResponse;
import com.engine.salary.entity.taxpayment.response.WithheldVoucherResponse;
import com.engine.salary.enums.taxdeclaration.TaxPaymentServiceTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.util.SalaryDateUtil;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 完税证明
*
* @author chengliming
* @date 2022-09-02 9:27 AM
**/
@Slf4j
public class TaxPaymentWithheldVoucherServiceImpl extends AbstractTaxPaymentService {
@Override
public Integer getServiceType() {
return TaxPaymentServiceTypeEnum.WITHHELD_VOUCHER.getValue();
}
protected <T extends BaseResponse> T getRequestIdResponse(TaxAgentTaxReturnPO returnPO, String taxAgentName, TaxPaymentQueryParam param, TaxDeclarationApiConfigPO apiConfig, Class<T> clazz) {
String url = apiConfig.getHost() + SzyhApiConstant.GET_WITHHELD_VOUCHER;
Map<String, Object> requestParam = DataCollectionBO.getApiBaseQueryParams(returnPO, taxAgentName, SalaryDateUtil.getFormatYearMonth(param.getTaxYearMonth()));
return postRequest(apiConfig, url, requestParam, clazz);
}
@Transactional(rollbackFor = Exception.class)
@Override
public TaxWithheldVoucherResultDTO getWithheldVoucher(TaxPaymentQueryParam param) {
TempWrapper tempWrapper = checkBeforeGetRequestIdResponse(param);
WithheldVoucherResponse queryResponse = getRequestIdResponse(tempWrapper.getTaxReturnPO(), tempWrapper.getTaxAgentPO().getName(),
param, tempWrapper.getApiConfigPO(), WithheldVoucherResponse.class);
// 校验请求结果
String responseCode = Optional.ofNullable(queryResponse).map(WithheldVoucherResponse::getHead).map(SzyhResponseHead::getCode).orElse(null);
WithheldVoucherResponse.Feedback feedback = Optional.ofNullable(queryResponse).map(WithheldVoucherResponse::getBody).map(WithheldVoucherResponse.Body::getZhsd).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);
}
}