|
|
@@ -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;
|
|
|
@@ -213,10 +214,10 @@ 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_start_date AS effectiveStartDate,(SELECT COUNT( hcs.complaint_id ) AS totalCount FROM `hotel_coupon_status` hcs WHERE hcs.complaint_id = hc.id ) AS totalCount, hc.limit_number as limitNumber,hc.remainder_number as remainderNumber, \n" +
|
|
|
- "\thc.effective_end_date AS effectiveEndDate \n" +
|
|
|
+ "\thc.grant_start_date AS effectiveStartDate,(SELECT COUNT( hcs.complaint_id ) AS totalCount FROM `hotel_coupon_status` hcs WHERE hcs.complaint_id = hc.id ) AS totalCount, hc.limit_number as limitNumber,hc.remainder_number as remainderNumber, \n" +
|
|
|
+ "\thc.grant_end_date AS effectiveEndDate \n" +
|
|
|
"FROM\n" +
|
|
|
- "\t`hotel_coupon` hc where hc.effective_start_date < :dateTime and hc.effective_end_date> :dateTime and hc.`status` = 1 ORDER BY hc.effective_start_date DESC limit :start,:rows";
|
|
|
+ "\t`hotel_coupon` hc where hc.grant_start_date < :dateTime and hc.grant_end_date> :dateTime and hc.`status` = 1 ORDER BY hc.effective_start_date DESC limit :start,:rows";
|
|
|
|
|
|
MapSqlParameterSource sps = new MapSqlParameterSource();
|
|
|
sps.addValue("dateTime", dateTime);
|
|
|
@@ -237,7 +238,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
String sql="SELECT\n" +
|
|
|
"\t count(1)\n" +
|
|
|
"FROM\n" +
|
|
|
- "\t`hotel_coupon` hc where hc.effective_start_date<:date and hc.effective_end_date>:date";
|
|
|
+ "\t`hotel_coupon` hc where hc.grant_start_date<:date and hc.grant_end_date>:date and hc.`status` = 1 ";
|
|
|
MapSqlParameterSource sps = new MapSqlParameterSource();
|
|
|
sps.addValue("date", date);
|
|
|
return namedParameterJdbcTemplate.queryForInt(sql, sps);
|
|
|
@@ -309,12 +310,25 @@ 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 ,\n" +
|
|
|
- "\tcount(hcs.complaint_id) AS count\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" +
|
|
|
+ "\thcs2.count AS count\n" +
|
|
|
"FROM\n" +
|
|
|
"\thotel_coupon_status hcs\n" +
|
|
|
- "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id where FIND_IN_SET(hc.type,:status) and hcs.user_id=:userId and hcs.status=1 \n" +
|
|
|
- "\tGROUP BY hcs.complaint_id ORDER BY hc.effective_start_date DESC limit :start,:rows";
|
|
|
+ "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id LEFT JOIN (\n" +
|
|
|
+ "SELECT\n" +
|
|
|
+ "\thc2.id AS id,\n" +
|
|
|
+ "\tcount( hcs.complaint_id ) AS count \n" +
|
|
|
+ "FROM\n" +
|
|
|
+ "\thotel_coupon_status hcs\n" +
|
|
|
+ "\tLEFT JOIN hotel_coupon hc2 ON hc2.id = hcs.complaint_id \n" +
|
|
|
+ "WHERE\n" +
|
|
|
+ "\tFIND_IN_SET( hc2.type, :status ) \n" +
|
|
|
+ "\tAND hcs.user_id = :userId \n" +
|
|
|
+ "\tAND hcs.`status` = 1 \n" +
|
|
|
+ "GROUP BY\n" +
|
|
|
+ "\thcs.complaint_id \n" +
|
|
|
+ "\t) hcs2 ON hcs2.id = hc.id where FIND_IN_SET(hc.type,:status) and hcs.user_id=:userId and hcs.status=1 \n" +
|
|
|
+ "\tORDER BY hc.effective_start_date DESC limit :start,:rows";
|
|
|
|
|
|
MapSqlParameterSource sps = new MapSqlParameterSource();
|
|
|
sps.addValue("status", types);
|
|
|
@@ -356,9 +370,9 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows) {
|
|
|
+ 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" +
|
|
|
@@ -367,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 \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 \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();
|
|
|
@@ -379,6 +396,8 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
sps.addValue("userId", userId);
|
|
|
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));
|
|
|
@@ -390,21 +409,30 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public int usefulCouponTotal(String hotelId, String userId) {
|
|
|
- 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";
|
|
|
+ "\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){
|