Skip to content

Commit

Permalink
Merge branch 'main' into dev-lifeng
Browse files Browse the repository at this point in the history
  • Loading branch information
maplestarplayl committed Dec 7, 2023
2 parents 25b9731 + 11cf820 commit 9db8f09
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 144 deletions.
Binary file modified lib/SastLink-Java-SDK-0.0.1.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/sast/evento/common/enums/ErrorEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum ErrorEnum {
EVENT_NOT_EXIST(1008,"event not exist"),
/* 登录异常 */
LOGIN_ERROR(1009,"login failed"),
LOGIN_EXPIRE(1010,"login expire"),
LOGIN_EXPIRE(1010,"login expired"),
NOT_REGISTER(1011,"user info not exist please register first"),

/* 其他服务错误 */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package sast.evento.common.enums;
package sast.evento.common.typehandler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import sast.evento.common.enums.EventState;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sast.evento.common.typehandler;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import sast.sastlink.sdk.enums.Organization;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class OrganizationTypeHandler extends BaseTypeHandler<String> {

@Override
public void setNonNullParameter(PreparedStatement preparedStatement, int i, String s, JdbcType jdbcType) throws SQLException {
Organization org = Organization.getByStr(s);
Integer res = org == null ? null : org.getId();
preparedStatement.setObject(i, res, 4);
}

@Override
public String getNullableResult(ResultSet resultSet, String s) throws SQLException {
Object o = resultSet.getObject(s);
return o == null ? null : Organization.getById((Integer) o).getOrg();
}

@Override
public String getNullableResult(ResultSet resultSet, int i) throws SQLException {
Object o = resultSet.getObject(i);
return o == null ? null : Organization.getById((Integer) o).getOrg();
}

@Override
public String getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
Object o = callableStatement.getObject(i);
return o == null ? null : Organization.getById((Integer) o).getOrg();
}
}
9 changes: 4 additions & 5 deletions src/main/java/sast/evento/config/SastLinkServiceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import sast.sastlink.sdk.service.SastLinkService;
import sast.sastlink.sdk.service.impl.RestTemplateSastLinkService;
import sast.sastlink.sdk.test.RestTemplateTestSastLinkService;

/**
* @projectName: sast-evento-backend
Expand Down Expand Up @@ -41,7 +40,7 @@ public class SastLinkServiceConfig {

@Bean
public SastLinkService sastLinkService() {
return RestTemplateSastLinkService.Builder()
return RestTemplateTestSastLinkService.builder()
.setRedirectUri(redirectUri)
.setClientId(clientId)
.setClientSecret(clientSecret)
Expand All @@ -52,7 +51,7 @@ public SastLinkService sastLinkService() {

@Bean
public SastLinkService sastLinkServiceWeb() {
return RestTemplateSastLinkService.Builder()
return RestTemplateTestSastLinkService.builder()
.setRedirectUri(redirectUri_web)
.setClientId(clientId_web)
.setClientSecret(clientSecret_web)
Expand All @@ -63,7 +62,7 @@ public SastLinkService sastLinkServiceWeb() {

@Bean
public SastLinkService sastLinkServiceMobileDev() {
return RestTemplateSastLinkService.Builder()
return RestTemplateTestSastLinkService.builder()
.setRedirectUri(redirectUri_mobile_dev)
.setClientId(clientId_mobile_dev)
.setClientSecret(clientSecret_mobile_dev)
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/sast/evento/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ public String loginByTicket(@RequestParam String ticket){
return "ok";
}

/**
* 获取使用密码登录时加密使用的RSA公钥
* @param studentId 学号
* @return Map
*/
@OperateLog("获取key")
@GetMapping("/login/key")
@DefaultActionState(ActionState.PUBLIC)
public Map<String, Object> getKey(@RequestParam String studentId){
return loginService.getKeyForLogin(studentId);
}

