|
@@ -15,6 +15,7 @@ import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Repository;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -369,9 +370,9 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@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;// 每页的起始下标
|
|
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" +
|
|
"\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
|
|
|
"\thc.hotelIds as hotelIds,\n" +
|
|
"\thc.hotelIds as hotelIds,\n" +
|
|
|
"\thc.`name` as name,\n" +
|
|
"\thc.`name` as name,\n" +
|
|
@@ -380,11 +381,14 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
"\thc.deduction_price as deductionPrice,\n" +
|
|
"\thc.deduction_price as deductionPrice,\n" +
|
|
|
"\thc.max_deduction as maxDeduction,\n" +
|
|
"\thc.max_deduction as maxDeduction,\n" +
|
|
|
"\thc.meet_price as meetPrice,\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" +
|
|
"FROM\n" +
|
|
|
"\thotel_coupon_status hcs\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();
|
|
MapSqlParameterSource sps = new MapSqlParameterSource();
|
|
@@ -393,6 +397,7 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
sps.addValue("start", start);
|
|
sps.addValue("start", start);
|
|
|
sps.addValue("rows", rows);
|
|
sps.addValue("rows", rows);
|
|
|
sps.addValue("totalPrice",totalPrice);
|
|
sps.addValue("totalPrice",totalPrice);
|
|
|
|
|
+ sps.addValue("now",format);
|
|
|
List<UsefulCouponVo> list = null;
|
|
List<UsefulCouponVo> list = null;
|
|
|
try{
|
|
try{
|
|
|
list = namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper<>(UsefulCouponVo.class));
|
|
list = namedParameterJdbcTemplate.query(sql, sps,new BeanPropertyRowMapper<>(UsefulCouponVo.class));
|
|
@@ -404,21 +409,30 @@ public class HotelCouponImplDao implements HotelCouponDao {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@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" +
|
|
"FROM\n" +
|
|
|
"\thotel_coupon_status hcs\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();
|
|
MapSqlParameterSource sps = new MapSqlParameterSource();
|
|
|
sps.addValue("hotelId", hotelId);
|
|
sps.addValue("hotelId", hotelId);
|
|
|
sps.addValue("userId", userId);
|
|
sps.addValue("userId", userId);
|
|
|
sps.addValue("totalPrice",totalPrice);
|
|
sps.addValue("totalPrice",totalPrice);
|
|
|
|
|
+ sps.addValue("now",format);
|
|
|
return namedParameterJdbcTemplate.queryForInt(sql, sps);
|
|
return namedParameterJdbcTemplate.queryForInt(sql, sps);
|
|
|
}
|
|
}
|
|
|
private void appendValue(HotelCoupon hotelCoupon, StringBuffer stringBuffer, MapSqlParameterSource sps){
|
|
private void appendValue(HotelCoupon hotelCoupon, StringBuffer stringBuffer, MapSqlParameterSource sps){
|