Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
D
draw
Project
Project
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
draw
draw
Commits
ce7f5ed0
Commit
ce7f5ed0
authored
Aug 06, 2021
by
心月梦天
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加上缓存操作
parent
e6ac164a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
104 additions
and
6 deletions
+104
-6
BusinessConfig.java
...in/java/com/miya/draw/config/business/BusinessConfig.java
+1
-1
BusinessConfigImpl.java
...ava/com/miya/draw/config/business/BusinessConfigImpl.java
+1
-2
DrawController.java
src/main/java/com/miya/draw/controller/DrawController.java
+8
-0
RedisController.java
src/main/java/com/miya/draw/controller/RedisController.java
+91
-0
DrawManagerImpl.java
src/main/java/com/miya/draw/manager/DrawManagerImpl.java
+2
-2
bussiness-config.yml
src/main/resources/bussiness-config.yml
+1
-1
No files found.
src/main/java/com/miya/draw/config/business/BusinessConfig.java
View file @
ce7f5ed0
...
...
@@ -24,7 +24,7 @@ public interface BusinessConfig {
*
* @return
*/
Integer
getDrawCountUnit
();
String
getDrawCountUnit
();
/**
* 理论上最大可花费金额
...
...
src/main/java/com/miya/draw/config/business/BusinessConfigImpl.java
View file @
ce7f5ed0
...
...
@@ -4,7 +4,6 @@
*/
package
com
.
miya
.
draw
.
config
.
business
;
import
io.swagger.models.auth.In
;
import
lombok.Data
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
...
...
@@ -22,7 +21,7 @@ public class BusinessConfigImpl implements BusinessConfig {
private
Integer
drawMaxCount
;
@Value
(
"${draw.countunit}"
)
public
Integer
drawCountUnit
;
public
String
drawCountUnit
;
@Value
(
"${draw.maxmoney}"
)
public
Long
drawMaxMoney
;
...
...
src/main/java/com/miya/draw/controller/DrawController.java
View file @
ce7f5ed0
...
...
@@ -15,6 +15,7 @@ import com.miya.draw.response.PrizeDrawListResponse;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -89,6 +90,12 @@ public class DrawController {
@PostMapping
(
value
=
"prize/draw/list"
)
public
RestResult
<
List
<
PrizeDrawListResponse
>>
prizeDrawList
(
@RequestBody
@Valid
PrizeDrawListRequest
request
)
{
List
<
DrawModel
>
drawModelList
=
drawManager
.
listAllWinningInfo
(
request
.
getSize
());
drawModelList
.
forEach
(
x
->
{
if
(
StringUtils
.
isNotBlank
(
x
.
getAccountName
())){
x
.
setAccountName
(
x
.
getAccountName
().
replaceAll
(
"(\\d{3})\\d{4}(\\d{4})"
,
"$1****$2"
));
}
});
List
<
PrizeDrawListResponse
>
prizeDrawListResponses
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
drawModelList
))
{
prizeDrawListResponses
=
drawModelList
.
stream
().
map
(
drawModel
->
{
...
...
@@ -98,4 +105,5 @@ public class DrawController {
}
return
RestResultUtil
.
createSuccessResult
(
prizeDrawListResponses
);
}
}
src/main/java/com/miya/draw/controller/RedisController.java
0 → 100644
View file @
ce7f5ed0
package
com
.
miya
.
draw
.
controller
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.Sets
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.core.Cursor
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.ScanOptions
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Objects
;
import
java.util.Set
;
/**
* @author jack
*/
@Slf4j
@Api
(
tags
=
"redis操作"
)
@RestController
@RequestMapping
(
"/redis"
)
public
class
RedisController
{
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
/**
* 查询redis key
*
* @param payload {"key":"123"}
* @return key
*/
@PostMapping
(
value
=
"scanKeys"
)
public
String
scanKey
(
@RequestBody
String
payload
)
{
String
key
=
JSON
.
parseObject
(
payload
).
getString
(
"key"
);
return
JSON
.
toJSONString
(
scan
(
"*"
+
key
+
"*"
));
}
/**
* 删除redis key
*
* @param payload {"key":"123"}
* @return 删除
*/
@PostMapping
(
value
=
"deleteKey"
)
public
String
deleteKey
(
@RequestBody
String
payload
)
{
String
key
=
JSON
.
parseObject
(
payload
).
getString
(
"key"
);
Long
delete
=
redisTemplate
.
delete
(
scan
(
"*"
+
key
+
"*"
));
return
JSON
.
toJSONString
(
delete
);
}
/**
* 自定义scan方法
*
* @param pattern 正则
* @return Set<String>
*/
private
Set
<
String
>
scan
(
String
pattern
)
{
Set
<
String
>
keys
=
Sets
.
newHashSet
();
RedisConnection
connection
=
null
;
try
{
if
(
Objects
.
isNull
(
redisTemplate
.
getConnectionFactory
()))
{
return
keys
;
}
connection
=
redisTemplate
.
getConnectionFactory
().
getConnection
();
ScanOptions
scanOptions
=
ScanOptions
.
scanOptions
()
.
match
(
pattern
)
.
count
(
100
)
.
build
();
Cursor
<
byte
[]>
cursor
=
connection
.
scan
(
scanOptions
);
while
(
cursor
.
hasNext
())
{
keys
.
add
(
new
String
(
cursor
.
next
()));
}
}
catch
(
Exception
e
)
{
log
.
error
(
"遍历key失败={}"
,
e
.
getMessage
());
}
finally
{
if
(
null
!=
connection
)
{
connection
.
close
();
}
}
return
keys
;
}
}
src/main/java/com/miya/draw/manager/DrawManagerImpl.java
View file @
ce7f5ed0
...
...
@@ -91,7 +91,7 @@ public class DrawManagerImpl implements IDrawManager {
List
<
SyncTrade
>
buyGoodList
=
syncTradeService
.
listCanDrawGoods
(
request
.
getPhone
(),
start
,
end
,
storeIdList
,
goodCodeList
);
BigDecimal
buyTotal
=
gainBuyTotal
(
buyGoodList
);
Long
purchasedAmount
=
buyTotal
.
multiply
(
BigDecimal
.
valueOf
(
100
)).
longValue
();
Integer
drawCountTotal
=
buyTotal
.
divide
(
BigDecimal
.
valueOf
(
businessConfig
.
getDrawCountUnit
()),
RoundingMode
.
DOWN
).
intValue
();
Integer
drawCountTotal
=
buyTotal
.
divide
(
new
BigDecimal
(
businessConfig
.
getDrawCountUnit
()),
RoundingMode
.
DOWN
).
intValue
();
drawCountTotal
=
Math
.
max
(
drawCountTotal
-
alreadyDrawCount
,
0
);
drawCountTotal
=
Math
.
min
(
businessConfig
.
getDrawMaxCount
(),
drawCountTotal
);
Integer
joinActivityPeopleNum
=
accountPrizeService
.
countJoinActivityPeople
();
...
...
@@ -162,7 +162,7 @@ public class DrawManagerImpl implements IDrawManager {
LocalDateTime
end
=
LocalDateTimeUtil
.
endOfDay
(
nowTime
);
List
<
SyncTrade
>
buyGoodList
=
syncTradeService
.
listCanDrawGoods
(
phone
,
start
,
end
,
activityStoreService
.
listAllActivityStoreId
(),
activityGoodsService
.
listAllActivityGoods
());
BigDecimal
buyTotal
=
gainBuyTotal
(
buyGoodList
);
int
drawCountTotal
=
buyTotal
.
divide
(
BigDecimal
.
valueOf
(
businessConfig
.
getDrawCountUnit
()),
RoundingMode
.
DOWN
).
intValue
();
int
drawCountTotal
=
buyTotal
.
divide
(
new
BigDecimal
(
businessConfig
.
getDrawCountUnit
()),
RoundingMode
.
DOWN
).
intValue
();
drawCountTotal
=
Math
.
min
(
businessConfig
.
getDrawMaxCount
(),
drawCountTotal
);
if
(
drawCountTotal
<=
0
)
{
throw
new
BusinessException
(
ErrorEnum
.
DRAW_CHECK_EXP
,
"抱歉,你的购物金额不足,已无抽奖次数"
);
...
...
src/main/resources/bussiness-config.yml
View file @
ce7f5ed0
######################## 业务配置 ####################
draw
:
maxcount
:
9999999
#抽奖最大次数
countunit
:
5
#每抽10元加1次次数
countunit
:
9.9
#每抽10元加1次次数
maxmoney
:
25
#理论上最多花费金额 元
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