Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
documentServices
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
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Samir Sadykhov
documentServices
Commits
3660d6d3
Commit
3660d6d3
authored
Mar 11, 2026
by
Samir Sadykhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix добавление строк в таблицу doc_number_input, теперь группами
parent
1404524c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
68 deletions
+81
-68
DocumentDAO.java
src/main/java/kz/arta/documentServices/dao/DocumentDAO.java
+81
-68
No files found.
src/main/java/kz/arta/documentServices/dao/DocumentDAO.java
View file @
3660d6d3
...
@@ -9,13 +9,14 @@ import java.sql.Connection;
...
@@ -9,13 +9,14 @@ import java.sql.Connection;
import
java.sql.PreparedStatement
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.ResultSet
;
import
java.sql.ResultSet
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
DocumentDAO
{
public
class
DocumentDAO
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DocumentDAO
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DocumentDAO
.
class
);
public
boolean
updateUserMask
(
String
documentID
,
String
numberTemplate
)
throws
Exception
{
public
boolean
updateUserMask
(
String
documentID
,
String
numberTemplate
)
throws
Exception
{
Connection
con
=
null
;
Connection
con
=
null
;
try
{
try
{
...
@@ -23,125 +24,137 @@ public class DocumentDAO {
...
@@ -23,125 +24,137 @@ public class DocumentDAO {
con
=
ConnectionPool
.
getConnection
();
con
=
ConnectionPool
.
getConnection
();
con
.
setAutoCommit
(
false
);
con
.
setAutoCommit
(
false
);
// 1. Получаем docID и formula
String
docID
;
PreparedStatement
select
=
con
.
prepareStatement
(
String
formula
;
// Получаем docID и formula
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"SELECT rg.docID, nt.formula "
+
"SELECT rg.docID, nt.formula "
+
"FROM register_docs rg "
+
"FROM register_docs rg "
+
"LEFT JOIN object_folders of ON rg.docID = of.objectID "
+
"LEFT JOIN object_folders of ON rg.docID = of.objectID "
+
"LEFT JOIN registers r ON r.registerID = rg.registerID "
+
"LEFT JOIN registers r ON r.registerID = rg.registerID "
+
"LEFT JOIN number_templates nt ON nt.templateID = r.templateID "
+
"LEFT JOIN number_templates nt ON nt.templateID = r.templateID "
+
"WHERE of.folderid = ? "
+
"WHERE of.folderid = ? AND of.object_type = '1024'"
"AND of.object_type = '1024'"
))
{
);
select
.
setString
(
1
,
documentID
);
ps
.
setString
(
1
,
documentID
);
ResultSet
rs
=
select
.
executeQuery
();
try
(
ResultSet
rs
=
ps
.
executeQuery
())
{
if
(!
rs
.
next
())
{
if
(!
rs
.
next
())
{
throw
new
Exception
(
"d
ocument not found"
);
throw
new
Exception
(
"D
ocument not found"
);
}
}
String
docID
=
rs
.
getString
(
"docID"
);
docID
=
rs
.
getString
(
"docID"
);
String
formula
=
rs
.
getString
(
"formula"
);
formula
=
rs
.
getString
(
"formula"
);
}
}
if
(
formula
==
null
)
{
if
(
formula
==
null
||
numberTemplate
==
null
)
{
throw
new
Exception
(
"
formula not found
"
);
throw
new
Exception
(
"
Invalid template data
"
);
}
}
if
(
numberTemplate
==
null
||
numberTemplate
.
isEmpty
())
{
if
(
numberTemplate
.
length
()
<
formula
.
length
())
{
throw
new
Exception
(
"numberTemplate
empty
"
);
throw
new
Exception
(
"numberTemplate
shorter than formula
"
);
}
}
//
2. Обновляем
user_mask
//
update
user_mask
PreparedStatement
update
=
con
.
prepareStatement
(
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"UPDATE register_docs SET user_mask = ? WHERE docID = ?"
"UPDATE register_docs SET user_mask = ? WHERE docID = ?"
)
;
)
)
{
update
.
setString
(
1
,
numberTemplate
);
ps
.
setString
(
1
,
numberTemplate
);
update
.
setString
(
2
,
docID
);
ps
.
setString
(
2
,
docID
);
update
.
executeUpdate
();
ps
.
executeUpdate
();
}
//
3. Удаляем старые значения
//
delete old inputs
PreparedStatement
delete
=
con
.
prepareStatement
(
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
"DELETE FROM doc_number_input WHERE docID = ?"
"DELETE FROM doc_number_input WHERE docID = ?"
);
))
{
delete
.
setString
(
1
,
docID
);
delete
.
executeUpdate
();
char
[]
formulaChars
=
formula
.
toCharArray
();
ps
.
setString
(
1
,
docID
);
char
[]
templateChars
=
numberTemplate
.
toCharArray
();
ps
.
executeUpdate
();
if
(
templateChars
.
length
<
formulaChars
.
length
)
{
throw
new
Exception
(
"numberTemplate shorter than formula"
);
}
}
// защита от слишком больших формул
// парсим formula
int
maxInsert
=
100
;
int
starCount
=
0
;
StringBuilder
sql
=
new
StringBuilder
(
StringBuilder
sql
=
new
StringBuilder
(
"INSERT INTO doc_number_input(number, docID, value) VALUES "
"INSERT INTO doc_number_input(number, docID, value) VALUES "
);
);
for
(
int
i
=
0
;
i
<
formulaChars
.
length
;
i
++)
{
List
<
String
>
values
=
new
ArrayList
<>();
int
templateIndex
=
0
;
if
(
formulaChars
[
i
]
==
'*'
)
{
for
(
int
i
=
0
;
i
<
formula
.
length
();
i
++
)
{
if
(
starCount
>=
maxInsert
)
{
char
c
=
formula
.
charAt
(
i
);
throw
new
Exception
(
"too many mask characters in formula"
);
if
(
c
==
'*'
)
{
int
start
=
templateIndex
;
int
starLen
=
0
;
while
(
i
<
formula
.
length
()
&&
formula
.
charAt
(
i
)
==
'*'
)
{
starLen
++;
templateIndex
++;
i
++;
}
}
if
(
starCount
>
0
)
{
values
.
add
(
numberTemplate
.
substring
(
start
,
start
+
starLen
));
if
(
values
.
size
()
>
1
)
{
sql
.
append
(
","
);
sql
.
append
(
","
);
}
}
sql
.
append
(
"(null, ?, ?)"
);
sql
.
append
(
"(null, ?, ?)"
);
starCount
++;
i
--;
}
else
{
templateIndex
++;
}
}
}
}
// если звездочек нет
if
(!
values
.
isEmpty
())
{
if
(
starCount
==
0
)
{
con
.
commit
();
return
true
;
}
PreparedStatement
insert
=
con
.
prepareStatement
(
sql
.
toString
());
try
(
PreparedStatement
ps
=
con
.
prepareStatement
(
sql
.
toString
()))
{
int
paramI
ndex
=
1
;
int
i
ndex
=
1
;
for
(
int
i
=
0
;
i
<
formulaChars
.
length
;
i
++
)
{
for
(
String
v
:
values
)
{
if
(
formulaChars
[
i
]
==
'*'
)
{
ps
.
setString
(
index
++,
docID
);
ps
.
setString
(
index
++,
v
);
}
insert
.
setString
(
paramIndex
++,
docID
);
ps
.
executeUpdate
();
insert
.
setString
(
paramIndex
++,
String
.
valueOf
(
templateChars
[
i
]));
}
}
}
}
insert
.
executeUpdate
();
con
.
commit
();
con
.
commit
();
return
true
;
return
true
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
if
(
con
!=
null
)
{
if
(
con
!=
null
)
{
con
.
rollback
();
try
{
}
con
.
rollback
();
}
catch
(
Exception
ignored
)
{}
}
throw
e
;
throw
e
;
}
finally
{
}
finally
{
if
(
con
!=
null
)
{
con
.
setAutoCommit
(
true
);
}
ConnectionPool
.
close
(
con
);
if
(
con
!=
null
)
{
try
{
con
.
setAutoCommit
(
true
);
}
catch
(
Exception
ignored
)
{}
ConnectionPool
.
close
(
con
);
}
}
}
}
}
}
}
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