活动子系统部分修改,初步测试成功

This commit is contained in:
chuyan 2020-02-19 14:34:19 +08:00 committed by yourtree
parent f2539d6c12
commit 429ed0d941
9 changed files with 134 additions and 47 deletions

View File

@ -2,11 +2,10 @@ package com.codesdream.ase.model.activity;
import com.codesdream.ase.model.permission.User;
import lombok.Data;
import org.springframework.security.core.parameters.P;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.*;
@Data
@Entity
@ -21,7 +20,7 @@ public class Activity {
private String title;
//创建人
@OneToOne(cascade = CascadeType.ALL)
@ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(nullable = false)
private User creator;
@ -30,20 +29,20 @@ public class Activity {
private String type;
//活动描述
@Column(nullable = true)
@Column
private String description;
//活动周期格式阿拉伯数字数字+单位0表示无周期
@Column(nullable = true)
@Column
private String cycle;
//自愿参与人列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_volunteer")
private Set<User> volunteers;
//参与人列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_participate",
joinColumns = {
@JoinColumn(name = "act_id")
@ -55,7 +54,7 @@ public class Activity {
private Set<User> participateGroup;
//实际参与人列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_participated",
joinColumns = {
@JoinColumn(name = "act_id" )
@ -67,7 +66,7 @@ public class Activity {
private Set<User> participatedGroup;
//可报名人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_sign",
joinColumns = {
@JoinColumn(name = "act_id")
@ -79,7 +78,7 @@ public class Activity {
private Set<User> signGroup;
//已报名人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_signed",
joinColumns = {
@JoinColumn(name = "act_id")
@ -91,7 +90,7 @@ public class Activity {
private Set<User> signedGroup;
//可见人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_vis",
joinColumns = {
@JoinColumn(name = "act_id")
@ -103,7 +102,7 @@ public class Activity {
private Set<User> visibleGroup;
//通知人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_inform",
joinColumns = {
@JoinColumn(name = "act_id")
@ -115,7 +114,7 @@ public class Activity {
private Set<User> informGroup;
//已通知人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.DETACH)
@JoinTable(name = "act_informed",
joinColumns = {
@JoinColumn(name = "act_id")
@ -136,6 +135,7 @@ public class Activity {
//提前提醒时间
@Column(name = "remind_time", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Date remindTime;
//附件组(名字)
@ -143,21 +143,21 @@ public class Activity {
private List<String> enclosures;
//主要负责人
@OneToOne(cascade = CascadeType.ALL)
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(nullable = false)
private User chiefManager;
//次要负责人
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@OneToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
@JoinColumn(name = "act_id")
private List<User> assistManagers;
private Set<User> assistManagers;
//是否开始
@JoinColumn(name = "is_on", nullable = false)
@Column//(name = "is_on", nullable = false)
boolean isOn;
//是否结束
@JoinColumn(name = "is_off", nullable = false)
@Column//(name = "is_off", nullable = false)
boolean isOff;
//考勤安排
@ -167,4 +167,32 @@ public class Activity {
//活动报告
@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;
}
}

View File

@ -16,11 +16,11 @@ public class Attendance {
private int id;
//二维码url
@Column(name = "qr_code", nullable = false, unique = true)
@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;
//打卡时段列表
@ -28,6 +28,6 @@ public class Attendance {
private Set<Period> clockInPeriods;
//打卡方式0表示被扫1表示扫
@Column(nullable = false)
@Column//(nullable = false)
private boolean means;
}

View File

@ -4,6 +4,8 @@ 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;
@ -16,15 +18,15 @@ public class Period {
private int id;
//开始时间
@Column(name = "start_time", nullable = false)
private Date startTime;
@Column(name = "start_time")//, nullable = false)
private LocalDateTime startTime = LocalDateTime.of(2020,2,18,16,36);
//结束时间
@Column(name = "end_time", nullable = false)
private Date endTime;
@Column(name = "end_time")//, nullable = false)
private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);
//启用状态
@Column(name = "enabled", nullable = false)
@Column(name = "enabled")//, nullable = false)
private boolean enabled;
}

View File

@ -23,8 +23,8 @@ public class Report {
private String title;
//创建人
@Column(nullable = false)
private String creator;
@OneToOne(cascade = CascadeType.MERGE)
private User creator;
//活动类型
@Column(nullable = false)
@ -39,12 +39,12 @@ public class Report {
private String cycle;
//自愿参与人列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_volunteer")
private Set<User> volunteers;
//参与人列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_participate",
joinColumns = {
@JoinColumn(name = "act_id")
@ -68,7 +68,7 @@ public class Report {
private Set<User> participatedGroup;
//可报名人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_sign",
joinColumns = {
@JoinColumn(name = "act_id")
@ -80,7 +80,7 @@ public class Report {
private Set<User> signGroup;
//已报名人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_signed",
joinColumns = {
@JoinColumn(name = "act_id")
@ -92,7 +92,7 @@ public class Report {
private Set<User> signedGroup;
//可见人员列表
@ManyToMany(cascade = CascadeType.ALL)
@ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_vis",
joinColumns = {
@JoinColumn(name = "act_id")
@ -170,4 +170,5 @@ public class Report {
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "activity")
private Activity activity;
}

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository;
package com.codesdream.ase.repository.activity;
import com.codesdream.ase.model.activity.Activity;
import org.springframework.data.repository.CrudRepository;

View File

@ -1,4 +1,4 @@
package com.codesdream.ase.repository;
package com.codesdream.ase.repository.activity;
import com.codesdream.ase.model.activity.Report;
import org.springframework.data.repository.CrudRepository;

View File

@ -2,15 +2,17 @@ package com.codesdream.ase.service;
import com.codesdream.ase.model.activity.Activity;
import com.codesdream.ase.model.activity.Report;
import com.codesdream.ase.repository.ActivityRepository;
import com.codesdream.ase.repository.activity.ActivityRepository;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Optional;
@Service
public class ActivityService implements IActivityService {
ActivityRepository activityRepository;
@Resource
private ActivityRepository activityRepository;
@Override
public Optional<Activity> findActivityByTitle(String title) {
@ -24,15 +26,13 @@ public class ActivityService implements IActivityService {
@Override
public Activity save(Activity activity) {
activityRepository.save(activity);
return activity;
return activityRepository.save(activity);
}
@Override
public Activity addReport(Activity activity, Report report) {
activity.setReport(report);
update(activity);
return activity;
return update(activity);
}
@Override
@ -42,8 +42,7 @@ public class ActivityService implements IActivityService {
@Override
public Activity update(Activity activity) {
activityRepository.save(activity);
return activity;
return activityRepository.save(activity);
}
}

View File

@ -2,12 +2,14 @@ package com.codesdream.ase.service;
import com.codesdream.ase.model.activity.Activity;
import com.codesdream.ase.model.activity.Report;
import com.codesdream.ase.repository.ReportRepository;
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;
@ -27,8 +29,7 @@ public class ReportService implements IReportService {
throw new RuntimeException("Activity does not exist.");
}
activityService.addReport(activity, report);
reportRepository.save(report);
return report;
return reportRepository.save(report);
}
@Override

View File

@ -0,0 +1,56 @@
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.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.junit4.SpringRunner;
import javax.annotation.Resource;
@SpringBootTest
@RunWith(SpringRunner.class)
public class ActivityServiceTest {
@Resource
ActivityService activityService;
@Resource
UserService userService;
//Activity model的增删改查
@Test
public void baseFuncTest(){
User creator = new User();
creator.setUsername("Tom");
creator.setPassword("123456");
creator.getUserAuth().setStudentID("2018303026");
creator.getUserAuth().setMail("937447984@qq.com");
creator.getUserAuth().setUserQuestion("Your favourite animal?");
creator.getUserAuth().setUserAnswer("Cat");
creator.getUserDetail().setAtSchool(true);
creator.getUserDetail().setRealName("张三");
Pair<Boolean, User> checker = userService.checkIfUserExists("Tom");
if(checker.getKey()){
userService.delete(checker.getValue());
}
creator = userService.save(creator);
Activity activity = new Activity();
activity.setTitle("活动1");
activity.setCreator(creator);
activity.setType("lo");
activity.setChiefManager(creator);
Report report = new Report();
report.setTitle("活动1的报告");
activity = activityService.save(activity);
activity = activityService.addReport(activity, report);
//activityService.delete();
//Activity activity1 = new Activity("活动2");
}
}