package com.bonus.material.device.controller;

import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.device.domain.SafeBookInfo;
import com.bonus.material.device.service.SafeBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
/**
 * @Author：liang.chao
 * @Date：2024/12/4 - 16:24
 */
@RestController
@RequestMapping("/safeBook")
@Api(value = "安全证书",tags = "安全证书管理")
public class SafeBookController extends BaseController {

    @Resource
    private SafeBookService safeBookService;

    @ApiOperation(value = "安全证书列表")
    @GetMapping("/getSafeBookByMaId")
    public AjaxResult getSafeBookByMaId(SafeBookInfo safeBookInfo) {
        startPage();
        List<SafeBookInfo> list = safeBookService.getSafeBookByMaId(safeBookInfo);
        return AjaxResult.success(getDataTable(list));
    }

    @ApiOperation(value = "新增安全证书")
    @PostMapping("/addSafeBook")
    public AjaxResult addSafeBook(@RequestBody SafeBookInfo safeBookInfo) {
        Integer i = safeBookService.addSafeBook(safeBookInfo);
        if (i > 0) {
            return AjaxResult.success("新增成功");
        } else {
            return AjaxResult.error("新增失败");
        }
    }
    @ApiOperation(value = "修改安全证书")
    @PostMapping("/editSafeBook")
    public AjaxResult editSafeBook(@RequestBody SafeBookInfo safeBookInfo) {
        Integer i = safeBookService.editSafeBook(safeBookInfo);
        if (i > 0) {
            return AjaxResult.success("修改成功");
        } else {
            return AjaxResult.error("修改失败");
        }
    }


    @ApiOperation(value = "删除安全证书")
    @PostMapping("/delSafeBook")
    public AjaxResult delSafeBook(@RequestBody SafeBookInfo safeBookInfo) {
        Integer i = safeBookService.delSafeBook(safeBookInfo);
        if (i > 0) {
            return AjaxResult.success("删除成功");
        } else {
            return AjaxResult.error("删除失败");
        }
    }
}
