package org.jeecg.modules.ctop.controller;

import cn.com.ctop.common.module.material.entity.MaterialVideoWatermark;
import cn.com.ctop.common.module.material.service.IMaterialVideoWatermarkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
* 视频素材水印信息
*/
@Slf4j
@RestController
@RequestMapping("/com.cn/materialVideoWatermark")
public class MaterialVideoWatermarkController {
   @Autowired
   private IMaterialVideoWatermarkService materialVideoWatermarkService;

   /**
     * 分页列表查询
    */
   @GetMapping(value = "/list")
   public Result<IPage<MaterialVideoWatermark>> queryPageList(MaterialVideoWatermark materialVideoWatermark,
                                                              @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                              @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                              HttpServletRequest req) {
       Result<IPage<MaterialVideoWatermark>> result = new Result<>();
       QueryWrapper<MaterialVideoWatermark> queryWrapper = QueryGenerator.initQueryWrapper(materialVideoWatermark, req.getParameterMap());
       Page<MaterialVideoWatermark> page = new Page<>(pageNo, pageSize);
       IPage<MaterialVideoWatermark> pageList = materialVideoWatermarkService.page(page, queryWrapper);
       result.setSuccess(true);
       result.setResult(pageList);
       return result;
   }

   /**
    *   添加
    */
   @PostMapping(value = "/add")
   public Result<MaterialVideoWatermark> add(@RequestBody MaterialVideoWatermark materialVideoWatermark) {
       Result<MaterialVideoWatermark> result = new Result<>();
       try {
           materialVideoWatermarkService.save(materialVideoWatermark);
           result.success("添加成功！");
       } catch (Exception e) {
           log.error(e.getMessage(),e);
           result.error500("操作失败");
       }
       return result;
   }

}
