Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
徐少华
midjourney-proxy
Commits
957ac6e5
Commit
957ac6e5
authored
Jan 30, 2019
by
shuyunhu
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://begitlab.chubanyun.me/rays/pcloud-common-parent
parents
3d06297f
302789f6
Show whitespace changes
Inline
Side-by-side
Showing
50 changed files
with
3528 additions
and
220 deletions
+3528
-220
bootstrap.yml
pcloud-common-config/src/main/resources.prod/bootstrap.yml
+19
-2
public_system.properties
...n-config/src/main/resources.prod/public_system.properties
+3
-0
bootstrap.yml
pcloud-common-config/src/main/resources.uat/bootstrap.yml
+19
-2
public_system.properties
...on-config/src/main/resources.uat/public_system.properties
+3
-0
BacklogQueueBiz.java
...main/java/com/pcloud/common/core/biz/BacklogQueueBiz.java
+19
-0
BacklogQueueBizImpl.java
.../java/com/pcloud/common/core/biz/BacklogQueueBizImpl.java
+39
-0
AppTypeEnum.java
...ain/java/com/pcloud/common/core/constant/AppTypeEnum.java
+6
-1
ConvertEnum.java
...ain/java/com/pcloud/common/core/constant/ConvertEnum.java
+6
-1
MQQueueConstant.java
...java/com/pcloud/common/core/constant/MQQueueConstant.java
+15
-0
MQTopicProducer.java
...java/com/pcloud/common/core/constant/MQTopicProducer.java
+28
-1
ProductTypeConstant.java
.../com/pcloud/common/core/constant/ProductTypeConstant.java
+22
-2
RoleCodeEnum.java
...in/java/com/pcloud/common/core/constant/RoleCodeEnum.java
+2
-1
WeektaskCode.java
...in/java/com/pcloud/common/core/constant/WeektaskCode.java
+67
-0
DataSourceConfig.java
...a/com/pcloud/common/core/datasource/DataSourceConfig.java
+186
-42
BacklogQueueDto.java
...main/java/com/pcloud/common/core/dto/BacklogQueueDto.java
+124
-0
ConvertQueueDto.java
...main/java/com/pcloud/common/core/dto/ConvertQueueDto.java
+18
-2
SendAppMessageDto.java
...in/java/com/pcloud/common/core/dto/SendAppMessageDto.java
+34
-3
AudioDTO.java
...ain/java/com/pcloud/common/core/dto/dubbing/AudioDTO.java
+105
-0
DubbingDTO.java
...n/java/com/pcloud/common/core/dto/dubbing/DubbingDTO.java
+142
-0
DubbingResultDTO.java
.../com/pcloud/common/core/dto/dubbing/DubbingResultDTO.java
+104
-0
SpeechDTO.java
...in/java/com/pcloud/common/core/dto/dubbing/SpeechDTO.java
+54
-0
BacklogTypeEnum.java
...in/java/com/pcloud/common/core/enums/BacklogTypeEnum.java
+29
-0
TranscodeFromEnum.java
.../java/com/pcloud/common/core/enums/TranscodeFromEnum.java
+11
-1
GlobalExceptionHandler.java
.../pcloud/common/core/exception/GlobalExceptionHandler.java
+22
-0
pom.xml
pcloud-common/pom.xml
+10
-7
BasePageRequestVO.java
...main/java/com/pcloud/common/entity/BasePageRequestVO.java
+53
-0
BaseRequestVO.java
...src/main/java/com/pcloud/common/entity/BaseRequestVO.java
+30
-0
AppTypeEnum.java
...on/src/main/java/com/pcloud/common/enums/AppTypeEnum.java
+2
-1
QrcodeTypeEnum.java
...src/main/java/com/pcloud/common/enums/QrcodeTypeEnum.java
+78
-0
DateNewUtils.java
...n/src/main/java/com/pcloud/common/utils/DateNewUtils.java
+1543
-0
FileUtils.java
...mmon/src/main/java/com/pcloud/common/utils/FileUtils.java
+39
-18
ImageUtils.java
...mon/src/main/java/com/pcloud/common/utils/ImageUtils.java
+36
-0
PictureUtil.java
...on/src/main/java/com/pcloud/common/utils/PictureUtil.java
+1
-1
QrcodeUtils.java
...on/src/main/java/com/pcloud/common/utils/QrcodeUtils.java
+37
-0
ResultUtils.java
...on/src/main/java/com/pcloud/common/utils/ResultUtils.java
+20
-0
OssUtils.java
...rc/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
+195
-75
Cookie.java
.../src/main/java/com/pcloud/common/utils/cookie/Cookie.java
+13
-12
WordDataExportor.java
...com/pcloud/common/utils/export/word/WordDataExportor.java
+41
-0
UrlUtils.java
...ain/java/com/pcloud/common/utils/httpclient/UrlUtils.java
+23
-13
MD5.java
...common/src/main/java/com/pcloud/common/utils/rsa/MD5.java
+15
-4
StringTools.java
...main/java/com/pcloud/common/utils/string/StringTools.java
+20
-1
CompressUtils.java
.../main/java/com/pcloud/common/utils/zip/CompressUtils.java
+3
-3
BaseVO.java
pcloud-common/src/main/java/com/pcloud/common/vo/BaseVO.java
+25
-0
pom.xml
pcloud-solr/pom.xml
+73
-0
SolrDto.java
pcloud-solr/src/main/java/com/pcloud/solr/SolrDto.java
+1
-1
SolrQueryParam.java
...ud-solr/src/main/java/com/pcloud/solr/SolrQueryParam.java
+1
-1
SolrResult.java
pcloud-solr/src/main/java/com/pcloud/solr/SolrResult.java
+5
-5
SolrUtils.java
pcloud-solr/src/main/java/com/pcloud/solr/SolrUtils.java
+178
-13
pom.xml
pom.xml
+9
-7
temp.jpg
temp.jpg
+0
-0
No files found.
pcloud-common-config/src/main/resources.prod/bootstrap.yml
View file @
957ac6e5
...
@@ -10,9 +10,26 @@ spring:
...
@@ -10,9 +10,26 @@ spring:
loadbalancer
:
loadbalancer
:
retry
:
retry
:
enabled
:
true
enabled
:
true
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
initialSize
:
2
minIdle
:
5
maxActive
:
50
maxWait
:
60000
timeBetweenEvictionRunsMillis
:
3000
minEvictableIdleTimeMillis
:
3600000
validationQuery
:
SELECT 'x' FROM DUAL
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
poolPreparedStatements
:
true
maxPoolPreparedStatementPerConnectionSize
:
20
connectionPropertiesNew
:
config.decrypt=true;config.decrypt.key=${spring.datasource.publicKey}
filtersNew
:
config
metrics
:
metrics
:
influx
:
influx
:
uri
:
http://192.168.8
3.241
:8086/write
uri
:
http://192.168.8
9.200
:8086/write
step
:
PT10S
step
:
PT10S
db
:
${spring.application.name}
db
:
${spring.application.name}
enabled
:
true
enabled
:
true
...
@@ -32,7 +49,7 @@ spring:
...
@@ -32,7 +49,7 @@ spring:
retry
:
retry
:
max-attempts
:
3
# 最大重试次数
max-attempts
:
3
# 最大重试次数
enabled
:
true
# 是否开启消费者重试(为false时关闭消费者重试,这时消费端代码异常会一直重复收到消息)
enabled
:
true
# 是否开启消费者重试(为false时关闭消费者重试,这时消费端代码异常会一直重复收到消息)
initial-interval
:
5
000
# 重试间隔时间(单位毫秒)
initial-interval
:
300
000
# 重试间隔时间(单位毫秒)
default-requeue-rejected
:
true
# 重试次数超过上面的设置之后是否丢弃(false不丢弃时需要写相应代码将该消息加入死信队列)
default-requeue-rejected
:
true
# 重试次数超过上面的设置之后是否丢弃(false不丢弃时需要写相应代码将该消息加入死信队列)
data
:
data
:
solr
:
solr
:
...
...
pcloud-common-config/src/main/resources.prod/public_system.properties
View file @
957ac6e5
...
@@ -87,3 +87,5 @@ uedThirdPartyOrderUrl=https://rayscloud.chubanyun.net
...
@@ -87,3 +87,5 @@ uedThirdPartyOrderUrl=https://rayscloud.chubanyun.net
system.env
=
pro
system.env
=
pro
jsbj.agent.id
=
1000009100
jsbj.agent.id
=
1000009100
product.parentTutor.proLabelId
=
7461
\ No newline at end of file
pcloud-common-config/src/main/resources.uat/bootstrap.yml
View file @
957ac6e5
...
@@ -10,9 +10,26 @@ spring:
...
@@ -10,9 +10,26 @@ spring:
loadbalancer
:
loadbalancer
:
retry
:
retry
:
enabled
:
true
enabled
:
true
datasource
:
type
:
com.alibaba.druid.pool.DruidDataSource
driver-class-name
:
com.mysql.jdbc.Driver
initialSize
:
2
minIdle
:
5
maxActive
:
50
maxWait
:
60000
timeBetweenEvictionRunsMillis
:
3000
minEvictableIdleTimeMillis
:
3600000
validationQuery
:
SELECT 'x' FROM DUAL
testWhileIdle
:
true
testOnBorrow
:
false
testOnReturn
:
false
poolPreparedStatements
:
true
maxPoolPreparedStatementPerConnectionSize
:
20
connectionPropertiesNew
:
config.decrypt=true;config.decrypt.key=${spring.datasource.publicKey}
filtersNew
:
config
metrics
:
metrics
:
influx
:
influx
:
uri
:
http://192.168.8
3.241
:8086/write
uri
:
http://192.168.8
9.200
:8086/write
step
:
PT10S
step
:
PT10S
db
:
${spring.application.name}
db
:
${spring.application.name}
enabled
:
false
enabled
:
false
...
@@ -32,7 +49,7 @@ spring:
...
@@ -32,7 +49,7 @@ spring:
retry
:
retry
:
max-attempts
:
3
# 最大重试次数
max-attempts
:
3
# 最大重试次数
enabled
:
true
# 是否开启消费者重试(为false时关闭消费者重试,这时消费端代码异常会一直重复收到消息)
enabled
:
true
# 是否开启消费者重试(为false时关闭消费者重试,这时消费端代码异常会一直重复收到消息)
initial-interval
:
5
000
# 重试间隔时间(单位毫秒)
initial-interval
:
300
000
# 重试间隔时间(单位毫秒)
default-requeue-rejected
:
true
# 重试次数超过上面的设置之后是否丢弃(false不丢弃时需要写相应代码将该消息加入死信队列)
default-requeue-rejected
:
true
# 重试次数超过上面的设置之后是否丢弃(false不丢弃时需要写相应代码将该消息加入死信队列)
data
:
data
:
solr
:
solr
:
...
...
pcloud-common-config/src/main/resources.uat/public_system.properties
View file @
957ac6e5
...
@@ -89,3 +89,5 @@ uedThirdPartyOrderUrl=http://deveapi.chubanyun.net
...
@@ -89,3 +89,5 @@ uedThirdPartyOrderUrl=http://deveapi.chubanyun.net
system.env
=
uat
system.env
=
uat
jsbj.agent.id
=
12829
jsbj.agent.id
=
12829
product.parentTutor.proLabelId
=
812
\ No newline at end of file
pcloud-common-core/src/main/java/com/pcloud/common/core/biz/BacklogQueueBiz.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
biz
;
import
com.pcloud.common.core.dto.BacklogQueueDto
;
import
com.pcloud.common.exceptions.BizException
;
/**
* @描述:待办事项统计队列
* @作者:zhuyajie
* @创建时间:10:33 2018/10/31
* @版本:1.0
*/
public
interface
BacklogQueueBiz
{
/**
* 发送待办事项
* @param backlogQueueDto
*/
public
void
sendBacklogQueue
(
BacklogQueueDto
backlogQueueDto
)
throws
BizException
;
}
pcloud-common-core/src/main/java/com/pcloud/common/core/biz/BacklogQueueBizImpl.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
biz
;
import
com.pcloud.common.core.aspect.ParamLog
;
import
com.pcloud.common.core.constant.MQQueueConstant
;
import
com.pcloud.common.core.dto.BacklogQueueDto
;
import
com.pcloud.common.exceptions.BizException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* @描述:待办事务统计
* @作者:zhuyajie
* @创建时间:10:46 2018/10/31
* @版本:1.0
*/
@Component
(
"backlogQueueBiz"
)
public
class
BacklogQueueBizImpl
implements
BacklogQueueBiz
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
BacklogQueueBizImpl
.
class
);
@Autowired
private
AmqpTemplate
amqpTemplate
;
@Override
@ParamLog
(
"发送待办事务通知"
)
public
void
sendBacklogQueue
(
BacklogQueueDto
backlogQueueDto
)
throws
BizException
{
if
(
backlogQueueDto
==
null
)
{
throw
BizException
.
PARAM_IS_NULL
;
}
try
{
amqpTemplate
.
convertAndSend
(
MQQueueConstant
.
BACKLOG
,
backlogQueueDto
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"发送失败,"
+
e
.
getMessage
()
+
","
+
backlogQueueDto
.
toString
(),
e
);
throw
BizException
.
SEND_QUEUE_FAIL
;
}
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/AppTypeEnum.java
View file @
957ac6e5
...
@@ -77,7 +77,12 @@ public enum AppTypeEnum {
...
@@ -77,7 +77,12 @@ public enum AppTypeEnum {
/**
/**
* 打卡
* 打卡
*/
*/
CLOCK
(
"clock"
);
CLOCK
(
"clock"
),
/**
* 伴读魔法箱
*/
AUDIO_MAGIC
(
"magic"
);
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/ConvertEnum.java
View file @
957ac6e5
...
@@ -88,7 +88,12 @@ public enum ConvertEnum {
...
@@ -88,7 +88,12 @@ public enum ConvertEnum {
/**
/**
* 音频纯听
* 音频纯听
*/
*/
AUDIO_LISTEN
(
"AUDIO_LISTEN"
);
AUDIO_LISTEN
(
"AUDIO_LISTEN"
),
/**
* 音频魔法箱
*/
AUDIO_MAGIC
(
"AUDIO_MAGIC"
);
/**
/**
* 值
* 值
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/MQQueueConstant.java
View file @
957ac6e5
...
@@ -16,6 +16,11 @@ public class MQQueueConstant {
...
@@ -16,6 +16,11 @@ public class MQQueueConstant {
public
static
final
String
TEMPLATE
=
"templateQueue"
;
public
static
final
String
TEMPLATE
=
"templateQueue"
;
/**
/**
* 音频配音(MP3)
*/
public
static
final
String
DUBBING
=
"dubbingQueue"
;
/**
* 文件转码(PDF、OFFICE)
* 文件转码(PDF、OFFICE)
*/
*/
public
static
final
String
TRANSCODE
=
"transcodeQueue"
;
public
static
final
String
TRANSCODE
=
"transcodeQueue"
;
...
@@ -86,6 +91,11 @@ public class MQQueueConstant {
...
@@ -86,6 +91,11 @@ public class MQQueueConstant {
public
static
final
String
CONVERT_TO_AUDIOLESSON
=
"convert2AudioLessonQueue"
;
public
static
final
String
CONVERT_TO_AUDIOLESSON
=
"convert2AudioLessonQueue"
;
/**
/**
* 文件转码结束(音视频)->音频课/纯听
*/
public
static
final
String
CONVERT_TO_AUDIOMAGIC
=
"convert2AudioMagicQueue"
;
/**
* 数据埋点
* 数据埋点
*/
*/
public
static
final
String
FRONT_EVENT
=
"frontEventQueue"
;
public
static
final
String
FRONT_EVENT
=
"frontEventQueue"
;
...
@@ -150,4 +160,9 @@ public class MQQueueConstant {
...
@@ -150,4 +160,9 @@ public class MQQueueConstant {
*/
*/
public
static
final
String
DEAD
=
"rays.dlq"
;
public
static
final
String
DEAD
=
"rays.dlq"
;
/**
* 待办事项数量统计
*/
public
static
final
String
BACKLOG
=
"backlogQueue"
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/MQTopicProducer.java
View file @
957ac6e5
...
@@ -17,6 +17,11 @@ public class MQTopicProducer {
...
@@ -17,6 +17,11 @@ public class MQTopicProducer {
public
static
final
String
FILE_TRANSCODE
=
"topic.fileTranscode"
;
public
static
final
String
FILE_TRANSCODE
=
"topic.fileTranscode"
;
/**
/**
* 音频配音结束(MP3)
*/
public
static
final
String
FILE_DUBBING
=
"topic.fileDubbing"
;
/**
* 报名新增用户
* 报名新增用户
*/
*/
public
static
final
String
BM_ADD_USER
=
"topic.bmAddUser"
;
public
static
final
String
BM_ADD_USER
=
"topic.bmAddUser"
;
...
@@ -70,7 +75,14 @@ public class MQTopicProducer {
...
@@ -70,7 +75,14 @@ public class MQTopicProducer {
* TIP
* TIP
*/
*/
public
static
final
String
TIP
=
"topic.tip"
;
public
static
final
String
TIP
=
"topic.tip"
;
/**
* 打赏给读者
*/
public
static
final
String
TIP_FOR_WECHAT_USER
=
"topic.tipForWechatUser"
;
/**
* GENUINE
*/
public
static
final
String
GENUINE
=
"topic.genuine"
;
/**
/**
* 订单完成
* 订单完成
*/
*/
...
@@ -267,6 +279,11 @@ public class MQTopicProducer {
...
@@ -267,6 +279,11 @@ public class MQTopicProducer {
public
static
final
String
RECORD_USER_HABIT
=
"topic.recordUserHabit"
;
public
static
final
String
RECORD_USER_HABIT
=
"topic.recordUserHabit"
;
/**
/**
* 扫码
*/
public
static
final
String
SCAN_QRCODE
=
"topic.scanQrcode"
;
/**
* topic交换机名称(勿改)
* topic交换机名称(勿改)
*/
*/
public
static
final
String
EXCHAGE
=
"rays.topic"
;
public
static
final
String
EXCHAGE
=
"rays.topic"
;
...
@@ -275,4 +292,14 @@ public class MQTopicProducer {
...
@@ -275,4 +292,14 @@ public class MQTopicProducer {
* 更新图书封面图
* 更新图书封面图
*/
*/
public
static
final
String
UPDATE_BOOK_COVERIMG
=
"topic.updateBookCoverImg"
;
public
static
final
String
UPDATE_BOOK_COVERIMG
=
"topic.updateBookCoverImg"
;
/**
* 微信用户关系
*/
public
static
final
String
WECHAT_RELATE_INFO
=
"topic.wechatRelateInfo"
;
/**
* 更新用户头像
*/
public
static
final
String
UPDATE_USER_HEADURL
=
"topic.updateUserHeadUrl"
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/ProductTypeConstant.java
View file @
957ac6e5
...
@@ -223,6 +223,21 @@ public class ProductTypeConstant {
...
@@ -223,6 +223,21 @@ public class ProductTypeConstant {
public
static
final
String
EBOOK_APP
=
"EBOOK_APP"
;
public
static
final
String
EBOOK_APP
=
"EBOOK_APP"
;
/**
/**
* 亲子伴读魔法箱
*/
public
static
final
String
AUDIO_MAGIC
=
"AUDIO_MAGIC"
;
/**
* 音频课
*/
public
static
final
String
AUDIO_SCHEDULE
=
"AUDIO_SCHEDULE"
;
/**
* 音频课程
*/
public
static
final
String
AUDIO_COURSE
=
"AUDIO_COURSE"
;
/**
* 热门作品类型
* 热门作品类型
*/
*/
public
static
final
String
[]
HOT_PRODUCT_TYPE
=
{
QA
,
PDF
,
VIDEO
,
PRETEST
};
public
static
final
String
[]
HOT_PRODUCT_TYPE
=
{
QA
,
PDF
,
VIDEO
,
PRETEST
};
...
@@ -231,7 +246,7 @@ public class ProductTypeConstant {
...
@@ -231,7 +246,7 @@ public class ProductTypeConstant {
* 资源型作品(免费即可体验)
* 资源型作品(免费即可体验)
*/
*/
public
static
final
String
[]
RESOURCE_PRODUCT
=
{
AUDIO
,
VIDEO
,
PDF
,
EBOOK
,
ALBUM
,
PRETEST
,
QANEWS
,
public
static
final
String
[]
RESOURCE_PRODUCT
=
{
AUDIO
,
VIDEO
,
PDF
,
EBOOK
,
ALBUM
,
PRETEST
,
QANEWS
,
FORMAT
,
WORD
,
ARTICLE
,
LISTEN
,
SCHEDULE
,
PBMUSIC
,
TUTORIAL
,
VIDEO_SCHEDULE
};
FORMAT
,
WORD
,
ARTICLE
,
LISTEN
,
SCHEDULE
,
PBMUSIC
,
TUTORIAL
,
VIDEO_SCHEDULE
,
AUDIO_SCHEDULE
};
/**
/**
* 参与促销激励作品
* 参与促销激励作品
...
@@ -248,11 +263,16 @@ public class ProductTypeConstant {
...
@@ -248,11 +263,16 @@ public class ProductTypeConstant {
* 应用型作品(伴随应用使用)
* 应用型作品(伴随应用使用)
*/
*/
public
static
final
String
[]
APP_PRODUCT
=
{
LOOK
,
LIVE
,
TUTOR
,
GROUP
,
ZSCORE
,
VOTE
,
CLOCK
,
TEST
,
AUDIOAPP
,
ANSWER
,
public
static
final
String
[]
APP_PRODUCT
=
{
LOOK
,
LIVE
,
TUTOR
,
GROUP
,
ZSCORE
,
VOTE
,
CLOCK
,
TEST
,
AUDIOAPP
,
ANSWER
,
EF
,
MUSIC
,
VIDEO_COURSE
,
PRETESTAPP
,
AUDIO_RESOURCE
,
QA_APP
,
EBOOK_APP
};
EF
,
MUSIC
,
VIDEO_COURSE
,
PRETESTAPP
,
AUDIO_RESOURCE
,
QA_APP
,
EBOOK_APP
,
AUDIO_MAGIC
};
/**
/**
* 数据平台埋点型作品
* 数据平台埋点型作品
*/
*/
public
static
final
String
[]
TRACK_PRODUCT
=
{
COMMON
,
AUDIO
,
VIDEO
,
PDF
,
EBOOK
,
BOOK
,
MATCH
,
ALBUM
,
NUMBER
,
MEMBER
,
public
static
final
String
[]
TRACK_PRODUCT
=
{
COMMON
,
AUDIO
,
VIDEO
,
PDF
,
EBOOK
,
BOOK
,
MATCH
,
ALBUM
,
NUMBER
,
MEMBER
,
PRETEST
,
QANEWS
,
REVIEW
,
TOOL
,
QS
,
FORMAT
,
WORD
,
ARTICLE
};
PRETEST
,
QANEWS
,
REVIEW
,
TOOL
,
QS
,
FORMAT
,
WORD
,
ARTICLE
};
/**
* 作品下资源来源于content中心的作品
*/
public
static
final
String
[]
RESOURCE_CONTENT_PRODUCT
=
{
AUDIO
,
VIDEO
,
BOOK
,
LISTEN
,
PDF
,
ALBUM
,
FORMAT
,
EBOOK
};
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/RoleCodeEnum.java
View file @
957ac6e5
...
@@ -14,7 +14,8 @@ public enum RoleCodeEnum {
...
@@ -14,7 +14,8 @@ public enum RoleCodeEnum {
merchant
(
"merchant"
),
// 商户
merchant
(
"merchant"
),
// 商户
channel
(
"channel"
),
// 渠道
channel
(
"channel"
),
// 渠道
agent
(
"agent"
),
// 代理
agent
(
"agent"
),
// 代理
adviser
(
"adviser"
);
// 顾问
adviser
(
"adviser"
),
// 顾问
platform
(
"platform"
);
// 平台
/**
/**
* 值
* 值
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/WeektaskCode.java
View file @
957ac6e5
...
@@ -48,6 +48,8 @@ public enum WeektaskCode {
...
@@ -48,6 +48,8 @@ public enum WeektaskCode {
UPDATE_BOOK_INFO
(
"update_book_info"
),
UPDATE_BOOK_INFO
(
"update_book_info"
),
//调整应用顺序
//调整应用顺序
SET_STEP
(
"set_step"
),
SET_STEP
(
"set_step"
),
//确定回复
DEFINITE_REPLY
(
"definite_reply"
),
/**
/**
* -------通用埋点------
* -------通用埋点------
*/
*/
...
@@ -139,6 +141,15 @@ public enum WeektaskCode {
...
@@ -139,6 +141,15 @@ public enum WeektaskCode {
C_PUBLISH_DYNAMIC
(
"c_publish_dynamic"
),
C_PUBLISH_DYNAMIC
(
"c_publish_dynamic"
),
//专题问答设置免费
//专题问答设置免费
SET_FREE
(
"set_free"
),
SET_FREE
(
"set_free"
),
//选择性格心理类场景
CREATE_TEST_CHARACTER
(
"create_test_character"
),
//选择知识抢答类场景
CREATE_TEST_RESPONDER
(
"create_test_responder"
),
//读者圈中加入直播课程
W_POST_LIVEAPP_NOTE
(
"w_post_liveapp_note"
),
//创建专题扩展应用新增栏目
NEW_COLUMN
(
"new_column"
),
//----------------------------------成就任务-------------------
//----------------------------------成就任务-------------------
/**
/**
* 读者在读者圈中发动态
* 读者在读者圈中发动态
...
@@ -651,6 +662,62 @@ public enum WeektaskCode {
...
@@ -651,6 +662,62 @@ public enum WeektaskCode {
*创建抽奖应用
*创建抽奖应用
*/
*/
W5_CREATE_DRAW_APP
(
"w5_create_draw_app"
),
W5_CREATE_DRAW_APP
(
"w5_create_draw_app"
),
/**
*预览效果
*/
W5_CONFIGURE_NEWS
(
"w5_configure_news"
),
/**
*分享排名
*/
W5_SHARE_RANK
(
"w5_share_rank"
),
/**
* 新增性格心理类场景应用(周E3)
*/
W5_CREATE_TEST_CHARACTER
(
"w5_create_test_character"
),
/**
* 新增知识抢答类场景应用(周F3)
*/
W5_CREATE_TEST_RESPONDER
(
"w5_create_test_responder"
),
/**
* 新建直播课应用(周E4)
*/
W5_CREATE_RELATE_LIVEAPP
(
"w5_create_relate_liveapp"
),
/**
* 新建读者交流圈应用(周E5)
*/
W5_CREATE_RELATE_GROUP
(
"w5_create_relate_group"
),
/**
* 新建读书卡片应用(周E6)
*/
W5_CREATE_BOOKCARD
(
"w5_create_bookcard"
),
/**
* 新建电子书应用(周E7)
*/
W5_CREATE_EBOOK
(
"w5_create_ebook"
),
/**
* 新建分数排名应用(周F6)
*/
W5_CREATE_SCORE_APP
(
"w5_create_score_app"
),
/**
* 新建专题扩展应用(周F7)
*/
W5_CREATE_SPECIAL_APP
(
"w5_create_special_app"
),
/**
* 新建作者留言应用(周F8)
*/
W5_CREATE_VOICE_APP
(
"w5_create_voice_app"
),
/**
* 新建报名应用(周F9)
*/
W5_CREATE_BM_APP
(
"w5_create_bm_app"
),
/**
* 新建专家咨询应用(周F4)
*/
W5_CREATE_QA_APP
(
"w5_create_qa_app"
),
/**
*体验专家咨询应用(周F5)
*/
W5_EXPERIENCE_CONSULTING
(
"w5_experience_consulting"
),
;
;
public
final
String
code
;
public
final
String
code
;
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/datasource/DataSourceConfig.java
View file @
957ac6e5
...
@@ -16,6 +16,7 @@ import org.slf4j.Logger;
...
@@ -16,6 +16,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.context.annotation.Primary
;
...
@@ -25,65 +26,48 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
...
@@ -25,65 +26,48 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import
com.alibaba.druid.pool.DruidDataSource
;
import
com.alibaba.druid.pool.DruidDataSource
;
@Configuration
@Configuration
@MapperScan
(
basePackages
=
DataSourceConfig
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory"
)
@ConfigurationProperties
(
prefix
=
"spring.datasource"
)
@MapperScan
(
basePackages
=
DataSourceConfig
.
PACKAGE
,
sqlSessionFactoryRef
=
"sqlSessionFactory"
)
public
class
DataSourceConfig
{
public
class
DataSourceConfig
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DataSourceConfig
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DataSourceConfig
.
class
);
static
final
String
PACKAGE
=
"com.pcloud.common.core.dao"
;
static
final
String
PACKAGE
=
"com.pcloud.common.core.dao"
;
@Value
(
"${spring.datasource.url}"
)
private
String
url
;
private
String
dbUrl
;
@Value
(
"${spring.datasource.type}"
)
private
String
type
;
private
String
dbType
;
@Value
(
"${spring.datasource.username}"
)
private
String
username
;
private
String
username
;
@Value
(
"${spring.datasource.password}"
)
private
String
password
;
private
String
password
;
@Value
(
"${spring.datasource.driver-class-name}"
)
private
String
driverClassName
;
private
String
driverClassName
;
@Value
(
"${spring.datasource.initialSize}"
)
private
int
initialSize
;
private
int
initialSize
;
@Value
(
"${spring.datasource.minIdle}"
)
private
int
minIdle
;
private
int
minIdle
;
@Value
(
"${spring.datasource.maxActive}"
)
private
int
maxActive
;
private
int
maxActive
;
@Value
(
"${spring.datasource.maxWait}"
)
private
int
maxWait
;
private
int
maxWait
;
@Value
(
"${spring.datasource.timeBetweenEvictionRunsMillis}"
)
private
int
timeBetweenEvictionRunsMillis
;
private
int
timeBetweenEvictionRunsMillis
;
@Value
(
"${spring.datasource.minEvictableIdleTimeMillis}"
)
private
int
minEvictableIdleTimeMillis
;
private
int
minEvictableIdleTimeMillis
;
@Value
(
"${spring.datasource.validationQuery}"
)
private
String
validationQuery
;
private
String
validationQuery
;
@Value
(
"${spring.datasource.testWhileIdle}"
)
private
boolean
testWhileIdle
;
private
boolean
testWhileIdle
;
@Value
(
"${spring.datasource.testOnBorrow}"
)
private
boolean
testOnBorrow
;
private
boolean
testOnBorrow
;
@Value
(
"${spring.datasource.testOnReturn}"
)
private
boolean
testOnReturn
;
private
boolean
testOnReturn
;
@Value
(
"${spring.datasource.poolPreparedStatements}"
)
private
boolean
poolPreparedStatements
;
private
boolean
poolPreparedStatements
;
@Value
(
"${spring.datasource.filters}"
)
private
String
filtersNew
;
private
String
filters
;
@Value
(
"${spring.datasource.connectionProperties}"
)
private
String
connectionPropertiesNew
;
private
String
connectionProperties
;
@Value
(
"${mybatis.mapper-locations}"
)
@Value
(
"${mybatis.mapper-locations}"
)
private
String
mapperLocations
;
private
String
mapperLocations
;
...
@@ -91,22 +75,22 @@ public class DataSourceConfig {
...
@@ -91,22 +75,22 @@ public class DataSourceConfig {
@Value
(
"${mybatis.type-aliases-package}"
)
@Value
(
"${mybatis.type-aliases-package}"
)
private
String
typeAliasesPackage
;
private
String
typeAliasesPackage
;
//
@Value("${spring.datasource.useGlobalDataSourceStat}")
//
@Value("${spring.datasource.useGlobalDataSourceStat}")
//
private boolean useGlobalDataSourceStat;
//
private boolean useGlobalDataSourceStat;
//
//
//
@Value("${spring.datasource.druidLoginName}")
//
@Value("${spring.datasource.druidLoginName}")
//
private String druidLoginName;
//
private String druidLoginName;
//
//
//
@Value("${spring.datasource.druidPassword}")
//
@Value("${spring.datasource.druidPassword}")
//
private String druidPassword;
//
private String druidPassword;
@Bean
(
name
=
"druidDataSource"
)
@Bean
(
name
=
"druidDataSource"
)
@Primary
//
不要漏了这
@Primary
//
不要漏了这
public
DataSource
dataSource
()
{
public
DataSource
dataSource
()
{
DruidDataSource
datasource
=
new
DruidDataSource
();
DruidDataSource
datasource
=
new
DruidDataSource
();
try
{
try
{
datasource
.
setUrl
(
this
.
dbU
rl
);
datasource
.
setUrl
(
u
rl
);
datasource
.
setDbType
(
dbT
ype
);
datasource
.
setDbType
(
t
ype
);
datasource
.
setUsername
(
username
);
datasource
.
setUsername
(
username
);
datasource
.
setPassword
(
password
);
datasource
.
setPassword
(
password
);
datasource
.
setDriverClassName
(
driverClassName
);
datasource
.
setDriverClassName
(
driverClassName
);
...
@@ -121,9 +105,9 @@ public class DataSourceConfig {
...
@@ -121,9 +105,9 @@ public class DataSourceConfig {
datasource
.
setTestOnBorrow
(
testOnBorrow
);
datasource
.
setTestOnBorrow
(
testOnBorrow
);
datasource
.
setTestOnReturn
(
testOnReturn
);
datasource
.
setTestOnReturn
(
testOnReturn
);
datasource
.
setPoolPreparedStatements
(
poolPreparedStatements
);
datasource
.
setPoolPreparedStatements
(
poolPreparedStatements
);
datasource
.
setFilters
(
filters
);
datasource
.
setFilters
(
filtersNew
);
datasource
.
setConnectionProperties
(
connectionProperties
);
datasource
.
setConnectionProperties
(
connectionPropertiesNew
);
//
datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
//
datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
ArrayList
<
String
>
arr
=
new
ArrayList
<>();
ArrayList
<
String
>
arr
=
new
ArrayList
<>();
arr
.
add
(
"set names utf8mb4;"
);
arr
.
add
(
"set names utf8mb4;"
);
datasource
.
setConnectionInitSqls
(
arr
);
datasource
.
setConnectionInitSqls
(
arr
);
...
@@ -139,7 +123,6 @@ public class DataSourceConfig {
...
@@ -139,7 +123,6 @@ public class DataSourceConfig {
return
new
DataSourceTransactionManager
(
dataSource
());
return
new
DataSourceTransactionManager
(
dataSource
());
}
}
@Bean
(
name
=
"sqlSessionFactory"
)
@Bean
(
name
=
"sqlSessionFactory"
)
@Autowired
@Autowired
public
SqlSessionFactory
sqlSessionFactory
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
public
SqlSessionFactory
sqlSessionFactory
(
ExecutorInterceptor
interceptor
)
throws
Exception
{
...
@@ -149,7 +132,7 @@ public class DataSourceConfig {
...
@@ -149,7 +132,7 @@ public class DataSourceConfig {
sessionFactoryBean
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
mapperLocations
));
sessionFactoryBean
.
setMapperLocations
(
new
PathMatchingResourcePatternResolver
().
getResources
(
mapperLocations
));
sessionFactoryBean
.
setVfs
(
SpringBootVFS
.
class
);
sessionFactoryBean
.
setVfs
(
SpringBootVFS
.
class
);
sessionFactoryBean
.
setTypeAliasesPackage
(
typeAliasesPackage
);
sessionFactoryBean
.
setTypeAliasesPackage
(
typeAliasesPackage
);
sessionFactoryBean
.
setPlugins
(
new
Interceptor
[]{
interceptor
});
sessionFactoryBean
.
setPlugins
(
new
Interceptor
[]
{
interceptor
});
return
sessionFactoryBean
.
getObject
();
return
sessionFactoryBean
.
getObject
();
}
}
...
@@ -160,4 +143,165 @@ public class DataSourceConfig {
...
@@ -160,4 +143,165 @@ public class DataSourceConfig {
final
SqlSessionTemplate
sessionFactoryBean
=
new
SqlSessionTemplate
(
sqlSessionFactory
(
interceptor
));
final
SqlSessionTemplate
sessionFactoryBean
=
new
SqlSessionTemplate
(
sqlSessionFactory
(
interceptor
));
return
sessionFactoryBean
;
return
sessionFactoryBean
;
}
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getDriverClassName
()
{
return
driverClassName
;
}
public
void
setDriverClassName
(
String
driverClassName
)
{
this
.
driverClassName
=
driverClassName
;
}
public
int
getInitialSize
()
{
return
initialSize
;
}
public
void
setInitialSize
(
int
initialSize
)
{
this
.
initialSize
=
initialSize
;
}
public
int
getMinIdle
()
{
return
minIdle
;
}
public
void
setMinIdle
(
int
minIdle
)
{
this
.
minIdle
=
minIdle
;
}
public
int
getMaxActive
()
{
return
maxActive
;
}
public
void
setMaxActive
(
int
maxActive
)
{
this
.
maxActive
=
maxActive
;
}
public
int
getMaxWait
()
{
return
maxWait
;
}
public
void
setMaxWait
(
int
maxWait
)
{
this
.
maxWait
=
maxWait
;
}
public
int
getTimeBetweenEvictionRunsMillis
()
{
return
timeBetweenEvictionRunsMillis
;
}
public
void
setTimeBetweenEvictionRunsMillis
(
int
timeBetweenEvictionRunsMillis
)
{
this
.
timeBetweenEvictionRunsMillis
=
timeBetweenEvictionRunsMillis
;
}
public
int
getMinEvictableIdleTimeMillis
()
{
return
minEvictableIdleTimeMillis
;
}
public
void
setMinEvictableIdleTimeMillis
(
int
minEvictableIdleTimeMillis
)
{
this
.
minEvictableIdleTimeMillis
=
minEvictableIdleTimeMillis
;
}
public
String
getValidationQuery
()
{
return
validationQuery
;
}
public
void
setValidationQuery
(
String
validationQuery
)
{
this
.
validationQuery
=
validationQuery
;
}
public
boolean
isTestWhileIdle
()
{
return
testWhileIdle
;
}
public
void
setTestWhileIdle
(
boolean
testWhileIdle
)
{
this
.
testWhileIdle
=
testWhileIdle
;
}
public
boolean
isTestOnBorrow
()
{
return
testOnBorrow
;
}
public
void
setTestOnBorrow
(
boolean
testOnBorrow
)
{
this
.
testOnBorrow
=
testOnBorrow
;
}
public
boolean
isTestOnReturn
()
{
return
testOnReturn
;
}
public
void
setTestOnReturn
(
boolean
testOnReturn
)
{
this
.
testOnReturn
=
testOnReturn
;
}
public
boolean
isPoolPreparedStatements
()
{
return
poolPreparedStatements
;
}
public
void
setPoolPreparedStatements
(
boolean
poolPreparedStatements
)
{
this
.
poolPreparedStatements
=
poolPreparedStatements
;
}
public
String
getFiltersNew
()
{
return
filtersNew
;
}
public
void
setFiltersNew
(
String
filtersNew
)
{
this
.
filtersNew
=
filtersNew
;
}
public
String
getConnectionPropertiesNew
()
{
return
connectionPropertiesNew
;
}
public
void
setConnectionPropertiesNew
(
String
connectionPropertiesNew
)
{
this
.
connectionPropertiesNew
=
connectionPropertiesNew
;
}
public
String
getMapperLocations
()
{
return
mapperLocations
;
}
public
void
setMapperLocations
(
String
mapperLocations
)
{
this
.
mapperLocations
=
mapperLocations
;
}
public
String
getTypeAliasesPackage
()
{
return
typeAliasesPackage
;
}
public
void
setTypeAliasesPackage
(
String
typeAliasesPackage
)
{
this
.
typeAliasesPackage
=
typeAliasesPackage
;
}
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/BacklogQueueDto.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
dto
;
import
java.io.Serializable
;
/**
* @描述:待办事务统计
* @作者:zhuyajie
* @创建时间:10:36 2018/10/31
* @版本:1.0
*/
public
class
BacklogQueueDto
implements
Serializable
{
/**
* 编辑id
*/
private
Long
adviserId
;
/**
* 应用id或商品id
*/
private
Long
targetId
;
/**
*类型(APP/PRODUCT)
*/
private
String
targetType
;
/**
*封面图
*/
private
String
coverImg
;
/**
*标题
*/
private
String
title
;
/**
*待审核/确认数量
*/
private
Integer
waitCount
;
/**
*新动态数量
*/
private
Integer
newCount
;
/**
*应用/商品类型编码
*/
private
String
typeCode
;
public
Long
getAdviserId
()
{
return
adviserId
;
}
public
void
setAdviserId
(
Long
adviserId
)
{
this
.
adviserId
=
adviserId
;
}
public
Long
getTargetId
()
{
return
targetId
;
}
public
void
setTargetId
(
Long
targetId
)
{
this
.
targetId
=
targetId
;
}
public
String
getTargetType
()
{
return
targetType
;
}
public
void
setTargetType
(
String
targetType
)
{
this
.
targetType
=
targetType
;
}
public
String
getCoverImg
()
{
return
coverImg
;
}
public
void
setCoverImg
(
String
coverImg
)
{
this
.
coverImg
=
coverImg
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
Integer
getWaitCount
()
{
return
waitCount
;
}
public
void
setWaitCount
(
Integer
waitCount
)
{
this
.
waitCount
=
waitCount
;
}
public
Integer
getNewCount
()
{
return
newCount
;
}
public
void
setNewCount
(
Integer
newCount
)
{
this
.
newCount
=
newCount
;
}
public
String
getTypeCode
()
{
return
typeCode
;
}
public
void
setTypeCode
(
String
typeCode
)
{
this
.
typeCode
=
typeCode
;
}
@Override
public
String
toString
()
{
return
"BacklogQueueDto{"
+
"adviserId="
+
adviserId
+
", targetId="
+
targetId
+
", targetType='"
+
targetType
+
'\''
+
", coverImg='"
+
coverImg
+
'\''
+
", title='"
+
title
+
'\''
+
", waitCount="
+
waitCount
+
", newCount="
+
newCount
+
", typeCode='"
+
typeCode
+
'\''
+
'}'
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/ConvertQueueDto.java
View file @
957ac6e5
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
...
@@ -9,6 +9,7 @@ import java.io.Serializable;
/**
/**
* @描述:
* @描述:
*
* @作者:songx
* @作者:songx
* @创建时间:2017年2月27日,上午11:23:29 @版本:1.0
* @创建时间:2017年2月27日,上午11:23:29 @版本:1.0
*/
*/
...
@@ -41,6 +42,11 @@ public class ConvertQueueDto implements Serializable {
...
@@ -41,6 +42,11 @@ public class ConvertQueueDto implements Serializable {
private
String
customType
;
private
String
customType
;
/**
/**
* 视频截图时间点
*/
private
int
snapshotTime
;
/**
* 来源标识
* 来源标识
*/
*/
private
Long
fromId
;
private
Long
fromId
;
...
@@ -90,6 +96,14 @@ public class ConvertQueueDto implements Serializable {
...
@@ -90,6 +96,14 @@ public class ConvertQueueDto implements Serializable {
*/
*/
private
String
m3u8Url
;
private
String
m3u8Url
;
public
int
getSnapshotTime
()
{
return
snapshotTime
;
}
public
void
setSnapshotTime
(
int
snapshotTime
)
{
this
.
snapshotTime
=
snapshotTime
;
}
public
String
getCustomType
()
{
public
String
getCustomType
()
{
return
customType
;
return
customType
;
}
}
...
@@ -186,7 +200,8 @@ public class ConvertQueueDto implements Serializable {
...
@@ -186,7 +200,8 @@ public class ConvertQueueDto implements Serializable {
}
}
/**
/**
* @param fileUrl The fileUrl to set.
* @param fileUrl
* The fileUrl to set.
*/
*/
public
void
setFileUrl
(
String
fileUrl
)
{
public
void
setFileUrl
(
String
fileUrl
)
{
this
.
fileUrl
=
fileUrl
;
this
.
fileUrl
=
fileUrl
;
...
@@ -200,7 +215,8 @@ public class ConvertQueueDto implements Serializable {
...
@@ -200,7 +215,8 @@ public class ConvertQueueDto implements Serializable {
}
}
/**
/**
* @param fileSize The fileSize to set.
* @param fileSize
* The fileSize to set.
*/
*/
public
void
setFileSize
(
Long
fileSize
)
{
public
void
setFileSize
(
Long
fileSize
)
{
this
.
fileSize
=
fileSize
;
this
.
fileSize
=
fileSize
;
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/SendAppMessageDto.java
View file @
957ac6e5
...
@@ -32,6 +32,14 @@ public class SendAppMessageDto implements Serializable{
...
@@ -32,6 +32,14 @@ public class SendAppMessageDto implements Serializable{
* 模板参数
* 模板参数
*/
*/
private
Map
<
String
,
Object
>
paramKeyMap
;
private
Map
<
String
,
Object
>
paramKeyMap
;
/**
* 设备类型
*/
private
String
deviceType
;
/**
* 应用id
*/
private
Long
appId
;
public
String
getRegistrationId
()
{
public
String
getRegistrationId
()
{
return
registrationId
;
return
registrationId
;
...
@@ -64,12 +72,35 @@ public class SendAppMessageDto implements Serializable{
...
@@ -64,12 +72,35 @@ public class SendAppMessageDto implements Serializable{
public
void
setIsNow
(
Boolean
isNow
)
{
public
void
setIsNow
(
Boolean
isNow
)
{
this
.
isNow
=
isNow
;
this
.
isNow
=
isNow
;
}
}
public
String
getDeviceType
()
{
return
deviceType
;
}
public
void
setDeviceType
(
String
deviceType
)
{
this
.
deviceType
=
deviceType
;
}
public
Long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
Long
appId
)
{
this
.
appId
=
appId
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"SendAppMessageDto [registrationId="
+
registrationId
+
", adviserId="
+
adviserId
+
", typeCode="
return
"SendAppMessageDto{"
+
+
typeCode
+
", isNow="
+
isNow
+
", paramKeyMap="
+
paramKeyMap
+
"]"
;
"registrationId='"
+
registrationId
+
'\''
+
", adviserId="
+
adviserId
+
", typeCode='"
+
typeCode
+
'\''
+
", isNow="
+
isNow
+
", paramKeyMap="
+
paramKeyMap
+
", deviceType='"
+
deviceType
+
'\''
+
", appId="
+
appId
+
'}'
;
}
}
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/dubbing/AudioDTO.java
0 → 100644
View file @
957ac6e5
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
dto
.
dubbing
;
import
java.io.Serializable
;
import
com.alibaba.fastjson.JSONObject
;
/**
*
* @author:songx
* @date:2018年12月5日,下午5:07:40
*/
public
class
AudioDTO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1217229671463911762L
;
/**
* 文件名称
*/
private
String
fileName
;
/**
* 时长
*/
private
int
duration
;
/**
* 文件地址
*/
private
String
fileUrl
;
/**
* 文件大小
*/
private
long
fileSize
;
/**
* 语音文件插入时间点
*/
private
int
start
;
/**
* id
*/
private
int
id
;
public
long
getFileSize
()
{
return
fileSize
;
}
public
void
setFileSize
(
long
fileSize
)
{
this
.
fileSize
=
fileSize
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getFileName
()
{
return
fileName
;
}
public
void
setFileName
(
String
fileName
)
{
this
.
fileName
=
fileName
;
}
public
int
getDuration
()
{
return
duration
;
}
public
void
setDuration
(
int
duration
)
{
this
.
duration
=
duration
;
}
public
String
getFileUrl
()
{
return
fileUrl
;
}
public
void
setFileUrl
(
String
fileUrl
)
{
this
.
fileUrl
=
fileUrl
;
}
public
int
getStart
()
{
return
start
;
}
public
void
setStart
(
int
start
)
{
this
.
start
=
start
;
}
@Override
public
String
toString
()
{
return
"DubbingResultDTO : "
+
JSONObject
.
toJSONString
(
this
);
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/dubbing/DubbingDTO.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
dto
.
dubbing
;
import
java.io.Serializable
;
import
java.util.List
;
import
com.alibaba.fastjson.JSONObject
;
/**
* 绘本配音资源DTO
*
* @author:songx
* @date:2018年12月5日,上午10:07:26
*/
public
class
DubbingDTO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
5639047705106025465L
;
/**
* 用户添加的问题文本(不超过5条)
*/
private
List
<
SpeechDTO
>
speechDTOs
;
/**
* 待合成的背景音乐URL(不超过4条)
*/
private
String
[]
bgms
;
/**
* 录音文件地址
*/
private
String
soundUrl
;
/**
* 来源类型
*/
private
String
fromType
;
/**
* 导语
*/
private
String
beforeText
;
/**
* 结束语
*/
private
String
afterText
;
/**
* 应用ID
*/
private
Long
appId
;
/**
* 编辑ID
*/
private
Long
adviserId
;
/**
* 音乐ID
*/
private
Long
musicId
;
public
String
getSoundUrl
()
{
return
soundUrl
;
}
public
void
setSoundUrl
(
String
soundUrl
)
{
this
.
soundUrl
=
soundUrl
;
}
public
String
getFromType
()
{
return
fromType
;
}
public
void
setFromType
(
String
fromType
)
{
this
.
fromType
=
fromType
;
}
public
String
getBeforeText
()
{
return
beforeText
;
}
public
void
setBeforeText
(
String
beforeText
)
{
this
.
beforeText
=
beforeText
;
}
public
String
getAfterText
()
{
return
afterText
;
}
public
void
setAfterText
(
String
afterText
)
{
this
.
afterText
=
afterText
;
}
public
Long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
Long
appId
)
{
this
.
appId
=
appId
;
}
public
Long
getAdviserId
()
{
return
adviserId
;
}
public
void
setAdviserId
(
Long
adviserId
)
{
this
.
adviserId
=
adviserId
;
}
public
Long
getMusicId
()
{
return
musicId
;
}
public
void
setMusicId
(
Long
musicId
)
{
this
.
musicId
=
musicId
;
}
public
List
<
SpeechDTO
>
getSpeechDTOs
()
{
return
speechDTOs
;
}
public
void
setSpeechDTOs
(
List
<
SpeechDTO
>
speechDTOs
)
{
this
.
speechDTOs
=
speechDTOs
;
}
public
String
[]
getBgms
()
{
return
bgms
;
}
public
void
setBgms
(
String
[]
bgms
)
{
this
.
bgms
=
bgms
;
}
@Override
public
String
toString
()
{
return
"DubbingDTO : "
+
JSONObject
.
toJSONString
(
this
);
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/dubbing/DubbingResultDTO.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
dto
.
dubbing
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.common.core.dto.dubbing.AudioDTO
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* 绘本配音资源DTO
*
* @author:songx
* @date:2018年12月5日,上午10:07:26
*/
public
class
DubbingResultDTO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
2458000180158610651L
;
/**
* 来源类型
*/
private
String
fromType
;
/**
* 语音文件
*/
private
List
<
AudioDTO
>
speechs
;
/**
* 混合音频
*/
private
AudioDTO
mixAudio
;
/**
* 应用ID
*/
private
Long
appId
;
/**
* 编辑ID
*/
private
Long
adviserId
;
/**
* 音乐ID
*/
private
Long
musicId
;
public
String
getFromType
()
{
return
fromType
;
}
public
void
setFromType
(
String
fromType
)
{
this
.
fromType
=
fromType
;
}
public
Long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
Long
appId
)
{
this
.
appId
=
appId
;
}
public
Long
getAdviserId
()
{
return
adviserId
;
}
public
void
setAdviserId
(
Long
adviserId
)
{
this
.
adviserId
=
adviserId
;
}
public
Long
getMusicId
()
{
return
musicId
;
}
public
void
setMusicId
(
Long
musicId
)
{
this
.
musicId
=
musicId
;
}
public
List
<
AudioDTO
>
getSpeechs
()
{
return
speechs
;
}
public
void
setSpeechs
(
List
<
AudioDTO
>
speechs
)
{
this
.
speechs
=
speechs
;
}
public
AudioDTO
getMixAudio
()
{
return
mixAudio
;
}
public
void
setMixAudio
(
AudioDTO
mixAudio
)
{
this
.
mixAudio
=
mixAudio
;
}
@Override
public
String
toString
()
{
return
"DubbingResultDTO : "
+
JSONObject
.
toJSONString
(
this
);
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/dubbing/SpeechDTO.java
0 → 100644
View file @
957ac6e5
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
dto
.
dubbing
;
import
java.io.Serializable
;
import
com.alibaba.fastjson.JSONObject
;
/**
*
* @author:songx
* @date:2018年12月5日,下午5:05:57
*/
public
class
SpeechDTO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
5054460976926789378L
;
/**
* 文本内容
*/
private
String
text
;
/**
* id
*/
private
int
id
;
public
String
getText
()
{
return
text
;
}
public
void
setText
(
String
text
)
{
this
.
text
=
text
;
}
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
@Override
public
String
toString
()
{
return
"SpeechDTO : "
+
JSONObject
.
toJSONString
(
this
);
}
}
\ No newline at end of file
pcloud-common-core/src/main/java/com/pcloud/common/core/enums/BacklogTypeEnum.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
core
.
enums
;
/**
* @描述:代办事务类型
* @作者:zhuyajie
* @创建时间:10:54 2018/10/31
* @版本:1.0
*/
public
enum
BacklogTypeEnum
{
/**
* 应用
*/
APP
(
"APP"
),
/**
* 作品
*/
PRODUCT
(
"PRODUCT"
);
private
String
value
;
public
String
getValue
()
{
return
value
;
}
BacklogTypeEnum
(
String
value
)
{
this
.
value
=
value
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/enums/TranscodeFromEnum.java
View file @
957ac6e5
...
@@ -42,7 +42,17 @@ public enum TranscodeFromEnum {
...
@@ -42,7 +42,17 @@ public enum TranscodeFromEnum {
/**
/**
* 直播
* 直播
*/
*/
LIVE_HOMEWORD
(
"LIVE_HOMEWORD"
);
LIVE_HOMEWORD
(
"LIVE_HOMEWORD"
),
/**
* 音频
*/
AUDIOAPP_PDF
(
"AUDIOAPP_PDF"
),
/**
* 文件管理中心
*/
CONVERT_PDF
(
"CONVERT_PDF"
);
/**
/**
* 值
* 值
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/exception/GlobalExceptionHandler.java
View file @
957ac6e5
...
@@ -9,7 +9,10 @@ import org.slf4j.LoggerFactory;
...
@@ -9,7 +9,10 @@ import org.slf4j.LoggerFactory;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.http.converter.HttpMessageNotReadableException
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.FieldError
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.HttpRequestMethodNotSupportedException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.ServletRequestBindingException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
...
@@ -22,6 +25,8 @@ import com.pcloud.common.permission.PermissionException;
...
@@ -22,6 +25,8 @@ import com.pcloud.common.permission.PermissionException;
import
feign.FeignException
;
import
feign.FeignException
;
import
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException
;
import
org.springframework.web.method.annotation.MethodArgumentTypeMismatchException
;
import
java.util.List
;
/**
/**
*
*
* @描述:异常集中处理
* @描述:异常集中处理
...
@@ -92,6 +97,23 @@ public class GlobalExceptionHandler {
...
@@ -92,6 +97,23 @@ public class GlobalExceptionHandler {
LOGGER
.
warn
(
"【响应未结束】"
+
exception
.
getMessage
(),
exception
);
LOGGER
.
warn
(
"【响应未结束】"
+
exception
.
getMessage
(),
exception
);
return
new
ResponseEntity
<>(
"响应未结束!"
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
"响应未结束!"
,
HttpStatus
.
OK
);
}
}
else
if
(
exception
instanceof
MethodArgumentNotValidException
)
{
LOGGER
.
info
(
"【参数异常】"
+
exception
.
getMessage
(),
exception
);
MethodArgumentNotValidException
methodArgumentNotValidException
=
(
MethodArgumentNotValidException
)
exception
;
ResponseDto
<
Object
>
responseDto
=
new
ResponseDto
<>();
BindingResult
bindingResult
=
methodArgumentNotValidException
.
getBindingResult
();
String
resultMessage
=
"参数异常:"
;
List
<
FieldError
>
fieldErrors
=
bindingResult
.
getFieldErrors
();
for
(
int
i
=
0
;
i
<
fieldErrors
.
size
();
i
++)
{
if
(
fieldErrors
.
size
()==
1
||
i
==
fieldErrors
.
size
()-
1
){
resultMessage
+=
fieldErrors
.
get
(
i
).
getDefaultMessage
();
}
else
{
resultMessage
+=
fieldErrors
.
get
(
i
).
getDefaultMessage
()
+
", "
;
}
}
responseDto
.
setMessage
(
resultMessage
);
return
new
ResponseEntity
<>(
responseDto
,
HttpStatus
.
OK
);
}
// 业务异常
// 业务异常
else
if
(
exception
instanceof
BizException
)
{
else
if
(
exception
instanceof
BizException
)
{
LOGGER
.
info
(
"【业务异常】"
+
exception
.
getMessage
(),
exception
);
LOGGER
.
info
(
"【业务异常】"
+
exception
.
getMessage
(),
exception
);
...
...
pcloud-common/pom.xml
View file @
957ac6e5
...
@@ -178,6 +178,10 @@
...
@@ -178,6 +178,10 @@
<artifactId>
httpcore
</artifactId>
<artifactId>
httpcore
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<artifactId>
jedis
</artifactId>
</dependency>
</dependency>
...
@@ -291,13 +295,6 @@
...
@@ -291,13 +295,6 @@
<artifactId>
aliyun-java-sdk-mts
</artifactId>
<artifactId>
aliyun-java-sdk-mts
</artifactId>
</dependency>
</dependency>
<!-- solr add by gaop at 2018-4-23 11:33:47 -->
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-solr
</artifactId>
</dependency>
<!-- end -->
<!-- Jackson Begin -->
<!-- Jackson Begin -->
<dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<groupId>
org.codehaus.jackson
</groupId>
...
@@ -387,6 +384,12 @@
...
@@ -387,6 +384,12 @@
<version>
2.0
</version>
<version>
2.0
</version>
</dependency>
</dependency>
<!-- util sdk -->
<dependency>
<groupId>
com.dcg.sdk
</groupId>
<artifactId>
util-sdk
</artifactId>
<version>
1.0.0
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
pcloud-common/src/main/java/com/pcloud/common/entity/BasePageRequestVO.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
/**
* @author peidawei
* @version 1.0.0
* @package com.pcloud.common.entity
* @className BasePageRequestVO
* @description 分页请求VO基类
* @date 2018年11月29日 下午 14:46
*/
@ApiModel
(
"分页请求VO基类"
)
public
class
BasePageRequestVO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
4034188768789093041L
;
@ApiModelProperty
(
hidden
=
true
)
private
Long
userId
;
@ApiModelProperty
(
"每页多少条"
)
private
Integer
numPerPage
;
@ApiModelProperty
(
"当前页"
)
private
Integer
currentPage
;
public
Long
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
Long
userId
)
{
this
.
userId
=
userId
;
}
public
Integer
getNumPerPage
()
{
return
numPerPage
;
}
public
void
setNumPerPage
(
Integer
numPerPage
)
{
this
.
numPerPage
=
numPerPage
;
}
public
Integer
getCurrentPage
()
{
return
currentPage
;
}
public
void
setCurrentPage
(
Integer
currentPage
)
{
this
.
currentPage
=
currentPage
;
}
}
pcloud-common/src/main/java/com/pcloud/common/entity/BaseRequestVO.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
java.io.Serializable
;
/**
* @author peidawei
* @version 1.0.0
* @package com.pcloud.common.entity
* @className BaseRequestVO
* @description 请求VO基类
* @date 2018年11月29日 下午 14:44
*/
@ApiModel
(
"请求VO基类"
)
public
class
BaseRequestVO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1078697162056973900L
;
@ApiModelProperty
(
hidden
=
true
)
private
Long
userId
;
public
Long
getUserId
()
{
return
userId
;
}
public
void
setUserId
(
Long
userId
)
{
this
.
userId
=
userId
;
}
}
pcloud-common/src/main/java/com/pcloud/common/enums/AppTypeEnum.java
View file @
957ac6e5
...
@@ -54,7 +54,8 @@ public enum AppTypeEnum {
...
@@ -54,7 +54,8 @@ public enum AppTypeEnum {
WISH
(
"WISH"
),
// 愿望单
WISH
(
"WISH"
),
// 愿望单
LIVEAPP
(
"LIVEAPP"
),
//直播3.0
LIVEAPP
(
"LIVEAPP"
),
//直播3.0
TASTETEST
(
"TASTETEST"
),
//趣味测试
TASTETEST
(
"TASTETEST"
),
//趣味测试
VIDEO_CLASSIC
(
"VIDEO_CLASSIC"
);
//经典版视频
VIDEO_CLASSIC
(
"VIDEO_CLASSIC"
),
//经典版视频
AUDIO_MAGIC
(
"AUDIO_MAGIC"
);
//音频伴读魔法箱
/**
/**
* 枚举转换
* 枚举转换
...
...
pcloud-common/src/main/java/com/pcloud/common/enums/QrcodeTypeEnum.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
enums
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author lily
* @date 2018/12/6 11:36
*/
public
enum
QrcodeTypeEnum
{
MAGIC
(
"AUDIO_MAGIC"
,
0
,
"听画书"
,
"AUDIO_MAGIC"
,
"APP"
,
true
),
REWARD
(
"CLOCK"
,
1
,
"打卡书"
,
"REWARD"
,
"APP"
,
true
),
PREVIEW_APP
(
"VIDEO"
,
2
,
"预习课"
,
"PREVIEW"
,
"APP"
,
true
),
PREVIEW_PRODUCT
(
"VIDEO_SCHEDULE"
,
3
,
"预习课"
,
"PREVIEW"
,
"PRODUCT"
,
true
),
ZSCORE
(
"ZSCORE"
,
4
,
"查分书"
,
"ZSCORE"
,
"APP"
,
true
);
/**
* 类型
*/
private
String
type
;
private
Integer
value
;
private
String
description
;
private
String
scene
;
private
String
typeCode
;
private
Boolean
isNeedCover
;
public
static
final
Map
<
String
,
QrcodeTypeEnum
>
QRCODE_TYPE_MAP
=
new
HashMap
<>();
QrcodeTypeEnum
(
String
type
,
Integer
value
,
String
description
,
String
scene
,
String
typeCode
,
Boolean
isNeedCover
)
{
this
.
type
=
type
;
this
.
value
=
value
;
this
.
description
=
description
;
this
.
scene
=
scene
;
this
.
typeCode
=
typeCode
;
this
.
isNeedCover
=
isNeedCover
;
}
static
{
Arrays
.
asList
(
values
()).
forEach
((
m
)
->
{
QRCODE_TYPE_MAP
.
put
(
m
.
type
,
m
);
});
}
public
String
getType
()
{
return
type
;
}
public
Integer
getValue
()
{
return
value
;
}
public
String
getDescription
()
{
return
description
;
}
public
String
getScene
()
{
return
scene
;
}
public
String
getTypeCode
()
{
return
typeCode
;
}
public
Boolean
getNeedCover
()
{
return
isNeedCover
;
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/DateNewUtils.java
0 → 100644
View file @
957ac6e5
package
com
.
pcloud
.
common
.
utils
;
import
java.sql.Timestamp
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.pcloud.common.utils.validate.ValidateUtils
;
/**
* 线程安全的时间工具类
* @author PENG
* @date 2018年12月11日16:40:06
*/
public
class
DateNewUtils
extends
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
{
public
static
final
long
DAY_MILLI
=
24
*
60
*
60
*
1000
;
public
final
static
int
LEFT_OPEN_RIGHT_OPEN
=
1
;
public
final
static
int
LEFT_CLOSE_RIGHT_OPEN
=
2
;
public
final
static
int
LEFT_OPEN_RIGHT_CLOSE
=
3
;
public
final
static
int
LEFT_CLOSE_RIGHT_CLOSE
=
4
;
/**
* 比较日期的模式 --只比较日期,不比较时间
*/
public
final
static
int
COMP_MODEL_DATE
=
1
;
/**
* 比较日期的模式 --只比较时间,不比较日期
*/
public
final
static
int
COMP_MODEL_TIME
=
2
;
/**
* 比较日期的模式 --比较日期,也比较时间
*/
public
final
static
int
COMP_MODEL_DATETIME
=
3
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
DateNewUtils
.
class
);
/**
* 要用到的DATE Format的定义
*/
public
static
final
String
SHORT_DATE_FORMAT_PATTERN
=
"yyyy-MM-dd"
;
public
static
final
String
YMD_DATE_FORMAT_PATTERN
=
"yyyyMMdd"
;
public
static
final
String
YMD_DATE_FORMAT_PATTERN1
=
"yyyy/MM/dd"
;
public
static
final
String
YMD_DATE_FORMAT_PATTERN2
=
"yyyy年MM月dd日"
;
public
static
final
String
LONG_DATE_FORMAT_PATTERN
=
"yyyy-MM-dd HH:mm:ss"
;
public
static
final
String
TIME_WITH_MINUTE_PATTERN
=
"HH:mm"
;
public
static
final
String
TIME_DATE_FORMAT_PATTERN
=
"HH:mm:ss"
;
public
static
final
String
HMS_DATE_FORMAT_PATTERN
=
"HHmmss"
;
public
static
final
String
YMDHMS_DATE_FORMAT_PATTERN
=
"yyyyMMddHHmmss"
;
public
static
final
String
YMDHM_DATE_FORMAT_PATTERN
=
"yyyy-MM-dd HH:mm"
;
public
static
final
String
YMDHMSS_DATE_FORMAT_PATTERN
=
"yyyy-MM-dd hh:mm:ss:SSS"
;
/**
* 锁对象
*/
private
static
final
Object
LOCK_OBJ
=
new
Object
();
/**
* 存放不同的日期模板格式的sdf的Map
*/
private
static
Map
<
String
,
ThreadLocal
<
SimpleDateFormat
>>
sdfMap
=
new
HashMap
<>();
/**
* 返回一个ThreadLocal的sdf,每个线程只会new一次sdf
* @param pattern
* @return
*/
private
static
SimpleDateFormat
getSdf
(
final
String
pattern
)
{
ThreadLocal
<
SimpleDateFormat
>
tl
=
sdfMap
.
get
(
pattern
);
// 此处的双重判断和同步是为了防止sdfMap这个单例被多次put重复的sdf
if
(
tl
==
null
)
{
synchronized
(
LOCK_OBJ
)
{
// 这里是关键,使用ThreadLocal<SimpleDateFormat>替代原来直接new SimpleDateFormat
tl
=
sdfMap
.
computeIfAbsent
(
pattern
,
k
->
ThreadLocal
.
withInitial
(()
->
new
SimpleDateFormat
(
pattern
)));
}
}
return
tl
.
get
();
}
/**
* 根据日期格式字符串解析日期字符串
* @param str 日期字符串
* @param parsePatterns 日期格式字符串
* @return 解析后日期
* @throws ParseException
*/
public
static
synchronized
Date
parseDate
(
String
str
,
String
parsePatterns
)
throws
ParseException
{
return
org
.
apache
.
commons
.
lang
.
time
.
DateUtils
.
parseDate
(
str
,
new
String
[]{
parsePatterns
});
}
/**
* 根据单位字段比较两个日期
* @param date 日期1
* @param otherDate 日期2
* @param withUnit 单位字段,从Calendar field取值
* @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
*/
public
static
int
compareDate
(
Date
date
,
Date
otherDate
,
int
withUnit
)
{
Calendar
dateCal
=
Calendar
.
getInstance
();
dateCal
.
setTime
(
date
);
Calendar
otherDateCal
=
Calendar
.
getInstance
();
otherDateCal
.
setTime
(
otherDate
);
switch
(
withUnit
)
{
case
Calendar
.
YEAR
:
dateCal
.
clear
(
Calendar
.
MONTH
);
otherDateCal
.
clear
(
Calendar
.
MONTH
);
case
Calendar
.
MONTH
:
dateCal
.
set
(
Calendar
.
DATE
,
1
);
otherDateCal
.
set
(
Calendar
.
DATE
,
1
);
case
Calendar
.
DATE
:
dateCal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
otherDateCal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
case
Calendar
.
HOUR
:
dateCal
.
clear
(
Calendar
.
MINUTE
);
otherDateCal
.
clear
(
Calendar
.
MINUTE
);
case
Calendar
.
MINUTE
:
dateCal
.
clear
(
Calendar
.
SECOND
);
otherDateCal
.
clear
(
Calendar
.
SECOND
);
case
Calendar
.
SECOND
:
dateCal
.
clear
(
Calendar
.
MILLISECOND
);
otherDateCal
.
clear
(
Calendar
.
MILLISECOND
);
case
Calendar
.
MILLISECOND
:
break
;
default
:
throw
new
IllegalArgumentException
(
"withUnit 单位字段 "
+
withUnit
+
" 不合法!!"
);
}
return
dateCal
.
compareTo
(
otherDateCal
);
}
/**
* 根据单位字段比较两个时间
* @param date 时间1
* @param otherDate 时间2
* @param withUnit 单位字段,从Calendar field取值
* @return 等于返回0值, 大于返回大于0的值 小于返回小于0的值
*/
public
static
int
compareTime
(
Date
date
,
Date
otherDate
,
int
withUnit
)
{
Calendar
dateCal
=
Calendar
.
getInstance
();
dateCal
.
setTime
(
date
);
Calendar
otherDateCal
=
Calendar
.
getInstance
();
otherDateCal
.
setTime
(
otherDate
);
dateCal
.
clear
(
Calendar
.
YEAR
);
dateCal
.
clear
(
Calendar
.
MONTH
);
dateCal
.
set
(
Calendar
.
DATE
,
1
);
otherDateCal
.
clear
(
Calendar
.
YEAR
);
otherDateCal
.
clear
(
Calendar
.
MONTH
);
otherDateCal
.
set
(
Calendar
.
DATE
,
1
);
switch
(
withUnit
)
{
case
Calendar
.
HOUR
:
dateCal
.
clear
(
Calendar
.
MINUTE
);
otherDateCal
.
clear
(
Calendar
.
MINUTE
);
case
Calendar
.
MINUTE
:
dateCal
.
clear
(
Calendar
.
SECOND
);
otherDateCal
.
clear
(
Calendar
.
SECOND
);
case
Calendar
.
SECOND
:
dateCal
.
clear
(
Calendar
.
MILLISECOND
);
otherDateCal
.
clear
(
Calendar
.
MILLISECOND
);
case
Calendar
.
MILLISECOND
:
break
;
default
:
throw
new
IllegalArgumentException
(
"withUnit 单位字段 "
+
withUnit
+
" 不合法!!"
);
}
return
dateCal
.
compareTo
(
otherDateCal
);
}
/**
* 获得当前的日期毫秒
* @return
*/
public
static
long
nowTimeMillis
()
{
return
System
.
currentTimeMillis
();
}
/**
* 获得当前的unix时间戳,不含毫秒
* @return
*/
public
static
long
nowTimeSecond
()
{
return
System
.
currentTimeMillis
()
/
1000
;
}
/**
* 获得当前的unix时间戳,不含毫秒
* @return
*/
public
static
long
addNowTimeSecond
(
long
second
)
{
return
System
.
currentTimeMillis
()
/
1000
+
second
;
}
/**
* 获得当前的时间戳
* @return
*/
public
static
Timestamp
nowTimeStamp
()
{
return
new
Timestamp
(
nowTimeMillis
());
}
/**
* yyyy-MM-dd 当前日期
*/
public
static
String
getReqDate
()
{
return
getSdf
(
YMD_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
/**
* yyyy-MM-dd 传入日期
* @param date
* @return
*/
public
static
String
getReqDate
(
Date
date
)
{
return
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
date
);
}
/**
* yyyyMMdd 传入日期
* @param date
* @return
*/
public
static
String
getReqDateyyyyMMdd
(
Date
date
)
{
return
getSdf
(
YMD_DATE_FORMAT_PATTERN
).
format
(
date
);
}
/**
* yyyy-MM-dd 传入的时间戳
* @param tmp
* @return
*/
public
static
String
timestampToDateStr
(
Timestamp
tmp
)
{
return
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
tmp
);
}
/**
* HH:mm:ss 当前时间
* @return
*/
public
static
String
getReqTime
()
{
return
getSdf
(
TIME_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
/**
* HHmmss 当前时间
* @return
*/
public
static
String
getHmsTime
()
{
return
getSdf
(
HMS_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
/**
* yyyyMMddHHmmss 当前时间
* @return
*/
public
static
String
getYmdHmsTime
()
{
return
getSdf
(
YMDHMS_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
/**
* 得到时间戳格式字串
* @param date
* @return
*/
public
static
String
getTimeStampStr
(
Date
date
)
{
return
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
date
);
}
/**
* 得到长日期格式字串
* @return
*/
public
static
String
getLongDateStr
()
{
return
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
public
static
String
getLongDateStr
(
Timestamp
time
)
{
return
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
time
);
}
/**
* 得到短日期格式字串
* @param date
* @return
*/
public
static
String
getShortDateStr
(
Date
date
)
{
return
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
date
);
}
public
static
String
getShortDateStr
()
{
return
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
new
Date
());
}
/**
* 计算 second 秒后的时间
* @param date
* @param second
* @return
*/
public
static
Date
addSecond
(
Date
date
,
int
second
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
SECOND
,
second
);
return
calendar
.
getTime
();
}
/**
* 计算 minute 分钟后的时间
* @param date
* @param minute
* @return
*/
public
static
Date
addMinute
(
Date
date
,
int
minute
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
MINUTE
,
minute
);
return
calendar
.
getTime
();
}
/**
* 计算 hour 小时后的时间
* @param date
* @param hour
* @return
*/
public
static
Date
addHour
(
Date
date
,
int
hour
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
HOUR
,
hour
);
return
calendar
.
getTime
();
}
/**
* 得到day的起始时间点。
* @param date
* @return
*/
public
static
Date
getDayStart
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 得到day的终止时间点.
* @param date
* @return
*/
public
static
Date
getDayEnd
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
add
(
Calendar
.
MILLISECOND
,
-
1
);
return
calendar
.
getTime
();
}
/**
* 计算 day 天后的时间
* @param date
* @param day
* @return
*/
public
static
Date
addDay
(
Date
date
,
int
day
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
day
);
return
calendar
.
getTime
();
}
/**
* 得到month的终止时间点.
* @param date
* @return
*/
public
static
Date
getMonthEnd
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
calendar
.
add
(
Calendar
.
MONTH
,
1
);
calendar
.
add
(
Calendar
.
MILLISECOND
,
-
1
);
return
calendar
.
getTime
();
}
public
static
Date
addYear
(
Date
date
,
int
year
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
add
(
Calendar
.
DAY_OF_YEAR
,
365
*
year
);
return
calendar
.
getTime
();
}
public
static
Timestamp
strToTimestamp
(
String
dateStr
)
{
return
Timestamp
.
valueOf
(
dateStr
);
}
public
static
Timestamp
strToTimestamp
(
Date
date
)
{
return
Timestamp
.
valueOf
(
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
date
));
}
public
static
Timestamp
getCurTimestamp
()
{
return
Timestamp
.
valueOf
(
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
new
Date
()));
}
/**
* 取得两个日期之间的日数
* @return t1到t2间的日数,如果t2 在 t1之后,返回正数,否则返回负数
*/
public
static
long
daysBetween
(
java
.
sql
.
Timestamp
t1
,
java
.
sql
.
Timestamp
t2
)
{
return
(
t2
.
getTime
()
-
t1
.
getTime
())
/
DAY_MILLI
;
}
/**
* 返回java.sql.Timestamp型的SYSDATE
* @return java.sql.Timestamp型的SYSDATE
* @history
* @since 1.0
*/
public
static
java
.
sql
.
Timestamp
getSysDateTimestamp
()
{
return
new
java
.
sql
.
Timestamp
(
System
.
currentTimeMillis
());
}
/**
* 利用缺省的Date格式(YYYY/MM/DD)转换String到java.sql.Timestamp
* @param sDate Date string
* @return
* @history
* @since 1.0
*/
public
static
java
.
sql
.
Timestamp
toSqlTimestamp
(
String
sDate
)
{
if
(
sDate
==
null
)
{
return
null
;
}
if
(
sDate
.
length
()
!=
SHORT_DATE_FORMAT_PATTERN
.
length
()
&&
sDate
.
length
()
!=
LONG_DATE_FORMAT_PATTERN
.
length
())
{
return
null
;
}
return
toSqlTimestamp
(
sDate
,
sDate
.
length
()
==
SHORT_DATE_FORMAT_PATTERN
.
length
()
?
SHORT_DATE_FORMAT_PATTERN
:
LONG_DATE_FORMAT_PATTERN
);
}
/**
* 利用缺省的Date格式(YYYY/MM/DD hh:mm:ss)转化String到java.sql.Timestamp
* @param sDate Date string
* @param sFmt Date format YMD_DATE_FORMAT_PATTERN/TIME_DATE_FORMAT_PATTERN
* @return
* @history
* @since 1.0
*/
public
static
java
.
sql
.
Timestamp
toSqlTimestamp
(
String
sDate
,
String
sFmt
)
{
String
temp
=
null
;
if
(
sDate
==
null
||
sFmt
==
null
)
{
return
null
;
}
if
(
sDate
.
length
()
!=
sFmt
.
length
())
{
return
null
;
}
if
(
sFmt
.
equals
(
LONG_DATE_FORMAT_PATTERN
))
{
temp
=
sDate
.
replace
(
'/'
,
'-'
);
temp
=
temp
+
".000000000"
;
}
else
if
(
sFmt
.
equals
(
SHORT_DATE_FORMAT_PATTERN
))
{
temp
=
sDate
.
replace
(
'/'
,
'-'
);
temp
=
temp
+
" 00:00:00.000000000"
;
}
else
{
return
null
;
}
return
java
.
sql
.
Timestamp
.
valueOf
(
temp
);
}
/**
* 以YYYY/MM/DD HH24:MI:SS格式返回系统日期时间
* @return 系统日期时间
* @history
* @since 1.0
*/
public
static
String
getSysDateTimeString
()
{
return
toString
(
new
java
.
util
.
Date
(
System
.
currentTimeMillis
()),
getSdf
(
LONG_DATE_FORMAT_PATTERN
));
}
/**
* 根据指定的Format转化java.util.Date到String
* @param dt java.util.Date instance
* @param sFmt Date format , YMD_DATE_FORMAT_PATTERN or TIME_DATE_FORMAT_PATTERN
* @return
* @history
* @since 1.0
*/
public
static
String
toString
(
java
.
util
.
Date
dt
,
String
sFmt
)
{
if
(
dt
==
null
||
sFmt
==
null
||
""
.
equals
(
sFmt
))
{
return
""
;
}
return
toString
(
dt
,
getSdf
(
sFmt
));
}
/**
* 利用指定SimpleDateFormat instance转换java.util.Date到String
* @param dt java.util.Date instance
* @param formatter SimpleDateFormat Instance
* @return
* @history
* @since 1.0
*/
private
static
String
toString
(
java
.
util
.
Date
dt
,
SimpleDateFormat
formatter
)
{
String
sRet
=
null
;
try
{
sRet
=
formatter
.
format
(
dt
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"error:"
,
e
);
sRet
=
null
;
}
return
sRet
;
}
/**
* 转换java.sql.Timestamp到String,格式为YYYY/MM/DD HH24:MI
* @param dt java.sql.Timestamp instance
* @return
* @history
* @since 1.0
*/
public
static
String
toSqlTimestampString2
(
java
.
sql
.
Timestamp
dt
)
{
if
(
dt
==
null
)
{
return
null
;
}
String
temp
=
toSqlTimestampString
(
dt
,
LONG_DATE_FORMAT_PATTERN
);
return
temp
.
substring
(
0
,
16
);
}
public
static
String
toString
(
java
.
sql
.
Timestamp
dt
)
{
return
dt
==
null
?
""
:
toSqlTimestampString2
(
dt
);
}
/**
* 根据指定的格式转换java.sql.Timestamp到String
* @param dt java.sql.Timestamp instance
* @param sFmt Date 格式,YMD_DATE_FORMAT_PATTERN/TIME_DATE_FORMAT_PATTERN/
* DATE_FORMAT_SESSION
* @return
* @history
* @since 1.0
*/
public
static
String
toSqlTimestampString
(
java
.
sql
.
Timestamp
dt
,
String
sFmt
)
{
String
temp
=
null
;
String
out
=
null
;
if
(
dt
==
null
||
sFmt
==
null
)
{
return
null
;
}
temp
=
dt
.
toString
();
if
(
sFmt
.
equals
(
LONG_DATE_FORMAT_PATTERN
)
||
sFmt
.
equals
(
SHORT_DATE_FORMAT_PATTERN
))
{
temp
=
temp
.
substring
(
0
,
sFmt
.
length
());
out
=
temp
.
replace
(
'/'
,
'-'
);
}
return
out
;
}
/**
* 得到当前日期的星期
* @return
*/
public
static
int
getWeek
()
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
return
cal
.
get
(
Calendar
.
DAY_OF_WEEK
);
}
/**
* Timestamp 格式转换成yyyy-MM-dd timestampToSql(Timestamp 格式转换成yyyy-MM-dd)
* @param timestamp 时间
* @return createTimeStr yyyy-MM-dd 时间
* @Exception 异常对象
* @since V1.0
*/
public
static
String
timestampToStringYMD
(
java
.
sql
.
Timestamp
timestamp
)
{
return
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
timestamp
);
}
/**
* 判断一个时间是否在某个时间区间内
* @param now 目标时间
* @param start 时间区间开始
* @param end 时间区间结束
* @param model 区间模式
* @return 是否在区间内
*/
public
static
boolean
isBetween
(
Date
now
,
Date
start
,
Date
end
,
int
model
)
{
return
isBetween
(
now
,
start
,
end
,
model
,
COMP_MODEL_DATE
);
}
/**
* 判断时间是否在制定的时间段之类
* @param date 需要判断的时间
* @param start 时间段的起始时间
* @param end 时间段的截止时间
* @param interModel 区间的模式
* 取值:
* LEFT_OPEN_RIGHT_OPEN
* LEFT_CLOSE_RIGHT_OPEN
* LEFT_OPEN_RIGHT_CLOSE
* LEFT_CLOSE_RIGHT_CLOSE
* @param compModel 比较的模式
* 取值:
* COMP_MODEL_DATE 只比较日期,不比较时间
* COMP_MODEL_TIME 只比较时间,不比较日期
* COMP_MODEL_DATETIME 比较日期,也比较时间
* @return
*/
public
static
boolean
isBetween
(
Date
date
,
Date
start
,
Date
end
,
int
interModel
,
int
compModel
)
{
if
(
date
==
null
||
start
==
null
||
end
==
null
)
{
throw
new
IllegalArgumentException
(
"日期不能为空"
);
}
SimpleDateFormat
format
=
null
;
switch
(
compModel
)
{
case
COMP_MODEL_DATE:
{
format
=
getSdf
(
YMD_DATE_FORMAT_PATTERN
);
break
;
}
case
COMP_MODEL_TIME:
{
format
=
getSdf
(
HMS_DATE_FORMAT_PATTERN
);
break
;
}
case
COMP_MODEL_DATETIME:
{
format
=
getSdf
(
YMDHMS_DATE_FORMAT_PATTERN
);
break
;
}
default
:
{
throw
new
IllegalArgumentException
(
String
.
format
(
"日期的比较模式[%d]有误"
,
compModel
));
}
}
long
dateNumber
=
Long
.
parseLong
(
format
.
format
(
date
));
long
startNumber
=
Long
.
parseLong
(
format
.
format
(
start
));
long
endNumber
=
Long
.
parseLong
(
format
.
format
(
end
));
switch
(
interModel
)
{
case
LEFT_OPEN_RIGHT_OPEN:
{
if
(
dateNumber
<=
startNumber
||
dateNumber
>=
endNumber
)
{
return
false
;
}
else
{
return
true
;
}
}
case
LEFT_CLOSE_RIGHT_OPEN:
{
if
(
dateNumber
<
startNumber
||
dateNumber
>=
endNumber
)
{
return
false
;
}
else
{
return
true
;
}
}
case
LEFT_OPEN_RIGHT_CLOSE:
{
if
(
dateNumber
<=
startNumber
||
dateNumber
>
endNumber
)
{
return
false
;
}
else
{
return
true
;
}
}
case
LEFT_CLOSE_RIGHT_CLOSE:
{
if
(
dateNumber
<
startNumber
||
dateNumber
>
endNumber
)
{
return
false
;
}
else
{
return
true
;
}
}
default
:
{
throw
new
IllegalArgumentException
(
String
.
format
(
"日期的区间模式[%d]有误"
,
interModel
));
}
}
}
/**
* 得到当前周起始时间
* @param date
* @return
*/
public
static
Date
getWeekStart
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
get
(
Calendar
.
WEEK_OF_YEAR
);
int
firstDay
=
calendar
.
getFirstDayOfWeek
();
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
firstDay
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 得到当前周截止时间
* @param date
* @return
*/
public
static
Date
getWeekEnd
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
get
(
Calendar
.
WEEK_OF_YEAR
);
int
firstDay
=
calendar
.
getFirstDayOfWeek
();
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
8
-
firstDay
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 得到当月起始时间
* @param date
* @return
*/
public
static
Date
getMonthStart
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 得到当前年起始时间
* @param date
* @return
*/
public
static
Date
getYearStart
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
YEAR
,
calendar
.
get
(
Calendar
.
YEAR
));
calendar
.
set
(
Calendar
.
MONTH
,
0
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
1
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 得到当前年最后一天
* @param date
* @return
*/
public
static
Date
getYearEnd
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
YEAR
,
calendar
.
get
(
Calendar
.
YEAR
));
calendar
.
set
(
Calendar
.
MONTH
,
11
);
calendar
.
set
(
Calendar
.
DAY_OF_MONTH
,
31
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
calendar
.
set
(
Calendar
.
MINUTE
,
59
);
calendar
.
set
(
Calendar
.
SECOND
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
();
}
/**
* 取得月天数
* @param date
* @return
*/
public
static
int
getDayOfMonth
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
return
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
}
/**
* 取得月第一天
* @param date
* @return
*/
public
static
Date
getFirstDateOfMonth
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
c
.
getActualMinimum
(
Calendar
.
DAY_OF_MONTH
));
return
c
.
getTime
();
}
/**
* 取得月最后一天
* @param date
* @return
*/
public
static
Date
getLastDateOfMonth
(
Date
date
)
{
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
c
.
set
(
Calendar
.
DAY_OF_MONTH
,
c
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
));
return
c
.
getTime
();
}
/**
* 取得季度第一天
* @param date
* @return
*/
public
static
Date
getSeasonStart
(
Date
date
)
{
return
getDayStart
(
getFirstDateOfMonth
(
getSeasonDate
(
date
)[
0
]));
}
/**
* 取得季度最后一天
* @param date
* @return
*/
public
static
Date
getSeasonEnd
(
Date
date
)
{
return
getDayEnd
(
getLastDateOfMonth
(
getSeasonDate
(
date
)[
2
]));
}
/**
* 取得季度月
* @param date
* @return
*/
public
static
Date
[]
getSeasonDate
(
Date
date
)
{
Date
[]
season
=
new
Date
[
3
];
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
int
nSeason
=
getSeason
(
date
);
if
(
nSeason
==
1
)
{
// 第一季度
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JANUARY
);
season
[
0
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
FEBRUARY
);
season
[
1
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
MARCH
);
season
[
2
]
=
c
.
getTime
();
}
else
if
(
nSeason
==
2
)
{
// 第二季度
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
APRIL
);
season
[
0
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
MAY
);
season
[
1
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JUNE
);
season
[
2
]
=
c
.
getTime
();
}
else
if
(
nSeason
==
3
)
{
// 第三季度
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
JULY
);
season
[
0
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
AUGUST
);
season
[
1
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
SEPTEMBER
);
season
[
2
]
=
c
.
getTime
();
}
else
if
(
nSeason
==
4
)
{
// 第四季度
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
OCTOBER
);
season
[
0
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
NOVEMBER
);
season
[
1
]
=
c
.
getTime
();
c
.
set
(
Calendar
.
MONTH
,
Calendar
.
DECEMBER
);
season
[
2
]
=
c
.
getTime
();
}
return
season
;
}
/**
* 1 第一季度 2 第二季度 3 第三季度 4 第四季度
* @param date
* @return
*/
public
static
int
getSeason
(
Date
date
)
{
int
season
=
0
;
Calendar
c
=
Calendar
.
getInstance
();
c
.
setTime
(
date
);
int
month
=
c
.
get
(
Calendar
.
MONTH
);
switch
(
month
)
{
case
Calendar
.
JANUARY
:
case
Calendar
.
FEBRUARY
:
case
Calendar
.
MARCH
:
season
=
1
;
break
;
case
Calendar
.
APRIL
:
case
Calendar
.
MAY
:
case
Calendar
.
JUNE
:
season
=
2
;
break
;
case
Calendar
.
JULY
:
case
Calendar
.
AUGUST
:
case
Calendar
.
SEPTEMBER
:
season
=
3
;
break
;
case
Calendar
.
OCTOBER
:
case
Calendar
.
NOVEMBER
:
case
Calendar
.
DECEMBER
:
season
=
4
;
break
;
default
:
break
;
}
return
season
;
}
/**
* 字符串转date
* @param dateString
* @return
*/
public
static
Date
stringToDate
(
String
dateString
)
{
Date
date
=
null
;
try
{
date
=
getSdf
(
YMD_DATE_FORMAT_PATTERN1
).
parse
(
dateString
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
date
;
}
/**
* 字符串转date
* @param dateString
* @return
*/
public
static
Date
stringToShortDate
(
String
dateString
)
{
Date
date
=
null
;
try
{
date
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
parse
(
dateString
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
date
;
}
/**
* 字符串转换datetime
* @param dateString
* @return
*/
public
static
Date
stringToDateTime
(
String
dateString
)
{
Date
date
=
null
;
try
{
date
=
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
parse
(
dateString
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
date
;
}
/**
* 判断输入日期是一个星期中的第几天(星期天为一个星期第一天)
* @param date
* @return
*/
public
static
int
getWeekIndex
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
return
calendar
.
get
(
Calendar
.
DAY_OF_WEEK
);
}
/**
* 当前时间的前几天,并且以例如2013/12/09 00:00:00 形式输出
*/
public
static
Date
subDays
(
int
days
)
{
Date
date
=
addDay
(
new
Date
(),
-
days
);
String
dateStr
=
getReqDate
(
date
);
Date
date1
=
null
;
try
{
date1
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
parse
(
dateStr
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
date1
;
}
/**
* 判断开始时间和结束时间,是否超出了当前时间的一定的间隔数限制 如:开始时间和结束时间,不能超出距离当前时间90天
* @param startDate 开始时间
* @param endDate 结束时间按
* @param interval 间隔数
* @param dateUnit 单位(如:月,日),参照Calendar的时间单位
* @return
*/
public
static
boolean
isOverIntervalLimit
(
Date
startDate
,
Date
endDate
,
int
interval
,
int
dateUnit
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
cal
.
add
(
dateUnit
,
interval
*
(-
1
));
Date
curDate
=
getDayStart
(
cal
.
getTime
());
if
(
getDayStart
(
startDate
).
compareTo
(
curDate
)
<
0
||
getDayStart
(
endDate
).
compareTo
(
curDate
)
<
0
)
{
return
true
;
}
return
false
;
}
/**
* 判断开始时间和结束时间,是否超出了当前时间的一定的间隔数限制, 时间单位默认为天数 如:开始时间和结束时间,不能超出距离当前时间90天
* @param startDate 开始时间
* @param endDate 结束时间按
* @param interval 间隔数
* @return
*/
public
static
boolean
isOverIntervalLimit
(
Date
startDate
,
Date
endDate
,
int
interval
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
new
Date
());
cal
.
add
(
Calendar
.
DAY_OF_MONTH
,
interval
*
(-
1
));
Date
curDate
=
getDayStart
(
cal
.
getTime
());
if
(
getDayStart
(
startDate
).
compareTo
(
curDate
)
<
0
||
getDayStart
(
endDate
).
compareTo
(
curDate
)
<
0
)
{
return
true
;
}
return
false
;
}
/**
* 判断开始时间和结束时间,是否超出了当前时间的一定的间隔数限制, 时间单位默认为天数 如:开始时间和结束时间,不能超出距离当前时间90天
* @param startDateStr 开始时间
* @param endDateStr 结束时间按
* @param interval 间隔数
* @return
*/
public
static
boolean
isOverIntervalLimit
(
String
startDateStr
,
String
endDateStr
,
int
interval
)
{
Date
startDate
=
null
;
Date
endDate
=
null
;
try
{
startDate
=
parseDate
(
startDateStr
,
SHORT_DATE_FORMAT_PATTERN
);
endDate
=
parseDate
(
endDateStr
,
SHORT_DATE_FORMAT_PATTERN
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
return
false
;
}
return
isOverIntervalLimit
(
startDate
,
endDate
,
interval
);
}
/**
* 传入时间字符串及时间格式,返回对应的Date对象
* @param src 时间字符串
* @param pattern 时间格式
* @return Date
*/
public
static
Date
getDateFromString
(
String
src
,
String
pattern
)
{
try
{
return
getSdf
(
pattern
).
parse
(
src
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
return
null
;
}
}
/**
* 取季度
* @param date
* @return
*/
@SuppressWarnings
(
"deprecation"
)
public
static
int
getQuarter
(
Date
date
)
{
if
(
date
.
getMonth
()
==
0
||
date
.
getMonth
()
==
1
||
date
.
getMonth
()
==
2
)
{
return
1
;
}
else
if
(
date
.
getMonth
()
==
3
||
date
.
getMonth
()
==
4
||
date
.
getMonth
()
==
5
)
{
return
2
;
}
else
if
(
date
.
getMonth
()
==
6
||
date
.
getMonth
()
==
7
||
date
.
getMonth
()
==
8
)
{
return
3
;
}
else
if
(
date
.
getMonth
()
==
9
||
date
.
getMonth
()
==
10
||
date
.
getMonth
()
==
11
)
{
return
4
;
}
else
{
return
0
;
}
}
/**
* 取得通用日期时间格式字符串
* @param date
* @return String
*/
public
static
String
formatDate
(
Date
date
)
{
if
(
date
==
null
)
{
return
""
;
}
return
getSdf
(
LONG_DATE_FORMAT_PATTERN
).
format
(
date
);
}
/**
* 获取当日的日期格式串
* @return String
*/
public
static
String
today
()
{
return
formatDate
(
new
Date
(),
SHORT_DATE_FORMAT_PATTERN
);
}
/**
* 获取当前时间格式串
* @return String
*/
public
static
String
currentTime
()
{
return
formatDate
(
new
Date
(),
YMDHMSS_DATE_FORMAT_PATTERN
);
}
/**
* 取得指定日期格式的字符串
* @param date
* @return pattern
*/
public
static
String
formatDate
(
Date
date
,
String
pattern
)
{
return
getSdf
(
pattern
).
format
(
date
);
}
/**
* 获取昨日的日期格式串
* @return Date
*/
public
static
String
getYesterday
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DATE
,
-
1
);
return
formatDate
(
calendar
.
getTime
(),
SHORT_DATE_FORMAT_PATTERN
);
}
/**
* 判断当前时间是否在一定的时间范围内
* @param startTime
* @return boolean
*/
public
static
boolean
isInBetweenTimes
(
String
startTime
,
String
endTime
)
{
Date
nowTime
=
new
Date
();
String
time
=
getSdf
(
TIME_DATE_FORMAT_PATTERN
).
format
(
nowTime
);
if
(
time
.
compareTo
(
startTime
)
>=
0
&&
time
.
compareTo
(
endTime
)
<=
0
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的时间范围内
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDate
(
String
startDate
,
String
endDate
)
{
Date
now
=
new
Date
();
String
date
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
now
);
if
(
date
.
compareTo
(
startDate
)
>=
0
&&
date
.
compareTo
(
endDate
)
<=
0
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的时间范围内
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDate
(
Date
startDate
,
Date
endDate
)
{
Date
now
=
new
Date
();
String
date
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
now
);
if
(
date
.
compareTo
(
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
startDate
))
>=
0
&&
date
.
compareTo
(
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
format
(
endDate
))
<=
0
)
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 字符转日期
* @param dateStr
* @return
*/
public
static
Date
getDateByStr
(
String
dateStr
)
{
SimpleDateFormat
formatter
=
null
;
if
(
dateStr
==
null
)
{
return
null
;
}
else
if
(
dateStr
.
length
()
==
10
)
{
formatter
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
);
}
else
if
(
dateStr
.
length
()
==
16
)
{
formatter
=
getSdf
(
YMDHM_DATE_FORMAT_PATTERN
);
}
else
if
(
dateStr
.
length
()
==
19
)
{
formatter
=
getSdf
(
LONG_DATE_FORMAT_PATTERN
);
}
else
if
(
dateStr
.
length
()
>
19
)
{
dateStr
=
dateStr
.
substring
(
0
,
19
);
formatter
=
getSdf
(
LONG_DATE_FORMAT_PATTERN
);
}
else
{
return
null
;
}
try
{
return
formatter
.
parse
(
dateStr
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
return
null
;
}
}
/**
* 根据传入的数字,输出相比现在days天的数据
* @param days
* @return Date
*/
public
static
Date
getDate
(
int
days
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DATE
,
days
);
return
calendar
.
getTime
();
}
/**
* 根据传入的数字,输出相比现在days天的数据
* @param days
* @return Date
*/
public
static
Date
getDate
(
String
currentDate
,
int
days
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
DATE
,
days
);
return
calendar
.
getTime
();
}
/**
* 日期最大时间
* @param dt
* @return
*/
public
static
Date
getMaxTime
(
Date
dt
)
{
Date
dt1
=
null
;
Calendar
ca
=
Calendar
.
getInstance
();
ca
.
setTime
(
dt
);
ca
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
dt1
=
ca
.
getTime
();
dt1
=
getMinTime
(
dt1
);
ca
.
setTime
(
dt1
);
ca
.
add
(
Calendar
.
SECOND
,
-
1
);
dt1
=
ca
.
getTime
();
return
dt1
;
}
/**
* 日期最小时间
* @param dt
* @return
*/
public
static
Date
getMinTime
(
Date
dt
)
{
return
getDateByStr
(
formatDate
(
dt
,
SHORT_DATE_FORMAT_PATTERN
));
}
/**
* 月的最后一天
* @param date
* @return
*/
@SuppressWarnings
(
"deprecation"
)
public
static
Date
getLastDayOfMonth
(
Date
date
)
{
Calendar
cDay1
=
Calendar
.
getInstance
();
cDay1
.
setTime
(
date
);
int
lastDay
=
cDay1
.
getActualMaximum
(
Calendar
.
DAY_OF_MONTH
);
Date
lastDate
=
cDay1
.
getTime
();
lastDate
.
setDate
(
lastDay
);
return
lastDate
;
}
/**
* 月的第一天
* @param date
* @return
*/
public
static
Date
getFirstDayOfMonth
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
DATE
,
calendar
.
getActualMinimum
(
Calendar
.
DATE
));
return
calendar
.
getTime
();
}
/**
* 上月第一天
* @return
*/
public
static
Date
getPreviousMonthFirstDay
()
{
Calendar
lastDate
=
Calendar
.
getInstance
();
// 设为当前月的1号
lastDate
.
set
(
Calendar
.
DATE
,
1
);
// 减一个月,变为下月的1号
lastDate
.
add
(
Calendar
.
MONTH
,
-
1
);
return
getMinTime
(
lastDate
.
getTime
());
}
/**
* 上月最后一天
* @return
*/
public
static
Date
getPreviousMonthLastDay
()
{
Calendar
lastDate
=
Calendar
.
getInstance
();
// 设为当前月的1号
lastDate
.
set
(
Calendar
.
DATE
,
1
);
lastDate
.
add
(
Calendar
.
DATE
,
-
1
);
return
getMinTime
(
lastDate
.
getTime
());
}
/**
* 两个日期相关天数
* @param startDate
* @param endDate
* @return
*/
public
static
long
getDateDiff
(
String
startDate
,
String
endDate
)
{
long
diff
=
0
;
try
{
Date
date1
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
parse
(
startDate
);
Date
date2
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
).
parse
(
endDate
);
diff
=
(
date1
.
getTime
()
-
date2
.
getTime
())
/
(
24
*
60
*
60
*
1000
)
>
0
?
(
date1
.
getTime
()
-
date2
.
getTime
())
/
(
24
*
60
*
60
*
1000
)
:
(
date2
.
getTime
()
-
date1
.
getTime
())
/
(
24
*
60
*
60
*
1000
);
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
diff
;
}
public
static
long
getDateDiff
(
Date
date1
,
Date
date2
)
{
if
(
ValidateUtils
.
isEmpty
(
date1
)
||
ValidateUtils
.
isEmpty
(
date1
))
{
return
0L
;
}
long
diff
=
(
date1
.
getTime
()
-
date2
.
getTime
())
/
(
24
*
60
*
60
*
1000
)
>
0
?
(
date1
.
getTime
()
-
date2
.
getTime
())
/
(
24
*
60
*
60
*
1000
)
:
(
date2
.
getTime
()
-
date1
.
getTime
())
/
(
24
*
60
*
60
*
1000
);
return
diff
;
}
/**
* 判断两个时间是不是在一个周中
*/
public
static
boolean
isSameWeekWithToday
(
Date
date
)
{
if
(
date
==
null
)
{
return
false
;
}
// 0.先把Date类型的对象转换Calendar类型的对象
Calendar
todayCal
=
Calendar
.
getInstance
();
Calendar
dateCal
=
Calendar
.
getInstance
();
todayCal
.
setTime
(
new
Date
());
dateCal
.
setTime
(
date
);
int
subYear
=
todayCal
.
get
(
Calendar
.
YEAR
)
-
dateCal
.
get
(
Calendar
.
YEAR
);
// subYear==0,说明是同一年
if
(
subYear
==
0
)
{
if
(
todayCal
.
get
(
Calendar
.
WEEK_OF_YEAR
)
==
dateCal
.
get
(
Calendar
.
WEEK_OF_YEAR
))
{
return
true
;
}
}
else
if
(
subYear
==
1
&&
dateCal
.
get
(
Calendar
.
MONTH
)
==
11
&&
todayCal
.
get
(
Calendar
.
MONTH
)
==
0
)
{
if
(
todayCal
.
get
(
Calendar
.
WEEK_OF_YEAR
)
==
dateCal
.
get
(
Calendar
.
WEEK_OF_YEAR
))
{
return
true
;
}
}
else
if
(
subYear
==
-
1
&&
todayCal
.
get
(
Calendar
.
MONTH
)
==
11
&&
dateCal
.
get
(
Calendar
.
MONTH
)
==
0
)
{
if
(
todayCal
.
get
(
Calendar
.
WEEK_OF_YEAR
)
==
dateCal
.
get
(
Calendar
.
WEEK_OF_YEAR
))
{
return
true
;
}
}
return
false
;
}
/**
* getStrFormTime: <br/>
* @param form 格式时间
* @param date 时间
* @return
*/
public
static
String
getStrFormTime
(
String
form
,
Date
date
)
{
return
getSdf
(
form
).
format
(
date
);
}
/**
* 获取几天内日期 return 2014-5-4、2014-5-3
*/
public
static
List
<
String
>
getLastDays
(
int
countDay
)
{
List
<
String
>
listDate
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
countDay
;
i
++)
{
listDate
.
add
(
getReqDateyyyyMMdd
(
getDate
(-
i
)));
}
return
listDate
;
}
/**
* 获取几天内日期 return 2014-5-4、2014-5-3
*/
public
static
List
<
String
>
getLastDays
(
String
currentDate
,
int
countDay
)
{
Date
date
=
stringToShortDate
(
currentDate
);
List
<
String
>
listDate
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
countDay
;
i
++)
{
listDate
.
add
(
getReqDate
(
addDay
(
date
,
-
i
)));
}
return
listDate
;
}
/**
* 对时间进行格式化
* @param date
* @return
*/
public
static
Date
dateFormat
(
Date
date
)
{
SimpleDateFormat
sdf
=
getSdf
(
SHORT_DATE_FORMAT_PATTERN
);
Date
value
=
new
Date
();
try
{
value
=
sdf
.
parse
(
sdf
.
format
(
date
));
}
catch
(
ParseException
e
)
{
logger
.
error
(
"error:"
,
e
);
}
return
value
;
}
/**
* 比较两个时间差
* @param endDate
* @param nowDate
* @return
*/
public
static
String
datePoor
(
Date
endDate
,
Date
nowDate
)
{
if
(
endDate
==
null
||
nowDate
==
null
)
{
return
null
;
}
long
nd
=
1000
*
24
*
60
*
60
;
long
nh
=
1000
*
60
*
60
;
long
nm
=
1000
*
60
;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long
diff
=
endDate
.
getTime
()
-
nowDate
.
getTime
();
// 计算差多少天
long
day
=
diff
/
nd
;
// 计算差多少小时
long
hour
=
diff
%
nd
/
nh
;
// 计算差多少分钟
long
min
=
diff
%
nd
%
nh
/
nm
;
// 计算差多少秒//输出结果
return
String
.
valueOf
(
day
)
+
"天"
+
hour
+
"小时"
+
min
+
"分钟"
;
}
/**
* 获取两个时间差,时,分,秒
* @param endDate
* @param nowDate
* @return
*/
public
static
long
[]
getDatePoor
(
Date
endDate
,
Date
nowDate
)
{
if
(
endDate
==
null
||
nowDate
==
null
)
{
return
null
;
}
long
nd
=
1000
*
24
*
60
*
60
;
long
nh
=
1000
*
60
*
60
;
long
nm
=
1000
*
60
;
// long ns = 1000;
// 获得两个时间的毫秒时间差异
long
diff
=
endDate
.
getTime
()
-
nowDate
.
getTime
();
// 计算差多少天
long
day
=
diff
/
nd
;
// 计算差多少小时
long
hour
=
diff
%
nd
/
nh
;
// 计算差多少分钟
long
min
=
diff
%
nd
%
nh
/
nm
;
// 计算差多少秒//输出结果
return
new
long
[]{
day
,
hour
,
min
};
}
/**
* 获取下一周最后一天
* @return
*/
public
static
Date
getLastDayOfNextWeek
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
add
(
Calendar
.
WEEK_OF_YEAR
,
1
);
while
(
calendar
.
get
(
Calendar
.
DAY_OF_WEEK
)
!=
Calendar
.
SUNDAY
)
{
calendar
.
add
(
Calendar
.
DATE
,
1
);
}
return
calendar
.
getTime
();
}
/**
* 获取今天开始时间
* @return
*/
public
static
Date
getDayBegin
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
cal
.
set
(
Calendar
.
MINUTE
,
0
);
cal
.
set
(
Calendar
.
SECOND
,
0
);
cal
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
cal
.
getTime
();
}
/**
* 获取今天结束时间
* @return
*/
public
static
Date
getDayEnd
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
cal
.
set
(
Calendar
.
MINUTE
,
59
);
cal
.
set
(
Calendar
.
SECOND
,
59
);
return
cal
.
getTime
();
}
/**
* 获取某个日期的开始时间
* @param day
* @return
*/
public
static
Timestamp
getDayStartTime
(
Date
day
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
day
)
{
calendar
.
setTime
(
day
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
0
,
0
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
/**
* 获取某个日期的结束时间
* @param day 日期
* @return
*/
public
static
Timestamp
getDayEndTime
(
Date
day
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
if
(
null
!=
day
)
{
calendar
.
setTime
(
day
);
}
calendar
.
set
(
calendar
.
get
(
Calendar
.
YEAR
),
calendar
.
get
(
Calendar
.
MONTH
),
calendar
.
get
(
Calendar
.
DAY_OF_MONTH
),
23
,
59
,
59
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
999
);
return
new
Timestamp
(
calendar
.
getTimeInMillis
());
}
/**
* 获取昨天开始时间
* @return
*/
public
static
Date
getBeginDayOfYesterday
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
setTime
(
getDayBegin
());
cal
.
add
(
Calendar
.
DAY_OF_MONTH
,
-
1
);
return
cal
.
getTime
();
}
/**
* 获取昨天的结束时间
* @return
*/
public
static
Date
getEndDayOfYesterDay
()
{
Calendar
cal
=
new
GregorianCalendar
();
cal
.
setTime
(
getDayEnd
());
cal
.
add
(
Calendar
.
DAY_OF_MONTH
,
-
1
);
return
cal
.
getTime
();
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/FileUtils.java
View file @
957ac6e5
...
@@ -97,60 +97,71 @@ public class FileUtils {
...
@@ -97,60 +97,71 @@ public class FileUtils {
public
final
static
String
TEXT
=
"TEXT"
;
public
final
static
String
TEXT
=
"TEXT"
;
/**
/**
* OFFICE
*/
public
final
static
String
OFFICE
=
"OFFICE"
;
/**
* PDF文件格式
* PDF文件格式
*/
*/
public
static
final
String
[]
PDF_GATHER
=
{
"PDF"
};
public
static
final
String
[]
PDF_GATHER
=
{
"PDF"
};
/**
/**
* XML文件格式
* XML文件格式
*/
*/
public
static
final
String
[]
XML_GATHER
=
{
"XML"
};
public
static
final
String
[]
XML_GATHER
=
{
"XML"
};
/**
/**
* 图片文件格式
* 图片文件格式
*/
*/
public
static
final
String
[]
IMAGE_GATHER
=
{
"BMP"
,
"JPG"
,
"GIF"
,
"PNG"
,
"PCX"
,
"TIF"
,
"JPEG"
,
"SVG"
};
public
static
final
String
[]
IMAGE_GATHER
=
{
"BMP"
,
"JPG"
,
"GIF"
,
"PNG"
,
"PCX"
,
"TIF"
,
"JPEG"
,
"SVG"
,
"WEBP"
};
/**
/**
* 音頻文件格式 【"LRC" 为歌词字幕(这里作为音頻文件上传)】
* 音頻文件格式 【"LRC" 为歌词字幕(这里作为音頻文件上传)】
*/
*/
public
static
final
String
[]
AUDIO_GATHER
=
{
"AMR"
,
"MP3"
,
"WMA"
,
"WAV"
,
"AAC"
,
"APE"
,
"M4A"
};
public
static
final
String
[]
AUDIO_GATHER
=
{
"AMR"
,
"MP3"
,
"WMA"
,
"WAV"
,
"AAC"
,
"APE"
,
"M4A"
};
/**
/**
* 視頻文件格式 【"SRT", "SSA", "SMI", "SUB" 为视频“外挂型”字幕(这里作为视频文件上传)】
* 視頻文件格式 【"SRT", "SSA", "SMI", "SUB" 为视频“外挂型”字幕(这里作为视频文件上传)】
*/
*/
public
static
final
String
[]
VIDEO_GATHER
=
{
"MPG"
,
"MPEG"
,
"AVI"
,
"MOV"
,
"ASF"
,
"WMV"
,
"NAVI"
,
"3GP"
,
"MKV"
,
public
static
final
String
[]
VIDEO_GATHER
=
{
"MPG"
,
"MPEG"
,
"AVI"
,
"MOV"
,
"ASF"
,
"WMV"
,
"NAVI"
,
"3GP"
,
"MKV"
,
"FLV"
,
"F4V"
,
"RMVB"
,
"RM"
,
"MP4"
,
"SRT"
,
"SSA"
,
"SMI"
,
"SUB"
,
"ASX"
,
"M3U8"
};
"FLV"
,
"F4V"
,
"RMVB"
,
"RM"
,
"MP4"
,
"SRT"
,
"SSA"
,
"SMI"
,
"SUB"
,
"ASX"
,
"M3U8"
};
/**
/**
* 压缩包文件格式
* 压缩包文件格式
*/
*/
public
static
final
String
[]
COMPRESS_GATHER
=
{
"RAR"
,
"ZIP"
};
public
static
final
String
[]
COMPRESS_GATHER
=
{
"RAR"
,
"ZIP"
};
/**
/**
* 文件格式
* 文件格式
*/
*/
public
static
final
String
[]
TEXT_GATHER
=
{
"TXT"
,
"LRC"
};
public
static
final
String
[]
TEXT_GATHER
=
{
"TXT"
,
"LRC"
};
/**
/**
* 编辑器格式
* 编辑器格式
*/
*/
public
static
final
String
[]
EDITOR_GATHER
=
{
"DOC"
,
"DOCX"
,
"XLS"
,
"XLSX"
,
"PPT"
,
"PPTX"
};
public
static
final
String
[]
EDITOR_GATHER
=
{
"DOC"
,
"DOCX"
,
"XLS"
,
"XLSX"
,
"PPT"
,
"PPTX"
};
/**
/**
* word格式
* word格式
*/
*/
public
static
final
String
[]
WORD_GATHER
=
{
"DOC"
,
"DOCX"
};
public
static
final
String
[]
WORD_GATHER
=
{
"DOC"
,
"DOCX"
};
/**
/**
* excel格式
* excel格式
*/
*/
public
static
final
String
[]
EXCEL_GATHER
=
{
"XLS"
,
"XLSX"
,
"XLSM"
,
"XLT"
,
"XLTX"
,
"XLTM"
,
"CSV"
};
public
static
final
String
[]
EXCEL_GATHER
=
{
"XLS"
,
"XLSX"
,
"XLSM"
,
"XLT"
,
"XLTX"
,
"XLTM"
,
"CSV"
};
/**
/**
* PPT格式
* PPT格式
*/
*/
public
static
final
String
[]
PPT_GATHER
=
{
"PPT"
,
"PPTX"
};
public
static
final
String
[]
PPT_GATHER
=
{
"PPT"
,
"PPTX"
};
/**
* office
*/
public
static
final
String
[]
OFFICE_GATHER
=
{
"DOC"
,
"DOCX"
,
"PPT"
,
"PPTX"
,
"XLS"
,
"XLSX"
,
"XLSM"
,
"XLT"
,
"XLTX"
,
"XLTM"
,
"CSV"
};
/**
/**
* 根据文件类型获取文件分类
* 根据文件类型获取文件分类
...
@@ -190,17 +201,22 @@ public class FileUtils {
...
@@ -190,17 +201,22 @@ public class FileUtils {
if
(
Arrays
.
asList
(
EDITOR_GATHER
).
contains
(
fileType
.
toUpperCase
()))
{
if
(
Arrays
.
asList
(
EDITOR_GATHER
).
contains
(
fileType
.
toUpperCase
()))
{
return
EDITOR
;
return
EDITOR
;
}
}
// COMPRESS
// TEXT
if
(
Arrays
.
asList
(
TEXT_GATHER
).
contains
(
fileType
.
toUpperCase
()))
{
if
(
Arrays
.
asList
(
TEXT_GATHER
).
contains
(
fileType
.
toUpperCase
()))
{
return
TEXT
;
return
TEXT
;
}
}
// OFFICE
if
(
Arrays
.
asList
(
OFFICE_GATHER
).
contains
(
fileType
.
toUpperCase
()))
{
return
OFFICE
;
}
return
null
;
return
null
;
}
}
/**
/**
* 传入文件夹路径,该方法能够实现创建整个路径
* 传入文件夹路径,该方法能够实现创建整个路径
*
*
* @param path 文件夹路径,不包含文件名称及后缀名
* @param path
* 文件夹路径,不包含文件名称及后缀名
*/
*/
public
static
boolean
isDir
(
String
filePath
)
{
public
static
boolean
isDir
(
String
filePath
)
{
if
(
StringUtil
.
isEmpty
(
filePath
))
{
if
(
StringUtil
.
isEmpty
(
filePath
))
{
...
@@ -864,6 +880,7 @@ public class FileUtils {
...
@@ -864,6 +880,7 @@ public class FileUtils {
lines
.
forEach
(
line
->
{
lines
.
forEach
(
line
->
{
result
.
append
(
line
+
System
.
lineSeparator
());
result
.
append
(
line
+
System
.
lineSeparator
());
});
});
lines
.
close
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【文件工具】读取文件内容8.<ERROR>:"
+
e
.
getMessage
(),
e
);
LOGGER
.
error
(
"【文件工具】读取文件内容8.<ERROR>:"
+
e
.
getMessage
(),
e
);
}
finally
{
}
finally
{
...
@@ -877,7 +894,8 @@ public class FileUtils {
...
@@ -877,7 +894,8 @@ public class FileUtils {
* 文件剪切,网络路径、按文件大小的百分比
* 文件剪切,网络路径、按文件大小的百分比
*
*
* @param url
* @param url
* @param percent 1~100的整数
* @param percent
* 1~100的整数
* @return 返回剪切后上传后的文件路径
* @return 返回剪切后上传后的文件路径
* @throws BizException
* @throws BizException
*/
*/
...
@@ -908,7 +926,8 @@ public class FileUtils {
...
@@ -908,7 +926,8 @@ public class FileUtils {
* 文件剪切,本地路径、按百分比
* 文件剪切,本地路径、按百分比
*
*
* @param inputFile
* @param inputFile
* @param cutPercent 1~100的整数
* @param cutPercent
* 1~100的整数
* @return 返回本地路径地址
* @return 返回本地路径地址
* @throws BizException
* @throws BizException
*/
*/
...
@@ -926,8 +945,10 @@ public class FileUtils {
...
@@ -926,8 +945,10 @@ public class FileUtils {
/**
/**
* 文件剪切
* 文件剪切
*
*
* @param inputFile 待剪切的文件
* @param inputFile
* @param cutLength 剪切长度(Byte)
* 待剪切的文件
* @param cutLength
* 剪切长度(Byte)
*/
*/
public
static
String
clipByLength
(
File
inputFile
,
long
cutLength
)
throws
BizException
{
public
static
String
clipByLength
(
File
inputFile
,
long
cutLength
)
throws
BizException
{
LOGGER
.
info
(
"【文件API】文件剪切.<START>.[cutLength]="
+
cutLength
);
LOGGER
.
info
(
"【文件API】文件剪切.<START>.[cutLength]="
+
cutLength
);
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/ImageUtils.java
View file @
957ac6e5
...
@@ -14,9 +14,12 @@ import javax.imageio.ImageIO;
...
@@ -14,9 +14,12 @@ import javax.imageio.ImageIO;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.dcg.util.StringUtils
;
import
com.itextpdf.text.Image
;
import
com.itextpdf.text.Image
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.ImageConstant
;
import
com.pcloud.common.constant.ImageConstant
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageEnum
;
import
com.pcloud.common.enums.ImageEnum
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
import
com.pcloud.common.exceptions.FileException
;
...
@@ -688,4 +691,37 @@ public class ImageUtils {
...
@@ -688,4 +691,37 @@ public class ImageUtils {
return
size
;
return
size
;
}
}
/**
* 上传的图片转换成webpO
*
* @param localFilePath
* 源文件的本地路径
* @param httpUrl
* 源文件上传后的路径,主要用于子文件上传时对应http文件路径
*/
public
static
UploadResultInfo
toWebp
(
String
fileUrl
)
{
String
fileNameAll
=
FileUtils
.
getFileNameAll
(
fileUrl
);
String
localFilePath
=
FilePathConst
.
DOWNLOAD_PATH
+
fileNameAll
;
FileUtils
.
downloadFileFromUrl
(
fileUrl
,
localFilePath
);
String
tragetPath
=
null
;
try
{
tragetPath
=
com
.
dcg
.
util
.
ImageUtils
.
transcodeToWebp
(
localFilePath
,
80
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【IMAGE】图片转换成webp失败:"
+
e
.
getMessage
(),
e
);
return
null
;
}
if
(
StringUtils
.
isEmpty
(
tragetPath
))
{
return
null
;
}
try
{
return
OssUtils
.
uploadLocalFile4Child
(
tragetPath
,
fileUrl
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【IMAGE】图片转换成webp,上传失败:"
+
e
.
getMessage
(),
e
);
}
finally
{
FileUtils
.
deleteFile
(
localFilePath
);
FileUtils
.
deleteFile
(
tragetPath
);
}
return
null
;
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/PictureUtil.java
View file @
957ac6e5
...
@@ -213,7 +213,7 @@ public class PictureUtil {
...
@@ -213,7 +213,7 @@ public class PictureUtil {
header
.
put
(
"Content-Type"
,
"application/json"
);
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
param
.
put
(
"htmlCode"
,
html
);
String
postResult
=
HttpKit
.
post
(
"http://192.168.
92.111:8214
/transcode/htm2img/jpg"
,
JSON
.
toJSONString
(
param
));
String
postResult
=
HttpKit
.
post
(
"http://192.168.
1.7:8216
/transcode/htm2img/jpg"
,
JSON
.
toJSONString
(
param
));
Map
map
=
JSONUtils
.
jsonToMap
(
postResult
,
String
.
class
,
String
.
class
);
Map
map
=
JSONUtils
.
jsonToMap
(
postResult
,
String
.
class
,
String
.
class
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/QrcodeUtils.java
View file @
957ac6e5
...
@@ -21,6 +21,7 @@ import java.util.Map;
...
@@ -21,6 +21,7 @@ import java.util.Map;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
javax.swing.ImageIcon
;
import
javax.swing.ImageIcon
;
import
com.pcloud.common.utils.cache.redis.JedisClusterUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -215,6 +216,42 @@ public class QrcodeUtils {
...
@@ -215,6 +216,42 @@ public class QrcodeUtils {
}
}
/**
/**
* 创建二维码
*
* @param url
* 二维码响应地址
* @return
* @throws Exception
*/
public
static
String
createWithMargin
(
String
url
,
Integer
marginNum
)
throws
BizException
{
String
key
=
"createWithMargin:"
+
url
+
"_"
+
marginNum
;
if
(
JedisClusterUtils
.
exists
(
key
)){
String
s
=
JedisClusterUtils
.
get
(
key
);
return
s
;
}
else
{
LOGGER
.
info
(
"【二维码】创建二维码,<START>.[url]="
+
url
);
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
level
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
marginNum
);
// 设置白边
try
{
// 生成矩阵
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
url
,
BarcodeFormat
.
QR_CODE
,
ImageConstant
.
QRCODE_WITH
,
ImageConstant
.
QRCODE_HEIGHT
,
hints
);
BufferedImage
bufferedImage
=
toBufferedImage
(
bitMatrix
,
onColor
);
bufferedImage
.
flush
();
String
s
=
uploadImage
(
bufferedImage
);
JedisClusterUtils
.
set
(
key
,
s
,
24
*
3600
);
return
s
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建二维码失败"
);
}
}
}
/**
* 创建带颜色的二维码
* 创建带颜色的二维码
* @param url
* @param url
* @param onColor
* @param onColor
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/ResultUtils.java
View file @
957ac6e5
...
@@ -18,6 +18,26 @@ import com.pcloud.common.page.PageBeanNew;
...
@@ -18,6 +18,26 @@ import com.pcloud.common.page.PageBeanNew;
public
class
ResultUtils
{
public
class
ResultUtils
{
/**
/**
* 单个对象实例化
*
* @param t
* @param clazz
* @return
* @author songx
* @date 2019年1月14日,下午7:32:35
*/
public
static
<
T
>
T
object
(
T
t
,
Class
<
T
>
clazz
)
{
if
(
t
==
null
)
{
return
null
;
}
try
{
return
clazz
.
newInstance
();
}
catch
(
Exception
e
)
{
}
return
null
;
}
/**
* 集合查询结果判断
* 集合查询结果判断
*
*
* @param lists
* @param lists
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
View file @
957ac6e5
...
@@ -59,6 +59,7 @@ import com.pcloud.common.utils.string.StringUtil;
...
@@ -59,6 +59,7 @@ import com.pcloud.common.utils.string.StringUtil;
/**
/**
* @描述:
* @描述:
*
* @作者:songx
* @作者:songx
* @创建时间:2017年6月26日,下午12:03:44 @版本:1.0
* @创建时间:2017年6月26日,下午12:03:44 @版本:1.0
*/
*/
...
@@ -120,8 +121,10 @@ public class OssUtils {
...
@@ -120,8 +121,10 @@ public class OssUtils {
/**
/**
* 本地上传文件到aliOSS,isFlag=true,表示上传成功
* 本地上传文件到aliOSS,isFlag=true,表示上传成功
*
*
* @param filePath 源文件物理地址
* @param filePath
* @param fileName 源文件名称,可为null
* 源文件物理地址
* @param fileName
* 源文件名称,可为null
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -133,8 +136,10 @@ public class OssUtils {
...
@@ -133,8 +136,10 @@ public class OssUtils {
* 本地上传文件到aliOSS,isFlag=true,表示上传成功 <br>
* 本地上传文件到aliOSS,isFlag=true,表示上传成功 <br>
* 自定义上传后的文件名称
* 自定义上传后的文件名称
*
*
* @param filePath 源文件物理地址
* @param filePath
* @param fileName 源文件名称,可为null
* 源文件物理地址
* @param fileName
* 源文件名称,可为null
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -142,15 +147,41 @@ public class OssUtils {
...
@@ -142,15 +147,41 @@ public class OssUtils {
String
fileType
=
FileUtils
.
getFileType
(
filePath
);
String
fileType
=
FileUtils
.
getFileType
(
filePath
);
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
fileName
,
fileType
);
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
fileName
,
fileType
);
uploadPointFile2OSS
(
filePath
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
uploadPointFile2OSS
(
filePath
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
UploadResultInfo
uploadResultInfo
=
getResultInfo
(
outObjectKey
,
new
File
(
filePath
).
length
(),
null
,
AliyunConstant
.
FILE_BUCKET
);
// 如果上传的是图片转换成webp
// if (uploadResultInfo != null && FileTypeUtils.equalsGatherName(fileType, FileTypeUtils.IMAGE)) {
// ImageUtils.toWebp(uploadResultInfo.getUrl());
// }
return
uploadResultInfo
;
}
/**
* 父子文件上传,子文件全路径和父文件相同,文件后缀类型自定义
*
* @param filePath
* 子文件本地路径
* @param parentFileUrl
* 仅限OSS的全路径,其他本地文件路径均不支持
* @return
* @throws FileException
*/
public
static
UploadResultInfo
uploadLocalFile4Child
(
String
filePath
,
String
parentFileUrl
)
throws
FileException
{
String
fileType
=
FileUtils
.
getFileType
(
filePath
);
String
outObjectKey
=
splitObjectKey
(
parentFileUrl
)
+
"."
+
fileType
;
uploadPointFile2OSS
(
filePath
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
return
getResultInfo
(
outObjectKey
,
new
File
(
filePath
).
length
(),
null
,
AliyunConstant
.
FILE_BUCKET
);
return
getResultInfo
(
outObjectKey
,
new
File
(
filePath
).
length
(),
null
,
AliyunConstant
.
FILE_BUCKET
);
}
}
/**
/**
* byte[]数组文件流上传 ,isFlag=true,表示上传成功
* byte[]数组文件流上传 ,isFlag=true,表示上传成功
*
*
* @param buff 源文件字节数组
* @param buff
* @param fileName 源文件名称不带后缀,可为null
* 源文件字节数组
* @param fileType 源文件后缀
* @param fileName
* 源文件名称不带后缀,可为null
* @param fileType
* 源文件后缀
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -162,9 +193,12 @@ public class OssUtils {
...
@@ -162,9 +193,12 @@ public class OssUtils {
* 文件流上传到aliOSS, isFlag=true,表示上传成功 <br/>
* 文件流上传到aliOSS, isFlag=true,表示上传成功 <br/>
* 慎用,该方法稳定性不确定,曾出现过上传的文件流丢失的情况
* 慎用,该方法稳定性不确定,曾出现过上传的文件流丢失的情况
*
*
* @param is 源文件流
* @param is
* @param fileName 源文件名称不带后缀,可为null
* 源文件流
* @param fileType 源文件后缀
* @param fileName
* 源文件名称不带后缀,可为null
* @param fileType
* 源文件后缀
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -172,7 +206,12 @@ public class OssUtils {
...
@@ -172,7 +206,12 @@ public class OssUtils {
throws
FileException
{
throws
FileException
{
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
null
,
fileType
);
String
outObjectKey
=
getOutObjectKey
(
AliyunEnum
.
UPLOAD
.
value
,
null
,
fileType
);
uploadFileStream2OSS
(
is
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
uploadFileStream2OSS
(
is
,
AliyunConstant
.
FILE_BUCKET
,
outObjectKey
);
return
getResultInfo
(
outObjectKey
,
null
,
null
,
AliyunConstant
.
FILE_BUCKET
);
UploadResultInfo
uploadResultInfo
=
getResultInfo
(
outObjectKey
,
null
,
null
,
AliyunConstant
.
FILE_BUCKET
);
// 如果上传的是图片转换成webp
// if (uploadResultInfo != null && FileTypeUtils.equalsGatherName(fileType, FileTypeUtils.IMAGE)) {
// ImageUtils.toWebp(uploadResultInfo.getUrl());
// }
return
uploadResultInfo
;
}
}
/**
/**
...
@@ -246,8 +285,10 @@ public class OssUtils {
...
@@ -246,8 +285,10 @@ public class OssUtils {
/**
/**
* 提交MP4转码作业
* 提交MP4转码作业
*
*
* @param fileName 源文件的名称不带后缀,可为null
* @param fileName
* @param filePath 源文件本地路径
* 源文件的名称不带后缀,可为null
* @param filePath
* 源文件本地路径
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -277,9 +318,12 @@ public class OssUtils {
...
@@ -277,9 +318,12 @@ public class OssUtils {
/**
/**
* 提交MP4转码作业,文件流方式
* 提交MP4转码作业,文件流方式
*
*
* @param buff 源文件流
* @param buff
* @param fileName 源文件的名称不带后缀,可为null
* 源文件流
* @param fileType 源文件的后缀
* @param fileName
* 源文件的名称不带后缀,可为null
* @param fileType
* 源文件的后缀
* @return
* @return
*/
*/
public
static
String
submitTranscodeJobMp4
(
byte
[]
buff
,
String
fileName
,
String
fileType
)
throws
FileException
{
public
static
String
submitTranscodeJobMp4
(
byte
[]
buff
,
String
fileName
,
String
fileType
)
throws
FileException
{
...
@@ -296,8 +340,10 @@ public class OssUtils {
...
@@ -296,8 +340,10 @@ public class OssUtils {
/**
/**
* 提交MP3转码作业
* 提交MP3转码作业
*
*
* @param fileName 源文件的名称不带后缀,可为null
* @param fileName
* @param filePath 源文件本地路径
* 源文件的名称不带后缀,可为null
* @param filePath
* 源文件本地路径
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -328,9 +374,12 @@ public class OssUtils {
...
@@ -328,9 +374,12 @@ public class OssUtils {
* 提交MP3转码作业,文件流方式 <br/>
* 提交MP3转码作业,文件流方式 <br/>
* 使用byte[]方式上传,文件流上传容易导致读取长度0,造成转码失败
* 使用byte[]方式上传,文件流上传容易导致读取长度0,造成转码失败
*
*
* @param is 源文件流
* @param is
* @param fileName 源文件的名称不带后缀,可为null
* 源文件流
* @param fileType 源文件的后缀
* @param fileName
* 源文件的名称不带后缀,可为null
* @param fileType
* 源文件的后缀
* @return
* @return
*/
*/
@Deprecated
@Deprecated
...
@@ -347,9 +396,12 @@ public class OssUtils {
...
@@ -347,9 +396,12 @@ public class OssUtils {
/**
/**
* 提交MP3转码作业
* 提交MP3转码作业
*
*
* @param buff 文件
* @param buff
* @param fileName 源文件的名称不带后缀,可为null
* 文件
* @param fileType 上传的文件后缀
* @param fileName
* 源文件的名称不带后缀,可为null
* @param fileType
* 上传的文件后缀
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -380,8 +432,10 @@ public class OssUtils {
...
@@ -380,8 +432,10 @@ public class OssUtils {
/**
/**
* 转码作业
* 转码作业
*
*
* @param fileName 文件名称
* @param fileName
* @param filePath 文件地址
* 文件名称
* @param filePath
* 文件地址
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -394,9 +448,12 @@ public class OssUtils {
...
@@ -394,9 +448,12 @@ public class OssUtils {
* 转码作业
* 转码作业
*
*
* @param fileName
* @param fileName
* @param fileUrl 文件地址
* @param fileUrl
* @param outFileType 输出文件类型
* 文件地址
* @param waterMarkContent 视频水印文本,如果不需要水印传null
* @param outFileType
* 输出文件类型
* @param waterMarkContent
* 视频水印文本,如果不需要水印传null
* @return [0]:jobId,[1]:转码后的地址
* @return [0]:jobId,[1]:转码后的地址
*/
*/
public
static
String
[]
transcodeJobEx
(
String
fileName
,
String
fileUrl
,
String
outFileType
,
public
static
String
[]
transcodeJobEx
(
String
fileName
,
String
fileUrl
,
String
outFileType
,
...
@@ -479,8 +536,10 @@ public class OssUtils {
...
@@ -479,8 +536,10 @@ public class OssUtils {
/**
/**
* 视频文件合并,异步方法
* 视频文件合并,异步方法
*
*
* @param fileUrl 主文件地址
* @param fileUrl
* @param mergeUrls 需要合并的子文件列表,最多支持4个
* 主文件地址
* @param mergeUrls
* 需要合并的子文件列表,最多支持4个
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -511,8 +570,10 @@ public class OssUtils {
...
@@ -511,8 +570,10 @@ public class OssUtils {
/**
/**
* 视频文件合并,同步方法
* 视频文件合并,同步方法
*
*
* @param fileUrl 主文件地址
* @param fileUrl
* @param mergeUrls 需要合并的子文件列表,最多支持4个
* 主文件地址
* @param mergeUrls
* 需要合并的子文件列表,最多支持4个
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -554,10 +615,14 @@ public class OssUtils {
...
@@ -554,10 +615,14 @@ public class OssUtils {
/**
/**
* 转码作业
* 转码作业
*
*
* @param inputFile 输入文件
* @param inputFile
* @param templateId 转码模板
* 输入文件
* @param outObjectKey 转码输出对象地址
* @param templateId
* @param waterMarkConfigArray 水印参数
* 转码模板
* @param outObjectKey
* 转码输出对象地址
* @param waterMarkConfigArray
* 水印参数
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -625,7 +690,7 @@ public class OssUtils {
...
@@ -625,7 +690,7 @@ public class OssUtils {
JSONArray
mergeJsons
=
new
JSONArray
();
JSONArray
mergeJsons
=
new
JSONArray
();
for
(
String
mergeUrl
:
mergeUrls
)
{
for
(
String
mergeUrl
:
mergeUrls
)
{
// 如果是本地文件先上传
// 如果是本地文件先上传
if
(!
StringTools
.
startsWith
(
mergeUrl
,
new
String
[]{
"http://"
,
"https://"
}))
{
if
(!
StringTools
.
startsWith
(
mergeUrl
,
new
String
[]
{
"http://"
,
"https://"
}))
{
UploadResultInfo
uploadResultInfo
=
uploadLocalFile
(
mergeUrl
,
null
);
UploadResultInfo
uploadResultInfo
=
uploadLocalFile
(
mergeUrl
,
null
);
if
(!
uploadResultInfo
.
isFlag
())
{
if
(!
uploadResultInfo
.
isFlag
())
{
continue
;
continue
;
...
@@ -673,8 +738,10 @@ public class OssUtils {
...
@@ -673,8 +738,10 @@ public class OssUtils {
*
*
* @param fileName
* @param fileName
* @param filePath
* @param filePath
* @param seek 开始时间:[0.000,86399.999]
* @param seek
* @param duration 持续时长 [0.000,86399.999]
* 开始时间:[0.000,86399.999]
* @param duration
* 持续时长 [0.000,86399.999]
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -714,8 +781,10 @@ public class OssUtils {
...
@@ -714,8 +781,10 @@ public class OssUtils {
* @param buff
* @param buff
* @param fileName
* @param fileName
* @param fileType
* @param fileType
* @param seek 开始时间:[0.000,86399.999]
* @param seek
* @param duration 持续时长 [0.000,86399.999]
* 开始时间:[0.000,86399.999]
* @param duration
* 持续时长 [0.000,86399.999]
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -737,8 +806,10 @@ public class OssUtils {
...
@@ -737,8 +806,10 @@ public class OssUtils {
*
*
* @param inputFile
* @param inputFile
* @param outObjectKey
* @param outObjectKey
* @param seek 开始时间:[0.000,86399.999]
* @param seek
* @param duration 持续时长 [0.000,86399.999]
* 开始时间:[0.000,86399.999]
* @param duration
* 持续时长 [0.000,86399.999]
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -785,8 +856,10 @@ public class OssUtils {
...
@@ -785,8 +856,10 @@ public class OssUtils {
/**
/**
* 组装剪切参数
* 组装剪切参数
*
*
* @param seek 开始时间:sssss[.SSS]
* @param seek
* @param duration 持续时长 sssss[.SSS]
* 开始时间:sssss[.SSS]
* @param duration
* 持续时长 sssss[.SSS]
* @return
* @return
*/
*/
private
static
JSONObject
generateClipInput
(
String
seek
,
String
duration
)
{
private
static
JSONObject
generateClipInput
(
String
seek
,
String
duration
)
{
...
@@ -804,7 +877,8 @@ public class OssUtils {
...
@@ -804,7 +877,8 @@ public class OssUtils {
* 提交视频截图任务,成功返回图片地址 <br>
* 提交视频截图任务,成功返回图片地址 <br>
*
*
* @param fileUrl
* @param fileUrl
* @param time 秒
* @param time
* 秒
* @return 成功:图片地址,失败:null
* @return 成功:图片地址,失败:null
*/
*/
public
static
String
submitSnapshotJob
(
String
fileUrl
,
int
time
)
{
public
static
String
submitSnapshotJob
(
String
fileUrl
,
int
time
)
{
...
@@ -1115,6 +1189,7 @@ public class OssUtils {
...
@@ -1115,6 +1189,7 @@ public class OssUtils {
}
else
{
}
else
{
uploadResultInfo
.
setSize
(
size
);
uploadResultInfo
.
setSize
(
size
);
}
}
uploadResultInfo
.
setFileName
(
FileUtils
.
getFileName
(
objectKey
));
uploadResultInfo
.
setFileId
(
"ali"
);
uploadResultInfo
.
setFileId
(
"ali"
);
uploadResultInfo
.
setFlag
(
true
);
uploadResultInfo
.
setFlag
(
true
);
uploadResultInfo
.
setFinish
(
true
);
uploadResultInfo
.
setFinish
(
true
);
...
@@ -1152,6 +1227,9 @@ public class OssUtils {
...
@@ -1152,6 +1227,9 @@ public class OssUtils {
if
(!
fileUrl
.
startsWith
(
"http"
))
{
if
(!
fileUrl
.
startsWith
(
"http"
))
{
return
fileUrl
;
return
fileUrl
;
}
}
if
(
fileUrl
.
startsWith
(
"oss/"
))
{
return
fileUrl
;
}
if
(!
StringTools
.
contains
(
fileUrl
,
AliyunConstant
.
OSS_CDN_URLS
))
{
if
(!
StringTools
.
contains
(
fileUrl
,
AliyunConstant
.
OSS_CDN_URLS
))
{
throw
new
FileException
(
FileException
.
FILE_TYPE_ERROR
,
"不是有效的文件路径"
);
throw
new
FileException
(
FileException
.
FILE_TYPE_ERROR
,
"不是有效的文件路径"
);
}
}
...
@@ -1227,7 +1305,8 @@ public class OssUtils {
...
@@ -1227,7 +1305,8 @@ public class OssUtils {
* 密钥需要结合域名https://download.5rs.me使用,可以在浏览器直接下载 <br>
* 密钥需要结合域名https://download.5rs.me使用,可以在浏览器直接下载 <br>
*
*
* @param fileUrl
* @param fileUrl
* @param second 秒,地址有效期
* @param second
* 秒,地址有效期
* @return
* @return
*/
*/
public
static
String
getHashValue
(
String
fileUrl
,
long
second
)
{
public
static
String
getHashValue
(
String
fileUrl
,
long
second
)
{
...
@@ -1247,7 +1326,8 @@ public class OssUtils {
...
@@ -1247,7 +1326,8 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
* 默认有效期48小时
* 默认有效期48小时
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKey
(
String
fileUrl
)
{
public
static
String
urlAddKey
(
String
fileUrl
)
{
...
@@ -1258,7 +1338,8 @@ public class OssUtils {
...
@@ -1258,7 +1338,8 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
* 长期有效
* 长期有效
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKeyLong
(
String
fileUrl
)
{
public
static
String
urlAddKeyLong
(
String
fileUrl
)
{
...
@@ -1268,8 +1349,10 @@ public class OssUtils {
...
@@ -1268,8 +1349,10 @@ public class OssUtils {
/**
/**
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 <br>
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* @param second 秒,地址有效期
* 文件URL全路径地址
* @param second
* 秒,地址有效期
* @return
* @return
*/
*/
public
static
String
urlAddKey
(
String
fileUrl
,
long
second
)
{
public
static
String
urlAddKey
(
String
fileUrl
,
long
second
)
{
...
@@ -1280,8 +1363,10 @@ public class OssUtils {
...
@@ -1280,8 +1363,10 @@ public class OssUtils {
/**
/**
* 将文件URL生成带密钥的地址,可以在浏览器直接访问(不转义中文) <br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问(不转义中文) <br>
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* @param second 秒,地址有效期
* 文件URL全路径地址
* @param second
* 秒,地址有效期
* @return
* @return
*/
*/
public
static
String
urlAddKeyChina
(
String
fileUrl
,
long
second
)
{
public
static
String
urlAddKeyChina
(
String
fileUrl
,
long
second
)
{
...
@@ -1308,7 +1393,8 @@ public class OssUtils {
...
@@ -1308,7 +1393,8 @@ public class OssUtils {
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
* 默认有效期48小时
* 默认有效期48小时
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKey2Sms
(
String
fileUrl
)
{
public
static
String
urlAddKey2Sms
(
String
fileUrl
)
{
...
@@ -1319,7 +1405,8 @@ public class OssUtils {
...
@@ -1319,7 +1405,8 @@ public class OssUtils {
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
* 长期有效
* 长期有效
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKeyLong2Sms
(
String
fileUrl
)
{
public
static
String
urlAddKeyLong2Sms
(
String
fileUrl
)
{
...
@@ -1329,8 +1416,10 @@ public class OssUtils {
...
@@ -1329,8 +1416,10 @@ public class OssUtils {
/**
/**
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
* 将文件URL生成带密钥的下载地址,返回的地址不带域名 <br>
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* @param second 秒,地址有效期
* 文件URL全路径地址
* @param second
* 秒,地址有效期
* @return
* @return
*/
*/
public
static
String
urlAddKey2Sms
(
String
fileUrl
,
long
second
)
{
public
static
String
urlAddKey2Sms
(
String
fileUrl
,
long
second
)
{
...
@@ -1354,7 +1443,8 @@ public class OssUtils {
...
@@ -1354,7 +1443,8 @@ public class OssUtils {
/**
/**
* 将文件URL生成带密钥的地址,可以在浏览器直接访问,并转换为短链接<br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问,并转换为短链接<br>
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKey2Short
(
String
fileUrl
)
{
public
static
String
urlAddKey2Short
(
String
fileUrl
)
{
...
@@ -1365,7 +1455,8 @@ public class OssUtils {
...
@@ -1365,7 +1455,8 @@ public class OssUtils {
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 ,并转换为短链接<br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问 ,并转换为短链接<br>
* 长期有效
* 长期有效
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* 文件URL全路径地址
* @return
* @return
*/
*/
public
static
String
urlAddKeyLong2Short
(
String
fileUrl
)
{
public
static
String
urlAddKeyLong2Short
(
String
fileUrl
)
{
...
@@ -1375,8 +1466,10 @@ public class OssUtils {
...
@@ -1375,8 +1466,10 @@ public class OssUtils {
/**
/**
* 将文件URL生成带密钥的地址,可以在浏览器直接访问,并转换为短链接<br>
* 将文件URL生成带密钥的地址,可以在浏览器直接访问,并转换为短链接<br>
*
*
* @param fileUrl 文件URL全路径地址
* @param fileUrl
* @param second 秒,地址有效期
* 文件URL全路径地址
* @param second
* 秒,地址有效期
* @return
* @return
*/
*/
public
static
String
urlAddKey2Short
(
String
fileUrl
,
long
second
)
{
public
static
String
urlAddKey2Short
(
String
fileUrl
,
long
second
)
{
...
@@ -1414,7 +1507,8 @@ public class OssUtils {
...
@@ -1414,7 +1507,8 @@ public class OssUtils {
* 图片缩放,按宽度等比例缩放
* 图片缩放,按宽度等比例缩放
*
*
* @param fileUrl
* @param fileUrl
* @param width 目前最大支持1024,超过1024或者小于0都按1024计算
* @param width
* 目前最大支持1024,超过1024或者小于0都按1024计算
* @return 返回处理后的图片本地地址
* @return 返回处理后的图片本地地址
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1437,7 +1531,8 @@ public class OssUtils {
...
@@ -1437,7 +1531,8 @@ public class OssUtils {
* 图片缩放,按倍数百分比缩放
* 图片缩放,按倍数百分比缩放
*
*
* @param fileUrl
* @param fileUrl
* @param p 1-1000,倍数百分比。 小于100,即是缩小,大于100即是放大。
* @param p
* 1-1000,倍数百分比。 小于100,即是缩小,大于100即是放大。
* @return 返回处理后的图片本地地址
* @return 返回处理后的图片本地地址
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1460,7 +1555,8 @@ public class OssUtils {
...
@@ -1460,7 +1555,8 @@ public class OssUtils {
* 图片自动旋转
* 图片自动旋转
*
*
* @param fileUrl
* @param fileUrl
* @param width 图片旋转以后的宽度,最大不能超过4096,传0则按原始宽度旋转
* @param width
* 图片旋转以后的宽度,最大不能超过4096,传0则按原始宽度旋转
* @return 返回处理后的图片本地地址
* @return 返回处理后的图片本地地址
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1486,10 +1582,14 @@ public class OssUtils {
...
@@ -1486,10 +1582,14 @@ public class OssUtils {
* 图片裁剪,如果图片带有旋转属性,会自动旋转纠正角度后在进行裁剪。
* 图片裁剪,如果图片带有旋转属性,会自动旋转纠正角度后在进行裁剪。
*
*
* @param fileUrl
* @param fileUrl
* @param width 裁剪的宽度
* @param width
* @param height 裁剪的高度
* 裁剪的宽度
* @param x 左上角开始, 裁剪的X轴坐标
* @param height
* @param y 左上角开始, 裁剪的Y轴坐标
* 裁剪的高度
* @param x
* 左上角开始, 裁剪的X轴坐标
* @param y
* 左上角开始, 裁剪的Y轴坐标
* @return 返回处理后的图片本地地址
* @return 返回处理后的图片本地地址
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1541,9 +1641,12 @@ public class OssUtils {
...
@@ -1541,9 +1641,12 @@ public class OssUtils {
/**
/**
* 图片增加水印(文本)
* 图片增加水印(文本)
*
*
* @param fileUrl 原图地址
* @param fileUrl
* @param fontSize 字体大小
* 原图地址
* @param watermarkContent 水印内容
* @param fontSize
* 字体大小
* @param watermarkContent
* 水印内容
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1572,8 +1675,10 @@ public class OssUtils {
...
@@ -1572,8 +1675,10 @@ public class OssUtils {
/**
/**
* 图片增加水印(图片)
* 图片增加水印(图片)
*
*
* @param fileUrl 原图地址
* @param fileUrl
* @param watermarkImageUrl 水印图片地址
* 原图地址
* @param watermarkImageUrl
* 水印图片地址
* @return
* @return
* @throws FileException
* @throws FileException
*/
*/
...
@@ -1695,7 +1800,7 @@ public class OssUtils {
...
@@ -1695,7 +1800,7 @@ public class OssUtils {
* @param fileUrl
* @param fileUrl
* @return true:001,false:002
* @return true:001,false:002
*/
*/
private
static
boolean
fileUrlExist001
(
String
fileUrl
)
{
public
static
boolean
fileUrlExist001
(
String
fileUrl
)
{
boolean
isUploadfe
=
false
;
boolean
isUploadfe
=
false
;
String
objectKey
=
splitObjectKey
(
fileUrl
);
String
objectKey
=
splitObjectKey
(
fileUrl
);
if
(
doesObjectExist
(
AliyunConstant
.
INPUT_BUCKET
,
objectKey
))
{
if
(
doesObjectExist
(
AliyunConstant
.
INPUT_BUCKET
,
objectKey
))
{
...
@@ -1704,4 +1809,19 @@ public class OssUtils {
...
@@ -1704,4 +1809,19 @@ public class OssUtils {
return
isUploadfe
;
return
isUploadfe
;
}
}
/**
* 判断文件是存在002中
*
* @param fileUrl
* @return true:001,false:002
*/
public
static
boolean
fileUrlExist002
(
String
fileUrl
)
{
boolean
isUploadfe
=
false
;
String
objectKey
=
splitObjectKey
(
fileUrl
);
if
(
doesObjectExist
(
AliyunConstant
.
FILE_BUCKET
,
objectKey
))
{
isUploadfe
=
true
;
}
return
isUploadfe
;
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/cookie/Cookie.java
View file @
957ac6e5
...
@@ -12,6 +12,7 @@ import org.slf4j.Logger;
...
@@ -12,6 +12,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.utils.NumberUtil
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.string.StringUtil
;
/**
/**
...
@@ -125,25 +126,25 @@ public class Cookie {
...
@@ -125,25 +126,25 @@ public class Cookie {
String
[]
channel
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
channel
=
userInfoArry
[
i
].
split
(
"="
);
String
channelId
=
channel
[
channel
.
length
-
1
];
String
channelId
=
channel
[
channel
.
length
-
1
];
userInfos
.
put
(
"channelId"
,
StringUtil
.
isEmpty
(
channelId
)
||
"undefined"
.
equalsIgnoreCase
(
channelId
)
userInfos
.
put
(
"channelId"
,
StringUtil
.
isEmpty
(
channelId
)
||
"undefined"
.
equalsIgnoreCase
(
channelId
)
||
"null"
.
equalsIgnoreCase
(
channelId
)
?
null
:
Long
.
valueOf
(
channelId
));
||
"null"
.
equalsIgnoreCase
(
channelId
)
?
null
:
NumberUtil
.
toLong
(
channelId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"officialAccountsId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"officialAccountsId"
))
{
String
[]
wechat
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
wechat
=
userInfoArry
[
i
].
split
(
"="
);
String
officialAccountsId
=
wechat
[
wechat
.
length
-
1
];
String
officialAccountsId
=
wechat
[
wechat
.
length
-
1
];
userInfos
.
put
(
"officialAccountsId"
,
StringUtil
.
isEmpty
(
officialAccountsId
)
||
"undefined"
.
equalsIgnoreCase
(
officialAccountsId
)
userInfos
.
put
(
"officialAccountsId"
,
StringUtil
.
isEmpty
(
officialAccountsId
)
||
"undefined"
.
equalsIgnoreCase
(
officialAccountsId
)
||
"null"
.
equalsIgnoreCase
(
officialAccountsId
)
?
null
:
Long
.
valueOf
(
officialAccountsId
));
||
"null"
.
equalsIgnoreCase
(
officialAccountsId
)
?
null
:
NumberUtil
.
toLong
(
officialAccountsId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"wechatUserId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"wechatUserId"
))
{
String
[]
user
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
user
=
userInfoArry
[
i
].
split
(
"="
);
String
wechatUserId
=
user
[
user
.
length
-
1
];
String
wechatUserId
=
user
[
user
.
length
-
1
];
userInfos
.
put
(
"wechatUserId"
,
StringUtil
.
isEmpty
(
wechatUserId
)
||
"undefined"
.
equalsIgnoreCase
(
wechatUserId
)
userInfos
.
put
(
"wechatUserId"
,
StringUtil
.
isEmpty
(
wechatUserId
)
||
"undefined"
.
equalsIgnoreCase
(
wechatUserId
)
||
"null"
.
equalsIgnoreCase
(
wechatUserId
)
?
null
:
Long
.
valueOf
(
wechatUserId
));
||
"null"
.
equalsIgnoreCase
(
wechatUserId
)
?
null
:
NumberUtil
.
toLong
(
wechatUserId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"partyId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"partyId"
))
{
String
[]
party
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
party
=
userInfoArry
[
i
].
split
(
"="
);
String
partyId
=
party
[
party
.
length
-
1
];
String
partyId
=
party
[
party
.
length
-
1
];
userInfos
.
put
(
"partyId"
,
StringUtil
.
isEmpty
(
partyId
)
||
"undefined"
.
equalsIgnoreCase
(
partyId
)
||
"null"
.
equalsIgnoreCase
(
partyId
)
userInfos
.
put
(
"partyId"
,
StringUtil
.
isEmpty
(
partyId
)
||
"undefined"
.
equalsIgnoreCase
(
partyId
)
||
"null"
.
equalsIgnoreCase
(
partyId
)
?
null
:
Long
.
valueOf
(
partyId
));
?
null
:
NumberUtil
.
toLong
(
partyId
));
}
}
// editBy TC cookie里面需要带上顾问,systemCode,是否系统,场景值
// editBy TC cookie里面需要带上顾问,systemCode,是否系统,场景值
// modify by songx at 2017-05-17 如果值为undefined或者null直接跳过
// modify by songx at 2017-05-17 如果值为undefined或者null直接跳过
...
@@ -151,7 +152,7 @@ public class Cookie {
...
@@ -151,7 +152,7 @@ public class Cookie {
String
[]
adviser
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
adviser
=
userInfoArry
[
i
].
split
(
"="
);
String
adviserId
=
adviser
[
adviser
.
length
-
1
];
String
adviserId
=
adviser
[
adviser
.
length
-
1
];
userInfos
.
put
(
"adviserId"
,
StringUtil
.
isEmpty
(
adviserId
)
||
"undefined"
.
equalsIgnoreCase
(
adviserId
)
||
"null"
.
equalsIgnoreCase
(
adviserId
)
userInfos
.
put
(
"adviserId"
,
StringUtil
.
isEmpty
(
adviserId
)
||
"undefined"
.
equalsIgnoreCase
(
adviserId
)
||
"null"
.
equalsIgnoreCase
(
adviserId
)
?
null
:
Long
.
valueOf
(
adviserId
));
?
null
:
NumberUtil
.
toLong
(
adviserId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"systemCode"
))
{
if
(
userInfoArry
[
i
].
contains
(
"systemCode"
))
{
String
[]
systemCode
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
systemCode
=
userInfoArry
[
i
].
split
(
"="
);
...
@@ -168,25 +169,25 @@ public class Cookie {
...
@@ -168,25 +169,25 @@ public class Cookie {
String
[]
scene
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
scene
=
userInfoArry
[
i
].
split
(
"="
);
String
sceneId
=
scene
[
scene
.
length
-
1
];
String
sceneId
=
scene
[
scene
.
length
-
1
];
userInfos
.
put
(
"sceneId"
,
StringUtil
.
isEmpty
(
sceneId
)
||
"undefined"
.
equalsIgnoreCase
(
sceneId
)
||
"null"
.
equalsIgnoreCase
(
sceneId
)
?
null
userInfos
.
put
(
"sceneId"
,
StringUtil
.
isEmpty
(
sceneId
)
||
"undefined"
.
equalsIgnoreCase
(
sceneId
)
||
"null"
.
equalsIgnoreCase
(
sceneId
)
?
null
:
Long
.
valueOf
(
sceneId
));
:
NumberUtil
.
toLong
(
sceneId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"userId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"userId"
))
{
String
[]
userLogin
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
userLogin
=
userInfoArry
[
i
].
split
(
"="
);
String
userId
=
userLogin
[
userLogin
.
length
-
1
];
String
userId
=
userLogin
[
userLogin
.
length
-
1
];
userInfos
.
put
(
"userId"
,
StringUtil
.
isEmpty
(
userId
)
||
"undefined"
.
equalsIgnoreCase
(
userId
)
||
"null"
.
equalsIgnoreCase
(
userId
)
?
null
userInfos
.
put
(
"userId"
,
StringUtil
.
isEmpty
(
userId
)
||
"undefined"
.
equalsIgnoreCase
(
userId
)
||
"null"
.
equalsIgnoreCase
(
userId
)
?
null
:
Long
.
valueOf
(
userId
));
:
NumberUtil
.
toLong
(
userId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"merchantMemberId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"merchantMemberId"
))
{
String
[]
merchant
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
merchant
=
userInfoArry
[
i
].
split
(
"="
);
String
merchantMemberId
=
merchant
[
merchant
.
length
-
1
];
String
merchantMemberId
=
merchant
[
merchant
.
length
-
1
];
userInfos
.
put
(
"merchantMemberId"
,
StringUtil
.
isEmpty
(
merchantMemberId
)
||
"undefined"
.
equalsIgnoreCase
(
merchantMemberId
)
userInfos
.
put
(
"merchantMemberId"
,
StringUtil
.
isEmpty
(
merchantMemberId
)
||
"undefined"
.
equalsIgnoreCase
(
merchantMemberId
)
||
"null"
.
equalsIgnoreCase
(
merchantMemberId
)
?
null
:
Long
.
valueOf
(
merchantMemberId
));
||
"null"
.
equalsIgnoreCase
(
merchantMemberId
)
?
null
:
NumberUtil
.
toLong
(
merchantMemberId
));
}
}
if
(
userInfoArry
[
i
].
contains
(
"agentMemberId"
))
{
if
(
userInfoArry
[
i
].
contains
(
"agentMemberId"
))
{
String
[]
merchant
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
merchant
=
userInfoArry
[
i
].
split
(
"="
);
String
agentMemberId
=
merchant
[
merchant
.
length
-
1
];
String
agentMemberId
=
merchant
[
merchant
.
length
-
1
];
userInfos
.
put
(
"agentMemberId"
,
StringUtil
.
isEmpty
(
agentMemberId
)
||
"undefined"
.
equalsIgnoreCase
(
agentMemberId
)
userInfos
.
put
(
"agentMemberId"
,
StringUtil
.
isEmpty
(
agentMemberId
)
||
"undefined"
.
equalsIgnoreCase
(
agentMemberId
)
||
"null"
.
equalsIgnoreCase
(
agentMemberId
)
?
null
:
Long
.
valueOf
(
agentMemberId
));
||
"null"
.
equalsIgnoreCase
(
agentMemberId
)
?
null
:
NumberUtil
.
toLong
(
agentMemberId
));
}
}
// add by gaop
// add by gaop
if
(
userInfoArry
[
i
].
contains
(
PREVIEW_TYPE
))
{
if
(
userInfoArry
[
i
].
contains
(
PREVIEW_TYPE
))
{
...
@@ -205,13 +206,13 @@ public class Cookie {
...
@@ -205,13 +206,13 @@ public class Cookie {
String
[]
firstTD
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
firstTD
=
userInfoArry
[
i
].
split
(
"="
);
String
code
=
firstTD
[
firstTD
.
length
-
1
];
String
code
=
firstTD
[
firstTD
.
length
-
1
];
userInfos
.
put
(
FIRST_TD
,
StringUtil
.
isEmpty
(
code
)
||
"undefined"
.
equalsIgnoreCase
(
code
)
||
"null"
.
equalsIgnoreCase
(
code
)
?
null
userInfos
.
put
(
FIRST_TD
,
StringUtil
.
isEmpty
(
code
)
||
"undefined"
.
equalsIgnoreCase
(
code
)
||
"null"
.
equalsIgnoreCase
(
code
)
?
null
:
Long
.
valueOf
(
code
));
:
NumberUtil
.
toLong
(
code
));
}
}
if
(
userInfoArry
[
i
].
contains
(
SECOND_TD
))
{
if
(
userInfoArry
[
i
].
contains
(
SECOND_TD
))
{
String
[]
secondTD
=
userInfoArry
[
i
].
split
(
"="
);
String
[]
secondTD
=
userInfoArry
[
i
].
split
(
"="
);
String
code
=
secondTD
[
secondTD
.
length
-
1
];
String
code
=
secondTD
[
secondTD
.
length
-
1
];
userInfos
.
put
(
SECOND_TD
,
StringUtil
.
isEmpty
(
code
)
||
"undefined"
.
equalsIgnoreCase
(
code
)
||
"null"
.
equalsIgnoreCase
(
code
)
?
null
userInfos
.
put
(
SECOND_TD
,
StringUtil
.
isEmpty
(
code
)
||
"undefined"
.
equalsIgnoreCase
(
code
)
||
"null"
.
equalsIgnoreCase
(
code
)
?
null
:
Long
.
valueOf
(
code
));
:
NumberUtil
.
toLong
(
code
));
}
}
}
}
return
userInfos
;
return
userInfos
;
...
@@ -226,7 +227,7 @@ public class Cookie {
...
@@ -226,7 +227,7 @@ public class Cookie {
*/
*/
public
static
Long
getId
(
String
userInfo
,
String
type
)
throws
BizException
{
public
static
Long
getId
(
String
userInfo
,
String
type
)
throws
BizException
{
String
value
=
getString
(
userInfo
,
type
);
String
value
=
getString
(
userInfo
,
type
);
return
StringUtil
.
isEmpty
(
value
)
||
"undefined"
.
equalsIgnoreCase
(
value
)
||
"null"
.
equalsIgnoreCase
(
value
)
?
null
:
Long
.
valueOf
(
value
);
return
StringUtil
.
isEmpty
(
value
)
||
"undefined"
.
equalsIgnoreCase
(
value
)
||
"null"
.
equalsIgnoreCase
(
value
)
?
null
:
NumberUtil
.
toLong
(
value
);
}
}
/**
/**
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/export/word/WordDataExportor.java
View file @
957ac6e5
...
@@ -127,6 +127,47 @@ public class WordDataExportor {
...
@@ -127,6 +127,47 @@ public class WordDataExportor {
}
}
/**
/**
* 生成word
* @param dataMap
* @param templateName
* @return
* @author linweibin
* @date 2017年5月22日 下午5:22:38
*/
@SuppressWarnings
(
"deprecation"
)
public
static
void
generateWord
(
Class
clazz
,
Map
<
String
,
Object
>
dataMap
,
String
templateName
,
File
tmpdir
,
String
fileName
)
{
logger
.
info
(
"开始生成word+++"
);
try
{
// 创建配置实例
Configuration
configuration
=
new
Configuration
();
// 设置编码
configuration
.
setDefaultEncoding
(
"UTF-8"
);
// 获取template文件路径
configuration
.
setClassForTemplateLoading
(
clazz
,
"/template"
);
// 获取模板
Template
template
=
configuration
.
getTemplate
(
templateName
);
// 输出文件
File
outFile
=
new
File
(
tmpdir
,
fileName
);
// 将模板和数据模型合并生成文件
Writer
out
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
outFile
),
"UTF-8"
));
// 生成文件
template
.
process
(
dataMap
,
out
);
logger
.
info
(
"生成word+++成功"
);
// 关闭流
out
.
flush
();
out
.
close
();
}
catch
(
Exception
e
)
{
logger
.
error
(
"生成word异常+++"
+
e
.
getMessage
(),
e
);
}
}
/**
* 生成随机文件名
* 生成随机文件名
* @return
* @return
* @author linweibin
* @author linweibin
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/httpclient/UrlUtils.java
View file @
957ac6e5
...
@@ -40,6 +40,11 @@ public class UrlUtils {
...
@@ -40,6 +40,11 @@ public class UrlUtils {
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
/**
/**
* 自定义生成 MD5 加密字符传前的混合 KEY
*/
public
static
final
String
PRIVATE_KEY
=
"lgsc1205"
;
/**
* 获取短链接(新浪)
* 获取短链接(新浪)
*
*
* @param long_url
* @param long_url
...
@@ -112,13 +117,13 @@ public class UrlUtils {
...
@@ -112,13 +117,13 @@ public class UrlUtils {
HttpPost
httpPost
=
new
HttpPost
(
REQUEST_URL2
);
HttpPost
httpPost
=
new
HttpPost
(
REQUEST_URL2
);
String
resContent
=
null
;
String
resContent
=
null
;
try
{
try
{
//设置参数到请求对象中
// 设置参数到请求对象中
JSONObject
jsonObject
=
new
JSONObject
();
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"originUrl"
,
long_url
);
jsonObject
.
put
(
"originUrl"
,
long_url
);
StringEntity
stringEntity
=
new
StringEntity
(
jsonObject
.
toJSONString
(),
Charset
.
forName
(
"UTF-8"
));
StringEntity
stringEntity
=
new
StringEntity
(
jsonObject
.
toJSONString
(),
Charset
.
forName
(
"UTF-8"
));
httpPost
.
setEntity
(
stringEntity
);
httpPost
.
setEntity
(
stringEntity
);
//设置header信息
// 设置header信息
//指定报文头【Content-type】、【User-Agent】
// 指定报文头【Content-type】、【User-Agent】
httpPost
.
setHeader
(
"Content-type"
,
"application/json;charset=UTF-8"
);
httpPost
.
setHeader
(
"Content-type"
,
"application/json;charset=UTF-8"
);
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpPost
);
CloseableHttpResponse
response
=
httpclient
.
execute
(
httpPost
);
// 获取响应实体
// 获取响应实体
...
@@ -134,27 +139,32 @@ public class UrlUtils {
...
@@ -134,27 +139,32 @@ public class UrlUtils {
}
}
/**
/**
* 缩短链接
* 对传入的链接进行加密
*
*
* @param url
* @param url
* @return
* @return
*/
*/
public
static
String
[]
shortenUrl
(
String
url
)
{
public
static
String
[]
shortenUrl
(
String
url
)
{
// 可以自定义生成 MD5 加密字符传前的混合 KEY
// 对传入网址进行 MD5 加密
String
key
=
"lgsc1205"
;
String
hex
=
MD5
.
getMD5Str
(
PRIVATE_KEY
+
url
);
return
shortenUrlMd5
(
hex
);
}
/**
* 缩短链接
*
* @param url
* @return
*/
public
static
String
[]
shortenUrlMd5
(
String
hex
)
{
// 要使用生成 URL 的字符
// 要使用生成 URL 的字符
String
[]
chars
=
new
String
[]{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
String
[]
chars
=
new
String
[]
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
,
"f"
,
"g"
,
"h"
,
"i"
,
"j"
,
"k"
,
"l"
,
"m"
,
"n"
,
"o"
,
"p"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"A"
,
"q"
,
"r"
,
"s"
,
"t"
,
"u"
,
"v"
,
"w"
,
"x"
,
"y"
,
"z"
,
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"G"
,
"H"
,
"I"
,
"J"
,
"K"
,
"L"
,
"M"
,
"N"
,
"O"
,
"P"
,
"Q"
,
"R"
,
"S"
,
"T"
,
"U"
,
"V"
,
"W"
,
"X"
,
"Y"
,
"Z"
"W"
,
"X"
,
"Y"
,
"Z"
};
};
// 对传入网址进行 MD5 加密
String
hex
=
MD5
.
getMD5Str
(
key
+
url
);
String
[]
resUrl
=
new
String
[
4
];
String
[]
resUrl
=
new
String
[
4
];
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
// 把加密字符按照 8 位一组 16 进制与 0x3FFFFFFF 进行位与运算
// 把加密字符按照 8 位一组 16 进制与 0x3FFFFFFF 进行位与运算
String
sTempSubString
=
hex
.
substring
(
i
*
8
,
i
*
8
+
8
);
String
sTempSubString
=
hex
.
substring
(
i
*
8
,
i
*
8
+
8
);
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/rsa/MD5.java
View file @
957ac6e5
...
@@ -10,8 +10,6 @@ import org.slf4j.LoggerFactory;
...
@@ -10,8 +10,6 @@ import org.slf4j.LoggerFactory;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.string.StringUtil
;
/**
/**
* MD5
* MD5
*/
*/
...
@@ -66,7 +64,20 @@ public class MD5 {
...
@@ -66,7 +64,20 @@ public class MD5 {
else
else
md5StrBuff
.
append
(
Integer
.
toHexString
(
0xFF
&
byteArray
[
i
]));
md5StrBuff
.
append
(
Integer
.
toHexString
(
0xFF
&
byteArray
[
i
]));
}
}
return
md5StrBuff
.
toString
().
toUpperCase
();
return
md5StrBuff
.
toString
();
}
/**
* MD5字符串,全大写
*
* @param str
* @return
*/
public
static
String
getMD5StrUpper
(
String
str
)
{
if
(
StringUtil
.
isEmpty
(
str
))
{
return
str
;
}
return
getMD5Str
(
str
).
toUpperCase
();
}
}
/**
/**
...
@@ -111,7 +122,7 @@ public class MD5 {
...
@@ -111,7 +122,7 @@ public class MD5 {
return
md5StrBuff
.
toString
().
toUpperCase
();
return
md5StrBuff
.
toString
().
toUpperCase
();
}
}
public
static
void
main
(
String
[]
args
){
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
MD5
.
getMD5Str
(
"chenjianhua"
));
System
.
out
.
println
(
MD5
.
getMD5Str
(
"chenjianhua"
));
System
.
out
.
println
(
DigestUtils
.
md5Hex
(
"chenjianhua"
).
toUpperCase
());
System
.
out
.
println
(
DigestUtils
.
md5Hex
(
"chenjianhua"
).
toUpperCase
());
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/string/StringTools.java
View file @
957ac6e5
...
@@ -613,7 +613,26 @@ public class StringTools {
...
@@ -613,7 +613,26 @@ public class StringTools {
* @param array
* @param array
* @return
* @return
*/
*/
public
static
boolean
equalss
(
String
str
,
String
[]
array
)
{
public
static
boolean
equalss
(
String
str
,
String
...
array
)
{
if
(
StringUtil
.
isEmpty
(
str
)
||
array
==
null
)
{
return
false
;
}
for
(
String
s
:
array
)
{
if
(
str
.
equals
(
s
))
{
return
true
;
}
}
return
false
;
}
/**
* 判断字符是否在数组中存在。如果数组为null则返回false
*
* @param str
* @param array
* @return
*/
public
static
boolean
equalss
(
String
str
,
List
<
String
>
array
)
{
if
(
StringUtil
.
isEmpty
(
str
)
||
array
==
null
)
{
if
(
StringUtil
.
isEmpty
(
str
)
||
array
==
null
)
{
return
false
;
return
false
;
}
}
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/zip/CompressUtils.java
View file @
957ac6e5
...
@@ -120,8 +120,8 @@ public class CompressUtils {
...
@@ -120,8 +120,8 @@ public class CompressUtils {
if
(
ListUtils
.
isEmpty
(
fileUrlList
))
{
if
(
ListUtils
.
isEmpty
(
fileUrlList
))
{
return
null
;
return
null
;
}
}
zipName
=
FileUtils
.
formatName
(
zipName
);
String
zipNameFormat
=
FileUtils
.
formatName
(
zipName
);
String
tempZipName
=
zipName
+
"_"
+
LocalDateUtils
.
getYmdhmss
();
String
tempZipName
=
zipName
Format
+
"_"
+
LocalDateUtils
.
getYmdhmss
();
String
zipFilePath
=
ZIP_FILE_PATH
+
tempZipName
+
".zip"
;
String
zipFilePath
=
ZIP_FILE_PATH
+
tempZipName
+
".zip"
;
// 检查临时文件夹是否存在,不存在就创建
// 检查临时文件夹是否存在,不存在就创建
String
fileFolderPath
=
FILE_LOCAL_PATH
+
tempZipName
;
String
fileFolderPath
=
FILE_LOCAL_PATH
+
tempZipName
;
...
@@ -141,7 +141,7 @@ public class CompressUtils {
...
@@ -141,7 +141,7 @@ public class CompressUtils {
FileUtils
.
isDir
(
ZIP_FILE_PATH
);
FileUtils
.
isDir
(
ZIP_FILE_PATH
);
CompressUtils
.
zip
(
fileFolderPath
,
zipFilePath
);
CompressUtils
.
zip
(
fileFolderPath
,
zipFilePath
);
// 上传文件到服务器中
// 上传文件到服务器中
uploadResultInfo
=
OssUtils
.
uploadLocalFile4CustomName
(
zipFilePath
,
zipName
);
uploadResultInfo
=
OssUtils
.
uploadLocalFile4CustomName
(
zipFilePath
,
zipName
Format
);
uploadResultInfo
.
setFileName
(
zipName
);
uploadResultInfo
.
setFileName
(
zipName
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【压缩】压缩失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
LOGGER
.
error
(
"【压缩】压缩失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
...
...
pcloud-common/src/main/java/com/pcloud/common/vo/BaseVO.java
0 → 100644
View file @
957ac6e5
/**
*
*/
package
com
.
pcloud
.
common
.
vo
;
import
java.io.Serializable
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
/**
* VO父类
*
* @author:songx
* @date:2019年1月14日,下午8:53:01
*/
@JsonInclude
(
value
=
Include
.
NON_NULL
)
public
class
BaseVO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
5943734920212204836L
;
}
pcloud-solr/pom.xml
0 → 100644
View file @
957ac6e5
<project
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
com.pcloud.common
</groupId>
<artifactId>
pcloud-common-parent
</artifactId>
<version>
2.1.0-SNAPSHOT
</version>
</parent>
<artifactId>
pcloud-solr
</artifactId>
<packaging>
jar
</packaging>
<version>
${pcloud-solr.version}
</version>
<name>
pcloud-solr
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>
com.pcloud.common
</groupId>
<artifactId>
pcloud-common-config
</artifactId>
<version>
${pcloud-common-config.version}
</version>
</dependency>
<!-- solr add by gaop at 2018-4-23 11:33:47 -->
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-solr
</artifactId>
<version>
${spring.data.solr.version}
</version>
</dependency>
<!-- Spring Cloud Begin -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-config
</artifactId>
</dependency>
<!-- Spring Cloud End -->
<!-- Common Dependency Begin -->
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
1.7.18
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.4
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.38
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-collections4
</artifactId>
<version>
4.1
</version>
</dependency>
<!-- Common Dependency End -->
</dependencies>
</project>
pcloud-
common/src/main/java/com/pcloud/common/utils
/solr/SolrDto.java
→
pcloud-
solr/src/main/java/com/pcloud
/solr/SolrDto.java
View file @
957ac6e5
package
com
.
pcloud
.
common
.
utils
.
solr
;
package
com
.
pcloud
.
solr
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Calendar
;
import
java.util.Calendar
;
...
...
pcloud-
common/src/main/java/com/pcloud/common/utils
/solr/SolrQueryParam.java
→
pcloud-
solr/src/main/java/com/pcloud
/solr/SolrQueryParam.java
View file @
957ac6e5
package
com
.
pcloud
.
common
.
utils
.
solr
;
package
com
.
pcloud
.
solr
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
pcloud-
common/src/main/java/com/pcloud/common/utils
/solr/SolrResult.java
→
pcloud-
solr/src/main/java/com/pcloud
/solr/SolrResult.java
View file @
957ac6e5
package
com
.
pcloud
.
common
.
utils
.
solr
;
package
com
.
pcloud
.
solr
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
...
@@ -8,7 +8,7 @@ import java.util.List;
...
@@ -8,7 +8,7 @@ import java.util.List;
* @author PENG
* @author PENG
* @date 2018/4/24
* @date 2018/4/24
*/
*/
public
class
SolrResult
implements
Serializable
{
public
class
SolrResult
<
T
>
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1195918725820896691L
;
private
static
final
long
serialVersionUID
=
1195918725820896691L
;
...
@@ -25,7 +25,7 @@ public class SolrResult implements Serializable {
...
@@ -25,7 +25,7 @@ public class SolrResult implements Serializable {
/**
/**
* 查询结果列表
* 查询结果列表
*/
*/
private
List
<
SolrDto
>
list
;
private
List
<
T
>
list
;
public
Integer
getTotalCount
()
{
public
Integer
getTotalCount
()
{
return
totalCount
;
return
totalCount
;
...
@@ -43,11 +43,11 @@ public class SolrResult implements Serializable {
...
@@ -43,11 +43,11 @@ public class SolrResult implements Serializable {
this
.
maxScore
=
maxScore
;
this
.
maxScore
=
maxScore
;
}
}
public
List
<
SolrDto
>
getList
()
{
public
List
<
T
>
getList
()
{
return
list
;
return
list
;
}
}
public
void
setList
(
List
<
SolrDto
>
list
)
{
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
this
.
list
=
list
;
}
}
...
...
pcloud-
common/src/main/java/com/pcloud/common/utils
/solr/SolrUtils.java
→
pcloud-
solr/src/main/java/com/pcloud
/solr/SolrUtils.java
View file @
957ac6e5
package
com
.
pcloud
.
common
.
utils
.
solr
;
package
com
.
pcloud
.
solr
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.function.Function
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.collections
4
.MapUtils
;
import
org.apache.solr.client.solrj.SolrClient
;
import
org.apache.solr.client.solrj.SolrClient
;
import
org.apache.solr.client.solrj.SolrQuery
;
import
org.apache.solr.client.solrj.SolrQuery
;
import
org.apache.solr.client.solrj.impl.CloudSolrClient
;
import
org.apache.solr.client.solrj.impl.CloudSolrClient
;
...
@@ -21,8 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -21,8 +23,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.pcloud.common.utils.DateUtils
;
import
com.pcloud.common.utils.ListUtils
;
/**
/**
* Description solr全文检索工具类
* Description solr全文检索工具类
...
@@ -39,7 +39,7 @@ public class SolrUtils {
...
@@ -39,7 +39,7 @@ public class SolrUtils {
private
static
String
defaultCollection
;
private
static
String
defaultCollection
;
pr
ivate
static
CloudSolrClient
solrClient
;
pr
otected
static
CloudSolrClient
solrClient
;
/**
/**
* 新增或修改索引(id主键存在时为更新)
* 新增或修改索引(id主键存在时为更新)
...
@@ -52,6 +52,15 @@ public class SolrUtils {
...
@@ -52,6 +52,15 @@ public class SolrUtils {
/**
/**
* 新增或修改索引(id主键存在时为更新)
* 新增或修改索引(id主键存在时为更新)
* @param object solr索引DTO
* @return 是否成功
*/
public
static
Boolean
addObject
(
Object
object
)
{
return
addObject
(
getDefaultCollection
(),
object
);
}
/**
* 新增或修改索引(id主键存在时为更新)
* @param collection 索引集
* @param collection 索引集
* @param solrDto solr索引DTO
* @param solrDto solr索引DTO
* @return 是否成功
* @return 是否成功
...
@@ -68,6 +77,23 @@ public class SolrUtils {
...
@@ -68,6 +77,23 @@ public class SolrUtils {
}
}
/**
/**
* 新增或修改索引(id主键存在时为更新)
* @param collection 索引集
* @param object solr索引DTO
* @return 是否成功
*/
public
static
Boolean
addObject
(
String
collection
,
Object
object
)
{
try
{
solrClient
.
addBean
(
collection
,
object
);
solrClient
.
commit
(
collection
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"solr新增索引失败:"
+
e
.
getMessage
(),
e
);
return
false
;
}
return
true
;
}
/**
* 批量新增或修改索引(id主键存在时为更新)
* 批量新增或修改索引(id主键存在时为更新)
* @param list solr索引DTO列表
* @param list solr索引DTO列表
* @return 是否成功
* @return 是否成功
...
@@ -78,6 +104,15 @@ public class SolrUtils {
...
@@ -78,6 +104,15 @@ public class SolrUtils {
/**
/**
* 批量新增或修改索引(id主键存在时为更新)
* 批量新增或修改索引(id主键存在时为更新)
* @param list solr索引DTO列表
* @return 是否成功
*/
public
static
Boolean
addObject
(
List
<
Object
>
list
)
{
return
addObject
(
getDefaultCollection
(),
list
);
}
/**
* 批量新增或修改索引(id主键存在时为更新)
* @param collection 索引集
* @param collection 索引集
* @param list solr索引DTO列表
* @param list solr索引DTO列表
* @return 是否成功
* @return 是否成功
...
@@ -94,6 +129,23 @@ public class SolrUtils {
...
@@ -94,6 +129,23 @@ public class SolrUtils {
}
}
/**
/**
* 批量新增或修改索引(id主键存在时为更新)
* @param collection 索引集
* @param list solr索引DTO列表
* @return 是否成功
*/
public
static
Boolean
addObject
(
String
collection
,
List
<
SolrDto
>
list
)
{
try
{
solrClient
.
addBeans
(
collection
,
list
);
solrClient
.
commit
(
collection
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"solr批量新增索引失败:"
+
e
.
getMessage
(),
e
);
return
false
;
}
return
true
;
}
/**
* 根据id主键删除索引
* 根据id主键删除索引
* @param id id主键
* @param id id主键
* @return 是否成功
* @return 是否成功
...
@@ -156,6 +208,15 @@ public class SolrUtils {
...
@@ -156,6 +208,15 @@ public class SolrUtils {
/**
/**
* 根据id主键获取索引
* 根据id主键获取索引
* @param id id主键
* @return SolrDto
*/
public
static
SolrDocument
getObjectById
(
String
id
)
{
return
getObjectById
(
getDefaultCollection
(),
id
);
}
/**
* 根据id主键获取索引
* @param collection 索引集
* @param collection 索引集
* @param id id主键
* @param id id主键
* @return SolrDto
* @return SolrDto
...
@@ -175,6 +236,21 @@ public class SolrUtils {
...
@@ -175,6 +236,21 @@ public class SolrUtils {
}
}
/**
/**
* 根据id主键获取索引
* @param collection 索引集
* @param id id主键
* @return SolrDto
*/
public
static
SolrDocument
getObjectById
(
String
collection
,
String
id
)
{
try
{
return
solrClient
.
getById
(
collection
,
id
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"solr根据id查询索引失败:"
+
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 根据id主键列表批量获取索引
* 根据id主键列表批量获取索引
* @param ids id主键列表
* @param ids id主键列表
* @return SolrDto Map
* @return SolrDto Map
...
@@ -185,13 +261,22 @@ public class SolrUtils {
...
@@ -185,13 +261,22 @@ public class SolrUtils {
/**
/**
* 根据id主键列表批量获取索引
* 根据id主键列表批量获取索引
* @param ids id主键列表
* @return SolrDto Map
*/
public
static
Map
<
String
,
SolrDocument
>
mapObjectByIds
(
List
<
String
>
ids
)
{
return
mapObjectByIds
(
getDefaultCollection
(),
ids
);
}
/**
* 根据id主键列表批量获取索引
* @param collection 索引集
* @param collection 索引集
* @param ids id主键列表
* @param ids id主键列表
* @return SolrDto Map
* @return SolrDto Map
*/
*/
public
static
Map
<
String
,
SolrDto
>
getById
(
String
collection
,
List
<
String
>
ids
)
{
public
static
Map
<
String
,
SolrDto
>
getById
(
String
collection
,
List
<
String
>
ids
)
{
try
{
try
{
if
(
ListUtils
.
isEmpty
(
ids
))
{
if
(
null
==
ids
||
ids
.
isEmpty
(
))
{
return
null
;
return
null
;
}
}
SolrDocumentList
documents
=
solrClient
.
getById
(
collection
,
ids
);
SolrDocumentList
documents
=
solrClient
.
getById
(
collection
,
ids
);
...
@@ -211,6 +296,33 @@ public class SolrUtils {
...
@@ -211,6 +296,33 @@ public class SolrUtils {
}
}
/**
/**
* 根据id主键列表批量获取索引
* @param collection 索引集
* @param ids id主键列表
* @return SolrDto Map
*/
public
static
Map
<
String
,
SolrDocument
>
mapObjectByIds
(
String
collection
,
List
<
String
>
ids
)
{
try
{
if
(
null
==
ids
||
ids
.
isEmpty
())
{
return
null
;
}
SolrDocumentList
documents
=
solrClient
.
getById
(
collection
,
ids
);
if
(
null
!=
documents
)
{
Map
<
String
,
SolrDocument
>
map
=
new
HashMap
<>();
for
(
SolrDocument
document
:
documents
)
{
map
.
put
((
String
)
document
.
get
(
"id"
),
document
);
}
return
map
;
}
else
{
return
null
;
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"solr根据id批量查询索引失败:"
+
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 查询
* 查询
* @param param 查询参数
* @param param 查询参数
* @return SolrResult
* @return SolrResult
...
@@ -221,18 +333,27 @@ public class SolrUtils {
...
@@ -221,18 +333,27 @@ public class SolrUtils {
/**
/**
* 查询
* 查询
* @param param 查询参数
* @return SolrResult
*/
public
static
SolrResult
<
SolrDocument
>
searchObject
(
SolrQueryParam
param
)
{
return
searchObject
(
getDefaultCollection
(),
param
);
}
/**
* 查询
* @param collection 索引集
* @param collection 索引集
* @param param 查询参数
* @param param 查询参数
* @return SolrResult
* @return SolrResult
*/
*/
public
static
SolrResult
search
(
String
collection
,
SolrQueryParam
param
)
{
public
static
SolrResult
<
SolrDto
>
search
(
String
collection
,
SolrQueryParam
param
)
{
try
{
try
{
SolrQuery
solrQuery
=
formatQueryParam
(
param
);
SolrQuery
solrQuery
=
formatQueryParam
(
param
);
solrQuery
.
set
(
"wt"
,
"json"
);
solrQuery
.
set
(
"wt"
,
"json"
);
QueryResponse
response
=
solrClient
.
query
(
collection
,
solrQuery
);
QueryResponse
response
=
solrClient
.
query
(
collection
,
solrQuery
);
SolrDocumentList
documents
=
response
.
getResults
();
SolrDocumentList
documents
=
response
.
getResults
();
LOGGER
.
info
(
"solr查询结果:"
+
documents
.
toString
());
LOGGER
.
info
(
"solr查询结果:"
+
documents
.
toString
());
SolrResult
solrResult
=
new
SolrResult
();
SolrResult
<
SolrDto
>
solrResult
=
new
SolrResult
<
SolrDto
>
();
solrResult
.
setTotalCount
(
Integer
.
parseInt
(
documents
.
getNumFound
()
+
""
));
solrResult
.
setTotalCount
(
Integer
.
parseInt
(
documents
.
getNumFound
()
+
""
));
solrResult
.
setMaxScore
(
documents
.
getMaxScore
());
solrResult
.
setMaxScore
(
documents
.
getMaxScore
());
List
<
SolrDto
>
list
=
new
ArrayList
<>();
List
<
SolrDto
>
list
=
new
ArrayList
<>();
...
@@ -249,6 +370,34 @@ public class SolrUtils {
...
@@ -249,6 +370,34 @@ public class SolrUtils {
}
}
/**
/**
* 查询
* @param collection 索引集
* @param param 查询参数
* @return SolrResult
*/
public
static
SolrResult
<
SolrDocument
>
searchObject
(
String
collection
,
SolrQueryParam
param
)
{
try
{
SolrQuery
solrQuery
=
formatQueryParam
(
param
);
solrQuery
.
set
(
"wt"
,
"json"
);
QueryResponse
response
=
solrClient
.
query
(
collection
,
solrQuery
);
SolrDocumentList
documents
=
response
.
getResults
();
LOGGER
.
info
(
"solr查询结果:"
+
documents
.
toString
());
SolrResult
<
SolrDocument
>
solrResult
=
new
SolrResult
<>();
solrResult
.
setTotalCount
(
Integer
.
parseInt
(
documents
.
getNumFound
()
+
""
));
solrResult
.
setMaxScore
(
documents
.
getMaxScore
());
List
<
SolrDocument
>
list
=
new
ArrayList
<>();
for
(
SolrDocument
document
:
documents
)
{
list
.
add
(
document
);
}
solrResult
.
setList
(
list
);
return
solrResult
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"solr查询索引失败:"
+
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 将solr返回的document转换成solrDto
* 将solr返回的document转换成solrDto
* @param document solr文档
* @param document solr文档
* @return SolrDto
* @return SolrDto
...
@@ -287,7 +436,7 @@ public class SolrUtils {
...
@@ -287,7 +436,7 @@ public class SolrUtils {
* @param param solr查询参数
* @param param solr查询参数
* @return SolrQuery
* @return SolrQuery
*/
*/
pr
ivate
static
SolrQuery
formatQueryParam
(
SolrQueryParam
param
)
{
pr
otected
static
SolrQuery
formatQueryParam
(
SolrQueryParam
param
)
{
SolrQuery
solrQuery
=
new
SolrQuery
();
SolrQuery
solrQuery
=
new
SolrQuery
();
if
(
null
==
param
)
{
if
(
null
==
param
)
{
param
=
new
SolrQueryParam
();
param
=
new
SolrQueryParam
();
...
@@ -297,7 +446,7 @@ public class SolrUtils {
...
@@ -297,7 +446,7 @@ public class SolrUtils {
}
else
{
}
else
{
solrQuery
.
set
(
"q"
,
"*:*"
);
solrQuery
.
set
(
"q"
,
"*:*"
);
}
}
if
(
!
ListUtils
.
isEmpty
(
param
.
getFq
()
))
{
if
(
null
!=
param
.
getFq
()
&&
!
param
.
getFq
().
isEmpty
(
))
{
for
(
String
fq
:
param
.
getFq
())
{
for
(
String
fq
:
param
.
getFq
())
{
solrQuery
.
addFilterQuery
(
fq
);
solrQuery
.
addFilterQuery
(
fq
);
}
}
...
@@ -353,7 +502,7 @@ public class SolrUtils {
...
@@ -353,7 +502,7 @@ public class SolrUtils {
*/
*/
public
static
String
getUTCShortDateStr
()
{
public
static
String
getUTCShortDateStr
()
{
Calendar
calendar
=
Calendar
.
getInstance
();
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
DateUtils
.
dateFormat
(
new
Date
()));
calendar
.
setTime
(
dateFormat
(
new
Date
()));
calendar
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
8
);
calendar
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
8
);
return
UTC_FULL_DATE_FORMAT
.
format
(
calendar
.
getTime
());
return
UTC_FULL_DATE_FORMAT
.
format
(
calendar
.
getTime
());
}
}
...
@@ -365,15 +514,31 @@ public class SolrUtils {
...
@@ -365,15 +514,31 @@ public class SolrUtils {
*/
*/
public
static
String
formatUTCShortDate
(
Date
date
)
{
public
static
String
formatUTCShortDate
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
DateUtils
.
dateFormat
(
date
));
calendar
.
setTime
(
dateFormat
(
date
));
calendar
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
8
);
calendar
.
add
(
Calendar
.
HOUR_OF_DAY
,
-
8
);
return
UTC_FULL_DATE_FORMAT
.
format
(
calendar
.
getTime
());
return
UTC_FULL_DATE_FORMAT
.
format
(
calendar
.
getTime
());
}
}
/**
/**
* 对时间进行格式化
* @param date 时间
* @return 格式化时间
*/
protected
static
Date
dateFormat
(
Date
date
)
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
Date
value
=
new
Date
();
try
{
value
=
format
.
parse
(
format
.
format
(
date
));
}
catch
(
ParseException
e
)
{
LOGGER
.
error
(
"日期转换错误:"
+
e
.
getMessage
(),
e
);
}
return
value
;
}
/**
* 获取默认集合
* 获取默认集合
*/
*/
pr
ivate
static
String
getDefaultCollection
()
{
pr
otected
static
String
getDefaultCollection
()
{
return
null
==
solrClient
.
getDefaultCollection
()
?
defaultCollection
:
solrClient
.
getDefaultCollection
();
return
null
==
solrClient
.
getDefaultCollection
()
?
defaultCollection
:
solrClient
.
getDefaultCollection
();
}
}
...
...
pom.xml
View file @
957ac6e5
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
<module>
pcloud-common-config
</module>
<module>
pcloud-common-config
</module>
<module>
pcloud-common
</module>
<module>
pcloud-common
</module>
<module>
pcloud-common-core
</module>
<module>
pcloud-common-core
</module>
<module>
pcloud-solr
</module>
</modules>
</modules>
<packaging>
pom
</packaging>
<packaging>
pom
</packaging>
...
@@ -47,6 +48,7 @@
...
@@ -47,6 +48,7 @@
<pcloud-common.version>
2.1.0-RELEASE
</pcloud-common.version>
<pcloud-common.version>
2.1.0-RELEASE
</pcloud-common.version>
<pcloud-common-config.version>
2.1.0-RELEASE
</pcloud-common-config.version>
<pcloud-common-config.version>
2.1.0-RELEASE
</pcloud-common-config.version>
<pcloud-common-core.version>
2.1.0-RELEASE
</pcloud-common-core.version>
<pcloud-common-core.version>
2.1.0-RELEASE
</pcloud-common-core.version>
<pcloud-solr.version>
2.1.0-RELEASE
</pcloud-solr.version>
</properties>
</properties>
</profile>
</profile>
<!-- 压测环境 -->
<!-- 压测环境 -->
...
@@ -68,6 +70,7 @@
...
@@ -68,6 +70,7 @@
<pcloud-common.version>
2.1.0-RELEASE
</pcloud-common.version>
<pcloud-common.version>
2.1.0-RELEASE
</pcloud-common.version>
<pcloud-common-config.version>
2.1.0-RELEASE
</pcloud-common-config.version>
<pcloud-common-config.version>
2.1.0-RELEASE
</pcloud-common-config.version>
<pcloud-common-core.version>
2.1.0-RELEASE
</pcloud-common-core.version>
<pcloud-common-core.version>
2.1.0-RELEASE
</pcloud-common-core.version>
<pcloud-solr.version>
2.1.0-RELEASE
</pcloud-solr.version>
</properties>
</properties>
</profile>
</profile>
<!-- 生产环境 RAYS -->
<!-- 生产环境 RAYS -->
...
@@ -89,6 +92,7 @@
...
@@ -89,6 +92,7 @@
<pcloud-common.version>
2.1.1-RELEASE
</pcloud-common.version>
<pcloud-common.version>
2.1.1-RELEASE
</pcloud-common.version>
<pcloud-common-config.version>
2.1.1-RELEASE
</pcloud-common-config.version>
<pcloud-common-config.version>
2.1.1-RELEASE
</pcloud-common-config.version>
<pcloud-common-core.version>
2.1.1-RELEASE
</pcloud-common-core.version>
<pcloud-common-core.version>
2.1.1-RELEASE
</pcloud-common-core.version>
<pcloud-solr.version>
2.1.1-RELEASE
</pcloud-solr.version>
</properties>
</properties>
</profile>
</profile>
</profiles>
</profiles>
...
@@ -227,6 +231,11 @@
...
@@ -227,6 +231,11 @@
<version>
4.4.6
</version>
<version>
4.4.6
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpmime
</artifactId>
<version>
4.5.3
</version>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
<artifactId>
jedis
</artifactId>
<version>
2.9.0
</version>
<version>
2.9.0
</version>
...
@@ -303,13 +312,6 @@
...
@@ -303,13 +312,6 @@
</dependency>
</dependency>
<!-- end -->
<!-- end -->
<!-- solr add by gaop at 2018-4-23 11:33:47 -->
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-solr
</artifactId>
<version>
${spring.data.solr.version}
</version>
</dependency>
<!-- Jackson Begin -->
<!-- Jackson Begin -->
<dependency>
<dependency>
<groupId>
org.codehaus.jackson
</groupId>
<groupId>
org.codehaus.jackson
</groupId>
...
...
temp.jpg
deleted
100644 → 0
View file @
3d06297f
1.82 MB
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