Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dsk-operate-sys-cscec
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
fulixin
dsk-operate-sys-cscec
Commits
d0051f1b
Commit
d0051f1b
authored
Feb 23, 2024
by
chenyuefang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
成本汇总导入修改
parent
7d0f01ac
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
91 deletions
+158
-91
CbSummaryController.java
...in/java/com/dsk/cscec/controller/CbSummaryController.java
+1
-1
CbSummaryCostAccountImportListener.java
...sk/cscec/listener/CbSummaryCostAccountImportListener.java
+7
-1
CbSummaryProjectImportListener.java
...om/dsk/cscec/listener/CbSummaryProjectImportListener.java
+14
-7
CbProjectFileMapper.java
...c/main/java/com/dsk/cscec/mapper/CbProjectFileMapper.java
+1
-0
CbSummaryService.java
...src/main/java/com/dsk/cscec/service/CbSummaryService.java
+1
-2
CbSummaryServiceImpl.java
...java/com/dsk/cscec/service/impl/CbSummaryServiceImpl.java
+125
-79
CbProjectFileMapper.xml
...i/src/main/resources/mapper/cscec/CbProjectFileMapper.xml
+9
-1
No files found.
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/controller/CbSummaryController.java
View file @
d0051f1b
...
@@ -134,7 +134,7 @@ public class CbSummaryController extends BaseController {
...
@@ -134,7 +134,7 @@ public class CbSummaryController extends BaseController {
*/
*/
@PostMapping
(
"/analysisData"
)
@PostMapping
(
"/analysisData"
)
public
void
analysisData
(
Long
projectId
){
public
void
analysisData
(
Long
projectId
){
cbSummaryService
.
importCb
Project
(
projectId
);
cbSummaryService
.
importCb
Summary
(
projectId
);
}
}
}
}
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/listener/CbSummaryCostAccountImportListener.java
View file @
d0051f1b
...
@@ -53,6 +53,12 @@ public class CbSummaryCostAccountImportListener extends AnalysisEventListener<Cb
...
@@ -53,6 +53,12 @@ public class CbSummaryCostAccountImportListener extends AnalysisEventListener<Cb
failureMsg
.
append
(
"<br/>"
).
append
(
"第"
+
sort
+
"条数据序号为空"
);
failureMsg
.
append
(
"<br/>"
).
append
(
"第"
+
sort
+
"条数据序号为空"
);
return
;
return
;
}
}
//成本科目不能为空
if
(
StringUtil
.
isBlank
(
importVo
.
getCbName
()))
{
failureNum
++;
failureMsg
.
append
(
"<br/>"
).
append
(
"第"
+
sort
+
"条数据成本科目为空"
);
return
;
}
//父级数据处理
//父级数据处理
if
(
sort
==
1
)
{
if
(
sort
==
1
)
{
...
@@ -74,7 +80,7 @@ public class CbSummaryCostAccountImportListener extends AnalysisEventListener<Cb
...
@@ -74,7 +80,7 @@ public class CbSummaryCostAccountImportListener extends AnalysisEventListener<Cb
@Override
@Override
public
String
getAnalysis
()
{
public
String
getAnalysis
()
{
if
(
failureNum
>
0
)
{
if
(
failureNum
>
0
)
{
failureMsg
.
insert
(
0
,
"
失败原因:
共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
failureMsg
.
insert
(
0
,
"共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
throw
new
ServiceException
(
failureMsg
.
toString
());
throw
new
ServiceException
(
failureMsg
.
toString
());
}
else
{
}
else
{
successMsg
.
insert
(
0
,
"成本科目汇总数据已全部解析成功!共 "
+
getList
().
size
()
+
" 条"
);
successMsg
.
insert
(
0
,
"成本科目汇总数据已全部解析成功!共 "
+
getList
().
size
()
+
" 条"
);
...
...
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/listener/CbSummaryProjectImportListener.java
View file @
d0051f1b
package
com
.
dsk
.
cscec
.
listener
;
package
com
.
dsk
.
cscec
.
listener
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.dsk.common.excel.ExcelListener
;
import
com.dsk.common.excel.ExcelListener
;
...
@@ -42,8 +43,12 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
...
@@ -42,8 +43,12 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
@Override
@Override
public
void
invoke
(
CbSummaryProjectImportVo
importVo
,
AnalysisContext
context
)
{
public
void
invoke
(
CbSummaryProjectImportVo
importVo
,
AnalysisContext
context
)
{
//第一个序号不能为空? todo
//名称不能为空
if
(
StringUtil
.
isBlank
(
importVo
.
getCbName
()))
{
failureNum
++;
failureMsg
.
append
(
"<br/>"
).
append
(
"第"
+
sort
+
"条数据名称为空"
);
return
;
}
//添加父级数据
//添加父级数据
if
(
sort
==
0
)
{
if
(
sort
==
0
)
{
CbSummaryProjectImportVo
firstVo
=
new
CbSummaryProjectImportVo
();
CbSummaryProjectImportVo
firstVo
=
new
CbSummaryProjectImportVo
();
...
@@ -63,8 +68,12 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
...
@@ -63,8 +68,12 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
//按sort倒序取number不为空的最大level
//按sort倒序取number不为空的最大level
Object
[]
objects
=
resultList
.
stream
().
sorted
(
Comparator
.
comparingInt
(
CbSummaryProjectImportVo:
:
getSort
).
reversed
())
Object
[]
objects
=
resultList
.
stream
().
sorted
(
Comparator
.
comparingInt
(
CbSummaryProjectImportVo:
:
getSort
).
reversed
())
.
filter
(
vo
->
StringUtil
.
isNotBlank
(
vo
.
getNumber
())).
limit
(
1
).
map
(
CbSummaryProjectImportVo:
:
getLevel
).
toArray
();
.
filter
(
vo
->
StringUtil
.
isNotBlank
(
vo
.
getNumber
())).
limit
(
1
).
map
(
CbSummaryProjectImportVo:
:
getLevel
).
toArray
();
//数据序号错误 todo
//数据序号错误
if
(
ObjectUtil
.
isEmpty
(
objects
))
{
failureNum
++;
failureMsg
.
append
(
"<br/>"
).
append
(
"第"
+
sort
+
"条数据序号错误"
);
return
;
}
Integer
lastLevel
=
(
Integer
)
objects
[
0
];
Integer
lastLevel
=
(
Integer
)
objects
[
0
];
importVo
.
setLevel
(
lastLevel
+
1
);
importVo
.
setLevel
(
lastLevel
+
1
);
...
@@ -75,8 +84,6 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
...
@@ -75,8 +84,6 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
}
}
// failureNum++;
// failureMsg.append("<br/>").append(failureNum);
resultList
.
add
(
importVo
);
resultList
.
add
(
importVo
);
}
}
...
@@ -93,7 +100,7 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
...
@@ -93,7 +100,7 @@ public class CbSummaryProjectImportListener extends AnalysisEventListener<CbSumm
@Override
@Override
public
String
getAnalysis
()
{
public
String
getAnalysis
()
{
if
(
failureNum
>
0
)
{
if
(
failureNum
>
0
)
{
failureMsg
.
insert
(
0
,
"
失败原因:
共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
failureMsg
.
insert
(
0
,
"共 "
+
failureNum
+
" 条数据格式不正确,错误如下:"
);
throw
new
ServiceException
(
failureMsg
.
toString
());
throw
new
ServiceException
(
failureMsg
.
toString
());
}
else
{
}
else
{
successMsg
.
insert
(
0
,
"项目汇总数据已全部解析成功!共 "
+
getList
().
size
()
+
" 条"
);
successMsg
.
insert
(
0
,
"项目汇总数据已全部解析成功!共 "
+
getList
().
size
()
+
" 条"
);
...
...
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/mapper/CbProjectFileMapper.java
View file @
d0051f1b
...
@@ -16,5 +16,6 @@ public interface CbProjectFileMapper extends BaseMapper<CbProjectFile> {
...
@@ -16,5 +16,6 @@ public interface CbProjectFileMapper extends BaseMapper<CbProjectFile> {
List
<
CbProjectFile
>
selectAnalysisList
(
@Param
(
"projectId"
)
Long
projectId
,
@Param
(
"cbType"
)
Integer
cbType
,
@Param
(
"cbStage"
)
Integer
cbStage
);
List
<
CbProjectFile
>
selectAnalysisList
(
@Param
(
"projectId"
)
Long
projectId
,
@Param
(
"cbType"
)
Integer
cbType
,
@Param
(
"cbStage"
)
Integer
cbStage
);
int
removeById
(
@Param
(
"id"
)
Long
id
);
}
}
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/service/CbSummaryService.java
View file @
d0051f1b
...
@@ -2,7 +2,6 @@ package com.dsk.cscec.service;
...
@@ -2,7 +2,6 @@ package com.dsk.cscec.service;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.dsk.common.core.domain.R
;
import
com.dsk.common.core.domain.R
;
import
com.dsk.cscec.domain.CbProjectFile
;
import
com.dsk.cscec.domain.CbSummary
;
import
com.dsk.cscec.domain.CbSummary
;
import
com.dsk.cscec.domain.bo.CbSummaryActualBo
;
import
com.dsk.cscec.domain.bo.CbSummaryActualBo
;
import
com.dsk.cscec.domain.bo.CbSummaryActualListBo
;
import
com.dsk.cscec.domain.bo.CbSummaryActualListBo
;
...
@@ -26,7 +25,7 @@ public interface CbSummaryService extends IService<CbSummary> {
...
@@ -26,7 +25,7 @@ public interface CbSummaryService extends IService<CbSummary> {
* 项目汇总导入
* 项目汇总导入
* @param projectId
* @param projectId
*/
*/
void
importCb
Project
(
Long
projectId
);
void
importCb
Summary
(
Long
projectId
);
/**
/**
* 获取一级名称/成本科目列表
* 获取一级名称/成本科目列表
...
...
dsk-module/dsk-biz-api/src/main/java/com/dsk/cscec/service/impl/CbSummaryServiceImpl.java
View file @
d0051f1b
...
@@ -28,9 +28,14 @@ import com.dsk.system.service.ISysOssService;
...
@@ -28,9 +28,14 @@ import com.dsk.system.service.ISysOssService;
import
jodd.util.StringUtil
;
import
jodd.util.StringUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.support.TransactionTemplate
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
java.util.*
;
...
@@ -59,43 +64,52 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
...
@@ -59,43 +64,52 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
@Autowired
@Autowired
private
ISysOssService
ossService
;
private
ISysOssService
ossService
;
@Override
@Autowired
public
void
importCbProject
(
Long
projectId
)
{
private
TransactionTemplate
transactionTemplate
;
//获取del_flag为1的文件,若存在则根据fileId删除相关基础数据,并修改文件del_flag为2 todo
@Async
@Override
public
void
importCbSummary
(
Long
projectId
)
{
//获取文件信息
//获取待解析和待删除文件信息
List
<
CbProjectFile
>
cbProjectFiles
=
cbProjectFileMapper
.
selectList
(
new
LambdaQueryWrapper
<
CbProjectFile
>()
List
<
CbProjectFile
>
cbProjectFiles
=
cbProjectFileMapper
.
selectAnalysisList
(
projectId
,
CbProjectConstants
.
CB_TYPE_SUMMARY
,
null
);
.
eq
(
CbProjectFile:
:
getProjectId
,
projectId
)
// .eq(CbProjectFile::getCbStage, cbStage)
.
eq
(
CbProjectFile:
:
getCbType
,
CbProjectConstants
.
CB_TYPE_SUMMARY
)
.
eq
(
CbProjectFile:
:
getFileParseStatus
,
CbProjectConstants
.
PROJECT_FILE_STATUS_PREPARING
)
);
//解析数据
//解析数据
cbProjectFiles
.
forEach
(
cbProjectFile
->
{
cbProjectFiles
.
forEach
(
cbProjectFile
->
{
if
(
cbProjectFile
.
getDelFlag
()
==
1
)
{
if
(
cbProjectFile
.
getFileName
().
contains
(
"项目"
))
{
//根据fileId删除相关基础数据,并删除文件
saveCbSummaryProject
(
projectId
,
cbProjectFile
);
baseMapper
.
delete
(
new
LambdaQueryWrapper
<
CbSummary
>().
eq
(
CbSummary:
:
getCbProjectFileId
,
cbProjectFile
.
getId
()));
}
else
if
(
cbProjectFile
.
getFileName
().
contains
(
"成本科目"
))
{
cbProjectFileMapper
.
removeById
(
cbProjectFile
.
getId
());
saveCbSummaryCostAccount
(
projectId
,
cbProjectFile
);
}
else
{
}
else
{
//修改文件状态
try
{
cbProjectFile
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_FAIL
);
if
(
cbProjectFile
.
getFileName
().
contains
(
"项目"
))
{
cbProjectFile
.
setFailRemark
(
"失败原因:文件名错误"
);
saveCbSummaryProject
(
projectId
,
cbProjectFile
);
cbProjectFileMapper
.
updateById
(
cbProjectFile
);
}
else
if
(
cbProjectFile
.
getFileName
().
contains
(
"成本科目"
))
{
saveCbSummaryCostAccount
(
projectId
,
cbProjectFile
);
}
else
{
throw
new
ServiceException
(
"文件名错误"
);
}
}
catch
(
Exception
e
)
{
//修改文件状态
cbProjectFile
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_FAIL
);
cbProjectFile
.
setFailRemark
(
"失败原因:"
+
e
.
getMessage
());
cbProjectFileMapper
.
updateById
(
cbProjectFile
);
}
}
}
});
});
}
}
/**
/**
* 成本汇总-项目汇总导入
* 成本汇总-项目汇总导入
*
* @param projectId
* @param projectId
* @param file
* @param file
* @return
* @return
*/
*/
boolean
saveCbSummaryProject
(
Long
projectId
,
CbProjectFile
file
){
boolean
saveCbSummaryProject
(
Long
projectId
,
CbProjectFile
file
)
{
//修改文件状态为解析中
//修改文件状态为解析中
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSING
);
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSING
);
cbProjectFileMapper
.
updateById
(
file
);
cbProjectFileMapper
.
updateById
(
file
);
...
@@ -103,54 +117,72 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
...
@@ -103,54 +117,72 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
//文件下载
//文件下载
InputStream
inputStream
=
ossService
.
downFileIO
(
file
.
getFileOssId
());
InputStream
inputStream
=
ossService
.
downFileIO
(
file
.
getFileOssId
());
if
(
ObjectUtil
.
isNull
(
inputStream
))
{
if
(
ObjectUtil
.
isNull
(
inputStream
))
{
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_FAIL
);
throw
new
ServiceException
(
"文件数据不存在!"
);
file
.
setFailRemark
(
"失败原因:文件数据不存在"
);
cbProjectFileMapper
.
updateById
(
file
);
return
false
;
}
}
//解析数据
//解析数据
ExcelResult
<
CbSummaryProjectImportVo
>
importVoExcelResult
=
ExcelUtil
.
importExcel
(
inputStream
,
CbSummaryProjectImportVo
.
class
,
new
CbSummaryProjectImportListener
(
projectId
,
file
.
getId
()));
ExcelResult
<
CbSummaryProjectImportVo
>
importVoExcelResult
=
ExcelUtil
.
importExcel
(
inputStream
,
CbSummaryProjectImportVo
.
class
,
new
CbSummaryProjectImportListener
(
projectId
,
file
.
getId
()));
log
.
info
(
importVoExcelResult
.
getAnalysis
());
log
.
info
(
importVoExcelResult
.
getAnalysis
());
if
(
CollectionUtil
.
isEmpty
(
importVoExcelResult
.
getList
()))
{
throw
new
ServiceException
(
"文件中不存在待导入数据!"
);
}
List
<
CbSummary
>
addList
=
BeanUtil
.
copyToList
(
importVoExcelResult
.
getList
(),
CbSummary
.
class
);
List
<
CbSummary
>
addList
=
BeanUtil
.
copyToList
(
importVoExcelResult
.
getList
(),
CbSummary
.
class
);
this
.
saveBatch
(
addList
);
//处理父级id
transactionTemplate
.
execute
(
status
->
{
List
<
CbSummary
>
cbSummaryList
=
baseMapper
.
selectList
(
try
{
new
LambdaQueryWrapper
<
CbSummary
>()
boolean
flag
=
this
.
saveBatch
(
addList
);
.
eq
(
CbSummary:
:
getProjectId
,
projectId
)
if
(!
flag
)
{
.
eq
(
CbSummary:
:
getCbType
,
1
)
throw
new
ServiceException
(
"导入数据失败"
);
.
orderByAsc
(
CbSummary:
:
getSort
)
}
);
for
(
CbSummary
cbSummary:
cbSummaryList
)
{
//处理父级id
if
(
cbSummary
.
getLevel
()==
0
){
List
<
CbSummary
>
cbSummaryList
=
baseMapper
.
selectList
(
continue
;
new
LambdaQueryWrapper
<
CbSummary
>()
.
eq
(
CbSummary:
:
getProjectId
,
projectId
)
.
eq
(
CbSummary:
:
getCbType
,
1
)
.
orderByAsc
(
CbSummary:
:
getSort
)
);
for
(
CbSummary
cbSummary
:
cbSummaryList
)
{
if
(
cbSummary
.
getLevel
()
==
0
)
{
continue
;
}
//获取父级id
Integer
parentLevel
=
cbSummary
.
getLevel
()
-
1
;
CbSummary
parent
=
cbSummaryList
.
stream
().
filter
(
summary
->
summary
.
getSort
()
<
cbSummary
.
getSort
()
&&
summary
.
getLevel
()
==
parentLevel
)
.
max
(
Comparator
.
comparing
(
CbSummary:
:
getSort
)).
get
();
cbSummary
.
setParentId
(
parent
.
getId
());
}
flag
=
this
.
updateBatchById
(
cbSummaryList
);
if
(!
flag
)
{
throw
new
ServiceException
(
"更新数据失败"
);
}
//修改文件状态为解析成功
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_SUCCESS
);
flag
=
cbProjectFileMapper
.
updateById
(
file
)
>
0
;
if
(!
flag
)
{
throw
new
ServiceException
(
"更新文件状态失败"
);
}
}
catch
(
Exception
e
)
{
status
.
setRollbackOnly
();
throw
e
;
}
}
//获取父级id
return
Boolean
.
TRUE
;
Integer
parentLevel
=
cbSummary
.
getLevel
()-
1
;
});
CbSummary
parent
=
cbSummaryList
.
stream
().
filter
(
summary
->
summary
.
getSort
()<
cbSummary
.
getSort
()&&
summary
.
getLevel
()==
parentLevel
)
.
max
(
Comparator
.
comparing
(
CbSummary:
:
getSort
)).
get
();
cbSummary
.
setParentId
(
parent
.
getId
());
}
this
.
updateBatchById
(
cbSummaryList
);
//修改文件状态为解析成功
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_SUCCESS
);
cbProjectFileMapper
.
updateById
(
file
);
return
true
;
return
true
;
}
}
/**
/**
* 成本汇总-成本科目汇总导入
* 成本汇总-成本科目汇总导入
*
* @param projectId
* @param projectId
* @param file
* @param file
* @return
* @return
*/
*/
boolean
saveCbSummaryCostAccount
(
Long
projectId
,
CbProjectFile
file
)
{
boolean
saveCbSummaryCostAccount
(
Long
projectId
,
CbProjectFile
file
)
{
//修改文件状态为解析中
//修改文件状态为解析中
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSING
);
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSING
);
cbProjectFileMapper
.
updateById
(
file
);
cbProjectFileMapper
.
updateById
(
file
);
...
@@ -158,43 +190,57 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
...
@@ -158,43 +190,57 @@ public class CbSummaryServiceImpl extends ServiceImpl<CbSummaryMapper, CbSummary
//文件下载
//文件下载
InputStream
inputStream
=
ossService
.
downFileIO
(
file
.
getFileOssId
());
InputStream
inputStream
=
ossService
.
downFileIO
(
file
.
getFileOssId
());
if
(
ObjectUtil
.
isNull
(
inputStream
))
{
if
(
ObjectUtil
.
isNull
(
inputStream
))
{
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_FAIL
);
throw
new
ServiceException
(
"文件数据不存在"
);
file
.
setFailRemark
(
"失败原因:文件数据不存在"
);
cbProjectFileMapper
.
updateById
(
file
);
return
false
;
}
}
//解析数据
//解析数据
ExcelResult
<
CbSummaryCostAccountImportVo
>
importVoExcelResult
=
ExcelUtil
.
importExcel
(
inputStream
,
CbSummaryCostAccountImportVo
.
class
,
new
CbSummaryCostAccountImportListener
(
projectId
,
file
.
getId
()));
ExcelResult
<
CbSummaryCostAccountImportVo
>
importVoExcelResult
=
ExcelUtil
.
importExcel
(
inputStream
,
CbSummaryCostAccountImportVo
.
class
,
new
CbSummaryCostAccountImportListener
(
projectId
,
file
.
getId
()));
log
.
info
(
importVoExcelResult
.
getAnalysis
());
log
.
info
(
importVoExcelResult
.
getAnalysis
());
if
(
CollectionUtil
.
isEmpty
(
importVoExcelResult
.
getList
()))
{
throw
new
ServiceException
(
"文件中不存在待导入数据!"
);
}
List
<
CbSummary
>
addList
=
BeanUtil
.
copyToList
(
importVoExcelResult
.
getList
(),
CbSummary
.
class
);
List
<
CbSummary
>
addList
=
BeanUtil
.
copyToList
(
importVoExcelResult
.
getList
(),
CbSummary
.
class
);
this
.
saveBatch
(
addList
);
//处理父级id
transactionTemplate
.
execute
(
status
->
{
List
<
CbSummary
>
cbSummaryList
=
baseMapper
.
selectList
(
try
{
new
LambdaQueryWrapper
<
CbSummary
>()
boolean
flag
=
this
.
saveBatch
(
addList
);
.
eq
(
CbSummary:
:
getProjectId
,
projectId
)
if
(!
flag
)
{
.
eq
(
CbSummary:
:
getCbType
,
1
)
throw
new
ServiceException
(
"导入数据失败"
);
.
orderByAsc
(
CbSummary:
:
getSort
)
}
);
for
(
CbSummary
cbSummary:
cbSummaryList
)
{
//处理父级id
if
(
cbSummary
.
getLevel
()==
0
){
List
<
CbSummary
>
cbSummaryList
=
baseMapper
.
selectList
(
continue
;
new
LambdaQueryWrapper
<
CbSummary
>()
.
eq
(
CbSummary:
:
getProjectId
,
projectId
)
.
eq
(
CbSummary:
:
getCbType
,
1
)
.
orderByAsc
(
CbSummary:
:
getSort
)
);
for
(
CbSummary
cbSummary
:
cbSummaryList
)
{
if
(
cbSummary
.
getLevel
()
==
0
)
{
continue
;
}
//获取父级id
Integer
parentLevel
=
cbSummary
.
getLevel
()
-
1
;
CbSummary
parent
=
cbSummaryList
.
stream
().
filter
(
summary
->
summary
.
getSort
()
<
cbSummary
.
getSort
()
&&
summary
.
getLevel
()
==
parentLevel
)
.
max
(
Comparator
.
comparing
(
CbSummary:
:
getSort
)).
get
();
cbSummary
.
setParentId
(
parent
.
getId
());
}
this
.
updateBatchById
(
cbSummaryList
);
//修改文件状态为解析成功
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_SUCCESS
);
flag
=
cbProjectFileMapper
.
updateById
(
file
)
>
0
;
if
(!
flag
)
{
throw
new
ServiceException
(
"更新文件状态失败"
);
}
}
catch
(
Exception
e
)
{
status
.
setRollbackOnly
();
throw
e
;
}
}
//获取父级id
return
Boolean
.
TRUE
;
Integer
parentLevel
=
cbSummary
.
getLevel
()-
1
;
});
CbSummary
parent
=
cbSummaryList
.
stream
().
filter
(
summary
->
summary
.
getSort
()<
cbSummary
.
getSort
()&&
summary
.
getLevel
()==
parentLevel
)
.
max
(
Comparator
.
comparing
(
CbSummary:
:
getSort
)).
get
();
cbSummary
.
setParentId
(
parent
.
getId
());
}
this
.
updateBatchById
(
cbSummaryList
);
//修改文件状态为解析成功
file
.
setFileParseStatus
(
CbProjectConstants
.
PROJECT_FILE_STATUS_PARSE_SUCCESS
);
cbProjectFileMapper
.
updateById
(
file
);
return
true
;
return
true
;
}
}
...
...
dsk-module/dsk-biz-api/src/main/resources/mapper/cscec/CbProjectFileMapper.xml
View file @
d0051f1b
...
@@ -7,6 +7,14 @@
...
@@ -7,6 +7,14 @@
del_flag, create_by, create_time, update_by, update_time
del_flag, create_by, create_time, update_by, update_time
FROM cb_project_file
FROM cb_project_file
WHERE ((del_flag = 0 and file_parse_status in (1,3)) or del_flag = 1)
WHERE ((del_flag = 0 and file_parse_status in (1,3)) or del_flag = 1)
and project_id=#{projectId} and cb_stage =#{cbStage} and cb_type = #{cbType}
and project_id=#{projectId}
<if
test=
"cbStage != null"
>
and cb_stage =#{cbStage}
</if>
and cb_type = #{cbType}
</select>
</select>
<update
id=
"removeById"
>
UPDATE cb_project_file SET del_flag=2 WHERE id=#{id}
</update>
</mapper>
</mapper>
\ 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