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

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

View File

@ -4,6 +4,8 @@ import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import javax.persistence.*; import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
@ -16,15 +18,15 @@ public class Period {
private int id; private int id;
//开始时间 //开始时间
@Column(name = "start_time", nullable = false) @Column(name = "start_time")//, nullable = false)
private Date startTime; private LocalDateTime startTime = LocalDateTime.of(2020,2,18,16,36);
//结束时间 //结束时间
@Column(name = "end_time", nullable = false) @Column(name = "end_time")//, nullable = false)
private Date endTime; private LocalDateTime endTime = LocalDateTime.of(2020,2,18,16,37);
//启用状态 //启用状态
@Column(name = "enabled", nullable = false) @Column(name = "enabled")//, nullable = false)
private boolean enabled; private boolean enabled;
} }

View File

@ -23,8 +23,8 @@ public class Report {
private String title; private String title;
//创建人 //创建人
@Column(nullable = false) @OneToOne(cascade = CascadeType.MERGE)
private String creator; private User creator;
//活动类型 //活动类型
@Column(nullable = false) @Column(nullable = false)
@ -39,12 +39,12 @@ public class Report {
private String cycle; private String cycle;
//自愿参与人列表 //自愿参与人列表
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_volunteer") @JoinTable(name = "act_volunteer")
private Set<User> volunteers; private Set<User> volunteers;
//参与人列表 //参与人列表
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_participate", @JoinTable(name = "act_participate",
joinColumns = { joinColumns = {
@JoinColumn(name = "act_id") @JoinColumn(name = "act_id")
@ -68,7 +68,7 @@ public class Report {
private Set<User> participatedGroup; private Set<User> participatedGroup;
//可报名人员列表 //可报名人员列表
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_sign", @JoinTable(name = "act_sign",
joinColumns = { joinColumns = {
@JoinColumn(name = "act_id") @JoinColumn(name = "act_id")
@ -80,7 +80,7 @@ public class Report {
private Set<User> signGroup; private Set<User> signGroup;
//已报名人员列表 //已报名人员列表
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_signed", @JoinTable(name = "act_signed",
joinColumns = { joinColumns = {
@JoinColumn(name = "act_id") @JoinColumn(name = "act_id")
@ -92,7 +92,7 @@ public class Report {
private Set<User> signedGroup; private Set<User> signedGroup;
//可见人员列表 //可见人员列表
@ManyToMany(cascade = CascadeType.ALL) @ManyToMany(cascade = CascadeType.MERGE)
@JoinTable(name = "act_vis", @JoinTable(name = "act_vis",
joinColumns = { joinColumns = {
@JoinColumn(name = "act_id") @JoinColumn(name = "act_id")
@ -170,4 +170,5 @@ public class Report {
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "activity") @JoinColumn(name = "activity")
private Activity 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 com.codesdream.ase.model.activity.Activity;
import org.springframework.data.repository.CrudRepository; 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 com.codesdream.ase.model.activity.Report;
import org.springframework.data.repository.CrudRepository; 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.Activity;
import com.codesdream.ase.model.activity.Report; 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 org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Optional; import java.util.Optional;
@Service @Service
public class ActivityService implements IActivityService { public class ActivityService implements IActivityService {
ActivityRepository activityRepository; @Resource
private ActivityRepository activityRepository;
@Override @Override
public Optional<Activity> findActivityByTitle(String title) { public Optional<Activity> findActivityByTitle(String title) {
@ -24,15 +26,13 @@ public class ActivityService implements IActivityService {
@Override @Override
public Activity save(Activity activity) { public Activity save(Activity activity) {
activityRepository.save(activity); return activityRepository.save(activity);
return activity;
} }
@Override @Override
public Activity addReport(Activity activity, Report report) { public Activity addReport(Activity activity, Report report) {
activity.setReport(report); activity.setReport(report);
update(activity); return update(activity);
return activity;
} }
@Override @Override
@ -42,8 +42,7 @@ public class ActivityService implements IActivityService {
@Override @Override
public Activity update(Activity activity) { public Activity update(Activity activity) {
activityRepository.save(activity); return activityRepository.save(activity);
return 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.Activity;
import com.codesdream.ase.model.activity.Report; 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; import java.util.Optional;
public class ReportService implements IReportService { public class ReportService implements IReportService {
@Resource
ReportRepository reportRepository; ReportRepository reportRepository;
ActivityService activityService; ActivityService activityService;
@ -27,8 +29,7 @@ public class ReportService implements IReportService {
throw new RuntimeException("Activity does not exist."); throw new RuntimeException("Activity does not exist.");
} }
activityService.addReport(activity, report); activityService.addReport(activity, report);
reportRepository.save(report); return reportRepository.save(report);
return report;
} }
@Override @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");
}
}