diff --git a/src/main/java/cn/teammodel/controller/EvaluationController.java b/src/main/java/cn/teammodel/controller/EvaluationController.java index 2652c98..7a92f09 100644 --- a/src/main/java/cn/teammodel/controller/EvaluationController.java +++ b/src/main/java/cn/teammodel/controller/EvaluationController.java @@ -5,7 +5,7 @@ import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.GetEvaluateTreeDto; import cn.teammodel.model.dto.InsertNodeDto; import cn.teammodel.model.dto.UpdateNodeDto; -import cn.teammodel.model.entity.Appraise; +import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.service.EvaluationService; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.PostMapping; @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import javax.validation.Valid; /** * @author winter @@ -46,8 +47,7 @@ public class EvaluationController { } @PostMapping("deleteNode") @ApiOperation(value = "删除评价树的节点") - public R deleteNode(@RequestBody DeleteNodeDto deleteNodeDto) { - // todo: 注意删除子节点 + public R deleteNode(@Valid @RequestBody DeleteNodeDto deleteNodeDto) { Appraise appraise = evaluationService.deleteNode(deleteNodeDto); return R.success(appraise); } diff --git a/src/main/java/cn/teammodel/dao/EvaluationRepository.java b/src/main/java/cn/teammodel/dao/EvaluationRepository.java index aa28cd7..2fa4a4b 100644 --- a/src/main/java/cn/teammodel/dao/EvaluationRepository.java +++ b/src/main/java/cn/teammodel/dao/EvaluationRepository.java @@ -1,6 +1,6 @@ package cn.teammodel.dao; -import cn.teammodel.model.entity.Appraise; +import cn.teammodel.model.entity.appraise.Appraise; import com.azure.cosmos.models.PartitionKey; import com.azure.spring.data.cosmos.repository.CosmosRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java b/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java index bba209c..85de9a4 100644 --- a/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java +++ b/src/main/java/cn/teammodel/model/dto/DeleteNodeDto.java @@ -2,6 +2,8 @@ package cn.teammodel.model.dto; import lombok.Data; +import javax.validation.constraints.NotNull; + /** * @author winter * @create 2023-11-22 16:16 @@ -10,6 +12,6 @@ import lombok.Data; public class DeleteNodeDto { // 检索需要,但是有 bug String periodId; - // todo: 判断空 + @NotNull String id; } diff --git a/src/main/java/cn/teammodel/model/entity/AppraiseRecord.java b/src/main/java/cn/teammodel/model/entity/AppraiseRecord.java deleted file mode 100644 index c5b8afe..0000000 --- a/src/main/java/cn/teammodel/model/entity/AppraiseRecord.java +++ /dev/null @@ -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; - - -} diff --git a/src/main/java/cn/teammodel/model/entity/Appraise.java b/src/main/java/cn/teammodel/model/entity/appraise/Appraise.java similarity index 81% rename from src/main/java/cn/teammodel/model/entity/Appraise.java rename to src/main/java/cn/teammodel/model/entity/appraise/Appraise.java index 85ef5ba..e57452e 100644 --- a/src/main/java/cn/teammodel/model/entity/Appraise.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/Appraise.java @@ -1,5 +1,6 @@ -package cn.teammodel.model.entity; +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; @@ -16,7 +17,7 @@ import java.util.List; @Container(containerName = "School") @Data @JsonInclude(JsonInclude.Include.NON_NULL) -public class Appraise extends BaseItem{ +public class Appraise extends BaseItem { /** * 学校 Id */ diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java new file mode 100644 index 0000000..ff9cf9b --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecord.java @@ -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 nodes; + +} diff --git a/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java new file mode 100644 index 0000000..d852db4 --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseRecordItem.java @@ -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; +} diff --git a/src/main/java/cn/teammodel/model/entity/AppraiseTreeNode.java b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java similarity index 94% rename from src/main/java/cn/teammodel/model/entity/AppraiseTreeNode.java rename to src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java index b5e92e5..5927e9e 100644 --- a/src/main/java/cn/teammodel/model/entity/AppraiseTreeNode.java +++ b/src/main/java/cn/teammodel/model/entity/appraise/AppraiseTreeNode.java @@ -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; diff --git a/src/main/java/cn/teammodel/model/entity/school/Semester.java b/src/main/java/cn/teammodel/model/entity/school/Semester.java new file mode 100644 index 0000000..647cfd9 --- /dev/null +++ b/src/main/java/cn/teammodel/model/entity/school/Semester.java @@ -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; +} diff --git a/src/main/java/cn/teammodel/security/service/PermissionService.java b/src/main/java/cn/teammodel/security/service/PermissionService.java index 72c432e..79e900f 100644 --- a/src/main/java/cn/teammodel/security/service/PermissionService.java +++ b/src/main/java/cn/teammodel/security/service/PermissionService.java @@ -3,7 +3,7 @@ package cn.teammodel.security.service; import java.util.Set; import cn.teammodel.model.entity.User; -import cn.teammodel.security.utils.SecurityUtils; +import cn.teammodel.security.utils.SecurityUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; @@ -48,7 +48,7 @@ public class PermissionService { return false; } - Authentication authentication = SecurityUtils.getAuthentication(); + Authentication authentication = SecurityUtil.getAuthentication(); if (authentication == null || CollectionUtils.isEmpty(authentication.getAuthorities())) { return false; @@ -68,7 +68,7 @@ public class PermissionService { return false; } - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); if (loginUser == null || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -99,7 +99,7 @@ public class PermissionService { return false; } - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); if (loginUser == null || CollectionUtils.isEmpty(loginUser.getPermissions())) { return false; @@ -126,7 +126,7 @@ public class PermissionService if (StringUtils.isEmpty(role)) { return false; } - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); if (loginUser == null || CollectionUtils.isEmpty(loginUser.getRoles())) { return false; @@ -157,7 +157,7 @@ public class PermissionService { return false; } - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); if (loginUser == null || CollectionUtils.isEmpty(loginUser.getRoles())) { return false; diff --git a/src/main/java/cn/teammodel/security/utils/SecurityUtils.java b/src/main/java/cn/teammodel/security/utils/SecurityUtil.java similarity index 95% rename from src/main/java/cn/teammodel/security/utils/SecurityUtils.java rename to src/main/java/cn/teammodel/security/utils/SecurityUtil.java index b3dcf5f..448c60b 100644 --- a/src/main/java/cn/teammodel/security/utils/SecurityUtils.java +++ b/src/main/java/cn/teammodel/security/utils/SecurityUtil.java @@ -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; + } +} diff --git a/src/main/java/cn/teammodel/service/EvaluationService.java b/src/main/java/cn/teammodel/service/EvaluationService.java index 092ddb8..f74472c 100644 --- a/src/main/java/cn/teammodel/service/EvaluationService.java +++ b/src/main/java/cn/teammodel/service/EvaluationService.java @@ -4,8 +4,8 @@ import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.GetEvaluateTreeDto; import cn.teammodel.model.dto.InsertNodeDto; import cn.teammodel.model.dto.UpdateNodeDto; -import cn.teammodel.model.entity.Appraise; -import cn.teammodel.model.entity.AppraiseTreeNode; +import cn.teammodel.model.entity.appraise.Appraise; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import java.util.List; @@ -25,7 +25,6 @@ public interface EvaluationService { * 递归扁平化树 * @param trees: 树的列表 * @param nodes: 扁平化后的节点列表 - * @return: void * @author: winter * @date: 2023/11/21 16:40 * @description: diff --git a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java index 9bc96cc..d30bf37 100644 --- a/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java +++ b/src/main/java/cn/teammodel/service/impl/EvaluationServiceImpl.java @@ -9,10 +9,10 @@ import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.GetEvaluateTreeDto; import cn.teammodel.model.dto.InsertNodeDto; import cn.teammodel.model.dto.UpdateNodeDto; -import cn.teammodel.model.entity.Appraise; -import cn.teammodel.model.entity.AppraiseTreeNode; +import cn.teammodel.model.entity.appraise.Appraise; +import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.User; -import cn.teammodel.security.utils.SecurityUtils; +import cn.teammodel.security.utils.SecurityUtil; import cn.teammodel.service.EvaluationService; import com.azure.spring.data.cosmos.core.CosmosTemplate; import org.apache.commons.lang3.ObjectUtils; @@ -43,7 +43,7 @@ public class EvaluationServiceImpl implements EvaluationService { private Appraise findAppraise(String periodId) { // 默认学区为 default periodId = StringUtils.isEmpty(periodId) ? "default" : periodId; - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); String schoolId = loginUser.getSchoolId(); // 拿到要新增节点的原始数据 @@ -102,7 +102,7 @@ public class EvaluationServiceImpl implements EvaluationService { @Override public Appraise insertNode(InsertNodeDto insertNodeDto) { Appraise appraise = findAppraise(insertNodeDto.getPeriodId()); - User loginUser = SecurityUtils.getLoginUser(); + User loginUser = SecurityUtil.getLoginUser(); List originNodes = appraise.getNodes(); // 拷贝数据到新节点 diff --git a/src/main/java/cn/teammodel/utils/SchoolDateUtil.java b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java new file mode 100644 index 0000000..b2ac09e --- /dev/null +++ b/src/main/java/cn/teammodel/utils/SchoolDateUtil.java @@ -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 { + + /** + * 通过当前时间与学校的学期安排获取当前的学年 + * 学校学期: + *
+     * "semesters": [
+     *         {
+     *           "name": "下学期",
+     *           "start": 0,
+     *           "month": 3,
+     *           "day": 1,
+     *           "id": "2"
+     *         },
+     *         {
+     *           "name": "上学期",
+     *           "start": 1,
+     *           "month": 9,
+     *           "day": 1,
+     *           "id": "1"
+     *         }
+     *         
+    */
+    public static String getSemesterByNow(List semesters, LocalDate date) {
+        return "";
+    }
+
+}
diff --git a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java
index 6165015..565b174 100644
--- a/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java
+++ b/src/test/java/cn/teammodel/TeamModelExtensionApplicationTests.java
@@ -3,8 +3,8 @@ package cn.teammodel;
 import cn.teammodel.dao.EvaluationRepository;
 import cn.teammodel.dao.StudentRepository;
 import cn.teammodel.manager.DingAlertNotifier;
-import cn.teammodel.model.entity.Appraise;
-import cn.teammodel.model.entity.AppraiseTreeNode;
+import cn.teammodel.model.entity.appraise.Appraise;
+import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
 import cn.teammodel.service.EvaluationService;
 import cn.teammodel.service.impl.EvaluationServiceImpl;
 import com.azure.cosmos.models.PartitionKey;
@@ -87,4 +87,16 @@ class TeamModelExtensionApplicationTests {
         evaluationRepository.save(saved);
     }
 
+    @Test
+    public void testSave() {
+        Appraise appraise = new Appraise();
+        appraise.setId("1b69e5d1-5c22-453a-9f67-ed82e1075b62");
+        appraise.setCode("Appraise");
+        appraise.setPeriodId("default");
+        appraise.setSchoolId("test_modified");
+        //System.out.println(cosmosTemplate.insert(appraise, PK.of(PK.PK_APPRAISE)));
+        // 使用这个似乎必须要有 id,因为是依据 id 判断是否存在 (由 id 和 partitionKey 唯一定位)
+        cosmosTemplate.upsert(appraise);
+    }
+
 }
diff --git a/src/test/java/cn/teammodel/TestWithoutSpring.java b/src/test/java/cn/teammodel/TestWithoutSpring.java
index 1216416..afb9955 100644
--- a/src/test/java/cn/teammodel/TestWithoutSpring.java
+++ b/src/test/java/cn/teammodel/TestWithoutSpring.java
@@ -1,7 +1,7 @@
 package cn.teammodel;
 
-import cn.teammodel.model.entity.Appraise;
-import cn.teammodel.model.entity.AppraiseTreeNode;
+import cn.teammodel.model.entity.appraise.Appraise;
+import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
 import cn.teammodel.service.impl.EvaluationServiceImpl;
 import com.dingtalk.api.DefaultDingTalkClient;
 import com.dingtalk.api.DingTalkClient;