HotelCoupomImplService.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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.apache.commons.lang.ObjectUtils;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import javax.annotation.Resource;
  18. import java.time.LocalDateTime;
  19. import java.time.format.DateTimeFormatter;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. @Service("hotelCoupomService")
  24. public class HotelCoupomImplService implements HotelCoupomService {
  25. @Resource
  26. private HotelCouponDao hotelCouponDao;
  27. @Resource
  28. public HotelDao hotelDao;
  29. @Resource
  30. public HotelCoupomStatusService hotelCoupomStatusService;
  31. @Resource
  32. public BookService bookService;
  33. @Override
  34. public int insert(HotelCoupon hotelCoupon) {
  35. return hotelCouponDao.insert(hotelCoupon);
  36. }
  37. @Override
  38. public int update(HotelCoupon hotelCoupon) {
  39. return hotelCouponDao.update(hotelCoupon);
  40. }
  41. @Override
  42. public int delete(Integer id) {
  43. return hotelCouponDao.delete(id);
  44. }
  45. @Override
  46. public HotelCoupon getById(String id) {
  47. return hotelCouponDao.getById(id);
  48. }
  49. @Override
  50. public IPage<HotelCoupon> queryPage(String sqlx, int page, int rows) {
  51. IPage<HotelCoupon> iPage = new IPage();
  52. List<HotelCoupon> hotelCouponList = hotelCouponDao.queryPage(sqlx,page,rows);
  53. hotelCouponList.forEach(hotelCoupon -> {
  54. String hotelIds = hotelCoupon.getHotelIds();
  55. String sql = " and id in ( " + hotelIds + " )";
  56. List<Hotel> hotels = hotelDao.queryList(sql);
  57. if (hotels!=null){
  58. StringBuilder stringBuilder = new StringBuilder();
  59. hotels.forEach(hotel -> {
  60. stringBuilder.append(hotel.getHname()).append(",");
  61. });
  62. String hotelNames = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
  63. hotelCoupon.setHotelNames(hotelNames);
  64. }
  65. });
  66. int total = hotelCouponDao.queryTotal(sqlx);
  67. iPage.setPageList(hotelCouponList);
  68. iPage.setPage(page);
  69. iPage.setTotalPage( (int)Math.ceil((double)total/rows));
  70. iPage.setRows(rows);
  71. iPage.setTotal(total);
  72. return iPage;
  73. }
  74. @Override
  75. public List<HotelCoupon> queryList(String sqlx) {
  76. return hotelCouponDao.queryList(sqlx);
  77. }
  78. @Override
  79. public int updateExpire() {
  80. return hotelCouponDao.updateExpire();
  81. }
  82. @Override
  83. public int updateLapse(List<String> coupomIds) {
  84. return hotelCouponDao.updateLapse(coupomIds);
  85. }
  86. /**
  87. * ��ȯ����
  88. *
  89. * @param date
  90. * @return
  91. */
  92. @Override
  93. public IPage<CouponCollectionVo> couponCollection(String date, int page, int rows) {
  94. IPage<CouponCollectionVo> iPage = new IPage();
  95. List<CouponCollectionVo> hotelCouponList = hotelCouponDao.couponCollection(date, page, rows);
  96. if (hotelCouponList!=null&&hotelCouponList.size()>0) {
  97. for (CouponCollectionVo couponCollectionVo : hotelCouponList) {
  98. if (couponCollectionVo != null) {
  99. Integer limitNumber = couponCollectionVo.getLimitNumber();
  100. if (limitNumber == null) {
  101. limitNumber = 0;
  102. }
  103. Integer totalCount = couponCollectionVo.getTotalCount();
  104. if (totalCount == null) {
  105. totalCount = 0;
  106. }
  107. Integer remainderNumber = couponCollectionVo.getRemainderNumber();
  108. if (remainderNumber == null) {
  109. remainderNumber = 0;
  110. }
  111. if (limitNumber > totalCount && remainderNumber > 0) {
  112. couponCollectionVo.setClaimStatus(1);
  113. } else {
  114. couponCollectionVo.setClaimStatus(2);
  115. }
  116. }
  117. }
  118. }
  119. int total = hotelCouponDao.couponCollectionTotal(date);
  120. iPage.setPageList(hotelCouponList);
  121. iPage.setPage(page);
  122. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  123. iPage.setRows(rows);
  124. iPage.setTotal(total);
  125. return iPage;
  126. }
  127. /**
  128. * ָ������
  129. *
  130. * @param hotelIds
  131. * @return
  132. */
  133. @Override
  134. public DesignatedHotelVo designatedHotel(String hotelIds) {
  135. return hotelCouponDao.designatedHotel(hotelIds);
  136. }
  137. /**
  138. * ͨ���Ż�ȯid�ж��Ƿ������ȯ
  139. *
  140. * @param complaintId
  141. * @return
  142. */
  143. @Override
  144. public Boolean quota(String complaintId) {
  145. QuotaVo quotaVo = hotelCouponDao.quota(complaintId);
  146. if (quotaVo != null) {
  147. Integer limitNumber = quotaVo.getLimitNumber();
  148. if (limitNumber == null) {
  149. limitNumber = 0;
  150. }
  151. Integer totalCount = quotaVo.getTotalCount();
  152. if (totalCount == null) {
  153. totalCount = 0;
  154. }
  155. Integer remainderNumber = quotaVo.getRemainderNumber();
  156. if (remainderNumber == null) {
  157. remainderNumber = 0;
  158. }
  159. if (limitNumber > totalCount && remainderNumber > 0) {
  160. return true;
  161. } else {
  162. return false;
  163. }
  164. }
  165. return true;
  166. }
  167. /**
  168. * ��ȡ�Ż�ȯ
  169. *
  170. * @param hotelCouponStatus
  171. * @return
  172. */
  173. @Override
  174. @Transactional(rollbackFor = Exception.class, readOnly = false)
  175. public int coupon(HotelCouponStatus hotelCouponStatus) {
  176. try {
  177. // �����޸��Ż�ȯ������
  178. int num = hotelCouponDao.updateRemainderNumber(hotelCouponStatus.getComplaintId(), hotelCouponStatus.getModifyDate());
  179. num = hotelCoupomStatusService.insert(hotelCouponStatus);
  180. return num;
  181. } catch (Exception e) {
  182. e.printStackTrace();
  183. }
  184. return 0;
  185. }
  186. @Override
  187. public IPage<CardCouponPageVo> cardCouponPage(String types, String userId, int page, int rows) {
  188. IPage<CardCouponPageVo> iPage = new IPage();
  189. List<CardCouponPageVo> hotelCouponList = hotelCouponDao.cardCouponPage(types, userId, page, rows);
  190. if (hotelCouponList!=null && hotelCouponList.size()>0) {
  191. for (CardCouponPageVo cardCouponPageVo : hotelCouponList) {
  192. Integer effectiveType = cardCouponPageVo.getEffectiveType();
  193. if (2==effectiveType) {
  194. //生效天数
  195. Integer effectiveDay = cardCouponPageVo.getEffectiveDay();
  196. //失效时间天数
  197. Integer effectiveLoseDay = cardCouponPageVo.getEffectiveLoseDay();
  198. //领券时间
  199. String dateTime = cardCouponPageVo.getDateTime();
  200. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  201. String substring = dateTime.substring(0, 19);
  202. LocalDateTime parse = LocalDateTime.parse(substring, dateTimeFormatter);
  203. // 开始时间
  204. LocalDateTime localDateTime = parse.plusDays(effectiveDay);
  205. cardCouponPageVo.setEffectiveStartDate(localDateTime.format(dateTimeFormatter));
  206. // 结束时间
  207. LocalDateTime localDateTime1 = localDateTime.plusDays(effectiveLoseDay);
  208. cardCouponPageVo.setEffectiveEndDate(localDateTime1.format(dateTimeFormatter));
  209. }
  210. }
  211. }
  212. int total = hotelCouponDao.cardCouponPageTotal(types, userId);
  213. iPage.setPageList(hotelCouponList);
  214. iPage.setPage(page);
  215. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  216. iPage.setRows(rows);
  217. iPage.setTotal(total);
  218. return iPage;
  219. }
  220. @Override
  221. public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
  222. IPage<UsefulCouponVo> iPage = new IPage();
  223. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  224. //判断当前时间是否在有效期内
  225. LocalDateTime now = LocalDateTime.now();
  226. String format = now.format(dateTimeFormatter);
  227. List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows,totalPrice,format);
  228. int total = hotelCouponDao.usefulCouponTotal(hotelId, userId,totalPrice,format);
  229. iPage.setPageList(hotelCouponList);
  230. iPage.setPage(page);
  231. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  232. iPage.setRows(rows);
  233. iPage.setTotal(total);
  234. return iPage;
  235. }
  236. @Override
  237. @Transactional(rollbackFor = Exception.class)
  238. public int useCoupons( HotelCoupon hotelCoupon, HotelCouponStatus hotelCouponStatus) {
  239. int update = hotelCouponDao.update(hotelCoupon);
  240. int u=hotelCoupomStatusService.update(hotelCouponStatus);
  241. if (update>0&&u>0) {
  242. return update;
  243. }
  244. return 0;
  245. }
  246. }