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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.common.system.query.QueryGenerator;
import org.jeecg.modules.system.app.entity.AppGameSchedule;
import org.jeecg.modules.system.app.service.IAppGameScheduleService;
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;
import java.util.Arrays;
 /**
 * @Description: 赛程安排表
 * @Author: jeecg-boot
 * @Date:   2025-07-08
 * @Version: V1.0
 */
@Tag(name="赛程安排表")
@RestController
@RequestMapping("/app/appGameSchedule")
@Slf4j
public class AppGameScheduleController extends JeecgController<AppGameSchedule, IAppGameScheduleService> {
	@Autowired
	private IAppGameScheduleService appGameScheduleService;
	
	/**
	 * 分页列表查询
	 *
	 * @param appGameSchedule
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "赛程安排表-分页列表查询")
	@Operation(summary="赛程安排表-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<AppGameSchedule>> queryPageList(AppGameSchedule appGameSchedule,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {


        QueryWrapper<AppGameSchedule> queryWrapper = QueryGenerator.initQueryWrapper(appGameSchedule, req.getParameterMap());
		Page<AppGameSchedule> page = new Page<AppGameSchedule>(pageNo, pageSize);
		IPage<AppGameSchedule> pageList = appGameScheduleService.page(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param appGameSchedule
	 * @return
	 */
	@AutoLog(value = "赛程安排表-添加")
	@Operation(summary="赛程安排表-添加")
	@RequiresPermissions("org.jeecg.modules.system.app:nm_game_schedule:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody AppGameSchedule appGameSchedule) {
		appGameScheduleService.save(appGameSchedule);

		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param appGameSchedule
	 * @return
	 */
	@AutoLog(value = "赛程安排表-编辑")
	@Operation(summary="赛程安排表-编辑")
	@RequiresPermissions("org.jeecg.modules.system.app:nm_game_schedule:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody AppGameSchedule appGameSchedule) {
		appGameScheduleService.updateById(appGameSchedule);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "赛程安排表-通过id删除")
	@Operation(summary="赛程安排表-通过id删除")
	@RequiresPermissions("org.jeecg.modules.system.app:nm_game_schedule:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		appGameScheduleService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "赛程安排表-批量删除")
	@Operation(summary="赛程安排表-批量删除")
	@RequiresPermissions("org.jeecg.modules.system.app:nm_game_schedule:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.appGameScheduleService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "赛程安排表-通过id查询")
	@Operation(summary="赛程安排表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<AppGameSchedule> queryById(@RequestParam(name="id",required=true) String id) {
		AppGameSchedule appGameSchedule = appGameScheduleService.getById(id);
		if(appGameSchedule==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(appGameSchedule);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param appGameSchedule
    */
    @RequiresPermissions("org.jeecg.modules.system.app:nm_game_schedule:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, AppGameSchedule appGameSchedule) {
        return super.exportXls(request, appGameSchedule, AppGameSchedule.class, "赛程安排表");
    }

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

}
