Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
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
1
Merge Requests
1
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
haoban3.0
haoban-manage3.0
Commits
c2806b44
Commit
c2806b44
authored
Apr 24, 2022
by
墨竹
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:代码公用
parent
61a23544
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
21 deletions
+7
-21
MaterialApiServiceImpl.java
...nage/service/service/out/impl/MaterialApiServiceImpl.java
+7
-21
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/service/out/impl/MaterialApiServiceImpl.java
View file @
c2806b44
...
...
@@ -19,11 +19,11 @@ import com.gic.haoban.manage.service.service.MaterialCategoryService;
import
com.gic.haoban.manage.service.service.MaterialService
;
import
com.gic.haoban.manage.service.service.MiniprogramSettingService
;
import
com.gic.haoban.manage.service.service.WxEnterpriseService
;
import
com.gic.haoban.manage.service.util.CommonUtil
;
import
com.gic.wechat.api.enums.QywxMediaTypeEnum
;
import
com.gic.wechat.api.service.qywx.QywxSuiteApiService
;
import
com.github.pagehelper.PageHelper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.slf4j.Logger
;
...
...
@@ -31,8 +31,6 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.io.InputStream
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
...
...
@@ -134,7 +132,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if
(
type
==
3
)
{
String
imgUrl
=
materialDTO
.
getImgUrl
();
logger
.
info
(
"【上传图片】imgUrl={}"
,
imgUrl
);
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
imgUrl
));
logger
.
info
(
"【上传图片返回】response={}"
,
JSON
.
toJSONString
(
response
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
...
...
@@ -142,7 +140,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if
(
fileType
!=
null
)
{
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
...
...
@@ -198,7 +196,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
String
imgUrl
=
materialDTO
.
getImgUrl
();
String
oldImgUrl
=
materialDTO
.
getImgUrl
();
if
(!
imgUrl
.
equals
(
oldImgUrl
))
{
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
imgUrl
));
JSONResponse
response
=
qywxSuiteApiService
.
uploadImage
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
imgUrl
));
String
wxImgUrl
=
response
.
getResult
()
==
null
?
""
:
response
.
getResult
().
toString
();
materialDTO
.
setWxImgUrl
(
wxImgUrl
);
}
...
...
@@ -206,7 +204,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if
(
fileType
!=
null
&&
!
url
.
equals
(
oldUrl
))
{
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
materialDTO
.
setWxLastUploadTime
(
new
Date
());
materialDTO
.
setMediaId
(
jp
.
getResult
().
toString
());
...
...
@@ -254,7 +252,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
String
[]
arr
=
url
.
split
(
"/"
);
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
enterprise
.
getCorpid
(),
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
old
.
setWxLastUploadTime
(
new
Date
());
old
.
setMediaId
(
jp
.
getResult
().
toString
());
...
...
@@ -308,18 +306,6 @@ public class MaterialApiServiceImpl implements MaterialApiService {
return
PageUtil
.
changePageHelperToCurrentPage
(
page
,
MaterialDTO
.
class
);
}
private
static
byte
[]
getFileByte
(
String
url
)
{
try
{
InputStream
in
=
new
URL
(
url
).
openStream
();
byte
[]
data
=
IOUtils
.
toByteArray
(
in
);
return
data
;
}
catch
(
Exception
e
)
{
logger
.
info
(
"【异常】"
+
e
.
getMessage
(),
e
);
}
return
null
;
}
@Override
public
List
<
MaterialCategoryDTO
>
listByParentCategory
(
String
categoryId
)
{
return
materialCategoryService
.
listByParentCategory
(
categoryId
);
...
...
@@ -439,7 +425,7 @@ public class MaterialApiServiceImpl implements MaterialApiService {
// 先写死为图片类型, 以后有别的再扩展
QywxMediaTypeEnum
fileType
=
QywxMediaTypeEnum
.
IMAGE
;
int
count
=
arr
.
length
;
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
corPid
,
config
.
getWxSuiteid
(),
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
JSONResponse
jp
=
qywxSuiteApiService
.
uploadMedia
(
corPid
,
config
.
getWxSuiteid
(),
CommonUtil
.
getFileByte
(
url
),
arr
[
count
-
1
],
fileType
.
getCode
());
if
(
jp
.
getErrorCode
()
==
0
)
{
return
jp
.
getResult
().
toString
();
}
...
...
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