Browse Source

定时任务

Administrator 2 years ago
parent
commit
24810e0ce7

+ 3 - 1
mhotel/src/com/happy/Until/weixin/JaxbUtil.java

@@ -159,6 +159,8 @@ public class JaxbUtil {
             }
         }
         sb.append("</xml>");
-        return new String(sb.toString().toString().getBytes(), "utf-8");
+
+        return sb.toString();
+//        return new String(sb.toString().toString().getBytes(), "utf-8");
     }
 } 

+ 44 - 1
mhotel/src/com/happy/action/AppBookingAction.java

@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedReader;
 import java.io.PrintWriter;
+import java.text.ParseException;
 import java.util.*;
 
 /**
@@ -126,6 +127,46 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         this.status = status;
     }
 
+    /**
+     * 定时任务
+     * @return
+     */
+    public String scheduledTasks()
+    {
+        // 获取所有的订单待支付状态
+        StringBuffer strSqlBook = new StringBuffer();
+        strSqlBook.append(" and order_status = '").append(PayEnum.ONE.getNum()).append("' ");
+        List<Booking> bookingList = bookService.queryList(strSqlBook.toString());
+        if (bookingList == null || bookingList.size() <= 0){
+            return null;
+        }
+
+        try {
+            for (Booking booking: bookingList) {
+                if (booking == null  || Func.checkNull(booking.getCreateTime()) || Func.checkNull(booking.getLockTime()))
+                    continue;
+
+                // 对订单时间进行累加
+                String lockTime = TimeExchange.TimeRangeM(booking.getCreateTime(),Func.parseInt(booking.getLockTime()));
+                boolean flag = TimeExchange.CompareDate(lockTime,TimeExchange.getDate());
+                if (flag)
+                {
+                    // 如果超时,则将订单状态修改为已超时
+                    booking.setOrderStatus(Func.parseStr(PayEnum.SIX.getPayStatus()));
+                    booking.setUpdateTime(TimeExchange.getDate());
+                    bookService.updateBooking(booking);
+                    System.out.println("已将订单"+booking.getOrderNum()+"标识为支付超时");
+                }
+            }
+
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+
 
     /**
      * houseId; // 房型id
@@ -565,6 +606,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         try {
             // 支付费用
             int totalPrice = (int) booking.getHouseTotalPrice();
+            int totalfee = (int) (totalPrice * 100);
+
             WechatUnifiedOrder w = new WechatUnifiedOrder();
             w.setAppid(WeiXinUtil.appid_c);
             w.setAttach("chuanghai");
@@ -576,7 +619,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             String orderNo = booking.getOrderNum(); // 订单编号
             w.setOut_trade_no(orderNo);
             w.setSpbill_create_ip(WeiXinUtil.ip);
-            w.setTotal_fee(totalPrice);
+            w.setTotal_fee(totalfee);
             w.setTrade_type("JSAPI");
             Map<String, String> params = new HashMap<String, String>();
             params.put("attach", w.getAttach());