New file |
| | |
| | | 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()); |
| | | } |
| | | } |