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
1404524c
Commit
1404524c
authored
Mar 11, 2026
by
Samir Sadykhov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix updateMask api, добавление строк в таблице doc_number_input
parent
4cdefc0b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
13 deletions
+121
-13
DocumentDAO.java
src/main/java/kz/arta/documentServices/dao/DocumentDAO.java
+116
-13
beans.xml
src/main/webapp/WEB-INF/beans.xml
+5
-0
No files found.
src/main/java/kz/arta/documentServices/dao/DocumentDAO.java
View file @
1404524c
...
...
@@ -8,36 +8,140 @@ import javax.naming.NamingException;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.ResultSet
;
public
class
DocumentDAO
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DocumentDAO
.
class
);
public
boolean
updateUserMask
(
String
documentID
,
String
numberTemplate
)
throws
SQLException
,
Naming
Exception
{
public
boolean
updateUserMask
(
String
documentID
,
String
numberTemplate
)
throws
Exception
{
Connection
con
=
null
;
try
{
con
=
ConnectionPool
.
getConnection
();
con
.
setAutoCommit
(
false
);
PreparedStatement
ps
=
con
.
prepareStatement
(
"UPDATE register_docs rd "
+
"JOIN object_folders of ON rd.docID = of.objectID "
+
"SET rd.user_mask = ? "
+
"WHERE of.folderid = ? "
+
"AND of.object_type = '1024'"
// 1. Получаем docID и formula
PreparedStatement
select
=
con
.
prepareStatement
(
"SELECT rg.docID, nt.formula "
+
"FROM register_docs rg "
+
"LEFT JOIN object_folders of ON rg.docID = of.objectID "
+
"LEFT JOIN registers r ON r.registerID = rg.registerID "
+
"LEFT JOIN number_templates nt ON nt.templateID = r.templateID "
+
"WHERE of.folderid = ? "
+
"AND of.object_type = '1024'"
);
ps
.
setString
(
1
,
numberTemplate
);
ps
.
setString
(
2
,
documentID
);
select
.
setString
(
1
,
documentID
);
int
updated
=
ps
.
executeUpdate
();
ResultSet
rs
=
select
.
executeQuery
();
return
updated
>
0
;
if
(!
rs
.
next
())
{
throw
new
Exception
(
"document not found"
);
}
String
docID
=
rs
.
getString
(
"docID"
);
String
formula
=
rs
.
getString
(
"formula"
);
if
(
formula
==
null
)
{
throw
new
Exception
(
"formula not found"
);
}
if
(
numberTemplate
==
null
||
numberTemplate
.
isEmpty
())
{
throw
new
Exception
(
"numberTemplate empty"
);
}
// 2. Обновляем user_mask
PreparedStatement
update
=
con
.
prepareStatement
(
"UPDATE register_docs SET user_mask = ? WHERE docID = ?"
);
update
.
setString
(
1
,
numberTemplate
);
update
.
setString
(
2
,
docID
);
update
.
executeUpdate
();
// 3. Удаляем старые значения
PreparedStatement
delete
=
con
.
prepareStatement
(
"DELETE FROM doc_number_input WHERE docID = ?"
);
delete
.
setString
(
1
,
docID
);
delete
.
executeUpdate
();
char
[]
formulaChars
=
formula
.
toCharArray
();
char
[]
templateChars
=
numberTemplate
.
toCharArray
();
if
(
templateChars
.
length
<
formulaChars
.
length
)
{
throw
new
Exception
(
"numberTemplate shorter than formula"
);
}
// защита от слишком больших формул
int
maxInsert
=
100
;
int
starCount
=
0
;
StringBuilder
sql
=
new
StringBuilder
(
"INSERT INTO doc_number_input(number, docID, value) VALUES "
);
for
(
int
i
=
0
;
i
<
formulaChars
.
length
;
i
++)
{
if
(
formulaChars
[
i
]
==
'*'
)
{
if
(
starCount
>=
maxInsert
)
{
throw
new
Exception
(
"too many mask characters in formula"
);
}
if
(
starCount
>
0
)
{
sql
.
append
(
","
);
}
sql
.
append
(
"(null, ?, ?)"
);
starCount
++;
}
}
// если звездочек нет
if
(
starCount
==
0
)
{
con
.
commit
();
return
true
;
}
PreparedStatement
insert
=
con
.
prepareStatement
(
sql
.
toString
());
int
paramIndex
=
1
;
for
(
int
i
=
0
;
i
<
formulaChars
.
length
;
i
++)
{
if
(
formulaChars
[
i
]
==
'*'
)
{
insert
.
setString
(
paramIndex
++,
docID
);
insert
.
setString
(
paramIndex
++,
String
.
valueOf
(
templateChars
[
i
]));
}
}
insert
.
executeUpdate
();
con
.
commit
();
return
true
;
}
catch
(
Exception
e
)
{
if
(
con
!=
null
)
{
con
.
rollback
();
}
throw
e
;
}
finally
{
if
(
con
!=
null
)
{
con
.
setAutoCommit
(
true
);
}
ConnectionPool
.
close
(
con
);
}
}
}
\ No newline at end of file
}
src/main/webapp/WEB-INF/beans.xml
0 → 100644
View file @
1404524c
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://xmlns.jcp.org/xml/ns/javaee"
version=
"1.1"
bean-discovery-mode=
"annotated"
>
</beans>
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