feat: 增加新传感器的功能接口
parent
89ca4dd4f2
commit
11723c61f1
@ -0,0 +1,76 @@
|
||||
package com.xydl.cac.controller;
|
||||
|
||||
import com.xydl.cac.entity.NSensor;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
import com.xydl.cac.model.Response;
|
||||
import com.xydl.cac.service.NSensorService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = {"监测设备相关接口"})
|
||||
@RequestMapping("nsensor")
|
||||
@Slf4j
|
||||
public class NSensorController extends BasicController {
|
||||
|
||||
@Resource
|
||||
NSensorService service;
|
||||
|
||||
@GetMapping("listAll")
|
||||
@ApiOperation("查询列表")
|
||||
public Response<List<NSensor>> listAll(@NotNull(message = "主设备编号不能缺少") @Param("zsbid") Integer zsbid) {
|
||||
List<NSensor> result = service.listAll(zsbid);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation("新增")
|
||||
public Response<NSensor> add(@Validated @RequestBody NSensor item) throws Exception {
|
||||
NSensor result = service.add(item);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation("更新")
|
||||
public Response<String> update(@Validated @RequestBody NSensor item) throws Exception {
|
||||
if (item.getId() == null) {
|
||||
throw new BusinessException("ID不能为空!");
|
||||
}
|
||||
service.update(item);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation("删除")
|
||||
public Response<String> delete(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id) {
|
||||
service.delete(id);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@PostMapping("detail")
|
||||
@ApiOperation("详情")
|
||||
public Response<NSensor> detail(@Validated @NotNull(message = "ID不能为空!") Integer id) throws Exception {
|
||||
NSensor detail = service.detail(id);
|
||||
return Response.success(detail);
|
||||
}
|
||||
|
||||
@PostMapping("bindicd")
|
||||
@ApiOperation("详情")
|
||||
public Response<String> bindicd(@Validated @NotNull(message = "ID不能为空!") @Param("id") Integer id, @Validated @NotNull(message = "icdid不能为空!") @Param("icdid") Integer icdid) {
|
||||
try {
|
||||
service.bindicd(id, icdid);
|
||||
return Response.success("OK");
|
||||
} catch (Exception ex) {
|
||||
return Response.fail(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue