HotelCouponImplDao.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. package com.happy.dao.impl;
  2. import com.happy.Model.AdminManager;
  3. import com.happy.Model.HotelCoupon;
  4. import com.happy.Until.Func;
  5. import com.happy.Until.SqlUtil;
  6. import com.happy.Until.UUIDUtil;
  7. import com.happy.dao.HotelCouponDao;
  8. import com.happy.vo.*;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.jdbc.core.BeanPropertyRowMapper;
  11. import org.springframework.jdbc.core.SqlOutParameter;
  12. import org.springframework.jdbc.core.namedparam.EmptySqlParameterSource;
  13. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  14. import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
  15. import org.springframework.stereotype.Repository;
  16. import java.time.LocalDateTime;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import java.util.List;
  20. import java.util.UUID;
  21. @Repository("HotelCouponDao")
  22. public class HotelCouponImplDao implements HotelCouponDao {
  23. @Autowired
  24. private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
  25. public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
  26. return namedParameterJdbcTemplate;
  27. }
  28. public void setNamedParameterJdbcTemplate(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
  29. this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
  30. }
  31. private String selectSql = "select " +
  32. "id,hotelIds,name,type,rebate_price,deduction_price,max_deduction,grant_number,limit_number,grant_start_date,grant_end_date," +
  33. "meet_price,effective_start_date,effective_end_date,effective_type,effective_day,effective_lose_day,create_id,create_date,modify_date,status,remainder_number,reversed_number" +
  34. " from hotel_coupon where 1=1";
  35. @Override
  36. public int insert(HotelCoupon hotelCoupon) {
  37. String sql = "INSERT INTO `hotel_coupon` (`id`, `hotelIds`, `name`, `type`, `rebate_price`, `deduction_price`, `max_deduction`, `grant_number`, `limit_number`, `grant_start_date`, `grant_end_date`, `meet_price`, `effective_start_date`, `effective_end_date`, `effective_day`,`effective_type`, `effective_lose_day`,`create_id`, `create_date`, `modify_date`, `status`, `remainder_number`, `reversed_number`) VALUES (:id,:hotelIds,:name,:type,:rebate_price,:deduction_price,:max_deduction,:grant_number,:limit_number,:grant_start_date,:grant_end_date,:meet_price,:effective_start_date,:effective_end_date,:effective_day,:effective_type,:effective_lose_day,:create_id,:create_date,:modify_date,:status,:remainder_number,:reversed_number)";
  38. MapSqlParameterSource sps = new MapSqlParameterSource();
  39. if (hotelCoupon.getId() == null || "".equals(hotelCoupon.getId())) {
  40. sps.addValue("id", String.valueOf(UUID.randomUUID()));
  41. } else {
  42. sps.addValue("id", hotelCoupon.getId());
  43. }
  44. sps.addValue("hotelIds", hotelCoupon.getHotelIds());
  45. sps.addValue("name", hotelCoupon.getName());
  46. sps.addValue("type", hotelCoupon.getType());
  47. sps.addValue("rebate_price", hotelCoupon.getRebatePrice());
  48. sps.addValue("deduction_price", hotelCoupon.getDeductionPrice());
  49. sps.addValue("max_deduction", hotelCoupon.getMaxDeduction());
  50. sps.addValue("grant_number", hotelCoupon.getGrantNumber());
  51. sps.addValue("limit_number", hotelCoupon.getLimitNumber());
  52. sps.addValue("grant_start_date", hotelCoupon.getGrantStartDate());
  53. sps.addValue("grant_end_date", hotelCoupon.getGrantEndDate());
  54. sps.addValue("meet_price", hotelCoupon.getMeetPrice());
  55. sps.addValue("effective_start_date", hotelCoupon.getEffectiveStartDate());
  56. sps.addValue("effective_end_date", hotelCoupon.getEffectiveEndDate());
  57. sps.addValue("effective_day", hotelCoupon.getEffectiveDay());
  58. sps.addValue("effective_type", hotelCoupon.getEffectiveType());
  59. sps.addValue("effective_lose_day", hotelCoupon.getEffectiveLoseDay());
  60. sps.addValue("create_id", hotelCoupon.getCreateId());
  61. sps.addValue("modify_date", UUIDUtil.getNewDate());
  62. sps.addValue("create_date", UUIDUtil.getNewDate());
  63. sps.addValue("status", hotelCoupon.getStatus());
  64. sps.addValue("remainder_number", hotelCoupon.getRemainderNumber());
  65. sps.addValue("reversed_number", hotelCoupon.getReversedNumber());
  66. int num = 0;
  67. try {
  68. num = namedParameterJdbcTemplate.update(sql, sps);
  69. } catch (Exception e) {
  70. e.printStackTrace();
  71. }
  72. return num;
  73. }
  74. @Override
  75. public int update(HotelCoupon hotelCoupon) {
  76. StringBuffer stringBuffer = new StringBuffer(" update `hotel_coupon` set ");
  77. MapSqlParameterSource sps = new MapSqlParameterSource();
  78. // 将要修改的数据填充到查询语句中
  79. appendValue(hotelCoupon, stringBuffer, sps);
  80. stringBuffer.append(" where id=:id ");
  81. sps.addValue("id", hotelCoupon.getId());
  82. int num = 0;
  83. try {
  84. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. return num;
  89. }
  90. @Override
  91. public int delete(Integer id) {
  92. return 0;
  93. }
  94. @Override
  95. public HotelCoupon getById(String id) {
  96. String sql = selectSql + " AND id = :id and status=1";
  97. MapSqlParameterSource sps = new MapSqlParameterSource();
  98. sps.addValue("id", id);
  99. List<HotelCoupon> list = null;
  100. try {
  101. list = namedParameterJdbcTemplate.query(sql, sps,
  102. new BeanPropertyRowMapper<>(HotelCoupon.class));
  103. } catch (Exception e) {
  104. e.printStackTrace();
  105. }
  106. if (list != null && list.size() > 0) return list.get(0);
  107. return null;
  108. }
  109. @Override
  110. public List<HotelCoupon> queryPage(String sqlx, int page, int rows) {
  111. SqlUtil.filterKeyword(sqlx);
  112. int start = (page - 1) * rows;// 每页的起始下标
  113. String sql = selectSql + sqlx + " ORDER BY create_date DESC limit :start,:rows ";
  114. MapSqlParameterSource sps = new MapSqlParameterSource();
  115. sps.addValue("start", start);
  116. sps.addValue("rows", rows);
  117. List<HotelCoupon> list = namedParameterJdbcTemplate.query(sql, sps,
  118. new BeanPropertyRowMapper<>(HotelCoupon.class));
  119. if (list != null && list.size() > 0) return list;
  120. return null;
  121. }
  122. @Override
  123. public int queryTotal(String sqlx) {
  124. SqlUtil.filterKeyword(sqlx);
  125. String sql = "SELECT count(*) FROM `hotel_coupon` where 1=1 " + sqlx;
  126. MapSqlParameterSource sps = new MapSqlParameterSource();
  127. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  128. }
  129. @Override
  130. public List<HotelCoupon> queryList(String sqlx) {
  131. SqlUtil.filterKeyword(sqlx);
  132. String sql = selectSql + sqlx;
  133. List<HotelCoupon> list = null;
  134. try {
  135. list = namedParameterJdbcTemplate.query(sql, new BeanPropertyRowMapper<>(HotelCoupon.class));
  136. } catch (Exception e) {
  137. e.printStackTrace();
  138. }
  139. if (list != null && list.size() > 0) return list;
  140. return null;
  141. }
  142. @Override
  143. public int updateExpire() {
  144. //查询
  145. String sql = "SELECT `id` from `hotel_coupon` WHERE 1=1 and (DATE_FORMAT(`effective_end_date`, '%Y-%m-%d') < CURDATE() AND `effective_lose_day` IS NULL and `status` = 1)" +
  146. " OR" +
  147. " (DATE_FORMAT(DATE_ADD(`effective_end_date`, INTERVAL `effective_lose_day` + `effective_day` DAY),'%Y-%m-%d') < CURDATE() and `status` = 1)";
  148. int num = 0;
  149. try {
  150. List<String> ids = namedParameterJdbcTemplate.queryForList(sql, EmptySqlParameterSource.INSTANCE, String.class);
  151. if (ids.isEmpty()) return 0;
  152. //修改
  153. StringBuffer stringBuffer = new StringBuffer(" update `hotel_coupon` set ");
  154. MapSqlParameterSource sps = new MapSqlParameterSource();
  155. stringBuffer.append(" status = 3 ");
  156. stringBuffer.append(", modify_date=:modify_date ");
  157. sps.addValue("modify_date", UUIDUtil.getNewDate());
  158. stringBuffer.append(" where id in (:id)");
  159. sps.addValue("id", ids);
  160. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  161. } catch (Exception e) {
  162. e.printStackTrace();
  163. }
  164. return num;
  165. }
  166. @Override
  167. public int updateLapse(List<String> coupomIds) {
  168. StringBuffer stringBuffer = new StringBuffer(" update `hotel_coupon` set ");
  169. MapSqlParameterSource sps = new MapSqlParameterSource();
  170. // 将要修改的数据填充到查询语句中
  171. stringBuffer.append(" status = 2 ");//失效状态写死
  172. stringBuffer.append(", modify_date=:modify_date ");
  173. sps.addValue("modify_date", UUIDUtil.getNewDate());
  174. stringBuffer.append(" where id in (:id)");
  175. sps.addValue("id", coupomIds);
  176. int num = 0;
  177. try {
  178. num = namedParameterJdbcTemplate.update(stringBuffer.toString(), sps);
  179. } catch (Exception e) {
  180. e.printStackTrace();
  181. }
  182. return num;
  183. }
  184. @Override
  185. public List<CouponCollectionVo> couponCollection(String dateTime, int page, int rows, String userId) {
  186. int start = (page - 1) * rows;// 每页的起始下标
  187. String sql = "SELECT\n" +
  188. "\t hc.id as id,hc.hotelIds as hotelIds,\n" +
  189. "\thc.type as type,\n" +
  190. "\thc.`name` as name,\n" +
  191. "\thc.rebate_price as rebatePrice,\n" +
  192. "\thc.deduction_price as deductionPrice,\n" +
  193. "\thc.max_deduction AS maxDeduction,\n" +
  194. "\thc.meet_price as meetPrice,\n" +
  195. "\thc.grant_start_date AS effectiveStartDate,(SELECT COUNT( hcs.complaint_id ) AS totalCount FROM `hotel_coupon_status` hcs WHERE hcs.complaint_id = hc.id and hcs.create_id =:userId ) AS totalCount, hc.limit_number as limitNumber,hc.remainder_number as remainderNumber, \n" +
  196. "\thc.grant_end_date AS effectiveEndDate \n" +
  197. "FROM\n" +
  198. "\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";
  199. MapSqlParameterSource sps = new MapSqlParameterSource();
  200. sps.addValue("dateTime", dateTime);
  201. sps.addValue("start", start);
  202. sps.addValue("rows", rows);
  203. sps.addValue("userId", userId);
  204. List<CouponCollectionVo> list = null;
  205. try {
  206. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(CouponCollectionVo.class));
  207. } catch (Exception e) {
  208. e.printStackTrace();
  209. }
  210. if (list != null && list.size() > 0) return list;
  211. return null;
  212. }
  213. @Override
  214. public int couponCollectionTotal(String date) {
  215. String sql = "SELECT\n" +
  216. "\t count(1)\n" +
  217. "FROM\n" +
  218. "\t`hotel_coupon` hc where hc.grant_start_date<:date and hc.grant_end_date>:date and hc.`status` = 1 ";
  219. MapSqlParameterSource sps = new MapSqlParameterSource();
  220. sps.addValue("date", date);
  221. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  222. }
  223. @Override
  224. public DesignatedHotelVo designatedHotel(String hotelIds) {
  225. String sql = "SELECT GROUP_CONCAT( h.hname ) as name FROM hotel h where FIND_IN_SET(h.id,:hotelIds)";
  226. MapSqlParameterSource sps = new MapSqlParameterSource();
  227. sps.addValue("hotelIds", hotelIds);
  228. List<DesignatedHotelVo> list = null;
  229. try {
  230. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(DesignatedHotelVo.class));
  231. } catch (Exception e) {
  232. e.printStackTrace();
  233. }
  234. if (list != null && list.size() > 0) return list.get(0);
  235. return null;
  236. }
  237. @Override
  238. public QuotaVo quota(String complaintId, String userId) {
  239. String sql = "SELECT\n" +
  240. "\tCOUNT( hcs.complaint_id ) AS totalCount,\n" +
  241. "\t( SELECT hc.limit_number FROM hotel_coupon hc WHERE hc.id = :complaintId and hc.`status`=1 ) AS limitNumber, \n" +
  242. "\t( SELECT hc.remainder_number FROM hotel_coupon hc WHERE hc.id = :complaintId and hc.`status`=1 ) AS remainderNumber \n" +
  243. "FROM\n" +
  244. "\t`hotel_coupon_status` hcs \n" +
  245. "WHERE\n" +
  246. "\thcs.complaint_id = :complaintId and hcs.user_id= :userId ";
  247. MapSqlParameterSource sps = new MapSqlParameterSource();
  248. sps.addValue("complaintId", complaintId);
  249. sps.addValue("userId", userId);
  250. List<QuotaVo> list = null;
  251. try {
  252. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(QuotaVo.class));
  253. } catch (Exception e) {
  254. e.printStackTrace();
  255. }
  256. if (list != null && list.size() > 0) return list.get(0);
  257. return null;
  258. }
  259. @Override
  260. public List<CouponModel> getCoupon(String strs) {
  261. String sql = "select h.id,hd.name from admin_manager am\n" +
  262. " left join hotel_dict hd on hd.code = 10 and hd.id = am.hotel_township\n" +
  263. " left join hotel h on h.manager_id = am.id\n" +
  264. " where am.id in (select manager_id from hotel where id in (" + strs + "))";
  265. MapSqlParameterSource sps = new MapSqlParameterSource();
  266. List<CouponModel> list = null;
  267. try {
  268. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(CouponModel.class));
  269. } catch (Exception e) {
  270. e.printStackTrace();
  271. }
  272. if (list != null && list.size() > 0) {
  273. return list;
  274. }
  275. return null;
  276. }
  277. @Override
  278. public int updateRemainderNumber(String complaintId, String modifyDate) {
  279. String sql = "UPDATE `hotel_coupon` SET remainder_number=remainder_number-1 ,modify_date=:modifyDate WHERE id=:complaintId ";
  280. MapSqlParameterSource sps = new MapSqlParameterSource();
  281. sps.addValue("modifyDate", modifyDate);
  282. sps.addValue("complaintId", complaintId);
  283. int num = 0;
  284. try {
  285. num = namedParameterJdbcTemplate.update(sql, sps);
  286. } catch (Exception e) {
  287. e.printStackTrace();
  288. }
  289. return num;
  290. }
  291. @Override
  292. public List<CardCouponPageVo> cardCouponPage(String types, String userId, int page, int rows) {
  293. int start = (page - 1) * rows;// 每页的起始下标
  294. String sql = "SELECT\n" +
  295. "\thc.id as id,\n" +
  296. "\thc.hotelIds as hotelIds,\n" +
  297. "\thc.`name` as name,\n" +
  298. "\thc.type as type,\n" +
  299. "\thc.rebate_price as rebatePrice,\n" +
  300. "\thc.deduction_price as deductionPrice,\n" +
  301. "\thc.max_deduction as maxDeduction,\n" +
  302. "\thc.meet_price as meetPrice,\n" +
  303. "\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" +
  304. "FROM\n" +
  305. "\thotel_coupon_status hcs\n" +
  306. "\tLEFT JOIN hotel_coupon hc ON hc.id = hcs.complaint_id " +
  307. "\t where FIND_IN_SET(hc.type, :status ) and hcs.user_id= :userId and hcs.status=1 \n" +
  308. "\tORDER BY hc.effective_start_date DESC limit :start , :rows";
  309. MapSqlParameterSource sps = new MapSqlParameterSource();
  310. sps.addValue("status", types);
  311. sps.addValue("userId", userId);
  312. sps.addValue("start", start);
  313. sps.addValue("rows", rows);
  314. List<CardCouponPageVo> list = null;
  315. try {
  316. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(CardCouponPageVo.class));
  317. } catch (Exception e) {
  318. e.printStackTrace();
  319. }
  320. if (list != null && list.size() > 0) return list;
  321. return null;
  322. }
  323. @Override
  324. public int cardCouponPageTotal(String types, String userId) {
  325. String sql = "SELECT COUNT(*) FROM (SELECT\n" +
  326. "\thc.id as id,\n" +
  327. "\thc.hotelIds as hotelIds,\n" +
  328. "\thc.`name` as name,\n" +
  329. "\thc.type as type,\n" +
  330. "\thc.rebate_price as rebatePrice,\n" +
  331. "\thc.deduction_price as deductionPrice,\n" +
  332. "\thc.max_deduction as maxDeduction,\n" +
  333. "\thc.meet_price as meetPrice,\n" +
  334. "\thc.effective_end_date as effectiveEndDate ,\n" +
  335. "\tcount(hcs.complaint_id) AS count\n" +
  336. "FROM\n" +
  337. "\thotel_coupon_status hcs\n" +
  338. "\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" +
  339. "\tGROUP BY hcs.complaint_id ORDER BY hc.effective_start_date DESC ) hcs2";
  340. MapSqlParameterSource sps = new MapSqlParameterSource();
  341. sps.addValue("status", types);
  342. sps.addValue("userId", userId);
  343. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  344. }
  345. @Override
  346. public List<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows, Double totalPrice, String format) {
  347. int start = (page - 1) * rows;// 每页的起始下标
  348. String sql = " SELECT * FROM (SELECT\n" +
  349. "\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
  350. "\thc.hotelIds as hotelIds,\n" +
  351. "\thc.`name` as name,\n" +
  352. "\thc.type as type,\n" +
  353. "\thc.rebate_price as rebatePrice,\n" +
  354. "\thc.deduction_price as deductionPrice,\n" +
  355. "\thc.max_deduction as maxDeduction,\n" +
  356. "\thc.meet_price as meetPrice,\n" +
  357. "\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" +
  358. "\tTIMESTAMPADD(DAY,hc.effective_day+hc.effective_lose_day,hcs.create_date) as beforDate\n" +
  359. "FROM\n" +
  360. "\thotel_coupon_status hcs\n" +
  361. "\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" +
  362. "\tOR (hc2.afterDate < :now and hc2.beforDate > :now ) \n" +
  363. "\t) \n" +
  364. "\t ORDER BY hc2.dateTime DESC limit :start,:rows";
  365. MapSqlParameterSource sps = new MapSqlParameterSource();
  366. sps.addValue("hotelId", hotelId);
  367. sps.addValue("userId", userId);
  368. sps.addValue("start", start);
  369. sps.addValue("rows", rows);
  370. sps.addValue("totalPrice", totalPrice);
  371. sps.addValue("now", format);
  372. List<UsefulCouponVo> list = null;
  373. try {
  374. list = namedParameterJdbcTemplate.query(sql, sps, new BeanPropertyRowMapper<>(UsefulCouponVo.class));
  375. } catch (Exception e) {
  376. e.printStackTrace();
  377. }
  378. if (list != null && list.size() > 0) return list;
  379. return null;
  380. }
  381. @Override
  382. public int usefulCouponTotal(String hotelId, String userId, Double totalPrice, String format) {
  383. String sql = " SELECT count(*) FROM (SELECT\n" +
  384. "\t hcs.id as id , hcs.complaint_id AS complaintId,\n" +
  385. "\thc.hotelIds as hotelIds,\n" +
  386. "\thc.`name` as name,\n" +
  387. "\thc.type as type,\n" +
  388. "\thc.rebate_price as rebatePrice,\n" +
  389. "\thc.deduction_price as deductionPrice,\n" +
  390. "\thc.max_deduction as maxDeduction,\n" +
  391. "\thc.meet_price as meetPrice,\n" +
  392. "\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" +
  393. "\tTIMESTAMPADD(DAY,hc.effective_day+hc.effective_lose_day,hcs.create_date) as beforDate\n" +
  394. "FROM\n" +
  395. "\thotel_coupon_status hcs\n" +
  396. "\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" +
  397. "\tOR (hc2.afterDate < :now and hc2.beforDate > :now ) \n" +
  398. "\t) \n" +
  399. "\t ORDER BY hc2.dateTime DESC ";
  400. MapSqlParameterSource sps = new MapSqlParameterSource();
  401. sps.addValue("hotelId", hotelId);
  402. sps.addValue("userId", userId);
  403. sps.addValue("totalPrice", totalPrice);
  404. sps.addValue("now", format);
  405. return namedParameterJdbcTemplate.queryForInt(sql, sps);
  406. }
  407. @Override
  408. public int updatReversedNumber(HotelCoupon hotelCoupon) {
  409. String sql = " update hotel_coupon set reversed_number = :reversedNumber where id= :id";
  410. MapSqlParameterSource sps = new MapSqlParameterSource();
  411. // 将要修改的数据填充到查询语句中
  412. sps.addValue("id", hotelCoupon.getId());
  413. sps.addValue("reversedNumber", hotelCoupon.getReversedNumber());
  414. int num = 0;
  415. try {
  416. num = namedParameterJdbcTemplate.update(sql, sps);
  417. } catch (Exception e) {
  418. e.printStackTrace();
  419. }
  420. return num;
  421. }
  422. private void appendValue(HotelCoupon hotelCoupon, StringBuffer stringBuffer, MapSqlParameterSource sps) {
  423. if (!Func.checkNull(String.valueOf(hotelCoupon.getHotelIds()))) {
  424. stringBuffer.append(" hotelIds=:hotelIds ,");
  425. sps.addValue("hotelIds", hotelCoupon.getHotelIds());
  426. }
  427. if (!Func.checkNull(String.valueOf(hotelCoupon.getName()))) {
  428. stringBuffer.append(" name=:name ,");
  429. sps.addValue("name", hotelCoupon.getName());
  430. }
  431. if (!Func.checkNull(String.valueOf(hotelCoupon.getType()))) {
  432. stringBuffer.append(" type=:type ,");
  433. sps.addValue("type", hotelCoupon.getType());
  434. }
  435. if (!Func.checkNull(String.valueOf(hotelCoupon.getRebatePrice()))) {
  436. stringBuffer.append(" rebate_price=:rebate_price ,");
  437. sps.addValue("rebate_price", hotelCoupon.getRebatePrice());
  438. }
  439. if (!Func.checkNull(String.valueOf(hotelCoupon.getDeductionPrice()))) {
  440. stringBuffer.append(" deduction_price=:deduction_price ,");
  441. sps.addValue("deduction_price", hotelCoupon.getDeductionPrice());
  442. }
  443. if (!Func.checkNull(String.valueOf(hotelCoupon.getMaxDeduction()))) {
  444. stringBuffer.append(" max_deduction=:max_deduction ,");
  445. sps.addValue("max_deduction", hotelCoupon.getMaxDeduction());
  446. }
  447. if (!Func.checkNull(String.valueOf(hotelCoupon.getGrantNumber()))) {
  448. stringBuffer.append(" grant_number=:grant_number ,");
  449. sps.addValue("grant_number", hotelCoupon.getGrantNumber());
  450. }
  451. if (!Func.checkNull(String.valueOf(hotelCoupon.getLimitNumber()))) {
  452. stringBuffer.append(" limit_number=:limit_number ,");
  453. sps.addValue("limit_number", hotelCoupon.getLimitNumber());
  454. }
  455. if (!Func.checkNull(String.valueOf(hotelCoupon.getGrantStartDate()))) {
  456. stringBuffer.append(" grant_start_date=:grant_start_date ,");
  457. sps.addValue("grant_start_date", hotelCoupon.getGrantStartDate());
  458. }
  459. if (!Func.checkNull(String.valueOf(hotelCoupon.getGrantEndDate()))) {
  460. stringBuffer.append(" grant_end_date=:grant_end_date ,");
  461. sps.addValue("grant_end_date", hotelCoupon.getGrantEndDate());
  462. }
  463. if (!Func.checkNull(String.valueOf(hotelCoupon.getMeetPrice()))) {
  464. stringBuffer.append(" meet_price=:meet_price ,");
  465. sps.addValue("meet_price", hotelCoupon.getMeetPrice());
  466. }
  467. if (!Func.checkNull(String.valueOf(hotelCoupon.getEffectiveStartDate()))) {
  468. stringBuffer.append(" effective_start_date=:effective_start_date ,");
  469. sps.addValue("effective_start_date", hotelCoupon.getEffectiveStartDate());
  470. }
  471. if (!Func.checkNull(String.valueOf(hotelCoupon.getEffectiveEndDate()))) {
  472. stringBuffer.append(" effective_end_date=:effective_end_date ,");
  473. sps.addValue("effective_end_date", hotelCoupon.getEffectiveEndDate());
  474. }
  475. if (!Func.checkNull(String.valueOf(hotelCoupon.getEffectiveDay()))) {
  476. stringBuffer.append(" effective_day=:effective_day ,");
  477. sps.addValue("effective_day", hotelCoupon.getEffectiveDay());
  478. }
  479. if (!Func.checkNull(String.valueOf(hotelCoupon.getEffectiveLoseDay()))) {
  480. stringBuffer.append(" effective_lose_day=:effective_lose_day ,");
  481. sps.addValue("effective_lose_day", hotelCoupon.getEffectiveLoseDay());
  482. }
  483. if (!Func.checkNull(String.valueOf(hotelCoupon.getStatus()))) {
  484. stringBuffer.append(" status=:status ,");
  485. sps.addValue("status", hotelCoupon.getStatus());
  486. }
  487. stringBuffer.append(" modify_date=:modify_date ");
  488. sps.addValue("modify_date", UUIDUtil.getNewDate());
  489. }
  490. }