CarsController.java
3.07 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
package com.bsth.controller;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Cars;
import com.bsth.service.schedule.utils.DataImportExportService;
import com.bsth.service.schedule.utils.DataToolsProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* Created by xu on 16/5/31.
*/
@RestController
@RequestMapping("cars")
@EnableConfigurationProperties(DataToolsProperties.class)
public class CarsController extends BaseController2<Cars, Integer> {
@Autowired
private DataToolsProperties dataToolsProperties;
@Autowired
private DataImportExportService dataImportExportService;
/**
* 验证。
* @param map
* @return
*/
@RequestMapping(value = "/validate/equale", method = RequestMethod.GET)
public Map<String, Object> validateData(@RequestParam Map<String, Object> map) {
// 一般比较自编号是否重复
return baseService.validateEquale(map);
}
// uploadFile post
// 验证excel sheet
@RequestMapping(value = "/validate/sheet", method = RequestMethod.GET)
public Map<String, Object> validateSheet() throws Exception {
Map<String, Object> rtn = new HashMap<>();
// TODO:
rtn.put("status", ResponseCode.SUCCESS);
return rtn;
}
@RequestMapping(value = "/importfile", method = RequestMethod.POST)
public Map<String, Object> importData(
@RequestParam Map<String, Object> form)
throws Exception {
Map<String, Object> rtn = new HashMap<>();
// TODO:
String filename = (String) form.get("filename");
try {
// 获取ktr转换文件绝对路径
File ktrfile = new File(this.getClass().getResource(getDataImportKtrClasspath()).toURI());
System.out.println(ktrfile.getAbsolutePath());
// 导入数据
dataImportExportService.fileDataImport(new File(filename), ktrfile);
rtn.put("status", ResponseCode.SUCCESS);
rtn.put("msg", "导入成功");
} catch (Exception exp) {
exp.printStackTrace();
rtn.put("status", ResponseCode.ERROR);
rtn.put("msg", exp.getLocalizedMessage());
}
return rtn;
}
@Override
protected String getDataImportKtrClasspath() {
return dataToolsProperties.getCarsDatainputktr();
}
@Override
protected String getDataExportKtrClasspath() {
return dataToolsProperties.getCarsDataoutputktr();
}
@Override
protected String getDataExportFilename() {
return "车辆基础数据";
}
}