refactor: 重构实体类,按其归属分类

11111
winter 1 year ago
parent 38f5bf39ef
commit aa582361f8

@ -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<Appraise> deleteNode(@RequestBody DeleteNodeDto deleteNodeDto) {
// todo: 注意删除子节点
public R<Appraise> deleteNode(@Valid @RequestBody DeleteNodeDto deleteNodeDto) {
Appraise appraise = evaluationService.deleteNode(deleteNodeDto);
return R.success(appraise);
}

@ -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;

@ -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;
}

@ -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;
}

@ -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;

@ -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;
}

@ -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;

@ -13,7 +13,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
*
* @author winter
*/
public class SecurityUtils
public class SecurityUtil
{
/**
* ID

@ -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:

@ -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<AppraiseTreeNode> originNodes = appraise.getNodes();
// 拷贝数据到新节点

@ -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 "";
}
}

@ -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);
}
}

@ -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;

Loading…
Cancel
Save