BudgetController.java
7.22 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.bsth.controller.forms;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
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 org.springframework.web.multipart.MultipartFile;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.entity.forms.Budget;
import com.bsth.service.forms.BudgetService;
import com.google.common.io.Files;
@RestController
@RequestMapping("budget")
public class BudgetController extends BaseController<Budget, Integer>{
@Autowired
private BudgetService service;
@RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
public String uploadFile(MultipartFile file) throws Exception{
Map<String, Object> map = new HashMap<String, Object>();
File newFile = new File(
getDataImportClasspath() + File.separator +
file.getOriginalFilename());
Files.write(file.getBytes(), newFile);
String result = service.importExcel(newFile);
return "{\"result\":" + "\""+result+"\"}";
}
public String getDataImportClasspath(){
return this.getClass().getResource("/").getPath() + "/static/pages/forms/budget";
}
@RequestMapping(value = "/deleteIds", method = RequestMethod.POST)
public Map<String, Object> deleteIds(@RequestParam Map<String, Object> map) {
Map<String, Object> maps=new HashMap<String, Object>();
try {
maps= service.deleteIds(map);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return maps;
}
@RequestMapping(value = "/updateRevenue", method = RequestMethod.GET)
public Map<String, Object> updateRevenue(@RequestParam Map<String, Object> map) {
Map<String, Object> resMap=new HashMap<String, Object>();
try {
System.out.println(map);
if(map.get("date") != null && map.get("date").toString().length() > 0){
resMap = service.updateRevenue(map.get("date").toString());
}
if(map.get("date1") != null && map.get("date1").toString().length() > 0
&& map.get("date2") != null && map.get("date2").toString().length() > 0){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String date1 = map.get("date1").toString();
String date2 = map.get("date2").toString();
Date parse1 = sdf.parse(date1);
Date parse2 = sdf.parse(date2);
for(Date parse = new Date(parse1.getTime());
parse.getTime() <= parse2.getTime();
parse.setTime(parse.getTime() + 1l*1000*60*60*24)){
service.updateRevenue(sdf.format(parse));
}
}
resMap.put("status", ResponseCode.SUCCESS);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
resMap.put("status", ResponseCode.ERROR);
}
return resMap;
}
@RequestMapping(value = "/budgetMileage", method = RequestMethod.POST)
public List<Map<String, Object>> budgetMileage(@RequestParam Map<String, Object> map) {
List<Map<String, Object>> resList=new ArrayList<Map<String, Object>>();
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
String year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetMileage(year, type, key);
} else {
return resList;
}
}
@RequestMapping(value = "/budgetPerson", method = RequestMethod.POST)
public List<Map<String, Object>> budgetPerson(@RequestParam Map<String, Object> map) {
List<Map<String, Object>> resList=new ArrayList<Map<String, Object>>();
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
String year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetPerson(year, type, key);
} else {
return resList;
}
}
@RequestMapping(value = "/budgetAmounts", method = RequestMethod.POST)
public List<Map<String, Object>> budgetAmounts(@RequestParam Map<String, Object> map) {
List<Map<String, Object>> resList=new ArrayList<Map<String, Object>>();
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
String year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetAmounts(year, type, key);
} else {
return resList;
}
}
@RequestMapping(value = "/budgetSum", method = RequestMethod.POST)
public List<Map<String, Object>> budgetSum(@RequestParam Map<String, Object> map) {
List<Map<String, Object>> resList=new ArrayList<Map<String, Object>>();
String nature="0";
if(map.get("nature")!=null){
nature=map.get("nature").toString();
}
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
String year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetSum(year, nature, type, key);
} else {
return resList;
}
}
@RequestMapping(value = "/timeSum", method = RequestMethod.POST)
public List<Map<String, Object>> timeSum(@RequestParam Map<String, Object> map) throws Exception{
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String date = "";
if(map.get("date")!=null){
date=map.get("date").toString();
}
String date2 = "";
if(map.get("date2")!=null){
date2=map.get("date2").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
return service.timeSum(date, date2, type, key);
}
@RequestMapping(value = "/timeAnaly", method = RequestMethod.POST)
public Map<String, Object> timeAnaly(@RequestParam Map<String, Object> map) throws Exception{
String company = "";
if(map.get("company")!=null){
company=map.get("company").toString();
}
String subCompany = "";
if(map.get("subCompany")!=null){
subCompany=map.get("subCompany").toString();
}
String date = "";
if(map.get("date")!=null){
date=map.get("date").toString();
}
String line = "";
if(map.get("line")!=null){
line=map.get("line").toString();
}
String model = "";
if(map.get("model")!=null){
model=map.get("model").toString();
}
String type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String key = "";
if(map.get("key")!=null){
key=map.get("key").toString();
}
return service.timeAnaly(company, subCompany, date, line, model, type, key);
}
}