feat: 新增以及完善部分数据结构

11111
winter 1 year ago
parent 8301cfd96d
commit 6dffd636ec

@ -11,6 +11,7 @@
## 数据表规则: ## 数据表规则:
> ID 没有特殊之指明则为 UUID
### 教育评价树 ### 教育评价树
分区键: `Appraise` , 表内 `schoolId` 区分学校, `periodId` 区分学区 分区键: `Appraise` , 表内 `schoolId` 区分学校, `periodId` 区分学区
@ -18,3 +19,4 @@
> 学生每学期所有的评价项都在一个项中,按学校进行分区 > 学生每学期所有的评价项都在一个项中,按学校进行分区
分区键: `AppraiseRecord-{学校id}` 分区键: `AppraiseRecord-{学校id}`
Id: `学年 + semesterId` -> eg: 2022.uuid

@ -1,10 +1,11 @@
package cn.teammodel.controller; package cn.teammodel.controller;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.Appraise.AppraiseVoteDto;
import cn.teammodel.model.dto.GetEvaluateTreeDto; import cn.teammodel.model.dto.Appraise.DeleteNodeDto;
import cn.teammodel.model.dto.InsertNodeDto; import cn.teammodel.model.dto.Appraise.GetEvaluateTreeDto;
import cn.teammodel.model.dto.UpdateNodeDto; import cn.teammodel.model.dto.Appraise.InsertNodeDto;
import cn.teammodel.model.dto.Appraise.UpdateNodeDto;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.service.EvaluationService; import cn.teammodel.service.EvaluationService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -22,7 +23,7 @@ import javax.validation.Valid;
*/ */
@RestController @RestController
@RequestMapping("/appraise") @RequestMapping("/appraise")
public class EvaluationController { public class AppraiseController {
@Resource @Resource
private EvaluationService evaluationService; private EvaluationService evaluationService;
@ -51,4 +52,13 @@ public class EvaluationController {
Appraise appraise = evaluationService.deleteNode(deleteNodeDto); Appraise appraise = evaluationService.deleteNode(deleteNodeDto);
return R.success(appraise); return R.success(appraise);
} }
@PostMapping("vote")
@ApiOperation(value = "给某个学生评价(投票)")
public R<String> vote(@Valid @RequestBody AppraiseVoteDto appraiseVoteDto) {
evaluationService.vote(appraiseVoteDto);
return R.success("评价成功");
}
} }

