HotelCoupomImplService.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 if (remainderNumber==0){
  114. couponCollectionVo.setClaimStatus(3);
  115. }else {
  116. couponCollectionVo.setClaimStatus(2);
  117. }
  118. }
  119. }
  120. }
  121. int total = hotelCouponDao.couponCollectionTotal(date);
  122. iPage.setPageList(hotelCouponList);
  123. iPage.setPage(page);
  124. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  125. iPage.setRows(rows);
  126. iPage.setTotal(total);
  127. return iPage;
  128. }
  129. /**
  130. * ָ������
  131. *
  132. * @param hotelIds
  133. * @return
  134. */
  135. @Override
  136. public DesignatedHotelVo designatedHotel(String hotelIds) {
  137. return hotelCouponDao.designatedHotel(hotelIds);
  138. }
  139. /**
  140. * ͨ���Ż�ȯid�ж��Ƿ������ȯ
  141. *
  142. * @param complaintId
  143. * @return
  144. */
  145. @Override
  146. public Boolean quota(String complaintId) {
  147. QuotaVo quotaVo = hotelCouponDao.quota(complaintId);
  148. if (quotaVo != null) {
  149. Integer limitNumber = quotaVo.getLimitNumber();
  150. if (limitNumber == null) {
  151. limitNumber = 0;
  152. }
  153. Integer totalCount = quotaVo.getTotalCount();
  154. if (totalCount == null) {
  155. totalCount = 0;
  156. }
  157. Integer remainderNumber = quotaVo.getRemainderNumber();
  158. if (remainderNumber == null) {
  159. remainderNumber = 0;
  160. }
  161. if (limitNumber > totalCount && remainderNumber > 0) {
  162. return true;
  163. } else {
  164. return false;
  165. }
  166. }
  167. return true;
  168. }
  169. /**
  170. * ��ȡ�Ż�ȯ
  171. *
  172. * @param hotelCouponStatus
  173. * @return
  174. */
  175. @Override
  176. @Transactional(rollbackFor = Exception.class, readOnly = false)
  177. public int coupon(HotelCouponStatus hotelCouponStatus) {
  178. try {
  179. // �����޸��Ż�ȯ������
  180. int num = hotelCouponDao.updateRemainderNumber(hotelCouponStatus.getComplaintId(), hotelCouponStatus.getModifyDate());
  181. num = hotelCoupomStatusService.insert(hotelCouponStatus);
  182. return num;
  183. } catch (Exception e) {
  184. e.printStackTrace();
  185. }
  186. return 0;
  187. }
  188. @Override
  189. public IPage<CardCouponPageVo> cardCouponPage(String types, String userId, int page, int rows) {
  190. IPage<CardCouponPageVo> iPage = new IPage();
  191. List<CardCouponPageVo> hotelCouponList = hotelCouponDao.cardCouponPage(types, userId, page, rows);
  192. if (hotelCouponList!=null && hotelCouponList.size()>0) {
  193. for (CardCouponPageVo cardCouponPageVo : hotelCouponList) {
  194. Integer effectiveType = cardCouponPageVo.getEffectiveType();
  195. if (2==effectiveType) {
  196. //生效天数
  197. Integer effectiveDay = cardCouponPageVo.getEffectiveDay();
  198. //失效时间天数
  199. Integer effectiveLoseDay = cardCouponPageVo.getEffectiveLoseDay();
  200. //领券时间
  201. String dateTime = cardCouponPageVo.getDateTime();
  202. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  203. String substring = dateTime.substring(0, 19);
  204. LocalDateTime parse = LocalDateTime.parse(substring, dateTimeFormatter);
  205. // 开始时间
  206. LocalDateTime localDateTime = parse.plusDays(effectiveDay);
  207. cardCouponPageVo.setEffectiveStartDate(localDateTime.format(dateTimeFormatter));
  208. // 结束时间
  209. LocalDateTime localDateTime1 = localDateTime.plusDays(effectiveLoseDay);
  210. cardCouponPageVo.setEffectiveEndDate(localDateTime1.format(dateTimeFormatter));
  211. }
  212. }
  213. }
  214. int total = hotelCouponDao.cardCouponPageTotal(types, userId);
  215. iPage.setPageList(hotelCouponList);
  216. iPage.setPage(page);
  217. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  218. iPage.setRows(rows);
  219. iPage.setTotal(total);
  220. return iPage;
  221. }
  222. @Override
  223. public IPage<UsefulCouponVo> usefulCoupon(String hotelId, String userId, int page, int rows,Double totalPrice) {
  224. IPage<UsefulCouponVo> iPage = new IPage();
  225. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  226. //判断当前时间是否在有效期内
  227. LocalDateTime now = LocalDateTime.now();
  228. String format = now.format(dateTimeFormatter);
  229. List<UsefulCouponVo> hotelCouponList = hotelCouponDao.usefulCoupon(hotelId, userId, page, rows,totalPrice,format);
  230. int total = hotelCouponDao.usefulCouponTotal(hotelId, userId,totalPrice,format);
  231. iPage.setPageList(hotelCouponList);
  232. iPage.setPage(page);
  233. iPage.setTotalPage((int) Math.ceil((double) total / rows));
  234. iPage.setRows(rows);
  235. iPage.setTotal(total);
  236. return iPage;
  237. }
  238. @Override
  239. @Transactional(rollbackFor = Exception.class)
  240. public int useCoupons( HotelCoupon hotelCoupon, HotelCouponStatus hotelCouponStatus) {
  241. int update = hotelCouponDao.update(hotelCoupon);
  242. int u=hotelCoupomStatusService.update(hotelCouponStatus);
  243. if (update>0&&u>0) {
  244. return update;
  245. }
  246. return 0;
  247. }
  248. }