package com.fs.course.controller.qw;

import com.fs.common.annotation.Log;
import com.fs.common.constant.HttpStatus;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.course.param.FsCourseAnswerLogsParam;
import com.fs.course.service.IFsCourseAnswerLogsService;
import com.fs.course.vo.FsCourseAnswerLogsListVO;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

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

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

    @Autowired
    private TokenService tokenService;
    /**
     * 查询答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCourseAnswerLogsParam param)
    {
        if (param.getPhoneMk() != null && param.getPhoneMk() != "") {
            param.setPhone(encryptPhone(param.getPhoneMk()));
        }

        List<FsCourseAnswerLogsListVO> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVO(param);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVOCount(param));
        return rspData;
    }

    /**
     * 查询答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:myList')")
    @GetMapping("/myList")
    public TableDataInfo myList(FsCourseAnswerLogsParam param)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId( loginUser.getCompany().getCompanyId());

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

        List<FsCourseAnswerLogsListVO> list = fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVO(param);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(fsCourseAnswerLogsService.selectFsCourseAnswerLogsListVOCount(param));
        return rspData;
    }
    /**
     * 导出答题日志列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseAnswerLog:export')")
    @Log(title = "答题日志", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(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:myExport')")
    @Log(title = "答题日志", businessType = BusinessType.EXPORT)
    @GetMapping("/myExport")
    public AjaxResult myExport(FsCourseAnswerLogsParam param)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId( loginUser.getCompany().getCompanyId());

        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));
//    }
}
