Merge branch 'master' of 39.100.94.111:root/ASE into hua_1
This commit is contained in:
commit
7e43a10dc3
@ -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<JSONObject> 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<User> creator = userService.findUserById(userId);
|
||||
activity.setCreator(creator.get());
|
||||
|
||||
//设置参与人员
|
||||
List<Integer> participateGroupFromJson = (List<Integer>) jsonObject.get("participate-group");
|
||||
Set<User> 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<User> chiefManager = userService.findUserById(chiefManagerId);
|
||||
activity.setChiefManager(chiefManager.get());
|
||||
|
||||
//设置次要负责人
|
||||
List<Integer> assistManagersFromJSON = (List<Integer>) jsonObject.get("assist-managers");
|
||||
Set<User> 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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<ConfigAttribute> 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;
|
||||
}
|
||||
}
|
@ -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<String, Collection<ConfigAttribute>> map = null;
|
||||
|
||||
@Resource
|
||||
private FunctionRepository functionRepository;
|
||||
|
||||
private void loadFunctionDefine(){
|
||||
map = new HashMap<>();
|
||||
Iterable<Function> functions = functionRepository.findAll();
|
||||
for(Function function : functions) {
|
||||
Collection<ConfigAttribute> array = new ArrayList<>();
|
||||
ConfigAttribute cfg = new SecurityConfig(function.getName());
|
||||
|
||||
array.add(cfg);
|
||||
|
||||
map.put(function.getUrl(), array);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConfigAttribute> 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<ConfigAttribute> getAllConfigAttributes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
@ -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> 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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> 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());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -8,5 +8,5 @@ import java.util.Date;
|
||||
@Slf4j
|
||||
public class JSONBaseObject {
|
||||
Date time = new Date();
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.codesdream.ase.component.json.form;
|
||||
|
||||
public class RegisterForm {
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<FunctionalPermissionContainer> fpc = permissionService.findFPC(this.fpcId);
|
||||
if(!fpc.isPresent()) throw new NotFoundException(this.fpcId.toString());
|
||||
fsr.setFunctionalPermissionContainer(fpc.get());
|
||||
}
|
||||
|
||||
if(this.spcId != null){
|
||||
Optional<ScopePermissionContainer> spc = permissionService.findSPC(this.spcId);
|
||||
if(!spc.isPresent()) throw new NotFoundException(this.spcId.toString());
|
||||
fsr.setScopePermissionContainer(spc.get());
|
||||
}
|
||||
|
||||
return fsr;
|
||||
|
||||
}
|
||||
}
|
@ -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<Function> fatherFunction = permissionService.findFunction(this.fatherId);
|
||||
if (!fatherFunction.isPresent()) throw new NotFoundException(fatherId.toString());
|
||||
function.setFather(fatherFunction.get());
|
||||
}
|
||||
function.setUrl(this.url);
|
||||
|
||||
return function;
|
||||
}
|
||||
}
|
@ -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<Integer> 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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Integer> users;
|
||||
|
||||
|
||||
public JsonableUserList(Tag tag){
|
||||
for(User user : tag.getUsers()){
|
||||
users.add(user.getId());
|
||||
}
|
||||
}
|
||||
}
|
@ -10,10 +10,10 @@ import java.util.Collection;
|
||||
@Component
|
||||
public class UserAuthoritiesGenerator {
|
||||
@Resource
|
||||
UserRolesListGenerator userRolesListGenerator;
|
||||
UserFunctionsListGenerator userFunctionsListGenerator;
|
||||
|
||||
public Collection<? extends GrantedAuthority> grantedAuthorities(User user){
|
||||
return userRolesListGenerator.generateRoles(user);
|
||||
return userFunctionsListGenerator.generateRoles(user);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<FunctionalPermissionContainer> fpcs){
|
||||
Collection<GrantedAuthority> 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;
|
@ -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);
|
||||
|
||||
|
@ -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";
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<int>", value = "可参与人员"),
|
||||
@ApiImplicitParam(name = "inform-group", dataType = "List<int>", value = "通知人群,若为空,则默认为预定参与人员和可报名人员的并集"),
|
||||
@ApiImplicitParam(name = "visible-group", dataType = "List<int>", 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<JSONObject> json = jsonParameter.getJSONByRequest(request);
|
||||
if (!json.isPresent()) return jsonParameter.getJSONString(new JSONStandardFailedRespond());
|
||||
|
||||
List<String> 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<String> nullValues = nullValueValidator.checkNullValues(activity);
|
||||
|
||||
@ -136,7 +137,7 @@ public class ActivityCreatorController {
|
||||
String username = json.get().get("creator").toString();
|
||||
Optional<User> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Activity> participatedActivities = activityRepository.findc
|
||||
return "/my/participated";
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findCreatedActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/parting_acts")
|
||||
String showParticipate(HttpServletRequest request) {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findParticipatingActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/parted_acts")
|
||||
String showParticipated() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findParticipatedActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/sign_acts")
|
||||
String showSign() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findSignActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/vis_acts")
|
||||
String showVisible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findVisibleActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/all")
|
||||
String showAll() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findAll(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/main_responsible_acts")
|
||||
String showMainResponsible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> activities = activityService.findMainResponsibleActs(user);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
|
||||
@GetMapping("/sec_responsible_acts")
|
||||
String showSecondaryResponsible() {
|
||||
|
||||
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
List<Activity> 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<Activity> activities = activityService.findActivityByType(user, type);
|
||||
return JSONObject.toJSONString(activities);
|
||||
}
|
||||
}
|
||||
|
@ -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<FunctionalPermissionContainer> 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<JsonableFPC> listFPC(){
|
||||
Iterable<FunctionalPermissionContainer> fpcs = permissionService.findAllFPC();
|
||||
Set<JsonableFPC> 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> 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<FunctionalPermissionContainer> 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<JsonableFunction> getFunctionFPC(@RequestParam(value = "id") Integer id){
|
||||
Optional<FunctionalPermissionContainer> fpc = permissionService.findFPC(id);
|
||||
if(!fpc.isPresent()) throw new NotFoundException(id.toString());
|
||||
|
||||
|
||||
Set<JsonableFunction> jsonableFunctions = new HashSet<>();
|
||||
for(Function function : fpc.get().getFunctions()){
|
||||
jsonableFunctions.add(new JsonableFunction(function));
|
||||
}
|
||||
return jsonableFunctions;
|
||||
}
|
||||
|
||||
@PutMapping("fpc/funcs")
|
||||
@ApiOperation("搜索单个功能性权限容器所属功能集合信息")
|
||||
public Set<JsonableFunction> setFunctionFPC(@RequestParam(value = "id") Integer id,
|
||||
@RequestBody List<Integer> functionIdList){
|
||||
Optional<FunctionalPermissionContainer> fpc = permissionService.findFPC(id);
|
||||
if(!fpc.isPresent()) throw new NotFoundException(id.toString());
|
||||
|
||||
Set<Integer> functionSet = new HashSet<>(functionIdList);
|
||||
fpc.get().setFunctions(permissionService.findFunctions(functionSet));
|
||||
|
||||
Set<JsonableFunction> jsonableFunctions = new HashSet<>();
|
||||
for(Function function : permissionService.update(fpc.get()).getFunctions()){
|
||||
jsonableFunctions.add(new JsonableFunction(function));
|
||||
}
|
||||
return jsonableFunctions;
|
||||
}
|
||||
|
||||
@PostMapping("fpc/funcs")
|
||||
@ApiOperation("从单个功能性权限容器所属功能集合中添加一个或多个功能")
|
||||
public Set<JsonableFunction> addFunctionFPC(@RequestParam(value = "id") Integer id,
|
||||
@RequestBody List<Integer> functionIdList){
|
||||
Optional<FunctionalPermissionContainer> fpc = permissionService.findFPC(id);
|
||||
if(!fpc.isPresent()) throw new NotFoundException(id.toString());
|
||||
Set<Function> newFunctionSet = permissionService.findFunctions(new HashSet<>(functionIdList));
|
||||
|
||||
Set<Function> functionSet = fpc.get().getFunctions();
|
||||
|
||||
functionSet.addAll(newFunctionSet);
|
||||
fpc.get().setFunctions(functionSet);
|
||||
|
||||
Set<JsonableFunction> 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<JsonableFunction> deleteUserTag(@RequestParam Integer id,
|
||||
@RequestBody List<Integer> functionIdList){
|
||||
Optional<FunctionalPermissionContainer> fpc = permissionService.findFPC(id);
|
||||
if(!fpc.isPresent()) throw new NotFoundException(id.toString());
|
||||
Set<Function> functionSet = fpc.get().getFunctions();
|
||||
Set<Function> deleteFuncSet = permissionService.findFunctions(new HashSet<>(functionIdList));
|
||||
|
||||
functionSet.removeAll(deleteFuncSet);
|
||||
fpc.get().setFunctions(functionSet);
|
||||
|
||||
Set<JsonableFunction> jsonableFunctions = new HashSet<>();
|
||||
for(Function function : permissionService.update(fpc.get()).getFunctions()){
|
||||
jsonableFunctions.add(new JsonableFunction(function));
|
||||
}
|
||||
return jsonableFunctions;
|
||||
}
|
||||
|
||||
}
|
@ -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> 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<JsonableFunction> listFunction(){
|
||||
Iterable<Function> functions = permissionService.findAllFunction();
|
||||
Set<JsonableFunction> 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> 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())));
|
||||
}
|
||||
}
|
@ -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<ScopePermissionContainer> 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<JsonableSPC> listSPC(){
|
||||
Iterable<ScopePermissionContainer> spcs = permissionService.findALLSPC();
|
||||
Set<JsonableSPC> 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<JsonableTag> listSPCTag(@RequestParam(value = "id") Integer id){
|
||||
Optional<ScopePermissionContainer> spc = permissionService.findSPC(id);
|
||||
if(!spc.isPresent()) throw new NotFoundException(id.toString());
|
||||
|
||||
Set<JsonableTag> 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<ScopePermissionContainer> 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())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -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<Tag> 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<Tag> tagOptional = permissionService.findTag(name);
|
||||
public JsonableTag checkTag(@RequestParam(value = "id") Integer id){
|
||||
Optional<Tag> 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<JsonableTag> listTag(){
|
||||
Iterable<Tag> tagIterable = permissionService.findAllTag();
|
||||
Set<JsonableTag> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
public void deleteTag(@RequestParam(value = "id") Integer id){
|
||||
Optional<Tag> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
public JsonableTag updateTag(@RequestParam(value = "id") Integer id, @RequestBody JsonPatch patch){
|
||||
Optional<Tag> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
return new JsonableUserList(tag.get());
|
||||
public Set<JsonableUser> getUserTag(@RequestParam(value = "id") Integer id){
|
||||
Optional<Tag> tag = permissionService.findTag(id);
|
||||
if(!tag.isPresent()) throw new NotFoundException(id.toString());
|
||||
Set<JsonableUser> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
@ApiOperation("搜索单个标签所属用户集合信息")
|
||||
public Set<JsonableUser> setUserTag(@RequestParam(value = "id") Integer id,
|
||||
@RequestBody List<Integer> userIdList){
|
||||
Optional<Tag> tag = permissionService.findTag(id);
|
||||
if(!tag.isPresent()) throw new NotFoundException(id.toString());
|
||||
|
||||
Set<Integer> userSet = new HashSet<>(userList.getUsers());
|
||||
Set<Integer> userSet = new HashSet<>(userIdList);
|
||||
tag.get().setUsers(userService.findUsersById(userSet));
|
||||
|
||||
return new JsonableUserList(permissionService.save(tag.get()));
|
||||
Set<JsonableUser> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
Set<User> newUserSet = userService.findUsersById(new HashSet<>(userList.getUsers()));
|
||||
@ApiOperation("从单个标签所属用户集合中添加一个或多个用户")
|
||||
public Set<JsonableUser> addUserTag(@RequestParam(value = "id") Integer id,
|
||||
@RequestBody List<Integer> userIdList){
|
||||
Optional<Tag> tag = permissionService.findTag(id);
|
||||
if(!tag.isPresent()) throw new NotFoundException(id.toString());
|
||||
Set<User> newUserSet = userService.findUsersById(new HashSet<>(userIdList));
|
||||
|
||||
Set<User> userSet = tag.get().getUsers();
|
||||
|
||||
userSet.addAll(newUserSet);
|
||||
tag.get().setUsers(userSet);
|
||||
|
||||
return new JsonableUserList(permissionService.save(tag.get()));
|
||||
Set<JsonableUser> 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> tag = permissionService.findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
public Set<JsonableUser> deleteUserTag(@RequestParam Integer id,
|
||||
@RequestBody List<Integer> userIdList){
|
||||
Optional<Tag> tag = permissionService.findTag(id);
|
||||
if(!tag.isPresent()) throw new NotFoundException(id.toString());
|
||||
Set<User> userSet = tag.get().getUsers();
|
||||
Set<User> deleteUserSet = userService.findUsersById(new HashSet<>(userList.getUsers()));
|
||||
Set<User> deleteUserSet = userService.findUsersById(new HashSet<>(userIdList));
|
||||
|
||||
userSet.removeAll(deleteUserSet);
|
||||
tag.get().setUsers(userSet);
|
||||
|
||||
return new JsonableUserList(permissionService.save(tag.get()));
|
||||
Set<JsonableUser> 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<JsonableUser> getUserTags(@RequestParam(value = "name") List<String> names){
|
||||
Set<Tag> tagSet = permissionService.findTags(names);
|
||||
public Set<JsonableUser> getUserTags(@RequestParam(value = "id") List<Integer> ids){
|
||||
Set<Tag> tagSet = permissionService.findTags(ids);
|
||||
Set<User> userSet = new HashSet<>();
|
||||
Set<JsonableUser> 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<Tag> tagOptional = permissionService.findTag(name);
|
||||
if(!tagOptional.isPresent()) throw new NotFoundException(name);
|
||||
@ApiOperation("获取标签所含权力列表")
|
||||
public JsonablePCCList getPCCTag(@RequestParam(value = "id") Integer id){
|
||||
Optional<Tag> 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<Tag> tagOptional = permissionService.findTag(name);
|
||||
if(!tagOptional.isPresent()) throw new NotFoundException(name);
|
||||
public JsonablePCCList addPCCTag(@RequestParam(value = "id") Integer id, JsonablePCCList jsonablePCCList){
|
||||
Optional<Tag> tagOptional = permissionService.findTag(id);
|
||||
if(!tagOptional.isPresent()) throw new NotFoundException(id.toString());
|
||||
|
||||
Set<PermissionContainersCollection> pccs = tagOptional.get().getPermissionContainersCollections();
|
||||
pccs.addAll(permissionService.findPCCs(new HashSet<Integer>(jsonablePCCList.getPccIdList())));
|
||||
pccs.addAll(permissionService.findPCCs(new HashSet<>(jsonablePCCList.getPccIdList())));
|
||||
|
||||
tagOptional.get().setPermissionContainersCollections(pccs);
|
||||
|
@ -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> 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<JsonableUser> listUser(){
|
||||
Iterable<User> users = userService.findAll();
|
||||
Set<JsonableUser> 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<User> 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())));
|
||||
}
|
||||
}
|
@ -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;}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<ExamResult> examResults = new HashSet<>();
|
||||
|
||||
// 个人学分积
|
||||
@JoinColumn(nullable = true)
|
||||
private float accumulatedGPA;
|
||||
|
||||
|
||||
//除数为零exception待加
|
||||
public AccumulatedGPA(Set<ExamResult> initExamResults) {
|
||||
int totalProduct = 0, totalCredit = 0;
|
||||
for(ExamResult er : initExamResults){
|
||||
totalProduct += er.getCredit() * er.getScore();
|
||||
totalCredit += er.getCredit();
|
||||
}
|
||||
this.accumulatedGPA = totalProduct / totalCredit;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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<Award> awards = new HashSet<>();
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<ExamResult> examResults = new HashSet<>();
|
||||
|
||||
// 个人学分积
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = true)
|
||||
private AccumulatedGPA accumulatedGPA;
|
||||
|
||||
}
|
@ -23,33 +23,33 @@ public class UserActivity {
|
||||
|
||||
//主要负责的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> manageActivities;
|
||||
private List<Activity> mainResponsibleActs;
|
||||
|
||||
//次要负责的活动
|
||||
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> assistActivities;
|
||||
private List<Activity> secondaryResponsibleActs;
|
||||
|
||||
//可见的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> visibleActivities;
|
||||
private List<Activity> visibleActs;
|
||||
|
||||
//创建的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> createdActivities;
|
||||
private List<Activity> createdActs;
|
||||
|
||||
//可报名的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> signUpActivities;
|
||||
private List<Activity> signUpActs;
|
||||
|
||||
//已经参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatedActivities;
|
||||
private List<Activity> participatedActs;
|
||||
|
||||
//正在(将要)参与的活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> participatingActivities;
|
||||
private List<Activity> participatingActs;
|
||||
|
||||
//打卡签到活动
|
||||
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.DETACH, CascadeType.PERSIST}, fetch = FetchType.LAZY)
|
||||
private List<Activity> clockIn;
|
||||
private List<Activity> clockIns;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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<String> roles = new LinkedList<>();
|
||||
private Set<Function> functions = new HashSet<>();
|
||||
|
||||
// 是否启用
|
||||
@Column(nullable = false)
|
||||
|
@ -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;
|
||||
|
@ -6,7 +6,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 权限容器集合
|
||||
* 权限容器集合(多项权力)
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
|
@ -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<Activity, Integer> {
|
||||
public interface ActivityRepository extends JpaRepository<Activity, Integer> {
|
||||
|
||||
Optional<Activity> findByTitle(String Title);
|
||||
|
||||
|
@ -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, Integer> {
|
||||
|
||||
UserActivity findByUser(User user);
|
||||
|
||||
}
|
||||
|
@ -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<Function, Integer> {
|
||||
Optional<Function> findByName(String name);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.codesdream.ase.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class AchievementService {
|
||||
|
||||
}
|
@ -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<Activity> findActivityByTitle(String title) {
|
||||
return activityRepository.findByTitle(title);
|
||||
@ -25,6 +32,20 @@ public class ActivityService implements IActivityService {
|
||||
return activityRepository.findByCreator(creatorName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Activity> findActivityByType(User user, String type) {
|
||||
|
||||
List<Activity> activities = this.findAll(user);
|
||||
List<Activity> 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<Activity> findMainResponsibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getMainResponsibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findSecondaryResponsibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getSecondaryResponsibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findVisibleActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getVisibleActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findSignActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getSignUpActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findParticipatedActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getParticipatedActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findParticipatingActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getParticipatingActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findCreatedActs(User user) {
|
||||
|
||||
UserActivity userActivity = userActivityRepository.findByUser(user);
|
||||
List<Activity> acts = userActivity.getCreatedActs();
|
||||
Collections.sort(acts, new ActivityComparator());
|
||||
return acts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Activity> findAll(User user) {
|
||||
|
||||
List<Activity> activities = findCreatedActs(user);
|
||||
List<Activity> activities1 = findMainResponsibleActs(user);
|
||||
List<Activity> activities2 = findSecondaryResponsibleActs(user);
|
||||
List<Activity> activities3 = findParticipatingActs(user);
|
||||
List<Activity> activities4 = findParticipatedActs(user);
|
||||
List<Activity> activities5 = findParticipatingActs(user);
|
||||
List<Activity> activities6 = findSignActs(user);
|
||||
List<Activity> activities7 = findVisibleActs(user);
|
||||
Set<Activity> 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<Activity> res = new ArrayList<>(activitySet);
|
||||
Collections.sort(res, new ActivityComparator());
|
||||
return res;
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
class ActivityComparator implements Comparator<Activity> {
|
||||
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
@ -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<Activity> findActivityByCreator(String creatorName);
|
||||
|
||||
//通过活动类型查找活动
|
||||
List<Activity> 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<Activity> findMainResponsibleActs(User user);
|
||||
|
||||
//查询次要负责的活动
|
||||
List<Activity> findSecondaryResponsibleActs(User user);
|
||||
|
||||
//查询所有可见活动(即可报名活动、主次要负责的活动、参与过的活动等等之外却仍然可见的活动并集)
|
||||
List<Activity> findVisibleActs(User user);
|
||||
|
||||
//查找可报名的活动
|
||||
List<Activity> findSignActs(User user);
|
||||
|
||||
//查询参与过的活动
|
||||
List<Activity> findParticipatedActs(User user);
|
||||
|
||||
//查询将要参与的活动
|
||||
List<Activity> findParticipatingActs(User user);
|
||||
|
||||
//查询创建的活动
|
||||
List<Activity> findCreatedActs(User user);
|
||||
|
||||
//查询所有活动(权限内)
|
||||
List<Activity> findAll(User user);
|
||||
|
||||
}
|
||||
|
@ -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<Tag> findAllTag();
|
||||
|
||||
Set<Tag> findTags(List<String> names);
|
||||
Set<Tag> findTags(List<Integer> ids);
|
||||
|
||||
// 查找功能性权限容器
|
||||
Optional<FunctionalPermissionContainer> findFPC(String name);
|
||||
|
||||
Iterable<FunctionalPermissionContainer> findAllFPC();
|
||||
|
||||
// 查找范围性权限容器
|
||||
Optional<ScopePermissionContainer> findSPC(String name);
|
||||
|
||||
// 根据id查找功能性权限容器
|
||||
Optional<FunctionalPermissionContainer> findFPC(int id);
|
||||
|
||||
Iterable<ScopePermissionContainer> findALLSPC();
|
||||
|
||||
// 根据id查找范围性权限容器
|
||||
Optional<ScopePermissionContainer> findSPC(int id);
|
||||
|
||||
@ -48,6 +49,17 @@ public interface IPermissionService {
|
||||
|
||||
Optional<PermissionContainersCollection> findPCC(Integer id);
|
||||
|
||||
// 查找功能
|
||||
Optional<Function> findFunction(Integer id);
|
||||
|
||||
// 查找功能
|
||||
Optional<Function> findFunction(String name);
|
||||
|
||||
// 根据序号列表寻找功能
|
||||
Set<Function> findFunctions(Set<Integer> funcs);
|
||||
|
||||
Iterable<Function> findAllFunction();
|
||||
|
||||
// 获得范围性权限容器下的所有标签列表
|
||||
Collection<Tag> getTagsFromSPC(
|
||||
ScopePermissionContainer spc);
|
||||
@ -84,12 +96,12 @@ public interface IPermissionService {
|
||||
// 为功能性权限容器添加一个访问控制角色
|
||||
FunctionalPermissionContainer addRoleToFPC(
|
||||
FunctionalPermissionContainer fpc,
|
||||
String role);
|
||||
Function function);
|
||||
|
||||
// 为功能性权限容器添加多个访问控制角色
|
||||
FunctionalPermissionContainer addRolesToFPC(
|
||||
FunctionalPermissionContainer fpc,
|
||||
Collection<String> roles);
|
||||
Collection<Function> 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);
|
||||
|
@ -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<Tag> findTags(List<String> names) {
|
||||
public Set<Tag> findTags(List<Integer> ids) {
|
||||
Set<Tag> tagSet = new HashSet<>();
|
||||
for(String name : names){
|
||||
Optional<Tag> tag = findTag(name);
|
||||
if(!tag.isPresent()) throw new NotFoundException(name);
|
||||
for(Integer id : ids){
|
||||
Optional<Tag> 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<FunctionalPermissionContainer> findAllFPC() {
|
||||
return fpcRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ScopePermissionContainer> findSPC(String name) {
|
||||
return spcRepository.findByName(name);
|
||||
@ -100,6 +104,11 @@ public class PermissionService implements IPermissionService {
|
||||
return fpcRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<ScopePermissionContainer> findALLSPC() {
|
||||
return spcRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ScopePermissionContainer> findSPC(int id) {
|
||||
return spcRepository.findById(id);
|
||||
@ -126,6 +135,32 @@ public class PermissionService implements IPermissionService {
|
||||
return pccRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Function> findFunction(Integer id) {
|
||||
return functionRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Function> findFunction(String name) {
|
||||
return functionRepository.findByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Function> findFunctions(Set<Integer> funcs) {
|
||||
Set<Function> set = new HashSet<>();
|
||||
for(Integer id : funcs){
|
||||
Optional<Function> function = findFunction(id);
|
||||
if(!function.isPresent()) throw new NotFoundException(id.toString());
|
||||
set.add(function.get());
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Function> findAllFunction() {
|
||||
return functionRepository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Tag> 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<String> roles) {
|
||||
for(String role : roles){
|
||||
fpc = addRoleToFPC(fpc, role);
|
||||
public FunctionalPermissionContainer addRolesToFPC(FunctionalPermissionContainer fpc, Collection<Function> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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<? extends GrantedAuthority> getUserAuthorities(User user) {
|
||||
return userRolesListGenerator.generateRoles(user);
|
||||
return userFunctionsListGenerator.generateRoles(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user