Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
manager
Project
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
reyun
manager
Commits
bd6da457
Commit
bd6da457
authored
Jul 22, 2021
by
kangxiaoshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DMP 收入导入
parent
c2f4df04
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
128 additions
and
106 deletions
+128
-106
ContractRepository.java
src/main/java/common/repository/ContractRepository.java
+6
-3
DmpIncomeServiceImpl.java
src/main/java/common/service/impl/DmpIncomeServiceImpl.java
+122
-103
No files found.
src/main/java/common/repository/ContractRepository.java
View file @
bd6da457
...
...
@@ -140,14 +140,17 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
List
<
Long
>
findRelationContractBySideAgre
();
@Query
(
value
=
"SELECT * from contract where contract_code = ?1 UNION SELECT * from contract where relation_code = ?1 and create_time <= ?2 and id<> ?3 and contract_type = '2'"
,
nativeQuery
=
true
)
List
<
Contract
>
findByCreateTimeAndCodeNotOwn
(
String
contractCode
,
String
createTime
,
Long
id
);
List
<
Contract
>
findByCreateTimeAndCodeNotOwn
(
String
contractCode
,
String
createTime
,
Long
id
);
@Query
(
value
=
"select * from contract where next_signed_contract_code=?1 limit 1 "
,
nativeQuery
=
true
)
@Query
(
value
=
"select * from contract where next_signed_contract_code=?1 limit 1 "
,
nativeQuery
=
true
)
Contract
findByNextSignedContractCode
(
String
contractCode
);
@Query
(
value
=
"select * from contract where platform=?1 and share_sign = ?2 "
,
nativeQuery
=
true
)
@Query
(
value
=
"select * from contract where platform=?1 and share_sign = ?2 "
,
nativeQuery
=
true
)
List
<
Contract
>
findByPlatformAndShareSign
(
String
platform
,
int
share_sign
);
@Query
(
value
=
"select * from contract where contract_code = ?1 and status != 'del'"
,
nativeQuery
=
true
)
Contract
findByCodeAndNotDel
(
String
contractCode
);
@Query
(
value
=
"select id from contract where contract_code = ?1 "
,
nativeQuery
=
true
)
List
<
Long
>
findIdByCode
(
String
relationCode
);
}
src/main/java/common/service/impl/DmpIncomeServiceImpl.java
View file @
bd6da457
...
...
@@ -208,103 +208,6 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return
ResultModel
.
OK
();
}
private
int
checkSheetTitle
(
Workbook
workbook
,
String
sheetTitle
,
String
code
)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
0
);
int
titleLength
=
sheetTitle
.
split
(
"\t"
).
length
;
StringBuffer
titleUp
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
titleLength
;
i
++)
{
if
(
i
>
0
)
titleUp
.
append
(
code
);
titleUp
.
append
(
row
.
getCell
(
i
));
}
if
(!
titleUp
.
toString
().
equals
(
sheetTitle
))
{
return
-
1
;
}
return
titleLength
;
}
private
Workbook
getWorkbook
(
MultipartFile
excelfile
)
{
InputStream
stream
=
null
;
Workbook
workbook
=
null
;
try
{
stream
=
excelfile
.
getInputStream
();
workbook
=
WorkbookFactory
.
create
(
stream
);
}
catch
(
Exception
e
)
{
logger
.
error
(
""
,
e
);
}
finally
{
if
(
stream
!=
null
)
{
try
{
stream
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
""
,
e
);
}
}
}
return
workbook
;
}
private
DmpIncome
saveDmpIncomeItem
(
Sheet
sheet
,
int
index
,
User
user
)
{
//logger.info(" line index {}", index);
Row
rowItem
=
sheet
.
getRow
(
index
);
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome
income
=
new
DmpIncome
();
income
.
setContractCode
(
getCellStringValue
(
rowItem
,
0
));
income
.
setIncomeMonth
(
getCellStringValue
(
rowItem
,
1
));
income
.
setPeriod
(
getCellStringValue
(
rowItem
,
2
));
income
.
setSysSettlement
(
getCellStringValue
(
rowItem
,
3
));
income
.
setMonthSettlement
(
getCellStringValue
(
rowItem
,
4
));
income
.
setTaxRate
(
getCellStringValue
(
rowItem
,
5
));
income
.
setConfirmSettlement
(
getCellStringValue
(
rowItem
,
6
));
// 时间 上传人
income
.
setCreateTime
(
new
Date
());
income
.
setUploadUser
(
user
.
getName
());
if
(
StringUtils
.
isEmpty
(
income
.
getContractCode
()))
{
return
null
;
}
DmpIncome
one
=
dmpIncomeRepository
.
findByCodeMonth
(
income
.
getContractCode
(),
income
.
getIncomeMonth
());
if
(
one
!=
null
)
{
// 同一合同同一月份不重复保存
return
null
;
}
dmpIncomeRepository
.
save
(
income
);
return
income
;
}
private
String
getCellDateValue
(
Row
row
,
int
index
)
{
Cell
cell
=
row
.
getCell
(
index
);
if
(
cell
==
null
)
{
return
"erro"
;
}
String
dfmate
=
cell
.
getCellStyle
().
getDataFormatString
();
if
(!
"yyyy/mm;@"
.
equals
(
dfmate
)
&&
!
"m/d/yy"
.
equals
(
dfmate
)
&&
!
"yy/m/d"
.
equals
(
dfmate
)
&&
!
"mm/dd/yy"
.
equals
(
dfmate
)
&&
!
"dd-mmm-yy"
.
equals
(
dfmate
)
&&
!
"yyyy/m/d"
.
equals
(
dfmate
)
&&
!
"yyyy/m/d;@"
.
equals
(
dfmate
))
{
return
"erro"
;
}
if
(
org
.
apache
.
poi
.
ss
.
usermodel
.
DateUtil
.
isCellDateFormatted
(
cell
))
{
// 用于转化为日期格式
Date
d
=
cell
.
getDateCellValue
();
DateFormat
formater
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
formater
.
format
(
d
);
}
return
cell
.
toString
();
}
private
String
getCellStringValue
(
Row
row
,
int
index
)
{
Cell
cell
=
row
.
getCell
(
index
);
return
cell
==
null
?
""
:
cell
.
toString
();
}
private
String
getCellStringValue
(
Row
row
,
int
index
,
String
defaulValue
)
{
Cell
cell
=
row
.
getCell
(
index
);
return
cell
==
null
?
defaulValue
:
cell
.
toString
();
}
@Override
public
ResultModel
contractUploadFile
(
MultipartFile
file
,
String
platform
,
User
loginAccount
)
{
Workbook
workbook
=
getWorkbook
(
file
);
...
...
@@ -386,18 +289,19 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
if
(
StringUtils
.
isEmpty
(
contract
.
getEmail
()))
{
return
erroValueTip
(
i
,
"客户主账号"
);
}
if
(
StringUtils
.
isEmpty
(
contract
.
getContractCode
()))
{
return
erroValueTip
(
i
,
"合同编号"
);
}
else
{
contract
.
setCodeNum
(
Integer
.
parseInt
(
contract
.
getContractCode
().
split
(
"-"
)[
3
]));
}
if
(!
CONTRACT_TYPE_NAME
.
containsKey
(
contract
.
getContractType
()))
{
return
erroValueTip
(
i
,
"签约类型"
);
}
else
{
contract
.
setContractType
(
CONTRACT_TYPE_NAME
.
get
(
contract
.
getContractType
()));
}
if
(!
BUSINESS_TYPE_NAME
.
containsKey
(
contract
.
getBusinessTypeName
()))
{
return
erroValueTip
(
i
,
"业务类型"
);
}
else
{
...
...
@@ -417,15 +321,34 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return
ResultModel
.
ERROR
(
"上传内容为空"
);
}
//allContracts.stream().map(v->v.getRelationCode()).collect(Collectors.toList())
CompletableFuture
.
runAsync
(()
->
{
StopWatch
stopWatch
=
new
StopWatch
();
stopWatch
.
start
();
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
35
);
CompletableFuture
[]
futures
=
allContracts
.
stream
()
.
map
(
contract
->
CompletableFuture
.
runAsync
(
()
->
contractRepository
.
save
(
contract
),
executorService
)
.
exceptionally
((
t
)
->
null
)
.
map
(
contract
->
CompletableFuture
.
runAsync
(()
->
{
if
(!
StringUtils
.
isEmpty
(
contract
.
getRelationCode
()))
{
List
<
Long
>
idList
=
contractRepository
.
findIdByCode
(
contract
.
getRelationCode
());
if
(!
idList
.
isEmpty
())
{
contract
.
setRelationContract
(
idList
.
get
(
0
));
}
else
{
contract
.
setRelationContract
(-
1L
);
}
}
else
{
contract
.
setRelationContract
(-
1L
);
}
if
(
contract
.
getRelationContract
()
<
0
)
{
contract
.
setRelationCode
(
null
);
}
contractRepository
.
save
(
contract
);
},
executorService
).
exceptionally
((
t
)
->
null
)
).
toArray
(
size
->
new
CompletableFuture
[
size
]);
CompletableFuture
.
allOf
(
futures
).
join
();
executorService
.
shutdownNow
();
stopWatch
.
stop
();
...
...
@@ -434,6 +357,103 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
return
ResultModel
.
OK
();
}
private
int
checkSheetTitle
(
Workbook
workbook
,
String
sheetTitle
,
String
code
)
{
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
0
);
int
titleLength
=
sheetTitle
.
split
(
"\t"
).
length
;
StringBuffer
titleUp
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
titleLength
;
i
++)
{
if
(
i
>
0
)
titleUp
.
append
(
code
);
titleUp
.
append
(
row
.
getCell
(
i
));
}
if
(!
titleUp
.
toString
().
equals
(
sheetTitle
))
{
return
-
1
;
}
return
titleLength
;
}
private
Workbook
getWorkbook
(
MultipartFile
excelfile
)
{
InputStream
stream
=
null
;
Workbook
workbook
=
null
;
try
{
stream
=
excelfile
.
getInputStream
();
workbook
=
WorkbookFactory
.
create
(
stream
);
}
catch
(
Exception
e
)
{
logger
.
error
(
""
,
e
);
}
finally
{
if
(
stream
!=
null
)
{
try
{
stream
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
""
,
e
);
}
}
}
return
workbook
;
}
private
DmpIncome
saveDmpIncomeItem
(
Sheet
sheet
,
int
index
,
User
user
)
{
//logger.info(" line index {}", index);
Row
rowItem
=
sheet
.
getRow
(
index
);
//合同编号 收入月份 结算周期 系统结算 按月结算 税率 确认收入
DmpIncome
income
=
new
DmpIncome
();
income
.
setContractCode
(
getCellStringValue
(
rowItem
,
0
));
income
.
setIncomeMonth
(
getCellStringValue
(
rowItem
,
1
));
income
.
setPeriod
(
getCellStringValue
(
rowItem
,
2
));
income
.
setSysSettlement
(
getCellStringValue
(
rowItem
,
3
));
income
.
setMonthSettlement
(
getCellStringValue
(
rowItem
,
4
));
income
.
setTaxRate
(
getCellStringValue
(
rowItem
,
5
));
income
.
setConfirmSettlement
(
getCellStringValue
(
rowItem
,
6
));
// 时间 上传人
income
.
setCreateTime
(
new
Date
());
income
.
setUploadUser
(
user
.
getName
());
if
(
StringUtils
.
isEmpty
(
income
.
getContractCode
()))
{
return
null
;
}
DmpIncome
one
=
dmpIncomeRepository
.
findByCodeMonth
(
income
.
getContractCode
(),
income
.
getIncomeMonth
());
if
(
one
!=
null
)
{
// 同一合同同一月份不重复保存
return
null
;
}
dmpIncomeRepository
.
save
(
income
);
return
income
;
}
private
String
getCellDateValue
(
Row
row
,
int
index
)
{
Cell
cell
=
row
.
getCell
(
index
);
if
(
cell
==
null
)
{
return
"erro"
;
}
String
dfmate
=
cell
.
getCellStyle
().
getDataFormatString
();
if
(!
"yyyy/mm;@"
.
equals
(
dfmate
)
&&
!
"m/d/yy"
.
equals
(
dfmate
)
&&
!
"yy/m/d"
.
equals
(
dfmate
)
&&
!
"mm/dd/yy"
.
equals
(
dfmate
)
&&
!
"dd-mmm-yy"
.
equals
(
dfmate
)
&&
!
"yyyy/m/d"
.
equals
(
dfmate
)
&&
!
"yyyy/m/d;@"
.
equals
(
dfmate
))
{
return
"erro"
;
}
if
(
org
.
apache
.
poi
.
ss
.
usermodel
.
DateUtil
.
isCellDateFormatted
(
cell
))
{
// 用于转化为日期格式
Date
d
=
cell
.
getDateCellValue
();
DateFormat
formater
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
formater
.
format
(
d
);
}
return
cell
.
toString
();
}
private
String
getCellStringValue
(
Row
row
,
int
index
)
{
Cell
cell
=
row
.
getCell
(
index
);
return
cell
==
null
?
""
:
cell
.
toString
();
}
private
String
getCellStringValue
(
Row
row
,
int
index
,
String
defaulValue
)
{
Cell
cell
=
row
.
getCell
(
index
);
return
cell
==
null
?
defaulValue
:
cell
.
toString
();
}
private
void
fillDataByRow
(
Contract
contract
,
Row
rowItem
)
{
//我方签约主体 客户签约主体 客户简称
contract
.
setMyBodyName
(
getCellStringValue
(
rowItem
,
0
));
...
...
@@ -455,8 +475,7 @@ public class DmpIncomeServiceImpl implements DmpIncomeService {
contract
.
setBusinessTypeName
(
getCellStringValue
(
rowItem
,
13
));
contract
.
setAgreementTypeName
(
getCellStringValue
(
rowItem
,
14
));
contract
.
setMoney
(
Double
.
parseDouble
(
getCellStringValue
(
rowItem
,
15
,
"0"
)));
contract
.
setRelationContract
(
new
BigDecimal
(
getCellStringValue
(
rowItem
,
16
,
"0"
)).
longValue
());
contract
.
setRelationCode
(
getCellStringValue
(
rowItem
,
16
));
}
private
ResultModel
erroValueTip
(
int
line
,
String
title
)
{
...
...
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