package org.jeecg.modules.ctop.controller;

import cn.com.ctop.common.module.material.entity.MaterialVideoAuthor;
import cn.com.ctop.common.module.material.service.IMaterialVideoAuthorService;
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/materialVideoAuthor")
public class MaterialVideoAuthorController {
	@Autowired
	private IMaterialVideoAuthorService materialVideoAuthorService;

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

	/**
     *  编辑
	 */
	@PostMapping(value = "/edit")
	public Result<MaterialVideoAuthor> edit(@RequestBody MaterialVideoAuthor materialVideoAuthor) {
		Result<MaterialVideoAuthor> result = new Result<MaterialVideoAuthor>();
		MaterialVideoAuthor materialVideoAuthorEntity = materialVideoAuthorService.getById(materialVideoAuthor.getId());
		if(materialVideoAuthorEntity==null) {
			result.error500("未找到对应实体");
		}else {
			boolean ok = materialVideoAuthorService.updateById(materialVideoAuthor);
			if(ok) {
				result.success("修改成功!");
			}
		}

		return result;
	}

}
