Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
5d33e647
Commit
5d33e647
authored
Aug 22, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片旋转判断
parent
c57cfa0b
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
31 deletions
+54
-31
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/AdminStorageController.java
.../com/wwdz/ch/admin/controller/AdminStorageController.java
+8
-4
ch-core/src/main/java/com/wwdz/ch/core/qcode/QCodeService.java
...re/src/main/java/com/wwdz/ch/core/qcode/QCodeService.java
+5
-4
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
...rc/main/java/com/wwdz/ch/core/storage/StorageService.java
+4
-18
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
+30
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+2
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
...src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
+2
-1
ch-wx-api/src/main/resources/瓷器短信表.xlsx
ch-wx-api/src/main/resources/瓷器短信表.xlsx
+0
-0
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/WxPayServiceTest.java
...pi/src/test/java/com/wwdz/ch/wx/api/WxPayServiceTest.java
+3
-3
No files found.
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/AdminStorageController.java
View file @
5d33e647
...
...
@@ -2,6 +2,11 @@ package com.wwdz.ch.admin.controller;
import
cn.hutool.core.util.RandomUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.drew.imaging.ImageMetadataReader
;
import
com.drew.metadata.Directory
;
import
com.drew.metadata.Metadata
;
import
com.drew.metadata.MetadataException
;
import
com.drew.metadata.exif.ExifIFD0Directory
;
import
com.github.pagehelper.PageInfo
;
import
com.wwdz.ch.admin.annotation.RequiresPermissionsDesc
;
import
com.wwdz.ch.admin.service.AdminStorageService
;
...
...
@@ -9,6 +14,7 @@ import com.wwdz.ch.admin.service.UploadService;
import
com.wwdz.ch.admin.util.AuthSupport
;
import
com.wwdz.ch.core.storage.StorageService
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.core.validator.Order
;
import
com.wwdz.ch.core.validator.Sort
;
...
...
@@ -62,18 +68,16 @@ public class AdminStorageController {
@RequiresPermissions
(
"admin:storage:create"
)
@RequiresPermissionsDesc
(
menu
=
{
"系统管理"
,
"对象存储"
},
button
=
"上传"
)
@PostMapping
(
"/create"
)
public
Object
create
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
IO
Exception
{
public
Object
create
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
Exception
{
logger
.
info
(
"【请求开始】操作人:["
+
AuthSupport
.
userName
()+
"] 系统管理->对象存储->上传,请求参数,file:{}"
,
file
.
getOriginalFilename
());
String
originalFilename
=
file
.
getOriginalFilename
();
long
nowTime
=
System
.
currentTimeMillis
();
String
name
=
new
BASE64Encoder
().
encode
(
Long
.
toString
(
nowTime
).
getBytes
())
+
RandomUtil
.
randomInt
(
1000
);
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
name
);
name
,
MediaUtil
.
isRotation
(
file
)
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"url"
,
url
);
logger
.
info
(
"【请求结束】系统管理->对象存储->查询:响应结果:{}"
,
JSONObject
.
toJSONString
(
data
));
return
ResponseUtil
.
ok
(
data
);
}
...
...
ch-core/src/main/java/com/wwdz/ch/core/qcode/QCodeService.java
View file @
5d33e647
...
...
@@ -22,6 +22,7 @@ import javax.imageio.ImageIO;
import
com.wwdz.ch.core.storage.StorageService
;
import
com.wwdz.ch.core.system.SystemConfig
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.PriceUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -65,7 +66,7 @@ public class QCodeService {
byte
[]
imageData
=
drawPicture
(
inputStream
,
goodPicUrl
,
goodName
,
price
);
ByteArrayInputStream
inputStream2
=
new
ByteArrayInputStream
(
imageData
);
// 存储分享图
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getKeyName
(
goodId
));
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getKeyName
(
goodId
)
,
false
);
logger
.
info
(
"创建商品分享图 URL:{}"
,
url
);
return
url
;
}
catch
(
WxErrorException
e
)
{
...
...
@@ -214,7 +215,7 @@ public class QCodeService {
FileInputStream
inputStream
=
new
FileInputStream
(
file
);
fileStream
=
new
FileInputStream
(
file
);
url
=
storageService
.
store
(
inputStream
,
fileStream
.
available
(),
"image/jpeg"
,
getShareUserKey
(
userId
));
url
=
storageService
.
store
(
inputStream
,
fileStream
.
available
(),
"image/jpeg"
,
getShareUserKey
(
userId
)
,
false
);
logger
.
info
(
"创建商品分享图 URL:{}"
,
url
);
}
catch
(
WxErrorException
e
)
{
...
...
@@ -276,7 +277,7 @@ public class QCodeService {
byte
[]
imageData
=
drawTopicPicture
(
inputStream
,
picUrl
,
subtitle
,
price
);
ByteArrayInputStream
inputStream2
=
new
ByteArrayInputStream
(
imageData
);
// 存储分享图
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getTopicKey
(
topicId
));
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getTopicKey
(
topicId
)
,
false
);
logger
.
info
(
"创建活动主题分享图 URL:{}"
,
url
);
return
url
;
}
catch
(
WxErrorException
e
)
{
...
...
@@ -362,7 +363,7 @@ public class QCodeService {
byte
[]
imageData
=
drawBrandPicture
(
inputStream
,
picUrl
,
name
,
defaultCategory
);
ByteArrayInputStream
inputStream2
=
new
ByteArrayInputStream
(
imageData
);
// 存储分享图
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getBrandKey
(
brandId
));
String
url
=
storageService
.
store
(
inputStream2
,
imageData
.
length
,
"image/jpeg"
,
getBrandKey
(
brandId
)
,
false
);
logger
.
info
(
"创建品牌商铺主题分享图 URL:{}"
,
url
);
return
url
;
}
catch
(
WxErrorException
e
)
{
...
...
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
View file @
5d33e647
...
...
@@ -67,28 +67,12 @@ public class StorageService {
* @param fileName
* 文件索引名
*/
public
String
store
(
InputStream
inputStream
,
long
contentLength
,
String
contentType
,
String
fileName
)
{
public
String
store
(
InputStream
inputStream
,
long
contentLength
,
String
contentType
,
String
fileName
,
boolean
rotation
)
{
BufferedImage
bufferedImage
=
null
;
boolean
rotation
=
false
;
try
{
bufferedImage
=
ImageIO
.
read
(
inputStream
);
Metadata
metadata
=
ImageMetadataReader
.
readMetadata
(
inputStream
);
Directory
imageDirectory
=
metadata
.
getFirstDirectoryOfType
(
ExifIFD0Directory
.
class
);
int
orientation
=
1
;
try
{
orientation
=
imageDirectory
.
getInt
(
ExifIFD0Directory
.
TAG_ORIENTATION
);
}
catch
(
MetadataException
ignore
)
{
}
switch
(
orientation
)
{
case
5
:
// - PI/2 and Flip X
case
6
:
// -PI/2 and -width
case
7
:
// PI/2 and Flip
case
8
:
// PI / 2
rotation
=
true
;
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
logger
.
error
(
"存储图片error:{}"
,
e
);
}
String
type
=
MediaTypeEnum
.
getByMime
(
contentType
)
==
null
?
MediaTypeEnum
.
IMAGE_JPG
.
getExt
()
:
MediaTypeEnum
.
getByMime
(
contentType
).
getExt
();
String
keyName
;
...
...
@@ -104,6 +88,8 @@ public class StorageService {
return
generateUrl
(
keyName
);
}
private
String
generateKey
(
String
originalFilename
)
{
int
index
=
originalFilename
.
lastIndexOf
(
'.'
);
String
suffix
=
originalFilename
.
substring
(
index
);
...
...
ch-core/src/main/java/com/wwdz/ch/core/util/MediaUtil.java
View file @
5d33e647
package
com.wwdz.ch.core.util
;
import
com.drew.imaging.ImageMetadataReader
;
import
com.drew.metadata.Directory
;
import
com.drew.metadata.Metadata
;
import
com.drew.metadata.exif.ExifIFD0Directory
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
import
com.wwdz.ch.core.entity.ImageInfo
;
...
...
@@ -7,6 +11,7 @@ import com.xxdxxs.utils.CommonUtils;
import
com.xxdxxs.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
...
...
@@ -91,6 +96,31 @@ public class MediaUtil {
return
null
;
}
/**
* 图片是否旋转
* @param file
* @return
*/
public
static
boolean
isRotation
(
MultipartFile
file
){
boolean
rotation
=
false
;
int
orientation
=
1
;
try
{
Metadata
metadata
=
ImageMetadataReader
.
readMetadata
(
file
.
getInputStream
());
Directory
imageDirectory
=
metadata
.
getFirstDirectoryOfType
(
ExifIFD0Directory
.
class
);
orientation
=
imageDirectory
.
getInt
(
ExifIFD0Directory
.
TAG_ORIENTATION
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"读取图片方向error:{}"
,
e
);
}
switch
(
orientation
)
{
case
5
:
// - PI/2 and Flip X
case
6
:
// -PI/2 and -width
case
7
:
// PI/2 and Flip
case
8
:
// PI / 2
rotation
=
true
;
}
return
rotation
;
}
/**
* 获取展示图片
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
5d33e647
...
...
@@ -1116,8 +1116,9 @@ public class ItemServiceImpl implements ItemService {
InputStream imageStream = bufferedImageToInputStream(bufferedImage, lastKey.substring(1));
qiniuStorage.store(imageStream, file.getSize(), file.getContentType(), keyName);*/
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
,
MediaUtil
.
isRotation
(
file
)
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"url"
,
url
);
return
Result
.
success
(
map
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
View file @
5d33e647
...
...
@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.storage.StorageService
;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.db.dao.dts.DtsStorageDao
;
import
com.wwdz.ch.db.domain.Storage
;
...
...
@@ -78,7 +79,7 @@ public class WxStorageController {
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
originalFilename
,
MediaUtil
.
isRotation
(
file
)
);
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"url"
,
url
);
...
...
ch-wx-api/src/main/resources/瓷器短信表.xlsx
deleted
100644 → 0
View file @
c57cfa0b
File deleted
ch-wx-api/src/test/java/com/wwdz/ch/wx/api/WxPayServiceTest.java
View file @
5d33e647
...
...
@@ -89,12 +89,12 @@ public class WxPayServiceTest {
@Test
public
void
refund
()
{
List
<
String
>
list
=
Arrays
.
asList
(
"DA2408
041940485642547
"
);
List
<
String
>
list
=
Arrays
.
asList
(
"DA2408
162000075498680
"
);
list
.
forEach
(
orderId
->{
DistributionOrderRequestDto
dto
=
new
DistributionOrderRequestDto
();
dto
.
setDistributionOrderId
(
orderId
);
dto
.
setAmount
(
"
26
0"
);
dto
.
setRefundPrice
(
"
26
0"
);
dto
.
setAmount
(
"
43
0"
);
dto
.
setRefundPrice
(
"
43
0"
);
Result
result
=
wxPayServiceApi
.
refund
(
dto
);
logger
.
info
(
"申请微信支付退款:{}"
,
result
);
});
...
...
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