Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gjjs-bd-common
Overview
Overview
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
s_guodong
gjjs-bd-common
Commits
42246fae
Commit
42246fae
authored
Nov 15, 2023
by
s_guodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dbcounter查一条返回多条的兼容处理
parent
007035bd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
32 deletions
+50
-32
TblCountermapper.xml
...d-business/src/main/resources/mapper/TblCountermapper.xml
+1
-1
countermapper.xml
gjjs-bd-business/src/main/resources/mapper/countermapper.xml
+1
-1
CounterImplWithSpringTransaction.java
...pport/mybatis/count/CounterImplWithSpringTransaction.java
+4
-4
CounterMapper.java
...iance/mda/support/mybatis/count/mapper/CounterMapper.java
+24
-15
TblCounterMapper.java
...ce/mda/support/mybatis/count/mapper/TblCounterMapper.java
+20
-11
No files found.
gjjs-bd-business/src/main/resources/mapper/TblCountermapper.xml
View file @
42246fae
...
...
@@ -11,7 +11,7 @@
</select>
<update
id=
"updateCounter"
>
update TBLCNT set VAL =
VAL
+ STP where TYP = #{typ}
update TBLCNT set VAL =
#{val}
+ STP where TYP = #{typ}
</update>
<select
id=
"seqNextval"
resultType=
"java.lang.Integer"
>
...
...
gjjs-bd-business/src/main/resources/mapper/countermapper.xml
View file @
42246fae
...
...
@@ -11,7 +11,7 @@
</select>
<update
id=
"updateCounter"
>
update CNT set VAL =
VAL
+ STP where NAM = #{nam}
update CNT set VAL =
#{val}
+ STP where NAM = #{nam}
</update>
<select
id=
"seqNextval"
resultType=
"java.lang.Integer"
>
...
...
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/CounterImplWithSpringTransaction.java
View file @
42246fae
...
...
@@ -38,14 +38,14 @@ public class CounterImplWithSpringTransaction implements CounterService {
cnt
=
0
;
counterMapper
.
insertNewCounter
(
seqname
,
1
);
//插入新数
}
else
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
counterMapper
.
updateCounter
(
seqname
,
cnt
);
//计算器增加
}
catch
(
Exception
e
)
{
throw
(
new
RuleExecuteException
(
"主键生成异常"
,
e
));
}
finally
{
lock
.
unlock
();
}
}
else
counterMapper
.
updateCounter
(
seqname
);
//计算器增加
counterMapper
.
updateCounter
(
seqname
,
cnt
);
//计算器增加
return
cnt
;
}
...
...
@@ -62,14 +62,14 @@ public class CounterImplWithSpringTransaction implements CounterService {
cnt
=
0
;
tblCounterMapper
.
insertNewCounter
(
seqname
,
1
);
//插入新数
}
else
tblCounterMapper
.
updateCounter
(
seqname
);
//计算器增加
tblCounterMapper
.
updateCounter
(
seqname
,
cnt
);
//计算器增加
}
catch
(
Exception
e
)
{
throw
(
new
RuleExecuteException
(
"主键生成异常"
,
e
));
}
finally
{
lock
.
unlock
();
}
}
else
tblCounterMapper
.
updateCounter
(
seqname
);
//计算器增加
tblCounterMapper
.
updateCounter
(
seqname
,
cnt
);
//计算器增加
return
cnt
;
}
}
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/mapper/CounterMapper.java
View file @
42246fae
package
com
.
brilliance
.
mda
.
support
.
mybatis
.
count
.
mapper
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.ibatis.annotations.Param
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
CounterMapper
{
public
class
CounterMapper
{
final
String
FNAME
=
this
.
getClass
().
getName
();
...
...
@@ -19,29 +20,36 @@ public class CounterMapper{
public
SqlSessionTemplate
template
;
public
Integer
getCountValWithUpdate
(
@Param
(
"nam"
)
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".getCountValWithUpdate"
,
seqName
);
public
Integer
getCountValWithUpdate
(
@Param
(
"nam"
)
String
seqName
)
{
List
<
Integer
>
lst
=
template
.
selectList
(
FNAME
+
".getCountValWithUpdate"
,
seqName
);
if
(
lst
.
isEmpty
())
{
return
null
;
}
return
Collections
.
max
(
lst
);
}
public
int
insertNewCounter
(
@Param
(
"nam"
)
String
nam
,
@Param
(
"stp"
)
int
stp
){
public
int
insertNewCounter
(
@Param
(
"nam"
)
String
nam
,
@Param
(
"stp"
)
int
stp
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"nam"
,
nam
);
map
.
put
(
"start"
,
1
);
map
.
put
(
"start"
,
1
);
map
.
put
(
"stp"
,
stp
);
return
template
.
insert
(
FNAME
+
".insertNewCounter"
,
map
);
return
template
.
insert
(
FNAME
+
".insertNewCounter"
,
map
);
}
public
void
updateCounter
(
@Param
(
"nam"
)
String
seqName
){
template
.
selectOne
(
FNAME
+
".updateCounter"
,
seqName
);
public
void
updateCounter
(
@Param
(
"nam"
)
String
seqName
,
@Param
(
"val"
)
int
val
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"nam"
,
seqName
);
map
.
put
(
"val"
,
val
);
template
.
selectList
(
FNAME
+
".updateCounter"
,
map
);
}
public
int
seqNextval
(
String
seqName
)
{
return
template
.
selectOne
(
FNAME
+
".seqNextval"
,
seqName
);
return
template
.
selectOne
(
FNAME
+
".seqNextval"
,
seqName
);
}
public
int
dbCounter
(
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".dbCounter"
,
seqName
);
public
int
dbCounter
(
String
seqName
)
{
return
template
.
selectOne
(
FNAME
+
".dbCounter"
,
seqName
);
}
}
\ No newline at end of file
gjjs-bd-mybatis-support/src/main/java/com/brilliance/mda/support/mybatis/count/mapper/TblCounterMapper.java
View file @
42246fae
...
...
@@ -5,7 +5,9 @@ import org.mybatis.spring.SqlSessionTemplate;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -18,29 +20,35 @@ public class TblCounterMapper {
public
SqlSessionTemplate
template
;
public
Integer
getCountValWithUpdate
(
@Param
(
"typ"
)
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".getCountValWithUpdate"
,
seqName
);
public
Integer
getCountValWithUpdate
(
@Param
(
"typ"
)
String
seqName
)
{
List
<
Integer
>
lst
=
template
.
selectList
(
FNAME
+
".getCountValWithUpdate"
,
seqName
);
if
(
lst
.
isEmpty
())
{
return
null
;
}
return
Collections
.
max
(
lst
);
}
public
int
insertNewCounter
(
@Param
(
"typ"
)
String
typ
,
@Param
(
"stp"
)
int
stp
){
public
int
insertNewCounter
(
@Param
(
"typ"
)
String
typ
,
@Param
(
"stp"
)
int
stp
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"typ"
,
typ
);
map
.
put
(
"start"
,
1
);
map
.
put
(
"start"
,
1
);
map
.
put
(
"stp"
,
stp
);
return
template
.
insert
(
FNAME
+
".insertNewCounter"
,
map
);
return
template
.
insert
(
FNAME
+
".insertNewCounter"
,
map
);
}
public
void
updateCounter
(
@Param
(
"typ"
)
String
seqName
){
template
.
selectOne
(
FNAME
+
".updateCounter"
,
seqName
);
public
void
updateCounter
(
@Param
(
"typ"
)
String
seqName
,
@Param
(
"val"
)
int
val
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"typ"
,
seqName
);
map
.
put
(
"val"
,
val
);
template
.
selectList
(
FNAME
+
".updateCounter"
,
map
);
}
public
int
seqNextval
(
String
seqName
)
{
return
template
.
selectOne
(
FNAME
+
".seqNextval"
,
seqName
);
return
template
.
selectOne
(
FNAME
+
".seqNextval"
,
seqName
);
}
public
int
dbCounter
(
String
seqName
){
return
template
.
selectOne
(
FNAME
+
".dbCounter"
,
seqName
);
public
int
dbCounter
(
String
seqName
)
{
return
template
.
selectOne
(
FNAME
+
".dbCounter"
,
seqName
);
}
}
\ No newline at end of file
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