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
2ac38974
Commit
2ac38974
authored
Jul 08, 2019
by
裴大威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat 1001121
parent
f83fcd71
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
3 deletions
+104
-3
BookAuthInfoBizImpl.java
...m/pcloud/book/copyright/biz/impl/BookAuthInfoBizImpl.java
+4
-0
CopyrightTools.java
.../java/com/pcloud/book/copyright/tools/CopyrightTools.java
+100
-3
No files found.
pcloud-service-book/src/main/java/com/pcloud/book/copyright/biz/impl/BookAuthInfoBizImpl.java
View file @
2ac38974
...
@@ -183,6 +183,10 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
...
@@ -183,6 +183,10 @@ public class BookAuthInfoBizImpl implements BookAuthInfoBiz {
String
url
=
generateExcel
(
bookAuthCodes
,
bookDto
.
getBookName
());
String
url
=
generateExcel
(
bookAuthCodes
,
bookDto
.
getBookName
());
String
zipUrl
=
CopyrightTools
.
generateBar4Zip
(
bookAuthCodes
,
bookDto
.
getBookName
(),
url
);
String
zipUrl
=
CopyrightTools
.
generateBar4Zip
(
bookAuthCodes
,
bookDto
.
getBookName
(),
url
);
noticeUrl
=
zipUrl
;
noticeUrl
=
zipUrl
;
}
else
if
(
isHaveBarCode
.
equals
(
2
)){
String
url
=
generateExcel
(
bookAuthCodes
,
bookDto
.
getBookName
());
String
zipUrl
=
CopyrightTools
.
generateQrcode4Zip
(
bookAuthCodes
,
bookDto
.
getBookName
(),
url
);
noticeUrl
=
zipUrl
;
}
else
{
}
else
{
String
url
=
generateExcel
(
bookAuthCodes
,
bookDto
.
getBookName
());
String
url
=
generateExcel
(
bookAuthCodes
,
bookDto
.
getBookName
());
noticeUrl
=
url
;
noticeUrl
=
url
;
...
...
pcloud-service-book/src/main/java/com/pcloud/book/copyright/tools/CopyrightTools.java
View file @
2ac38974
package
com
.
pcloud
.
book
.
copyright
.
tools
;
package
com
.
pcloud
.
book
.
copyright
.
tools
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.MultiFormatWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
com.pcloud.book.book.constant.BookConstant
;
import
com.pcloud.book.book.constant.BookConstant
;
import
com.pcloud.book.copyright.dto.DateDTO
;
import
com.pcloud.book.copyright.dto.DateDTO
;
import
com.pcloud.book.copyright.entity.BookAuthCode
;
import
com.pcloud.book.copyright.entity.BookAuthCode
;
...
@@ -14,6 +20,7 @@ import com.pcloud.common.utils.LocalDateUtils;
...
@@ -14,6 +20,7 @@ import com.pcloud.common.utils.LocalDateUtils;
import
com.pcloud.common.utils.UUIDUitl
;
import
com.pcloud.common.utils.UUIDUitl
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.zip.CompressUtils
;
import
com.pcloud.common.utils.zip.CompressUtils
;
import
org.jbarcode.JBarcode
;
import
org.jbarcode.JBarcode
;
import
org.jbarcode.encode.Code128Encoder
;
import
org.jbarcode.encode.Code128Encoder
;
import
org.jbarcode.paint.BaseLineTextPainter
;
import
org.jbarcode.paint.BaseLineTextPainter
;
...
@@ -23,7 +30,6 @@ import org.slf4j.Logger;
...
@@ -23,7 +30,6 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
...
@@ -38,6 +44,8 @@ import java.util.Map;
...
@@ -38,6 +44,8 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.UUID
;
import
javax.imageio.ImageIO
;
/**
/**
* @author lily
* @author lily
* @date 2018/12/4 16:37
* @date 2018/12/4 16:37
...
@@ -66,12 +74,13 @@ public class CopyrightTools {
...
@@ -66,12 +74,13 @@ public class CopyrightTools {
return
shortBuffer
.
toString
().
toLowerCase
();
return
shortBuffer
.
toString
().
toLowerCase
();
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
long
time
=
System
.
currentTimeMillis
();
long
time
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
createShortUuidByCount
(
100000
));
System
.
out
.
println
(
createShortUuidByCount
(
100000
));
long
time1
=
System
.
currentTimeMillis
();
long
time1
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
time1
-
time
);
System
.
out
.
println
(
time1
-
time
);
}
}
/**
/**
* 生成count位非重复的数
* 生成count位非重复的数
*
*
...
@@ -108,6 +117,13 @@ public class CopyrightTools {
...
@@ -108,6 +117,13 @@ public class CopyrightTools {
}
}
}
}
/**
* 生成条形码
* @param bookAuthCodes
* @param fileName
* @param excelUrl
* @return
*/
public
static
String
generateBar4Zip
(
List
<
BookAuthCode
>
bookAuthCodes
,
String
fileName
,
String
excelUrl
)
{
public
static
String
generateBar4Zip
(
List
<
BookAuthCode
>
bookAuthCodes
,
String
fileName
,
String
excelUrl
)
{
fileName
=
FileUtils
.
formatName
(
fileName
);
fileName
=
FileUtils
.
formatName
(
fileName
);
String
tempZipName
=
fileName
+
"_"
+
LocalDateUtils
.
getYmdhmss
();
String
tempZipName
=
fileName
+
"_"
+
LocalDateUtils
.
getYmdhmss
();
...
@@ -147,6 +163,66 @@ public class CopyrightTools {
...
@@ -147,6 +163,66 @@ public class CopyrightTools {
return
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
return
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
}
}
/**
* 生成二维码
* @param bookAuthCodes
* @param fileName
* @param excelUrl
* @return
*/
public
static
String
generateQrcode4Zip
(
List
<
BookAuthCode
>
bookAuthCodes
,
String
fileName
,
String
excelUrl
)
{
fileName
=
FileUtils
.
formatName
(
fileName
);
String
tempZipName
=
fileName
+
"_"
+
LocalDateUtils
.
getYmdhmss
();
String
zipFilePath
=
ZIP_FILE_PATH
+
tempZipName
+
".zip"
;
String
fileFolderPath
=
FILE_LOCAL_PATH
+
tempZipName
;
FileUtils
.
isDir
(
fileFolderPath
);
UploadResultInfo
uploadResultInfo
;
try
{
for
(
BookAuthCode
bookAuthCode
:
bookAuthCodes
)
{
LOGGER
.
info
(
"【二维码】generateQrcode4Zip,<START>.[url]="
+
bookAuthCode
);
Map
<
EncodeHintType
,
Object
>
hints
=
new
HashMap
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
ErrorCorrectionLevel
.
H
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
0
);
// 设置白边
try
{
// 生成矩阵
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
bookAuthCode
.
getFullCode
(),
BarcodeFormat
.
QR_CODE
,
55
,
55
,
hints
);
int
width
=
bitMatrix
.
getWidth
();
int
height
=
bitMatrix
.
getHeight
();
BufferedImage
bufferedImage
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
width
;
x
++){
for
(
int
y
=
0
;
y
<
height
;
y
++){
bufferedImage
.
setRGB
(
x
,
y
,
bitMatrix
.
get
(
x
,
y
)
?
0xFF000000
:
0xFFFFFFFF
);
}
}
// paintQrcodeText(bufferedImage, bookAuthCode.getFullCode());
File
file
=
new
File
(
fileFolderPath
+
"/"
+
bookAuthCode
.
getFullCode
()
+
".png"
);
ImageIO
.
write
(
bufferedImage
,
ImageTypeEnum
.
PNG
.
value
,
file
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【二维码】创建二维码失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
FILE_UPLOAD_FAILURE
,
"创建二维码失败"
);
}
}
String
downloadLocalPath
=
fileFolderPath
+
"/"
+
fileName
+
".xls"
;
FileUtils
.
downloadFileFromUrl
(
excelUrl
,
downloadLocalPath
);
// 检查压缩包临时文件夹是否存在,不存在就创建
FileUtils
.
isDir
(
ZIP_FILE_PATH
);
CompressUtils
.
zip
(
fileFolderPath
,
zipFilePath
);
// 上传文件到服务器中
uploadResultInfo
=
OssUtils
.
uploadLocalFile4CustomName
(
zipFilePath
,
fileName
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"【压缩】压缩失败,<ERROR>:"
+
e
.
getMessage
(),
e
);
throw
new
FileException
(
FileException
.
ZIP_ERROR
,
"压缩失败!"
);
}
finally
{
// 删除产生的文件
FileUtils
.
deleteDirectory
(
fileFolderPath
);
FileUtils
.
deleteFile
(
zipFilePath
);
}
return
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
}
public
static
String
uploadImage
(
BufferedImage
image
)
throws
BizException
{
public
static
String
uploadImage
(
BufferedImage
image
)
throws
BizException
{
UploadResultInfo
uploadResultInfo
=
null
;
UploadResultInfo
uploadResultInfo
=
null
;
...
@@ -207,6 +283,27 @@ public class CopyrightTools {
...
@@ -207,6 +283,27 @@ public class CopyrightTools {
// g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
// g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
// }
// }
public
static
void
paintQrcodeText
(
BufferedImage
barCodeImage
,
String
text
)
{
//绘图
Graphics
g2d
=
barCodeImage
.
getGraphics
();
//创建字体
Font
font
=
new
Font
(
"console"
,
Font
.
PLAIN
,
5
);
g2d
.
setFont
(
font
);
FontMetrics
fm
=
g2d
.
getFontMetrics
();
int
height
=
fm
.
getHeight
();
// int center = (barCodeImage.getWidth() - fm.stringWidth(text)) / 2;
g2d
.
setColor
(
Color
.
WHITE
);
g2d
.
fillRect
(
0
,
0
,
barCodeImage
.
getWidth
(),
barCodeImage
.
getHeight
()
/
20
);
g2d
.
fillRect
(
0
,
barCodeImage
.
getHeight
()
-
(
height
*
9
/
10
),
barCodeImage
.
getWidth
(),
(
height
*
9
/
10
));
g2d
.
setColor
(
Color
.
BLACK
);
//g2d.drawString(text, center, barCodeImage.getHeight() - (height / 10) - 2);
int
start
=
17
;
int
length
=
(
barCodeImage
.
getWidth
()
-
2
*
start
)
/
text
.
length
();
for
(
int
i
=
0
;
i
<
text
.
length
();
i
++)
{
g2d
.
drawString
(
text
.
substring
(
i
,
i
+
1
),
start
+
i
*
length
,
barCodeImage
.
getHeight
()
-
(
height
/
10
)
-
2
);
}
}
public
static
void
paintText
(
BufferedImage
barCodeImage
,
String
text
)
{
public
static
void
paintText
(
BufferedImage
barCodeImage
,
String
text
)
{
//绘图
//绘图
Graphics
g2d
=
barCodeImage
.
getGraphics
();
Graphics
g2d
=
barCodeImage
.
getGraphics
();
...
...
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