增加了一个validator,活动子系统功能进一步增加
This commit is contained in:
parent
0a975dd82a
commit
45a8ea9c2d
@ -0,0 +1,39 @@
|
|||||||
|
package com.codesdream.ase.configure;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class ActivityFormConfigure {
|
||||||
|
|
||||||
|
private static final Set<String> stdActivityForm = new HashSet(){{
|
||||||
|
add("title");
|
||||||
|
add("creator");
|
||||||
|
add("type");
|
||||||
|
add("description");
|
||||||
|
add("cycle");
|
||||||
|
add("volunteers");
|
||||||
|
add("participate");
|
||||||
|
add("sign");
|
||||||
|
add("visible");
|
||||||
|
add("inform");
|
||||||
|
add("start-time");
|
||||||
|
add("remind");
|
||||||
|
add("enclosure");
|
||||||
|
add("chief-manager");
|
||||||
|
add("assist-manager");
|
||||||
|
add("attendance");
|
||||||
|
}};
|
||||||
|
public final static HashMap<String, Set<String>> stdActivityMap;
|
||||||
|
|
||||||
|
static {
|
||||||
|
stdActivityMap = new HashMap() {{
|
||||||
|
put("activity", stdActivityForm);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
|
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||||
|
import com.codesdream.ase.configure.AppConfigure;
|
||||||
|
import com.codesdream.ase.exception.InvalidFormFormatException;
|
||||||
|
import com.codesdream.ase.service.ActivityService;
|
||||||
|
import com.codesdream.ase.validator.WebFormValidator;
|
||||||
|
import org.springframework.http.HttpRequest;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class ActivityController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
ActivityService activityService;
|
||||||
|
|
||||||
|
@RequestMapping(value = "/activityCreator")
|
||||||
|
String activityCreatorView(Model model){return "activityCreator";}
|
||||||
|
|
||||||
|
@PostMapping(value = "/activityCreator")
|
||||||
|
String activityCreator(Model model, HttpServletRequest request) throws InvalidFormFormatException {
|
||||||
|
|
||||||
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||||
|
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
||||||
|
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
||||||
|
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||||
|
HashMap<String, Boolean> checkResult = webFormValidator.check(activityFormConfigure.stdActivityMap, parameterMap);
|
||||||
|
if(checkResult.get("activity").equals(false)){
|
||||||
|
throw new InvalidFormFormatException("Invalid activity form.");
|
||||||
|
}
|
||||||
|
return "act_created";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.codesdream.ase.exception;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
public class InvalidFormFormatException extends Throwable {
|
||||||
|
|
||||||
|
private String message = "";
|
||||||
|
|
||||||
|
public InvalidFormFormatException(){
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidFormFormatException(String message){
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
@ -17,39 +17,39 @@ public class UserActivity {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
//关联的用户
|
//关联的用户
|
||||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "userActivity")
|
@OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "userActivity")
|
||||||
@JoinColumn(nullable = false)
|
@JoinColumn(nullable = false)
|
||||||
private User user;
|
private User user;
|
||||||
|
|
||||||
//主要负责的活动
|
//主要负责的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> manageActivities;
|
private List<Activity> manageActivities;
|
||||||
|
|
||||||
//次要负责的活动
|
//次要负责的活动
|
||||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> assistActivities;
|
private List<Activity> assistActivities;
|
||||||
|
|
||||||
//可见的活动
|
//可见的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> visibleActivities;
|
private List<Activity> visibleActivities;
|
||||||
|
|
||||||
//创建的活动
|
//创建的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> createdActivities;
|
private List<Activity> createdActivities;
|
||||||
|
|
||||||
//可报名的活动
|
//可报名的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> signUpActivities;
|
private List<Activity> signUpActivities;
|
||||||
|
|
||||||
//已经参与的活动
|
//已经参与的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> participatedActivities;
|
private List<Activity> participatedActivities;
|
||||||
|
|
||||||
//正在(将要)参与的活动
|
//正在(将要)参与的活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> participatingActivities;
|
private List<Activity> participatingActivities;
|
||||||
|
|
||||||
//打卡签到活动
|
//打卡签到活动
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||||
private List<Activity> clockIn;
|
private List<Activity> clockIn;
|
||||||
}
|
}
|
||||||
|
@ -45,4 +45,9 @@ public class ActivityService implements IActivityService {
|
|||||||
return activityRepository.save(activity);
|
return activityRepository.save(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity createActivity(Activity activity) {
|
||||||
|
return activityRepository.save(activity);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,7 @@ public interface IActivityService {
|
|||||||
//活动信息更新
|
//活动信息更新
|
||||||
Activity update(Activity activity);
|
Activity update(Activity activity);
|
||||||
|
|
||||||
|
//活动创建
|
||||||
|
Activity createActivity(Activity activity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.codesdream.ase.validator;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class WebFormValidator {
|
||||||
|
|
||||||
|
public HashMap<String, Boolean> check(Map<String, Set<String>> stdFormMap, Map<String, String[]> webFormMap){
|
||||||
|
|
||||||
|
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
|
||||||
|
Set<String> stdKey = stdFormMap.keySet();
|
||||||
|
Set<String> webKey = webFormMap.keySet();
|
||||||
|
|
||||||
|
for(String key : webKey){
|
||||||
|
if(stdKey.contains(key)){
|
||||||
|
Set<String> stdSet = stdFormMap.get(key);
|
||||||
|
String[] webForm = webFormMap.get(key);
|
||||||
|
List<String> webList = new ArrayList<>();
|
||||||
|
Collections.addAll(webList, webForm);
|
||||||
|
if(stdSet.containsAll(webList)){
|
||||||
|
result.put(key,true);
|
||||||
|
}
|
||||||
|
else result.put(key,false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user