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
Springboot Plus
Commits
dd1f72e1
"admin-console/vscode:/vscode.git/clone" did not exist on "c85119ce41a217d21d37cc0674d954216c5e1518"
Commit
dd1f72e1
authored
Mar 11, 2018
by
xiandafu
Browse files
attachement
parent
fa59b9c0
Changes
18
Hide whitespace changes
Inline
Side-by-side
admin-console/src/main/java/com/ibeetl/admin/console/service/UserConsoleService.java
View file @
dd1f72e1
...
@@ -4,6 +4,7 @@ import java.util.ArrayList;
...
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
org.apache.catalina.User
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.beetl.sql.core.engine.PageQuery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -19,6 +20,7 @@ import com.ibeetl.admin.core.conf.PasswordConfig.PasswordEncryptService;
...
@@ -19,6 +20,7 @@ import com.ibeetl.admin.core.conf.PasswordConfig.PasswordEncryptService;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreDict
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.entity.CoreUserRole
;
import
com.ibeetl.admin.core.entity.CoreUserRole
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.rbac.tree.OrgItem
;
import
com.ibeetl.admin.core.rbac.tree.OrgItem
;
import
com.ibeetl.admin.core.service.BaseService
;
import
com.ibeetl.admin.core.service.BaseService
;
import
com.ibeetl.admin.core.service.CoreDictService
;
import
com.ibeetl.admin.core.service.CoreDictService
;
...
@@ -34,6 +36,10 @@ public class UserConsoleService extends BaseService<CoreUser> {
...
@@ -34,6 +36,10 @@ public class UserConsoleService extends BaseService<CoreUser> {
@Autowired
@Autowired
UserConsoleDao
userDao
;
UserConsoleDao
userDao
;
@Autowired
FileService
fileService
;
@Autowired
@Autowired
PasswordEncryptService
passwordEncryptService
;
PasswordEncryptService
passwordEncryptService
;
...
@@ -70,6 +76,11 @@ public class UserConsoleService extends BaseService<CoreUser> {
...
@@ -70,6 +76,11 @@ public class UserConsoleService extends BaseService<CoreUser> {
user
.
setPassword
(
passwordEncryptService
.
password
(
user
.
getPassword
()));
user
.
setPassword
(
passwordEncryptService
.
password
(
user
.
getPassword
()));
user
.
setDelFlag
(
DelFlagEnum
.
NORMAL
.
getValue
());
user
.
setDelFlag
(
DelFlagEnum
.
NORMAL
.
getValue
());
userDao
.
insert
(
user
,
true
);
userDao
.
insert
(
user
,
true
);
if
(
StringUtils
.
isNotEmpty
(
user
.
getAttachmentId
())){
//更新附件详细信息,关联到这个用户
fileService
.
updateFile
(
user
.
getAttachmentId
(),
User
.
class
.
getSimpleName
(),
String
.
valueOf
(
user
.
getId
()));
}
}
}
...
...
admin-console/src/main/java/com/ibeetl/admin/console/web/UserConsoleController.java
View file @
dd1f72e1
...
@@ -7,6 +7,7 @@ import java.io.OutputStream;
...
@@ -7,6 +7,7 @@ import java.io.OutputStream;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Properties
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -66,7 +67,8 @@ public class UserConsoleController {
...
@@ -66,7 +67,8 @@ public class UserConsoleController {
@Autowired
@Autowired
FileService
fileService
;
FileService
fileService
;
/* 页面 */
/* 页面 */
...
...
admin-console/src/main/resources/templates/admin/user/add.html
View file @
dd1f72e1
...
@@ -64,6 +64,11 @@
...
@@ -64,6 +64,11 @@
</div>
</div>
<div
class=
"layui-row"
>
<layui:attachment
name=
"attachmentId"
batchFileUUID=
"${uuid()}"
isNew=
"true"
/>
</div>
<layui:submitButtons
id=
"saveUser"
/>
<layui:submitButtons
id=
"saveUser"
/>
</form>
</form>
...
...
admin-console/src/main/resources/templates/admin/user/edit.html
View file @
dd1f72e1
...
@@ -63,7 +63,9 @@
...
@@ -63,7 +63,9 @@
</div>
</div>
<div
class=
"layui-row"
>
<layui:attachment
name=
"attachmentId"
batchFileUUID=
"${user.attachmentId}"
isNew=
"false"
bizId=
"${user.id}"
bizType=
"User"
/>
</div>
<layui:submitButtons
id=
"saveUser"
/>
<layui:submitButtons
id=
"saveUser"
/>
<input
type=
"hidden"
name=
"id"
value=
${user.id}
/>
<input
type=
"hidden"
name=
"id"
value=
${user.id}
/>
...
...
admin-core/src/main/java/com/ibeetl/admin/core/conf/BeetlConf.java
View file @
dd1f72e1
...
@@ -22,6 +22,7 @@ import com.ibeetl.admin.core.rbac.DataAccess;
...
@@ -22,6 +22,7 @@ import com.ibeetl.admin.core.rbac.DataAccess;
import
com.ibeetl.admin.core.rbac.DataAccessFactory
;
import
com.ibeetl.admin.core.rbac.DataAccessFactory
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.util.beetl.DictQueryFunction
;
import
com.ibeetl.admin.core.util.beetl.DictQueryFunction
;
import
com.ibeetl.admin.core.util.beetl.FileFunction
;
import
com.ibeetl.admin.core.util.beetl.FunAccessUrlFunction
;
import
com.ibeetl.admin.core.util.beetl.FunAccessUrlFunction
;
import
com.ibeetl.admin.core.util.beetl.FunFunction
;
import
com.ibeetl.admin.core.util.beetl.FunFunction
;
import
com.ibeetl.admin.core.util.beetl.MenuFunction
;
import
com.ibeetl.admin.core.util.beetl.MenuFunction
;
...
@@ -29,6 +30,7 @@ import com.ibeetl.admin.core.util.beetl.OrgFunction;
...
@@ -29,6 +30,7 @@ import com.ibeetl.admin.core.util.beetl.OrgFunction;
import
com.ibeetl.admin.core.util.beetl.RoleFunction
;
import
com.ibeetl.admin.core.util.beetl.RoleFunction
;
import
com.ibeetl.admin.core.util.beetl.SearchCondtionFunction
;
import
com.ibeetl.admin.core.util.beetl.SearchCondtionFunction
;
import
com.ibeetl.admin.core.util.beetl.SysFunctionTreeFunction
;
import
com.ibeetl.admin.core.util.beetl.SysFunctionTreeFunction
;
import
com.ibeetl.admin.core.util.beetl.UUIDFunction
;
import
com.ibeetl.admin.core.util.beetl.XXSDefenderFormat
;
import
com.ibeetl.admin.core.util.beetl.XXSDefenderFormat
;
import
com.ibeetl.admin.core.web.query.QueryParser
;
import
com.ibeetl.admin.core.web.query.QueryParser
;
import
com.ibeetl.starter.BeetlTemplateCustomize
;
import
com.ibeetl.starter.BeetlTemplateCustomize
;
...
@@ -55,6 +57,8 @@ public class BeetlConf {
...
@@ -55,6 +57,8 @@ public class BeetlConf {
@Autowired
@Autowired
RoleFunction
roleFunction
;
RoleFunction
roleFunction
;
@Autowired
FileFunction
fileFunction
;
@Autowired
@Autowired
SearchCondtionFunction
searchCondtionFunction
;
SearchCondtionFunction
searchCondtionFunction
;
...
@@ -96,10 +100,10 @@ public class BeetlConf {
...
@@ -96,10 +100,10 @@ public class BeetlConf {
groupTemplate
.
registerFunction
(
"core.menuName"
,
menuFunction
);
groupTemplate
.
registerFunction
(
"core.menuName"
,
menuFunction
);
groupTemplate
.
registerFunction
(
"core.searchCondtion"
,
searchCondtionFunction
);
groupTemplate
.
registerFunction
(
"core.searchCondtion"
,
searchCondtionFunction
);
groupTemplate
.
registerFunction
(
"core.roles"
,
roleFunction
);
groupTemplate
.
registerFunction
(
"core.roles"
,
roleFunction
);
groupTemplate
.
registerFunction
(
"core.file"
,
fileFunction
);
groupTemplate
.
registerFormat
(
"xss"
,
new
XXSDefenderFormat
());
groupTemplate
.
registerFormat
(
"xss"
,
new
XXSDefenderFormat
());
groupTemplate
.
registerFunction
(
"uuid"
,
new
UUIDFunction
());
groupTemplate
.
registerFunctionPackage
(
"dict"
,
dictDownQueryFunction
);
groupTemplate
.
registerFunctionPackage
(
"dict"
,
dictDownQueryFunction
);
// 模板页面判断是否有按钮权限,比如canAccess
// 模板页面判断是否有按钮权限,比如canAccess
groupTemplate
.
registerFunction
(
"canAccess"
,
new
Function
()
{
groupTemplate
.
registerFunction
(
"canAccess"
,
new
Function
()
{
...
...
admin-core/src/main/java/com/ibeetl/admin/core/conf/MVCConf.java
View file @
dd1f72e1
...
@@ -116,100 +116,6 @@ public class MVCConf implements WebMvcConfigurer, InitializingBean {
...
@@ -116,100 +116,6 @@ public class MVCConf implements WebMvcConfigurer, InitializingBean {
}
}
@Override
public
void
addArgumentResolvers
(
List
<
HandlerMethodArgumentResolver
>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addReturnValueHandlers
(
List
<
HandlerMethodReturnValueHandler
>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
addViewControllers
(
ViewControllerRegistry
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureAsyncSupport
(
AsyncSupportConfigurer
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureContentNegotiation
(
ContentNegotiationConfigurer
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureDefaultServletHandling
(
DefaultServletHandlerConfigurer
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureHandlerExceptionResolvers
(
List
<
HandlerExceptionResolver
>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureMessageConverters
(
List
<
HttpMessageConverter
<?>>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configurePathMatch
(
PathMatchConfigurer
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
configureViewResolvers
(
ViewResolverRegistry
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
extendHandlerExceptionResolvers
(
List
<
HandlerExceptionResolver
>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
void
extendMessageConverters
(
List
<
HttpMessageConverter
<?>>
arg0
)
{
// TODO Auto-generated method stub
}
@Override
public
MessageCodesResolver
getMessageCodesResolver
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Validator
getValidator
()
{
// TODO Auto-generated method stub
return
null
;
}
}
}
...
...
admin-core/src/main/java/com/ibeetl/admin/core/dao/CoreFileDao.java
View file @
dd1f72e1
package
com.ibeetl.admin.core.dao
;
package
com.ibeetl.admin.core.dao
;
import
org.beetl.sql.core.annotatoin.Sql
;
import
org.beetl.sql.core.mapper.BaseMapper
;
import
org.beetl.sql.core.mapper.BaseMapper
;
import
com.ibeetl.admin.core.entity.CoreFile
;
import
com.ibeetl.admin.core.entity.CoreFile
;
public
interface
CoreFileDao
extends
BaseMapper
<
CoreFile
>
{
public
interface
CoreFileDao
extends
BaseMapper
<
CoreFile
>
{
@Sql
(
"update core_file set biz_type=?,biz_id=? where file_batch_id=?"
)
public
void
updateBatchIdInfo
(
String
bizType
,
String
bizId
,
String
fileBatchId
);
}
}
admin-core/src/main/java/com/ibeetl/admin/core/entity/BaseEntity.java
View file @
dd1f72e1
...
@@ -16,7 +16,7 @@ public class BaseEntity extends TailBean implements java.io.Serializable {
...
@@ -16,7 +16,7 @@ public class BaseEntity extends TailBean implements java.io.Serializable {
protected
final
static
String
ORACLE_CORE_SEQ_NAME
=
"core_seq"
;
protected
final
static
String
ORACLE_CORE_SEQ_NAME
=
"core_seq"
;
protected
final
static
String
ORACLE_AUDIT_SEQ_NAME
=
"audit_seq"
;
protected
final
static
String
ORACLE_AUDIT_SEQ_NAME
=
"audit_seq"
;
protected
final
static
String
ORACLE_FILE_SEQ_NAME
=
"
fil
e_seq"
;
protected
final
static
String
ORACLE_FILE_SEQ_NAME
=
"
cor
e_seq"
;
@JsonAnyGetter
@JsonAnyGetter
public
Map
<
String
,
Object
>
getTails
(){
public
Map
<
String
,
Object
>
getTails
(){
return
super
.
getTails
();
return
super
.
getTails
();
...
...
admin-core/src/main/java/com/ibeetl/admin/core/entity/CoreFile.java
View file @
dd1f72e1
...
@@ -17,7 +17,7 @@ import com.ibeetl.admin.core.entity.BaseEntity;
...
@@ -17,7 +17,7 @@ import com.ibeetl.admin.core.entity.BaseEntity;
*/
*/
public
class
CoreFile
extends
BaseEntity
{
public
class
CoreFile
extends
BaseEntity
{
@NotNull
(
message
=
"ID不能为空"
,
groups
=
ValidateConfig
.
UPDATE
.
class
)
@NotNull
(
message
=
"ID不能为空"
,
groups
=
ValidateConfig
.
UPDATE
.
class
)
@SeqID
(
name
=
ORACLE_
COR
E_SEQ_NAME
)
@SeqID
(
name
=
ORACLE_
FIL
E_SEQ_NAME
)
@AutoID
@AutoID
private
Long
id
;
private
Long
id
;
// 文件名称
// 文件名称
...
@@ -32,6 +32,8 @@ public class CoreFile extends BaseEntity {
...
@@ -32,6 +32,8 @@ public class CoreFile extends BaseEntity {
private
Date
createTime
;
private
Date
createTime
;
private
Long
orgId
;
private
Long
orgId
;
private
String
bizType
;
private
String
bizType
;
private
String
fileBatchId
;
public
CoreFile
()
{
public
CoreFile
()
{
}
}
...
@@ -149,4 +151,14 @@ public class CoreFile extends BaseEntity {
...
@@ -149,4 +151,14 @@ public class CoreFile extends BaseEntity {
public
void
setBizType
(
String
bizType
)
{
public
void
setBizType
(
String
bizType
)
{
this
.
bizType
=
bizType
;
this
.
bizType
=
bizType
;
}
}
public
String
getFileBatchId
()
{
return
fileBatchId
;
}
public
void
setFileBatchId
(
String
fileBatchId
)
{
this
.
fileBatchId
=
fileBatchId
;
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/entity/CoreUser.java
View file @
dd1f72e1
...
@@ -65,6 +65,8 @@ public class CoreUser extends BaseEntity {
...
@@ -65,6 +65,8 @@ public class CoreUser extends BaseEntity {
private
Date
updateTime
;
private
Date
updateTime
;
/*用户的个人资料附件,保存到Core_File 表里*/
private
String
attachmentId
;
public
String
getCode
()
{
public
String
getCode
()
{
return
code
;
return
code
;
...
@@ -157,6 +159,14 @@ public class CoreUser extends BaseEntity {
...
@@ -157,6 +159,14 @@ public class CoreUser extends BaseEntity {
this
.
updateTime
=
updateTime
;
this
.
updateTime
=
updateTime
;
}
}
public
String
getAttachmentId
()
{
return
attachmentId
;
}
public
void
setAttachmentId
(
String
attachmentId
)
{
this
.
attachmentId
=
attachmentId
;
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/DBIndexHelper.java
View file @
dd1f72e1
...
@@ -37,8 +37,8 @@ public class DBIndexHelper {
...
@@ -37,8 +37,8 @@ public class DBIndexHelper {
public
void
createFileItem
(
CoreFile
file
,
List
<
FileTag
>
tags
)
{
public
void
createFileItem
(
CoreFile
file
,
List
<
FileTag
>
tags
)
{
fileDao
.
insert
(
file
);
fileDao
.
insert
(
file
,
true
);
if
(
tags
.
isEmpty
())
{
if
(
tags
==
null
||
tags
.
isEmpty
())
{
return
;
return
;
}
}
Long
fileId
=
file
.
getId
();
Long
fileId
=
file
.
getId
();
...
@@ -62,6 +62,13 @@ public class DBIndexHelper {
...
@@ -62,6 +62,13 @@ public class DBIndexHelper {
return
dbDatas
;
return
dbDatas
;
}
}
public
List
<
CoreFile
>
queryByBatchId
(
String
batchId
){
CoreFile
template
=
new
CoreFile
();
template
.
setFileBatchId
(
batchId
);
List
<
CoreFile
>
dbDatas
=
fileDao
.
template
(
template
);
return
dbDatas
;
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/FileItem.java
View file @
dd1f72e1
...
@@ -3,6 +3,7 @@ package com.ibeetl.admin.core.file;
...
@@ -3,6 +3,7 @@ package com.ibeetl.admin.core.file;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
public
abstract
class
FileItem
{
public
abstract
class
FileItem
{
protected
Long
id
;
protected
String
name
;
protected
String
name
;
protected
String
path
;
protected
String
path
;
boolean
isTemp
=
false
;
boolean
isTemp
=
false
;
...
@@ -11,7 +12,8 @@ public abstract class FileItem {
...
@@ -11,7 +12,8 @@ public abstract class FileItem {
public
abstract
void
copy
(
OutputStream
os
);
public
abstract
void
copy
(
OutputStream
os
);
public
abstract
void
delete
();
public
abstract
boolean
delete
();
public
String
getName
()
{
public
String
getName
()
{
return
name
;
return
name
;
...
@@ -33,6 +35,14 @@ public abstract class FileItem {
...
@@ -33,6 +35,14 @@ public abstract class FileItem {
public
void
setTemp
(
boolean
isTemp
)
{
public
void
setTemp
(
boolean
isTemp
)
{
this
.
isTemp
=
isTemp
;
this
.
isTemp
=
isTemp
;
}
}
public
Long
getId
()
{
return
id
;
}
public
void
setId
(
Long
id
)
{
this
.
id
=
id
;
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/FileService.java
View file @
dd1f72e1
...
@@ -25,13 +25,28 @@ public interface FileService {
...
@@ -25,13 +25,28 @@ public interface FileService {
* @param tags
* @param tags
* @return
* @return
*/
*/
public
FileItem
createFileItem
(
String
name
,
String
bizType
,
String
bizId
,
Long
userId
,
Long
orgId
,
List
<
FileTag
>
tags
);
public
FileItem
createFileItem
(
String
name
,
String
bizType
,
String
bizId
,
Long
userId
,
Long
orgId
,
String
fileBatchId
,
List
<
FileTag
>
tags
);
public
FileItem
loadFileItemByPath
(
String
path
);
public
FileItem
loadFileItemByPath
(
String
path
);
public
FileItem
getFileItemById
(
Long
id
);
public
FileItem
getFileItemById
(
Long
id
);
public
List
<
FileItem
>
queryByUserId
(
Long
userId
,
List
<
FileTag
>
tags
);
public
List
<
FileItem
>
queryByUserId
(
Long
userId
,
List
<
FileTag
>
tags
);
public
List
<
FileItem
>
queryByBiz
(
String
bizType
,
String
bizId
);
public
List
<
FileItem
>
queryByBiz
(
String
bizType
,
String
bizId
);
public
List
<
FileItem
>
queryByBatchId
(
String
fileBatchId
);
/**
* 删除某个文件
* @param id
* @param fileBatchId,用于验证
*/
public
void
removeFile
(
Long
id
,
String
fileBatchId
);
/**
* 完善附件信息
* @param fileBatchId
* @param bizType
* @param bizId
*/
public
void
updateFile
(
String
fileBatchId
,
String
bizType
,
String
bizId
);
...
...
admin-core/src/main/java/com/ibeetl/admin/core/file/LocalFileItem.java
View file @
dd1f72e1
...
@@ -7,7 +7,11 @@ import java.io.IOException;
...
@@ -7,7 +7,11 @@ import java.io.IOException;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.PlatformException
;
/**
* 本地文件系统
* @author xiandafu
*
*/
class
LocalFileItem
extends
PersistFileItem
{
class
LocalFileItem
extends
PersistFileItem
{
String
root
=
null
;
String
root
=
null
;
public
LocalFileItem
(
String
root
)
{
public
LocalFileItem
(
String
root
)
{
...
@@ -60,11 +64,12 @@ class LocalFileItem extends PersistFileItem{
...
@@ -60,11 +64,12 @@ class LocalFileItem extends PersistFileItem{
}
}
@Override
@Override
public
void
delete
()
{
public
boolean
delete
()
{
File
file
=
new
File
(
root
+
File
.
separator
+
path
);
File
file
=
new
File
(
root
+
File
.
separator
+
path
);
file
.
delete
();
return
file
.
delete
();
}
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/file/LocalFileService.java
View file @
dd1f72e1
...
@@ -2,21 +2,25 @@ package com.ibeetl.admin.core.file;
...
@@ -2,21 +2,25 @@ package com.ibeetl.admin.core.file;
import
java.io.File
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Random
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
com.ibeetl.admin.core.dao.CoreFileDao
;
import
com.ibeetl.admin.core.dao.CoreFileDao
;
import
com.ibeetl.admin.core.entity.CoreFile
;
import
com.ibeetl.admin.core.entity.CoreFile
;
import
com.ibeetl.admin.core.util.DateUtil
;
import
com.ibeetl.admin.core.util.DateUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
import
com.ibeetl.admin.core.util.UUIDUtil
;
/**
/**
* 一个本地文件系统,管理临时文件和用户文件
* 一个本地文件系统,管理临时文件和用户文件
* @author xiandafu
* @author xiandafu
*
*
*/
*/
public
class
LocalFileService
implements
FileService
{
public
class
LocalFileService
implements
FileService
{
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
DBIndexHelper
dbHelper
=
null
;
DBIndexHelper
dbHelper
=
null
;
String
root
=
null
;
String
root
=
null
;
...
@@ -34,7 +38,7 @@ public class LocalFileService implements FileService {
...
@@ -34,7 +38,7 @@ public class LocalFileService implements FileService {
}
}
LocalFileItem
item
=
new
LocalFileItem
(
root
);
LocalFileItem
item
=
new
LocalFileItem
(
root
);
item
.
setPath
(
path
);
item
.
setPath
(
path
);
item
.
setName
(
parseName
(
path
));
item
.
setName
(
parse
TempFile
Name
(
path
));
item
.
setTemp
(
true
);
item
.
setTemp
(
true
);
return
item
;
return
item
;
}
}
...
@@ -50,20 +54,22 @@ public class LocalFileService implements FileService {
...
@@ -50,20 +54,22 @@ public class LocalFileService implements FileService {
}
}
@Override
@Override
public
FileItem
createFileItem
(
String
name
,
String
bizType
,
String
bizId
,
Long
userId
,
Long
orgId
,
List
<
FileTag
>
tags
)
{
public
FileItem
createFileItem
(
String
name
,
String
bizType
,
String
bizId
,
Long
userId
,
Long
orgId
,
String
fileBatchId
,
List
<
FileTag
>
tags
)
{
CoreFile
coreFile
=
new
CoreFile
();
CoreFile
coreFile
=
new
CoreFile
();
coreFile
.
setBizId
(
bizId
);
coreFile
.
setBizId
(
bizId
);
coreFile
.
setBizType
(
bizType
);
coreFile
.
setBizType
(
bizType
);
coreFile
.
setUserId
(
userId
);
coreFile
.
setUserId
(
userId
);
coreFile
.
setOrgId
(
orgId
);
coreFile
.
setOrgId
(
orgId
);
coreFile
.
setName
(
name
);
coreFile
.
setName
(
name
);
String
dir
=
DateUtil
.
now
();
coreFile
.
setCreateTime
(
new
Date
());
File
file
=
new
File
(
root
+
File
.
separator
+
dir
);
coreFile
.
setFileBatchId
(
fileBatchId
);
if
(!
file
.
exists
())
{
String
dir
=
DateUtil
.
now
(
"yyyyMMdd"
);
file
.
mkdirs
();
File
dirFile
=
new
File
(
root
+
File
.
separator
+
dir
);
if
(!
dirFile
.
exists
())
{
dirFile
.
mkdirs
();
}
}
String
fileName
=
name
+
"."
+
suffix
();
String
fileName
=
name
+
"."
+
UUIDUtil
.
uuid
();
String
path
=
root
+
File
.
separator
+
dir
+
File
.
separator
+
fileName
;
String
path
=
dir
+
File
.
separator
+
fileName
;
coreFile
.
setPath
(
path
);
coreFile
.
setPath
(
path
);
//目前忽略tags
//目前忽略tags
dbHelper
.
createFileItem
(
coreFile
,
tags
);
dbHelper
.
createFileItem
(
coreFile
,
tags
);
...
@@ -75,12 +81,15 @@ public class LocalFileService implements FileService {
...
@@ -75,12 +81,15 @@ public class LocalFileService implements FileService {
private
String
suffix
()
{
private
String
suffix
()
{
// TODO,改成唯一算法
// TODO,改成唯一算法
return
System
.
currentTimeMillis
()
+
""
+
new
Random
().
nextInt
(
10000
);
return
DateUtil
.
now
(
"yyyyMMddhhmm"
)
+
"
-
"
+
UUIDUtil
.
uuid
(
);
}
}
private
String
parseName
(
String
path
)
{
private
String
parse
TempFile
Name
(
String
path
)
{
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
return
file
.
getName
();
String
name
=
file
.
getName
();
//去掉最后的临时标记
int
index
=
name
.
lastIndexOf
(
"."
);
return
name
.
substring
(
0
,
index
);
}
}
protected
FileItem
getFileItem
(
CoreFile
file
)
{
protected
FileItem
getFileItem
(
CoreFile
file
)
{
...
@@ -91,6 +100,7 @@ public class LocalFileService implements FileService {
...
@@ -91,6 +100,7 @@ public class LocalFileService implements FileService {
item
.
setBizType
(
file
.
getBizType
());
item
.
setBizType
(
file
.
getBizType
());
item
.
setId
(
file
.
getId
());
item
.
setId
(
file
.
getId
());
item
.
setOrgId
(
file
.
getOrgId
());
item
.
setOrgId
(
file
.
getOrgId
());
item
.
setId
(
file
.
getId
());
return
item
;
return
item
;
}
}
...
@@ -119,6 +129,35 @@ public class LocalFileService implements FileService {
...
@@ -119,6 +129,35 @@ public class LocalFileService implements FileService {
public
List
<
FileItem
>
queryByBiz
(
String
bizType
,
String
bizId
)
{
public
List
<
FileItem
>
queryByBiz
(
String
bizType
,
String
bizId
)
{
return
this
.
getFileItem
(
dbHelper
.
queryByBiz
(
bizType
,
bizId
));
return
this
.
getFileItem
(
dbHelper
.
queryByBiz
(
bizType
,
bizId
));
}
}
@Override
public
List
<
FileItem
>
queryByBatchId
(
String
fileBatchId
)
{
return
this
.
getFileItem
(
dbHelper
.
queryByBatchId
(
fileBatchId
));
}
@Override
public
void
removeFile
(
Long
id
,
String
fileBatchId
)
{
CoreFile
file
=
dbHelper
.
getFileItemById
(
id
);
if
(!
file
.
getFileBatchId
().
equals
(
fileBatchId
)){
return
;
}
FileItem
item
=
this
.
getFileItem
(
file
);
boolean
success
=
item
.
delete
();
if
(!
success
)
{
log
.
warn
(
"删除文件失败 "
+
file
.
getName
()+
",id="
+
file
.
getId
()+
" path="
+
file
.
getPath
());
throw
new
PlatformException
(
"删除文件失败 "
+
file
.
getName
());
}
dbHelper
.
fileDao
.
deleteById
(
id
);
return
;
}
@Override
public
void
updateFile
(
String
fileBatchId
,
String
bizType
,
String
bizId
)
{
dbHelper
.
fileDao
.
updateBatchIdInfo
(
bizType
,
bizId
,
fileBatchId
);
}
...
...
admin-core/src/main/java/com/ibeetl/admin/core/util/DateUtil.java
View file @
dd1f72e1
...
@@ -8,4 +8,9 @@ public class DateUtil {
...
@@ -8,4 +8,9 @@ public class DateUtil {
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
return
sdf
.
format
(
new
Date
());
return
sdf
.
format
(
new
Date
());
}
}
public
static
String
now
(
String
format
)
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
format
);
return
sdf
.
format
(
new
Date
());
}
}
}
admin-core/src/main/java/com/ibeetl/admin/core/web/FileSystemContorller.java
View file @
dd1f72e1
package
com.ibeetl.admin.core.web
;
package
com.ibeetl.admin.core.web
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
...
@@ -10,18 +10,27 @@ import org.apache.commons.logging.Log;
...
@@ -10,18 +10,27 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.ModelAndView
;
import
com.ibeetl.admin.core.entity.CoreOrg
;
import
com.ibeetl.admin.core.entity.CoreUser
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileItem
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.file.FileService
;
import
com.ibeetl.admin.core.service.CorePlatformService
;
import
com.ibeetl.admin.core.util.FileUtil
;
import
com.ibeetl.admin.core.util.FileUtil
;
import
com.ibeetl.admin.core.util.PlatformException
;
@Controller
@Controller
public
class
FileSystemContorller
{
public
class
FileSystemContorller
{
private
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
private
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
());
@Autowired
CorePlatformService
platformService
;
private
static
final
String
MODEL
=
"/core/file"
;
private
static
final
String
MODEL
=
"/core/file"
;
@Autowired
@Autowired
FileService
fileService
;
FileService
fileService
;
...
@@ -37,6 +46,26 @@ public class FileSystemContorller {
...
@@ -37,6 +46,26 @@ public class FileSystemContorller {
}
}
return
null
;
return
null
;
}
}
@PostMapping
(
MODEL
+
"/upload.json"
)
@ResponseBody
public
JsonResult
upload
(
@RequestParam
(
"file"
)
MultipartFile
file
,
String
batchFileUUID
,
String
bizType
,
String
bizId
)
throws
IOException
{
if
(
file
.
isEmpty
())
{
return
JsonResult
.
fail
();
}
CoreUser
user
=
platformService
.
getCurrentUser
();
CoreOrg
org
=
platformService
.
getCurrentOrg
();
FileItem
fileItem
=
fileService
.
createFileItem
(
file
.
getOriginalFilename
(),
bizType
,
bizId
,
user
.
getId
(),
org
.
getId
(),
batchFileUUID
,
null
);
OutputStream
os
=
fileItem
.
openOutpuStream
();
FileUtil
.
copy
(
file
.
getInputStream
(),
os
);
return
JsonResult
.
success
(
fileItem
);
}
@PostMapping
(
MODEL
+
"/deleteFile.json"
)
@ResponseBody
public
JsonResult
deleteFile
(
Long
fileId
,
String
batchFileUUID
)
throws
IOException
{
fileService
.
removeFile
(
fileId
,
batchFileUUID
);
return
JsonResult
.
success
();
}
@GetMapping
(
MODEL
+
"/downloadTemplate.do"
)
@GetMapping
(
MODEL
+
"/downloadTemplate.do"
)
public
ModelAndView
dowloadTemplate
(
HttpServletResponse
response
,
String
path
)
throws
IOException
{
public
ModelAndView
dowloadTemplate
(
HttpServletResponse
response
,
String
path
)
throws
IOException
{
...
...
pom.xml
View file @
dd1f72e1
...
@@ -8,9 +8,7 @@
...
@@ -8,9 +8,7 @@
<properties>
<properties>
<java.version>
1.8
</java.version>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<fastjson.version>
1.2.28
</fastjson.version>
<commons-lang3.version>
3.3.2
</commons-lang3.version>
<commons-lang3.version>
3.3.2
</commons-lang3.version>
<joda-time.version>
2.9.7
</joda-time.version>
</properties>
</properties>
<modules>
<modules>
<module>
admin-core
</module>
<module>
admin-core
</module>
...
...
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