Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-cost
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huluobin
bailuntec-cost
Commits
38d65050
Commit
38d65050
authored
Jul 16, 2021
by
liyanlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加zip批量添加费用计划功能
parent
a7af8ba4
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
736 additions
and
12 deletions
+736
-12
pom.xml
cost-service/pom.xml
+13
-0
ExcelUtil.java
...ce/src/main/java/com/blt/other/common/util/ExcelUtil.java
+86
-0
ThrowingConsumer.java
...n/java/com/blt/other/common/wrapper/ThrowingConsumer.java
+42
-0
CostPlanDomain.java
...ain/java/com/blt/other/database/model/CostPlanDomain.java
+3
-0
CostTypeDomain.java
...ain/java/com/blt/other/database/model/CostTypeDomain.java
+3
-3
CostPlanNewController.java
...t/other/module/cost/controller/CostPlanNewController.java
+48
-0
CostTypeDao.java
.../main/java/com/blt/other/module/cost/dao/CostTypeDao.java
+7
-0
CostTypeService.java
...va/com/blt/other/module/cost/service/CostTypeService.java
+10
-0
CostTypeServiceImpl.java
...t/other/module/cost/service/impl/CostTypeServiceImpl.java
+5
-0
CostPlanServiceFactory.java
...le/cost/service/impl/costplan/CostPlanServiceFactory.java
+316
-1
CostFileUtil.java
...in/java/com/blt/other/module/cost/utils/CostFileUtil.java
+8
-8
CostPlanEnumVo.java
...ain/java/com/blt/other/module/cost/vo/CostPlanEnumVo.java
+175
-0
CostTypeMapper.xml
cost-service/src/main/resources/mapper/CostTypeMapper.xml
+20
-0
No files found.
cost-service/pom.xml
View file @
38d65050
...
...
@@ -295,6 +295,19 @@
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<!--zip解压-->
<dependency>
<groupId>
ant
</groupId>
<artifactId>
ant
</artifactId>
<version>
1.7.0
</version>
</dependency>
<!-- 导入rar解压包 -->
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-compress
</artifactId>
<version>
1.8.1
</version>
</dependency>
</dependencies>
...
...
cost-service/src/main/java/com/blt/other/common/util/ExcelUtil.java
0 → 100644
View file @
38d65050
package
com
.
blt
.
other
.
common
.
util
;
import
org.apache.poi.ss.usermodel.*
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.*;
import
static
org
.
apache
.
poi
.
ss
.
usermodel
.
CellType
.
NUMERIC
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public
class
ExcelUtil
{
public
static
List
<
Map
<
String
,
Object
>>
ExcelData
(
Workbook
wb
){
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
Sheet
sheet
=
null
;
Row
row
=
null
;
Object
cellData
=
null
;
if
(
wb
!=
null
){
//用来存放表中数据
list
=
new
ArrayList
<>();
//获取第一个sheet
sheet
=
wb
.
getSheetAt
(
0
);
//获取最大行数
int
rowNum
=
sheet
.
getPhysicalNumberOfRows
();
//获取第一行
row
=
sheet
.
getRow
(
0
);
//获取最大列数
int
colNum
=
row
.
getPhysicalNumberOfCells
();
for
(
int
i
=
1
;
i
<
rowNum
;
i
++)
{
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
row
=
sheet
.
getRow
(
i
);
if
(
row
!=
null
){
for
(
int
j
=
0
;
j
<
colNum
;
j
++){
cellData
=
getCellFormatValue
(
row
.
getCell
(
j
));
//map.put(columns[j], cellData);
}
}
else
{
break
;
}
list
.
add
(
map
);
}
}
return
list
;
}
public
static
Object
getCellFormatValue
(
Cell
cell
){
Object
cellValue
=
null
;
if
(
cell
!=
null
){
//判断cell类型
switch
(
cell
.
getCellTypeEnum
()){
case
NUMERIC:
{
cellValue
=
String
.
valueOf
(
cell
.
getNumericCellValue
());
break
;
}
case
FORMULA:
{
//判断cell是否为日期格式
if
(
DateUtil
.
isCellDateFormatted
(
cell
)){
//转换为日期格式YYYY-mm-dd
cellValue
=
cell
.
getDateCellValue
();
}
else
{
//数字
cellValue
=
String
.
valueOf
(
cell
.
getNumericCellValue
());
}
break
;
}
case
STRING:
{
cellValue
=
cell
.
getRichStringCellValue
().
getString
();
break
;
}
default
:
cellValue
=
""
;
}
}
else
{
cellValue
=
""
;
}
return
cellValue
;
}
}
cost-service/src/main/java/com/blt/other/common/wrapper/ThrowingConsumer.java
0 → 100644
View file @
38d65050
package
com
.
blt
.
other
.
common
.
wrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
java.util.function.Consumer
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@FunctionalInterface
public
interface
ThrowingConsumer
<
T
,
E
extends
Exception
>
{
void
accept
(
T
t
)
throws
E
;
static
<
T
>
Consumer
<
T
>
throwingConsumerWrapper
(
ThrowingConsumer
<
T
,
Exception
>
throwingConsumer
)
{
return
i
->
{
try
{
throwingConsumer
.
accept
(
i
);
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
}
};
}
static
<
T
,
E
extends
Exception
>
Consumer
<
T
>
handlingConsumerWrapper
(
ThrowingConsumer
<
T
,
E
>
throwingConsumer
,
Class
<
E
>
exceptionClass
)
{
return
i
->
{
try
{
throwingConsumer
.
accept
(
i
);
}
catch
(
Exception
ex
)
{
try
{
E
exCast
=
exceptionClass
.
cast
(
ex
);
System
.
err
.
println
(
"Exception occured : "
+
exCast
.
getMessage
());
}
catch
(
ClassCastException
ccEx
)
{
throw
new
RuntimeException
(
ex
);
}
}
};
}
}
cost-service/src/main/java/com/blt/other/database/model/CostPlanDomain.java
View file @
38d65050
...
...
@@ -167,6 +167,9 @@ public class CostPlanDomain implements Serializable {
@ApiModelProperty
(
"项目"
)
private
String
projectType
;
@ApiModelProperty
(
"客户编号"
)
private
String
customerNum
;
public
CostPlanDto
castToDto
()
{
StatusMapper
statusMapper
=
SpringContextUtil
.
getBean
(
StatusMapper
.
class
);
...
...
cost-service/src/main/java/com/blt/other/database/model/CostTypeDomain.java
View file @
38d65050
...
...
@@ -15,17 +15,17 @@ import java.time.LocalDateTime;
public
class
CostTypeDomain
{
/**
* 费用类型 包括付款 借还
* 费用类型 包括付款 借还
9
*/
public
static
final
Integer
FEE_TYPE
=
0b1001
;
/**
* 收入类别 包括收款
* 收入类别 包括收款
4
*/
public
static
final
Integer
INCOME_TYPE
=
0b0100
;
/**
* 借支类别 包括借支
* 借支类别 包括借支
2
*/
public
static
final
Integer
BORROW
=
0b0010
;
...
...
cost-service/src/main/java/com/blt/other/module/cost/controller/CostPlanNewController.java
View file @
38d65050
package
com
.
blt
.
other
.
module
.
cost
.
controller
;
import
com.bailuntec.cost.api.response.CostResult
;
import
com.blt.other.common.annotation.LoginIgnore
;
import
com.blt.other.common.exception.BizRuntimeException
;
import
com.blt.other.common.util.CurUtils
;
import
com.blt.other.common.util.PathUtil
;
import
com.blt.other.database.model.CostPlanDomain
;
import
com.blt.other.module.cost.dto.response.RestResp
;
import
com.blt.other.module.cost.dto.response.SaveResp
;
import
com.blt.other.module.cost.service.CostPlanService
;
import
com.blt.other.module.cost.service.impl.costplan.CostPlanServiceFactory
;
import
com.mchange.v2.uid.UidUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.io.Resource
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
static
java
.
util
.
stream
.
Collectors
.
joining
;
@Slf4j
@Api
(
tags
=
"费用计划接口"
)
...
...
@@ -132,4 +146,38 @@ public class CostPlanNewController {
return
result
;
}
@LoginIgnore
@ApiOperation
(
"rar导入费用计划"
)
@PostMapping
(
"/upload"
)
public
CostResult
<
String
>
upload
(
MultipartFile
file
,
String
userCode
)
{
/*附件字段*/
if
(
file
!=
null
&&
file
.
getOriginalFilename
().
endsWith
(
".zip"
))
{
try
{
InputStream
is
=
file
.
getResource
().
getInputStream
();
File
rar
=
File
.
createTempFile
(
UidUtils
.
VM_ID
+
"fee-original"
,
".zip"
);
file
.
transferTo
(
rar
);
Map
<
CostPlanService
,
List
<
CostPlanDomain
>>
costPlanServiceListMap
=
CostPlanServiceFactory
.
getCostPlanService
(
rar
,
userCode
);
costPlanServiceListMap
.
forEach
((
x
,
y
)
->
{
y
.
forEach
(
costPlanDomain
->
{
x
.
save
(
costPlanDomain
);
});
});
String
costPlanNos
=
costPlanServiceListMap
.
values
()
.
stream
()
.
map
(
x
->
x
.
stream
()
.
map
(
y
->
y
.
getCostPlanNo
())
.
collect
(
joining
(
","
))
)
.
collect
(
joining
(
","
));
return
new
CostResult
<
String
>().
success
(
"费用计划单号:"
+
costPlanNos
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
new
CostResult
<
String
>().
error
(
"无法读取文件"
);
}
catch
(
Exception
exception
)
{
return
new
CostResult
<
String
>().
error
(
exception
.
getMessage
());
}
}
return
new
CostResult
<
String
>().
error
(
"文件为空或不是.zip格式"
);
}
}
cost-service/src/main/java/com/blt/other/module/cost/dao/CostTypeDao.java
View file @
38d65050
...
...
@@ -58,6 +58,13 @@ public interface CostTypeDao extends BaseMapper<CostTypeDomain> {
CostTypeResult
queryByNo
(
String
typeNo
);
/**
* 获取费用类型详情
* @param typeName
* @return
*/
List
<
CostTypeResult
>
queryByTypeName
(
@Param
(
"typeName"
)
String
typeName
,
@Param
(
"costTemplateType"
)
Integer
costTemplateType
);
/**
* 根据费用类型名称和类型查询
*
* @param name name
...
...
cost-service/src/main/java/com/blt/other/module/cost/service/CostTypeService.java
View file @
38d65050
...
...
@@ -7,9 +7,11 @@ import com.blt.other.module.cost.dto.request.*;
import
com.blt.other.module.cost.dto.response.CostTypeResult
;
import
com.blt.other.module.cost.dto.response.GetLogisticsBankResp
;
import
com.blt.other.module.cost.dto.response.GetLogisticsCodeResp
;
import
org.apache.ibatis.annotations.Param
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
public
interface
CostTypeService
extends
IService
<
CostTypeDomain
>
{
...
...
@@ -60,6 +62,14 @@ public interface CostTypeService extends IService<CostTypeDomain> {
CostTypeResult
queryByNo
(
String
typeNo
);
/**
* 根据名称和模板类型获取费用费用详情
* @param typeName
* @param costTemplateType
* @return
*/
List
<
CostTypeResult
>
queryByTypeName
(
String
typeName
,
Integer
costTemplateType
);
/**
* 获取物流subjectCode
*
* @return rs
...
...
cost-service/src/main/java/com/blt/other/module/cost/service/impl/CostTypeServiceImpl.java
View file @
38d65050
...
...
@@ -147,6 +147,11 @@ public class CostTypeServiceImpl extends ServiceImpl<CostTypeDao, CostTypeDomain
}
@Override
public
List
<
CostTypeResult
>
queryByTypeName
(
String
typeName
,
Integer
costTemplateType
){
return
baseMapper
.
queryByTypeName
(
typeName
,
costTemplateType
);
}
@Override
public
GetLogisticsCodeResp
getLogisticsCode
()
{
GetLogisticsCodeResp
resp
=
new
GetLogisticsCodeResp
();
resp
.
setSuccess
(
true
);
...
...
cost-service/src/main/java/com/blt/other/module/cost/service/impl/costplan/CostPlanServiceFactory.java
View file @
38d65050
package
com
.
blt
.
other
.
module
.
cost
.
service
.
impl
.
costplan
;
import
com.alibaba.fastjson.JSONObject
;
import
com.bailuntec.common.SpringContextUtil
;
import
com.blt.other.common.exception.BizRuntimeException
;
import
com.blt.other.database.model.CostCompanyDomain
;
import
com.blt.other.module.cost.dao.CostDao
;
import
com.blt.other.module.cost.dao.CostPlanDao
;
import
com.blt.other.module.cost.service.CostPlanService
;
import
com.blt.other.module.cost.dao.CostTypeDao
;
import
com.blt.other.module.cost.dto.request.AddItemReq
;
import
com.blt.other.module.cost.dto.request.AddItemResp
;
import
com.blt.other.module.cost.dto.response.CostTypeResult
;
import
com.blt.other.module.cost.model.CostDomain
;
import
com.blt.other.module.cost.service.*
;
import
com.blt.other.database.model.CostPlanDomain
;
import
com.blt.other.module.cost.service.impl.CostCompanyServiceImpl
;
import
com.blt.other.module.cost.service.impl.CostTypeServiceImpl
;
import
com.blt.other.module.cost.service.impl.cost.AbstractCostService
;
import
com.blt.other.module.cost.utils.CostFileUtil
;
import
com.blt.other.module.cost.vo.CostPlanEnumVo
;
import
com.mchange.v2.uid.UidUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveEntry
;
import
org.apache.commons.compress.archivers.zip.ZipArchiveInputStream
;
import
org.apache.commons.compress.utils.IOUtils
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.beans.BeanUtils
;
import
javax.annotation.Resource
;
import
java.io.*
;
import
java.math.BigDecimal
;
import
java.util.*
;
import
static
com
.
blt
.
other
.
common
.
wrapper
.
ThrowingConsumer
.
handlingConsumerWrapper
;
import
static
com
.
blt
.
other
.
common
.
wrapper
.
ThrowingConsumer
.
throwingConsumerWrapper
;
/**
* <p>
...
...
@@ -13,12 +45,44 @@ import com.blt.other.database.model.CostPlanDomain;
* @author robbendev
* @since 2020/10/17 10:13 上午
*/
@Slf4j
public
class
CostPlanServiceFactory
{
/**
* 费用类型 包括付款 借还 9
*/
private
static
final
Integer
FEE_TYPE
=
0b1001
;
/**
* 收入类别 包括收款 4
*/
private
static
final
Integer
INCOME_TYPE
=
0b0100
;
/**
* 借支类别 包括借支 2
*/
private
static
final
Integer
BORROW
=
0b0010
;
private
static
CostTypeService
getCostTypeService
(){
return
SpringContextUtil
.
getBean
(
CostTypeServiceImpl
.
class
);
}
private
static
CostCompanyService
getCostCompanyService
(){
return
SpringContextUtil
.
getBean
(
CostCompanyServiceImpl
.
class
);
}
private
static
CostPlanTempService
getCostPlanTempService
(){
return
SpringContextUtil
.
getBean
(
CostPlanTempServiceImpl
.
class
);
}
public
static
CostPlanService
getCostPlanService
()
{
return
SpringContextUtil
.
getBean
(
DefaultCostPlanServiceImpl
.
class
);
}
public
static
CostService
getCostService
()
{
return
SpringContextUtil
.
getBean
(
AbstractCostService
.
class
);
}
public
static
CostPlanService
getCostPlanService
(
String
costPlanNo
)
{
CostPlanDao
costPlanDao
=
SpringContextUtil
.
getBean
(
CostPlanDao
.
class
);
...
...
@@ -41,6 +105,257 @@ public class CostPlanServiceFactory {
}
return
SpringContextUtil
.
getBean
(
DefaultCostPlanServiceImpl
.
class
);
}
/**
* 根据上传的文件构建
*
* @param zip
* @return
*/
public
static
Map
<
CostPlanService
,
List
<
CostPlanDomain
>>
getCostPlanService
(
File
zip
,
String
userCode
)
throws
Exception
{
Map
<
CostPlanService
,
List
<
CostPlanDomain
>>
costPlanServiceListMap
=
new
HashMap
<>();
Map
<
String
,
File
>
fileMap
=
new
HashMap
<>();
List
<
String
>
createdPlanNos
=
new
ArrayList
<>();
try
(
ZipArchiveInputStream
inputStream
=
new
ZipArchiveInputStream
(
new
BufferedInputStream
(
new
FileInputStream
(
zip
))))
{
ZipArchiveEntry
entry
;
while
((
entry
=
inputStream
.
getNextZipEntry
())
!=
null
)
{
if
(!
entry
.
isDirectory
())
{
File
tempFile
=
File
.
createTempFile
(
UidUtils
.
VM_ID
,
entry
.
getName
());
OutputStream
outputStream
=
new
FileOutputStream
(
tempFile
);
IOUtils
.
copy
(
inputStream
,
outputStream
);
outputStream
.
close
();
fileMap
.
put
(
entry
.
getName
(),
tempFile
);
}
}
File
feeExcel
=
fileMap
.
get
(
"费用计划.xlsx"
);
if
(
feeExcel
==
null
){
throw
new
Exception
(
"缺少文件【费用计划.xlsx】"
);
}
InputStream
feeIn
=
new
FileInputStream
(
feeExcel
);
Workbook
wb
=
new
XSSFWorkbook
(
feeIn
);
for
(
int
sheetIndex
=
0
;
sheetIndex
<=
3
;
sheetIndex
++){
Sheet
sheet
=
wb
.
getSheetAt
(
sheetIndex
);
if
(
sheet
!=
null
&&
sheet
.
getLastRowNum
()
>
0
)
{
costPlanServiceListMap
.
putAll
(
getCostPlan
(
sheet
,
fileMap
,
userCode
,
createdPlanNos
));
}
}
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
throw
fileNotFoundException
;
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
throw
ioException
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
e
;
}
return
costPlanServiceListMap
;
}
/**
* 获取费用计划
* @param sheet
* @param fileMap
* @param userCode
* @return
* @throws Exception
*/
private
static
Map
<
CostPlanService
,
List
<
CostPlanDomain
>>
getCostPlan
(
Sheet
sheet
,
Map
<
String
,
File
>
fileMap
,
String
userCode
,
List
<
String
>
createdPlanNos
)
throws
Exception
{
Row
firstRow
=
sheet
.
getRow
(
0
);
String
sheetName
=
sheet
.
getSheetName
();
Map
<
CostPlanService
,
List
<
CostPlanDomain
>>
costPlanServiceListMap
=
new
HashMap
<>();
List
<
CostPlanDomain
>
costPlanDomainList
=
new
ArrayList
<>();
Map
<
String
,
CostTypeResult
>
costTypeResultMap
=
new
HashMap
<>();
Map
<
Integer
,
Map
<
CostPlanDomain
,
List
<
AddItemReq
>>>
costPlanAndItemMap
=
new
HashMap
<>();
//公司主体映射
Map
<
String
,
CostCompanyDomain
>
costCompanyDomainMap
=
getCostCompanyService
().
costCompanyMap
();
for
(
int
i
=
1
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
Row
row
=
sheet
.
getRow
(
i
);
JSONObject
jsonObject
=
new
JSONObject
();
for
(
int
j
=
0
;
j
<
firstRow
.
getLastCellNum
();
j
++)
{
String
costPlanField
=
CostPlanEnumVo
.
getCostPlanField
(
sheetName
,
firstRow
.
getCell
(
j
).
toString
());
if
(!
costPlanField
.
equals
(
""
)
&&
row
.
getCell
(
j
)
!=
null
)
{
jsonObject
.
put
(
costPlanField
,
row
.
getCell
(
j
).
toString
());
}
}
CostPlanDomain
costPlanDomain
=
jsonObject
.
toJavaObject
(
CostPlanDomain
.
class
);
costPlanDomain
.
setAttach
(
new
ArrayList
<>());
//上传文件
File
currentFile
=
fileMap
.
get
(
costPlanDomain
.
getFilePath
());
String
path
=
CostFileUtil
.
qiniuUpload
(
currentFile
);
if
(
path
==
null
)
{
throw
new
Exception
(
"上传附件失败"
);
}
path
=
"http://dcfile.blsct.com/"
+
path
;
//类别
CostTypeResult
costTypeResult
=
costTypeResultMap
.
get
(
sheetName
+
costPlanDomain
.
getTypeName
());
if
(
costTypeResult
==
null
)
{
costTypeResult
=
getCostType
(
sheetName
,
costPlanDomain
.
getTypeName
());
costTypeResultMap
.
put
(
sheetName
+
costPlanDomain
.
getTypeName
(),
costTypeResult
);
}
//设置用户编号
costPlanDomain
.
setCreateUsercode
(
userCode
);
//设置付款/收款主体
CostCompanyDomain
costCompanyDomain
=
costCompanyDomainMap
.
get
(
costPlanDomain
.
getCompanyName
());
costPlanDomain
.
setCompanyNo
(
costCompanyDomain
.
getCompanyNo
());
costPlanDomain
.
setCompanyValue
(
costCompanyDomain
.
getValue
());
if
(!
sheetName
.
equals
(
"付款"
))
{
if
(
sheetName
.
equals
(
"借还"
)){
//借还的lendType = 借支的借支类别
CostTypeResult
lendTypeCostTypeResult
=
costTypeResultMap
.
get
(
"借支"
+
costPlanDomain
.
getLendType
());
if
(
lendTypeCostTypeResult
==
null
)
{
lendTypeCostTypeResult
=
getCostType
(
"借支"
,
costPlanDomain
.
getLendType
());
costTypeResultMap
.
put
(
"借支"
+
costPlanDomain
.
getLendType
(),
lendTypeCostTypeResult
);
}
//借支信息
CostDomain
supCost
=
getCostService
().
getCostByCostNo
(
costPlanDomain
.
getSupCostNo
());
if
(
supCost
==
null
||
!
supCost
.
getCreateUsercode
().
equalsIgnoreCase
(
userCode
)
||
!(
supCost
.
getCostForm
().
equals
(
3
)
&&
supCost
.
getIsLend
().
equals
(
1
))){
throw
new
BizRuntimeException
(
"费用单"
+
costPlanDomain
.
getSupCostNo
()+
"无法作为借还单的关联借支单,请检查是否填写正确"
);
}
//借支
costPlanDomain
.
setCounteract
(
supCost
.
getCounteract
());
costPlanDomain
.
setLendBalance
(
supCost
.
getLendBalance
());
costPlanDomain
.
setDic
(
supCost
.
getDic
());
costPlanDomain
.
setPlanAmount
(
supCost
.
getCounteract
().
add
(
supCost
.
getLendBalance
()));
//借还总计
costPlanDomain
.
setPayPlanAmount
(
costPlanDomain
.
getPayCounteract
().
add
(
costPlanDomain
.
getPayLendBalance
()));
//银行卡信息
costPlanDomain
.
setBankCompany
(
supCost
.
getBankCompany
());
costPlanDomain
.
setBankName
(
supCost
.
getBankName
());
costPlanDomain
.
setBankCard
(
supCost
.
getBankCard
());
costPlanDomain
.
setBankCardUser
(
supCost
.
getBankCardUser
());
costPlanDomain
.
setLendType
(
lendTypeCostTypeResult
.
getTypeNo
());
}
//计划单号
String
planNo
=
getCostPlanService
().
createNo
();
while
(
createdPlanNos
.
contains
(
planNo
)){
planNo
=
getCostPlanService
().
createNo
();
}
createdPlanNos
.
add
(
planNo
);
costPlanDomain
.
setCostPlanNo
(
planNo
);
//太快了计划单号会重复
Thread
.
sleep
(
100
);
//文件
costPlanDomain
.
setFilePath
(
path
);
//费用类别/付款类别/收款类别
BeanUtils
.
copyProperties
(
costTypeResult
,
costPlanDomain
,
"id"
);
costPlanDomain
.
setTypeId
(
costTypeResult
.
getId
());
//加入list
costPlanDomainList
.
add
(
costPlanDomain
);
//log.info(costPlanDomain.toString());
}
else
{
//付款,需要保存
//AddItemReq
AddItemReq
itemReq
=
jsonObject
.
toJavaObject
(
AddItemReq
.
class
);
itemReq
.
setFilePath
(
path
);
itemReq
.
setTypeNo
(
costTypeResult
.
getTypeNo
());
costPlanDomain
.
setTypeName
(
null
);
costPlanDomain
.
setFilePath
(
null
);
Integer
costPlanHash
=
(
costPlanDomain
.
getCompanyValue
()
+
costPlanDomain
.
getBankCard
()
+
costPlanDomain
.
getBankCompany
()
+
costPlanDomain
.
getBankName
()).
hashCode
();
Map
<
CostPlanDomain
,
List
<
AddItemReq
>>
planItemMap
=
costPlanAndItemMap
.
get
(
costPlanHash
);
if
(
planItemMap
==
null
){
//计划单号
String
planNo
=
getCostPlanService
().
createNo
();
while
(
createdPlanNos
.
contains
(
planNo
)){
planNo
=
getCostPlanService
().
createNo
();
}
createdPlanNos
.
add
(
planNo
);
costPlanDomain
.
setCostPlanNo
(
planNo
);
itemReq
.
setCostPlanNo
(
costPlanDomain
.
getCostPlanNo
());
planItemMap
=
new
HashMap
<>();
planItemMap
.
put
(
costPlanDomain
,
new
ArrayList
<
AddItemReq
>()
{
{
add
(
itemReq
);
}
});
costPlanAndItemMap
.
put
(
costPlanHash
,
planItemMap
);
}
else
{
String
currentCostPlanNo
=
planItemMap
.
keySet
().
stream
().
map
(
x
->
x
.
getCostPlanNo
()).
findFirst
().
get
();
itemReq
.
setCostPlanNo
(
currentCostPlanNo
);
planItemMap
.
values
().
stream
().
findFirst
().
get
().
add
(
itemReq
);
}
}
}
if
(
costPlanAndItemMap
.
size
()
>
0
){
costPlanAndItemMap
.
values
().
forEach
(
x
->{
x
.
entrySet
().
forEach
(
y
->
{
y
.
getValue
().
forEach
(
v
->{
});
y
.
getValue
().
forEach
(
throwingConsumerWrapper
(
v
->{
AddItemResp
resp
=
getCostPlanTempService
().
doSave
(
v
);
if
(!
resp
.
getSuccess
()){
throw
new
Exception
(
"保存item异常"
);
}
}));
BigDecimal
totalAmount
=
y
.
getValue
().
stream
().
map
(
AddItemReq:
:
getAmount
).
reduce
(
BigDecimal:
:
add
).
get
();
y
.
getKey
().
setPlanAmount
(
totalAmount
);
costPlanDomainList
.
add
(
y
.
getKey
());
});
});
}
switch
(
sheetName
){
case
"付款"
:
costPlanDomainList
.
forEach
(
x
->
{
x
.
setCostForm
(
1
);
x
.
setCostTemplateId
(
3
);});
costPlanServiceListMap
.
put
(
SpringContextUtil
.
getBean
(
CostPlanNewPayServiceImpl
.
class
),
costPlanDomainList
);
break
;
case
"收款"
:
costPlanDomainList
.
forEach
(
x
->
{
x
.
setCostForm
(
2
);
x
.
setCostTemplateId
(
5
);});
costPlanServiceListMap
.
put
(
SpringContextUtil
.
getBean
(
CostPlanNewReceiptServiceImpl
.
class
),
costPlanDomainList
);
break
;
case
"借支"
:
costPlanDomainList
.
forEach
(
x
->
{
x
.
setCostForm
(
3
);
x
.
setIsLend
(
1
);
x
.
setCostTemplateId
(
6
);
});
costPlanServiceListMap
.
put
(
SpringContextUtil
.
getBean
(
CostPlanNewLend1ServiceImpl
.
class
),
costPlanDomainList
);
break
;
case
"借还"
:
costPlanDomainList
.
forEach
(
x
->
{
x
.
setCostForm
(
3
);
x
.
setIsLend
(
2
);
x
.
setCostTemplateId
(
7
);
});
costPlanServiceListMap
.
put
(
SpringContextUtil
.
getBean
(
CostPlanNewLend2ServiceImpl
.
class
),
costPlanDomainList
);
break
;
}
return
costPlanServiceListMap
;
}
private
static
CostTypeResult
getCostType
(
String
sheetName
,
String
typeName
)
throws
Exception
{
Integer
feeType
=
0
;
switch
(
sheetName
)
{
case
"付款"
:
case
"借还"
:
feeType
=
FEE_TYPE
;
break
;
case
"收款"
:
feeType
=
INCOME_TYPE
;
break
;
case
"借支"
:
feeType
=
BORROW
;
break
;
}
List
<
CostTypeResult
>
costTypeResultList
=
getCostTypeService
().
queryByTypeName
(
typeName
,
feeType
);
if
(
costTypeResultList
==
null
||
costTypeResultList
.
size
()
<=
0
||
costTypeResultList
.
size
()
>
1
)
{
throw
new
Exception
(
"费用类型【"
+
typeName
+
"】异常"
);
}
CostTypeResult
costTypeResult
=
costTypeResultList
.
get
(
0
);
return
costTypeResult
;
}
}
cost-service/src/main/java/com/blt/other/module/cost/utils/CostFileUtil.java
View file @
38d65050
...
...
@@ -5,6 +5,7 @@ import com.bailuntec.common.StringUtils;
import
com.bailuntec.common.exception.BizException
;
import
com.baomidou.mybatisplus.core.toolkit.IdWorker
;
import
com.blt.other.common.util.PathUtil
;
import
com.mchange.v2.uid.UidUtils
;
import
com.qiniu.common.QiniuException
;
import
com.qiniu.http.Response
;
import
com.qiniu.storage.Configuration
;
...
...
@@ -51,6 +52,7 @@ public class CostFileUtil {
return
fileName
;
}
public
static
String
upload
(
String
netUrl
,
String
filePath
)
throws
IOException
{
RestTemplate
restTemplate
=
new
RestTemplate
();
...
...
@@ -79,7 +81,7 @@ public class CostFileUtil {
}
public
String
saveImage
(
MultipartFile
multipartFile
)
throws
IOException
{
public
static
String
saveImage
(
MultipartFile
multipartFile
)
throws
IOException
{
//临时文件地址
String
basePath
=
PathUtil
.
getBasePath
()
+
PathUtil
.
getPath
(
"cost/"
);
//文件名
...
...
@@ -100,27 +102,25 @@ public class CostFileUtil {
return
qiniuUpload
(
localFile
);
}
public
String
qiniuUpload
(
File
localFilePath
)
{
public
static
String
qiniuUpload
(
File
localFilePath
)
{
//1、构造一个带指定Zone对象的配置类
// Configuration cfg = new Configuration(Zone.zone2());
Configuration
cfg
=
new
Configuration
(
Region
.
region2
());
//2、其他参数参考类注释
UploadManager
uploadManager
=
new
UploadManager
(
cfg
);
//3、生成上传凭证,然后准备上传
String
accessKey
=
"
RWQXlbVA7oe3BxnPuFtqkAJocQZkWTwrwYyldklr
"
;
String
secretKey
=
"
tS2gxsQO26mGoFZJI-x8WSH9X5aPgYMJcyoJdak5
"
;
String
bucket
=
"b
egogirls
"
;
String
accessKey
=
"
QSvtvN4Ons1CiNzaMGqx8XmDaiM1L0ZqSwJ2YoTn
"
;
String
secretKey
=
"
yagRd-cBOVhkRGGT-o_reMqNVjI8_k7YwoTXkhrm
"
;
String
bucket
=
"b
ailun-data-center
"
;
//默认不指定key的情况下,以文件内容的hash值作为文件名
String
key
=
null
;
String
key
=
UidUtils
.
VM_ID
+
"-"
+
localFilePath
.
getName
()
;
Auth
auth
=
Auth
.
create
(
accessKey
,
secretKey
);
String
upToken
=
auth
.
uploadToken
(
bucket
);
try
{
Response
response
=
uploadManager
.
put
(
localFilePath
,
key
,
upToken
);
//4、解析上传成功的结果
DefaultPutRet
putRet
=
JsonUtilByFsJson
.
jsonToBean
(
response
.
bodyString
(),
DefaultPutRet
.
class
);
System
.
out
.
println
(
putRet
.
key
);
System
.
out
.
println
(
putRet
.
hash
);
return
putRet
.
key
;
}
catch
(
QiniuException
ex
)
{
Response
r
=
ex
.
response
;
...
...
cost-service/src/main/java/com/blt/other/module/cost/vo/CostPlanEnumVo.java
0 → 100644
View file @
38d65050
package
com
.
blt
.
other
.
module
.
cost
.
vo
;
import
lombok.extern.slf4j.Slf4j
;
import
java.math.BigDecimal
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@Slf4j
public
enum
CostPlanEnumVo
{
companyName
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"付款主体"
);
put
(
"收款"
,
"收款主体"
);
put
(
"借支"
,
"付款主体"
);
put
(
"借还"
,
"收款主体"
);
}
}),
bankCompany
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"收款单位"
);
put
(
"收款"
,
"付款单位"
);
put
(
"借支"
,
"收款单位"
);
}
}),
bankName
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"收款银行"
);
put
(
"收款"
,
"付款银行"
);
put
(
"借支"
,
"收款银行"
);
}
}),
bankCard
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"收款账户"
);
put
(
"收款"
,
"付款账户"
);
put
(
"借支"
,
"收款账户"
);
}
}),
bankCardUser
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"持卡人"
);
put
(
"收款"
,
"持卡人"
);
put
(
"借支"
,
"持卡人"
);
}
}),
costRemark
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"备注"
);
put
(
"收款"
,
"备注"
);
put
(
"借支"
,
"备注"
);
put
(
"借还"
,
"备注"
);
}
}),
lendType
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"借支"
,
"借支类别"
);
put
(
"借还"
,
"借支类别"
);
}
}),
supCostNo
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"借还"
,
"关联借支单"
);
}
}),
typeName
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"费用类别"
);
put
(
"收款"
,
"收入类别"
);
put
(
"借支"
,
"费用类别"
);
put
(
"借还"
,
"费用类别"
);
}
}),
projectType
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"收款"
,
"项目"
);
}
}),
payCounteract
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"借还"
,
"冲销金额"
);
}
}),
payLendBalance
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"借还"
,
"归还金额"
);
}
}),
customerNum
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"收款"
,
"客户编号"
);
}
}),
dic
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"币种"
);
put
(
"收款"
,
"币种"
);
put
(
"借支"
,
"币种"
);
}
}),
payDic
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"借还"
,
"借还币种"
);
}
}),
planAmount
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"收款"
,
"原币金额"
);
put
(
"借支"
,
"原币金额"
);
}
}),
amount
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"原币金额"
);
}
}),
costReason
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"费用用途"
);
put
(
"收款"
,
"收款理由"
);
put
(
"借支"
,
"借支理由"
);
put
(
"借还"
,
"借还理由"
);
}
}),
filePath
(
new
HashMap
<
String
,
String
>()
{
{
put
(
"付款"
,
"附件名"
);
put
(
"收款"
,
"附件名"
);
put
(
"借支"
,
"附件名"
);
put
(
"借还"
,
"附件名"
);
}
});
private
Map
<
String
,
String
>
typeMap
;
private
Class
clazz
;
private
String
parseMethod
;
CostPlanEnumVo
(
Map
<
String
,
String
>
typeMap
)
{
this
.
typeMap
=
typeMap
;
}
public
static
CostPlanEnumVo
match
(
String
name
,
CostPlanEnumVo
defaultItem
){
for
(
CostPlanEnumVo
item:
CostPlanEnumVo
.
values
())
{
if
(
item
.
name
().
equals
(
name
))
{
return
item
;
}
}
return
defaultItem
;
}
public
static
String
getCostPlanField
(
String
type
,
String
fieldName
){
try
{
for
(
CostPlanEnumVo
item
:
CostPlanEnumVo
.
values
())
{
if
(
item
.
typeMap
.
get
(
type
)
==
null
){
continue
;
}
if
(
item
.
typeMap
.
get
(
type
).
equals
(
fieldName
))
{
return
item
.
name
();
}
}
}
catch
(
Exception
ex
){
log
.
error
(
ex
.
toString
());
}
return
""
;
}
}
cost-service/src/main/resources/mapper/CostTypeMapper.xml
View file @
38d65050
...
...
@@ -81,6 +81,26 @@
where t1.type_no = #{typeNo}
</select>
<select
id=
"queryByTypeName"
resultType=
"com.blt.other.module.cost.dto.response.CostTypeResult"
>
select t1.id,
t1.type_no,
t1.type_name,
t1.description,
t1.accounting_subject_no,
t2.name as accounting_subject_name,
t1.create_time,
t1.update_user,
t1.update_user_id,
t1.last_update_time,
t1.create_user_id,
t1.create_user,
t1.is_manage_cost
from cost_type t1
left join accounting_subject t2 on t1.accounting_subject_no = t2.subject_no
where t1.type_name = #{typeName}
and t1.cost_template_type = #{costTemplateType}
</select>
<select
id=
"selectByNameAndType"
resultType=
"com.blt.other.database.model.CostTypeDomain"
>
select *
from cost_type
...
...
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