package com.zksy.park.controller;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.common.annotation.Log;
import com.zksy.common.core.domain.Result;
import com.zksy.common.enums.BusinessType;
import com.zksy.common.utils.SearchUtil;
import com.zksy.park.domain.ParkVisualVideo;
import com.zksy.park.domain.dto.PackInfoDto;
import com.zksy.park.service.ParkVisualVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @project dh-server-micro
 * @description 园区可视化视频
 * @date 2024/12/23 08:42:12
 */
@RestController
@RequestMapping("/ParkVisualVideo")
@Api(tags = "园区可视化视频", description = "园区可视化视频desc")
public class ParkVisualVideoController {

    @Autowired
    private ParkVisualVideoService service;

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "园区可视化视频搜索getById")
    public Result getById(@PathVariable String id) {
        return Result.ok(service.getById(id));
    }

    @GetMapping("/findByPage")
    @ApiOperation(value = "园区可视化视频分页")
    public Page findByPage(long pageNum, long pageSize, String conditionJson) throws Exception {
        return service.page(new Page<>(pageNum, pageSize), SearchUtil.parseWhereSql(conditionJson));
    }

    @GetMapping("/getList")
    @ApiOperation(value = "园区可视化视频查询所有")
    public Result getList(String conditionJson) throws Exception {
        return Result.ok(service.list(SearchUtil.parseWhereSql(conditionJson)));
    }

    @PostMapping("/save")
    @ApiOperation(value = "园区可视化视频新增")
    @Log(title = "新增园区信息", businessType = BusinessType.INSERT)
    public Result<Object> save(@RequestBody ParkVisualVideo entity) {
        entity.setCreateTime(new DateTime().toLocalDateTime());
        entity.setUpdateTime(new DateTime().toLocalDateTime());
        return Result.ok(service.save(entity));
    }

    @PostMapping("/saveBatch")
    @ApiOperation(value = "园区可视化视频批量新增")
    @Log(title = "批量新增园区信息", businessType = BusinessType.INSERT)
    public Result<Object> saveBatch(@RequestBody List<ParkVisualVideo> entityList) {
        entityList.forEach(q->{
            q.setUpdateTime(new DateTime().toLocalDateTime());
            q.setCreateTime(new DateTime().toLocalDateTime());
        });
        return Result.ok(service.saveBatch(entityList));
    }

    @PutMapping("/updateById")
    @ApiOperation(value = "园区可视化视频修改")
    @Log(title = "园区可视化视频信息", businessType = BusinessType.UPDATE)
    public Result<Object> updateById(@RequestBody ParkVisualVideo entity) {
        entity.setUpdateTime(new DateTime().toLocalDateTime());
        return Result.ok(service.updateById(entity));
    }

    @DeleteMapping("/deleteById")
    @ApiOperation(value = "园区可视化视频删除")
    @Log(title = "园区可视化视频信息", businessType = BusinessType.DELETE)
    public Result<Object> deleteById(String id) {
        return Result.ok(service.removeById(id));
    }

    @DeleteMapping("/deleteBatchById")
    @ApiOperation(value = "园区可视化视频批量删除")
    @Log(title = "园区可视化视频批量删除", businessType = BusinessType.DELETE)
    public Result<Object> deleteBatchById(@RequestParam List<String> ids) {
        return Result.ok(service.removeByIds(ids));
    }
}
