Ver Fonte

无车 运单号查询发票数据 自己使用不对外-20220808

mashengyi há 2 anos atrás
pai
commit
bc5f4d4d5f

+ 3 - 0
src/main/java/com/jkcredit/invoice/credit/InterfaceCheckServer.java

@@ -281,6 +281,9 @@ public class InterfaceCheckServer {
                     statisRequestIdTimeComp.removeReQuestIdAndTime(requestid);
                 }
                 break;
+            case "WAY_BILL_NUM_FIND_OWNER_INVOICE"://无车  运单号查询发票数据 透传上游
+                result = noCarInterService.noCarVoiceOwnerQuery(appKey,api,data,requestid);
+                break;
             default:
                 result = null;
                 break;

+ 1 - 0
src/main/java/com/jkcredit/invoice/credit/SimpleCORSFilter.java

@@ -66,6 +66,7 @@ public class SimpleCORSFilter implements Filter {
             put( "FIND_NO_SEARCH_NUM" ,  "1");//获取未查询过发票的运单编号
             put( "BALANCE_QUERY" ,  "1");//账号余额查询
             put( "RED_INK_INVOICE_QUERY" ,  "1");//红冲发票查询
+            put( "WAY_BILL_NUM_FIND_OWNER_INVOICE" ,  "1");// 运单号查询发票数据 透传上游,自己使用,不对外
 
 
             //自有车下游客户调用接口

+ 3 - 0
src/main/java/com/jkcredit/invoice/credit/interserver/NoCarInterService.java

@@ -33,4 +33,7 @@ public interface NoCarInterService {
 
     //无车红冲发票查询接口
     DataResult redInkInvoiceQuery(String appKey, String api, String data, String requestid);
+
+    //无车  运单号查询发票数据 自己使用不对外
+    DataResult noCarVoiceOwnerQuery(String appKey, String api, String data, String requestid);
 }

+ 82 - 0
src/main/java/com/jkcredit/invoice/credit/interserver/NoCarInterServiceImpl.java

@@ -937,4 +937,86 @@ public class NoCarInterServiceImpl implements NoCarInterService {
     }
 
 
+
+
+
+    /**
+     * 无车 运单号查询发票数据
+     * @param appKey
+     * @param api
+     * @param data
+     * @return
+     */
+    @Override
+    public DataResult noCarVoiceOwnerQuery(String appKey, String api, String data,String requestid) {
+
+        long costtimestart = System.currentTimeMillis();
+
+        DataResult result = new DataResult();
+
+        result.setData(3);
+        result.setCode(200);
+        result.setRequestid(requestid);
+        result.setMsg("无法认证");
+
+        try {
+            log.info("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] request appKey=" + appKey + " ,api=" + api + " ,data=" +data+ " ,requestid=" +requestid);
+            JSONObject jsonObject = JSONObject.parseObject(data);
+            String num =  jsonObject.getString("num");//运单号 必输
+            if(StringUtils.isEmpty(data)|| null == jsonObject || StringUtils.isEmpty(num)
+
+            ){
+                result.setMsg("有空的必填运单要素,请检查");
+                return  result;
+            }
+
+            NoCarWayBill noCarWayBill1 =null ;
+            try {
+                noCarWayBill1 = noCarWaybillMapper.selectByBillNum(num);
+            }catch (Exception e){
+                log.info("xuyaoshanchuyundannoCarVoiceOwnerQuery:"+num);
+                result.setMsg("平台运单号存在多条,请联系管理员删除无效运单");
+                return result;
+            }
+            if (null == noCarWayBill1){
+                noCarWayBill1 = new NoCarWayBill();
+                noCarWayBill1.setBillNum(num);
+                noCarWayBill1.setInterType(0);
+                noCarWayBill1.setBillwayStatus(-5);
+            }
+            if(noCarWayBill1.getInterType() == 3 || (noCarWayBill1.getBillwayStatus()<2 && noCarWayBill1.getFailReason()!=null && noCarWayBill1.getFailReason().contains("XyWaybillHistoryEnd"))){
+                noCarWayBill1.setBillwayStatus(-5);
+            }
+            noCarWayBill1.setCustomerName(appKey);
+            noCarWayBill1.setCompanyName(noCarWayBill1.getCompanyName());
+
+            noCarWayBill1.setInterType(3);
+
+            RespR rs = noCarService.getInvoiceByWayBillOwnerNumReal(noCarWayBill1,false);
+            long costtimeend = System.currentTimeMillis();
+            log.info("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] result is "
+                    + rs.toString() + ", request is " + data + " ,costtime="
+                    + (costtimeend - costtimestart));
+            if(null != rs && rs.getCode() == 0){
+                result.setData(1);
+                result.setCode(200);
+                result.setMsg(rs.getData().toString());
+                return result;
+            } else {
+                result.setData(3);
+                if("未查得".equals(rs.getMsg())){
+                    result.setData(2);
+                }
+                result.setCode(200);
+                result.setMsg(rs.getMsg());
+                return result;
+            }
+        } catch (Exception e) {
+            log.error("[-NoCarInterServiceImpl.noCarVoiceOwnerQuery-] get httpclient exception is "
+                    + e + ", request is " + data);
+        }
+        return result;
+    }
+
+
 }

