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
ed0ae6b3
Commit
ed0ae6b3
authored
Jul 30, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
积分规则接口校验
parent
0612f246
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
129 additions
and
28 deletions
+129
-28
ErrorCodeConstants.java
...iocoder/yudao/module/member/enums/ErrorCodeConstants.java
+2
-1
ScoreRuleController.java
...ember/controller/admin/scoreRule/ScoreRuleController.java
+5
-6
ScoreRuleService.java
...dao/module/member/service/scoreRule/ScoreRuleService.java
+2
-2
ScoreRuleServiceImpl.java
...module/member/service/scoreRule/ScoreRuleServiceImpl.java
+118
-17
ScoreRuleBaseVO.java
...der/yudao/module/member/vo/scoreRule/ScoreRuleBaseVO.java
+1
-1
ScoreRuleShareExtraVO.java
...dule/member/vo/scoreRule/extra/ScoreRuleShareExtraVO.java
+1
-1
No files found.
yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java
View file @
ed0ae6b3
...
...
@@ -48,7 +48,8 @@ public interface ErrorCodeConstants {
ErrorCode
SCORE_RULE_NOT_EXISTS
=
new
ErrorCode
(
1004008004
,
"score.rule.not.exists"
);
ErrorCode
SCORE_RULE_DELETE_ERROR
=
new
ErrorCode
(
1004008005
,
"score.rule.delete.error"
);
ErrorCode
SCORE_RULE_UPDATE_ERROR
=
new
ErrorCode
(
1004008005
,
"score.rule.update.error"
);
ErrorCode
SCORE_RULE_UPDATE_ERROR
=
new
ErrorCode
(
1004008006
,
"score.rule.update.error"
);
ErrorCode
SCORE_RULE_FIELD_ERROR
=
new
ErrorCode
(
1004008007
,
"score.rule.field.error"
);
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/controller/admin/scoreRule/ScoreRuleController.java
View file @
ed0ae6b3
...
...
@@ -90,22 +90,21 @@ public class ScoreRuleController {
@ApiOperation
(
"启用关闭"
)
@PreAuthorize
(
"@ss.hasPermission('member:score-rule:update')"
)
public
CommonResult
<
Boolean
>
updateStatus
(
@Valid
@RequestBody
ScoreRuleStatusReqVO
scoreRuleStatusReqVO
)
{
Boolean
res
=
scoreRuleService
.
updateStatus
(
scoreRuleStatusReqVO
);
return
success
(
res
);
scoreRuleService
.
updateStatus
(
scoreRuleStatusReqVO
);
return
success
(
true
);
}
@PostMapping
(
"/copy"
)
@ApiOperation
(
"复制规则"
)
@PreAuthorize
(
"@ss.hasPermission('member:score-rule:create')"
)
public
CommonResult
<
Long
>
copyScoreRule
(
@NotNull
@RequestBody
Long
id
)
{
Long
newId
=
scoreRuleService
.
copyScoreRule
(
id
);
return
success
(
id
);
return
success
(
scoreRuleService
.
copyScoreRule
(
id
));
}
@PostMapping
(
"/delay"
)
@ApiOperation
(
"延期规则"
)
@PreAuthorize
(
"@ss.hasPermission('member:score-rule:update')"
)
public
CommonResult
<
Boolean
>
delayScoreRule
(
@Valid
@RequestBody
ScoreDelayReqVO
scoreDelayReqVO
)
{
Boolean
res
=
scoreRuleService
.
delayScoreRule
(
scoreDelayReqVO
);
return
success
(
res
);
scoreRuleService
.
delayScoreRule
(
scoreDelayReqVO
);
return
success
(
true
);
}
@GetMapping
(
"/export-excel"
)
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/scoreRule/ScoreRuleService.java
View file @
ed0ae6b3
...
...
@@ -72,7 +72,7 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
* @param scoreRuleStatusReqVO 积分规则状态
* @return
*/
Boolean
updateStatus
(
ScoreRuleStatusReqVO
scoreRuleStatusReqVO
);
void
updateStatus
(
ScoreRuleStatusReqVO
scoreRuleStatusReqVO
);
/**
* 积分规则复制
...
...
@@ -86,5 +86,5 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
* @param scoreDelayReqVO 积分规则延期
* @return
*/
Boolean
delayScoreRule
(
ScoreDelayReqVO
scoreDelayReqVO
);
void
delayScoreRule
(
ScoreDelayReqVO
scoreDelayReqVO
);
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/service/scoreRule/ScoreRuleServiceImpl.java
View file @
ed0ae6b3
...
...
@@ -6,17 +6,20 @@ import javax.annotation.Resource;
import
cn.hutool.json.JSONUtil
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery
;
import
cn.iocoder.yudao.framework.mybatis.core.service.AbstractService
;
import
cn.iocoder.yudao.module.member.convert.scoreRule.ScoreRuleConvert
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum
;
import
cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum
;
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.ScoreRuleRegisterExtraVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleShareExtraVO
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRulerRecommendExtraVO
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -40,23 +43,56 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override
public
Long
createScoreRule
(
ScoreRuleCreateReqVO
createReqVO
)
{
ScoreRuleDO
scoreRule
=
ScoreRuleConvert
.
INSTANCE
.
convert
(
createReqVO
);
verifyCommon
(
scoreRule
);
Integer
scoreRuleType
=
scoreRule
.
getType
();
s
etExtraDO
(
createReqVO
,
scoreRuleType
,
scoreRule
);
verifyAndS
etExtraDO
(
createReqVO
,
scoreRuleType
,
scoreRule
);
scoreRuleMapper
.
insert
(
scoreRule
);
// 返回
return
scoreRule
.
getId
();
}
private
void
verifyCommon
(
ScoreRuleDO
scoreRule
)
{
//校验公共入参
if
(
scoreRule
.
getGetScoreOnce
()
<=
0
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
scoreRule
.
getMaxScoreTotal
()
<=
0
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
scoreRule
.
getStartTime
().
after
((
scoreRule
.
getEndTime
()))
||
scoreRule
.
getEndTime
().
before
(
Date
.
from
(
Instant
.
now
())))
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
scoreRule
.
getSocrePeriod
()
<=
0
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验
if
(
scoreRule
.
getStatus
()
==
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()
&&
scoreRule
.
getType
()
!=
ScoreRuleTypeEnum
.
SHARE
.
getValue
())
{
LambdaQuery
<
ScoreRuleDO
>
scoreRuleDOLambdaQuery
=
new
LambdaQuery
<>();
scoreRuleDOLambdaQuery
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getType
,
scoreRule
.
getType
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
());
Long
count
=
scoreRuleMapper
.
selectCount
(
scoreRuleDOLambdaQuery
);
if
(
count
>
1
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
}
}
@Override
public
void
updateScoreRule
(
ScoreRuleUpdateReqVO
updateReqVO
)
{
// 校验存在
this
.
validateScoreRuleExists
(
updateReqVO
.
getId
());
ScoreRuleDO
scoreRuleDO
=
scoreRuleMapper
.
selectById
(
updateReqVO
.
getId
());
if
(
scoreRuleDO
==
null
)
{
throw
exception
(
SCORE_RULE_NOT_EXISTS
);
}
if
(
scoreRuleDO
.
getStatus
()
==
ScoreRuleStatusEnum
.
ENABLED
.
getValue
())
{
throw
exception
(
SCORE_RULE_UPDATE_ERROR
);
}
ScoreRuleDO
scoreRule
=
ScoreRuleConvert
.
INSTANCE
.
convert
(
updateReqVO
);
setExtraDO
(
updateReqVO
,
updateReqVO
.
getType
(),
scoreRule
);
verifyCommon
(
scoreRule
);
verifyAndSetExtraDO
(
updateReqVO
,
updateReqVO
.
getType
(),
scoreRule
);
// 更新
ScoreRuleDO
updateObj
=
ScoreRuleConvert
.
INSTANCE
.
convert
(
updateReqVO
);
scoreRuleMapper
.
updateById
(
updateObj
);
scoreRuleMapper
.
updateById
(
scoreRule
);
}
/**
...
...
@@ -66,20 +102,70 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
* @param scoreRuleType 指标类型
* @param scoreRule 需要填充额外字段的DO
*/
private
void
s
etExtraDO
(
ScoreRuleBaseVO
reqVO
,
Integer
scoreRuleType
,
ScoreRuleDO
scoreRule
)
{
private
void
verifyAndS
etExtraDO
(
ScoreRuleBaseVO
reqVO
,
Integer
scoreRuleType
,
ScoreRuleDO
scoreRule
)
{
if
(
scoreRuleType
==
ScoreRuleTypeEnum
.
ORDER_V
.
getValue
())
{
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
reqVO
.
getExtraOrderV
()));
ScoreRuleOrderVExtraVO
extraOrderV
=
reqVO
.
getExtraOrderV
();
if
(
extraOrderV
==
null
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
extraOrderV
.
getFirstOrder
()
!=
YesOrNoTypeEnum
.
YES
.
ordinal
()
&&
extraOrderV
.
getFirstOrder
()
!=
YesOrNoTypeEnum
.
NO
.
ordinal
())
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
StringUtils
.
isAnyBlank
(
extraOrderV
.
getTargetCountry
(),
extraOrderV
.
getTargetCity
(),
extraOrderV
.
getReceiveAddr
(),
extraOrderV
.
getOrderEntry
()))
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
verifyOrderVRule
(
extraOrderV
.
getOrderVRule
());
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
extraOrderV
));
}
else
if
(
scoreRuleType
==
ScoreRuleTypeEnum
.
REGISTER
.
getValue
())
{
if
(
reqVO
.
getExtraRegister
()
==
null
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
StringUtils
.
isBlank
(
reqVO
.
getExtraRegister
().
getRegisterPlatform
()))
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
reqVO
.
getExtraRegister
()));
}
else
if
(
scoreRuleType
==
ScoreRuleTypeEnum
.
RECOMMEND
.
getValue
())
{
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
reqVO
.
getExtraRecommend
()));
ScoreRulerRecommendExtraVO
extraRecommend
=
reqVO
.
getExtraRecommend
();
if
(
extraRecommend
==
null
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
extraRecommend
.
getShareStatus
()
!=
YesOrNoTypeEnum
.
YES
.
ordinal
()
&&
extraRecommend
.
getShareStatus
()
!=
YesOrNoTypeEnum
.
NO
.
ordinal
())
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
StringUtils
.
isAnyBlank
(
extraRecommend
.
getShareContentEn
(),
extraRecommend
.
getShareContentZh
()))
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
extraRecommend
));
}
else
if
(
scoreRuleType
==
ScoreRuleTypeEnum
.
SHARE
.
getValue
())
{
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
reqVO
.
getExtraShare
()));
ScoreRuleShareExtraVO
extraShare
=
reqVO
.
getExtraShare
();
if
(
extraShare
==
null
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
StringUtils
.
isAnyBlank
(
extraShare
.
getActivityDescZh
(),
extraShare
.
getActivityDescEn
(),
extraShare
.
getActivityUrl
()))
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
if
(
extraShare
.
getShareStatus
()
!=
YesOrNoTypeEnum
.
YES
.
ordinal
()
&&
extraShare
.
getShareStatus
()
!=
YesOrNoTypeEnum
.
NO
.
ordinal
())
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
scoreRule
.
setExtra
(
JSONUtil
.
toJsonStr
(
extraShare
));
}
else
{
throw
exception
(
SCORE_RULE_NOT_EXISTS
);
}
}
private
void
verifyOrderVRule
(
List
<
ScoreRuleOrderVExtraVO
.
OrderVRule
>
extraOrderVRule
)
{
if
(
extraOrderVRule
==
null
||
extraOrderVRule
.
isEmpty
())
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
int
low
=
0
;
for
(
ScoreRuleOrderVExtraVO
.
OrderVRule
orderVRule
:
extraOrderVRule
)
{
if
(
orderVRule
.
getLow
()
<
low
||
orderVRule
.
getHigh
()
<=
orderVRule
.
getLow
()
||
orderVRule
.
getScore
()
<=
0
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
low
=
orderVRule
.
getHigh
();
}
}
@Override
public
void
deleteScoreRule
(
Long
id
)
{
ScoreRuleDO
scoreRuleDO
=
scoreRuleMapper
.
selectById
(
id
);
...
...
@@ -151,16 +237,31 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
}
@Override
public
Boolean
updateStatus
(
ScoreRuleStatusReqVO
scoreRuleStatusReqVO
)
{
public
void
updateStatus
(
ScoreRuleStatusReqVO
scoreRuleStatusReqVO
)
{
ScoreRuleDO
scoreRuleDO
=
scoreRuleMapper
.
selectById
(
scoreRuleStatusReqVO
.
getId
());
if
(
scoreRuleDO
==
null
)
{
throw
exception
(
SCORE_RULE_NOT_EXISTS
);
}
Integer
oldStatus
=
scoreRuleDO
.
getStatus
();
ScoreRuleDO
upScoreRuleDO
=
new
ScoreRuleDO
();
upScoreRuleDO
.
setId
(
scoreRuleStatusReqVO
.
getId
());
upScoreRuleDO
.
setStatus
(
scoreRuleStatusReqVO
.
getStatus
());
int
updated
=
scoreRuleMapper
.
updateById
(
upScoreRuleDO
);
return
updated
>
0
;
if
(
oldStatus
==
ScoreRuleStatusEnum
.
ENABLED
.
getValue
()
&&
scoreRuleStatusReqVO
.
getStatus
()
==
ScoreRuleStatusEnum
.
CLOSED
.
getValue
())
{
upScoreRuleDO
.
setStatus
(
scoreRuleStatusReqVO
.
getStatus
());
}
else
if
(
oldStatus
==
ScoreRuleStatusEnum
.
DISABLED
.
getValue
()
&&
scoreRuleStatusReqVO
.
getStatus
()
==
ScoreRuleStatusEnum
.
ENABLED
.
getValue
())
{
//如果是启用,校验同一个规则下,有效期内有没有重复的规则设置,分享不校验
if
(
scoreRuleDO
.
getType
()
!=
ScoreRuleTypeEnum
.
SHARE
.
getValue
())
{
LambdaQuery
<
ScoreRuleDO
>
scoreRuleDOLambdaQuery
=
new
LambdaQuery
<>();
scoreRuleDOLambdaQuery
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
())
.
eq
(
ScoreRuleDO:
:
getType
,
scoreRuleDO
.
getType
())
.
eq
(
ScoreRuleDO:
:
getStatus
,
ScoreRuleStatusEnum
.
ENABLED
.
getValue
());
Long
count
=
scoreRuleMapper
.
selectCount
(
scoreRuleDOLambdaQuery
);
if
(
count
>
1
)
{
throw
exception
(
SCORE_RULE_FIELD_ERROR
);
}
}
upScoreRuleDO
.
setStatus
(
scoreRuleStatusReqVO
.
getStatus
());
}
scoreRuleMapper
.
updateById
(
upScoreRuleDO
);
}
@Override
...
...
@@ -173,12 +274,13 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
scoreRuleDO
.
setId
(
null
);
scoreRuleDO
.
setCreateTime
(
null
);
scoreRuleDO
.
setUpdateTime
(
null
);
scoreRuleDO
.
setUpdater
(
null
);
scoreRuleMapper
.
insert
(
scoreRuleDO
);
return
scoreRuleDO
.
getId
();
}
@Override
public
Boolean
delayScoreRule
(
ScoreDelayReqVO
delayReqVO
)
{
public
void
delayScoreRule
(
ScoreDelayReqVO
delayReqVO
)
{
ScoreRuleDO
scoreRuleDO
=
scoreRuleMapper
.
selectById
(
delayReqVO
.
getId
());
if
(
scoreRuleDO
==
null
)
{
throw
exception
(
SCORE_RULE_NOT_EXISTS
);
...
...
@@ -194,7 +296,6 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
ScoreRuleDO
upScoreRuleDO
=
new
ScoreRuleDO
();
upScoreRuleDO
.
setId
(
delayReqVO
.
getId
());
upScoreRuleDO
.
setEndTime
(
delayReqVO
.
getEndTime
());
int
updated
=
scoreRuleMapper
.
updateById
(
upScoreRuleDO
);
return
updated
>
0
;
scoreRuleMapper
.
updateById
(
upScoreRuleDO
);
}
}
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/vo/scoreRule/ScoreRuleBaseVO.java
View file @
ed0ae6b3
...
...
@@ -24,7 +24,7 @@ public class ScoreRuleBaseVO {
private
Integer
type
;
@ApiModelProperty
(
value
=
"规则标题中文"
,
required
=
true
)
@Not
Null
(
message
=
"规则标题中文不能为空"
)
@Not
Blank
(
message
=
"规则标题中文不能为空"
)
private
String
titleZh
;
@ApiModelProperty
(
value
=
"规则标题英文"
,
required
=
true
)
...
...
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/vo/scoreRule/extra/ScoreRuleShareExtraVO.java
View file @
ed0ae6b3
...
...
@@ -14,5 +14,5 @@ public class ScoreRuleShareExtraVO {
@ApiModelProperty
(
value
=
"活动链接"
,
required
=
true
)
private
String
activityUrl
;
@ApiModelProperty
(
value
=
"是否分享(0是,1否)默认是"
,
required
=
true
)
private
String
shareStatus
;
private
Integer
shareStatus
;
}
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