Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
de6892d8
Commit
de6892d8
authored
Nov 29, 2021
by
季圣华
Browse files
解决供应商、客户、会员导入的bug
parent
8b415b2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/controller/SupplierController.java
View file @
de6892d8
...
...
@@ -262,19 +262,19 @@ public class SupplierController {
}
/**
* 导入
excel表格
* 导入
供应商
* @param file
* @param request
* @param response
* @return
*/
@PostMapping
(
value
=
"/import
Excel
"
)
@ApiOperation
(
value
=
"导入
excel表格
"
)
public
BaseResponseInfo
import
Excel
(
MultipartFile
file
,
@PostMapping
(
value
=
"/import
Vendor
"
)
@ApiOperation
(
value
=
"导入
供应商
"
)
public
BaseResponseInfo
import
Vendor
(
MultipartFile
file
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
try
{
importFun
(
file
);
supplierService
.
importVendor
(
file
,
request
);
res
.
code
=
200
;
res
.
data
=
"导入成功"
;
}
catch
(
Exception
e
){
...
...
@@ -285,63 +285,77 @@ public class SupplierController {
return
res
;
}
public
String
importFun
(
MultipartFile
file
)
throws
Exception
{
BaseResponseInfo
info
=
new
BaseResponseInfo
();
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
String
message
=
"成功"
;
/**
* 导入客户
* @param file
* @param request
* @param response
* @return
*/
@PostMapping
(
value
=
"/importCustomer"
)
@ApiOperation
(
value
=
"导入客户"
)
public
BaseResponseInfo
importCustomer
(
MultipartFile
file
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
try
{
Sheet
src
=
null
;
//文件合法性校验
try
{
Workbook
workbook
=
Workbook
.
getWorkbook
(
file
.
getInputStream
());
src
=
workbook
.
getSheet
(
0
);
}
catch
(
Exception
e
)
{
message
=
"导入文件不合法,请检查"
;
data
.
put
(
"message"
,
message
);
info
.
code
=
400
;
info
.
data
=
data
;
}
//每行中数据顺序 "名称","类型","联系人","电话","电子邮箱","预收款","期初应收","期初应付","备注","传真","手机","地址","纳税人识别号","开户行","账号","税率","状态"
List
<
Supplier
>
sList
=
new
ArrayList
<
Supplier
>();
for
(
int
i
=
1
;
i
<
src
.
getRows
();
i
++)
{
Supplier
s
=
new
Supplier
();
s
.
setSupplier
(
ExcelUtils
.
getContent
(
src
,
i
,
0
));
s
.
setType
(
ExcelUtils
.
getContent
(
src
,
i
,
1
));
s
.
setContacts
(
ExcelUtils
.
getContent
(
src
,
i
,
2
));
s
.
setPhoneNum
(
ExcelUtils
.
getContent
(
src
,
i
,
3
));
s
.
setEmail
(
ExcelUtils
.
getContent
(
src
,
i
,
4
));
s
.
setAdvanceIn
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
5
)));
s
.
setBeginNeedGet
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
6
)));
s
.
setBeginNeedPay
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
7
)));
s
.
setDescription
(
ExcelUtils
.
getContent
(
src
,
i
,
8
));
s
.
setFax
(
ExcelUtils
.
getContent
(
src
,
i
,
9
));
s
.
setTelephone
(
ExcelUtils
.
getContent
(
src
,
i
,
10
));
s
.
setAddress
(
ExcelUtils
.
getContent
(
src
,
i
,
11
));
s
.
setTaxNum
(
ExcelUtils
.
getContent
(
src
,
i
,
12
));
s
.
setBankName
(
ExcelUtils
.
getContent
(
src
,
i
,
13
));
s
.
setAccountNumber
(
ExcelUtils
.
getContent
(
src
,
i
,
14
));
s
.
setTaxRate
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
15
)));
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
16
);
s
.
setEnabled
(
enabled
.
equals
(
"启用"
)?
true
:
false
);
s
.
setIsystem
(
Byte
.
parseByte
(
"1"
));
sList
.
add
(
s
);
}
info
=
supplierService
.
importExcel
(
sList
);
}
catch
(
Exception
e
)
{
supplierService
.
importCustomer
(
file
,
request
);
res
.
code
=
200
;
res
.
data
=
"导入成功"
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
message
=
"导入失败"
;
info
.
code
=
500
;
data
.
put
(
"message"
,
message
);
info
.
data
=
data
;
res
.
code
=
500
;
res
.
data
=
"导入失败"
;
}
return
null
;
return
res
;
}
public
BigDecimal
parseBigDecimalEx
(
String
str
)
throws
Exception
{
if
(!
StringUtil
.
isEmpty
(
str
))
{
return
new
BigDecimal
(
str
);
}
else
{
return
null
;
/**
* 导入会员
* @param file
* @param request
* @param response
* @return
*/
@PostMapping
(
value
=
"/importMember"
)
@ApiOperation
(
value
=
"导入会员"
)
public
BaseResponseInfo
importMember
(
MultipartFile
file
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
try
{
supplierService
.
importMember
(
file
,
request
);
res
.
code
=
200
;
res
.
data
=
"导入成功"
;
}
catch
(
Exception
e
){
e
.
printStackTrace
();
res
.
code
=
500
;
res
.
data
=
"导入失败"
;
}
return
res
;
}
/**
* 生成excel表格
* @param supplier
* @param type
* @param phonenum
* @param telephone
* @param request
* @param response
* @return
*/
@GetMapping
(
value
=
"/exportExcel"
)
public
void
exportExcel
(
@RequestParam
(
value
=
"supplier"
,
required
=
false
)
String
supplier
,
@RequestParam
(
"type"
)
String
type
,
@RequestParam
(
value
=
"phonenum"
,
required
=
false
)
String
phonenum
,
@RequestParam
(
value
=
"telephone"
,
required
=
false
)
String
telephone
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
try
{
List
<
Supplier
>
dataList
=
supplierService
.
findByAll
(
supplier
,
type
,
phonenum
,
telephone
);
File
file
=
supplierService
.
exportExcel
(
dataList
,
type
);
ExportExecUtil
.
showExec
(
file
,
file
.
getName
(),
response
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java
View file @
de6892d8
...
...
@@ -18,16 +18,21 @@ import com.jsh.erp.service.systemConfig.SystemConfigService;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.service.userBusiness.UserBusinessService
;
import
com.jsh.erp.utils.BaseResponseInfo
;
import
com.jsh.erp.utils.ExcelUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
jxl.Sheet
;
import
jxl.Workbook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.File
;
import
java.math.BigDecimal
;
import
java.util.*
;
...
...
@@ -384,13 +389,93 @@ public class SupplierService {
return
list
;
}
public
void
importVendor
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
String
type
=
"供应商"
;
Workbook
workbook
=
Workbook
.
getWorkbook
(
file
.
getInputStream
());
Sheet
src
=
workbook
.
getSheet
(
0
);
//'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '传真', '期初应付', '纳税人识别号', '税率(%)', '开户行', '账号', '地址', '备注', '状态'
List
<
Supplier
>
sList
=
new
ArrayList
<>();
for
(
int
i
=
2
;
i
<
src
.
getRows
();
i
++)
{
Supplier
s
=
new
Supplier
();
s
.
setType
(
type
);
s
.
setSupplier
(
ExcelUtils
.
getContent
(
src
,
i
,
0
));
s
.
setContacts
(
ExcelUtils
.
getContent
(
src
,
i
,
1
));
s
.
setTelephone
(
ExcelUtils
.
getContent
(
src
,
i
,
2
));
s
.
setPhoneNum
(
ExcelUtils
.
getContent
(
src
,
i
,
3
));
s
.
setEmail
(
ExcelUtils
.
getContent
(
src
,
i
,
4
));
s
.
setFax
(
ExcelUtils
.
getContent
(
src
,
i
,
5
));
s
.
setBeginNeedGet
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
6
)));
s
.
setTaxNum
(
ExcelUtils
.
getContent
(
src
,
i
,
7
));
s
.
setTaxRate
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
8
)));
s
.
setBankName
(
ExcelUtils
.
getContent
(
src
,
i
,
9
));
s
.
setAccountNumber
(
ExcelUtils
.
getContent
(
src
,
i
,
10
));
s
.
setAddress
(
ExcelUtils
.
getContent
(
src
,
i
,
11
));
s
.
setDescription
(
ExcelUtils
.
getContent
(
src
,
i
,
12
));
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
13
);
s
.
setEnabled
(
enabled
.
equals
(
"1"
));
sList
.
add
(
s
);
}
importExcel
(
sList
,
type
);
}
public
void
importCustomer
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
String
type
=
"客户"
;
Workbook
workbook
=
Workbook
.
getWorkbook
(
file
.
getInputStream
());
Sheet
src
=
workbook
.
getSheet
(
0
);
//'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '传真', '期初应收', '纳税人识别号', '税率(%)', '开户行', '账号', '地址', '备注', '状态'
List
<
Supplier
>
sList
=
new
ArrayList
<>();
for
(
int
i
=
2
;
i
<
src
.
getRows
();
i
++)
{
Supplier
s
=
new
Supplier
();
s
.
setType
(
type
);
s
.
setSupplier
(
ExcelUtils
.
getContent
(
src
,
i
,
0
));
s
.
setContacts
(
ExcelUtils
.
getContent
(
src
,
i
,
1
));
s
.
setTelephone
(
ExcelUtils
.
getContent
(
src
,
i
,
2
));
s
.
setPhoneNum
(
ExcelUtils
.
getContent
(
src
,
i
,
3
));
s
.
setEmail
(
ExcelUtils
.
getContent
(
src
,
i
,
4
));
s
.
setFax
(
ExcelUtils
.
getContent
(
src
,
i
,
5
));
s
.
setBeginNeedGet
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
6
)));
s
.
setTaxNum
(
ExcelUtils
.
getContent
(
src
,
i
,
7
));
s
.
setTaxRate
(
parseBigDecimalEx
(
ExcelUtils
.
getContent
(
src
,
i
,
8
)));
s
.
setBankName
(
ExcelUtils
.
getContent
(
src
,
i
,
9
));
s
.
setAccountNumber
(
ExcelUtils
.
getContent
(
src
,
i
,
10
));
s
.
setAddress
(
ExcelUtils
.
getContent
(
src
,
i
,
11
));
s
.
setDescription
(
ExcelUtils
.
getContent
(
src
,
i
,
12
));
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
13
);
s
.
setEnabled
(
enabled
.
equals
(
"1"
));
sList
.
add
(
s
);
}
importExcel
(
sList
,
type
);
}
public
void
importMember
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
String
type
=
"会员"
;
Workbook
workbook
=
Workbook
.
getWorkbook
(
file
.
getInputStream
());
Sheet
src
=
workbook
.
getSheet
(
0
);
//'名称', '联系人', '手机号码', '联系电话', '电子邮箱', '备注', '状态'
List
<
Supplier
>
sList
=
new
ArrayList
<>();
for
(
int
i
=
2
;
i
<
src
.
getRows
();
i
++)
{
Supplier
s
=
new
Supplier
();
s
.
setType
(
type
);
s
.
setSupplier
(
ExcelUtils
.
getContent
(
src
,
i
,
0
));
s
.
setContacts
(
ExcelUtils
.
getContent
(
src
,
i
,
1
));
s
.
setTelephone
(
ExcelUtils
.
getContent
(
src
,
i
,
2
));
s
.
setPhoneNum
(
ExcelUtils
.
getContent
(
src
,
i
,
3
));
s
.
setEmail
(
ExcelUtils
.
getContent
(
src
,
i
,
4
));
s
.
setDescription
(
ExcelUtils
.
getContent
(
src
,
i
,
5
));
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
6
);
s
.
setEnabled
(
enabled
.
equals
(
"1"
));
sList
.
add
(
s
);
}
importExcel
(
sList
,
type
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
BaseResponseInfo
importExcel
(
List
<
Supplier
>
mList
)
throws
Exception
{
logService
.
insertLog
(
"商家"
,
public
BaseResponseInfo
importExcel
(
List
<
Supplier
>
mList
,
String
type
)
throws
Exception
{
logService
.
insertLog
(
type
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_IMPORT
).
append
(
mList
.
size
()).
append
(
BusinessConstants
.
LOG_DATA_UNIT
).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
BaseResponseInfo
info
=
new
BaseResponseInfo
();
Map
<
String
,
Object
>
data
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
try
{
for
(
Supplier
s:
mList
)
{
SupplierExample
example
=
new
SupplierExample
();
...
...
@@ -414,4 +499,78 @@ public class SupplierService {
info
.
data
=
data
;
return
info
;
}
public
BigDecimal
parseBigDecimalEx
(
String
str
)
throws
Exception
{
if
(!
StringUtil
.
isEmpty
(
str
))
{
return
new
BigDecimal
(
str
);
}
else
{
return
null
;
}
}
public
File
exportExcel
(
List
<
Supplier
>
dataList
,
String
type
)
throws
Exception
{
if
(
"供应商"
.
equals
(
type
))
{
return
exportExcelVendorOrCustomer
(
dataList
,
type
);
}
else
if
(
"客户"
.
equals
(
type
))
{
return
exportExcelVendorOrCustomer
(
dataList
,
type
);
}
else
{
//会员
String
[]
names
=
{
"名称"
,
"联系人"
,
"手机号码"
,
"联系电话"
,
"电子邮箱"
,
"预付款"
,
"备注"
,
"状态"
};
String
title
=
"信息报表"
;
List
<
String
[]>
objects
=
new
ArrayList
<
String
[]>();
if
(
null
!=
dataList
)
{
for
(
Supplier
s
:
dataList
)
{
String
[]
objs
=
new
String
[
15
];
objs
[
0
]
=
s
.
getSupplier
();
objs
[
1
]
=
s
.
getContacts
();
objs
[
2
]
=
s
.
getTelephone
();
objs
[
3
]
=
s
.
getPhoneNum
();
objs
[
4
]
=
s
.
getEmail
();
objs
[
5
]
=
s
.
getAdvanceIn
()
==
null
?
""
:
s
.
getAdvanceIn
().
toString
();
objs
[
6
]
=
s
.
getDescription
();
objs
[
7
]
=
s
.
getEnabled
()
?
"启用"
:
"禁用"
;
objects
.
add
(
objs
);
}
}
return
ExcelUtils
.
exportObjectsWithoutTitle
(
title
,
names
,
title
,
objects
);
}
}
private
File
exportExcelVendorOrCustomer
(
List
<
Supplier
>
dataList
,
String
type
)
throws
Exception
{
String
beginNeedStr
=
""
;
String
allNeedStr
=
""
;
if
(
"供应商"
.
equals
(
type
))
{
beginNeedStr
=
"期初应付"
;
allNeedStr
=
"期末应付"
;
}
else
if
(
"客户"
.
equals
(
type
))
{
beginNeedStr
=
"期初应收"
;
allNeedStr
=
"期末应收"
;
}
String
[]
names
=
{
"名称"
,
"联系人"
,
"手机号码"
,
"联系电话"
,
"电子邮箱"
,
"传真"
,
beginNeedStr
,
allNeedStr
,
"纳税人识别号"
,
"税率(%)"
,
"开户行"
,
"账号"
,
"地址"
,
"备注"
,
"状态"
};
String
title
=
"信息报表"
;
List
<
String
[]>
objects
=
new
ArrayList
<
String
[]>();
if
(
null
!=
dataList
)
{
for
(
Supplier
s
:
dataList
)
{
String
[]
objs
=
new
String
[
15
];
objs
[
0
]
=
s
.
getSupplier
();
objs
[
1
]
=
s
.
getContacts
();
objs
[
2
]
=
s
.
getTelephone
();
objs
[
3
]
=
s
.
getPhoneNum
();
objs
[
4
]
=
s
.
getEmail
();
objs
[
5
]
=
s
.
getFax
();
objs
[
6
]
=
s
.
getBeginNeedPay
()
==
null
?
""
:
s
.
getBeginNeedPay
().
toString
();
objs
[
7
]
=
s
.
getAllNeedPay
()
==
null
?
""
:
s
.
getAllNeedPay
().
toString
();
objs
[
8
]
=
s
.
getTaxNum
();
objs
[
9
]
=
s
.
getTaxRate
()
==
null
?
""
:
s
.
getTaxRate
().
toString
();
objs
[
10
]
=
s
.
getBankName
();
objs
[
11
]
=
s
.
getAccountNumber
();
objs
[
12
]
=
s
.
getAddress
();
objs
[
13
]
=
s
.
getDescription
();
objs
[
14
]
=
s
.
getEnabled
()
?
"启用"
:
"禁用"
;
objects
.
add
(
objs
);
}
}
return
ExcelUtils
.
exportObjectsWithoutTitle
(
title
,
names
,
title
,
objects
);
}
}
Write
Preview
Supports
Markdown
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