@ -1,7 +1,7 @@
package cn.teammodel.controller; package cn.teammodel.controller;
import cn.teammodel.common.R; import cn.teammodel.common.R;
import cn.teammodel.dao.EvaluationRepository; import cn.teammodel.dao.AppraiseRepository;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -15,7 +15,7 @@ import javax.annotation.Resource;
public class HelloController { public class HelloController {
@Resource @Resource
private EvaluationRepository evaluationRepository; private AppraiseRepository appraiseRepository;
@GetMapping("hello") @GetMapping("hello")
@PreAuthorize("@ss.hasRole('admin')") @PreAuthorize("@ss.hasRole('admin')")

@ -1,7 +1,6 @@
package cn.teammodel.dao; package cn.teammodel.dao;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
import com.azure.cosmos.models.PartitionKey;
import com.azure.spring.data.cosmos.repository.CosmosRepository; import com.azure.spring.data.cosmos.repository.CosmosRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -16,9 +15,6 @@ import org.springframework.stereotype.Repository;
* List<User> findByLastname(String lastname, Pageable pageable);<br/> * List<User> findByLastname(String lastname, Pageable pageable);<br/>
*/ */
@Repository @Repository
public interface EvaluationRepository extends CosmosRepository<Appraise, String> { public interface AppraiseRecordRepository extends CosmosRepository<Appraise, String> {
Appraise findBySchoolId(String schoolId, PartitionKey partitionKey);
Appraise findAppraiseBySchoolIdAndPeriodIdAndCode(String schoolId, String periodId, String code);
} }

@ -0,0 +1,30 @@
package cn.teammodel.dao;
import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
import com.azure.cosmos.models.PartitionKey;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author winter
* @create 2023-11-20 14:39 <br/>
* Page<User> findByLastname(String lastname, Pageable pageable); <br/>
* Slice<User> findByLastname(String lastname, Pageable pageable);<br/>
* Window<User> findTop10ByLastname(String lastname, ScrollPosition position, Sort sort);<br/>
* List<User> findByLastname(String lastname, Sort sort);<br/>
* List<User> findByLastname(String lastname, Sort sort, Limit limit);<br/>
* List<User> findByLastname(String lastname, Pageable pageable);<br/>
*/
@Repository
public interface AppraiseRepository extends CosmosRepository<Appraise, String> {
Appraise findBySchoolId(String schoolId, PartitionKey partitionKey);
Appraise findAppraiseBySchoolIdAndPeriodIdAndCode(String schoolId, String periodId, String code);
@Query("SELECT value n FROM School AS s join n in s.nodes where s.schoolId = @schoolId and s.periodId = @periodId and s.code = @code and n.id = @nodeId")
List<AppraiseTreeNode> findNodeById(@Param("schoolId") String schoolId, @Param("periodId") String periodId, @Param("code") String code, @Param("nodeId") String nodeId);
}

@ -0,0 +1,15 @@
package cn.teammodel.dao;
import cn.teammodel.model.entity.school.School;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import org.springframework.stereotype.Repository;
/**
* @author winter
* @create 2023-11-28 17:39
*/
@Repository
public interface SchoolRepository extends CosmosRepository<School, String> {
//@Query("select c.period.semesters from c where c.id = @id and c.code = @code")
//List<School.Semester> findSemestersById(@Param("id") String id, @Param("code") String code);
}

@ -0,0 +1,21 @@
package cn.teammodel.model.dto.Appraise;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author winter
* @create 2023-11-28 16:16
*/
@Data
public class AppraiseVoteDto {
@NotNull
private String studentId;
@NotNull // todo: semester 还是 period
private String semesterId;
@NotNull
private String appraiseId;
// 校区 id
private String periodId;
}

@ -1,4 +1,4 @@
package cn.teammodel.model.dto; package cn.teammodel.model.dto.Appraise;
import lombok.Data; import lombok.Data;

@ -1,4 +1,4 @@
package cn.teammodel.model.dto; package cn.teammodel.model.dto.Appraise;
import lombok.Data; import lombok.Data;

@ -1,4 +1,4 @@
package cn.teammodel.model.dto; package cn.teammodel.model.dto.Appraise;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;

@ -1,4 +1,4 @@
package cn.teammodel.model.dto; package cn.teammodel.model.dto.Appraise;
import lombok.Data; import lombok.Data;

@ -9,7 +9,8 @@ import lombok.EqualsAndHashCode;
import java.util.List; import java.util.List;
/** /**
* (+ = ) * (+ = ) <br/>
* : Id + semesterId
* @author winter * @author winter
* @create 2023-11-27 11:02 * @create 2023-11-27 11:02
*/ */
@ -23,6 +24,14 @@ public class AppraiseRecord extends BaseItem {
*/ */
private String periodId; private String periodId;
private String studentId; private String studentId;
/**
*
*/
private Integer praiseCount;
/**
*
*/
private Integer score;
private List<AppraiseRecordItem> nodes; private List<AppraiseRecordItem> nodes;
} }

@ -1,8 +1,11 @@
package cn.teammodel.model.entity.appraise; package cn.teammodel.model.entity.appraise;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime;
/** /**
* *
* @author winter * @author winter
@ -14,4 +17,8 @@ import lombok.Data;
public class AppraiseRecordItem { public class AppraiseRecordItem {
private String id; private String id;
private String appraiseNodeId; private String appraiseNodeId;
String creator;
String creatorId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createTime;
} }

@ -0,0 +1,94 @@
package cn.teammodel.model.entity.school;
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;
@EqualsAndHashCode(callSuper = true)
@Container(containerName = "School")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class School extends BaseItem {
/**
*
*/
private String name;
private String schoolCode;
private String region;
private String province;
private String city;
private String dist;
private String areaId;
private Integer size;
private Integer tsize;
private String address;
private String picture;
private TimeZone timeZone;
private Integer type;
private String standard;
private Integer hpappraise;
private Integer scale;
private Edition edition;
private long createTime;
private boolean isinit;
private boolean openLessonRecord;
//private Module[] modules;
private String pk;
private List<Period> period;
private List<Campus> campuses;
@Data
public static class Period {
private List<Major> majors;
private List<String> grades;
private List<Subject> subjects;
private List<Semester> semesters;
private String name;
}
@Data
public static class Major {
private String id;
private String name;
}
@Data
public static class Subject {
private String id;
private String name;
private Integer type;
private String bindId;
}
@Data
public static class Semester {
private String name;
private Integer start;
private Integer month;
private Integer day;
private String id;
}
@Data
public static class Campus {
private String name;
private String id;
}
@Data
public static class TimeZone {
private String label;
private String value;
}
@Data
public static class Edition {
private Integer current;
private Integer record;
private String scaleVersion;
}
}

