Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
scrm
/
rop-merchant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 1c94c6f7
authored
Aug 02, 2021
by
zhouhb
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]员工导出
1 parent
028701bf
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
494 additions
and
19 deletions
pom.xml
src/main/java/cn/com/glsx/merchants/config/SystemProperty.java
src/main/java/cn/com/glsx/merchants/controller/StaffController.java
src/main/java/cn/com/glsx/merchants/request/staff/StaffExportRequest.java
src/main/java/cn/com/glsx/merchants/response/StaffExportResponse.java
src/main/java/cn/com/glsx/merchants/service/StaffService.java
src/main/java/cn/com/glsx/merchants/util/ExcelUtiles.java
src/main/java/cn/com/glsx/merchants/util/FileUploadServerData.java
src/main/java/cn/com/glsx/merchants/util/FileUploadUtil.java
src/test/java/cn/com/glsx/merchants/controller/BaseControllerTest.java
src/test/java/cn/com/glsx/merchants/controller/StaffControllerTest.java
pom.xml
View file @
1c94c6f
...
...
@@ -48,5 +48,34 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
cn.afterturn
</groupId>
<artifactId>
easypoi-base
</artifactId>
<version>
3.2.0
</version>
<exclusions>
<exclusion>
<artifactId>
slf4j-api
</artifactId>
<groupId>
org.slf4j
</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
cn.afterturn
</groupId>
<artifactId>
easypoi-web
</artifactId>
<version>
3.2.0
</version>
</dependency>
<dependency>
<groupId>
cn.afterturn
</groupId>
<artifactId>
easypoi-annotation
</artifactId>
<version>
3.2.0
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.15
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
src/main/java/cn/com/glsx/merchants/config/SystemProperty.java
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
config
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@ConfigurationProperties
(
"system"
)
@Data
public
class
SystemProperty
{
// 对应配置项:system.name
private
String
name
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
private
String
uploadFileUrl
;
}
src/main/java/cn/com/glsx/merchants/controller/StaffController.java
View file @
1c94c6f
...
...
@@ -9,6 +9,8 @@ import cn.com.glsx.merchants.response.MerchantRopResponse;
import
cn.com.glsx.merchants.response.StaffResponse
;
import
cn.com.glsx.merchants.service.StaffService
;
import
cn.com.glsx.merchants.util.Pagination
;
import
com.rop.AbstractRopRequest
;
import
com.rop.annotation.HttpAction
;
import
com.rop.annotation.NeedInSessionType
;
import
com.rop.annotation.ServiceMethod
;
import
com.rop.annotation.ServiceMethodBean
;
...
...
@@ -39,7 +41,7 @@ public class StaffController {
* @param staffSaveRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
merchant
.saveStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.saveStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"保存员工"
)
public
RopResponse
<
Boolean
>
saveStaff
(
StaffSaveRequest
staffSaveRequest
)
{
try
{
...
...
@@ -57,7 +59,7 @@ public class StaffController {
* @param staffUpdateRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
merchant
.updateStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.updateStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"更新员工"
)
public
RopResponse
<
Boolean
>
updateStaff
(
StaffUpdateRequest
staffUpdateRequest
)
{
try
{
...
...
@@ -75,7 +77,7 @@ public class StaffController {
* @param staffDeleteRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
merchant
.deleteStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.deleteStaff"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"删除员工"
)
public
RopResponse
<
Boolean
>
deleteStaff
(
StaffDeleteRequest
staffDeleteRequest
)
{
try
{
...
...
@@ -93,11 +95,11 @@ public class StaffController {
* @param staffSearchRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
merchant
.staffSearchRequest"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.staffSearchRequest"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"查询员工详情"
)
public
RopResponse
<
StaffResponse
>
findMerchantStaffDetail
(
StaffSearchRequest
staffSearchRequest
)
{
try
{
StaffResponse
staffResponse
=
staffService
.
findMerchantStaffDetail
(
staffSearchRequest
);
StaffResponse
staffResponse
=
staffService
.
findMerchantStaffDetail
(
staffSearchRequest
);
return
RopResponse
.
success
(
staffResponse
);
}
catch
(
RpcServiceException
e
)
{
log
.
info
(
"=======StaffController__invoke__findMerchantStaffDetail__exception:{}"
,
e
.
getMessage
());
...
...
@@ -111,11 +113,11 @@ public class StaffController {
* @param staffListRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
merchant
.findMerchantStaffList"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.findMerchantStaffList"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"查询员工列表"
)
public
RopResponse
<
List
<
StaffResponse
>>
findMerchantStaffList
(
StaffListRequest
staffListRequest
)
{
try
{
List
<
StaffResponse
>
staffResponse
=
staffService
.
findMerchantStaffList
(
staffListRequest
);
List
<
StaffResponse
>
staffResponse
=
staffService
.
findMerchantStaffList
(
staffListRequest
);
return
RopResponse
.
success
(
staffResponse
);
}
catch
(
RpcServiceException
e
)
{
log
.
info
(
"=======StaffController__invoke__findMerchantStaffList__exception:{}"
,
e
.
getMessage
());
...
...
@@ -130,7 +132,7 @@ public class StaffController {
* @param staffPageRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
menu
.findStaffByPage"
,
needInSession
=
NeedInSessionType
.
NO
)
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.
staff
.findStaffByPage"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"查询员工分页列表"
)
public
RopResponse
<
Pagination
<
StaffResponse
>>
findStaffByPage
(
StaffPageRequest
staffPageRequest
)
{
try
{
...
...
@@ -141,4 +143,23 @@ public class StaffController {
return
RopResponse
.
error
(
e
.
getErrId
(),
e
.
getMessage
());
}
}
/**
* 查询员工分页列表
*
* @param staffExportRequest 入参
* @return
*/
@ServiceMethod
(
method
=
"cn.com.glsx.merchants.staff.exportData"
,
needInSession
=
NeedInSessionType
.
NO
)
@ApiOperation
(
"员工导出"
)
public
RopResponse
<
String
>
exportData
(
StaffExportRequest
staffExportRequest
)
{
try
{
String
url
=
staffService
.
exportData
(
staffExportRequest
);
return
RopResponse
.
success
(
url
);
}
catch
(
RpcServiceException
e
)
{
log
.
info
(
"=======MerchantMenuController__invoke__exportData__exception:{}"
,
e
.
getMessage
());
return
RopResponse
.
error
(
e
.
getErrId
(),
e
.
getMessage
());
}
}
}
src/main/java/cn/com/glsx/merchants/request/staff/StaffExportRequest.java
0 → 100644
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
request
.
staff
;
import
cn.com.glsx.merchants.request.DefaultRequest
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* @author zhouhaibao
* @version 1.0
* @description: TODO
* @date 2021/8/2 12:44
*/
public
class
StaffExportRequest
extends
DefaultRequest
{
@ApiModelProperty
(
notes
=
"员工状态"
)
private
Integer
status
;
@ApiModelProperty
(
notes
=
"员工姓名"
)
private
String
staffName
;
@ApiModelProperty
(
notes
=
"员工手机号"
)
private
String
staffPhone
;
@ApiModelProperty
(
notes
=
"创建人"
)
private
String
createdName
;
@ApiModelProperty
(
notes
=
"商户id"
)
private
Integer
merchantId
;
}
src/main/java/cn/com/glsx/merchants/response/StaffExportResponse.java
0 → 100644
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
response
;
import
cn.afterturn.easypoi.excel.annotation.Excel
;
import
cn.afterturn.easypoi.excel.annotation.ExcelIgnore
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.hibernate.validator.constraints.Length
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.List
;
@Data
public
class
StaffExportResponse
implements
Serializable
{
/**
* 员工姓名
*/
@Excel
(
name
=
"员工姓名"
,
orderNum
=
"1"
)
private
String
staffName
;
/**
* 员工编码
*/
@Excel
(
name
=
"员工编码"
,
orderNum
=
"2"
)
private
String
staffCode
;
/**
* 角色名称
*/
@Excel
(
name
=
"角色名称"
,
orderNum
=
"3"
)
private
String
roleName
;
/**
* 手机号
*/
@Excel
(
name
=
"登录手机号"
,
orderNum
=
"4"
)
private
String
staffPhone
;
/**
* 密码
*/
@Excel
(
name
=
"密码"
,
orderNum
=
"5"
)
private
String
password
;
/**
* 创建者
*/
@Excel
(
name
=
"创建者"
,
orderNum
=
"6"
)
private
String
createdAccount
;
/**
* 商户
*/
@Excel
(
name
=
"商户名"
,
orderNum
=
"7"
)
private
String
merchantName
;
/**
* 创建时间
*/
@ExcelIgnore
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
createdTime
;
/**
* 创建时间
*/
@Excel
(
name
=
"创建时间"
,
orderNum
=
"8"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
String
createDate
;
}
\ No newline at end of file
src/main/java/cn/com/glsx/merchants/service/StaffService.java
View file @
1c94c6f
...
...
@@ -3,6 +3,7 @@ package cn.com.glsx.merchants.service;
import
cn.com.glsx.framework.core.beans.rpc.RpcPagination
;
import
cn.com.glsx.framework.core.beans.rpc.RpcResponse
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
cn.com.glsx.merchants.config.SystemProperty
;
import
cn.com.glsx.merchants.convert.ConvertRequest
;
import
cn.com.glsx.merchants.convert.ConvertResponse
;
import
cn.com.glsx.merchants.model.request.MerchantFileRequest
;
...
...
@@ -11,10 +12,15 @@ import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import
cn.com.glsx.merchants.remote.MerchantStaffRemote
;
import
cn.com.glsx.merchants.request.file.FileSaveRequest
;
import
cn.com.glsx.merchants.request.staff.*
;
import
cn.com.glsx.merchants.response.StaffExportResponse
;
import
cn.com.glsx.merchants.response.StaffResponse
;
import
cn.com.glsx.merchants.util.ExcelUtiles
;
import
cn.com.glsx.merchants.util.FileUploadServerData
;
import
cn.com.glsx.merchants.util.FileUploadUtil
;
import
cn.com.glsx.merchants.util.Pagination
;
import
com.glsx.plat.common.annotation.SysLog
;
import
com.glsx.plat.common.enums.OperateType
;
import
com.glsx.plat.common.utils.DateUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -35,7 +41,7 @@ public class StaffService {
private
MerchantStaffRemote
merchantStaffRemote
;
@Autowired
private
MerchantUserService
merchantUserService
;
private
SystemProperty
systemProperty
;
/**
* 保存员工
...
...
@@ -53,7 +59,7 @@ public class StaffService {
private
MerchantStaffRequest
converRequest
(
StaffSaveRequest
staffSaveRequest
)
{
MerchantStaffRequest
merchantStaffRequest
=
ConvertRequest
.
convertRequest
(
staffSaveRequest
,
new
MerchantStaffRequest
());
FileSaveRequest
merchantFileRequest
=
staffSaveRequest
.
getMerchantFileRequest
();
if
(
merchantFileRequest
!=
null
)
{
if
(
merchantFileRequest
!=
null
)
{
merchantStaffRequest
.
setMerchantFileRequest
(
ConvertRequest
.
convertRequest
(
merchantFileRequest
,
new
MerchantFileRequest
()));
}
return
merchantStaffRequest
;
...
...
@@ -130,4 +136,24 @@ public class StaffService {
}
throw
new
RpcServiceException
(
staffByPageRemote
.
getException
().
getErrId
(),
staffByPageRemote
.
getMessage
());
}
/**
* 导出员工
*
* @param staffExportRequest 入参
* @return
*/
public
String
exportData
(
StaffExportRequest
staffExportRequest
)
{
RpcResponse
<
List
<
MerchantStaffResponse
>>
listRpcResponse
=
merchantStaffRemote
.
exportStaffRemote
(
ConvertRequest
.
convertRequest
(
staffExportRequest
,
new
MerchantStaffRequest
()));
if
(
listRpcResponse
.
isSuccess
())
{
List
<
StaffExportResponse
>
staffResponses
=
ConvertResponse
.
convertList
(
listRpcResponse
.
getResult
(),
StaffExportResponse
.
class
);
staffResponses
.
forEach
(
index
->{
index
.
setCreateDate
(
DateUtils
.
format
(
index
.
getCreatedTime
(),
DateUtils
.
NORMAL_DATE_TIME_PATTERN
));
});
byte
[]
bytes
=
ExcelUtiles
.
exportGoodsExcel
(
staffResponses
,
StaffExportResponse
.
class
);
FileUploadServerData
fileUploadServerData
=
FileUploadUtil
.
uploadToFileSystem
(
systemProperty
.
getUploadFileUrl
(),
""
,
bytes
,
"xlsx"
);
return
fileUploadServerData
.
getUrl
();
}
throw
new
RpcServiceException
(
listRpcResponse
.
getException
().
getErrId
(),
listRpcResponse
.
getMessage
());
}
}
src/main/java/cn/com/glsx/merchants/util/ExcelUtiles.java
0 → 100644
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
util
;
import
cn.afterturn.easypoi.excel.ExcelExportUtil
;
import
cn.afterturn.easypoi.excel.ExcelImportUtil
;
import
cn.afterturn.easypoi.excel.entity.ExportParams
;
import
cn.afterturn.easypoi.excel.entity.ImportParams
;
import
cn.afterturn.easypoi.excel.entity.enmus.ExcelType
;
import
cn.afterturn.easypoi.excel.entity.result.ExcelImportResult
;
import
cn.com.glsx.framework.core.exception.ServiceException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.List
;
@Slf4j
public
class
ExcelUtiles
{
/**
* 转换文件内容为流数据
*
* @param content
* @return
*/
public
static
ByteArrayInputStream
parseContentToStream
(
byte
[]
content
)
{
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
content
);
ImportParams
parmas
=
new
ImportParams
();
parmas
.
setNeedVerfiy
(
true
);
return
inputStream
;
}
/**
* 校验参数
*
* @return
*/
public
static
ImportParams
verify
()
{
ImportParams
parmas
=
new
ImportParams
();
parmas
.
setNeedVerfiy
(
false
);
return
parmas
;
}
/**
* 不校验参数
*
* @return
*/
public
static
ImportParams
unVerify
()
{
ImportParams
parmas
=
new
ImportParams
();
parmas
.
setNeedVerfiy
(
false
);
return
parmas
;
}
public
static
byte
[]
exportGoodsExcel
(
List
<?>
list
,
Class
<?>
pojoClass
)
{
ExportParams
exportParams
=
new
ExportParams
();
exportParams
.
setCreateHeadRows
(
true
);
exportParams
.
setType
(
ExcelType
.
HSSF
);
Workbook
workbook
=
ExcelExportUtil
.
exportExcel
(
exportParams
,
pojoClass
,
list
);
byte
[]
barray
=
null
;
if
(
workbook
!=
null
)
{
try
{
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
workbook
.
write
(
bos
);
barray
=
bos
.
toByteArray
();
}
catch
(
Exception
e
)
{
log
.
info
(
"excel导出异常===msg:"
+
e
.
getMessage
());
throw
new
ServiceException
(
"excel异常"
);
}
}
return
barray
;
}
public
static
<
T
>
ExcelImportResult
<
T
>
importExcel
(
byte
[]
content
,
Class
<
T
>
pojoClass
)
{
ByteArrayInputStream
fileInputStream
=
ExcelUtiles
.
parseContentToStream
(
content
);
ExcelImportResult
<
T
>
excelModulList
=
null
;
try
{
excelModulList
=
ExcelImportUtil
.
importExcelMore
(
fileInputStream
,
pojoClass
,
ExcelUtiles
.
verify
());
}
catch
(
Exception
e
)
{
log
.
info
(
"excel导入异常===msg:"
+
e
.
getMessage
());
throw
new
ServiceException
(
"excel异常"
);
}
return
excelModulList
;
}
}
src/main/java/cn/com/glsx/merchants/util/FileUploadServerData.java
0 → 100644
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
util
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.Serializable
;
@SuppressWarnings
(
"serial"
)
public
class
FileUploadServerData
implements
Serializable
{
public
static
final
int
UPLOAD_SUCCSSS
=
0
;
// "上传文件成功!",
public
static
final
int
UPLOAD_FAILURE
=
1
;
// "上传文件失败!"),
//private static final int UPLOAD_TYPE_ERROR = 2; // "上传文件类型错误!"),
//private static final int UPLOAD_OVERSIZE = 3; // "上传文件过大!"),
//private static final int UPLOAD_ZEROSIZE = 4; // "上传文件为空!"),
//private static final int UPLOAD_NOTFOUND = 5; // "上传文件路径错误!")
private
Integer
status
=
0
;
private
String
message
=
""
;
private
String
url
=
""
;
private
String
systemSign
;
private
String
filePath
;
private
String
param1
;
private
String
param2
;
private
String
param3
;
private
String
secureUrl
;
public
Integer
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
status
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getSystemSign
()
{
return
systemSign
;
}
public
void
setSystemSign
(
String
systemSign
)
{
this
.
systemSign
=
systemSign
;
}
public
String
getFilePath
()
{
return
filePath
;
}
public
void
setFilePath
(
String
filePath
)
{
this
.
filePath
=
filePath
;
}
public
String
getParam1
()
{
return
param1
;
}
public
void
setParam1
(
String
param1
)
{
this
.
param1
=
param1
;
}
public
String
getParam2
()
{
return
param2
;
}
public
void
setParam2
(
String
param2
)
{
this
.
param2
=
param2
;
}
public
String
getParam3
()
{
return
param3
;
}
public
void
setParam3
(
String
param3
)
{
this
.
param3
=
param3
;
}
public
String
getSecureUrl
()
{
return
secureUrl
;
}
public
void
setSecureUrl
(
String
secureUrl
)
{
this
.
secureUrl
=
secureUrl
;
}
@Override
public
String
toString
()
{
return
"FileUploadServerData{"
+
"status="
+
status
+
", message='"
+
message
+
'\''
+
", url='"
+
url
+
'\''
+
", systemSign='"
+
systemSign
+
'\''
+
", filePath='"
+
filePath
+
'\''
+
", param1='"
+
param1
+
'\''
+
", param2='"
+
param2
+
'\''
+
", param3='"
+
param3
+
'\''
+
", secureUrl='"
+
secureUrl
+
'\''
+
'}'
;
}
public
FileUploadServerData
()
{
}
public
FileUploadServerData
(
HttpServletRequest
request
)
{
this
.
systemSign
=
request
.
getParameter
(
"systemSign"
);
this
.
filePath
=
request
.
getParameter
(
"filePath"
);
this
.
param1
=
request
.
getParameter
(
"param1"
);
this
.
param2
=
request
.
getParameter
(
"param2"
);
this
.
param3
=
request
.
getParameter
(
"param3"
);
}
}
src/main/java/cn/com/glsx/merchants/util/FileUploadUtil.java
0 → 100644
View file @
1c94c6f
package
cn
.
com
.
glsx
.
merchants
.
util
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.Arrays
;
import
java.util.List
;
/**
* @author wangxw
* @version 1.0.0
* @ClassName FileUploadUtil.java
* @description: 文件上传操作类
* @createTime 2019年11月24日 14:29:00
*/
@Component
public
class
FileUploadUtil
{
public
static
final
String
EXCEL_TYPE_COMPLETE
=
"xlsx,xls,csv"
;
/**
* 校验文件类型
*
* @param fileType
* @return
* @Author zhaojp
* @Date 2019年12月19日 14:11:37
**/
public
static
boolean
verifyFileType
(
String
fileType
)
{
if
(
StringUtils
.
isBlank
(
fileType
))
{
return
false
;
}
List
<
String
>
fileTypes
=
Arrays
.
asList
(
EXCEL_TYPE_COMPLETE
.
split
(
","
));
return
fileTypes
.
contains
(
fileType
);
}
/**
* 将文件上传至文件服务器
*
* @param uploadData
* @param fileType
* @return
*/
public
static
FileUploadServerData
uploadToFileSystem
(
String
url
,
String
fileName
,
byte
[]
uploadData
,
String
fileType
)
{
RestTemplate
restTemplate
=
new
RestTemplate
();
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
form
.
add
(
"systemSign"
,
"biz"
);
form
.
add
(
"filePath"
,
""
);
// fileName由服务端指定
form
.
add
(
"param1"
,
""
);
form
.
add
(
"param2"
,
""
);
form
.
add
(
"param3"
,
""
);
form
.
add
(
"files"
,
fileType
+
"@"
+
Base64
.
encodeBase64String
(
uploadData
));
return
restTemplate
.
postForObject
(
url
,
form
,
FileUploadServerData
.
class
);
}
/**
* 获取文件的名称
*
* @param fileName 文件名 如 开发手册.pdf
* @return 文件名称 如:开发手册
*/
public
static
String
getFilePreName
(
String
fileName
)
{
if
(
fileName
.
contains
(
"."
))
{
int
pointIndex
=
fileName
.
lastIndexOf
(
"."
);
return
fileName
.
substring
(
0
,
pointIndex
);
}
return
fileName
;
}
/**
* 获取文件的类型
*
* @param fileName 文件名 如:开发手册.pdf
* @return 文件后缀:.pdf
*/
public
static
String
getFileTypeByFileName
(
String
fileName
)
{
if
(
fileName
.
contains
(
"."
))
{
int
pointIndex
=
fileName
.
lastIndexOf
(
"."
);
return
fileName
.
substring
(
pointIndex
);
}
return
""
;
}
}
src/test/java/cn/com/glsx/merchants/controller/BaseControllerTest.java
View file @
1c94c6f
...
...
@@ -91,7 +91,7 @@ public class BaseControllerTest {
rest
.
setUriTemplateHandler
(
uriTemplateHandler
);
url
=
url
+
"?"
+
getUrlParamsByMap
(
params
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"TGT"
,
"
8c7547b4-9350-4677-a488-30fa2c070d4d
"
);
headers
.
add
(
"TGT"
,
"
67d3ef25-2da5-4e2d-bbd8-79cb9d10150f
"
);
String
s
=
rest
.
postForObject
(
url
,
new
HttpEntity
<
String
>(
headers
),
String
.
class
);
return
s
;
}
...
...
src/test/java/cn/com/glsx/merchants/controller/StaffControllerTest.java
View file @
1c94c6f
...
...
@@ -24,7 +24,7 @@ public class StaffControllerTest extends BaseControllerTest{
params
.
add
(
"staffJob"
,
"反抗军地方"
);
params
.
add
(
"password"
,
"反抗军地方"
);
params
.
add
(
"visibleInferiorMer"
,
"反抗军地方"
);
params
.
add
(
"staffPhone"
,
"13476565
6511
"
);
params
.
add
(
"staffPhone"
,
"13476565
332E
"
);
params
.
add
(
"merchantId"
,
"31"
);
params
.
add
(
"staffEmail"
,
"31545445@"
);
params
.
add
(
"roleIds[0]"
,
"1"
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment