package org.jeecg.modules.orderplatform.controller;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.orderplatform.entity.PlatformVideo;
import org.jeecg.modules.orderplatform.service.IPlatformVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
  * 下单平台关联视频
  */
@Slf4j
@RestController
@RequestMapping("/platformVideo")
public class PlatformVideoController {

	@Autowired
	private IPlatformVideoService platformVideoService;

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


	/**
	 *  通过id删除
	 */
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam Integer id) {
		try {
			PlatformVideo  platformVideo=new PlatformVideo();
			platformVideo.setId(id);
			platformVideo.setIsDelete(1);
			boolean result = platformVideoService.updateById(platformVideo);
		} catch (Exception e) {
			log.error("删除失败",e.getMessage());
			return Result.error("删除失败!");
		}
		return Result.ok("删除成功!");
	}


	/**
	 * 通过id查询
	 */
	@GetMapping(value = "/queryById")
	public Result<PlatformVideo> queryById(@RequestParam(name="id",required=true) String id) {
		Result<PlatformVideo> result = new Result<>();
		PlatformVideo platformVideo = platformVideoService.getById(id);
		if(platformVideo==null) {
			result.error500("未找到对应实体");
		}else {
			result.setResult(platformVideo);
			result.setSuccess(true);
		}
		return result;
	}

}
