Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
OSmall
/
linjiashop
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 6eec7f4b
authored
Dec 28, 2020
by
王能兵
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'dev' into 'master'
Dev See merge request
!9
2 parents
04abd67c
b13259ed
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
444 additions
and
44 deletions
doc/database-open-platform.sql
doc/database.sql
doc/http-request/http-client.env.json
shop-core/src/main/java/com/glsx/shop/bean/dto/AppUserDTO.java
shop-core/src/main/java/com/glsx/shop/bean/entity/cms/Banner.java
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/Goods.java
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/PlatformUser.java
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/TuYaUser.java
shop-core/src/main/java/com/glsx/shop/dao/shop/TuYaUserRepository.java
shop-core/src/main/java/com/glsx/shop/security/UserService.java
shop-core/src/main/java/com/glsx/shop/service/shop/TuYaUserService.java
shop-core/src/main/java/com/glsx/shop/service/system/FileService.java
shop-core/src/main/java/com/glsx/shop/web/controller/FileController.java
doc/database-open-platform.sql
View file @
6eec7f4
...
...
@@ -22,7 +22,7 @@ CREATE TABLE `t_platform_customer`
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`contact_channel_number`
(
`contact_number`
,
`channel_number`
),
UNIQUE
KEY
`customer_name`
(
`customer_name`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'客户管理表'
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
00000
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'客户管理表'
;
DROP
TABLE
IF
EXISTS
`t_platform_secretkey`
;
CREATE
TABLE
`t_platform_secretkey`
...
...
@@ -69,7 +69,6 @@ CREATE TABLE `t_platform_user`
`last_login_time`
DATETIME
DEFAULT
NULL
COMMENT
'最后登录时间'
,
`status`
TINYINT
(
2
)
DEFAULT
1
COMMENT
'用户状态 0 注销 1 正常'
,
`app_account_id`
INT
(
11
)
DEFAULT
NULL
COMMENT
'APP 账户ID'
,
`tu_ya_id`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'涂鸦平台ID'
,
`create_time`
DATETIME
DEFAULT
NULL
COMMENT
'创建时间 注册时间'
,
`update_time`
DATETIME
DEFAULT
NULL
COMMENT
'更新时间'
,
`create_by`
INT
(
11
)
DEFAULT
NULL
COMMENT
'创建人'
,
...
...
@@ -77,7 +76,22 @@ CREATE TABLE `t_platform_user`
`remark`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'备注'
,
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`contact_number`
(
`contact_number`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'用户管理表'
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
10000000
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'用户管理表'
;
DROP
TABLE
IF
EXISTS
`t_tuya_user`
;
CREATE
TABLE
`t_tuya_user`
(
`id`
INT
(
11
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'主键'
,
`nickname`
VARCHAR
(
32
)
DEFAULT
NULL
COMMENT
'昵称,账号'
,
`contact_number`
VARCHAR
(
11
)
DEFAULT
NULL
COMMENT
'联系电话'
,
`password`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'密码'
,
`channel`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'渠道'
,
`status`
TINYINT
(
2
)
DEFAULT
'1'
COMMENT
'用户状态 0 注销 1 正常'
,
`tuya_id`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'涂鸦平台ID'
,
`create_time`
DATETIME
DEFAULT
NULL
COMMENT
'创建时间 注册时间'
,
`remark`
VARCHAR
(
50
)
DEFAULT
NULL
COMMENT
'备注'
,
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`contact_number`
(
`contact_number`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COMMENT
=
'涂鸦用户表'
;
DROP
TABLE
IF
EXISTS
`t_platform_api`
;
CREATE
TABLE
`t_platform_api`
...
...
doc/database.sql
View file @
6eec7f4
...
...
@@ -53,7 +53,7 @@ CREATE TABLE `t_cms_banner` (
`create_time`
datetime
DEFAULT
NULL
COMMENT
'创建时间/注册时间'
,
`modify_by`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'最后更新人'
,
`modify_time`
datetime
DEFAULT
NULL
COMMENT
'最后更新时间'
,
`id_file`
varchar
(
64
)
DEFAULT
NULL
COMMENT
'banner图id'
,
`id_file`
varchar
(
128
)
DEFAULT
NULL
COMMENT
'banner图id'
,
`page`
varchar
(
64
)
DEFAULT
NULL
COMMENT
'界面'
,
`param`
varchar
(
128
)
DEFAULT
NULL
COMMENT
'参数'
,
`title`
varchar
(
64
)
DEFAULT
NULL
COMMENT
'标题'
,
...
...
@@ -414,7 +414,7 @@ CREATE TABLE `t_shop_goods` (
`modify_time`
datetime
DEFAULT
NULL
COMMENT
'最后更新时间'
,
`descript`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'产品简介'
,
`detail`
text
COMMENT
'产品详情'
,
`gallery`
varchar
(
512
)
DEFAULT
NULL
COMMENT
'大图相册列表,以逗号分隔'
,
`gallery`
text
DEFAULT
NULL
COMMENT
'大图相册列表,以逗号分隔'
,
`id_category`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'类别id'
,
`is_delete`
tinyint
(
4
)
DEFAULT
NULL
COMMENT
'是否删除'
,
`is_hot`
tinyint
(
4
)
DEFAULT
NULL
COMMENT
'是否人气商品'
,
...
...
@@ -422,7 +422,8 @@ CREATE TABLE `t_shop_goods` (
`is_on_sale`
tinyint
(
4
)
DEFAULT
NULL
COMMENT
'是否上架'
,
`like_num`
int
(
11
)
DEFAULT
NULL
COMMENT
'收藏数'
,
`name`
varchar
(
32
)
DEFAULT
NULL
COMMENT
'名称'
,
`pic`
varchar
(
64
)
DEFAULT
NULL
COMMENT
'小图'
,
`pic`
varchar
(
100
)
DEFAULT
NULL
COMMENT
'小图'
,
`marketing_price`
varchar
(
32
)
DEFAULT
NULL
COMMENT
'市场价,原价'
,
`price`
varchar
(
16
)
DEFAULT
NULL
COMMENT
'价格'
,
`stock`
int
(
11
)
DEFAULT
NULL
COMMENT
'库存数量'
,
PRIMARY
KEY
(
`id`
)
...
...
doc/http-request/http-client.env.json
View file @
6eec7f4
{
"local"
:
{
"domain_admin"
:
"http://localhost:8082"
,
"domain_mobile"
:
"http://localhost:8081"
"domain_admin"
:
"http://localhost:9402/shop-admin"
,
"domain_mobile"
:
"http://localhost:8209/shop-app"
},
"test"
:
{
"domain_admin"
:
"https://aiot-shop-mobile.frontend.test.glsx.com.cn/shop-admin"
,
"domain_mobile"
:
"https://aiot-shop-mobile.frontend.test.glsx.com.cn/shop-app"
}
}
shop-core/src/main/java/com/glsx/shop/bean/dto/AppUserDTO.java
View file @
6eec7f4
...
...
@@ -15,7 +15,9 @@ public class AppUserDTO {
private
String
contactNumber
;
private
String
channel
;
private
String
customerId
;
private
String
channel
;
//涂鸦对应的渠道
private
Integer
appAccountId
;
...
...
shop-core/src/main/java/com/glsx/shop/bean/entity/cms/Banner.java
View file @
6eec7f4
package
com
.
glsx
.
shop
.
bean
.
entity
.
cms
;
import
com.glsx.shop.bean.entity.BaseEntity
;
import
lombok.Data
;
import
org.hibernate.annotations.Table
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.EntityListeners
;
import
javax.validation.constraints.NotBlank
;
import
com.glsx.shop.bean.entity.BaseEntity
;
import
lombok.Data
;
import
org.hibernate.annotations.Table
;
import
org.springframework.data.jpa.domain.support.AuditingEntityListener
;
@Entity
(
name
=
"t_cms_banner"
)
@Table
(
appliesTo
=
"t_cms_banner"
,
comment
=
"文章"
)
...
...
@@ -23,7 +22,7 @@ public class Banner extends BaseEntity {
@Column
(
columnDefinition
=
"VARCHAR(32) COMMENT '类型'"
)
@NotBlank
(
message
=
"类型不能为空"
)
private
String
type
;
@Column
(
columnDefinition
=
"VARCHAR(
64
) COMMENT 'banner图id'"
)
@Column
(
columnDefinition
=
"VARCHAR(
128
) COMMENT 'banner图id'"
)
private
String
idFile
;
@Column
(
columnDefinition
=
"VARCHAR(64) COMMENT '界面'"
)
private
String
page
;
...
...
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/Goods.java
View file @
6eec7f4
...
...
@@ -27,9 +27,9 @@ public class Goods extends BaseEntity {
@NotBlank
(
message
=
"商品名称不能为空"
)
@Column
(
columnDefinition
=
"VARCHAR(32) COMMENT '名称'"
)
private
String
name
;
@Column
(
columnDefinition
=
"VARCHAR(
64
) COMMENT '小图'"
)
@Column
(
columnDefinition
=
"VARCHAR(
128
) COMMENT '小图'"
)
private
String
pic
;
@Column
(
columnDefinition
=
"
VARCHAR(512)
COMMENT '大图相册列表,以逗号分隔'"
)
@Column
(
columnDefinition
=
"
TEXT
COMMENT '大图相册列表,以逗号分隔'"
)
private
String
gallery
;
@Column
(
name
=
"id_category"
,
columnDefinition
=
"BIGINT COMMENT '类别id'"
)
private
Long
idCategory
;
...
...
@@ -51,6 +51,8 @@ public class Goods extends BaseEntity {
*/
@Column
(
columnDefinition
=
"VARCHAR(16) COMMENT '价格'"
)
private
BigDecimal
price
;
@Column
(
name
=
"marketing_price"
,
columnDefinition
=
"VARCHAR(32) COMMENT '市场价,原价'"
)
private
BigDecimal
marketingPrice
;
@Column
(
columnDefinition
=
"tinyint COMMENT '是否删除'"
)
private
Boolean
isDelete
=
false
;
@Column
(
columnDefinition
=
"tinyint COMMENT '是否上架'"
)
...
...
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/PlatformUser.java
View file @
6eec7f4
...
...
@@ -17,7 +17,7 @@ import java.util.Date;
* @date :Created in 2019/10/29 17:41
*/
@Data
@Table
(
appliesTo
=
"t_platform_user"
,
comment
=
"
用户管理
表"
)
@Table
(
appliesTo
=
"t_platform_user"
,
comment
=
"
平台用户
表"
)
@Entity
(
name
=
"t_platform_user"
)
@JsonIgnoreProperties
(
value
=
{
"hibernateLazyInitializer"
,
"handler"
})
public
class
PlatformUser
implements
Serializable
{
...
...
@@ -44,8 +44,6 @@ public class PlatformUser implements Serializable {
private
Integer
status
;
@Column
(
columnDefinition
=
"INT(11) COMMENT 'APP 账户ID'"
)
private
Integer
appAccountId
;
@Column
(
columnDefinition
=
"VARCHAR(50) COMMENT '涂鸦平台ID'"
)
private
String
tuYaId
;
@Column
(
columnDefinition
=
"INT(11) COMMENT '创建人'"
)
private
Integer
createBy
;
@Column
(
columnDefinition
=
"INT(11) COMMENT '更新人'"
)
...
...
shop-core/src/main/java/com/glsx/shop/bean/entity/shop/TuYaUser.java
0 → 100644
View file @
6eec7f4
package
com
.
glsx
.
shop
.
bean
.
entity
.
shop
;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
lombok.Data
;
import
org.hibernate.annotations.Table
;
import
org.springframework.data.annotation.CreatedDate
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* @author glsx
* @date :Created in 2019/10/29 17:41
*/
@Data
@Table
(
appliesTo
=
"t_tuya_user"
,
comment
=
"涂鸦用户表"
)
@Entity
(
name
=
"t_tuya_user"
)
@JsonIgnoreProperties
(
value
=
{
"hibernateLazyInitializer"
,
"handler"
})
public
class
TuYaUser
implements
Serializable
{
@Id
@GeneratedValue
private
Long
id
;
@CreatedDate
@Column
(
columnDefinition
=
"DATETIME COMMENT '创建时间 注册时间'"
)
private
Date
createTime
;
@Column
(
columnDefinition
=
"VARCHAR(32) COMMENT '昵称,账号'"
)
private
String
nickname
;
@Column
(
columnDefinition
=
"VARCHAR(11) COMMENT '联系电话'"
)
private
String
contactNumber
;
@Column
(
columnDefinition
=
"VARCHAR(50) COMMENT '密码'"
)
private
String
password
;
@Column
(
columnDefinition
=
"VARCHAR(50) COMMENT '渠道'"
)
private
String
channel
;
@Column
(
columnDefinition
=
"TINYINT(11) COMMENT '用户状态 0 注销 1 正常'"
)
private
Integer
status
;
@Column
(
columnDefinition
=
"VARCHAR(50) COMMENT '涂鸦平台ID'"
)
private
String
tuyaId
;
@Column
(
columnDefinition
=
"VARCHAR(50) COMMENT '备注'"
)
private
String
remark
;
}
shop-core/src/main/java/com/glsx/shop/dao/shop/TuYaUserRepository.java
0 → 100644
View file @
6eec7f4
package
com
.
glsx
.
shop
.
dao
.
shop
;
import
com.glsx.shop.bean.entity.shop.TuYaUser
;
import
com.glsx.shop.dao.BaseRepository
;
import
java.util.List
;
public
interface
TuYaUserRepository
extends
BaseRepository
<
TuYaUser
,
Long
>
{
List
<
TuYaUser
>
findByContactNumber
(
String
contactNumber
);
}
shop-core/src/main/java/com/glsx/shop/security/UserService.java
View file @
6eec7f4
...
...
@@ -6,13 +6,14 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.Set
;
import
com.glsx.shop.bean.core.AuthorizationUser
;
import
com.glsx.shop.bean.entity.shop.
Shop
User
;
import
com.glsx.shop.bean.entity.shop.
Platform
User
;
import
com.glsx.shop.bean.entity.system.Role
;
import
com.glsx.shop.bean.entity.system.User
;
import
com.glsx.shop.bean.vo.JwtUser
;
import
com.glsx.shop.bean.vo.SpringContextHolder
;
import
com.glsx.shop.cache.CacheDao
;
import
com.glsx.shop.cache.TokenCache
;
import
com.glsx.shop.dao.shop.PlatformUserRepository
;
import
com.glsx.shop.dao.shop.ShopUserRepository
;
import
com.glsx.shop.dao.system.MenuRepository
;
import
com.glsx.shop.dao.system.RoleRepository
;
...
...
@@ -20,6 +21,7 @@ import com.glsx.shop.dao.system.UserRepository;
import
com.glsx.shop.service.system.impl.ConstantFactory
;
import
com.glsx.shop.utils.Convert
;
import
com.glsx.shop.utils.HttpUtil
;
import
com.glsx.shop.utils.JsonUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -51,6 +53,8 @@ public class UserService {
private
CacheDao
cacheDao
;
@Autowired
private
ShopUserRepository
shopUserRepository
;
@Autowired
private
PlatformUserRepository
platformUserRepository
;
public
static
UserService
me
()
{
return
SpringContextHolder
.
getBean
(
UserService
.
class
);
...
...
@@ -61,6 +65,9 @@ public class UserService {
String
token
=
HttpUtil
.
getToken
();
AuthorizationUser
userBean
=
tokenCache
.
getUser
(
token
);
this
.
logger
.
info
(
"$$$$ getAuthorizationInfo account: {}, userBean = {}"
,
account
,
JsonUtil
.
toJson
(
userBean
));
if
(
userBean
!=
null
)
{
return
userBean
;
}
...
...
@@ -68,6 +75,7 @@ public class UserService {
//构建后台用户认证信息
if
(
userType
==
JwtUser
.
MANAGER
)
{
User
user
=
userRepository
.
findByAccount
(
account
);
this
.
logger
.
info
(
"$$$$ getAuthorizationInfo manager = {}"
,
JsonUtil
.
toJson
(
user
));
userBean
.
setId
(
user
.
getId
());
userBean
.
setAccount
(
user
.
getAccount
());
userBean
.
setDeptId
(
user
.
getDeptid
());
...
...
@@ -97,10 +105,17 @@ public class UserService {
}
//构建前台用户认证信息
if
(
userType
==
JwtUser
.
FRONT_USER
)
{
ShopUser
user
=
shopUserRepository
.
findByMobile
(
account
);
userBean
.
setId
(
user
.
getId
());
userBean
.
setAccount
(
user
.
getMobile
());
userBean
.
setPassword
(
user
.
getPassword
());
// 修改:使用 platform_user 表里面的用户信息进行校验
PlatformUser
platformUser
=
this
.
platformUserRepository
.
findByContactNumber
(
account
);
this
.
logger
.
info
(
"$$$$ getAuthorizationInfo frontUser = {}"
,
JsonUtil
.
toJson
(
platformUser
));
userBean
.
setId
(
platformUser
.
getId
());
userBean
.
setAccount
(
platformUser
.
getContactNumber
());
userBean
.
setPassword
(
platformUser
.
getRemark
());
//ShopUser user = shopUserRepository.findByMobile(account);
//userBean.setId(user.getId());
//userBean.setAccount(user.getMobile());
//userBean.setPassword(user.getPassword());
}
tokenCache
.
setUser
(
token
,
userBean
);
return
userBean
;
...
...
shop-core/src/main/java/com/glsx/shop/service/shop/TuYaUserService.java
0 → 100644
View file @
6eec7f4
package
com
.
glsx
.
shop
.
service
.
shop
;
import
com.glsx.shop.bean.entity.shop.TuYaUser
;
import
com.glsx.shop.dao.shop.TuYaUserRepository
;
import
com.glsx.shop.service.BaseService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Slf4j
@Service
public
class
TuYaUserService
extends
BaseService
<
TuYaUser
,
Long
,
TuYaUserRepository
>
{
@Autowired
private
TuYaUserRepository
tuYaUserRepository
;
public
List
<
TuYaUser
>
findByContactNumber
(
String
contactNumber
)
{
return
tuYaUserRepository
.
findByContactNumber
(
contactNumber
);
}
}
shop-core/src/main/java/com/glsx/shop/service/system/FileService.java
View file @
6eec7f4
package
com
.
glsx
.
shop
.
service
.
system
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedInputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Date
;
...
...
@@ -21,6 +22,7 @@ import com.glsx.shop.cache.TokenCache;
import
com.glsx.shop.dao.system.FileInfoRepository
;
import
com.glsx.shop.security.JwtUtil
;
import
com.glsx.shop.service.BaseService
;
import
com.glsx.shop.utils.HttpUtil
;
import
com.glsx.shop.utils.XlsUtils
;
import
org.jxls.common.Context
;
import
org.jxls.expression.JexlExpressionEvaluator
;
...
...
@@ -29,6 +31,7 @@ import org.jxls.util.JxlsHelper;
import
org.slf4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -133,40 +136,35 @@ public class FileService extends BaseService<FileInfo, Long, FileInfoRepository>
* @return
*/
public
FileInfo
createExcel
(
String
template
,
String
fileName
,
Map
<
String
,
Object
>
data
)
{
FileOutputStream
outputStream
=
null
;
File
file
=
new
File
(
cfgService
.
getCfgValue
(
CfgKey
.
SYSTEM_FILE_UPLOAD_PATH
)
+
File
.
separator
+
UUID
.
randomUUID
().
toString
()
+
".xlsx"
);
try
{
// 定义输出类型
outputStream
=
new
FileOutputStream
(
file
);
HttpServletResponse
response
=
HttpUtil
.
getResponse
();
ServletOutputStream
outputStream
=
response
.
getOutputStream
();
response
.
setHeader
(
HttpHeaders
.
SET_COOKIE
,
"fileDownload=true; path=/"
);
response
.
setHeader
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment;filename=\""
+
fileName
+
"\""
);
response
.
setContentType
(
"application/csv"
);
JxlsHelper
jxlsHelper
=
JxlsHelper
.
getInstance
();
String
templateFile
=
getClass
().
getClassLoader
().
getResource
(
template
).
getPath
();
InputStream
is
=
new
BufferedInputStream
(
new
FileInputStream
(
templateFile
));
Transformer
transformer
=
jxlsHelper
.
createTransformer
(
is
,
outputStream
);
InputStream
templateStream
=
new
BufferedInputStream
(
new
FileInputStream
(
templateFile
));
Transformer
transformer
=
jxlsHelper
.
createTransformer
(
templateStream
,
outputStream
);
Context
context
=
new
Context
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
data
.
entrySet
())
{
context
.
putVar
(
entry
.
getKey
(),
entry
.
getValue
());
}
JexlExpressionEvaluator
evaluator
=
(
JexlExpressionEvaluator
)
transformer
.
getTransformationConfig
().
getExpressionEvaluator
();
JexlExpressionEvaluator
evaluator
=
(
JexlExpressionEvaluator
)
transformer
.
getTransformationConfig
().
getExpressionEvaluator
();
Map
<
String
,
Object
>
funcs
=
new
HashMap
<>(
4
);
funcs
.
put
(
"utils"
,
new
XlsUtils
());
evaluator
.
getJexlEngine
().
setFunctions
(
funcs
);
jxlsHelper
.
processTemplate
(
context
,
transformer
);
outputStream
.
flush
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
outputStream
.
flush
();
outputStream
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
save
(
fileName
,
file
);
return
new
FileInfo
();
}
/**
...
...
shop-core/src/main/java/com/glsx/shop/web/controller/FileController.java
0 → 100644
View file @
6eec7f4
package
com
.
glsx
.
shop
.
web
.
controller
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.glsx.shop.bean.entity.shop.ShopUser
;
import
com.glsx.shop.bean.entity.system.FileInfo
;
import
com.glsx.shop.bean.exception.ApplicationExceptionEnum
;
import
com.glsx.shop.bean.vo.front.Rets
;
import
com.glsx.shop.bean.vo.shop.Base64File
;
import
com.glsx.shop.service.shop.ShopUserService
;
import
com.glsx.shop.service.system.FileService
;
import
com.glsx.shop.utils.CryptUtil
;
import
com.glsx.shop.utils.FdfsUtils
;
import
com.glsx.shop.utils.HttpUtil
;
import
com.glsx.shop.utils.JsonUtil
;
import
com.glsx.shop.utils.Maps
;
import
com.glsx.shop.utils.StringUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestPart
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
@RestController
@RequestMapping
(
"/file"
)
public
class
FileController
extends
BaseController
{
@Autowired
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileController
.
class
);
@Autowired
private
FileService
fileService
;
@Autowired
private
ShopUserService
shopUserService
;
/**
* 上传文件
*
* @param file 文件
* @return 结果
*/
@RequestMapping
(
value
=
"/uploadFile"
,
method
=
{
RequestMethod
.
POST
})
public
Object
uploadFile
(
@RequestPart
(
"file"
)
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
ApplicationExceptionEnum
.
PARAM_ERROR
.
exception
();
}
try
{
String
fileUrl
=
FdfsUtils
.
uploadFile
(
file
);
super
.
logger
.
info
(
"$$$$ /uploadFile result: {}"
,
fileUrl
);
return
Rets
.
success
(
fileUrl
);
}
catch
(
IOException
e
)
{
throw
ApplicationExceptionEnum
.
FILE_UPLOAD_ERROR
.
exception
();
}
}
/**
* 上传多个文件
*
* @param files 文件
* @return 结果
*/
@RequestMapping
(
value
=
"/uploadMultipleFile"
,
method
=
{
RequestMethod
.
POST
})
public
Object
uploadMultipleFile
(
@RequestPart
(
"file"
)
MultipartFile
[]
files
)
{
if
(
files
==
null
||
files
.
length
==
0
)
{
throw
ApplicationExceptionEnum
.
PARAM_ERROR
.
exception
();
}
try
{
List
<
String
>
fileUrlList
=
new
ArrayList
<>();
for
(
MultipartFile
file
:
files
)
{
fileUrlList
.
add
(
FdfsUtils
.
uploadFile
(
file
));
}
super
.
logger
.
info
(
"$$$$ /uploadMultipleFile result: {}"
,
JsonUtil
.
toJson
(
fileUrlList
));
return
Rets
.
success
(
fileUrlList
);
}
catch
(
IOException
e
)
{
throw
ApplicationExceptionEnum
.
FILE_UPLOAD_ERROR
.
exception
();
}
}
/**
* 上传文件
*
* @return 结果
*/
@RequestMapping
(
value
=
"/uploadFile2"
,
method
=
{
RequestMethod
.
POST
})
public
Object
uploadFile2
()
{
String
fileUrl
=
FdfsUtils
.
uploadFile
(
new
byte
[]
{
65
,
10
},
"sql"
);
System
.
out
.
println
(
fileUrl
);
return
Rets
.
success
(
fileUrl
);
}
/**
* 删除服务器上的文件
*
* @param fileUrl 文件路径
* @return 结果
*/
@RequestMapping
(
value
=
"/deleteFile"
,
method
=
{
RequestMethod
.
POST
})
public
Object
deleteFile
(
String
fileUrl
)
{
if
(
StringUtils
.
isBlank
(
fileUrl
))
{
throw
ApplicationExceptionEnum
.
PARAM_ERROR
.
exception
();
}
try
{
super
.
logger
.
info
(
"$$$$ /deleteFile param: {}"
,
fileUrl
);
FdfsUtils
.
deleteFile
(
fileUrl
);
return
Rets
.
success
();
}
catch
(
RuntimeException
e
)
{
throw
ApplicationExceptionEnum
.
FILE_DELETE_ERROR
.
exception
();
}
}
/**
* 上传文件
*
* @param multipartFile
* @return
*/
@RequestMapping
(
value
=
"upload"
,
method
=
RequestMethod
.
POST
)
public
Object
upload
(
@RequestPart
(
"file"
)
MultipartFile
multipartFile
)
{
try
{
FileInfo
fileInfo
=
fileService
.
upload
(
multipartFile
);
return
Rets
.
success
(
fileInfo
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"上传文件异常"
,
e
);
return
Rets
.
failure
(
"上传文件失败"
);
}
}
@RequestMapping
(
value
=
"upload/base64"
,
method
=
RequestMethod
.
POST
)
public
Object
uploadUploadFileBase64
(
@RequestBody
Base64File
base64File
)
{
try
{
FileInfo
fileInfo
=
fileService
.
upload
(
base64File
);
ShopUser
user
=
shopUserService
.
getCurrentUser
();
user
.
setAvatar
(
String
.
valueOf
(
fileInfo
.
getRealFileName
()));
shopUserService
.
update
(
user
);
return
Rets
.
success
(
user
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"上传文件异常"
,
e
);
return
Rets
.
failure
(
"上传文件失败"
);
}
}
/**
* 下载文件
*
* @param fileName
*/
@RequestMapping
(
value
=
"download"
,
method
=
RequestMethod
.
GET
)
public
void
download
(
@RequestParam
(
value
=
"fileName"
,
required
=
false
)
String
fileName
,
@RequestParam
(
value
=
"idFile"
,
required
=
false
)
Long
idFile
)
{
FileInfo
fileInfo
;
if
(
StringUtil
.
isNotEmpty
(
fileName
))
{
fileInfo
=
fileService
.
getByName
(
fileName
);
}
else
if
(
idFile
!=
null
)
{
fileInfo
=
fileService
.
get
(
idFile
);
}
else
{
throw
ApplicationExceptionEnum
.
REQUEST_NULL
.
exception
();
}
fileName
=
fileInfo
.
getOriginalFileName
();
HttpServletResponse
response
=
HttpUtil
.
getResponse
();
response
.
setContentType
(
"application/x-download"
);
try
{
fileName
=
new
String
(
fileName
.
getBytes
(),
"ISO-8859-1"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
fileName
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
int
length
=
1024
;
byte
[]
buffer
=
new
byte
[
length
];
FileInputStream
fis
=
null
;
BufferedInputStream
bis
=
null
;
OutputStream
os
;
try
{
File
file
=
new
File
(
fileInfo
.
getAblatePath
());
os
=
response
.
getOutputStream
();
fis
=
new
FileInputStream
(
file
);
bis
=
new
BufferedInputStream
(
fis
);
int
i
=
bis
.
read
(
buffer
);
while
(
i
!=
-
1
)
{
os
.
write
(
buffer
);
buffer
=
new
byte
[
length
];
i
=
bis
.
read
(
buffer
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"download error"
,
e
);
}
finally
{
try
{
bis
.
close
();
fis
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"close inputstream error"
,
e
);
}
}
}
/**
* 获取base64图片数据
*
* @param fileName
* @return
*/
@RequestMapping
(
value
=
"getImgBase64"
,
method
=
RequestMethod
.
GET
)
public
Object
getImgBase64
(
@RequestParam
(
"idFile"
)
String
fileName
)
{
FileInfo
fileInfo
=
fileService
.
getByName
(
fileName
);
FileInputStream
fis
=
null
;
try
{
File
file
=
new
File
(
fileInfo
.
getAblatePath
());
byte
[]
bytes
=
new
byte
[(
int
)
file
.
length
()];
fis
=
new
FileInputStream
(
file
);
BufferedInputStream
bis
=
new
BufferedInputStream
(
fis
);
bis
.
read
(
bytes
);
String
base64
=
CryptUtil
.
encodeBASE64
(
bytes
);
return
Rets
.
success
(
Maps
.
newHashMap
(
"imgContent"
,
base64
));
}
catch
(
Exception
e
)
{
logger
.
error
(
"get img error"
,
e
);
return
Rets
.
failure
(
"获取图片异常"
);
}
finally
{
try
{
fis
.
close
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"close getImgBase64 error"
,
e
);
}
}
}
/**
* 获取图片流
*
* @param response
* @param fileName
*/
@RequestMapping
(
value
=
"getImgStream"
,
method
=
RequestMethod
.
GET
)
public
void
getImgStream
(
HttpServletResponse
response
,
@RequestParam
(
"idFile"
)
String
fileName
)
{
FileInfo
fileInfo
=
fileService
.
getByName
(
fileName
);
FileInputStream
fis
=
null
;
response
.
setContentType
(
"image/"
+
fileInfo
.
getRealFileName
().
split
(
"\\."
)[
1
]);
try
{
OutputStream
out
=
response
.
getOutputStream
();
File
file
=
new
File
(
fileInfo
.
getAblatePath
());
fis
=
new
FileInputStream
(
file
);
byte
[]
b
=
new
byte
[
fis
.
available
()];
fis
.
read
(
b
);
out
.
write
(
b
);
out
.
flush
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"getImgStream error"
,
e
);
}
finally
{
if
(
fis
!=
null
)
{
try
{
fis
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
"close getImgStream error"
,
e
);
}
}
}
}
}
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