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.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;
|
2024-04-12 17:46:53 +08:00
|
|
|
|
import com.engine.salary.entity.taxdeclaration.po.TaxDeclareStatusPO;
|
2023-08-17 14:55:32 +08:00
|
|
|
|
import com.engine.salary.entity.taxpayment.bo.TaxPaymentBO;
|
|
|
|
|
|
import com.engine.salary.entity.taxpayment.dto.TaxFeedbackResultDTO;
|
|
|
|
|
|
import com.engine.salary.entity.taxpayment.dto.TaxWithholdingVoucherFeedbackDTO;
|
|
|
|
|
|
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.SyncWithholdingFeedbackResponse;
|
|
|
|
|
|
import com.engine.salary.entity.taxpayment.response.WithholdingVoucherFeedbackResponse;
|
|
|
|
|
|
import com.engine.salary.enums.SalaryOnOffEnum;
|
|
|
|
|
|
import com.engine.salary.enums.taxdeclaration.TaxPaymentServiceTypeEnum;
|
|
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
2024-07-02 15:39:31 +08:00
|
|
|
|
import com.engine.salary.remote.tax.client.TaxPaymentClient;
|
2024-07-04 10:32:09 +08:00
|
|
|
|
import com.engine.salary.util.JsonUtil;
|
|
|
|
|
|
import com.engine.salary.util.SalaryAssert;
|
|
|
|
|
|
import com.engine.salary.util.SalaryDateUtil;
|
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
2023-08-17 14:55:32 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 缴款凭证
|
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 TaxPaymentWithholdingVoucherServiceImpl extends AbstractTaxPaymentService {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public TaxFeedbackResultDTO getFeedback(TaxPaymentQueryParam param) {
|
|
|
|
|
|
WithholdingVoucherFeedbackResponse feedbackResponse = (WithholdingVoucherFeedbackResponse) checkBeforeGetFeedbackResponse(param);
|
|
|
|
|
|
// 校验请求结果
|
|
|
|
|
|
String responseCode = Optional.ofNullable(feedbackResponse).map(WithholdingVoucherFeedbackResponse::getHead).map(SzyhResponseHead::getCode).orElse(null);
|
|
|
|
|
|
String msg = Optional.ofNullable(feedbackResponse).map(WithholdingVoucherFeedbackResponse::getHead).map(SzyhResponseHead::getMsg).orElse(null);
|
2024-08-01 11:43:26 +08:00
|
|
|
|
if (SzyhApiConstant.HANDLING_CODE.equals(responseCode)||SzyhApiConstant.TASK_HANDLING_CODE.equals(responseCode)) {
|
2023-08-17 14:55:32 +08:00
|
|
|
|
// 如果接口仍在处理中,则继续轮询
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175337, "缴款还在处理中,请稍后点击缴款反馈"));
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!SzyhApiConstant.SUCCESS_CODE.equals(responseCode)) {
|
|
|
|
|
|
log.info("getAgreementQueryFeedbackResponse not success: {}", JSON.toJSONString(feedbackResponse));
|
|
|
|
|
|
throw new SalaryRunTimeException(msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (feedbackResponse.getBody() == null) {
|
|
|
|
|
|
log.info("getAgreementQueryFeedbackResponse body null: {}", JSON.toJSONString(feedbackResponse));
|
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(175339, "税局接口异常,请稍后重试"));
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取返回的信息列表
|
|
|
|
|
|
WithholdingVoucherFeedbackResponse.Feedback synthesize = feedbackResponse.getBody().getZhsd();
|
|
|
|
|
|
if (synthesize.getFkzt().equals("1")) {
|
|
|
|
|
|
throw new SalaryRunTimeException(synthesize.getFkms());
|
|
|
|
|
|
}
|
|
|
|
|
|
if (SalaryOnOffEnum.ON.getValue().equals(param.getCheckFeedback())) {
|
|
|
|
|
|
return new TaxFeedbackResultDTO().setFinish(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 更新缴款请求为已反馈
|
|
|
|
|
|
updateTaxPaymentRequest(param);
|
|
|
|
|
|
// 组装数据
|
|
|
|
|
|
TaxWithholdingVoucherFeedbackDTO feedbackDTO = TaxPaymentBO.buildTaxWithholdingVoucherFeedbackDTO(synthesize);
|
|
|
|
|
|
List<TaxWithholdingVoucherFeedbackDTO.Detail> details = synthesize.getJkpzmxlb().stream().map(e -> {
|
|
|
|
|
|
TaxWithholdingVoucherFeedbackDTO.Detail detail = new TaxWithholdingVoucherFeedbackDTO.Detail();
|
|
|
|
|
|
detail.setPaymentCode(e.getZsxmmc());
|
|
|
|
|
|
detail.setPaymentItem(e.getZspmmc());
|
|
|
|
|
|
detail.setPayAmount(e.getYjse());
|
|
|
|
|
|
return detail;
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
feedbackDTO.setDetails(details);
|
|
|
|
|
|
return feedbackDTO;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Integer getServiceType() {
|
|
|
|
|
|
return TaxPaymentServiceTypeEnum.WITHHOLDING_VOUCHER.getValue();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected <T extends BaseResponse> T getRequestIdResponse(TaxAgentTaxReturnPO returnPO,
|
|
|
|
|
|
String taxAgentName,
|
|
|
|
|
|
TaxPaymentQueryParam param,
|
|
|
|
|
|
TaxDeclarationApiConfigPO apiConfig,
|
|
|
|
|
|
Class<T> clazz) {
|
|
|
|
|
|
boolean syncStatus = clazz == SyncWithholdingFeedbackResponse.class;
|
|
|
|
|
|
String api = syncStatus ? SzyhApiConstant.GET_SYNC_WITHHOLDING_FEEDBACK : SzyhApiConstant.WITHHOLDING_VOUCHER;
|
|
|
|
|
|
String url = apiConfig.getHost() + api;
|
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
|
|
|
|
if (syncStatus) {
|
2024-04-10 09:18:05 +08:00
|
|
|
|
requestParam.put("bblx", param.getReportType());
|
2023-08-17 14:55:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
return postRequest(apiConfig, url, requestParam, clazz);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void cancelWithholdingVoucher(TaxDeclarationApiConfigPO apiConfig, TaxDeclareRecordPO taxDeclareRecord, Map<String, Object> requestParam) {
|
|
|
|
|
|
TaxPaymentRequestPO paymentRequestPO = getTaxPaymentRequestMapper().getOne(TaxPaymentRequestPO
|
|
|
|
|
|
.builder()
|
|
|
|
|
|
.requestType(TaxPaymentServiceTypeEnum.WITHHOLDING_VOUCHER.getValue())
|
|
|
|
|
|
.taxAgentId(taxDeclareRecord.getTaxAgentId())
|
|
|
|
|
|
.taxYearMonth(taxDeclareRecord.getTaxCycle())
|
|
|
|
|
|
.build());
|
2023-12-12 17:18:56 +08:00
|
|
|
|
// if (paymentRequestPO != null) {
|
2024-04-12 17:46:53 +08:00
|
|
|
|
|
|
|
|
|
|
List<TaxDeclareStatusPO> statuses = getTaxDeclareStatusService(user).getTaxDeclareStatusByTaxDeclareRecordId(taxDeclareRecord.getId());
|
2024-07-02 15:39:31 +08:00
|
|
|
|
TaxPaymentClient taxPaymentClient = new TaxPaymentClient(taxDeclareRecord.getTaxAgentId());
|
2024-04-12 17:46:53 +08:00
|
|
|
|
statuses.forEach(status -> {
|
|
|
|
|
|
requestParam.put("sblx", status.getReportType());
|
2024-07-02 15:39:31 +08:00
|
|
|
|
QuerySpecialAmountResponse cancelResponse = taxPaymentClient.cancelWithholdingVoucher(requestParam);
|
2023-08-17 14:55:32 +08:00
|
|
|
|
SzyhResponseHead head = Optional.ofNullable(cancelResponse).map(QuerySpecialAmountResponse::getHead)
|
|
|
|
|
|
.orElse(new SzyhResponseHead("0", SalaryI18nUtil.getI18nLabel(183785, "银联缴款凭证作废失败,请稍后重试")));
|
|
|
|
|
|
SalaryAssert.isTrue(SzyhApiConstant.SUCCESS_CODE.equals(head.getCode()), head.getMsg());
|
|
|
|
|
|
getTaxPaymentRequestMapper().updateFeedbackByRequestTypeTaxAgentIdTaxYearMonth(TaxPaymentRequestPO
|
|
|
|
|
|
.builder()
|
|
|
|
|
|
.feedback(SalaryOnOffEnum.ON.getValue())
|
|
|
|
|
|
.requestType(TaxPaymentServiceTypeEnum.WITHHOLDING_VOUCHER.getValue())
|
|
|
|
|
|
.taxAgentId(taxDeclareRecord.getTaxAgentId())
|
|
|
|
|
|
.taxYearMonth(taxDeclareRecord.getTaxCycle())
|
|
|
|
|
|
.build());
|
2024-04-12 17:46:53 +08:00
|
|
|
|
});
|
2023-12-12 17:18:56 +08:00
|
|
|
|
// }
|
2023-08-17 14:55:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-04 10:32:09 +08:00
|
|
|
|
// @Override
|
|
|
|
|
|
// public void syncWithholdingFeedback(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()));
|
|
|
|
|
|
// requestParam.put("bblx", param.getReportType());
|
|
|
|
|
|
// SyncWithholdingFeedbackResponse response = taxPaymentClient.getSyncWithholding(requestParam);
|
|
|
|
|
|
//
|
|
|
|
|
|
// // 校验请求结果
|
|
|
|
|
|
// String responseCode = Optional.ofNullable(response)
|
|
|
|
|
|
// .map(SyncWithholdingFeedbackResponse::getHead)
|
|
|
|
|
|
// .map(SzyhResponseHead::getCode)
|
|
|
|
|
|
// .orElse(null);
|
|
|
|
|
|
// WithholdingFeedbackResponse.Feedback body = Optional.ofNullable(response)
|
|
|
|
|
|
// .map(SyncWithholdingFeedbackResponse::getBody)
|
|
|
|
|
|
// .orElse(null);
|
|
|
|
|
|
// if (!SzyhApiConstant.SUCCESS_CODE.equals(responseCode) || Objects.isNull(body)) {
|
|
|
|
|
|
// log.info("syncWithholdingFeedback code error:{}", JSON.toJSONString(response));
|
|
|
|
|
|
// throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(95828, "税局接口异常,请稍后重试"));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// Integer paymentStatus = SalaryEntityUtil.getIntValue(body.getJkzt(), -1);
|
|
|
|
|
|
// TaxPaymentStatusEnum paymentStatusEnum = SalaryEnumUtil.enumMatchByValue(paymentStatus, TaxPaymentStatusEnum.class);
|
|
|
|
|
|
// if (paymentStatusEnum != TaxPaymentStatusEnum.SUCCESS) {
|
|
|
|
|
|
// throw new SalaryRunTimeException(String.format("查询失败,失败原因:%s,申报状态:%s", body.getJksbyy(), body.getSbzt()));
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 累计实缴金额
|
|
|
|
|
|
// BigDecimal totalPaid = body.getKkfhlb().stream().map(e -> new BigDecimal(e.getSjse())).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
// // 更新个税申报记录状态为已缴款
|
|
|
|
|
|
// updateTaxDeclareRecord(param, totalPaid);
|
|
|
|
|
|
// // 更新三方缴款反馈状态
|
|
|
|
|
|
// getTaxPaymentRequestMapper().updateFeedbackByTaxDeclareRecordId(TaxPaymentRequestPO
|
|
|
|
|
|
// .builder()
|
|
|
|
|
|
// .feedback(SalaryOnOffEnum.ON.getValue())
|
|
|
|
|
|
// .requestType(TaxPaymentServiceTypeEnum.WITHHOLDING_VOUCHER.getValue())
|
|
|
|
|
|
// .taxDeclareRecordId(param.getTaxDeclareRecordId())
|
|
|
|
|
|
// .build());
|
|
|
|
|
|
// }
|
2023-08-17 14:55:32 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void cancelWithholdingVoucher(TaxPaymentQueryParam param) {
|
|
|
|
|
|
TempWrapper tempWrapper = checkBeforeGetRequestIdResponse(param);
|
2023-08-23 15:46:18 +08:00
|
|
|
|
Map<String, Object> requestParam = DataCollectionBO.getApiBaseQueryParams(tempWrapper.getTaxReturnPO(), tempWrapper.getTaxAgentPO().getName(), SalaryDateUtil.getFormatYYYYMM(param.getTaxYearMonth()));
|
2023-08-17 14:55:32 +08:00
|
|
|
|
cancelWithholdingVoucher(tempWrapper.getApiConfigPO(), tempWrapper.getTaxDeclareRecord(), requestParam);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected BaseResponse getFeedbackResponse(TaxDeclarationApiConfigPO apiConfig, String requestId) {
|
|
|
|
|
|
String url = apiConfig.getHost() + SzyhApiConstant.WITHHOLDING_VOUCHER_FEEDBACK;
|
|
|
|
|
|
String res = getRequest(apiConfig, requestId, url);
|
|
|
|
|
|
return JsonUtil.parseObject(res, WithholdingVoucherFeedbackResponse.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|