jinpengyong
2021-06-30 e6c6e6225bdbaaa27bcde320a79acde8239416c2
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.moral.api.controller;
 
import com.alibaba.fastjson.JSON;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.entity.Sensor;
import com.moral.api.service.MonitorPointService;
import com.moral.api.service.SensorService;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
import com.moral.util.WebUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
 
@Slf4j
@Api(tags = {"站点"})
@RestController
@RequestMapping("/monitorPoint")
public class MonitorPointController {
 
    @Autowired
    private MonitorPointService monitorPointService;
 
    @Autowired
    private SensorService sensorService;
 
    @RequestMapping(value = "insertOneMonitorPoint", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage insertOneMonitorPoint(@RequestBody Map<String, Object> parameters,HttpServletRequest request) {
        MonitorPoint monitorPoint = JSON.parseObject(JSON.toJSONString(parameters), MonitorPoint.class);
        Map<String,Object> resultMap = monitorPointService.insertMonitorPoint(monitorPoint);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
        //return null;
    }
 
    @RequestMapping(value = "updateMonitorPoint", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage updateMonitorPoint(@RequestBody Map<String, Object> parameters,HttpServletRequest request) {
        Map<String,Object> resultMap = monitorPointService.updateMonitorPoint(parameters);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
    }
 
    @RequestMapping(value = "getAllMonitorPoint", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getAllMonitorPoint(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map<String,Object> resultMap = monitorPointService.getAllMonitorPoint(parameters);
        if (!resultMap.containsKey("code")){
            return ResultMessage.ok(resultMap);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
    }
 
    @RequestMapping(value = "deleteMonitorPoint", method = RequestMethod.POST)
    @ResponseBody
    public ResultMessage deleteMonitorPoint(@RequestBody Map<String, Object> parameters,HttpServletRequest request) {
        if (!parameters.containsKey("id")){
            return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
        }
        Map<String,Object> resultMap = monitorPointService.deleteMonitorPoint(parameters);
        String msg = resultMap.get("msg").toString();
        int code = Integer.parseInt(resultMap.get("code").toString());
        if (code == 0){
            return ResultMessage.ok(msg);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
    }
 
    @RequestMapping(value = "getMonitorPointByFuzzy", method = RequestMethod.GET)
    @ResponseBody
    public ResultMessage getMonitorPointByFuzzy(HttpServletRequest request) {
        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
        Map<String,Object> resultMap = monitorPointService.getMonitorPointByFuzzy(parameters);
        if (!resultMap.containsKey("code")){
            return ResultMessage.ok(resultMap);
        }
        return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString());
    }
}