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
5f4a3783
Commit
5f4a3783
authored
May 23, 2020
by
macro
Browse files
前台商品、品牌接口完善
parent
6ff6d4c9
Changes
11
Hide whitespace changes
Inline
Side-by-side
mall-portal/src/main/java/com/macro/mall/portal/controller/PmsPortalProductController.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.controller
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.PmsProduct
;
import
com.macro.mall.portal.domain.PmsPortalProductDetail
;
import
com.macro.mall.portal.domain.PmsProductCategoryNode
;
import
com.macro.mall.portal.service.PmsPortalProductService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
* 前台商品管理Controller
* Created by macro on 2020/4/6.
*/
@Controller
@Api
(
tags
=
"PmsPortalProductController"
,
description
=
"前台商品管理"
)
@RequestMapping
(
"/product"
)
public
class
PmsPortalProductController
{
@Autowired
private
PmsPortalProductService
portalProductService
;
@ApiOperation
(
value
=
"综合搜索、筛选、排序"
)
@ApiImplicitParam
(
name
=
"sort"
,
value
=
"排序字段:0->按相关度;1->按新品;2->按销量;3->价格从低到高;4->价格从高到低"
,
defaultValue
=
"0"
,
allowableValues
=
"0,1,2,3,4"
,
paramType
=
"query"
,
dataType
=
"integer"
)
@RequestMapping
(
value
=
"/search"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
PmsProduct
>>
search
(
@RequestParam
(
required
=
false
)
String
keyword
,
@RequestParam
(
required
=
false
)
Long
brandId
,
@RequestParam
(
required
=
false
)
Long
productCategoryId
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
required
=
false
,
defaultValue
=
"5"
)
Integer
pageSize
,
@RequestParam
(
required
=
false
,
defaultValue
=
"0"
)
Integer
sort
)
{
List
<
PmsProduct
>
productList
=
portalProductService
.
search
(
keyword
,
brandId
,
productCategoryId
,
pageNum
,
pageSize
,
sort
);
return
CommonResult
.
success
(
CommonPage
.
restPage
(
productList
));
}
@ApiOperation
(
"以树形结构获取所有商品分类"
)
@RequestMapping
(
value
=
"/categoryTreeList"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
PmsProductCategoryNode
>>
categoryTreeList
()
{
List
<
PmsProductCategoryNode
>
list
=
portalProductService
.
categoryTreeList
();
return
CommonResult
.
success
(
list
);
}
@ApiOperation
(
"获取前台商品详情"
)
@RequestMapping
(
value
=
"/detail/{id}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
PmsPortalProductDetail
>
detail
(
@PathVariable
Long
id
)
{
PmsPortalProductDetail
productDetail
=
portalProductService
.
detail
(
id
);
return
CommonResult
.
success
(
productDetail
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/controller/PortalBrandController.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.controller
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.common.api.CommonResult
;
import
com.macro.mall.model.PmsBrand
;
import
com.macro.mall.model.PmsProduct
;
import
com.macro.mall.portal.service.PortalBrandService
;
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.*
;
import
java.util.List
;
/**
* 首页品牌推荐管理Controller
* Created by macro on 2020/5/15.
*/
@Controller
@Api
(
tags
=
"PortalBrandController"
,
description
=
"前台品牌管理"
)
@RequestMapping
(
"/brand"
)
public
class
PortalBrandController
{
@Autowired
private
PortalBrandService
homeBrandService
;
@ApiOperation
(
"分页获取推荐品牌"
)
@RequestMapping
(
value
=
"/recommendList"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
List
<
PmsBrand
>>
recommendList
(
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"6"
)
Integer
pageSize
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
)
{
List
<
PmsBrand
>
brandList
=
homeBrandService
.
recommendList
(
pageNum
,
pageSize
);
return
CommonResult
.
success
(
brandList
);
}
@ApiOperation
(
"获取品牌详情"
)
@RequestMapping
(
value
=
"/detail/{brandId}"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
PmsBrand
>
detail
(
@PathVariable
Long
brandId
)
{
PmsBrand
brand
=
homeBrandService
.
detail
(
brandId
);
return
CommonResult
.
success
(
brand
);
}
@ApiOperation
(
"分页获取品牌相关商品"
)
@RequestMapping
(
value
=
"/productList"
,
method
=
RequestMethod
.
GET
)
@ResponseBody
public
CommonResult
<
CommonPage
<
PmsProduct
>>
productList
(
@RequestParam
Long
brandId
,
@RequestParam
(
value
=
"pageNum"
,
defaultValue
=
"1"
)
Integer
pageNum
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"6"
)
Integer
pageSize
)
{
CommonPage
<
PmsProduct
>
result
=
homeBrandService
.
productList
(
brandId
,
pageNum
,
pageSize
);
return
CommonResult
.
success
(
result
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/dao/PortalProductDao.java
View file @
5f4a3783
package
com.macro.mall.portal.dao
;
import
com.macro.mall.model.SmsCoupon
;
import
com.macro.mall.portal.domain.CartProduct
;
import
com.macro.mall.portal.domain.PromotionProduct
;
import
org.apache.ibatis.annotations.Param
;
...
...
@@ -13,4 +14,5 @@ import java.util.List;
public
interface
PortalProductDao
{
CartProduct
getCartProduct
(
@Param
(
"id"
)
Long
id
);
List
<
PromotionProduct
>
getPromotionProductList
(
@Param
(
"ids"
)
List
<
Long
>
ids
);
List
<
SmsCoupon
>
getAvailableCouponList
(
@Param
(
"productId"
)
Long
productId
,
@Param
(
"productCategoryId"
)
Long
productCategoryId
);
}
mall-portal/src/main/java/com/macro/mall/portal/domain/PmsPortalProductDetail.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.domain
;
import
com.macro.mall.model.*
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* 前台商品详情
* Created by macro on 2020/4/6.
*/
@Getter
@Setter
public
class
PmsPortalProductDetail
{
@ApiModelProperty
(
"商品信息"
)
private
PmsProduct
product
;
@ApiModelProperty
(
"商品品牌"
)
private
PmsBrand
brand
;
@ApiModelProperty
(
"商品属性与参数"
)
private
List
<
PmsProductAttribute
>
productAttributeList
;
@ApiModelProperty
(
"手动录入的商品属性与参数值"
)
private
List
<
PmsProductAttributeValue
>
productAttributeValueList
;
@ApiModelProperty
(
"商品的sku库存信息"
)
private
List
<
PmsSkuStock
>
skuStockList
;
@ApiModelProperty
(
"商品阶梯价格设置"
)
private
List
<
PmsProductLadder
>
productLadderList
;
@ApiModelProperty
(
"商品满减价格设置"
)
private
List
<
PmsProductFullReduction
>
productFullReductionList
;
@ApiModelProperty
(
"商品可用优惠券"
)
private
List
<
SmsCoupon
>
couponList
;
}
mall-portal/src/main/java/com/macro/mall/portal/domain/PmsProductCategoryNode.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.domain
;
import
com.macro.mall.model.PmsProductCategory
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.util.List
;
/**
* 商品分类,包含子分类
* Created by macro on 2020/4/6.
*/
@Getter
@Setter
public
class
PmsProductCategoryNode
extends
PmsProductCategory
{
private
List
<
PmsProductCategoryNode
>
children
;
}
mall-portal/src/main/java/com/macro/mall/portal/service/PmsPortalProductService.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.service
;
import
com.macro.mall.model.PmsProduct
;
import
com.macro.mall.portal.domain.PmsPortalProductDetail
;
import
com.macro.mall.portal.domain.PmsProductCategoryNode
;
import
java.util.List
;
/**
* 前台商品管理Service
* Created by macro on 2020/4/6.
*/
public
interface
PmsPortalProductService
{
/**
* 综合搜索商品
*/
List
<
PmsProduct
>
search
(
String
keyword
,
Long
brandId
,
Long
productCategoryId
,
Integer
pageNum
,
Integer
pageSize
,
Integer
sort
);
/**
* 以树形结构获取所有商品分类
*/
List
<
PmsProductCategoryNode
>
categoryTreeList
();
/**
* 获取前台商品详情
*/
PmsPortalProductDetail
detail
(
Long
id
);
}
mall-portal/src/main/java/com/macro/mall/portal/service/PortalBrandService.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.service
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.model.PmsBrand
;
import
com.macro.mall.model.PmsProduct
;
import
java.util.List
;
/**
* 前台品牌管理Service
* Created by macro on 2020/5/15.
*/
public
interface
PortalBrandService
{
/**
* 分页获取推荐品牌
*/
List
<
PmsBrand
>
recommendList
(
Integer
pageNum
,
Integer
pageSize
);
/**
* 获取品牌详情
*/
PmsBrand
detail
(
Long
brandId
);
/**
* 分页获取品牌关联商品
*/
CommonPage
<
PmsProduct
>
productList
(
Long
brandId
,
Integer
pageNum
,
Integer
pageSize
);
}
mall-portal/src/main/java/com/macro/mall/portal/service/impl/PmsPortalProductServiceImpl.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.service.impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.mapper.*
;
import
com.macro.mall.model.*
;
import
com.macro.mall.portal.dao.PortalProductDao
;
import
com.macro.mall.portal.domain.PmsPortalProductDetail
;
import
com.macro.mall.portal.domain.PmsProductCategoryNode
;
import
com.macro.mall.portal.service.PmsPortalProductService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* 前台订单管理Service实现类
* Created by macro on 2020/4/6.
*/
@Service
public
class
PmsPortalProductServiceImpl
implements
PmsPortalProductService
{
@Autowired
private
PmsProductMapper
productMapper
;
@Autowired
private
PmsProductCategoryMapper
productCategoryMapper
;
@Autowired
private
PmsBrandMapper
brandMapper
;
@Autowired
private
PmsProductAttributeMapper
productAttributeMapper
;
@Autowired
private
PmsProductAttributeValueMapper
productAttributeValueMapper
;
@Autowired
private
PmsSkuStockMapper
skuStockMapper
;
@Autowired
private
PmsProductLadderMapper
productLadderMapper
;
@Autowired
private
PmsProductFullReductionMapper
productFullReductionMapper
;
@Autowired
private
PortalProductDao
portalProductDao
;
@Override
public
List
<
PmsProduct
>
search
(
String
keyword
,
Long
brandId
,
Long
productCategoryId
,
Integer
pageNum
,
Integer
pageSize
,
Integer
sort
)
{
PageHelper
.
startPage
(
pageNum
,
pageSize
);
PmsProductExample
example
=
new
PmsProductExample
();
PmsProductExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andDeleteStatusEqualTo
(
0
);
if
(
StrUtil
.
isNotEmpty
(
keyword
))
{
criteria
.
andNameLike
(
"%"
+
keyword
+
"%"
);
}
if
(
brandId
!=
null
)
{
criteria
.
andBrandIdEqualTo
(
brandId
);
}
if
(
productCategoryId
!=
null
)
{
criteria
.
andProductCategoryIdEqualTo
(
productCategoryId
);
}
//1->按新品;2->按销量;3->价格从低到高;4->价格从高到低
if
(
sort
==
1
)
{
example
.
setOrderByClause
(
"id desc"
);
}
else
if
(
sort
==
2
)
{
example
.
setOrderByClause
(
"sale desc"
);
}
else
if
(
sort
==
3
)
{
example
.
setOrderByClause
(
"price asc"
);
}
else
if
(
sort
==
4
)
{
example
.
setOrderByClause
(
"price desc"
);
}
return
productMapper
.
selectByExample
(
example
);
}
@Override
public
List
<
PmsProductCategoryNode
>
categoryTreeList
()
{
PmsProductCategoryExample
example
=
new
PmsProductCategoryExample
();
List
<
PmsProductCategory
>
allList
=
productCategoryMapper
.
selectByExample
(
example
);
List
<
PmsProductCategoryNode
>
result
=
allList
.
stream
()
.
filter
(
item
->
item
.
getParentId
().
equals
(
0L
))
.
map
(
item
->
covert
(
item
,
allList
)).
collect
(
Collectors
.
toList
());
return
result
;
}
@Override
public
PmsPortalProductDetail
detail
(
Long
id
)
{
PmsPortalProductDetail
result
=
new
PmsPortalProductDetail
();
//获取商品信息
PmsProduct
product
=
productMapper
.
selectByPrimaryKey
(
id
);
result
.
setProduct
(
product
);
//获取品牌信息
PmsBrand
brand
=
brandMapper
.
selectByPrimaryKey
(
product
.
getBrandId
());
result
.
setBrand
(
brand
);
//获取商品属性信息
PmsProductAttributeExample
attributeExample
=
new
PmsProductAttributeExample
();
attributeExample
.
createCriteria
().
andProductAttributeCategoryIdEqualTo
(
product
.
getProductAttributeCategoryId
());
List
<
PmsProductAttribute
>
productAttributeList
=
productAttributeMapper
.
selectByExample
(
attributeExample
);
result
.
setProductAttributeList
(
productAttributeList
);
//获取商品属性值信息
if
(
CollUtil
.
isNotEmpty
(
productAttributeList
)){
List
<
Long
>
attributeIds
=
productAttributeList
.
stream
().
map
(
PmsProductAttribute:
:
getId
).
collect
(
Collectors
.
toList
());
PmsProductAttributeValueExample
attributeValueExample
=
new
PmsProductAttributeValueExample
();
attributeValueExample
.
createCriteria
().
andProductIdEqualTo
(
product
.
getId
())
.
andProductAttributeIdIn
(
attributeIds
);
List
<
PmsProductAttributeValue
>
productAttributeValueList
=
productAttributeValueMapper
.
selectByExample
(
attributeValueExample
);
result
.
setProductAttributeValueList
(
productAttributeValueList
);
}
//获取商品SKU库存信息
PmsSkuStockExample
skuExample
=
new
PmsSkuStockExample
();
skuExample
.
createCriteria
().
andProductIdEqualTo
(
product
.
getId
());
List
<
PmsSkuStock
>
skuStockList
=
skuStockMapper
.
selectByExample
(
skuExample
);
result
.
setSkuStockList
(
skuStockList
);
//商品阶梯价格设置
if
(
product
.
getPromotionType
()==
3
){
PmsProductLadderExample
ladderExample
=
new
PmsProductLadderExample
();
ladderExample
.
createCriteria
().
andProductIdEqualTo
(
product
.
getId
());
List
<
PmsProductLadder
>
productLadderList
=
productLadderMapper
.
selectByExample
(
ladderExample
);
result
.
setProductLadderList
(
productLadderList
);
}
//商品满减价格设置
if
(
product
.
getPromotionType
()==
4
){
PmsProductFullReductionExample
fullReductionExample
=
new
PmsProductFullReductionExample
();
fullReductionExample
.
createCriteria
().
andProductIdEqualTo
(
product
.
getId
());
List
<
PmsProductFullReduction
>
productFullReductionList
=
productFullReductionMapper
.
selectByExample
(
fullReductionExample
);
result
.
setProductFullReductionList
(
productFullReductionList
);
}
//商品可用优惠券
result
.
setCouponList
(
portalProductDao
.
getAvailableCouponList
(
product
.
getId
(),
product
.
getProductCategoryId
()));
return
result
;
}
/**
* 初始对象转化为节点对象
*/
private
PmsProductCategoryNode
covert
(
PmsProductCategory
item
,
List
<
PmsProductCategory
>
allList
)
{
PmsProductCategoryNode
node
=
new
PmsProductCategoryNode
();
BeanUtils
.
copyProperties
(
item
,
node
);
List
<
PmsProductCategoryNode
>
children
=
allList
.
stream
()
.
filter
(
subItem
->
subItem
.
getParentId
().
equals
(
item
.
getId
()))
.
map
(
subItem
->
covert
(
subItem
,
allList
)).
collect
(
Collectors
.
toList
());
node
.
setChildren
(
children
);
return
node
;
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/impl/PortalBrandServiceImpl.java
0 → 100644
View file @
5f4a3783
package
com.macro.mall.portal.service.impl
;
import
com.github.pagehelper.PageHelper
;
import
com.macro.mall.common.api.CommonPage
;
import
com.macro.mall.mapper.PmsBrandMapper
;
import
com.macro.mall.mapper.PmsProductMapper
;
import
com.macro.mall.model.PmsBrand
;
import
com.macro.mall.model.PmsProduct
;
import
com.macro.mall.model.PmsProductExample
;
import
com.macro.mall.portal.dao.HomeDao
;
import
com.macro.mall.portal.service.PortalBrandService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 前台品牌管理Service实现类
* Created by macro on 2020/5/15.
*/
@Service
public
class
PortalBrandServiceImpl
implements
PortalBrandService
{
@Autowired
private
HomeDao
homeDao
;
@Autowired
private
PmsBrandMapper
brandMapper
;
@Autowired
private
PmsProductMapper
productMapper
;
@Override
public
List
<
PmsBrand
>
recommendList
(
Integer
pageNum
,
Integer
pageSize
)
{
int
offset
=
(
pageNum
-
1
)
*
pageSize
;
return
homeDao
.
getRecommendBrandList
(
offset
,
pageSize
);
}
@Override
public
PmsBrand
detail
(
Long
brandId
)
{
return
brandMapper
.
selectByPrimaryKey
(
brandId
);
}
@Override
public
CommonPage
<
PmsProduct
>
productList
(
Long
brandId
,
Integer
pageNum
,
Integer
pageSize
)
{
PageHelper
.
startPage
(
pageNum
,
pageSize
);
PmsProductExample
example
=
new
PmsProductExample
();
example
.
createCriteria
().
andDeleteStatusEqualTo
(
0
)
.
andBrandIdEqualTo
(
brandId
);
List
<
PmsProduct
>
productList
=
productMapper
.
selectByExample
(
example
);
return
CommonPage
.
restPage
(
productList
);
}
}
mall-portal/src/main/resources/application.yml
View file @
5f4a3783
...
...
@@ -29,6 +29,8 @@ secure:
-
/actuator/**
-
/sso/**
-
/home/**
-
/product/**
-
/brand/**
# 自定义redis key
redis
:
...
...
mall-portal/src/main/resources/dao/PortalProductDao.xml
View file @
5f4a3783
...
...
@@ -72,4 +72,31 @@
#{id}
</foreach>
</select>
<select
id=
"getAvailableCouponList"
resultMap=
"com.macro.mall.mapper.SmsCouponMapper.BaseResultMap"
>
SELECT *
FROM sms_coupon
WHERE use_type = 0
AND start_time
<
NOW()
AND end_time
>
NOW()
UNION
(
SELECT c.*
FROM sms_coupon_product_category_relation cpc
LEFT JOIN sms_coupon c ON cpc.coupon_id = c.id
WHERE c.use_type = 1
AND c.start_time
<
NOW()
AND c.end_time
>
NOW()
AND cpc.product_category_id = #{productCategoryId}
)
UNION
(
SELECT c.*
FROM sms_coupon_product_relation cp
LEFT JOIN sms_coupon c ON cp.coupon_id = c.id
WHERE c.use_type = 2
AND c.start_time
<
NOW()
AND c.end_time
>
NOW()
AND cp.product_id = #{productId}
)
</select>
</mapper>
\ No newline at end of file
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