@ -1,9 +1,6 @@
package cn.teammodel.service; package cn.teammodel.service;
import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.Appraise.*;
import cn.teammodel.model.dto.GetEvaluateTreeDto;
import cn.teammodel.model.dto.InsertNodeDto;
import cn.teammodel.model.dto.UpdateNodeDto;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
@ -45,4 +42,9 @@ public interface EvaluationService {
* , * ,
*/ */
Appraise deleteNode(DeleteNodeDto deleteNodeDto); Appraise deleteNode(DeleteNodeDto deleteNodeDto);
/**
*
*/
void vote(AppraiseVoteDto appraiseVoteDto);
} }

@ -4,11 +4,8 @@ import cn.hutool.core.lang.UUID;
import cn.teammodel.common.ErrorCode; import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.dao.EvaluationRepository; import cn.teammodel.dao.AppraiseRepository;
import cn.teammodel.model.dto.DeleteNodeDto; import cn.teammodel.model.dto.Appraise.*;
import cn.teammodel.model.dto.GetEvaluateTreeDto;
import cn.teammodel.model.dto.InsertNodeDto;
import cn.teammodel.model.dto.UpdateNodeDto;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
import cn.teammodel.model.entity.appraise.AppraiseTreeNode; import cn.teammodel.model.entity.appraise.AppraiseTreeNode;
import cn.teammodel.model.entity.User; import cn.teammodel.model.entity.User;
@ -34,7 +31,7 @@ public class EvaluationServiceImpl implements EvaluationService {
@Resource @Resource
CosmosTemplate cosmosTemplate; CosmosTemplate cosmosTemplate;
@Resource @Resource
private EvaluationRepository evaluationRepository; private AppraiseRepository appraiseRepository;
/** /**
* evaluation : , <br/> * evaluation : , <br/>
@ -47,7 +44,7 @@ public class EvaluationServiceImpl implements EvaluationService {
String schoolId = loginUser.getSchoolId(); String schoolId = loginUser.getSchoolId();
// 拿到要新增节点的原始数据 // 拿到要新增节点的原始数据
Appraise appraise = evaluationRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE); Appraise appraise = appraiseRepository.findAppraiseBySchoolIdAndPeriodIdAndCode(schoolId, periodId, PK.PK_APPRAISE);
if (appraise == null) { if (appraise == null) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在"); throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "学校评价数据不存在");
} }
@ -124,7 +121,7 @@ public class EvaluationServiceImpl implements EvaluationService {
newNode.setCreateTime(LocalDateTime.now()); newNode.setCreateTime(LocalDateTime.now());
originNodes.add(newNode); originNodes.add(newNode);
return buildTree(evaluationRepository.save(appraise)); return buildTree(appraiseRepository.save(appraise));
} }
@Override @Override
@ -145,7 +142,7 @@ public class EvaluationServiceImpl implements EvaluationService {
updateNode.setPraise(updateNodeDto.isPraise()); updateNode.setPraise(updateNodeDto.isPraise());
// todo: 为新节点赋值必须参数 (id, creator), 可不可以添加默认值 order ? // todo: 为新节点赋值必须参数 (id, creator), 可不可以添加默认值 order ?
return buildTree(evaluationRepository.save(appraise)); return buildTree(appraiseRepository.save(appraise));
} }
@Override @Override
@ -166,7 +163,24 @@ public class EvaluationServiceImpl implements EvaluationService {
} }
nodes.removeAll(nodesToDelete); nodes.removeAll(nodesToDelete);
return buildTree(evaluationRepository.save(appraise)); return buildTree(appraiseRepository.save(appraise));
}
@Override
public void vote(AppraiseVoteDto appraiseVoteDto) {
String studentId = appraiseVoteDto.getStudentId();
String appraiseId = appraiseVoteDto.getAppraiseId();
String periodId = appraiseVoteDto.getPeriodId();
periodId = StringUtils.isEmpty(periodId) ? "default" : periodId;
User loginUser = SecurityUtil.getLoginUser();
List<AppraiseTreeNode> nodes = appraiseRepository.findNodeById(loginUser.getSchoolId(), periodId, PK.PK_APPRAISE, appraiseId);
if (ObjectUtils.isEmpty(nodes) || nodes.size() > 1) {
throw new ServiceException(ErrorCode.PARAMS_ERROR.getCode(), "找不到该评价项");
}
AppraiseTreeNode node = nodes.get(0);
// 组装 AppraiseRecord
} }
/** /**

@ -1,6 +1,7 @@
package cn.teammodel; package cn.teammodel;
import cn.teammodel.dao.EvaluationRepository; import cn.teammodel.dao.AppraiseRepository;
import cn.teammodel.dao.SchoolRepository;
import cn.teammodel.dao.StudentRepository; import cn.teammodel.dao.StudentRepository;
import cn.teammodel.manager.DingAlertNotifier; import cn.teammodel.manager.DingAlertNotifier;
import cn.teammodel.model.entity.appraise.Appraise; import cn.teammodel.model.entity.appraise.Appraise;
@ -29,7 +30,9 @@ class TeamModelExtensionApplicationTests {
@Autowired @Autowired
StudentRepository studentRepository; StudentRepository studentRepository;
@Autowired @Autowired
private EvaluationRepository evaluationRepository; SchoolRepository schoolRepository;
@Autowired
private AppraiseRepository appraiseRepository;
@Test @Test
void contextLoads() { void contextLoads() {
@ -74,17 +77,21 @@ class TeamModelExtensionApplicationTests {
@Test @Test
public void testSelect() { public void testSelect() {
Appraise saved = evaluationRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); //Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
EvaluationService service = new EvaluationServiceImpl(); //EvaluationService service = new EvaluationServiceImpl();
//System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty()); //System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty());
//List<AppraiseTreeNode> nodeById = appraiseRepository.findNodeById("habook", "default", "Appraise", "43e23f03-288c-4012-b5f3-4d5c022739a2");
//System.out.println(nodeById);
System.out.println(schoolRepository.findSemestersById("hbcn", "Base"));
} }
@Test @Test
public void testUpdate() { public void testUpdate() {
//EvaluationTree saved = evaluationTreeRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); //EvaluationTree saved = evaluationTreeRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
Appraise saved = evaluationRepository.findBySchoolId("hbcn", new PartitionKey("evaluation")); Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
EvaluationService service = new EvaluationServiceImpl(); EvaluationService service = new EvaluationServiceImpl();
//System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty()); //System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty());
evaluationRepository.save(saved); appraiseRepository.save(saved);
} }
@Test @Test
@ -99,4 +106,6 @@ class TeamModelExtensionApplicationTests {
cosmosTemplate.upsert(appraise); cosmosTemplate.upsert(appraise);
} }
} }

Loading…
Cancel
Save