Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
d5627814
Commit
d5627814
authored
Mar 21, 2023
by
查志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
买券支持非码付
parent
ef033a2d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
111 deletions
+0
-111
order-application-service/src/main/java/cn/freemud/manager/BuyProductOnceManager.java
+0
-70
order-application-service/src/main/java/cn/freemud/service/impl/SellCouponOrderServiceImpl.java
+0
-0
order-application-service/src/test/java/cn.freemud/manager/BuyProductOnceTest.java
+0
-41
No files found.
order-application-service/src/main/java/cn/freemud/manager/BuyProductOnceManager.java
deleted
100644 → 0
View file @
ef033a2d
package
cn
.
freemud
.
manager
;
import
cn.freemud.constant.RedisKeyConstant
;
import
cn.freemud.entities.dto.product.ProductInfo
;
import
cn.freemud.enums.ResponseResult
;
import
cn.freemud.redis.RedisCache
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
/**
* @author freemud
* @title: BuyProductOnceManager
* @projectName order-group
* @description: 618活动一元秒杀抢18元券包活动专属manager
* @date 2021/6/10上午9:53
*/
@Component
public
class
BuyProductOnceManager
{
// @Autowired
// protected RedisTemplate redisTemplate;
@Autowired
private
RedisCache
redisCache
;
//用户限购:每人每单限购一次 / 禁用
public
ResponseResult
checkBuyProductOnce
(
List
<
ProductInfo
>
products
,
String
partnerId
,
String
userId
)
{
RedisTemplate
redisTemplate
=
redisCache
.
getRedisTemplate
();
List
<
ProductInfo
>
productsCheck
=
products
.
stream
().
filter
(
product
->
product
.
getIsLimitNumProduct
()
==
1
).
collect
(
Collectors
.
toList
());
if
(
CollectionUtils
.
isNotEmpty
(
productsCheck
))
{
//每人每单限购一次
if
(
productsCheck
.
size
()
>
1
)
{
return
ResponseResult
.
USER_BUY_PRODUCT_MORE_THAN_THE_NUMBER
;
}
String
key
=
this
.
getCheckBuyProductOnceKey
(
partnerId
,
userId
,
productsCheck
.
get
(
0
).
getPid
());
if
(
redisTemplate
.
hasKey
(
key
))
{
return
ResponseResult
.
USER_BUY_PRODUCT_ALREADY
;
}
redisTemplate
.
opsForValue
().
set
(
key
,
"Y"
);
//活动时间10天,防止redis脏数据,设置过期时间
redisTemplate
.
expire
(
key
,
10
,
TimeUnit
.
DAYS
);
}
return
ResponseResult
.
SUCCESS
;
}
public
String
getCheckBuyProductOnceKey
(
String
partnerId
,
String
userId
,
String
pid
)
{
StringBuilder
key
=
new
StringBuilder
(
RedisKeyConstant
.
USER_BUY_PRODUCT_ONCE
)
.
append
(
partnerId
)
.
append
(
":"
)
.
append
(
userId
)
.
append
(
":"
)
.
append
(
pid
);
return
key
.
toString
();
}
//清掉key
public
boolean
removeCheckBuyProductOnceKey
(
String
partnerId
,
String
userId
,
String
pid
)
{
RedisTemplate
redisTemplate
=
redisCache
.
getRedisTemplate
();
String
key
=
this
.
getCheckBuyProductOnceKey
(
partnerId
,
userId
,
pid
);
redisTemplate
.
delete
(
key
);
return
true
;
}
}
order-application-service/src/main/java/cn/freemud/service/impl/SellCouponOrderServiceImpl.java
View file @
d5627814
This diff is collapsed.
Click to expand it.
order-application-service/src/test/java/cn.freemud/manager/BuyProductOnceTest.java
deleted
100644 → 0
View file @
ef033a2d
package
cn
.
freemud
.
manager
;
import
cn.freemud.entities.dto.product.ProductInfo
;
import
cn.freemud.enums.ResponseResult
;
import
cn.freemud.utils.ResponseUtil
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @author freemud
* @title: BuyProductOnceTest
* @projectName order-group
* @description: TODO
* @date 2021/6/10下午2:52
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
BuyProductOnceTest
{
@Autowired
private
BuyProductOnceManager
buyProductOnceManager
;
@Test
public
void
buyProductOnceTest
(){
List
<
ProductInfo
>
products
=
new
ArrayList
<>();
ProductInfo
productInfo
=
new
ProductInfo
();
productInfo
.
setIsLimitNumProduct
(
1
);
products
.
add
(
productInfo
);
ResponseResult
re
=
buyProductOnceManager
.
checkBuyProductOnce
(
products
,
"1864"
,
"wanghanghang"
);
System
.
out
.
println
(
re
.
getCode
()
+
" "
+
re
.
getMessage
());
}
}
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