Newer
Older
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
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.ces.WebApplication;
import com.ces.web.device.entity.DeviceInfo;
import com.ces.web.device.service.IDeviceService;
import org.junit.Test;
import org.junit.platform.commons.util.StringUtils;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
/**
* @author Tao
* @date 2024/8/30
*/
@SpringBootTest(classes = WebApplication.class)
@RunWith(SpringRunner.class)
public class ImportDataTest2 {
@Autowired
private IDeviceService deviceService;
@Test
public void importData() {
ExcelReader reader = ExcelUtil.getReader("D:\\WXWork DATA\\WXWork\\1688856274420445\\Cache\\File\\2024-08\\摄像头.xlsx");
List<List<Object>> rows = reader.read();
for (int i = 1; i < rows.size(); i++) {
List<Object> cols = rows.get(i);
String name = StrUtil.toString(cols.get(0));
String gbid = StrUtil.toString(cols.get(1));
saveData(name, gbid);
}
System.out.println("==== 完成 ====");
}
public void saveData(String name, String gbid) {
DeviceInfo deviceInfo = new DeviceInfo();
deviceInfo.setName(name);
deviceInfo.setGbId(gbid);
deviceInfo.setStatus("0");
deviceInfo.setPrisonName("沪-北");
deviceInfo.setBaseArea("0");
String[] split = name.split("-");
if (split.length >2) {
deviceInfo.setPlace(split[split.length - 1]);
if (split.length > 3) {
String first = split[2];
if (first.contains("楼")) {
deviceInfo.setBuildName(first);
}
if (first.contains("监区")) {
deviceInfo.setAreaName(first);
}
}
}
deviceService.save(deviceInfo);
//
// System.out.println("name: " + deviceInfo.getName() + " | buildName: " + deviceInfo.getBuildName() + " | areaName: " +
// deviceInfo.getAreaName() + " | floor: " + deviceInfo.getFloor() + " | place: " + deviceInfo.getPlace());
}
}