liu 2 лет назад
Родитель
Сommit
3a81a7b164

+ 3 - 2
mhotel/src/com/happy/dao/HotelCouponDao.java

@@ -3,6 +3,7 @@ package com.happy.dao;
 import com.happy.Model.HotelCoupon;
 import com.happy.vo.*;
 
+import java.time.LocalDateTime;
 import java.util.Date;
 import java.util.List;
 
@@ -78,8 +79,8 @@ public interface HotelCouponDao {
 
     int cardCouponPageTotal(String types, String userId);
 
-    List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice);
+    List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows, Double totalPrice, String format);
 
-    int usefulCouponTotal(String hotelId, String userId,Double totalPrice);
+    int usefulCouponTotal(String hotelId, String userId,Double totalPrice,String format);
 
 }

+ 27 - 13
mhotel/src/com/happy/dao/impl/HotelCouponImplDao.java

@@ -15,6 +15,7 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
 import org.springframework.stereotype.Repository;
 
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -369,9 +370,9 @@ public class HotelCouponImplDao implements HotelCouponDao {
     }
 
     @Override
-    public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
+    public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows, Double totalPrice, String format) {
         int start = (page - 1) * rows;// 每页的起始下标
-        String sql="SELECT\n" +
+        String sql=" SELECT * FROM (SELECT\n" +
                 "\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
                 "\thc.hotelIds as hotelIds,\n" +
                 "\thc.`name` as name,\n" +
@@ -380,11 +381,14 @@ public class HotelCouponImplDao implements HotelCouponDao {
                 "\thc.deduction_price as deductionPrice,\n" +
                 "\thc.max_deduction as maxDeduction,\n" +
                 "\thc.meet_price as meetPrice,\n" +
-                "\thc.effective_end_date as effectiveEndDate ,hc.effective_start_date as effectiveStartDate, hc.effective_day as effectiveDay,hc.effective_lose_day as effectiveLoseDay , hc.effective_type as effectiveType, hcs.create_date as dateTime \n" +
+                "\thc.effective_end_date as effectiveEndDate ,hc.effective_start_date as effectiveStartDate, hc.effective_day as effectiveDay,hc.effective_lose_day as effectiveLoseDay , hc.effective_type as effectiveType, hcs.create_date as dateTime ,TIMESTAMPADD(DAY,hc.effective_day,hcs.create_date) as afterDate,\n" +
+                "\tTIMESTAMPADD(DAY,hc.effective_day+hc.effective_lose_day,hcs.create_date) as beforDate\n" +
                 "FROM\n" +
                 "\thotel_coupon_status hcs\n" +
-                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where (FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) and hcs.user_id=:userId and hcs.status=1 and hc.meet_price<= :totalPrice   \n" +
-                "\t ORDER BY hc.effective_start_date DESC limit :start,:rows";
+                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where (FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) and hcs.user_id=:userId and hcs.status=1 and hc.meet_price<= :totalPrice ) hc2 where ( (hc2.effectiveStartDate < :now AND hc2.effectiveEndDate > :now )\n" +
+                "\tOR (hc2.afterDate < :now  and hc2.beforDate > :now ) \n" +
+                "\t)  \n" +
+                "\t ORDER BY hc2.dateTime DESC   limit :start,:rows";
 
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
@@ -393,6 +397,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
         sps.addValue("start", start);
         sps.addValue("rows", rows);
         sps.addValue("totalPrice",totalPrice);
+        sps.addValue("now",format);
         List<UsefulCouponVo> list = null;
         try{
             list = namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper<>(UsefulCouponVo.class));
@@ -404,21 +409,30 @@ public class HotelCouponImplDao implements HotelCouponDao {
     }
 
     @Override
-    public int usefulCouponTotal(String hotelId, String userId,Double totalPrice) {
-        String sql="SELECT\n" +
-                "\tCOUNT(*) \n" +
+    public int usefulCouponTotal(String hotelId, String userId,Double totalPrice,String format) {
+        String sql=" SELECT count(*) FROM (SELECT\n" +
+                "\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
+                "\thc.hotelIds as hotelIds,\n" +
+                "\thc.`name` as name,\n" +
+                "\thc.type as type,\n" +
+                "\thc.rebate_price as rebatePrice,\n" +
+                "\thc.deduction_price as deductionPrice,\n" +
+                "\thc.max_deduction as maxDeduction,\n" +
+                "\thc.meet_price as meetPrice,\n" +
+                "\thc.effective_end_date as effectiveEndDate ,hc.effective_start_date as effectiveStartDate, hc.effective_day as effectiveDay,hc.effective_lose_day as effectiveLoseDay , hc.effective_type as effectiveType, hcs.create_date as dateTime ,TIMESTAMPADD(DAY,hc.effective_day,hcs.create_date) as afterDate,\n" +
+                "\tTIMESTAMPADD(DAY,hc.effective_day+hc.effective_lose_day,hcs.create_date) as beforDate\n" +
                 "FROM\n" +
                 "\thotel_coupon_status hcs\n" +
-                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id \n" +
-                "WHERE\n" +
-                "\t(FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) \n" +
-                "\tAND hcs.user_id = :userId \n" +
-                "\tAND hcs.`status` = 1 and hc.meet_price<= :totalPrice ";
+                "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where (FIND_IN_SET(:hotelId, hc.hotelIds) or hc.hotelIds=-1 ) and hcs.user_id=:userId and hcs.status=1 and hc.meet_price<= :totalPrice ) hc2 where ( (hc2.effectiveStartDate < :now AND hc2.effectiveEndDate > :now )\n" +
+                "\tOR (hc2.afterDate < :now  and hc2.beforDate > :now ) \n" +
+                "\t)  \n" +
+                "\t ORDER BY hc2.dateTime DESC  ";
 
         MapSqlParameterSource sps = new MapSqlParameterSource();
         sps.addValue("hotelId", hotelId);
         sps.addValue("userId", userId);
         sps.addValue("totalPrice",totalPrice);
+        sps.addValue("now",format);
         return namedParameterJdbcTemplate.queryForInt(sql, sps);
     }
     private void appendValue(HotelCoupon hotelCoupon, StringBuffer stringBuffer, MapSqlParameterSource sps){

+ 4 - 2
mhotel/src/com/happy/service/impl/BookingCommentImplService.java

@@ -295,8 +295,10 @@ public class BookingCommentImplService implements BookingCommentService {
         for (BookingComment bookingComment : list) {
             List<BookingComment> listByParentId = bookingCommentDao.getByParentId(bookingComment.getId());
             List<BookingComment> bookingCommentList = new ArrayList<>();
-            for (BookingComment parentComment : listByParentId) {
-                bookingCommentList.add(getComment(parentComment));
+            if (listByParentId!=null&&listByParentId.size()>0) {
+                for (BookingComment parentComment : listByParentId) {
+                    bookingCommentList.add(getComment(parentComment));
+                }
             }
             bookingComment.setLowCommentList(bookingCommentList);
         }

+ 6 - 39
mhotel/src/com/happy/service/impl/HotelCoupomImplService.java

@@ -248,48 +248,15 @@ public class HotelCoupomImplService implements HotelCoupomService {
     @Override
     public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
         IPage<UsefulCouponVo> iPage = new IPage();
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         //判断当前时间是否在有效期内
-        List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows,totalPrice);
-        ArrayList<UsefulCouponVo> vos = new ArrayList<>();
-        if (hotelCouponList!=null && hotelCouponList.size()>0) {
-            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+        String format = now.format(dateTimeFormatter);
+        List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows,totalPrice,format);
 
-            for (UsefulCouponVo vo : hotelCouponList) {
-                Integer effectiveType = vo.getEffectiveType();
-                if (2==effectiveType) {
-                    //生效天数
-                    Integer effectiveDay = vo.getEffectiveDay();
-                    //失效时间天数
-                    Integer effectiveLoseDay = vo.getEffectiveLoseDay();
-                    //领券时间
-                    String dateTime = vo.getDateTime();
+        int total = hotelCouponDao.usefulCouponTotal(hotelId, userId,totalPrice,format);
 
-                    String substring = dateTime.substring(0, 19);
-                    LocalDateTime parse = LocalDateTime.parse(substring, dateTimeFormatter);
-//                    开始时间
-                    LocalDateTime localDateTime = parse.plusDays(effectiveDay);
-                    vo.setEffectiveStartDate(localDateTime.format(dateTimeFormatter));
-//                    结束时间
-                    LocalDateTime localDateTime1 = localDateTime.plusDays(effectiveLoseDay);
-                    vo.setEffectiveEndDate(localDateTime1.format(dateTimeFormatter));
-
-                }
-
-                String effectiveStartDate = vo.getEffectiveStartDate();
-                String effectiveEndDate = vo.getEffectiveEndDate();
-                String substring = effectiveStartDate.substring(0, 19);
-                String substring2 = effectiveEndDate.substring(0, 19);
-                LocalDateTime now = LocalDateTime.now();
-
-                if (now.isAfter(LocalDateTime.parse(substring, dateTimeFormatter))&& now.isBefore(LocalDateTime.parse(substring2, dateTimeFormatter))) {
-                    vos.add(vo);
-                }
-
-            }
-        }
-
-        int total = hotelCouponDao.usefulCouponTotal(hotelId, userId,totalPrice);
-        iPage.setPageList(vos);
+        iPage.setPageList(hotelCouponList);
         iPage.setPage(page);
         iPage.setTotalPage((int) Math.ceil((double) total / rows));
         iPage.setRows(rows);

+ 3 - 0
mhotel/src/com/happy/vo/UsefulCouponVo.java

@@ -34,4 +34,7 @@ public class UsefulCouponVo {
 
     private String dateTime;//领券时间
 
+    private String afterDate;
+    private String beforDate;
+
 }