/**
* 给已经使用第三方登陆的用户绑定密码或者修改密码
* @param password 密码
Expand Down
23 changes: 15 additions & 8 deletions src/main/java/sast/evento/controller/PermissionController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sast.evento.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import sast.evento.annotation.DefaultActionState;
Expand All @@ -17,6 +18,7 @@
import sast.evento.service.UserService;

import java.util.List;
import java.util.Map;


@RestController
Expand Down Expand Up @@ -69,8 +71,10 @@ public String deleteAdmin(@RequestParam(required = false) String userId,
@OperateLog("获取后台管理者列表")
@DefaultActionState(value = ActionState.ADMIN, group = "permission")
@GetMapping("/admins")
public List<User> getAdmins() {
return permissionService.getAdmins();
public Map<String, Object> getAdmins(@RequestParam(required = false,defaultValue = "1")Integer current,
@RequestParam(required = false,defaultValue = "10")Integer size) {
Page<User> userPage = permissionService.getAdmins(current, size);
return Map.of("users", userPage.getRecords(), "total", userPage.getTotal());
}

@OperateLog("添加后台管理者")
Expand Down Expand Up @@ -176,9 +180,12 @@ public String addManager(@RequestParam List<String> methodNames,
@OperateLog("获取活动管理者列表")
@DefaultActionState(ActionState.LOGIN)
@GetMapping(value = "/event/managers")
public List<User> getManagers(@RequestParam @EventId Integer eventId) {
public Map<String, Object> getManagers(@RequestParam @EventId Integer eventId,
@RequestParam(required = false,defaultValue = "1")Integer current,
@RequestParam(required = false,defaultValue = "10")Integer size) {
checkEventId(eventId);
return permissionService.getManagers(eventId);
Page<User> userPage = permissionService.getManagers(eventId, current, size);
return Map.of("users", userPage.getRecords(), "total", userPage.getTotal());
}

@OperateLog("获取用户具有哪些活动的管理权限")
Expand Down Expand Up @@ -207,13 +214,13 @@ public List<String> getSelfManagerPermission(@RequestParam @EventId Integer even
return permissionService.getUserManagerPermissAsList(eventId, user.getId());
}

private String checkUser(String userId,String studentId) {
private String checkUser(String userId, String studentId) {
if (userId != null && !userId.isEmpty()) {
return userId;
return userId;
}
if(studentId != null && !studentId.isEmpty()){
if (studentId != null && !studentId.isEmpty()) {
User user = userService.getUserByStudentId(studentId);
if(user.getId() == null){
if(user == null || user.getId() == null){
throw new LocalRunTimeException(ErrorEnum.STUDENT_NOT_BIND);
}
return user.getId();
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/sast/evento/controller/TestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
import sast.evento.model.Action;
import sast.evento.model.UserModel;
import sast.evento.service.PermissionService;
import sast.sastlink.sdk.service.SastLinkService;
import sast.sastlink.sdk.test.RestTemplateTestSastLinkService;
import sast.sastlink.sdk.test.data.Token;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -39,7 +38,11 @@ public class TestController {
private String method;

@Resource
private SastLinkService sastLinkService;
private RestTemplateTestSastLinkService sastLinkService;
@Resource
private RestTemplateTestSastLinkService sastLinkServiceWeb;
@Resource
private RestTemplateTestSastLinkService sastLinkServiceMobileDev;
@Resource
private PermissionService permissionService;
@Resource
Expand All @@ -51,14 +54,21 @@ public class TestController {
@OperateLog("link登录")
@DefaultActionState(ActionState.PUBLIC)
@PostMapping("/linklogin")
public String linkLogin(@RequestParam String email,
public String linkLogin(@RequestParam Integer type,
@RequestParam String email,
@RequestParam String password) {
RestTemplateTestSastLinkService service = switch (type) {
case 0 -> sastLinkService;
case 1 -> sastLinkServiceWeb;
case 2 -> sastLinkServiceMobileDev;
default -> throw new LocalRunTimeException(ErrorEnum.COMMON_ERROR, "error link client type value: " + type);
};
if (challenge.isEmpty() || method.isEmpty()) {
throw new LocalRunTimeException(ErrorEnum.COMMON_ERROR);
}
try {
String token = sastLinkService.login(email, password);
return sastLinkService.authorize(token, challenge, method);
Token token = service.login(email, password);
return service.authorize(token.getLoginToken(), challenge, method);
} catch (Exception e) {
throw new LocalRunTimeException(ErrorEnum.SAST_LINK_SERVICE_ERROR, e.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sast/evento/entitiy/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.Data;
import lombok.NoArgsConstructor;
import sast.evento.common.enums.EventState;
import sast.evento.common.enums.EventStateTypeHandler;
import sast.evento.common.typehandler.EventStateTypeHandler;
import sast.evento.model.EventModel;

import java.util.Date;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/sast/evento/entitiy/User.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package sast.evento.entitiy;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.handlers.GsonTypeHandler;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.servlet.annotation.HandlesTypes;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import sast.evento.utils.JsonUtil;
import sast.sastlink.sdk.enums.Organization;
import sast.evento.common.typehandler.OrganizationTypeHandler;
import sast.sastlink.sdk.model.UserInfo;

import java.util.List;
Expand All @@ -23,9 +23,9 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "user",autoResultMap = true)
@TableName(value = "user", autoResultMap = true)
public class User {
@TableId(value = "id",type = IdType.ASSIGN_ID)
@TableId(value = "id", type = IdType.ASSIGN_ID)
private String id;
@JsonIgnore
private String unionId;//openId属于隐私信息,不得随意当成返回
Expand All @@ -43,22 +43,22 @@ public class User {
private String avatar;

@JsonAlias("org")
@TableField("org")
private Integer organization; //这里使用sast-link SDK 与sast-link遵守相同规范
@TableField(value = "org", typeHandler = OrganizationTypeHandler.class)
private String organization; //这里使用sast-link SDK 与sast-link遵守相同规范

@JsonAlias("bio")
@TableField("bio")
private String biography;
@TableField(value = "link",typeHandler = JacksonTypeHandler.class)
@TableField(value = "link", typeHandler = JacksonTypeHandler.class)
private List<String> link;

public User(UserInfo userInfo){
public User(UserInfo userInfo) {
this.linkId = userInfo.getUserId();
this.studentId = userInfo.getUserId();
this.email = userInfo.getEmail();
this.nickname = userInfo.getNickname();
this.avatar = userInfo.getAvatar();
this.organization = (userInfo.getOrg() == null||userInfo.getOrg().isEmpty())?null: Organization.valueOf(userInfo.getOrg()).getId();
this.organization = userInfo.getOrg();
this.biography = userInfo.getBio();
this.link = userInfo.getLink();
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/sast/evento/mapper/PermissionMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,5 @@
@Mapper
@Repository
public interface PermissionMapper extends BaseMapper<Permission> {
List<User> getUserHasPermissionByEvent(Integer eventId);

List<Integer> getManageEvent(String userId);

void updatePermission(@Param("user_id") String userId,
@Param("event_id") Integer eventId,
@Param("all_method_name") String allMethodName,
@Param("update_time") Date updateTime);

}
2 changes: 0 additions & 2 deletions src/main/java/sast/evento/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public interface LoginService {

Map<String, Object> bindStudentOnWechat(String userId, String studentId, Boolean force);

Map<String, Object> getKeyForLogin(String studentId);

Map<String, Object> getLoginTicket(String studentId, String ticket);

void checkTicket(String studentId, String ticket);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/sast/evento/service/PermissionService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sast.evento.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import sast.evento.entitiy.User;
import sast.evento.model.Action;
import sast.evento.model.treeDataNodeDTO.TreeDataNode;
Expand All @@ -20,7 +21,7 @@ public interface PermissionService {

void deleteAdmin(String userId);

List<User> getAdmins();
Page<User> getAdmins(Integer num, Integer size);

void updateAdminPermission(List<String> methodNames, String userId);

Expand All @@ -32,7 +33,7 @@ public interface PermissionService {

void deleteManager(Integer eventId, String userId);

List<User> getManagers(Integer eventId);
Page<User> getManagers(Integer eventId,Integer num,Integer size);

void updateManagerPermission(Integer eventId, List<String> methodNames, String userId);

Expand Down
Loading

0 comments on commit 9db8f09

Please sign in to comment.