Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
377067f5
Commit
377067f5
authored
Jan 18, 2024
by
LiuLin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(YMT):添加初始化Redis接口和监管码为空的时候,初始化Redis
parent
eaaa455f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
7 deletions
+42
-7
IGenerateCodeService.java
...mos/boot/module/ymt/api/service/IGenerateCodeService.java
+2
-0
GenerateCodeController.java
...oot/module/ymt/biz/controller/GenerateCodeController.java
+11
-4
GenerateCodeServiceImpl.java
.../module/ymt/biz/service/impl/GenerateCodeServiceImpl.java
+29
-3
No files found.
amos-boot-system-tzs/amos-boot-module-ymt/amos-boot-module-ymt-api/src/main/java/com/yeejoin/amos/boot/module/ymt/api/service/IGenerateCodeService.java
View file @
377067f5
...
@@ -51,4 +51,6 @@ public interface IGenerateCodeService {
...
@@ -51,4 +51,6 @@ public interface IGenerateCodeService {
* @return 7位监管编码生成
* @return 7位监管编码生成
*/
*/
String
createSupervisoryCode
(
String
key
);
String
createSupervisoryCode
(
String
key
);
String
initCode
();
}
}
amos-boot-system-tzs/amos-boot-module-ymt/amos-boot-module-ymt-biz/src/main/java/com/yeejoin/amos/boot/module/ymt/biz/controller/GenerateCodeController.java
View file @
377067f5
...
@@ -5,10 +5,7 @@ import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
...
@@ -5,10 +5,7 @@ import com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
import
org.typroject.tyboot.core.restful.utils.ResponseHelper
;
...
@@ -66,4 +63,14 @@ public class GenerateCodeController extends BaseController {
...
@@ -66,4 +63,14 @@ public class GenerateCodeController extends BaseController {
public
ResponseModel
<
String
>
createUseRegistrationCode
(
@RequestParam
(
"key"
)
String
key
)
{
public
ResponseModel
<
String
>
createUseRegistrationCode
(
@RequestParam
(
"key"
)
String
key
)
{
return
ResponseHelper
.
buildResponse
(
generateCodeService
.
createUseRegistrationCode
(
key
));
return
ResponseHelper
.
buildResponse
(
generateCodeService
.
createUseRegistrationCode
(
key
));
}
}
/**
* 初始化96333和监管码到Redis
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@GetMapping
(
value
=
"/init-code"
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"初始化96333和监管码到Redis"
,
notes
=
"初始化96333和监管码到Redis"
)
public
ResponseModel
<
String
>
initCode
()
{
return
ResponseHelper
.
buildResponse
(
generateCodeService
.
initCode
());
}
}
}
amos-boot-system-tzs/amos-boot-module-ymt/amos-boot-module-ymt-biz/src/main/java/com/yeejoin/amos/boot/module/ymt/biz/service/impl/GenerateCodeServiceImpl.java
View file @
377067f5
...
@@ -3,9 +3,11 @@ package com.yeejoin.amos.boot.module.ymt.biz.service.impl;
...
@@ -3,9 +3,11 @@ package com.yeejoin.amos.boot.module.ymt.biz.service.impl;
import
com.yeejoin.amos.boot.module.ymt.api.common.DateUtils
;
import
com.yeejoin.amos.boot.module.ymt.api.common.DateUtils
;
import
com.yeejoin.amos.boot.module.ymt.api.enums.ApplicationFormTypeEnum
;
import
com.yeejoin.amos.boot.module.ymt.api.enums.ApplicationFormTypeEnum
;
import
com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentCategoryEnum
;
import
com.yeejoin.amos.boot.module.ymt.api.enums.EquipmentCategoryEnum
;
import
com.yeejoin.amos.boot.module.ymt.api.mapper.CategoryOtherInfoMapper
;
import
com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService
;
import
com.yeejoin.amos.boot.module.ymt.api.service.IGenerateCodeService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
...
@@ -33,12 +35,15 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
...
@@ -33,12 +35,15 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
private
static
final
String
SEQUENCE_TYPE
=
"%07d"
;
private
static
final
String
SEQUENCE_TYPE
=
"%07d"
;
private
static
final
long
LOCK_EXPIRATION_SECONDS
=
60
;
private
static
final
long
LOCK_EXPIRATION_SECONDS
=
60
;
private
final
RedisTemplate
<
String
,
String
>
redisTemplate
;
private
final
RedisTemplate
<
String
,
String
>
redisTemplate
;
private
final
StringRedisTemplate
stringRedisTemplate
;
private
final
CategoryOtherInfoMapper
categoryOtherInfoMapper
;
private
String
rulePrefix
=
""
;
private
String
rulePrefix
=
""
;
public
GenerateCodeServiceImpl
(
RedisTemplate
<
String
,
String
>
redisTemplate
)
{
public
GenerateCodeServiceImpl
(
RedisTemplate
<
String
,
String
>
redisTemplate
,
StringRedisTemplate
stringRedisTemplate
,
CategoryOtherInfoMapper
categoryOtherInfoMapper
)
{
this
.
redisTemplate
=
redisTemplate
;
this
.
redisTemplate
=
redisTemplate
;
this
.
stringRedisTemplate
=
stringRedisTemplate
;
this
.
categoryOtherInfoMapper
=
categoryOtherInfoMapper
;
}
}
/**
/**
* 生成申请单编号(13位,GZ20231214000)
* 生成申请单编号(13位,GZ20231214000)
*
*
...
@@ -93,6 +98,15 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
...
@@ -93,6 +98,15 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
return
(
key
.
length
()
==
5
)
?
generateSupervisorySequence
(
key
)
:
"生成码规则不对!"
;
return
(
key
.
length
()
==
5
)
?
generateSupervisorySequence
(
key
)
:
"生成码规则不对!"
;
}
}
@Override
public
String
initCode
()
{
categoryOtherInfoMapper
.
selectSupervisorCodeMaxValue
().
forEach
(
vo
->
stringRedisTemplate
.
opsForValue
().
set
(
vo
.
getName
(),
String
.
valueOf
(
vo
.
getValue
())));
categoryOtherInfoMapper
.
selectElevatorCodeMaxValue
().
forEach
(
vo
->
stringRedisTemplate
.
opsForValue
().
set
(
vo
.
getName
(),
String
.
valueOf
(
vo
.
getValue
())));
return
"ok"
;
}
private
String
generateSupervisorySequence
(
String
sequenceKey
)
{
private
String
generateSupervisorySequence
(
String
sequenceKey
)
{
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
// 使用分布式锁,确保在并发情况下只有一个线程能够生成顺序码
Boolean
lockAcquired
=
obtainLock
(
GenerateCodeServiceImpl
.
LOCK_KEY_SUPERVISORY
);
Boolean
lockAcquired
=
obtainLock
(
GenerateCodeServiceImpl
.
LOCK_KEY_SUPERVISORY
);
...
@@ -102,7 +116,7 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
...
@@ -102,7 +116,7 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
ValueOperations
<
String
,
String
>
valueOps
=
redisTemplate
.
opsForValue
();
ValueOperations
<
String
,
String
>
valueOps
=
redisTemplate
.
opsForValue
();
String
currentSequenceStr
=
valueOps
.
get
(
sequenceKey
);
String
currentSequenceStr
=
valueOps
.
get
(
sequenceKey
);
// 如果为空,则初始化为0
// 如果为空,则初始化为0
Long
currentSequence
=
(
currentSequenceStr
!=
null
)
?
Long
.
parseLong
(
currentSequenceStr
)
:
0L
;
Long
currentSequence
=
(
currentSequenceStr
!=
null
)
?
Long
.
parseLong
(
currentSequenceStr
)
:
this
.
initRedis
(
sequenceKey
)
;
log
.
info
(
"===================>获取《{}》当前顺序码:{}<==================="
,
sequenceKey
,
currentSequenceStr
);
log
.
info
(
"===================>获取《{}》当前顺序码:{}<==================="
,
sequenceKey
,
currentSequenceStr
);
currentSequence
++;
currentSequence
++;
...
@@ -121,6 +135,18 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
...
@@ -121,6 +135,18 @@ public class GenerateCodeServiceImpl implements IGenerateCodeService {
}
}
/**
/**
* 监管码为空的话,初始化Redis
* @param sequenceKey key
* @return 顺序码
*/
private
Long
initRedis
(
String
sequenceKey
)
{
categoryOtherInfoMapper
.
selectSupervisorCodeMaxValue
().
forEach
(
vo
->
stringRedisTemplate
.
opsForValue
().
set
(
vo
.
getName
(),
String
.
valueOf
(
vo
.
getValue
())));
return
Long
.
parseLong
(
Objects
.
requireNonNull
(
redisTemplate
.
opsForValue
().
get
(
sequenceKey
)));
}
/**
* 校验枚举合法性
* 校验枚举合法性
*
*
* @param value value
* @param value value
...
...
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