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 38b079a..5d2783f 100644 --- a/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java +++ b/src/main/java/com/codesdream/ase/component/activity/ActivityConverter.java @@ -17,7 +17,9 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; -//将合法的JSON对象转化为Activity对象 +/** + * JSONObject-Activity转化类 + */ @Component public class ActivityConverter { @@ -30,6 +32,10 @@ public class ActivityConverter { @Resource AttendanceService attendanceService; + /** + * @param json 一个Optional的json对象,用以转化为Activity对象,此过程中进行值的合法校验 + * @return 一个可以被直接存储在数据库中的合法的Activity对象 + */ public Activity convertToActivity(Optional json) { if (!json.isPresent()) { throw new NullPointerException(); @@ -37,10 +43,12 @@ public class ActivityConverter { Activity activity = new Activity(); JSONObject jsonObject = json.get(); + //设置活动创建人 int userId = (int) jsonObject.get("creator"); Optional creator = userService.findUserById(userId); activity.setCreator(creator.get()); + //设置参与人员 List participateGroupFromJson = (List) jsonObject.get("participate-group"); Set participateGroup = new HashSet<>(); for (int id : participateGroupFromJson) { @@ -49,13 +57,16 @@ public class ActivityConverter { } activity.setParticipateGroup(participateGroup); + //设置活动标题 String title = (String) jsonObject.get("title"); activity.setTitle(title); + //设置主要负责人 int chiefManagerId = (int) jsonObject.get("chief-manager"); Optional chiefManager = userService.findUserById(chiefManagerId); activity.setChiefManager(chiefManager.get()); + //设置次要负责人 List assistManagersFromJSON = (List) jsonObject.get("assist-managers"); Set assistManager = new HashSet<>(); for (int id : assistManagersFromJSON) { @@ -64,9 +75,11 @@ public class ActivityConverter { } activity.setAssistManagers(assistManager); + //设置活动类型 String type = (String) jsonObject.get("type"); activity.setType(type); + //设置 String startTimeFromJSON = (String) jsonObject.get("start-time"); String endTimeFromJSON = (String) jsonObject.get("end-time"); LocalDateTime startTime = LocalDateTime.parse(startTimeFromJSON, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); @@ -152,9 +165,7 @@ public class ActivityConverter { Attendance attendance = new Attendance(); attendance.setClockInPeriods(periods); attendance.setOnline(attendanceOnLine); - /** - * 二维码模块未完成 - */ + attendance = attendanceService.save(attendance); activity.setAttendance(attendance); diff --git a/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java b/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java index 4389f67..e18de65 100644 --- a/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java +++ b/src/main/java/com/codesdream/ase/component/activity/QrCodeUtils.java @@ -5,11 +5,9 @@ import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; -import jdk.internal.util.xml.impl.Input; import org.springframework.stereotype.Component; import javax.imageio.ImageIO; -import javax.imageio.stream.ImageOutputStream; import java.awt.*; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; 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/auth/ASEAccessDecisionManager.java b/src/main/java/com/codesdream/ase/component/auth/ASEAccessDecisionManager.java new file mode 100644 index 0000000..ae22d9e --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/auth/ASEAccessDecisionManager.java @@ -0,0 +1,42 @@ +package com.codesdream.ase.component.auth; + +import org.springframework.security.access.AccessDecisionManager; +import org.springframework.security.access.AccessDeniedException; +import org.springframework.security.access.ConfigAttribute; +import org.springframework.security.authentication.InsufficientAuthenticationException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.Iterator; + +@Component +public class ASEAccessDecisionManager implements AccessDecisionManager { + @Override + public void decide(Authentication authentication, Object object, Collection configAttributes) throws AccessDeniedException, InsufficientAuthenticationException { + if(null == configAttributes || configAttributes.size() <= 0) { + return; + } + + for (ConfigAttribute c : configAttributes) { + String needRole = c.getAttribute(); + for (GrantedAuthority ga : authentication.getAuthorities()) { + if (needRole.trim().equals(ga.getAuthority())) { + return; + } + } + } + throw new AccessDeniedException("Access Denied"); + } + + @Override + public boolean supports(ConfigAttribute attribute) { + return true; + } + + @Override + public boolean supports(Class clazz) { + return true; + } +} diff --git a/src/main/java/com/codesdream/ase/component/auth/ASEInvocationSecurityMetadataSource.java b/src/main/java/com/codesdream/ase/component/auth/ASEInvocationSecurityMetadataSource.java new file mode 100644 index 0000000..3c1f359 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/auth/ASEInvocationSecurityMetadataSource.java @@ -0,0 +1,65 @@ +package com.codesdream.ase.component.auth; + +import com.codesdream.ase.model.permission.Function; +import com.codesdream.ase.repository.permission.FunctionRepository; +import org.springframework.security.access.ConfigAttribute; +import org.springframework.security.access.SecurityConfig; +import org.springframework.security.web.FilterInvocation; +import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; + +@Component +public class ASEInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource { + + private HashMap> map = null; + + @Resource + private FunctionRepository functionRepository; + + private void loadFunctionDefine(){ + map = new HashMap<>(); + Iterable functions = functionRepository.findAll(); + for(Function function : functions) { + Collection array = new ArrayList<>(); + ConfigAttribute cfg = new SecurityConfig(function.getName()); + + array.add(cfg); + + map.put(function.getUrl(), array); + } + } + + @Override + public Collection getAttributes(Object object) throws IllegalArgumentException { + + if(map == null) loadFunctionDefine(); + + HttpServletRequest request = ((FilterInvocation) object).getHttpRequest(); + + for (String url : map.keySet()) { + AntPathRequestMatcher matcher = new AntPathRequestMatcher(url); + if (matcher.matches(request)) { + return map.get(url); + } + } + return null; + } + + @Override + public Collection getAllConfigAttributes() { + return null; + } + + @Override + public boolean supports(Class clazz) { + return true; + } +} diff --git a/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java index fe35cef..f7f54f2 100644 --- a/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java +++ b/src/main/java/com/codesdream/ase/component/auth/ASEJSONTokenAuthenticationFilter.java @@ -1,10 +1,5 @@ package com.codesdream.ase.component.auth; -import com.codesdream.ase.component.auth.AJAXRequestChecker; -import com.codesdream.ase.component.auth.JSONRandomCodeGenerator; -import com.codesdream.ase.component.auth.JSONSignedGenerator; -import com.codesdream.ase.component.auth.JSONTokenAuthenticationToken; -import com.codesdream.ase.component.datamanager.JSONParameter; import com.codesdream.ase.model.auth.JSONToken; import com.codesdream.ase.service.AuthService; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/codesdream/ase/component/auth/ASESecurityInterceptor.java b/src/main/java/com/codesdream/ase/component/auth/ASESecurityInterceptor.java new file mode 100644 index 0000000..f8ea470 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/auth/ASESecurityInterceptor.java @@ -0,0 +1,62 @@ +package com.codesdream.ase.component.auth; + +import javax.annotation.Resource; +import javax.servlet.*; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.SecurityMetadataSource; +import org.springframework.security.access.intercept.AbstractSecurityInterceptor; +import org.springframework.security.access.intercept.InterceptorStatusToken; +import org.springframework.security.web.FilterInvocation; +import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Component +public class ASESecurityInterceptor extends AbstractSecurityInterceptor implements Filter { + + @Resource + private FilterInvocationSecurityMetadataSource securityMetadataSource; + + @Resource + public void setASEAccessDecisionManager(ASEAccessDecisionManager accessDecisionManager) { + super.setAccessDecisionManager(accessDecisionManager); + } + + @Override + public Class getSecureObjectClass() { + return FilterInvocation.class; + } + + @Override + public SecurityMetadataSource obtainSecurityMetadataSource() { + return this.securityMetadataSource; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + FilterInvocation fi = new FilterInvocation(request, response, chain); + invoke(fi); + } + + public void invoke(FilterInvocation fi) throws IOException, ServletException { + InterceptorStatusToken token = super.beforeInvocation(fi); + try { + //执行下一个拦截器 + fi.getChain().doFilter(fi.getRequest(), fi.getResponse()); + } finally { + super.afterInvocation(token, null); + } + } + + @Override + public void destroy() { + + } +} diff --git a/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java b/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java index dbce1a6..c87dea7 100644 --- a/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java +++ b/src/main/java/com/codesdream/ase/component/datamanager/JSONParameter.java @@ -3,6 +3,12 @@ package com.codesdream.ase.component.datamanager; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.component.json.respond.JSONBaseRespondObject; +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.Component; import javax.servlet.http.HttpServletRequest; @@ -69,6 +75,15 @@ public class JSONParameter { return json.map(jsonObject -> getJavaObject(jsonObject, type)); } + 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/datamanager/JsonPathParameter.java b/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java deleted file mode 100644 index 64b719b..0000000 --- a/src/main/java/com/codesdream/ase/component/datamanager/JsonPathParameter.java +++ /dev/null @@ -1,23 +0,0 @@ -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/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(); - + } diff --git a/src/main/java/com/codesdream/ase/component/json/form/RegisterForm.java b/src/main/java/com/codesdream/ase/component/json/form/RegisterForm.java new file mode 100644 index 0000000..ccd73f0 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/form/RegisterForm.java @@ -0,0 +1,5 @@ +package com.codesdream.ase.component.json.form; + +public class RegisterForm { + +} 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..af57a91 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableFPC.java @@ -0,0 +1,38 @@ +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(); + } + + public FunctionalPermissionContainer parseObject(FunctionalPermissionContainer fpc){ + fpc.setName(this.name); + fpc.setDescription(this.description); + fpc.setEnabled(this.enabled); + fpc.setDeleted(this.deleted); + return fpc; + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableFSR.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableFSR.java new file mode 100644 index 0000000..c72f333 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableFSR.java @@ -0,0 +1,62 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import com.codesdream.ase.model.permission.FunctionalScopeRelation; +import com.codesdream.ase.model.permission.ScopePermissionContainer; +import com.codesdream.ase.service.IPermissionService; +import com.codesdream.ase.service.PermissionService; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.annotation.Resource; +import java.util.Optional; + +@Data +@NoArgsConstructor +@ApiModel("单项权力") +public class JsonableFSR { + private Integer id; + + private String name; + + private String description; + + private Integer fpcId; + + private Integer spcId; + + @Resource + @ApiModelProperty(hidden = true) + private IPermissionService permissionService; + + public JsonableFSR(FunctionalScopeRelation fsr){ + this.id = fsr.getId(); + this.name = fsr.getName(); + this.description = fsr.getDescription(); + this.fpcId = fsr.getFunctionalPermissionContainer().getId(); + this.spcId = fsr.getScopePermissionContainer().getId(); + } + + public FunctionalScopeRelation parseObject(FunctionalScopeRelation fsr){ + fsr.setName(this.name); + fsr.setDescription(this.description); + if(this.fpcId != null){ + Optional fpc = permissionService.findFPC(this.fpcId); + if(!fpc.isPresent()) throw new NotFoundException(this.fpcId.toString()); + fsr.setFunctionalPermissionContainer(fpc.get()); + } + + if(this.spcId != null){ + Optional spc = permissionService.findSPC(this.spcId); + if(!spc.isPresent()) throw new NotFoundException(this.spcId.toString()); + fsr.setScopePermissionContainer(spc.get()); + } + + return fsr; + + } +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableFunction.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableFunction.java new file mode 100644 index 0000000..afdd13b --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableFunction.java @@ -0,0 +1,60 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.Function; +import com.codesdream.ase.service.IPermissionService; +import com.codesdream.ase.service.PermissionService; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; +import io.swagger.models.auth.In; +import lombok.Data; +import lombok.NoArgsConstructor; +import springfox.documentation.annotations.ApiIgnore; + +import javax.annotation.Resource; +import java.util.Optional; + +@Data +@NoArgsConstructor +@ApiModel("功能") +public class JsonableFunction { + + private Integer id; + + private String name; + + private String description; + + private Integer fatherId; + + private String url; + + @Resource + @ApiModelProperty(hidden = true) + private IPermissionService permissionService; + + public JsonableFunction(Function function){ + this.id = function.getId(); + this.name = function.getName(); + this.description = function.getDescription(); + if(function.getFather() != null) { + this.fatherId = function.getFather().getId(); + } + else this.fatherId = null; + this.url = function.getUrl(); + } + + public Function parseObject(Function function){ + function.setName(this.name); + function.setDescription(this.description); + if(this.fatherId != null) { + Optional fatherFunction = permissionService.findFunction(this.fatherId); + if (!fatherFunction.isPresent()) throw new NotFoundException(fatherId.toString()); + function.setFather(fatherFunction.get()); + } + function.setUrl(this.url); + + return function; + } +} 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..efacf0f --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableRoleList.java @@ -0,0 +1,26 @@ +package com.codesdream.ase.component.json.model; + +import com.codesdream.ase.model.permission.Function; +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 functions = new HashSet<>(); + + public JsonableRoleList(FunctionalPermissionContainer fpc){ + this.id = fpc.getId(); + if(fpc.getFunctions() != null) { + for(Function function : fpc.getFunctions()) + this.functions.add(function.getId()); + } + } +} 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..14fffd1 --- /dev/null +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableSPC.java @@ -0,0 +1,39 @@ +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(); + } + + public ScopePermissionContainer parseObject(ScopePermissionContainer spc){ + spc.setName(this.name); + spc.setDescription(this.description); + spc.setEnabled(this.enabled); + spc.setDeleted(this.deleted); + + return spc; + } + +} diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java index 8db125b..8b518ec 100644 --- a/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableTag.java @@ -24,11 +24,25 @@ public class JsonableTag { @ApiModelProperty(value = "标签说明", example = "该系统的管理员") private String description; + private boolean enabled; + + private boolean deleted; + public JsonableTag(Tag tag){ this.id = tag.getId(); this.name = tag.getName(); this.description = tag.getDescription(); + this.enabled = tag.isEnabled(); + this.deleted = tag.isDeleted(); + } + + public Tag parseObject(Tag tag){ + tag.setName(this.name); + tag.setDescription(this.description); + tag.setDeleted(this.deleted); + tag.setEnabled(this.enabled); + return tag; } } diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java index 74f6467..ad72dec 100644 --- a/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java +++ b/src/main/java/com/codesdream/ase/component/json/model/JsonableUser.java @@ -1,6 +1,8 @@ package com.codesdream.ase.component.json.model; import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.model.permission.UserAuth; +import com.codesdream.ase.model.permission.UserDetail; import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,9 +13,21 @@ import lombok.NoArgsConstructor; public class JsonableUser { private Integer id; private String username; + private boolean enabled; + private boolean deleted; + public JsonableUser(User user){ this.id = user.getId(); this.username = user.getUsername(); + + this.enabled = user.isEnabled(); + this.deleted= user.isDeleted(); + } + + public User parseObject(User user){ + user.setEnabled(this.enabled); + user.setDeleted(this.deleted); + return user; } } diff --git a/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java b/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java deleted file mode 100644 index e91c3cb..0000000 --- a/src/main/java/com/codesdream/ase/component/json/model/JsonableUserList.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.codesdream.ase.component.json.model; - -import com.codesdream.ase.model.permission.Tag; -import com.codesdream.ase.model.permission.User; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -@Data -@NoArgsConstructor -@ApiModel("标签所属用户集合") -public class JsonableUserList { - - @ApiModelProperty(name = "用户列表") - private List users; - - - public JsonableUserList(Tag tag){ - for(User user : tag.getUsers()){ - users.add(user.getId()); - } - } -} diff --git a/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java index 3963c38..ded5ff7 100644 --- a/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java +++ b/src/main/java/com/codesdream/ase/component/permission/UserAuthoritiesGenerator.java @@ -10,10 +10,10 @@ import java.util.Collection; @Component public class UserAuthoritiesGenerator { @Resource - UserRolesListGenerator userRolesListGenerator; + UserFunctionsListGenerator userFunctionsListGenerator; public Collection grantedAuthorities(User user){ - return userRolesListGenerator.generateRoles(user); + return userFunctionsListGenerator.generateRoles(user); } } diff --git a/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java b/src/main/java/com/codesdream/ase/component/permission/UserFunctionsListGenerator.java similarity index 83% rename from src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java rename to src/main/java/com/codesdream/ase/component/permission/UserFunctionsListGenerator.java index 9b861c3..337ddad 100644 --- a/src/main/java/com/codesdream/ase/component/permission/UserRolesListGenerator.java +++ b/src/main/java/com/codesdream/ase/component/permission/UserFunctionsListGenerator.java @@ -1,5 +1,6 @@ package com.codesdream.ase.component.permission; +import com.codesdream.ase.model.permission.Function; import com.codesdream.ase.model.permission.FunctionalPermissionContainer; import com.codesdream.ase.model.permission.User; import org.springframework.security.core.GrantedAuthority; @@ -14,7 +15,7 @@ import java.util.Collection; * 生成用户访问权限角色列表 */ @Component -public class UserRolesListGenerator { +public class UserFunctionsListGenerator { @Resource private UserFPCListGenerator fpcListGenerator; @@ -22,8 +23,8 @@ public class UserRolesListGenerator { Collection fpcs){ Collection authorities = new ArrayList<>(); for(FunctionalPermissionContainer fpc :fpcs){ - for(String role :fpc.getRoles()){ - authorities.add(new SimpleGrantedAuthority(role)); + for(Function function :fpc.getFunctions()){ + authorities.add(new SimpleGrantedAuthority(function.getName())); } } return authorities; diff --git a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java index b2d3413..0e3d814 100644 --- a/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java +++ b/src/main/java/com/codesdream/ase/configure/CustomWebSecurityConfig.java @@ -12,6 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.session.SessionRegistry; import org.springframework.security.core.session.SessionRegistryImpl; +import org.springframework.security.web.access.intercept.FilterSecurityInterceptor; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; import org.springframework.security.web.authentication.session.ConcurrentSessionControlAuthenticationStrategy; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; @@ -48,6 +49,9 @@ public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter { @Resource ASEAccessDeniedHandler accessDeniedHandler; + @Resource + ASESecurityInterceptor securityInterceptor; + @Override protected void configure(HttpSecurity http) throws Exception { @@ -64,7 +68,8 @@ public class CustomWebSecurityConfig extends WebSecurityConfigurerAdapter { // 替换掉原有的UsernamePasswordAuthenticationFilter http.addFilterAt(aseUsernamePasswordAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) - .addFilterBefore(asejsonTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); + .addFilterBefore(asejsonTokenAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class) + .addFilterAt(securityInterceptor, FilterSecurityInterceptor.class); http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS); diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java index 29d8d83..568e2cb 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityAttendanceController.java @@ -2,10 +2,15 @@ package com.codesdream.ase.controller.activity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; @Controller +@RequestMapping("/act") public class ActivityAttendanceController { + private final String url = "/forget"; + + } diff --git a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java index 35b4743..a1ea1e2 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityCreatorController.java @@ -22,6 +22,7 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; @@ -31,6 +32,7 @@ import java.util.List; import java.util.Optional; @Controller +@RequestMapping("/forget/act") public class ActivityCreatorController { @Resource @@ -66,41 +68,40 @@ public class ActivityCreatorController { @Resource ActivityConverter activityConverter; - private final String url = "/forget/activity"; - - @PostMapping(value = url + "/activity_creator") + @PostMapping(value = "/creator") @ResponseBody @ApiOperation(value = "创建活动", notes = "所有有关用户的数据传递均使用id,类型为int") @ApiImplicitParams({ - @ApiImplicitParam(name = "title", value = "活动标题", required = true), - @ApiImplicitParam(name = "type", value = "活动类型", required = true), + @ApiImplicitParam(name = "title", value = "活动标题", dataType = "String", required = true), + @ApiImplicitParam(name = "type", value = "活动类型", dataType = "String", required = true), @ApiImplicitParam(name = "start-time", value = "活动开始时间,格式为yyyy-MM-dd HH:mm:ss", required = true), @ApiImplicitParam(name = "end-time", value = "活动结束时间,格式为yyyy-MM-dd HH:mm:ss", required = true), - @ApiImplicitParam(name = "chief-manager", value = "主要负责人", required = true), - @ApiImplicitParam(name = "assist-managers", value = "次要负责人"), - @ApiImplicitParam(name = "description", value = "活动描述"), - @ApiImplicitParam(name = "cycle", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"), + @ApiImplicitParam(name = "chief-manager", dataType = "int", value = "主要负责人", required = true), + @ApiImplicitParam(name = "assist-managers", dataType = "int", value = "次要负责人"), + @ApiImplicitParam(name = "description", dataType = "String", value = "活动描述"), + @ApiImplicitParam(name = "cycle", dataType = "String", value = "活动周期,格式为阿拉伯数字数字+单位,0表示无周期"), @ApiImplicitParam(name = "participate-group", value = "预定参与人员"), - @ApiImplicitParam(name = "sign-group", value = "可参与人员"), - @ApiImplicitParam(name = "inform-group", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"), - @ApiImplicitParam(name = "visible-group", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"), - @ApiImplicitParam(name = "remind-time", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"), + @ApiImplicitParam(name = "sign-group", dataType = "List", value = "可参与人员"), + @ApiImplicitParam(name = "inform-group", dataType = "List", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"), + @ApiImplicitParam(name = "visible-group", dataType = "List", value = "活动可见人群,若为空,则默认为负责人、活动创建者预定参和可报名人员以及通知人员的并集"), + @ApiImplicitParam(name = "remind-time", dataType = "String", defaultValue = "30m", value = "活动提醒时间,格式为数字+单位,可接受的单位从大到小有:w,d,h,m,s"), }) String activityCreator(HttpServletRequest request) throws InvalidFormFormatException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { JSONObject error = new JSONObject(); aseSpringUtil = new ASESpringUtil(); + //判断是否为JSON对象 Optional json = jsonParameter.getJSONByRequest(request); if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond()); List formatCheckResult = jsonFormValidator.check(activityFormConfigure.getStdActivityForm(), json.get()); + //检验JSON格式是否有误 if (!formatCheckResult.isEmpty()) { error.put("error", formatCheckResult); - return error.toJSONString(); + throw new InvalidFormFormatException(error.toJSONString()); } - // 需要检查JSON是否合法 Activity activity = activityConverter.convertToActivity(json); List nullValues = nullValueValidator.checkNullValues(activity); @@ -136,7 +137,7 @@ public class ActivityCreatorController { String username = json.get().get("creator").toString(); Optional user = userService.findUserByUsername(username); UserActivity userActivity = userActivityRepository.findByUser(user.get()); - userActivity.getCreatedActivities().add(activity); + userActivity.getCreatedActs().add(activity); userActivityRepository.save(userActivity); } } @@ -146,7 +147,8 @@ public class ActivityCreatorController { nullParameters.put("null_values",nullValueAttributes.getNullValueAttributes()); return nullParameters.toJSONString(); } - return url + "/act_created"; + JSONObject jsonObject = (JSONObject) JSONObject.toJSON(activity); + return jsonObject.toJSONString(); } } 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 7068097..27ffa82 100644 --- a/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java +++ b/src/main/java/com/codesdream/ase/controller/activity/ActivityViewerController.java @@ -1,37 +1,94 @@ package com.codesdream.ase.controller.activity; -import com.codesdream.ase.component.ASESpringUtil; -import com.codesdream.ase.component.datamanager.JSONParameter; +import com.alibaba.fastjson.JSONObject; import com.codesdream.ase.model.activity.Activity; -import com.codesdream.ase.repository.activity.ActivityRepository; +import com.codesdream.ase.model.permission.User; import com.codesdream.ase.service.ActivityService; +import org.springframework.security.core.context.SecurityContextHolder; 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.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.security.Principal; +import java.util.List; @Controller +@RequestMapping("/forget/act") public class ActivityViewerController { - private final String url = "/forget/activity"; @Resource ActivityService activityService; - @Resource - ActivityRepository activityRepository; + @GetMapping("/created_acts") + String showCreated() { - @RequestMapping(value = url + "/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"; + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findCreatedActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/parting_acts") + String showParticipate(HttpServletRequest request) { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findParticipatingActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/parted_acts") + String showParticipated() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findParticipatedActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/sign_acts") + String showSign() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findSignActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/vis_acts") + String showVisible() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findVisibleActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/all") + String showAll() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findAll(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/main_responsible_acts") + String showMainResponsible() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findMainResponsibleActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/sec_responsible_acts") + String showSecondaryResponsible() { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findSecondaryResponsibleActs(user); + return JSONObject.toJSONString(activities); + } + + @GetMapping("/acts_by_type") + String showInType(@RequestParam(defaultValue = "考勤", name = "type") String type) { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + List activities = activityService.findActivityByType(user, type); + return JSONObject.toJSONString(activities); } } 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..bd8cb3d --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/FPCController.java @@ -0,0 +1,169 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.model.JsonableFPC; +import com.codesdream.ase.component.json.model.JsonableFunction; +import com.codesdream.ase.component.json.model.JsonableRoleList; +import com.codesdream.ase.component.json.model.JsonableUser; +import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.Function; +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import com.codesdream.ase.model.permission.Tag; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.service.PermissionService; +import com.github.fge.jsonpatch.JsonPatch; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +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 java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +@RestController +@RequestMapping(value = "pmt") +@Api(tags = "功能性权限容器接口") +public class FPCController { + + @Resource + private PermissionService permissionService; + + @Resource + private JSONParameter jsonParameter; + + @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(); + + + return new JsonableFPC(permissionService.save(fpc.parseObject(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/roles") + @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()); + } + + @PatchMapping("fpc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "更新标功能性权限容器内容") + public JsonableFPC patchFPC(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + + JsonableFPC jsonableFPC = new JsonableFPC(fpc.get()); + + jsonableFPC = jsonParameter.parsePathToObject(patch, jsonableFPC); + + return new JsonableFPC(permissionService.update(jsonableFPC.parseObject(fpc.get()))); + } + + @GetMapping("fpc/funcs") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "功能性权限容器所含功能集合") + public Set getFunctionFPC(@RequestParam(value = "id") Integer id){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + + + Set jsonableFunctions = new HashSet<>(); + for(Function function : fpc.get().getFunctions()){ + jsonableFunctions.add(new JsonableFunction(function)); + } + return jsonableFunctions; + } + + @PutMapping("fpc/funcs") + @ApiOperation("搜索单个功能性权限容器所属功能集合信息") + public Set setFunctionFPC(@RequestParam(value = "id") Integer id, + @RequestBody List functionIdList){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + + Set functionSet = new HashSet<>(functionIdList); + fpc.get().setFunctions(permissionService.findFunctions(functionSet)); + + Set jsonableFunctions = new HashSet<>(); + for(Function function : permissionService.update(fpc.get()).getFunctions()){ + jsonableFunctions.add(new JsonableFunction(function)); + } + return jsonableFunctions; + } + + @PostMapping("fpc/funcs") + @ApiOperation("从单个功能性权限容器所属功能集合中添加一个或多个功能") + public Set addFunctionFPC(@RequestParam(value = "id") Integer id, + @RequestBody List functionIdList){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + Set newFunctionSet = permissionService.findFunctions(new HashSet<>(functionIdList)); + + Set functionSet = fpc.get().getFunctions(); + + functionSet.addAll(newFunctionSet); + fpc.get().setFunctions(functionSet); + + Set jsonableFunctions = new HashSet<>(); + for(Function function : permissionService.update(fpc.get()).getFunctions()){ + jsonableFunctions.add(new JsonableFunction(function)); + } + return jsonableFunctions; + } + + @DeleteMapping("fpc/funcs") + @ResponseStatus(HttpStatus.OK) + @ApiOperation("从单个功能性权限容器所属功能集合中删除一个或多个功能") + public Set deleteUserTag(@RequestParam Integer id, + @RequestBody List functionIdList){ + Optional fpc = permissionService.findFPC(id); + if(!fpc.isPresent()) throw new NotFoundException(id.toString()); + Set functionSet = fpc.get().getFunctions(); + Set deleteFuncSet = permissionService.findFunctions(new HashSet<>(functionIdList)); + + functionSet.removeAll(deleteFuncSet); + fpc.get().setFunctions(functionSet); + + Set jsonableFunctions = new HashSet<>(); + for(Function function : permissionService.update(fpc.get()).getFunctions()){ + jsonableFunctions.add(new JsonableFunction(function)); + } + return jsonableFunctions; + } + +} diff --git a/src/main/java/com/codesdream/ase/controller/permission/FunctionController.java b/src/main/java/com/codesdream/ase/controller/permission/FunctionController.java new file mode 100644 index 0000000..f31a831 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/FunctionController.java @@ -0,0 +1,78 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.model.JsonableFPC; +import com.codesdream.ase.component.json.model.JsonableFunction; +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.Function; +import com.codesdream.ase.model.permission.FunctionalPermissionContainer; +import com.codesdream.ase.service.PermissionService; +import com.github.fge.jsonpatch.JsonPatch; +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 FunctionController { + @Resource + private PermissionService permissionService; + + @Resource + private JSONParameter jsonParameter; + + @GetMapping("func") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "查找功能") + public JsonableFunction getFunction(@RequestParam(value = "id") Integer id){ + Optional function = permissionService.findFunction(id); + if(!function.isPresent()) throw new NotFoundException(id.toString()); + return new JsonableFunction(function.get()); + } + + @PostMapping("func") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "创建新的功能") + public JsonableFunction createFunction(@RequestBody JsonableFunction function){ + if(permissionService.findFunction(function.getName()).isPresent()) + throw new AlreadyExistException(function.getName()); + + return new JsonableFunction(permissionService.save(function.parseObject(new Function()))); + } + + @GetMapping("funcs") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得所有功能的信息") + public Set listFunction(){ + Iterable functions = permissionService.findAllFunction(); + Set jsonableFunctions = new HashSet<>(); + for(Function function : functions){ + jsonableFunctions.add(new JsonableFunction(function)); + } + return jsonableFunctions; + } + + @PatchMapping("func") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "更新标功能内容") + public JsonableFunction patchFunction(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){ + Optional function = permissionService.findFunction(id); + if(!function.isPresent()) throw new NotFoundException(id.toString()); + + JsonableFunction jsonableFunction = new JsonableFunction(function.get()); + + jsonableFunction = jsonParameter.parsePathToObject(patch, jsonableFunction); + + return new JsonableFunction(permissionService.update(jsonableFunction.parseObject(function.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..8cf9963 --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/SPCController.java @@ -0,0 +1,92 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.datamanager.JSONParameter; +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 com.github.fge.jsonpatch.JsonPatch; +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; + + @Resource + private JSONParameter jsonParameter; + + @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/tags") + @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()); + + return new JsonableSPC(permissionService.save(spc.parseObject(permissionService.getDefaultSPC(spc.getName())))); + } + + @PatchMapping(value = "spc") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "更新范围性权限容器信息") + public JsonableSPC updateSPC(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){ + Optional spc = permissionService.findSPC(id); + if(!spc.isPresent()) throw new NotFoundException(id.toString()); + JsonableSPC jsonableSPC = jsonParameter.parsePathToObject(patch, new JsonableSPC(spc.get())); + + return new JsonableSPC(permissionService.update(jsonableSPC.parseObject(spc.get()))); + } + + + +} 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 55% 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..1ad8d60 100644 --- a/src/main/java/com/codesdream/ase/controller/PermissionController.java +++ b/src/main/java/com/codesdream/ase/controller/permission/TagController.java @@ -1,9 +1,8 @@ -package com.codesdream.ase.controller; +package com.codesdream.ase.controller.permission; -import com.codesdream.ase.component.datamanager.JsonPathParameter; +import com.codesdream.ase.component.datamanager.JSONParameter; import com.codesdream.ase.component.json.model.JsonablePCCList; import com.codesdream.ase.component.json.model.JsonableTag; -import com.codesdream.ase.component.json.model.JsonableUserList; import com.codesdream.ase.component.json.model.JsonableUser; import com.codesdream.ase.exception.badrequest.AlreadyExistException; import com.codesdream.ase.exception.conflict.RelatedObjectsExistException; @@ -14,16 +13,11 @@ 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 java.util.HashSet; @@ -33,8 +27,8 @@ import java.util.Set; @RestController @RequestMapping("pmt") -@Api(tags = "权限管理接口") -public class PermissionController { +@Api(tags = "标签管理接口") +public class TagController { @Resource private PermissionService permissionService; @@ -43,7 +37,7 @@ public class PermissionController { private IUserService userService; @Resource - private JsonPathParameter pathParameter; + private JSONParameter jsonParameter; // 根据名字创建新的标签 @PostMapping("tag") @@ -53,31 +47,26 @@ public class PermissionController { String tagName = tag.getName(); Optional tagOptional = permissionService.findTag(tagName); if(tagOptional.isPresent()) throw new AlreadyExistException(tagName); - Tag newTag = permissionService.getDefaultTag(tagName); - if(tag.getDescription() != null) { - newTag.setDescription(tag.getDescription()); - } - return new JsonableTag(permissionService.save(newTag)); + + return new JsonableTag(permissionService.save(tag.parseObject(permissionService.getDefaultTag(tag.getName())))); } // 根据名字搜索标签的简要信息 @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 +80,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,83 +92,95 @@ 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); + jsonableTag = jsonParameter.parsePathToObject(patch, jsonableTag); - tag.get().setName(jsonableTag.getName()); - tag.get().setDescription(jsonableTag.getDescription()); - - return new JsonableTag(permissionService.save(tag.get())); + return new JsonableTag(permissionService.update(jsonableTag.parseObject(tag.get()))); } - - @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); + @ApiOperation("搜索单个标签所属用户集合信息") + public Set setUserTag(@RequestParam(value = "id") Integer id, + @RequestBody List userIdList){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); - Set userSet = new HashSet<>(userList.getUsers()); + Set userSet = new HashSet<>(userIdList); tag.get().setUsers(userService.findUsersById(userSet)); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : permissionService.update(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); - Set newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers())); + @ApiOperation("从单个标签所属用户集合中添加一个或多个用户") + public Set addUserTag(@RequestParam(value = "id") Integer id, + @RequestBody List userIdList){ + Optional tag = permissionService.findTag(id); + if(!tag.isPresent()) throw new NotFoundException(id.toString()); + Set newUserSet = userService.findUsersById(new HashSet<>(userIdList)); Set userSet = tag.get().getUsers(); userSet.addAll(newUserSet); tag.get().setUsers(userSet); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : permissionService.update(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 List userIdList){ + 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())); + Set deleteUserSet = userService.findUsersById(new HashSet<>(userIdList)); userSet.removeAll(deleteUserSet); tag.get().setUsers(userSet); - return new JsonableUserList(permissionService.save(tag.get())); + Set jsonableUsers = new HashSet<>(); + for(User user : permissionService.update(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){ @@ -194,10 +194,10 @@ 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); + @ApiOperation("获取标签所含权力列表") + 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,12 +205,12 @@ 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()))); + pccs.addAll(permissionService.findPCCs(new HashSet<>(jsonablePCCList.getPccIdList()))); tagOptional.get().setPermissionContainersCollections(pccs); diff --git a/src/main/java/com/codesdream/ase/controller/permission/UserController.java b/src/main/java/com/codesdream/ase/controller/permission/UserController.java new file mode 100644 index 0000000..2ded81d --- /dev/null +++ b/src/main/java/com/codesdream/ase/controller/permission/UserController.java @@ -0,0 +1,68 @@ +package com.codesdream.ase.controller.permission; + +import com.codesdream.ase.component.datamanager.JSONParameter; +import com.codesdream.ase.component.json.model.JsonableFunction; +import com.codesdream.ase.component.json.model.JsonableUser; +import com.codesdream.ase.exception.badrequest.AlreadyExistException; +import com.codesdream.ase.exception.notfound.NotFoundException; +import com.codesdream.ase.model.permission.Function; +import com.codesdream.ase.model.permission.User; +import com.codesdream.ase.service.PermissionService; +import com.codesdream.ase.service.UserService; +import com.github.fge.jsonpatch.JsonPatch; +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 UserController { + + @Resource + private UserService userService; + + @Resource + private JSONParameter jsonParameter; + + @GetMapping("user") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "查找用户") + public JsonableUser getUser(@RequestParam(value = "id") Integer id){ + Optional user = userService.findUserById(id); + if(!user.isPresent()) throw new NotFoundException(id.toString()); + return new JsonableUser(user.get()); + } + + @GetMapping("users") + @ResponseStatus(HttpStatus.OK) + @ApiOperation(value = "获得所有用户的信息") + public Set listUser(){ + Iterable users = userService.findAll(); + Set jsonableUsers = new HashSet<>(); + for(User user : users){ + jsonableUsers.add(new JsonableUser(user)); + } + return jsonableUsers; + } + + @PatchMapping("user") + @ResponseStatus(HttpStatus.CREATED) + @ApiOperation(value = "更新标用户的部分信息") + public JsonableUser patchUser(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){ + Optional userOptional = userService.findUserById(id); + if(!userOptional.isPresent()) throw new NotFoundException(id.toString()); + + JsonableUser jsonableUser = new JsonableUser(userOptional.get()); + + jsonableUser = jsonParameter.parsePathToObject(patch, jsonableUser); + + return new JsonableUser(userService.update(jsonableUser.parseObject(userOptional.get()))); + } +} diff --git a/src/main/java/com/codesdream/ase/exception/LackOfActivityInformation.java b/src/main/java/com/codesdream/ase/exception/LackOfActivityInformation.java deleted file mode 100644 index 9b6425a..0000000 --- a/src/main/java/com/codesdream/ase/exception/LackOfActivityInformation.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.codesdream.ase.exception; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class LackOfActivityInformation extends Throwable { - private String message = ""; - - public LackOfActivityInformation(){super();} - - public LackOfActivityInformation(String message){this.message = message;} -} diff --git a/src/main/java/com/codesdream/ase/exception/LackOfActivityInformationException.java b/src/main/java/com/codesdream/ase/exception/LackOfActivityInformationException.java new file mode 100644 index 0000000..656d2ca --- /dev/null +++ b/src/main/java/com/codesdream/ase/exception/LackOfActivityInformationException.java @@ -0,0 +1,18 @@ +package com.codesdream.ase.exception; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class LackOfActivityInformationException extends Throwable { + private String message = ""; + + public LackOfActivityInformationException() { + super(); + } + + public LackOfActivityInformationException(String message) { + this.message = message; + } +} 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/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; + } + +} 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/model/activity/UserActivity.java b/src/main/java/com/codesdream/ase/model/activity/UserActivity.java index 01add89..7e54c53 100644 --- a/src/main/java/com/codesdream/ase/model/activity/UserActivity.java +++ b/src/main/java/com/codesdream/ase/model/activity/UserActivity.java @@ -23,33 +23,33 @@ public class UserActivity { //主要负责的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List manageActivities; + private List mainResponsibleActs; //次要负责的活动 @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List assistActivities; + private List secondaryResponsibleActs; //可见的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List visibleActivities; + private List visibleActs; //创建的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List createdActivities; + private List createdActs; //可报名的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List signUpActivities; + private List signUpActs; //已经参与的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List participatedActivities; + private List participatedActs; //正在(将要)参与的活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List participatingActivities; + private List participatingActs; //打卡签到活动 @OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY) - private List clockIn; + private List clockIns; } diff --git a/src/main/java/com/codesdream/ase/model/permission/Function.java b/src/main/java/com/codesdream/ase/model/permission/Function.java new file mode 100644 index 0000000..b1b1cf5 --- /dev/null +++ b/src/main/java/com/codesdream/ase/model/permission/Function.java @@ -0,0 +1,31 @@ +package com.codesdream.ase.model.permission; + +import io.swagger.models.auth.In; +import lombok.Data; +import org.hibernate.annotations.GeneratorType; + +import javax.persistence.*; + +/** + * 功能 + */ +@Data +@Entity +@Table(name = "function") +public class Function { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Integer id; + + // 功能名称 + private String name; + + // 功能描述 + private String description; + + @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) + private Function father = null; + + // 授权url + private String url; +} diff --git a/src/main/java/com/codesdream/ase/model/permission/FunctionalPermissionContainer.java b/src/main/java/com/codesdream/ase/model/permission/FunctionalPermissionContainer.java index 5d40330..281f724 100644 --- a/src/main/java/com/codesdream/ase/model/permission/FunctionalPermissionContainer.java +++ b/src/main/java/com/codesdream/ase/model/permission/FunctionalPermissionContainer.java @@ -3,8 +3,10 @@ package com.codesdream.ase.model.permission; import lombok.Data; import javax.persistence.*; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; /** @@ -25,10 +27,10 @@ public class FunctionalPermissionContainer { // 功能性权限容器解释 private String description = ""; - // 对应访问控制角色列表 - @ElementCollection + // 对应访问控制角色列表W + @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY) @Column(nullable = false) - private List roles = new LinkedList<>(); + private Set functions = new HashSet<>(); // 是否启用 @Column(nullable = false) diff --git a/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java b/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java index 59bd01f..cb76aa6 100644 --- a/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java +++ b/src/main/java/com/codesdream/ase/model/permission/FunctionalScopeRelation.java @@ -6,7 +6,7 @@ import lombok.Data; import javax.persistence.*; /** - * 功能性权限容器与范围性权限容器关联对 + * 功能性权限容器与范围性权限容器关联对 (单项权力) */ @Data @Entity @@ -17,6 +17,10 @@ public class FunctionalScopeRelation { @GeneratedValue(strategy = GenerationType.AUTO) private int id; + private String name; + + private String description; + // 对应功能性权限容器 @OneToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) private FunctionalPermissionContainer functionalPermissionContainer; diff --git a/src/main/java/com/codesdream/ase/model/permission/PermissionContainersCollection.java b/src/main/java/com/codesdream/ase/model/permission/PermissionContainersCollection.java index d1fc295..f7b75c0 100644 --- a/src/main/java/com/codesdream/ase/model/permission/PermissionContainersCollection.java +++ b/src/main/java/com/codesdream/ase/model/permission/PermissionContainersCollection.java @@ -6,7 +6,7 @@ import java.util.HashSet; import java.util.Set; /** - * 权限容器集合 + * 权限容器集合(多项权力) */ @Data @Entity diff --git a/src/main/java/com/codesdream/ase/repository/activity/ActivityRepository.java b/src/main/java/com/codesdream/ase/repository/activity/ActivityRepository.java index 77c49bd..aa5ea5b 100644 --- a/src/main/java/com/codesdream/ase/repository/activity/ActivityRepository.java +++ b/src/main/java/com/codesdream/ase/repository/activity/ActivityRepository.java @@ -1,13 +1,18 @@ package com.codesdream.ase.repository.activity; import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.model.permission.User; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository -public interface ActivityRepository extends CrudRepository { +public interface ActivityRepository extends JpaRepository { Optional findByTitle(String Title); diff --git a/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java b/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java index 80ff99c..dbbef67 100644 --- a/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java +++ b/src/main/java/com/codesdream/ase/repository/activity/UserActivityRepository.java @@ -1,14 +1,17 @@ package com.codesdream.ase.repository.activity; +import com.codesdream.ase.model.activity.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.List; import java.util.Optional; @Repository public interface UserActivityRepository extends CrudRepository { UserActivity findByUser(User user); + } diff --git a/src/main/java/com/codesdream/ase/repository/permission/FunctionRepository.java b/src/main/java/com/codesdream/ase/repository/permission/FunctionRepository.java new file mode 100644 index 0000000..49f34f2 --- /dev/null +++ b/src/main/java/com/codesdream/ase/repository/permission/FunctionRepository.java @@ -0,0 +1,12 @@ +package com.codesdream.ase.repository.permission; + +import com.codesdream.ase.model.permission.Function; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface FunctionRepository extends CrudRepository { + Optional findByName(String name); +} 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..e2f7a0a --- /dev/null +++ b/src/main/java/com/codesdream/ase/service/AchievementService.java @@ -0,0 +1,8 @@ +package com.codesdream.ase.service; + +import org.springframework.stereotype.Service; + +@Service +public class AchievementService { + +} diff --git a/src/main/java/com/codesdream/ase/service/ActivityService.java b/src/main/java/com/codesdream/ase/service/ActivityService.java index 1c683b8..9c42112 100644 --- a/src/main/java/com/codesdream/ase/service/ActivityService.java +++ b/src/main/java/com/codesdream/ase/service/ActivityService.java @@ -1,13 +1,17 @@ package com.codesdream.ase.service; import com.codesdream.ase.model.activity.Activity; +import com.codesdream.ase.model.activity.Period; import com.codesdream.ase.model.activity.Report; +import com.codesdream.ase.model.activity.UserActivity; import com.codesdream.ase.model.permission.User; import com.codesdream.ase.repository.activity.ActivityRepository; +import com.codesdream.ase.repository.activity.UserActivityRepository; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.Optional; +import java.time.LocalDateTime; +import java.util.*; @Service public class ActivityService implements IActivityService { @@ -15,6 +19,9 @@ public class ActivityService implements IActivityService { @Resource private ActivityRepository activityRepository; + @Resource + private UserActivityRepository userActivityRepository; + @Override public Optional findActivityByTitle(String title) { return activityRepository.findByTitle(title); @@ -25,6 +32,20 @@ public class ActivityService implements IActivityService { return activityRepository.findByCreator(creatorName); } + + @Override + public List findActivityByType(User user, String type) { + + List activities = this.findAll(user); + List actsByType = new ArrayList<>(); + for (Activity activity : activities) { + if (activity.getType().equals(type)) { + actsByType.add(activity); + } + } + return actsByType; + } + @Override public Activity save(Activity activity) { return activityRepository.save(activity); @@ -51,9 +72,109 @@ public class ActivityService implements IActivityService { return activityRepository.save(activity); } - /*@Override - public Activity findActivitiesInTheCharge(User user) { + @Override + public List findMainResponsibleActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getMainResponsibleActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findSecondaryResponsibleActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getSecondaryResponsibleActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findVisibleActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getVisibleActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findSignActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getSignUpActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findParticipatedActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getParticipatedActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findParticipatingActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getParticipatingActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findCreatedActs(User user) { + + UserActivity userActivity = userActivityRepository.findByUser(user); + List acts = userActivity.getCreatedActs(); + Collections.sort(acts, new ActivityComparator()); + return acts; + } + + @Override + public List findAll(User user) { + + List activities = findCreatedActs(user); + List activities1 = findMainResponsibleActs(user); + List activities2 = findSecondaryResponsibleActs(user); + List activities3 = findParticipatingActs(user); + List activities4 = findParticipatedActs(user); + List activities5 = findParticipatingActs(user); + List activities6 = findSignActs(user); + List activities7 = findVisibleActs(user); + Set activitySet = new HashSet<>(); + activitySet.addAll(activities); + activitySet.addAll(activities1); + activitySet.addAll(activities2); + activitySet.addAll(activities3); + activitySet.addAll(activities4); + activitySet.addAll(activities5); + activitySet.addAll(activities6); + activitySet.addAll(activities7); + List res = new ArrayList<>(activitySet); + Collections.sort(res, new ActivityComparator()); + return res; + } - }*/ } + +class ActivityComparator implements Comparator { + + + @Override + public int compare(Activity o1, Activity o2) { + + Period p1 = o1.getRealPeriod(); + Period p2 = o2.getRealPeriod(); + LocalDateTime s1 = p1.getStartTime(); + LocalDateTime s2 = p2.getStartTime(); + if (s1.isBefore(s2)) return -1; + else if (s1.isAfter(s2)) return 1; + else return 0; + } +} \ No newline at end of file diff --git a/src/main/java/com/codesdream/ase/service/IActivityService.java b/src/main/java/com/codesdream/ase/service/IActivityService.java index 1e9ba3e..0e85465 100644 --- a/src/main/java/com/codesdream/ase/service/IActivityService.java +++ b/src/main/java/com/codesdream/ase/service/IActivityService.java @@ -4,6 +4,7 @@ import com.codesdream.ase.model.activity.Activity; import com.codesdream.ase.model.activity.Report; import com.codesdream.ase.model.permission.User; +import java.util.List; import java.util.Optional; public interface IActivityService { @@ -13,6 +14,9 @@ public interface IActivityService { //通过创建人姓名查找活动 Optional findActivityByCreator(String creatorName); + //通过活动类型查找活动 + List findActivityByType(User user, String type); + //活动持久化 Activity save(Activity activity); @@ -29,6 +33,27 @@ public interface IActivityService { Activity createActivity(Activity activity); //查询主要负责的活动 - //Activity findActivitiesInTheCharge(User user); + List findMainResponsibleActs(User user); + + //查询次要负责的活动 + List findSecondaryResponsibleActs(User user); + + //查询所有可见活动(即可报名活动、主次要负责的活动、参与过的活动等等之外却仍然可见的活动并集) + List findVisibleActs(User user); + + //查找可报名的活动 + List findSignActs(User user); + + //查询参与过的活动 + List findParticipatedActs(User user); + + //查询将要参与的活动 + List findParticipatingActs(User user); + + //查询创建的活动 + List findCreatedActs(User user); + + //查询所有活动(权限内) + List findAll(User user); } diff --git a/src/main/java/com/codesdream/ase/service/IPermissionService.java b/src/main/java/com/codesdream/ase/service/IPermissionService.java index fb875ab..5bd47ad 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); @@ -48,6 +49,17 @@ public interface IPermissionService { Optional findPCC(Integer id); + // 查找功能 + Optional findFunction(Integer id); + + // 查找功能 + Optional findFunction(String name); + + // 根据序号列表寻找功能 + Set findFunctions(Set funcs); + + Iterable findAllFunction(); + // 获得范围性权限容器下的所有标签列表 Collection getTagsFromSPC( ScopePermissionContainer spc); @@ -84,12 +96,12 @@ public interface IPermissionService { // 为功能性权限容器添加一个访问控制角色 FunctionalPermissionContainer addRoleToFPC( FunctionalPermissionContainer fpc, - String role); + Function function); // 为功能性权限容器添加多个访问控制角色 FunctionalPermissionContainer addRolesToFPC( FunctionalPermissionContainer fpc, - Collection roles); + Collection functions); // 为范围性权限容器添加一个标签 ScopePermissionContainer addTagToSPC(ScopePermissionContainer spc, Tag tag); @@ -105,6 +117,8 @@ public interface IPermissionService { Tag save(Tag tag); + Function save(Function tag); + void delete(Tag tag); FunctionalPermissionContainer save(FunctionalPermissionContainer fpc); @@ -115,6 +129,8 @@ public interface IPermissionService { Tag update(Tag tag); + Function update(Function function); + FunctionalPermissionContainer update(FunctionalPermissionContainer fpc); ScopePermissionContainer update(ScopePermissionContainer spc); diff --git a/src/main/java/com/codesdream/ase/service/PermissionService.java b/src/main/java/com/codesdream/ase/service/PermissionService.java index 6ddea4f..21c7774 100644 --- a/src/main/java/com/codesdream/ase/service/PermissionService.java +++ b/src/main/java/com/codesdream/ase/service/PermissionService.java @@ -2,14 +2,11 @@ package com.codesdream.ase.service; import com.codesdream.ase.component.permission.UserFPCListGenerator; import com.codesdream.ase.component.permission.UserFSRGenerator; +import com.codesdream.ase.exception.badrequest.AlreadyExistException; import com.codesdream.ase.exception.notfound.NotFoundException; import com.codesdream.ase.model.permission.*; -import com.codesdream.ase.repository.permission.FunctionalPermissionContainerRepository; -import com.codesdream.ase.repository.permission.PermissionContainersCollectionRepository; -import com.codesdream.ase.repository.permission.ScopePermissionContainerRepository; -import com.codesdream.ase.repository.permission.TagRepository; +import com.codesdream.ase.repository.permission.*; import javafx.util.Pair; -import org.apache.poi.ss.formula.functions.T; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -39,6 +36,9 @@ public class PermissionService implements IPermissionService { @Resource private UserFSRGenerator userFSRGenerator; + @Resource + private FunctionRepository functionRepository; + @Override public FunctionalPermissionContainer getDefaultFPC(String name) { return new FunctionalPermissionContainer(name); @@ -75,11 +75,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 +90,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 +104,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); @@ -126,6 +135,32 @@ public class PermissionService implements IPermissionService { return pccRepository.findById(id); } + @Override + public Optional findFunction(Integer id) { + return functionRepository.findById(id); + } + + @Override + public Optional findFunction(String name) { + return functionRepository.findByName(name); + } + + @Override + public Set findFunctions(Set funcs) { + Set set = new HashSet<>(); + for(Integer id : funcs){ + Optional function = findFunction(id); + if(!function.isPresent()) throw new NotFoundException(id.toString()); + set.add(function.get()); + } + return set; + } + + @Override + public Iterable findAllFunction() { + return functionRepository.findAll(); + } + @Override public Collection getTagsFromSPC(ScopePermissionContainer spc) { return new ArrayList<>(spc.getTags()); @@ -204,15 +239,15 @@ public class PermissionService implements IPermissionService { } @Override - public FunctionalPermissionContainer addRoleToFPC(FunctionalPermissionContainer fpc, String role) { - fpc.getRoles().add(role); + public FunctionalPermissionContainer addRoleToFPC(FunctionalPermissionContainer fpc, Function function) { + fpc.getFunctions().add(function); return update(fpc); } @Override - public FunctionalPermissionContainer addRolesToFPC(FunctionalPermissionContainer fpc, Collection roles) { - for(String role : roles){ - fpc = addRoleToFPC(fpc, role); + public FunctionalPermissionContainer addRolesToFPC(FunctionalPermissionContainer fpc, Collection functions) { + for(Function function : functions){ + fpc = addRoleToFPC(fpc, function); } return fpc; } @@ -252,10 +287,17 @@ public class PermissionService implements IPermissionService { @Override public Tag save(Tag tag) { if(tagRepository.findByName(tag.getName()).isPresent()) - throw new RuntimeException("Tag Already Exist"); + throw new AlreadyExistException(tag.getName()); return tagRepository.save(tag); } + @Override + public Function save(Function function) { + if(functionRepository.findByName(function.getName()).isPresent()) + throw new AlreadyExistException(function.getName()); + return functionRepository.save(function); + } + @Override public void delete(Tag tag) { tagRepository.delete(tag); @@ -264,49 +306,56 @@ public class PermissionService implements IPermissionService { @Override public FunctionalPermissionContainer save(FunctionalPermissionContainer fpc) { if(fpcRepository.findByName(fpc.getName()).isPresent()) - throw new RuntimeException("FPC Already Exist"); + throw new AlreadyExistException(fpc.getName()); return fpcRepository.save(fpc); } @Override public ScopePermissionContainer save(ScopePermissionContainer spc) { if(spcRepository.findByName(spc.getName()).isPresent()) - throw new RuntimeException("SPC Already Exist"); + throw new AlreadyExistException(spc.getName()); return spcRepository.save(spc); } @Override public PermissionContainersCollection save(PermissionContainersCollection pcc) { if(pccRepository.findByName(pcc.getName()).isPresent()) - throw new RuntimeException("PCC Already Exist"); + throw new RuntimeException(pcc.getName()); return pccRepository.save(pcc); } @Override public Tag update(Tag tag) { if(!tagRepository.findByName(tag.getName()).isPresent()) - throw new RuntimeException(("Tag Not Exist")); + throw new NotFoundException(tag.getName()); return tagRepository.save(tag); } + @Override + public Function update(Function function) { + if(!functionRepository.findByName(function.getName()).isPresent()) + throw new NotFoundException(function.getName()); + return functionRepository.save(function); + } + @Override public FunctionalPermissionContainer update(FunctionalPermissionContainer fpc) { if(!fpcRepository.findByName(fpc.getName()).isPresent()) - throw new RuntimeException("FPC Not Exist"); + throw new NotFoundException(fpc.getName()); return fpcRepository.save(fpc); } @Override public ScopePermissionContainer update(ScopePermissionContainer spc) { if(!spcRepository.findByName(spc.getName()).isPresent()) - throw new RuntimeException("SPC Not Exist"); + throw new NotFoundException(spc.getName()); return spcRepository.save(spc); } @Override public PermissionContainersCollection update(PermissionContainersCollection pcc) { if(!pccRepository.findByName(pcc.getName()).isPresent()) - throw new RuntimeException("PCC Not Exist"); + throw new NotFoundException(pcc.getName()); return pccRepository.save(pcc); } } diff --git a/src/main/java/com/codesdream/ase/service/UserService.java b/src/main/java/com/codesdream/ase/service/UserService.java index da9333b..29b70fa 100644 --- a/src/main/java/com/codesdream/ase/service/UserService.java +++ b/src/main/java/com/codesdream/ase/service/UserService.java @@ -2,7 +2,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.component.permission.UserFunctionsListGenerator; import com.codesdream.ase.exception.badrequest.UserInformationIllegalException; import com.codesdream.ase.exception.notfound.UserNotFoundException; import com.codesdream.ase.exception.badrequest.UsernameAlreadyExistException; @@ -20,7 +20,7 @@ import java.util.*; @Service public class UserService implements IUserService { @Resource - UserRolesListGenerator userRolesListGenerator; + UserFunctionsListGenerator userFunctionsListGenerator; @Resource UserRepository userRepository; @@ -56,7 +56,7 @@ public class UserService implements IUserService { @Override public Collection getUserAuthorities(User user) { - return userRolesListGenerator.generateRoles(user); + return userFunctionsListGenerator.generateRoles(user); } @Override 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; + + +} diff --git a/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java b/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java index 8bc8cd2..f56ca04 100644 --- a/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java +++ b/src/test/java/com/codesdream/ase/test/PermissionServiceTest.java @@ -41,9 +41,9 @@ public class PermissionServiceTest { pcc = permissionService.save(pcc); // 给活动管理权赋予添加/参与/管理的权力 - fpc = permissionService.addRoleToFPC(fpc, "activity_create"); +/* fpc = permissionService.addRoleToFPC(fpc, "activity_create"); fpc = permissionService.addRoleToFPC(fpc, "activity_participate"); - fpc = permissionService.addRoleToFPC(fpc, "activity_manage"); + fpc = permissionService.addRoleToFPC(fpc, "activity_manage");*/ // 把九班班委加入到九班全体学生中 spc = permissionService.addTagToSPC(spc, tag2);