package com.kxs.system.biz.controller.kxsapp;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kxs.common.core.util.R;
import com.kxs.common.security.annotation.Inner;
import com.kxs.common.security.util.SecurityUtils;
import com.kxs.system.api.dto.kxsapp.camp.*;
import com.kxs.system.api.model.KxsBcqtTeam;
import com.kxs.system.api.model.KxsCampReport;
import com.kxs.system.api.vo.kxsapp.camp.CampPageVO;
import com.kxs.system.api.vo.kxsapp.camp.CampUserPageVO;
import com.kxs.system.biz.service.KxsBcqtTeamService;
import com.kxs.system.biz.service.KxsCampReportService;
import com.kxs.system.biz.service.KxsCampService;
import com.kxs.system.biz.service.KxsCampUserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

/**
 * 训练营(Camp)控制层
 *
 * @author 系统
 * @since 2024-04-09 11:56:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("camp")
public class CampController {

    /**
     * 服务对象
     */
    private final KxsCampService kxsCampService;
    private final KxsCampUserService kxsCampUserService;
    private final KxsBcqtTeamService kxsBcqtTeamService;
    private final KxsCampReportService kxsCampReportService;


    /**
     * 列表
     *
     * @param page 分页对象
     * @return 列表
     */
    @GetMapping("/page")
    public R page(@ParameterObject Page<CampPageVO> page) {
        return R.ok(kxsCampService.getByPage(page));
    }


    /**
     * 详情
     *
     * @param id 主键ID
     * @return 详情
     */
    @GetMapping("/getById")
    public R getById(@RequestParam("id") Integer id) {

        return kxsCampService.getByData(id);
    }


    /**
     * 参与创客列表
     *
     * @param page 分页对象
     * @param campId 训练营ID
     * @return 参与创客列表
     */
    @GetMapping("/campUserPage")
    public R campUserPage(@ParameterObject Page<CampUserPageVO> page, @RequestParam("campId") Integer campId){

        return R.ok(kxsCampUserService.getByPage(page, campId));
    }

    /**
     * 获取当前用户参加训练营的信息
     *
     * @return {@link R}
     */
    @GetMapping("/getByCampInfo")
    public R getByCampInfo(){

        return R.ok(kxsCampUserService.getByCampInfo());
    }

    /**
     * 训练营报备提交
     *
     * @return {@link R}
     */
    @PostMapping("/report")
    public R report(@Valid @RequestBody KxsCampReport param){

        return R.ok(kxsCampReportService.report(param));
    }

    /**
     * 训练营报备列表
     *
     * @return {@link R}
     */
    @GetMapping("/reportPage")
    public R reportPage(@ParameterObject Page<KxsCampReport> page, @ParameterObject KxsCampReport param){

        param.setUserId(SecurityUtils.getUser().getId());
        return R.ok(kxsCampReportService.page(page, Wrappers.lambdaQuery(param).orderByDesc(KxsCampReport::getCreateTime)));
    }

    /**
     * 训练营报备取消
     *
     * @return {@link R}
     */
    @PutMapping("/cancelReport")
    public R cancelReport(@RequestBody KxsCampReport param){

        return R.ok(kxsCampReportService.cancelReport(param));
    }





    /**
     * 训练营奖金池刷新
     *
     * @param param 参数
     * @return {@link R}
     */
    @Inner
    @PostMapping("/prizePoolIsRefreshed")
    public R prizePoolIsRefreshed(@RequestBody PrizePoolDTO param){

        kxsCampService.prizePoolIsRefreshed(param);
        return R.ok();
    }

    /**
     * 开机数据统计
     *
     * @param param 参数
     */
    @Inner
    @PostMapping("/campOpenNumStat")
    public void campOpenNumStat(@RequestBody CampOpenNumStatDTO param)  {

        kxsCampService.campOpenNumStat(param);
    }

    /**
     * 百城千团-获取列表
     *
     * @param page 分页对象
     * @param keyword 查询关键字
     * @return 百城千团-获取列表
     */
    @GetMapping("/getBcqtList")
    public R getBcqtList(@ParameterObject Page<KxsBcqtTeam> page, @ParameterObject  String keyword) {
        return kxsBcqtTeamService.getBcqtList(page,keyword);
    }


    /**
     * 百城千团-获取我的参团记录
     *
     * @param page 分页对象
     * @return 百城千团-获取我的参团记录
     */
    @GetMapping("/getMyBcqtList")
    public R getMyBcqtList(@ParameterObject Page<KxsBcqtTeam> page) {

        return kxsBcqtTeamService.getMyBcqtList(page);
    }


    /**
     * 百城千团-创建团队
     *
     * @param param 实体对象
     * @return 百城千团-创建团队
     */
    @PostMapping("/addBcqtTeam")
    @Inner
    public R addBcqtTeam(@Valid @RequestBody CampAddBcqtTeamDTO param) {

        return  kxsBcqtTeamService.addBcqtTeam(param);
    }

    /**
     * 百城千团-创建团队校验
     *
     * @return 百城千团-创建团队
     */
    @PostMapping("/verifyAddTeam")
    public R verifyAddTeam() {
        CampAddBcqtTeamDTO param = new CampAddBcqtTeamDTO();
        Long id = SecurityUtils.getUser().getId();
        param.setCaptainId(id);
        return kxsBcqtTeamService.verifyAddTeam(param);
    }


    /**
     * 百城千团-退出团队
     *
     * @param param 实体对象
     * @return 百城千团-退出团队
     */
    @PostMapping("/returnTeam")
    public R returnTeam(@RequestBody CampReturnTeamDTO param) {

        return kxsBcqtTeamService.returnTeam(param);
    }


    /**
     * 百城千团-开启活动
     *
     * @param param 实体对象
     * @return 百城千团-开启活动
     */
    @PostMapping("/openActivity")
    public R openActivity(@RequestBody CampOpenActivityDTO param) {
        return kxsBcqtTeamService.openActivity(param);
    }


    /**
     * 百城千团-业绩查看
     *
     * @param id 主键ID
     * @return 百城千团-业绩查看
     */
    @GetMapping("/getBcqtDetail")
    public R getBcqtDetail(@RequestParam("id") Integer id) {

        return kxsBcqtTeamService.getBcqtDetail(id);
    }


    /**
     * 定时统计活动期间人员激活  定时任务
     *
     */
    @PostMapping("/setUserActivityTimeStat")
    @Inner
    public void setUserActivityTimeStat() {
        kxsBcqtTeamService.setUserActivityTimeStat();
    }

    /**
     * 定时任务,关闭活动结束的team和用户状态
     */
    @PostMapping("/setUserActiviteStatus")
    @Inner
    public void setUserActiviteStatus() {
        kxsBcqtTeamService.setUserActiviteStatus();
    }



    /**
     * 百城千团-加入团队
     *
     * @return 百城千团-加入团队
     */
    @PostMapping("/joinTheTeam")
    public R joinTheTeam(@Valid @RequestBody JoinTheTeamDTO joinTheTeamDTO) {

        return kxsBcqtTeamService.joinTheTeam(joinTheTeamDTO.getId());
    }












}

