BudgetController.java
5.36 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
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.entity.forms.Revenue;
import com.bsth.service.forms.BudgetService;
import com.bsth.service.forms.impl.RevenueLoader;
import com.google.common.io.Files;
import lombok.experimental.var;
@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 year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetMileage(year, type);
} 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 year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetPerson(year, type);
} 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 year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetAmounts(year, type);
} 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 type = "";
if(map.get("type")!=null){
type=map.get("type").toString();
}
String year = "";
if(map.get("year")!=null){
year=map.get("year").toString();
return service.budgetSum(year, type);
} else {
return resList;
}
}
}