package com.sundot.airport.web.controller.exam;

import com.sundot.airport.exam.common.HttpResult;
import com.sundot.airport.exam.common.PageData;
import com.sundot.airport.exam.logic.manage.model.params.*;
import com.sundot.airport.exam.logic.manage.model.result.*;
import com.sundot.airport.exam.logic.manage.service.ExamBizService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <b>功能名：</b>ExamController<br>
 * <b>说明：</b> 考试管理表管理 225200 - 225299 <br>
 * <b>著作权：</b> Copyright (C) 2021 HUIFANEDU  CORPORATION<br>
 * <b>修改履历：
 *
 * @author 2021-06-23 liangxiao
 */
@RestController
@RequestMapping("/v1/cs/manage/exam")
public class ExamController extends BaseController {

    @Resource
    private ExamBizService examBizService;

    /**
     * <b>方法名: </b> page <br>
     * <b>说明: </b> 考试管理表分页列表 <br>
     *
     * @param param com.sundot.airport.model.params.ExamPageParam 考试管理表分页列表请求参数
     * @return com.huifanedu.kernel.model.response.HttpResult<com.huifanedu.kernel.model.pager.PageData < com.sundot.airport.model.result.ExamPageResult>>
     * <b>修改履历: </b>
     * @author 2021-06-23 liangxiao
     */
    @PostMapping("/list")
    public HttpResult<PageData<ExamPageResult>> page(@RequestBody ExamPageParam param) {
        return examBizService.pageList(param);
    }

    /**
     * <b>方法名: </b> get <br>
     * <b>说明: </b> 考试管理表详情 <br>
     *
     * @param exId java.lang.String 考试业务id
     * @return com.huifanedu.kernel.model.response.HttpResult<com.sundot.airport.model.result.ExamGetResult>
     * <b>修改履历: </b>
     * @author 2021-06-23 liangxiao
     */
    @GetMapping("")
    public HttpResult<ExamGetResult> get(@RequestParam("exId") String exId) {
        HttpResult<ExamGetResult> res = examBizService.get(exId);
        if (res.getModel().getExExamTime() != null && res.getModel().getExExamTime() > 0) {
            // 数据库中保存的时间为秒 前端需要分钟
            res.getModel().setExExamTime(res.getModel().getExExamTime() / 60);
        }
        return res;
    }

    /**
     * <b>方法名: </b> add <br>
     * <b>说明: </b> 考试管理表添加 <br>
     *
     * @param param com.sundot.airport.model.params.ExamAddParam 考试管理表添加请求参数
     * @return com.huifanedu.kernel.model.response.HttpResult<com.sundot.airport.model.result.ExamAddResult>
     * <b>修改履历: </b>
     * @author 2021-06-23 liangxiao
     */
    @PostMapping("")
    public HttpResult<ExamAddResult> add(@Valid @RequestBody ExamAddParam param) {
        if (param.getExExamTime() > 0) {
            // 前端传入分钟 数据库中为秒
            param.setExExamTime(param.getExExamTime() * 60);
        }
        return examBizService.add(param);
    }

    /**
     * <b>方法名: </b> delete <br>
     * <b>说明: </b> 考试管理表删除 <br>
     *
     * @param param com.sundot.airport.model.params.ExamDelParam 考试管理表删除请求参数
     * @return com.huifanedu.kernel.model.response.HttpResult<java.lang.Boolean>
     * <b>修改履历: </b>
     * @author 2021-06-23 liangxiao
     */
    @DeleteMapping("")
    public HttpResult<Boolean> del(@Valid @RequestBody ExamDelParam param) {
        return examBizService.delete(param);
    }

    /**
     * <b>方法名: </b> update <br>
     * <b>说明: </b> 考试管理表修改 <br>
     *
     * @param param com.sundot.airport.model.params.ExamUpdParam 考试管理表修改请求参数
     * @return com.huifanedu.kernel.model.response.HttpResult<java.lang.Boolean>
     * <b>修改履历: </b>
     * @author 2021-06-23 liangxiao
     */
    @PutMapping("")
    public HttpResult<Boolean> update(@Valid @RequestBody ExamUpdParam param) {
        if (param.getExExamTime() > 0) {
            // 前端传入分钟 数据库为秒
            param.setExExamTime(param.getExExamTime() * 60);
        }
        return examBizService.update(param);
    }

    /**
     * <b>方法名: </b> recordList <br>
     * <b>说明: </b> 考试批阅列表 <br>
     *
     * @param param com.sundot.airport.logic.manage.model.params.ExamRecordPageParam 考试记录查询的参数封装
     * @return com.huifanedu.kernel.model.response.HttpResult<com.huifanedu.kernel.model.pager.PageData < com.sundot.airport.logic.manage.model.result.ExamRecordPageResult>><br>
     * <b>修改履历: </b>
     * @author 2021/7/6 liangxiao
     */
    @PostMapping("/record_list")
    public HttpResult<PageData<ExamRecordPageResult>> recordList(@Valid @RequestBody ExamRecordPageParam param) {
        return examBizService.recordList(param);
    }

    /**
     * <b>方法名: </b> recordDetail <br>
     * <b>说明: </b> 考试记录详情 <br>
     *
     * @param erId java.lang.String 测试记录业务id
     * @return com.huifanedu.kernel.model.response.HttpResult<com.huifanedu.kernel.model.pager.PageData < com.sundot.airport.logic.manage.model.result.ExamRecordDetailResult>><br>
     * <b>修改履历: </b>
     * @author 2021/7/6 liangxiao
     */
    @GetMapping("/record_detail")
    public HttpResult<ExamRecordDetailResult> recordDetail(@RequestParam("erId") String erId) {
        return examBizService.recordDetail(erId);
    }

}
