BookMongoControllerTest.java
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package com.songshu.mongo.test;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.songshu.mongo.model.json.JsonString;
import com.songshu.mongo.model.dto.BookDTO;
import com.songshu.mongo.service.BookMongoService;
import com.songshu.mongo.service.StaticScheduleTaskService;
import com.songshu.mongo.service.UpdateTingcheService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@SpringBootTest
@RunWith(SpringRunner.class)
public class BookMongoControllerTest {
@Autowired
private BookMongoService bookMongoService;
@Autowired
private StaticScheduleTaskService staticScheduleTaskService;
@Autowired
private UpdateTingcheService updateTingcheService;
/**
* 测试json转对象(for:拿示例json数据做批量新增)
*
* @throws JsonProcessingException
*/
@Test
public void jsonToObj() throws JsonProcessingException {
String jsonString = JsonString.jsonString;
// json转对象集合
List<BookDTO> bookDTOList = JSON.parseArray(jsonString, BookDTO.class);
System.out.println(bookDTOList);
//集合转对象
// String json = new ObjectMapper().writeValueAsString(bookDTOList);
}
/**
* 新增)(单个新增)
*/
@Test
public void insert() {
BookDTO bookDTO = new BookDTO();
bookDTO.setId("5");
bookDTO.setName("万界圣主");
bookDTO.setPrice("17.8");
bookDTO.setType("仙侠");
bookDTO.setReadedNum(Double.parseDouble("10.7"));
bookMongoService.inserBookInfo(bookDTO);
}
/**
* 新增(批量新增)
*/
@Test
public void insertBatch() {
// 拿到示例json数据
String jsonString = JsonString.jsonString;
// json转对象集合
List<BookDTO> bookDTOList = JSON.parseArray(jsonString, BookDTO.class);
bookMongoService.inserBatchBookInfo(bookDTOList);
}
/**
* 修改
*/
@Test
public void update() {
// 条件
Query query = Query.query(Criteria.where("_id").is("2"));
// 修改内容
Update update = Update.update("price", "19.9");
bookMongoService.updateBookInfo(query, update);
}
/**
* 查询所有
*/
@Test
public void findAll() {
List<BookDTO> allBookInfo = bookMongoService.findAllBookInfo();
System.out.println(allBookInfo);
}
/**
* 根据书名查询:精准
*/
@Test
public void findByName() {
String name = "盗墓笔记";
List<BookDTO> allBookInfo = bookMongoService.findBookInfoByName(name);
System.out.println(allBookInfo);
}
/**
* 根据书名查询: 模糊查
*/
@Test
public void findReName() {
String name = "主";
List<BookDTO> allBookInfo = bookMongoService.findBookInfoReName(name);
System.out.println(allBookInfo);
}
/**
* 根据阅读量:范围查询,排序
*/
@Test
public void findReRange() {
// 注意,这里范围查询得时候,直接用作字符串去查,并不会把字符串里面得数字提取出来然后做范围查询,所以这里改成Double,改成Long坑太多.
Double minReadedNum = Double.parseDouble("8.3");
Double maxReadedNum = Double.parseDouble("18.0");
List<BookDTO> allBookInfo = bookMongoService.findBookInfoReRange(minReadedNum, maxReadedNum);
System.out.println(allBookInfo);
}
/**
* 根据阅读量:范围查询,排序,分页(页码是物理下标,入数是逻辑下标)
*/
@Test
public void findPage() {
// 注意,这里范围查询得时候,直接用作字符串去查,并不会把字符串里面得数字提取出来然后做范围查询,所以这里改成Double,改成Long坑太多.
Double minReadedNum = Double.parseDouble("7.0");
Double maxReadedNum = Double.parseDouble("35.9");
Integer pageNum = 2;
Integer pageSize = 2;
List<BookDTO> allBookInfo = bookMongoService.findBookInfoPage(minReadedNum, maxReadedNum, pageNum, pageSize);
System.out.println(allBookInfo);
}
// 高级查询待写........
/**
* 测试用
*/
@Test
public void findAll3() {
// staticScheduleTaskService.SynchronousDataRuildings();
// staticScheduleTaskService.SynchronousDataContractsRoom();
// staticScheduleTaskService.SynchronousDataRuildings();
// staticScheduleTaskService.SynchronousDataRoom();
// staticScheduleTaskService.SynchronousDataContracts();
// staticScheduleTaskService.SynchronousDataAccounts();
// staticScheduleTaskService.SynchronousDataContractReceipts();
// staticScheduleTaskService.SynchronousDataContractAuditRecords();
// List<Room> allBookInfo = bookMongoService.findAllBookInfo3();
//
// updateTingcheService.updateTjTcsjtjn();
// updateTingcheService.updateTjCljrsctjn();
// updateTingcheService.updateTjCljrsctjy();
// updateTingcheService.updateTjCljrsctjr();
// updateTingcheService.updateTjJrcrktcsj(); 不用了
// updateTingcheService.updateTjParkingPayment();
// updateTingcheService.updateTjVehicleRecords();
}
}