|
@@ -0,0 +1,140 @@
|
|
|
+package com.macro.mall.portal.service.impl;
|
|
|
+
|
|
|
+import com.macro.mall.mapper.SmsFlashPromotionMapper;
|
|
|
+import com.macro.mall.mapper.SmsFlashPromotionSessionMapper;
|
|
|
+import com.macro.mall.mapper.SmsHomeAdvertiseMapper;
|
|
|
+import com.macro.mall.model.*;
|
|
|
+import com.macro.mall.portal.dao.HomeDao;
|
|
|
+import com.macro.mall.portal.domain.FlashPromotionProduct;
|
|
|
+import com.macro.mall.portal.domain.HomeContentResult;
|
|
|
+import com.macro.mall.portal.domain.HomeFlashPromotion;
|
|
|
+import com.macro.mall.portal.service.HomeService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 首页内容管理Service实现类
|
|
|
+ * Created by macro on 2019/1/28.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class HomeServiceImpl implements HomeService {
|
|
|
+ @Autowired
|
|
|
+ private SmsHomeAdvertiseMapper advertiseMapper;
|
|
|
+ @Autowired
|
|
|
+ private HomeDao homeDao;
|
|
|
+ @Autowired
|
|
|
+ private SmsFlashPromotionMapper flashPromotionMapper;
|
|
|
+ @Autowired
|
|
|
+ private SmsFlashPromotionSessionMapper promotionSessionMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HomeContentResult content() {
|
|
|
+ HomeContentResult result = new HomeContentResult();
|
|
|
+ //获取首页广告
|
|
|
+ result.setAdvertiseList(getHomeAdvertiseList());
|
|
|
+ //获取推荐品牌
|
|
|
+ result.setBrandList(homeDao.getRecommendBrand());
|
|
|
+ //获取秒杀信息
|
|
|
+ result.setHomeFlashPromotion(getHomeFlashPromotion());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HomeFlashPromotion getHomeFlashPromotion() {
|
|
|
+ HomeFlashPromotion homeFlashPromotion = new HomeFlashPromotion();
|
|
|
+ //获取当前秒杀活动
|
|
|
+ Date now = new Date();
|
|
|
+ SmsFlashPromotion flashPromotion = getFlashPromotion(now);
|
|
|
+ if (flashPromotion != null) {
|
|
|
+ //获取当前秒杀场次
|
|
|
+ SmsFlashPromotionSession flashPromotionSession = getFlashPromotionSession(now);
|
|
|
+ if (flashPromotionSession != null) {
|
|
|
+ homeFlashPromotion.setStartTime(flashPromotionSession.getStartTime());
|
|
|
+ homeFlashPromotion.setEndTime(flashPromotionSession.getEndTime());
|
|
|
+ //获取下一个秒杀场次
|
|
|
+ SmsFlashPromotionSession nextSession = getNextFlashPromotionSession(homeFlashPromotion.getStartTime());
|
|
|
+ if(nextSession!=null){
|
|
|
+ homeFlashPromotion.setNextStartTime(nextSession.getStartTime());
|
|
|
+ homeFlashPromotion.setNextEndTime(nextSession.getEndTime());
|
|
|
+ }
|
|
|
+ //获取秒杀商品
|
|
|
+ List<FlashPromotionProduct> flashProductList = homeDao.getFlashProductList(flashPromotion.getId(), flashPromotionSession.getId());
|
|
|
+ homeFlashPromotion.setProductList(flashProductList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return homeFlashPromotion;
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取下一个场次信息
|
|
|
+ private SmsFlashPromotionSession getNextFlashPromotionSession(Date date) {
|
|
|
+ SmsFlashPromotionSessionExample sessionExample = new SmsFlashPromotionSessionExample();
|
|
|
+ sessionExample.createCriteria()
|
|
|
+ .andStartTimeGreaterThan(date);
|
|
|
+ sessionExample.setOrderByClause("start_time asc");
|
|
|
+ List<SmsFlashPromotionSession> promotionSessionList = promotionSessionMapper.selectByExample(sessionExample);
|
|
|
+ if (!CollectionUtils.isEmpty(promotionSessionList)) {
|
|
|
+ return promotionSessionList.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //从当前日期中提取日期时间戳
|
|
|
+ private Date getDate(Date now) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(now);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ //从当前日期中提取时间时间戳
|
|
|
+ private Date getTime(Date now) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(now);
|
|
|
+ calendar.set(Calendar.YEAR, 1970);
|
|
|
+ calendar.set(Calendar.MONTH, 0);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<SmsHomeAdvertise> getHomeAdvertiseList() {
|
|
|
+ SmsHomeAdvertiseExample example = new SmsHomeAdvertiseExample();
|
|
|
+ example.createCriteria().andTypeEqualTo(1).andStatusEqualTo(1);
|
|
|
+ example.setOrderByClause("sort desc");
|
|
|
+ return advertiseMapper.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据时间获取秒杀活动
|
|
|
+ private SmsFlashPromotion getFlashPromotion(Date date) {
|
|
|
+ Date currDate = getDate(date);
|
|
|
+ SmsFlashPromotionExample example = new SmsFlashPromotionExample();
|
|
|
+ example.createCriteria()
|
|
|
+ .andStatusEqualTo(1)
|
|
|
+ .andStartDateLessThanOrEqualTo(currDate)
|
|
|
+ .andEndDateGreaterThanOrEqualTo(currDate);
|
|
|
+ List<SmsFlashPromotion> flashPromotionList = flashPromotionMapper.selectByExample(example);
|
|
|
+ if (!CollectionUtils.isEmpty(flashPromotionList)) {
|
|
|
+ return flashPromotionList.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据时间获取秒杀场次
|
|
|
+ private SmsFlashPromotionSession getFlashPromotionSession(Date date) {
|
|
|
+ Date currTime = getTime(date);
|
|
|
+ SmsFlashPromotionSessionExample sessionExample = new SmsFlashPromotionSessionExample();
|
|
|
+ sessionExample.createCriteria()
|
|
|
+ .andStartTimeLessThanOrEqualTo(currTime)
|
|
|
+ .andEndTimeGreaterThanOrEqualTo(currTime);
|
|
|
+ List<SmsFlashPromotionSession> promotionSessionList = promotionSessionMapper.selectByExample(sessionExample);
|
|
|
+ if (!CollectionUtils.isEmpty(promotionSessionList)) {
|
|
|
+ return promotionSessionList.get(0);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|