Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zh-baseversion-project
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
王浩
zh-baseversion-project
Commits
1690938a
Commit
1690938a
authored
Jun 14, 2024
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
并发生成序列号
parent
3ae1c138
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
43 deletions
+90
-43
TSerialNumberInfo.java
...main/java/com/zehong/system/domain/TSerialNumberInfo.java
+33
-33
ITSerialNumberInfoService.java
.../com/zehong/system/service/ITSerialNumberInfoService.java
+9
-0
TSerialNumberInfoServiceImpl.java
...ong/system/service/impl/TSerialNumberInfoServiceImpl.java
+42
-4
TSerialNumberInfoMapper.xml
.../main/resources/mapper/system/TSerialNumberInfoMapper.xml
+6
-6
No files found.
zh-baseversion-system/src/main/java/com/zehong/system/domain/TSerialNumberInfo.java
View file @
1690938a
...
...
@@ -7,9 +7,9 @@ import com.zehong.common.core.domain.BaseEntity;
/**
* 序列号对象 t_serial_number_info
*
*
* @author zehong
* @date 2024-06-
07
* @date 2024-06-
13
*/
public
class
TSerialNumberInfo
extends
BaseEntity
{
...
...
@@ -20,88 +20,88 @@ public class TSerialNumberInfo extends BaseEntity
/** 表类型 */
@Excel
(
name
=
"表类型"
)
private
Lo
ng
tableType
;
private
Stri
ng
tableType
;
/** 列名 */
@Excel
(
name
=
"列名"
)
private
Lo
ng
columnName
;
private
Stri
ng
columnName
;
/** 最大值 */
@Excel
(
name
=
"最大值"
)
private
Stri
ng
maxNum
;
private
Lo
ng
maxNum
;
/** 序号长度 */
@Excel
(
name
=
"序号长度"
)
private
Stri
ng
numLength
;
private
Lo
ng
numLength
;
/** 版本号 */
@Excel
(
name
=
"版本号"
)
private
Stri
ng
version
;
private
Lo
ng
version
;
/** 删除状态:0.否 1.是 */
@Excel
(
name
=
"删除状态:0.否 1.是"
)
private
String
isDel
;
public
void
setNumberId
(
Long
numberId
)
public
void
setNumberId
(
Long
numberId
)
{
this
.
numberId
=
numberId
;
}
public
Long
getNumberId
()
public
Long
getNumberId
()
{
return
numberId
;
}
public
void
setTableType
(
Long
tableType
)
public
void
setTableType
(
String
tableType
)
{
this
.
tableType
=
tableType
;
}
public
Long
getTableType
()
public
String
getTableType
()
{
return
tableType
;
}
public
void
setColumnName
(
Long
columnName
)
public
void
setColumnName
(
String
columnName
)
{
this
.
columnName
=
columnName
;
}
public
Long
getColumnName
()
public
String
getColumnName
()
{
return
columnName
;
}
public
void
setMaxNum
(
String
maxNum
)
public
void
setMaxNum
(
Long
maxNum
)
{
this
.
maxNum
=
maxNum
;
}
public
String
getMaxNum
()
public
Long
getMaxNum
()
{
return
maxNum
;
}
public
void
setNumLength
(
String
numLength
)
public
void
setNumLength
(
Long
numLength
)
{
this
.
numLength
=
numLength
;
}
public
String
getNumLength
()
public
Long
getNumLength
()
{
return
numLength
;
}
public
void
setVersion
(
String
version
)
public
void
setVersion
(
Long
version
)
{
this
.
version
=
version
;
}
public
String
getVersion
()
public
Long
getVersion
()
{
return
version
;
}
public
void
setIsDel
(
String
isDel
)
public
void
setIsDel
(
String
isDel
)
{
this
.
isDel
=
isDel
;
}
public
String
getIsDel
()
public
String
getIsDel
()
{
return
isDel
;
}
...
...
@@ -109,16 +109,16 @@ public class TSerialNumberInfo extends BaseEntity
@Override
public
String
toString
()
{
return
new
ToStringBuilder
(
this
,
ToStringStyle
.
MULTI_LINE_STYLE
)
.
append
(
"numberId"
,
getNumberId
())
.
append
(
"tableType"
,
getTableType
())
.
append
(
"columnName"
,
getColumnName
())
.
append
(
"maxNum"
,
getMaxNum
())
.
append
(
"numLength"
,
getNumLength
())
.
append
(
"updateTime"
,
getUpdateTime
())
.
append
(
"updateBy"
,
getUpdateBy
())
.
append
(
"version"
,
getVersion
())
.
append
(
"isDel"
,
getIsDel
())
.
append
(
"remark"
,
getRemark
())
.
toString
();
.
append
(
"numberId"
,
getNumberId
())
.
append
(
"tableType"
,
getTableType
())
.
append
(
"columnName"
,
getColumnName
())
.
append
(
"maxNum"
,
getMaxNum
())
.
append
(
"numLength"
,
getNumLength
())
.
append
(
"version"
,
getVersion
())
.
append
(
"updateTime"
,
getUpdateTime
())
.
append
(
"updateBy"
,
getUpdateBy
())
.
append
(
"isDel"
,
getIsDel
())
.
append
(
"remark"
,
getRemark
())
.
toString
();
}
}
}
\ No newline at end of file
zh-baseversion-system/src/main/java/com/zehong/system/service/ITSerialNumberInfoService.java
View file @
1690938a
package
com
.
zehong
.
system
.
service
;
import
java.util.List
;
import
java.util.Map
;
import
com.zehong.system.domain.TSerialNumberInfo
;
/**
...
...
@@ -58,4 +60,11 @@ public interface ITSerialNumberInfoService
* @return 结果
*/
public
int
deleteTSerialNumberInfoById
(
Long
numberId
);
/**
* 根据表类型获取序列号
* @param tableType 表表类型
* @return
*/
Map
<
String
,
String
>
getSerialNumberByTableType
(
String
tableType
);
}
zh-baseversion-system/src/main/java/com/zehong/system/service/impl/TSerialNumberInfoServiceImpl.java
View file @
1690938a
package
com
.
zehong
.
system
.
service
.
impl
;
import
java.util.List
;
import
com.zehong.common.exception.CustomException
;
import
com.zehong.common.utils.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.zehong.system.mapper.TSerialNumberInfoMapper
;
import
com.zehong.system.domain.TSerialNumberInfo
;
import
com.zehong.system.mapper.TSerialNumberInfoMapper
;
import
com.zehong.system.service.ITSerialNumberInfoService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 序列号Service业务层处理
...
...
@@ -92,4 +96,38 @@ public class TSerialNumberInfoServiceImpl implements ITSerialNumberInfoService
{
return
tSerialNumberInfoMapper
.
deleteTSerialNumberInfoById
(
numberId
);
}
/**
* 根据表类型获取序列号
* @param tableType 表表类型
* @return
*/
@Override
public
synchronized
Map
<
String
,
String
>
getSerialNumberByTableType
(
String
tableType
){
//获取最新编号
TSerialNumberInfo
tSerialNumberInfo
=
new
TSerialNumberInfo
();
tSerialNumberInfo
.
setTableType
(
tableType
);
List
<
TSerialNumberInfo
>
serialNumberInfoList
=
tSerialNumberInfoMapper
.
selectTSerialNumberInfoList
(
tSerialNumberInfo
);
Map
<
String
,
String
>
numberMap
=
new
HashMap
<>();
//更新编号
serialNumberInfoList
.
stream
().
forEach
(
item
->{
//自旋更新
int
result
;
int
lookNum
=
0
;
do
{
lookNum
++;
Long
maxNum
=
item
.
getMaxNum
();
maxNum
++;
maxNum
=
maxNum
.
toString
().
length
()
>
item
.
getNumLength
()
?
0
:
maxNum
;
String
number
=
String
.
format
(
"%0"
+
item
.
getNumLength
()
+
"d"
,
maxNum
);
numberMap
.
put
(
item
.
getColumnName
(),
number
);
item
.
setMaxNum
(
maxNum
);
result
=
tSerialNumberInfoMapper
.
updateTSerialNumberInfo
(
item
);
if
(
result
==
0
)
item
=
tSerialNumberInfoMapper
.
selectTSerialNumberInfoById
(
item
.
getNumberId
());
}
while
(
result
==
0
&&
lookNum
<
5
);
if
(
lookNum
>
4
)
throw
new
CustomException
(
"序列号生成失败"
);
});
return
numberMap
;
}
}
zh-baseversion-system/src/main/resources/mapper/system/TSerialNumberInfoMapper.xml
View file @
1690938a
...
...
@@ -18,14 +18,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql
id=
"selectTSerialNumberInfoVo"
>
select number_id, table_type,
column_name
, max_num, num_length, update_time, update_by, version, is_del, remark from t_serial_number_info
select number_id, table_type,
`column_name`
, max_num, num_length, update_time, update_by, version, is_del, remark from t_serial_number_info
</sql>
<select
id=
"selectTSerialNumberInfoList"
parameterType=
"TSerialNumberInfo"
resultMap=
"TSerialNumberInfoResult"
>
<include
refid=
"selectTSerialNumberInfoVo"
/>
<where>
<if
test=
"tableType != null "
>
and table_type = #{tableType}
</if>
<if
test=
"columnName != null "
>
and
column_name
like concat('%', #{columnName}, '%')
</if>
<if
test=
"columnName != null "
>
and
`column_name`
like concat('%', #{columnName}, '%')
</if>
<if
test=
"maxNum != null and maxNum != ''"
>
and max_num = #{maxNum}
</if>
<if
test=
"numLength != null and numLength != ''"
>
and num_length = #{numLength}
</if>
<if
test=
"version != null and version != ''"
>
and version = #{version}
</if>
...
...
@@ -42,7 +42,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into t_serial_number_info
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"tableType != null"
>
table_type,
</if>
<if
test=
"columnName != null"
>
column_name
,
</if>
<if
test=
"columnName != null"
>
`column_name`
,
</if>
<if
test=
"maxNum != null"
>
max_num,
</if>
<if
test=
"numLength != null"
>
num_length,
</if>
<if
test=
"updateTime != null"
>
update_time,
</if>
...
...
@@ -68,16 +68,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update t_serial_number_info
<trim
prefix=
"SET"
suffixOverrides=
","
>
<if
test=
"tableType != null"
>
table_type = #{tableType},
</if>
<if
test=
"columnName != null"
>
column_name
= #{columnName},
</if>
<if
test=
"columnName != null"
>
`column_name`
= #{columnName},
</if>
<if
test=
"maxNum != null"
>
max_num = #{maxNum},
</if>
<if
test=
"numLength != null"
>
num_length = #{numLength},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime},
</if>
<if
test=
"updateBy != null"
>
update_by = #{updateBy},
</if>
<if
test=
"version != null"
>
version = #{version},
</if>
<if
test=
"version != null"
>
version = #{version}
+ 1
,
</if>
<if
test=
"isDel != null"
>
is_del = #{isDel},
</if>
<if
test=
"remark != null"
>
remark = #{remark},
</if>
</trim>
where number_id = #{numberId}
where number_id = #{numberId}
and version = #{version}
</update>
<delete
id=
"deleteTSerialNumberInfoById"
parameterType=
"Long"
>
...
...
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