YlbController.java
2.99 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
package com.bsth.controller.oil;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
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 com.bsth.controller.BaseController;
import com.bsth.entity.oil.Ylb;
import com.bsth.entity.sys.SysUser;
import com.bsth.security.util.SecurityUtils;
import com.bsth.service.oil.YlbService;
import com.google.common.base.Splitter;
@RestController
@RequestMapping("ylb")
public class YlbController extends BaseController<Ylb, Integer>{
@Autowired
YlbService yblService;
@RequestMapping(value = "/saveYlb",method = RequestMethod.POST)
public Map<String, Object> saveYlb(Ylb t){
// SysUser user = SecurityUtils.getCurrentUser();
t.setCreatetime(new Date());
// Ylb t=new Ylb();
return yblService.save(t);
}
/**
* 把加油(YLXXB)的数据加入
* @param map
* @return
*/
@RequestMapping(value = "/obtain",method = RequestMethod.GET)
public List<Map<String, Object>> obtain(@RequestParam Map<String, Object> map){
String rq=map.get("rq").toString();
List<Map<String, Object>> list=yblService.obtain(rq);
System.out.println();
return list;
}
/**
*
* @Title: list
* @Description: TODO(多条件分页查询)
* @param @param map 查询条件
* @param @param page 页码
* @param @param size 每页显示数量
* @throws
*/
@RequestMapping(method = RequestMethod.GET)
public Page<Ylb> list(@RequestParam Map<String, Object> map,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(defaultValue = "id") String order,
@RequestParam(defaultValue = "DESC") String direction){
Direction d;
try {
String rq=map.get("rq").toString();
if(!(rq=="")){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
map.put("rq_eq", sdf.parse(rq));
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(null != direction && direction.equals("ASC"))
d = Direction.ASC;
else
d = Direction.DESC;
// 允许多个字段排序,order可以写单个字段,也可以写多个字段
// 多个字段格式:{col1},{col2},{col3},....,{coln}
// 每个字段的排序方向都是一致,这个以后再看要不要改
List<String> list = Splitter.on(",").trimResults().splitToList(order);
return baseService.list(map, new PageRequest(page, size, new Sort(d, list)));
}
}