+ 8 - 0
src/main/java/com/jkcredit/invoice/service/lowerservice/NoCarService.java

@@ -101,4 +101,12 @@ public interface NoCarService {
      * @return
      */
     RespR monthAccQueryUpdate(MonthAccountQueryVo monthAccountQueryVo);
+
+    /**
+     * 获取发票和运单状态 true 实时 false 走本地 自用,不对外
+     * @param noCarWayBill1
+     * @param b
+     * @return
+     */
+    RespR getInvoiceByWayBillOwnerNumReal(NoCarWayBill noCarWayBill1, boolean b);
 }

+ 149 - 0
src/main/java/com/jkcredit/invoice/service/lowerservice/impl/NoCarServiceImpl.java

@@ -881,4 +881,153 @@ public class NoCarServiceImpl implements NoCarService{
             mounthAccMapper.insert(mounthAcc);
         });
     }
+
+
+    /**
+     * 获取发票和运单状态 true 实时 false 走本地 自用,不对外
+     * @param noCarWayBill
+     * @param isInterface
+     * @return
+     */
+    @Override
+    @Transactional(isolation= Isolation.READ_COMMITTED)
+    public RespR getInvoiceByWayBillOwnerNumReal(NoCarWayBill noCarWayBill, boolean isInterface) {
+        byte isKf = 1;
+        /**
+         * 迁移数据
+         */
+        if(noCarWayBill.getInterType() == 3){
+            isKf = 3;
+        }
+        /**
+         * 特殊处理数据
+         */
+        if(noCarWayBill.getInterType() == 5){
+            isKf = 5;
+        }
+        log.info("取票啦:NoCarServiceImpl.getInvoiceByWayBillOwnerNumReal{},isCurr{}",noCarWayBill,isInterface);
+        if(isInterface && (noCarWayBill.getBillwayStatus()!=-5 || noCarWayBill.getInterType() == 4)){
+            if(noCarWayBill.getBillwayStatus() == 1 || noCarWayBill.getBillwayStatus() == 2 || noCarWayBill.getBillwayStatus() == 3 || noCarWayBill.getBillwayStatus() == 4){
+                //直接返回发票信息
+                List<BillInvoice> billInvoices = billInvoiceMapper.selectByBillNum(noCarWayBill.getBillNum());
+                WaybillNumFindInvoiceResponse waybillNumFindInvoiceResponse = buildInterFaceVoiceData(noCarWayBill,billInvoices);
+                return new RespR(waybillNumFindInvoiceResponse);
+            }else{
+                return new RespR(false,noCarWayBill.getFailReason()==null?"运单未知异常":noCarWayBill.getFailReason());
+            }
+        }
+        if(noCarWayBill.getBillwayStatus()!=2 && noCarWayBill.getBillwayStatus()!=-5){
+            return new RespR(false,"不是开票中的状态,别取票啦");
+        }
+      //  RespR respR = checkCarWayBillAndSetInfo(noCarWayBill);
+     //   if(respR.getCode() == 1){
+      //      log.info("取票失败啦:NoCarServiceImpl.getInvoiceByWayBillOwnerNumReal{},isCurr{},msg{}",noCarWayBill,isInterface,respR.getMsg());
+      //      return  respR;
+      //  }
+
+        //进行取票操作
+        WaybillNumFindInvoiceRequest waybillNumFindInvoiceRequest = new WaybillNumFindInvoiceRequest();
+        String companyNum = paramService.getParamsByParamName("REQUEST_COMPANY_NUM").getParamValue();
+        waybillNumFindInvoiceRequest.setCompanyNum(companyNum);
+        waybillNumFindInvoiceRequest.setWaybillNum(noCarWayBill.getBillNum());
+        RespR<WaybillNumFindInvoiceResponse> responseRespR = noCarInterface.waybillNumFindInvoice(waybillNumFindInvoiceRequest);
+        if(responseRespR.getCode() == 1){
+            log.info("取票失败啦:NoCarServiceImpl.getInvoiceByWayBillOwnerNumReal{},isCurr{},msg{}",noCarWayBill,isInterface,responseRespR.getMsg());
+            return new RespR(false,responseRespR.getMsg());
+        }else{
+            int tempStatus = responseRespR.getData().getWaybillStatus().intValue();
+            if(noCarWayBill.getBillwayStatus()==-5){
+                if(isKf != 3){
+                    noCarWayBill.setInterType(0);
+                }else{
+                    if(tempStatus == 3){
+                        noCarWayBill.setInterType(4);
+                    }
+                }
+                noCarWayBill.setPlateNum(responseRespR.getData().getPlateNum());
+                noCarWayBill.setStartTime(DateUtil.tTimeToDate(responseRespR.getData().getWaybillStartTime()));
+                noCarWayBill.setPredictEndTime(DateUtil.tTimeToDate(responseRespR.getData().getWaybillEndTime()));
+                //更改票状态
+                noCarWayBill.setBillwayStatus(tempStatus);
+                insertOrUpdateBill(noCarWayBill);
+
+            }else {
+                //更改票状态
+                noCarWayBill.setPlateNum(responseRespR.getData().getPlateNum());
+                noCarWayBill.setStartTime(DateUtil.tTimeToDate(responseRespR.getData().getWaybillStartTime()));
+                noCarWayBill.setPredictEndTime(DateUtil.tTimeToDate(responseRespR.getData().getWaybillEndTime()));
+                noCarWayBill.setBillwayStatus(tempStatus);
+                noCarWayBill.setUpdateTime(DateUtil.getCurrentDateStr());
+                noCarWaybillMapper.updateByBillNum(noCarWayBill);
+            }
+
+            if(tempStatus == 2 || tempStatus==3){
+                //删除已有发票
+                billInvoiceMapper.deleteByBillNum(noCarWayBill.getBillNum());
+                //发票入库
+                List<InvoiceProcessingListModel> invoiceProcessingListModels = responseRespR.getData().getResult();
+                //用set来去重计费信息
+                Set<NoCarCalculateInfor> carCalculateInfors = new HashSet<>();
+                invoiceProcessingListModels.stream().forEach(invoiceProcessingListModel -> {
+                    log.info("44444getInvoiceByWayBillOwnerNumReal{}",invoiceProcessingListModel.getTransactionId());
+                    BillInvoice billInvoice = buildFromInvoiceProcessingListModel(invoiceProcessingListModel);
+                    billInvoice.setCompanyName(noCarWayBill.getCompanyName());
+                    billInvoice.setCompanyNum(noCarWayBill.getCompanyNum());
+                    billInvoice.setCustomerName(noCarWayBill.getCustomerName());
+                    //扣费明细入账
+                    NoCarCalculateInfor calculateInfor = new NoCarCalculateInfor();
+                    if(noCarWayBill.getInterType()!=4 && noCarWayBill.getInterType()!=3){
+                        calculateInfor.setCalculateTime(DateUtil.getCurrentDateStr());
+                    }else{
+                        calculateInfor.setCalculateTime("2021-01-11 00:00:00");
+                    }
+
+                    calculateInfor.setCompanyNum(noCarWayBill.getCompanyNum());
+                    calculateInfor.setCtype(1);
+                    calculateInfor.setCustomId(noCarWayBill.getCustomerName());
+                    calculateInfor.setBuyerName(invoiceProcessingListModel.getBuyerName());
+                    calculateInfor.setBuyerTaxpayerCode(invoiceProcessingListModel.getBuyerTaxpayerCode());
+                    calculateInfor.setInvoiceMakeTime(billInvoice.getInvoiceMakeTime());
+                    calculateInfor.setTradeId(billInvoice.getTransactionId());
+                    NoCarCalculateInfor noCarCalculateInfor = calculateInforMapper.selectByTradeId(billInvoice.getTransactionId());
+                    if(noCarCalculateInfor!=null){
+                        billInvoice.setCalculateTime(noCarCalculateInfor.getCalculateTime());
+                    }else{
+                        carCalculateInfors.add(calculateInfor);
+                        billInvoice.setCalculateTime(calculateInfor.getCalculateTime());
+                    }
+                    billInvoiceMapper.insert(billInvoice);
+                });
+                log.info("6666666getInvoiceByWayBillOwnerNumReal{}",noCarWayBill.getBillNum());
+                if(isKf == 3)
+                    return new RespR(responseRespR.getData());
+                //统一插入交易id 和 和计费信息
+                Param param = paramService.getParamsByParamName("CUST_NOCAR_FEE");
+                Double fee = Double.parseDouble(param.getParamValue());
+                Customer customer = customerMapper.selectByCustomerNameForLock(noCarWayBill.getCustomerName());
+                customer.setInvoiceTime(DateUtil.getCurrentDateStr());
+                carCalculateInfors.stream().forEach(calculateInfor -> {
+                    try {
+                        calculateInfor.setCompanyLongName(customer.getCompany());
+                        calculateInfor.setFee(fee);
+                        calculateInforMapper.insert(calculateInfor);
+                        customer.setAccountBalance(MathUtil.sub(customer.getAccountBalance(),calculateInfor.getFee()));
+                    }catch (Exception e){
+                        log.error("重复数据来啦getInvoiceByWayBillOwnerNumReal"+calculateInfor.getTradeId());
+                    }
+
+
+                });
+                if(isKf==1)
+                    customerMapper.updateByPrimaryKeySelective(customer);
+
+            }
+            if(true){
+                log.info("10000000000getInvoiceByWayBillOwnerNumReal{}",noCarWayBill.getBillNum());
+                return new RespR(responseRespR.getData());
+            }
+        }
+        log.info("99999999getInvoiceByWayBillOwnerNumReal{}",noCarWayBill.getBillNum());
+        return new RespR("success");
+    }
 }