|
|
|
@ -6,11 +6,14 @@ import cn.hutool.http.HttpUtil; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.dxhy.common.constant.DbConstant; |
|
|
|
|
import com.dxhy.common.datasource.config.DynamicContextHolder; |
|
|
|
|
import com.dxhy.common.enums.SNFplxEnum; |
|
|
|
|
import com.dxhy.common.util.UserInfoUtil; |
|
|
|
|
import com.dxhy.common.util.InvoiceUtil; |
|
|
|
|
import com.dxhy.common.vo.UserInfo; |
|
|
|
|
import com.dxhy.erp.dao.AreaDao; |
|
|
|
|
import com.dxhy.erp.dao.OrgUserInfoDao; |
|
|
|
|
import com.dxhy.erp.entity.kfpt.ApiCheckInvoiceSingleRequest; |
|
|
|
|
import com.dxhy.erp.entity.kfpt.ApiRequest; |
|
|
|
|
import com.dxhy.erp.entity.kfpt.ApiResponse; |
|
|
|
|
import com.dxhy.erp.entity.kfpt.TokenResponse; |
|
|
|
|
import com.dxhy.erp.entity.sdny.InvoiceDetail; |
|
|
|
|
import com.dxhy.erp.entity.sdny.InvoiceInfo; |
|
|
|
|
import com.dxhy.erp.entity.sdny.area.Area; |
|
|
|
@ -25,6 +28,7 @@ import javax.annotation.Resource; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.text.ParseException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@ -37,14 +41,32 @@ import java.util.Map; |
|
|
|
|
@SuppressWarnings("AlibabaUndefineMagicConstant") |
|
|
|
|
@Service |
|
|
|
|
@Slf4j |
|
|
|
|
public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
|
|
|
|
|
@Value("${sdny.snYxUrl}") |
|
|
|
|
private String snYxUrl; |
|
|
|
|
|
|
|
|
|
@Value("${params.api.invoiceCheckSingleUrl}") |
|
|
|
|
private String invoiceCheckSingleUrl; |
|
|
|
|
|
|
|
|
|
@Value("${params.api.appKey}") |
|
|
|
|
private String appKey; |
|
|
|
|
|
|
|
|
|
@Value("${params.api.appSecret}") |
|
|
|
|
private String appSecret; |
|
|
|
|
|
|
|
|
|
@Value("${params.api.entCode}") |
|
|
|
|
private String entCode; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private InvoiceQueryUtil invoiceQueryUtil; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private ApiUtils apiUtils; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private IcpUtils icpUtils; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private AreaDao areaDao; |
|
|
|
|
|
|
|
|
@ -67,7 +89,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
public JSONObject checkInvoice(Map<String, String> pramsMap, UserInfo userInfo) { |
|
|
|
|
|
|
|
|
|
// uuid = 发票代码+发票号码
|
|
|
|
|
String uuid = (org.apache.commons.lang.StringUtils.isBlank(pramsMap.get("invoiceCode"))?"":pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); |
|
|
|
|
String uuid = (org.apache.commons.lang.StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); |
|
|
|
|
|
|
|
|
|
DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ); |
|
|
|
|
|
|
|
|
@ -80,10 +102,9 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
gfsh = "91370000166120002R"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject queryInvoiceResult = invoiceQueryUtil.queryInvoice(pramsMap.get("invoiceCode"), |
|
|
|
|
pramsMap.get("invoiceNumber"), pramsMap.get("billingDate"), pramsMap.get("totalAmount"), pramsMap.get("checkCode"), |
|
|
|
|
gfsh,pramsMap.get("invoiceType")); |
|
|
|
|
gfsh, pramsMap.get("invoiceType")); |
|
|
|
|
String resultCode = queryInvoiceResult.getString("resultCode"); |
|
|
|
|
|
|
|
|
|
DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE); |
|
|
|
@ -94,12 +115,138 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return queryInvoiceResult; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public JSONObject singleCheckInvoice(Map<String, String> pramsMap) { |
|
|
|
|
|
|
|
|
|
//1.封装查验参数
|
|
|
|
|
ApiRequest apiRequest = new ApiRequest(); |
|
|
|
|
apiRequest.setEntCode(entCode); |
|
|
|
|
|
|
|
|
|
InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); |
|
|
|
|
String fplxdm = iu.getFplxdm(); |
|
|
|
|
|
|
|
|
|
String snIinvoiceType = pramsMap.get("invoiceType"); |
|
|
|
|
|
|
|
|
|
ApiCheckInvoiceSingleRequest request = new ApiCheckInvoiceSingleRequest(); |
|
|
|
|
request.setFphm(pramsMap.get("invoiceNumber")); |
|
|
|
|
request.setFpdm(pramsMap.get("invoiceCode")); |
|
|
|
|
request.setFpje(pramsMap.get("totalAmount")); |
|
|
|
|
request.setKprq(pramsMap.get("billingDate")); |
|
|
|
|
request.setJym(pramsMap.get("checkCode")); |
|
|
|
|
request.setFpzl(fplxdm); |
|
|
|
|
|
|
|
|
|
String check = JSONObject.toJSONString(request); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2.获取token
|
|
|
|
|
TokenResponse token = apiUtils.getToken(appKey, appSecret); |
|
|
|
|
String access_token = token.getAccess_token(); |
|
|
|
|
|
|
|
|
|
//3.调用开放平台查验接口
|
|
|
|
|
ApiResponse apiResponse = apiUtils.callApi(invoiceCheckSingleUrl, entCode, request, access_token, apiRequest.getDataExchangeId()); |
|
|
|
|
|
|
|
|
|
//4.封装返回参数
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
if (StringUtils.isNoneBlank(apiResponse.getContent())) |
|
|
|
|
jsonObject = convertToSnObject(apiResponse.getContent(), jsonObject, snIinvoiceType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return jsonObject; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JSONObject convertToSnObject(String content, JSONObject jsonObject, String invoiceType) { |
|
|
|
|
|
|
|
|
|
HashMap contentMap = JSONObject.parseObject(Base64.decode(content).toString(), HashMap.class); |
|
|
|
|
|
|
|
|
|
if ("0000".equals(contentMap.get("code"))) { |
|
|
|
|
|
|
|
|
|
HashMap<String, String> invoiceData = (HashMap<String, String>) contentMap.get("data"); |
|
|
|
|
|
|
|
|
|
jsonObject.put("invoiceType", invoiceType); |
|
|
|
|
jsonObject.put("administrativeDivisionNo", ""); |
|
|
|
|
jsonObject.put("administrativeDivisionName", ""); |
|
|
|
|
|
|
|
|
|
jsonObject.put("invoiceCode", invoiceData.get("fpdm")); |
|
|
|
|
jsonObject.put("invoiceNumber", invoiceData.get("fphm")); |
|
|
|
|
jsonObject.put("billingDate", invoiceData.get("kprq")); |
|
|
|
|
jsonObject.put("purchaserName", invoiceData.get("gmfmc")); |
|
|
|
|
jsonObject.put("purchaserTaxNo", invoiceData.get("gmfsbh")); |
|
|
|
|
jsonObject.put("purchaserBank", invoiceData.get("gmfyhzh")); |
|
|
|
|
jsonObject.put("purchaserAddressPhone", invoiceData.get("gmfdzdh")); |
|
|
|
|
jsonObject.put("salesName", invoiceData.get("xhfmc")); |
|
|
|
|
jsonObject.put("salesTaxNo", invoiceData.get("xhfsbh")); |
|
|
|
|
jsonObject.put("salesAddressPhone", invoiceData.get("xhfdzdh")); |
|
|
|
|
jsonObject.put("salesBank", invoiceData.get("xhfyhzh")); |
|
|
|
|
jsonObject.put("totalAmount", invoiceData.get("totalAmount")); |
|
|
|
|
jsonObject.put("totalTax", invoiceData.get("fpse")); |
|
|
|
|
jsonObject.put("amountTax", invoiceData.get("jshj")); |
|
|
|
|
jsonObject.put("amountTaxCN", ""); |
|
|
|
|
jsonObject.put("checkCode", invoiceData.get("jym")); |
|
|
|
|
jsonObject.put("state", invoiceData.get("zfbz")); |
|
|
|
|
jsonObject.put("carrierName", invoiceData.get("cyrmc")); |
|
|
|
|
jsonObject.put("carrierTaxNo", invoiceData.get("cyrsbh")); |
|
|
|
|
jsonObject.put("draweeName", invoiceData.get("spfmc")); |
|
|
|
|
jsonObject.put("draweeTaxNo", invoiceData.get("spfsbh")); |
|
|
|
|
jsonObject.put("cargoInformation", invoiceData.get("ysgwxx")); |
|
|
|
|
jsonObject.put("transportRoute", invoiceData.get("qydjyddd")); |
|
|
|
|
jsonObject.put("machineCode", invoiceData.get("skph")); |
|
|
|
|
jsonObject.put("tonnage", invoiceData.get("ccdw")); |
|
|
|
|
jsonObject.put("taxAuthorityNo", invoiceData.get("zgswjgdm")); |
|
|
|
|
jsonObject.put("taxAuthorityName", invoiceData.get("zgswjgmc")); |
|
|
|
|
jsonObject.put("remarks", invoiceData.get("bz")); |
|
|
|
|
jsonObject.put("vehicleType", invoiceData.get("cllx")); |
|
|
|
|
jsonObject.put("brandModel", invoiceData.get("cpxh")); |
|
|
|
|
jsonObject.put("originPlace", invoiceData.get("cd")); |
|
|
|
|
jsonObject.put("certificateNo", invoiceData.get("hgzs")); |
|
|
|
|
jsonObject.put("inspectionListNo", invoiceData.get("sjdh")); |
|
|
|
|
jsonObject.put("engineNo", invoiceData.get("fdjhm")); |
|
|
|
|
jsonObject.put("vehicleNo", invoiceData.get("clsbh")); |
|
|
|
|
jsonObject.put("importCertificateNo", invoiceData.get("jszmsh")); |
|
|
|
|
jsonObject.put("paymentVoucherNo", invoiceData.get("wspzhm")); |
|
|
|
|
jsonObject.put("passengersLimited", invoiceData.get("xcrs")); |
|
|
|
|
jsonObject.put("tollSign", invoiceData.get("txfbz")); |
|
|
|
|
jsonObject.put("zeroTaxRateSign", invoiceData.get("lslbs")); |
|
|
|
|
jsonObject.put("source", ""); |
|
|
|
|
jsonObject.put("idcardNo", invoiceData.get("sfzh")); |
|
|
|
|
|
|
|
|
|
List<Map<String, String>> returnDetailList = new ArrayList<>(); |
|
|
|
|
String detailListStr = invoiceData.get("detailList"); |
|
|
|
|
List<Map<String, String>> detailList = JSONObject.parseObject(detailListStr, List.class); |
|
|
|
|
int i = 1; |
|
|
|
|
for (Map<String, String> detail : detailList) { |
|
|
|
|
|
|
|
|
|
Map<String, String> snDetailMap = new HashMap<String, String>(); |
|
|
|
|
snDetailMap.put("rowNo", i + ""); |
|
|
|
|
snDetailMap.put("commodityCode", detail.get("mxbh")); |
|
|
|
|
snDetailMap.put("commodityName", detail.get("hwmc")); |
|
|
|
|
snDetailMap.put("specificationModel", detail.get("ggxh")); |
|
|
|
|
snDetailMap.put("unit", detail.get("jldw")); |
|
|
|
|
snDetailMap.put("quantity", detail.get("spsl")); |
|
|
|
|
snDetailMap.put("unitPrice", detail.get("hsdj")); |
|
|
|
|
snDetailMap.put("amount", detail.get("je")); |
|
|
|
|
snDetailMap.put("taxRate", detail.get("sl")); |
|
|
|
|
snDetailMap.put("tax", detail.get("se")); |
|
|
|
|
snDetailMap.put("currentDateEnd", detail.get("txrqz")); |
|
|
|
|
snDetailMap.put("currentDateStart", detail.get("txrqq")); |
|
|
|
|
snDetailMap.put("licensePlateNum", detail.get("cph")); |
|
|
|
|
snDetailMap.put("type", detail.get("lx")); |
|
|
|
|
|
|
|
|
|
returnDetailList.add(snDetailMap); |
|
|
|
|
i++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
jsonObject.put("invoiceLineList", returnDetailList); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
jsonObject.put("code", contentMap.get("code")); |
|
|
|
|
jsonObject.put("message", contentMap.get("message")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return jsonObject; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 客票价税计算 |
|
|
|
@ -338,7 +485,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { |
|
|
|
|
result = "出发或到达城市不符合标准"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|