| package com.moral.api.controller; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.moral.api.entity.ManageRole; | 
| import com.moral.api.entity.Sensor; | 
| import com.moral.api.service.ManageRoleMenuService; | 
| import com.moral.api.service.ManageRoleService; | 
| 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 io.swagger.annotations.ApiImplicitParam; | 
| import io.swagger.annotations.ApiImplicitParams; | 
| import io.swagger.annotations.ApiOperation; | 
| import lombok.extern.slf4j.Slf4j; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.data.redis.core.RedisTemplate; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import java.util.ArrayList; | 
| import java.util.Arrays; | 
| import java.util.List; | 
| import java.util.Map; | 
|   | 
| import static org.springframework.web.util.WebUtils.getParametersStartingWith; | 
|   | 
| @Slf4j | 
| @Api(tags = {"因子"}) | 
| @RestController | 
| @RequestMapping("/sensor") | 
| public class SensorController { | 
|   | 
|     @Autowired | 
|     private SensorService sensorService; | 
|   | 
|     @RequestMapping(value = "insertOneSensor", method = RequestMethod.POST) | 
|     @ResponseBody | 
|     public ResultMessage insertOneSensor(@RequestBody Map<String, Object> parameters,HttpServletRequest request) { | 
|         Sensor sensor = JSON.parseObject(JSON.toJSONString(parameters), Sensor.class); | 
|         Map<String,Object> resultMap = sensorService.insertOne(sensor); | 
|         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 = "updateSensor", method = RequestMethod.POST) | 
|     @ResponseBody | 
|     public ResultMessage updateSensor(@RequestBody Map<String, Object> parameters,HttpServletRequest request) { | 
|         Map<String,Object> resultMap = sensorService.updateSensor(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 = "getAllSensor", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage getAllSensor(HttpServletRequest request) { | 
|         Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|         Map<String,Object> resultMap = sensorService.getAllSensor(parameters); | 
|         if (!resultMap.containsKey("code")){ | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString()); | 
|     } | 
|   | 
|     @RequestMapping(value = "getAllSensorWithoutPage", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage getAllSensorWithoutPage(HttpServletRequest request) { | 
|         Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|         Map<String,Object> resultMap = sensorService.getAllSensorWithoutPage(); | 
|         if (!resultMap.containsKey("code")){ | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString()); | 
|     } | 
|   | 
|     @RequestMapping(value = "deleteSensor", method = RequestMethod.POST) | 
|     @ResponseBody | 
|     public ResultMessage deleteSensor(@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 = sensorService.deleteSensor(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 = "getSensorByFuzzy", method = RequestMethod.GET) | 
|     @ResponseBody | 
|     public ResultMessage getSensorByFuzzy(HttpServletRequest request) { | 
|         Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); | 
|         Map<String,Object> resultMap = sensorService.getSensorByFuzzy(parameters); | 
|         if (!resultMap.containsKey("code")){ | 
|             return ResultMessage.ok(resultMap); | 
|         } | 
|         return ResultMessage.fail(Integer.parseInt(resultMap.get("code").toString()),resultMap.get("msg").toString()); | 
|     } | 
| } |