二维码模块基本完善;同时添加了一些文件处理工具FileUtils,存放于component/activity/下;为ActivityCreatorController添加了API调用说明
This commit is contained in:
parent
e09f373fc0
commit
b9ddb73f3f
@ -15,7 +15,6 @@ import javafx.util.converter.LocalDateTimeStringConverter;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -24,9 +23,6 @@ import java.util.*;
|
|||||||
@Component
|
@Component
|
||||||
public class ActivityConverter {
|
public class ActivityConverter {
|
||||||
|
|
||||||
@Resource
|
|
||||||
ActivityService activityService;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@ -43,14 +39,14 @@ public class ActivityConverter {
|
|||||||
Activity activity = new Activity();
|
Activity activity = new Activity();
|
||||||
JSONObject jsonObject = json.get();
|
JSONObject jsonObject = json.get();
|
||||||
|
|
||||||
String username = (String) jsonObject.get("creator");
|
int userId = (int) jsonObject.get("creator");
|
||||||
Optional<User> creator = userService.findUserByUsername(username);
|
Optional<User> creator = userService.findUserById(userId);
|
||||||
activity.setCreator(creator.get());
|
activity.setCreator(creator.get());
|
||||||
|
|
||||||
List<String> participateGroupFromJson = (List) jsonObject.get("participate-group");
|
List<Integer> participateGroupFromJson = (List<Integer>) jsonObject.get("participate-group");
|
||||||
Set<User> participateGroup = new HashSet<>();
|
Set<User> participateGroup = new HashSet<>();
|
||||||
for (String name : participateGroupFromJson) {
|
for (int id : participateGroupFromJson) {
|
||||||
Optional<User> user = userService.findUserByUsername(name);
|
Optional<User> user = userService.findUserById(id);
|
||||||
participateGroup.add(user.get());
|
participateGroup.add(user.get());
|
||||||
}
|
}
|
||||||
activity.setParticipateGroup(participateGroup);
|
activity.setParticipateGroup(participateGroup);
|
||||||
@ -58,14 +54,14 @@ public class ActivityConverter {
|
|||||||
String title = (String) jsonObject.get("title");
|
String title = (String) jsonObject.get("title");
|
||||||
activity.setTitle(title);
|
activity.setTitle(title);
|
||||||
|
|
||||||
String chiefManagerName = (String) jsonObject.get("chief-manager");
|
int chiefManagerId = (int) jsonObject.get("chief-manager");
|
||||||
Optional<User> chiefManager = userService.findUserByUsername(chiefManagerName);
|
Optional<User> chiefManager = userService.findUserById(chiefManagerId);
|
||||||
activity.setChiefManager(chiefManager.get());
|
activity.setChiefManager(chiefManager.get());
|
||||||
|
|
||||||
List<String> assistManagerFromJSON = (List) jsonObject.get("assist-manager");
|
List<Integer> assistManagersFromJSON = (List<Integer>) jsonObject.get("assist-managers");
|
||||||
Set<User> assistManager = new HashSet<>();
|
Set<User> assistManager = new HashSet<>();
|
||||||
for (String name : assistManagerFromJSON) {
|
for (int id : assistManagersFromJSON) {
|
||||||
Optional<User> user = userService.findUserByUsername(name);
|
Optional<User> user = userService.findUserById(id);
|
||||||
assistManager.add(user.get());
|
assistManager.add(user.get());
|
||||||
}
|
}
|
||||||
activity.setAssistManagers(assistManager);
|
activity.setAssistManagers(assistManager);
|
||||||
@ -88,26 +84,31 @@ public class ActivityConverter {
|
|||||||
String description = (String) jsonObject.get("description");
|
String description = (String) jsonObject.get("description");
|
||||||
activity.setDescription(description);
|
activity.setDescription(description);
|
||||||
|
|
||||||
List<String> signGroupFromJSON = (List) jsonObject.get("sign-group");
|
List<Integer> signGroupFromJSON = (List<Integer>) jsonObject.get("sign-group");
|
||||||
Set<User> signGroup = new HashSet<>();
|
Set<User> signGroup = new HashSet<>();
|
||||||
for (String name : signGroupFromJSON) {
|
for (int id : signGroupFromJSON) {
|
||||||
Optional<User> user = userService.findUserByUsername(name);
|
Optional<User> user = userService.findUserById(id);
|
||||||
signGroup.add(user.get());
|
signGroup.add(user.get());
|
||||||
}
|
}
|
||||||
activity.setSignGroup(signGroup);
|
activity.setSignGroup(signGroup);
|
||||||
|
|
||||||
List<String> informGroupFromJSON = (List) jsonObject.get("inform-group");
|
List<Integer> informGroupFromJSON = (List<Integer>) jsonObject.get("inform-group");
|
||||||
|
if (informGroupFromJSON == null) {
|
||||||
|
participateGroupFromJson.removeAll(signGroupFromJSON);
|
||||||
|
participateGroupFromJson.addAll(signGroupFromJSON);
|
||||||
|
informGroupFromJSON = participateGroupFromJson;
|
||||||
|
}
|
||||||
Set<User> informGroup = new HashSet<>();
|
Set<User> informGroup = new HashSet<>();
|
||||||
for (String name : informGroupFromJSON) {
|
for (int id : informGroupFromJSON) {
|
||||||
Optional<User> user = userService.findUserByUsername(name);
|
Optional<User> user = userService.findUserById(id);
|
||||||
informGroup.add(user.get());
|
informGroup.add(user.get());
|
||||||
}
|
}
|
||||||
activity.setInformGroup(informGroup);
|
activity.setInformGroup(informGroup);
|
||||||
|
|
||||||
List<String> visibleGroupFromJSON = (List) jsonObject.get("visible-group");
|
List<Integer> visibleGroupFromJSON = (List<Integer>) jsonObject.get("visible-group");
|
||||||
Set<User> visibleGroup = new HashSet<>();
|
Set<User> visibleGroup = new HashSet<>();
|
||||||
for (String name : visibleGroupFromJSON) {
|
for (int id : visibleGroupFromJSON) {
|
||||||
Optional<User> user = userService.findUserByUsername(name);
|
Optional<User> user = userService.findUserById(id);
|
||||||
visibleGroup.add(user.get());
|
visibleGroup.add(user.get());
|
||||||
}
|
}
|
||||||
activity.setVisibleGroup(informGroup);
|
activity.setVisibleGroup(informGroup);
|
||||||
|
@ -0,0 +1,129 @@
|
|||||||
|
package com.codesdream.ase.component.activity;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FileUtils {
|
||||||
|
/**
|
||||||
|
* 得到图片字节流 数组大小
|
||||||
|
*/
|
||||||
|
public static byte[] readStream(InputStream inStream) throws Exception {
|
||||||
|
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len = -1;
|
||||||
|
while ((len = inStream.read(buffer)) != -1) {
|
||||||
|
outStream.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
outStream.close();
|
||||||
|
inStream.close();
|
||||||
|
return outStream.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将文件转换成Byte数组
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static byte[] getBytesByFile(File file) {
|
||||||
|
try {
|
||||||
|
FileInputStream fis = new FileInputStream(file);
|
||||||
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
|
||||||
|
byte[] b = new byte[1000];
|
||||||
|
int n;
|
||||||
|
while ((n = fis.read(b)) != -1) {
|
||||||
|
bos.write(b, 0, n);
|
||||||
|
}
|
||||||
|
fis.close();
|
||||||
|
byte[] data = bos.toByteArray();
|
||||||
|
bos.close();
|
||||||
|
return data;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MultipartFile转File
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static File transfer(MultipartFile param) {
|
||||||
|
if (!param.isEmpty()) {
|
||||||
|
File file = null;
|
||||||
|
try {
|
||||||
|
InputStream in = param.getInputStream();
|
||||||
|
file = new File(param.getOriginalFilename());
|
||||||
|
OutputStream out = new FileOutputStream(file);
|
||||||
|
int bytesRead = 0;
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
|
||||||
|
out.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
return file;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定文件的输入流
|
||||||
|
*
|
||||||
|
* @param logoPath 文件的路径
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static InputStream getResourceAsStream(String logoPath) {
|
||||||
|
return FileUtils.class.getResourceAsStream(logoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将InputStream写入到File中
|
||||||
|
*
|
||||||
|
* @param ins
|
||||||
|
* @param file
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void inputStreamToFile(InputStream ins, File file) throws IOException {
|
||||||
|
OutputStream os = new FileOutputStream(file);
|
||||||
|
int bytesRead = 0;
|
||||||
|
byte[] buffer = new byte[8192];
|
||||||
|
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
os.close();
|
||||||
|
ins.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将图片转化成输入流
|
||||||
|
*
|
||||||
|
* @param image 图片
|
||||||
|
* @return inputStream 图片转化之后的输入流
|
||||||
|
*/
|
||||||
|
public static InputStream getImageStream(BufferedImage image) {
|
||||||
|
InputStream inputStream = null;
|
||||||
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
ImageOutputStream imageOutputStream;
|
||||||
|
try {
|
||||||
|
imageOutputStream = ImageIO.createImageOutputStream(byteArrayOutputStream);
|
||||||
|
ImageIO.write(image, "jpg", imageOutputStream);
|
||||||
|
inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return inputStream;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,227 @@
|
|||||||
|
package com.codesdream.ase.component.activity;
|
||||||
|
|
||||||
|
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 jdk.internal.util.xml.impl.Input;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.geom.RoundRectangle2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码生成工具类
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class QrCodeUtils {
|
||||||
|
private static final String CHARSET = "utf-8";
|
||||||
|
public static final String FORMAT = "JPG";
|
||||||
|
// 二维码尺寸
|
||||||
|
private static final int QRCODE_SIZE = 300;
|
||||||
|
// LOGO宽度
|
||||||
|
private static final int LOGO_WIDTH = 60;
|
||||||
|
// LOGO高度
|
||||||
|
private static final int LOGO_HEIGHT = 60;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码
|
||||||
|
*
|
||||||
|
* @param content 二维码内容
|
||||||
|
* @param logoPath logo地址
|
||||||
|
* @param needCompress 是否压缩logo
|
||||||
|
* @return 图片
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static BufferedImage createImage(String content, String logoPath, boolean needCompress) throws Exception {
|
||||||
|
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
|
||||||
|
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 (logoPath == null || "".equals(logoPath)) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
// 插入图片
|
||||||
|
QrCodeUtils.insertImage(image, logoPath, needCompress);
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入LOGO
|
||||||
|
*
|
||||||
|
* @param source 二维码图片
|
||||||
|
* @param logoPath LOGO图片地址
|
||||||
|
* @param needCompress 是否压缩
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private static void insertImage(BufferedImage source, String logoPath, boolean needCompress) throws IOException {
|
||||||
|
InputStream inputStream = null;
|
||||||
|
try {
|
||||||
|
inputStream = FileUtils.getResourceAsStream(logoPath);
|
||||||
|
Image src = ImageIO.read(inputStream);
|
||||||
|
int width = src.getWidth(null);
|
||||||
|
int height = src.getHeight(null);
|
||||||
|
if (needCompress) { // 压缩LOGO
|
||||||
|
if (width > LOGO_WIDTH) {
|
||||||
|
width = LOGO_WIDTH;
|
||||||
|
}
|
||||||
|
if (height > LOGO_HEIGHT) {
|
||||||
|
height = LOGO_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(3f));
|
||||||
|
graph.draw(shape);
|
||||||
|
graph.dispose();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码(内嵌LOGO)
|
||||||
|
* 二维码文件名随机,文件名可能会有重复
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param logoPath LOGO地址
|
||||||
|
* @param destPath 存放目录
|
||||||
|
* @param needCompress 是否压缩LOGO
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encode(String content, String logoPath, String destPath, boolean needCompress) throws Exception {
|
||||||
|
BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress);
|
||||||
|
mkdirs(destPath);
|
||||||
|
String fileName = new Random().nextInt(99999999) + "." + FORMAT.toLowerCase();
|
||||||
|
ImageIO.write(image, FORMAT, new File(destPath + "/" + fileName));
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码(内嵌LOGO)
|
||||||
|
* 调用者指定二维码文件名
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param logoPath LOGO地址
|
||||||
|
* @param destPath 存放目录
|
||||||
|
* @param fileName 二维码文件名
|
||||||
|
* @param needCompress 是否压缩LOGO
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encode(String content, String logoPath, String destPath, String fileName, boolean needCompress) throws Exception {
|
||||||
|
BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress);
|
||||||
|
mkdirs(destPath);
|
||||||
|
fileName = fileName.substring(0, fileName.indexOf(".") > 0 ? fileName.indexOf(".") : fileName.length())
|
||||||
|
+ "." + FORMAT.toLowerCase();
|
||||||
|
ImageIO.write(image, FORMAT, new File(destPath + "/" + fileName));
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.
|
||||||
|
* (mkdir如果父目录不存在则会抛出异常)
|
||||||
|
*
|
||||||
|
* @param destPath 存放目录
|
||||||
|
*/
|
||||||
|
public static void mkdirs(String destPath) {
|
||||||
|
File file = new File(destPath);
|
||||||
|
if (!file.exists() && !file.isDirectory()) {
|
||||||
|
file.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码(内嵌LOGO)
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param logoPath LOGO地址
|
||||||
|
* @param destPath 存储地址
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encode(String content, String logoPath, String destPath) throws Exception {
|
||||||
|
return QrCodeUtils.encode(content, logoPath, destPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param destPath 存储地址
|
||||||
|
* @param needCompress 是否压缩LOGO
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encode(String content, String destPath, boolean needCompress) throws Exception {
|
||||||
|
return QrCodeUtils.encode(content, null, destPath, needCompress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param destPath 存储地址
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static String encode(String content, String destPath) throws Exception {
|
||||||
|
return QrCodeUtils.encode(content, null, destPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码(内嵌LOGO)
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param logoPath LOGO地址
|
||||||
|
* @param output 输出流
|
||||||
|
* @param needCompress 是否压缩LOGO
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void encode(String content, String logoPath, OutputStream output, boolean needCompress)
|
||||||
|
throws Exception {
|
||||||
|
BufferedImage image = QrCodeUtils.createImage(content, logoPath, needCompress);
|
||||||
|
ImageIO.write(image, FORMAT, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成二维码
|
||||||
|
*
|
||||||
|
* @param content 内容
|
||||||
|
* @param output 输出流
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public static void encode(String content, OutputStream output) throws Exception {
|
||||||
|
QrCodeUtils.encode(content, null, output, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.codesdream.ase.controller.activity;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class ActivityAttendanceController {
|
||||||
|
|
||||||
|
}
|
@ -12,23 +12,22 @@ import com.codesdream.ase.model.activity.Activity;
|
|||||||
import com.codesdream.ase.model.activity.UserActivity;
|
import com.codesdream.ase.model.activity.UserActivity;
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import com.codesdream.ase.repository.activity.UserActivityRepository;
|
import com.codesdream.ase.repository.activity.UserActivityRepository;
|
||||||
import com.codesdream.ase.repository.permission.UserRepository;
|
|
||||||
import com.codesdream.ase.service.ActivityService;
|
import com.codesdream.ase.service.ActivityService;
|
||||||
|
import com.codesdream.ase.service.UserService;
|
||||||
import com.codesdream.ase.validator.ActivityValidator;
|
import com.codesdream.ase.validator.ActivityValidator;
|
||||||
import com.codesdream.ase.validator.NullValueValidator;
|
import com.codesdream.ase.validator.NullValueValidator;
|
||||||
import com.codesdream.ase.validator.JSONFormValidator;
|
import com.codesdream.ase.validator.JSONFormValidator;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ -59,7 +58,7 @@ public class ActivityCreatorController {
|
|||||||
ActivityValidator activityValidator;
|
ActivityValidator activityValidator;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
UserRepository userRepository;
|
UserService userService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
UserActivityRepository userActivityRepository;
|
UserActivityRepository userActivityRepository;
|
||||||
@ -69,12 +68,25 @@ public class ActivityCreatorController {
|
|||||||
|
|
||||||
private final String url = "/forget/activity";
|
private final String url = "/forget/activity";
|
||||||
|
|
||||||
@RequestMapping(value = url + "/activity_creator")
|
|
||||||
String activityCreatorView(Model model){return "activity_creator";}
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping(value = url + "/activity_creator")
|
@PostMapping(value = url + "/activity_creator")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
@ApiOperation(value = "创建活动", notes = "所有有关用户的数据传递均使用id,类型为int")
|
||||||
|
@ApiImplicitParams({
|
||||||
|
@ApiImplicitParam(name = "title", value = "活动标题", required = true),
|
||||||
|
@ApiImplicitParam(name = "type", value = "活动类型", required = true),
|
||||||
|
@ApiImplicitParam(name = "start-time", value = "活动开始时间,格式为yyyy-MM-dd HH:mm:ss", required = true),
|
||||||
|
@ApiImplicitParam(name = "end-time", value = "活动结束时间,格式为yyyy-MM-dd HH:mm:ss", required = true),
|
||||||
|
@ApiImplicitParam(name = "chief-manager", value = "主要负责人", required = true),
|
||||||
|
@ApiImplicitParam(name = "assist-managers", value = "次要负责人"),
|
||||||
|
@ApiImplicitParam(name = "description", value = "活动描述"),
|
||||||
|
@ApiImplicitParam(name = "cycle", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"),
|
||||||
|
@ApiImplicitParam(name = "participate-group", value = "预定参与人员"),
|
||||||
|
@ApiImplicitParam(name = "sign-group", value = "可参与人员"),
|
||||||
|
@ApiImplicitParam(name = "inform-group", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"),
|
||||||
|
@ApiImplicitParam(name = "visible-group", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"),
|
||||||
|
@ApiImplicitParam(name = "remind-time", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"),
|
||||||
|
})
|
||||||
String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
JSONObject error = new JSONObject();
|
JSONObject error = new JSONObject();
|
||||||
@ -82,19 +94,16 @@ public class ActivityCreatorController {
|
|||||||
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||||
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||||
|
|
||||||
//WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
|
||||||
List<String> formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get());
|
List<String> formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get());
|
||||||
|
|
||||||
if (!formatCheckResult.isEmpty()) {
|
if (!formatCheckResult.isEmpty()) {
|
||||||
error.put("error", formatCheckResult);
|
error.put("error", formatCheckResult);
|
||||||
return error.toJSONString();
|
return error.toJSONString();
|
||||||
}
|
}
|
||||||
// 需要检查JSON是否合法
|
// 需要检查JSON是否合法
|
||||||
|
|
||||||
Activity activity = activityConverter.convertToActivity(json);
|
Activity activity = activityConverter.convertToActivity(json);
|
||||||
|
|
||||||
//NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
|
||||||
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||||
//= aseSpringUtil.getBean(NullValueAttributes.class);
|
|
||||||
for (String str : nullValues){
|
for (String str : nullValues){
|
||||||
if(str.equals("title")){
|
if(str.equals("title")){
|
||||||
nullValueAttributes.getNullValueAttributes().add("title");
|
nullValueAttributes.getNullValueAttributes().add("title");
|
||||||
@ -113,9 +122,8 @@ public class ActivityCreatorController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//如果为空,存下此活动并跳转至成功创建页面
|
//如果为空,存下此活动并跳转至成功创建页面
|
||||||
if(nullValueAttributes.getNullValueAttributes().isEmpty()){
|
if (!nullValueAttributes.getNullValueAttributes().isEmpty()) {
|
||||||
|
|
||||||
//ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class);
|
|
||||||
String[] errorParameters = activityValidator.check(json);
|
String[] errorParameters = activityValidator.check(json);
|
||||||
if(errorParameters != null){
|
if(errorParameters != null){
|
||||||
JSONObject invalidParameters = new JSONObject();
|
JSONObject invalidParameters = new JSONObject();
|
||||||
@ -124,12 +132,9 @@ public class ActivityCreatorController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class);
|
|
||||||
//activityService = aseSpringUtil.getBean(ActivityService.class);
|
|
||||||
activity = activityService.createActivity(activity);
|
activity = activityService.createActivity(activity);
|
||||||
String username = json.get().get("creator").toString();
|
String username = json.get().get("creator").toString();
|
||||||
Optional<User> user = userRepository.findByUsername(username);
|
Optional<User> user = userService.findUserByUsername(username);
|
||||||
//UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class);
|
|
||||||
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
||||||
userActivity.getCreatedActivities().add(activity);
|
userActivity.getCreatedActivities().add(activity);
|
||||||
userActivityRepository.save(userActivity);
|
userActivityRepository.save(userActivity);
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.codesdream.ase.controller.activity;
|
||||||
|
|
||||||
|
import com.codesdream.ase.component.activity.QrCodeUtils;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class QRCodeController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
@GetMapping("/qrcode")
|
||||||
|
public void qrCode(HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
StringBuffer url = request.getRequestURL();
|
||||||
|
// 域名
|
||||||
|
String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append("/").toString();
|
||||||
|
|
||||||
|
// 再加上请求链接
|
||||||
|
String requestUrl = tempContextUrl + "/index";
|
||||||
|
try {
|
||||||
|
OutputStream os = response.getOutputStream();
|
||||||
|
QrCodeUtils.encode(requestUrl, "", os, true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,8 +2,6 @@ package com.codesdream.ase.model.activity;
|
|||||||
|
|
||||||
import com.codesdream.ase.model.permission.User;
|
import com.codesdream.ase.model.permission.User;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import org.springframework.security.core.parameters.P;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
@ -15,10 +15,6 @@ public class Attendance {
|
|||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
//二维码url
|
|
||||||
@Column(name = "qr_code")//, nullable = false, unique = true)
|
|
||||||
private String QRCode;
|
|
||||||
|
|
||||||
//是否在线
|
//是否在线
|
||||||
@Column(name = "is_online")//, nullable = false)
|
@Column(name = "is_online")//, nullable = false)
|
||||||
private boolean isOnline;
|
private boolean isOnline;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.codesdream.ase.model.activity;
|
package com.codesdream.ase.model.activity;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||||
|
|
||||||
@ -18,10 +20,12 @@ public class Period {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
//开始时间
|
//开始时间
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
@Column(name = "start_time")//, nullable = false)
|
@Column(name = "start_time")//, nullable = false)
|
||||||
private LocalDateTime startTime = LocalDateTime.of(2020,2,18,16,36);
|
private LocalDateTime startTime = LocalDateTime.of(2020,2,18,16,36);
|
||||||
|
|
||||||
//结束时间
|
//结束时间
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||||
@Column(name = "end_time")//, nullable = false)
|
@Column(name = "end_time")//, nullable = false)
|
||||||
private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);
|
private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user