package com.xjrsoft.module.evaluate.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.evaluate.dto.*;
import com.xjrsoft.module.evaluate.service.IEvaluateManageService;
import com.xjrsoft.module.evaluate.service.IEvaluateResultService;
import com.xjrsoft.module.evaluate.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* @title: 评价项
* @Author szs
* @Date: 2024-01-15
* @Version 1.0
*/
@RestController
@RequestMapping("/evaluate" + "/evaluatewrite")
@Api(value = "/evaluate"  + "/evaluatewrite",tags = "移动端评价管理代码")
@AllArgsConstructor
public class EvaluateWriteController {


    private final IEvaluateManageService evaluateManageService;

    private final IEvaluateResultService evaluateResultService;

    @GetMapping(value = "/index-page")
    @ApiOperation(value="评价管理首页列表(分页)")
    @SaCheckPermission("evaluatemanage:detail")
    public RT<PageOutput<MobileIndexPageVo>> indexPage(@Valid MobileIndexPageDto dto){
        dto.setLoginUserId(StpUtil.getLoginIdAsLong());
        Page<MobileIndexPageVo> page = evaluateManageService.getMobileIndexPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<MobileIndexPageVo> pageOutput = ConventPage.getPageOutput(page, MobileIndexPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/result-page")
    @ApiOperation(value="评价结果页列表(分页)")
    @SaCheckPermission("evaluatemanage:detail")
    public RT<PageOutput<MobileResultPageVo>> resultPage(@Valid MobileResultPageDto dto){
        dto.setLoginUserId(StpUtil.getLoginIdAsLong());
        Page<MobileResultPageVo> page = evaluateManageService.getMobileResultPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<MobileResultPageVo> pageOutput = ConventPage.getPageOutput(page, MobileResultPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/drill-ev-class-list")
    @ApiOperation(value="教官当天评价班级集合")
    @SaCheckPermission("evaluatemanage:detail")
    public RT<List<DrillEvaluateClassListVo>> drillEvClassList(@Valid DrillEvaluateClassListDto dto){
        dto.setLoginUserId(StpUtil.getLoginIdAsLong());
        List<DrillEvaluateClassListVo> list = evaluateManageService.getDrillEvaluateClassList(dto);
        return RT.ok(list);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询评价项信息")
    @SaCheckPermission("evaluateitem:detail")
    public RT<EvaluateWriteVo> info(@RequestParam Long id){
        EvaluateWriteVo evaluateWriteVo = evaluateManageService.getWriteInfo(id);
        if (evaluateWriteVo == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(evaluateWriteVo);
    }

    @GetMapping(value = "/item-list")
    @ApiOperation(value="评价题目列表")
    @SaCheckPermission("evaluatemanage:detail")
    public RT<List<EvaluateManageItemVo>> itemList(@RequestParam Long id){
        List<EvaluateManageItemVo> itemList = evaluateManageService.getItemList(id);
        return RT.ok(itemList);
    }

    @GetMapping(value = "/result-list")
    @ApiOperation(value="评价结果列表")
    @SaCheckPermission("evaluatemanage:detail")
    public RT<List<EvaluateManageItemVo>> resultList(@Valid ResultListDto dto){
        List<EvaluateManageItemVo> itemList = evaluateManageService.getResultList(dto);
        return RT.ok(itemList);
    }

    @PostMapping
    @ApiOperation(value = "评价对象保存")
    @SaCheckPermission("evaluateobject:save")
    public RT<String> save(@Valid @RequestBody EvaluateResultSaveDto dto){
        String isSuccess = evaluateResultService.saveBatch(dto);
        return RT.ok(isSuccess);
    }
}