Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cust-api
Project
Project
Details
Activity
Releases
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
李伟
cust-api
Commits
11b26e11
Commit
11b26e11
authored
Feb 24, 2025
by
liwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了发表动态接口
parent
30db737f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
22 deletions
+40
-22
OpmArticle.java
...va/org/rcisoft/business/opmArticle/entity/OpmArticle.java
+6
-0
OpmArticleServiceImpl.java
...siness/opmArticle/service/impl/OpmArticleServiceImpl.java
+34
-22
No files found.
src/main/java/org/rcisoft/business/opmArticle/entity/OpmArticle.java
View file @
11b26e11
...
@@ -231,5 +231,11 @@ public class OpmArticle extends CyIdIncreEntity<OpmArticle> {
...
@@ -231,5 +231,11 @@ public class OpmArticle extends CyIdIncreEntity<OpmArticle> {
*/
*/
@TableField
(
exist
=
false
)
@TableField
(
exist
=
false
)
private
String
wxOpenid
;
private
String
wxOpenid
;
/**
* 是否付费 1:付费 0:不付费
*/
@TableField
(
exist
=
false
)
private
String
isPay
;
}
}
src/main/java/org/rcisoft/business/opmArticle/service/impl/OpmArticleServiceImpl.java
View file @
11b26e11
...
@@ -31,6 +31,7 @@ import org.rcisoft.sys.dictionary.service.DictionaryService;
...
@@ -31,6 +31,7 @@ import org.rcisoft.sys.dictionary.service.DictionaryService;
import
org.redisson.api.RLock
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Isolation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
...
@@ -67,6 +68,8 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
...
@@ -67,6 +68,8 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
private
CyRedisServiceImpl
cyRedisServiceImpl
;
private
CyRedisServiceImpl
cyRedisServiceImpl
;
@Autowired
@Autowired
private
RedissonClient
redissonClient
;
private
RedissonClient
redissonClient
;
@Autowired
private
StringRedisTemplate
redisTemplate
;
/**
/**
* 保存 opmArticle管理
* 保存 opmArticle管理
* @param opmArticle
* @param opmArticle
...
@@ -100,7 +103,7 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
...
@@ -100,7 +103,7 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
Object
redisCount
=
cyRedisServiceImpl
.
get
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
);
Object
redisCount
=
cyRedisServiceImpl
.
get
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
);
if
(
redisCount
!=
null
&&
(
int
)
redisCount
>=
publishCountAll
){
if
(
redisCount
!=
null
&&
(
int
)
redisCount
>=
publishCountAll
){
//超出最大数量
//超出最大数量
throw
new
CyServiceException
(
1001
,
"
发布动态
已达上限"
);
throw
new
CyServiceException
(
1001
,
"
今日发布动态总次数
已达上限"
);
}
else
if
(
redisCount
==
null
){
}
else
if
(
redisCount
==
null
){
//当天第一次发布动态
//当天第一次发布动态
cyRedisServiceImpl
.
set
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
,
1
,
48
*
60
*
60L
);
cyRedisServiceImpl
.
set
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
,
1
,
48
*
60
*
60L
);
...
@@ -109,28 +112,39 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
...
@@ -109,28 +112,39 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
//判断免费和付费数量
//判断免费和付费数量
if
((
int
)
redisCount
>=
publishCount
){
if
((
int
)
redisCount
>=
publishCount
){
//超过免费限制次数 需要付费
//超过免费限制次数 需要付费
//扣除该用户的金币数量
if
(
opmArticle
.
getIsPay
().
equals
(
"1"
)){
int
line
=
0
;
//扣除该用户的金币数量
boolean
isGetLock
=
false
;
int
line
=
0
;
RLock
lock
=
redissonClient
.
getLock
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK
+
userId
);
boolean
isGetLock
=
false
;
try
{
RLock
lock
=
redissonClient
.
getLock
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK
+
userId
);
isGetLock
=
lock
.
tryLock
(
Long
.
parseLong
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK_WAIT_TIME
),
try
{
Long
.
parseLong
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK_LEASE_TIME
),
TimeUnit
.
SECONDS
);
isGetLock
=
lock
.
tryLock
(
Long
.
parseLong
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK_WAIT_TIME
),
if
(
isGetLock
)
{
Long
.
parseLong
(
OpmArticleRedisBean
.
USER_ARTICLE_LOCK_LEASE_TIME
),
TimeUnit
.
SECONDS
);
MemInfo
memInfo
=
memInfoRepository
.
selectByOpenId
(
opmArticle
.
getWxOpenid
());
if
(
isGetLock
)
{
if
(
memInfo
.
getGoldCoinsCount
()
-
payCount
<
0
){
MemInfo
memInfo
=
memInfoRepository
.
selectByOpenId
(
opmArticle
.
getWxOpenid
());
throw
new
CyServiceException
(
1003
,
"金币余额不足,请先充值"
);
if
(
memInfo
.
getGoldCoinsCount
()
-
payCount
<
0
){
throw
new
CyServiceException
(
1003
,
"金币余额不足,请先充值"
);
}
memInfo
.
setGoldCoinsCount
(
memInfo
.
getGoldCoinsCount
()
-
payCount
);
memInfoRepository
.
updateById
(
memInfo
);
//增加操作
redisTemplate
.
opsForValue
().
increment
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
,
1L
);
}
}
memInfo
.
setGoldCoinsCount
(
memInfo
.
getGoldCoinsCount
()
-
payCount
);
lock
.
unlock
();
memInfoRepository
.
updateById
(
memInfo
);
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
lock
.
unlock
();
isGetLock
=
false
;
throw
new
CyServiceException
(
1004
,
"服务器繁忙,请稍后再试"
);
}
}
lock
.
unlock
();
}
else
{
}
catch
(
InterruptedException
e
)
{
//不进行发表动态
Thread
.
currentThread
().
interrupt
();
throw
new
CyServiceException
(
1002
,
"今日发表动态免费次数超出限制"
);
lock
.
unlock
();
isGetLock
=
false
;
throw
new
CyServiceException
(
1004
,
"服务器繁忙,请稍后再试"
);
}
}
}
else
{
//没超过免费次数限制
//增加操作
redisTemplate
.
opsForValue
().
increment
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
,
1L
);
}
}
}
}
//3、进行审核 从redis获取动态审核配置 0:自动审核,1:人工审核
//3、进行审核 从redis获取动态审核配置 0:自动审核,1:人工审核
...
@@ -164,8 +178,6 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
...
@@ -164,8 +178,6 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
}
}
}
}
//增加操作
cyRedisServiceImpl
.
incr
(
OpmArticleRedisBean
.
USER_ARTICLE_COUNT
+
date
+
":"
+
userId
,
1L
);
int
line
=
baseMapper
.
insert
(
opmArticle
);
int
line
=
baseMapper
.
insert
(
opmArticle
);
log
.
debug
(
CyUserUtil
.
getAuthenUsername
()+
"新增了ID为"
+
log
.
debug
(
CyUserUtil
.
getAuthenUsername
()+
"新增了ID为"
+
opmArticle
.
getBusinessId
()+
"的opmArticle管理信息"
);
opmArticle
.
getBusinessId
()+
"的opmArticle管理信息"
);
...
...
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