-
Notifications
You must be signed in to change notification settings - Fork 502
Expand file tree
/
Copy pathOrderStatsController.java
More file actions
69 lines (58 loc) · 2.52 KB
/
OrderStatsController.java
File metadata and controls
69 lines (58 loc) · 2.52 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
package com.app.api.order;
import io.swagger.annotations.*;
//import springfox.documentation.annotations.*;
import org.springframework.http.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.data.domain.*;
//import static org.springframework.http.MediaType.*;
import java.util.*;
import java.lang.*;
import java.math.BigDecimal;
import com.app.api.*;
import com.app.repo.*;
import com.app.model.order.*;
import com.app.model.response.*;
import com.app.model.data.*;
import static com.app.model.response.OperationResponse.*;
@RestController
@RequestMapping(value = "/api", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = {"Order"})
public class OrderStatsController {
@Autowired private JdbcTemplate jdbcTemplate;
@ApiOperation(value = "Order Stats", response = SingleDataSeriseResponse.class)
@RequestMapping(value = "/order-stats/{type}", method = RequestMethod.GET)
public SingleDataSeriseResponse getOrderStats(@PathVariable("type") String type ) {
String fieldName = "";
if (type.equalsIgnoreCase("status") || type.equalsIgnoreCase("order_status")){
fieldName = " order_status ";
}
else if (type.equalsIgnoreCase("paytype") || type.equalsIgnoreCase("payment_type")){
fieldName = " payment_type ";
}
else if (type.equalsIgnoreCase("country") || type.equalsIgnoreCase("ship_country")){
fieldName = " ship_country ";
}
else{
fieldName = " order_status ";
}
String sql = "select count(*) as value, " + fieldName + " as name from orders group by " + fieldName;
String countType = new String();
long count;
SingleSerise singleSerise;
SingleDataSeriseResponse resp = new SingleDataSeriseResponse();
ArrayList<SingleSerise> dataItemList = new ArrayList<SingleSerise>();
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
for (Map<String, Object> row : list) {
singleSerise = new SingleSerise((String)row.get("name"), new BigDecimal((long)row.get("value")) );
dataItemList.add(singleSerise);
}
resp.setItems(dataItemList);
resp.setOperationStatus(ResponseStatusEnum.SUCCESS);
resp.setOperationMessage("Orders by " + fieldName);
//resp.setItems(singleSerise);
return resp;
}
}