diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java index f0f2c5c3..23942001 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java @@ -161,6 +161,7 @@ public class SDNYMainProcessController extends AbstractController { checkInvoiceResult.put("invoiceNo",checkInvoiceResult.getString("invoiceNumber")); checkInvoiceResult.put("company",company); + log.info("返回给影像系统的结果为:{}",checkInvoiceResult); signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName); } diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java index 280d2ec2..f33e3596 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java @@ -103,7 +103,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { return post; } - public String pushInvoiceToRecordInvoice(SNRequestObject snRequestObject,String taxNo,String company) throws Exception { + public String pushInvoiceToRecordInvoice(SNRequestObject snRequestObject, String taxNo, String company) throws Exception { QueryWrapper currentWrapper = new QueryWrapper<>(); currentWrapper.eq("taxno", taxNo); @@ -111,12 +111,11 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { BaseTDxTaxCurrent current = baseTDxTaxCurrentDao.selectOne(currentWrapper); - List invoiceInfoList = snRequestObject.getInvoiceInfoList(); - if(invoiceInfoList != null && invoiceInfoList.size() > 0) { + if (invoiceInfoList != null && invoiceInfoList.size() > 0) { - for(SNInvoice snInvoice : invoiceInfoList) { + for (SNInvoice snInvoice : invoiceInfoList) { String fpdm = snInvoice.getInvoiceCode(); String fphm = snInvoice.getInvoiceNumber(); @@ -160,9 +159,9 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { recordInvoice.setInvoiceType(invoiceType); recordInvoice.setCompany(company); - if(baseTDxRecordInvoice != null) { - baseTDxRecordInvoiceDao.update(recordInvoice,recordWrapper); - }else{ + if (baseTDxRecordInvoice != null) { + baseTDxRecordInvoiceDao.update(recordInvoice, recordWrapper); + } else { baseTDxRecordInvoiceDao.insert(recordInvoice); } } @@ -177,8 +176,8 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { int update = 0; List invoiceInfoList = snRequestObject.getInvoiceInfoList(); - if(invoiceInfoList != null && invoiceInfoList.size() > 0) { - for(SNInvoice snInvoice : invoiceInfoList) { + if (invoiceInfoList != null && invoiceInfoList.size() > 0) { + for (SNInvoice snInvoice : invoiceInfoList) { String fpdm = snInvoice.getInvoiceCode(); String fphm = snInvoice.getInvoiceNumber(); QueryWrapper recordWrapper = new QueryWrapper<>(); @@ -189,7 +188,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { update = baseTDxRecordInvoiceDao.update(recordInvoice, recordWrapper); } - }else{ + } else { String imageId = snRequestObject.getImageId(); QueryWrapper recordWrapper = new QueryWrapper<>(); recordWrapper.eq("image_id", imageId); @@ -236,7 +235,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { return queryInvoiceResult; } - public JSONObject singleCheckInvoice(Map pramsMap) throws Exception{ + public JSONObject singleCheckInvoice(Map pramsMap) throws Exception { //1.封装查验参数 ApiRequest apiRequest = new ApiRequest(); @@ -253,9 +252,9 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { request.setFpje(pramsMap.get("totalAmount")); request.setKprq(pramsMap.get("billingDate")); request.setJym(pramsMap.get("checkCode")); - if("21".equals(snIinvoiceType)){ + if ("21".equals(snIinvoiceType)) { request.setFpzl(snIinvoiceType); - }else { + } else { request.setFpzl(fplxdm); } @@ -270,8 +269,10 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { //4.封装返回参数 JSONObject jsonObject = new JSONObject(); - if (StringUtils.isNoneBlank(apiResponse.getContent())) + if (StringUtils.isNoneBlank(apiResponse.getContent())) { + log.info("查验的结果为:{}", apiResponse.getContent()); jsonObject = convertToSnObject(apiResponse.getContent(), jsonObject, fplxdm); + } return jsonObject; @@ -284,8 +285,17 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { if ("0000".equals(contentMap.get("code"))) { HashMap invoiceData = JSONObject.parseObject(contentMap.get("data").toString(), HashMap.class); - if("0001".equals(invoiceData.get("cyjg"))) { + if ("0001".equals(invoiceData.get("cyjg"))) { try { + + invoiceType = invoiceData.get("fpzl").toString(); + if ("22".equals(invoiceType)) { + invoiceType = "33"; + } + if ("21".equals(invoiceType)) { + invoiceType = "31"; + } + jsonObject.put("invoiceType", invoiceType); jsonObject.put("administrativeDivisionNo", ""); jsonObject.put("administrativeDivisionName", ""); @@ -308,10 +318,10 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { jsonObject.put("salesAddressPhone", invoiceData.get("xhfdzdh")); jsonObject.put("salesBank", invoiceData.get("xhfyhzh")); jsonObject.put("totalAmount", invoiceData.get("fpje")); - if("11".equals(invoiceData.get("fpzl"))){ + if ("11".equals(invoiceData.get("fpzl"))) { jsonObject.put("totalTax", "0"); jsonObject.put("totalAmount", "0"); - }else{ + } else { jsonObject.put("totalTax", invoiceData.get("fpse")); jsonObject.put("totalAmount", invoiceData.get("fpje")); } @@ -337,6 +347,10 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { jsonObject.put("tonnage", invoiceData.get("ccdw")); jsonObject.put("taxAuthorityNo", invoiceData.get("zgswjgdm")); jsonObject.put("taxAuthorityName", invoiceData.get("zgswjgmc")); + if ("03".equals(invoiceData.get("fpzl"))) { + jsonObject.put("administrativeDivisionNo", invoiceData.get("zgswjgdm")); + jsonObject.put("administrativeDivisionName", invoiceData.get("zgswjgmc")); + } jsonObject.put("remarks", invoiceData.get("bz")); jsonObject.put("vehicleType", invoiceData.get("cllx")); jsonObject.put("brandModel", invoiceData.get("cpxh")); @@ -355,7 +369,7 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { } jsonObject.put("zeroTaxRateSign", invoiceData.get("lslbs")); - log.info("零税率标识为:{}",invoiceData.get("lslbs")); + log.info("零税率标识为:{}", invoiceData.get("lslbs")); jsonObject.put("source", ""); jsonObject.put("idcardNo", invoiceData.get("sfzh")); jsonObject.put("buyerIDNum", invoiceData.get("sfzh")); @@ -374,14 +388,26 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { jsonObject.put("taxRecords", invoiceData.get("wspzhm")); jsonObject.put("tonnage", invoiceData.get("dw")); jsonObject.put("limitPeople", invoiceData.get("xcrs")); - - if(invoiceData.get("sl") != null && StringUtils.isNoneBlank(invoiceData.get("sl").toString())) { - String taxRate = invoiceData.get("sl").toString(); - taxRate = "0." + taxRate; - taxRate = taxRate.substring(0,taxRate.length()-1); - log.info("发票税率为:{}",taxRate); + String taxRate = ""; + if ("免税".equals(invoiceData.get("sl"))) { + taxRate = "0"; jsonObject.put("taxRate", taxRate); + } else { + if (invoiceData.get("sl") != null && StringUtils.isNoneBlank(invoiceData.get("sl").toString())) { + taxRate = invoiceData.get("sl").toString(); + if (!"0".equals(taxRate)) { + taxRate = "0." + taxRate; + taxRate = taxRate.substring(0, taxRate.length() - 1); + } + + if ("11".equals(invoiceType)) { + taxRate = "0.000"; + } + log.info("明细-发票税率为:{}", taxRate); + jsonObject.put("taxRate", taxRate); + } } + taxRate = ""; jsonObject.put("limitPeople", invoiceData.get("xcrs")); jsonObject.put("machineNo", invoiceData.get("jqbh")); @@ -409,34 +435,83 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { List> returnDetailList = new ArrayList<>(); JSONArray detailList = (JSONArray) invoiceData.get("detailList"); + for (int i = 0; i < detailList.size(); i++) { + String taxRateDetail = ""; JSONObject detail = (JSONObject) detailList.get(i); Map snDetailMap = new HashMap(); - snDetailMap.put("rowNo", ++i + ""); + 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")); - snDetailMap.put("quantity", detail.getString("spsl")); - snDetailMap.put("unitPrice", detail.getString("bhsdj")); - log.info("明细-unitPrice={}",detail.get("bhsdj")); - snDetailMap.put("amount", detail.getString("je")); - String taxRate = ""; - if(detail.get("sl") != null && StringUtils.isNoneBlank(detail.get("sl").toString())) { - taxRate = detail.get("sl").toString(); - if(!"0".equals(taxRate)) { - taxRate = "0." + taxRate; - taxRate = taxRate.substring(0,taxRate.length()-1); + 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); + int num = Integer.parseInt(taxRateDetail); + if (num > 9) { + taxRateDetail = "0." + taxRateDetail; + } else { + taxRateDetail = "0.0" + taxRateDetail; + } + } + } + } + + if ("11".equals(invoiceType)) { + taxRateDetail = "0.000"; + } + log.info("明细-发票税率为:{}", taxRateDetail); + snDetailMap.put("taxRate", taxRateDetail); } - log.info("明细-发票税率为:{}",taxRate); - jsonObject.put("taxRate", taxRate); } - snDetailMap.put("taxRate", "免税".equals(taxRate) ? "0.00" : detail.getString("sl")); - log.info("明细-taxRate={}",taxRate); - log.info("明细-tax={}",detail.get("se")); - log.info("明细-commodityCode={}",detail.get("ssflbm")); - snDetailMap.put("tax", "***".equals(detail.getString("se")) ? "0.00" : detail.getString("se")); + 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")); @@ -446,12 +521,12 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { } jsonObject.put("invoiceLineList", returnDetailList); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - }else{ - jsonObject.put("cyjg",invoiceData.get("cyjg")); - jsonObject.put("cyjgxx",invoiceData.get("cyjgxx")); + } else { + jsonObject.put("cyjg", invoiceData.get("cyjg")); + jsonObject.put("cyjgxx", invoiceData.get("cyjgxx")); } } else {