From 887b44e2eeeaf4792582553182a92f48d0865d66 Mon Sep 17 00:00:00 2001 From: chuyan <1047381936@qq.com> Date: Sat, 14 Mar 2020 13:16:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?activity=20controller=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/controller/ActivityController.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/codesdream/ase/controller/ActivityController.java b/src/main/java/com/codesdream/ase/controller/ActivityController.java index dff7f0f..6dac269 100644 --- a/src/main/java/com/codesdream/ase/controller/ActivityController.java +++ b/src/main/java/com/codesdream/ase/controller/ActivityController.java @@ -2,6 +2,7 @@ package com.codesdream.ase.controller; import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.component.activity.NullValueAttributes; import com.codesdream.ase.component.datamanager.JSONParameter; import com.codesdream.ase.configure.ActivityFormConfigure; import com.codesdream.ase.exception.InvalidFormFormatException; @@ -32,6 +33,8 @@ public class ActivityController { @Resource JSONParameter jsonParameter; + + @RequestMapping(value = "/activity_creator") String activityCreatorView(Model model){return "activity_creator";} @@ -49,6 +52,24 @@ public class ActivityController { Activity activity = jsonObject.toJavaObject(Activity.class); NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class); List nullValues = nullValueValidator.checkNullValues(activity); + NullValueAttributes nullValueAttributes = aseSpringUtil.getBean(NullValueAttributes.class); + for (String str : nullValues){ + if(str.equals("title")){ + nullValueAttributes.getNullValueAttributes().add("title"); + } + else if(str.equals("creator")){ + nullValueAttributes.getNullValueAttributes().add("creator"); + } + else if(str.equals("type")){ + nullValueAttributes.getNullValueAttributes().add("type"); + } + else if(str.equals("planPeriod")){ + nullValueAttributes.getNullValueAttributes().add("planPeriod"); + } + else if(str.equals("chiefManager")){ + nullValueAttributes.getNullValueAttributes().add("chiefManager"); + } + } return "act_created"; } From c1a23adabae56a64a74b47bf9a805add7c828ab8 Mon Sep 17 00:00:00 2001 From: chuyan <1047381936@qq.com> Date: Sat, 14 Mar 2020 17:28:01 +0800 Subject: [PATCH 2/6] =?UTF-8?q?controller=E7=BB=93=E6=9E=84=E5=BE=AE?= =?UTF-8?q?=E8=B0=83=EF=BC=9B=E6=B4=BB=E5=8A=A8=E5=88=9B=E5=BB=BA=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=9F=BA=E6=9C=AC=E5=AE=8C=E5=96=84=EF=BC=9B=E6=B4=BB?= =?UTF-8?q?=E5=8A=A8=E6=9F=A5=E7=9C=8B=E7=95=8C=E9=9D=A2=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E7=BC=96=E8=BE=91=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=99=A8=EF=BC=9B=E7=BB=84=E4=BB=B6=E7=BB=93=E6=9E=84=E5=BE=AE?= =?UTF-8?q?=E8=B0=83=EF=BC=9BDAO=E5=B1=82=E5=BE=AE=E8=B0=83=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0UserActivityRepository=EF=BC=9B=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AF=BB=E6=89=BE=E5=BD=93=E5=89=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=BB=84=E4=BB=B6=EF=BC=8C=E6=AD=A4=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=B0=9A=E6=9C=AA=E5=AE=8C=E5=96=84=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activity/ActivityViewerController.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java new file mode 100644 index 0000000..91a112d --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java @@ -0,0 +1,36 @@ +package com.codesdream.ase.controller.activity; + +import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.repository.activity.ActivityRepository; +import com.codesdream.ase.service.ActivityService; +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 javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.security.Principal; +import java.util.List; + +@Controller +public class ActivityViewerController { + + @Resource + ActivityService activityService; + + @Resource + ActivityRepository activityRepository; + + @RequestMapping(value = "/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 participatedActivities = activityRepository.findc + return "/my/participated"; + } +} From 205b7e26029f44486906a6288d11610fdf567132 Mon Sep 17 00:00:00 2001 From: Vindicator645 <45960487+Vindicator645@users.noreply.github.com> Date: Sat, 14 Mar 2020 17:30:51 +0800 Subject: [PATCH 3/6] Leaving --- .../ase/controller/LeavesController.java | 71 +++++++++++++++++++ .../codesdream/ase/model/leaves/Leave.java | 2 +- .../ase/model/leaves/LeavesSystem.java | 7 -- .../repository/leaves/LeaveRepository.java | 6 ++ .../ase/service/ILeavesService.java | 4 ++ .../codesdream/ase/service/LeavesService.java | 57 +++++++++++++++ 6 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/controller/LeavesController.java delete mode 100644 src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java create mode 100644 src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java create mode 100644 src/main/java/com/codesdream/ase/service/ILeavesService.java create mode 100644 src/main/java/com/codesdream/ase/service/LeavesService.java diff --git a/src/main/java/com/codesdream/ase/controller/LeavesController.java b/src/main/java/com/codesdream/ase/controller/LeavesController.java new file mode 100644 index 0000000..8694283 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/LeavesController.java @@ -0,0 +1,71 @@ +package com.codesdream.ase.controller; + +import com.alibaba.fastjson.JSONObject; +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.respond.FailedSONRespond; +import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; +import com.codesdream.ase.component.permission.ASEUsernameEncoder; +import com.codesdream.ase.component.json.request.UserLeaveChecker; +import com.codesdream.ase.component.json.respond.UserLeaveCheckerJSONRespond; +import com.codesdream.ase.service.LeavesService; +import lombok.extern.slf4j.Slf4j; +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.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Optional; + + +/** + * 登录界面控制器类 + */ +@Slf4j +@Controller +public class LeavesController { + + @Resource + private JSONParameter jsonParameter; + + @Resource + private LeavesService leavesService; + + @Resource + private ASEUsernameEncoder usernameEncoder; + + @RequestMapping(value = "/") + String printLeave(Model model) { + return "Leave"; + } + + @RequestMapping(value = "/Leave/check", method = RequestMethod.POST) + @ResponseBody + String checkLeave(HttpServletRequest request){ + + // 检查是否为JSON + Optional json = jsonParameter.getJSONByRequest(request); + if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond()); + + + UserLeaveChecker LeaveChecker = json.get().toJavaObject(UserLeaveChecker.class); + // 检查类型 + if(LeaveChecker.getCheckType().equals("UsernameExistChecker")){ + // 根据学号计算用户名 + String user = usernameEncoder.encode(LeaveChecker.getUsername()) ; + // 查询用户名存在状态 + boolean existStatus = userService.checkIfUserExists(user).getKey(); + // 构造返回对象 + UserLeaveCheckerJSONRespond respond = new UserLeaveCheckerJSONRespond(); + respond.setUserExist(existStatus); + return jsonParameter.getJSONString(respond); + } + else { + // 返回失败对象 + return jsonParameter.getJSONString(new JSONBaseRespondObject()); + } + } + +} diff --git a/src/main/java/com/codesdream/ase/model/leaves/Leave.java b/src/main/java/com/codesdream/ase/model/leaves/Leave.java index bc4f361..80a00ae 100644 --- a/src/main/java/com/codesdream/ase/model/leaves/Leave.java +++ b/src/main/java/com/codesdream/ase/model/leaves/Leave.java @@ -6,7 +6,7 @@ import java.util.*; import javax.persistence.*; @Data @Entity -@Table(name = "leaves_archive") +@Table(name = "leave") public class Leave { @Id @GeneratedValue(strategy = GenerationType.AUTO) diff --git a/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java b/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java deleted file mode 100644 index d21d7ad..0000000 --- a/src/main/java/com/codesdream/ase/model/leaves/LeavesSystem.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.codesdream.ase.model.leaves; -/** - 请假信息的管理系统 - */ -public class LeavesSystem { - -} diff --git a/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java b/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java new file mode 100644 index 0000000..180baf2 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java @@ -0,0 +1,6 @@ +package com.codesdream.ase.repository.leaves; +import org.springframework.data.repository.CrudRepository; + +public interface LeaveRepository extends CrudRepository{ + +} diff --git a/src/main/java/com/codesdream/ase/service/ILeavesService.java b/src/main/java/com/codesdream/ase/service/ILeavesService.java new file mode 100644 index 0000000..4f8b0af --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/ILeavesService.java @@ -0,0 +1,4 @@ +package com.codesdream.ase.service; + +public interface ILeavesService { +} diff --git a/src/main/java/com/codesdream/ase/service/LeavesService.java b/src/main/java/com/codesdream/ase/service/LeavesService.java new file mode 100644 index 0000000..7a36cce --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/LeavesService.java @@ -0,0 +1,57 @@ +package com.codesdream.ase.service; + +import com.codesdream.ase.model.leaves.Leave; +import com.codesdream.ase.repository.leaves.LeaveRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Optional; + +@Service +public class LeavesService implements ILeavesService { + + @Resource + private LeaveRepository leaveRepository; + + @Override + public Optional findLeaveByTitle(String title) { + return LeaveRepository.findByTitle(title); + } + + @Override + public Optional findLeaveByCreator(String creatorName) { + return LeaveRepository.findByCreator(creatorName); + } + + @Override + public Leave save(Leave Leave) { + return LeaveRepository.save(Leave); + } + + @Override + public Leave addReport(Leave Leave, Report report) { + Leave.setReport(report); + return update(Leave); + } + + @Override + public void delete(Leave Leave) { + LeaveRepository.delete(Leave); + } + + @Override + public Leave update(Leave Leave) { + return LeaveRepository.save(Leave); + } + + @Override + public Leave createLeave(Leave Leave) { + return LeaveRepository.save(Leave); + } + + /*@Override + public Leave findActivitiesInTheCharge(User user) { + + }*/ + +} From 2277f5c8e4fc890622a400cd90577e9b9e02440f Mon Sep 17 00:00:00 2001 From: Vindicator645 <45960487+Vindicator645@users.noreply.github.com> Date: Sun, 15 Mar 2020 15:17:47 +0800 Subject: [PATCH 4/6] Leaving --- .../repository/leaves/LeaveRepository.java | 8 ++++- .../ase/service/ILeavesService.java | 27 ++++++++++++++ .../codesdream/ase/service/LeavesService.java | 36 +++++++++---------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java b/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java index 180baf2..5ea51c1 100644 --- a/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java +++ b/src/main/java/com/codesdream/ase/repository/leaves/LeaveRepository.java @@ -1,6 +1,12 @@ package com.codesdream.ase.repository.leaves; +import com.codesdream.ase.model.activity.Report; +import com.codesdream.ase.model.leaves.Leave; import org.springframework.data.repository.CrudRepository; -public interface LeaveRepository extends CrudRepository{ +import java.util.Optional; +public interface LeaveRepository extends CrudRepository{ + + Optional findByTitle(String title) ; + Optional findByCreator(String creatorName); } diff --git a/src/main/java/com/codesdream/ase/service/ILeavesService.java b/src/main/java/com/codesdream/ase/service/ILeavesService.java index 4f8b0af..0d7b994 100644 --- a/src/main/java/com/codesdream/ase/service/ILeavesService.java +++ b/src/main/java/com/codesdream/ase/service/ILeavesService.java @@ -1,4 +1,31 @@ package com.codesdream.ase.service; +import com.codesdream.ase.model.leaves.Leave; + + +import java.util.Optional; + public interface ILeavesService { + //通过标题查找活动 + Optional findLeaveByTitle(String title); + + //通过创建人姓名查找活动 + Optional findLeaveByCreator(String creatorName); + + //活动 + Leave save(Leave leave); + + + //请假删除 + void delete(Leave Leave); + + //请假信息更新 + Leave update(Leave Leave); + + //创建请假条目 + Leave createLeave(Leave Leave); + + //查询主要负责的活动 + //Leave findActivitiesInTheCharge(User user); + } diff --git a/src/main/java/com/codesdream/ase/service/LeavesService.java b/src/main/java/com/codesdream/ase/service/LeavesService.java index 7a36cce..a9c475d 100644 --- a/src/main/java/com/codesdream/ase/service/LeavesService.java +++ b/src/main/java/com/codesdream/ase/service/LeavesService.java @@ -13,40 +13,36 @@ public class LeavesService implements ILeavesService { @Resource private LeaveRepository leaveRepository; + @Override public Optional findLeaveByTitle(String title) { - return LeaveRepository.findByTitle(title); + return Optional.empty(); } @Override - public Optional findLeaveByCreator(String creatorName) { - return LeaveRepository.findByCreator(creatorName); + public Optional findLeaveByCreator(String creatorName) { + return Optional.empty(); } @Override - public Leave save(Leave Leave) { - return LeaveRepository.save(Leave); + public Leave save(Leave leave) { + return leaveRepository.save(leave); + } + + + @Override + public void delete(Leave leave) { + leaveRepository.delete(leave); } @Override - public Leave addReport(Leave Leave, Report report) { - Leave.setReport(report); - return update(Leave); + public Leave update(Leave leave) { + return leaveRepository.save(leave); } @Override - public void delete(Leave Leave) { - LeaveRepository.delete(Leave); - } - - @Override - public Leave update(Leave Leave) { - return LeaveRepository.save(Leave); - } - - @Override - public Leave createLeave(Leave Leave) { - return LeaveRepository.save(Leave); + public Leave createLeave(Leave leave) { + return leaveRepository.save(leave); } /*@Override From f13b30b4b7e5e7251fec524ee9b475c288dd7243 Mon Sep 17 00:00:00 2001 From: chuyan <1047381936@qq.com> Date: Sun, 15 Mar 2020 19:59:41 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=B4=BB=E5=8A=A8control?= =?UTF-8?q?ler=E4=BF=AE=E6=94=B9=E4=BB=A5=E5=8F=8A=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E3=80=82=E9=83=A8=E5=88=86=E6=A0=A1=E9=AA=8C=E5=99=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E3=80=82activity=E7=B3=BB=E7=BB=9Fbug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/activity/CurrentUserGetter.java | 26 +++ .../activity/NullValueAttributes.java | 12 ++ .../ase/controller/ActivityController.java | 82 ---------- .../activity/ActivityCreatorController.java | 148 ++++++++++++++++++ .../activity/ActivityViewerController.java | 1 - .../ase/exception/UserNotFoundException.java | 7 +- .../ase/model/activity/Activity.java | 5 +- .../ase/model/activity/UserActivity.java | 2 +- .../activity/UserActivityRepository.java | 14 ++ .../ase/validator/ActivityValidator.java | 17 ++ .../ase/validator/WebFormValidator.java | 2 +- 11 files changed, 228 insertions(+), 88 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java create mode 100644 src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java delete mode 100644 src/main/java/com/codesdream/ase/controller/ActivityController.java create mode 100644 src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java create mode 100644 src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java create mode 100644 src/main/java/com/codesdream/ase/validator/ActivityValidator.java diff --git a/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java b/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java new file mode 100644 index 0000000..cfebcbc --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/activity/CurrentUserGetter.java @@ -0,0 +1,26 @@ +package com.codesdream.ase.component.activity; + +import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.repository.permission.UserRepository; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.security.Principal; +import java.util.Optional; + +//获取当前用户的用户名 +@Component +public class CurrentUserGetter { + private Optional user; + public Optional getCurrentUser(HttpServletRequest request){ + + Principal principal = request.getUserPrincipal(); + String username = principal.getName(); + ASESpringUtil aseSpringUtil = new ASESpringUtil(); + UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class); + this.user = userRepository.findByUsername(username); + return this.user; + } + +} diff --git a/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java b/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java new file mode 100644 index 0000000..dcd93ea --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/activity/NullValueAttributes.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.component.activity; + +import lombok.Data; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Data +@Component +public class NullValueAttributes { + private List nullValueAttributes; +} diff --git a/src/main/java/com/codesdream/ase/controller/ActivityController.java b/src/main/java/com/codesdream/ase/controller/ActivityController.java deleted file mode 100644 index cc214a0..0000000 --- a/src/main/java/com/codesdream/ase/controller/ActivityController.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.codesdream.ase.controller; - -import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.component.ASESpringUtil; -import com.codesdream.ase.component.activity.NullValueAttributes; -import com.codesdream.ase.component.datamanager.JSONParameter; -import com.codesdream.ase.configure.ActivityFormConfigure; -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.validator.NullValueValidator; -import com.codesdream.ase.validator.WebFormValidator; -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 javax.validation.constraints.Null; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -@Controller -public class ActivityController { - - @Resource - ActivityService activityService; - - @Resource - JSONParameter jsonParameter; - - - - @RequestMapping(value = "/activity_creator") - String activityCreatorView(Model model){return "activity_creator";} - - @PostMapping(value = "/activity_creator") - String activityCreator(Model model, HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - - Map parameterMap = request.getParameterMap(); - ASESpringUtil aseSpringUtil = new ASESpringUtil(); - ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class); - WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class); - if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)) { - throw new InvalidFormFormatException("Invalid activity form."); - } - // 需要检查JSON是否合法 - Optional jsonObject = jsonParameter.getJSONByRequest(request); - if(!jsonObject.isPresent()) return "error"; - Activity activity = jsonObject.get().toJavaObject(Activity.class); - - NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class); - List nullValues = nullValueValidator.checkNullValues(activity); - NullValueAttributes nullValueAttributes = aseSpringUtil.getBean(NullValueAttributes.class); - for (String str : nullValues){ - if(str.equals("title")){ - nullValueAttributes.getNullValueAttributes().add("title"); - } - else if(str.equals("creator")){ - nullValueAttributes.getNullValueAttributes().add("creator"); - } - else if(str.equals("type")){ - nullValueAttributes.getNullValueAttributes().add("type"); - } - else if(str.equals("planPeriod")){ - nullValueAttributes.getNullValueAttributes().add("planPeriod"); - } - else if(str.equals("chiefManager")){ - nullValueAttributes.getNullValueAttributes().add("chiefManager"); - } - } - - return "act_created"; - } -} - - diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java new file mode 100644 index 0000000..25f1d4b --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java @@ -0,0 +1,148 @@ +package com.codesdream.ase.controller.activity; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.codesdream.ase.component.ASESpringUtil; +import com.codesdream.ase.component.activity.NullValueAttributes; +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; +import com.codesdream.ase.configure.ActivityFormConfigure; +import com.codesdream.ase.exception.InvalidFormFormatException; +import com.codesdream.ase.exception.UserNotFoundException; +import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.model.activity.UserActivity; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.repository.activity.UserActivityRepository; +import com.codesdream.ase.repository.permission.UserRepository; +import com.codesdream.ase.service.ActivityService; +import com.codesdream.ase.validator.ActivityValidator; +import com.codesdream.ase.validator.NullValueValidator; +import com.codesdream.ase.validator.WebFormValidator; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.lang.reflect.InvocationTargetException; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@Controller +public class ActivityCreatorController { + + @Resource + ActivityService activityService; + + @Resource + JSONParameter jsonParameter; + + @Resource + ASESpringUtil aseSpringUtil; + + @Resource + ActivityFormConfigure activityFormConfigure; + + @Resource + WebFormValidator webFormValidator; + + @Resource + NullValueValidator nullValueValidator; + + @Resource + NullValueAttributes nullValueAttributes; + + @Resource + ActivityValidator activityValidator; + + @Resource + UserRepository userRepository; + + @Resource + UserActivityRepository userActivityRepository; + + private final String url = "/forget/activity"; + + @RequestMapping(value = url + "/activity_creator") + String activityCreatorView(Model model){return "activity_creator";} + + + @PostMapping(value = url + "/activity_creator") + @ResponseBody + String activityCreator(@RequestBody JSONObject jsonParam, Model model, HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { + + JSONObject error = new JSONObject(); + + Map parameterMap = request.getParameterMap(); + aseSpringUtil = new ASESpringUtil(); + //WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class); + if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)) { + error.put("error", "Invalid form format"); + return error.toJSONString(); + } + // 需要检查JSON是否合法 + Optional jsonObject = jsonParameter.getJSONByRequest(request); + if(!jsonObject.isPresent()){ + error.put("error", "Invalid type."); + return error.toJSONString(); + } + Activity activity = jsonObject.get().toJavaObject(Activity.class); + + //NullValueValidator nullValueValidator = aseSpringUtil.getBean(NullValueValidator.class); + List nullValues = nullValueValidator.checkNullValues(activity); + //= aseSpringUtil.getBean(NullValueAttributes.class); + for (String str : nullValues){ + if(str.equals("title")){ + nullValueAttributes.getNullValueAttributes().add("title"); + } + else if(str.equals("creator")){ + nullValueAttributes.getNullValueAttributes().add("creator"); + } + else if(str.equals("type")){ + nullValueAttributes.getNullValueAttributes().add("type"); + } + else if(str.equals("planPeriod")){ + nullValueAttributes.getNullValueAttributes().add("planPeriod"); + } + else if(str.equals("chiefManager")){ + nullValueAttributes.getNullValueAttributes().add("chiefManager"); + } + } + //如果为空,存下此活动并跳转至成功创建页面 + if(nullValueAttributes.getNullValueAttributes().isEmpty()){ + + //ActivityValidator activityValidator = aseSpringUtil.getBean(ActivityValidator.class); + String[] errorParameters = activityValidator.check(parameterMap); + if(errorParameters != null){ + JSONObject invalidParameters = new JSONObject(); + invalidParameters.put("invalid_parameters", errorParameters); + return invalidParameters.toJSONString(); + + } + else{ + //UserRepository userRepository = aseSpringUtil.getBean(UserRepository.class); + //activityService = aseSpringUtil.getBean(ActivityService.class); + activity = activityService.createActivity(activity); + String username = parameterMap.get("creator")[0]; + Optional user = userRepository.findByUsername(username); + //UserActivityRepository userActivityRepository = aseSpringUtil.getBean(UserActivityRepository.class); + UserActivity userActivity = userActivityRepository.findByUser(user.get()); + userActivity.getCreatedActivities().add(activity); + userActivityRepository.save(userActivity); + } + } + //否则返回一个JSON对象给前端,此处应该是JSP页面,动态标红 + else{ + JSONObject nullParameters = new JSONObject(); + nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes()); + return nullParameters.toJSONString(); + } + return url + "/act_created"; + } +} + + diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java index 91a112d..e6df04e 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java @@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMethod; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.security.Principal; -import java.util.List; @Controller public class ActivityViewerController { diff --git a/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java b/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java index f0d38e3..c721ae9 100644 --- a/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java +++ b/src/main/java/com/codesdream/ase/exception/UserNotFoundException.java @@ -8,10 +8,15 @@ import lombok.EqualsAndHashCode; public class UserNotFoundException extends RuntimeException { Integer id; String username; - + String message; public UserNotFoundException(Integer id, String username){ super(); this.id = id; this.username = username; } + + public UserNotFoundException(String message){ + super(); + this.message = message; + } } 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 6359756..4da4f56 100644 --- a/src/main/java/com/codesdream/ase/model/activity/Activity.java +++ b/src/main/java/com/codesdream/ase/model/activity/Activity.java @@ -129,6 +129,7 @@ public class Activity { //计划开始时间 @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(nullable = false) private Period planPeriod; //实际开始时间 @@ -154,11 +155,11 @@ public class Activity { private Set assistManagers; //是否开始 - @Column//(name = "is_on", nullable = false) + @Column(name = "is_on", nullable = false) boolean isOn; //是否结束 - @Column//(name = "is_off", nullable = false) + @Column(name = "is_off", nullable = false) boolean isOff; //考勤安排 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 b1acab7..01add89 100644 --- a/src/main/java/com/codesdream/ase/model/activity/UserActivity.java +++ b/src/main/java/com/codesdream/ase/model/activity/UserActivity.java @@ -18,7 +18,7 @@ public class UserActivity { //关联的用户 @OneToOne(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY, mappedBy = "userActivity") - @JoinColumn(nullable = false) + @JoinColumn(nullable = false, unique = true) private User user; //主要负责的活动 diff --git a/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java b/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java new file mode 100644 index 0000000..80ff99c --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java @@ -0,0 +1,14 @@ +package com.codesdream.ase.repository.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.Optional; + +@Repository +public interface UserActivityRepository extends CrudRepository { + + UserActivity findByUser(User user); +} diff --git a/src/main/java/com/codesdream/ase/validator/ActivityValidator.java b/src/main/java/com/codesdream/ase/validator/ActivityValidator.java new file mode 100644 index 0000000..2d8b4bf --- /dev/null +++ b/src/main/java/com/codesdream/ase/validator/ActivityValidator.java @@ -0,0 +1,17 @@ +package com.codesdream.ase.validator; + +import com.codesdream.ase.model.activity.Activity; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +//检查当前活动各属性值是否合法(存在) +@Component +public class ActivityValidator { + + public String[] check(Map parameterMap){ + return null; + } +} diff --git a/src/main/java/com/codesdream/ase/validator/WebFormValidator.java b/src/main/java/com/codesdream/ase/validator/WebFormValidator.java index e710ce3..6ffaac0 100644 --- a/src/main/java/com/codesdream/ase/validator/WebFormValidator.java +++ b/src/main/java/com/codesdream/ase/validator/WebFormValidator.java @@ -11,7 +11,7 @@ public class WebFormValidator { public boolean check(Collection stdForm, Map webFormMap){ Collection webForm = webFormMap.keySet(); - if(stdForm.containsAll(webForm)){ + if(webForm.containsAll(stdForm)){ return true; } return false; From 4916dea8913764bef7346f7a58318ff94b027846 Mon Sep 17 00:00:00 2001 From: Vindicator645 <45960487+Vindicator645@users.noreply.github.com> Date: Sun, 15 Mar 2020 20:25:42 +0800 Subject: [PATCH 6/6] Leaving --- .../json/request/UserLeaveRequest.java | 7 +++++ .../ase/controller/LeavesController.java | 26 ++++++------------- .../codesdream/ase/model/leaves/Leave.java | 12 ++++++++- 3 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java diff --git a/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java new file mode 100644 index 0000000..485c0ce --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java @@ -0,0 +1,7 @@ +package com.codesdream.ase.component.json.request; + +public class UserLeaveRequest { + + + +} diff --git a/src/main/java/com/codesdream/ase/controller/LeavesController.java b/src/main/java/com/codesdream/ase/controller/LeavesController.java index 8694283..9ad7eb1 100644 --- a/src/main/java/com/codesdream/ase/controller/LeavesController.java +++ b/src/main/java/com/codesdream/ase/controller/LeavesController.java @@ -2,11 +2,10 @@ package com.codesdream.ase.controller; import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.request.UserLeaveRequest; import com.codesdream.ase.component.json.respond.FailedSONRespond; import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; import com.codesdream.ase.component.permission.ASEUsernameEncoder; -import com.codesdream.ase.component.json.request.UserLeaveChecker; -import com.codesdream.ase.component.json.respond.UserLeaveCheckerJSONRespond; import com.codesdream.ase.service.LeavesService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; @@ -41,31 +40,22 @@ public class LeavesController { return "Leave"; } + //提交请假申请 @RequestMapping(value = "/Leave/check", method = RequestMethod.POST) @ResponseBody - String checkLeave(HttpServletRequest request){ + String requestLeave(HttpServletRequest request){ // 检查是否为JSON Optional json = jsonParameter.getJSONByRequest(request); if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond()); - UserLeaveChecker LeaveChecker = json.get().toJavaObject(UserLeaveChecker.class); + UserLeaveRequest LeaveChecker = json.get().toJavaObject(UserLeaveRequest.class); // 检查类型 - if(LeaveChecker.getCheckType().equals("UsernameExistChecker")){ - // 根据学号计算用户名 - String user = usernameEncoder.encode(LeaveChecker.getUsername()) ; - // 查询用户名存在状态 - boolean existStatus = userService.checkIfUserExists(user).getKey(); - // 构造返回对象 - UserLeaveCheckerJSONRespond respond = new UserLeaveCheckerJSONRespond(); - respond.setUserExist(existStatus); - return jsonParameter.getJSONString(respond); - } - else { - // 返回失败对象 - return jsonParameter.getJSONString(new JSONBaseRespondObject()); - } + } + //列出某辅导员待审核名单 + + //列出某人 } diff --git a/src/main/java/com/codesdream/ase/model/leaves/Leave.java b/src/main/java/com/codesdream/ase/model/leaves/Leave.java index 80a00ae..5cf3b32 100644 --- a/src/main/java/com/codesdream/ase/model/leaves/Leave.java +++ b/src/main/java/com/codesdream/ase/model/leaves/Leave.java @@ -17,15 +17,25 @@ public class Leave { //审批人容器 @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private Set userTo; + //请假原因 + @Column + private String reasonToLeave; + + //请假类型 病假,事假等 @Column(name = "type", nullable = false) private String type; //批准状态 @Column(name = "Authentication", nullable = false) - private Boolean Authentication; + private String Authentication; + + //审核备注 + @Column + private String Comment; //开始时间 @Column(nullable = false) private Date startTime; + @Column(nullable = false) private Date endTime; //申请时间