package com.fs.course.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsCourseAnswerLogs;
import com.fs.course.param.FsCourseAnswerLogsParam;
import com.fs.course.service.IFsCourseAnswerLogsService;
import com.fs.course.vo.FsCourseAnswerLogsListVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.fs.his.utils.PhoneUtil.encryptPhone;

/**
 * 答题日志Controller
 *
 * @author fs
 * @date 2024-10-26
 */
@RestController
@RequestMapping("/course/courseAnswerLog")
public class FsCourseAnswerLogsController extends BaseController
{
    @Autowired
    private IFsCourseAnswerLogsService fsCourseAnswerLogsService;

    /**
     * 查询答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:list')")
    @PostMapping("/list")
    public R list(@RequestBody  FsCourseAnswerLogsParam param)
    {
        if(param.getPageNum() == null) {
            param.setPageNum(1);
        }
        if(param.getPageSize() == null) {
            param.setPageSize(10);
        }

        if (param.getPhoneMk() != null && param.getPhoneMk() != "") {
            param.setPhone(encryptPhone(param.getPhoneMk()));
        }


        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        List<FsCourseAnswerLogsListVO> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVO(param);

        return R.ok().put("data",new PageInfo<>(list));
    }

    /**
     * 导出答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:export')")
    @Log(title = "答题日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(@RequestBody FsCourseAnswerLogsParam param)
    {
        if (param.getPhoneMk() != null && param.getPhoneMk() != "") {
            param.setPhone(encryptPhone(param.getPhoneMk()));
        }
        List<FsCourseAnswerLogsListVO> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVO(param);
        ExcelUtil<FsCourseAnswerLogsListVO> util = new ExcelUtil<FsCourseAnswerLogsListVO>(FsCourseAnswerLogsListVO.class);
        return util.exportExcel(list, "答题日志数据");
    }

//    /**
//     * 获取答题日志详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:query')")
//    @GetMapping(value = "/{logId}")
//    public AjaxResult getInfo(@PathVariable("logId") Long logId)
//    {
//        return AjaxResult.success(fsCourseAnswerLogsService.selectFsCourseAnswerLogsByLogId(logId));
//    }

//    /**
//     * 新增答题日志
//     */
//    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:add')")
//    @Log(title = "答题日志", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody FsCourseAnswerLogs fsCourseAnswerLogs)
//    {
//        return toAjax(fsCourseAnswerLogsService.insertFsCourseAnswerLogs(fsCourseAnswerLogs));
//    }
//
//    /**
//     * 修改答题日志
//     */
//    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:edit')")
//    @Log(title = "答题日志", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody FsCourseAnswerLogs fsCourseAnswerLogs)
//    {
//        return toAjax(fsCourseAnswerLogsService.updateFsCourseAnswerLogs(fsCourseAnswerLogs));
//    }
//
//    /**
//     * 删除答题日志
//     */
//    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:remove')")
//    @Log(title = "答题日志", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{logIds}")
//    public AjaxResult remove(@PathVariable Long[] logIds)
//    {
//        return toAjax(fsCourseAnswerLogsService.deleteFsCourseAnswerLogsByLogIds(logIds));
//    }
}
