Browse Source

自动接单

夏文涛 2 years ago
parent
commit
82550a56ab

+ 13 - 0
mhotel/src/com/happy/Model/Hotel.java

@@ -159,6 +159,11 @@ public class Hotel {
 	private String managerPhone;
 
 	/**
+	 * 乡镇ID
+	 */
+	private String hotelTownship;
+
+	/**
 	 * 关联商家所属乡镇
 	 */
 	private String hotelTownshipName;
@@ -478,4 +483,12 @@ public class Hotel {
 	public void setCancelTime(String cancelTime) {
 		this.cancelTime = cancelTime;
 	}
+
+	public String getHotelTownship() {
+		return hotelTownship;
+	}
+
+	public void setHotelTownship(String hotelTownship) {
+		this.hotelTownship = hotelTownship;
+	}
 }

+ 131 - 76
mhotel/src/com/happy/action/AppBookingAction.java

@@ -30,9 +30,11 @@ import java.io.BufferedReader;
 import java.io.PrintWriter;
 import java.math.BigDecimal;
 import java.text.ParseException;
+import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -160,30 +162,29 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
     /**
      * 定时任务
+     *
      * @return
      */
-    public String scheduledTasks()
-    {
+    public String scheduledTasks() {
         // 获取所有的订单待支付状态
         StringBuffer strSqlBook = new StringBuffer();
         strSqlBook.append(" and order_status = '").append(PayEnum.待支付.getNum()).append("' ");
         List<Booking> bookingList = bookService.queryList(strSqlBook.toString());
-        if (bookingList == null || bookingList.size() <= 0){
+        if (bookingList == null || bookingList.size() <= 0) {
             return null;
         }
 
         try {
-            for (Booking booking: bookingList) {
-                if (booking == null  || Func.checkNull(booking.getCreateTime()) || Func.checkNull(booking.getLockTime()))
+            for (Booking booking : bookingList) {
+                if (booking == null || Func.checkNull(booking.getCreateTime()) || Func.checkNull(booking.getLockTime()))
                     continue;
 
-                Date createTime = DateUtil.parseDate(booking.getCreateTime(),DateUtil.Time_Formatter_Second);
+                Date createTime = DateUtil.parseDate(booking.getCreateTime(), DateUtil.Time_Formatter_Second);
                 // 对订单时间进行累加
-                String lockTime = TimeExchange.TimeRangeM(DateUtil.getFormatPaternDate(createTime),Func.parseInt(booking.getLockTime()));
+                String lockTime = TimeExchange.TimeRangeM(DateUtil.getFormatPaternDate(createTime), Func.parseInt(booking.getLockTime()));
                 // 当前时间 大于 锁定时间 为true  且支付状态
                 boolean flag = TimeExchange.CompareDate(lockTime, TimeExchange.getDate());
-                if (flag)
-                {
+                if (flag) {
                     // 如果超时,则将订单状态修改为已超时
                     booking.setOrderStatus(Func.parseStr(PayEnum.支付超时.getNum()));
                     booking.setUpdateTime(TimeExchange.getDate());
@@ -195,7 +196,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                     // 将状态修改为已超时订单时,写入数据操作
                     bookinglogService.addBooklog(OrderEnum.将订单设置为已超时.toString(), booking);
 
-                    System.out.println("已将订单"+booking.getOrderNum()+"标识为支付超时");
+                    System.out.println("已将订单" + booking.getOrderNum() + "标识为支付超时");
                 }
             }
 
@@ -208,13 +209,12 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
     /**
      * 进行更新数据将订单状态修改为已超时。
+     *
      * @return
      */
-    public String updateOrderStatus()
-    {
+    public String updateOrderStatus() {
         JSONObject jsonObject = new JSONObject();
-        if (Func.checkNull(bookingId))
-        {
+        if (Func.checkNull(bookingId)) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.message, "未传入bookingId---updateOrderStatus");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
@@ -223,20 +223,19 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
         try {
             Booking booking = bookService.getById(Func.parseInt(bookingId));
-            Date createTime = DateUtil.parseDate(booking.getCreateTime(),DateUtil.Time_Formatter_Second);
+            Date createTime = DateUtil.parseDate(booking.getCreateTime(), DateUtil.Time_Formatter_Second);
             // 对订单时间进行累加
             String lockTime = TimeExchange.TimeRangeM(DateUtil.getFormatPaternDate(createTime), Func.parseInt(booking.getLockTime()));
             // 当前时间 大于 锁定时间 为true  且支付状态
             boolean flag = TimeExchange.CompareDate(lockTime, TimeExchange.getDate());
-            if (flag)
-            {
+            if (flag) {
                 // 如果超时,则将订单状态修改为已超时
                 booking.setOrderStatus(Func.parseStr(PayEnum.支付超时.getNum()));
                 booking.setUpdateTime(TimeExchange.getDate());
                 bookService.updateBooking(booking);
 
                 // 将状态修改为已超时订单时,写入数据操作
-                bookinglogService.addBooklog(OrderEnum.将订单设置为已超时.toString(),booking);
+                bookinglogService.addBooklog(OrderEnum.将订单设置为已超时.toString(), booking);
 
                 List<HotelCouponStatus> list = hotelCoupomStatusService.getBookingId(booking.getId() + "");
                 if (list != null && list.size() > 0) {
@@ -246,7 +245,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 System.out.println("已将订单" + booking.getOrderNum() + "标识为支付超时");
 
                 jsonObject.put(B.code, ResultStatusCode.OK.getStatus());
-                jsonObject.put(B.message, "已将订单"+booking.getOrderNum()+"标识为支付超时");
+                jsonObject.put(B.message, "已将订单" + booking.getOrderNum() + "标识为支付超时");
                 ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             }
         } catch (ParseException e) {
@@ -282,7 +281,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         String endDate = DateUtil.parseDateToStr((Func.parseDate(endTime)), DateUtil.Time_Formatter_Day);
 
         // 创建订单之前,先验证是否有房间
-        String backMessage = appBookService.varificationHouse(houseId, startDate, endDate,houseOrderNumber);
+        String backMessage = appBookService.varificationHouse(houseId, startDate, endDate, houseOrderNumber);
         if (!Func.checkNull(backMessage)) {
             jsonObject.put(B.code, ResultStatusCode.CANNTBOOKING.getStatus());
             jsonObject.put(B.message, backMessage);
@@ -310,7 +309,8 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     /**
      * bookingId 订单id
      * 商家在已支付,待入住时点退单 ,进入退款流程后退单
-     *    在已入住,时点退单,进入退款流程后退款
+     * 在已入住,时点退单,进入退款流程后退款
+     *
      * @return
      */
     public String chargeback() throws Exception {
@@ -325,8 +325,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
         //1待支付,2已支付,3待入住,4已入住,5已消费,6支付超时,7已取消,8已退单,9已退款,10退款中
         int status = Func.parseInt(book.getOrderStatus());
-        if (status == PayEnum.待支付.getNum())
-        {
+        if (status == PayEnum.待支付.getNum()) {
             book.setOrderStatus(Func.parseStr(PayEnum.已取消.getNum())); // 如果在1待支付情况,用户点击取消订单按钮,后台直接修改取消订单操作
             book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
             bookService.updateBooking(book);
@@ -343,8 +342,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             jsonObject.put(B.message, ResultStatusCode.OK.getMsg());
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
             return null;
-        }else if (status == PayEnum.已支付.getNum() || status == PayEnum.待入住.getNum())
-        {
+        } else if (status == PayEnum.已支付.getNum() || status == PayEnum.待入住.getNum()) {
             book.setOrderStatus(Func.parseStr(PayEnum.退款中.getNum())); // 如果在2已支付,3待入住 情况,商家点击取消订单按钮,后台先修改状态为退款中,然后走退款流程
             book.setRemake(Func.parseStr(PayEnum.已退单.getPayStatus()));
             List<HotelCouponStatus> list = hotelCoupomStatusService.getBookingId(book.getId() + "");
@@ -365,7 +363,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             book.setRefundWay(OrderEnum.微信退款.toString());
         }
 
-        jsonObject = refundMethod(book,users.getOpenid());
+        jsonObject = refundMethod(book, users.getOpenid());
         ResUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
     }
@@ -390,7 +388,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
         // 取消订单,修改订单的支付状态
         Booking book = bookService.getById(Func.parseInt(bookingId));
-        if (book == null ) {
+        if (book == null) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
             jsonObject.put(B.message, "未获取到订单信息,请重新查询");
             ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
@@ -450,7 +448,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         // 退款操作
         book.setRemake(Func.parseStr(PayEnum.已取消.getPayStatus()));
         book.setRefundWay(OrderEnum.微信退款.toString());
-        jsonObject = refundMethod(book,users.getOpenid());
+        jsonObject = refundMethod(book, users.getOpenid());
         jsonObject.put(B.data, book);
         ResponseUtil.writeJson(ServletActionContext.getResponse(), jsonObject.toString());
         return null;
@@ -458,13 +456,14 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
     /**
      * 退款方法
+     *
      * @param book
      * @param open_id
      * @return
      * @throws Exception
      */
-    public JSONObject refundMethod(Booking book,String open_id) throws Exception {
-        JSONObject  jsonObject  = new JSONObject();
+    public JSONObject refundMethod(Booking book, String open_id) throws Exception {
+        JSONObject jsonObject = new JSONObject();
         if (book == null || Func.checkNull(open_id)) {
             jsonObject.put("code", 400);
             jsonObject.put("message", "未传入book和open_id数据---refundMethod");
@@ -496,7 +495,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         params.put("notify_url", w.getNotify_url());
         params.put("out_refund_no", w.getOut_refund_no());   // 退款单号
         params.put("out_trade_no", w.getOut_trade_no());
-        params.put("refund_fee",w.getRefund_fee()+"");  // 退款金额
+        params.put("refund_fee", w.getRefund_fee() + "");  // 退款金额
         params.put("total_fee", w.getTotal_fee() + "");
 
         w.setSign(PayWxUtil.getSign(params, WeiXinUtil.key));
@@ -508,10 +507,10 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 "<nonce_str>" + w.getNonce_str() + "</nonce_str>" +
                 "<notify_url>" + w.getNotify_url() + "</notify_url>" +
                 "<out_refund_no>" + w.getOut_refund_no() + "</out_refund_no>" +
-                "<out_trade_no>" + w.getOut_trade_no() + "</out_trade_no>"	+
-                "<refund_fee>" + w.getRefund_fee()+"" + "</refund_fee>" +
+                "<out_trade_no>" + w.getOut_trade_no() + "</out_trade_no>" +
+                "<refund_fee>" + w.getRefund_fee() + "" + "</refund_fee>" +
                 "<total_fee>" + w.getTotal_fee() + "" + "</total_fee>" +
-                "<sign>" + w.getSign() + "</sign>"	+
+                "<sign>" + w.getSign() + "</sign>" +
                 "</xml>";
         //String msg = HttpsClient.sendPost2("https://api.mch.weixin.qq.com/secapi/pay/refund", retXml);
         String msg = HttpUtils.post2("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
@@ -523,10 +522,10 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         }
         // 设置订单状态为退款中
         book.setOrderStatus(Func.parseStr(PayEnum.退款中.getNum()));
-        book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+        book.setUpdateTime(DateUtil.parseDateToStr(new Date(), DateUtil.Time_Formatter_Second));
         bookService.updateBooking(book);  // 退款中
         // 用户在待支付状态下取消了订单时,写入数据操作
-        bookinglogService.addBooklog("用户在取消了订单,正进入退款流程",book);
+        bookinglogService.addBooklog("用户在取消了订单,正进入退款流程", book);
         jsonObject.put("code", 200);
         jsonObject.put("message", "申请已提交,请稍候查询");
         return jsonObject;
@@ -625,7 +624,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
         StringBuffer strSqlBook = new StringBuffer();
         strSqlBook.append(" and order_status = '").append(PayEnum.退款中.getNum()).append("' ");
         List<Booking> booking = bookService.queryList(strSqlBook.toString());
-        if (booking==null){
+        if (booking == null) {
             return null;
         }
         WechatUnifiedOrder w = new WechatUnifiedOrder();
@@ -653,21 +652,21 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             params.put("sign", w.getSign());
             String retXml = JaxbUtil.getRequestXml(params);
             String msg = HttpUtils.post("https://api.mch.weixin.qq.com/pay/refundquery", retXml);
-            if (msg.indexOf("<refund_status_0><![CDATA[SUCCESS]]></refund_status_0>")>0) {
+            if (msg.indexOf("<refund_status_0><![CDATA[SUCCESS]]></refund_status_0>") > 0) {
                 //退款的数据删除一下房态删除
                 String sql = " and booking_id = " + book.getId();
                 List<HouseNumberStatus> houseNumberStatuse = houseNumberStatusService.getList(sql);
                 houseNumberStatusService.updateHouseNumberStatus(String.valueOf(book.getId()));
 
                 // 退款成功,将数据写入本地数据库
-                book.setRefundTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+                book.setRefundTime(DateUtil.parseDateToStr(new Date(), DateUtil.Time_Formatter_Second));
                 book.setRefundAmount(book.getHouseTotalPrice());
-                book.setUpdateTime(DateUtil.parseDateToStr(new Date(),DateUtil.Time_Formatter_Second));
+                book.setUpdateTime(DateUtil.parseDateToStr(new Date(), DateUtil.Time_Formatter_Second));
                 book.setOrderStatus(Func.parseStr(PayEnum.getKeyByValue(book.getRemake()))); // 将走微信前的标识,写入回调函数
                 bookService.updateBooking(book);
 
                 // 退款成功后,写入数据操作
-                bookinglogService.addBooklog("用户在取消了订单,已退款成功,退款金额是" + book.getRefundAmount()  ,book);
+                bookinglogService.addBooklog("用户在取消了订单,已退款成功,退款金额是" + book.getRefundAmount(), book);
 
                 // 发送成功消息给商家和用户
                 AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
@@ -675,14 +674,14 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 String sendMsg = book.getRemake();
                 // 推给用户(需求确定,用户点取消退款以后[标识订单状态已取消]只发商家,不发用户。  商家点拒单以后[标识订单状态已退单]只发用户不发商家)
                 int status = Func.parseInt(book.getOrderStatus());
-                if (status == PayEnum.已退单.getNum()){
-                    Message.send(users.getOpenid(),book.getHotelName(),book.getOrderStatus(), book.getOrderStartTime(),book.getOrderEndTime(), book.getHouseName());
+                if (status == PayEnum.已退单.getNum()) {
+                    Message.send(users.getOpenid(), book.getHotelName(), book.getOrderStatus(), book.getOrderStartTime(), book.getOrderEndTime(), book.getHouseName());
                 }
 
                 // 推给商家
-                String live_end = book.getOrderStartTime().substring(0,10)  +"~"+  book.getOrderEndTime().substring(0,10);
+                String live_end = book.getOrderStartTime().substring(0, 10) + "~" + book.getOrderEndTime().substring(0, 10);
                 String hotelName = Func.checkNull(book.getHotelName()) ? book.getHotelName() : book.getHouseName();
-                if (status ==  PayEnum.已取消.getNum()) {
+                if (status == PayEnum.已取消.getNum()) {
                     Message2.send(adminManager.getOpenid(), book.getHotelType(), book.getHouseName(), live_end, book.getUserName(), hotelName, Func.parseStr(book.getId()));
                 }
             }
@@ -743,7 +742,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             return null;
         }
 
-        String backMessage = appBookService.varificationHouse(houseId, startTime, endTime,houseOrderNumber);
+        String backMessage = appBookService.varificationHouse(houseId, startTime, endTime, houseOrderNumber);
 
         if (!Func.checkNull(backMessage)) {
             jsonObject.put(B.code, ResultStatusCode.BAD_REQUEST.getStatus());
@@ -786,7 +785,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
 
         try {
             // 支付费用
-            double totalPrice = booking.getHouseTotalPrice() ;
+            double totalPrice = booking.getHouseTotalPrice();
             int totalfee = Func.parseInt(totalPrice * 100);
 
             WechatUnifiedOrder w = new WechatUnifiedOrder();
@@ -852,8 +851,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 bookService.updateBooking(booking);
 
                 //用户开启支付,写入数据操作
-                bookinglogService.addBooklog("用户点击订单,进行支付"  ,booking);
-
+                bookinglogService.addBooklog("用户点击订单,进行支付", booking);
 
 
                 resultjson.put(B.code, ResultStatusCode.OK.getStatus());
@@ -870,13 +868,12 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
 
     /**
-     *  支付成功后回调,推送消息给商家
-     *
+     * 支付成功后回调,推送消息给商家
      */
-    public String payResulet(){
+    public String payResulet() {
         System.out.println("进入支付回调====");
         JSONObject resultjson = new JSONObject();
-        try{
+        try {
             BufferedReader reader = null;// BufferedReader 字符输入流
             reader = request.getReader();
             String line = "";
@@ -890,10 +887,10 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
             JaxbUtil requestBinder = new JaxbUtil(PayResult.class, PayResult.class);
             PayResult result = requestBinder.fromXml(xmlString);// Xml到Java,用fromXML()方法
             String order_num = result.getOut_trade_no();
-            System.out.println("支付成功回调,订单号:"+order_num);
+            System.out.println("支付成功回调,订单号:" + order_num);
             Booking book = bookService.queryByOrder(order_num);
             // 支付成功
-            if (result.getResult_code().equals("SUCCESS") && book!=null && ("1").equals(book.getOrderStatus())) {
+            if (result.getResult_code().equals("SUCCESS") && book != null && ("1").equals(book.getOrderStatus())) {
 
                 // 保存支付信息
                 book.setUpdateTime(DateUtil.getFormatPaternDate(new Date()));
@@ -901,33 +898,93 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 book.setPayTime(DateUtil.getFormatPaternDate(new Date()));
                 book.setPayWay(OrderEnum.微信支付.toString());
                 // 进行业务判断,如果是商家设定了自动接单,则支付状态直接变为待入住  接单设置(1自动接单 2手动接单)
-				//目前该自动接单逻辑无法与定时的自动接单操作衔接特此屏蔽 后续可以直接删除
-//                if ("1".equals(book.getHotelIsOrder()))
-//                {
-//                    // 自动接单,订单状态修改为待入住
-//                    book.setOrderStatus(Func.parseStr(PayEnum.待入住.getNum()));
-//                    String userId = book.getCreateUserid();
-//                    Users users = userService.queryByUserId(userId);
-//                    String mess = "您已成功订房,订单号:"+order_num;
-//                    Message.send(users.getOpenid(),book.getHotelName(),book.getOrderStatus(), book.getOrderStartTime(),book.getOrderEndTime(), book.getHouseName());
-//                }
+                //目前付完钱之后如果是设置的自动接单就进行自动接单
+                if ("1".equals(book.getHotelIsOrder())) {
+                    AtomicInteger n = new AtomicInteger();
+                    String userId = book.getCreateUserid();
+                    Users users = userService.queryByUserId(userId);
+                    String mess = "您已成功订房,订单号:" + order_num;
+                    Message.send(users.getOpenid(), book.getHotelName(), book.getOrderStatus(), book.getOrderStartTime(), book.getOrderEndTime(), book.getHouseName());
+
+                    System.out.println("手动接单定时程序5");
+                    List<HouseNumberStatus> list = new ArrayList<>();
+                    //不可入住的房间
+                    List<HouseNumber> houseNumbers = houseNumberService.queryHouseStatus(book);
+                    //所有房间
+                    List<HouseNumber> houseNumberList = houseNumberService.queryByHouseId(book.getHouseId());
+                    AtomicInteger i = new AtomicInteger();
+                    List<String> Ids = new ArrayList<>();
+                    if (houseNumbers != null) {
+                        houseNumberList.forEach(houseNumber -> {
+                            //添加的房间不在不可添加的房间当中并且数量小于订房总数
+                            if (!houseNumbers.contains(houseNumber) && i.get() < book.getHouseOrderNumber()) {
+                                Ids.add(houseNumber.getId());
+                                i.getAndIncrement();
+                            }
+                        });
+                    } else {
+                        //所有房间都可以预定
+                        houseNumberList.forEach(houseNumber -> {
+                            //添加的房间不在不可添加的房间当中并且数量小于订房总数
+                            if (i.get() < book.getHouseOrderNumber()) {
+                                Ids.add(houseNumber.getId());
+                                i.getAndIncrement();
+                            }
+                        });
+                    }
+
+                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                    DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                    LocalDateTime str = LocalDateTime.parse(book.getOrderStartTime(), inputFormatter);
+                    LocalDateTime end = LocalDateTime.parse(book.getOrderEndTime(), inputFormatter);
+                    String a = str.format(formatter);
+                    String B = end.format(formatter);
+                    LocalDate strDate = LocalDate.parse(a, formatter);
+                    LocalDate endDate = LocalDate.parse(B, formatter);
+                    Date now = null;
+                    try {
+                        now = DateUtil.formateDate(DateUtil.getCurrentDate(), DateUtil.Time_Formatter_Second);
+                    } catch (ParseException e) {
+                        throw new RuntimeException(e);
+                    }
+                    for (String number : Ids) {
+                        for (LocalDate date = strDate; !date.isAfter(endDate.minusDays(1)); date = date.plusDays(1)) {
+                            HouseNumberStatus houseNumberStatus = new HouseNumberStatus();
+                            houseNumberStatus.setNumberId(number);
+                            houseNumberStatus.setId(String.valueOf(UUID.randomUUID()));
+                            houseNumberStatus.setCreateDate(now);
+                            houseNumberStatus.setModifyDate(now);
+                            houseNumberStatus.setRemark("");
+                            houseNumberStatus.setBookingId(String.valueOf(book.getId()));
+                            houseNumberStatus.setSetDate(date.format(formatter));
+                            houseNumberStatus.setStatus(5);//状态(0删除 1.正常 2.关房 3.脏房 4.净房 5.预定 6.入住)
+                            list.add(houseNumberStatus);
+                        }
+                    }
+                    int m = houseNumberStatusService.saveBatch(list);
+                    if (m > 0) {
+                        n.getAndIncrement();
+                        // 自动接单,订单状态修改为待入住
+                        book.setOrderStatus(Func.parseStr(PayEnum.待入住.getNum()));
+                        book.setUpdateTime(UUIDUtil.getNewDate());
+                    }
+                }
 
                 // 手动接单,发消息给商家
                 AdminManager adminManager = adminManagerService.getById(Func.parseInt(book.getHotelManagerId()));
-                String live_end = book.getOrderStartTime().substring(0,10)  +"~"+  book.getOrderEndTime().substring(0,10);
+                String live_end = book.getOrderStartTime().substring(0, 10) + "~" + book.getOrderEndTime().substring(0, 10);
                 String hotelName = book.getHotelName();
-                if (Func.checkNull(book.getHotelName()))
-                {
+                if (Func.checkNull(book.getHotelName())) {
                     hotelName = book.getHouseName();
                 }
-                Message2.send(adminManager.getOpenid(),order_num,book.getHouseName(),live_end,book.getUserName(),hotelName, Func.parseStr(book.getId()));
-                double totalPrice = book.getHouseTotalPrice() ;
+                Message2.send(adminManager.getOpenid(), order_num, book.getHouseName(), live_end, book.getUserName(), hotelName, Func.parseStr(book.getId()));
+                double totalPrice = book.getHouseTotalPrice();
                 book.setPayAccount(totalPrice);
                 int m = bookService.updateBooking(book);
                 //用户支付,写入数据操作
-                bookinglogService.addBooklog("用户支付成功" ,book);
+                bookinglogService.addBooklog("用户支付成功", book);
 
-                if (m>0){
+                if (m > 0) {
                     String returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                     HttpServletResponse response = ServletActionContext.getResponse();
                     response.setContentType("text/html;charset=utf-8");
@@ -938,7 +995,7 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
                 }
                 return null;
             }
-        } catch (Exception e){
+        } catch (Exception e) {
             resultjson.put("message", "支付失败");
             resultjson.put("code", 205);
             ResUtil.writeJson(ServletActionContext.getResponse(), resultjson.toString());
@@ -951,8 +1008,6 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     }
 
 
-
-
     public String getOpen_id() {
         return open_id;
     }
@@ -960,4 +1015,4 @@ public class AppBookingAction extends ActionSupport implements ServletRequestAwa
     public void setOpen_id(String open_id) {
         this.open_id = open_id;
     }
-}
+}

+ 1 - 1
mhotel/src/com/happy/action/AppHomePageAction.java

@@ -353,7 +353,7 @@ public class AppHomePageAction extends ActionSupport implements ServletRequestAw
                 DecimalFormat decimalFormat = new DecimalFormat("#####.##");
                 for (Hotel hotel : iPage.getPageList()) {
                     //2023-11-09 A-jax 获取剩余房间数
-                    List<OwnerHouseDto> result = adminManagerService.getTotalManageCount(hotel_township, type);
+                    List<OwnerHouseDto> result = adminManagerService.getTotalManageCount(hotel.getHotelTownship(), type);
                     if(result != null && result.size() > 0){
                         Optional<OwnerHouseDto> mhd = result.stream().filter(e -> e.getManagerId().equals(hotel.getManagerId())).findFirst();
                         if(mhd != null && mhd.isPresent()){

+ 11 - 10
mhotel/src/com/happy/action/bookAction.java

@@ -852,33 +852,34 @@ public class bookAction extends ActionSupport implements ServletRequestAware {
 
     /**
      * 定时任务
+     * 搞定超时未处理的手动接单数据
      */
     public void setBookStatus() throws ParseException {
 
-        System.out.println("动接单定时程序");
+        System.out.println("动接单定时程序");
 
         HotelDict respTime = hotelDictService.getById(1111111111);//响应时间
 
-        System.out.println("动接单定时程序1");
+        System.out.println("动接单定时程序1");
 
-        HotelDict operate = hotelDictService.getById(1000011002);//响应时间 1动接单 2自动拒单
+        HotelDict operate = hotelDictService.getById(1000011002);//响应时间 1动接单 2自动拒单
 
-        System.out.println("动接单定时程序2");
+        System.out.println("动接单定时程序2");
         String dateTime = TimeExchange.TimeRangeI(TimeExchange.getTime(), Integer.valueOf(respTime.getName()), "yyyy-MM-dd HH:mm:ss");
-        String sqlx = " and create_time <= '" + dateTime + "' and order_status = 2 and hotel_is_order = 1";
+        String sqlx = " and create_time <= '" + dateTime + "' and order_status = 2 and hotel_is_order = 2";
         List<Booking> bookings = bookService.queryList(sqlx);
 
-        System.out.println("动接单定时程序3:" + sqlx);
+        System.out.println("动接单定时程序3:" + sqlx);
 
         String result = bookings == null ? "" : bookings.stream().map(Booking::getOrderNum).collect(Collectors.joining());
 
-        System.out.println("动接单,订单编号:" + result + ";拼接条件:" + sqlx);
+        System.out.println("动接单,订单编号:" + result + ";拼接条件:" + sqlx);
 
         AtomicInteger n = new AtomicInteger();
         if ("1".equals(operate.getName())) {
-            System.out.println("动接单定时程序4");
+            System.out.println("动接单定时程序4");
             for (Booking booking : bookings) {
-                System.out.println("动接单定时程序5");
+                System.out.println("动接单定时程序5");
                 List<HouseNumberStatus> list = new ArrayList<>();
                 //不可入住的房间
                 List<HouseNumber> houseNumbers = houseNumberService.queryHouseStatus(booking);
@@ -942,7 +943,7 @@ public class bookAction extends ActionSupport implements ServletRequestAware {
                 }
             }
         } else {
-            System.out.println("动接单定时程序6");
+            System.out.println("动接单定时程序6");
             HotelDict dict = hotelDictService.getById(1000011999);
             for (Booking booking : bookings) {
                 Map<String, String> params = new HashMap<>();

+ 18 - 2
mhotel/src/com/happy/dao/impl/AdminManagerImplDao.java

@@ -1,6 +1,5 @@
 package com.happy.dao.impl;
 
-import com.happy.Model.Admin;
 import com.happy.Model.AdminManager;
 import com.happy.Until.Func;
 import com.happy.Until.SqlUtil;
@@ -9,7 +8,6 @@ import com.happy.dao.AdminManagerDao;
 import com.happy.dto.ManageHouseDto;
 import com.happy.dto.OwnerHouseDto;
 import com.happy.dto.townshipCountDTO;
-import org.apache.poi.ss.formula.functions.T;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -161,6 +159,10 @@ public class AdminManagerImplDao implements AdminManagerDao {
         return null;
     }
 
+    /**
+     * 描述:获取各乡俗民宿级别数量
+     * @return
+     */
     @Override
     public List<townshipCountDTO> getTownshipCount() {
         String sql = "select a.name,sum(case when b.id is not null then 1 else 0 end) sumNumber,sum(case when b.type=1 then 1 else 0 end) aSum,sum(case when b.type=2 then 1 else 0 end) bSum,sum(case when b.type=3 then 1 else 0 end) cSum from \n" +
@@ -179,6 +181,10 @@ public class AdminManagerImplDao implements AdminManagerDao {
         return null;
     }
 
+    /**
+     * 描述:获取各乡镇剩余房数
+     * @return
+     */
     @Override
     public List<townshipCountDTO> getResidueCount() {
         String sql = "select a.name,ifnull(b.number,0) residueNumber from \n" +
@@ -201,6 +207,10 @@ public class AdminManagerImplDao implements AdminManagerDao {
         return null;
     }
 
+    /**
+     * 描述:获取各个乡镇下的总房间数
+     * @return
+     */
     @Override
     public List<ManageHouseDto> getTotalHouseCount() {
         String sql = "select (select Count(*) from house_number where status = 1 and house_id in (\n" +
@@ -224,6 +234,12 @@ public class AdminManagerImplDao implements AdminManagerDao {
         return null;
     }
 
+    /**
+     * 描述:获取乡镇下民宿的总房间数
+     * @param hotelTownship
+     * @param type
+     * @return
+     */
     @Override
     public List<OwnerHouseDto> getTotalManageCount(String hotelTownship, Integer type) {
         String sql = "select (select Count(*) from house_number where status = 1 and house_id in (\n" +

+ 1 - 1
mhotel/src/com/happy/dao/impl/HotelImplDao.java

@@ -171,7 +171,7 @@ public class HotelImplDao implements HotelDao {
     public List<Hotel> queryPagePrice(String sqlx, int page, int rows) {
         SqlUtil.filterKeyword(sqlx);
         int start = (page - 1) * rows;// 每页的起始下标
-        String sql = "SELECT a.*,(select Count(*) from booking where hotel_id = a.id and order_status = 5) as booking_num,b.min_price,c.hotel_township,d.hotel_township_name, e.h_type_name,c.hotel_name,c.link_pro_url,(SELECT round( AVG( score ), 1 ) as score FROM `booking_comment` bc where bc.comment_parent_id IS NULL AND bc.hotel_id = a.id AND `status` = 1) as score" +
+        String sql = "SELECT a.*,c.hotel_township,(select Count(*) from booking where hotel_id = a.id and order_status = 5) as booking_num,b.min_price,c.hotel_township,d.hotel_township_name, e.h_type_name,c.hotel_name,c.link_pro_url,(SELECT round( AVG( score ), 1 ) as score FROM `booking_comment` bc where bc.comment_parent_id IS NULL AND bc.hotel_id = a.id AND `status` = 1) as score" +
                 " FROM `hotel` a " +
                 "left join (select manager_id,min(price) min_price from house where status=1 group by manager_id) b on a.manager_id = b.manager_id " +
                 "left join (select id,manager_id,hotel_township,hotel_name,type,status,link_pro_url from admin_manager ) c on a.manager_id = c.id " +