活动子系统service和repository初始添加
This commit is contained in:
parent
77113fcdc0
commit
eb66a86df7
@ -17,12 +17,13 @@ public class Activity {
|
||||
private int id;
|
||||
|
||||
//活动标题
|
||||
@Column(name = "title", nullable = false, unique = true)
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
//创建人
|
||||
@Column(name = "creator", nullable = false)
|
||||
private String creator;
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(nullable = false)
|
||||
private User creator;
|
||||
|
||||
//活动类型
|
||||
@Column(nullable = false)
|
||||
@ -137,7 +138,7 @@ public class Activity {
|
||||
@Column(name = "remind_time", nullable = true)
|
||||
private Date remindTime;
|
||||
|
||||
//附件组
|
||||
//附件组(名字)
|
||||
@ElementCollection(targetClass = java.lang.String.class)
|
||||
private List<String> enclosures;
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class Attendance {
|
||||
|
||||
//二维码url
|
||||
@Column(name = "qr_code", nullable = false, unique = true)
|
||||
private String qrCode;
|
||||
private String QRCode;
|
||||
|
||||
//是否在线
|
||||
@Column(name = "is_online", nullable = false)
|
||||
|
@ -26,7 +26,7 @@ public class UserActivity {
|
||||
private List<Activity> manageActivities;
|
||||
|
||||
//次要负责的活动
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
private List<Activity> assistActivities;
|
||||
|
||||
//可见的活动
|
||||
|
@ -0,0 +1,16 @@
|
||||
package com.codesdream.ase.repository;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ActivityRepository extends CrudRepository<Activity, Integer> {
|
||||
|
||||
Optional<Activity> findByTitle(String Title);
|
||||
|
||||
Optional<Activity> findByCreator(String creatorName);
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.codesdream.ase.repository;
|
||||
|
||||
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);
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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 org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class ActivityService implements IActivityService {
|
||||
|
||||
ActivityRepository activityRepository;
|
||||
|
||||
@Override
|
||||
public Optional<Activity> findActivityByTitle(String title) {
|
||||
return activityRepository.findByTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Activity> findActivityByCreator(String creatorName) {
|
||||
return activityRepository.findByCreator(creatorName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity save(Activity activity) {
|
||||
activityRepository.save(activity);
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity addReport(Activity activity, Report report) {
|
||||
activity.setReport(report);
|
||||
update(activity);
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Activity activity) {
|
||||
activityRepository.delete(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity update(Activity activity) {
|
||||
activityRepository.save(activity);
|
||||
return activity;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IActivityService {
|
||||
//通过标题查找活动
|
||||
Optional<Activity> findActivityByTitle(String title);
|
||||
|
||||
//通过创建人姓名查找活动
|
||||
Optional<Activity> findActivityByCreator(String creatorName);
|
||||
|
||||
//活动持久化
|
||||
Activity save(Activity activity);
|
||||
|
||||
//添加活动报告
|
||||
Activity addReport(Activity activity, Report report);
|
||||
|
||||
//活动删除
|
||||
void delete(Activity activity);
|
||||
|
||||
//活动信息更新
|
||||
Activity update(Activity activity);
|
||||
|
||||
}
|
19
src/main/java/com/codesdream/ase/service/IReportService.java
Normal file
19
src/main/java/com/codesdream/ase/service/IReportService.java
Normal file
@ -0,0 +1,19 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.model.activity.Report;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IReportService {
|
||||
|
||||
Optional<Report> findByTitle(String title);
|
||||
|
||||
Optional<Report> findByCreator(String creatorName);
|
||||
|
||||
Report save(Activity activity, Report report);
|
||||
|
||||
void delete(Report report);
|
||||
|
||||
Report update (Report report);
|
||||
}
|
45
src/main/java/com/codesdream/ase/service/ReportService.java
Normal file
45
src/main/java/com/codesdream/ase/service/ReportService.java
Normal file
@ -0,0 +1,45 @@
|
||||
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 java.util.Optional;
|
||||
|
||||
public class ReportService implements IReportService {
|
||||
|
||||
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);
|
||||
reportRepository.save(report);
|
||||
return 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user