You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
942 lines
38 KiB
942 lines
38 KiB
package com.dxhy.erp.controller;
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.dxhy.common.aspect.SysLog;
|
|
import com.dxhy.common.constant.CommonConstants;
|
|
import com.dxhy.common.constant.ConfigureConstant;
|
|
import com.dxhy.common.constant.DbConstant;
|
|
import com.dxhy.common.controller.AbstractController;
|
|
import com.dxhy.common.datasource.config.DynamicContextHolder;
|
|
import com.dxhy.common.enums.SNFplxEnum;
|
|
import com.dxhy.common.util.InvoiceUtil;
|
|
import com.dxhy.common.util.UserInfoUtil;
|
|
import com.dxhy.common.utils.R;
|
|
import com.dxhy.erp.dao.CustomsRecordDao;
|
|
import com.dxhy.erp.dao.GsClientMapper;
|
|
import com.dxhy.erp.dao.RecordInvoiceDao;
|
|
import com.dxhy.erp.dao.TdxSaleRecordInvoiceDao;
|
|
import com.dxhy.erp.entity.*;
|
|
import com.dxhy.erp.entity.sdny.*;
|
|
import com.dxhy.erp.service.*;
|
|
import com.dxhy.erp.utils.HmacSHA1Util;
|
|
import com.dxhy.erp.utils.ServiceResult;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.math.BigDecimal;
|
|
import java.text.ParseException;
|
|
import java.text.ParsePosition;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* 山东能源查验主流程控制器
|
|
*
|
|
* @author ariesy
|
|
* @date 2023-03-15
|
|
*/
|
|
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong"})
|
|
@RestController
|
|
@Slf4j
|
|
public class SDNYMainProcessController extends AbstractController {
|
|
|
|
@Value("${sdny.environment}")
|
|
private String environment;
|
|
|
|
@Resource
|
|
private GsClientMapper gsClientMapper;
|
|
|
|
@Resource
|
|
private InvoiceQueryService invoiceQueryService;
|
|
|
|
@Resource
|
|
private SNPushCheckRecordService snPushCheckRecordService;
|
|
|
|
@Resource
|
|
private SignSaveInvoiceInfoService signSaveInvoiceInfoService;
|
|
|
|
@Resource
|
|
private SignCheckRecordService signCheckRecordService;
|
|
|
|
@Resource
|
|
private TDxInvoiceReimburseService tDxInvoiceReimburseService;
|
|
|
|
@Resource
|
|
TdxSaleRecordInvoiceDao tdxSaleRecordInvoiceDao;
|
|
|
|
@Resource
|
|
private CustomsRecordDao customsRecordDao;
|
|
|
|
@Resource
|
|
private RecordInvoiceDao recordInvoiceDao;
|
|
|
|
/**
|
|
* 查验发票
|
|
*/
|
|
@PostMapping("/sn/singleInvoiceCheck")
|
|
@ResponseBody
|
|
@SysLog("发票查验")
|
|
public ResponseEntity<String> singleInvoiceCheck(@RequestBody Map<String, String> pramsMap) throws ParseException {
|
|
log.info("传入的参数为:{}", pramsMap);
|
|
String userid = "101833";
|
|
String dbName = "business";
|
|
String company = "BIGB";
|
|
|
|
// 入参统一在入口处理
|
|
// String userid = getLoginName();
|
|
// String dbName = getUserInfo().getDbName();
|
|
// String company = getUserInfo().getCompany();
|
|
JSONObject checkInvoiceResult = null;
|
|
InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode"));
|
|
String fplxdm = iu.getFplxdm();
|
|
if (fplxdm != null || "10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))) {
|
|
//查验类发票,执行查验操作后入库
|
|
log.info("查验类发票,执行查验操作后入库");
|
|
//权限校验
|
|
if (pramsMap.get("invoiceNumber").isEmpty()) {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error("发票号码不能为空!")));
|
|
}
|
|
|
|
pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber"));
|
|
|
|
if (!pramsMap.get("billingDate").isEmpty()) {
|
|
String billingDate = pramsMap.get("billingDate").replaceAll("-", "");
|
|
iu.setKprq(pramsMap.get("billingDate"));
|
|
pramsMap.put("invoiceDate", billingDate);
|
|
pramsMap.put("billingDate", billingDate);
|
|
} else {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error("开票日期不能为空!")));
|
|
}
|
|
|
|
if (pramsMap.get("invoiceType").isEmpty()) {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error("开票日期不能为空!")));
|
|
}
|
|
|
|
if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType"))
|
|
|| SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) {
|
|
if (pramsMap.get("totalAmount").isEmpty()) {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error("金额不能为空!")));
|
|
}
|
|
} else {
|
|
if (pramsMap.get("checkCode").isEmpty()) {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error("校验码不能为空!")));
|
|
}
|
|
}
|
|
|
|
if ("10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))) {
|
|
pramsMap.put("invoiceType", "21");
|
|
}
|
|
|
|
log.info("发票类型为:{}", pramsMap.get("invoiceType"));
|
|
|
|
String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo");
|
|
log.info("uuid={}", uuid);
|
|
String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo());
|
|
if (notes != null) {
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error(notes)));
|
|
}
|
|
|
|
//查询底账库是否有对应发票,有则直接返回
|
|
TdxCheckRecordInvoice checkInvoiceByUuid = signCheckRecordService.getCheckInvoiceByUuid(uuid);
|
|
if (checkInvoiceByUuid != null) {
|
|
log.info("进项票池已存在发票.直接返回票池信息");
|
|
R data = new R(1000, "default success");
|
|
|
|
JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(checkInvoiceByUuid);
|
|
convertToResult(checkInvoice);
|
|
|
|
data.put("data", checkInvoice);
|
|
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
} else {
|
|
TdxSaleRecordInvoice tdxSaleRecordInvoice = tdxSaleRecordInvoiceDao.selectByUuid(uuid);
|
|
log.info("tdxSaleRecordInvoice={}", tdxSaleRecordInvoice);
|
|
if (tdxSaleRecordInvoice != null) {
|
|
log.info("销项票池已存在发票.直接返回票池信息");
|
|
R data = new R(1000, "default success");
|
|
|
|
JSONObject checkInvoice = (JSONObject) JSONObject.toJSON(tdxSaleRecordInvoice);
|
|
convertToResult(checkInvoice);
|
|
|
|
data.put("data", checkInvoice);
|
|
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (!checkInvoiceResult.containsKey("code")) {
|
|
R data = new R(1000, "default success");
|
|
data.put("message", "success");
|
|
data.put("data", checkInvoiceResult);
|
|
|
|
if (!checkInvoiceResult.containsKey("cyjg")) {
|
|
|
|
checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber"));
|
|
checkInvoiceResult.put("company", company);
|
|
log.info("返回给影像系统的结果为:{}", checkInvoiceResult);
|
|
signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName);
|
|
}
|
|
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
}
|
|
} else {
|
|
//其他类发票,直接入库
|
|
log.info("其他类发票,不做查验,直接入库");
|
|
TDxInvoiceReimburse reimburse = new TDxInvoiceReimburse();
|
|
int insert = tDxInvoiceReimburseService.getBaseMapper().insert(reimburse);
|
|
|
|
R data = new R(1000, "default success");
|
|
data.put("message", "success");
|
|
|
|
if (insert > 0) {
|
|
checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber"));
|
|
checkInvoiceResult.put("company", company);
|
|
checkInvoiceResult.put("message", "入库成功");
|
|
log.info("返回给影像系统的结果为:{}", checkInvoiceResult);
|
|
}
|
|
|
|
data.put("data", checkInvoiceResult);
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
|
|
}
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error().put("data", checkInvoiceResult)));
|
|
}
|
|
|
|
private void convertToResult(JSONObject checkInvoice) throws ParseException {
|
|
checkInvoice.put("totalTax", checkInvoice.getString("taxAmount"));
|
|
checkInvoice.put("amountTax", checkInvoice.getString("totalAmount"));
|
|
checkInvoice.put("totalAmount", checkInvoice.getString("invoiceAmount"));
|
|
String invoiceCode = checkInvoice.get("invoiceCode").toString();
|
|
String invoiceType = checkInvoice.get("invoiceType").toString();
|
|
if ("22".equals(invoiceType)) {
|
|
invoiceType = "33";
|
|
}
|
|
if ("21".equals(invoiceType)) {
|
|
invoiceType = "31";
|
|
}
|
|
|
|
checkInvoice.put("invoiceType", invoiceType);
|
|
checkInvoice.put("administrativeDivisionNo", "");
|
|
checkInvoice.put("administrativeDivisionName", "");
|
|
|
|
checkInvoice.put("invoiceCode", invoiceCode);
|
|
checkInvoice.put("invoiceNumber", checkInvoice.get("invoiceNo").toString());
|
|
String uuid = "";
|
|
if(invoiceCode != null && StringUtils.isNoneBlank(invoiceCode)){
|
|
uuid = invoiceCode + checkInvoice.get("invoiceNo").toString();
|
|
checkInvoice.put("uuid",uuid);
|
|
}else{
|
|
uuid = checkInvoice.get("invoiceNo").toString();
|
|
checkInvoice.put("uuid",uuid);
|
|
}
|
|
|
|
|
|
String kprq = checkInvoice.get("invoiceDate").toString();
|
|
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
|
|
Date date = sdf.parse(kprq);
|
|
String formatStr = new SimpleDateFormat("yyyy-MM-dd").format(date);
|
|
log.info("开票日期为:{} ", formatStr);
|
|
|
|
checkInvoice.put("billingDate", formatStr);
|
|
checkInvoice.put("purchaserName", checkInvoice.get("gfName"));
|
|
checkInvoice.put("purchaserTaxNo", checkInvoice.get("gfTaxNo"));
|
|
checkInvoice.put("purchaserBank", checkInvoice.get("gfBankAndNo"));
|
|
checkInvoice.put("purchaserAddressPhone", checkInvoice.get("gfAddressAndPhone"));
|
|
checkInvoice.put("salesName", checkInvoice.get("xfName"));
|
|
checkInvoice.put("salesTaxNo", checkInvoice.get("xfTaxNo"));
|
|
checkInvoice.put("salesAddressPhone", checkInvoice.get("gfAddressAndPhone"));
|
|
checkInvoice.put("salesBank", checkInvoice.get("gfBankAndNo"));
|
|
checkInvoice.put("checkCode", checkInvoice.get("checkCode"));
|
|
checkInvoice.put("state", "0");
|
|
checkInvoice.put("tollSign", "07");
|
|
String taxRate = "";
|
|
|
|
List<Map<String, String>> returnDetailList = new ArrayList<>();
|
|
// JSONArray detailList = (JSONArray) invoiceData.get("detailList");
|
|
JSONArray detailList = new JSONArray();
|
|
|
|
for (int i = 0; i < detailList.size(); i++) {
|
|
String taxRateDetail = "";
|
|
JSONObject detail = (JSONObject) detailList.get(i);
|
|
Map<String, String> snDetailMap = new HashMap<String, String>();
|
|
snDetailMap.put("rowNo", i + 1 + "");
|
|
snDetailMap.put("commodityCode", detail.getString("ssflbm"));
|
|
snDetailMap.put("commodityName", detail.getString("hwmc"));
|
|
snDetailMap.put("specificationModel", detail.getString("ggxh"));
|
|
snDetailMap.put("unit", detail.getString("jldw"));
|
|
String quantity = detail.getString("spsl");
|
|
// if (quantity.length() > 3) {
|
|
// int index = quantity.indexOf(".");
|
|
// quantity = quantity.substring(0, index + 2);
|
|
// }
|
|
snDetailMap.put("quantity", quantity);
|
|
|
|
String unitPrice = detail.getString("bhsdj");
|
|
// if (unitPrice.length() > 3) {
|
|
// int index = unitPrice.indexOf(".");
|
|
// unitPrice = unitPrice.substring(0, index + 3);
|
|
// }
|
|
|
|
snDetailMap.put("unitPrice", unitPrice);
|
|
|
|
|
|
if ("11".equals(invoiceType)) {
|
|
snDetailMap.put("tax", "0");
|
|
|
|
//如果是卷票计算合计金额
|
|
Float hjje = null;
|
|
if (detail.getString("se") != null && detail.getString("je") != null) {
|
|
Float je = Float.parseFloat(detail.getString("je"));
|
|
Float se = Float.parseFloat(detail.getString("se"));
|
|
hjje = je + se;
|
|
}
|
|
|
|
if (hjje != null)
|
|
snDetailMap.put("amount", hjje.toString());
|
|
|
|
} else {
|
|
snDetailMap.put("tax", "***".equals(detail.getString("se")) ? "0.00" : detail.getString("se"));
|
|
snDetailMap.put("amount", detail.getString("je"));
|
|
}
|
|
|
|
|
|
if ("免税".equals(detail.getString("sl"))) {
|
|
taxRateDetail = "0";
|
|
snDetailMap.put("taxRate", taxRateDetail);
|
|
} else {
|
|
if (detail.get("sl") != null && StringUtils.isNoneBlank(detail.get("sl").toString())) {
|
|
taxRateDetail = detail.get("sl").toString();
|
|
if (!"0".equals(taxRateDetail)) {
|
|
if (StringUtils.isNoneBlank(taxRateDetail)) {
|
|
int index = taxRateDetail.indexOf("%");
|
|
if (index > 0) {
|
|
taxRateDetail = taxRateDetail.substring(0, taxRateDetail.length() - 1);
|
|
Float num = Float.parseFloat(taxRateDetail);
|
|
if (num > 9) {
|
|
taxRateDetail = "0." + taxRateDetail;
|
|
} else {
|
|
if (!taxRateDetail.startsWith("0")) {
|
|
taxRateDetail = "0.0" + taxRateDetail;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ("11".equals(invoiceType)) {
|
|
taxRateDetail = "0.000";
|
|
}
|
|
log.info("明细-发票税率为:{}", taxRateDetail);
|
|
snDetailMap.put("taxRate", taxRateDetail);
|
|
}
|
|
}
|
|
|
|
log.info("明细-tax={}", detail.get("se"));
|
|
log.info("明细-commodityCode={}", detail.get("ssflbm"));
|
|
snDetailMap.put("currentDateEnd", detail.getString("txrqz"));
|
|
snDetailMap.put("currentDateStart", detail.getString("txrqq"));
|
|
snDetailMap.put("licensePlateNum", detail.getString("cph"));
|
|
snDetailMap.put("type", detail.getString("lx"));
|
|
|
|
returnDetailList.add(snDetailMap);
|
|
}
|
|
|
|
checkInvoice.put("invoiceLineList", returnDetailList);
|
|
}
|
|
|
|
/**
|
|
* 查验发票
|
|
*/
|
|
@PostMapping("/sn/syncInvoiceInfo")
|
|
@ResponseBody
|
|
@SysLog("同步发票信息")
|
|
public ResponseEntity<String> syncInvoiceInfo(@RequestBody SNRequestObject snRequestObject) {
|
|
|
|
log.info("影像系统同步数据:{}", JSONObject.toJSONString(snRequestObject));
|
|
|
|
String userid = "101833";
|
|
String dbName = "business";
|
|
String company = "BIGB";
|
|
String taxNo = "9111112222333344DD";
|
|
String orgCode = "1010";
|
|
|
|
// // 入参统一在入口处理
|
|
// String userid = getLoginName();
|
|
// String dbName = getUserInfo().getDbName();
|
|
// String company = getUserInfo().getCompany();
|
|
// List<String> gfshAll = UserInfoUtil.getGfshAll(getUserInfo().getOrg());
|
|
// String gfsh = "";
|
|
// if (gfshAll.size() > 0) {
|
|
// gfsh = gfshAll.get(0);
|
|
// }
|
|
|
|
String result = "";
|
|
|
|
try {
|
|
|
|
List<SNInvoice> invoiceInfoList = snRequestObject.getInvoiceInfoList();
|
|
|
|
String imageId = snRequestObject.getImageId();
|
|
String compCode = snRequestObject.getCompCode();
|
|
|
|
TDxInvoiceReimburse reimburse = new TDxInvoiceReimburse();
|
|
reimburse.setImageId(imageId);
|
|
reimburse.setCompCode(compCode);
|
|
|
|
SNSAPObject object = new SNSAPObject();
|
|
object.setSYSID("FPXT");
|
|
object.setIFYWID("FI845");
|
|
object.setBSKEY(UUID.randomUUID().toString().replace("-", ""));
|
|
object.setSAPKEY("");
|
|
object.setZORG(compCode);
|
|
object.setZFILED1("");
|
|
object.setZFILED2("");
|
|
object.setZFILED3("");
|
|
object.setZFILED4("");
|
|
// List<GsClient> gsClients = gsClientMapper.selectByGsdm(orgCode);
|
|
// if(gsClients != null && gsClients.size() > 0) {
|
|
// object.setZFILED5(gsClients.get(0).getClient());
|
|
// }else{
|
|
// object.setZFILED5(environment);
|
|
// }
|
|
|
|
object.setZFILED5(environment);
|
|
List<SAPInvoiceInfo> sapInvoiceInfos = new ArrayList<>();
|
|
if (invoiceInfoList != null && invoiceInfoList.size() > 0) {
|
|
for (SNInvoice invoice : invoiceInfoList) {
|
|
String fplxdm = "";
|
|
String snFplx = "";
|
|
result = snPushCheckRecordService.updateInvoicePoll(company, taxNo, reimburse, invoice, fplxdm, imageId, compCode);
|
|
|
|
//价税分离判断
|
|
if (!"ok".equals(result) && !"0000".equals(result)) {
|
|
R data = new R(1000, "default success");
|
|
data.put("data", result);
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error(result)));
|
|
}
|
|
SAPInvoiceInfo info = convertToSapOnject(invoice, imageId, compCode);
|
|
sapInvoiceInfos.add(info);
|
|
}
|
|
object.setZDATA(JSONObject.toJSONString(sapInvoiceInfos));
|
|
|
|
//推送到SAP
|
|
log.info("推送山能数据:{}", JSONObject.toJSONString(object));
|
|
JSONObject request = new JSONObject();
|
|
request.put("IS_INPUT", object);
|
|
|
|
try {
|
|
//将信息推送到影像系统
|
|
result = snPushCheckRecordService.pushCheckResultToSAP(request.toJSONString());
|
|
|
|
R data = new R(1000, "default success");
|
|
data.put("data", result);
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
log.error("", e);
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)));
|
|
}
|
|
} else {
|
|
R data = new R(1000, "default success");
|
|
data.put("data", result);
|
|
return ResponseEntity.ok(JSONObject.toJSONString(data));
|
|
}
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
return ResponseEntity.ok(JSONObject.toJSONString(R.error(CommonConstants.MSG_ERR_PUSH_SDNY)));
|
|
}
|
|
|
|
|
|
/**
|
|
* 查验发票
|
|
*/
|
|
@PostMapping("/sn/signature")
|
|
@ResponseBody
|
|
@SysLog("获取接口签名值")
|
|
public String signature(HttpServletRequest request, @RequestBody Map<String, String> paramMap) {
|
|
String ip = paramMap.get("ip");
|
|
String apiCode = paramMap.get("apiCode");
|
|
String secretId = paramMap.get("secretId");
|
|
String secretKey = paramMap.get("secretKey");
|
|
String content = paramMap.get("content");
|
|
String dataExchangeId = paramMap.get("dataExchangeId");
|
|
|
|
TreeMap<String, String> sortMap = new TreeMap<>();
|
|
sortMap.put("SecretId", secretId);
|
|
sortMap.put("dataExchangeId", dataExchangeId);
|
|
sortMap.put("encryptCode", "0");
|
|
sortMap.put("zipCode", "0");
|
|
sortMap.put("content", content);
|
|
|
|
String reqUrl = request.getRequestURL().toString();
|
|
if (reqUrl.contains(ConfigureConstant.STRING_WH)) {
|
|
reqUrl = reqUrl.substring(ConfigureConstant.INT_0, reqUrl.indexOf(ConfigureConstant.STRING_WH));
|
|
}
|
|
//获取鉴权URL
|
|
String signUrl = getAuthUrl(reqUrl, request.getMethod());
|
|
String signature = HmacSHA1Util.genSign(signUrl, sortMap, secretKey);
|
|
return signature;
|
|
}
|
|
|
|
private static String getAuthUrl(String reqUrl, String method) {
|
|
if (reqUrl.split(ConfigureConstant.STRING_COLON).length > ConfigureConstant.INT_2) {
|
|
String one = reqUrl.split(ConfigureConstant.STRING_COLON)[1];
|
|
String two = reqUrl.split(ConfigureConstant.STRING_COLON)[2];
|
|
//支持带端口数据的返回
|
|
if (two.indexOf(ConfigureConstant.STRING_SLASH_LINE) > 0) {
|
|
reqUrl = one.replaceAll("//", "") + ConfigureConstant.STRING_COLON + two;
|
|
} else {
|
|
reqUrl = one.replaceAll("//", "") + two.substring(two.indexOf(ConfigureConstant.STRING_SLASH_LINE));
|
|
}
|
|
} else if (reqUrl.split(ConfigureConstant.STRING_COLON).length == ConfigureConstant.INT_2) {
|
|
String one = reqUrl.split(ConfigureConstant.STRING_COLON)[1];
|
|
reqUrl = one.contains("//") ? one.replaceAll("//", "") : reqUrl;
|
|
}
|
|
return method + reqUrl + "?";
|
|
}
|
|
|
|
private SAPInvoiceInfo convertToSapOnject(SNInvoice snInvoice, String imageId, String compCode) {
|
|
|
|
//转换时间格式
|
|
Date date = new Date();
|
|
SimpleDateFormat formatterTime = new SimpleDateFormat("yyyyMMdd");
|
|
SimpleDateFormat formatterDate = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
String timeString = formatterTime.format(date);
|
|
String dateString = formatterDate.format(date);
|
|
|
|
SAPInvoiceInfo info = new SAPInvoiceInfo();
|
|
|
|
String snFplx = convertToSapType(snInvoice.getInvoiceType());
|
|
info.setZBAZT("0");
|
|
info.setZXFSH(snInvoice.getSalesTaxNo());
|
|
info.setZFPSZD(snInvoice.getPlace());
|
|
info.setZSPMC(snInvoice.getDraweeName());
|
|
info.setZSPSBH(snInvoice.getDraweeTaxNo());
|
|
info.setZCYJG(snInvoice.getCheckResultMessage());
|
|
info.setZJKZM(snInvoice.getImportCertificateNo());
|
|
info.setZDJZH(snInvoice.getCertificateNo());
|
|
info.setZGFMC(snInvoice.getPurchaserName());
|
|
info.setSORT(snInvoice.getSort());
|
|
//机打代码
|
|
info.setZJDDM(snInvoice.getMachineCode());
|
|
if (snInvoice.getTotalAmount() != null) {
|
|
BigDecimal total = new BigDecimal(snInvoice.getTotalAmount());
|
|
// BigDecimal tax = new BigDecimal(snInvoice.getTotalTax());
|
|
// BigDecimal subtract = total.subtract(tax);
|
|
info.setZJK(total.toString());
|
|
} else {
|
|
info.setZJK("0.00");
|
|
}
|
|
info.setZSCSJ("000000");
|
|
info.setZYSHW(snInvoice.getCargoInformation());
|
|
info.setZFPLX(snFplx);
|
|
info.setZQYD(snInvoice.getTransportRoute());
|
|
info.setZCCRXM(snInvoice.getRiderName());
|
|
if (snInvoice.getBillingDate() != null) {
|
|
String billingDate = snInvoice.getBillingDate();
|
|
String replace = billingDate.replace("-", "");
|
|
info.setZKPRQ(replace);
|
|
}
|
|
|
|
info.setZSE(snInvoice.getTotalTax());
|
|
info.setZTXBZ(snInvoice.getTollSign());
|
|
// info.setZSKPH(snInvoice.getMachineCode());
|
|
info.setZGFZH(snInvoice.getPurchaserBank());
|
|
info.setZBZ(snInvoice.getRemarks());
|
|
|
|
List<SNInvoiceDetail> invoiceLineList = snInvoice.getInvoiceLineList();
|
|
List<SAPInvoiceDetail> sapInvoiceDetailList = new ArrayList<>();
|
|
if (invoiceLineList != null && invoiceLineList.size() > 0) {
|
|
for (SNInvoiceDetail snInvoiceDetail : invoiceLineList) {
|
|
SAPInvoiceDetail sapInvoiceDetail = new SAPInvoiceDetail();
|
|
|
|
//设置id
|
|
sapInvoiceDetail.setZHID(UUID.randomUUID().toString().replace("-",""));
|
|
// sapInvoiceDetail.setZZWDJ("");
|
|
|
|
sapInvoiceDetail.setIMG_ID(imageId);
|
|
sapInvoiceDetail.setZCPH(snInvoiceDetail.getLicensePlateNum());
|
|
// sapInvoiceDetail.setZCJSJ();
|
|
// sapInvoiceDetail.setZCJRQ();
|
|
sapInvoiceDetail.setFPYXBH(snInvoice.getFileId());
|
|
sapInvoiceDetail.setZCFZ(snInvoice.getStationGetOn());
|
|
sapInvoiceDetail.setZTXZ(snInvoiceDetail.getCurrentDateEnd());
|
|
sapInvoiceDetail.setZTXQ(snInvoiceDetail.getCurrentDateStart());
|
|
|
|
if (snInvoiceDetail.getAmount() != null)
|
|
sapInvoiceDetail.setZJK(snInvoiceDetail.getAmount());
|
|
sapInvoiceDetail.setZHH(snInvoiceDetail.getRowNo());
|
|
//将类似于0.03数据格式转化为3.00
|
|
if (snInvoiceDetail.getTaxRate() != null && snInvoiceDetail.getTaxRate() != "") {
|
|
sapInvoiceDetail.setZTAX(snInvoiceDetail.getTaxRate());
|
|
if (snInvoiceDetail.equals("0")) {
|
|
sapInvoiceDetail.setZTAX("0.00");
|
|
}
|
|
if (snInvoiceDetail.getTaxRate().contains(".")) {
|
|
String getTaxRate = snInvoiceDetail.getTaxRate();
|
|
if (snInvoiceDetail.getTaxRate().length() > 4) {
|
|
getTaxRate = getTaxRate.substring(0, 4);
|
|
}
|
|
BigDecimal tax = new BigDecimal(getTaxRate);
|
|
BigDecimal tax1 = tax.multiply(new BigDecimal("100"));
|
|
sapInvoiceDetail.setZTAX(tax1.toString());
|
|
}
|
|
}
|
|
// if (invoiceLineList.size() == 1 && snInvoice.getTaxRate() == null) {
|
|
// info.setZTAX(sapInvoiceDetail.getZTAX());
|
|
// }
|
|
// sapInvoiceDetail.setZHBH("");
|
|
sapInvoiceDetail.setZDJ(snInvoiceDetail.getUnitPrice());
|
|
// sapInvoiceDetail.setZHID("");
|
|
sapInvoiceDetail.setZDDZ(snInvoice.getStationGetOff());
|
|
sapInvoiceDetail.setZHWMC(snInvoiceDetail.getCommodityName());
|
|
sapInvoiceDetail.setZCYR(info.getZCYRMC());
|
|
sapInvoiceDetail.setZDW(snInvoiceDetail.getUnit());
|
|
sapInvoiceDetail.setZGSJBM(snInvoiceDetail.getCommodityCode());
|
|
sapInvoiceDetail.setZSE(snInvoiceDetail.getTax());
|
|
sapInvoiceDetail.setZSL(snInvoiceDetail.getQuantity());
|
|
sapInvoiceDetail.setZSM(getZSM(snInvoiceDetail.getTaxRate()));
|
|
sapInvoiceDetail.setZGGXH(snInvoiceDetail.getSpecificationModel());
|
|
if (snInvoice.getInvoiceCode() != null) {
|
|
sapInvoiceDetail.setZTID(snInvoice.getInvoiceCode() + snInvoice.getInvoiceNumber() + snFplx);
|
|
} else {
|
|
sapInvoiceDetail.setZTID(snInvoice.getInvoiceNumber() + snFplx);
|
|
}
|
|
sapInvoiceDetailList.add(sapInvoiceDetail);
|
|
}
|
|
}
|
|
|
|
info.setIT_ITEM(sapInvoiceDetailList);
|
|
|
|
//获取税率
|
|
String taxRate = snInvoice.getTaxRate();
|
|
if (taxRate != null && !taxRate.contains("%")){
|
|
BigDecimal bigDecimal = new BigDecimal(taxRate);
|
|
BigDecimal multiply = bigDecimal.multiply(new BigDecimal("100"));
|
|
info.setZTAX(multiply.toString());
|
|
info.setZSM(getZSM(taxRate));
|
|
}
|
|
if (taxRate != null && taxRate.contains("%")) {
|
|
String replace = taxRate.replace("%", "");
|
|
BigDecimal bigDecimal = new BigDecimal(replace);
|
|
BigDecimal divide = bigDecimal.divide(new BigDecimal(100));
|
|
// taxRate = divide.toString();
|
|
// info.setZTAX(bigDecimal.multiply(new BigDecimal("0.01")).toString());
|
|
info.setZTAX(replace+".00");
|
|
info.setZSM(getZSM(divide.toString()));
|
|
}
|
|
if (info.getZTAX() == null || info.getZTAX() == "") {
|
|
info.setZTAX("0.00");
|
|
info.setZSM(getZSM(info.getZTAX()));
|
|
}
|
|
info.setZFPDM(snInvoice.getInvoiceCode());
|
|
info.setZCD(snInvoice.getOriginPlace());
|
|
info.setZSCCZ(snInvoice.getStationGetOn());
|
|
info.setZCC(snInvoice.getTrainNumber());
|
|
info.setZFPHM(snInvoice.getInvoiceNumber());
|
|
info.setZBXF(snInvoice.getInsurance());
|
|
info.setZRYFJ(snInvoice.getFuelSurcharge());
|
|
info.setZCLSB(snInvoice.getVehicleNo());
|
|
info.setZKPSJ("000000");
|
|
info.setZXCSJ("000000");
|
|
info.setZXFMC(snInvoice.getSalesName());
|
|
info.setZCYRSBH(snInvoice.getCarrierName());
|
|
|
|
info.setIMG_ID(imageId);
|
|
info.setZCPH(snInvoice.getLicensePlate());
|
|
info.setZLSLBZ(snInvoice.getZeroTaxRateSign());
|
|
info.setFPYXBH(snInvoice.getFileId());
|
|
//转换日期
|
|
info.setZCJSJ(dateString);
|
|
info.setZFPZT(snInvoice.getState());
|
|
if (snInvoice.getState() == null) {
|
|
info.setZFPZT("0");
|
|
} else {
|
|
info.setZFPZT(snInvoice.getState());
|
|
}
|
|
// info.setZESCSC("");
|
|
info.setZFDJM(snInvoice.getEngineNo());
|
|
info.setZGXR("");
|
|
|
|
//认证相关
|
|
String zrzjg = getZRZJG(snInvoice.getInvoiceCode(),snInvoice.getInvoiceNumber(),info.getZFPLX());
|
|
info.setZRZJG(zrzjg);
|
|
info.setZRZSSQ("");
|
|
// info.setZRZMS("");
|
|
// info.setZRZRQ("");
|
|
|
|
info.setZLC(snInvoice.getMileage());
|
|
info.setZHGZH(snInvoice.getCertificateNo());
|
|
info.setZXFDH(snInvoice.getSalesAddressPhone());
|
|
|
|
// info.setZESCSH("");
|
|
info.setZGSDM(compCode);
|
|
info.setZGFSH(snInvoice.getPurchaserTaxNo());
|
|
info.setZXCRS(snInvoice.getPassengersLimited());
|
|
info.setZWSPZ(snInvoice.getPaymentVoucherNo());
|
|
info.setZCCDW(snInvoice.getTonnage());
|
|
info.setZSWJG(snInvoice.getTaxAuthorityName());
|
|
// info.setZYWDJ("");
|
|
info.setZXCCZ(snInvoice.getStationGetOff());
|
|
info.setZCCRZH(snInvoice.getIdcardNo());
|
|
info.setZCPXH(snInvoice.getBrandModel());
|
|
info.setZMHFZJJ(snInvoice.getCaacDevelopmentFund());
|
|
|
|
if (!"nullnull".equals(snInvoice.getPurchaserAddressPhone())){
|
|
info.setZGFDH(snInvoice.getPurchaserAddressPhone());
|
|
// info.setZGFDH("");
|
|
}
|
|
info.setZXFZH(snInvoice.getSalesBank());
|
|
info.setZJYM(snInvoice.getCheckCode());
|
|
info.setZSJDH(snInvoice.getInspectionListNo());
|
|
// info.setZYGC("");
|
|
info.setZJSHJ(snInvoice.getAmountTax());
|
|
if (snInvoice.getAmountTax() == null && ("17".equals(info.getZFPLX()) || "18".equals(info.getZFPLX()))){
|
|
info.setZJSHJ(snInvoice.getTotalAmount());
|
|
|
|
}
|
|
info.setZCYRMC(snInvoice.getCarrierName());
|
|
info.setZJGDM(snInvoice.getTaxAuthorityNo());
|
|
//时间转换
|
|
info.setZGXSJ(dateString);
|
|
info.setZPJZT("1");
|
|
info.setZZWLX(snInvoice.getSeat());
|
|
info.setZPJLY(snInvoice.getSource());
|
|
if (snInvoice.getSource() == null) {
|
|
info.setZPJLY("1");
|
|
}
|
|
|
|
if ("01".equals(snInvoice.getInvoiceType()) || "02".equals(snInvoice.getInvoiceType()) || "03".equals(snInvoice.getInvoiceType()) || "04".equals(snInvoice.getInvoiceType())
|
|
|| "08".equals(snInvoice.getInvoiceType()) || "10".equals(snInvoice.getInvoiceType()) || "11".equals(snInvoice.getInvoiceType()) || "14".equals(snInvoice.getInvoiceType())
|
|
|| "15".equals(snInvoice.getInvoiceType()) || "31".equals(snInvoice.getInvoiceType()) || "32".equals(snInvoice.getInvoiceType())) {
|
|
//可查验发票,
|
|
info.setZCYZT("1");
|
|
} else {
|
|
//不可查验发票
|
|
info.setZCYZT("3");
|
|
}
|
|
// info.setZCYZT(snInvoice.getCheckStaus());
|
|
// if (snInvoice.getCheckStaus() == null) {
|
|
// info.setZCYZT("1");
|
|
// }
|
|
info.setZCJR("opentext");
|
|
info.setZGXR("opentext");
|
|
info.setZQM("opentext");
|
|
if (snInvoice.getCheckDate() != null) {
|
|
String checkDate = snInvoice.getCheckDate().replace("-", "");
|
|
info.setZCYRQ(checkDate);
|
|
}
|
|
if (snInvoice.getInvoiceCode() != null) {
|
|
info.setZTID(snInvoice.getInvoiceCode() + snInvoice.getInvoiceNumber() + snFplx);
|
|
} else {
|
|
info.setZTID(snInvoice.getInvoiceNumber() + snFplx);
|
|
}
|
|
return info;
|
|
}
|
|
|
|
private String convertToSapType(String invoiceType) {
|
|
|
|
switch (invoiceType) {
|
|
|
|
case "01":// 增值税专用发票
|
|
invoiceType = "10";
|
|
break;
|
|
case "04":
|
|
invoiceType = "11";
|
|
break;
|
|
case "10":
|
|
invoiceType = "12";
|
|
break;
|
|
case "11":
|
|
invoiceType = "13";
|
|
break;
|
|
case "03":
|
|
invoiceType = "14";
|
|
break;
|
|
case "15":
|
|
invoiceType = "15";
|
|
break;
|
|
case "95":
|
|
invoiceType = "16";
|
|
break;
|
|
case "97":
|
|
invoiceType = "17";
|
|
break;
|
|
case "91":
|
|
invoiceType = "18";
|
|
break;
|
|
case "92":
|
|
invoiceType = "19";
|
|
break;
|
|
case "89":
|
|
invoiceType = "20";
|
|
break;
|
|
case "90":
|
|
invoiceType = "21";
|
|
break;
|
|
case "101":
|
|
invoiceType = "22";
|
|
break;
|
|
case "14":
|
|
invoiceType = "24";
|
|
break;
|
|
case "08":
|
|
invoiceType = "25";
|
|
break;
|
|
case "31":
|
|
invoiceType = "26";
|
|
break;
|
|
case "32":
|
|
invoiceType = "27";
|
|
break;
|
|
case "88":
|
|
invoiceType = "28";
|
|
break;
|
|
default:
|
|
invoiceType = "";
|
|
break;
|
|
|
|
}
|
|
return invoiceType;
|
|
|
|
}
|
|
|
|
private String getZSM(String taxRate) {
|
|
|
|
String sm = "";
|
|
|
|
switch (taxRate) {
|
|
// 发票采集
|
|
case "0":
|
|
sm = "J0";
|
|
break;
|
|
case "0.00":
|
|
sm = "J0";
|
|
break;
|
|
case "0.000":
|
|
sm = "J0";
|
|
break;
|
|
case "免税":
|
|
sm = "J0";
|
|
break;
|
|
case "0.16":
|
|
sm = "J1";
|
|
break;
|
|
case "0.13":
|
|
sm = "J2";
|
|
break;
|
|
case "0.10":
|
|
sm = "J3";
|
|
break;
|
|
case "0.09":
|
|
sm = "J4";
|
|
break;
|
|
case "0.06":
|
|
sm = "J5";
|
|
break;
|
|
case "0.05":
|
|
sm = "J6";
|
|
break;
|
|
case "0.03":
|
|
sm = "J7";
|
|
break;
|
|
case "0.02":
|
|
sm = "J8";
|
|
break;
|
|
case "0.01":
|
|
sm = "J9";
|
|
break;
|
|
case "0.17":
|
|
sm = "JC";
|
|
break;
|
|
default:
|
|
sm = "";
|
|
break;
|
|
|
|
}
|
|
return sm;
|
|
}
|
|
|
|
private String getZRZJG(String invoiceCode, String invoiceNo,String FPLX){
|
|
String ZCYJG = "";
|
|
String uuid = invoiceCode+invoiceNo;
|
|
DynamicContextHolder.push(DbConstant.BUSINESS_READ);
|
|
|
|
//可价税分离票种
|
|
//10:增值税专用发票
|
|
//12:增值税电子普通发票
|
|
//13:增值税普通发票(卷票)
|
|
//14:机动车销售统一发票
|
|
//15:二手车销售统一发票
|
|
//24:增值税电子普通发票(通行费)
|
|
//25:增值税电子专用发票
|
|
//26:电子发票(增值税专用发票)
|
|
//27:电子发票(普通发票)
|
|
//22:过路费发票
|
|
//11:增值税普通发票
|
|
//16:定额发票
|
|
//17:机打发票
|
|
//18:出租车发票
|
|
if ("10".equals(FPLX) || "12".equals(FPLX) || "13".equals(FPLX) || "14".equals(FPLX) || "15".equals(FPLX)
|
|
|| "24".equals(FPLX) || "25".equals(FPLX) || "26".equals(FPLX) || "27".equals(FPLX) || "22".equals(FPLX)
|
|
|| "11".equals(FPLX) || "16".equals(FPLX) || "17".equals(FPLX) || "18".equals(FPLX) ) {
|
|
QueryWrapper<TDxInvoiceReimburse> wrapper = new QueryWrapper();
|
|
wrapper.eq("uuid", uuid);
|
|
TDxInvoiceReimburse one = tDxInvoiceReimburseService.getOne(wrapper);
|
|
if (one != null){
|
|
ZCYJG = one.getRzhYesorno();
|
|
}
|
|
|
|
|
|
} else {
|
|
//19:火车票
|
|
//20:客运汽车
|
|
//21:航空运输电子客票行程单
|
|
//28:船票
|
|
//如果是可查验类型,直接更新数据库
|
|
if ( "19".equals(FPLX) || "20".equals(FPLX) || "21".equals(FPLX) || "28".equals(FPLX)) {
|
|
//其他票种
|
|
QueryWrapper<RecordInvoice> wrapper = new QueryWrapper();
|
|
wrapper.eq("uuid", uuid);
|
|
RecordInvoice recordInvoice = recordInvoiceDao.selectOne(wrapper);
|
|
if (recordInvoice != null){
|
|
ZCYJG = recordInvoice.getRzhYesorno();
|
|
}
|
|
|
|
} else {
|
|
//海关缴款书
|
|
QueryWrapper<TdxCustomsRecord> wrapper = new QueryWrapper();
|
|
wrapper.eq("uuid", uuid);
|
|
TdxCustomsRecord tdxCustomsRecord = customsRecordDao.selectOne(wrapper);
|
|
if (tdxCustomsRecord != null){
|
|
ZCYJG = tdxCustomsRecord.getRzhYesorno();
|
|
}
|
|
}
|
|
|
|
}
|
|
return ZCYJG;
|
|
}
|
|
}
|
|
|