|
|
|
package cn.teammodel;
|
|
|
|
|
|
|
|
import cn.teammodel.dao.AppraiseRecordRepository;
|
|
|
|
import cn.teammodel.dao.AppraiseRepository;
|
|
|
|
import cn.teammodel.dao.SchoolRepository;
|
|
|
|
import cn.teammodel.dao.StudentRepository;
|
|
|
|
import cn.teammodel.manager.DingAlertNotifier;
|
|
|
|
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;
|
|
|
|
import com.azure.spring.data.cosmos.core.CosmosTemplate;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
@SpringBootTest
|
|
|
|
class TeamModelExtensionApplicationTests {
|
|
|
|
@Resource
|
|
|
|
CosmosTemplate cosmosTemplate;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private DingAlertNotifier notifier;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
AppraiseRecordRepository appraiseRecordRepository;
|
|
|
|
@Autowired
|
|
|
|
StudentRepository studentRepository;
|
|
|
|
@Autowired
|
|
|
|
SchoolRepository schoolRepository;
|
|
|
|
@Autowired
|
|
|
|
private AppraiseRepository appraiseRepository;
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void contextLoads() {
|
|
|
|
notifier.send("告警: 测试消息推送封装模块");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCrud() {
|
|
|
|
Appraise appraise = new Appraise();
|
|
|
|
appraise.setCode("evaluation");
|
|
|
|
appraise.setPeriodId("default");
|
|
|
|
List<AppraiseTreeNode> nodes = new ArrayList<>();
|
|
|
|
|
|
|
|
// 1
|
|
|
|
String rootId = UUID.randomUUID().toString();
|
|
|
|
AppraiseTreeNode node = new AppraiseTreeNode();
|
|
|
|
node.setId(rootId);
|
|
|
|
node.setPid(null);
|
|
|
|
node.setName("root");
|
|
|
|
node.setScore(0);
|
|
|
|
// 2
|
|
|
|
AppraiseTreeNode node1 = new AppraiseTreeNode();
|
|
|
|
String subId = UUID.randomUUID().toString();
|
|
|
|
node1.setId(subId);
|
|
|
|
node1.setPid(rootId);
|
|
|
|
node1.setName("child-1");
|
|
|
|
node1.setScore(0);
|
|
|
|
// 3
|
|
|
|
AppraiseTreeNode node2 = new AppraiseTreeNode();
|
|
|
|
node2.setId(UUID.randomUUID().toString());
|
|
|
|
node2.setPid(subId);
|
|
|
|
node2.setName("child-2");
|
|
|
|
node2.setScore(0);
|
|
|
|
nodes.add(node);
|
|
|
|
nodes.add(node1);
|
|
|
|
nodes.add(node2);
|
|
|
|
appraise.setNodes(nodes);
|
|
|
|
|
|
|
|
Appraise saved = cosmosTemplate.insert(appraise, null);
|
|
|
|
System.out.println(saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSelect() {
|
|
|
|
//Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
|
|
|
|
//EvaluationService service = new EvaluationServiceImpl();
|
|
|
|
//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("habook", "50fdecdb-6cbd-4c9a-8dc2-a627f4d6b312"));
|
|
|
|
// 评价记录
|
|
|
|
long t1 = System.currentTimeMillis();
|
|
|
|
//List<Student> student = studentRepository.findByIdAndCode("202201008", String.format(PK.STUDENT, "hbcn"));
|
|
|
|
String hbcn = cosmosTemplate.findById("hbcn", String.class);
|
|
|
|
long t2 = System.currentTimeMillis();
|
|
|
|
System.out.println(t2 - t1);
|
|
|
|
System.out.println(hbcn);
|
|
|
|
|
|
|
|
//System.out.println(RepositoryUtil.findOne(student, "error"));
|
|
|
|
|
|
|
|
//List<AppraiseRecord> record = appraiseRecordRepository.findScoreAndPraise("fakeStudentId1",
|
|
|
|
// "2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017",
|
|
|
|
// String.format(PK.PK_APPRAISE_RECORD,"habook")
|
|
|
|
//);
|
|
|
|
//System.out.println(RepositoryUtil.findOne(record));
|
|
|
|
//List<AppraiseRecordItem> record = appraiseRecordRepository.searchNodesByCondition(null,
|
|
|
|
// null, null,"1595321354","2023-71fbd0bd-9a46-0490-f6b3-7d16cba4c017",
|
|
|
|
// String.format(PK.PK_APPRAISE_RECORD,"habook")
|
|
|
|
//);
|
|
|
|
//System.out.println(record);
|
|
|
|
}
|
|
|
|
@Test
|
|
|
|
public void testUpdate() {
|
|
|
|
//EvaluationTree saved = evaluationTreeRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
|
|
|
|
Appraise saved = appraiseRepository.findBySchoolId("hbcn", new PartitionKey("evaluation"));
|
|
|
|
EvaluationService service = new EvaluationServiceImpl();
|
|
|
|
//System.out.println(JSONUtil.parse(service.buildTree(saved.getNodes())).toStringPretty());
|
|
|
|
appraiseRepository.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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|