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
59cf09ff
Commit
59cf09ff
authored
Aug 30, 2019
by
郑永强
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://192.168.89.173/rays/pcloud-common-parent
into zyq
parents
90b7924f
bd57671b
Hide whitespace changes
Inline
Side-by-side
Showing
44 changed files
with
3840 additions
and
2332 deletions
+3840
-2332
public_system.properties
...n-config/src/main/resources.prod/public_system.properties
+9
-2
public_system.properties
...on-config/src/main/resources.uat/public_system.properties
+11
-2
KnowledgeUseQueueBiz.java
...java/com/pcloud/common/core/biz/KnowledgeUseQueueBiz.java
+22
-0
TranscodeQueueBiz.java
...in/java/com/pcloud/common/core/biz/TranscodeQueueBiz.java
+1
-1
KnowledgeUseQueueBizImpl.java
...pcloud/common/core/biz/impl/KnowledgeUseQueueBizImpl.java
+38
-0
ConvertEnum.java
...ain/java/com/pcloud/common/core/constant/ConvertEnum.java
+5
-1
MQQueueConstant.java
...java/com/pcloud/common/core/constant/MQQueueConstant.java
+11
-2
MQTopicProducer.java
...java/com/pcloud/common/core/constant/MQTopicProducer.java
+24
-0
ProductTypeConstant.java
.../com/pcloud/common/core/constant/ProductTypeConstant.java
+7
-1
WXKeywordOperationConstant.java
...loud/common/core/constant/WXKeywordOperationConstant.java
+5
-0
ExapiMessageContentDto.java
...va/com/pcloud/common/core/dto/ExapiMessageContentDto.java
+33
-0
KnowledgeUseMQDTO.java
...in/java/com/pcloud/common/core/dto/KnowledgeUseMQDTO.java
+35
-0
SendMessageDto.java
.../main/java/com/pcloud/common/core/dto/SendMessageDto.java
+14
-0
AppProductTypeEnum.java
...java/com/pcloud/common/core/enums/AppProductTypeEnum.java
+18
-13
TempletCodeEnum.java
...in/java/com/pcloud/common/core/enums/TempletCodeEnum.java
+59
-53
Application.java
...n/src/main/java/com/pcloud/common/config/Application.java
+22
-0
AppTypeConstant.java
...main/java/com/pcloud/common/constant/AppTypeConstant.java
+42
-0
CacheConstant.java
...c/main/java/com/pcloud/common/constant/CacheConstant.java
+5
-0
FilePathConstant.java
...ain/java/com/pcloud/common/constant/FilePathConstant.java
+69
-0
ResponseDto.java
...mmon/src/main/java/com/pcloud/common/dto/ResponseDto.java
+158
-105
StoreFlowInfoDto.java
...src/main/java/com/pcloud/common/dto/StoreFlowInfoDto.java
+221
-0
StoreMyPayDto.java
...on/src/main/java/com/pcloud/common/dto/StoreMyPayDto.java
+270
-0
AppRouteEnum.java
...n/src/main/java/com/pcloud/common/enums/AppRouteEnum.java
+186
-0
AppTypeEnum.java
...on/src/main/java/com/pcloud/common/enums/AppTypeEnum.java
+89
-65
ParamCheck.java
...rc/main/java/com/pcloud/common/exceptions/ParamCheck.java
+131
-116
QueueNameConstant.java
...java/com/pcloud/common/mq/constant/QueueNameConstant.java
+14
-0
ServerLinkDTO.java
...src/main/java/com/pcloud/common/mq/dto/ServerLinkDTO.java
+65
-0
ServerLinkQueue.java
...main/java/com/pcloud/common/mq/queue/ServerLinkQueue.java
+54
-0
FileUtils.java
...mmon/src/main/java/com/pcloud/common/utils/FileUtils.java
+6
-6
ImageUtils.java
...mon/src/main/java/com/pcloud/common/utils/ImageUtils.java
+39
-85
LocalDateUtils.java
...src/main/java/com/pcloud/common/utils/LocalDateUtils.java
+569
-433
PictureUtil.java
...on/src/main/java/com/pcloud/common/utils/PictureUtil.java
+354
-358
ResponseHandleUtil.java
...main/java/com/pcloud/common/utils/ResponseHandleUtil.java
+311
-203
SessionUtil.java
...on/src/main/java/com/pcloud/common/utils/SessionUtil.java
+25
-4
ThreadUtil.java
...mon/src/main/java/com/pcloud/common/utils/ThreadUtil.java
+29
-22
UUIDUitl.java
...ommon/src/main/java/com/pcloud/common/utils/UUIDUitl.java
+212
-195
OssUtils.java
...rc/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
+3
-3
UrlUtils.java
...ain/java/com/pcloud/common/utils/httpclient/UrlUtils.java
+2
-18
PdfUtils.java
...n/src/main/java/com/pcloud/common/utils/pdf/PdfUtils.java
+5
-7
StringUtil.java
.../main/java/com/pcloud/common/utils/string/StringUtil.java
+15
-0
WordNewUtils.java
.../main/java/com/pcloud/common/utils/word/WordNewUtils.java
+632
-632
WordUtils.java
...src/main/java/com/pcloud/common/utils/word/WordUtils.java
+4
-4
SolrDto.java
pcloud-solr/src/main/java/com/pcloud/solr/SolrDto.java
+15
-0
SolrQueryParam.java
...ud-solr/src/main/java/com/pcloud/solr/SolrQueryParam.java
+1
-1
No files found.
pcloud-common-config/src/main/resources.prod/public_system.properties
View file @
59cf09ff
...
...
@@ -102,4 +102,12 @@ ownAgentIds = 2,1362
papercut.domain
=
papercut.5rs.me
## \u5C0F\u7A0B\u5E8F\u57DF\u540D
app.domain
=
app.5rs.me
\ No newline at end of file
app.domain
=
app.5rs.me
adviser.product.search.excluding.supermerchants
=
1000022269,1000022270
our_manager_account_id
=
2
group.luck.url
=
https://app.5rs.me/luck/W23/C2/A0/groupluck
manage_official_id
=
22
pcloud-common-config/src/main/resources.uat/public_system.properties
View file @
59cf09ff
...
...
@@ -104,4 +104,14 @@ papercut.domain = papercut.raysyun.com
## \u5C0F\u7A0B\u5E8F\u57DF\u540D
app.domain
=
app.raysyun.com
\ No newline at end of file
app.domain
=
app.raysyun.com
adviser.product.search.excluding.supermerchants
=
7,1000233
our_manager_account_id
=
12829
group.luck.url
=
https://app10035515.raysyun.com/luck/W35515/C35515/A0/groupluck
manage_official_id
=
22
pcloud-common-core/src/main/java/com/pcloud/common/core/biz/KnowledgeUseQueueBiz.java
0 → 100644
View file @
59cf09ff
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
biz
;
import
com.pcloud.common.core.dto.KnowledgeUseMQDTO
;
import
com.pcloud.common.exceptions.BizException
;
/**
* @author:songx
* @date:2019/6/20,11:38
*/
public
interface
KnowledgeUseQueueBiz
{
/**
* 发送消息
*
* @param knowledgeUseMQDTO
*/
void
send
(
KnowledgeUseMQDTO
knowledgeUseMQDTO
)
throws
BizException
;
}
pcloud-common-core/src/main/java/com/pcloud/common/core/biz/TranscodeQueueBiz.java
View file @
59cf09ff
...
...
@@ -17,7 +17,7 @@ public interface TranscodeQueueBiz {
/**
* 发送消息
*
* @param
messageQueueDto
* @param
transcodeMQDTO
*/
void
sendTranscodeQueue
(
TranscodeMQDTO
transcodeMQDTO
)
throws
BizException
;
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/biz/impl/KnowledgeUseQueueBizImpl.java
0 → 100644
View file @
59cf09ff
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
biz
.
impl
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.pcloud.common.core.aspect.ParamLog
;
import
com.pcloud.common.core.biz.KnowledgeUseQueueBiz
;
import
com.pcloud.common.core.constant.MQQueueConstant
;
import
com.pcloud.common.core.dto.KnowledgeUseMQDTO
;
import
com.pcloud.common.exceptions.BizException
;
/**
* @author:songx
* @date:2019/6/20,11:37
*/
@Component
public
class
KnowledgeUseQueueBizImpl
implements
KnowledgeUseQueueBiz
{
@Autowired
private
AmqpTemplate
amqpTemplate
;
/**
* 知识点标签使用QUEUE
*/
@Override
@ParamLog
(
"知识点标签使用QUEUE"
)
public
void
send
(
KnowledgeUseMQDTO
knowledgeUseMQDTO
)
throws
BizException
{
if
(
knowledgeUseMQDTO
==
null
)
{
throw
BizException
.
PARAM_IS_NULL
;
}
amqpTemplate
.
convertAndSend
(
MQQueueConstant
.
KNOWLEDGE_USE
,
knowledgeUseMQDTO
);
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/ConvertEnum.java
View file @
59cf09ff
...
...
@@ -98,7 +98,11 @@ public enum ConvertEnum {
/**
* 场景化应用
*/
SCENARIZED_APP
(
"SCENARIZED_APP"
);
SCENARIZED_APP
(
"SCENARIZED_APP"
),
/**
* BOOK
*/
BOOK
(
"BOOK"
);
/**
* 值
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/MQQueueConstant.java
View file @
59cf09ff
...
...
@@ -9,8 +9,13 @@ package com.pcloud.common.core.constant;
* @date:2018年8月16日,下午9:54:51
*/
public
class
MQQueueConstant
{
/**
/**
* 知识点标签使用
*/
public
static
final
String
KNOWLEDGE_USE
=
"knowledgeUse"
;
/**
* 模板消息
*/
public
static
final
String
TEMPLATE
=
"templateQueue"
;
...
...
@@ -98,6 +103,10 @@ public class MQQueueConstant {
* 文件转码结束(音视频)->场景化应用
*/
public
static
final
String
CONVERT_TO_SCENARIZEDAPP
=
"convert2ScenarizedAppQueue"
;
/**
* 文件转码结束(音视频)->BOOK
*/
public
static
final
String
CONVERT_TO_BOOK
=
"convert2BookQueue"
;
/**
* 数据埋点
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/MQTopicProducer.java
View file @
59cf09ff
...
...
@@ -344,4 +344,28 @@ public class MQTopicProducer {
* 微信群用户绑定TOPIC
*/
public
static
final
String
WXGROUP_USER_BIND
=
"topic.wXGroupUserBind"
;
/**
* 商品创建
*/
public
static
final
String
PRODUCT_CREATE
=
"topic.productCreate"
;
/**
* 代理商删除TOPIC
*/
public
static
final
String
DELETE_PROMOTER
=
"topic.deletePromoter"
;
/**
* 社群书群分类删除
*/
public
static
final
String
GROUP_CLASSIFY_DELETE
=
"topic.groupClassifyDelete"
;
/**
* 微信群学习报告
*/
public
static
final
String
WXGROUP_LEARNING_REPORT
=
"topic.wxGroupLearningReport"
;
/**
* 同意加好友
*/
public
static
final
String
WX_AGREE_ADD_USER
=
"topic.wxAgreeAddUser"
;
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/ProductTypeConstant.java
View file @
59cf09ff
...
...
@@ -347,7 +347,7 @@ public class ProductTypeConstant {
* 资源型作品(免费即可体验)
*/
public
static
final
String
[]
RESOURCE_PRODUCT
=
{
AUDIO
,
VIDEO
,
PDF
,
EBOOK
,
ALBUM
,
PRETEST
,
QANEWS
,
FORMAT
,
WORD
,
ARTICLE
,
LISTEN
,
SCHEDULE
,
PBMUSIC
,
TUTORIAL
,
VIDEO_SCHEDULE
,
AUDIO_SCHEDULE
,
LINK
};
FORMAT
,
WORD
,
ARTICLE
,
LISTEN
,
SCHEDULE
,
PBMUSIC
,
TUTORIAL
,
VIDEO_SCHEDULE
,
AUDIO_SCHEDULE
,
LINK
,
AUDIOAPP
,
SUBJECTNOTE
};
/**
* 参与促销激励作品
...
...
@@ -378,4 +378,10 @@ public class ProductTypeConstant {
* 作品下资源来源于content中心的作品
*/
public
static
final
String
[]
RESOURCE_CONTENT_PRODUCT
=
{
AUDIO
,
VIDEO
,
BOOK
,
LISTEN
,
PDF
,
ALBUM
,
FORMAT
,
EBOOK
};
/**
* 自建码支持的作品类型
*/
public
static
final
String
[]
IS_ALI_TYPE_PRODUCT
=
{
AUDIO
,
VIDEO
,
PDF
,
SCHEDULE
,
VIDEO_SCHEDULE
,
AUDIO_SCHEDULE
,
LINK
,
SUBJECTNOTE
,
ARTICLE
,
EBOOK
,
ALBUM
,
NUMBER
,
PRETEST
,
LISTEN
,
FORMAT
,
WORD
,
ARTICLE
,
PBMUSIC
};
}
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/WXKeywordOperationConstant.java
View file @
59cf09ff
...
...
@@ -18,4 +18,9 @@ public class WXKeywordOperationConstant {
public
static
final
String
SEND_ATTENDANCE_RECORD
=
"SEND_ATTENDANCE_RECORD"
;
/**
* 打卡作品/应用--加入且打卡
*/
public
static
final
String
JOIN_AND_SEND_RECORD
=
"JOIN_AND_SEND_RECORD"
;
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/ExapiMessageContentDto.java
View file @
59cf09ff
...
...
@@ -28,6 +28,12 @@ public class ExapiMessageContentDto implements Serializable{
String
agentName
;
@ApiModelProperty
(
"商品名称"
)
String
productName
;
@ApiModelProperty
(
"扫码名称"
)
String
sceneName
;
@ApiModelProperty
(
"书籍名称"
)
String
bookName
;
@ApiModelProperty
(
"公众号名称名称"
)
String
officialAccountName
;
public
Long
getCustomerId
()
{
return
customerId
;
...
...
@@ -101,6 +107,30 @@ public class ExapiMessageContentDto implements Serializable{
this
.
productName
=
productName
;
}
public
String
getSceneName
()
{
return
sceneName
;
}
public
void
setSceneName
(
String
sceneName
)
{
this
.
sceneName
=
sceneName
;
}
public
String
getBookName
()
{
return
bookName
;
}
public
void
setBookName
(
String
bookName
)
{
this
.
bookName
=
bookName
;
}
public
String
getOfficialAccountName
()
{
return
officialAccountName
;
}
public
void
setOfficialAccountName
(
String
officialAccountName
)
{
this
.
officialAccountName
=
officialAccountName
;
}
@Override
public
String
toString
()
{
return
"ExapiMessageContentDto{"
+
...
...
@@ -113,6 +143,9 @@ public class ExapiMessageContentDto implements Serializable{
", actionTime='"
+
actionTime
+
'\''
+
", agentName='"
+
agentName
+
'\''
+
", productName='"
+
productName
+
'\''
+
", sceneName='"
+
sceneName
+
'\''
+
", bookName='"
+
bookName
+
'\''
+
", officialAccountName='"
+
officialAccountName
+
'\''
+
'}'
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/KnowledgeUseMQDTO.java
0 → 100644
View file @
59cf09ff
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
dto
;
import
java.io.Serializable
;
import
java.util.List
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
/**
* @author:songx
* @date:2018年5月17日,下午4:27:26
*/
@Getter
@Setter
@ToString
(
callSuper
=
true
)
public
class
KnowledgeUseMQDTO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
6111501255761694004L
;
/**
* 知识点标签
*/
private
List
<
Long
>
knowledgeIds
;
public
KnowledgeUseMQDTO
()
{
}
public
KnowledgeUseMQDTO
(
List
<
Long
>
knowledgeIds
)
{
this
.
knowledgeIds
=
knowledgeIds
;
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/dto/SendMessageDto.java
View file @
59cf09ff
...
...
@@ -30,6 +30,11 @@ public class SendMessageDto implements Serializable{
*/
private
Map
<
String
,
String
>
paramKeyMap
;
/**
* 区号
*/
private
String
phoneAreaCode
;
public
String
getSmsTemplateCode
()
{
return
smsTemplateCode
;
}
...
...
@@ -49,12 +54,21 @@ public class SendMessageDto implements Serializable{
this
.
paramKeyMap
=
paramKeyMap
;
}
public
String
getPhoneAreaCode
()
{
return
phoneAreaCode
;
}
public
void
setPhoneAreaCode
(
String
phoneAreaCode
)
{
this
.
phoneAreaCode
=
phoneAreaCode
;
}
@Override
public
String
toString
()
{
return
"SendMessageDto{"
+
"smsTemplateCode='"
+
smsTemplateCode
+
'\''
+
", phoneNumber='"
+
phoneNumber
+
'\''
+
", paramKeyMap="
+
paramKeyMap
+
", phoneAreaCode='"
+
phoneAreaCode
+
'\''
+
'}'
;
}
...
...
pcloud-common-core/src/main/java/com/pcloud/common/core/enums/AppProductTypeEnum.java
View file @
59cf09ff
...
...
@@ -2,13 +2,13 @@ package com.pcloud.common.core.enums;
import
com.pcloud.common.core.constant.ProductTypeConstant
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.enums.AppTypeEnum
;
/**
* Description 应用作品类型关联枚举
* Created by PENG on 2019/3/27.
* Description 应用作品类型关联枚举 Created by PENG on 2019/3/27.
*/
public
enum
AppProductTypeEnum
{
KK
(
AppTypeEnum
.
KK
.
value
,
ProductTypeConstant
.
LOOK
),
TUTOR
(
AppTypeEnum
.
TUTOR
.
value
,
ProductTypeConstant
.
TUTOR
),
GROUP
(
AppTypeEnum
.
GROUP
.
value
,
ProductTypeConstant
.
GROUP
),
...
...
@@ -38,18 +38,19 @@ public enum AppProductTypeEnum {
RECITE_WORD
(
AppTypeEnum
.
RECITE_WORD
.
value
,
ProductTypeConstant
.
WORD_APP
),
SUBJECTNOTE
(
AppTypeEnum
.
SUBJECTNOTE
.
value
,
ProductTypeConstant
.
SUBJECTNOTE_APP
),
BM
(
AppTypeEnum
.
BM
.
value
,
ProductTypeConstant
.
BM
);
public
final
String
appTypeCode
;
public
final
String
productTypeCode
;
AppProductTypeEnum
(
String
appTypeCode
,
String
productTypeCode
)
{
this
.
appTypeCode
=
appTypeCode
;
this
.
productTypeCode
=
productTypeCode
;
}
/**
* 根据应用类型编码获取作品类型编码
*
* @param appTypeCode 应用类型编码
* @return
*/
...
...
@@ -67,9 +68,10 @@ public enum AppProductTypeEnum {
}
return
null
;
}
/**
* 根据作品类型编码获取应用类型编码
*
* @param productTypeCode 作品类型编码
* @return
*/
...
...
@@ -87,16 +89,19 @@ public enum AppProductTypeEnum {
}
return
null
;
}
/**
* 会员应用可设置会员免费的作品类型
*/
public
static
final
String
[]
MEMBER_INCLUDE_PRODUCT_TYPE
=
{
ProductTypeConstant
.
PDF
,
ProductTypeConstant
.
AUDIO
,
ProductTypeConstant
.
VIDEO
,
ProductTypeConstant
.
PRETEST
,
ProductTypeConstant
.
ARTICLE
,
ProductTypeConstant
.
FORMAT
,
ProductTypeConstant
.
ALBUM
,
ProductTypeConstant
.
BOOK
,
ProductTypeConstant
.
EBOOK
,
ProductTypeConstant
.
VIDEO_SCHEDULE
};
public
static
final
String
[]
MEMBER_INCLUDE_PRODUCT_TYPE
=
{
ProductTypeConstant
.
PDF
,
ProductTypeConstant
.
AUDIO
,
ProductTypeConstant
.
VIDEO
,
ProductTypeConstant
.
PRETEST
,
ProductTypeConstant
.
ARTICLE
,
ProductTypeConstant
.
FORMAT
,
ProductTypeConstant
.
ALBUM
,
ProductTypeConstant
.
BOOK
,
ProductTypeConstant
.
EBOOK
,
ProductTypeConstant
.
VIDEO_SCHEDULE
};
/**
* 会员应用可设置会员免费的应用类型
*/
public
static
final
String
[]
MEMBER_INCLUDE_APP_TYPE
=
{
AppTypeEnum
.
ANSWER
.
value
,
AppTypeEnum
.
ITEM_BANK
.
value
,
AppTypeEnum
.
EBOOK
.
value
,
AppTypeEnum
.
TEACH_RESOURCE
.
value
,
AppTypeEnum
.
COURSE_WARE
.
value
,
public
static
final
String
[]
MEMBER_INCLUDE_APP_TYPE
=
{
AppTypeEnum
.
ANSWER
.
value
,
AppTypeEnum
.
ITEM_BANK
.
value
,
AppTypeEnum
.
EBOOK
.
value
,
AppTypeEnum
.
TEACH_RESOURCE
.
value
,
AppTypeEnum
.
COURSE_WARE
.
value
,
AppTypeEnum
.
TEST_PAPER
.
value
};
}
pcloud-common-core/src/main/java/com/pcloud/common/core/enums/TempletCodeEnum.java
View file @
59cf09ff
package
com
.
pcloud
.
common
.
core
.
enums
;
import
com.pcloud.common.enums.AppTypeEnum
;
/**
* @描述:
* @作者:songx
* @创建时间:20"1"7年"1"0月3"1"日,上午"1""1":45:58
* @版本:"1".0
*
* @作者:songx @创建时间:20"1"7年"1"0月3"1"日,上午"1""1":45:58 @版本:"1".0
*/
public
enum
TempletCodeEnum
{
K12
(
"K12教辅(试卷类)"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
ZSCORE
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
QA
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
PUBLIC_PROSE
(
"大众类散文随笔诗歌"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
K12
(
"K12教辅(试卷类)"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
ZSCORE
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
QA
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
PUBLIC_PROSE
(
"大众类散文随笔诗歌"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
PUBLIC_JOURNAL
(
"大众类期刊"
,
new
String
[][]
{
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
FORMAT
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
PUBLIC_NOVEL
(
"大众类小说"
,
new
String
[][]
{
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
}
}),
SINOLOGY
(
"国学类图书(18+)"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
VACATION
(
"假期作业"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
SPECIAL
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PRETEST
.
name
(),
"1"
}
}),
VACATION
(
"假期作业"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
SPECIAL
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PRETEST
.
name
(),
"1"
}
}),
MILITARY
(
"军事历史类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
AUDIO
.
name
(),
"1"
}
}),
IMPORTED_HIGER
(
"教材教辅类(高中)图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"2"
}
}),
IMPORTED_SMALL
(
"教材教辅类(小学初中)图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"2"
}
}),
GERIATRIC
(
"老年大学教材"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
AUDIO
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
VIDEO
.
name
(),
"1"
}
}),
IMPORTED_HIGER
(
"教材教辅类(高中)图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"2"
}
}),
IMPORTED_SMALL
(
"教材教辅类(小学初中)图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"2"
}
}),
GERIATRIC
(
"老年大学教材"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
AUDIO
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
VIDEO
.
name
(),
"1"
}
}),
EXTRACURRICULAR
(
"课外读本类"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
CELEBRITY
(
"名人传记类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
ALBUM
.
name
(),
"1"
}
}),
CHILD_PUFFIN
(
"少儿读物类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
AUDIO
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
ALBUM
.
name
(),
"1"
}
}),
CHILD_PUFFIN
(
"少儿读物类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
AUDIO
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
CHILD_SINOLOGY
(
"少儿国学类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
CHILD_INTEREST
(
"少儿兴趣学习类"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
WORD
.
name
(),
"1"
}
}),
PROFESSIONAL
(
"职教、专业技术类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
SCIENCE
(
"生活科普类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
KK
.
name
(),
"1"
}
}),
PROMOTE
(
"提升类图书"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
}
}),
SPECIAL_SMALL
(
"专题类教材教辅(小学、初中)"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
EF
.
name
(),
"1"
}
}),
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
EF
.
name
(),
"1"
}
}),
SPECIAL_HIGER
(
"专题类教材教辅(高中)"
,
new
String
[][]
{
{
PcloudTypeEnum
.
APP
.
name
(),
AppTypeEnum
.
GROUP
.
name
(),
"1"
},
{
PcloudTypeEnum
.
PRODUCT
.
name
(),
ProductTypeEnum
.
PDF
.
name
(),
"1"
},
...
...
@@ -89,7 +95,7 @@ public enum TempletCodeEnum {
* 服务列表
*/
public
final
String
[][]
serves
;
/**
* 构造
*
...
...
@@ -99,5 +105,5 @@ public enum TempletCodeEnum {
this
.
value
=
value
;
this
.
serves
=
strs
;
}
}
pcloud-common/src/main/java/com/pcloud/common/config/Application.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
config
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* @Author: songx
* @Date: 2019年07月11日, 14:11
*/
@Component
public
class
Application
{
/**
* 应用名称
*/
public
static
String
APP_NAME
;
@Value
(
"${spring.application.name}"
)
public
void
setAppName
(
String
appName
)
{
this
.
APP_NAME
=
appName
;
}
}
pcloud-common/src/main/java/com/pcloud/common/constant/AppTypeConstant.java
0 → 100644
View file @
59cf09ff
/**
*
*/
package
com
.
pcloud
.
common
.
constant
;
import
com.pcloud.common.enums.AppTypeEnum
;
/**
*
*
* @author:songx
* @date:2018年1月10日,下午2:58:42
*/
public
class
AppTypeConstant
{
/**
* 含有销售价的应用(创建修改同步操作资源中心)
*/
public
static
final
String
[]
PRICE_APP
=
{
AppTypeEnum
.
TEACH_RESOURCE
.
value
,
AppTypeEnum
.
COURSE_WARE
.
value
,
AppTypeEnum
.
STROKE_ORDER
.
value
,
AppTypeEnum
.
IMAGE
.
value
,
AppTypeEnum
.
RECITE_WORD
.
value
};
/**
* 其它服务的含有销售价的应用
*/
public
static
final
String
[]
REMOTE_PRICE_APP
=
{
AppTypeEnum
.
MATCH_LISTEN
.
value
,
AppTypeEnum
.
WORD_DICTATION
.
value
,
AppTypeEnum
.
ARTICLE_READING
.
value
,
AppTypeEnum
.
ENGLISH_WALKMAN
.
value
,
AppTypeEnum
.
ORAL_EVALUATION
.
value
,
AppTypeEnum
.
PBSTORY
.
value
};
/**
* 自建码包含的应用类型
*/
public
static
final
String
[]
IS_ALI_TYPE_APP
=
{
AppTypeEnum
.
ANSWER
.
value
,
AppTypeEnum
.
TEACH_RESOURCE
.
value
,
AppTypeEnum
.
COURSE_WARE
.
value
,
AppTypeEnum
.
PDF
.
value
,
AppTypeEnum
.
TEST_PAPER
.
value
,
AppTypeEnum
.
SUBJECTNOTE
.
value
,
AppTypeEnum
.
STROKE_ORDER
.
value
,
AppTypeEnum
.
EBOOK
.
value
,
AppTypeEnum
.
IMAGE
.
value
,
AppTypeEnum
.
ARTICLE
.
value
,
AppTypeEnum
.
BOOK
.
value
,
AppTypeEnum
.
LIVE_TIMETABLE
.
value
,
AppTypeEnum
.
AUDIO
.
value
,
AppTypeEnum
.
VIDEO
.
value
,
AppTypeEnum
.
MATCH_LISTEN
.
value
,
AppTypeEnum
.
WORD_DICTATION
.
value
,
AppTypeEnum
.
GROUP
.
value
,
AppTypeEnum
.
ITEM_BANK
.
value
,
AppTypeEnum
.
DRAW
.
value
};
}
pcloud-common/src/main/java/com/pcloud/common/constant/CacheConstant.java
View file @
59cf09ff
...
...
@@ -152,4 +152,9 @@ public class CacheConstant {
*/
public
static
final
String
EDUCATIONFORM
=
"EDUCATIONFORM:"
;
/**
* 微信群
*/
public
static
final
String
WECHAT_GROUP
=
"WECHATGROUP:"
;
}
pcloud-common/src/main/java/com/pcloud/common/constant/FilePathConstant.java
0 → 100644
View file @
59cf09ff
/*
* 武汉理工数字传播工程有限公司源代码,版权归武汉理工数字传播工程有限公司所有.
* 项目名称 : pcloud-common
* 创建日期 : 2017年3月3日
* 修改历史 :
* 1. [2017年3月3日]创建文件 by xnxqs
*/
package
com
.
pcloud
.
common
.
constant
;
/**
*
*
* @Author: songx
* @Date: 2019/7/29,14:11
*/
public
class
FilePathConstant
{
/**
* 视频剪切文件夹
*/
public
final
static
String
CUT
=
getFolder
(
"cut"
);
/**
* 下载文件夹
*/
public
final
static
String
DOWNLOAD
=
getFolder
(
"download"
);
/**
* 生成图片地址
*/
public
final
static
String
IMAGE
=
getFolder
(
"image"
);
/**
* 生成带水印文件夹
*/
public
final
static
String
IMAGE_WATERMARK
=
getFolder
(
"image/watermark"
);
/**
* 生成音频文件夹
*/
public
final
static
String
AUDIO
=
getFolder
(
"audio"
);
/**
* 生成PDF文件夹
*/
public
final
static
String
PDF
=
getFolder
(
"pdf"
);
/**
* 生成WORD文件夹
*/
public
final
static
String
WORD
=
getFolder
(
"word"
);
/**
* 生成TEXT文件夹
*/
public
final
static
String
TEXT
=
getFolder
(
"text"
);
/**
* 组装文件夹路径
*
* @param folderName
* @return
*/
private
static
String
getFolder
(
String
folderName
)
{
return
OSConstant
.
USERDIR
+
OSConstant
.
SEPARATOR
+
"files"
+
folderName
+
OSConstant
.
SEPARATOR
;
}
}
pcloud-common/src/main/java/com/pcloud/common/dto/ResponseDto.java
View file @
59cf09ff
package
com
.
pcloud
.
common
.
dto
;
import
java.io.Serializable
;
import
com.alibaba.fastjson.JSON
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
java.io.Serializable
;
/**
* @描述:服务响应实体类
* @作者:shichunshan
...
...
@@ -12,107 +13,159 @@ import java.io.Serializable;
*/
@JsonInclude
(
value
=
Include
.
NON_NULL
)
public
class
ResponseDto
<
T
>
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
9004186626234235043L
;
/**
* 默认操作成功,成功代码
*/
private
static
final
int
SUCCESS
=
0
;
/**
* 默认成功消息
*/
private
static
final
String
SUCCESS_MSG
=
"操作成功!"
;
/**
* 错误码
*/
private
int
errCode
;
/**
* 消息
*/
private
String
message
;
/**
* 数据
*/
private
T
data
;
/**
* 默认成功
*/
public
ResponseDto
()
{
super
();
this
.
errCode
=
SUCCESS
;
this
.
message
=
SUCCESS_MSG
;
}
/**
* @param errCode
* @param message
*/
public
ResponseDto
(
int
errCode
,
String
message
)
{
super
();
this
.
errCode
=
errCode
;
this
.
message
=
message
;
}
/**
* @param errCode
* @param message
* @param data
*/
public
ResponseDto
(
int
errCode
,
String
message
,
T
data
)
{
super
();
this
.
errCode
=
errCode
;
this
.
message
=
message
;
this
.
data
=
data
;
}
/**
* 默认成功
*
* @param data
*/
public
ResponseDto
(
T
data
)
{
super
();
this
.
errCode
=
SUCCESS
;
this
.
message
=
SUCCESS_MSG
;
this
.
data
=
data
;
}
public
int
getErrCode
()
{
return
errCode
;
}
public
void
setErrCode
(
int
errCode
)
{
this
.
errCode
=
errCode
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
@Override
public
String
toString
()
{
return
"ResponseDto [errCode="
+
errCode
+
", message="
+
message
+
", data="
+
data
+
"]"
;
}
/**
*
*/
private
static
final
long
serialVersionUID
=
-
9004186626234235043L
;
/**
* 默认操作成功,成功代码
*/
private
static
final
int
SUCCESS
=
0
;
/**
* 默认成功消息
*/
private
static
final
String
SUCCESS_MSG
=
"操作成功!"
;
/**
* 错误码
*/
private
int
errCode
;
/**
* 消息
*/
private
String
message
;
/**
* 数据
*/
private
T
data
;
/**
* 生产者名称
*/
private
String
produceAppName
;
/**
* 生产者IP
*/
private
String
produceIp
;
/**
* 生产者类名
*/
private
String
produceClassName
;
/**
* 生产者方法名
*/
private
String
produceMethodName
;
/**
* 默认成功
*/
public
ResponseDto
()
{
super
();
this
.
errCode
=
SUCCESS
;
this
.
message
=
SUCCESS_MSG
;
}
/**
* @param errCode
* @param message
*/
public
ResponseDto
(
int
errCode
,
String
message
)
{
super
();
this
.
errCode
=
errCode
;
this
.
message
=
message
;
}
/**
* @param errCode
* @param message
* @param data
*/
public
ResponseDto
(
int
errCode
,
String
message
,
T
data
)
{
super
();
this
.
errCode
=
errCode
;
this
.
message
=
message
;
this
.
data
=
data
;
}
/**
* 默认成功
*
* @param data
*/
public
ResponseDto
(
T
data
)
{
super
();
this
.
errCode
=
SUCCESS
;
this
.
message
=
SUCCESS_MSG
;
this
.
data
=
data
;
}
public
int
getErrCode
()
{
return
errCode
;
}
public
void
setErrCode
(
int
errCode
)
{
this
.
errCode
=
errCode
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
public
String
getProduceAppName
()
{
return
produceAppName
;
}
public
void
setProduceAppName
(
String
produceAppName
)
{
this
.
produceAppName
=
produceAppName
;
}
public
String
getProduceClassName
()
{
return
produceClassName
;
}
public
void
setProduceClassName
(
String
produceClassName
)
{
this
.
produceClassName
=
produceClassName
;
}
public
String
getProduceMethodName
()
{
return
produceMethodName
;
}
public
void
setProduceMethodName
(
String
produceMethodName
)
{
this
.
produceMethodName
=
produceMethodName
;
}
public
String
getProduceIp
()
{
return
produceIp
;
}
public
void
setProduceIp
(
String
produceIp
)
{
this
.
produceIp
=
produceIp
;
}
@Override
public
String
toString
()
{
return
"ResponseDto -> "
+
JSON
.
toJSONString
(
this
);
}
}
pcloud-common/src/main/java/com/pcloud/common/dto/StoreFlowInfoDto.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
dto
;
import
java.math.BigDecimal
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* @Describe: TODO
* @Author: zhangdongwei
* @Date: Create on 11:35 2019/7/24 0024
*/
@ApiModel
(
"商城信息流信息dto"
)
public
class
StoreFlowInfoDto
extends
BaseDto
{
/**
* 标识(appId/productId/bookGroupId)
*/
@ApiModelProperty
(
"标识(appId/productId/bookGroupId)"
)
private
Long
originId
;
/**
* 类型(APP/PRODUCT/BOOK_GROUP)
*/
@ApiModelProperty
(
"类型(APP/PRODUCT/BOOK_GROUP)"
)
private
String
originType
;
/**
* 具体类型编码
*/
@ApiModelProperty
(
"具体类型"
)
private
String
typeCode
;
/**
* 具体类型名称
*/
private
String
typeName
;
/**
* 标题
*/
@ApiModelProperty
(
"标题"
)
private
String
title
;
/**
* 封面图片
*/
@ApiModelProperty
(
"封面图片"
)
private
String
coverImg
;
/**
* 大图
*/
@ApiModelProperty
(
"大图"
)
private
String
bigImg
;
/**
* 价格
*/
@ApiModelProperty
(
"价格"
)
private
BigDecimal
price
;
/**
* 最早开始时间(MM-dd)
*/
@ApiModelProperty
(
"开始时间(MM-dd)"
)
private
String
startDateBegin
;
/**
* 最晚开始时间(MM-dd)
*/
@ApiModelProperty
(
"最晚开始时间(MM-dd)"
)
private
String
startDateEnd
;
/**
* 数量(应用、作品下的资源数量, 社群书的群数量,等)
*/
@ApiModelProperty
(
"数量(应用、作品下的资源数量, 社群书的群数量,等)"
)
private
Integer
resourceNum
;
/**
* 数量(资源的item数量,群的成员数量,等)
*/
@ApiModelProperty
(
"数量(资源的item数量,群的成员数量,等)"
)
private
Integer
resourceItemNum
;
/**
* 讲师
*/
@ApiModelProperty
(
"讲师"
)
private
String
lecturer
;
/**
* 讲师头像
*/
@ApiModelProperty
(
"讲师头像"
)
private
String
lecturerImg
;
public
Long
getOriginId
()
{
return
originId
;
}
public
void
setOriginId
(
Long
originId
)
{
this
.
originId
=
originId
;
}
public
String
getOriginType
()
{
return
originType
;
}
public
void
setOriginType
(
String
originType
)
{
this
.
originType
=
originType
;
}
public
String
getTypeCode
()
{
return
typeCode
;
}
public
void
setTypeCode
(
String
typeCode
)
{
this
.
typeCode
=
typeCode
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getCoverImg
()
{
return
coverImg
;
}
public
void
setCoverImg
(
String
coverImg
)
{
this
.
coverImg
=
coverImg
;
}
public
String
getBigImg
()
{
return
bigImg
;
}
public
void
setBigImg
(
String
bigImg
)
{
this
.
bigImg
=
bigImg
;
}
public
BigDecimal
getPrice
()
{
return
price
;
}
public
void
setPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
}
public
Integer
getResourceNum
()
{
return
resourceNum
;
}
public
void
setResourceNum
(
Integer
resourceNum
)
{
this
.
resourceNum
=
resourceNum
;
}
public
Integer
getResourceItemNum
()
{
return
resourceItemNum
;
}
public
void
setResourceItemNum
(
Integer
resourceItemNum
)
{
this
.
resourceItemNum
=
resourceItemNum
;
}
public
String
getLecturer
()
{
return
lecturer
;
}
public
void
setLecturer
(
String
lecturer
)
{
this
.
lecturer
=
lecturer
;
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
String
getLecturerImg
()
{
return
lecturerImg
;
}
public
void
setLecturerImg
(
String
lecturerImg
)
{
this
.
lecturerImg
=
lecturerImg
;
}
public
String
getStartDateBegin
()
{
return
startDateBegin
;
}
public
void
setStartDateBegin
(
String
startDateBegin
)
{
this
.
startDateBegin
=
startDateBegin
;
}
public
String
getStartDateEnd
()
{
return
startDateEnd
;
}
public
void
setStartDateEnd
(
String
startDateEnd
)
{
this
.
startDateEnd
=
startDateEnd
;
}
@Override
public
String
toString
()
{
return
"StoreFlowInfoDto{"
+
"originId="
+
originId
+
", originType='"
+
originType
+
'\''
+
", typeCode='"
+
typeCode
+
'\''
+
", typeName='"
+
typeName
+
'\''
+
", title='"
+
title
+
'\''
+
", coverImg='"
+
coverImg
+
'\''
+
", bigImg='"
+
bigImg
+
'\''
+
", price="
+
price
+
", startDateBegin='"
+
startDateBegin
+
'\''
+
", startDateEnd='"
+
startDateEnd
+
'\''
+
", resourceNum="
+
resourceNum
+
", resourceItemNum="
+
resourceItemNum
+
", lecturer='"
+
lecturer
+
'\''
+
", lecturerImg='"
+
lecturerImg
+
'\''
+
'}'
;
}
}
pcloud-common/src/main/java/com/pcloud/common/dto/StoreMyPayDto.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
dto
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* @Describe: 商城用户已购买的应用或作品dto
* @Author: zhangdongwei
* @Date: Create on 18:16 2019/8/7 0007
*/
@ApiModel
(
"商城用户已购买的应用或作品dto"
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_NULL
)
public
class
StoreMyPayDto
{
/**
* 标识(appId/productId/bookGroupId)
*/
@ApiModelProperty
(
"标识(appId/productId/bookGroupId)"
)
private
Long
originId
;
/**
* 类型(APP/PRODUCT/BOOK_GROUP)
*/
@ApiModelProperty
(
"类型(APP/PRODUCT/BOOK_GROUP)"
)
private
String
originType
;
/**
* 具体类型编码
*/
@ApiModelProperty
(
"具体类型"
)
private
String
typeCode
;
/**
* 具体类型名称
*/
private
String
typeName
;
/**
* 标题
*/
@ApiModelProperty
(
"标题"
)
private
String
originName
;
/**
* 封面图片
*/
@ApiModelProperty
(
"封面图片"
)
private
String
coverImg
;
/**
* 简介
*/
@ApiModelProperty
(
"简介"
)
private
String
description
;
/**
* 价格
*/
@ApiModelProperty
(
"价格"
)
private
BigDecimal
price
;
/**
* 是否支持单节购买
*/
@ApiModelProperty
(
"是否支持单节购买"
)
private
Integer
isSaleOne
;
/**
* 已经购买的资源数量
*/
@ApiModelProperty
(
"已经购买的资源数量"
)
private
Integer
resourceNum
;
/**
* 购买时间
*/
@ApiModelProperty
(
"购买时间"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
Date
payTime
;
/**
*总课时数
*/
@ApiModelProperty
(
"总课时数"
)
private
Integer
totalCourseNum
;
/**
* 已开课节数
*/
@ApiModelProperty
(
"已开课节数"
)
private
Integer
openCourseNum
;
/**
* 用户已打卡天数
*/
@ApiModelProperty
(
"用户已打卡天数"
)
private
Integer
clockDayNum
;
@ApiModelProperty
(
"会员有效期天数"
)
private
Long
overDay
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@ApiModelProperty
(
"开始时间"
)
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
@ApiModelProperty
(
"结束时间"
)
private
Date
endTime
;
public
Long
getOriginId
()
{
return
originId
;
}
public
void
setOriginId
(
Long
originId
)
{
this
.
originId
=
originId
;
}
public
String
getOriginType
()
{
return
originType
;
}
public
void
setOriginType
(
String
originType
)
{
this
.
originType
=
originType
;
}
public
String
getTypeCode
()
{
return
typeCode
;
}
public
void
setTypeCode
(
String
typeCode
)
{
this
.
typeCode
=
typeCode
;
}
public
String
getTypeName
()
{
return
typeName
;
}
public
void
setTypeName
(
String
typeName
)
{
this
.
typeName
=
typeName
;
}
public
String
getOriginName
()
{
return
originName
;
}
public
void
setOriginName
(
String
originName
)
{
this
.
originName
=
originName
;
}
public
String
getCoverImg
()
{
return
coverImg
;
}
public
void
setCoverImg
(
String
coverImg
)
{
this
.
coverImg
=
coverImg
;
}
public
BigDecimal
getPrice
()
{
return
price
;
}
public
void
setPrice
(
BigDecimal
price
)
{
this
.
price
=
price
;
}
public
Integer
getIsSaleOne
()
{
return
isSaleOne
;
}
public
void
setIsSaleOne
(
Integer
isSaleOne
)
{
this
.
isSaleOne
=
isSaleOne
;
}
public
Integer
getResourceNum
()
{
return
resourceNum
;
}
public
void
setResourceNum
(
Integer
resourceNum
)
{
this
.
resourceNum
=
resourceNum
;
}
public
Date
getPayTime
()
{
return
payTime
;
}
public
void
setPayTime
(
Date
payTime
)
{
this
.
payTime
=
payTime
;
}
public
Integer
getTotalCourseNum
()
{
return
totalCourseNum
;
}
public
void
setTotalCourseNum
(
Integer
totalCourseNum
)
{
this
.
totalCourseNum
=
totalCourseNum
;
}
public
Integer
getOpenCourseNum
()
{
return
openCourseNum
;
}
public
void
setOpenCourseNum
(
Integer
openCourseNum
)
{
this
.
openCourseNum
=
openCourseNum
;
}
public
Integer
getClockDayNum
()
{
return
clockDayNum
;
}
public
void
setClockDayNum
(
Integer
clockDayNum
)
{
this
.
clockDayNum
=
clockDayNum
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
Long
getOverDay
()
{
return
overDay
;
}
public
void
setOverDay
(
Long
overDay
)
{
this
.
overDay
=
overDay
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getEndTime
()
{
return
endTime
;
}
public
void
setEndTime
(
Date
endTime
)
{
this
.
endTime
=
endTime
;
}
@Override
public
String
toString
()
{
return
"StoreMyPayDto{"
+
"originId="
+
originId
+
", originType='"
+
originType
+
'\''
+
", typeCode='"
+
typeCode
+
'\''
+
", typeName='"
+
typeName
+
'\''
+
", originName='"
+
originName
+
'\''
+
", coverImg='"
+
coverImg
+
'\''
+
", description='"
+
description
+
'\''
+
", price="
+
price
+
", isSaleOne="
+
isSaleOne
+
", resourceNum="
+
resourceNum
+
", payTime="
+
payTime
+
", totalCourseNum="
+
totalCourseNum
+
", openCourseNum="
+
openCourseNum
+
", clockDayNum="
+
clockDayNum
+
", overDay="
+
overDay
+
", createTime="
+
createTime
+
", endTime="
+
endTime
+
'}'
;
}
}
pcloud-common/src/main/java/com/pcloud/common/enums/AppRouteEnum.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
enums
;
/**
* 应用类型路由
*
* @Author: songx
* @Date: 2019/7/2,10:15
*/
public
enum
AppRouteEnum
{
/**
* 一对一辅导
*/
CC
(
"cc"
,
AppTypeEnum
.
TUTOR
.
value
),
/**
* 圈子
*/
GROUP
(
"group"
,
AppTypeEnum
.
GROUP
.
value
),
/**
* 扫扫看
*/
KK
(
"kk"
,
AppTypeEnum
.
KK
.
value
),
/**
* 专题
*/
ST
(
"st"
,
AppTypeEnum
.
SPECIAL
.
value
),
/**
* 背单词
*/
WD
(
"wd"
,
AppTypeEnum
.
RECITE_WORD
.
value
),
/**
* 数据采集/问卷调查
*/
QN
(
"qn"
,
AppTypeEnum
.
DA
.
value
),
/**
* 报名
*/
REPLY_SCENE
(
"mt"
,
AppTypeEnum
.
BM
.
value
),
/**
* 投票
*/
VT
(
"vt"
,
AppTypeEnum
.
VOTE
.
value
),
/**
* 题库
*/
PRETEST
(
"pretest"
,
AppTypeEnum
.
ITEM_BANK
.
value
),
/**
* 标准分
*/
ZSCORE
(
"zscore"
,
AppTypeEnum
.
ZSCORE
.
value
),
/**
* 读书卡片
*/
BOOKCARD
(
"card"
,
AppTypeEnum
.
BOOKCARD
.
value
),
/**
* 教育表格
*/
TB
(
"tb"
,
AppTypeEnum
.
EF
.
value
),
/**
* 直播
*/
LIVE
(
"live"
,
AppTypeEnum
.
LIVE_TIMETABLE
.
value
),
/**
* 打卡
*/
CLOCK
(
"clock"
,
AppTypeEnum
.
CLOCK
.
value
),
/**
* 伴读魔法箱
*/
AUDIO_MAGIC
(
"magic"
,
AppTypeEnum
.
AUDIO_MAGIC
.
value
),
/**
* 课件
*/
COURSE_WARE
(
"cw"
,
AppTypeEnum
.
COURSE_WARE
.
value
),
/**
* 读者反馈
*/
NAIRE
(
"qn"
,
AppTypeEnum
.
NAIRE
.
value
),
/**
* 互动墙
*/
INTERACT
(
"interact"
,
AppTypeEnum
.
INTERACT
.
value
),
/**
* 抽奖
*/
DRAW
(
"luck"
,
AppTypeEnum
.
DRAW
.
value
),
/**
* 教辅资料包
*/
TEACH_RESOURCE
(
"tr"
,
AppTypeEnum
.
TEACH_RESOURCE
.
value
),
/**
* 测试工具
*/
TEST
(
"tt"
,
AppTypeEnum
.
TEST
.
value
),
/**
* 愿望单
*/
WISH
(
"wish"
,
AppTypeEnum
.
WISH
.
value
),
/**
* 笔顺动图
*/
STROKE_ORDER
(
"pen"
,
AppTypeEnum
.
STROKE_ORDER
.
value
),
/**
* 生词听写
*/
WORD_DICTATION
(
"dictation"
,
AppTypeEnum
.
WORD_DICTATION
.
value
),
/**
* 配套听力
*/
MATCH_LISTEN
(
"mv"
,
AppTypeEnum
.
MATCH_LISTEN
.
value
),
/**
* 开通会员
*/
MEMBER
(
"member"
,
AppTypeEnum
.
MEMBER
.
value
),
/**
* 课文诵读
*/
ARTICLE_READING
(
"ar"
,
AppTypeEnum
.
ARTICLE_READING
.
value
),
/**
* 英语随身听
*/
ENGLISH_WALKMAN
(
"wm"
,
AppTypeEnum
.
ENGLISH_WALKMAN
.
value
),
/**
* 口语评测
*/
ORAL_EVALUATION
(
"speak"
,
AppTypeEnum
.
ORAL_EVALUATION
.
value
),
/**
* 绘本故事
*/
PBSTORY
(
"pbstory"
,
AppTypeEnum
.
PBSTORY
.
value
),
/**
* 错题本
*/
SUBJECTNOTE
(
"subject"
,
AppTypeEnum
.
SUBJECTNOTE
.
value
);
/**
* 值
*/
public
final
String
value
;
/**
* 对应的类型编码
*/
public
String
typeCode
;
/**
* 构造
*
* @param value
*/
private
AppRouteEnum
(
String
value
,
String
typeCode
)
{
this
.
value
=
value
;
this
.
typeCode
=
typeCode
;
}
}
pcloud-common/src/main/java/com/pcloud/common/enums/AppTypeEnum.java
View file @
59cf09ff
...
...
@@ -14,89 +14,113 @@ import com.google.common.collect.Maps;
* @创建时间:2016年12月1日,上午11:07:21 @版本:1.0
*/
public
enum
AppTypeEnum
{
MASTER
(
"MASTER"
),
// 主应用
RECOMMEND
(
"RECOMMEND"
),
// 推荐应用
CHARGE
(
"CHARGE"
),
// 付费应用
ARTICLE
(
"ARTICLE"
),
// 文章
KK
(
"KK"
),
// 看一看
LIVE
(
"LIVE"
),
// 直播
VOTE
(
"VOTE"
),
// 投票
ENROLL
(
"ENROLL"
),
// 编创赛报名
BM
(
"BM"
),
// 报名
NAIRE
(
"NAIRE"
),
// 问卷调查
DA
(
"DA"
),
// 数据采集
BOOKCARD
(
"BOOKCARD"
),
// 读书卡片
TUTOR
(
"TUTOR"
),
// 一对一辅导
GROUP
(
"GROUP"
),
// 与你同行(圈子)(add by gaop at 2017-6-13 16:52:07)
ITEM_BANK
(
"ITEM_BANK"
),
// 题库
VOICE_MSG
(
"VOICE_MSG"
),
// 语音留言
AUDIO
(
"AUDIO"
),
// 音频
VIDEO
(
"VIDEO"
),
// 视频
IMAGE
(
"IMAGE"
),
// 图片
PDF
(
"PDF"
),
// PDF
BOOK
(
"BOOK"
),
// 图书
EF
(
"EF"
),
// 教育表格
QA
(
"QA"
),
// 问答
LISTEN
(
"LISTEN"
),
// 听力
ANSWER
(
"ANSWER"
),
// 答案
ACTIVITY
(
"ACTIVITY"
),
// 分享互动
ZSCORE
(
"ZSCORE"
),
// 标准分
RECITE_WORD
(
"RECITE_WORD"
),
// 背单词
INTERACT
(
"INTERACT"
),
// 互动墙
SPECIAL
(
"SPECIAL"
),
// 专题
CLOCK
(
"CLOCK"
),
// 打卡
TEST
(
"TEST"
),
// 趣味测试(测试工具)
EBOOK
(
"EBOOK"
),
// 电子书
LIVE_TIMETABLE
(
"LIVE_TIMETABLE"
),
// 直播课表
DRAW
(
"DRAW"
),
// 抽奖
WISH
(
"WISH"
),
// 愿望单
LIVEAPP
(
"LIVEAPP"
),
//直播3.0
TASTETEST
(
"TASTETEST"
),
//趣味测试
VIDEO_CLASSIC
(
"VIDEO_CLASSIC"
),
//经典版视频
AUDIO_MAGIC
(
"AUDIO_MAGIC"
),
//音频伴读魔法箱
TEACH_RESOURCE
(
"TEACH_RESOURCE"
),
//教辅资料包
COURSE_WARE
(
"COURSE_WARE"
),
//课件
TEST_PAPER
(
"TEST_PAPER"
),
//试卷
MATCH_LISTEN
(
"MATCH_LISTEN"
),
//配套听力
WORD_DICTATION
(
"WORD_DICTATION"
),
//生词听写
STROKE_ORDER
(
"STROKE_ORDER"
),
//笔顺动图
ARTICLE_READING
(
"ARTICLE_READING"
),
//课文诵读
ENGLISH_WALKMAN
(
"ENGLISH_WALKMAN"
),
//英语随身听
WECHAT_STUDY_GROUP
(
"WECHAT_STUDY_GROUP"
),
// 微信学习交流圈
TASK_CLOCK
(
"TASK_CLOCK"
),
//任务打卡
REWARD_CLOCK
(
"REWARD_CLOCK"
),
//奖励打卡
CUSTOM_CLOCK
(
"CUSTOM_CLOCK"
),
//自定义打卡
MEMBER
(
"MEMBER"
),
//开通会员
ORAL_EVALUATION
(
"ORAL_EVALUATION"
),
//口语评测
PBSTORY
(
"PBSTORY"
),
//绘本故事
SUBJECTNOTE
(
"SUBJECTNOTE"
);
// 错题本
/**
* 应用分类
*/
MASTER
(
"MASTER"
,
"主应用"
),
RECOMMEND
(
"RECOMMEND"
,
"推荐应用"
),
CHARGE
(
"CHARGE"
,
"付费应用"
),
ARTICLE
(
"ARTICLE"
,
"文章"
),
KK
(
"KK"
,
" 看一看"
),
LIVE
(
"LIVE"
,
"直播"
),
VOTE
(
"VOTE"
,
"投票"
),
ENROLL
(
"ENROLL"
,
"编创赛报名"
),
BM
(
"BM"
,
"报名"
),
NAIRE
(
"NAIRE"
,
"问卷调查"
),
BOOKCARD
(
"BOOKCARD"
,
"读书卡片"
),
TUTOR
(
"TUTOR"
,
"一对一辅导"
),
/**
* 该类型应用已删除
*/
DA
(
"DA"
,
"数据采集"
),
/**
* add by gaop at 2017-6-13 16:52:07
*/
GROUP
(
"GROUP"
,
"与你同行(圈子)"
),
ITEM_BANK
(
"ITEM_BANK"
,
"题库"
),
VOICE_MSG
(
"VOICE_MSG"
,
"语音留言"
),
AUDIO
(
"AUDIO"
,
"音频"
),
VIDEO
(
"VIDEO"
,
"视频"
),
IMAGE
(
"IMAGE"
,
"图片"
),
PDF
(
"PDF"
,
"PDF"
),
BOOK
(
"BOOK"
,
"图书"
),
EF
(
"EF"
,
"教育表格"
),
QA
(
"QA"
,
"问答"
),
LISTEN
(
"LISTEN"
,
"听力"
),
ANSWER
(
"ANSWER"
,
"答案"
),
ACTIVITY
(
"ACTIVITY"
,
"分享互动"
),
ZSCORE
(
"ZSCORE"
,
"标准分"
),
RECITE_WORD
(
"RECITE_WORD"
,
"背单词"
),
INTERACT
(
"INTERACT"
,
"互动墙"
),
SPECIAL
(
"SPECIAL"
,
"专题"
),
CLOCK
(
"CLOCK"
,
"打卡"
),
TEST
(
"TEST"
,
"趣味测试(测试工具)"
),
EBOOK
(
"EBOOK"
,
"电子书"
),
LIVE_TIMETABLE
(
"LIVE_TIMETABLE"
,
"直播课表"
),
DRAW
(
"DRAW"
,
"抽奖"
),
WISH
(
"WISH"
,
"愿望单"
),
LIVEAPP
(
"LIVEAPP"
,
"直播3.0"
),
TASTETEST
(
"TASTETEST"
,
"趣味测试"
),
VIDEO_CLASSIC
(
"VIDEO_CLASSIC"
,
"经典版视频"
),
AUDIO_MAGIC
(
"AUDIO_MAGIC"
,
"音频伴读魔法箱"
),
TEACH_RESOURCE
(
"TEACH_RESOURCE"
,
"教辅资料包"
),
COURSE_WARE
(
"COURSE_WARE"
,
"课件"
),
TEST_PAPER
(
"TEST_PAPER"
,
"试卷"
),
MATCH_LISTEN
(
"MATCH_LISTEN"
,
"配套听力"
),
WORD_DICTATION
(
"WORD_DICTATION"
,
"生词听写"
),
STROKE_ORDER
(
"STROKE_ORDER"
,
"笔顺动图"
),
ARTICLE_READING
(
"ARTICLE_READING"
,
"课文诵读"
),
ENGLISH_WALKMAN
(
"ENGLISH_WALKMAN"
,
"英语随身听"
),
WECHAT_STUDY_GROUP
(
"WECHAT_STUDY_GROUP"
,
"微信学习交流圈"
),
TASK_CLOCK
(
"TASK_CLOCK"
,
"任务打卡"
),
REWARD_CLOCK
(
"REWARD_CLOCK"
,
"奖励打卡"
),
CUSTOM_CLOCK
(
"CUSTOM_CLOCK"
,
"自定义打卡"
),
MEMBER
(
"MEMBER"
,
"开通会员"
),
ORAL_EVALUATION
(
"ORAL_EVALUATION"
,
"口语评测"
),
PBSTORY
(
"PBSTORY"
,
"绘本故事"
),
/**
* add by songx at 2019-5-25 16:52:07
*/
SUBJECTNOTE
(
"SUBJECTNOTE"
,
"错题本"
);
/**
* 枚举转换
*/
public
static
final
Map
<
String
,
AppTypeEnum
>
APP_TYPE_MAP
=
Maps
.
newHashMap
();
static
{
Arrays
.
asList
(
AppTypeEnum
.
values
()).
forEach
(
m
->
{
APP_TYPE_MAP
.
put
(
m
.
value
,
m
);
});
}
/**
* 值
*/
public
final
String
value
;
/**
* 名称
*/
public
final
String
name
;
/**
* 构造
*
* @param value
*/
private
AppTypeEnum
(
String
value
)
{
private
AppTypeEnum
(
String
value
,
String
name
)
{
this
.
value
=
value
;
this
.
name
=
name
;
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
AppTypeEnum
.
valueOf
(
"SUBJECTNOTE"
));
}
}
pcloud-common/src/main/java/com/pcloud/common/exceptions/ParamCheck.java
View file @
59cf09ff
package
com
.
pcloud
.
common
.
exceptions
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
com.pcloud.common.entity.BasePageVO
;
import
com.pcloud.common.utils.ListUtils
;
/**
* 参数校验
*
* @author:songx
* @date:2019年4月15日,下午3:01:35
*/
public
class
ParamCheck
{
/**
* check number is null
*
* @param number
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:03
*/
public
static
void
isNull
(
Number
number
,
String
msg
)
throws
BizException
{
if
(
number
==
null
)
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check boolean is null
*
* @param bool
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:25
*/
public
static
void
isNull
(
Boolean
bool
,
String
msg
)
throws
BizException
{
if
(
bool
==
null
)
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check string is null
*
* @param string
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:36
*/
public
static
void
isEmpty
(
String
string
,
String
msg
)
throws
BizException
{
if
(
StringUtils
.
isEmpty
(
string
))
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check page number is null
*
* @param currentPage
* @param numPerPage
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:07:07
*/
public
static
void
isNull
(
Integer
currentPage
,
Integer
numPerPage
)
throws
BizException
{
if
(
currentPage
==
null
||
numPerPage
==
null
||
currentPage
<
0
||
numPerPage
<
0
)
{
throw
BizException
.
PAGE_PARAM_DELETION
;
}
}
/**
* check list is null
*
* @param list
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:07:37
*/
public
static
void
isEmpty
(
List
<?>
list
,
String
msg
)
throws
BizException
{
if
(
ListUtils
.
isEmpty
(
list
))
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* 校验分页参数校验分页参数
*
* @param basePageVO
* @throws BizException
*/
public
static
void
pageParam
(
BasePageVO
basePageVO
)
throws
BizException
{
pageParam
(
basePageVO
.
getCurrentPage
(),
basePageVO
.
getNumPerPage
());
}
/**
* 校验分页参数
*
* @param currentPage 当前页
* @param numPerPage 每页行数
* @throws BizException
*/
public
static
void
pageParam
(
Integer
currentPage
,
Integer
numPerPage
)
throws
BizException
{
if
(
currentPage
==
null
||
currentPage
<
0
||
numPerPage
==
null
||
numPerPage
<
0
)
{
throw
BizException
.
PAGE_PARAM_DELETION
;
}
}
}
package
com
.
pcloud
.
common
.
exceptions
;
import
java.util.List
;
import
org.apache.commons.lang3.StringUtils
;
import
com.pcloud.common.entity.BasePageVO
;
import
com.pcloud.common.utils.ListUtils
;
/**
* 参数校验
*
* @author:songx
* @date:2019年4月15日,下午3:01:35
*/
public
class
ParamCheck
{
/**
* check number is null
*
* @param number
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:03
*/
public
static
void
isNull
(
Number
number
,
String
msg
)
throws
BizException
{
if
(
number
==
null
)
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check boolean is null
*
* @param bool
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:25
*/
public
static
void
isNull
(
Boolean
bool
,
String
msg
)
throws
BizException
{
if
(
bool
==
null
)
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check string is null
*
* @param string
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:06:36
*/
public
static
void
isEmpty
(
String
string
,
String
msg
)
throws
BizException
{
if
(
StringUtils
.
isEmpty
(
string
))
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check page number is null
*
* @param currentPage
* @param numPerPage
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:07:07
*/
public
static
void
isNull
(
Integer
currentPage
,
Integer
numPerPage
)
throws
BizException
{
if
(
currentPage
==
null
||
numPerPage
==
null
||
currentPage
<
0
||
numPerPage
<
0
)
{
throw
BizException
.
PAGE_PARAM_DELETION
;
}
}
/**
* check list is null
*
* @param list
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:07:37
*/
public
static
void
isEmpty
(
List
<?>
list
,
String
msg
)
throws
BizException
{
if
(
ListUtils
.
isEmpty
(
list
))
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* check bety[] is null
*
* @param bts
* @param msg
* @throws BizException
* @author songx
* @date 2019年4月23日, 下午3:07:37
*/
public
static
void
isEmpty
(
byte
[]
bts
,
String
msg
)
throws
BizException
{
if
(
bts
==
null
||
bts
.
length
==
0
)
{
throw
new
BizException
(
BizException
.
PARAM_IS_NULL
.
getCode
(),
msg
);
}
}
/**
* 校验分页参数校验分页参数
*
* @param basePageVO
* @throws BizException
*/
public
static
void
pageParam
(
BasePageVO
basePageVO
)
throws
BizException
{
pageParam
(
basePageVO
.
getCurrentPage
(),
basePageVO
.
getNumPerPage
());
}
/**
* 校验分页参数
*
* @param currentPage 当前页
* @param numPerPage 每页行数
* @throws BizException
*/
public
static
void
pageParam
(
Integer
currentPage
,
Integer
numPerPage
)
throws
BizException
{
if
(
currentPage
==
null
||
currentPage
<
0
||
numPerPage
==
null
||
numPerPage
<
0
)
{
throw
BizException
.
PAGE_PARAM_DELETION
;
}
}
}
pcloud-common/src/main/java/com/pcloud/common/mq/constant/QueueNameConstant.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
mq
.
constant
;
/**
* @Author: songx
* @Date: 2019年07月11日, 14:48
*/
public
class
QueueNameConstant
{
/**
* 服务调用链路
*/
public
static
final
String
SERVER_LINK
=
"serverLinkQueue"
;
}
pcloud-common/src/main/java/com/pcloud/common/mq/dto/ServerLinkDTO.java
0 → 100644
View file @
59cf09ff
package
com
.
pcloud
.
common
.
mq
.
dto
;
import
com.pcloud.common.dto.BaseDto
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
/**
* @Author: songx
* @Date: 2019年07月11日, 14:52
*/
@Getter
@Setter
@ToString
(
callSuper
=
true
)
public
class
ServerLinkDTO
extends
BaseDto
{
private
static
final
long
serialVersionUID
=
2029227731936018946L
;
/**
* 消费者服务名称
*/
private
String
consumerAppName
;
/**
* 消费者IP
*/
private
String
consumerIp
;
/**
* 消费者类名
*/
private
String
consumerClassName
;
/**
* 消费者方法名
*/
private
String
consumerMethodName
;
/**
* 生产者服务名称
*/
private
String
produceAppName
;
/**
* 生产者IP
*/
private
String
produceIp
;
/**
* 生产者类名
*/
private
String
produceClassName
;
/**
* 生产者方法名
*/
private
String
produceMethodName
;
/**
* 完整的调用链路
*/
private
String
links
;
}
pcloud-common/src/main/java/com/pcloud/common/mq/queue/ServerLinkQueue.java
0 → 100644
View file @
59cf09ff
/**
*
*/
package
com
.
pcloud
.
common
.
mq
.
queue
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.mq.constant.QueueNameConstant
;
import
com.pcloud.common.mq.dto.ServerLinkDTO
;
import
lombok.extern.slf4j.Slf4j
;
/**
* @author:songx
* @date:2019/6/20,11:37
*/
@Slf4j
@Component
public
class
ServerLinkQueue
{
/**
* 服务调用链路QUEUE
*/
public
static
void
send
(
ServerLinkDTO
serverLinkDTO
)
throws
BizException
{
log
.
info
(
"【QUEUE】服务调用链路.[serverLinkDTO]->"
+
serverLinkDTO
);
if
(
serverLinkDTO
==
null
)
{
throw
BizException
.
PARAM_IS_NULL
;
}
getAmqpTemplate
().
convertAndSend
(
QueueNameConstant
.
SERVER_LINK
,
serverLinkDTO
);
}
/**
* 获取实例
*
* @return
*/
public
static
AmqpTemplate
getAmqpTemplate
()
{
return
SingletonInstance
.
amqpTemplate
;
}
@Component
public
static
class
SingletonInstance
{
private
static
AmqpTemplate
amqpTemplate
;
public
SingletonInstance
(
@Autowired
AmqpTemplate
amqpTemplate
)
{
this
.
amqpTemplate
=
amqpTemplate
;
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/FileUtils.java
View file @
59cf09ff
...
...
@@ -29,7 +29,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.FilePathConst
ant
;
import
com.pcloud.common.constant.OSConstant
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.exceptions.BizException
;
...
...
@@ -215,7 +215,7 @@ public class FileUtils {
/**
* 传入文件夹路径,该方法能够实现创建整个路径
*
* @param
p
ath
* @param
fileP
ath
* 文件夹路径,不包含文件名称及后缀名
*/
public
static
boolean
isDir
(
String
filePath
)
{
...
...
@@ -882,7 +882,7 @@ public class FileUtils {
String
fileType
=
getFileType
(
url
);
String
localFilePath
=
url
;
if
(
url
.
startsWith
(
"http"
))
{
localFilePath
=
FilePathConst
.
TEXT_PATH
+
UUIDUitl
.
taskName
()
+
"."
+
fileType
;
localFilePath
=
FilePathConst
ant
.
TEXT
+
UUIDUitl
.
taskName
()
+
"."
+
fileType
;
downloadFileFromUrl
(
url
,
localFilePath
);
}
try
{
...
...
@@ -919,7 +919,7 @@ public class FileUtils {
return
null
;
}
// 下载文件
String
downloadPath
=
FilePathConst
.
DOWNLOAD_PATH
+
UUIDUitl
.
generateString
(
32
)
+
"."
+
fileType
;
String
downloadPath
=
FilePathConst
ant
.
DOWNLOAD
+
UUIDUitl
.
generateString
(
32
)
+
"."
+
fileType
;
FileUtils
.
downloadFileFromUrl
(
url
,
downloadPath
);
// 剪切文件
String
cutPath
=
clipByPercent
(
new
File
(
downloadPath
),
percent
);
...
...
@@ -969,7 +969,7 @@ public class FileUtils {
throw
new
FileException
(
FileException
.
FILE_READ_FAILURE
,
"剪切的文件必须大于1KB"
);
}
// 输出文件路径
String
outFilePath
=
FilePathConst
.
CUT_PATH
+
UUIDUitl
.
generateString
(
12
)
+
"_"
+
inputFile
.
getName
();
String
outFilePath
=
FilePathConst
ant
.
CUT
+
UUIDUitl
.
generateString
(
12
)
+
"_"
+
inputFile
.
getName
();
creatFiles
(
outFilePath
);
// 剪切长度
cutLength
=
cutLength
>
inputFile
.
length
()
?
inputFile
.
length
()
:
cutLength
;
...
...
@@ -1043,7 +1043,7 @@ public class FileUtils {
OutputStream
out
=
null
;
try
{
// Base64解码
byte
[]
b
=
Base64
.
decodeBase64
(
targetPath
);
byte
[]
b
=
Base64
.
decodeBase64
(
base64Code
);
for
(
int
i
=
0
;
i
<
b
.
length
;
++
i
)
{
if
(
b
[
i
]
<
0
)
{
// 调整异常数据
b
[
i
]
+=
256
;
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/ImageUtils.java
View file @
59cf09ff
...
...
@@ -11,16 +11,12 @@ import java.math.BigDecimal;
import
javax.imageio.ImageIO
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.itextpdf.text.Image
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.ImageConstant
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageEnum
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
...
...
@@ -738,37 +734,32 @@ public class ImageUtils {
* @param fileUrl
* @return
*/
// public static UploadResultInfo transcodeToWebp(String fileUrl, int quality) {
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[fileUrl]=" + fileUrl
// + ",[quality]=" + quality);
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConst.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String outputFilePath = FilePathConst.IMAGE_PATH + "webp/" + fileNameAll +
// ".webp";
// FileUtils.creatFiles(outputFilePath);
// UploadResultInfo uploadResultInfo = null;
// try {
// String os = System.getProperty("os.name");
// if (os.toLowerCase().startsWith("win")) {
// executeCwebp4Win(localFilePath, outputFilePath, quality);
// } else {
// executeCwebp4Linux(localFilePath, outputFilePath, quality);
// }
// uploadResultInfo = OssUtils.uploadLocalFile4Child(outputFilePath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("An error happend when convert to webp. Img is: " +
// e.getMessage(), e);
// throw new FileException(FileException.FILE_CONVERT_FAIL, "transcode to webp
// is fail!");
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(outputFilePath);
// }
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[uploadResultInfo]="
// + uploadResultInfo);
// return uploadResultInfo;
// }
// public static UploadResultInfo transcodeToWebp(String fileUrl, int quality) {
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[fileUrl]=" + fileUrl + ",[quality]=" + quality);
// String fileNameAll = FileUtils.getFileNameAll(fileUrl);
// String localFilePath = FilePathConstant.DOWNLOAD_PATH + fileNameAll;
// FileUtils.downloadFileFromUrl(fileUrl, localFilePath);
// String outputFilePath = FilePathConstant.IMAGE_PATH + "webp/" + fileNameAll + ".webp";
// FileUtils.creatFiles(outputFilePath);
// UploadResultInfo uploadResultInfo = null;
// try {
// String os = System.getProperty("os.name");
// if (os.toLowerCase().startsWith("win")) {
// executeCwebp4Win(localFilePath, outputFilePath, quality);
// } else {
// executeCwebp4Linux(localFilePath, outputFilePath, quality);
// }
// uploadResultInfo = OssUtils.uploadLocalFile4Child(outputFilePath, fileUrl);
// } catch (Exception e) {
// LOGGER.error("An error happend when convert to webp. Img is: " + e.getMessage(), e);
// throw new FileException(FileException.FILE_CONVERT_FAIL, "transcode to webp is fail!");
// } finally {
// FileUtils.deleteFile(localFilePath);
// FileUtils.deleteFile(outputFilePath);
// }
// LOGGER.info("【IMAGE API】image transcode to webp.<START>.[uploadResultInfo]=" + uploadResultInfo);
// return uploadResultInfo;
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
...
...
@@ -778,15 +769,13 @@ public class ImageUtils {
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Win(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("cwebp", "-q", (quality == 0 ? 80 :
// quality) + "", inputFilePath, "-o",
// outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
// private static void executeCwebp4Win(String inputFilePath, String outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("cwebp", "-q", (quality == 0 ? 80 : quality) + "", inputFilePath, "-o",
// outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* execute cwebp command:cwebp [options] input_file -o output_file.webp
...
...
@@ -796,47 +785,12 @@ public class ImageUtils {
* @param quality
* @throws Exception
*/
// private static void executeCwebp4Linux(String inputFilePath, String
// outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("/usr/local/bin/cwebp", "-q", (quality
// == 0 ? 80 : quality) + "",
// inputFilePath, "-o", outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// }
/**
* 上传的图片转换成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;
// private static void executeCwebp4Linux(String inputFilePath, String outputFilePath, int quality) throws Exception {
// Process process = new ProcessBuilder("/usr/local/bin/cwebp", "-q", (quality == 0 ? 80 : quality) + "",
// inputFilePath, "-o", outputFilePath).redirectErrorStream(true).start();
// if (0 != process.waitFor()) {
// throw new Exception("process wait for fail!");
// }
// 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/LocalDateUtils.java
View file @
59cf09ff
/**
*
*
*/
package
com
.
pcloud
.
common
.
utils
;
...
...
@@ -9,7 +9,13 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.time.ZoneId
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
import
java.time.temporal.TemporalAdjusters
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
com.pcloud.common.utils.string.StringUtil
;
...
...
@@ -19,436 +25,566 @@ import com.pcloud.common.utils.string.StringUtil;
* @创建时间:2017年7月20日,上午9:11:37 @版本:1.0
*/
public
class
LocalDateUtils
{
private
static
final
DateTimeFormatter
TIME
=
DateTimeFormatter
.
ofPattern
(
"HHmmss"
);
private
static
final
DateTimeFormatter
SHORT_MILLISECOND
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmssSSS"
);
private
static
final
DateTimeFormatter
SHORT_DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmss"
);
private
static
final
DateTimeFormatter
DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
private
static
final
DateTimeFormatter
SHORT_DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
private
static
final
DateTimeFormatter
DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
/**
* 获取当前的日期字符串(yyyy-MM-dd)
*
* @return
*/
public
static
String
getDateNow
()
{
return
LocalDate
.
now
().
format
(
DATE
);
}
/**
* 获取当前的日期字符串(yyyyMMdd)
*
* @return
*/
public
static
String
getShortDateNow
()
{
return
LocalDate
.
now
().
format
(
SHORT_DATE
);
}
/**
* 获取当前的时间字符串(HHmmss)
*
* @return
*/
public
static
String
getShortTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
TIME
);
}
/**
* 获取当前的日期字符串(yyyy-MM-dd HH:mm:ss)
*
* @return
*/
public
static
String
getDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
DATETIME
);
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmss)
*
* @return
*/
public
static
String
getShortDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_DATETIME
);
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmssSSS)
*
* @return
*/
public
static
String
getYmdhmss
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_MILLISECOND
);
}
/**
* 时间戳转换成字符串格式的时间
*
* @param time
* @return
*/
public
static
String
convertToString
(
long
time
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()).
toString
().
replace
(
"T"
,
" "
);
}
/**
* 转换成Stirng类型的时间字符串(yyyy-MM-dd HH:mm:ss)
*
* @param localDateTime
* @return
*/
public
static
String
convertToString
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
==
null
)
{
return
null
;
}
return
localDateTime
.
format
(
DATETIME
);
}
/**
* 获取当前日前多少天以前的日期
*
* @param days
* @return
*/
public
static
LocalDate
getMinusDays
(
long
days
)
{
LocalDate
localDate
=
LocalDate
.
now
();
return
localDate
.
minusDays
(
days
);
}
/**
* 获取当前日前多少小时以前的日期
*
* @param minutes
* @return
*/
public
static
LocalDateTime
getMinusHours
(
long
hours
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
return
localDateTime
.
minusHours
(
hours
);
}
/**
* 获取当前日前多少分钟以前的日期
*
* @param minutes
* @return
*/
public
static
LocalDateTime
getMinusMinutes
(
long
minutes
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
return
localDateTime
.
minusMinutes
(
minutes
);
}
/**
* 获取指定日前多少天以后的日期
*
* @param date
* @param days
* @return
*/
public
static
LocalDateTime
getPlusDays
(
Date
date
,
long
days
)
{
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
localDateTime
.
plusDays
(
days
);
}
/**
* Date转换为localDate
*
* @param date
* @return
*/
public
static
LocalDate
convertDate
(
Date
date
)
{
return
convertDateTime
(
date
).
toLocalDate
();
}
/**
* Date转换为localDateTime
*
* @param date
* @return
*/
public
static
LocalDateTime
convertDateTime
(
Date
date
)
{
if
(
date
==
null
)
{
return
null
;
}
Instant
instant
=
date
.
toInstant
();
return
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
}
/**
* string转换为localDateTime
*
* @param dateTime
* @return
*/
public
static
LocalDateTime
convertDateTime
(
String
dateTime
)
{
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
return
null
;
}
if
(!
dateTime
.
contains
(
"T"
))
{
dateTime
=
dateTime
.
replace
(
" "
,
"T"
);
}
return
LocalDateTime
.
parse
(
dateTime
);
}
/**
* 判断当前日期是否在指定日前之前,含当前日期
*
* @param date
* @return
*/
public
static
boolean
isBefore
(
Date
date
)
{
if
(
date
==
null
)
{
return
false
;
}
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
LocalDateTime
.
now
().
isBefore
(
localDateTime
);
}
/**
* 判断当前日期是否在指定日前之后,含当前日期
*
* @param date
* @return
*/
public
static
boolean
isAfter
(
Date
date
)
{
if
(
date
==
null
)
{
return
false
;
}
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
}
/**
* 判断当前日期是否在指定日前之后,含当前日期
*
* @param localDateTime
* @return
*/
public
static
boolean
isAfter
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
==
null
)
{
return
false
;
}
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
LocalDateTime
firstDateTime
,
LocalDateTime
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
firstDateTime
.
isAfter
(
secondDateTime
);
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
String
firstDateTime
,
String
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
Date
firstDateTime
,
Date
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
}
/**
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInIncludeDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
return
false
;
}
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
nowTime
.
isAfter
(
startDate
.
plusDays
(-
1
))
&&
nowTime
.
isBefore
(
endDate
.
plusDays
(
1
)))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInIncludeDateString
(
String
startDate
,
String
endDate
)
{
return
isInIncludeDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
return
false
;
}
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
nowTime
.
isAfter
(
startDate
)
&&
nowTime
.
isBefore
(
endDate
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDateString
(
String
startDate
,
String
endDate
)
{
return
isInBetweenDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTime
(
LocalDateTime
startDateTime
,
LocalDateTime
endDateTime
)
{
if
(
startDateTime
==
null
||
endDateTime
==
null
)
{
return
false
;
}
LocalDateTime
nowTime
=
LocalDateTime
.
now
();
if
(
nowTime
.
isAfter
(
startDateTime
)
&&
nowTime
.
isBefore
(
endDateTime
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTime
(
Date
startDateTime
,
Date
endDateTime
)
{
return
isInBetweenDateTime
(
convertDateTime
(
startDateTime
),
convertDateTime
(
endDateTime
));
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTimeString
(
String
startDateTime
,
String
endDateTime
)
{
return
isInBetweenDateTime
(
LocalDateTime
.
parse
(
startDateTime
),
LocalDateTime
.
parse
(
endDateTime
));
}
/**
* 获取两个时间差,天,时,分
*
* @param stratDateTime
* @param endDateTime
* @return
*/
public
static
long
[]
getDatePoor
(
LocalDateTime
stratDateTime
,
LocalDateTime
endDateTime
)
{
if
(
stratDateTime
==
null
||
stratDateTime
==
null
)
{
return
null
;
}
Duration
duration
=
Duration
.
between
(
stratDateTime
,
endDateTime
);
// 计算差多少天
long
day
=
duration
.
toDays
();
// 计算差多少小时
long
hour
=
duration
.
toHours
()
-
day
*
24
;
// 计算差多少分钟
long
min
=
duration
.
toMinutes
()
-
duration
.
toHours
()
*
60
;
return
new
long
[]
{
day
,
hour
,
min
};
}
/**
* 获取指定时间与当前日期相差多少小时
*
* @param date
* @return
*/
public
static
long
getHourPoor
(
Date
date
)
{
if
(
date
==
null
)
{
return
-
1
;
}
return
getHourPoor
(
convertDateTime
(
date
));
}
/**
* 获取指定时间与当前日期相差多少小时
*
* @param dateTime
* @return
*/
public
static
long
getHourPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
return
-
1
;
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toHours
();
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param date
* @return
*/
public
static
long
getDayPoor
(
Date
date
)
{
if
(
date
==
null
)
{
return
-
1
;
}
return
getDayPoor
(
convertDateTime
(
date
));
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param dateTime
* @return
*/
public
static
long
getDayPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
return
-
1
;
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toDays
();
}
private
static
final
DateTimeFormatter
TIME
=
DateTimeFormatter
.
ofPattern
(
"HHmmss"
);
private
static
final
DateTimeFormatter
SHORT_MILLISECOND
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmssSSS"
);
private
static
final
DateTimeFormatter
SHORT_DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMddHHmmss"
);
private
static
final
DateTimeFormatter
DATETIME
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
private
static
final
DateTimeFormatter
SHORT_DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyyMMdd"
);
private
static
final
DateTimeFormatter
DATE
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
/**
* 获取当前的日期字符串(yyyy-MM-dd)
*
* @return
*/
public
static
String
getDateNow
()
{
return
LocalDate
.
now
().
format
(
DATE
);
}
/**
* 获取当前的日期字符串(yyyyMMdd)
*
* @return
*/
public
static
String
getShortDateNow
()
{
return
LocalDate
.
now
().
format
(
SHORT_DATE
);
}
/**
* 获取当前的时间字符串(HHmmss)
*
* @return
*/
public
static
String
getShortTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
TIME
);
}
/**
* 获取当前的日期字符串(yyyy-MM-dd HH:mm:ss)
*
* @return
*/
public
static
String
getDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
DATETIME
);
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmss)
*
* @return
*/
public
static
String
getShortDateTimeNow
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_DATETIME
);
}
/**
* 获取当前的日期字符串(yyyyMMddHHmmssSSS)
*
* @return
*/
public
static
String
getYmdhmss
()
{
return
LocalDateTime
.
now
().
format
(
SHORT_MILLISECOND
);
}
/**
* 时间戳转换成字符串格式的时间
*
* @param time
* @return
*/
public
static
String
convertToString
(
long
time
)
{
return
LocalDateTime
.
ofInstant
(
Instant
.
ofEpochMilli
(
time
),
ZoneId
.
systemDefault
()).
toString
().
replace
(
"T"
,
" "
);
}
/**
* 转换成Stirng类型的时间字符串(yyyy-MM-dd HH:mm:ss)
*
* @param localDateTime
* @return
*/
public
static
String
convertToString
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
==
null
)
{
return
null
;
}
return
localDateTime
.
format
(
DATETIME
);
}
/**
* 获取当前日前多少天以前的日期
*
* @param days
* @return
*/
public
static
LocalDate
getMinusDays
(
long
days
)
{
LocalDate
localDate
=
LocalDate
.
now
();
return
localDate
.
minusDays
(
days
);
}
/**
* 获取指定日前多少天以前的日期
*
* @param date
* @param days
* @return
*/
public
static
LocalDate
getMinusDays
(
LocalDate
date
,
long
days
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
minusDays
(
days
);
}
/**
* 获取当前日前多少小时以前的日期
*
* @param hours
* @return
*/
public
static
LocalDateTime
getMinusHours
(
long
hours
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
return
localDateTime
.
minusHours
(
hours
);
}
/**
* 获取当前日前多少分钟以前的日期
*
* @param minutes
* @return
*/
public
static
LocalDateTime
getMinusMinutes
(
long
minutes
)
{
LocalDateTime
localDateTime
=
LocalDateTime
.
now
();
return
localDateTime
.
minusMinutes
(
minutes
);
}
/**
* 获取指定日前多少天以后的日期
*
* @param date
* @param days
* @return
*/
public
static
LocalDateTime
getPlusDays
(
Date
date
,
long
days
)
{
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
localDateTime
.
plusDays
(
days
);
}
/**
* String转换为localDate
*
* @param date
* @return
*/
public
static
LocalDate
convertDate
(
String
date
)
{
if
(
StringUtil
.
isEmpty
(
date
))
{
return
null
;
}
return
LocalDate
.
parse
(
date
);
}
/**
* Date转换为localDate
*
* @param date
* @return
*/
public
static
LocalDate
convertDate
(
Date
date
)
{
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
if
(
localDateTime
==
null
)
{
return
null
;
}
return
localDateTime
.
toLocalDate
();
}
/**
* Date转换为localDateTime
*
* @param date
* @return
*/
public
static
LocalDateTime
convertDateTime
(
Date
date
)
{
if
(
date
==
null
)
{
return
null
;
}
Instant
instant
=
date
.
toInstant
();
return
LocalDateTime
.
ofInstant
(
instant
,
ZoneId
.
systemDefault
());
}
/**
* string转换为localDateTime
*
* @param dateTime
* @return
*/
public
static
LocalDateTime
convertDateTime
(
String
dateTime
)
{
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
return
null
;
}
if
(!
dateTime
.
contains
(
"T"
))
{
dateTime
=
dateTime
.
replace
(
" "
,
"T"
);
}
return
LocalDateTime
.
parse
(
dateTime
);
}
/**
* 判断当前日期是否在指定日前之前,含当前日期
*
* @param date
* @return
*/
public
static
boolean
isBefore
(
Date
date
)
{
if
(
date
==
null
)
{
return
false
;
}
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
LocalDateTime
.
now
().
isBefore
(
localDateTime
);
}
/**
* 判断当前日期是否在指定日前之后,含当前日期
*
* @param date
* @return
*/
public
static
boolean
isAfter
(
Date
date
)
{
if
(
date
==
null
)
{
return
false
;
}
LocalDateTime
localDateTime
=
convertDateTime
(
date
);
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
}
/**
* 判断当前日期是否在指定日前之后,含当前日期
*
* @param localDateTime
* @return
*/
public
static
boolean
isAfter
(
LocalDateTime
localDateTime
)
{
if
(
localDateTime
==
null
)
{
return
false
;
}
return
LocalDateTime
.
now
().
isAfter
(
localDateTime
);
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
LocalDateTime
firstDateTime
,
LocalDateTime
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
firstDateTime
.
isAfter
(
secondDateTime
);
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
String
firstDateTime
,
String
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
}
/**
* 判断第一个日期是否在第二个日前之后
*
* @param firstDateTime
* @param secondDateTime
* @return
*/
public
static
boolean
isAfter
(
Date
firstDateTime
,
Date
secondDateTime
)
{
if
(
firstDateTime
==
null
||
secondDateTime
==
null
)
{
return
false
;
}
return
convertDateTime
(
firstDateTime
).
isAfter
(
convertDateTime
(
secondDateTime
));
}
/**
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInIncludeDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
return
false
;
}
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
nowTime
.
isAfter
(
startDate
.
plusDays
(-
1
))
&&
nowTime
.
isBefore
(
endDate
.
plusDays
(
1
)))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内,包含前后的两天,例:2017-07-15->[2017-07-01, 2017-07-15]
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInIncludeDateString
(
String
startDate
,
String
endDate
)
{
return
isInIncludeDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDate
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
return
false
;
}
LocalDate
nowTime
=
LocalDate
.
now
();
if
(
nowTime
.
isAfter
(
startDate
)
&&
nowTime
.
isBefore
(
endDate
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内,不包含前后的两天,例:2017-07-15->(2017-07-01, 2017-07-15)
*
* @param startDate
* @param endDate
* @return
*/
public
static
boolean
isInBetweenDateString
(
String
startDate
,
String
endDate
)
{
return
isInBetweenDate
(
LocalDate
.
parse
(
startDate
),
LocalDate
.
parse
(
endDate
));
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTime
(
LocalDateTime
startDateTime
,
LocalDateTime
endDateTime
)
{
if
(
startDateTime
==
null
||
endDateTime
==
null
)
{
return
false
;
}
LocalDateTime
nowTime
=
LocalDateTime
.
now
();
if
(
nowTime
.
isAfter
(
startDateTime
)
&&
nowTime
.
isBefore
(
endDateTime
))
{
return
true
;
}
else
{
return
false
;
}
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTime
(
Date
startDateTime
,
Date
endDateTime
)
{
return
isInBetweenDateTime
(
convertDateTime
(
startDateTime
),
convertDateTime
(
endDateTime
));
}
/**
* 判断当前日期是否在一定的日期之内, 例:2017-07-15 12:12:12->(2017-07-01 12:12:12, 2017-07-15
* 12:12:12)
*
* @param startDateTime
* @param endDateTime
* @return
*/
public
static
boolean
isInBetweenDateTimeString
(
String
startDateTime
,
String
endDateTime
)
{
return
isInBetweenDateTime
(
LocalDateTime
.
parse
(
startDateTime
),
LocalDateTime
.
parse
(
endDateTime
));
}
/**
* 获取两个时间差,天,时,分
*
* @param stratDateTime
* @param endDateTime
* @return
*/
public
static
long
[]
getDatePoor
(
LocalDateTime
stratDateTime
,
LocalDateTime
endDateTime
)
{
if
(
stratDateTime
==
null
||
stratDateTime
==
null
)
{
return
null
;
}
Duration
duration
=
Duration
.
between
(
stratDateTime
,
endDateTime
);
// 计算差多少天
long
day
=
duration
.
toDays
();
// 计算差多少小时
long
hour
=
duration
.
toHours
()
-
day
*
24
;
// 计算差多少分钟
long
min
=
duration
.
toMinutes
()
-
duration
.
toHours
()
*
60
;
return
new
long
[]{
day
,
hour
,
min
};
}
/**
* 获取指定时间与当前日期相差多少小时
*
* @param date
* @return
*/
public
static
long
getHourPoor
(
Date
date
)
{
if
(
date
==
null
)
{
return
-
1
;
}
return
getHourPoor
(
convertDateTime
(
date
));
}
/**
* 获取指定时间与当前日期相差多少小时
*
* @param dateTime
* @return
*/
public
static
long
getHourPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
return
-
1
;
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toHours
();
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param date
* @return
*/
public
static
long
getDayPoor
(
Date
date
)
{
if
(
date
==
null
)
{
return
-
1
;
}
return
getDayPoor
(
convertDateTime
(
date
));
}
/**
* 获取指定时间与当前日期相差多少天
*
* @param dateTime
* @return
*/
public
static
long
getDayPoor
(
LocalDateTime
dateTime
)
{
if
(
dateTime
==
null
)
{
throw
new
IllegalArgumentException
(
"dateTime is null"
);
}
Duration
duration
=
Duration
.
between
(
dateTime
,
LocalDateTime
.
now
());
return
duration
.
toDays
();
}
/**
* 获取指定时间相差多少天
*
* @param startDate 格式:2017-01-01
* @param endDate 格式:2017-02-01
* @return
*/
public
static
long
getDayPoor
(
String
startDate
,
String
endDate
)
{
if
(
StringUtil
.
isEmpty
(
startDate
)
||
StringUtil
.
isEmpty
(
endDate
))
{
throw
new
IllegalArgumentException
(
"startDate or endDate is null"
);
}
return
getDayPoor
(
convertDate
(
startDate
),
convertDate
(
endDate
));
}
/**
* 获取指定时间相差多少天
*
* @param startDate
* @param endDate
* @return
*/
public
static
long
getDayPoor
(
LocalDate
startDate
,
LocalDate
endDate
)
{
if
(
startDate
==
null
||
endDate
==
null
)
{
throw
new
IllegalArgumentException
(
"startDate or endDate is null"
);
}
return
startDate
.
until
(
endDate
,
ChronoUnit
.
DAYS
);
}
/**
* 获取月份
*
* @param dateTime 时间格式:2019-01-01 00:00:00
* @return
*/
public
static
int
getMonth
(
String
dateTime
)
{
if
(
StringUtil
.
isEmpty
(
dateTime
))
{
return
0
;
}
return
convertDateTime
(
dateTime
).
getMonthValue
();
}
/**
* 获取当月第一天
*
* @param date
* @return
*/
public
static
LocalDate
firstDay
(
LocalDate
date
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
with
(
TemporalAdjusters
.
firstDayOfMonth
());
}
/**
* 获取当月最后一天
*
* @param date
* @return
*/
public
static
LocalDate
lastDay
(
LocalDate
date
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
date
.
with
(
TemporalAdjusters
.
lastDayOfMonth
());
}
/**
* 获取指定日期和天数以前的日期时间集合(不含指定日期)
*
* @param date
* @return
*/
public
static
List
<
LocalDate
>
getBeforeDays
(
LocalDate
date
,
long
days
)
{
if
(
date
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
List
<
LocalDate
>
localDates
=
new
ArrayList
<>();
for
(
long
i
=
days
;
i
>
0
;
i
--)
{
localDates
.
add
(
getMinusDays
(
date
,
i
));
}
return
localDates
;
}
/**
* 获取指定日期之间的日期集合(含指定日期)
*
* @param startdate
* @param endDate
* @return
*/
public
static
List
<
LocalDate
>
getDates
(
LocalDate
startdate
,
LocalDate
endDate
)
{
if
(
startdate
==
null
||
endDate
==
null
)
{
throw
new
IllegalArgumentException
(
"date is null"
);
}
return
Stream
.
iterate
(
startdate
,
date
->
date
.
plusDays
(
1
))
.
limit
(
ChronoUnit
.
DAYS
.
between
(
startdate
,
endDate
)
+
1
).
collect
(
Collectors
.
toList
());
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/PictureUtil.java
View file @
59cf09ff
package
com
.
pcloud
.
common
.
utils
;
/**
* Created by ${user} on ${date}
*/
import
com.alibaba.fastjson.JSON
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageTypeEnum
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.httpclient.SimpleHttpUtils
;
import
com.pcloud.common.utils.json.JSONUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author TianChao
* @date 2018/10/13 15:02
*/
public
class
PictureUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
PictureUtil
.
class
);
private
static
Color
defaultColor
=
new
Color
(
252
,
252
,
252
);
private
static
Color
borderColor
=
new
Color
(
221
,
221
,
221
);
private
static
String
playPic
=
"https://file.5rs.me/oss/uploadfe/png/3c687bffac4d885ecfff8517d6c3f9c2.png"
;
private
static
String
defaultBackgroundPic
=
"https://oss.5rs.me/oss/uploadfe/png/3003b8978e85052f96ababdf7d46f70a.png"
;
public
static
Color
getImagePixel
(
BufferedImage
bi
)
{
if
(
bi
.
getWidth
()*
bi
.
getHeight
()>
500000
)
{
BufferedImage
pic1
=
new
BufferedImage
(
157
,
224
,
BufferedImage
.
SCALE_SMOOTH
);
Graphics
graphics
=
pic1
.
getGraphics
();
graphics
.
drawImage
(
bi
.
getScaledInstance
(
157
,
224
,
Image
.
SCALE_SMOOTH
),
0
,
0
,
null
);
graphics
.
dispose
();
bi
=
pic1
;
}
int
width
=
bi
.
getWidth
();
int
height
=
bi
.
getHeight
();
int
sum
=
width
*
height
;
int
minx
=
bi
.
getMinX
();
int
miny
=
bi
.
getMinY
();
int
R
=
0
;
int
G
=
0
;
int
B
=
0
;
List
<
String
>
list
=
new
ArrayList
<>();
for
(
int
i
=
minx
;
i
<
width
;
i
++)
{
for
(
int
j
=
miny
;
j
<
height
;
j
++)
{
int
pixel
=
bi
.
getRGB
(
i
,
j
);
if
(
pixel
==
Color
.
white
.
getRGB
()
||
pixel
==
Color
.
black
.
getRGB
()){
continue
;
}
R
=(
pixel
&
0xff0000
)
>>
16
;
G
=(
pixel
&
0xff00
)
>>
8
;
B
=(
pixel
&
0xff
);
if
((
R
>
230
&&
G
>
230
&&
B
>
230
)
||(
R
<
30
&&
G
<
30
&&
B
<
30
)){
continue
;
}
list
.
add
(
R
+
"-"
+
G
+
"-"
+
B
);
}
}
// R = R/sum;
// G = G/sum;
// B = B/sum;
// return new Color(R,G,B);
return
getMaxCount
(
list
);
}
public
static
Color
getMaxCount
(
List
<
String
>
s
)
{
List
<
String
>
list
=
s
;
Map
<
String
,
Integer
>
map
=
new
HashMap
<
String
,
Integer
>();
for
(
String
c
:
list
)
{
Integer
l
=
map
.
get
(
c
);
if
(
l
==
null
)
l
=
1
;
else
l
++;
map
.
put
(
c
,
l
);
}
String
max
=
null
;
long
num
=
0
;
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
String
key
=
entry
.
getKey
();
Integer
temp
=
entry
.
getValue
();
if
(
max
==
null
||
temp
>
num
)
{
max
=
key
;
num
=
temp
;
}
}
String
str
[]
=
max
.
split
(
"\\-"
);
if
(
str
.
length
==
3
)
{
return
new
Color
(
Integer
.
parseInt
(
str
[
0
]),
Integer
.
parseInt
(
str
[
1
]),
Integer
.
parseInt
(
str
[
2
]));
}
return
Color
.
gray
;
}
public
static
String
getB16
(
int
R
,
int
G
,
int
B
){
String
[]
h
=
new
String
[
256
];
h
[
0
]=
"00"
;
h
[
1
]=
"01"
;
h
[
2
]=
"02"
;
h
[
3
]=
"03"
;
h
[
4
]=
"04"
;
h
[
5
]=
"05"
;
h
[
6
]=
"06"
;
h
[
7
]=
"07"
;
h
[
8
]=
"08"
;
h
[
9
]=
"09"
;
h
[
10
]=
"0A"
;
h
[
11
]=
"0B"
;
h
[
12
]=
"0C"
;
h
[
13
]=
"0D"
;
h
[
14
]=
"0E"
;
h
[
15
]=
"0F"
;
h
[
16
]=
"10"
;
h
[
17
]=
"11"
;
h
[
18
]=
"12"
;
h
[
19
]=
"13"
;
h
[
20
]=
"14"
;
h
[
21
]=
"15"
;
h
[
22
]=
"16"
;
h
[
23
]=
"17"
;
h
[
24
]=
"18"
;
h
[
25
]=
"19"
;
h
[
26
]=
"1A"
;
h
[
27
]=
"1B"
;
h
[
28
]=
"1C"
;
h
[
29
]=
"1D"
;
h
[
30
]=
"1E"
;
h
[
31
]=
"1F"
;
h
[
32
]=
"20"
;
h
[
33
]=
"21"
;
h
[
34
]=
"22"
;
h
[
35
]=
"23"
;
h
[
36
]=
"24"
;
h
[
37
]=
"25"
;
h
[
38
]=
"26"
;
h
[
39
]=
"27"
;
h
[
40
]=
"28"
;
h
[
41
]=
"29"
;
h
[
42
]=
"2A"
;
h
[
43
]=
"2B"
;
h
[
44
]=
"2C"
;
h
[
45
]=
"2D"
;
h
[
46
]=
"2E"
;
h
[
47
]=
"2F"
;
h
[
48
]=
"30"
;
h
[
49
]=
"31"
;
h
[
50
]=
"32"
;
h
[
51
]=
"33"
;
h
[
52
]=
"34"
;
h
[
53
]=
"35"
;
h
[
54
]=
"36"
;
h
[
55
]=
"37"
;
h
[
56
]=
"38"
;
h
[
57
]=
"39"
;
h
[
58
]=
"3A"
;
h
[
59
]=
"3B"
;
h
[
60
]=
"3C"
;
h
[
61
]=
"3D"
;
h
[
62
]=
"3E"
;
h
[
63
]=
"3F"
;
h
[
64
]=
"40"
;
h
[
65
]=
"41"
;
h
[
66
]=
"42"
;
h
[
67
]=
"43"
;
h
[
68
]=
"44"
;
h
[
69
]=
"45"
;
h
[
70
]=
"46"
;
h
[
71
]=
"47"
;
h
[
72
]=
"48"
;
h
[
73
]=
"49"
;
h
[
74
]=
"4A"
;
h
[
75
]=
"4B"
;
h
[
76
]=
"4C"
;
h
[
77
]=
"4D"
;
h
[
78
]=
"4E"
;
h
[
79
]=
"4F"
;
h
[
80
]=
"50"
;
h
[
81
]=
"51"
;
h
[
82
]=
"52"
;
h
[
83
]=
"53"
;
h
[
84
]=
"54"
;
h
[
85
]=
"55"
;
h
[
86
]=
"56"
;
h
[
87
]=
"57"
;
h
[
88
]=
"58"
;
h
[
89
]=
"59"
;
h
[
90
]=
"5A"
;
h
[
91
]=
"5B"
;
h
[
92
]=
"5C"
;
h
[
93
]=
"5D"
;
h
[
94
]=
"5E"
;
h
[
95
]=
"6F"
;
h
[
96
]=
"60"
;
h
[
97
]=
"61"
;
h
[
98
]=
"62"
;
h
[
99
]=
"63"
;
h
[
100
]=
"64"
;
h
[
101
]=
"65"
;
h
[
102
]=
"66"
;
h
[
103
]=
"67"
;
h
[
104
]=
"68"
;
h
[
105
]=
"69"
;
h
[
106
]=
"6A"
;
h
[
107
]=
"6B"
;
h
[
108
]=
"6C"
;
h
[
109
]=
"6D"
;
h
[
110
]=
"6E"
;
h
[
111
]=
"6F"
;
h
[
112
]=
"70"
;
h
[
113
]=
"71"
;
h
[
114
]=
"72"
;
h
[
115
]=
"73"
;
h
[
116
]=
"74"
;
h
[
117
]=
"75"
;
h
[
118
]=
"76"
;
h
[
119
]=
"77"
;
h
[
120
]=
"78"
;
h
[
121
]=
"79"
;
h
[
122
]=
"7A"
;
h
[
123
]=
"7B"
;
h
[
124
]=
"7C"
;
h
[
125
]=
"7D"
;
h
[
126
]=
"7E"
;
h
[
127
]=
"7F"
;
h
[
128
]=
"80"
;
h
[
129
]=
"81"
;
h
[
130
]=
"82"
;
h
[
131
]=
"83"
;
h
[
132
]=
"84"
;
h
[
133
]=
"85"
;
h
[
134
]=
"86"
;
h
[
135
]=
"87"
;
h
[
136
]=
"88"
;
h
[
137
]=
"89"
;
h
[
138
]=
"8A"
;
h
[
139
]=
"8B"
;
h
[
140
]=
"8C"
;
h
[
141
]=
"8D"
;
h
[
142
]=
"8E"
;
h
[
143
]=
"8F"
;
h
[
144
]=
"90"
;
h
[
145
]=
"91"
;
h
[
146
]=
"92"
;
h
[
147
]=
"93"
;
h
[
148
]=
"94"
;
h
[
149
]=
"95"
;
h
[
150
]=
"96"
;
h
[
151
]=
"97"
;
h
[
152
]=
"98"
;
h
[
153
]=
"99"
;
h
[
154
]=
"9A"
;
h
[
155
]=
"9B"
;
h
[
156
]=
"9C"
;
h
[
157
]=
"9D"
;
h
[
158
]=
"9E"
;
h
[
159
]=
"9F"
;
h
[
160
]=
"A0"
;
h
[
161
]=
"A1"
;
h
[
162
]=
"A2"
;
h
[
163
]=
"A3"
;
h
[
164
]=
"A4"
;
h
[
165
]=
"A5"
;
h
[
166
]=
"A6"
;
h
[
167
]=
"A7"
;
h
[
168
]=
"A8"
;
h
[
169
]=
"A9"
;
h
[
170
]=
"AA"
;
h
[
171
]=
"AB"
;
h
[
172
]=
"AC"
;
h
[
173
]=
"AD"
;
h
[
174
]=
"AE"
;
h
[
175
]=
"AF"
;
h
[
176
]=
"B0"
;
h
[
177
]=
"B1"
;
h
[
178
]=
"B2"
;
h
[
179
]=
"B3"
;
h
[
180
]=
"B4"
;
h
[
181
]=
"B5"
;
h
[
182
]=
"B6"
;
h
[
183
]=
"B7"
;
h
[
184
]=
"B8"
;
h
[
185
]=
"B9"
;
h
[
186
]=
"BA"
;
h
[
187
]=
"BB"
;
h
[
188
]=
"BC"
;
h
[
189
]=
"BD"
;
h
[
190
]=
"BE"
;
h
[
191
]=
"BF"
;
h
[
192
]=
"C0"
;
h
[
193
]=
"C1"
;
h
[
194
]=
"C2"
;
h
[
195
]=
"C3"
;
h
[
196
]=
"C4"
;
h
[
197
]=
"C5"
;
h
[
198
]=
"C6"
;
h
[
199
]=
"C7"
;
h
[
200
]=
"C8"
;
h
[
201
]=
"C9"
;
h
[
202
]=
"CA"
;
h
[
203
]=
"CB"
;
h
[
204
]=
"CC"
;
h
[
205
]=
"CD"
;
h
[
206
]=
"CE"
;
h
[
207
]=
"CF"
;
h
[
208
]=
"D0"
;
h
[
209
]=
"D1"
;
h
[
210
]=
"D2"
;
h
[
211
]=
"D3"
;
h
[
212
]=
"D4"
;
h
[
213
]=
"D5"
;
h
[
214
]=
"D6"
;
h
[
215
]=
"D7"
;
h
[
216
]=
"D8"
;
h
[
217
]=
"D9"
;
h
[
218
]=
"DA"
;
h
[
219
]=
"DB"
;
h
[
220
]=
"DC"
;
h
[
221
]=
"DD"
;
h
[
222
]=
"DE"
;
h
[
223
]=
"DF"
;
h
[
224
]=
"E0"
;
h
[
225
]=
"E1"
;
h
[
226
]=
"E2"
;
h
[
227
]=
"E3"
;
h
[
228
]=
"E4"
;
h
[
229
]=
"E5"
;
h
[
230
]=
"E6"
;
h
[
231
]=
"E7"
;
h
[
232
]=
"E8"
;
h
[
233
]=
"E9"
;
h
[
234
]=
"EA"
;
h
[
235
]=
"EB"
;
h
[
236
]=
"EC"
;
h
[
237
]=
"ED"
;
h
[
238
]=
"EE"
;
h
[
239
]=
"EF"
;
h
[
240
]=
"F0"
;
h
[
241
]=
"F1"
;
h
[
242
]=
"F2"
;
h
[
243
]=
"F3"
;
h
[
244
]=
"F4"
;
h
[
245
]=
"F5"
;
h
[
246
]=
"F6"
;
h
[
247
]=
"F7"
;
h
[
248
]=
"F8"
;
h
[
249
]=
"F9"
;
h
[
250
]=
"FA"
;
h
[
251
]=
"FB"
;
h
[
252
]=
"FC"
;
h
[
253
]=
"FD"
;
h
[
254
]=
"FE"
;
h
[
255
]=
"FF"
;
return
"#"
+
h
[
R
]
+
h
[
G
]
+
h
[
B
];
}
public
static
Color
getImagePixel
(
String
imgFile
)
{
BufferedImage
bi
=
null
;
Color
imagePixel
;
try
{
if
(
imgFile
.
contains
(
"http"
)){
bi
=
ImageIO
.
read
(
new
URL
(
imgFile
));
}
else
{
bi
=
ImageIO
.
read
(
new
File
(
imgFile
));
}
imagePixel
=
getImagePixel
(
bi
);
}
catch
(
Exception
e
)
{
imagePixel
=
Color
.
gray
;
LOGGER
.
warn
(
"生成图片失败,图片="
+
imgFile
+
","
+
e
.
getMessage
(),
e
);
}
return
imagePixel
;
}
public
static
String
toBrowserHexValue
(
int
number
)
{
StringBuilder
builder
=
new
StringBuilder
(
Integer
.
toHexString
(
number
&
0xff
));
while
(
builder
.
length
()
<
2
)
{
builder
=
new
StringBuilder
(
"0"
).
append
(
builder
);
}
return
builder
.
toString
().
toUpperCase
();
}
public
static
Color
toColorFromString
(
String
colorStr
){
colorStr
=
colorStr
.
substring
(
2
);
Color
color
=
new
Color
(
Integer
.
parseInt
(
colorStr
,
16
))
;
return
color
;
}
private
static
BufferedImage
subPicByWhite
(
BufferedImage
picImage
){
return
picImage
.
getSubimage
(
9
,
9
,
699
,
300
);
}
public
static
String
getQrCover
(
String
bookPic
,
boolean
isDefault
){
String
resultPath
=
""
;
try
{
Color
color
=
null
;
try
{
color
=
getImagePixel
(
bookPic
);
}
catch
(
Exception
e
){
color
=
Color
.
gray
;
}
String
lightIcon
=
"https://oss.5rs.me/oss/uploadfe/png/12dcbc38528d926912c444765d786a9a.png"
;
String
deepIcon
=
"https://oss.5rs.me/oss/uploadfe/png/60612a7415bdac8533568ae0c21a94b6.png"
;
String
icon
;
if
(
color
!=
null
&&
(
color
.
getRed
()<
180
||
color
.
getBlue
()<
180
||
color
.
getGreen
()<
180
)){
icon
=
lightIcon
;
}
else
{
icon
=
deepIcon
;
}
String
html
=
"<div style = \"position: relative;width: 700px;height: 300px;border: 0px solid green;background-color: #fcfcfc;text-align: center;\"> <div style = \"position: absolute;width: 100%;height: 66%;background-color: rgb("
+
color
.
getRed
()+
","
+
color
.
getGreen
()+
","
+
color
.
getBlue
()+
");overflow: hidden;\"> <div style = \"position: absolute;top: 20px;right: -20px;background-image: url('"
+
icon
+
"');background-size: 100%;width: 219px;height: 149px;\"> </div> </div><div style=\"position: relative;display: inline-block;width: 158px;height: 225px;box-shadow: 0px 4px 14px 2px rgba(14, 47, 70, 0.2);border-radius: 4px;border: solid 1px #ddd; margin-top: 35px;background: url('"
+
bookPic
+
"') no-repeat;background-size: cover;background-position: center;\"></div></div>"
;
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
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
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bufferedImage
=
subPicByWhite
(
bookPicImage
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
bufferedImage
,
ImageTypeEnum
.
JPG
.
value
,
os
);
UploadResultInfo
uploadResultInfo
=
OssUtils
.
uploadFileByte
(
os
.
toByteArray
(),
UUIDUitl
.
taskName
(),
ImageTypeEnum
.
JPG
.
value
);
os
.
close
();
resultPath
=
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"生成合成图失败,url="
+
bookPic
+
"====="
+
e
.
getMessage
(),
e
);
}
return
resultPath
;
}
public
static
void
main
(
String
[]
args
)
{
// String bookPic = "https://file.5rs.me/oss/upload/image/jpg/c2c7f0b85f9f4eb683cd86a2945bc5e5.jpg";
String
bookPic
=
"https://oss.5rs.me/oss/uploadfe/jpg/e88c2f608fe4365f5c0efd7dda0eb59e.jpg"
;
Color
color
;
if
(
bookPic
.
contains
(
"/oss/"
)){
String
s
=
SimpleHttpUtils
.
httpGet
(
bookPic
+
"?x-oss-process=image/average-hue"
,
null
);
System
.
out
.
println
(
s
);
Map
map
=
JSONUtils
.
jsonToMap
(
s
,
String
.
class
,
String
.
class
);
String
rgb
=
(
String
)
map
.
get
(
"RGB"
);
color
=
toColorFromString
(
rgb
);
}
else
{
color
=
getImagePixel
(
bookPic
);
}
String
lightIcon
=
"https://oss.5rs.me/oss/uploadfe/png/12dcbc38528d926912c444765d786a9a.png"
;
String
deepIcon
=
"https://oss.5rs.me/oss/uploadfe/png/60612a7415bdac8533568ae0c21a94b6.png"
;
String
icon
;
if
(
color
!=
null
&&
(
color
.
getRed
()<
180
||
color
.
getBlue
()<
180
||
color
.
getGreen
()<
180
)){
icon
=
lightIcon
;
}
else
{
icon
=
deepIcon
;
}
String
html
=
"<div style = \"position: relative;width: 700px;height: 300px;border: 0px solid green;background-color: #fcfcfc;text-align: center;\"> <div style = \"position: absolute;width: 100%;height: 66%;background-color: rgb("
+
color
.
getRed
()+
","
+
color
.
getGreen
()+
","
+
color
.
getBlue
()+
");overflow: hidden;\"> <div style = \"position: absolute;top: 20px;right: -20px;background-image: url('"
+
icon
+
"');background-size: 100%;width: 219px;height: 149px;\"> </div> </div><div style=\"position: relative;display: inline-block;width: 158px;height: 225px;box-shadow: 0px 4px 14px 2px rgba(14, 47, 70, 0.2);border-radius: 4px;border: solid 1px #ddd; margin-top: 35px;background: url('"
+
bookPic
+
"') no-repeat;background-size: cover;background-position: center;\"></div></div>"
;
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
String
postResult
=
HttpKit
.
post
(
"http://192.168.92.111:8214/transcode/htm2img/jpg"
,
JSON
.
toJSONString
(
param
));
// String s = SimpleHttpUtils.httpRequest("http://localhost:8214/transcode/htm2img/jpg", param,"POST","utf-8",header);
Map
map
=
JSONUtils
.
jsonToMap
(
postResult
,
String
.
class
,
String
.
class
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
System
.
out
.
println
(
pic
);
try
{
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bufferedImage
=
subPicByWhite
(
bookPicImage
);
OutputStream
os
=
new
FileOutputStream
(
"C:\\Users\\LiHao\\Desktop\\封面图\\result.jpg"
);
ImageIO
.
write
(
bufferedImage
,
ImageTypeEnum
.
JPG
.
value
,
os
);
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// String bookPic = "C:\\Users\\LiHao\\Desktop\\封面图\\aa.jpg";
// String playPic = "C:\\Users\\LiHao\\Desktop\\封面图\\播放按钮.png";
// String defaultBackgroundPic = "C:\\Users\\LiHao\\Desktop\\封面图\\默认图背景.png";
// String resultPath = "C:\\Users\\LiHao\\Desktop\\封面图\\result.jpg";
// Boolean isDefalut = false;
// try {
// //取书封面和播放按钮图
// BufferedImage bookPicImage;
// BufferedImage playPicImage;
// BufferedImage defaultBackgroudImage;
// if(bookPic.contains("https:")){
// bookPicImage = ImageIO.read(new URL(bookPic));
// playPicImage = ImageIO.read(new URL(playPic));
// defaultBackgroudImage = ImageIO.read(new URL(defaultBackgroundPic));
// }else{
// bookPicImage = ImageIO.read(new File(bookPic));
// playPicImage = ImageIO.read(new File(playPic));
// defaultBackgroudImage = ImageIO.read(new File(defaultBackgroundPic));
// }
//
// //画一个空的背景
// BufferedImage bg = new BufferedImage(702, 299, BufferedImage.TYPE_3BYTE_BGR);
// Graphics2D g = bg.createGraphics();
// //获取主题色
// Color c = getImagePixel(bookPic);
//
//
// //画纯色的背景或者默认背景图
// g.setColor(c);
// if(isDefalut){
// g.drawImage(defaultBackgroudImage.getScaledInstance(702,196, Image.SCALE_DEFAULT), 0, 0, null);
// }else {
// g.fillRect(0, 0, 702, 196);
// }
// g.setColor(new Color(252, 252, 252));
// g.fillRect(0, 196, 702, 102);
//
// g.setColor(new Color(221, 221, 221));
// //插入书籍图和播放按钮
// g.drawImage(bookPicImage.getScaledInstance(172,238, Image.SCALE_DEFAULT), 265, 30, null);
// g.drawImage(playPicImage.getScaledInstance(80,80, Image.SCALE_DEFAULT), 306, 105, null);
// g.drawRect(265,30,172,238);
//
// for(int i=0;i<3;i++){
//
// }
//
// //保存图片
// if(bookPic.contains("https:")) {
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// ImageIO.write(bg, ImageTypeEnum.JPG.value, os);
// UploadResultInfo uploadResultInfo = OssUtils.uploadFileByte(os.toByteArray(), UUIDUitl.taskName(), ImageTypeEnum.JPG.value);
// os.close();
// s = uploadResultInfo == null ? null : uploadResultInfo.getUrl();
// }else{
// OutputStream os = new FileOutputStream(resultPath);
// ImageIO.write(bg, ImageTypeEnum.JPG.value, os);
// os.close();
// }
// System.out.println(s);
// } catch (Exception e) {
// System.out.println(e.getMessage());
// }
}
}
package
com
.
pcloud
.
common
.
utils
;
/**
* Created by ${user} on ${date}
*/
import
com.alibaba.fastjson.JSON
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageTypeEnum
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.httpclient.SimpleHttpUtils
;
import
com.pcloud.common.utils.json.JSONUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.io.*
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author TianChao
* @date 2018/10/13 15:02
*/
public
class
PictureUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
PictureUtil
.
class
);
private
static
Color
defaultColor
=
new
Color
(
252
,
252
,
252
);
private
static
Color
borderColor
=
new
Color
(
221
,
221
,
221
);
private
static
String
playPic
=
"https://file.5rs.me/oss/uploadfe/png/3c687bffac4d885ecfff8517d6c3f9c2.png"
;
private
static
String
defaultBackgroundPic
=
"https://oss.5rs.me/oss/uploadfe/png/3003b8978e85052f96ababdf7d46f70a.png"
;
public
static
Color
getImagePixel
(
BufferedImage
bi
)
{
if
(
bi
.
getWidth
()*
bi
.
getHeight
()>
500000
)
{
BufferedImage
pic1
=
new
BufferedImage
(
157
,
224
,
BufferedImage
.
SCALE_SMOOTH
);
Graphics
graphics
=
pic1
.
getGraphics
();
graphics
.
drawImage
(
bi
.
getScaledInstance
(
157
,
224
,
Image
.
SCALE_SMOOTH
),
0
,
0
,
null
);
graphics
.
dispose
();
bi
=
pic1
;
}
int
width
=
bi
.
getWidth
();
int
height
=
bi
.
getHeight
();
int
sum
=
width
*
height
;
int
minx
=
bi
.
getMinX
();
int
miny
=
bi
.
getMinY
();
int
R
=
0
;
int
G
=
0
;
int
B
=
0
;
List
<
String
>
list
=
new
ArrayList
<>();
for
(
int
i
=
minx
;
i
<
width
;
i
++)
{
for
(
int
j
=
miny
;
j
<
height
;
j
++)
{
int
pixel
=
bi
.
getRGB
(
i
,
j
);
if
(
pixel
==
Color
.
white
.
getRGB
()
||
pixel
==
Color
.
black
.
getRGB
()){
continue
;
}
R
=(
pixel
&
0xff0000
)
>>
16
;
G
=(
pixel
&
0xff00
)
>>
8
;
B
=(
pixel
&
0xff
);
if
((
R
>
230
&&
G
>
230
&&
B
>
230
)
||(
R
<
30
&&
G
<
30
&&
B
<
30
)){
continue
;
}
list
.
add
(
R
+
"-"
+
G
+
"-"
+
B
);
}
}
return
getMaxCount
(
list
);
}
public
static
Color
getMaxCount
(
List
<
String
>
s
)
{
List
<
String
>
list
=
s
;
Map
<
String
,
Integer
>
map
=
new
HashMap
<
String
,
Integer
>();
for
(
String
c
:
list
)
{
Integer
l
=
map
.
get
(
c
);
if
(
l
==
null
)
l
=
1
;
else
l
++;
map
.
put
(
c
,
l
);
}
String
max
=
null
;
long
num
=
0
;
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
String
key
=
entry
.
getKey
();
Integer
temp
=
entry
.
getValue
();
if
(
max
==
null
||
temp
>
num
)
{
max
=
key
;
num
=
temp
;
}
}
String
str
[]
=
max
.
split
(
"\\-"
);
if
(
str
.
length
==
3
)
{
return
new
Color
(
Integer
.
parseInt
(
str
[
0
]),
Integer
.
parseInt
(
str
[
1
]),
Integer
.
parseInt
(
str
[
2
]));
}
return
Color
.
gray
;
}
public
static
String
getB16
(
int
R
,
int
G
,
int
B
){
String
[]
h
=
new
String
[
256
];
h
[
0
]=
"00"
;
h
[
1
]=
"01"
;
h
[
2
]=
"02"
;
h
[
3
]=
"03"
;
h
[
4
]=
"04"
;
h
[
5
]=
"05"
;
h
[
6
]=
"06"
;
h
[
7
]=
"07"
;
h
[
8
]=
"08"
;
h
[
9
]=
"09"
;
h
[
10
]=
"0A"
;
h
[
11
]=
"0B"
;
h
[
12
]=
"0C"
;
h
[
13
]=
"0D"
;
h
[
14
]=
"0E"
;
h
[
15
]=
"0F"
;
h
[
16
]=
"10"
;
h
[
17
]=
"11"
;
h
[
18
]=
"12"
;
h
[
19
]=
"13"
;
h
[
20
]=
"14"
;
h
[
21
]=
"15"
;
h
[
22
]=
"16"
;
h
[
23
]=
"17"
;
h
[
24
]=
"18"
;
h
[
25
]=
"19"
;
h
[
26
]=
"1A"
;
h
[
27
]=
"1B"
;
h
[
28
]=
"1C"
;
h
[
29
]=
"1D"
;
h
[
30
]=
"1E"
;
h
[
31
]=
"1F"
;
h
[
32
]=
"20"
;
h
[
33
]=
"21"
;
h
[
34
]=
"22"
;
h
[
35
]=
"23"
;
h
[
36
]=
"24"
;
h
[
37
]=
"25"
;
h
[
38
]=
"26"
;
h
[
39
]=
"27"
;
h
[
40
]=
"28"
;
h
[
41
]=
"29"
;
h
[
42
]=
"2A"
;
h
[
43
]=
"2B"
;
h
[
44
]=
"2C"
;
h
[
45
]=
"2D"
;
h
[
46
]=
"2E"
;
h
[
47
]=
"2F"
;
h
[
48
]=
"30"
;
h
[
49
]=
"31"
;
h
[
50
]=
"32"
;
h
[
51
]=
"33"
;
h
[
52
]=
"34"
;
h
[
53
]=
"35"
;
h
[
54
]=
"36"
;
h
[
55
]=
"37"
;
h
[
56
]=
"38"
;
h
[
57
]=
"39"
;
h
[
58
]=
"3A"
;
h
[
59
]=
"3B"
;
h
[
60
]=
"3C"
;
h
[
61
]=
"3D"
;
h
[
62
]=
"3E"
;
h
[
63
]=
"3F"
;
h
[
64
]=
"40"
;
h
[
65
]=
"41"
;
h
[
66
]=
"42"
;
h
[
67
]=
"43"
;
h
[
68
]=
"44"
;
h
[
69
]=
"45"
;
h
[
70
]=
"46"
;
h
[
71
]=
"47"
;
h
[
72
]=
"48"
;
h
[
73
]=
"49"
;
h
[
74
]=
"4A"
;
h
[
75
]=
"4B"
;
h
[
76
]=
"4C"
;
h
[
77
]=
"4D"
;
h
[
78
]=
"4E"
;
h
[
79
]=
"4F"
;
h
[
80
]=
"50"
;
h
[
81
]=
"51"
;
h
[
82
]=
"52"
;
h
[
83
]=
"53"
;
h
[
84
]=
"54"
;
h
[
85
]=
"55"
;
h
[
86
]=
"56"
;
h
[
87
]=
"57"
;
h
[
88
]=
"58"
;
h
[
89
]=
"59"
;
h
[
90
]=
"5A"
;
h
[
91
]=
"5B"
;
h
[
92
]=
"5C"
;
h
[
93
]=
"5D"
;
h
[
94
]=
"5E"
;
h
[
95
]=
"6F"
;
h
[
96
]=
"60"
;
h
[
97
]=
"61"
;
h
[
98
]=
"62"
;
h
[
99
]=
"63"
;
h
[
100
]=
"64"
;
h
[
101
]=
"65"
;
h
[
102
]=
"66"
;
h
[
103
]=
"67"
;
h
[
104
]=
"68"
;
h
[
105
]=
"69"
;
h
[
106
]=
"6A"
;
h
[
107
]=
"6B"
;
h
[
108
]=
"6C"
;
h
[
109
]=
"6D"
;
h
[
110
]=
"6E"
;
h
[
111
]=
"6F"
;
h
[
112
]=
"70"
;
h
[
113
]=
"71"
;
h
[
114
]=
"72"
;
h
[
115
]=
"73"
;
h
[
116
]=
"74"
;
h
[
117
]=
"75"
;
h
[
118
]=
"76"
;
h
[
119
]=
"77"
;
h
[
120
]=
"78"
;
h
[
121
]=
"79"
;
h
[
122
]=
"7A"
;
h
[
123
]=
"7B"
;
h
[
124
]=
"7C"
;
h
[
125
]=
"7D"
;
h
[
126
]=
"7E"
;
h
[
127
]=
"7F"
;
h
[
128
]=
"80"
;
h
[
129
]=
"81"
;
h
[
130
]=
"82"
;
h
[
131
]=
"83"
;
h
[
132
]=
"84"
;
h
[
133
]=
"85"
;
h
[
134
]=
"86"
;
h
[
135
]=
"87"
;
h
[
136
]=
"88"
;
h
[
137
]=
"89"
;
h
[
138
]=
"8A"
;
h
[
139
]=
"8B"
;
h
[
140
]=
"8C"
;
h
[
141
]=
"8D"
;
h
[
142
]=
"8E"
;
h
[
143
]=
"8F"
;
h
[
144
]=
"90"
;
h
[
145
]=
"91"
;
h
[
146
]=
"92"
;
h
[
147
]=
"93"
;
h
[
148
]=
"94"
;
h
[
149
]=
"95"
;
h
[
150
]=
"96"
;
h
[
151
]=
"97"
;
h
[
152
]=
"98"
;
h
[
153
]=
"99"
;
h
[
154
]=
"9A"
;
h
[
155
]=
"9B"
;
h
[
156
]=
"9C"
;
h
[
157
]=
"9D"
;
h
[
158
]=
"9E"
;
h
[
159
]=
"9F"
;
h
[
160
]=
"A0"
;
h
[
161
]=
"A1"
;
h
[
162
]=
"A2"
;
h
[
163
]=
"A3"
;
h
[
164
]=
"A4"
;
h
[
165
]=
"A5"
;
h
[
166
]=
"A6"
;
h
[
167
]=
"A7"
;
h
[
168
]=
"A8"
;
h
[
169
]=
"A9"
;
h
[
170
]=
"AA"
;
h
[
171
]=
"AB"
;
h
[
172
]=
"AC"
;
h
[
173
]=
"AD"
;
h
[
174
]=
"AE"
;
h
[
175
]=
"AF"
;
h
[
176
]=
"B0"
;
h
[
177
]=
"B1"
;
h
[
178
]=
"B2"
;
h
[
179
]=
"B3"
;
h
[
180
]=
"B4"
;
h
[
181
]=
"B5"
;
h
[
182
]=
"B6"
;
h
[
183
]=
"B7"
;
h
[
184
]=
"B8"
;
h
[
185
]=
"B9"
;
h
[
186
]=
"BA"
;
h
[
187
]=
"BB"
;
h
[
188
]=
"BC"
;
h
[
189
]=
"BD"
;
h
[
190
]=
"BE"
;
h
[
191
]=
"BF"
;
h
[
192
]=
"C0"
;
h
[
193
]=
"C1"
;
h
[
194
]=
"C2"
;
h
[
195
]=
"C3"
;
h
[
196
]=
"C4"
;
h
[
197
]=
"C5"
;
h
[
198
]=
"C6"
;
h
[
199
]=
"C7"
;
h
[
200
]=
"C8"
;
h
[
201
]=
"C9"
;
h
[
202
]=
"CA"
;
h
[
203
]=
"CB"
;
h
[
204
]=
"CC"
;
h
[
205
]=
"CD"
;
h
[
206
]=
"CE"
;
h
[
207
]=
"CF"
;
h
[
208
]=
"D0"
;
h
[
209
]=
"D1"
;
h
[
210
]=
"D2"
;
h
[
211
]=
"D3"
;
h
[
212
]=
"D4"
;
h
[
213
]=
"D5"
;
h
[
214
]=
"D6"
;
h
[
215
]=
"D7"
;
h
[
216
]=
"D8"
;
h
[
217
]=
"D9"
;
h
[
218
]=
"DA"
;
h
[
219
]=
"DB"
;
h
[
220
]=
"DC"
;
h
[
221
]=
"DD"
;
h
[
222
]=
"DE"
;
h
[
223
]=
"DF"
;
h
[
224
]=
"E0"
;
h
[
225
]=
"E1"
;
h
[
226
]=
"E2"
;
h
[
227
]=
"E3"
;
h
[
228
]=
"E4"
;
h
[
229
]=
"E5"
;
h
[
230
]=
"E6"
;
h
[
231
]=
"E7"
;
h
[
232
]=
"E8"
;
h
[
233
]=
"E9"
;
h
[
234
]=
"EA"
;
h
[
235
]=
"EB"
;
h
[
236
]=
"EC"
;
h
[
237
]=
"ED"
;
h
[
238
]=
"EE"
;
h
[
239
]=
"EF"
;
h
[
240
]=
"F0"
;
h
[
241
]=
"F1"
;
h
[
242
]=
"F2"
;
h
[
243
]=
"F3"
;
h
[
244
]=
"F4"
;
h
[
245
]=
"F5"
;
h
[
246
]=
"F6"
;
h
[
247
]=
"F7"
;
h
[
248
]=
"F8"
;
h
[
249
]=
"F9"
;
h
[
250
]=
"FA"
;
h
[
251
]=
"FB"
;
h
[
252
]=
"FC"
;
h
[
253
]=
"FD"
;
h
[
254
]=
"FE"
;
h
[
255
]=
"FF"
;
return
"#"
+
h
[
R
]
+
h
[
G
]
+
h
[
B
];
}
public
static
Color
getImagePixel
(
String
imgFile
)
{
BufferedImage
bi
=
null
;
Color
imagePixel
;
try
{
if
(
imgFile
.
contains
(
"http"
)){
bi
=
ImageIO
.
read
(
new
URL
(
imgFile
));
}
else
{
bi
=
ImageIO
.
read
(
new
File
(
imgFile
));
}
imagePixel
=
getImagePixel
(
bi
);
}
catch
(
Exception
e
)
{
imagePixel
=
Color
.
gray
;
LOGGER
.
warn
(
"生成图片失败,图片="
+
imgFile
+
","
+
e
.
getMessage
(),
e
);
}
return
imagePixel
;
}
public
static
String
toBrowserHexValue
(
int
number
)
{
StringBuilder
builder
=
new
StringBuilder
(
Integer
.
toHexString
(
number
&
0xff
));
while
(
builder
.
length
()
<
2
)
{
builder
=
new
StringBuilder
(
"0"
).
append
(
builder
);
}
return
builder
.
toString
().
toUpperCase
();
}
public
static
Color
toColorFromString
(
String
colorStr
){
colorStr
=
colorStr
.
substring
(
2
);
Color
color
=
new
Color
(
Integer
.
parseInt
(
colorStr
,
16
))
;
return
color
;
}
private
static
BufferedImage
subPicByWhite
(
BufferedImage
picImage
){
return
picImage
.
getSubimage
(
9
,
9
,
699
,
300
);
}
public
static
String
getQrCover
(
String
bookPic
,
boolean
isDefault
){
String
resultPath
=
""
;
try
{
Color
color
=
null
;
try
{
color
=
getImagePixel
(
bookPic
);
}
catch
(
Exception
e
){
color
=
Color
.
gray
;
}
String
lightIcon
=
"https://oss.5rs.me/oss/uploadfe/png/12dcbc38528d926912c444765d786a9a.png"
;
String
deepIcon
=
"https://oss.5rs.me/oss/uploadfe/png/60612a7415bdac8533568ae0c21a94b6.png"
;
String
icon
;
if
(
color
!=
null
&&
(
color
.
getRed
()<
180
||
color
.
getBlue
()<
180
||
color
.
getGreen
()<
180
)){
icon
=
lightIcon
;
}
else
{
icon
=
deepIcon
;
}
String
html
=
"<div style = \"position: relative;width: 700px;height: 300px;border: 0px solid green;background-color: #fcfcfc;text-align: center;\"> <div style = \"position: absolute;width: 100%;height: 66%;background-color: rgb("
+
color
.
getRed
()+
","
+
color
.
getGreen
()+
","
+
color
.
getBlue
()+
");overflow: hidden;\"> <div style = \"position: absolute;top: 20px;right: -20px;background-image: url('"
+
icon
+
"');background-size: 100%;width: 219px;height: 149px;\"> </div> </div><div style=\"position: relative;display: inline-block;width: 158px;height: 225px;box-shadow: 0px 4px 14px 2px rgba(14, 47, 70, 0.2);border-radius: 4px;border: solid 1px #ddd; margin-top: 35px;background: url('"
+
bookPic
+
"') no-repeat;background-size: cover;background-position: center;\"></div></div>"
;
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
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
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bufferedImage
=
subPicByWhite
(
bookPicImage
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
bufferedImage
,
ImageTypeEnum
.
JPG
.
value
,
os
);
UploadResultInfo
uploadResultInfo
=
OssUtils
.
uploadFileByte
(
os
.
toByteArray
(),
UUIDUitl
.
taskName
(),
ImageTypeEnum
.
JPG
.
value
);
os
.
close
();
resultPath
=
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"生成合成图失败,url="
+
bookPic
+
"====="
+
e
.
getMessage
(),
e
);
}
return
resultPath
;
}
public
static
void
main
(
String
[]
args
)
{
// String bookPic = "https://file.5rs.me/oss/upload/image/jpg/c2c7f0b85f9f4eb683cd86a2945bc5e5.jpg";
String
bookPic
=
"https://oss.5rs.me/oss/uploadfe/jpg/e88c2f608fe4365f5c0efd7dda0eb59e.jpg"
;
Color
color
;
if
(
bookPic
.
contains
(
"/oss/"
)){
String
s
=
SimpleHttpUtils
.
httpGet
(
bookPic
+
"?x-oss-process=image/average-hue"
,
null
);
System
.
out
.
println
(
s
);
Map
map
=
JSONUtils
.
jsonToMap
(
s
,
String
.
class
,
String
.
class
);
String
rgb
=
(
String
)
map
.
get
(
"RGB"
);
color
=
toColorFromString
(
rgb
);
}
else
{
color
=
getImagePixel
(
bookPic
);
}
String
lightIcon
=
"https://oss.5rs.me/oss/uploadfe/png/12dcbc38528d926912c444765d786a9a.png"
;
String
deepIcon
=
"https://oss.5rs.me/oss/uploadfe/png/60612a7415bdac8533568ae0c21a94b6.png"
;
String
icon
;
if
(
color
!=
null
&&
(
color
.
getRed
()<
180
||
color
.
getBlue
()<
180
||
color
.
getGreen
()<
180
)){
icon
=
lightIcon
;
}
else
{
icon
=
deepIcon
;
}
String
html
=
"<div style = \"position: relative;width: 700px;height: 300px;border: 0px solid green;background-color: #fcfcfc;text-align: center;\"> <div style = \"position: absolute;width: 100%;height: 66%;background-color: rgb("
+
color
.
getRed
()+
","
+
color
.
getGreen
()+
","
+
color
.
getBlue
()+
");overflow: hidden;\"> <div style = \"position: absolute;top: 20px;right: -20px;background-image: url('"
+
icon
+
"');background-size: 100%;width: 219px;height: 149px;\"> </div> </div><div style=\"position: relative;display: inline-block;width: 158px;height: 225px;box-shadow: 0px 4px 14px 2px rgba(14, 47, 70, 0.2);border-radius: 4px;border: solid 1px #ddd; margin-top: 35px;background: url('"
+
bookPic
+
"') no-repeat;background-size: cover;background-position: center;\"></div></div>"
;
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
String
postResult
=
HttpKit
.
post
(
"http://192.168.92.111:8214/transcode/htm2img/jpg"
,
JSON
.
toJSONString
(
param
));
// String s = SimpleHttpUtils.httpRequest("http://localhost:8214/transcode/htm2img/jpg", param,"POST","utf-8",header);
Map
map
=
JSONUtils
.
jsonToMap
(
postResult
,
String
.
class
,
String
.
class
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
System
.
out
.
println
(
pic
);
try
{
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bufferedImage
=
subPicByWhite
(
bookPicImage
);
OutputStream
os
=
new
FileOutputStream
(
"C:\\Users\\LiHao\\Desktop\\封面图\\result.jpg"
);
ImageIO
.
write
(
bufferedImage
,
ImageTypeEnum
.
JPG
.
value
,
os
);
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
// String bookPic = "C:\\Users\\LiHao\\Desktop\\封面图\\aa.jpg";
// String playPic = "C:\\Users\\LiHao\\Desktop\\封面图\\播放按钮.png";
// String defaultBackgroundPic = "C:\\Users\\LiHao\\Desktop\\封面图\\默认图背景.png";
// String resultPath = "C:\\Users\\LiHao\\Desktop\\封面图\\result.jpg";
// Boolean isDefalut = false;
// try {
// //取书封面和播放按钮图
// BufferedImage bookPicImage;
// BufferedImage playPicImage;
// BufferedImage defaultBackgroudImage;
// if(bookPic.contains("https:")){
// bookPicImage = ImageIO.read(new URL(bookPic));
// playPicImage = ImageIO.read(new URL(playPic));
// defaultBackgroudImage = ImageIO.read(new URL(defaultBackgroundPic));
// }else{
// bookPicImage = ImageIO.read(new File(bookPic));
// playPicImage = ImageIO.read(new File(playPic));
// defaultBackgroudImage = ImageIO.read(new File(defaultBackgroundPic));
// }
//
// //画一个空的背景
// BufferedImage bg = new BufferedImage(702, 299, BufferedImage.TYPE_3BYTE_BGR);
// Graphics2D g = bg.createGraphics();
// //获取主题色
// Color c = getImagePixel(bookPic);
//
//
// //画纯色的背景或者默认背景图
// g.setColor(c);
// if(isDefalut){
// g.drawImage(defaultBackgroudImage.getScaledInstance(702,196, Image.SCALE_DEFAULT), 0, 0, null);
// }else {
// g.fillRect(0, 0, 702, 196);
// }
// g.setColor(new Color(252, 252, 252));
// g.fillRect(0, 196, 702, 102);
//
// g.setColor(new Color(221, 221, 221));
// //插入书籍图和播放按钮
// g.drawImage(bookPicImage.getScaledInstance(172,238, Image.SCALE_DEFAULT), 265, 30, null);
// g.drawImage(playPicImage.getScaledInstance(80,80, Image.SCALE_DEFAULT), 306, 105, null);
// g.drawRect(265,30,172,238);
//
// for(int i=0;i<3;i++){
//
// }
//
// //保存图片
// if(bookPic.contains("https:")) {
// ByteArrayOutputStream os = new ByteArrayOutputStream();
// ImageIO.write(bg, ImageTypeEnum.JPG.value, os);
// UploadResultInfo uploadResultInfo = OssUtils.uploadFileByte(os.toByteArray(), UUIDUitl.taskName(), ImageTypeEnum.JPG.value);
// os.close();
// s = uploadResultInfo == null ? null : uploadResultInfo.getUrl();
// }else{
// OutputStream os = new FileOutputStream(resultPath);
// ImageIO.write(bg, ImageTypeEnum.JPG.value, os);
// os.close();
// }
// System.out.println(s);
// } catch (Exception e) {
// System.out.println(e.getMessage());
// }
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/ResponseHandleUtil.java
View file @
59cf09ff
...
...
@@ -4,195 +4,209 @@ import java.math.BigDecimal;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.collect.Maps
;
import
com.pcloud.common.config.Application
;
import
com.pcloud.common.dto.ResponseDto
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.mq.dto.ServerLinkDTO
;
import
com.pcloud.common.mq.queue.ServerLinkQueue
;
import
com.pcloud.common.utils.nginx.NginxUtils
;
/**
* Created by zengqiang on 17-12-14.
*/
public
class
ResponseHandleUtil
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ResponseHandleUtil
.
class
);
/**
* 解析一层list包装泛型数据
*
* @param obj
* 需要解析的数据对象
* @param clazz
* list内元素类型
* @param <T>
* @return
*/
public
static
<
T
>
List
<
T
>
getListData
(
Object
obj
,
Class
<
T
>
clazz
)
{
if
(
null
==
obj
)
{
return
null
;
}
return
JSON
.
parseArray
(
JSON
.
toJSONString
(
obj
),
clazz
);
}
public
static
<
K
,
V
>
Map
<
K
,
V
>
getMapData
(
Object
obj
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
if
(
null
==
obj
)
{
return
null
;
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
obj
));
Map
<
K
,
V
>
resultMap
=
Maps
.
newHashMap
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
resultMap
.
put
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
),
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getValue
()),
clazzV
));
}
return
resultMap
;
}
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ResponseHandleUtil
.
class
);
/**
* 解析一层list包装泛型数据
*
* @param obj 需要解析的数据对象
* @param clazz list内元素类型
* @param <T>
* @return
*/
public
static
<
T
>
List
<
T
>
getListData
(
Object
obj
,
Class
<
T
>
clazz
)
{
if
(
null
==
obj
)
{
return
null
;
}
return
JSON
.
parseArray
(
JSON
.
toJSONString
(
obj
),
clazz
);
}
/**
* @param obj
* @param clazzK
* @param clazzV
* @param <K>
* @param <V>
* @return
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
getMapData
(
Object
obj
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
if
(
null
==
obj
)
{
return
null
;
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
obj
));
Map
<
K
,
V
>
resultMap
=
Maps
.
newHashMap
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
resultMap
.
put
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
),
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getValue
()),
clazzV
));
}
return
resultMap
;
}
/**
* 解析map的value是list的泛型数据
*
* @param obj 需要解析的数据对象
* @param clazzK key元素类型
* @param clazzT value中list元素类型
* @return
*/
public
static
<
K
,
T
>
Map
<
K
,
List
<
T
>>
getMapListData
(
Object
obj
,
Class
<
K
>
clazzK
,
Class
<
T
>
clazzT
)
{
if
(
null
==
obj
)
{
return
null
;
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
obj
));
Map
<
K
,
List
<
T
>>
resultMap
=
Maps
.
newHashMap
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
resultMap
.
put
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
),
public
static
<
K
,
T
>
Map
<
K
,
List
<
T
>>
getMapListData
(
Object
obj
,
Class
<
K
>
clazzK
,
Class
<
T
>
clazzT
)
{
if
(
null
==
obj
)
{
return
null
;
}
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
obj
));
Map
<
K
,
List
<
T
>>
resultMap
=
Maps
.
newHashMap
();
for
(
Map
.
Entry
<
String
,
Object
>
entry
:
jsonObject
.
entrySet
())
{
resultMap
.
put
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
),
JSON
.
parseArray
(
JSON
.
toJSONString
(
entry
.
getValue
()),
clazzT
));
}
return
resultMap
;
}
public
static
<
T
>
T
parseResponse
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
Object
obj
=
parseResponse
(
entity
);
if
(
null
==
obj
)
{
return
null
;
}
if
(
clazz
.
equals
(
Long
.
class
))
{
if
(
obj
instanceof
Long
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
longValue
())
;
}
}
else
if
(
clazz
.
equals
(
Integer
.
class
))
{
if
(
obj
instanceof
Integer
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
int
Value
());
}
}
else
if
(
clazz
.
equals
(
Double
.
class
))
{
if
(
obj
instanceof
Double
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
double
Value
());
}
}
else
if
(
clazz
.
equals
(
Float
.
class
))
{
if
(
obj
instanceof
Float
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
float
Value
());
}
}
else
if
(
clazz
.
equals
(
BigDecimal
.
class
))
{
if
(
obj
instanceof
BigDecimal
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(
BigDecimal
.
valueOf
(((
Number
)
obj
).
doubleValue
()
));
}
}
try
{
return
clazz
.
cast
(
obj
);
}
catch
(
ClassCastException
e
)
{
return
JSON
.
parseObject
(
JSON
.
toJSONString
(
obj
),
clazz
);
}
}
/**
* List数据解析
*
* @param entity
* @param clazz
* @param <T>
* List元素类型
* @return
*/
public
static
<
T
>
List
<
T
>
parseListResponse
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
List
list
=
parseResponse
(
entity
,
List
.
class
);
if
(
null
==
list
)
{
return
list
;
}
return
JSON
.
parseArray
(
JSON
.
toJSONString
(
list
),
clazz
);
}
/**
*
* @param entity
* @param clazzK
* key class类型
* @param clazzV
* value
class类型
* @param <K>
* @param <V
>
* @return
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
parseMapResponse
(
ResponseEntity
<?>
entity
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
Map
map
=
parseResponse
(
entity
,
Map
.
class
);
if
(
null
==
map
)
{
return
map
;
}
Map
<
K
,
V
>
result
=
new
HashMap
<>();
for
(
Object
o
:
map
.
entrySet
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
o
;
K
k
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
);
V
v
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getValue
()),
clazzV
);
result
.
put
(
k
,
v
);
}
return
result
;
}
/**
* list转换
*
* @param entity
* @param clazz
* @return
*/
public
static
<
T
>
List
<
T
>
parseList
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
Object
object
=
parseResponse
(
entity
);
if
(
object
==
null
)
{
return
null
;
}
return
JSONArray
.
parseArray
(
JSON
.
toJSONString
(
object
),
clazz
);
}
/**
* Map转换
*
* @param entity
* @param clazzK
* @param clazzV
* @return
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
parseMap
(
ResponseEntity
<?>
entity
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
Object
object
=
parseResponse
(
entity
,
Map
.
class
);
if
(
object
==
null
)
{
return
null
;
}
return
getMapData
(
object
,
clazzK
,
clazzV
);
}
}
return
resultMap
;
}
/**
* @param entity
* @param clazz
* @param <T>
* @return
*/
public
static
<
T
>
T
parseResponse
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
Object
obj
=
parseResponse
(
entity
);
if
(
null
==
obj
)
{
return
null
;
}
if
(
clazz
.
equals
(
Long
.
class
))
{
if
(
obj
instanceof
Long
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
long
Value
());
}
}
else
if
(
clazz
.
equals
(
Integer
.
class
))
{
if
(
obj
instanceof
Integer
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
int
Value
());
}
}
else
if
(
clazz
.
equals
(
Double
.
class
))
{
if
(
obj
instanceof
Double
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
double
Value
());
}
}
else
if
(
clazz
.
equals
(
Float
.
class
))
{
if
(
obj
instanceof
Float
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(((
Number
)
obj
).
floatValue
(
));
}
}
else
if
(
clazz
.
equals
(
BigDecimal
.
class
))
{
if
(
obj
instanceof
BigDecimal
)
{
return
clazz
.
cast
(
obj
);
}
else
if
(
obj
instanceof
Number
)
{
return
clazz
.
cast
(
BigDecimal
.
valueOf
(((
Number
)
obj
).
doubleValue
())
);
}
}
try
{
return
clazz
.
cast
(
obj
);
}
catch
(
ClassCastException
e
)
{
return
JSON
.
parseObject
(
JSON
.
toJSONString
(
obj
),
clazz
);
}
}
/**
* List数据解析
*
* @param entity
* @param clazz
* @param <T> List元素类型
* @return
*/
public
static
<
T
>
List
<
T
>
parseListResponse
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
List
list
=
parseResponse
(
entity
,
List
.
class
);
if
(
null
==
list
)
{
return
list
;
}
return
JSON
.
parseArray
(
JSON
.
toJSONString
(
list
),
clazz
);
}
/**
* @param entity
* @param clazzK key
class类型
* @param clazzV value class类型
* @param <K
>
* @param <V>
* @return
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
parseMapResponse
(
ResponseEntity
<?>
entity
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
Map
map
=
parseResponse
(
entity
,
Map
.
class
);
if
(
null
==
map
)
{
return
map
;
}
Map
<
K
,
V
>
result
=
new
HashMap
<>();
for
(
Object
o
:
map
.
entrySet
())
{
Map
.
Entry
entry
=
(
Map
.
Entry
)
o
;
K
k
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getKey
()),
clazzK
);
V
v
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
entry
.
getValue
()),
clazzV
);
result
.
put
(
k
,
v
);
}
return
result
;
}
/**
* list转换
*
* @param entity
* @param clazz
* @return
*/
public
static
<
T
>
List
<
T
>
parseList
(
ResponseEntity
<?>
entity
,
Class
<
T
>
clazz
)
{
Object
object
=
parseResponse
(
entity
);
if
(
object
==
null
)
{
return
null
;
}
return
JSONArray
.
parseArray
(
JSON
.
toJSONString
(
object
),
clazz
);
}
/**
* Map转换
*
* @param entity
* @param clazzK
* @param clazzV
* @return
*/
public
static
<
K
,
V
>
Map
<
K
,
V
>
parseMap
(
ResponseEntity
<?>
entity
,
Class
<
K
>
clazzK
,
Class
<
V
>
clazzV
)
{
Object
object
=
parseResponse
(
entity
,
Map
.
class
);
if
(
object
==
null
)
{
return
null
;
}
return
getMapData
(
object
,
clazzK
,
clazzV
);
}
/**
* Map List转换
*
* @param entity 需要解析的数据对象
* @param clazzK key元素类型
* @param clazzT value中list元素类型
...
...
@@ -205,43 +219,136 @@ public class ResponseHandleUtil {
}
return
getMapListData
(
object
,
clazzK
,
clazzT
);
}
public
static
Object
parseResponse
(
ResponseEntity
<?>
entity
)
{
if
(
null
==
entity
)
{
LOGGER
.
warn
(
"null response object"
);
return
null
;
}
int
statusCode
=
entity
.
getStatusCodeValue
();
Object
errMsg
=
entity
.
getBody
();
if
(
statusCode
==
500
)
{
LOGGER
.
error
(
"【内部调用异常】异常信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【内部调用异常】异常信息: "
+
errMsg
);
}
else
if
(
statusCode
==
400
)
{
LOGGER
.
warn
(
"【请求异常】异常信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【请求异常】异常信息: "
+
errMsg
);
}
else
if
(
statusCode
!=
200
)
{
LOGGER
.
warn
(
"【请求错误】错误信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【请求错误】错误信息: "
+
errMsg
);
}
ResponseDto
<?>
body
=
(
ResponseDto
<?>)
entity
.
getBody
();
if
(
body
==
null
)
{
LOGGER
.
warn
(
"【请求NULL】ResponseDto==null"
);
return
null
;
}
if
(
body
.
getErrCode
()
!=
0
)
{
LOGGER
.
warn
(
"【业务异常】:"
+
body
.
getErrCode
()
+
", 异常信息: "
+
body
.
getMessage
());
throw
new
BizException
(
body
.
getErrCode
(),
body
.
getMessage
());
}
return
body
.
getData
();
}
public
static
<
T
>
ResponseEntity
<
ResponseDto
<
T
>>
toResponse
(
T
data
)
{
if
(
null
==
data
)
{
LOGGER
.
warn
(
"null data object"
);
return
null
;
}
ResponseDto
<
T
>
body
=
new
ResponseDto
<>(
data
);
return
new
ResponseEntity
<
ResponseDto
<
T
>>(
body
,
HttpStatus
.
OK
);
}
/**
* 内部接口返回值解析
*
* @param entity
* @return
*/
public
static
Object
parseResponse
(
ResponseEntity
<?>
entity
)
{
if
(
null
==
entity
)
{
LOGGER
.
warn
(
"null response object"
);
return
null
;
}
int
statusCode
=
entity
.
getStatusCodeValue
();
Object
errMsg
=
entity
.
getBody
();
if
(
statusCode
==
500
)
{
LOGGER
.
error
(
"【内部调用异常】异常信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【内部调用异常】异常信息: "
+
errMsg
);
}
else
if
(
statusCode
==
400
)
{
LOGGER
.
warn
(
"【请求异常】异常信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【请求异常】异常信息: "
+
errMsg
);
}
else
if
(
statusCode
!=
200
)
{
LOGGER
.
warn
(
"【请求错误】错误信息: "
+
errMsg
);
throw
new
RuntimeException
(
"【请求错误】错误信息: "
+
errMsg
);
}
ResponseDto
<?>
body
=
(
ResponseDto
<?>)
entity
.
getBody
();
if
(
body
==
null
)
{
LOGGER
.
warn
(
"【请求NULL】ResponseDto==null"
);
return
null
;
}
if
(
body
.
getErrCode
()
!=
0
)
{
LOGGER
.
warn
(
"【业务异常】:"
+
body
.
getErrCode
()
+
", 异常信息: "
+
body
.
getMessage
());
throw
new
BizException
(
body
.
getErrCode
(),
body
.
getMessage
());
}
// 获取当前的整个链路的调用类和方法,发送服务调用链queue
try
{
// StackTraceElement[] stackTraceElements = new Exception().getStackTrace();
// ThreadUtil.FIXED_POOL.execute(() -> sendServerLink(body, stackTraceElements));
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"【内部调用】获取调用类和方法失败:"
+
e
.
getMessage
(),
e
);
}
return
body
.
getData
();
}
/**
* 发送服务调用链queue
*
* @param body
*/
private
static
void
sendServerLink
(
ResponseDto
<?>
body
,
StackTraceElement
[]
stackTraceElements
)
{
int
index
=
2
;
// 如果第二级是parseMap或parseList表明是当前类的方法,则索引更新为3
String
methodName
=
stackTraceElements
[
index
].
getMethodName
();
if
(
methodName
.
startsWith
(
"parseMap"
)
||
methodName
.
startsWith
(
"parseList"
))
{
index
=
3
;
}
methodName
=
stackTraceElements
[
index
].
getMethodName
();
// 数据平台和获取微信分享参数的接口过滤不用统计
if
(
"trackEventInfo"
.
equals
(
methodName
)
||
"getJsShareParam"
.
equals
(
methodName
))
{
return
;
}
ServerLinkDTO
serverLinkDTO
=
new
ServerLinkDTO
();
serverLinkDTO
.
setConsumerClassName
(
stackTraceElements
[
index
].
getClassName
());
serverLinkDTO
.
setConsumerMethodName
(
methodName
);
serverLinkDTO
.
setConsumerAppName
(
Application
.
APP_NAME
);
serverLinkDTO
.
setConsumerIp
(
NginxUtils
.
getLocalAddress
());
serverLinkDTO
.
setProduceAppName
(
body
.
getProduceAppName
());
serverLinkDTO
.
setProduceIp
(
body
.
getProduceIp
());
serverLinkDTO
.
setProduceClassName
(
body
.
getProduceClassName
());
serverLinkDTO
.
setProduceMethodName
(
body
.
getProduceMethodName
());
serverLinkDTO
.
setLinks
(
appendLinks
(
stackTraceElements
,
index
));
try
{
ServerLinkQueue
.
send
(
serverLinkDTO
);
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"【内部调用】发送服务调用链QUEUE失败:"
+
e
.
getMessage
(),
e
);
}
}
/**
* 拼接整个调用链路
*
* @param stackTraceElements
* @return
*/
private
static
String
appendLinks
(
StackTraceElement
[]
stackTraceElements
,
int
index
)
{
if
(
stackTraceElements
==
null
||
stackTraceElements
.
length
==
0
)
{
return
null
;
}
int
i
=
0
;
StringBuilder
links
=
new
StringBuilder
();
for
(
StackTraceElement
element
:
stackTraceElements
)
{
// 过滤index以前的数据,index以前的数据都是本类的方法,无需记录
if
(
i
<
index
)
{
i
++;
continue
;
}
String
className
=
element
.
getClassName
();
// 只拼接调用的业务类和方法,JDK的类不拼接
if
(!
className
.
startsWith
(
"com.pcloud"
)
||
className
.
indexOf
(
"$$FastClassBySpringCGLIB$$"
)
>
0
||
className
.
indexOf
(
"$$EnhancerBySpringCGLIB$$"
)
>
0
)
{
continue
;
}
links
.
append
(
className
).
append
(
"."
).
append
(
element
.
getMethodName
()).
append
(
"->"
);
}
return
links
.
toString
();
}
/**
* 内部接口封装返回类型
*
* @param data
* @param <T>
* @return
*/
public
static
<
T
>
ResponseEntity
<
ResponseDto
<
T
>>
toResponse
(
T
data
)
{
if
(
null
==
data
)
{
LOGGER
.
warn
(
"null data object"
);
return
null
;
}
ResponseDto
<
T
>
body
=
new
ResponseDto
<>(
data
);
try
{
// body.setProduceAppName(Application.APP_NAME);
// body.setProduceIp(NginxUtils.getLocalAddress());
// StackTraceElement stackTraceElement = new Exception().getStackTrace()[1];
// body.setProduceClassName(stackTraceElement.getClassName());
// body.setProduceMethodName(stackTraceElement.getMethodName());
}
catch
(
Exception
e
)
{
LOGGER
.
warn
(
"【内部接口】封装返回类型失败:"
+
e
.
getMessage
(),
e
);
}
return
new
ResponseEntity
<>(
body
,
HttpStatus
.
OK
);
}
}
\ No newline at end of file
pcloud-common/src/main/java/com/pcloud/common/utils/SessionUtil.java
View file @
59cf09ff
...
...
@@ -67,14 +67,15 @@ public abstract class SessionUtil {
public
static
final
String
ROLE_CODE
=
"roleCode"
;
/**
*
wechatUserId
*
讲师ID
*/
public
static
final
String
WECHAT_USER_ID
=
"wechatUserId"
;
public
static
final
String
LECTURER_ID
=
"lecturerId"
;
/**
*
讲师
Id
*
wechatUser
Id
*/
public
static
final
String
LECTURER_ID
=
"lectur
erId"
;
public
static
final
String
WECHAT_USER_ID
=
"wechatUs
erId"
;
/**
* wechatUserId
...
...
@@ -82,6 +83,26 @@ public abstract class SessionUtil {
public
static
final
String
THIRD_TYPE
=
"thirdType"
;
/**
* 代理商ID
*/
public
static
final
String
PROMOTER_ID
=
"promoterId"
;
/**
* 代理商名称
*/
public
static
final
String
PROMOTER_NAME
=
"promoterName"
;
/**
* 代理商电话
*/
public
static
final
String
PROMOTER_PHONE
=
"promoterPhone"
;
/**
* 代理商创建时间
*/
public
static
final
String
PROMOTER_CREATE_TIME
=
"promoterCreateTime"
;
/**
* 登录场景
*/
public
static
final
String
MERCHANT_MEMBER_ID
=
"merchantMemberId"
;
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/ThreadUtil.java
View file @
59cf09ff
...
...
@@ -2,6 +2,8 @@ package com.pcloud.common.utils;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* @描述:
...
...
@@ -10,26 +12,31 @@ import java.util.Map;
* @版本:1.0
*/
public
class
ThreadUtil
{
@SuppressWarnings
(
"rawtypes"
)
private
static
final
ThreadLocal
ctx
=
new
ThreadLocal
();
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
static
void
put
(
Object
key
,
Object
value
)
{
Map
m
=
(
Map
)
ctx
.
get
();
if
(
m
==
null
)
{
m
=
new
HashMap
();
}
m
.
put
(
key
,
value
);
ctx
.
set
(
m
);
}
public
static
Object
get
(
Object
key
)
{
@SuppressWarnings
(
"rawtypes"
)
Map
m
=
(
Map
)
ctx
.
get
();
if
(
m
!=
null
)
{
return
m
.
get
(
key
);
}
return
null
;
}
/**
* 固定长度程池
*/
public
static
final
ExecutorService
FIXED_POOL
=
Executors
.
newFixedThreadPool
(
3
);
@SuppressWarnings
(
"rawtypes"
)
private
static
final
ThreadLocal
ctx
=
new
ThreadLocal
();
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
public
static
void
put
(
Object
key
,
Object
value
)
{
Map
m
=
(
Map
)
ctx
.
get
();
if
(
m
==
null
)
{
m
=
new
HashMap
();
}
m
.
put
(
key
,
value
);
ctx
.
set
(
m
);
}
public
static
Object
get
(
Object
key
)
{
@SuppressWarnings
(
"rawtypes"
)
Map
m
=
(
Map
)
ctx
.
get
();
if
(
m
!=
null
)
{
return
m
.
get
(
key
);
}
return
null
;
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/UUIDUitl.java
View file @
59cf09ff
...
...
@@ -6,201 +6,218 @@ import java.util.UUID;
/**
* @描述:生成随机数
* @作者:DiSeng.H
* @创建时间:2016年3月10日,下午1:17:02
* @版本:1.0
* @创建时间:2016年3月10日,下午1:17:02 @版本:1.0
*/
public
class
UUIDUitl
{
public
static
final
String
allCharStr
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+"
;
public
static
final
String
allChar
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
public
static
final
String
letterChar
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
public
static
final
String
numberChar
=
"0123456789"
;
public
static
final
String
specialChar
=
"!@#$%^&*()_+"
;
/**
* 生成的token
*/
public
static
final
String
someCharStr
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&*()_+"
;
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateInteger
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
numberChar
.
charAt
(
random
.
nextInt
(
numberChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
allChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateAllString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allCharStr
.
charAt
(
random
.
nextInt
(
allCharStr
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字),不包含#
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateSomeString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
someCharStr
.
charAt
(
random
.
nextInt
(
someCharStr
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机纯字母字符串(只包含大小写字母)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateMixString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
letterChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机纯大写字母字符串(只包含大小写字母)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateLowerString
(
int
length
)
{
return
generateMixString
(
length
).
toLowerCase
();
}
/**
* 返回一个定长的随机纯小写字母字符串(只包含大小写字母)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateUpperString
(
int
length
)
{
return
generateMixString
(
length
).
toUpperCase
();
}
/**
* 生成一个定长的纯0字符串
*
* @param length
* 字符串长度
* @return 纯0字符串
*/
public
static
String
generateZeroString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
'0'
);
}
return
sb
.
toString
();
}
/**
* 根据数字生成一个定长的字符串,长度不够前面补0
*
* @param num
* 数字
* @param fixdlenth
* 字符串长度
* @return 定长的字符串
*/
public
static
String
toFixdLengthString
(
long
num
,
int
fixdlenth
)
{
StringBuffer
sb
=
new
StringBuffer
();
String
strNum
=
String
.
valueOf
(
num
);
if
(
fixdlenth
-
strNum
.
length
()
>=
0
)
{
sb
.
append
(
generateZeroString
(
fixdlenth
-
strNum
.
length
()));
}
else
{
throw
new
RuntimeException
(
"将数字"
+
num
+
"转化为长度为"
+
fixdlenth
+
"的字符串发生异常!"
);
}
sb
.
append
(
strNum
);
return
sb
.
toString
();
}
/**
* 根据数字生成一个定长的字符串,长度不够前面补0
*
* @param num
* 数字
* @param fixdlenth
* 字符串长度
* @return 定长的字符串
*/
public
static
String
toFixdLengthString
(
int
num
,
int
fixdlenth
)
{
StringBuffer
sb
=
new
StringBuffer
();
String
strNum
=
String
.
valueOf
(
num
);
if
(
fixdlenth
-
strNum
.
length
()
>=
0
)
{
sb
.
append
(
generateZeroString
(
fixdlenth
-
strNum
.
length
()));
}
else
{
throw
new
RuntimeException
(
"将数字"
+
num
+
"转化为长度为"
+
fixdlenth
+
"的字符串发生异常!"
);
}
sb
.
append
(
strNum
);
return
sb
.
toString
();
}
/**
* 八位数字+字母+特殊字符随机密码生成
*
* @return
*/
public
static
String
generatePwdStr
()
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
letterChar
.
length
())));
sb
.
append
(
numberChar
.
charAt
(
random
.
nextInt
(
numberChar
.
length
())));
}
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
sb
.
append
(
specialChar
.
charAt
(
random
.
nextInt
(
specialChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 生成随机任务名称
*
* @return
*/
public
static
String
taskName
()
{
return
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
}
public
static
final
String
allCharStr
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+"
;
public
static
final
String
allChar
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
public
static
final
String
letterChar
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
public
static
final
String
numberChar
=
"0123456789"
;
public
static
final
String
specialChar
=
"!@#$%^&*()_+"
;
/**
* 生成的token
*/
public
static
final
String
someCharStr
=
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@$%^&*()_+"
;
public
static
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"
,
"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"
};
/**
* 生成8位不重复的随机码
*
* @return
*/
public
static
String
generateShort
()
{
StringBuffer
shortBuffer
=
new
StringBuffer
();
String
uuid
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
String
str
=
uuid
.
substring
(
i
*
4
,
i
*
4
+
4
);
int
x
=
Integer
.
parseInt
(
str
,
16
);
shortBuffer
.
append
(
chars
[
x
%
0x3E
]);
}
return
shortBuffer
.
toString
();
}
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
generateShort
());
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateInteger
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
numberChar
.
charAt
(
random
.
nextInt
(
numberChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
allChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateAllString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allCharStr
.
charAt
(
random
.
nextInt
(
allCharStr
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字),不包含#
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateSomeString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
someCharStr
.
charAt
(
random
.
nextInt
(
someCharStr
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机纯字母字符串(只包含大小写字母)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateMixString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
letterChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 返回一个定长的随机纯大写字母字符串(只包含大小写字母)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateLowerString
(
int
length
)
{
return
generateMixString
(
length
).
toLowerCase
();
}
/**
* 返回一个定长的随机纯小写字母字符串(只包含大小写字母)
*
* @param length 随机字符串长度
* @return 随机字符串
*/
public
static
String
generateUpperString
(
int
length
)
{
return
generateMixString
(
length
).
toUpperCase
();
}
/**
* 生成一个定长的纯0字符串
*
* @param length 字符串长度
* @return 纯0字符串
*/
public
static
String
generateZeroString
(
int
length
)
{
StringBuffer
sb
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
sb
.
append
(
'0'
);
}
return
sb
.
toString
();
}
/**
* 根据数字生成一个定长的字符串,长度不够前面补0
*
* @param num 数字
* @param fixdlenth 字符串长度
* @return 定长的字符串
*/
public
static
String
toFixdLengthString
(
long
num
,
int
fixdlenth
)
{
StringBuffer
sb
=
new
StringBuffer
();
String
strNum
=
String
.
valueOf
(
num
);
if
(
fixdlenth
-
strNum
.
length
()
>=
0
)
{
sb
.
append
(
generateZeroString
(
fixdlenth
-
strNum
.
length
()));
}
else
{
throw
new
RuntimeException
(
"将数字"
+
num
+
"转化为长度为"
+
fixdlenth
+
"的字符串发生异常!"
);
}
sb
.
append
(
strNum
);
return
sb
.
toString
();
}
/**
* 根据数字生成一个定长的字符串,长度不够前面补0
*
* @param num 数字
* @param fixdlenth 字符串长度
* @return 定长的字符串
*/
public
static
String
toFixdLengthString
(
int
num
,
int
fixdlenth
)
{
StringBuffer
sb
=
new
StringBuffer
();
String
strNum
=
String
.
valueOf
(
num
);
if
(
fixdlenth
-
strNum
.
length
()
>=
0
)
{
sb
.
append
(
generateZeroString
(
fixdlenth
-
strNum
.
length
()));
}
else
{
throw
new
RuntimeException
(
"将数字"
+
num
+
"转化为长度为"
+
fixdlenth
+
"的字符串发生异常!"
);
}
sb
.
append
(
strNum
);
return
sb
.
toString
();
}
/**
* 八位数字+字母+特殊字符随机密码生成
*
* @return
*/
public
static
String
generatePwdStr
()
{
StringBuffer
sb
=
new
StringBuffer
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
sb
.
append
(
allChar
.
charAt
(
random
.
nextInt
(
letterChar
.
length
())));
sb
.
append
(
numberChar
.
charAt
(
random
.
nextInt
(
numberChar
.
length
())));
}
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
sb
.
append
(
specialChar
.
charAt
(
random
.
nextInt
(
specialChar
.
length
())));
}
return
sb
.
toString
();
}
/**
* 生成随机任务名称
*
* @return
*/
public
static
String
taskName
()
{
return
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/aliyun/OssUtils.java
View file @
59cf09ff
...
...
@@ -40,7 +40,7 @@ import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobRequest;
import
com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse.SnapshotJob
;
import
com.aliyuncs.profile.DefaultProfile
;
import
com.pcloud.common.constant.AliyunConstant
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.FilePathConst
ant
;
import
com.pcloud.common.constant.UrlConstant
;
import
com.pcloud.common.dto.OssImageCropDTO
;
import
com.pcloud.common.dto.OssImageDTO
;
...
...
@@ -1600,7 +1600,7 @@ public class OssUtils {
// 创建OSSClient实例
OSSClient
ossClient
=
getOSSClient
(
bucketName
);
// 生成新的图片地址
String
localPath
=
FilePathConst
.
IMAGE_PATH
+
UUIDUitl
.
generateString
(
32
)
+
"."
+
fileType
;
String
localPath
=
FilePathConst
ant
.
IMAGE
+
UUIDUitl
.
generateString
(
32
)
+
"."
+
fileType
;
FileUtils
.
creatFiles
(
localPath
);
try
{
ossClient
.
getObject
(
request
,
new
File
(
localPath
));
...
...
@@ -1720,7 +1720,7 @@ public class OssUtils {
// 创建OSSClient实例
OSSClient
ossClient
=
getOSSClient
(
bucketName
);
// 生成带水印的本地图片地址
String
localPath
=
FilePathConst
.
IMAGE_WATERMARK_PATH
+
fileName
+
"_"
+
LocalDateUtils
.
getYmdhmss
()
+
"."
String
localPath
=
FilePathConst
ant
.
IMAGE_WATERMARK
+
fileName
+
"_"
+
LocalDateUtils
.
getYmdhmss
()
+
"."
+
fileType
;
FileUtils
.
creatFiles
(
localPath
);
ossClient
.
getObject
(
request
,
new
File
(
localPath
));
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/httpclient/UrlUtils.java
View file @
59cf09ff
...
...
@@ -14,7 +14,6 @@ import org.apache.http.util.EntityUtils;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pcloud.common.utils.rsa.MD5
;
import
com.pcloud.common.utils.string.StringUtil
;
...
...
@@ -25,17 +24,9 @@ import com.pcloud.common.utils.string.StringUtil;
*/
public
class
UrlUtils
{
/**
*
*/
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
UrlUtils
.
class
);
/**
* 请求地址(新郎接口)
*/
private
static
final
String
REQUEST_URL
=
"https://api.weibo.com/2/short_url/shorten.json?source=1681459862&url_long="
;
/**
* 请求地址(OWN)
*/
private
static
final
String
REQUEST_URL2
=
"https://rays.5rs.me/convert/v1.0/url/shorten"
;
...
...
@@ -51,20 +42,13 @@ public class UrlUtils {
public
static
final
String
PRIVATE_KEY
=
"lgsc1205"
;
/**
* 获取短链接
(新浪)
* 获取短链接
*
* @param long_url
* @return
*/
public
static
String
getShortUrl
(
String
long_url
)
{
String
result
=
callHttp
(
REQUEST_URL
+
long_url
);
if
(
StringUtil
.
isEmpty
(
result
))
{
return
null
;
}
JSONObject
resultObject
=
JSONObject
.
parseObject
(
result
);
JSONArray
array
=
resultObject
.
getJSONArray
(
"urls"
);
JSONObject
object
=
array
.
getJSONObject
(
0
);
return
object
.
getString
(
"url_short"
);
return
getShortUrl4Own
(
long_url
);
}
/**
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/pdf/PdfUtils.java
View file @
59cf09ff
...
...
@@ -29,7 +29,7 @@ import com.itextpdf.text.pdf.PdfPTable;
import
com.itextpdf.text.pdf.PdfReader
;
import
com.itextpdf.text.pdf.PdfStamper
;
import
com.itextpdf.text.pdf.PdfWriter
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.FilePathConst
ant
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
...
...
@@ -105,7 +105,7 @@ public class PdfUtils {
*/
private
static
String
pdfConvert
(
byte
[]
b
,
String
fileName
,
String
prefix
,
String
format
)
throws
FileException
{
// 解析PDF文件
String
outPath
=
FilePathConst
.
PDF_PATH
+
fileName
+
"_"
+
UUIDUitl
.
generateString
(
12
);
String
outPath
=
FilePathConst
ant
.
PDF
+
fileName
+
"_"
+
UUIDUitl
.
generateString
(
12
);
File
fi
=
new
File
(
outPath
);
if
(!
fi
.
exists
())
{
fi
.
mkdirs
();
...
...
@@ -161,7 +161,7 @@ public class PdfUtils {
/**
* 创建PDF
*
* @param pdf
ChunkD
Os
* @param pdf
P
Os
* @return
* @throws Exception
*/
...
...
@@ -176,7 +176,7 @@ public class PdfUtils {
OutputStream
os
=
null
;
try
{
// 输出路径
outPath
=
FilePathConst
.
PDF_PATH
+
UUIDUitl
.
taskName
()
+
".pdf"
;
outPath
=
FilePathConst
ant
.
PDF
+
UUIDUitl
.
taskName
()
+
".pdf"
;
FileUtils
.
creatFiles
(
outPath
);
// 创建输出流
os
=
new
FileOutputStream
(
new
File
(
outPath
));
...
...
@@ -358,10 +358,8 @@ public class PdfUtils {
/**
* 加水印(字符串)
*
* @param
inputFile
* @param
filePath
* 需要加水印的PDF路径
* @param outputFile
* 输出生成PDF的路径
* @param waterMarkName
* 水印字符
*/
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/string/StringUtil.java
View file @
59cf09ff
...
...
@@ -590,5 +590,20 @@ public class StringUtil extends StringUtilParent {
}
return
false
;
}
/**
* 过滤HTML标签
*
* @param str
* @return
*/
public
static
String
replaceHtml
(
String
str
)
{
if
(
StringUtil
.
isEmpty
(
str
))
{
return
""
;
}
Pattern
p_html
=
Pattern
.
compile
(
"<[^>]+>"
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
m_html
=
p_html
.
matcher
(
str
);
return
m_html
.
replaceAll
(
""
).
replaceAll
(
" "
,
""
);
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/word/WordNewUtils.java
View file @
59cf09ff
package
com
.
pcloud
.
common
.
utils
.
word
;
import
java.io.ByteArrayInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.math.BigInteger
;
import
java.util.List
;
import
org.apache.poi.POIXMLDocument
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.openxml4j.opc.OPCPackage
;
import
org.apache.poi.util.Units
;
import
org.apache.poi.wp.usermodel.HeaderFooterType
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFFooter
;
import
org.apache.poi.xwpf.usermodel.XWPFHeader
;
import
org.apache.poi.xwpf.usermodel.XWPFParagraph
;
import
org.apache.poi.xwpf.usermodel.XWPFPicture
;
import
org.apache.poi.xwpf.usermodel.XWPFPictureData
;
import
org.apache.poi.xwpf.usermodel.XWPFRun
;
import
org.apache.poi.xwpf.usermodel.XWPFTable
;
import
org.apache.poi.xwpf.usermodel.XWPFTableCell
;
import
org.apache.poi.xwpf.usermodel.XWPFTableRow
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.WordConstant
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
import
com.pcloud.common.utils.FileUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.UUIDUitl
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.word.dto.ParagraphDTO
;
import
com.pcloud.common.utils.word.dto.RunDTO
;
import
com.pcloud.common.utils.word.dto.RunImageDTO
;
import
com.pcloud.common.utils.word.dto.RunTableDTO
;
import
com.pcloud.common.utils.word.dto.RunTextDTO
;
import
com.pcloud.common.utils.word.dto.WordDTO
;
import
com.pcloud.common.utils.word.enums.ParagraphType
;
/**
* 重新定义word工具类
*
* @author:songx
* @date:2019/5/27,10:06
*/
public
class
WordNewUtils
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
WordNewUtils
.
class
);
// public static void main(String[] args) {
// List<ParagraphDTO> paragraphDTOS = new ArrayList<>();
// // 页眉
// paragraphDTOS.add(getHeader1());
// paragraphDTOS.add(getHeader2());
// // 标题
// paragraphDTOS.add(getParagraph1());
// // 内容
// paragraphDTOS.add(getParagraph2());
// paragraphDTOS.add(getParagraph3());
// paragraphDTOS.add(getParagraph4());
// paragraphDTOS.add(getParagraph4());
// // 页脚
// paragraphDTOS.add(getFooter1());
// try {
// System.out.println(create(paragraphDTOS));
// } catch (Exception e) {
// LOGGER.error(e.getMessage(), e);
// }
// System.out.println("Game over!");
// }
//
// private static ParagraphDTO getHeader1() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("?????的个人专属错题本 共40道错题", 9, "微软雅黑");
// return ParagraphDTO.newHeader(ParagraphType.text, runTextDTO);
// }
//
// private static ParagraphDTO getHeader2() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("来源《书名书名书名书名书名书名书名书书名书名书名书书名书名书名书》", 9, "微软雅黑");
// return ParagraphDTO.newHeader(ParagraphType.text, runTextDTO);
// }
//
// private static ParagraphDTO getParagraph1() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("个人专属错题本", 18, "微软雅黑", true);
// return ParagraphDTO.newParagraph(ParagraphType.text, ParagraphAlignment.CENTER, runTextDTO, 1);
// }
//
// private static ParagraphDTO getParagraph2() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("完成下面错题练习,扫描二维码核对答案,并记录练习结果:", 11, "微软雅黑", true);
// return ParagraphDTO.newParagraph(ParagraphType.text, runTextDTO, 1);
// }
//
// private static ParagraphDTO getParagraph3() {
// RunImageDTO runImageDTO = RunImageDTO
// .newImage("I:\\TEST\\image\\02.jpg", 80, 80, null, listAfterTexts3(11, "微软雅黑"));
// return ParagraphDTO.newParagraph(ParagraphType.image, TextAlignment.TOP, runImageDTO, 1);
// }
//
// private static ParagraphDTO getParagraph4() {
// RunImageDTO runImageDTO = RunImageDTO
// .newImage("I:\\TEST\\image\\2.jpg", 200, 500);
// return ParagraphDTO.newParagraph(ParagraphType.image, runImageDTO, 3);
// }
//
// private static ParagraphDTO getFooter1() {
// RunTextDTO runTextDTO = RunTextDTO.newText("反复练习,攻克错题", 11, "微软雅黑");
// return ParagraphDTO.newFooter(ParagraphType.text, ParagraphAlignment.CENTER, runTextDTO);
// }
//
// /**
// * 组装图片后面的文字
// *
// * @param fontSize
// * @param fontFamily
// * @return
// */
// private static List<RunTextDTO> listAfterTexts3(int fontSize, String fontFamily) {
// List<RunTextDTO> afterRuns = Lists.newArrayList();
// afterRuns.add(RunTextDTO.newText(" 答对", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" 10 ", fontSize, fontFamily, UnderlinePatterns.SINGLE));
// afterRuns.add(RunTextDTO.newText("道题,答错", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" 11 ", fontSize, fontFamily, UnderlinePatterns.SINGLE));
// afterRuns.add(RunTextDTO.newText("道题,日期", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" " + LocalDateUtils.getDateNow() + " ", fontSize, fontFamily,
// UnderlinePatterns.SINGLE));
// return afterRuns;
// }
/**
* 创建WORD
*
* @param wordDTO
* @return
* @throws Exception
*/
public
static
String
create
(
WordDTO
wordDTO
)
throws
FileException
{
LOGGER
.
info
(
"【WORD】创建WORD文档,<START>"
);
if
(
wordDTO
==
null
||
ListUtils
.
isEmpty
(
wordDTO
.
getParagraphs
()))
{
return
null
;
}
String
wordTemplate
=
null
;
String
outPath
=
null
;
CustomXWPFDocument
document
=
null
;
FileOutputStream
fos
=
null
;
try
{
wordTemplate
=
FilePathConst
.
WORD_PATH
+
UUIDUitl
.
taskName
()
+
".docx"
;
FileUtils
.
downloadFileFromUrl
(
WordConstant
.
TEMPLATE_URL
,
wordTemplate
);
OPCPackage
pack
=
POIXMLDocument
.
openPackage
(
wordTemplate
);
document
=
new
CustomXWPFDocument
(
pack
);
// 添加内容到文档中
addParagraphs
(
wordDTO
,
document
);
// 生成目标word
outPath
=
FilePathConst
.
WORD_PATH
+
UUIDUitl
.
taskName
()
+
".docx"
;
fos
=
new
FileOutputStream
(
outPath
);
document
.
write
(
fos
);
fos
.
flush
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】创建WORD文档失败:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_CONTENT_ERROR
,
e
.
getMessage
());
}
finally
{
close
(
document
,
fos
);
FileUtils
.
deleteFile
(
wordTemplate
);
}
LOGGER
.
info
(
"【WORD】创建WORD文档,<END>.[outPath]="
+
outPath
);
return
outPath
;
}
/**
* 添加内容到WORD中
*
* @param wordDTO
* @param document
* @throws BizException
*/
private
static
void
addParagraphs
(
WordDTO
wordDTO
,
CustomXWPFDocument
document
)
{
List
<
ParagraphDTO
>
paragraphDTOS
=
wordDTO
.
getParagraphs
();
for
(
ParagraphDTO
paragraphDTO
:
paragraphDTOS
)
{
ParagraphType
paragraphType
=
paragraphDTO
.
getParagraphType
();
if
(
ParagraphType
.
table
.
equals
(
paragraphType
))
{
addTable
(
paragraphDTO
,
document
);
}
else
if
(
ParagraphType
.
image
.
equals
(
paragraphType
))
{
addImage
(
wordDTO
,
paragraphDTO
,
document
);
}
else
if
(
ParagraphType
.
text
.
equals
(
paragraphType
))
{
addText
(
wordDTO
,
paragraphDTO
,
document
);
}
}
}
/**
* 获取段落
*
* @param paragraphDTO
* @param document
* @return
*/
private
static
XWPFParagraph
getParagraph
(
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
{
if
(
paragraphDTO
.
isHeader
())
{
XWPFHeader
xwpfHeader
=
document
.
createHeader
(
HeaderFooterType
.
DEFAULT
);
return
xwpfHeader
.
createParagraph
();
}
else
if
(
paragraphDTO
.
isFooter
())
{
XWPFFooter
xwpfFooter
=
document
.
createFooter
(
HeaderFooterType
.
DEFAULT
);
return
xwpfFooter
.
createParagraph
();
}
else
{
return
document
.
createParagraph
();
}
}
/**
* 添加文本块
*
* @param wordDTO
* @param paragraphDTO
* @throws BizException
*/
private
static
void
addText
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
throws
BizException
{
XWPFParagraph
paragraph
=
getParagraph
(
paragraphDTO
,
document
);
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 设置段落块样式
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
setTextStyle
(
wordDTO
,
(
RunTextDTO
)
paragraphDTO
.
getRun
(),
paragraph
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
setTextStyle
(
wordDTO
,
(
RunTextDTO
)
runDTO
,
paragraph
);
}
}
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 添加空行
*
* @param afterEmpty
* @param document
* @throws BizException
*/
private
static
void
addEmptyText
(
int
afterEmpty
,
CustomXWPFDocument
document
)
throws
BizException
{
for
(
int
i
=
0
;
i
<
afterEmpty
;
i
++)
{
setTextStyle
(
null
,
RunTextDTO
.
newEmpty
(),
document
.
createParagraph
());
}
}
/**
* 设置段落样式
*
* @param paragraphDTO
* @param paragraph
*/
private
static
void
setParagraphStyle
(
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
)
{
// 与前一行的间距
if
(
paragraphDTO
.
getSpacingBefore
()
>
0
)
{
paragraph
.
setSpacingBeforeLines
(
paragraphDTO
.
getSpacingBefore
());
}
// 与下一行的间距
if
(
paragraphDTO
.
getSpacingAfter
()
>
0
)
{
paragraph
.
setSpacingAfterLines
(
paragraphDTO
.
getSpacingAfter
());
}
// 对齐
if
(
paragraphDTO
.
getParagraphAlignment
()
!=
null
)
{
paragraph
.
setFontAlignment
(
paragraphDTO
.
getParagraphAlignment
().
getValue
());
}
// 水平居中
if
(
paragraphDTO
.
getTextAlignment
()
!=
null
)
{
paragraph
.
setVerticalAlignment
(
paragraphDTO
.
getTextAlignment
());
}
}
/**
* 设置文本样式
*
* @param wordDTO
* @param runTextDTO
* @param paragraph
*/
private
static
void
setTextStyle
(
WordDTO
wordDTO
,
RunTextDTO
runTextDTO
,
XWPFParagraph
paragraph
)
{
XWPFRun
xwpfRun
=
paragraph
.
createRun
();
xwpfRun
.
setText
(
runTextDTO
.
getText
());
// 是否加粗
xwpfRun
.
setBold
(
runTextDTO
.
isBold
());
// 字体大小
if
(
runTextDTO
.
getFontSize
()
>
0
)
{
xwpfRun
.
setFontSize
(
runTextDTO
.
getFontSize
());
}
else
if
(
wordDTO
!=
null
&&
wordDTO
.
getFontSize
()
>
0
)
{
xwpfRun
.
setFontSize
(
wordDTO
.
getFontSize
());
}
// 字体
if
(
runTextDTO
.
getFontFamily
()
!=
null
)
{
xwpfRun
.
setFontFamily
(
runTextDTO
.
getFontFamily
());
}
else
if
(
wordDTO
!=
null
&&
wordDTO
.
getFontFamily
()
!=
null
)
{
xwpfRun
.
setFontFamily
(
wordDTO
.
getFontFamily
());
}
// 下划线
if
(
runTextDTO
.
getUnderlinePatterns
()
!=
null
)
{
xwpfRun
.
setUnderline
(
runTextDTO
.
getUnderlinePatterns
());
}
}
/**
* 添加表格
*
* @param paragraphDTO
* @throws BizException
*/
private
static
void
addTable
(
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
throws
BizException
{
XWPFParagraph
paragraph
=
document
.
createParagraph
();
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 创建表格
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createTable
((
RunTableDTO
)
paragraphDTO
.
getRun
(),
document
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createTable
((
RunTableDTO
)
runDTO
,
document
);
}
}
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 创建表格
*
* @param runTableDTO
* @param document
*/
private
static
void
createTable
(
RunTableDTO
runTableDTO
,
CustomXWPFDocument
document
)
{
String
[][]
contents
=
runTableDTO
.
getContents
();
if
(
contents
==
null
||
contents
.
length
<
1
)
{
return
;
}
int
rowNum
=
contents
.
length
;
// 总行数
int
colNum
=
runTableDTO
.
getColumnWidths
().
length
;
// 总列数
if
(
colNum
<
1
)
{
throw
new
FileException
(
FileException
.
FILE_CONTENT_ERROR
,
"表格列数与内容列数不一致"
);
}
// 创建表格
XWPFTable
ComTable
=
document
.
createTable
();
// 列宽自动分割
CTTblWidth
comTableWidth
=
ComTable
.
getCTTbl
().
addNewTblPr
().
addNewTblW
();
comTableWidth
.
setType
(
STTblWidth
.
DXA
);
comTableWidth
.
setW
(
BigInteger
.
valueOf
(
9072
));
// 设置行和列
for
(
int
i
=
0
;
i
<
rowNum
;
i
++)
{
String
[]
cols
=
contents
[
i
];
// 创建行
XWPFTableRow
comTableRow
=
i
==
0
?
ComTable
.
getRow
(
0
)
:
ComTable
.
createRow
();
for
(
int
j
=
0
;
j
<
colNum
;
j
++)
{
String
text
=
(
j
>=
cols
.
length
||
StringUtil
.
isEmpty
(
cols
[
j
]))
?
""
:
cols
[
j
];
// 填充单元格内容
XWPFTableCell
cell
=
null
;
if
(
i
==
0
)
{
cell
=
j
==
0
?
comTableRow
.
getCell
(
0
)
:
comTableRow
.
addNewTableCell
();
}
else
{
cell
=
comTableRow
.
getCell
(
j
);
}
cell
.
setText
(
text
);
cell
.
setVerticalAlignment
(
runTableDTO
.
getVertAlign
());
}
// 行高
if
(
runTableDTO
.
getHeight
()
>
0
)
{
comTableRow
.
setHeight
(
runTableDTO
.
getHeight
());
}
}
}
/**
* 添加图片和文本
*
* @param paragraphDTO
* @param document
*/
private
static
void
addImage
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
{
XWPFParagraph
paragraph
=
null
;
if
(
paragraphDTO
.
isHeader
())
{
XWPFHeader
header
=
document
.
createHeader
(
HeaderFooterType
.
DEFAULT
);
paragraph
=
header
.
createParagraph
();
addImageHeader
(
wordDTO
,
paragraphDTO
,
paragraph
,
header
);
}
else
{
paragraph
=
document
.
createParagraph
();
addImageContent
(
wordDTO
,
paragraphDTO
,
paragraph
,
document
);
}
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 页眉中插入图片
*
* @param wordDTO
* @param paragraphDTO
* @param paragraph
* @param header
*/
private
static
void
addImageHeader
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
// 创建图片
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createImageHeader
(
wordDTO
,
(
RunImageDTO
)
paragraphDTO
.
getRun
(),
paragraph
,
header
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createImageHeader
(
wordDTO
,
(
RunImageDTO
)
runDTO
,
paragraph
,
header
);
}
}
}
/**
* 内容中插入图片
*
* @param wordDTO
* @param paragraphDTO
* @param paragraph
* @param document
*/
private
static
void
addImageContent
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
,
CustomXWPFDocument
document
)
{
// 创建图片
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createImageContent
(
wordDTO
,
(
RunImageDTO
)
paragraphDTO
.
getRun
(),
paragraph
,
document
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createImageContent
(
wordDTO
,
(
RunImageDTO
)
runDTO
,
paragraph
,
document
);
}
}
}
/**
* 创建图片和文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
* @param document
*/
private
static
void
createImageContent
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
CustomXWPFDocument
document
)
{
// 前置文本
addImageBefore
(
wordDTO
,
runImageDTO
,
paragraph
);
try
{
// 图片
String
relationId
=
addPictureContent
(
runImageDTO
,
document
);
if
(!
StringUtil
.
isEmpty
(
relationId
))
{
int
id
=
document
.
getAllPictures
().
size
()
-
1
;
document
.
createPicture
(
paragraph
,
relationId
,
id
,
runImageDTO
.
getWidth
(),
runImageDTO
.
getHeight
());
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】创建WORD文档失败:"
+
e
.
getMessage
(),
e
);
}
// 后置文本
addImageAfter
(
wordDTO
,
runImageDTO
,
paragraph
);
}
/**
* 创建图片
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
* @param header
*/
private
static
void
createImageHeader
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
// 前置文本
addImageBefore
(
wordDTO
,
runImageDTO
,
paragraph
);
// 图片
addPictureHeader
(
runImageDTO
,
paragraph
,
header
);
// 后置文本
addImageAfter
(
wordDTO
,
runImageDTO
,
paragraph
);
}
/**
* 图片前置文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
*/
private
static
void
addImageBefore
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
)
{
List
<
RunTextDTO
>
beforeTexts
=
runImageDTO
.
getBeforeTexts
();
if
(!
ListUtils
.
isEmpty
(
beforeTexts
))
{
for
(
RunTextDTO
runTextDTO
:
beforeTexts
)
{
setTextStyle
(
wordDTO
,
runTextDTO
,
paragraph
);
}
}
}
/**
* 图片后置文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
*/
private
static
void
addImageAfter
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
)
{
List
<
RunTextDTO
>
afterTexts
=
runImageDTO
.
getAfterTexts
();
if
(!
ListUtils
.
isEmpty
(
afterTexts
))
{
for
(
RunTextDTO
runTextDTO
:
afterTexts
)
{
setTextStyle
(
wordDTO
,
runTextDTO
,
paragraph
);
}
}
}
/**
* 添加页眉图片
*
* @param runImageDTO
* @param paragraph
* @param header
*/
private
static
void
addPictureHeader
(
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
InputStream
is
=
null
;
String
imageUrl
=
runImageDTO
.
getImageUrl
();
if
(!
StringUtil
.
isEmpty
(
imageUrl
))
{
if
(
imageUrl
.
startsWith
(
"http"
))
{
is
=
new
ByteArrayInputStream
(
FileUtils
.
downloadByteFromUrl
(
imageUrl
));
}
else
{
is
=
new
ByteArrayInputStream
(
FileUtils
.
file2byte
(
imageUrl
));
}
}
else
if
(
runImageDTO
.
getImageByte
()
!=
null
)
{
is
=
new
ByteArrayInputStream
(
runImageDTO
.
getImageByte
());
}
XWPFRun
run
=
paragraph
.
createRun
();
try
{
XWPFPicture
picture
=
run
.
addPicture
(
is
,
XWPFDocument
.
PICTURE_TYPE_JPEG
,
"123"
,
Units
.
toEMU
(
runImageDTO
.
getWidth
()),
Units
.
toEMU
(
runImageDTO
.
getHeight
()));
//这段必须有,不然打开的logo图片不显示
String
blipID
=
""
;
for
(
XWPFPictureData
picturedata
:
header
.
getAllPackagePictures
())
{
blipID
=
header
.
getRelationId
(
picturedata
);
}
picture
.
getCTPicture
().
getBlipFill
().
getBlip
().
setEmbed
(
blipID
);
run
.
addTab
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】WORD页眉图片生成失败:"
+
e
.
getMessage
(),
e
);
}
finally
{
try
{
if
(
is
!=
null
)
{
is
.
close
();
is
=
null
;
}
}
catch
(
Exception
e
)
{
}
}
}
/**
* 添加图片数据
*
* @param runImageDTO
* @param document
* @return
* @throws InvalidFormatException
*/
private
static
String
addPictureContent
(
RunImageDTO
runImageDTO
,
CustomXWPFDocument
document
)
throws
InvalidFormatException
{
String
relationId
=
null
;
String
imageUrl
=
runImageDTO
.
getImageUrl
();
if
(!
StringUtil
.
isEmpty
(
imageUrl
))
{
if
(
imageUrl
.
startsWith
(
"http"
))
{
relationId
=
document
.
addPictureData
(
FileUtils
.
downloadByteFromUrl
(
imageUrl
),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
else
{
relationId
=
document
.
addPictureData
(
FileUtils
.
file2byte
(
imageUrl
),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
}
else
if
(
runImageDTO
.
getImageByte
()
!=
null
)
{
relationId
=
document
.
addPictureData
(
runImageDTO
.
getImageByte
(),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
return
relationId
;
}
/**
* 根据图片类型获取对应的图片类型代码
*
* @param picType
* @return
*/
public
static
int
getPictureType
(
String
picType
)
{
int
res
=
CustomXWPFDocument
.
PICTURE_TYPE_PICT
;
if
(
picType
!=
null
)
{
if
(
picType
.
equalsIgnoreCase
(
"png"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_PNG
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"dib"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_DIB
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"emf"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_EMF
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"jpg"
)
||
picType
.
equalsIgnoreCase
(
"jpeg"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_JPEG
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"wmf"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_WMF
;
}
}
return
res
;
}
/**
* 结束关闭文件流
*
* @param document
* @param os
*/
public
static
void
close
(
CustomXWPFDocument
document
,
OutputStream
os
)
{
try
{
if
(
document
!=
null
)
{
document
.
close
();
document
=
null
;
}
if
(
os
!=
null
)
{
os
.
close
();
os
=
null
;
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】WORD文件流关闭失败:"
+
e
.
getMessage
(),
e
);
}
}
}
package
com
.
pcloud
.
common
.
utils
.
word
;
import
java.io.ByteArrayInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.math.BigInteger
;
import
java.util.List
;
import
org.apache.poi.POIXMLDocument
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.openxml4j.opc.OPCPackage
;
import
org.apache.poi.util.Units
;
import
org.apache.poi.wp.usermodel.HeaderFooterType
;
import
org.apache.poi.xwpf.usermodel.XWPFDocument
;
import
org.apache.poi.xwpf.usermodel.XWPFFooter
;
import
org.apache.poi.xwpf.usermodel.XWPFHeader
;
import
org.apache.poi.xwpf.usermodel.XWPFParagraph
;
import
org.apache.poi.xwpf.usermodel.XWPFPicture
;
import
org.apache.poi.xwpf.usermodel.XWPFPictureData
;
import
org.apache.poi.xwpf.usermodel.XWPFRun
;
import
org.apache.poi.xwpf.usermodel.XWPFTable
;
import
org.apache.poi.xwpf.usermodel.XWPFTableCell
;
import
org.apache.poi.xwpf.usermodel.XWPFTableRow
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth
;
import
org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.pcloud.common.constant.FilePathConst
ant
;
import
com.pcloud.common.constant.WordConstant
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
import
com.pcloud.common.utils.FileUtils
;
import
com.pcloud.common.utils.ListUtils
;
import
com.pcloud.common.utils.UUIDUitl
;
import
com.pcloud.common.utils.string.StringUtil
;
import
com.pcloud.common.utils.word.dto.ParagraphDTO
;
import
com.pcloud.common.utils.word.dto.RunDTO
;
import
com.pcloud.common.utils.word.dto.RunImageDTO
;
import
com.pcloud.common.utils.word.dto.RunTableDTO
;
import
com.pcloud.common.utils.word.dto.RunTextDTO
;
import
com.pcloud.common.utils.word.dto.WordDTO
;
import
com.pcloud.common.utils.word.enums.ParagraphType
;
/**
* 重新定义word工具类
*
* @author:songx
* @date:2019/5/27,10:06
*/
public
class
WordNewUtils
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
WordNewUtils
.
class
);
// public static void main(String[] args) {
// List<ParagraphDTO> paragraphDTOS = new ArrayList<>();
// // 页眉
// paragraphDTOS.add(getHeader1());
// paragraphDTOS.add(getHeader2());
// // 标题
// paragraphDTOS.add(getParagraph1());
// // 内容
// paragraphDTOS.add(getParagraph2());
// paragraphDTOS.add(getParagraph3());
// paragraphDTOS.add(getParagraph4());
// paragraphDTOS.add(getParagraph4());
// // 页脚
// paragraphDTOS.add(getFooter1());
// try {
// System.out.println(create(paragraphDTOS));
// } catch (Exception e) {
// LOGGER.error(e.getMessage(), e);
// }
// System.out.println("Game over!");
// }
//
// private static ParagraphDTO getHeader1() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("?????的个人专属错题本 共40道错题", 9, "微软雅黑");
// return ParagraphDTO.newHeader(ParagraphType.text, runTextDTO);
// }
//
// private static ParagraphDTO getHeader2() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("来源《书名书名书名书名书名书名书名书书名书名书名书书名书名书名书》", 9, "微软雅黑");
// return ParagraphDTO.newHeader(ParagraphType.text, runTextDTO);
// }
//
// private static ParagraphDTO getParagraph1() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("个人专属错题本", 18, "微软雅黑", true);
// return ParagraphDTO.newParagraph(ParagraphType.text, ParagraphAlignment.CENTER, runTextDTO, 1);
// }
//
// private static ParagraphDTO getParagraph2() {
// RunTextDTO runTextDTO = RunTextDTO
// .newText("完成下面错题练习,扫描二维码核对答案,并记录练习结果:", 11, "微软雅黑", true);
// return ParagraphDTO.newParagraph(ParagraphType.text, runTextDTO, 1);
// }
//
// private static ParagraphDTO getParagraph3() {
// RunImageDTO runImageDTO = RunImageDTO
// .newImage("I:\\TEST\\image\\02.jpg", 80, 80, null, listAfterTexts3(11, "微软雅黑"));
// return ParagraphDTO.newParagraph(ParagraphType.image, TextAlignment.TOP, runImageDTO, 1);
// }
//
// private static ParagraphDTO getParagraph4() {
// RunImageDTO runImageDTO = RunImageDTO
// .newImage("I:\\TEST\\image\\2.jpg", 200, 500);
// return ParagraphDTO.newParagraph(ParagraphType.image, runImageDTO, 3);
// }
//
// private static ParagraphDTO getFooter1() {
// RunTextDTO runTextDTO = RunTextDTO.newText("反复练习,攻克错题", 11, "微软雅黑");
// return ParagraphDTO.newFooter(ParagraphType.text, ParagraphAlignment.CENTER, runTextDTO);
// }
//
// /**
// * 组装图片后面的文字
// *
// * @param fontSize
// * @param fontFamily
// * @return
// */
// private static List<RunTextDTO> listAfterTexts3(int fontSize, String fontFamily) {
// List<RunTextDTO> afterRuns = Lists.newArrayList();
// afterRuns.add(RunTextDTO.newText(" 答对", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" 10 ", fontSize, fontFamily, UnderlinePatterns.SINGLE));
// afterRuns.add(RunTextDTO.newText("道题,答错", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" 11 ", fontSize, fontFamily, UnderlinePatterns.SINGLE));
// afterRuns.add(RunTextDTO.newText("道题,日期", fontSize, fontFamily));
// afterRuns.add(RunTextDTO.newText(" " + LocalDateUtils.getDateNow() + " ", fontSize, fontFamily,
// UnderlinePatterns.SINGLE));
// return afterRuns;
// }
/**
* 创建WORD
*
* @param wordDTO
* @return
* @throws Exception
*/
public
static
String
create
(
WordDTO
wordDTO
)
throws
FileException
{
LOGGER
.
info
(
"【WORD】创建WORD文档,<START>"
);
if
(
wordDTO
==
null
||
ListUtils
.
isEmpty
(
wordDTO
.
getParagraphs
()))
{
return
null
;
}
String
wordTemplate
=
null
;
String
outPath
=
null
;
CustomXWPFDocument
document
=
null
;
FileOutputStream
fos
=
null
;
try
{
wordTemplate
=
FilePathConst
ant
.
WORD
+
UUIDUitl
.
taskName
()
+
".docx"
;
FileUtils
.
downloadFileFromUrl
(
WordConstant
.
TEMPLATE_URL
,
wordTemplate
);
OPCPackage
pack
=
POIXMLDocument
.
openPackage
(
wordTemplate
);
document
=
new
CustomXWPFDocument
(
pack
);
// 添加内容到文档中
addParagraphs
(
wordDTO
,
document
);
// 生成目标word
outPath
=
FilePathConst
ant
.
WORD
+
UUIDUitl
.
taskName
()
+
".docx"
;
fos
=
new
FileOutputStream
(
outPath
);
document
.
write
(
fos
);
fos
.
flush
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】创建WORD文档失败:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_CONTENT_ERROR
,
e
.
getMessage
());
}
finally
{
close
(
document
,
fos
);
FileUtils
.
deleteFile
(
wordTemplate
);
}
LOGGER
.
info
(
"【WORD】创建WORD文档,<END>.[outPath]="
+
outPath
);
return
outPath
;
}
/**
* 添加内容到WORD中
*
* @param wordDTO
* @param document
* @throws BizException
*/
private
static
void
addParagraphs
(
WordDTO
wordDTO
,
CustomXWPFDocument
document
)
{
List
<
ParagraphDTO
>
paragraphDTOS
=
wordDTO
.
getParagraphs
();
for
(
ParagraphDTO
paragraphDTO
:
paragraphDTOS
)
{
ParagraphType
paragraphType
=
paragraphDTO
.
getParagraphType
();
if
(
ParagraphType
.
table
.
equals
(
paragraphType
))
{
addTable
(
paragraphDTO
,
document
);
}
else
if
(
ParagraphType
.
image
.
equals
(
paragraphType
))
{
addImage
(
wordDTO
,
paragraphDTO
,
document
);
}
else
if
(
ParagraphType
.
text
.
equals
(
paragraphType
))
{
addText
(
wordDTO
,
paragraphDTO
,
document
);
}
}
}
/**
* 获取段落
*
* @param paragraphDTO
* @param document
* @return
*/
private
static
XWPFParagraph
getParagraph
(
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
{
if
(
paragraphDTO
.
isHeader
())
{
XWPFHeader
xwpfHeader
=
document
.
createHeader
(
HeaderFooterType
.
DEFAULT
);
return
xwpfHeader
.
createParagraph
();
}
else
if
(
paragraphDTO
.
isFooter
())
{
XWPFFooter
xwpfFooter
=
document
.
createFooter
(
HeaderFooterType
.
DEFAULT
);
return
xwpfFooter
.
createParagraph
();
}
else
{
return
document
.
createParagraph
();
}
}
/**
* 添加文本块
*
* @param wordDTO
* @param paragraphDTO
* @throws BizException
*/
private
static
void
addText
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
throws
BizException
{
XWPFParagraph
paragraph
=
getParagraph
(
paragraphDTO
,
document
);
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 设置段落块样式
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
setTextStyle
(
wordDTO
,
(
RunTextDTO
)
paragraphDTO
.
getRun
(),
paragraph
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
setTextStyle
(
wordDTO
,
(
RunTextDTO
)
runDTO
,
paragraph
);
}
}
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 添加空行
*
* @param afterEmpty
* @param document
* @throws BizException
*/
private
static
void
addEmptyText
(
int
afterEmpty
,
CustomXWPFDocument
document
)
throws
BizException
{
for
(
int
i
=
0
;
i
<
afterEmpty
;
i
++)
{
setTextStyle
(
null
,
RunTextDTO
.
newEmpty
(),
document
.
createParagraph
());
}
}
/**
* 设置段落样式
*
* @param paragraphDTO
* @param paragraph
*/
private
static
void
setParagraphStyle
(
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
)
{
// 与前一行的间距
if
(
paragraphDTO
.
getSpacingBefore
()
>
0
)
{
paragraph
.
setSpacingBeforeLines
(
paragraphDTO
.
getSpacingBefore
());
}
// 与下一行的间距
if
(
paragraphDTO
.
getSpacingAfter
()
>
0
)
{
paragraph
.
setSpacingAfterLines
(
paragraphDTO
.
getSpacingAfter
());
}
// 对齐
if
(
paragraphDTO
.
getParagraphAlignment
()
!=
null
)
{
paragraph
.
setFontAlignment
(
paragraphDTO
.
getParagraphAlignment
().
getValue
());
}
// 水平居中
if
(
paragraphDTO
.
getTextAlignment
()
!=
null
)
{
paragraph
.
setVerticalAlignment
(
paragraphDTO
.
getTextAlignment
());
}
}
/**
* 设置文本样式
*
* @param wordDTO
* @param runTextDTO
* @param paragraph
*/
private
static
void
setTextStyle
(
WordDTO
wordDTO
,
RunTextDTO
runTextDTO
,
XWPFParagraph
paragraph
)
{
XWPFRun
xwpfRun
=
paragraph
.
createRun
();
xwpfRun
.
setText
(
runTextDTO
.
getText
());
// 是否加粗
xwpfRun
.
setBold
(
runTextDTO
.
isBold
());
// 字体大小
if
(
runTextDTO
.
getFontSize
()
>
0
)
{
xwpfRun
.
setFontSize
(
runTextDTO
.
getFontSize
());
}
else
if
(
wordDTO
!=
null
&&
wordDTO
.
getFontSize
()
>
0
)
{
xwpfRun
.
setFontSize
(
wordDTO
.
getFontSize
());
}
// 字体
if
(
runTextDTO
.
getFontFamily
()
!=
null
)
{
xwpfRun
.
setFontFamily
(
runTextDTO
.
getFontFamily
());
}
else
if
(
wordDTO
!=
null
&&
wordDTO
.
getFontFamily
()
!=
null
)
{
xwpfRun
.
setFontFamily
(
wordDTO
.
getFontFamily
());
}
// 下划线
if
(
runTextDTO
.
getUnderlinePatterns
()
!=
null
)
{
xwpfRun
.
setUnderline
(
runTextDTO
.
getUnderlinePatterns
());
}
}
/**
* 添加表格
*
* @param paragraphDTO
* @throws BizException
*/
private
static
void
addTable
(
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
throws
BizException
{
XWPFParagraph
paragraph
=
document
.
createParagraph
();
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 创建表格
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createTable
((
RunTableDTO
)
paragraphDTO
.
getRun
(),
document
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createTable
((
RunTableDTO
)
runDTO
,
document
);
}
}
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 创建表格
*
* @param runTableDTO
* @param document
*/
private
static
void
createTable
(
RunTableDTO
runTableDTO
,
CustomXWPFDocument
document
)
{
String
[][]
contents
=
runTableDTO
.
getContents
();
if
(
contents
==
null
||
contents
.
length
<
1
)
{
return
;
}
int
rowNum
=
contents
.
length
;
// 总行数
int
colNum
=
runTableDTO
.
getColumnWidths
().
length
;
// 总列数
if
(
colNum
<
1
)
{
throw
new
FileException
(
FileException
.
FILE_CONTENT_ERROR
,
"表格列数与内容列数不一致"
);
}
// 创建表格
XWPFTable
ComTable
=
document
.
createTable
();
// 列宽自动分割
CTTblWidth
comTableWidth
=
ComTable
.
getCTTbl
().
addNewTblPr
().
addNewTblW
();
comTableWidth
.
setType
(
STTblWidth
.
DXA
);
comTableWidth
.
setW
(
BigInteger
.
valueOf
(
9072
));
// 设置行和列
for
(
int
i
=
0
;
i
<
rowNum
;
i
++)
{
String
[]
cols
=
contents
[
i
];
// 创建行
XWPFTableRow
comTableRow
=
i
==
0
?
ComTable
.
getRow
(
0
)
:
ComTable
.
createRow
();
for
(
int
j
=
0
;
j
<
colNum
;
j
++)
{
String
text
=
(
j
>=
cols
.
length
||
StringUtil
.
isEmpty
(
cols
[
j
]))
?
""
:
cols
[
j
];
// 填充单元格内容
XWPFTableCell
cell
=
null
;
if
(
i
==
0
)
{
cell
=
j
==
0
?
comTableRow
.
getCell
(
0
)
:
comTableRow
.
addNewTableCell
();
}
else
{
cell
=
comTableRow
.
getCell
(
j
);
}
cell
.
setText
(
text
);
cell
.
setVerticalAlignment
(
runTableDTO
.
getVertAlign
());
}
// 行高
if
(
runTableDTO
.
getHeight
()
>
0
)
{
comTableRow
.
setHeight
(
runTableDTO
.
getHeight
());
}
}
}
/**
* 添加图片和文本
*
* @param paragraphDTO
* @param document
*/
private
static
void
addImage
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
CustomXWPFDocument
document
)
{
XWPFParagraph
paragraph
=
null
;
if
(
paragraphDTO
.
isHeader
())
{
XWPFHeader
header
=
document
.
createHeader
(
HeaderFooterType
.
DEFAULT
);
paragraph
=
header
.
createParagraph
();
addImageHeader
(
wordDTO
,
paragraphDTO
,
paragraph
,
header
);
}
else
{
paragraph
=
document
.
createParagraph
();
addImageContent
(
wordDTO
,
paragraphDTO
,
paragraph
,
document
);
}
// 设置段落样式
setParagraphStyle
(
paragraphDTO
,
paragraph
);
// 添加空行
addEmptyText
(
paragraphDTO
.
getAfterEmpty
(),
document
);
}
/**
* 页眉中插入图片
*
* @param wordDTO
* @param paragraphDTO
* @param paragraph
* @param header
*/
private
static
void
addImageHeader
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
// 创建图片
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createImageHeader
(
wordDTO
,
(
RunImageDTO
)
paragraphDTO
.
getRun
(),
paragraph
,
header
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createImageHeader
(
wordDTO
,
(
RunImageDTO
)
runDTO
,
paragraph
,
header
);
}
}
}
/**
* 内容中插入图片
*
* @param wordDTO
* @param paragraphDTO
* @param paragraph
* @param document
*/
private
static
void
addImageContent
(
WordDTO
wordDTO
,
ParagraphDTO
paragraphDTO
,
XWPFParagraph
paragraph
,
CustomXWPFDocument
document
)
{
// 创建图片
if
(
paragraphDTO
.
getRun
()
!=
null
)
{
createImageContent
(
wordDTO
,
(
RunImageDTO
)
paragraphDTO
.
getRun
(),
paragraph
,
document
);
}
else
if
(!
ListUtils
.
isEmpty
(
paragraphDTO
.
getRuns
()))
{
for
(
RunDTO
runDTO
:
paragraphDTO
.
getRuns
())
{
createImageContent
(
wordDTO
,
(
RunImageDTO
)
runDTO
,
paragraph
,
document
);
}
}
}
/**
* 创建图片和文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
* @param document
*/
private
static
void
createImageContent
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
CustomXWPFDocument
document
)
{
// 前置文本
addImageBefore
(
wordDTO
,
runImageDTO
,
paragraph
);
try
{
// 图片
String
relationId
=
addPictureContent
(
runImageDTO
,
document
);
if
(!
StringUtil
.
isEmpty
(
relationId
))
{
int
id
=
document
.
getAllPictures
().
size
()
-
1
;
document
.
createPicture
(
paragraph
,
relationId
,
id
,
runImageDTO
.
getWidth
(),
runImageDTO
.
getHeight
());
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】创建WORD文档失败:"
+
e
.
getMessage
(),
e
);
}
// 后置文本
addImageAfter
(
wordDTO
,
runImageDTO
,
paragraph
);
}
/**
* 创建图片
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
* @param header
*/
private
static
void
createImageHeader
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
// 前置文本
addImageBefore
(
wordDTO
,
runImageDTO
,
paragraph
);
// 图片
addPictureHeader
(
runImageDTO
,
paragraph
,
header
);
// 后置文本
addImageAfter
(
wordDTO
,
runImageDTO
,
paragraph
);
}
/**
* 图片前置文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
*/
private
static
void
addImageBefore
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
)
{
List
<
RunTextDTO
>
beforeTexts
=
runImageDTO
.
getBeforeTexts
();
if
(!
ListUtils
.
isEmpty
(
beforeTexts
))
{
for
(
RunTextDTO
runTextDTO
:
beforeTexts
)
{
setTextStyle
(
wordDTO
,
runTextDTO
,
paragraph
);
}
}
}
/**
* 图片后置文本
*
* @param wordDTO
* @param runImageDTO
* @param paragraph
*/
private
static
void
addImageAfter
(
WordDTO
wordDTO
,
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
)
{
List
<
RunTextDTO
>
afterTexts
=
runImageDTO
.
getAfterTexts
();
if
(!
ListUtils
.
isEmpty
(
afterTexts
))
{
for
(
RunTextDTO
runTextDTO
:
afterTexts
)
{
setTextStyle
(
wordDTO
,
runTextDTO
,
paragraph
);
}
}
}
/**
* 添加页眉图片
*
* @param runImageDTO
* @param paragraph
* @param header
*/
private
static
void
addPictureHeader
(
RunImageDTO
runImageDTO
,
XWPFParagraph
paragraph
,
XWPFHeader
header
)
{
InputStream
is
=
null
;
String
imageUrl
=
runImageDTO
.
getImageUrl
();
if
(!
StringUtil
.
isEmpty
(
imageUrl
))
{
if
(
imageUrl
.
startsWith
(
"http"
))
{
is
=
new
ByteArrayInputStream
(
FileUtils
.
downloadByteFromUrl
(
imageUrl
));
}
else
{
is
=
new
ByteArrayInputStream
(
FileUtils
.
file2byte
(
imageUrl
));
}
}
else
if
(
runImageDTO
.
getImageByte
()
!=
null
)
{
is
=
new
ByteArrayInputStream
(
runImageDTO
.
getImageByte
());
}
XWPFRun
run
=
paragraph
.
createRun
();
try
{
XWPFPicture
picture
=
run
.
addPicture
(
is
,
XWPFDocument
.
PICTURE_TYPE_JPEG
,
"123"
,
Units
.
toEMU
(
runImageDTO
.
getWidth
()),
Units
.
toEMU
(
runImageDTO
.
getHeight
()));
//这段必须有,不然打开的logo图片不显示
String
blipID
=
""
;
for
(
XWPFPictureData
picturedata
:
header
.
getAllPackagePictures
())
{
blipID
=
header
.
getRelationId
(
picturedata
);
}
picture
.
getCTPicture
().
getBlipFill
().
getBlip
().
setEmbed
(
blipID
);
run
.
addTab
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】WORD页眉图片生成失败:"
+
e
.
getMessage
(),
e
);
}
finally
{
try
{
if
(
is
!=
null
)
{
is
.
close
();
is
=
null
;
}
}
catch
(
Exception
e
)
{
}
}
}
/**
* 添加图片数据
*
* @param runImageDTO
* @param document
* @return
* @throws InvalidFormatException
*/
private
static
String
addPictureContent
(
RunImageDTO
runImageDTO
,
CustomXWPFDocument
document
)
throws
InvalidFormatException
{
String
relationId
=
null
;
String
imageUrl
=
runImageDTO
.
getImageUrl
();
if
(!
StringUtil
.
isEmpty
(
imageUrl
))
{
if
(
imageUrl
.
startsWith
(
"http"
))
{
relationId
=
document
.
addPictureData
(
FileUtils
.
downloadByteFromUrl
(
imageUrl
),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
else
{
relationId
=
document
.
addPictureData
(
FileUtils
.
file2byte
(
imageUrl
),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
}
else
if
(
runImageDTO
.
getImageByte
()
!=
null
)
{
relationId
=
document
.
addPictureData
(
runImageDTO
.
getImageByte
(),
XWPFDocument
.
PICTURE_TYPE_JPEG
);
}
return
relationId
;
}
/**
* 根据图片类型获取对应的图片类型代码
*
* @param picType
* @return
*/
public
static
int
getPictureType
(
String
picType
)
{
int
res
=
CustomXWPFDocument
.
PICTURE_TYPE_PICT
;
if
(
picType
!=
null
)
{
if
(
picType
.
equalsIgnoreCase
(
"png"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_PNG
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"dib"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_DIB
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"emf"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_EMF
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"jpg"
)
||
picType
.
equalsIgnoreCase
(
"jpeg"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_JPEG
;
}
else
if
(
picType
.
equalsIgnoreCase
(
"wmf"
))
{
res
=
CustomXWPFDocument
.
PICTURE_TYPE_WMF
;
}
}
return
res
;
}
/**
* 结束关闭文件流
*
* @param document
* @param os
*/
public
static
void
close
(
CustomXWPFDocument
document
,
OutputStream
os
)
{
try
{
if
(
document
!=
null
)
{
document
.
close
();
document
=
null
;
}
if
(
os
!=
null
)
{
os
.
close
();
os
=
null
;
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【WORD】WORD文件流关闭失败:"
+
e
.
getMessage
(),
e
);
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/word/WordUtils.java
View file @
59cf09ff
...
...
@@ -41,7 +41,7 @@ import com.lowagie.text.Paragraph;
import
com.lowagie.text.Phrase
;
import
com.lowagie.text.Table
;
import
com.lowagie.text.rtf.RtfWriter2
;
import
com.pcloud.common.constant.FilePathConst
;
import
com.pcloud.common.constant.FilePathConst
ant
;
import
com.pcloud.common.constant.WordConstant
;
import
com.pcloud.common.exceptions.BizException
;
import
com.pcloud.common.exceptions.FileException
;
...
...
@@ -84,7 +84,7 @@ public class WordUtils {
RtfWriter2
rtfWriter2
=
null
;
try
{
// 输出路径
outPath
=
FilePathConst
.
WORD_PATH
+
UUIDUitl
.
taskName
()
+
".doc"
;
outPath
=
FilePathConst
ant
.
WORD
+
UUIDUitl
.
taskName
()
+
".doc"
;
FileUtils
.
creatFiles
(
outPath
);
// 创建输出流
os
=
new
FileOutputStream
(
new
File
(
outPath
));
...
...
@@ -302,14 +302,14 @@ public class WordUtils {
CustomXWPFDocument
document
=
null
;
FileOutputStream
fos
=
null
;
try
{
wordTemplate
=
FilePathConst
.
WORD_PATH
+
UUIDUitl
.
taskName
()
+
".docx"
;
wordTemplate
=
FilePathConst
ant
.
WORD
+
UUIDUitl
.
taskName
()
+
".docx"
;
FileUtils
.
downloadFileFromUrl
(
WordConstant
.
TEMPLATE_URL
,
wordTemplate
);
OPCPackage
pack
=
POIXMLDocument
.
openPackage
(
wordTemplate
);
document
=
new
CustomXWPFDocument
(
pack
);
// 添加内容到文档中
addChunks
(
wordPOs
,
document
);
// 生成目标word
outPath
=
FilePathConst
.
WORD_PATH
+
UUIDUitl
.
taskName
()
+
".docx"
;
outPath
=
FilePathConst
ant
.
WORD
+
UUIDUitl
.
taskName
()
+
".docx"
;
fos
=
new
FileOutputStream
(
outPath
);
document
.
write
(
fos
);
fos
.
flush
();
...
...
pcloud-solr/src/main/java/com/pcloud/solr/SolrDto.java
View file @
59cf09ff
...
...
@@ -127,6 +127,12 @@ public class SolrDto implements Serializable {
@Field
private
Long
channelId
;
/**
* 场景编码
*/
@Field
private
String
sceneCode
;
public
String
getId
()
{
return
id
;
}
...
...
@@ -282,6 +288,14 @@ public class SolrDto implements Serializable {
this
.
saleState
=
saleState
;
}
public
String
getSceneCode
()
{
return
sceneCode
;
}
public
void
setSceneCode
(
String
sceneCode
)
{
this
.
sceneCode
=
sceneCode
;
}
@Override
public
String
toString
()
{
return
"SolrDto{"
+
...
...
@@ -292,6 +306,7 @@ public class SolrDto implements Serializable {
", typeId="
+
typeId
+
", typeCode='"
+
typeCode
+
'\''
+
", typeName='"
+
typeName
+
'\''
+
", sceneCode='"
+
sceneCode
+
'\''
+
", startDate="
+
startDate
+
", endDate="
+
endDate
+
", saleState="
+
saleState
+
...
...
pcloud-solr/src/main/java/com/pcloud/solr/SolrQueryParam.java
View file @
59cf09ff
...
...
@@ -44,7 +44,7 @@ public class SolrQueryParam {
/**
* 返回字段
*/
private
String
fl
=
"id,saleId,saleCode,typeId,typeCode,typeName,title,startDate,endDate,coverImg,description,createdUser,createdDate,lastModifiedDate,channelId"
;
private
String
fl
=
"id,saleId,saleCode,typeId,typeCode,typeName,title,startDate,endDate,coverImg,description,createdUser,createdDate,lastModifiedDate,channelId
,saleState,sceneCode
"
;
public
String
getQ
()
{
return
q
;
...
...
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