package com.miaxis.app.controller.h5;

import com.miaxis.common.annotation.Log;
import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.enums.BusinessTypeEnum;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.score.domain.ScoreInfo;
import com.miaxis.score.dto.ScoreInfoAllDTO;
import com.miaxis.score.dto.ScoreInfoDTO;
import com.miaxis.score.service.IScoreInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 【模拟考成绩】Controller
 *
 * @author miaxis
 * @date 2021-08-23
 */
@RestController
@RequestMapping(Constants.STUDENT_PREFIX+"/score/info")
@Api(tags={"【H5-模拟考成绩】"})
public class ScoreInfoController extends BaseController {
    @Autowired
    private IScoreInfoService scoreInfoService;

    /**
     * 查询模拟考成绩列表
     */
    @GetMapping("/list")
    @ApiOperation("查询模拟考成绩列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码" ,dataType = "int", paramType = "query", required = false),
            @ApiImplicitParam(name = "pageSize",value = "每页数据量" , dataType = "int", paramType = "query", required = false),
    })
    public ResponsePageInfo<ScoreInfo> list(){
        startPage();
        ScoreInfo scoreInfo = new ScoreInfo();
        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
        System.out.println();
        List<ScoreInfo> list = scoreInfoService.selectScoreInfoList(scoreInfo);
        return toResponsePageInfo(list);
    }



    /**
     * 获取模拟考成绩详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取模拟考成绩详细信息")
    public Response<ScoreInfo> getInfo(
            @ApiParam(name = "id", value = "模拟考成绩参数", required = true)
            @PathVariable("id") Long id
    ){
        return Response.success(scoreInfoService.getById(id));
    }

    /**
     * 新增模拟考成绩
     */
    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    @ApiOperation("新增模拟考成绩")
    public Response<Integer> add(@RequestBody ScoreInfoDTO scoreInfoDTO){
        ScoreInfo scoreInfo = new ScoreInfo();
        BeanUtils.copyProperties(scoreInfoDTO,scoreInfo);
        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
        return toResponse(scoreInfoService.save(scoreInfo) ? 1 : 0);
    }

    /**
     * 修改模拟考成绩
     */
    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    @ApiOperation("修改模拟考成绩")
    public Response<Integer> edit(@RequestBody ScoreInfo scoreInfo){
        return toResponse(scoreInfoService.updateById(scoreInfo) ? 1 : 0);
    }

    /**
     * 删除模拟考成绩
     */
    @Log(title = "模拟考成绩", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除模拟考成绩")
    public Response<Integer> remove(
            @ApiParam(name = "ids", value = "模拟考成绩ids参数", required = true)
            @PathVariable Long[] ids
    ){
        return toResponse(scoreInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    /**
     * 获取预测成功
     */
//    @GetMapping(value = "/forecastScore")
//    @ApiOperation("获取预测成绩")
//    public Response<Integer> getInfo(){
//        ScoreInfo scoreInfo = new ScoreInfo();
//        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
//        int forecastScore = scoreInfoService.getForecastScore(scoreInfo);
//        return Response.success(forecastScore);
//    }


    /**
     * 获取预测成功
     */
//    @GetMapping(value = "/avgScore")
//    @ApiOperation("获取平均成绩")
//    public Response<Integer> getAvgScore(){
//        ScoreInfo scoreInfo = new ScoreInfo();
//        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
//        int aveScore = scoreInfoService.getAveScore(scoreInfo);
//        return Response.success(aveScore);
//    }



    /**
     * 获取最大成绩，平均成绩，预测成绩
     */
    @GetMapping(value = "/getScoreInfoAll")
    @ApiOperation("获取最大成绩，平均成绩，预测成绩")
    public Response<ScoreInfoAllDTO> getScoreInfoAll(){
        ScoreInfo scoreInfo = new ScoreInfo();
        scoreInfo.setUserId(SecurityUtils.getLoginUser().getStudent().getId());
        ScoreInfoAllDTO scoreInfoAllDTO = scoreInfoService.getScoreInfoAll(scoreInfo);
        return Response.success(scoreInfoAllDTO);
    }
}
