Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
8047500a
Commit
8047500a
authored
Oct 25, 2018
by
eddie.woo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify batch insert
parent
e84c5a33
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
3 deletions
+35
-3
CellTemplateConfigDao.java
...main/java/pwc/taxtech/atms/dao/CellTemplateConfigDao.java
+16
-0
CellTemplateDao.java
...i/src/main/java/pwc/taxtech/atms/dao/CellTemplateDao.java
+16
-1
TemplateGroupServiceImpl.java
...c/taxtech/atms/service/impl/TemplateGroupServiceImpl.java
+3
-2
No files found.
atms-api/src/main/java/pwc/taxtech/atms/dao/CellTemplateConfigDao.java
View file @
8047500a
package
pwc
.
taxtech
.
atms
.
dao
;
package
pwc
.
taxtech
.
atms
.
dao
;
import
org.apache.ibatis.session.ExecutorType
;
import
org.apache.ibatis.session.SqlSession
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.entity.CellTemplateConfig
;
import
pwc.taxtech.atms.entity.CellTemplateConfig
;
import
pwc.taxtech.atms.entity.CellTemplateConfigExample
;
import
pwc.taxtech.atms.entity.CellTemplateConfigExample
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
public
class
CellTemplateConfigDao
{
public
class
CellTemplateConfigDao
{
@Autowired
@Autowired
private
CellTemplateConfigMapper
mapper
;
private
CellTemplateConfigMapper
mapper
;
@Resource
(
name
=
"sqlSessionTemplate"
)
private
SqlSessionTemplate
sqlSessionTemplate
;
public
List
<
CellTemplateConfig
>
getByTemplateId
(
Long
id
)
{
public
List
<
CellTemplateConfig
>
getByTemplateId
(
Long
id
)
{
CellTemplateConfigExample
example
=
new
CellTemplateConfigExample
();
CellTemplateConfigExample
example
=
new
CellTemplateConfigExample
();
...
@@ -19,5 +25,15 @@ public class CellTemplateConfigDao {
...
@@ -19,5 +25,15 @@ public class CellTemplateConfigDao {
return
mapper
.
selectByExample
(
example
);
return
mapper
.
selectByExample
(
example
);
}
}
public
void
batchInsert
(
List
<
CellTemplateConfig
>
list
)
{
long
start
=
System
.
currentTimeMillis
();
SqlSession
sqlSession
=
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
ExecutorType
.
BATCH
);
for
(
CellTemplateConfig
cellTemplate
:
list
)
{
mapper
.
insertSelective
(
cellTemplate
);
}
sqlSession
.
commit
();
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"---------------batch insert: count:"
+
list
.
size
()
+
" time: "
+
(
start
-
end
)
+
"---------------"
);
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/dao/CellTemplateDao.java
View file @
8047500a
package
pwc
.
taxtech
.
atms
.
dao
;
package
pwc
.
taxtech
.
atms
.
dao
;
import
org.apache.ibatis.session.ExecutorType
;
import
org.apache.ibatis.session.SqlSession
;
import
org.mybatis.spring.SqlSessionTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
pwc.taxtech.atms.entity.CellTemplate
;
import
pwc.taxtech.atms.entity.CellTemplate
;
import
pwc.taxtech.atms.entity.CellTemplateExample
;
import
pwc.taxtech.atms.entity.CellTemplateExample
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
@Service
@Service
public
class
CellTemplateDao
{
public
class
CellTemplateDao
{
@Autowired
@Autowired
private
CellTemplateMapper
mapper
;
private
CellTemplateMapper
mapper
;
@Resource
(
name
=
"sqlSessionTemplate"
)
private
SqlSessionTemplate
sqlSessionTemplate
;
public
List
<
CellTemplate
>
getByTemplateId
(
Long
id
)
{
public
List
<
CellTemplate
>
getByTemplateId
(
Long
id
)
{
CellTemplateExample
example
=
new
CellTemplateExample
();
CellTemplateExample
example
=
new
CellTemplateExample
();
...
@@ -19,5 +25,14 @@ public class CellTemplateDao {
...
@@ -19,5 +25,14 @@ public class CellTemplateDao {
return
mapper
.
selectByExample
(
example
);
return
mapper
.
selectByExample
(
example
);
}
}
public
void
batchInsert
(
List
<
CellTemplate
>
list
)
{
long
start
=
System
.
currentTimeMillis
();
SqlSession
sqlSession
=
sqlSessionTemplate
.
getSqlSessionFactory
().
openSession
(
ExecutorType
.
BATCH
);
for
(
CellTemplate
cellTemplate
:
list
)
{
mapper
.
insertSelective
(
cellTemplate
);
}
sqlSession
.
commit
();
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"---------------batch insert: count:"
+
list
.
size
()
+
" time: "
+
(
start
-
end
)
+
"---------------"
);
}
}
}
atms-api/src/main/java/pwc/taxtech/atms/service/impl/TemplateGroupServiceImpl.java
View file @
8047500a
...
@@ -371,9 +371,10 @@ public class TemplateGroupServiceImpl extends AbstractService {
...
@@ -371,9 +371,10 @@ public class TemplateGroupServiceImpl extends AbstractService {
}
}
}
}
List
<
List
<
CellTemplate
>>
tmpList
=
CommonUtils
.
subListWithLen
(
cellTemplateList
,
CommonUtils
.
BATCH_NUM
);
List
<
List
<
CellTemplate
>>
tmpList
=
CommonUtils
.
subListWithLen
(
cellTemplateList
,
CommonUtils
.
BATCH_NUM
);
tmpList
.
forEach
(
list
->
cellTemplateMapper
.
batchInsert2
(
list
));
// tmpList.forEach(list -> cellTemplateMapper.batchInsert2(list));
tmpList
.
forEach
(
list
->
cellTemplateDao
.
batchInsert
(
list
));
//todo 批量插入优化
List
<
List
<
CellTemplateConfig
>>
tmpConfigList
=
CommonUtils
.
subListWithLen
(
cellTemplateConfigList
,
CommonUtils
.
BATCH_NUM
);
List
<
List
<
CellTemplateConfig
>>
tmpConfigList
=
CommonUtils
.
subListWithLen
(
cellTemplateConfigList
,
CommonUtils
.
BATCH_NUM
);
tmpConfigList
.
forEach
(
list
->
cellTemplateConfig
Mapper
.
batchInsert
(
list
));
tmpConfigList
.
forEach
(
list
->
cellTemplateConfig
Dao
.
batchInsert
(
list
));
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"importTemplateExcelFile error."
,
e
);
logger
.
error
(
"importTemplateExcelFile error."
,
e
);
...
...
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