Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
lanbaoming
jiedao-api-boot-master
Commits
06697f9a
Commit
06697f9a
authored
Sep 05, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix-209: 积分规则列表添加编号
parent
c2cefe0d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
1 deletion
+128
-1
ScoreRuleCodeFlushTask.java
...e/member/controller/admin/job/ScoreRuleCodeFlushTask.java
+26
-0
ScoreRuleDO.java
...o/module/member/dal/dataobject/scoreRule/ScoreRuleDO.java
+4
-0
ScoreRuleMapper.java
...ao/module/member/dal/mysql/scoreRule/ScoreRuleMapper.java
+5
-0
ScoreRuleServiceImpl.java
...module/member/service/scoreRule/ScoreRuleServiceImpl.java
+7
-1
ScoreRuleGenCodeUtils.java
...coder/yudao/module/member/util/ScoreRuleGenCodeUtils.java
+82
-0
ScoreRuleBackVO.java
...der/yudao/module/member/vo/scoreRule/ScoreRuleBackVO.java
+4
-0
No files found.
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/admin/job/ScoreRuleCodeFlushTask.java
0 → 100644
View file @
06697f9a
package
cn
.
iocoder
.
yudao
.
module
.
member
.
controller
.
admin
.
job
;
import
cn.iocoder.yudao.framework.quartz.core.handler.JobHandler
;
import
cn.iocoder.yudao.module.member.util.ScoreRuleGenCodeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
/**
* 积分规则编号刷新任务
* @author zhaobiyan
*/
@Component
@Slf4j
public
class
ScoreRuleCodeFlushTask
implements
JobHandler
{
@Resource
private
ScoreRuleGenCodeUtils
scoreRuleGenCodeUtils
;
@Override
public
String
execute
(
String
param
)
throws
Exception
{
scoreRuleGenCodeUtils
.
historyScoreRuleCodeFlush
();
return
"success"
;
}
}
\ No newline at end of file
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/scoreRule/ScoreRuleDO.java
View file @
06697f9a
...
@@ -24,6 +24,10 @@ public class ScoreRuleDO extends BaseDO {
...
@@ -24,6 +24,10 @@ public class ScoreRuleDO extends BaseDO {
*/
*/
@TableId
@TableId
private
Long
id
;
private
Long
id
;
/**
* 规则编号
*/
private
String
code
;
/**
/**
* 指标类型
* 指标类型
*/
*/
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/scoreRule/ScoreRuleMapper.java
View file @
06697f9a
...
@@ -11,6 +11,8 @@ import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
...
@@ -11,6 +11,8 @@ import cn.iocoder.yudao.framework.mybatis.core.vo.PageVO;
import
cn.iocoder.yudao.module.member.enums.RelationSymbolEnum
;
import
cn.iocoder.yudao.module.member.enums.RelationSymbolEnum
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleQueryVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.ScoreRuleQueryVO
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.ResultType
;
import
org.apache.ibatis.annotations.Select
;
/**
/**
* 积分规则 Mapper
* 积分规则 Mapper
...
@@ -69,4 +71,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
...
@@ -69,4 +71,7 @@ public interface ScoreRuleMapper extends AbstractMapper<ScoreRuleDO> {
}
}
return
null
;
return
null
;
}
}
@ResultType
(
String
.
class
)
@Select
({
"select code from score_rule order by code desc limit 1"
})
String
getCurrentMaxScoreRuleCode
();
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/scoreRule/ScoreRuleServiceImpl.java
View file @
06697f9a
...
@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
...
@@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.TransportTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.TransportTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum
;
import
cn.iocoder.yudao.module.member.util.ScoreRuleGenCodeUtils
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.*
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.*
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleRegisterExtraVO
;
...
@@ -60,6 +61,8 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
...
@@ -60,6 +61,8 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
private
WarehouseService
warehouseService
;
private
WarehouseService
warehouseService
;
@Resource
@Resource
private
AdminUserApi
adminUserApi
;
private
AdminUserApi
adminUserApi
;
@Resource
private
ScoreRuleGenCodeUtils
scoreRuleGenCodeUtils
;
@Override
@Override
public
Long
createScoreRule
(
ScoreRuleCreateReqVO
createReqVO
)
{
public
Long
createScoreRule
(
ScoreRuleCreateReqVO
createReqVO
)
{
...
@@ -70,6 +73,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
...
@@ -70,6 +73,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
verifyCommon
(
createReqVO
);
verifyCommon
(
createReqVO
);
Integer
scoreRuleType
=
scoreRule
.
getType
();
Integer
scoreRuleType
=
scoreRule
.
getType
();
verifyAndSetExtraDO
(
createReqVO
,
scoreRuleType
,
scoreRule
);
verifyAndSetExtraDO
(
createReqVO
,
scoreRuleType
,
scoreRule
);
scoreRule
.
setCode
(
scoreRuleGenCodeUtils
.
generateScoreRuleCode
());
scoreRuleMapper
.
insert
(
scoreRule
);
scoreRuleMapper
.
insert
(
scoreRule
);
scoreRuleRedisDao
.
deleteEnableScoreRule
(
scoreRule
.
getType
());
scoreRuleRedisDao
.
deleteEnableScoreRule
(
scoreRule
.
getType
());
// 返回
// 返回
...
@@ -367,6 +371,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
...
@@ -367,6 +371,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
scoreRuleDO
.
setCreateTime
(
null
);
scoreRuleDO
.
setCreateTime
(
null
);
scoreRuleDO
.
setUpdateTime
(
null
);
scoreRuleDO
.
setUpdateTime
(
null
);
scoreRuleDO
.
setUpdater
(
null
);
scoreRuleDO
.
setUpdater
(
null
);
scoreRuleDO
.
setCode
(
scoreRuleGenCodeUtils
.
generateScoreRuleCode
());
scoreRuleMapper
.
insert
(
scoreRuleDO
);
scoreRuleMapper
.
insert
(
scoreRuleDO
);
return
scoreRuleDO
.
getId
();
return
scoreRuleDO
.
getId
();
}
}
...
@@ -449,8 +454,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
...
@@ -449,8 +454,9 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
case
RECOMMEND:
case
RECOMMEND:
case
REGISTER:
case
REGISTER:
return
getEnableScoreRuleByType
(
scoreRuleType
);
return
getEnableScoreRuleByType
(
scoreRuleType
);
default
:
return
null
;
}
}
return
null
;
}
}
@Override
@Override
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/util/ScoreRuleGenCodeUtils.java
0 → 100644
View file @
06697f9a
package
cn
.
iocoder
.
yudao
.
module
.
member
.
util
;
import
cn.iocoder.yudao.framework.redis.helper.RedisHelper
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper
;
import
com.alibaba.excel.util.DateUtils
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
GET_LOCK_FAILED
;
/**
* 根据规则生成各种code
*/
@Component
public
class
ScoreRuleGenCodeUtils
{
@Resource
private
RedisHelper
redisHelper
;
@Resource
private
RedissonClient
redissonClient
;
@Resource
private
ScoreRuleMapper
scoreRuleMapper
;
/**
* 生成积分规则编号
*/
public
String
generateScoreRuleCode
()
{
// 编号规则为PR+年份+5位数,例如PR2400001
String
key
=
"scoreRule:max:number"
;
StringBuilder
code
=
new
StringBuilder
();
code
.
append
(
"PR"
);
code
.
append
(
DateUtils
.
format
(
new
Date
(),
"yy"
));
Long
codeNum
;
if
(
redisHelper
.
hasKey
(
key
))
{
codeNum
=
redisHelper
.
incrBy
(
key
,
1
);
}
else
{
RLock
lock
=
redissonClient
.
getLock
(
"next:scoreRule:code:lock"
);
try
{
boolean
lockSuccess
=
lock
.
tryLock
(
2
,
2
,
TimeUnit
.
SECONDS
);
if
(!
lockSuccess
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
String
currentMaxScoreRuleCode
=
scoreRuleMapper
.
getCurrentMaxScoreRuleCode
();
if
(
currentMaxScoreRuleCode
==
null
){
codeNum
=
1L
;
}
else
{
codeNum
=
Long
.
parseLong
(
currentMaxScoreRuleCode
.
substring
(
4
))
+
1
;
}
redisHelper
.
set
(
key
,
String
.
valueOf
(
codeNum
),
10
,
TimeUnit
.
SECONDS
);
}
catch
(
InterruptedException
e
)
{
throw
exception
(
GET_LOCK_FAILED
);
}
finally
{
lock
.
unlock
();
}
}
// 获得5位序列号,不足位前面补0
code
.
append
(
String
.
format
(
"%05d"
,
codeNum
));
return
code
.
toString
();
}
public
void
historyScoreRuleCodeFlush
()
{
long
start
=
1L
;
redisHelper
.
delete
(
"scoreRule:max:number"
);
List
<
ScoreRuleDO
>
scoreRuleDOS
=
scoreRuleMapper
.
selectList
();
for
(
ScoreRuleDO
scoreRuleDO
:
scoreRuleDOS
)
{
StringBuilder
code
=
new
StringBuilder
();
code
.
append
(
"PR"
);
code
.
append
(
DateUtils
.
format
(
new
Date
(),
"yy"
));
code
.
append
(
String
.
format
(
"%05d"
,
start
));
scoreRuleDO
.
setCode
(
code
.
toString
());
scoreRuleMapper
.
updateById
(
scoreRuleDO
);
start
+=
1
;
}
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/vo/scoreRule/ScoreRuleBackVO.java
View file @
06697f9a
...
@@ -22,6 +22,10 @@ public class ScoreRuleBackVO {
...
@@ -22,6 +22,10 @@ public class ScoreRuleBackVO {
@ApiModelProperty
(
value
=
"主键"
,
required
=
true
)
@ApiModelProperty
(
value
=
"主键"
,
required
=
true
)
private
Long
id
;
private
Long
id
;
@ExcelProperty
(
"编号"
)
@ApiModelProperty
(
value
=
"编号"
,
required
=
true
)
private
String
code
;
@ExcelProperty
(
"指标类型"
)
@ExcelProperty
(
"指标类型"
)
@ApiModelProperty
(
value
=
"指标类型"
,
required
=
true
)
@ApiModelProperty
(
value
=
"指标类型"
,
required
=
true
)
private
Integer
type
;
private
Integer
type
;
...
...
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