package com.xydl.cac.controller;

import com.xydl.cac.entity.Iec104Point;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.Iec104PointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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 = {"Iec104点表接口"})
@RequestMapping("iec104")
@Slf4j
public class Iec104PointController extends BasicController {

    @Resource
    Iec104PointService iec104PointService;

    @GetMapping("list")
    @ApiOperation("查询104点表")
    public Response<List<Iec104Point>> list() {
        List<Iec104Point> result = iec104PointService.findAll();
        return Response.success(result);
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public Response<Iec104Point> add(@Validated @RequestBody Iec104Point iec104Point) throws Exception {
        Iec104Point add = iec104PointService.add(iec104Point);
        return Response.success(add);
    }

    @PostMapping("del")
    @ApiOperation("删除")
    public Response<String> del(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
        if (id == null) {
            throw new BusinessException("id不能为空!");
        }
        iec104PointService.delete(id);
        return Response.success("OK");
    }

}
