package com.ltgk.video.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ltgk.common.annotation.Log;
import com.ltgk.common.annotation.RepeatSubmit;
import com.ltgk.common.core.controller.BaseController;
import com.ltgk.common.core.domain.AjaxResult;
import com.ltgk.common.enums.BusinessType;
import com.ltgk.common.utils.SecurityUtils;
import com.ltgk.common.utils.sql.MybatisUtil;
import com.ltgk.common.validation.groups.Detail;
import com.ltgk.video.domain.entity.DsVideoPlan;
import com.ltgk.video.service.IDsVideoPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 视频监控方案数据表 前端控制器
 * </p>
 *
 * @author zhouyaoyao
 * @since 2025-01-19
 */
@Api(tags = "视频监控方案信息")
@RestController
@RequestMapping("/fishingPort/dsVideoPlan")
public class DsVideoPlanController extends BaseController {

    @Autowired
    IDsVideoPlanService dsVideoPlanService;

    @ApiOperation(value = "查询列表数据")
    @PostMapping("/getList")
    @Log(title = "视频监控方案信息", businessType = BusinessType.QUERY)
    public Object getList(@RequestBody DsVideoPlan dsVideoPlan) {
        QueryWrapper<DsVideoPlan> queryWrapper = MybatisUtil.notNullField(dsVideoPlan);
        List<DsVideoPlan> list = dsVideoPlanService.list(queryWrapper);
        return success(list);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping("/page")
    @Log(title = "视频监控方案信息", businessType = BusinessType.PAGE_QUERY)
    public Object page(@RequestBody DsVideoPlan dsVideoPlan) {
        QueryWrapper<DsVideoPlan> queryWrapper = MybatisUtil.notNullField(dsVideoPlan);
        startPage(dsVideoPlan.getPageNum(), dsVideoPlan.getPageSize());
        List<DsVideoPlan> list = dsVideoPlanService.list(queryWrapper);
        return getDataTable(list);
    }

    @ApiOperation(value = "详情查询")
    @PostMapping("/detail")
    @Log(title = "视频监控方案信息", businessType = BusinessType.QUERY)
    public Object page(@RequestParam("id") Long id) {
        if (Objects.isNull(id)) {
            return AjaxResult.error("id不能为空");
        }
        DsVideoPlan dsVideoPlan = dsVideoPlanService.getById(id);
        return success(dsVideoPlan);
    }

    @RepeatSubmit(message = "请勿重复提交")
    @ApiOperation(value = "添加")
    @PostMapping("/save")
    @Log(title = "视频监控方案信息", businessType = BusinessType.INSERT)
    public Object save(@RequestBody DsVideoPlan dsVideoPlan) {
        String userName = SecurityUtils.getLoginUser().getUser().getNickName();
        dsVideoPlan.setCreateBy(userName)
                .setCreateAt(new Date())
                .setUpdateBy(userName)
                .setUpdateAt(new Date());
        return toAjax(dsVideoPlanService.save(dsVideoPlan));
    }

    @ApiOperation(value = "编辑")
    @PostMapping("/update")
    @Log(title = "视频监控方案信息", businessType = BusinessType.UPDATE)
    public Object update(@RequestBody DsVideoPlan dsVideoPlan) {
        String userName = SecurityUtils.getLoginUser().getUser().getNickName();
        dsVideoPlan.setUpdateBy(userName)
                .setUpdateAt(new Date());
        return toAjax(dsVideoPlanService.updateById(dsVideoPlan));
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    @Log(title = "视频监控方案信息", businessType = BusinessType.DELETE)
    public Object delete(@Validated(Detail.class) @RequestBody DsVideoPlan dsVideoPlan) {
        return toAjax(dsVideoPlanService.removeById(dsVideoPlan.getId()));
    }

}

