parent
38f5bf39ef
commit
aa582361f8
@ -1,36 +0,0 @@
|
||||
package cn.teammodel.model.entity;
|
||||
|
||||
import com.azure.spring.data.cosmos.core.mapping.Container;
|
||||
import com.azure.spring.data.cosmos.core.mapping.GeneratedValue;
|
||||
import com.azure.spring.data.cosmos.core.mapping.PartitionKey;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* @author winter
|
||||
* @create 2023-11-27 11:02
|
||||
*/
|
||||
@Container(containerName = "Student")
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AppraiseRecord {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private String id;
|
||||
/**
|
||||
* 分区键: AppraiseRecord-{schoolId}
|
||||
*/
|
||||
@PartitionKey
|
||||
private String code;
|
||||
/**
|
||||
* 学校 Id
|
||||
*/
|
||||
private String schoolId;
|
||||
/**
|
||||
* 学段 id
|
||||
*/
|
||||
private String periodId;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package cn.teammodel.model.entity.appraise;
|
||||
|
||||
import cn.teammodel.model.entity.BaseItem;
|
||||
import com.azure.spring.data.cosmos.core.mapping.Container;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 一个学生在一个学年(学校+学年 = 分区键)的所有评价记录
|
||||
* @author winter
|
||||
* @create 2023-11-27 11:02
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Container(containerName = "Student")
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AppraiseRecord extends BaseItem {
|
||||
/**
|
||||
* 学段 id
|
||||
*/
|
||||
private String periodId;
|
||||
private String studentId;
|
||||
private List<AppraiseRecordItem> nodes;
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cn.teammodel.model.entity.appraise;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 评价项
|
||||
* @author winter
|
||||
* @create 2023-11-27 16:47
|
||||
*/
|
||||
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class AppraiseRecordItem {
|
||||
private String id;
|
||||
private String appraiseNodeId;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.teammodel.model.entity;
|
||||
package cn.teammodel.model.entity.appraise;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
@ -0,0 +1,26 @@
|
||||
package cn.teammodel.model.entity.school;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 学期(标记了学期的开始与结束)
|
||||
* @author winter
|
||||
* @create 2023-11-28 10:39
|
||||
*/
|
||||
@Data
|
||||
public class Semester {
|
||||
private String id;
|
||||
private String name;
|
||||
/**
|
||||
* start = 1 则代表一年开始的学期
|
||||
*/
|
||||
private Integer start;
|
||||
/**
|
||||
* 开始的月份
|
||||
*/
|
||||
private Integer month;
|
||||
/**
|
||||
* 开始的日
|
||||
*/
|
||||
private Integer day;
|
||||
}
|
@ -1,107 +1,107 @@
|
||||
package cn.teammodel.security.utils;
|
||||
|
||||
import cn.teammodel.config.exception.ServiceException;
|
||||
import cn.teammodel.model.entity.User;
|
||||
import cn.teammodel.model.entity.TmdUserDetail;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* 安全服务工具类
|
||||
*
|
||||
* @author winter
|
||||
*/
|
||||
public class SecurityUtils
|
||||
{
|
||||
/**
|
||||
* 用户ID
|
||||
**/
|
||||
public static String getUserId()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginUser().getId();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException( HttpStatus.UNAUTHORIZED.value(), "获取用户ID异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户账户
|
||||
**/
|
||||
public static String getUsername()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginUser().getName();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException(HttpStatus.UNAUTHORIZED.value(), "获取用户账户异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
**/
|
||||
public static User getLoginUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((TmdUserDetail) getAuthentication().getPrincipal()).getUser();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException(HttpStatus.UNAUTHORIZED.value(), "获取用户信息异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Authentication
|
||||
*/
|
||||
public static Authentication getAuthentication()
|
||||
{
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成BCryptPasswordEncoder密码
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 加密字符串
|
||||
*/
|
||||
public static String encryptPassword(String password)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.encode(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断密码是否相同
|
||||
*
|
||||
* @param rawPassword 真实密码
|
||||
* @param encodedPassword 加密后字符
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.matches(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
||||
package cn.teammodel.security.utils;
|
||||
|
||||
import cn.teammodel.config.exception.ServiceException;
|
||||
import cn.teammodel.model.entity.User;
|
||||
import cn.teammodel.model.entity.TmdUserDetail;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* 安全服务工具类
|
||||
*
|
||||
* @author winter
|
||||
*/
|
||||
public class SecurityUtil
|
||||
{
|
||||
/**
|
||||
* 用户ID
|
||||
**/
|
||||
public static String getUserId()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginUser().getId();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException( HttpStatus.UNAUTHORIZED.value(), "获取用户ID异常");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户账户
|
||||
**/
|
||||
public static String getUsername()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginUser().getName();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException(HttpStatus.UNAUTHORIZED.value(), "获取用户账户异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
**/
|
||||
public static User getLoginUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
return ((TmdUserDetail) getAuthentication().getPrincipal()).getUser();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException(HttpStatus.UNAUTHORIZED.value(), "获取用户信息异常");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Authentication
|
||||
*/
|
||||
public static Authentication getAuthentication()
|
||||
{
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成BCryptPasswordEncoder密码
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 加密字符串
|
||||
*/
|
||||
public static String encryptPassword(String password)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.encode(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断密码是否相同
|
||||
*
|
||||
* @param rawPassword 真实密码
|
||||
* @param encodedPassword 加密后字符
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.matches(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为管理员
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean isAdmin(Long userId)
|
||||
{
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package cn.teammodel.utils;
|
||||
|
||||
import cn.teammodel.model.entity.school.Semester;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 学校中年级,学年,日期相关的工具类
|
||||
* @author winter
|
||||
* @create 2023-11-28 10:15
|
||||
*/
|
||||
public class SchoolDateUtil {
|
||||
|
||||
/**
|
||||
* 通过当前时间与学校的学期安排获取当前的学年
|
||||
* 学校学期:
|
||||
* <pre>
|
||||
* "semesters": [
|
||||
* {
|
||||
* "name": "下学期",
|
||||
* "start": 0,
|
||||
* "month": 3,
|
||||
* "day": 1,
|
||||
* "id": "2"
|
||||
* },
|
||||
* {
|
||||
* "name": "上学期",
|
||||
* "start": 1,
|
||||
* "month": 9,
|
||||
* "day": 1,
|
||||
* "id": "1"
|
||||
* }
|
||||
* <pre/>
|
||||
*/
|
||||
public static String getSemesterByNow(List<Semester> semesters, LocalDate date) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue