Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
cdf0c2b6
Commit
cdf0c2b6
authored
Jan 29, 2019
by
zhh
Browse files
添加首页分类及专题接口
parent
25cc88c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
mall-portal/src/main/java/com/macro/mall/portal/config/SecurityConfig.java
View file @
cdf0c2b6
...
@@ -45,7 +45,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -45,7 +45,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.
permitAll
()
.
permitAll
()
.
antMatchers
(
.
antMatchers
(
"/sso/*"
,
//登录注册
"/sso/*"
,
//登录注册
"/home/*"
//首页接口
"/home/*
*
"
//首页接口
)
)
.
permitAll
()
.
permitAll
()
.
antMatchers
(
"/member/**"
,
"/returnApply/**"
)
// 测试时开启
.
antMatchers
(
"/member/**"
,
"/returnApply/**"
)
// 测试时开启
...
...
mall-portal/src/main/java/com/macro/mall/portal/controller/HomeController.java
View file @
cdf0c2b6
package
com.macro.mall.portal.controller
;
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.CommonResult
;
import
com.macro.mall.portal.domain.HomeContentResult
;
import
com.macro.mall.portal.domain.HomeContentResult
;
import
com.macro.mall.portal.service.HomeService
;
import
com.macro.mall.portal.service.HomeService
;
...
@@ -7,9 +10,9 @@ import io.swagger.annotations.Api;
...
@@ -7,9 +10,9 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.
RequestMapping
;
import
org.springframework.web.bind.annotation.
*
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.List
;
/**
/**
* 首页内容管理Controller
* 首页内容管理Controller
...
@@ -29,4 +32,31 @@ public class HomeController {
...
@@ -29,4 +32,31 @@ public class HomeController {
HomeContentResult
contentResult
=
homeService
.
content
();
HomeContentResult
contentResult
=
homeService
.
content
();
return
new
CommonResult
().
success
(
contentResult
);
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
);
}
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/HomeService.java
View file @
cdf0c2b6
package
com.macro.mall.portal.service
;
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
com.macro.mall.portal.domain.HomeContentResult
;
import
java.util.List
;
/**
/**
* 首页内容管理Service
* 首页内容管理Service
* Created by macro on 2019/1/28.
* Created by macro on 2019/1/28.
...
@@ -12,4 +17,21 @@ public interface HomeService {
...
@@ -12,4 +17,21 @@ public interface HomeService {
* 获取首页内容
* 获取首页内容
*/
*/
HomeContentResult
content
();
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
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/impl/HomeServiceImpl.java
View file @
cdf0c2b6
package
com.macro.mall.portal.service.impl
;
package
com.macro.mall.portal.service.impl
;
import
com.macro.mall.mapper.SmsFlashPromotionMapper
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.mapper.SmsFlashPromotionSessionMapper
;
import
com.macro.mall.mapper.*
;
import
com.macro.mall.mapper.SmsHomeAdvertiseMapper
;
import
com.macro.mall.model.*
;
import
com.macro.mall.model.*
;
import
com.macro.mall.portal.dao.HomeDao
;
import
com.macro.mall.portal.dao.HomeDao
;
import
com.macro.mall.portal.domain.FlashPromotionProduct
;
import
com.macro.mall.portal.domain.FlashPromotionProduct
;
import
com.macro.mall.portal.domain.HomeContentResult
;
import
com.macro.mall.portal.domain.HomeContentResult
;
import
com.macro.mall.portal.domain.HomeFlashPromotion
;
import
com.macro.mall.portal.domain.HomeFlashPromotion
;
import
com.macro.mall.portal.service.HomeService
;
import
com.macro.mall.portal.service.HomeService
;
import
com.macro.mall.portal.util.DateUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -31,6 +30,12 @@ public class HomeServiceImpl implements HomeService {
...
@@ -31,6 +30,12 @@ public class HomeServiceImpl implements HomeService {
private
SmsFlashPromotionMapper
flashPromotionMapper
;
private
SmsFlashPromotionMapper
flashPromotionMapper
;
@Autowired
@Autowired
private
SmsFlashPromotionSessionMapper
promotionSessionMapper
;
private
SmsFlashPromotionSessionMapper
promotionSessionMapper
;
@Autowired
private
PmsProductMapper
productMapper
;
@Autowired
private
PmsProductCategoryMapper
productCategoryMapper
;
@Autowired
private
CmsSubjectMapper
subjectMapper
;
@Override
@Override
public
HomeContentResult
content
()
{
public
HomeContentResult
content
()
{
...
@@ -50,6 +55,39 @@ public class HomeServiceImpl implements HomeService {
...
@@ -50,6 +55,39 @@ public class HomeServiceImpl implements HomeService {
return
result
;
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
()
{
private
HomeFlashPromotion
getHomeFlashPromotion
()
{
HomeFlashPromotion
homeFlashPromotion
=
new
HomeFlashPromotion
();
HomeFlashPromotion
homeFlashPromotion
=
new
HomeFlashPromotion
();
//获取当前秒杀活动
//获取当前秒杀活动
...
@@ -88,26 +126,6 @@ public class HomeServiceImpl implements HomeService {
...
@@ -88,26 +126,6 @@ public class HomeServiceImpl implements HomeService {
return
null
;
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
()
{
private
List
<
SmsHomeAdvertise
>
getHomeAdvertiseList
()
{
SmsHomeAdvertiseExample
example
=
new
SmsHomeAdvertiseExample
();
SmsHomeAdvertiseExample
example
=
new
SmsHomeAdvertiseExample
();
example
.
createCriteria
().
andTypeEqualTo
(
1
).
andStatusEqualTo
(
1
);
example
.
createCriteria
().
andTypeEqualTo
(
1
).
andStatusEqualTo
(
1
);
...
@@ -117,7 +135,7 @@ public class HomeServiceImpl implements HomeService {
...
@@ -117,7 +135,7 @@ public class HomeServiceImpl implements HomeService {
//根据时间获取秒杀活动
//根据时间获取秒杀活动
private
SmsFlashPromotion
getFlashPromotion
(
Date
date
)
{
private
SmsFlashPromotion
getFlashPromotion
(
Date
date
)
{
Date
currDate
=
getDate
(
date
);
Date
currDate
=
DateUtil
.
getDate
(
date
);
SmsFlashPromotionExample
example
=
new
SmsFlashPromotionExample
();
SmsFlashPromotionExample
example
=
new
SmsFlashPromotionExample
();
example
.
createCriteria
()
example
.
createCriteria
()
.
andStatusEqualTo
(
1
)
.
andStatusEqualTo
(
1
)
...
@@ -132,7 +150,7 @@ public class HomeServiceImpl implements HomeService {
...
@@ -132,7 +150,7 @@ public class HomeServiceImpl implements HomeService {
//根据时间获取秒杀场次
//根据时间获取秒杀场次
private
SmsFlashPromotionSession
getFlashPromotionSession
(
Date
date
)
{
private
SmsFlashPromotionSession
getFlashPromotionSession
(
Date
date
)
{
Date
currTime
=
getTime
(
date
);
Date
currTime
=
DateUtil
.
getTime
(
date
);
SmsFlashPromotionSessionExample
sessionExample
=
new
SmsFlashPromotionSessionExample
();
SmsFlashPromotionSessionExample
sessionExample
=
new
SmsFlashPromotionSessionExample
();
sessionExample
.
createCriteria
()
sessionExample
.
createCriteria
()
.
andStartTimeLessThanOrEqualTo
(
currTime
)
.
andStartTimeLessThanOrEqualTo
(
currTime
)
...
...
mall-portal/src/main/java/com/macro/mall/portal/util/DateUtil.java
0 → 100644
View file @
cdf0c2b6
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
();
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment