ZhuDongming
2019-08-19 c2b226e7902dbb2b36f349612886ccc7333895e6
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
package com.moral.controller;
 
import static com.moral.common.util.WebUtils.getParametersStartingWith;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.alibaba.fastjson.JSONObject;
import com.moral.common.bean.PageBean;
import com.moral.common.bean.ResultBean;
import com.moral.entity.Device;
import com.moral.entity.DeviceProperty;
import com.moral.service.DeviceService;
 
@RestController
@RequestMapping("device")
@CrossOrigin(origins = "*", maxAge = 3600)
public class DeviceController {
    @Resource
    DeviceService deviceService;
    @GetMapping("count-by-example")
    public ResultBean<Integer> countByExample(PageBean pageBean){
        return  new ResultBean<Integer>(deviceService.countByExample(pageBean));
    }
    @GetMapping("count-by-times")
    public ResultBean<List<Map>> countByTimes(Date start, Date end){
        return  new ResultBean<List<Map>>(deviceService.countByTimes(start,end,"%Y-%m"));
    }
    @GetMapping("page-list")
    public PageBean pageList(PageBean pageBean) {
        return deviceService.queryByPageBean(pageBean);
    }
    @PostMapping("delete-by-ids")
    public ResultBean deleteByIds(@RequestBody Integer [] ids){
        deviceService.deleteByIds(ids);
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        return resultBean;
    }
    @PostMapping("add-or-modify")
    public ResultBean addOrModify(@RequestBody Device device){
        deviceService.addOrModify(device);
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        return resultBean;
    }
 
    @GetMapping("monitorPointId")
    public ResultBean<List<Device>> getDevicesByMonitorPointId(@RequestParam(name="monitorPointId")Integer  monitorPointId) {
        
        List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPointId);
        return new ResultBean<List<Device>>(devices);
    }
 
    @GetMapping("professionId")
    public ResultBean<List<Device>> getDevicesByProfessionId(HttpServletRequest request) {
        Map<String, Object> parameters = getParametersStartingWith(request, null);
        List<Device> devices = deviceService.getDevicesByProfessionId(parameters);
        return new ResultBean<List<Device>>(devices);
    }
    
    @PostMapping("save-or-update")
    public ResultBean saveOrUpdate(@RequestBody String jsonString){
        Device device = JSONObject.parseObject(jsonString, Device.class);
        DeviceProperty deviceProperty = JSONObject.parseObject(jsonString, DeviceProperty.class);
        deviceService.saveOrUpdate(device,deviceProperty);
        ResultBean resultBean = new ResultBean(ResultBean.SUCCESS);
        return resultBean;
    }
 
    @GetMapping("device-list")
    public PageBean getDeviceList(PageBean pageBean) {
        return deviceService.getDeviceList(pageBean);
    }
 
}