package com.example.zxweb.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.zxweb.common.api.vo.Result;
import com.example.zxweb.dto.ZxCelueDTO;
import com.example.zxweb.entity.ZxCelue;
import com.example.zxweb.service.IZxCelueService;
import com.example.zxweb.vo.AddZxCeluePVO;
import com.example.zxweb.vo.QueryCelueVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description 策略管理接口
 * @Author ZhouWenTao
 * @Date 2023/9/13 11:50
 */
@Api(tags = "策略管理")
@RequestMapping("/celue")
@RestController
public class CelueController {
    @Resource
    IZxCelueService zxCelueService;

    @ApiOperation(value = "策略列表")
    @GetMapping(value = "/list")
    public Result<?> list(QueryCelueVO queryCelueVO){
        IPage<ZxCelueDTO> list= zxCelueService.pageList(queryCelueVO);
        return Result.OK(list);
    }

    @ApiOperation(value = "策略列表-全部")
    @GetMapping(value = "/listAll")
    public Result<?> listAll(){
        return Result.OK(zxCelueService.list());
    }

    @ApiOperation(value = "详情")
    @GetMapping
    public Result<?> getDetail(@RequestParam String id){
        return Result.OK(zxCelueService.getDetail(id));
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public Result<?> add(@RequestBody AddZxCeluePVO addZxCeluePVO){
        zxCelueService.saveZxCelue(addZxCeluePVO);
        return Result.OK("操作成功");
    }

    @ApiOperation(value = "编辑")
    @PutMapping
    public Result<?>edit(@RequestBody AddZxCeluePVO editZxCeluePVO){
        zxCelueService.saveZxCelue(editZxCeluePVO);
        return Result.OK("操作成功");
    }

    @ApiOperation(value = "编辑状态")
    @PutMapping("/status")
    public Result<?> status(@RequestBody ZxCelue zxCelue){
        boolean b = zxCelueService.editStatus(zxCelue);
        if (b) {
            return Result.OK("操作成功");
        }
        return Result.error("操作失败");
    }
    /**
     * 删除
     */
    @ApiOperation(value="删除", notes="删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@RequestParam(name="id") String id) {
        zxCelueService.deleteZxCelue(id);
        //zxCelueService.removeById(id);
        return Result.OK("操作成功");
    }

}
