Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
cb214744
Commit
cb214744
authored
Jul 23, 2022
by
caiyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复优化优惠券联调过程中遇到的问题
parent
480adf6d
Show whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
565 additions
and
63 deletions
+565
-63
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponCategoryController.java
+13
-1
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponController.java
+141
-6
soss-common/src/main/java/com/soss/common/enums/CouponState.java
+3
-3
soss-system/src/main/java/com/soss/system/domain/Coupon.java
+7
-0
soss-system/src/main/java/com/soss/system/domain/CouponCategory.java
+1
-0
soss-system/src/main/java/com/soss/system/domain/CouponRule.java
+2
-2
soss-system/src/main/java/com/soss/system/domain/po/CouponListPo.java
+18
-0
soss-system/src/main/java/com/soss/system/domain/po/CouponPo.java
+12
-28
soss-system/src/main/java/com/soss/system/domain/vo/CouponVo.java
+43
-0
soss-system/src/main/java/com/soss/system/mapper/CouponMapper.java
+15
-1
soss-system/src/main/java/com/soss/system/mapper/CouponRuleMapper.java
+11
-1
soss-system/src/main/java/com/soss/system/service/ICouponCategoryService.java
+2
-0
soss-system/src/main/java/com/soss/system/service/ICouponRuleService.java
+8
-0
soss-system/src/main/java/com/soss/system/service/ICouponService.java
+15
-0
soss-system/src/main/java/com/soss/system/service/impl/CouponCategoryServiceImpl.java
+57
-4
soss-system/src/main/java/com/soss/system/service/impl/CouponRuleServiceImpl.java
+29
-0
soss-system/src/main/java/com/soss/system/service/impl/CouponServiceImpl.java
+93
-11
soss-system/src/main/resources/mapper/system/CouponCategoryMapper.xml
+11
-3
soss-system/src/main/resources/mapper/system/CouponMapper.xml
+19
-1
soss-system/src/main/resources/mapper/system/CouponRuleMapper.xml
+9
-2
soss-system/src/main/resources/mapper/system/CouponUserMapper.xml
+56
-0
No files found.
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponCategoryController.java
View file @
cb214744
...
@@ -44,11 +44,23 @@ public class CouponCategoryController extends BaseController {
...
@@ -44,11 +44,23 @@ public class CouponCategoryController extends BaseController {
}
}
/**
/**
* 更新优惠券类别
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:category:update')"
)
@Log
(
title
=
"更新优惠券类别"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
(
"update"
)
@ApiOperation
(
"更新优惠券类别"
)
public
AjaxResult
update
(
@RequestBody
CouponCategory
couponCategory
)
{
couponCategoryService
.
updateCouponCategory
(
couponCategory
);
return
AjaxResult
.
success
();
}
/**
* 查询优惠券类别列表
* 查询优惠券类别列表
*/
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:category:list')"
)
@PreAuthorize
(
"@ss.hasPermi('coupon:category:list')"
)
@Log
(
title
=
"查询优惠券类别列表"
,
businessType
=
BusinessType
.
INSERT
)
@Log
(
title
=
"查询优惠券类别列表"
,
businessType
=
BusinessType
.
INSERT
)
@
Ge
tMapping
@
Pos
tMapping
@ApiOperation
(
"查询优惠券类别列表"
)
@ApiOperation
(
"查询优惠券类别列表"
)
public
TableDataInfo
listCouponCategory
(
@RequestBody
CouponCategory
couponCategory
)
{
public
TableDataInfo
listCouponCategory
(
@RequestBody
CouponCategory
couponCategory
)
{
startPage
();
startPage
();
...
...
soss-admin/src/main/java/com/soss/web/controller/coupon/CouponController.java
View file @
cb214744
...
@@ -2,18 +2,33 @@ package com.soss.web.controller.coupon;
...
@@ -2,18 +2,33 @@ package com.soss.web.controller.coupon;
import
com.soss.common.annotation.Log
;
import
com.soss.common.annotation.Log
;
import
com.soss.common.core.controller.BaseController
;
import
com.soss.common.core.domain.AjaxResult
;
import
com.soss.common.core.domain.AjaxResult
;
import
com.soss.common.core.page.TableDataInfo
;
import
com.soss.common.enums.BusinessType
;
import
com.soss.common.enums.BusinessType
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponState
;
import
com.soss.common.utils.StringUtils
;
import
com.soss.common.utils.bean.BeanUtils
;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.CouponRule
;
import
com.soss.system.domain.po.CouponListPo
;
import
com.soss.system.domain.po.CouponPo
;
import
com.soss.system.domain.po.CouponPo
;
import
com.soss.system.domain.vo.CouponVo
;
import
com.soss.system.service.ICouponRuleService
;
import
com.soss.system.service.ICouponService
;
import
com.soss.system.service.ICouponService
;
import
io.swagger.annotations.Api
;
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.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.PutMapping
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
/**
* <p>
* <p>
...
@@ -26,9 +41,80 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -26,9 +41,80 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RestController
@Api
(
tags
=
"优惠券服务类"
)
@Api
(
tags
=
"优惠券服务类"
)
@RequestMapping
(
"/coupon"
)
@RequestMapping
(
"/coupon"
)
public
class
CouponController
{
public
class
CouponController
extends
BaseController
{
@Autowired
@Autowired
private
ICouponService
couponService
;
private
ICouponService
couponService
;
@Autowired
private
ICouponRuleService
couponRuleService
;
/**
* 查询优惠券列表
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:list')"
)
@Log
(
title
=
"查询优惠券列表"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
(
"list"
)
@ApiOperation
(
"查询优惠券列表"
)
public
TableDataInfo
listCoupon
(
@RequestBody
CouponListPo
couponListPo
)
{
startPage
();
Coupon
couponParam
=
new
Coupon
();
BeanUtils
.
copyProperties
(
couponListPo
,
couponParam
);
List
<
Coupon
>
coupons
=
couponService
.
list
(
couponParam
);
Map
<
Integer
,
CouponRule
>
ruleMap
;
if
(
CollectionUtils
.
isEmpty
(
coupons
))
{
ruleMap
=
new
HashMap
<>();
}
else
{
List
<
Integer
>
ruleIds
=
coupons
.
stream
().
map
(
Coupon:
:
getRuleId
).
collect
(
Collectors
.
toList
());
ruleMap
=
couponRuleService
.
getCouponRuleMap
(
ruleIds
);
}
List
<
CouponVo
>
voList
=
coupons
.
stream
().
map
(
coupon
->
{
CouponVo
couponVo
=
new
CouponVo
();
BeanUtils
.
copyProperties
(
coupon
,
couponVo
);
couponVo
.
setStateDesc
(
CouponState
.
getDesc
(
coupon
.
getState
()));
couponVo
.
setTypeDesc
(
CouponCategoryType
.
getDesc
(
coupon
.
getType
()));
CouponRule
couponRule
=
ruleMap
.
get
(
coupon
.
getRuleId
());
if
(
couponRule
!=
null
)
{
BeanUtils
.
copyProperties
(
couponRule
,
couponVo
,
"name"
,
"state"
,
"categoryIds"
,
"goodsIds"
,
"province"
,
"city"
,
"area"
,
"shopIds"
);
couponVo
.
setRuleId
(
coupon
.
getRuleId
());
couponVo
.
setRuleName
(
couponRule
.
getName
());
couponVo
.
setRuleDesc
(
couponRule
.
getDesc
());
}
return
couponVo
;
}).
collect
(
Collectors
.
toList
());
return
getDataTable
(
voList
);
}
/**
* 获取优惠券详情
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:detail')"
)
@Log
(
title
=
"获取优惠券详情"
,
businessType
=
BusinessType
.
INSERT
)
@GetMapping
(
"/detail/{id}"
)
@ApiOperation
(
"获取优惠券详情"
)
public
AjaxResult
detail
(
@PathVariable
Integer
id
)
{
Coupon
coupon
=
couponService
.
detail
(
id
);
CouponVo
couponVo
=
new
CouponVo
();
BeanUtils
.
copyProperties
(
coupon
,
couponVo
);
CouponRule
couponRule
=
couponRuleService
.
detail
(
coupon
.
getRuleId
());
BeanUtils
.
copyProperties
(
couponRule
,
couponVo
,
"name"
,
"state"
,
"categoryIds"
,
"goodsIds"
,
"province"
,
"city"
,
"area"
,
"shopIds"
);
couponVo
.
setCategoryIds
(
transStrToIntList
(
couponRule
.
getCategoryIds
()));
couponVo
.
setGoodsIds
(
transStrToIntList
(
couponRule
.
getGoodsIds
()));
couponVo
.
setProvince
(
transStrToCodeList
(
couponRule
.
getProvince
()));
couponVo
.
setCity
(
transStrToCodeList
(
couponRule
.
getCity
()));
couponVo
.
setArea
(
transStrToCodeList
(
couponRule
.
getArea
()));
couponVo
.
setShopIds
(
transStrToIntList
(
couponRule
.
getShopIds
()));
return
AjaxResult
.
success
(
couponVo
);
}
private
String
[]
transStrToCodeList
(
String
codeStr
)
{
return
StringUtils
.
isEmpty
(
codeStr
)
?
null
:
codeStr
.
split
(
","
);
}
private
Integer
[]
transStrToIntList
(
String
idsStr
)
{
if
(
StringUtils
.
isEmpty
(
idsStr
))
{
return
null
;
}
return
Arrays
.
stream
(
idsStr
.
split
(
","
)).
map
(
Integer:
:
parseInt
).
toArray
(
Integer
[]::
new
);
}
/**
/**
* 新增优惠券
* 新增优惠券
...
@@ -47,10 +133,59 @@ public class CouponController {
...
@@ -47,10 +133,59 @@ public class CouponController {
*/
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:update')"
)
@PreAuthorize
(
"@ss.hasPermi('coupon:update')"
)
@Log
(
title
=
"更新优惠券"
,
businessType
=
BusinessType
.
INSERT
)
@Log
(
title
=
"更新优惠券"
,
businessType
=
BusinessType
.
INSERT
)
@P
u
tMapping
@P
os
tMapping
@ApiOperation
(
"更新优惠券"
)
@ApiOperation
(
"更新优惠券"
)
public
AjaxResult
update
(
@RequestBody
CouponPo
couponPo
)
{
public
AjaxResult
update
(
@RequestBody
CouponPo
couponPo
)
{
couponService
.
update
(
couponPo
);
couponService
.
update
(
couponPo
);
return
AjaxResult
.
success
();
return
AjaxResult
.
success
();
}
}
/**
* 上架优惠券
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:online')"
)
@Log
(
title
=
"上架优惠券"
,
businessType
=
BusinessType
.
INSERT
)
@GetMapping
(
"/online/{id}"
)
@ApiOperation
(
"上架优惠券"
)
public
AjaxResult
onlineCoupon
(
@PathVariable
Integer
id
)
{
int
updateCnt
=
couponService
.
onlineCoupon
(
id
);
return
toAjax
(
updateCnt
);
}
/**
* 下架优惠券
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:offline')"
)
@Log
(
title
=
"下架优惠券"
,
businessType
=
BusinessType
.
INSERT
)
@GetMapping
(
"/offline/{id}"
)
@ApiOperation
(
"下架优惠券"
)
public
AjaxResult
offlineCoupon
(
@PathVariable
Integer
id
)
{
int
updateCnt
=
couponService
.
offlineCoupon
(
id
);
return
toAjax
(
updateCnt
);
}
/**
* 删除优惠券
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:delete')"
)
@Log
(
title
=
"删除优惠券"
,
businessType
=
BusinessType
.
INSERT
)
@DeleteMapping
(
"/{id}"
)
@ApiOperation
(
"删除优惠券"
)
public
AjaxResult
deleteCoupon
(
@PathVariable
Integer
id
)
{
int
updateCnt
=
couponService
.
deleteCoupon
(
id
);
return
toAjax
(
updateCnt
);
}
/**
* 获取当前有效的规则集合
*/
@PreAuthorize
(
"@ss.hasPermi('coupon:list:effective')"
)
@Log
(
title
=
"获取当前有效的规则集合"
,
businessType
=
BusinessType
.
INSERT
)
@DeleteMapping
(
"/list/effective"
)
@ApiOperation
(
"获取当前有效的规则集合"
)
public
TableDataInfo
listEffective
()
{
startPage
();
List
<
Coupon
>
effectiveCoupons
=
couponService
.
getEffectiveCoupon
();
return
getDataTable
(
effectiveCoupons
);
}
}
}
soss-common/src/main/java/com/soss/common/enums/CouponState.java
View file @
cb214744
...
@@ -2,9 +2,9 @@ package com.soss.common.enums;
...
@@ -2,9 +2,9 @@ package com.soss.common.enums;
public
enum
CouponState
{
public
enum
CouponState
{
DEFAULT
(
0
,
"默认"
),
DEFAULT
(
0
,
"默认"
),
ONLINE
(
1
,
"
上架
"
),
ONLINE
(
1
,
"
生效中
"
),
OFFLINE
(
2
,
"
下架
"
),
OFFLINE
(
2
,
"
未生效
"
),
DELETE
(
3
,
"删除"
);
DELETE
(
3
,
"
已
删除"
);
private
Integer
state
;
private
Integer
state
;
private
String
desc
;
private
String
desc
;
...
...
soss-system/src/main/java/com/soss/system/domain/Coupon.java
View file @
cb214744
...
@@ -3,6 +3,7 @@ package com.soss.system.domain;
...
@@ -3,6 +3,7 @@ package com.soss.system.domain;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.soss.common.core.domain.BaseEntity
;
import
com.soss.common.core.domain.BaseEntity
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -15,6 +16,7 @@ import java.time.LocalDateTime;
...
@@ -15,6 +16,7 @@ import java.time.LocalDateTime;
* @since 2022-07-21
* @since 2022-07-21
*/
*/
@Data
@Data
@NoArgsConstructor
public
class
Coupon
extends
BaseEntity
{
public
class
Coupon
extends
BaseEntity
{
/**
/**
* 主键
* 主键
...
@@ -67,4 +69,9 @@ public class Coupon extends BaseEntity {
...
@@ -67,4 +69,9 @@ public class Coupon extends BaseEntity {
*/
*/
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
LocalDateTime
updatedAt
;
private
LocalDateTime
updatedAt
;
public
Coupon
(
Integer
id
,
Integer
state
)
{
this
.
id
=
id
;
this
.
state
=
state
;
}
}
}
soss-system/src/main/java/com/soss/system/domain/CouponCategory.java
View file @
cb214744
...
@@ -32,6 +32,7 @@ public class CouponCategory extends BaseEntity {
...
@@ -32,6 +32,7 @@ public class CouponCategory extends BaseEntity {
* 状态 0 默认 1 生效 2 下线 3删除
* 状态 0 默认 1 生效 2 下线 3删除
*/
*/
private
Integer
state
;
private
Integer
state
;
private
String
stateDesc
;
/**
/**
* 优惠券类别描述
* 优惠券类别描述
...
...
soss-system/src/main/java/com/soss/system/domain/CouponRule.java
View file @
cb214744
...
@@ -104,7 +104,7 @@ public class CouponRule extends BaseEntity {
...
@@ -104,7 +104,7 @@ public class CouponRule extends BaseEntity {
/**
/**
* 订单限制 0 整单 1 单杯
* 订单限制 0 整单 1 单杯
*/
*/
private
Integer
orderLimit
;
private
Boolean
orderLimit
;
/**
/**
* 周几限制 1,2,3
* 周几限制 1,2,3
...
@@ -124,7 +124,7 @@ public class CouponRule extends BaseEntity {
...
@@ -124,7 +124,7 @@ public class CouponRule extends BaseEntity {
/**
/**
* 是否发送短信0不1发
* 是否发送短信0不1发
*/
*/
private
Integer
sendMsg
;
private
Boolean
sendMsg
;
/**
/**
* 短信模板ID
* 短信模板ID
...
...
soss-system/src/main/java/com/soss/system/domain/po/CouponListPo.java
0 → 100644
View file @
cb214744
package
com
.
soss
.
system
.
domain
.
po
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
@Data
@ApiModel
(
"优惠券列表请求类"
)
public
class
CouponListPo
{
@ApiModelProperty
(
"优惠劵名"
)
private
String
name
;
@ApiModelProperty
(
"优惠券类别ID"
)
private
Integer
categoryId
;
@ApiModelProperty
(
"优惠券状态"
)
private
Integer
state
;
}
soss-system/src/main/java/com/soss/system/domain/po/CouponPo.java
View file @
cb214744
...
@@ -5,7 +5,6 @@ import com.soss.common.exception.ServiceException;
...
@@ -5,7 +5,6 @@ import com.soss.common.exception.ServiceException;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
org.springframework.util.CollectionUtils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
...
@@ -20,41 +19,26 @@ public class CouponPo {
...
@@ -20,41 +19,26 @@ public class CouponPo {
@ApiModelProperty
(
"优惠劵名"
)
@ApiModelProperty
(
"优惠劵名"
)
private
String
name
;
private
String
name
;
@ApiModelProperty
(
"优惠券编码"
)
private
String
serialNo
;
@ApiModelProperty
(
"优惠券类别ID"
)
@ApiModelProperty
(
"优惠券类别ID"
)
private
Integer
categoryId
;
private
Integer
categoryId
;
@ApiModelProperty
(
"优惠券类别名"
)
@ApiModelProperty
(
"可用商品类别列表,全品类传 [0]"
)
private
String
categoryName
;
private
Integer
[]
categoryIds
;
@ApiModelProperty
(
"优惠券规则id"
)
private
Integer
ruleId
;
@ApiModelProperty
(
"优惠券类型 1 抵扣 2 折扣 3 免单"
)
private
Integer
type
;
@ApiModelProperty
(
"优惠劵规则描述"
)
private
String
desc
;
@ApiModelProperty
(
"可用商品类别列表"
)
private
List
<
Integer
>
categoryIds
;
@ApiModelProperty
(
"可用商品id列表"
)
@ApiModelProperty
(
"可用商品id列表"
)
private
List
<
Integer
>
goodsIds
;
private
Integer
[]
goodsIds
;
@ApiModelProperty
(
"可用省份列表
可存code列表
"
)
@ApiModelProperty
(
"可用省份列表
,全国通用传 [0]
"
)
private
List
<
String
>
province
;
private
String
[]
province
;
@ApiModelProperty
(
"可用城市列表"
)
@ApiModelProperty
(
"可用城市列表"
)
private
List
<
String
>
city
;
private
String
[]
city
;
@ApiModelProperty
(
"可用区域列表"
)
@ApiModelProperty
(
"可用区域列表"
)
private
List
<
String
>
area
;
private
String
[]
area
;
@ApiModelProperty
(
"可用店铺ID列表"
)
@ApiModelProperty
(
"可用店铺ID列表"
)
private
List
<
Integer
>
shopIds
;
private
Integer
[]
shopIds
;
@ApiModelProperty
(
"领取开始时间"
)
@ApiModelProperty
(
"领取开始时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
...
@@ -101,16 +85,16 @@ public class CouponPo {
...
@@ -101,16 +85,16 @@ public class CouponPo {
public
void
couponUseLimitCheck
()
{
public
void
couponUseLimitCheck
()
{
int
limitDim
=
0
;
int
limitDim
=
0
;
if
(
!
CollectionUtils
.
isEmpty
(
province
)
)
{
if
(
province
!=
null
&&
province
.
length
>
0
)
{
limitDim
+=
1
;
limitDim
+=
1
;
}
}
if
(
!
CollectionUtils
.
isEmpty
(
city
)
)
{
if
(
city
!=
null
&&
city
.
length
>
0
)
{
limitDim
+=
1
;
limitDim
+=
1
;
}
}
if
(
!
CollectionUtils
.
isEmpty
(
area
)
)
{
if
(
area
!=
null
&&
area
.
length
>
0
)
{
limitDim
+=
1
;
limitDim
+=
1
;
}
}
if
(
!
CollectionUtils
.
isEmpty
(
shopIds
)
)
{
if
(
shopIds
!=
null
&&
shopIds
.
length
>
0
)
{
limitDim
+=
1
;
limitDim
+=
1
;
}
}
if
(
limitDim
>
1
)
{
if
(
limitDim
>
1
)
{
...
...
soss-system/src/main/java/com/soss/system/domain/vo/CouponVo.java
View file @
cb214744
...
@@ -8,6 +8,49 @@ import lombok.Data;
...
@@ -8,6 +8,49 @@ import lombok.Data;
@ApiModel
@ApiModel
@Data
@Data
public
class
CouponVo
extends
CouponPo
{
public
class
CouponVo
extends
CouponPo
{
@ApiModelProperty
(
"优惠券规则id"
)
private
Integer
ruleId
;
@ApiModelProperty
(
"优惠劵规则名称"
)
@ApiModelProperty
(
"优惠劵规则名称"
)
private
String
ruleName
;
private
String
ruleName
;
@ApiModelProperty
(
"优惠劵规则描述"
)
private
String
ruleDesc
;
@ApiModelProperty
(
"优惠券编码"
)
private
String
serialNo
;
@ApiModelProperty
(
"优惠券类型 1 抵扣 2 折扣 3 免单"
)
private
Integer
type
;
@ApiModelProperty
(
"优惠券类型描述"
)
private
String
typeDesc
;
@ApiModelProperty
(
"优惠券状态"
)
private
Integer
state
;
@ApiModelProperty
(
"优惠券状态描述"
)
private
String
stateDesc
;
@ApiModelProperty
(
"优惠券类别名"
)
private
String
categoryName
;
@ApiModelProperty
(
"可用商品类别描述"
)
private
String
categoryDesc
;
@ApiModelProperty
(
"可用商品描述"
)
private
String
goodsDesc
;
@ApiModelProperty
(
"可用省份描述"
)
private
String
provinceDesc
;
@ApiModelProperty
(
"可用城市描述"
)
private
String
cityDesc
;
@ApiModelProperty
(
"可用区域描述"
)
private
String
areaDesc
;
@ApiModelProperty
(
"可用店铺描述"
)
private
String
shopDesc
;
}
}
soss-system/src/main/java/com/soss/system/mapper/CouponMapper.java
View file @
cb214744
...
@@ -2,7 +2,6 @@ package com.soss.system.mapper;
...
@@ -2,7 +2,6 @@ package com.soss.system.mapper;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.domain.CouponRule
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
...
@@ -16,6 +15,14 @@ import java.util.List;
...
@@ -16,6 +15,14 @@ import java.util.List;
* @since 2022-07-21
* @since 2022-07-21
*/
*/
public
interface
CouponMapper
{
public
interface
CouponMapper
{
/**
* 查询优惠券列表
*
* @param coupon
* @return
*/
List
<
Coupon
>
listCoupon
(
Coupon
coupon
);
List
<
CouponCategory
>
getCouponCategoryTypeStat
(
@Param
(
"categoryIds"
)
List
<
Integer
>
categoryIds
);
List
<
CouponCategory
>
getCouponCategoryTypeStat
(
@Param
(
"categoryIds"
)
List
<
Integer
>
categoryIds
);
/**
/**
...
@@ -41,4 +48,11 @@ public interface CouponMapper {
...
@@ -41,4 +48,11 @@ public interface CouponMapper {
* @return
* @return
*/
*/
Coupon
selectCouponById
(
Integer
id
);
Coupon
selectCouponById
(
Integer
id
);
/**
* 获取当前有效的规则集合
*
* @return
*/
List
<
Coupon
>
getEffectiveCoupon
();
}
}
soss-system/src/main/java/com/soss/system/mapper/CouponRuleMapper.java
View file @
cb214744
package
com
.
soss
.
system
.
mapper
;
package
com
.
soss
.
system
.
mapper
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.domain.CouponRule
;
import
com.soss.system.domain.CouponRule
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
/**
* <p>
* <p>
...
@@ -35,4 +37,12 @@ public interface CouponRuleMapper {
...
@@ -35,4 +37,12 @@ public interface CouponRuleMapper {
* @return
* @return
*/
*/
CouponRule
selectCouponRuleById
(
Integer
id
);
CouponRule
selectCouponRuleById
(
Integer
id
);
/**
* 查询优惠券规则列表
*
* @param ids
* @return
*/
List
<
CouponRule
>
selectCouponRuleByIds
(
@Param
(
"ids"
)
List
<
Integer
>
ids
);
}
}
soss-system/src/main/java/com/soss/system/service/ICouponCategoryService.java
View file @
cb214744
...
@@ -16,6 +16,8 @@ public interface ICouponCategoryService {
...
@@ -16,6 +16,8 @@ public interface ICouponCategoryService {
void
insertCouponCategory
(
CouponCategory
couponCategory
);
void
insertCouponCategory
(
CouponCategory
couponCategory
);
void
updateCouponCategory
(
CouponCategory
couponCategory
);
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
);
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
);
int
onlineCouponCategory
(
Integer
id
);
int
onlineCouponCategory
(
Integer
id
);
...
...
soss-system/src/main/java/com/soss/system/service/ICouponRuleService.java
View file @
cb214744
package
com
.
soss
.
system
.
service
;
package
com
.
soss
.
system
.
service
;
import
com.soss.system.domain.CouponRule
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* <p>
* <p>
* 优惠券规则 服务类
* 优惠券规则 服务类
...
@@ -10,4 +15,7 @@ package com.soss.system.service;
...
@@ -10,4 +15,7 @@ package com.soss.system.service;
*/
*/
public
interface
ICouponRuleService
{
public
interface
ICouponRuleService
{
Map
<
Integer
,
CouponRule
>
getCouponRuleMap
(
List
<
Integer
>
ids
);
CouponRule
detail
(
Integer
id
);
}
}
soss-system/src/main/java/com/soss/system/service/ICouponService.java
View file @
cb214744
package
com
.
soss
.
system
.
service
;
package
com
.
soss
.
system
.
service
;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.po.CouponPo
;
import
com.soss.system.domain.po.CouponPo
;
import
java.util.List
;
/**
/**
* <p>
* <p>
* 优惠券 服务类
* 优惠券 服务类
...
@@ -12,7 +15,19 @@ import com.soss.system.domain.po.CouponPo;
...
@@ -12,7 +15,19 @@ import com.soss.system.domain.po.CouponPo;
*/
*/
public
interface
ICouponService
{
public
interface
ICouponService
{
List
<
Coupon
>
list
(
Coupon
coupon
);
Coupon
detail
(
Integer
id
);
void
save
(
CouponPo
couponPo
);
void
save
(
CouponPo
couponPo
);
void
update
(
CouponPo
couponPo
);
void
update
(
CouponPo
couponPo
);
int
onlineCoupon
(
Integer
id
);
int
offlineCoupon
(
Integer
id
);
int
deleteCoupon
(
Integer
id
);
List
<
Coupon
>
getEffectiveCoupon
();
}
}
soss-system/src/main/java/com/soss/system/service/impl/CouponCategoryServiceImpl.java
View file @
cb214744
...
@@ -2,16 +2,21 @@ package com.soss.system.service.impl;
...
@@ -2,16 +2,21 @@ package com.soss.system.service.impl;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponState
;
import
com.soss.common.enums.CouponState
;
import
com.soss.common.exception.ServiceException
;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.domain.CouponCategory
;
import
com.soss.system.mapper.CouponCategoryMapper
;
import
com.soss.system.mapper.CouponCategoryMapper
;
import
com.soss.system.mapper.CouponMapper
;
import
com.soss.system.mapper.CouponMapper
;
import
com.soss.system.service.ICouponCategoryService
;
import
com.soss.system.service.ICouponCategoryService
;
import
io.jsonwebtoken.lang.Assert
;
import
io.jsonwebtoken.lang.Assert
;
import
org.apache.http.util.Asserts
;
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.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -43,12 +48,34 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
...
@@ -43,12 +48,34 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
Assert
.
notNull
(
couponCategory
.
getName
(),
"优惠券类别名称还未填写"
);
Assert
.
notNull
(
couponCategory
.
getName
(),
"优惠券类别名称还未填写"
);
Assert
.
notNull
(
couponCategory
.
getType
(),
"优惠券类别的折扣形式还未选择"
);
Assert
.
notNull
(
couponCategory
.
getType
(),
"优惠券类别的折扣形式还未选择"
);
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
now
=
LocalDateTime
.
now
();
couponCategory
.
setState
(
CouponState
.
ONLINE
.
getState
());
couponCategory
.
setCreatedAt
(
now
);
couponCategory
.
setCreatedAt
(
now
);
couponCategory
.
setUpdatedAt
(
now
);
couponCategory
.
setUpdatedAt
(
now
);
couponCategoryMapper
.
insertCouponCategory
(
couponCategory
);
couponCategoryMapper
.
insertCouponCategory
(
couponCategory
);
}
}
/**
/**
* 修改优惠券类别
*
* @param couponCategory 优惠券类别
* @return 结果
*/
@Override
@Transactional
public
void
updateCouponCategory
(
CouponCategory
couponCategory
)
{
Asserts
.
notNull
(
couponCategory
.
getId
(),
"优惠券类别ID还未传递"
);
CouponCategory
couponCategoryOri
=
this
.
detail
(
couponCategory
.
getId
());
if
(!
couponCategoryOri
.
getState
().
equals
(
CouponState
.
OFFLINE
.
getState
()))
{
throw
new
ServiceException
(
"修改类别需先下架类别"
);
}
Assert
.
notNull
(
couponCategory
.
getName
(),
"优惠券类别名称还未填写"
);
Assert
.
notNull
(
couponCategory
.
getType
(),
"优惠券类别的折扣形式还未选择"
);
LocalDateTime
now
=
LocalDateTime
.
now
();
couponCategory
.
setUpdatedAt
(
now
);
couponCategoryMapper
.
updateCouponCategory
(
couponCategory
);
}
/**
* 查询优惠券类别列表
* 查询优惠券类别列表
*
*
* @param couponCategory 优惠券类别
* @param couponCategory 优惠券类别
...
@@ -57,14 +84,19 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
...
@@ -57,14 +84,19 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
@Override
@Override
public
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
)
{
public
List
<
CouponCategory
>
listCouponCategory
(
CouponCategory
couponCategory
)
{
List
<
CouponCategory
>
couponCategories
=
couponCategoryMapper
.
listCouponCategory
(
couponCategory
);
List
<
CouponCategory
>
couponCategories
=
couponCategoryMapper
.
listCouponCategory
(
couponCategory
);
Map
<
Integer
,
Long
>
countMap
;
if
(
CollectionUtils
.
isEmpty
(
couponCategories
))
{
List
<
Integer
>
categoryIds
=
couponCategories
.
stream
().
map
(
CouponCategory:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
Integer
>
categoryIds
=
couponCategories
.
stream
().
map
(
CouponCategory:
:
getId
).
collect
(
Collectors
.
toList
());
List
<
CouponCategory
>
couponCategoryCountList
=
couponMapper
.
getCouponCategoryTypeStat
(
categoryIds
);
List
<
CouponCategory
>
couponCategoryCountList
=
couponMapper
.
getCouponCategoryTypeStat
(
categoryIds
);
Map
<
Integer
,
Long
>
countMap
=
couponCategoryCountList
.
stream
()
countMap
=
couponCategoryCountList
.
stream
().
collect
(
Collectors
.
toMap
(
CouponCategory:
:
getId
,
CouponCategory:
:
getCouponCnt
));
.
collect
(
Collectors
.
toMap
(
CouponCategory:
:
getId
,
CouponCategory:
:
getCouponCnt
));
}
else
{
countMap
=
new
HashMap
<>();
}
for
(
CouponCategory
category
:
couponCategories
)
{
for
(
CouponCategory
category
:
couponCategories
)
{
category
.
setTypeDesc
(
CouponCategoryType
.
getDesc
(
category
.
getType
()));
category
.
setTypeDesc
(
CouponCategoryType
.
getDesc
(
category
.
getType
()));
Long
count
=
countMap
.
get
(
category
.
getId
());
Long
count
=
countMap
.
get
(
category
.
getId
());
category
.
setCouponCnt
(
count
==
null
?
0L
:
count
);
category
.
setCouponCnt
(
count
==
null
?
0L
:
count
);
category
.
setStateDesc
(
CouponState
.
getDesc
(
category
.
getState
()));
}
}
return
couponCategories
;
return
couponCategories
;
}
}
...
@@ -94,7 +126,13 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
...
@@ -94,7 +126,13 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
public
int
offlineCouponCategory
(
Integer
id
)
{
public
int
offlineCouponCategory
(
Integer
id
)
{
CouponCategory
online
=
new
CouponCategory
(
id
,
CouponState
.
OFFLINE
.
getState
());
CouponCategory
online
=
new
CouponCategory
(
id
,
CouponState
.
OFFLINE
.
getState
());
int
updateCnt
=
couponCategoryMapper
.
updateCouponCategory
(
online
);
int
updateCnt
=
couponCategoryMapper
.
updateCouponCategory
(
online
);
// offline logic todo
Coupon
coupon
=
new
Coupon
();
List
<
Coupon
>
coupons
=
couponMapper
.
listCoupon
(
coupon
);
long
unOfflineCnt
=
coupons
.
stream
().
filter
(
c
->
c
.
getState
().
equals
(
CouponState
.
DEFAULT
.
getState
())
||
c
.
getState
().
equals
(
CouponState
.
ONLINE
.
getState
())).
count
();
if
(
unOfflineCnt
>
0
)
{
throw
new
ServiceException
(
"需类下优惠券都处于下线状态才可下线"
);
}
return
updateCnt
;
return
updateCnt
;
}
}
...
@@ -107,9 +145,24 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
...
@@ -107,9 +145,24 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
@Override
@Override
@Transactional
@Transactional
public
int
deleteCouponCategory
(
Integer
id
)
{
public
int
deleteCouponCategory
(
Integer
id
)
{
CouponCategory
couponCategory
=
this
.
detail
(
id
);
if
(!
couponCategory
.
getState
().
equals
(
CouponState
.
OFFLINE
.
getState
()))
{
throw
new
ServiceException
(
"需未生效状态才可删除"
);
}
CouponCategory
online
=
new
CouponCategory
(
id
,
CouponState
.
DELETE
.
getState
());
CouponCategory
online
=
new
CouponCategory
(
id
,
CouponState
.
DELETE
.
getState
());
int
updateCnt
=
couponCategoryMapper
.
updateCouponCategory
(
online
);
int
updateCnt
=
couponCategoryMapper
.
updateCouponCategory
(
online
);
// delete logic todo
return
updateCnt
;
return
updateCnt
;
}
}
/**
* 获取优惠券类别详情
*
* @param id
* @return
*/
private
CouponCategory
detail
(
Integer
id
)
{
CouponCategory
couponCategory
=
couponCategoryMapper
.
selectCouponCategoryById
(
id
);
Asserts
.
notNull
(
couponCategory
,
"未查询到匹配记录[id="
+
couponCategory
+
"]"
);
return
couponCategory
;
}
}
}
soss-system/src/main/java/com/soss/system/service/impl/CouponRuleServiceImpl.java
View file @
cb214744
package
com
.
soss
.
system
.
service
.
impl
;
package
com
.
soss
.
system
.
service
.
impl
;
import
com.soss.system.domain.CouponRule
;
import
com.soss.system.mapper.CouponRuleMapper
;
import
com.soss.system.service.ICouponRuleService
;
import
com.soss.system.service.ICouponRuleService
;
import
io.jsonwebtoken.lang.Assert
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
/**
* <p>
* <p>
* 优惠券规则 服务实现类
* 优惠券规则 服务实现类
...
@@ -13,5 +22,25 @@ import org.springframework.stereotype.Service;
...
@@ -13,5 +22,25 @@ import org.springframework.stereotype.Service;
*/
*/
@Service
@Service
public
class
CouponRuleServiceImpl
implements
ICouponRuleService
{
public
class
CouponRuleServiceImpl
implements
ICouponRuleService
{
@Autowired
private
CouponRuleMapper
couponRuleMapper
;
@Override
public
Map
<
Integer
,
CouponRule
>
getCouponRuleMap
(
List
<
Integer
>
ids
)
{
List
<
CouponRule
>
couponRules
=
couponRuleMapper
.
selectCouponRuleByIds
(
ids
);
return
couponRules
.
stream
().
collect
(
Collectors
.
toMap
(
CouponRule:
:
getId
,
Function
.
identity
()));
}
/**
* 查询优惠券规则详情
*
* @param id
* @return
*/
@Override
public
CouponRule
detail
(
Integer
id
)
{
CouponRule
couponRule
=
couponRuleMapper
.
selectCouponRuleById
(
id
);
Assert
.
notNull
(
couponRule
,
"未查询到匹配的优惠券规则记录[id="
+
id
+
"]"
);
return
couponRule
;
}
}
}
soss-system/src/main/java/com/soss/system/service/impl/CouponServiceImpl.java
View file @
cb214744
package
com
.
soss
.
system
.
service
.
impl
;
package
com
.
soss
.
system
.
service
.
impl
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponCategoryType
;
import
com.soss.common.enums.CouponState
;
import
com.soss.common.exception.ServiceException
;
import
com.soss.common.exception.ServiceException
;
import
com.soss.common.utils.GenerateCode
;
import
com.soss.common.utils.GenerateCode
;
import
com.soss.system.domain.Coupon
;
import
com.soss.system.domain.Coupon
;
...
@@ -17,10 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -17,10 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.CollectionUtils
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -42,6 +44,24 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -42,6 +44,24 @@ public class CouponServiceImpl implements ICouponService {
@Autowired
@Autowired
private
CouponUserMapper
couponUserMapper
;
private
CouponUserMapper
couponUserMapper
;
/**
* 查询优惠券列表
*
* @param coupon
* @return
*/
@Override
public
List
<
Coupon
>
list
(
Coupon
coupon
)
{
return
couponMapper
.
listCoupon
(
coupon
);
}
@Override
public
Coupon
detail
(
Integer
id
)
{
Coupon
coupon
=
couponMapper
.
selectCouponById
(
id
);
Assert
.
notNull
(
coupon
,
"未查询到匹配的优惠券记录[id="
+
id
+
"]"
);
return
coupon
;
}
@Override
@Override
@Transactional
@Transactional
public
void
save
(
CouponPo
couponPo
)
{
public
void
save
(
CouponPo
couponPo
)
{
...
@@ -49,8 +69,10 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -49,8 +69,10 @@ public class CouponServiceImpl implements ICouponService {
CouponRule
couponRule
=
new
CouponRule
();
CouponRule
couponRule
=
new
CouponRule
();
this
.
checkAndWrapperCoupon
(
couponPo
,
coupon
,
couponRule
,
true
);
this
.
checkAndWrapperCoupon
(
couponPo
,
coupon
,
couponRule
,
true
);
couponRule
.
setState
(
CouponState
.
ONLINE
.
getState
());
couponRuleMapper
.
insertCouponRule
(
couponRule
);
couponRuleMapper
.
insertCouponRule
(
couponRule
);
coupon
.
setRuleId
(
couponRule
.
getId
());
coupon
.
setRuleId
(
couponRule
.
getId
());
coupon
.
setState
(
CouponState
.
ONLINE
.
getState
());
couponMapper
.
insertCoupon
(
coupon
);
couponMapper
.
insertCoupon
(
coupon
);
}
}
...
@@ -58,11 +80,12 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -58,11 +80,12 @@ public class CouponServiceImpl implements ICouponService {
@Transactional
@Transactional
public
void
update
(
CouponPo
couponPo
)
{
public
void
update
(
CouponPo
couponPo
)
{
Assert
.
notNull
(
couponPo
.
getId
(),
"要修改的优惠券ID还未传递"
);
Assert
.
notNull
(
couponPo
.
getId
(),
"要修改的优惠券ID还未传递"
);
Coupon
coupon
=
couponMapper
.
selectCouponById
(
couponPo
.
getId
());
Coupon
coupon
=
this
.
detail
(
couponPo
.
getId
());
Assert
.
notNull
(
coupon
,
"未查询到匹配的优惠券记录[id="
+
couponPo
.
getId
()
+
"]"
);
int
couponReceiveCount
=
couponUserMapper
.
getCouponReceiveCount
(
coupon
.
getId
());
int
couponReceiveCount
=
couponUserMapper
.
getCouponReceiveCount
(
coupon
.
getId
());
if
(
couponReceiveCount
>
0
)
{
if
(
couponReceiveCount
>
0
)
{
throw
new
ServiceException
(
"优惠券已被领取,无法编辑,只可下线"
);
throw
new
ServiceException
(
"优惠券已被领取,无法编辑,只可下线"
);
}
else
if
(!
coupon
.
getState
().
equals
(
CouponState
.
OFFLINE
.
getState
()))
{
throw
new
ServiceException
(
"修改优惠券需先下架优惠券"
);
}
}
CouponRule
couponRule
=
couponRuleMapper
.
selectCouponRuleById
(
coupon
.
getRuleId
());
CouponRule
couponRule
=
couponRuleMapper
.
selectCouponRuleById
(
coupon
.
getRuleId
());
checkAndWrapperCoupon
(
couponPo
,
coupon
,
couponRule
,
false
);
checkAndWrapperCoupon
(
couponPo
,
coupon
,
couponRule
,
false
);
...
@@ -84,7 +107,7 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -84,7 +107,7 @@ public class CouponServiceImpl implements ICouponService {
if
(
couponPo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
if
(
couponPo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
ruleDesc
=
"无门槛"
;
ruleDesc
=
"无门槛"
;
}
else
{
}
else
{
ruleDesc
=
"满"
+
couponPo
.
getPriceLimit
()
+
"元
可用
"
;
ruleDesc
=
"满"
+
couponPo
.
getPriceLimit
()
+
"元"
;
}
}
}
else
if
(
CouponCategoryType
.
DISCOUNT
.
getType
().
equals
(
couponCategory
.
getType
()))
{
}
else
if
(
CouponCategoryType
.
DISCOUNT
.
getType
().
equals
(
couponCategory
.
getType
()))
{
Assert
.
notNull
(
couponPo
.
getPriceDiscount
(),
"打折数还未设置"
);
Assert
.
notNull
(
couponPo
.
getPriceDiscount
(),
"打折数还未设置"
);
...
@@ -98,15 +121,16 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -98,15 +121,16 @@ public class CouponServiceImpl implements ICouponService {
if
(
couponPo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
if
(
couponPo
.
getPriceLimit
().
compareTo
(
BigDecimal
.
ZERO
)
==
0
)
{
ruleDesc
=
"无门槛"
;
ruleDesc
=
"无门槛"
;
}
else
{
}
else
{
ruleDesc
=
"满"
+
couponPo
.
getPriceLimit
()
+
"元
可用
"
;
ruleDesc
=
"满"
+
couponPo
.
getPriceLimit
()
+
"元"
;
}
}
}
}
Assert
.
notNull
(
couponPo
.
getUseStartTime
(),
"优惠券的绝对有效时间还未设置"
);
Assert
.
notNull
(
couponPo
.
getUseStartTime
(),
"优惠券的绝对有效时间还未设置"
);
Assert
.
notNull
(
couponPo
.
getUseEndTime
(),
"优惠券的绝对有效时间还未设置"
);
Assert
.
notNull
(
couponPo
.
getUseEndTime
(),
"优惠券的绝对有效时间还未设置"
);
Assert
.
isTrue
(!
CollectionUtils
.
isEmpty
(
couponPo
.
getCategoryIds
())
Assert
.
isTrue
((
couponPo
.
getCategoryIds
()
!=
null
&&
couponPo
.
getCategoryIds
().
length
>
0
)
&&
!
CollectionUtils
.
isEmpty
(
couponPo
.
getGoodsIds
()),
"商品范围还未设置"
);
||
(
couponPo
.
getGoodsIds
()
!=
null
&&
couponPo
.
getGoodsIds
().
length
>
0
),
"商品范围还未设置"
);
couponPo
.
couponUseLimitCheck
();
Assert
.
notNull
(
couponPo
.
getSendMsg
(),
"是否短信通知还未设置"
);
Assert
.
notNull
(
couponPo
.
getSendMsg
(),
"是否短信通知还未设置"
);
Assert
.
isTrue
(
couponPo
.
getSendMsg
()
&&
couponPo
.
getMsgId
()
!=
null
,
"短信模板还未选择"
);
Assert
.
isTrue
(
!
couponPo
.
getSendMsg
()
||
couponPo
.
getMsgId
()
!=
null
,
"短信模板还未选择"
);
coupon
.
setName
(
couponPo
.
getName
());
coupon
.
setName
(
couponPo
.
getName
());
coupon
.
setSerialNo
(
GenerateCode
.
getCode
(
"CP"
,
"%06d"
));
coupon
.
setSerialNo
(
GenerateCode
.
getCode
(
"CP"
,
"%06d"
));
...
@@ -122,15 +146,73 @@ public class CouponServiceImpl implements ICouponService {
...
@@ -122,15 +146,73 @@ public class CouponServiceImpl implements ICouponService {
BeanUtils
.
copyProperties
(
couponPo
,
couponRule
,
"name"
);
BeanUtils
.
copyProperties
(
couponPo
,
couponRule
,
"name"
);
couponRule
.
setName
(
ruleName
);
couponRule
.
setName
(
ruleName
);
couponRule
.
setDesc
(
ruleDesc
);
couponRule
.
setDesc
(
ruleDesc
);
couponRule
.
setCategoryIds
(
couponPo
.
getCategoryIds
().
stream
(
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
couponRule
.
setCategoryIds
(
Arrays
.
stream
(
couponPo
.
getCategoryIds
()
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
couponRule
.
setGoodsIds
(
couponPo
.
getGoodsIds
().
stream
(
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
couponRule
.
setGoodsIds
(
Arrays
.
stream
(
couponPo
.
getGoodsIds
()
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
couponRule
.
setProvince
(
String
.
join
(
","
,
couponPo
.
getProvince
()));
couponRule
.
setProvince
(
String
.
join
(
","
,
couponPo
.
getProvince
()));
couponRule
.
setCity
(
String
.
join
(
","
,
couponPo
.
getCity
()));
couponRule
.
setCity
(
String
.
join
(
","
,
couponPo
.
getCity
()));
couponRule
.
setArea
(
String
.
join
(
","
,
couponPo
.
getArea
()));
couponRule
.
setArea
(
String
.
join
(
","
,
couponPo
.
getArea
()));
couponRule
.
setShopIds
(
couponPo
.
getShopIds
().
stream
(
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
couponRule
.
setShopIds
(
Arrays
.
stream
(
couponPo
.
getShopIds
()
).
map
(
String:
:
valueOf
).
collect
(
Collectors
.
joining
(
","
)));
if
(
saveFlag
)
{
if
(
saveFlag
)
{
couponRule
.
setCreatedAt
(
now
);
couponRule
.
setCreatedAt
(
now
);
}
}
couponRule
.
setUpdatedAt
(
now
);
couponRule
.
setUpdatedAt
(
now
);
}
}
/**
* 上架优惠券
*
* @param id
* @return
*/
@Override
@Transactional
public
int
onlineCoupon
(
Integer
id
)
{
Coupon
online
=
new
Coupon
(
id
,
CouponState
.
ONLINE
.
getState
());
int
updateCnt
=
couponMapper
.
updateCoupon
(
online
);
return
updateCnt
;
}
/**
* 下架优惠券
*
* @param id
* @return
*/
@Override
@Transactional
public
int
offlineCoupon
(
Integer
id
)
{
Coupon
offline
=
new
Coupon
(
id
,
CouponState
.
OFFLINE
.
getState
());
int
updateCnt
=
couponMapper
.
updateCoupon
(
offline
);
return
updateCnt
;
}
/**
* 删除优惠券
*
* @param id
* @return
*/
@Override
@Transactional
public
int
deleteCoupon
(
Integer
id
)
{
Coupon
coupon
=
this
.
detail
(
id
);
if
(!
coupon
.
getState
().
equals
(
CouponState
.
OFFLINE
.
getState
()))
{
throw
new
ServiceException
(
"需下线优惠券才能删除"
);
}
Coupon
delete
=
new
Coupon
(
id
,
CouponState
.
DELETE
.
getState
());
int
updateCnt
=
couponMapper
.
updateCoupon
(
delete
);
return
updateCnt
;
}
/**
* 获取当前有效的规则集合
*
* @return
*/
@Override
public
List
<
Coupon
>
getEffectiveCoupon
()
{
return
couponMapper
.
getEffectiveCoupon
();
}
}
}
soss-system/src/main/resources/mapper/system/CouponCategoryMapper.xml
View file @
cb214744
...
@@ -18,16 +18,24 @@
...
@@ -18,16 +18,24 @@
<select
id=
"selectCouponCategoryById"
resultMap=
"BaseResultMap"
>
<select
id=
"selectCouponCategoryById"
resultMap=
"BaseResultMap"
>
<include
refid=
"selectCouponCategory"
/>
<include
refid=
"selectCouponCategory"
/>
where id = #{id}
and state = ${@com.soss.common.enums.CouponState @ONLINE.getState}
where id = #{id}
</select>
</select>
<select
id=
"listCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
resultMap=
"BaseResultMap"
>
<select
id=
"listCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
resultMap=
"BaseResultMap"
>
<include
refid=
"selectCouponCategory"
/>
<include
refid=
"selectCouponCategory"
/>
<where>
<where>
<if
test=
"name != null and name != ''"
>
and name like concat('%', #{name}, '%')
</if>
<if
test=
"type != null"
>
and type = #{type}
</if>
<if
test=
"type != null"
>
and type = #{type}
</if>
<if
test=
"state != null and state != ''"
>
and state = #{state}
</if>
<choose>
<when
test=
"state != null"
>
and state = #{state}
</when>
<otherwise>
and state
<
${@com.soss.common.enums.CouponState @DELETE.getState}
</otherwise>
</choose>
</where>
</where>
order by
updated_at desc,
id desc
order by id desc
</select>
</select>
<insert
id=
"insertCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
<insert
id=
"insertCouponCategory"
parameterType=
"com.soss.system.domain.CouponCategory"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
...
...
soss-system/src/main/resources/mapper/system/CouponMapper.xml
View file @
cb214744
...
@@ -21,6 +21,16 @@
...
@@ -21,6 +21,16 @@
where id = #{id}
where id = #{id}
</select>
</select>
<select
id=
"listCoupon"
parameterType=
"com.soss.system.domain.Coupon"
resultMap=
"BaseResultMap"
>
select * from coupon
<where>
<if
test=
"name != null and name != ''"
>
and name like concat('%', #{name}, '%')
</if>
<if
test=
"categoryId != null"
>
and category_id = #{categoryId}
</if>
<if
test=
"state != null"
>
and state = #{state}
</if>
</where>
order by updated_at desc, id desc
</select>
<select
id=
"getCouponCategoryTypeStat"
resultType=
"com.soss.system.domain.CouponCategory"
>
<select
id=
"getCouponCategoryTypeStat"
resultType=
"com.soss.system.domain.CouponCategory"
>
select category_id id, count(*) couponCnt from coupon where category_id in
select category_id id, count(*) couponCnt from coupon where category_id in
<foreach
collection=
"categoryIds"
item=
"categoryId"
open=
"("
close=
")"
separator=
","
>
#{categoryId}
</foreach>
<foreach
collection=
"categoryIds"
item=
"categoryId"
open=
"("
close=
")"
separator=
","
>
#{categoryId}
</foreach>
...
@@ -28,7 +38,7 @@
...
@@ -28,7 +38,7 @@
</select>
</select>
<insert
id=
"insertCoupon"
parameterType=
"com.soss.system.domain.Coupon"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
<insert
id=
"insertCoupon"
parameterType=
"com.soss.system.domain.Coupon"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into coupon
_category
insert into coupon
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
name,
</if>
<if
test=
"name != null and name != ''"
>
name,
</if>
<if
test=
"serialNo != null and serialNo != ''"
>
serial_no,
</if>
<if
test=
"serialNo != null and serialNo != ''"
>
serial_no,
</if>
...
@@ -66,4 +76,12 @@
...
@@ -66,4 +76,12 @@
</trim>
</trim>
where id = #{id}
where id = #{id}
</update>
</update>
<!-- 获取当前有效的规则集合 -->
<select
id=
"getEffectiveCoupon"
resultMap=
"BaseResultMap"
>
select c.id, c.name
from coupon_rule cr
left join coupon c on c.rule_id = cr.id
where cr.use_start_time > now() and cr.use_end_time
<
now()
</select>
</mapper>
</mapper>
soss-system/src/main/resources/mapper/system/CouponRuleMapper.xml
View file @
cb214744
...
@@ -36,9 +36,16 @@
...
@@ -36,9 +36,16 @@
where id = #{id}
where id = #{id}
</select>
</select>
<select
id=
"selectCouponRuleByIds"
resultMap=
"BaseResultMap"
>
select *
from coupon_rule
where id in
<foreach
collection=
"ids"
item=
"id"
open=
"("
close=
")"
separator=
","
>
#{id}
</foreach>
</select>
<insert
id=
"insertCouponRule"
parameterType=
"com.soss.system.domain.CouponRule"
useGeneratedKeys=
"true"
<insert
id=
"insertCouponRule"
parameterType=
"com.soss.system.domain.CouponRule"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
keyProperty=
"id"
>
insert into coupon_
category
insert into coupon_
rule
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
name,
</if>
<if
test=
"name != null and name != ''"
>
name,
</if>
<if
test=
"desc != null and desc != ''"
>
`desc`,
</if>
<if
test=
"desc != null and desc != ''"
>
`desc`,
</if>
...
@@ -94,7 +101,7 @@
...
@@ -94,7 +101,7 @@
</insert>
</insert>
<update
id=
"updateCouponRule"
parameterType=
"com.soss.system.domain.CouponRule"
>
<update
id=
"updateCouponRule"
parameterType=
"com.soss.system.domain.CouponRule"
>
update coupon_
category
update coupon_
rule
<trim
prefix=
"set"
suffixOverrides=
","
>
<trim
prefix=
"set"
suffixOverrides=
","
>
<if
test=
"name != null and name != ''"
>
name = #{name},
</if>
<if
test=
"name != null and name != ''"
>
name = #{name},
</if>
<if
test=
"desc != null and desc != ''"
>
`desc` = #{desc},
</if>
<if
test=
"desc != null and desc != ''"
>
`desc` = #{desc},
</if>
...
...
soss-system/src/main/resources/mapper/system/CouponUserMapper.xml
View file @
cb214744
...
@@ -25,4 +25,60 @@
...
@@ -25,4 +25,60 @@
from coupon_user
from coupon_user
where coupon_id = #{couponId}
where coupon_id = #{couponId}
</select>
</select>
<insert
id=
"insertCouponUser"
parameterType=
"com.soss.system.domain.CouponUser"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into coupon_user
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"userId != null"
>
user_id,
</if>
<if
test=
"userName != null and userName != ''"
>
user_name,
</if>
<if
test=
"userPhone != null and userPhone != ''"
>
user_phone,
</if>
<if
test=
"orderId != null"
>
order_id,
</if>
<if
test=
"couponId != null"
>
coupon_id,
</if>
<if
test=
"receiveTime != null"
>
receive_time,
</if>
<if
test=
"activeTime != null"
>
active_time,
</if>
<if
test=
"expiredTime != null"
>
expired_time,
</if>
<if
test=
"discount != null"
>
discount,
</if>
<if
test=
"source != null"
>
source,
</if>
<if
test=
"type != null"
>
type,
</if>
<if
test=
"state != null"
>
state,
</if>
<if
test=
"createdAt != null"
>
created_at,
</if>
<if
test=
"updatedAt != null"
>
updated_at,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"userId != null"
>
#{userId},
</if>
<if
test=
"userName != null and userName != ''"
>
#{userName},
</if>
<if
test=
"userPhone != null and userPhone != ''"
>
#{userPhone},
</if>
<if
test=
"orderId != null"
>
#{orderId},
</if>
<if
test=
"couponId != null"
>
#{couponId},
</if>
<if
test=
"receiveTime != null"
>
#{receiveTime},
</if>
<if
test=
"activeTime != null"
>
#{activeTime},
</if>
<if
test=
"expiredTime != null"
>
#{expiredTime},
</if>
<if
test=
"discount != null"
>
#{discount},
</if>
<if
test=
"source != null"
>
#{source},
</if>
<if
test=
"type != null"
>
#{type},
</if>
<if
test=
"state != null"
>
#{state},
</if>
<if
test=
"createdAt != null"
>
#{createdAt},
</if>
<if
test=
"updatedAt != null"
>
#{updatedAt},
</if>
</trim>
</insert>
<update
id=
"updateCouponUser"
parameterType=
"com.soss.system.domain.CouponUser"
>
update coupon_user
<trim
prefix=
"SET"
suffixOverrides=
","
>
<if
test=
"userId != null"
>
user_id = #{userId},
</if>
<if
test=
"userName != null and userName != ''"
>
user_name = #{userName},
</if>
<if
test=
"userPhone != null and userPhone != ''"
>
user_phone = #{userPhone},
</if>
<if
test=
"orderId != null"
>
order_id = #{orderId},
</if>
<if
test=
"couponId != null"
>
coupon_id = #{couponId},
</if>
<if
test=
"receiveTime != null"
>
receive_time = #{receiveTime},
</if>
<if
test=
"activeTime != null"
>
active_time = #{activeTime},
</if>
<if
test=
"expiredTime != null"
>
expired_time = #{expiredTime},
</if>
<if
test=
"discount != null"
>
discount = #{discount},
</if>
<if
test=
"source != null"
>
source = #{source},
</if>
<if
test=
"type != null"
>
type = #{type},
</if>
<if
test=
"state != null"
>
state = #{state},
</if>
<if
test=
"updatedAt != null"
>
updated_at = #{updatedAt},
</if>
</trim>
where id = #{id}
</update>
</mapper>
</mapper>
Write
Preview
Markdown
is supported
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