package com.zhongzheng.controller.plan;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.*;
import com.zhongzheng.modules.course.domain.Course;
import com.zhongzheng.modules.course.vo.CourseVo;
import com.zhongzheng.modules.goods.vo.GoodsVo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.user.vo.UserPlanVo;
import com.zhongzheng.modules.user.bo.UserPlanQueryBo;
import com.zhongzheng.modules.user.bo.UserPlanAddBo;
import com.zhongzheng.modules.user.bo.UserPlanEditBo;
import com.zhongzheng.modules.user.service.IUserPlanService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 学习计划Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@Api(value = "学习计划控制器", tags = {"学习计划管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/plan")
public class UserPlanController extends BaseController {

    private final IUserPlanService iUserPlanService;


    private final WxTokenService wxTokenService;
    /**
     * 查询学习计划列表
     */
    @ApiOperation("查询学习计划列表")
    @GetMapping("/list")
    public TableDataInfo<UserPlanVo> list(UserPlanQueryBo bo) {
        startPage();
        List<UserPlanVo> list = iUserPlanService.queryList(bo);
        return getDataTable(list);
    }
    

    /**
     * 获取学习计划详细信息
     */
    @ApiOperation("获取学习计划详细信息")
    @GetMapping("/{planId}")
    public AjaxResult<UserPlanVo> getInfo(@PathVariable("planId" ) Long planId) {
        return AjaxResult.success(iUserPlanService.queryById(planId));
    }

    /**
     * 新增学习计划
     */
    @ApiOperation("新增学习计划")
    @Log(title = "学习计划", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody UserPlanAddBo bo) {
        return toAjax(iUserPlanService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改学习计划
     */
    @ApiOperation("修改学习计划")
    @Log(title = "学习计划", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody UserPlanEditBo bo) {
        return toAjax(iUserPlanService.updateByEditBo(bo) ? 1 : 0);
    }


    /**
     * 查询学习计划列表
     */
    @ApiOperation("获得展示的日历学习计划，不添加到数据库")
    @GetMapping("/listPlan")
    public AjaxResult<UserPlanVo> listPlan(UserPlanEditBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        UserPlanVo list = iUserPlanService.listPlan(bo);
        return AjaxResult.success(list);
    }

    /**
     * 查询学习计划列表
     */
 /*   @ApiOperation("查询学员拥有商品能生成学习计划的商品")
    @GetMapping("/listGoods")
    public TableDataInfo<GoodsVo> listGoods(UserPlanQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<GoodsVo> list = iUserPlanService.listGoods(bo);
        return getDataTable(list);
    }*/
}
