From eb66a86df7ac78b93053e728290c058616346698 Mon Sep 17 00:00:00 2001 From: chuyan <1047381936@qq.com> Date: Mon, 17 Feb 2020 18:08:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=AD=90=E7=B3=BB=E7=BB=9Fse?= =?UTF-8?q?rvice=E5=92=8Crepository=E5=88=9D=E5=A7=8B=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/model/activity/Activity.java | 9 ++-- .../ase/model/activity/Attendance.java | 2 +- .../ase/model/activity/UserActivity.java | 2 +- .../ase/repository/ActivityRepository.java | 16 ++++++ .../ase/repository/ReportRepository.java | 14 ++++++ .../ase/service/ActivityService.java | 49 +++++++++++++++++++ .../ase/service/IActivityService.java | 27 ++++++++++ .../ase/service/IReportService.java | 19 +++++++ .../codesdream/ase/service/ReportService.java | 45 +++++++++++++++++ 9 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/repository/ActivityRepository.java create mode 100644 src/main/java/com/codesdream/ase/repository/ReportRepository.java create mode 100644 src/main/java/com/codesdream/ase/service/ActivityService.java create mode 100644 src/main/java/com/codesdream/ase/service/IActivityService.java create mode 100644 src/main/java/com/codesdream/ase/service/IReportService.java create mode 100644 src/main/java/com/codesdream/ase/service/ReportService.java diff --git a/src/main/java/com/codesdream/ase/model/activity/Activity.java b/src/main/java/com/codesdream/ase/model/activity/Activity.java index 85e2173..c75703f 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Activity.java +++ b/src/main/java/com/codesdream/ase/model/activity/Activity.java @@ -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 enclosures; diff --git a/src/main/java/com/codesdream/ase/model/activity/Attendance.java b/src/main/java/com/codesdream/ase/model/activity/Attendance.java index f65f92a..c68cb49 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Attendance.java +++ b/src/main/java/com/codesdream/ase/model/activity/Attendance.java @@ -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) diff --git a/src/main/java/com/codesdream/ase/model/activity/UserActivity.java b/src/main/java/com/codesdream/ase/model/activity/UserActivity.java index 8c610c8..8a06e1d 100644 --- a/src/main/java/com/codesdream/ase/model/activity/UserActivity.java +++ b/src/main/java/com/codesdream/ase/model/activity/UserActivity.java @@ -26,7 +26,7 @@ public class UserActivity { private List manageActivities; //次要负责的活动 - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List assistActivities; //可见的活动 diff --git a/src/main/java/com/codesdream/ase/repository/ActivityRepository.java b/src/main/java/com/codesdream/ase/repository/ActivityRepository.java new file mode 100644 index 0000000..d1dfe34 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/ActivityRepository.java @@ -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 { + + Optional findByTitle(String Title); + + Optional findByCreator(String creatorName); + +} \ No newline at end of file diff --git a/src/main/java/com/codesdream/ase/repository/ReportRepository.java b/src/main/java/com/codesdream/ase/repository/ReportRepository.java new file mode 100644 index 0000000..8df84fc --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/ReportRepository.java @@ -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 { + Optional findByTitle(String reportTitle); + + Optional findByCreator(String creatorName); +} diff --git a/src/main/java/com/codesdream/ase/service/ActivityService.java b/src/main/java/com/codesdream/ase/service/ActivityService.java new file mode 100644 index 0000000..00d71de --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/ActivityService.java @@ -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 findActivityByTitle(String title) { + return activityRepository.findByTitle(title); + } + + @Override + public Optional 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; + } + +} diff --git a/src/main/java/com/codesdream/ase/service/IActivityService.java b/src/main/java/com/codesdream/ase/service/IActivityService.java new file mode 100644 index 0000000..d35c7c1 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/IActivityService.java @@ -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 findActivityByTitle(String title); + + //通过创建人姓名查找活动 + Optional findActivityByCreator(String creatorName); + + //活动持久化 + Activity save(Activity activity); + + //添加活动报告 + Activity addReport(Activity activity, Report report); + + //活动删除 + void delete(Activity activity); + + //活动信息更新 + Activity update(Activity activity); + +} diff --git a/src/main/java/com/codesdream/ase/service/IReportService.java b/src/main/java/com/codesdream/ase/service/IReportService.java new file mode 100644 index 0000000..2ac8614 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/IReportService.java @@ -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 findByTitle(String title); + + Optional findByCreator(String creatorName); + + Report save(Activity activity, Report report); + + void delete(Report report); + + Report update (Report report); +} diff --git a/src/main/java/com/codesdream/ase/service/ReportService.java b/src/main/java/com/codesdream/ase/service/ReportService.java new file mode 100644 index 0000000..4a86fbc --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/ReportService.java @@ -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 findByTitle(String title) { + return reportRepository.findByTitle(title); + } + + @Override + public Optional 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; + } +}