jk-GitHub-coder 4 years ago
parent
commit
a2d3a77a45

+ 99 - 45
YijiaRestful/src/main/java/com/platform/yijia/controller/PayController.java

@@ -9,13 +9,13 @@ import com.platform.yijia.pojo.PayOrder;
 import com.platform.yijia.service.AppUserInfoService;
 import com.platform.yijia.service.AppUserInfoService;
 import com.platform.yijia.service.PayOrderService;
 import com.platform.yijia.service.PayOrderService;
 import com.platform.yijia.utils.*;
 import com.platform.yijia.utils.*;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 
 
 @Controller
 @Controller
@@ -362,9 +362,9 @@ public class PayController {
     @RequestMapping(value = "/getCallback", consumes = "application/json", method = RequestMethod.POST)
     @RequestMapping(value = "/getCallback", consumes = "application/json", method = RequestMethod.POST)
     @ResponseBody
     @ResponseBody
     public void getCallback(@RequestBody JSONObject request){
     public void getCallback(@RequestBody JSONObject request){
-
+        logger.info("-------------------------------回调开始----------------------------------------------");
         logger.info("回调返回过来的参数"+request);
         logger.info("回调返回过来的参数"+request);
-        logger.info("ordNo:" + request.get("ordNo").toString());
+        logger.info("ordNo信息:" + request.get("ordNo").toString());
         logger.info("sign信息:" + request.get("sign").toString());
         logger.info("sign信息:" + request.get("sign").toString());
         Gson gson =new Gson();
         Gson gson =new Gson();
 
 
@@ -452,49 +452,103 @@ public class PayController {
         JSONObject req = new JSONObject();
         JSONObject req = new JSONObject();
         System.out.println(resultStr);
         System.out.println(resultStr);
         if (RSASignature.doCheck(resultStr, sign, SXFPaySign.sxfPublic)) {
         if (RSASignature.doCheck(resultStr, sign, SXFPaySign.sxfPublic)) {
-            System.out.println("===================验签成功==============");
             logger.info("验签成功");
             logger.info("验签成功");
             //验签成功,修改订单状态
             //验签成功,修改订单状态
-            PayOrder payOrder = new PayOrder();
-            //payOrder.setOrderId(ordId);
-            payOrder.setOrderNo(ordNo);
-            payOrder.setStatus("1");
-            payOrder.setPayDate(new Date());    //支付时间
-            payOrder.setReceivedAmt(Double.valueOf(settleAmt)); //settleAmt商家入账金额
-            int count = payOrderService.getUpdatePayOrder(payOrder);
-            if(count > 0){
-                req.put("code","success");
-                req.put("msg","修改订单状态成功");
-                logger.info(req.toString());
-                List<PayOrder> list = payOrderService.getPayOrderList(ordNo);
-                logger.info("根据订单号,查询订单"+gson.toJson(list));
-                String sn = "921611605";     //测试打印机 sn:921611605 key:72338zma
-                String content;
-                if(list != null && list.size() == 1){
-                    content = "<CB>支付小票--商户联</CB><BR>";
-                    //content += "--------------------------------<BR>";
-                    content += "订单号:"+list.get(0).getOrderNo()+" <BR>";
-                    content += "时间:"+list.get(0).getCreatedDate().toString()+"<BR>";
-                    content += "油站:"+list.get(0).getStationName()+" 元<BR>";
-                    content += "油品: "+list.get(0).getOilName()+" 元<BR>";
-                    content += "油量: "+list.get(0).getOrderLiters()+" 升<BR>";
-                    content += "单价: "+list.get(0).getOilPirce()+" L/元<BR>";
-                    content += "金额: "+list.get(0).getReceivableAmt().toString()+" 元<BR>";
-                    content += "优惠: "+list.get(0).getDiscountAmt().toString()+" 元<BR>";
-                    content += "支付: "+list.get(0).getDiscountAmt().toString()+" 元<BR>";
-                    content += "--------------------------------<BR>";
-                    content = "<CB>支付小票--顾客联</CB><BR>";
-                    //content += "--------------------------------<BR>";
-                    content += "订单号:"+list.get(0).getOrderNo()+" <BR>";
-                    content += "时间:"+list.get(0).getCreatedDate().toString()+"<BR>";
-                    content += "油站:"+list.get(0).getStationName()+" 元<BR>";
-                    content += "油品: "+list.get(0).getOilName()+" 元<BR>";
-                    content += "油量: "+list.get(0).getOrderLiters()+" 升<BR>";
-                    content += "单价: "+list.get(0).getOilPirce()+" L/元<BR>";
-                    content += "金额: "+list.get(0).getReceivableAmt().toString()+" 元<BR>";
-                    content += "优惠: "+list.get(0).getDiscountAmt().toString()+" 元<BR>";
-                    content += "支付: "+list.get(0).getDiscountAmt().toString()+" 元<BR>";
-                    FeiEPrinterUtil.printReceipt(sn, content);
+            List<PayOrder> list = payOrderService.getPayOrderList(ordNo);
+            logger.info("根据订单号,查询订单"+gson.toJson(list));
+            if (list != null && list.size() == 1) {
+                String status = list.get(0).getStatus();
+                //状态为未支付 0  修改状态为1已支付
+                if (status.equals("0")) {
+                    PayOrder payOrder = new PayOrder();
+                    //payOrder.setOrderId(ordId);
+                    payOrder.setOrderNo(ordNo);
+                    payOrder.setStatus("1");
+                    payOrder.setPayDate(new Date());    //支付时间
+                    payOrder.setReceivedAmt(Double.valueOf(settleAmt)); //settleAmt商家入账金额
+                    //修改订单状态
+                    int count = payOrderService.getUpdatePayOrder(payOrder);
+                    if(count == 1){
+                        req.put("code","success");
+                        req.put("msg","修改订单状态成功");
+                        logger.info(req.toString());
+                        //开始打印
+                        List<PayOrder> listUp = payOrderService.getPayOrderList(ordNo);
+                        String sn = "921611605";     //测试打印机 sn:921611605 key:72338zma
+                        String content1;
+                        String content2;
+                        String orderNoP = "";
+                        String createdDateP ="";
+                        String stationNameP ="";
+                        String oilNameP ="";
+                        String orderLitersP ="";
+                        String oilPirceP ="";
+                        String receivableAmtP = "";
+                        String discountAmtP = "";
+                        String amtP = "";
+                        if(listUp != null && listUp.size() == 1){
+                            logger.info("要打印小票的订单信息:"+ listUp);
+                            if(StringUtils.isNotBlank(listUp.get(0).getOrderNo())){
+                                orderNoP =listUp.get(0).getOrderNo();
+                            }
+                            if(listUp.get(0).getCreatedDate() !=null && listUp.get(0).getCreatedDate().toString() !=""){
+                                //格式化日期
+                                SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                createdDateP =sdf.format(listUp.get(0).getCreatedDate());
+                            }
+                            if(StringUtils.isNotBlank(listUp.get(0).getStationName())){
+                                stationNameP =listUp.get(0).getStationName();
+                            }
+                            if(StringUtils.isNotBlank(listUp.get(0).getOilName())){
+                                oilNameP =listUp.get(0).getOilName();
+                            }
+                            //油价
+                            if(listUp.get(0).getOrderLiters() !=null && listUp.get(0).getOrderLiters() !=""){
+                                orderLitersP =listUp.get(0).getOrderLiters();
+                            }
+                            if(listUp.get(0).getOilPirce() !=null && listUp.get(0).getOilPirce() != "" ){
+                                oilPirceP =listUp.get(0).getOilPirce();
+                            }
+                            if(listUp.get(0).getReceivableAmt() !=null && listUp.get(0).getReceivableAmt().toString() !=""){
+                                receivableAmtP =listUp.get(0).getReceivableAmt().toString();
+                            }
+                            if(listUp.get(0).getDiscountAmt() != null && listUp.get(0).getDiscountAmt().toString() !=""){
+                                discountAmtP =listUp.get(0).getDiscountAmt().toString();
+                            }
+                            if(listUp.get(0).getAmt() !=null && listUp.get(0).getAmt().toString() !=""){
+                                amtP =listUp.get(0).getAmt().toString();
+                            }
+
+                            content1 = "<CB>支付小票--商户联</CB><BR>";
+                            content1 += "订单号:"+orderNoP+"  <BR>";
+                            content1 += "时间:"+createdDateP+" <BR>";
+                            content1 += "油站:"+stationNameP+"  <BR>";
+                            content1 += "油品: "+oilNameP+"  <BR>";
+                            content1 += "油量: "+orderLitersP+"  升<BR>";
+                            content1 += "单价: "+oilPirceP+" L/元<BR>";
+                            content1 += "金额: "+receivableAmtP+" 元<BR>";
+                            content1 += "优惠: "+discountAmtP+" 元<BR>";
+                            content1 += "支付: "+amtP+" 元<BR>";
+                            content1 += "<BR>";
+                            content1 += "--------------------------------<BR>";
+                            content1 += "<BR>";
+
+                            content2 = "<CB>支付小票--顾客联</CB><BR>";
+                            content2 += "订单号:"+orderNoP+" <BR>";
+                            content2 += "时间:"+createdDateP+"<BR>";
+                            content2 += "油站:"+stationNameP+" <BR>";
+                            content2 += "油品: "+oilNameP+" <BR>";
+                            content2 += "油量: "+orderLitersP+" 升<BR>";
+                            content2 += "单价: "+oilPirceP+" L/元<BR>";
+                            content2 += "金额: "+receivableAmtP+" 元<BR>";
+                            content2 += "优惠: "+discountAmtP+" 元<BR>";
+                            content2 += "支付: "+amtP+" 元<BR>";
+                            content2 += "<BR>";
+                            FeiEPrinterUtil.printReceipt(sn, content1 +content2);
+                        }
+
+                    }
+
                 }
                 }
             }
             }
         }else {
         }else {

+ 1 - 1
YijiaRestful/src/main/java/com/platform/yijia/utils/FeiEPrinterUtil.java

@@ -52,7 +52,7 @@ public class FeiEPrinterUtil {
         //拼凑订单内容时可参考如下格式
         //拼凑订单内容时可参考如下格式
         //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
         //根据打印纸张的宽度,自行调整内容的格式,可参考下面的样例格式
 
 
-//        String content;
+        //String content;
 //        content = "<CB>测试打印</CB><BR>";
 //        content = "<CB>测试打印</CB><BR>";
 //        content += "名称      单价  数量 金额<BR>";
 //        content += "名称      单价  数量 金额<BR>";
 //        content += "--------------------------------<BR>";
 //        content += "--------------------------------<BR>";

+ 1 - 1
YijiaRestful/src/main/resources/mapper/PayOrderMapper.xml

@@ -10,7 +10,7 @@
     <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
     <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
     <result column="oil_gun" jdbcType="VARCHAR" property="oilGun" />
     <result column="oil_gun" jdbcType="VARCHAR" property="oilGun" />
     <result column="oil_name" jdbcType="VARCHAR" property="oilName" />
     <result column="oil_name" jdbcType="VARCHAR" property="oilName" />
-    <result column="oil_price" jdbcType="VARCHAR" property="oilPirce" />
+    <result column="oil_pirce" jdbcType="VARCHAR" property="oilPirce" />
     <result column="consumer_id" jdbcType="INTEGER" property="consumerId" />
     <result column="consumer_id" jdbcType="INTEGER" property="consumerId" />
     <result column="consumer" jdbcType="VARCHAR" property="consumer" />
     <result column="consumer" jdbcType="VARCHAR" property="consumer" />
     <result column="amt" jdbcType="DOUBLE" property="amt" />
     <result column="amt" jdbcType="DOUBLE" property="amt" />

+ 40 - 2
YijiaRestful/src/test/java/com/palatform/yijia/YijiaApplicationTests.java

@@ -1,13 +1,51 @@
 package com.palatform.yijia;
 package com.palatform.yijia;
 
 
+import com.platform.yijia.pojo.PayOrder;
+import com.platform.yijia.service.PayOrderService;
+import com.platform.yijia.utils.FeiEPrinterUtil;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest;
 
 
+import javax.annotation.Resource;
+import java.util.List;
+
 @SpringBootTest
 @SpringBootTest
 class YijiaApplicationTests {
 class YijiaApplicationTests {
 
 
+    @Resource
+    private PayOrderService payOrderService;
     @Test
     @Test
-    void contextLoads() {
+    public void contextLoads() {
+        String ordNo = "2546627325194192730676";
+        List<PayOrder> list = payOrderService.getPayOrderList(ordNo);
+        //logger.info("根据订单号,查询订单"+gson.toJson(list));
+        String sn = "921611605";     //测试打印机 sn:921611605 key:72338zma
+        String content;
+        if (list != null && list.size() == 1) {
+            content = "<CB>支付小票--商户联</CB><BR>";
+            //content += "--------------------------------<BR>";
+            content += "订单号:" + list.get(0).getOrderNo() + " <BR>";
+            content += "时间:" + list.get(0).getCreatedDate().toString() + "<BR>";
+            content += "油站:" + list.get(0).getStationName() + " 元<BR>";
+            content += "油品: " + list.get(0).getOilName() + " 元<BR>";
+            content += "油量: " + list.get(0).getOrderLiters() + " 升<BR>";
+            content += "单价: " + list.get(0).getOilPirce() + " L/元<BR>";
+            content += "金额: " + list.get(0).getReceivableAmt().toString() + " 元<BR>";
+            content += "优惠: " + list.get(0).getDiscountAmt().toString() + " 元<BR>";
+            content += "支付: " + list.get(0).getDiscountAmt().toString() + " 元<BR>";
+            content += "--------------------------------<BR>";
+            content = "<CB>支付小票--顾客联</CB><BR>";
+            //content += "--------------------------------<BR>";
+            content += "订单号:" + list.get(0).getOrderNo() + " <BR>";
+            content += "时间:" + list.get(0).getCreatedDate().toString() + "<BR>";
+            content += "油站:" + list.get(0).getStationName() + " 元<BR>";
+            content += "油品: " + list.get(0).getOilName() + " 元<BR>";
+            content += "油量: " + list.get(0).getOrderLiters() + " 升<BR>";
+            content += "单价: " + list.get(0).getOilPirce() + " L/元<BR>";
+            content += "金额: " + list.get(0).getReceivableAmt().toString() + " 元<BR>";
+            content += "优惠: " + list.get(0).getDiscountAmt().toString() + " 元<BR>";
+            content += "支付: " + list.get(0).getDiscountAmt().toString() + " 元<BR>";
+            FeiEPrinterUtil.printReceipt(sn, content);
+        }
     }
     }
-
 }
 }