HotelCoupomImplService.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package com.happy.service.impl;
  2. import com.happy.Model.AdminManager;
  3. import com.happy.Model.Hotel;
  4. import com.happy.Model.HotelCoupon;
  5. import com.happy.Model.HotelCouponStatus;
  6. import com.happy.Until.DateUtil;
  7. import com.happy.dao.HotelCouponDao;
  8. import com.happy.dao.HotelDao;
  9. import com.happy.dto.IPage;
  10. import com.happy.service.BookService;
  11. import com.happy.service.HotelCoupomService;
  12. import com.happy.service.HotelCoupomStatusService;
  13. import com.happy.vo.*;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import javax.annotation.Resource;
  17. import java.util.ArrayList;
  18. import java.util.Date;
  19. import java.util.List;
  20. @Service("hotelCoupomService")
  21. public class HotelCoupomImplService implements HotelCoupomService {
  22. @Resource
  23. private HotelCouponDao hotelCouponDao;
  24. @Resource
  25. public HotelDao hotelDao;
  26. @Resource
  27. public HotelCoupomStatusService hotelCoupomStatusService;
  28. @Resource
  29. public BookService bookService;
  30. @Override
  31. public int insert(HotelCoupon hotelCoupon) {
  32. return hotelCouponDao.insert(hotelCoupon);
  33. }
  34. @Override
  35. public int update(HotelCoupon hotelCoupon) {
  36. return hotelCouponDao.update(hotelCoupon);
  37. }
  38. @Override
  39. public int delete(Integer id) {
  40. return hotelCouponDao.delete(id);
  41. }
  42. @Override
  43. public HotelCoupon getById(String id) {
  44. return hotelCouponDao.getById(id);
  45. }
  46. @Override
  47. public IPage<HotelCoupon> queryPage(String sqlx, int page, int rows) {
  48. IPage<HotelCoupon> iPage = new IPage();
  49. List<HotelCoupon> hotelCouponList = hotelCouponDao.queryPage(sqlx,page,rows);
  50. hotelCouponList.forEach(hotelCoupon -> {
  51. String hotelIds = hotelCoupon.getHotelIds();
  52. String sql = " and id in ( " + hotelIds + " )";
  53. List<Hotel> hotels = hotelDao.queryList(sql);
  54. if (hotels!=null){
  55. StringBuilder stringBuilder = new StringBuilder();
  56. hotels.forEach(hotel -> {
  57. stringBuilder.append(hotel.getHname()).append(",");
  58. });
  59. String hotelNames = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
  60. hotelCoupon.setHotelNames(hotelNames);
  61. }
  62. });
  63. int total = hotelCouponDao.queryTotal(sqlx);
  64. iPage.setPageList(hotelCouponList);
  65. iPage.setPage(page);
  66. iPage.setTotalPage( (int)Math.ceil((double)total/rows));
  67. iPage.setRows(rows);
  68. iPage.setTotal(total);
  69. return iPage;
  70. }
  71. @Override
  72. public List<HotelCoupon> queryList(String sqlx) {
  73. return hotelCouponDao.queryList(sqlx);
  74. }
  75. @Override
  76. public int updateExpire() {
  77. return hotelCouponDao.updateExpire();
  78. }
  79. @Override
  80. public int updateLapse(List<String> coupomIds) {
  81. return hotelCouponDao.updateLapse(coupomIds);
  82. }
  83. /**
  84. * ��ȯ����
  85. *
  86. * @param date
  87. * @return
  88. */
  89. @Override
  90. public IPage<CouponCollectionVo> couponCollection(String date, int page, int rows) {
  91. IPage<CouponCollectionVo> iPage = new IPage();
  92. List<CouponCollectionVo> hotelCouponList = hotelCouponDao.couponCollection(date, page, rows);
  93. if (hotelCouponList!=null&&hotelCouponList.size()>0) {
  94. for (CouponCollectionVo couponCollectionVo : hotelCouponList) {
  95. if (couponCollectionVo != null) {
  96. Integer limitNumber = couponCollectionVo.getLimitNumber();
  97. if (limitNumber == null) {
  98. limitNumber = 0;
  99. }
  100. Integer totalCount = couponCollectionVo.getTotalCount();
  101. if (totalCount == null) {
  102. totalCount = 0;
  103. }
  104. Integer remainderNumber = couponCollectionVo.getRemainderNumber();
  105. if (remainderNumber == null) {
  106. remainderNumber = 0;
  107. }
  108. if (limitNumber > totalCount && remainderNumber > 0) {
  109. couponCollectionVo.setClaimStatus(1);
  110. } else {
  111. couponCollectionVo.setClaimStatus(2);
  112. }
  113. }
  114. }
  115. }
  116. int total = hotelCouponDao.couponCollectionTotal(date);
  117. iPage.setPageList(hotelCouponList);
  118. iPage.setPage(page);
  119. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  120. iPage.setRows(rows);
  121. iPage.setTotal(total);
  122. return iPage;
  123. }
  124. /**
  125. * ָ������
  126. *
  127. * @param hotelIds
  128. * @return
  129. */
  130. @Override
  131. public DesignatedHotelVo designatedHotel(String hotelIds) {
  132. return hotelCouponDao.designatedHotel(hotelIds);
  133. }
  134. /**
  135. * ͨ���Ż�ȯid�ж��Ƿ������ȯ
  136. *
  137. * @param complaintId
  138. * @return
  139. */
  140. @Override
  141. public Boolean quota(String complaintId) {
  142. QuotaVo quotaVo = hotelCouponDao.quota(complaintId);
  143. if (quotaVo != null) {
  144. Integer limitNumber = quotaVo.getLimitNumber();
  145. if (limitNumber == null) {
  146. limitNumber = 0;
  147. }
  148. Integer totalCount = quotaVo.getTotalCount();
  149. if (totalCount == null) {
  150. totalCount = 0;
  151. }
  152. Integer remainderNumber = quotaVo.getRemainderNumber();
  153. if (remainderNumber == null) {
  154. remainderNumber = 0;
  155. }
  156. if (limitNumber > totalCount && remainderNumber > 0) {
  157. return true;
  158. } else {
  159. return false;
  160. }
  161. }
  162. return true;
  163. }
  164. /**
  165. * ��ȡ�Ż�ȯ
  166. *
  167. * @param hotelCouponStatus
  168. * @return
  169. */
  170. @Override
  171. @Transactional(rollbackFor = Exception.class, readOnly = false)
  172. public int coupon(HotelCouponStatus hotelCouponStatus) {
  173. try {
  174. // �����޸��Ż�ȯ������
  175. int num = hotelCouponDao.updateRemainderNumber(hotelCouponStatus.getComplaintId(), hotelCouponStatus.getModifyDate());
  176. num = hotelCoupomStatusService.insert(hotelCouponStatus);
  177. return num;
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }
  181. return 0;
  182. }
  183. @Override
  184. public IPage<CardCouponPageVo> cardCouponPage(String types, String userId, int page, int rows) {
  185. IPage<CardCouponPageVo> iPage = new IPage();
  186. List<CardCouponPageVo> hotelCouponList = hotelCouponDao.cardCouponPage(types, userId, page, rows);
  187. int total = hotelCouponDao.cardCouponPageTotal(types, userId);
  188. iPage.setPageList(hotelCouponList);
  189. iPage.setPage(page);
  190. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  191. iPage.setRows(rows);
  192. iPage.setTotal(total);
  193. return iPage;
  194. }
  195. @Override
  196. public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows) {
  197. IPage<UsefulCouponVo> iPage = new IPage();
  198. List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows);
  199. int total = hotelCouponDao.usefulCouponTotal(hotelId, userId);
  200. iPage.setPageList(hotelCouponList);
  201. iPage.setPage(page);
  202. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  203. iPage.setRows(rows);
  204. iPage.setTotal(total);
  205. return iPage;
  206. }
  207. @Override
  208. @Transactional(rollbackFor = Exception.class)
  209. public int useCoupons( HotelCoupon hotelCoupon, HotelCouponStatus hotelCouponStatus) {
  210. int update = hotelCouponDao.update(hotelCoupon);
  211. int u=hotelCoupomStatusService.update(hotelCouponStatus);
  212. if (update>0&&u>0) {
  213. return update;
  214. }
  215. return 0;
  216. }
  217. }