Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
chnmuseum-party
Project
Project
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
liqin
chnmuseum-party
Commits
3759d134
Commit
3759d134
authored
Apr 14, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
229c4937
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
4 additions
and
906 deletions
+4
-906
pom.xml
pom.xml
+4
-16
QRCodeUtil.java
.../cn/wisenergy/chnmuseum/party/common/util/QRCodeUtil.java
+0
-252
QRCodeUtils.java
...cn/wisenergy/chnmuseum/party/common/util/QRCodeUtils.java
+0
-244
TestQR.java
...java/cn/wisenergy/chnmuseum/party/common/util/TestQR.java
+0
-73
DemandInfoController.java
.../chnmuseum/party/web/controller/DemandInfoController.java
+0
-321
No files found.
pom.xml
View file @
3759d134
...
...
@@ -69,13 +69,13 @@
<!-- General Mapper -->
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-
boot-starte
r
</artifactId>
<version>
3.4.
2
</version>
<artifactId>
mybatis-plus-
generato
r
</artifactId>
<version>
3.4.
1
</version>
</dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<artifactId>
mybatis-plus-
generato
r
</artifactId>
<version>
3.4.
1
</version>
<artifactId>
mybatis-plus-
boot-starte
r
</artifactId>
<version>
3.4.
2
</version>
</dependency>
<!-- MySQL JDBC Driver -->
<dependency>
...
...
@@ -242,18 +242,6 @@
<version>
2.3
</version>
<scope>
provided
</scope>
</dependency>
<!-- QR Generator -->
<dependency>
<groupId>
com.google.zxing
</groupId>
<artifactId>
javase
</artifactId>
<version>
3.4.1
</version>
</dependency>
<!-- Emoji Support -->
<dependency>
<groupId>
com.vdurmont
</groupId>
<artifactId>
emoji-java
</artifactId>
<version>
5.1.1
</version>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/util/QRCodeUtil.java
deleted
100644 → 0
View file @
229c4937
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
import
com.google.zxing.*
;
import
com.google.zxing.client.j2se.BufferedImageLuminanceSource
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.common.HybridBinarizer
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.geom.RoundRectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.OutputStream
;
import
java.net.URL
;
import
java.util.Hashtable
;
import
java.util.Random
;
public
class
QRCodeUtil
{
private
static
final
String
CHARSET
=
"utf-8"
;
private
static
final
String
FORMAT_NAME
=
"JPG"
;
// 二维码尺寸
private
static
final
int
QRCODE_SIZE
=
300
;
// LOGO宽度
private
static
final
int
WIDTH
=
60
;
// LOGO高度
private
static
final
int
HEIGHT
=
60
;
private
static
BufferedImage
createImage
(
String
content
,
String
imgPath
,
boolean
needCompress
)
throws
Exception
{
Hashtable
<
EncodeHintType
,
Object
>
hints
=
new
Hashtable
<
EncodeHintType
,
Object
>();
hints
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
ErrorCorrectionLevel
.
H
);
hints
.
put
(
EncodeHintType
.
CHARACTER_SET
,
CHARSET
);
hints
.
put
(
EncodeHintType
.
MARGIN
,
1
);
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
QRCODE_SIZE
,
QRCODE_SIZE
,
hints
);
int
width
=
bitMatrix
.
getWidth
();
int
height
=
bitMatrix
.
getHeight
();
BufferedImage
image
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
for
(
int
x
=
0
;
x
<
width
;
x
++)
{
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
image
.
setRGB
(
x
,
y
,
bitMatrix
.
get
(
x
,
y
)
?
0xFF000000
:
0xFFFFFFFF
);
}
}
if
(
imgPath
==
null
||
""
.
equals
(
imgPath
))
{
return
image
;
}
// 插入图片
QRCodeUtil
.
insertImage
(
image
,
imgPath
,
needCompress
);
return
image
;
}
/**
* 插入LOGO
*
* @param source 二维码图片
* @param imgPath LOGO图片地址
* @param needCompress 是否压缩
* @throws Exception
*/
private
static
void
insertImage
(
BufferedImage
source
,
String
imgPath
,
boolean
needCompress
)
throws
Exception
{
// File file = new File(imgPath);
// if (!file.exists()) {
// System.err.println("" + imgPath + " 该文件不存在!");
// return;
// }
Image
src
=
ImageIO
.
read
(
new
URL
(
imgPath
));
int
width
=
src
.
getWidth
(
null
);
int
height
=
src
.
getHeight
(
null
);
if
(
needCompress
)
{
// 压缩LOGO
if
(
width
>
WIDTH
)
{
width
=
WIDTH
;
}
if
(
height
>
HEIGHT
)
{
height
=
HEIGHT
;
}
Image
image
=
src
.
getScaledInstance
(
width
,
height
,
Image
.
SCALE_SMOOTH
);
BufferedImage
tag
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics
g
=
tag
.
getGraphics
();
g
.
drawImage
(
image
,
0
,
0
,
null
);
// 绘制缩小后的图
g
.
dispose
();
src
=
image
;
}
// 插入LOGO
Graphics2D
graph
=
source
.
createGraphics
();
int
x
=
(
QRCODE_SIZE
-
width
)
/
2
;
int
y
=
(
QRCODE_SIZE
-
height
)
/
2
;
graph
.
drawImage
(
src
,
x
,
y
,
width
,
height
,
null
);
Shape
shape
=
new
RoundRectangle2D
.
Float
(
x
,
y
,
width
,
width
,
6
,
6
);
graph
.
setStroke
(
new
BasicStroke
(
3
f
));
graph
.
draw
(
shape
);
graph
.
dispose
();
}
/**
* 生成二维码(内嵌LOGO)
*
* @param content 内容
* @param imgPath LOGO地址
* @param destPath 存放目录
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
imgPath
,
String
destPath
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtil
.
createImage
(
content
,
imgPath
,
needCompress
);
mkdirs
(
destPath
);
String
file
=
new
Random
().
nextInt
(
99999999
)
+
".jpg"
;
ImageIO
.
write
(
image
,
FORMAT_NAME
,
new
File
(
destPath
+
"/"
+
file
));
}
/**
* 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
*
* @param destPath 存放目录
* @author lanyuan
* Email: mmm333zzz520@163.com
* @date 2013-12-11 上午10:16:36
*/
public
static
void
mkdirs
(
String
destPath
)
{
File
file
=
new
File
(
destPath
);
//当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
if
(!
file
.
exists
()
&&
!
file
.
isDirectory
())
{
file
.
mkdirs
();
}
}
/**
* 生成二维码(内嵌LOGO)
*
* @param content 内容
* @param imgPath LOGO地址
* @param destPath 存储地址
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
imgPath
,
String
destPath
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
imgPath
,
destPath
,
false
);
}
/**
* 生成二维码
*
* @param content 内容
* @param destPath 存储地址
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
destPath
,
boolean
needCompress
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
null
,
destPath
,
needCompress
);
}
/**
* 生成二维码
*
* @param content 内容
* @param destPath 存储地址
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
destPath
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
null
,
destPath
,
false
);
}
/**
* 生成二维码(内嵌LOGO)
*
* @param content 内容
* @param imgPath LOGO地址
* @param output 输出流
* @param needCompress 是否压缩LOGO
* @throws Exception
*/
public
static
void
encode
(
String
content
,
String
imgPath
,
OutputStream
output
,
boolean
needCompress
)
throws
Exception
{
BufferedImage
image
=
QRCodeUtil
.
createImage
(
content
,
imgPath
,
needCompress
);
ImageIO
.
write
(
image
,
FORMAT_NAME
,
output
);
}
/**
* 生成二维码
*
* @param content 内容
* @param output 输出流
* @throws Exception
*/
public
static
void
encode
(
String
content
,
OutputStream
output
)
throws
Exception
{
QRCodeUtil
.
encode
(
content
,
null
,
output
,
false
);
}
/**
* 解析二维码
*
* @param file 二维码图片
* @return
* @throws Exception
*/
public
static
String
decode
(
File
file
)
throws
Exception
{
BufferedImage
image
;
image
=
ImageIO
.
read
(
file
);
if
(
image
==
null
)
{
return
null
;
}
BufferedImageLuminanceSource
source
=
new
BufferedImageLuminanceSource
(
image
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
Result
result
;
Hashtable
<
DecodeHintType
,
Object
>
hints
=
new
Hashtable
<
DecodeHintType
,
Object
>();
hints
.
put
(
DecodeHintType
.
CHARACTER_SET
,
CHARSET
);
result
=
new
MultiFormatReader
().
decode
(
bitmap
,
hints
);
String
resultStr
=
result
.
getText
();
return
resultStr
;
}
/**
* 解析二维码
*
* @param path 二维码图片地址
* @return
* @throws Exception
*/
public
static
String
decode
(
String
path
)
throws
Exception
{
return
QRCodeUtil
.
decode
(
new
File
(
path
));
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
// String text = "杨建龙" + "杨智平"; //这里设置自定义网站url
// String logoPath = "http://40.125.210.149/group1/M00/00/35/CgAMBFuvKQmAC3ynAABTy6wx-K4542.jpg";
// String destPath = "d:\\";
// Image logoPath = ImageIO.read(new URL("http://40.125.210.149/group1/M00/00/35/CgAMBFuvKQmAC3ynAABTy6wx-K4542.jpg"));
// QRCodeUtil.encode(text, destPath, true);
// QRCodeUtil.encode(text, logoPath, destPath,true);
// String imagePath = "d:\\95413982.jpg";
// String ret = QRCodeUtil.decode(imagePath);
// System.out.println(ret);
String
text
=
"杨建龙"
+
"杨智平"
;
String
logoPath
=
"http://40.125.210.149/group1/M00/00/35/CgAMBFuvKQmAC3ynAABTy6wx-K4542.jpg"
;
String
destPath
=
"d:\\"
;
QRCodeUtil
.
encode
(
text
,
logoPath
,
destPath
,
true
);
int
祖
=
2289
;
}
}
\ No newline at end of file
src/main/java/cn/wisenergy/chnmuseum/party/common/util/QRCodeUtils.java
deleted
100644 → 0
View file @
229c4937
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.OutputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.imageio.ImageIO
;
import
com.google.zxing.BarcodeFormat
;
import
com.google.zxing.Binarizer
;
import
com.google.zxing.BinaryBitmap
;
import
com.google.zxing.DecodeHintType
;
import
com.google.zxing.EncodeHintType
;
import
com.google.zxing.LuminanceSource
;
import
com.google.zxing.MultiFormatReader
;
import
com.google.zxing.MultiFormatWriter
;
import
com.google.zxing.Result
;
import
com.google.zxing.WriterException
;
import
com.google.zxing.client.j2se.BufferedImageLuminanceSource
;
import
com.google.zxing.client.j2se.MatrixToImageWriter
;
import
com.google.zxing.common.BitMatrix
;
import
com.google.zxing.common.HybridBinarizer
;
import
com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
;
/**
* <p>
* 二维码工具类(使用ZXingjar包)
* </p>
*
* @author Tom
* @since 2018/9/29
*/
public
class
QRCodeUtils
{
// 默认宽为300
private
Integer
width
=
300
;
// 默认高为300
private
Integer
height
=
300
;
// 默认二维码图片格式
private
String
imageFormat
=
"png"
;
// 默认二维码字符编码
private
String
charType
=
"utf-8"
;
// 默认二维码的容错级别
private
ErrorCorrectionLevel
corretionLevel
=
ErrorCorrectionLevel
.
H
;
// 二维码与图片的边缘
private
Integer
margin
=
1
;
// 二维码参数
private
Map
<
EncodeHintType
,
Object
>
encodeHits
=
new
HashMap
<>();
//main方法测试工具类
public
static
void
main
(
String
[]
args
)
{
QRCodeUtils
qrCode
=
new
QRCodeUtils
(
300
,
300
);
//设置二维码的边缘为1
qrCode
.
setMargin
(
1
);
//设置输出到桌面
String
path
=
System
.
getProperty
(
"user.home"
)
+
File
.
separator
+
"Desktop"
+
File
.
separator
+
"test.png"
;
//创建图片二维码
qrCode
.
createQrImage
(
"https://www.baidu.com/"
,
path
);
//识别图片二维码的内容
System
.
out
.
println
(
qrCode
.
decodeQrImage
(
new
File
(
path
)));
//https://www.baidu.com/
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
,
String
imageFormat
,
String
charType
,
ErrorCorrectionLevel
corretionLevel
,
Integer
margin
)
{
if
(
width
!=
null
)
{
this
.
width
=
width
;
}
if
(
height
!=
null
)
{
this
.
height
=
height
;
}
if
(
imageFormat
!=
null
)
{
this
.
imageFormat
=
imageFormat
;
}
if
(
charType
!=
null
)
{
this
.
charType
=
charType
;
}
if
(
corretionLevel
!=
null
)
{
this
.
corretionLevel
=
corretionLevel
;
}
if
(
margin
!=
null
)
{
this
.
margin
=
margin
;
}
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
,
String
imageFormat
,
String
charType
,
ErrorCorrectionLevel
corretionLevel
)
{
this
(
width
,
height
,
imageFormat
,
charType
,
corretionLevel
,
null
);
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
,
String
imageFormat
,
String
charType
,
Integer
margin
)
{
this
(
width
,
height
,
imageFormat
,
charType
,
null
,
margin
);
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
,
String
imageFormat
,
String
charType
)
{
this
(
width
,
height
,
imageFormat
,
charType
,
null
,
null
);
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
,
String
imageFormat
)
{
this
(
width
,
height
,
imageFormat
,
null
,
null
,
null
);
}
public
QRCodeUtils
(
Integer
width
,
Integer
height
)
{
this
(
width
,
height
,
null
,
null
,
null
,
null
);
}
public
QRCodeUtils
()
{
}
// 初始化二维码的参数
private
void
initialParamers
()
{
// 字符编码
encodeHits
.
put
(
EncodeHintType
.
CHARACTER_SET
,
this
.
charType
);
// 容错等级 L、M、Q、H 其中 L 为最低, H 为最高
encodeHits
.
put
(
EncodeHintType
.
ERROR_CORRECTION
,
this
.
corretionLevel
);
// 二维码与图片边距
encodeHits
.
put
(
EncodeHintType
.
MARGIN
,
margin
);
}
// 得到二维码图片
public
BufferedImage
getBufferedImage
(
String
content
)
{
initialParamers
();
BufferedImage
bufferedImage
=
null
;
try
{
BitMatrix
bitMatrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
this
.
width
,
this
.
height
,
this
.
encodeHits
);
bufferedImage
=
MatrixToImageWriter
.
toBufferedImage
(
bitMatrix
);
}
catch
(
WriterException
e
)
{
e
.
printStackTrace
();
return
null
;
}
return
bufferedImage
;
}
// 将二维码保存到输出流中
public
void
writeToStream
(
String
content
,
OutputStream
os
)
{
initialParamers
();
try
{
BitMatrix
matrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
this
.
width
,
this
.
height
,
this
.
encodeHits
);
MatrixToImageWriter
.
writeToStream
(
matrix
,
this
.
imageFormat
,
os
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
// 将二维码图片保存为文件
public
void
createQrImage
(
String
content
,
File
file
)
{
initialParamers
();
try
{
BitMatrix
matrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
this
.
width
,
this
.
height
,
this
.
encodeHits
);
MatrixToImageWriter
.
writeToFile
(
matrix
,
this
.
imageFormat
,
file
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
// 将二维码图片保存到指定路径
public
void
createQrImage
(
String
content
,
String
path
)
{
initialParamers
();
try
{
BitMatrix
matrix
=
new
MultiFormatWriter
().
encode
(
content
,
BarcodeFormat
.
QR_CODE
,
this
.
width
,
this
.
height
,
this
.
encodeHits
);
MatrixToImageWriter
.
writeToPath
(
matrix
,
this
.
imageFormat
,
new
File
(
path
).
toPath
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//识别图片二维码
public
String
decodeQrImage
(
File
file
)
{
String
content
=
null
;
try
{
BufferedImage
bufferedImage
=
ImageIO
.
read
(
new
FileInputStream
(
file
));
LuminanceSource
source
=
new
BufferedImageLuminanceSource
(
bufferedImage
);
Binarizer
binarizer
=
new
HybridBinarizer
(
source
);
BinaryBitmap
image
=
new
BinaryBitmap
(
binarizer
);
Map
<
DecodeHintType
,
Object
>
decodeHits
=
new
HashMap
<>();
decodeHits
.
put
(
DecodeHintType
.
CHARACTER_SET
,
this
.
charType
);
Result
result
=
new
MultiFormatReader
().
decode
(
image
,
decodeHits
);
content
=
result
.
getText
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
content
;
}
public
Integer
getWidth
()
{
return
width
;
}
public
void
setWidth
(
Integer
width
)
{
this
.
width
=
width
;
}
public
Integer
getHeight
()
{
return
height
;
}
public
void
setHeight
(
Integer
height
)
{
this
.
height
=
height
;
}
public
String
getImageFormat
()
{
return
imageFormat
;
}
public
void
setImageFormat
(
String
imageFormat
)
{
this
.
imageFormat
=
imageFormat
;
}
public
String
getCharType
()
{
return
charType
;
}
public
void
setCharType
(
String
charType
)
{
this
.
charType
=
charType
;
}
public
ErrorCorrectionLevel
getCorretionLevel
()
{
return
corretionLevel
;
}
public
void
setCorretionLevel
(
ErrorCorrectionLevel
corretionLevel
)
{
this
.
corretionLevel
=
corretionLevel
;
}
public
Integer
getMargin
()
{
return
margin
;
}
public
void
setMargin
(
Integer
margin
)
{
this
.
margin
=
margin
;
}
public
Map
<
EncodeHintType
,
Object
>
getHits
()
{
return
encodeHits
;
}
public
void
setHits
(
Map
<
EncodeHintType
,
Object
>
hits
)
{
this
.
encodeHits
=
hits
;
}
}
src/main/java/cn/wisenergy/chnmuseum/party/common/util/TestQR.java
deleted
100644 → 0
View file @
229c4937
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
//package com.cmbchina.business.hall.common.util;
//
//
//
//import java.awt.Color;
//import java.awt.Graphics2D;
//import java.awt.image.BufferedImage;
//
//import javax.imageio.ImageIO;
//import javax.servlet.http.HttpServletResponse;
//
//import com.swetake.util.Qrcode;
//
///**
// * <p>
// *
// * </p>
// *
// * @author Tom
// * @since 2018/9/30
// */
//public class EncoderHandler {
//
// public void encoderQRCoder(String content, HttpServletResponse response) {
// try {
// Qrcode handler = new Qrcode();
// handler.setQrcodeErrorCorrect('M');
// handler.setQrcodeEncodeMode('B');
// handler.setQrcodeVersion(7);
//
// System.out.println(content);
// byte[] contentBytes = content.getBytes("UTF-8");
//
// BufferedImage bufImg = new BufferedImage(80, 80, BufferedImage.TYPE_INT_RGB);
//
// Graphics2D gs = bufImg.createGraphics();
//
// gs.setBackground(Color.WHITE);
// gs.clearRect(0, 0, 140, 140);
//
// //设定图像颜色:BLACK
// gs.setColor(Color.BLACK);
//
// //设置偏移量 不设置肯能导致解析出错
// int pixoff = 2;
// //输出内容:二维码
// if(contentBytes.length > 0 && contentBytes.length < 124) {
// boolean[][] codeOut = handler.calQrcode(contentBytes);
// for(int i = 0; i < codeOut.length; i++) {
// for(int j = 0; j < codeOut.length; j++) {
// if(codeOut[j][i]) {
// gs.fillRect(j * 3 + pixoff, i * 3 + pixoff,3, 3);
// }
// }
// }
// } else {
// System.err.println("QRCode content bytes length = " + contentBytes.length + " not in [ 0,120 ]. ");
// }
//
// gs.dispose();
// bufImg.flush();
//
//
//
// //生成二维码QRCode图片
// ImageIO.write(bufImg, "jpg", response.getOutputStream());
//
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//}
src/main/java/cn/wisenergy/chnmuseum/party/web/controller/DemandInfoController.java
deleted
100644 → 0
View file @
229c4937
package
cn
.
wisenergy
.
chnmuseum
.
party
.
web
.
controller
;
import
cn.wisenergy.chnmuseum.party.model.DemandInfo
;
import
cn.wisenergy.chnmuseum.party.model.Employee
;
import
cn.wisenergy.chnmuseum.party.service.impl.DemandInfoServiceImpl
;
import
cn.wisenergy.chnmuseum.party.service.impl.EmployeeServiceImpl
;
import
cn.wisenergy.chnmuseum.party.web.controller.base.BaseController
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.vdurmont.emoji.EmojiParser
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.shiro.authz.annotation.RequiresAuthentication
;
import
org.apache.shiro.authz.annotation.RequiresPermissions
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
import
java.util.Date
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* <p>
* 需求建议信息 前端控制器
* </p>
*
* @author 杨智平
* @since 2018-08-29
*/
@Api
(
tags
=
"呼叫服务或者吐槽建议"
)
@RestController
@RequestMapping
(
"/demandInfo"
)
public
class
DemandInfoController
extends
BaseController
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EmployeeController
.
class
);
@Resource
private
DemandInfoServiceImpl
demandInfoService
;
@Resource
private
EmployeeServiceImpl
employeeService
;
/**
* 获取单个呼叫服务或者吐槽建议
*
* @param id
* @return
*/
@ApiOperation
(
value
=
"获取单个呼叫服务或者吐槽建议"
)
@GetMapping
(
value
=
"/getById"
)
@RequiresAuthentication
//@RequiresPermissions("/demandInfo/getById")
public
ResponseEntity
<
DemandInfo
>
getById
(
String
id
)
{
try
{
DemandInfo
one
=
this
.
demandInfoService
.
selectOneById
(
id
);
if
(
null
!=
one
)
{
one
.
setContent
(
EmojiParser
.
parseToUnicode
(
one
.
getContent
()));
if
(
StringUtils
.
isNotBlank
(
one
.
getFeedbackInfo
()))
{
one
.
setFeedbackInfo
(
EmojiParser
.
parseToUnicode
(
one
.
getFeedbackInfo
()));
}
return
ResponseEntity
.
ok
(
one
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
(
null
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取单个呼叫服务或者吐槽建议出错!"
,
e
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
/**
* 获取呼叫服务或者吐槽建议列表
*
* @param lineNumber
* @param content
* @param phoneNumber
* @param type
* @param time
* @return
*/
@ApiOperation
(
value
=
"获取呼叫服务或者吐槽建议列表"
)
@GetMapping
(
value
=
"/getList"
)
@RequiresAuthentication
//@RequiresPermissions("/demandInfo/getList")
@ApiImplicitParams
(
value
=
{
@ApiImplicitParam
(
name
=
"lineNumber"
,
value
=
"叫号单号"
,
required
=
false
),
@ApiImplicitParam
(
name
=
"content"
,
value
=
"需求内容"
,
required
=
false
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"phoneNumber"
,
value
=
"手机号码"
,
required
=
false
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"type"
,
value
=
"消息类型:1-吐槽建议2-呼叫记录"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"time"
,
value
=
"反馈日期"
,
required
=
false
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"callTime"
,
value
=
"呼叫日期"
,
required
=
false
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"bankBranchId"
,
value
=
"归属网点ID"
,
required
=
false
,
dataType
=
"String"
)})
public
ResponseEntity
<
Page
<
DemandInfo
>>
getList
(
String
lineNumber
,
String
content
,
String
phoneNumber
,
Integer
type
,
String
time
,
String
callTime
,
String
bankBranchId
,
String
roleId
,
String
currentBankId
)
{
try
{
if
(!
"3"
.
equals
(
roleId
))
{
roleId
=
"0"
;
}
String
startDate
=
null
;
String
endDate
=
null
;
String
callStartDate
=
null
;
String
callEndDate
=
null
;
if
(
StringUtils
.
isNoneBlank
(
time
))
{
startDate
=
time
+
" 00:00:00"
;
endDate
=
time
+
" 23:59:59"
;
}
if
(
StringUtils
.
isNoneBlank
(
callTime
))
{
callStartDate
=
callTime
+
" 00:00:00"
;
callEndDate
=
callTime
+
" 23:59:59"
;
}
lineNumber
=
StringUtils
.
trimToNull
(
lineNumber
);
// 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
content
=
StringUtils
.
trimToNull
(
content
);
phoneNumber
=
StringUtils
.
trimToNull
(
phoneNumber
);
Page
<
DemandInfo
>
page
=
this
.
getPage
();
Page
<
DemandInfo
>
demandInfoPage
=
this
.
demandInfoService
.
selectDemandInfoList
(
page
,
lineNumber
,
content
,
phoneNumber
,
startDate
,
endDate
,
type
,
bankBranchId
,
callStartDate
,
callEndDate
,
roleId
,
currentBankId
);
for
(
DemandInfo
demandInfo
:
demandInfoPage
.
getRecords
())
{
demandInfo
.
setContent
(
EmojiParser
.
parseToUnicode
(
demandInfo
.
getContent
()));
if
(
StringUtils
.
isNotBlank
(
demandInfo
.
getFeedbackInfo
()))
{
demandInfo
.
setFeedbackInfo
(
EmojiParser
.
parseToUnicode
(
demandInfo
.
getFeedbackInfo
()));
}
}
return
ResponseEntity
.
ok
(
demandInfoPage
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"服务器错误!"
,
e
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
/**
* 添加
*/
@Transactional
@ApiOperation
(
"APP端添加吐槽建议或者呼叫记录"
)
@PostMapping
(
value
=
"/add"
)
@ApiImplicitParams
(
value
=
{
@ApiImplicitParam
(
name
=
"lineNumber"
,
value
=
"叫号单号"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"content"
,
value
=
"需求内容"
,
required
=
true
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"phoneNumber"
,
value
=
"手机号码"
,
required
=
true
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"type"
,
value
=
"消息类型:1-吐槽建议2-呼叫记录"
,
required
=
true
)})
public
ResponseEntity
<
Map
<
String
,
Object
>>
add
(
DemandInfo
demandInfo
)
{
Map
<
String
,
Object
>
resultMap
=
new
LinkedHashMap
<
String
,
Object
>();
try
{
boolean
ret
=
false
;
//接收人员工号,多人使用|分割,如"01014760|01158451"
String
recUsrNbr
=
""
;
//反馈人ID
String
personId
=
""
;
if
(
demandInfo
.
getBankBranchId
()
!=
null
)
{
Employee
emp
=
this
.
employeeService
.
getEmpCodeBybankId
(
demandInfo
.
getBankBranchId
());
if
(
emp
!=
null
)
{
recUsrNbr
=
emp
.
getCode
();
personId
=
emp
.
getId
();
//现在改为反馈的时候再存入反馈人ID
// demandInfo.setFeedbackPersonId(emp.getId());
}
}
demandInfo
.
setLineNumber
(
StringUtils
.
trimToNull
(
demandInfo
.
getLineNumber
()));
// 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
demandInfo
.
setContent
(
EmojiParser
.
parseToHtmlHexadecimal
(
demandInfo
.
getContent
().
trim
()));
demandInfo
.
setPhoneNumber
(
StringUtils
.
trimToNull
(
demandInfo
.
getPhoneNumber
()));
demandInfo
.
setCreateTime
(
new
Date
(
System
.
currentTimeMillis
()));
ret
=
this
.
demandInfoService
.
save
(
demandInfo
);
if
(!
ret
)
{
resultMap
.
put
(
"status"
,
400
);
resultMap
.
put
(
"message"
,
"提交失败"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
resultMap
);
}
if
(!
""
.
equals
(
recUsrNbr
))
{
//招乎正文,要求以[发送人姓名OR发送人部室]正文格式
String
zhCnt
=
""
;
if
(
demandInfo
.
getType
()
==
1
)
{
//吐槽建议
zhCnt
=
"客户"
+
demandInfo
.
getLineNumber
()
+
"号("
+
demandInfo
.
getPhoneNumber
()
+
")有吐槽建议,请及时反馈改进,"
+
"并点击链接"
+
demandInfo
.
getId
()
+
"&personId="
+
personId
+
"及时回复客户。"
;
}
else
if
(
demandInfo
.
getType
()
==
2
)
{
//呼叫大堂
zhCnt
=
"客户"
+
demandInfo
.
getLineNumber
()
+
"号("
+
demandInfo
.
getPhoneNumber
()
+
")呼叫大堂,内容为'"
+
demandInfo
.
getContent
()
+
"',请及时服务接待!"
;
}
logger
.
info
(
zhCnt
);
}
// 201
resultMap
.
put
(
"status"
,
200
);
resultMap
.
put
(
"message"
,
"提交成功"
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
resultMap
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"提交错误!"
,
e
);
}
resultMap
.
put
(
"status"
,
500
);
resultMap
.
put
(
"message"
,
"操作失败"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
@ApiOperation
(
value
=
"填写反馈内容"
)
@PutMapping
(
value
=
"/edit"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
edit
(
String
id
,
String
feedbackInfo
,
String
personId
)
{
Map
<
String
,
Object
>
resultMap
=
new
LinkedHashMap
<
String
,
Object
>();
try
{
if
(!
StringUtils
.
isNoneBlank
(
id
))
{
resultMap
.
put
(
"status"
,
400
);
resultMap
.
put
(
"message"
,
"页面信息失效,请重新点击链接进入"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
resultMap
);
}
//验证反馈人是否存在
Employee
employee
=
employeeService
.
getById
(
personId
);
if
(
employee
==
null
)
{
resultMap
.
put
(
"status"
,
400
);
resultMap
.
put
(
"message"
,
"反馈链接有误"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
resultMap
);
}
if
(!
StringUtils
.
isNoneBlank
(
feedbackInfo
))
{
resultMap
.
put
(
"status"
,
400
);
resultMap
.
put
(
"message"
,
"请输入反馈内容"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
resultMap
);
}
else
{
feedbackInfo
=
StringUtils
.
trimToNull
(
feedbackInfo
);
// 清除掉str首尾的空白字符,如果仅str全由空白字符组成则返回null
}
DemandInfo
entity
=
this
.
demandInfoService
.
getById
(
id
);
if
(
entity
.
getFeedbackInfo
()
!=
null
)
{
resultMap
.
put
(
"status"
,
400
);
resultMap
.
put
(
"message"
,
"您已反馈,请勿重复提交!"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
resultMap
);
}
//保存反馈人ID
entity
.
setFeedbackPersonId
(
personId
);
entity
.
setFeedbackTime
(
new
Date
(
System
.
currentTimeMillis
()));
entity
.
setFeedbackInfo
(
EmojiParser
.
parseToHtmlHexadecimal
(
feedbackInfo
.
trim
()));
boolean
ret
=
this
.
demandInfoService
.
updateById
(
entity
);
if
(!
ret
)
{
resultMap
.
put
(
"status"
,
500
);
resultMap
.
put
(
"message"
,
"反馈失败"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
else
{
resultMap
.
put
(
"status"
,
200
);
resultMap
.
put
(
"message"
,
"反馈成功"
);
return
ResponseEntity
.
ok
(
resultMap
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"反馈错误!"
,
e
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
resultMap
);
}
/**
* App获取呼叫服务或者吐槽建议列表
*
* @param type
* @param advisorId
* @param bankBranchId
* @return
*/
@ApiOperation
(
value
=
"App获取呼叫服务或者吐槽建议列表"
)
@GetMapping
(
value
=
"/getListOnApp"
)
@ApiImplicitParams
(
value
=
{
@ApiImplicitParam
(
name
=
"type"
,
value
=
"消息类型:1-吐槽建议2-呼叫记录"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"advisorId"
,
value
=
"发送人ID(当前登陆用户Id)"
,
required
=
true
,
dataType
=
"String"
),
@ApiImplicitParam
(
name
=
"bankBranchId"
,
value
=
"归属网点ID"
,
required
=
true
,
dataType
=
"String"
)})
public
ResponseEntity
<
List
<
DemandInfo
>>
getListOnApp
(
Integer
type
,
String
advisorId
,
String
bankBranchId
)
{
try
{
QueryWrapper
<
DemandInfo
>
demandInfoWrapper
=
new
QueryWrapper
<>();
demandInfoWrapper
.
eq
(
"type"
,
type
)
.
eq
(
"advisor_id"
,
advisorId
)
.
eq
(
"bank_branch_id"
,
bankBranchId
)
.
orderByDesc
(
"create_time"
);
List
<
DemandInfo
>
demandInfoList
=
this
.
demandInfoService
.
list
(
demandInfoWrapper
);
for
(
DemandInfo
demandInfo
:
demandInfoList
)
{
demandInfo
.
setContent
(
EmojiParser
.
parseToUnicode
(
demandInfo
.
getContent
()));
if
(
StringUtils
.
isNotBlank
(
demandInfo
.
getFeedbackInfo
()))
{
demandInfo
.
setFeedbackInfo
(
EmojiParser
.
parseToUnicode
(
demandInfo
.
getFeedbackInfo
()));
}
}
return
ResponseEntity
.
ok
(
demandInfoList
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"服务器错误!"
,
e
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
/**
* APP获取单个呼叫服务或者吐槽建议
*
* @param id
* @return
*/
@ApiOperation
(
value
=
"App获取单个呼叫服务或者吐槽建议"
)
@GetMapping
(
value
=
"/getByIdForApp"
)
public
ResponseEntity
<
DemandInfo
>
getByIdForApp
(
String
id
)
{
try
{
QueryWrapper
<
DemandInfo
>
ew
=
new
QueryWrapper
<>();
ew
.
select
(
"id,line_number AS lineNumber,create_time AS createTime,phone_number AS phoneNumber,content,feedback_info AS feedbackInfo"
);
ew
.
eq
(
"id"
,
id
);
DemandInfo
one
=
this
.
demandInfoService
.
getOne
(
ew
);
if
(
null
!=
one
)
{
return
ResponseEntity
.
ok
(
one
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
NOT_FOUND
).
body
(
null
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"获取单个呼叫服务或者吐槽建议出错!"
,
e
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
null
);
}
}
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