Merge branch 'master' of http://git.codesdream.com/root/ASE
Conflicts: src/main/java/com/codesdream/ase/repository/activity/ActivityRepository.java
This commit is contained in:
commit
3942d547af
@ -7,8 +7,6 @@ import com.codesdream.ase.model.activity.Attendance;
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.service.ActivityService;
|
||||
import com.codesdream.ase.service.AttendanceService;
|
||||
import com.codesdream.ase.service.PeriodService;
|
||||
import com.codesdream.ase.service.UserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -0,0 +1,189 @@
|
||||
package com.codesdream.ase.component.activity;
|
||||
|
||||
import com.codesdream.ase.exception.conflict.FileNameConflict;
|
||||
import com.codesdream.ase.exception.notfound.AppendixFileNotFoundException;
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.AppendixFile;
|
||||
import com.codesdream.ase.repository.activity.ActivityRepository;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class FileSystem {
|
||||
|
||||
@Resource
|
||||
private AppendixFileService appendixFileService;
|
||||
|
||||
|
||||
public static final int FAILED = -1;
|
||||
|
||||
//默认文件系统根路径
|
||||
private static final String rootDir = "d:/temp";
|
||||
|
||||
/**
|
||||
* 用于创建文件条目的辅助函数
|
||||
* @param fileName 文件名
|
||||
* @return 文件在数据库中的条目
|
||||
*/
|
||||
private AppendixFile createFileTable(String fileName)
|
||||
{
|
||||
AppendixFile appendixFile = new AppendixFile();
|
||||
appendixFile.setFileName(fileName);
|
||||
appendixFile.setLastEditTime(LocalDateTime.now());
|
||||
String[] temp = fileName.split("\\.",2);
|
||||
for(String s : temp)
|
||||
System.out.println(s);
|
||||
if(temp.length == 1)
|
||||
appendixFile.setType("");
|
||||
else
|
||||
appendixFile.setType(temp[temp.length-1]);
|
||||
return appendixFile;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 向磁盘中添加一个文件,并在数据库建立条目
|
||||
* @param data 文件的数据
|
||||
* @param fileName 文件名,包括拓展名
|
||||
* @return 成功时返回文件id,失败时返回FileSystem.FAILED
|
||||
*/
|
||||
public int addFile(byte data[], String fileName) throws Exception
|
||||
{
|
||||
AppendixFile appendixFile = createFileTable(fileName);
|
||||
appendixFile = appendixFileService.save(appendixFile);
|
||||
File file = new File(rootDir,""+appendixFile.getId());
|
||||
FileOutputStream outputStream;
|
||||
if(file.exists())
|
||||
throw new FileNameConflict(
|
||||
"file name conflict,there is a file in the directory, and is not created by this program",
|
||||
file.getName());
|
||||
File parent = file.getParentFile();
|
||||
if(!parent.exists())
|
||||
parent.mkdirs();
|
||||
try{
|
||||
file.createNewFile();
|
||||
outputStream = new FileOutputStream(file);
|
||||
outputStream.write(data);
|
||||
outputStream.close();
|
||||
return appendixFile.getId();
|
||||
}
|
||||
catch (Exception e){
|
||||
appendixFileService.delete(appendixFile);
|
||||
e.printStackTrace();
|
||||
throw new Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取一个磁盘中的文件
|
||||
* @param id 文件的id
|
||||
* @return 成功返回文件的InputStream,失败返回null
|
||||
*/
|
||||
public InputStream getFile(int id)throws AppendixFileNotFoundException
|
||||
{
|
||||
Optional<AppendixFile> optionalAppendixFile = appendixFileService.findById(id);
|
||||
if(!optionalAppendixFile.isPresent())
|
||||
throw new AppendixFileNotFoundException(
|
||||
"the required id does not exist in the database",id,
|
||||
AppendixFileNotFoundException.ID_NOT_FOUND);
|
||||
|
||||
AppendixFile appendixFile = appendixFileService.findById(id).get();
|
||||
File file = new File(rootDir,""+appendixFile.getId());
|
||||
|
||||
if(file.exists())
|
||||
{
|
||||
try {
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
return inputStream;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new AppendixFileNotFoundException(
|
||||
"the required id exists in the database, but the stream can not be opened",id,
|
||||
AppendixFileNotFoundException.STREAM_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new AppendixFileNotFoundException(
|
||||
"the required id exists in the database, but the file is missing",id,
|
||||
AppendixFileNotFoundException.FILE_NOT_fOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除一个文件,如果该文件不存在,则不会发生操作
|
||||
* @param id 要删除文件的id
|
||||
*/
|
||||
public void deleteFile(int id)
|
||||
{
|
||||
Optional<AppendixFile> optionalAppendixFile = appendixFileService.findById(id);
|
||||
if(!optionalAppendixFile.isPresent())
|
||||
return;
|
||||
AppendixFile appendixFile = appendixFileService.findById(id).get();
|
||||
File file = new File(rootDir,""+appendixFile.getId());
|
||||
if(file.exists()) {
|
||||
file.delete();
|
||||
appendixFileService.delete(appendixFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取一个文件的条目,其中包含文件信息
|
||||
* @param id 要寻找条目的id
|
||||
*/
|
||||
public AppendixFile getFileData(int id)throws AppendixFileNotFoundException
|
||||
{
|
||||
Optional<AppendixFile> optionalAppendixFile = appendixFileService.findById(id);
|
||||
if(!optionalAppendixFile.isPresent())
|
||||
throw new AppendixFileNotFoundException(
|
||||
"the required id does not exist in the database",id,
|
||||
AppendixFileNotFoundException.ID_NOT_FOUND);
|
||||
|
||||
AppendixFile appendixFile = appendixFileService.findById(id).get();
|
||||
|
||||
return appendixFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 维护数据库,删去所有文件已经缺失的条目(仅用于在文件系统出现故障时的维护)
|
||||
*/
|
||||
public void databaseRefresh()
|
||||
{
|
||||
for (AppendixFile appendixFile:
|
||||
appendixFileService.findAll()) {
|
||||
File file = new File(rootDir,""+appendixFile.getId());
|
||||
if(!file.exists())
|
||||
appendixFileService.delete(appendixFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 维护磁盘,删除指定根目录下所有不在数据库中的文件(仅用于文件系统出现故障时的维护)
|
||||
*/
|
||||
public void diskRefresh()
|
||||
{
|
||||
File dir = new File(rootDir);
|
||||
|
||||
if (dir.exists()) {
|
||||
if (null == dir.listFiles()) {
|
||||
return;
|
||||
}
|
||||
for(File file : dir.listFiles())
|
||||
{
|
||||
int id;
|
||||
try{
|
||||
id = Integer.parseInt(file.getName());
|
||||
if(!appendixFileService.findById(id).isPresent())
|
||||
file.delete();
|
||||
}
|
||||
catch (Exception ex){
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.codesdream.ase.controller.activity;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/act")
|
||||
public class ActivityAttendanceController {
|
||||
|
||||
private final String url = "/forget";
|
||||
|
||||
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
package com.codesdream.ase.controller.activity;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.codesdream.ase.component.ASESpringUtil;
|
||||
import com.codesdream.ase.component.activity.ActivityConverter;
|
||||
import com.codesdream.ase.component.activity.NullValueAttributes;
|
||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||
import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond;
|
||||
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||
import com.codesdream.ase.exception.innerservererror.InvalidFormFormatException;
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.UserActivity;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.repository.activity.UserActivityRepository;
|
||||
import com.codesdream.ase.service.ActivityService;
|
||||
import com.codesdream.ase.service.UserService;
|
||||
import com.codesdream.ase.validator.ActivityValidator;
|
||||
import com.codesdream.ase.validator.NullValueValidator;
|
||||
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.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/forget/act")
|
||||
public class ActivityCreatorController {
|
||||
|
||||
@Resource
|
||||
ActivityService activityService;
|
||||
|
||||
@Resource
|
||||
JSONParameter jsonParameter;
|
||||
|
||||
@Resource
|
||||
ASESpringUtil aseSpringUtil;
|
||||
|
||||
@Resource
|
||||
ActivityFormConfigure activityFormConfigure;
|
||||
|
||||
@Resource
|
||||
JSONFormValidator jsonFormValidator;
|
||||
|
||||
@Resource
|
||||
NullValueValidator nullValueValidator;
|
||||
|
||||
@Resource
|
||||
NullValueAttributes nullValueAttributes;
|
||||
|
||||
@Resource
|
||||
ActivityValidator activityValidator;
|
||||
|
||||
@Resource
|
||||
UserService userService;
|
||||
|
||||
@Resource
|
||||
UserActivityRepository userActivityRepository;
|
||||
|
||||
@Resource
|
||||
ActivityConverter activityConverter;
|
||||
|
||||
|
||||
@PostMapping(value = "/creator")
|
||||
@ResponseBody
|
||||
@ApiOperation(value = "创建活动", notes = "所有有关用户的数据传递均使用id,类型为int")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "title", value = "活动标题", dataType = "String", required = true),
|
||||
@ApiImplicitParam(name = "type", value = "活动类型", dataType = "String", 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", dataType = "int", value = "主要负责人", required = true),
|
||||
@ApiImplicitParam(name = "assist-managers", dataType = "int", value = "次要负责人"),
|
||||
@ApiImplicitParam(name = "description", dataType = "String", value = "活动描述"),
|
||||
@ApiImplicitParam(name = "cycle", dataType = "String", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"),
|
||||
@ApiImplicitParam(name = "participate-group", value = "预定参与人员"),
|
||||
@ApiImplicitParam(name = "sign-group", dataType = "List<int>", value = "可参与人员"),
|
||||
@ApiImplicitParam(name = "inform-group", dataType = "List<int>", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"),
|
||||
@ApiImplicitParam(name = "visible-group", dataType = "List<int>", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"),
|
||||
@ApiImplicitParam(name = "remind-time", dataType = "String", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"),
|
||||
})
|
||||
String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
|
||||
JSONObject error = new JSONObject();
|
||||
aseSpringUtil = new ASESpringUtil();
|
||||
//判断是否为JSON对象
|
||||
Optional<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||
|
||||
List<String> formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get());
|
||||
|
||||
//检验JSON格式是否有误
|
||||
if (!formatCheckResult.isEmpty()) {
|
||||
error.put("error", formatCheckResult);
|
||||
throw new InvalidFormFormatException(error.toJSONString());
|
||||
}
|
||||
Activity activity = activityConverter.convertToActivity(json);
|
||||
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||
|
||||
for (String str : nullValues){
|
||||
if(str.equals("title")){
|
||||
nullValueAttributes.getNullValueAttributes().add("title");
|
||||
}
|
||||
else if(str.equals("creator")){
|
||||
nullValueAttributes.getNullValueAttributes().add("creator");
|
||||
}
|
||||
else if(str.equals("type")){
|
||||
nullValueAttributes.getNullValueAttributes().add("type");
|
||||
}
|
||||
else if(str.equals("planPeriod")){
|
||||
nullValueAttributes.getNullValueAttributes().add("planPeriod");
|
||||
}
|
||||
else if(str.equals("chiefManager")){
|
||||
nullValueAttributes.getNullValueAttributes().add("chiefManager");
|
||||
}
|
||||
}
|
||||
//如果为空,存下此活动并跳转至成功创建页面
|
||||
if (!nullValueAttributes.getNullValueAttributes().isEmpty()) {
|
||||
|
||||
String[] errorParameters = activityValidator.check(json);
|
||||
if(errorParameters != null){
|
||||
JSONObject invalidParameters = new JSONObject();
|
||||
invalidParameters.put("invalid_parameters", errorParameters);
|
||||
return invalidParameters.toJSONString();
|
||||
|
||||
}
|
||||
else{
|
||||
activity = activityService.createActivity(activity);
|
||||
String username = json.get().get("creator").toString();
|
||||
Optional<User> user = userService.findUserByUsername(username);
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
||||
userActivity.getCreatedActs().add(activity);
|
||||
userActivityRepository.save(userActivity);
|
||||
}
|
||||
}
|
||||
//否则返回一个JSON对象给前端
|
||||
else{
|
||||
JSONObject nullParameters = new JSONObject();
|
||||
nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes());
|
||||
return nullParameters.toJSONString();
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(activity);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,94 +0,0 @@
|
||||
package com.codesdream.ase.controller.activity;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.service.ActivityService;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/forget/act")
|
||||
public class ActivityViewerController {
|
||||
|
||||
|
||||
@Resource
|
||||
ActivityService activityService;
|
||||
|
||||
@GetMapping("/created_acts")
|
||||
String showCreated() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findCreatedActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/parting_acts")
|
||||
String showParticipate(HttpServletRequest request) {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findParticipatingActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/parted_acts")
|
||||
String showParticipated() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findParticipatedActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/sign_acts")
|
||||
String showSign() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findSignActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/vis_acts")
|
||||
String showVisible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findVisibleActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
String showAll() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findAll(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/main_responsible_acts")
|
||||
String showMainResponsible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findMainResponsibleActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/sec_responsible_acts")
|
||||
String showSecondaryResponsible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findSecondaryResponsibleActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/acts_by_type")
|
||||
String showInType(@RequestParam(defaultValue = "考勤", name = "type") String type) {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findActivityByType(user, type);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.codesdream.ase.exception.conflict;
|
||||
|
||||
public class FileNameConflict extends RuntimeException {
|
||||
public String conflictName;
|
||||
public FileNameConflict(String msg,String conflictName)
|
||||
{
|
||||
super(msg);
|
||||
this.conflictName = conflictName;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.codesdream.ase.exception.notfound;
|
||||
|
||||
import com.codesdream.ase.model.activity.AppendixFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AppendixFileNotFoundException extends IOException {
|
||||
public int id;
|
||||
public int type;
|
||||
public static final int ID_NOT_FOUND = 1, FILE_NOT_fOUND = 2, STREAM_FAILURE = 3;
|
||||
|
||||
public AppendixFileNotFoundException(String msg,int id,int type){
|
||||
super(msg);
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.codesdream.ase.model.achievement;
|
||||
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "accumulated_gpa")
|
||||
|
||||
public class AccumulatedGPA {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 课程-得分集合
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||
private Set<ExamResult> examResults = new HashSet<>();
|
||||
|
||||
// 个人学分积
|
||||
@JoinColumn(nullable = true)
|
||||
private float accumulatedGPA;
|
||||
|
||||
|
||||
//除数为零exception待加
|
||||
public AccumulatedGPA(Set<ExamResult> initExamResults) {
|
||||
int totalProduct = 0, totalCredit = 0;
|
||||
for(ExamResult er : initExamResults){
|
||||
totalProduct += er.getCredit() * er.getScore();
|
||||
totalCredit += er.getCredit();
|
||||
}
|
||||
this.accumulatedGPA = totalProduct / totalCredit;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.codesdream.ase.model.achievement;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.model.permission.UserDetail;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "award")
|
||||
|
||||
public class Award {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 标题
|
||||
private String title = "";
|
||||
|
||||
// 描述
|
||||
private String description = "";
|
||||
|
||||
// 分类
|
||||
private String type = "";
|
||||
|
||||
// 加分
|
||||
private int bonus;
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.codesdream.ase.model.achievement;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.model.permission.UserDetail;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "comprehensive_evaluation")
|
||||
|
||||
public class ComprehensiveEvaluation {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 学分积
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private AccumulatedGPA accumulatedGPA;
|
||||
|
||||
// G2项得分
|
||||
private int g2;
|
||||
|
||||
// G3项得分
|
||||
private int g3;
|
||||
|
||||
// G4项得分
|
||||
private int g4;
|
||||
|
||||
// G5项得分
|
||||
private int g5;
|
||||
|
||||
// G6项得分
|
||||
private int g6;
|
||||
|
||||
// 获奖
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||
private Set<Award> awards = new HashSet<>();
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.codesdream.ase.model.achievement;
|
||||
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "exam_result")
|
||||
|
||||
public class ExamResult {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 课程名称
|
||||
@Column(name = "subject", nullable = false)
|
||||
private String subject = "";
|
||||
|
||||
// 课程学分
|
||||
@Column(name = "credit", nullable = false)
|
||||
private float credit;
|
||||
|
||||
// 课程成绩
|
||||
@Column(name = "score", nullable = true)
|
||||
private int score;
|
||||
|
||||
// 课程绩点
|
||||
@Column(name = "grade_point", nullable = true)
|
||||
private float gradePoint;
|
||||
|
||||
|
||||
public float getCredit() {
|
||||
return credit;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.codesdream.ase.model.achievement;
|
||||
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import com.codesdream.ase.model.permission.Tag;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "student_score_report")
|
||||
|
||||
public class StudentScoreReport {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
// 课程-得分集合
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY)
|
||||
private Set<ExamResult> examResults = new HashSet<>();
|
||||
|
||||
// 个人学分积
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = true)
|
||||
private AccumulatedGPA accumulatedGPA;
|
||||
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
package com.codesdream.ase.model.activity;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "activity")
|
||||
public class Activity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//活动标题
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
//创建人
|
||||
@ManyToOne(cascade = CascadeType.MERGE)
|
||||
@JoinColumn(nullable = false)
|
||||
private User creator;
|
||||
|
||||
//活动类型
|
||||
@Column(nullable = false)
|
||||
private String type;
|
||||
|
||||
//活动描述
|
||||
@Column
|
||||
private String description;
|
||||
|
||||
//活动周期,格式:阿拉伯数字数字+单位,0表示无周期
|
||||
@Column
|
||||
private String cycle;
|
||||
|
||||
//自愿参与人列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_volunteer")
|
||||
private Set<User> volunteers;
|
||||
|
||||
//参与人列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_participate",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "participate_id")
|
||||
}
|
||||
)
|
||||
private Set<User> participateGroup;
|
||||
|
||||
//实际参与人列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_participated",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id" )
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "participated_id")
|
||||
}
|
||||
)
|
||||
private Set<User> participatedGroup;
|
||||
|
||||
//可报名人员列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_sign",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "sign_id")
|
||||
}
|
||||
)
|
||||
private Set<User> signGroup;
|
||||
|
||||
//已报名人员列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_signed",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "signed_id")
|
||||
}
|
||||
)
|
||||
private Set<User> signedGroup;
|
||||
|
||||
//可见人员列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_vis",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "vis_id")
|
||||
}
|
||||
)
|
||||
private Set<User> visibleGroup;
|
||||
|
||||
//通知人员列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_inform",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "inform_id")
|
||||
}
|
||||
)
|
||||
private Set<User> informGroup;
|
||||
|
||||
//已通知人员列表
|
||||
@ManyToMany(cascade = CascadeType.DETACH)
|
||||
@JoinTable(name = "act_informed",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "informed_id")
|
||||
}
|
||||
)
|
||||
private Set<User> informedGroup;
|
||||
|
||||
//计划开始时间
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(nullable = false)
|
||||
private Period planPeriod;
|
||||
|
||||
//实际开始时间
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private Period realPeriod;
|
||||
|
||||
//提前提醒时间
|
||||
@Column(name = "remind_time", nullable = true)
|
||||
private LocalDateTime remindTime;
|
||||
|
||||
//附件组(名字)
|
||||
@ElementCollection(targetClass = String.class)
|
||||
private List<String> enclosures;
|
||||
|
||||
//主要负责人
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false)
|
||||
private User chiefManager;
|
||||
|
||||
//次要负责人
|
||||
@OneToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "act_id")
|
||||
private Set<User> assistManagers;
|
||||
|
||||
//是否开始
|
||||
@Column(name = "is_on", nullable = false)
|
||||
boolean isOn;
|
||||
|
||||
//是否结束
|
||||
@Column(name = "is_off", nullable = false)
|
||||
boolean isOff;
|
||||
|
||||
//考勤安排
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Attendance attendance;
|
||||
|
||||
//活动报告
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private Report report;
|
||||
|
||||
public Activity(){
|
||||
initDefault();
|
||||
}
|
||||
|
||||
private void initDefault(){
|
||||
this.title = "";
|
||||
this.creator = new User();
|
||||
this.type = "";
|
||||
this.description = "";
|
||||
this.cycle = "";
|
||||
this.volunteers = new HashSet<>();
|
||||
this.participateGroup = new HashSet<>();
|
||||
this.participatedGroup = new HashSet<>();
|
||||
this.participatedGroup = new HashSet<>();
|
||||
this.signGroup = new HashSet<>();
|
||||
this.signedGroup = new HashSet<>();
|
||||
this.visibleGroup = new HashSet<>();
|
||||
this.informGroup = new HashSet<>();
|
||||
this.informedGroup = new HashSet<>();
|
||||
this.planPeriod = new Period();
|
||||
this.realPeriod = new Period();
|
||||
this.enclosures = new ArrayList<>();
|
||||
this.chiefManager = new User();
|
||||
this.assistManagers = new HashSet<>();
|
||||
this.isOn = false;
|
||||
this.isOff = false;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.codesdream.ase.model.activity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "attendance")
|
||||
public class Attendance {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//是否在线
|
||||
@Column(name = "is_online")//, nullable = false)
|
||||
private boolean isOnline;
|
||||
|
||||
//打卡时段列表
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
private Set<Period> clockInPeriods;
|
||||
|
||||
//打卡方式,0表示被扫,1表示扫
|
||||
@Column//(nullable = false)
|
||||
private boolean means;
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package com.codesdream.ase.model.activity;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@Table(name = "period_container")
|
||||
@Data
|
||||
public class Period {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//开始时间
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@Column(name = "start_time")//, nullable = false)
|
||||
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)
|
||||
private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);
|
||||
|
||||
//启用状态
|
||||
@Column(name = "enabled")//, nullable = false)
|
||||
private boolean enabled;
|
||||
|
||||
public Period(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
this.startTime = startTime;
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public Period(){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,174 +0,0 @@
|
||||
package com.codesdream.ase.model.activity;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.awt.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "report")
|
||||
public class Report {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//活动标题
|
||||
@Column(nullable = false, unique = true)
|
||||
private String title;
|
||||
|
||||
//创建人
|
||||
@OneToOne(cascade = CascadeType.MERGE)
|
||||
private User creator;
|
||||
|
||||
//活动类型
|
||||
@Column(nullable = false)
|
||||
private String type;
|
||||
|
||||
//活动描述
|
||||
@Column(nullable = true)
|
||||
private String description;
|
||||
|
||||
//活动周期,格式:阿拉伯数字数字+单位,0表示无周期
|
||||
@Column(nullable = true)
|
||||
private String cycle;
|
||||
|
||||
//自愿参与人列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_volunteer")
|
||||
private Set<User> volunteers;
|
||||
|
||||
//参与人列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_participate",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "participate_id")
|
||||
}
|
||||
)
|
||||
private Set<User> participateGroup;
|
||||
|
||||
//实际参与人列表
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "act_participated",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id" )
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "participated_id")
|
||||
}
|
||||
)
|
||||
private Set<User> participatedGroup;
|
||||
|
||||
//可报名人员列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_sign",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "sign_id")
|
||||
}
|
||||
)
|
||||
private Set<User> signGroup;
|
||||
|
||||
//已报名人员列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_signed",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "signed_id")
|
||||
}
|
||||
)
|
||||
private Set<User> signedGroup;
|
||||
|
||||
//可见人员列表
|
||||
@ManyToMany(cascade = CascadeType.MERGE)
|
||||
@JoinTable(name = "act_vis",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "vis_id")
|
||||
}
|
||||
)
|
||||
private Set<User> visibleGroup;
|
||||
|
||||
//通知人员列表
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "act_inform",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "inform_id")
|
||||
}
|
||||
)
|
||||
private Set<User> informGroup;
|
||||
|
||||
//已通知人员列表
|
||||
@ManyToMany(cascade = CascadeType.ALL)
|
||||
@JoinTable(name = "act_informed",
|
||||
joinColumns = {
|
||||
@JoinColumn(name = "act_id")
|
||||
},
|
||||
inverseJoinColumns = {
|
||||
@JoinColumn(name = "informed_id")
|
||||
}
|
||||
)
|
||||
private Set<User> informedGroup;
|
||||
|
||||
//计划开始时间
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "plan_period")
|
||||
private Period planPeriod;
|
||||
|
||||
//实际开始时间
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "real_period")
|
||||
private Period realPeriod;
|
||||
|
||||
//主要负责人
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "chief_manager", nullable = false)
|
||||
private User chiefManager;
|
||||
|
||||
//次要负责人
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "act_id")
|
||||
private List<User> assistManagers;
|
||||
|
||||
|
||||
//考勤安排
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "attendance")
|
||||
private Attendance attendance;
|
||||
|
||||
//活动笔记
|
||||
@Column(name = "notes")
|
||||
private String notes;
|
||||
|
||||
//图表
|
||||
@ElementCollection(targetClass = java.lang.String.class)
|
||||
@Column(name = "charts")
|
||||
private List<String> charts;
|
||||
|
||||
//附件url
|
||||
@Column(name = "enclosure")
|
||||
private String enclosure;
|
||||
|
||||
//活动
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "activity")
|
||||
private Activity activity;
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.codesdream.ase.model.activity;
|
||||
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import javafx.scene.chart.ScatterChart;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "user_act")
|
||||
public class UserActivity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//关联的用户
|
||||
@OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "userActivity")
|
||||
@JoinColumn(nullable = false, unique = true)
|
||||
private User user;
|
||||
|
||||
//主要负责的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> mainResponsibleActs;
|
||||
|
||||
//次要负责的活动
|
||||
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> secondaryResponsibleActs;
|
||||
|
||||
//可见的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> visibleActs;
|
||||
|
||||
//创建的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> createdActs;
|
||||
|
||||
//可报名的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> signUpActs;
|
||||
|
||||
//已经参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatedActs;
|
||||
|
||||
//正在(将要)参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatingActs;
|
||||
|
||||
//打卡签到活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> clockIns;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.codesdream.ase.repository.activity;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ActivityRepository extends JpaRepository<Activity, Integer> {
|
||||
|
||||
Optional<Activity> findActivityByTitleAndType(String title,String type);
|
||||
|
||||
Optional<Activity> findActivityByTitle(String title);
|
||||
|
||||
Optional<Activity> findByCreator(String creatorName);
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.codesdream.ase.repository.activity;
|
||||
|
||||
import com.codesdream.ase.model.activity.Attendance;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface AttendanceRepository extends CrudRepository<Attendance, Integer> {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.codesdream.ase.repository.activity;
|
||||
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface PeriodRepository extends CrudRepository<Period, Integer> {
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.codesdream.ase.repository.activity;
|
||||
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ReportRepository extends CrudRepository<Report, Integer> {
|
||||
Optional<Report> findByTitle(String reportTitle);
|
||||
|
||||
Optional<Report> findByCreator(String creatorName);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.codesdream.ase.repository.activity;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.UserActivity;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface UserActivityRepository extends CrudRepository<UserActivity, Integer> {
|
||||
|
||||
UserActivity findByUser(User user);
|
||||
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AchievementService {
|
||||
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
import com.codesdream.ase.model.activity.UserActivity;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.repository.activity.ActivityRepository;
|
||||
import com.codesdream.ase.repository.activity.UserActivityRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ActivityService implements IActivityService {
|
||||
|
||||
@Resource
|
||||
private ActivityRepository activityRepository;
|
||||
|
||||
@Resource
|
||||
private UserActivityRepository userActivityRepository;
|
||||
|
||||
@Override
|
||||
public Optional<Activity> findActivityByTitle(String title) {
|
||||
return activityRepository.findByTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Activity> findActivityByCreator(String creatorName) {
|
||||
return activityRepository.findByCreator(creatorName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Activity> findActivityByType(User user, String type) {
|
||||
|
||||
List<Activity> activities = this.findAll(user);
|
||||
List<Activity> actsByType = new ArrayList<>();
|
||||
for (Activity activity : activities) {
|
||||
if (activity.getType().equals(type)) {
|
||||
actsByType.add(activity);
|
||||
}
|
||||
}
|
||||
return actsByType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity save(Activity activity) {
|
||||
return activityRepository.save(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity addReport(Activity activity, Report report) {
|
||||
activity.setReport(report);
|
||||
return update(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Activity activity) {
|
||||
activityRepository.delete(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity update(Activity activity) {
|
||||
return activityRepository.save(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity createActivity(Activity activity) {
|
||||
return activityRepository.save(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findMainResponsibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getMainResponsibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findSecondaryResponsibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getSecondaryResponsibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findVisibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getVisibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findSignActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getSignUpActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findParticipatedActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getParticipatedActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findParticipatingActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getParticipatingActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findCreatedActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getCreatedActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findAll(User user) {
|
||||
|
||||
List<Activity> activities = findCreatedActs(user);
|
||||
List<Activity> activities1 = findMainResponsibleActs(user);
|
||||
List<Activity> activities2 = findSecondaryResponsibleActs(user);
|
||||
List<Activity> activities3 = findParticipatingActs(user);
|
||||
List<Activity> activities4 = findParticipatedActs(user);
|
||||
List<Activity> activities5 = findParticipatingActs(user);
|
||||
List<Activity> activities6 = findSignActs(user);
|
||||
List<Activity> activities7 = findVisibleActs(user);
|
||||
Set<Activity> activitySet = new HashSet<>();
|
||||
activitySet.addAll(activities);
|
||||
activitySet.addAll(activities1);
|
||||
activitySet.addAll(activities2);
|
||||
activitySet.addAll(activities3);
|
||||
activitySet.addAll(activities4);
|
||||
activitySet.addAll(activities5);
|
||||
activitySet.addAll(activities6);
|
||||
activitySet.addAll(activities7);
|
||||
List<Activity> res = new ArrayList<>(activitySet);
|
||||
Collections.sort(res, new ActivityComparator());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ActivityComparator implements Comparator<Activity> {
|
||||
|
||||
|
||||
@Override
|
||||
public int compare(Activity o1, Activity o2) {
|
||||
|
||||
Period p1 = o1.getRealPeriod();
|
||||
Period p2 = o2.getRealPeriod();
|
||||
LocalDateTime s1 = p1.getStartTime();
|
||||
LocalDateTime s2 = p2.getStartTime();
|
||||
if (s1.isBefore(s2)) return -1;
|
||||
else if (s1.isAfter(s2)) return 1;
|
||||
else return 0;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Attendance;
|
||||
import com.codesdream.ase.repository.activity.AttendanceRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class AttendanceService {
|
||||
|
||||
@Resource
|
||||
AttendanceRepository attendanceRepository;
|
||||
|
||||
public Attendance save(Attendance attendance) {
|
||||
return attendanceRepository.save(attendance);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IActivityService {
|
||||
//通过标题查找活动
|
||||
Optional<Activity> findActivityByTitle(String title);
|
||||
|
||||
//通过创建人姓名查找活动
|
||||
Optional<Activity> findActivityByCreator(String creatorName);
|
||||
|
||||
//通过活动类型查找活动
|
||||
List<Activity> findActivityByType(User user, String type);
|
||||
|
||||
//活动持久化
|
||||
Activity save(Activity activity);
|
||||
|
||||
//添加活动报告
|
||||
Activity addReport(Activity activity, Report report);
|
||||
|
||||
//活动删除
|
||||
void delete(Activity activity);
|
||||
|
||||
//活动信息更新
|
||||
Activity update(Activity activity);
|
||||
|
||||
//活动创建
|
||||
Activity createActivity(Activity activity);
|
||||
|
||||
//查询主要负责的活动
|
||||
List<Activity> findMainResponsibleActs(User user);
|
||||
|
||||
//查询次要负责的活动
|
||||
List<Activity> findSecondaryResponsibleActs(User user);
|
||||
|
||||
//查询所有可见活动(即可报名活动、主次要负责的活动、参与过的活动等等之外却仍然可见的活动并集)
|
||||
List<Activity> findVisibleActs(User user);
|
||||
|
||||
//查找可报名的活动
|
||||
List<Activity> findSignActs(User user);
|
||||
|
||||
//查询参与过的活动
|
||||
List<Activity> findParticipatedActs(User user);
|
||||
|
||||
//查询将要参与的活动
|
||||
List<Activity> findParticipatingActs(User user);
|
||||
|
||||
//查询创建的活动
|
||||
List<Activity> findCreatedActs(User user);
|
||||
|
||||
//查询所有活动(权限内)
|
||||
List<Activity> findAll(User user);
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Period;
|
||||
import com.codesdream.ase.repository.activity.PeriodRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class PeriodService {
|
||||
|
||||
@Resource
|
||||
PeriodRepository periodRepository;
|
||||
|
||||
public Period save(Period period) {
|
||||
return periodRepository.save(period);
|
||||
}
|
||||
|
||||
public void delete(Period period) {
|
||||
periodRepository.delete(period);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
import com.codesdream.ase.repository.activity.ReportRepository;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ReportService implements IReportService {
|
||||
|
||||
@Resource
|
||||
ReportRepository reportRepository;
|
||||
ActivityService activityService;
|
||||
|
||||
@Override
|
||||
public Optional<Report> findByTitle(String title) {
|
||||
return reportRepository.findByTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Report> findByCreator(String creatorName) {
|
||||
return reportRepository.findByCreator(creatorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Report save(Activity activity, Report report) {
|
||||
if(activity == null){
|
||||
throw new RuntimeException("Activity does not exist.");
|
||||
}
|
||||
activityService.addReport(activity, report);
|
||||
return reportRepository.save(report);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Report report) {
|
||||
if(reportRepository.findById(report.getId()).isPresent()) reportRepository.delete(report);
|
||||
else throw new RuntimeException("Report does not exist.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Report update(Report report) {
|
||||
reportRepository.save(report);
|
||||
return report;
|
||||
}
|
||||
}
|
@ -2,12 +2,7 @@ package com.codesdream.ase.test;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
import com.codesdream.ase.model.permission.User;
|
||||
import com.codesdream.ase.service.AchievementService;
|
||||
import com.codesdream.ase.service.ActivityService;
|
||||
import com.codesdream.ase.service.UserService;
|
||||
import javafx.util.Pair;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
108
src/test/java/com/codesdream/ase/test/FileSystemTest.java
Normal file
108
src/test/java/com/codesdream/ase/test/FileSystemTest.java
Normal file
@ -0,0 +1,108 @@
|
||||
package com.codesdream.ase.test;
|
||||
|
||||
import com.codesdream.ase.component.activity.FileSystem;
|
||||
import com.codesdream.ase.exception.notfound.AppendixFileNotFoundException;
|
||||
import com.codesdream.ase.model.activity.AppendixFile;
|
||||
import com.codesdream.ase.repository.activity.AppendixFileRespository;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.InputStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
public class FileSystemTest {
|
||||
|
||||
@Resource
|
||||
FileSystem fileSystem;
|
||||
|
||||
@Resource
|
||||
AppendixFileService appendixFileService;
|
||||
|
||||
@Test
|
||||
public void getPresentFilesTest()
|
||||
{
|
||||
Iterable<AppendixFile> appendixFiles = appendixFileService.findAll();
|
||||
for (AppendixFile appendixFile:
|
||||
appendixFiles) {
|
||||
System.out.println(appendixFile.getFileName()+" "+appendixFile.getId()+" "+appendixFile.getType()+
|
||||
" "+appendixFile.getLastEditTime().toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void DeleteAllFilesTest()
|
||||
{
|
||||
Iterable<AppendixFile> appendixFiles = appendixFileService.findAll();
|
||||
for (AppendixFile appendixFile:
|
||||
appendixFiles) {
|
||||
fileSystem.deleteFile(appendixFile.getId());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongIDTest()
|
||||
{
|
||||
int id = 1;
|
||||
try {
|
||||
InputStream inputStream = fileSystem.getFile(id);
|
||||
} catch (AppendixFileNotFoundException e) {
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileNotExistErrorTest()
|
||||
{
|
||||
int id = 268;
|
||||
try {
|
||||
InputStream inputStream = fileSystem.getFile(id);
|
||||
} catch (AppendixFileNotFoundException e) {
|
||||
System.out.println(e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refreshDataBaseTest()
|
||||
{
|
||||
fileSystem.databaseRefresh();
|
||||
}
|
||||
@Test
|
||||
public void refreshDiskTest()
|
||||
{
|
||||
fileSystem.diskRefresh();
|
||||
}
|
||||
@Test
|
||||
public void createFile()
|
||||
{
|
||||
int id1 = 0;
|
||||
try {
|
||||
id1 = fileSystem.addFile("asfasefasgasgasg".getBytes(),"test1.txt");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
int id2 = fileSystem.addFile("aspgjparjgpoarjgpjpeg".getBytes(),"test2.jpeg");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = fileSystem.getFile(id1);
|
||||
} catch (AppendixFileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Scanner scanner = new Scanner(inputStream, "UTF-8");
|
||||
String text = scanner.useDelimiter("\\A").next();
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user