diff --git a/pom.xml b/pom.xml index 900747a..c36beed 100644 --- a/pom.xml +++ b/pom.xml @@ -177,6 +177,12 @@ 2.9.2 + + com.github.java-json-tools + json-patch + 1.12 + + diff --git a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java index 9706a9a..38b079a 100644 --- a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java +++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java @@ -1,17 +1,15 @@ package com.codesdream.ase.component.activity; import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.exception.DataInvalidFormatException; +import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException; import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.Attendance; import com.codesdream.ase.model.activity.Period; import com.codesdream.ase.model.permission.User; -import com.codesdream.ase.repository.activity.ActivityRepository; import com.codesdream.ase.service.ActivityService; import com.codesdream.ase.service.AttendanceService; import com.codesdream.ase.service.PeriodService; import com.codesdream.ase.service.UserService; -import javafx.util.converter.LocalDateTimeStringConverter; import org.springframework.stereotype.Component; import javax.annotation.Resource; diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java index 83c1948..c11d01b 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelGenerator.java @@ -1,7 +1,7 @@ package com.codesdream.ase.component.datamanager; import com.codesdream.ase.exception.notfound.DataFileNotFoundException; -import com.codesdream.ase.exception.DataIOException; +import com.codesdream.ase.exception.innerservererror.DataIOException; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java index f5471f2..794f8c3 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataExcelReader.java @@ -2,6 +2,9 @@ package com.codesdream.ase.component.datamanager; import com.codesdream.ase.exception.*; +import com.codesdream.ase.exception.innerservererror.DataIOException; +import com.codesdream.ase.exception.innerservererror.DataIllegalTableFormatException; +import com.codesdream.ase.exception.innerservererror.DataInvalidFormatException; import com.codesdream.ase.exception.notfound.DataFileNotFoundException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; @@ -48,7 +51,7 @@ public class DataExcelReader implements DataReader { Row titleRow = sheet.getRow(0); colNumber = titleRow.getLastCellNum(); // 表头项目个数不可为0 - if(colNumber == 0) throw new DataIllegalTableFormatException(); + if(colNumber == 0) throw new DataIllegalTableFormatException(); Collection title = new ArrayList<>(); for(int cellIdx = 0; cellIdx < colNumber; cellIdx++){ title.add(readCell(titleRow.getCell(cellIdx))); diff --git a/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java b/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java index cf1217c..97d04f5 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/DataTable.java @@ -1,11 +1,9 @@ package com.codesdream.ase.component.datamanager; -import com.codesdream.ase.exception.DataIllegalTableFormatException; +import com.codesdream.ase.exception.innerservererror.DataIllegalTableFormatException; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -import javax.persistence.Table; -import javax.swing.text.html.Option; import java.util.*; // 描述一张数据表 diff --git a/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java b/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java new file mode 100644 index 0000000..64b719b --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java @@ -0,0 +1,23 @@ +package com.codesdream.ase.component.datamanager; + +import com.codesdream.ase.exception.innerservererror.HandlingErrorsException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jsonpatch.JsonPatch; +import com.github.fge.jsonpatch.JsonPatchException; +import org.springframework.stereotype.Controller; + +@Controller +public class JsonPathParameter { + public T parsePathToObject(JsonPatch patch, T object){ + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode patched = patch.apply(mapper.convertValue(object, JsonNode.class)); + return (T) mapper.treeToValue(patched, object.getClass()); + } catch (JsonPatchException | JsonProcessingException e) { + throw new HandlingErrorsException(e.getMessage()); + } + + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java new file mode 100644 index 0000000..870743e --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonablePCCList.java @@ -0,0 +1,22 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.PermissionContainersCollection; +import com.codesdream.ase.model.permission.Tag; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@ApiModel("权限容器集合列表") +public class JsonablePCCList { + List pccIdList; + + public JsonablePCCList(Tag tag){ + for(PermissionContainersCollection pcc : tag.getPermissionContainersCollections()){ + pccIdList.add(pcc.getId()); + } + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java similarity index 87% rename from src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java rename to src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java index 523c61e..e91c3cb 100644 --- a/src/main/java/com/codesdream/ase/component/json/model/JsonableTagUserList.java +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java @@ -12,13 +12,13 @@ import java.util.List; @Data @NoArgsConstructor @ApiModel("标签所属用户集合") -public class JsonableTagUserList { +public class JsonableUserList { @ApiModelProperty(name = "用户列表") private List users; - public JsonableTagUserList(Tag tag){ + public JsonableUserList(Tag tag){ for(User user : tag.getUsers()){ users.add(user.getId()); } diff --git a/src/main/java/com/codesdream/ase/component/json/request/UserLeaveAuth.java b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveAuth.java new file mode 100644 index 0000000..92452c6 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveAuth.java @@ -0,0 +1,16 @@ +package com.codesdream.ase.component.json.request; + +import lombok.Data; + +@Data +public class UserLeaveAuth { + /* + 备注 + */ + private int id; + private String Comment; + /* + 审核结果 + */ + private String newStat; +} 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 index 485c0ce..df05547 100644 --- a/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java +++ b/src/main/java/com/codesdream/ase/component/json/request/UserLeaveRequest.java @@ -1,7 +1,15 @@ package com.codesdream.ase.component.json.request; +import lombok.Data; + +import java.util.Date; +@Data public class UserLeaveRequest { - - + private String UserId;//用户名 + private String Type;//请假类型 + private String Reason;//请假原因 + private String Addon;//附件 + private Date Starttime;//开始时间 + private Date EndTime;//结束时间 } diff --git a/src/main/java/com/codesdream/ase/component/json/request/UserSGettudentLeaveListRequest.java b/src/main/java/com/codesdream/ase/component/json/request/UserSGettudentLeaveListRequest.java new file mode 100644 index 0000000..b97c771 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/request/UserSGettudentLeaveListRequest.java @@ -0,0 +1,8 @@ +package com.codesdream.ase.component.json.request; + +import lombok.Data; + +@Data +public class UserSGettudentLeaveListRequest { + private int studentId; +} diff --git a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java index bdddf30..281ced4 100644 --- a/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java +++ b/src/main/java/com/codesdream/ase/controller/ASEControllerAdvice.java @@ -3,7 +3,11 @@ package com.codesdream.ase.controller; import com.codesdream.ase.component.api.QuickJSONRespond; import com.codesdream.ase.component.json.respond.ErrorInfoJSONRespond; import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.badrequest.IllegalException; import com.codesdream.ase.exception.conflict.RelatedObjectsExistException; +import com.codesdream.ase.exception.innerservererror.FormatException; +import com.codesdream.ase.exception.innerservererror.HandlingErrorsException; +import com.codesdream.ase.exception.innerservererror.RuntimeIOException; import com.codesdream.ase.exception.notfound.NotFoundException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,7 +25,8 @@ public class ASEControllerAdvice { @ExceptionHandler(value = { NullPointerException.class, - AlreadyExistException.class + AlreadyExistException.class, + IllegalException.class }) public ResponseEntity handleBadRequest(Exception ex) { return getResponse(HttpStatus.BAD_REQUEST, ex); @@ -43,6 +48,14 @@ public class ASEControllerAdvice { return getResponse(HttpStatus.CONFLICT, ex); } + @ExceptionHandler(value = { + HandlingErrorsException.class, + FormatException.class, + RuntimeIOException.class}) + public ResponseEntity handleInnerServerError(Exception ex){ + return getResponse(HttpStatus.INTERNAL_SERVER_ERROR, ex); + } + private ResponseEntity getResponse(HttpStatus status, Exception ex){ return ResponseEntity.status(status).body(getJSON(status, ex)); diff --git a/src/main/java/com/codesdream/ase/controller/LeavesController.java b/src/main/java/com/codesdream/ase/controller/LeavesController.java index d94a638..ae85621 100644 --- a/src/main/java/com/codesdream/ase/controller/LeavesController.java +++ b/src/main/java/com/codesdream/ase/controller/LeavesController.java @@ -1,9 +1,17 @@ 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.api.QuickJSONRespond; import com.codesdream.ase.component.auth.ASEUsernameEncoder; +import com.codesdream.ase.component.datamanager.JSONParameter; + +import com.codesdream.ase.component.json.request.UserLeaveAuth; +import com.codesdream.ase.component.json.request.UserLeaveRequest; +import com.codesdream.ase.component.json.request.UserSGettudentLeaveListRequest; +import com.codesdream.ase.component.json.respond.JSONStandardFailedRespond; +import com.codesdream.ase.exception.innerservererror.InvalidFormFormatException; +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.leaves.Leave; import com.codesdream.ase.service.LeavesService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; @@ -14,6 +22,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.Calendar; +import java.util.Date; import java.util.Optional; @@ -27,34 +37,79 @@ public class LeavesController { @Resource private JSONParameter jsonParameter; + @Resource + private QuickJSONRespond quickJSONRespond; + @Resource private LeavesService leavesService; @Resource private ASEUsernameEncoder usernameEncoder; - @RequestMapping(value = "/leave") +/* @RequestMapping(value = "/") String printLeave(Model model) { return "Leave"; - } + }*/ //提交请假申请 - @RequestMapping(value = "/leave/check", method = RequestMethod.POST) + @RequestMapping(value = "/Leave/check", method = RequestMethod.POST) @ResponseBody - String requestLeave(HttpServletRequest request){ + String leaveRequest(HttpServletRequest request){ // 检查是否为JSON Optional json = jsonParameter.getJSONByRequest(request); - // if(!json.isPresent()) return jsonParameter.getJSONString(new FailedSONRespond()); + if(!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond()); + UserLeaveRequest userLeaveRequest=json.get().toJavaObject(UserLeaveRequest.class); + Leave newleave=new Leave(); + newleave.setUserFrom(userLeaveRequest.getUserId()); + newleave.setType(userLeaveRequest.getType()); + newleave.setReasonToLeave(userLeaveRequest.getReason()); + //newleave.set + newleave.setStartTime(userLeaveRequest.getStarttime()); + newleave.setEndTime(userLeaveRequest.getEndTime()); + Calendar calendar =Calendar.getInstance(); + Date time = calendar.getTime(); + newleave.setApplyTime(time); + leavesService.save(newleave); + //eturn quickJSONRespond.getRespond200(null, respond); - UserLeaveRequest LeaveChecker = json.get().toJavaObject(UserLeaveRequest.class); + return quickJSONRespond.getRespond200("申请已提交"); // 检查类型 - return jsonParameter.getJSONString(request); } - //列出某辅导员待审核名单 + @RequestMapping(value = "/Leave/auth", method = RequestMethod.POST) + @ResponseBody + String getLeaveAuth(HttpServletRequest request){ + + // 检查是否为JSON + Optional json = jsonParameter.getJSONByRequest(request); + if(!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond()); + UserLeaveAuth userLeaveAuth=json.get().toJavaObject(UserLeaveAuth.class); + Optional leave =leavesService.findLeaveById(userLeaveAuth.getId()); + if(!leave.isPresent()){ + return quickJSONRespond.getRespond500("No such entry"); + } + Leave newLeave=leave.get(); + newLeave.setComment(userLeaveAuth.getComment()); + newLeave.setAuthentication(userLeaveAuth.getNewStat()); + return quickJSONRespond.getRespond200("Authentication status updated"); + } + + @RequestMapping(value = "/Leave/getStuLeaveList", method = RequestMethod.POST) + @ResponseBody + Leave getStuLeavelist(HttpServletRequest request) throws InvalidFormFormatException { + Optional json = jsonParameter.getJSONByRequest(request); + if(!json.isPresent()) throw new InvalidFormFormatException("json request not recognized"); + UserSGettudentLeaveListRequest userSGettudentLeaveListRequest=json.get().toJavaObject(UserSGettudentLeaveListRequest.class); + if(leavesService.findLeaveById(userSGettudentLeaveListRequest.getStudentId()).isPresent()){ + Leave leave =leavesService.findLeaveById(userSGettudentLeaveListRequest.getStudentId()).get(); + return leave; + }else{ + throw new NotFoundException("Student Does not exist"); + } + + } - //列出某人 } diff --git a/src/main/java/com/codesdream/ase/controller/PermissionController.java b/src/main/java/com/codesdream/ase/controller/PermissionController.java index 766d619..400bbfa 100644 --- a/src/main/java/com/codesdream/ase/controller/PermissionController.java +++ b/src/main/java/com/codesdream/ase/controller/PermissionController.java @@ -1,30 +1,31 @@ package com.codesdream.ase.controller; -import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.component.datamanager.JSONParameter; -import com.codesdream.ase.component.api.QuickJSONRespond; +import com.codesdream.ase.component.datamanager.JsonPathParameter; +import com.codesdream.ase.component.json.model.JsonablePCCList; import com.codesdream.ase.component.json.model.JsonableTag; -import com.codesdream.ase.component.json.model.JsonableTagUserList; +import com.codesdream.ase.component.json.model.JsonableUserList; import com.codesdream.ase.component.json.model.JsonableUser; -import com.codesdream.ase.component.json.respond.PermissionJSONRespond; import com.codesdream.ase.exception.badrequest.AlreadyExistException; import com.codesdream.ase.exception.conflict.RelatedObjectsExistException; import com.codesdream.ase.exception.notfound.NotFoundException; -import com.codesdream.ase.exception.notfound.TagNotFoundException; +import com.codesdream.ase.model.permission.PermissionContainersCollection; import com.codesdream.ase.model.permission.Tag; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.service.IUserService; import com.codesdream.ase.service.PermissionService; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jsonpatch.JsonPatch; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import springfox.documentation.spring.web.json.Json; import javax.annotation.Resource; -import javax.servlet.http.HttpServletRequest; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -41,6 +42,9 @@ public class PermissionController { @Resource private IUserService userService; + @Resource + private JsonPathParameter pathParameter; + // 根据名字创建新的标签 @PostMapping("tag") @ResponseStatus(HttpStatus.CREATED) @@ -99,31 +103,51 @@ public class PermissionController { permissionService.delete(tag.get()); } + // 根据名字搜索标签的简要信息 + @PatchMapping(path = "tag", consumes = "application/json-patch+json") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation("修改标签属性") + @ApiImplicitParam(name = "name", value = "标签名") + public JsonableTag updateTag(@RequestParam(value = "name") String name, @RequestBody JsonPatch patch){ + Optional tag = permissionService.findTag(name); + if(!tag.isPresent()) throw new NotFoundException(name); + + JsonableTag jsonableTag = new JsonableTag(tag.get()); + jsonableTag = pathParameter.parsePathToObject(patch, jsonableTag); + + tag.get().setName(jsonableTag.getName()); + tag.get().setDescription(jsonableTag.getDescription()); + + return new JsonableTag(permissionService.save(tag.get())); + + } + + @GetMapping("tag/users") @ResponseStatus(HttpStatus.OK) @ApiOperation("搜索单个标签所属用户集合信息") - public JsonableTagUserList getUserTag(@RequestParam(value = "name") String name){ + public JsonableUserList getUserTag(@RequestParam(value = "name") String name){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); - return new JsonableTagUserList(tag.get()); + return new JsonableUserList(tag.get()); } @PutMapping("tag/users") @ApiOperation("更新索单个标签所属用户集合信息") - public JsonableTagUserList setUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList setUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set userSet = new HashSet<>(userList.getUsers()); tag.get().setUsers(userService.findUsersById(userSet)); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @PostMapping("tag/users") @ApiOperation("更新单个标签所属用户集合中添加一个或多个用户") - public JsonableTagUserList addUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList addUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers())); @@ -133,13 +157,14 @@ public class PermissionController { userSet.addAll(newUserSet); tag.get().setUsers(userSet); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @DeleteMapping("tag/users") + @ResponseStatus(HttpStatus.OK) @ApiOperation("从单个标签所属用户集合中删除一个或多个用户") @ApiImplicitParam(name = "name", value = "标签名") - public JsonableTagUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableTagUserList userList){ + public JsonableUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ Optional tag = permissionService.findTag(name); if(!tag.isPresent()) throw new NotFoundException(name); Set userSet = tag.get().getUsers(); @@ -148,7 +173,7 @@ public class PermissionController { userSet.removeAll(deleteUserSet); tag.get().setUsers(userSet); - return new JsonableTagUserList(permissionService.save(tag.get())); + return new JsonableUserList(permissionService.save(tag.get())); } @GetMapping("tags/users") @@ -167,6 +192,31 @@ public class PermissionController { return jsonableUsers; } + @GetMapping("tag/pcc") + @ResponseStatus(HttpStatus.OK) + @ApiOperation("获取标签所含权限容器集合列表") + public JsonablePCCList getPCCTag(@RequestParam(value = "name") String name){ + Optional tagOptional = permissionService.findTag(name); + if(!tagOptional.isPresent()) throw new NotFoundException(name); + + return new JsonablePCCList(tagOptional.get()); + } + + @PostMapping("tag/pcc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation("在指定标签的权限列表中添加一个或多个权限容器") + public JsonablePCCList addPCCTag(@RequestParam(value = "name") String name, JsonablePCCList jsonablePCCList){ + Optional tagOptional = permissionService.findTag(name); + if(!tagOptional.isPresent()) throw new NotFoundException(name); + + Set pccs = tagOptional.get().getPermissionContainersCollections(); + pccs.addAll(permissionService.findPCCs(new HashSet(jsonablePCCList.getPccIdList()))); + + tagOptional.get().setPermissionContainersCollections(pccs); + + return new JsonablePCCList(permissionService.save(tagOptional.get())); + } + } diff --git a/src/main/java/com/codesdream/ase/exception/DataIOException.java b/src/main/java/com/codesdream/ase/exception/DataIOException.java deleted file mode 100644 index f220cac..0000000 --- a/src/main/java/com/codesdream/ase/exception/DataIOException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.codesdream.ase.exception; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class DataIOException extends RuntimeException { -} diff --git a/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java b/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java deleted file mode 100644 index 5c01b8c..0000000 --- a/src/main/java/com/codesdream/ase/exception/DataIllegalTableFormatException.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.codesdream.ase.exception; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class DataIllegalTableFormatException extends RuntimeException { -} diff --git a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java similarity index 73% rename from src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java rename to src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java index 34b485b..1cd9768 100644 --- a/src/main/java/com/codesdream/ase/exception/BaseInformationIllegalException.java +++ b/src/main/java/com/codesdream/ase/exception/badrequest/BaseInformationIllegalException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.badrequest; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class BaseInformationIllegalException extends RuntimeException { +public class BaseInformationIllegalException extends IllegalException { String type; String value; diff --git a/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java new file mode 100644 index 0000000..c62f81a --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/badrequest/IllegalException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.badrequest; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class IllegalException extends RuntimeException { + public IllegalException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java b/src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java similarity index 68% rename from src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java rename to src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java index ce1331e..1107c14 100644 --- a/src/main/java/com/codesdream/ase/exception/UserInformationIllegalException.java +++ b/src/main/java/com/codesdream/ase/exception/badrequest/UserInformationIllegalException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.badrequest; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class UserInformationIllegalException extends RuntimeException { +public class UserInformationIllegalException extends IllegalException { String username; diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java new file mode 100644 index 0000000..7c3615e --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIOException.java @@ -0,0 +1,9 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class DataIOException extends RuntimeIOException { +} diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java new file mode 100644 index 0000000..d68b2d8 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataIllegalTableFormatException.java @@ -0,0 +1,9 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class DataIllegalTableFormatException extends FormatException { +} diff --git a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java similarity index 71% rename from src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java rename to src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java index b5d4de5..99f6dd9 100644 --- a/src/main/java/com/codesdream/ase/exception/DataInvalidFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/DataInvalidFormatException.java @@ -1,11 +1,11 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.innerservererror; import lombok.Data; import lombok.EqualsAndHashCode; @EqualsAndHashCode(callSuper = true) @Data -public class DataInvalidFormatException extends RuntimeException { +public class DataInvalidFormatException extends FormatException { String information; public DataInvalidFormatException(Exception e){ diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java new file mode 100644 index 0000000..dd6a734 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/FormatException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class FormatException extends RuntimeException { + public FormatException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java new file mode 100644 index 0000000..e87c712 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/HandlingErrorsException.java @@ -0,0 +1,13 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.Data; +import lombok.NoArgsConstructor; + +// 处理错误对应的异常类 +@Data +@NoArgsConstructor +public class HandlingErrorsException extends RuntimeException { + public HandlingErrorsException(String msg){ + super(msg); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java similarity index 75% rename from src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java rename to src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java index be25439..fc49abb 100644 --- a/src/main/java/com/codesdream/ase/exception/InvalidFormFormatException.java +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/InvalidFormFormatException.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.exception; +package com.codesdream.ase.exception.innerservererror; import lombok.Data; import lombok.EqualsAndHashCode; @@ -7,7 +7,7 @@ import javax.persistence.criteria.CriteriaBuilder; @EqualsAndHashCode(callSuper = true) @Data -public class InvalidFormFormatException extends Throwable { +public class InvalidFormFormatException extends FormatException { private String message = "Invalid form format"; diff --git a/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java b/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java new file mode 100644 index 0000000..df0c511 --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/innerservererror/RuntimeIOException.java @@ -0,0 +1,10 @@ +package com.codesdream.ase.exception.innerservererror; + +import lombok.NoArgsConstructor; + +@NoArgsConstructor +public class RuntimeIOException extends RuntimeException { + public RuntimeIOException(String msg){ + super(msg); + } +} 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 e5ef606..5f65fc7 100644 --- a/src/main/java/com/codesdream/ase/model/leaves/Leave.java +++ b/src/main/java/com/codesdream/ase/model/leaves/Leave.java @@ -9,12 +9,13 @@ import javax.persistence.*; @Entity @Table(name = "leaves") public class Leave { + //请假的编号 @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; //发出人 - @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) - private User userFrom; + @Column + private String userFrom; //审批人容器 @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) private Set userTo; @@ -28,7 +29,7 @@ public class Leave { private String type; //批准状态 @Column(nullable = false) - private String authentication; + private String authentication="Pending"; //审核备注 @Column diff --git a/src/main/java/com/codesdream/ase/service/BaseInformationService.java b/src/main/java/com/codesdream/ase/service/BaseInformationService.java index ec287a5..b659029 100644 --- a/src/main/java/com/codesdream/ase/service/BaseInformationService.java +++ b/src/main/java/com/codesdream/ase/service/BaseInformationService.java @@ -2,7 +2,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.datamanager.DataTable; import com.codesdream.ase.exception.badrequest.BaseInformationAlreadyExistException; -import com.codesdream.ase.exception.BaseInformationIllegalException; +import com.codesdream.ase.exception.badrequest.BaseInformationIllegalException; import com.codesdream.ase.exception.notfound.BaseInformationNotFoundException; import com.codesdream.ase.model.information.*; import com.codesdream.ase.repository.information.*; diff --git a/src/main/java/com/codesdream/ase/service/ILeavesService.java b/src/main/java/com/codesdream/ase/service/ILeavesService.java index 0d7b994..4f64f43 100644 --- a/src/main/java/com/codesdream/ase/service/ILeavesService.java +++ b/src/main/java/com/codesdream/ase/service/ILeavesService.java @@ -4,6 +4,7 @@ import com.codesdream.ase.model.leaves.Leave; import java.util.Optional; +import java.util.OptionalInt; public interface ILeavesService { //通过标题查找活动 @@ -12,6 +13,8 @@ public interface ILeavesService { //通过创建人姓名查找活动 Optional findLeaveByCreator(String creatorName); + OptionalfindLeaveById(int id); + //活动 Leave save(Leave leave); @@ -21,7 +24,6 @@ public interface ILeavesService { //请假信息更新 Leave update(Leave Leave); - //创建请假条目 Leave createLeave(Leave Leave); diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index ca8ec6e..fb875ab 100644 --- a/src/main/java/com/codesdream/ase/service/IPermissionService.java +++ b/src/main/java/com/codesdream/ase/service/IPermissionService.java @@ -44,6 +44,10 @@ public interface IPermissionService { // 标签下所有的获得权限容器集合列表 Collection getPCCs(Tag tag); + Set findPCCs(Set pccs); + + Optional findPCC(Integer id); + // 获得范围性权限容器下的所有标签列表 Collection getTagsFromSPC( ScopePermissionContainer spc); diff --git a/src/main/java/com/codesdream/ase/service/LeavesService.java b/src/main/java/com/codesdream/ase/service/LeavesService.java index a9c475d..0e58d35 100644 --- a/src/main/java/com/codesdream/ase/service/LeavesService.java +++ b/src/main/java/com/codesdream/ase/service/LeavesService.java @@ -8,7 +8,7 @@ import javax.annotation.Resource; import java.util.Optional; @Service -public class LeavesService implements ILeavesService { +public class LeavesService implements ILeavesService { @Resource private LeaveRepository leaveRepository; @@ -25,10 +25,16 @@ public class LeavesService implements ILeavesService { } @Override - public Leave save(Leave leave) { + public Leave save( Leave leave) { return leaveRepository.save(leave); } + @Override + public Optional findLeaveById(int id) { + return leaveRepository.findById(id); + } + + @Override public void delete(Leave leave) { @@ -45,7 +51,8 @@ public class LeavesService implements ILeavesService { return leaveRepository.save(leave); } - /*@Override + +/*@Override public Leave findActivitiesInTheCharge(User user) { }*/ diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 918c7f2..6ddea4f 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -110,6 +110,22 @@ public class PermissionService implements IPermissionService { return new ArrayList<>(tag.getPermissionContainersCollections()); } + @Override + public Set findPCCs(Set pccs) { + Set set = new HashSet<>(); + for(Integer id : pccs){ + Optional pcc = findPCC(id); + if(!pcc.isPresent()) throw new NotFoundException(String.format("PCCId: %d",id)); + set.add(pcc.get()); + } + return set; + } + + @Override + public Optional findPCC(Integer id) { + return pccRepository.findById(id); + } + @Override public Collection getTagsFromSPC(ScopePermissionContainer spc) { return new ArrayList<>(spc.getTags()); diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index f4710e4..da9333b 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -3,7 +3,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.auth.ASEPasswordEncoder; import com.codesdream.ase.component.auth.ASEUsernameEncoder; import com.codesdream.ase.component.permission.UserRolesListGenerator; -import com.codesdream.ase.exception.UserInformationIllegalException; +import com.codesdream.ase.exception.badrequest.UserInformationIllegalException; import com.codesdream.ase.exception.notfound.UserNotFoundException; import com.codesdream.ase.exception.badrequest.UsernameAlreadyExistException; import com.codesdream.ase.model.information.BaseStudentInfo; diff --git a/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java b/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java index 79a3c83..a54272c 100644 --- a/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java +++ b/src/main/java/com/codesdream/ase/validator/JSONFormValidator.java @@ -1,8 +1,6 @@ package com.codesdream.ase.validator; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.codesdream.ase.exception.DataIllegalTableFormatException; import org.springframework.stereotype.Component; import java.util.*; diff --git a/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java b/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java index 11ef842..779f270 100644 --- a/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java +++ b/src/test/java/com/codesdream/ase/test/JSONFormValidatorTest.java @@ -2,13 +2,10 @@ package com.codesdream.ase.test; import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.component.ASESpringUtil; -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.innerservererror.InvalidFormFormatException; import com.codesdream.ase.validator.JSONFormValidator; -import com.fasterxml.jackson.databind.util.JSONPObject; import lombok.extern.slf4j.Slf4j; -import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest;