package org.jeecg.modules.system.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.system.app.dto.AppGameDTO;
import org.jeecg.modules.system.app.dto.AppGamePageDTO;
import org.jeecg.modules.system.app.entity.AppGame;
import org.jeecg.modules.system.app.service.IAppGameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 赛事表
 * @Author: jeecg-boot
 * @Date:   2025-07-03
 * @Version: V1.0
 */
@Tag(name="赛事表")
@RestController
@RequestMapping("/app/appGame")
@Slf4j
public class AppGameController extends JeecgController<AppGame, IAppGameService> {
	@Autowired
	private IAppGameService appGameService;


	
	/**
	 * 分页列表查询
	 *
	 * @param dto
	 * @return
	 */
	//@AutoLog(value = "赛事表-分页列表查询")
	@Operation(summary="赛事表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<AppGameDTO>> queryPageList(AppGamePageDTO dto) {
		return Result.OK(appGameService.queryWitchPriceRulesPage(dto));
	}
	
	/**
	 *   添加
	 *
	 * @param gameDTO
	 * @return
	 */
	@AutoLog(value = "赛事表-添加")
	@Operation(summary="赛事表-添加")
//	@RequiresPermissions("org.jeecg.modules.app:nm_game:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AppGameDTO gameDTO) {
		return appGameService.saveWitchPriceRules(gameDTO)? Result.OK("操作成功！"): Result.error("操作失败！");
	}
	
	/**
	 *  编辑
	 *
	 * @param gameDTO
	 * @return
	 */
	@AutoLog(value = "赛事表-编辑")
	@Operation(summary="赛事表-编辑")
//	@RequiresPermissions("org.jeecg.modules.app:nm_game:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AppGameDTO gameDTO) {
		return appGameService.editWitchPriceRules(gameDTO)? Result.OK("操作成功！"): Result.error("操作失败！");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "赛事表-通过id删除")
	@Operation(summary="赛事表-通过id删除")
//	@RequiresPermissions("org.jeecg.modules.app:nm_game:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		return appGameService.deleteWitchPriceRulesById(id)? Result.OK("操作成功！"): Result.error("操作失败！");
	}
	
//	/**
//	 *  批量删除
//	 *
//	 * @param ids
//	 * @return
//	 */
//	@AutoLog(value = "赛事表-批量删除")
//	@Operation(summary="赛事表-批量删除")
//	@RequiresPermissions("org.jeecg.modules.app:nm_game:deleteBatch")
//	@DeleteMapping(value = "/deleteBatch")
//	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
//		this.appGameService.removeByIds(Arrays.asList(ids.split(",")));
//		return Result.OK("批量删除成功!");
//	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "赛事表-通过id查询")
	@Operation(summary="赛事表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<AppGameDTO> queryById(@RequestParam(name="id",required=true) String id) {
		return Result.OK(appGameService.queryWitchPriceRulesById(id));
	}

	 /**
	  * 发布成绩
	  *
	  * @param appGame
	  * @return
	  */
	 @Operation(summary="赛事表-发布成绩")
	 @PutMapping(value = "/uploadScore")
	 public Result<String> uploadScore(@RequestBody  AppGame appGame) {
		 boolean save = appGameService.updateById(appGame);
		 if (!save){
			 return Result.error("上传成绩失败");
		 }
		 return Result.OK("上传成绩成功");
	 }

    /**
    * 导出excel
    *
    * @param request
    * @param appGame
    */
//    @RequiresPermissions("org.jeecg.modules.app:nm_game:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AppGame appGame) {
        return super.exportXls(request, appGame, AppGame.class, "赛事表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("org.jeecg.modules.app:nm_game:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, AppGame.class);
    }

}
