2023-08-17 14:55:32 +08:00
|
|
|
|
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;
|
2024-04-07 11:29:09 +08:00
|
|
|
|
import com.engine.salary.enums.salarysob.DeclareReportTypeEnum;
|
2023-08-17 14:55:32 +08:00
|
|
|
|
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 java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 完税证明
|
2023-08-24 11:36:17 +08:00
|
|
|
|
* <p>Copyright: Copyright (c) 2023</p>
|
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
2023-08-17 14:55:32 +08:00
|
|
|
|
*
|
2023-08-24 11:36:17 +08:00
|
|
|
|
* @author qiantao
|
|
|
|
|
|
* @version 1.0
|
2023-08-17 14:55:32 +08:00
|
|
|
|
**/
|
|
|
|
|
|
@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;
|
2023-08-23 15:46:18 +08:00
|
|
|
|
Map<String, Object> requestParam = DataCollectionBO.getApiBaseQueryParams(returnPO, taxAgentName, SalaryDateUtil.getFormatYYYYMM(param.getTaxYearMonth()));
|
2023-08-17 14:55:32 +08:00
|
|
|
|
return postRequest(apiConfig, url, requestParam, clazz);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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);
|
2024-04-07 11:29:09 +08:00
|
|
|
|
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);
|
2023-08-17 14:55:32 +08:00
|
|
|
|
if (!SzyhApiConstant.SUCCESS_CODE.equals(responseCode) || Objects.isNull(feedback)) {
|
|
|
|
|
|
log.info("getWithheldVoucher code error:{}", JSON.toJSONString(queryResponse));
|
2024-04-07 11:29:09 +08:00
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(95828, "税局接口异常,请稍后重试"));
|
2023-08-17 14:55:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
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++) {
|
2024-04-07 11:29:09 +08:00
|
|
|
|
vouchers.add(new TaxWithheldVoucherResultDTO.Voucher(SalaryI18nUtil.getI18nLabel(184013, "完税证明") + i, feedback.getWszmlb().get(i - 1)));
|
2023-08-17 14:55:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
return new TaxWithheldVoucherResultDTO().setVouchers(vouchers);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|