package com.zhongzheng.controller.activity;

import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.activity.bo.ActivityTaskQueryBo;
import com.zhongzheng.modules.activity.bo.ActivityTaskUserAddBo;
import com.zhongzheng.modules.activity.service.IActivityTaskService;
import com.zhongzheng.modules.activity.service.IActivityTaskUserService;
import com.zhongzheng.modules.activity.vo.ActivityTaskVo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Scanner;

/**
 * 任务存储Controller
 * 
 * @author change
 * @date 2021-05-19
 */
@Api(value = "任务存储控制器", tags = {"任务存储管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/task")
public class ActivityTaskController extends BaseController {

    private final IActivityTaskService iActivityTaskService;

    private final IActivityTaskUserService activityTaskUserService;

    private final com.zhongzheng.framework.web.service.WxTokenService WxTokenService;


    /**
     * 查询任务積分列表
     */
    @ApiOperation("查询任务積分列表")
    @GetMapping("/list")
    public TableDataInfo<ActivityTaskVo> listUser(ActivityTaskQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<ActivityTaskVo> list = iActivityTaskService.querylistUser(bo);
        return getDataTable(list);
    }

    /**
     * 签到获得积分
     */
    @ApiOperation("签到获得积分")
    @Log(title = "签到获得积分", businessType = BusinessType.UPDATE)
    @PostMapping("/signIn")
    public AjaxResult<Void> userTask(@RequestBody ActivityTaskUserAddBo bo) {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.userTask(bo) ? 1 : 0);
    }

    /**
     * 完善信息
     */
  /*  @ApiOperation("完善信息")
    @Log(title = "完善信息", businessType = BusinessType.UPDATE)
    @PostMapping("/information")
    public AjaxResult<Void> information(@RequestBody ActivityTaskUserAddBo bo) throws IllegalAccessException {
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.information(bo) ? 1 : 0);
    }*/



    /**
     * 邀请朋友
     */
    @ApiOperation("邀请朋友")
    @Log(title = "邀请朋友", businessType = BusinessType.UPDATE)
    @PostMapping("/invitation")
    public AjaxResult<Void> invitation(@RequestBody ActivityTaskUserAddBo bo){
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.invitation(bo) ? 1 : 0);
    }

    /**
     * 每日分享
     */
    @ApiOperation("每日分享")
    @Log(title = "每日分享", businessType = BusinessType.UPDATE)
    @PostMapping("/share")
    public AjaxResult<Void> share(@RequestBody ActivityTaskUserAddBo bo){
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.share(bo) ? 1 : 0);
    }

    /**
     * 学习时长
     */
 /*   @ApiOperation("学习时长")
    @Log(title = "学习时长", businessType = BusinessType.UPDATE)
    @PostMapping("/learnTime")
    public AjaxResult<Void> learnTime(@RequestBody ActivityTaskUserAddBo bo){
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.learnTime(bo) ? 1 : 0);
    }*/

    /**
     * 模拟考试
     */
 /*   @ApiOperation("模拟考试")
    @Log(title = "模拟考试", businessType = BusinessType.UPDATE)
    @PostMapping("/practiceTest")
    public AjaxResult<Void> practiceTest(@RequestBody ActivityTaskUserAddBo bo){
        ClientLoginUser loginUser = WxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        return toAjax(activityTaskUserService.practiceTest(bo) ? 1 : 0);
    }*/

}
