package com.zd.exam.controller;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.SecurityUtils;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.exam.domain.ElPointsLoginfo;
import com.zd.exam.domain.dto.ElPointsRecordDTO;
import com.zd.exam.domain.vo.ElPointsLoginfoVO;
import com.zd.exam.domain.vo.ElPointsRecordListVO;
import com.zd.exam.service.IElPointsRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zhoupan
 * @Date: 2021/09/07/13:53
 * @Description:
 */
@RestController
@RequestMapping("/rewardPoint")
@Api(tags = {"积分记录"})
public class ElrewardPointController extends BaseController {

    @Autowired
    private IElPointsRecordService pointsRecordService;

    /**
     * 查询积分记录列表  "points:record:list"
     */
    @ApiOperation(value = "查询积分记录列表 " ,notes="权限字符："+PerPrefix.EXAM_EL_CATEGORY+ PerFun.LIST)
    @PreAuthorize(hasPermi = PerPrefix.EXAM_EL_CATEGORY+ PerFun.LIST)
    @GetMapping("/list")
    public TableDataInfo list(ElPointsRecordDTO pointsRecordDTO) {
        startPage();
        List<ElPointsRecordListVO> list = pointsRecordService.selectElPointsRecordVOList(pointsRecordDTO);
        return getDataTable(list);
    }

    /**
     * 查询我的积分记录列表
     */
    // @PreAuthorize(hasPermi = "points:record:mylist")
    @ApiOperation(value = "查询我的积分记录列表 ")
    @GetMapping("/list/my")
    public TableDataInfo myList(ElPointsRecordDTO pointsRecordDTO) {
        startPage();
        pointsRecordDTO.setJoinUserId(SecurityUtils.getUserId());
        List<ElPointsRecordListVO> list = pointsRecordService.selectElPointsRecordVOList(pointsRecordDTO);
        return getDataTable(list);
    }



    /**
     * 小程序查询我的积分记录列表
     */
    // @PreAuthorize(hasPermi = "points:record:mylist")
    @RequestMapping("/list/myApp")
    @ApiOperation(value = "小程序查询我的积分记录列表")
    public TableDataInfo myApp(@RequestBody ElPointsRecordDTO pointsRecordDTO) {
        startPage(pointsRecordDTO.getAppPageNum(),pointsRecordDTO.getAppPageSize());
        pointsRecordDTO.setJoinUserId(SecurityUtils.getUserId());
        List<ElPointsRecordListVO> list = pointsRecordService.selectElPointsRecordVOList(pointsRecordDTO);
        return getDataTable(list);
    }

    /**
     * 小程序查询我的积分记录统计
     */
    // @PreAuthorize(hasPermi = "points:record:mylist")
    @RequestMapping("/count/myApp")
    @ApiOperation(value = "小程序查询我的积分记录统计")
    public AjaxResult countMyApp() {
        ElPointsRecordDTO pointsRecordDTO = new ElPointsRecordDTO();
        pointsRecordDTO.setJoinUserId(SecurityUtils.getUserId());
        Integer count = pointsRecordService.selectElCountPointsRecord(pointsRecordDTO);
        return AjaxResult.success(count==null?0:count);
    }


    /**
     * 查询积分记录日志详情列表
     */
    @GetMapping("/getPointsLoglist")
    @ApiOperation(value = "查询积分记录日志详情列表")
    public TableDataInfo getPointsLoglist(ElPointsLoginfoVO elPointsLoginfoVO) {
        startPage();
        List<ElPointsLoginfo> list = pointsRecordService.getPointsLoglist(elPointsLoginfoVO);
        return getDataTable(list);
    }




}
