From c580dae1767f8ff3d67b724d9d23966064d52daa Mon Sep 17 00:00:00 2001 From: Saturneric Date: Thu, 2 Apr 2020 00:42:16 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codesdream/ase/component/json/JSONBaseObject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java b/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java index 86504b4..a3030e1 100644 --- a/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java +++ b/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java @@ -8,5 +8,5 @@ import java.util.Date; @Slf4j public class JSONBaseObject { Date time = new Date(); - + } From 5168d6e2d98c7d9ae733a449747a4817f1fe6ee4 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Thu, 2 Apr 2020 14:51:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E7=9A=84=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/codesdream/ase/component/api/QuickJSONRespond.java | 2 -- .../java/com/codesdream/ase/component/json/JSONBaseObject.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java b/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java index be125bf..69d2db0 100644 --- a/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java +++ b/src/main/java/com/codesdream/ase/component/api/QuickJSONRespond.java @@ -1,9 +1,7 @@ package com.codesdream.ase.component.api; import com.codesdream.ase.component.datamanager.JSONParameter; -import com.codesdream.ase.component.json.respond.EmptyDataObjectRespond; import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; -import com.sun.deploy.net.HttpResponse; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java b/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java index a3030e1..86504b4 100644 --- a/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java +++ b/src/main/java/com/codesdream/ase/component/json/JSONBaseObject.java @@ -8,5 +8,5 @@ import java.util.Date; @Slf4j public class JSONBaseObject { Date time = new Date(); - + } From 217c20ea3bfbed3c014978594c3ab0038d6ab166 Mon Sep 17 00:00:00 2001 From: MusingZone Date: Sat, 4 Apr 2020 15:12:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=AD=90=E7=B3=BB=E7=BB=9F=E7=9A=84=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E7=89=88=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/model/achievement/ExamResult.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/codesdream/ase/model/achievement/ExamResult.java diff --git a/src/main/java/com/codesdream/ase/model/achievement/ExamResult.java b/src/main/java/com/codesdream/ase/model/achievement/ExamResult.java new file mode 100644 index 0000000..2543fca --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/achievement/ExamResult.java @@ -0,0 +1,43 @@ +package com.codesdream.ase.model.achievement; + +import com.codesdream.ase.model.activity.Period; +import lombok.Data; + +import javax.persistence.*; + +@Data +@Entity +@Table(name = "exam_result") + +public class ExamResult { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 课程名称 + @Column(name = "subject", nullable = false) + private String subject = ""; + + // 课程学分 + @Column(name = "credit", nullable = false) + private float credit; + + // 课程成绩 + @Column(name = "score", nullable = true) + private int score; + + // 课程绩点 + @Column(name = "grade_point", nullable = true) + private float gradePoint; + + + public float getCredit() { + return credit; + } + + public int getScore() { + return score; + } + +} From 418017a844c141c20390dda35339804800e05dae Mon Sep 17 00:00:00 2001 From: MusingZone Date: Sat, 4 Apr 2020 15:19:55 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=8F=88=E4=B8=80=E6=AC=A1=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=88=90=E7=BB=A9=E7=AE=A1=E7=90=86=E5=AD=90=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=9A=84=E7=AC=AC=E4=B8=80=E7=89=88=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/model/achievement/AccumulatedGPA.java | 42 ++++++++++++++++++ .../ase/model/achievement/Award.java | 34 ++++++++++++++ .../achievement/ComprehensiveEvaluation.java | 44 +++++++++++++++++++ .../model/achievement/StudentScoreReport.java | 33 ++++++++++++++ .../ase/service/AchievementService.java | 23 ++++++++++ .../ase/test/AchievementServiceTest.java | 31 +++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 src/main/java/com/codesdream/ase/model/achievement/AccumulatedGPA.java create mode 100644 src/main/java/com/codesdream/ase/model/achievement/Award.java create mode 100644 src/main/java/com/codesdream/ase/model/achievement/ComprehensiveEvaluation.java create mode 100644 src/main/java/com/codesdream/ase/model/achievement/StudentScoreReport.java create mode 100644 src/main/java/com/codesdream/ase/service/AchievementService.java create mode 100644 src/test/java/com/codesdream/ase/test/AchievementServiceTest.java diff --git a/src/main/java/com/codesdream/ase/model/achievement/AccumulatedGPA.java b/src/main/java/com/codesdream/ase/model/achievement/AccumulatedGPA.java new file mode 100644 index 0000000..aa89fcf --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/achievement/AccumulatedGPA.java @@ -0,0 +1,42 @@ +package com.codesdream.ase.model.achievement; + +import com.codesdream.ase.model.activity.Period; +import lombok.Data; + +import javax.persistence.*; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +@Data +@Entity +@Table(name = "accumulated_gpa") + +public class AccumulatedGPA { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 课程-得分集合 + @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY) + private Set examResults = new HashSet<>(); + + // 个人学分积 + @JoinColumn(nullable = true) + private float accumulatedGPA; + + + //除数为零exception待加 + public AccumulatedGPA(Set initExamResults) { + int totalProduct = 0, totalCredit = 0; + for(ExamResult er : initExamResults){ + totalProduct += er.getCredit() * er.getScore(); + totalCredit += er.getCredit(); + } + this.accumulatedGPA = totalProduct / totalCredit; + } + + +} diff --git a/src/main/java/com/codesdream/ase/model/achievement/Award.java b/src/main/java/com/codesdream/ase/model/achievement/Award.java new file mode 100644 index 0000000..8a6026c --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/achievement/Award.java @@ -0,0 +1,34 @@ +package com.codesdream.ase.model.achievement; + +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.model.permission.UserDetail; +import lombok.Data; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@Data +@Entity +@Table(name = "award") + +public class Award { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 标题 + private String title = ""; + + // 描述 + private String description = ""; + + // 分类 + private String type = ""; + + // 加分 + private int bonus; + + +} diff --git a/src/main/java/com/codesdream/ase/model/achievement/ComprehensiveEvaluation.java b/src/main/java/com/codesdream/ase/model/achievement/ComprehensiveEvaluation.java new file mode 100644 index 0000000..0393edd --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/achievement/ComprehensiveEvaluation.java @@ -0,0 +1,44 @@ +package com.codesdream.ase.model.achievement; + +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.model.permission.UserDetail; +import lombok.Data; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.Set; + +@Data +@Entity +@Table(name = "comprehensive_evaluation") + +public class ComprehensiveEvaluation { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 学分积 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private AccumulatedGPA accumulatedGPA; + + // G2项得分 + private int g2; + + // G3项得分 + private int g3; + + // G4项得分 + private int g4; + + // G5项得分 + private int g5; + + // G6项得分 + private int g6; + + // 获奖 + @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY) + private Set awards = new HashSet<>(); + +} diff --git a/src/main/java/com/codesdream/ase/model/achievement/StudentScoreReport.java b/src/main/java/com/codesdream/ase/model/achievement/StudentScoreReport.java new file mode 100644 index 0000000..32550ba --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/achievement/StudentScoreReport.java @@ -0,0 +1,33 @@ +package com.codesdream.ase.model.achievement; + +import com.codesdream.ase.model.activity.Period; +import com.codesdream.ase.model.permission.Tag; +import com.codesdream.ase.model.permission.User; +import lombok.Data; + +import javax.persistence.*; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +@Data +@Entity +@Table(name = "student_score_report") + +public class StudentScoreReport { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + // 课程-得分集合 + @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH}, fetch = FetchType.LAZY) + private Set examResults = new HashSet<>(); + + // 个人学分积 + @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) + @JoinColumn(nullable = true) + private AccumulatedGPA accumulatedGPA; + +} diff --git a/src/main/java/com/codesdream/ase/service/AchievementService.java b/src/main/java/com/codesdream/ase/service/AchievementService.java new file mode 100644 index 0000000..e768cb8 --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/AchievementService.java @@ -0,0 +1,23 @@ +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.badrequest.UserInformationIllegalException; +import com.codesdream.ase.exception.notfound.UserNotFoundException; +import com.codesdream.ase.exception.badrequest.UsernameAlreadyExistException; +import com.codesdream.ase.model.information.BaseStudentInfo; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.repository.permission.UserRepository; +import javafx.util.Pair; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Service +public class AchievementService { + +} diff --git a/src/test/java/com/codesdream/ase/test/AchievementServiceTest.java b/src/test/java/com/codesdream/ase/test/AchievementServiceTest.java new file mode 100644 index 0000000..381f586 --- /dev/null +++ b/src/test/java/com/codesdream/ase/test/AchievementServiceTest.java @@ -0,0 +1,31 @@ +package com.codesdream.ase.test; + +import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.model.activity.Report; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.service.AchievementService; +import com.codesdream.ase.service.ActivityService; +import com.codesdream.ase.service.UserService; +import javafx.util.Pair; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * 成绩管理子系统单元测试 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles("test") + +public class AchievementServiceTest { + + @Resource + private AchievementService achievementService; + + +} From b2903bb1300f11f7e897a9588de8eaa678a8ea25 Mon Sep 17 00:00:00 2001 From: Saturneric Date: Sat, 4 Apr 2020 18:50:53 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3;=E6=B7=BB=E5=8A=A0FPC=E4=B8=8ESPC=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3;=E5=AE=8C=E5=96=84=E6=9D=83=E9=99=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=AD=90=E7=B3=BB=E7=BB=9F=E6=9C=8D=E5=8A=A1=E5=B1=82?= =?UTF-8?q?;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ase/component/json/model/JsonableFPC.java | 30 +++++ .../json/model/JsonableRoleList.java | 24 ++++ .../ase/component/json/model/JsonableSPC.java | 30 +++++ .../controller/permission/FPCController.java | 77 +++++++++++++ .../controller/permission/SPCController.java | 79 +++++++++++++ .../TagController.java} | 105 ++++++++++-------- .../ase/service/IPermissionService.java | 11 +- .../ase/service/PermissionService.java | 18 ++- 8 files changed, 317 insertions(+), 57 deletions(-) create mode 100644 src/main/java/com/codesdream/ase/component/json/model/JsonableFPC.java create mode 100644 src/main/java/com/codesdream/ase/component/json/model/JsonableRoleList.java create mode 100644 src/main/java/com/codesdream/ase/component/json/model/JsonableSPC.java create mode 100644 src/main/java/com/codesdream/ase/controller/permission/FPCController.java create mode 100644 src/main/java/com/codesdream/ase/controller/permission/SPCController.java rename src/main/java/com/codesdream/ase/controller/{PermissionController.java => permission/TagController.java} (66%) diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableFPC.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableFPC.java new file mode 100644 index 0000000..cd32c79 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableFPC.java @@ -0,0 +1,30 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; +import springfox.documentation.spring.web.json.Json; + +@Data +@NoArgsConstructor +@ApiModel("功能性权限容器") +public class JsonableFPC { + private Integer id; + + private String name; + + private String description; + + private boolean enabled; + + private boolean deleted; + + public JsonableFPC(FunctionalPermissionContainer fpc){ + this.id = fpc.getId(); + this.name = fpc.getName(); + this.description = fpc.getDescription(); + this.enabled = fpc.isEnabled(); + this.deleted = fpc.isDeleted(); + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableRoleList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableRoleList.java new file mode 100644 index 0000000..8046070 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableRoleList.java @@ -0,0 +1,24 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.HashSet; +import java.util.Set; + +@Data +@NoArgsConstructor +@ApiModel("功能性权限容器所属角色集合") +public class JsonableRoleList { + private Integer id; + private Set roles = new HashSet<>(); + + public JsonableRoleList(FunctionalPermissionContainer fpc){ + this.id = fpc.getId(); + if(fpc.getRoles() != null) { + this.roles.addAll(fpc.getRoles()); + } + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableSPC.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableSPC.java new file mode 100644 index 0000000..124f9ae --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableSPC.java @@ -0,0 +1,30 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.ScopePermissionContainer; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@ApiModel("范围性权限容器") +public class JsonableSPC { + private Integer id; + + private String name; + + private String description; + + private boolean enabled; + + private boolean deleted; + + public JsonableSPC(ScopePermissionContainer spc){ + this.id = spc.getId(); + this.name = spc.getName(); + this.description = spc.getDescription(); + this.enabled = spc.isEnabled(); + this.deleted = spc.isDeleted(); + } + +} diff --git a/src/main/java/com/codesdream/ase/controller/permission/FPCController.java b/src/main/java/com/codesdream/ase/controller/permission/FPCController.java new file mode 100644 index 0000000..c4cfc71 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/FPCController.java @@ -0,0 +1,77 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.json.model.JsonableFPC; +import com.codesdream.ase.component.json.model.JsonableRoleList; +import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import com.codesdream.ase.service.PermissionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +@RestController +@RequestMapping(value = "pmt") +@Api(tags = "功能性权限容器接口") +public class FPCController { + + @Resource + private PermissionService permissionService; + + @GetMapping("fpc") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "查找功能性权限容器") + public JsonableFPC getFPC(@RequestParam(value = "id") Integer id){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + return new JsonableFPC(fpc.get()); + } + + @PostMapping("fpc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "创建新的功能性权限容器") + public JsonableFPC createFPC(@RequestBody JsonableFPC fpc){ + if(permissionService.findFPC(fpc.getName()).isPresent()) throw new AlreadyExistException(fpc.getName()); + FunctionalPermissionContainer functionalPermissionContainer = new FunctionalPermissionContainer(); + + functionalPermissionContainer.setName(fpc.getName()); + functionalPermissionContainer.setDescription(fpc.getDescription()); + functionalPermissionContainer.setEnabled(fpc.isEnabled()); + functionalPermissionContainer.setDeleted(fpc.isDeleted()); + + return new JsonableFPC(permissionService.save(functionalPermissionContainer)); + } + + @GetMapping("fpcs") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得所有功能性权限容器的信息") + public Set listFPC(){ + Iterable fpcs = permissionService.findAllFPC(); + Set jsonableFPCS = new HashSet<>(); + for(FunctionalPermissionContainer fpc : fpcs){ + jsonableFPCS.add(new JsonableFPC(fpc)); + } + return jsonableFPCS; + } + + @GetMapping("fpc/role") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得功能性权限容器所属角色") + public JsonableRoleList getFPCRoleList(@RequestParam(value = "id") Integer id){ + Optional functionalPermissionContainer = + permissionService.findFPC(id); + if(!functionalPermissionContainer.isPresent()) throw new NotFoundException(id.toString()); + + return new JsonableRoleList(functionalPermissionContainer.get()); + } + + + + +} diff --git a/src/main/java/com/codesdream/ase/controller/permission/SPCController.java b/src/main/java/com/codesdream/ase/controller/permission/SPCController.java new file mode 100644 index 0000000..1a4f8f6 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/SPCController.java @@ -0,0 +1,79 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.json.model.JsonableSPC; +import com.codesdream.ase.component.json.model.JsonableTag; +import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.ScopePermissionContainer; +import com.codesdream.ase.model.permission.Tag; +import com.codesdream.ase.service.PermissionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +@RestController +@RequestMapping(value = "pmt") +@Api(tags = "范围性权限容器接口") +public class SPCController { + + @Resource + private PermissionService permissionService; + + @GetMapping(value = "spc") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得范围性权限容器信息") + public JsonableSPC getSPC(@RequestParam(value = "id") Integer id){ + Optional spc = permissionService.findSPC(id); + if(!spc.isPresent()) throw new NotFoundException(id.toString()); + + return new JsonableSPC(spc.get()); + + } + + @GetMapping(value = "spcs") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得所有的范围性权限容器信息") + public Set listSPC(){ + Iterable spcs = permissionService.findALLSPC(); + Set jsonableSPCS = new HashSet<>(); + for(ScopePermissionContainer spc : spcs){ + jsonableSPCS.add(new JsonableSPC(spc)); + } + return jsonableSPCS; + } + + @GetMapping(value = "spc/tag") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "查询范围性权限容器下的所有标签集合") + public Set listSPCTag(@RequestParam(value = "id") Integer id){ + Optional spc = permissionService.findSPC(id); + if(!spc.isPresent()) throw new NotFoundException(id.toString()); + + Set tags = new HashSet<>(); + for(Tag tag : spc.get().getTags()){ + tags.add(new JsonableTag(tag)); + } + return tags; + } + + @PostMapping(value = "spc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "创建范围性权限容器") + public JsonableSPC createSPC(@RequestBody JsonableSPC spc) { + if(permissionService.findSPC(spc.getName()).isPresent()) throw new AlreadyExistException(spc.getName()); + + ScopePermissionContainer defaultSPC = permissionService.getDefaultSPC(spc.getName()); + defaultSPC.setDeleted(spc.isDeleted()); + defaultSPC.setEnabled(spc.isEnabled()); + defaultSPC.setDescription(spc.getDescription()); + + return new JsonableSPC(permissionService.save(defaultSPC)); + } + +} diff --git a/src/main/java/com/codesdream/ase/controller/PermissionController.java b/src/main/java/com/codesdream/ase/controller/permission/TagController.java similarity index 66% rename from src/main/java/com/codesdream/ase/controller/PermissionController.java rename to src/main/java/com/codesdream/ase/controller/permission/TagController.java index 400bbfa..b45a258 100644 --- a/src/main/java/com/codesdream/ase/controller/PermissionController.java +++ b/src/main/java/com/codesdream/ase/controller/permission/TagController.java @@ -1,4 +1,4 @@ -package com.codesdream.ase.controller; +package com.codesdream.ase.controller.permission; import com.codesdream.ase.component.datamanager.JsonPathParameter; import com.codesdream.ase.component.json.model.JsonablePCCList; @@ -14,18 +14,17 @@ 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 io.swagger.models.auth.In; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import springfox.documentation.spring.web.json.Json; import javax.annotation.Resource; +import javax.jws.soap.SOAPBinding; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -33,8 +32,8 @@ import java.util.Set; @RestController @RequestMapping("pmt") -@Api(tags = "权限管理接口") -public class PermissionController { +@Api(tags = "标签管理接口") +public class TagController { @Resource private PermissionService permissionService; @@ -64,20 +63,18 @@ public class PermissionController { @GetMapping("tag") @ResponseStatus(HttpStatus.OK) @ApiOperation("搜索标签信息") - @ApiImplicitParam(name = "name", value = "标签名") - public JsonableTag checkTag(@RequestParam(value = "name") String name){ - Optional tagOptional = permissionService.findTag(name); + public JsonableTag checkTag(@RequestParam(value = "id") Integer id){ + Optional tagOptional = permissionService.findTag(id); if(tagOptional.isPresent()){ return new JsonableTag(tagOptional.get()); } - else throw new NotFoundException(name); + else throw new NotFoundException(id.toString()); } // 根据名字搜索标签的简要信息 @GetMapping("tags") @ResponseStatus(HttpStatus.OK) @ApiOperation("列出所有的标签信息") - @ApiImplicitParam(name = "name", value = "标签名") public Set listTag(){ Iterable tagIterable = permissionService.findAllTag(); Set jsonableTagSet = new HashSet<>(); @@ -91,10 +88,9 @@ public class PermissionController { @DeleteMapping("tag") @ResponseStatus(HttpStatus.NO_CONTENT) @ApiOperation("删除标签") - @ApiImplicitParam(name = "name", value = "标签名") - public void deleteTag(@RequestParam(value = "name") String name){ - Optional tag = permissionService.findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); + public void deleteTag(@RequestParam(value = "id") Integer id){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); // 检查外键关联 if(tag.get().getUsers().size() > 0) throw new RelatedObjectsExistException(); @@ -104,13 +100,12 @@ public class PermissionController { } // 根据名字搜索标签的简要信息 - @PatchMapping(path = "tag", consumes = "application/json-patch+json") + @PatchMapping(path = "tag") @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); + public JsonableTag updateTag(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); JsonableTag jsonableTag = new JsonableTag(tag.get()); jsonableTag = pathParameter.parsePathToObject(patch, jsonableTag); @@ -122,34 +117,42 @@ public class PermissionController { } - - @GetMapping("tag/users") @ResponseStatus(HttpStatus.OK) @ApiOperation("搜索单个标签所属用户集合信息") - public JsonableUserList getUserTag(@RequestParam(value = "name") String name){ - Optional tag = permissionService.findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); - return new JsonableUserList(tag.get()); + public Set getUserTag(@RequestParam(value = "id") Integer id){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); + Set jsonableUsers = new HashSet<>(); + for(User user : tag.get().getUsers()){ + jsonableUsers.add(new JsonableUser(user)); + } + return jsonableUsers; } @PutMapping("tag/users") @ApiOperation("更新索单个标签所属用户集合信息") - public JsonableUserList setUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ - Optional tag = permissionService.findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); + public Set setUserTag(@RequestParam(value = "id") Integer id, + @RequestBody JsonableUserList userList){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); Set userSet = new HashSet<>(userList.getUsers()); tag.get().setUsers(userService.findUsersById(userSet)); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : tag.get().getUsers()){ + jsonableUsers.add(new JsonableUser(user)); + } + return jsonableUsers; } @PostMapping("tag/users") @ApiOperation("更新单个标签所属用户集合中添加一个或多个用户") - public JsonableUserList addUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ - Optional tag = permissionService.findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); + public Set addUserTag(@RequestParam(value = "id") Integer id, + @RequestBody JsonableUserList userList){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); Set newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers())); Set userSet = tag.get().getUsers(); @@ -157,30 +160,38 @@ public class PermissionController { userSet.addAll(newUserSet); tag.get().setUsers(userSet); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : tag.get().getUsers()){ + jsonableUsers.add(new JsonableUser(user)); + } + return jsonableUsers; } @DeleteMapping("tag/users") @ResponseStatus(HttpStatus.OK) @ApiOperation("从单个标签所属用户集合中删除一个或多个用户") - @ApiImplicitParam(name = "name", value = "标签名") - public JsonableUserList deleteUserTag(@RequestParam String name, @RequestBody JsonableUserList userList){ - Optional tag = permissionService.findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); + public Set deleteUserTag(@RequestParam Integer id, + @RequestBody JsonableUserList userList){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); Set userSet = tag.get().getUsers(); Set deleteUserSet = userService.findUsersById(new HashSet<>(userList.getUsers())); userSet.removeAll(deleteUserSet); tag.get().setUsers(userSet); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : tag.get().getUsers()){ + jsonableUsers.add(new JsonableUser(user)); + } + return jsonableUsers; } @GetMapping("tags/users") @ResponseStatus(HttpStatus.OK) @ApiOperation("搜索多个标签所属用户集合信息") - public Set getUserTags(@RequestParam(value = "name") List names){ - Set tagSet = permissionService.findTags(names); + public Set getUserTags(@RequestParam(value = "id") List ids){ + Set tagSet = permissionService.findTags(ids); Set userSet = new HashSet<>(); Set jsonableUsers = new HashSet<>(); for(Tag tag : tagSet){ @@ -195,9 +206,9 @@ public class PermissionController { @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); + public JsonablePCCList getPCCTag(@RequestParam(value = "id") Integer id){ + Optional tagOptional = permissionService.findTag(id); + if(!tagOptional.isPresent()) throw new NotFoundException(id.toString()); return new JsonablePCCList(tagOptional.get()); } @@ -205,9 +216,9 @@ public class PermissionController { @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); + public JsonablePCCList addPCCTag(@RequestParam(value = "id") Integer id, JsonablePCCList jsonablePCCList){ + Optional tagOptional = permissionService.findTag(id); + if(!tagOptional.isPresent()) throw new NotFoundException(id.toString()); Set pccs = tagOptional.get().getPermissionContainersCollections(); pccs.addAll(permissionService.findPCCs(new HashSet(jsonablePCCList.getPccIdList()))); diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index fb875ab..5c82bc8 100644 --- a/src/main/java/com/codesdream/ase/service/IPermissionService.java +++ b/src/main/java/com/codesdream/ase/service/IPermissionService.java @@ -3,10 +3,7 @@ package com.codesdream.ase.service; import com.codesdream.ase.model.permission.*; import javafx.util.Pair; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; public interface IPermissionService { @@ -27,17 +24,21 @@ public interface IPermissionService { // 列出所有的标签 Iterable findAllTag(); - Set findTags(List names); + Set findTags(List ids); // 查找功能性权限容器 Optional findFPC(String name); + Iterable findAllFPC(); + // 查找范围性权限容器 Optional findSPC(String name); // 根据id查找功能性权限容器 Optional findFPC(int id); + Iterable findALLSPC(); + // 根据id查找范围性权限容器 Optional findSPC(int id); diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 6ddea4f..9c4c520 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -9,7 +9,6 @@ import com.codesdream.ase.repository.permission.PermissionContainersCollectionRe import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository; import com.codesdream.ase.repository.permission.TagRepository; import javafx.util.Pair; -import org.apache.poi.ss.formula.functions.T; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -75,11 +74,11 @@ public class PermissionService implements IPermissionService { } @Override - public Set findTags(List names) { + public Set findTags(List ids) { Set tagSet = new HashSet<>(); - for(String name : names){ - Optional tag = findTag(name); - if(!tag.isPresent()) throw new NotFoundException(name); + for(Integer id : ids){ + Optional tag = findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); tagSet.add(tag.get()); } return tagSet; @@ -90,6 +89,10 @@ public class PermissionService implements IPermissionService { return fpcRepository.findByName(name); } + public Iterable findAllFPC() { + return fpcRepository.findAll(); + } + @Override public Optional findSPC(String name) { return spcRepository.findByName(name); @@ -100,6 +103,11 @@ public class PermissionService implements IPermissionService { return fpcRepository.findById(id); } + @Override + public Iterable findALLSPC() { + return spcRepository.findAll(); + } + @Override public Optional findSPC(int id) { return spcRepository.findById(id);