添加首页分类及专题接口
This commit is contained in:
parent
25cc88c64e
commit
cdf0c2b689
@ -45,7 +45,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
.permitAll()
|
||||
.antMatchers(
|
||||
"/sso/*",//登录注册
|
||||
"/home/*"//首页接口
|
||||
"/home/**"//首页接口
|
||||
)
|
||||
.permitAll()
|
||||
.antMatchers("/member/**","/returnApply/**")// 测试时开启
|
||||
|
@ -1,5 +1,8 @@
|
||||
package com.macro.mall.portal.controller;
|
||||
|
||||
import com.macro.mall.model.CmsSubject;
|
||||
import com.macro.mall.model.PmsProduct;
|
||||
import com.macro.mall.model.PmsProductCategory;
|
||||
import com.macro.mall.portal.domain.CommonResult;
|
||||
import com.macro.mall.portal.domain.HomeContentResult;
|
||||
import com.macro.mall.portal.service.HomeService;
|
||||
@ -7,9 +10,9 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页内容管理Controller
|
||||
@ -29,4 +32,31 @@ public class HomeController {
|
||||
HomeContentResult contentResult = homeService.content();
|
||||
return new CommonResult().success(contentResult);
|
||||
}
|
||||
|
||||
@ApiOperation("分页获取推荐商品")
|
||||
@RequestMapping(value = "/recommendProductList", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object recommendProductList(@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<PmsProduct> productList = homeService.recommendProductList(pageSize, pageNum);
|
||||
return new CommonResult().success(productList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取首页商品分类")
|
||||
@RequestMapping(value = "/productCateList/{parentId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getProductCateList(@PathVariable Long parentId) {
|
||||
List<PmsProductCategory> productCategoryList = homeService.getProductCateList(parentId);
|
||||
return new CommonResult().success(productCategoryList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据分类获取专题")
|
||||
@RequestMapping(value = "/subjectList", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getSubjectList(@RequestParam(required = false) Long cateId,
|
||||
@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
|
||||
List<CmsSubject> subjectList = homeService.getSubjectList(cateId,pageSize,pageNum);
|
||||
return new CommonResult().success(subjectList);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
package com.macro.mall.portal.service;
|
||||
|
||||
import com.macro.mall.model.CmsSubject;
|
||||
import com.macro.mall.model.PmsProduct;
|
||||
import com.macro.mall.model.PmsProductCategory;
|
||||
import com.macro.mall.portal.domain.HomeContentResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 首页内容管理Service
|
||||
* Created by macro on 2019/1/28.
|
||||
@ -12,4 +17,21 @@ public interface HomeService {
|
||||
* 获取首页内容
|
||||
*/
|
||||
HomeContentResult content();
|
||||
|
||||
/**
|
||||
* 首页商品推荐
|
||||
*/
|
||||
List<PmsProduct> recommendProductList(Integer pageSize, Integer pageNum);
|
||||
|
||||
/**
|
||||
* 获取商品分类
|
||||
* @param parentId 0:获取一级分类;其他:获取指定二级分类
|
||||
*/
|
||||
List<PmsProductCategory> getProductCateList(Long parentId);
|
||||
|
||||
/**
|
||||
* 根据专题分类分页获取专题
|
||||
* @param cateId 专题分类id
|
||||
*/
|
||||
List<CmsSubject> getSubjectList(Long cateId, Integer pageSize, Integer pageNum);
|
||||
}
|
||||
|
@ -1,19 +1,18 @@
|
||||
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.github.pagehelper.PageHelper;
|
||||
import com.macro.mall.mapper.*;
|
||||
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 com.macro.mall.portal.util.DateUtil;
|
||||
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;
|
||||
|
||||
@ -31,6 +30,12 @@ public class HomeServiceImpl implements HomeService {
|
||||
private SmsFlashPromotionMapper flashPromotionMapper;
|
||||
@Autowired
|
||||
private SmsFlashPromotionSessionMapper promotionSessionMapper;
|
||||
@Autowired
|
||||
private PmsProductMapper productMapper;
|
||||
@Autowired
|
||||
private PmsProductCategoryMapper productCategoryMapper;
|
||||
@Autowired
|
||||
private CmsSubjectMapper subjectMapper;
|
||||
|
||||
@Override
|
||||
public HomeContentResult content() {
|
||||
@ -50,6 +55,39 @@ public class HomeServiceImpl implements HomeService {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProduct> recommendProductList(Integer pageSize, Integer pageNum) {
|
||||
// TODO: 2019/1/29 暂时默认推荐所有商品
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
PmsProductExample example = new PmsProductExample();
|
||||
example.createCriteria()
|
||||
.andDeleteStatusEqualTo(0)
|
||||
.andPublishStatusEqualTo(1);
|
||||
return productMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PmsProductCategory> getProductCateList(Long parentId) {
|
||||
PmsProductCategoryExample example = new PmsProductCategoryExample();
|
||||
example.createCriteria()
|
||||
.andShowStatusEqualTo(1)
|
||||
.andParentIdEqualTo(parentId);
|
||||
example.setOrderByClause("sort desc");
|
||||
return productCategoryMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CmsSubject> getSubjectList(Long cateId, Integer pageSize, Integer pageNum) {
|
||||
PageHelper.startPage(pageNum,pageSize);
|
||||
CmsSubjectExample example = new CmsSubjectExample();
|
||||
CmsSubjectExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andShowStatusEqualTo(1);
|
||||
if(cateId!=null){
|
||||
criteria.andCategoryIdEqualTo(cateId);
|
||||
}
|
||||
return subjectMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
private HomeFlashPromotion getHomeFlashPromotion() {
|
||||
HomeFlashPromotion homeFlashPromotion = new HomeFlashPromotion();
|
||||
//获取当前秒杀活动
|
||||
@ -88,26 +126,6 @@ public class HomeServiceImpl implements HomeService {
|
||||
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);
|
||||
@ -117,7 +135,7 @@ public class HomeServiceImpl implements HomeService {
|
||||
|
||||
//根据时间获取秒杀活动
|
||||
private SmsFlashPromotion getFlashPromotion(Date date) {
|
||||
Date currDate = getDate(date);
|
||||
Date currDate = DateUtil.getDate(date);
|
||||
SmsFlashPromotionExample example = new SmsFlashPromotionExample();
|
||||
example.createCriteria()
|
||||
.andStatusEqualTo(1)
|
||||
@ -132,7 +150,7 @@ public class HomeServiceImpl implements HomeService {
|
||||
|
||||
//根据时间获取秒杀场次
|
||||
private SmsFlashPromotionSession getFlashPromotionSession(Date date) {
|
||||
Date currTime = getTime(date);
|
||||
Date currTime = DateUtil.getTime(date);
|
||||
SmsFlashPromotionSessionExample sessionExample = new SmsFlashPromotionSessionExample();
|
||||
sessionExample.createCriteria()
|
||||
.andStartTimeLessThanOrEqualTo(currTime)
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.macro.mall.portal.util;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 日期工具类
|
||||
* Created by macro on 2019/1/29.
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
/**
|
||||
* 从Date类型的时间中提取日期部分
|
||||
*/
|
||||
public static Date getDate(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从Date类型的时间中提取时间部分
|
||||
*/
|
||||
public static Date getTime(Date date) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
calendar.set(Calendar.YEAR, 1970);
|
||||
calendar.set(Calendar.MONTH, 0);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
return calendar.getTime();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user