package com.gk.hotwork.Controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.gk.hotwork.Controller.Base.BaseController;
|
import com.gk.hotwork.Domain.Enum.ErrorCode;
|
import com.gk.hotwork.Domain.EquipmentInfo;
|
import com.gk.hotwork.Domain.GasWarnInfo;
|
import com.gk.hotwork.Domain.Utils.Msg;
|
import com.gk.hotwork.Domain.Utils.PageInfo;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Service.EquipmentService;
|
import com.gk.hotwork.Service.GasWarnService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
|
@Api(tags = "设备数据接口")
|
@RestController
|
public class EquipmentController extends BaseController {
|
@Autowired
|
EquipmentService equipmentService;
|
@Autowired
|
GasWarnService gasWarnService;
|
|
@GetMapping("/gasWarn")
|
@ApiOperation(value = "获取气体阈值信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageIndex",value = "当前页码"),
|
@ApiImplicitParam(name = "pageSize",value = "每页行数"),
|
@ApiImplicitParam(name = "sort",value = "排序规则"),
|
@ApiImplicitParam(name = "order",value = "排序字段"),
|
@ApiImplicitParam(name = "gastype",value = "气体类型"),
|
@ApiImplicitParam(name = "warntype",value = "报警类型")
|
})
|
public Msg getGasWarn(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
|
String gastype, String warntype){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
|
PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
|
HashMap<String, Object> condition = new HashMap<String, Object>();
|
|
if (StringUtils.isNotBlank(gastype)) {
|
condition.put("gastype", gastype.trim());
|
}
|
|
if (StringUtils.isNotBlank(warntype)) {
|
condition.put("warntype", warntype.trim());
|
}
|
|
pageInfo.setCondition(condition);
|
gasWarnService.selectDataGrid(pageInfo);
|
msg.setResult(pageInfo);
|
return msg;
|
}
|
|
@PostMapping("/addGasWarn")
|
@ApiOperation(value = "添加气体阈值信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "gastype",value = "气体类型"),
|
@ApiImplicitParam(name = "warntype",value = "报警类型"),
|
@ApiImplicitParam(name = "max",value = "最大值"),
|
@ApiImplicitParam(name = "min",value = "最小值"),
|
@ApiImplicitParam(name = "gasunit",value = "气体单位"),
|
})
|
public Msg addGasWarn(@RequestBody GasWarnInfo gasWarnInfo){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
if (StringUtils.isBlank(gasWarnInfo.getGastype())||StringUtils.isBlank(gasWarnInfo.getWarntype())){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("气体类型、报警类型不能为空");
|
return msg;
|
}
|
GasWarnInfo gasWarnInfoExist = gasWarnService.selectExistByType(null,gasWarnInfo.getWarntype(),gasWarnInfo.getGastype());
|
if (gasWarnInfoExist != null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("存在相同气体类型、报警类型的配置");
|
return msg;
|
}
|
gasWarnInfo.setUpdateby(getUser().getRealname());
|
gasWarnInfo.setUpdatetime(new Date());
|
gasWarnService.save(gasWarnInfo);
|
return msg;
|
}
|
|
@PostMapping("/putGasWarn")
|
@ApiOperation(value = "修改气体阈值信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "gastype",value = "气体类型"),
|
@ApiImplicitParam(name = "warntype",value = "报警类型"),
|
@ApiImplicitParam(name = "max",value = "最大值"),
|
@ApiImplicitParam(name = "min",value = "最小值"),
|
@ApiImplicitParam(name = "gasunit",value = "气体单位"),
|
})
|
public Msg putGasWarn(@RequestBody GasWarnInfo gasWarnInfo){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
if (StringUtils.isBlank(gasWarnInfo.getGastype())||StringUtils.isBlank(gasWarnInfo.getWarntype())){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("气体类型、报警类型不能为空");
|
return msg;
|
}
|
GasWarnInfo gasWarnInfoExist = gasWarnService.selectExistByType(gasWarnInfo.getId(),gasWarnInfo.getWarntype(),gasWarnInfo.getGastype());
|
if (gasWarnInfoExist != null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("存在相同气体类型、报警类型的配置");
|
return msg;
|
}
|
gasWarnInfo.setUpdateby(getUser().getRealname());
|
gasWarnInfo.setUpdatetime(new Date());
|
gasWarnService.updateById(gasWarnInfo);
|
return msg;
|
}
|
|
@PostMapping("/delGasWarn")
|
@ApiOperation(value = "删除气体阈值信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id",value = "id"),
|
})
|
public Msg delGasWarn(@RequestBody JSONObject jsonObject){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
Long id = jsonObject.getLong("id");
|
|
if (id == null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("id不能为空");
|
return msg;
|
}
|
gasWarnService.removeById(id);
|
return msg;
|
}
|
|
@GetMapping("/equipment")
|
@ApiOperation(value = "获取设备信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "pageIndex",value = "当前页码"),
|
@ApiImplicitParam(name = "pageSize",value = "每页行数"),
|
@ApiImplicitParam(name = "sort",value = "排序规则"),
|
@ApiImplicitParam(name = "order",value = "排序字段"),
|
@ApiImplicitParam(name = "name",value = "设备名称"),
|
@ApiImplicitParam(name = "number",value = "设备条码")
|
})
|
public Msg equipmentService(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String sort, String order,
|
String name, String number){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
|
PageInfo pageInfo = new PageInfo(pageIndex, pageSize,sort,order);
|
HashMap<String, Object> condition = new HashMap<String, Object>();
|
|
if (StringUtils.isNotBlank(name)) {
|
condition.put("name", name.trim());
|
}
|
|
if (StringUtils.isNotBlank(number)) {
|
condition.put("number", number.trim());
|
}
|
|
pageInfo.setCondition(condition);
|
equipmentService.selectDataGrid(pageInfo);
|
msg.setResult(pageInfo);
|
return msg;
|
}
|
|
@PostMapping("/addEquipment")
|
@ApiOperation(value = "添加设备信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "name",value = "设备名称"),
|
@ApiImplicitParam(name = "number",value = "设备条码"),
|
@ApiImplicitParam(name = "isphoto",value = "是否有摄像头 1是 0否"),
|
@ApiImplicitParam(name = "photoname",value = "摄像头名称"),
|
@ApiImplicitParam(name = "photoaddress",value = "摄像头地址"),
|
})
|
public Msg addEquipment(@RequestBody EquipmentInfo equipmentInfo){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
if (StringUtils.isBlank(equipmentInfo.getName())||StringUtils.isBlank(equipmentInfo.getNumber())){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("设备名称、设备条码不能为空");
|
return msg;
|
}
|
EquipmentInfo equipmentInfoExist = equipmentService.selectExistByNumber(null,equipmentInfo.getNumber());
|
if (equipmentInfoExist != null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("存在相同设备条码");
|
return msg;
|
}
|
if (equipmentInfo.getIsphoto() == 1 && (StringUtils.isBlank(equipmentInfo.getPhotoname())
|
|| StringUtils.isBlank(equipmentInfo.getPhotoaddress()))){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("摄像头名称、地址不能为空");
|
return msg;
|
}
|
equipmentInfo.setUpdateby(getUser().getRealname());
|
equipmentInfo.setUpdatetime(new Date());
|
equipmentService.save(equipmentInfo);
|
return msg;
|
}
|
|
@PostMapping("/putEquipment")
|
@ApiOperation(value = "修改设备信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id",value = "id"),
|
@ApiImplicitParam(name = "name",value = "设备名称"),
|
@ApiImplicitParam(name = "number",value = "设备条码"),
|
@ApiImplicitParam(name = "isphoto",value = "是否有摄像头 1是 0否"),
|
@ApiImplicitParam(name = "photoname",value = "摄像头名称"),
|
@ApiImplicitParam(name = "photoaddress",value = "摄像头地址"),
|
})
|
public Msg putEquipment(@RequestBody EquipmentInfo equipmentInfo){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
if (StringUtils.isBlank(equipmentInfo.getName())||StringUtils.isBlank(equipmentInfo.getNumber())){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("设备名称、设备条码不能为空");
|
return msg;
|
}
|
EquipmentInfo equipmentInfoExist = equipmentService.selectExistByNumber(equipmentInfo.getId(),equipmentInfo.getNumber());
|
if (equipmentInfoExist != null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("存在相同设备条码");
|
return msg;
|
}
|
if (equipmentInfo.getIsphoto() == 1 && (StringUtils.isBlank(equipmentInfo.getPhotoname())
|
|| StringUtils.isBlank(equipmentInfo.getPhotoaddress()))){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("摄像头名称、地址不能为空");
|
return msg;
|
}
|
equipmentInfo.setUpdateby(getUser().getRealname());
|
equipmentInfo.setUpdatetime(new Date());
|
equipmentService.updateById(equipmentInfo);
|
return msg;
|
}
|
|
@PostMapping("/delEquipment")
|
@ApiOperation(value = "删除设备信息",response = Msg.class)
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "id",value = "id"),
|
})
|
public Msg delEquipment(@RequestBody JSONObject jsonObject){
|
Msg msg = new Msg();
|
msg.setCode("200");
|
msg.setMessage("success");
|
Long id = jsonObject.getLong("id");
|
|
if (id == null){
|
msg.setCode(ErrorCode.ERROR_10004.getCode());
|
msg.setMessage("id不能为空");
|
return msg;
|
}
|
equipmentService.removeById(id);
|
return msg;
|
}
|
|
}
|