ActivityViewerController基本完善
对DAO层以及service的功能进行了进一步完善 修改了一些命名规则
This commit is contained in:
parent
224b2c4a77
commit
b27cf72bc5
@ -17,7 +17,9 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
//将合法的JSON对象转化为Activity对象
|
||||
/**
|
||||
* JSONObject-Activity转化类
|
||||
*/
|
||||
@Component
|
||||
public class ActivityConverter {
|
||||
|
||||
@ -30,6 +32,10 @@ public class ActivityConverter {
|
||||
@Resource
|
||||
AttendanceService attendanceService;
|
||||
|
||||
/**
|
||||
* @param json 一个Optional的json对象,用以转化为Activity对象,此过程中进行值的合法校验
|
||||
* @return 一个可以被直接存储在数据库中的合法的Activity对象
|
||||
*/
|
||||
public Activity convertToActivity(Optional<JSONObject> json) {
|
||||
if (!json.isPresent()) {
|
||||
throw new NullPointerException();
|
||||
@ -37,10 +43,12 @@ public class ActivityConverter {
|
||||
Activity activity = new Activity();
|
||||
JSONObject jsonObject = json.get();
|
||||
|
||||
//设置活动创建人
|
||||
int userId = (int) jsonObject.get("creator");
|
||||
Optional<User> creator = userService.findUserById(userId);
|
||||
activity.setCreator(creator.get());
|
||||
|
||||
//设置参与人员
|
||||
List<Integer> participateGroupFromJson = (List<Integer>) jsonObject.get("participate-group");
|
||||
Set<User> participateGroup = new HashSet<>();
|
||||
for (int id : participateGroupFromJson) {
|
||||
@ -49,13 +57,16 @@ public class ActivityConverter {
|
||||
}
|
||||
activity.setParticipateGroup(participateGroup);
|
||||
|
||||
//设置活动标题
|
||||
String title = (String) jsonObject.get("title");
|
||||
activity.setTitle(title);
|
||||
|
||||
//设置主要负责人
|
||||
int chiefManagerId = (int) jsonObject.get("chief-manager");
|
||||
Optional<User> chiefManager = userService.findUserById(chiefManagerId);
|
||||
activity.setChiefManager(chiefManager.get());
|
||||
|
||||
//设置次要负责人
|
||||
List<Integer> assistManagersFromJSON = (List<Integer>) jsonObject.get("assist-managers");
|
||||
Set<User> assistManager = new HashSet<>();
|
||||
for (int id : assistManagersFromJSON) {
|
||||
@ -64,9 +75,11 @@ public class ActivityConverter {
|
||||
}
|
||||
activity.setAssistManagers(assistManager);
|
||||
|
||||
//设置活动类型
|
||||
String type = (String) jsonObject.get("type");
|
||||
activity.setType(type);
|
||||
|
||||
//设置
|
||||
String startTimeFromJSON = (String) jsonObject.get("start-time");
|
||||
String endTimeFromJSON = (String) jsonObject.get("end-time");
|
||||
LocalDateTime startTime = LocalDateTime.parse(startTimeFromJSON, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
@ -152,9 +165,7 @@ public class ActivityConverter {
|
||||
Attendance attendance = new Attendance();
|
||||
attendance.setClockInPeriods(periods);
|
||||
attendance.setOnline(attendanceOnLine);
|
||||
/**
|
||||
* 二维码模块未完成
|
||||
*/
|
||||
|
||||
attendance = attendanceService.save(attendance);
|
||||
activity.setAttendance(attendance);
|
||||
|
||||
|
@ -5,11 +5,9 @@ import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import jdk.internal.util.xml.impl.Input;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
@ -2,10 +2,15 @@ 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";
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ 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;
|
||||
@ -31,6 +32,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/forget/act")
|
||||
public class ActivityCreatorController {
|
||||
|
||||
@Resource
|
||||
@ -66,41 +68,40 @@ public class ActivityCreatorController {
|
||||
@Resource
|
||||
ActivityConverter activityConverter;
|
||||
|
||||
private final String url = "/forget/activity";
|
||||
|
||||
|
||||
@PostMapping(value = url + "/activity_creator")
|
||||
@PostMapping(value = "/creator")
|
||||
@ResponseBody
|
||||
@ApiOperation(value = "创建活动", notes = "所有有关用户的数据传递均使用id,类型为int")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "title", value = "活动标题", required = true),
|
||||
@ApiImplicitParam(name = "type", value = "活动类型", required = true),
|
||||
@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", value = "主要负责人", required = true),
|
||||
@ApiImplicitParam(name = "assist-managers", value = "次要负责人"),
|
||||
@ApiImplicitParam(name = "description", value = "活动描述"),
|
||||
@ApiImplicitParam(name = "cycle", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"),
|
||||
@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", value = "可参与人员"),
|
||||
@ApiImplicitParam(name = "inform-group", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"),
|
||||
@ApiImplicitParam(name = "visible-group", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"),
|
||||
@ApiImplicitParam(name = "remind-time", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"),
|
||||
@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);
|
||||
return error.toJSONString();
|
||||
throw new InvalidFormFormatException(error.toJSONString());
|
||||
}
|
||||
// 需要检查JSON是否合法
|
||||
Activity activity = activityConverter.convertToActivity(json);
|
||||
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||
|
||||
@ -136,7 +137,7 @@ public class ActivityCreatorController {
|
||||
String username = json.get().get("creator").toString();
|
||||
Optional<User> user = userService.findUserByUsername(username);
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user.get());
|
||||
userActivity.getCreatedActivities().add(activity);
|
||||
userActivity.getCreatedActs().add(activity);
|
||||
userActivityRepository.save(userActivity);
|
||||
}
|
||||
}
|
||||
@ -146,7 +147,8 @@ public class ActivityCreatorController {
|
||||
nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes());
|
||||
return nullParameters.toJSONString();
|
||||
}
|
||||
return url + "/act_created";
|
||||
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(activity);
|
||||
return jsonObject.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,37 +1,94 @@
|
||||
package com.codesdream.ase.controller.activity;
|
||||
|
||||
import com.codesdream.ase.component.ASESpringUtil;
|
||||
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.codesdream.ase.model.activity.Activity;
|
||||
import com.codesdream.ase.repository.activity.ActivityRepository;
|
||||
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.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.Principal;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/forget/act")
|
||||
public class ActivityViewerController {
|
||||
|
||||
private final String url = "/forget/activity";
|
||||
|
||||
@Resource
|
||||
ActivityService activityService;
|
||||
|
||||
@Resource
|
||||
ActivityRepository activityRepository;
|
||||
@GetMapping("/created_acts")
|
||||
String showCreated() {
|
||||
|
||||
@RequestMapping(value = url + "/my/participated", method = RequestMethod.GET)
|
||||
String showParticipated(Model model, HttpServletRequest request){
|
||||
Principal principal = request.getUserPrincipal();
|
||||
String username = principal.getName();
|
||||
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
||||
activityRepository = aseSpringUtil.getBean(ActivityRepository.class);
|
||||
//List<Activity> participatedActivities = activityRepository.findc
|
||||
return "/my/participated";
|
||||
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,14 +0,0 @@
|
||||
package com.codesdream.ase.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class LackOfActivityInformation extends Throwable {
|
||||
private String message = "";
|
||||
|
||||
public LackOfActivityInformation(){super();}
|
||||
|
||||
public LackOfActivityInformation(String message){this.message = message;}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.codesdream.ase.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class LackOfActivityInformationException extends Throwable {
|
||||
private String message = "";
|
||||
|
||||
public LackOfActivityInformationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LackOfActivityInformationException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -23,33 +23,33 @@ public class UserActivity {
|
||||
|
||||
//主要负责的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> manageActivities;
|
||||
private List<Activity> mainResponsibleActs;
|
||||
|
||||
//次要负责的活动
|
||||
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> assistActivities;
|
||||
private List<Activity> secondaryResponsibleActs;
|
||||
|
||||
//可见的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> visibleActivities;
|
||||
private List<Activity> visibleActs;
|
||||
|
||||
//创建的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> createdActivities;
|
||||
private List<Activity> createdActs;
|
||||
|
||||
//可报名的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> signUpActivities;
|
||||
private List<Activity> signUpActs;
|
||||
|
||||
//已经参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatedActivities;
|
||||
private List<Activity> participatedActs;
|
||||
|
||||
//正在(将要)参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatingActivities;
|
||||
private List<Activity> participatingActs;
|
||||
|
||||
//打卡签到活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> clockIn;
|
||||
private List<Activity> clockIns;
|
||||
}
|
||||
|
@ -1,16 +1,23 @@
|
||||
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 CrudRepository<Activity, Integer> {
|
||||
public interface ActivityRepository extends JpaRepository<Activity, Integer> {
|
||||
|
||||
Optional<Activity> findByTitle(String Title);
|
||||
|
||||
Optional<Activity> findByCreator(String creatorName);
|
||||
|
||||
List<Activity> findByUserAndType(User user, String type);
|
||||
|
||||
}
|
@ -1,14 +1,17 @@
|
||||
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,13 +1,17 @@
|
||||
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.util.Optional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
public class ActivityService implements IActivityService {
|
||||
@ -15,6 +19,9 @@ public class ActivityService implements IActivityService {
|
||||
@Resource
|
||||
private ActivityRepository activityRepository;
|
||||
|
||||
@Resource
|
||||
private UserActivityRepository userActivityRepository;
|
||||
|
||||
@Override
|
||||
public Optional<Activity> findActivityByTitle(String title) {
|
||||
return activityRepository.findByTitle(title);
|
||||
@ -25,6 +32,12 @@ public class ActivityService implements IActivityService {
|
||||
return activityRepository.findByCreator(creatorName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Activity> findActivityByType(User user, String type) {
|
||||
return activityRepository.findByUserAndType(user, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity save(Activity activity) {
|
||||
return activityRepository.save(activity);
|
||||
@ -51,9 +64,109 @@ public class ActivityService implements IActivityService {
|
||||
return activityRepository.save(activity);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public Activity findActivitiesInTheCharge(User user) {
|
||||
@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;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ 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 {
|
||||
@ -13,6 +14,9 @@ public interface IActivityService {
|
||||
//通过创建人姓名查找活动
|
||||
Optional<Activity> findActivityByCreator(String creatorName);
|
||||
|
||||
//通过活动类型查找活动
|
||||
List<Activity> findActivityByType(User user, String type);
|
||||
|
||||
//活动持久化
|
||||
Activity save(Activity activity);
|
||||
|
||||
@ -29,6 +33,27 @@ public interface IActivityService {
|
||||
Activity createActivity(Activity activity);
|
||||
|
||||
//查询主要负责的活动
|
||||
//Activity findActivitiesInTheCharge(User user);
|
||||
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);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user