Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
837b311eb4
@ -1,9 +1,14 @@
|
|||||||
package com.codesdream.ase.controller;
|
package com.codesdream.ase.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.codesdream.ase.component.ASESpringUtil;
|
import com.codesdream.ase.component.ASESpringUtil;
|
||||||
|
import com.codesdream.ase.component.datamanager.JSONParameter;
|
||||||
import com.codesdream.ase.configure.ActivityFormConfigure;
|
import com.codesdream.ase.configure.ActivityFormConfigure;
|
||||||
import com.codesdream.ase.exception.InvalidFormFormatException;
|
import com.codesdream.ase.exception.InvalidFormFormatException;
|
||||||
|
import com.codesdream.ase.exception.LackOfActivityInformation;
|
||||||
|
import com.codesdream.ase.model.activity.Activity;
|
||||||
import com.codesdream.ase.service.ActivityService;
|
import com.codesdream.ase.service.ActivityService;
|
||||||
|
import com.codesdream.ase.validator.NullValueValidator;
|
||||||
import com.codesdream.ase.validator.WebFormValidator;
|
import com.codesdream.ase.validator.WebFormValidator;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
@ -12,7 +17,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.constraints.Null;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@ -21,19 +29,26 @@ public class ActivityController {
|
|||||||
@Resource
|
@Resource
|
||||||
ActivityService activityService;
|
ActivityService activityService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
JSONParameter jsonParameter;
|
||||||
|
|
||||||
@RequestMapping(value = "/activity_creator")
|
@RequestMapping(value = "/activity_creator")
|
||||||
String activityCreatorView(Model model){return "activity_creator";}
|
String activityCreatorView(Model model){return "activity_creator";}
|
||||||
|
|
||||||
@PostMapping(value = "/activity_creator")
|
@PostMapping(value = "/activity_creator")
|
||||||
String activityCreator(Model model, HttpServletRequest request) throws InvalidFormFormatException {
|
String activityCreator(Model model, HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||||
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
||||||
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
||||||
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||||
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)){
|
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)) {
|
||||||
throw new InvalidFormFormatException("Invalid activity form.");
|
throw new InvalidFormFormatException("Invalid activity form.");
|
||||||
}
|
}
|
||||||
|
JSONObject jsonObject = jsonParameter.getJSONByRequest(request);
|
||||||
|
Activity activity = jsonObject.toJavaObject(Activity.class);
|
||||||
|
NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class);
|
||||||
|
List<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||||
|
|
||||||
return "act_created";
|
return "act_created";
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
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;}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import org.springframework.security.core.parameters.P;
|
import org.springframework.security.core.parameters.P;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -137,7 +138,7 @@ public class Activity {
|
|||||||
//提前提醒时间
|
//提前提醒时间
|
||||||
@Column(name = "remind_time", nullable = true)
|
@Column(name = "remind_time", nullable = true)
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date remindTime;
|
private LocalDateTime remindTime;
|
||||||
|
|
||||||
//附件组(名字)
|
//附件组(名字)
|
||||||
@ElementCollection(targetClass = java.lang.String.class)
|
@ElementCollection(targetClass = java.lang.String.class)
|
||||||
|
@ -2,6 +2,7 @@ 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.model.permission.User;
|
||||||
import com.codesdream.ase.repository.activity.ActivityRepository;
|
import com.codesdream.ase.repository.activity.ActivityRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -50,4 +51,9 @@ public class ActivityService implements IActivityService {
|
|||||||
return activityRepository.save(activity);
|
return activityRepository.save(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*@Override
|
||||||
|
public Activity findActivitiesInTheCharge(User user) {
|
||||||
|
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ 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.model.permission.User;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ -27,4 +28,7 @@ public interface IActivityService {
|
|||||||
//活动创建
|
//活动创建
|
||||||
Activity createActivity(Activity activity);
|
Activity createActivity(Activity activity);
|
||||||
|
|
||||||
|
//查询主要负责的活动
|
||||||
|
//Activity findActivitiesInTheCharge(User user);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.codesdream.ase.validator;
|
||||||
|
|
||||||
|
import com.codesdream.ase.model.activity.Attendance;
|
||||||
|
import com.codesdream.ase.model.activity.Period;
|
||||||
|
import com.codesdream.ase.model.activity.Report;
|
||||||
|
import com.codesdream.ase.model.permission.User;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class NullValueValidator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入一个对象,利用Java的反射机制判断各个属性的值是否为空,并返回空值列表
|
||||||
|
* @param object 传入的对象
|
||||||
|
* @return 一个字符串列表,维护值为空的属性的名字
|
||||||
|
* @throws NoSuchMethodException
|
||||||
|
* @throws InvocationTargetException
|
||||||
|
* @throws IllegalAccessException
|
||||||
|
*/
|
||||||
|
public List<String> checkNullValues (Object object) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
|
Field[] fields = object.getClass().getDeclaredFields();
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
for (Field field : fields){
|
||||||
|
String name = field.getName();
|
||||||
|
String type = field.getGenericType().toString();
|
||||||
|
Method method = object.getClass().getMethod("get" + name);
|
||||||
|
name = field.getName();
|
||||||
|
if(type.equals("class java.lang.String")){
|
||||||
|
String str = (String) method.invoke(object);
|
||||||
|
if(str.isEmpty()) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("class com.codesdream.ase.model.permission.User")){
|
||||||
|
User user = (User) method.invoke(object);
|
||||||
|
if(user == null) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("java.util.Set<com.codesdream.ase.model.permission.User>")){
|
||||||
|
Set<User> users = (Set<User>) method.invoke(object);
|
||||||
|
if(users.isEmpty()) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("class com.codesdream.ase.model.activity.Period")){
|
||||||
|
Period period = (Period) method.invoke(object);
|
||||||
|
if(period == null) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals(("class java.time.LocalDateTime"))){
|
||||||
|
LocalDateTime date = (LocalDateTime) method.invoke(object);
|
||||||
|
if(date == null) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("java.util.List<java.lang.String>")){
|
||||||
|
List<String> strings = (List<String>) method.invoke(object);
|
||||||
|
if(strings.isEmpty()) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("boolean")){
|
||||||
|
boolean a = (boolean) method.invoke(object);
|
||||||
|
if(!a) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("class com.codesdream.ase.model.activity.Attendance")){
|
||||||
|
Attendance attendance = (Attendance) method.invoke(object);
|
||||||
|
if(attendance == null) result.add(name);
|
||||||
|
}
|
||||||
|
else if(type.equals("class com.codesdream.ase.model.activity.Report")){
|
||||||
|
Report report = (Report) method.invoke(object);
|
||||||
|
if(report == null) result.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -39,7 +39,7 @@
|
|||||||
<table style="width: 80% ;left:20px;position:inherit " class="table table-bordered">
|
<table style="width: 80% ;left:20px;position:inherit " class="table table-bordered">
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr style="background-color: #F2F2F2;border-color: #212121">
|
<tr style="background-color: #F2F2F2;border-color: #212121">
|
||||||
<th scope="row"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建人</font></font></th>
|
<th scope="row"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">创建人</></font></th>
|
||||||
<td style="background-color: #FFFFFF"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">二狗子</font></font></td>
|
<td style="background-color: #FFFFFF"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">二狗子</font></font></td>
|
||||||
<td><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">报名人数</font></font></td>
|
<td><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">报名人数</font></font></td>
|
||||||
<td style="background-color: #FFFFFF"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">1223</font></font></td>
|
<td style="background-color: #FFFFFF"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">1223</font></font></td>
|
||||||
|
Loading…
Reference in New Issue
Block a user