package jnpf.cultivate.controller.web.teaching;

import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.TeachingRecordService;
import jnpf.model.cultivate.dto.teaching.QueryTeachingRecordDto;
import jnpf.model.cultivate.vo.teaching.TeachingDataListVo;
import jnpf.model.cultivate.vo.teaching.TeachingRecordVo;
import jnpf.model.cultivate.vo.teaching.TeachingStoreListVo;
import jnpf.util.FtbUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 带教管理
 */
@Slf4j
@RestController
@RequestMapping("/web/teachingRecord")
public class TeachingController {

    @Autowired
    private TeachingRecordService teachingRecordService;


    /**
     * 汇总数据-带教-分页列表
     * @param queryTeachingRecordDto
     * @return ActionResult<PageListVO<TeachingDataListVo>>
     */
    @PostMapping("/summaryTeach")
    public ActionResult<PageListVO<TeachingDataListVo>> summaryTeach(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        PageInfo<TeachingDataListVo> pageInfo = teachingRecordService.teachingSummaryPage(queryTeachingRecordDto);
        return ActionResult.page(pageInfo.getList(), FtbUtil.getPagination(pageInfo));
    }

    /**
     * 汇总数据-带教-导出
     * @param queryTeachingRecordDto
     * @return void
     */
    @PostMapping("/summaryTeachExport")
    public void summaryTeachExport(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        teachingRecordService.summaryTeachExport(queryTeachingRecordDto);
    }

    /**
     * 查看带教门店下拉列表
     * @return ActionResult<TeachingRecordDetailVo>
     */
    @GetMapping("/storeList")
    public ActionResult<List<TeachingStoreListVo>> storeList() {
        List<TeachingStoreListVo> teachingStoreList = teachingRecordService.getTeachingStoreList();
        return ActionResult.success(teachingStoreList);
    }

    /**
     * 带教汇总详情页-学员统计
     * @param queryTeachingRecordDto
     * @return
     */
    @PostMapping("/summaryTeachDetailPage")
    public ActionResult<PageListVO<TeachingDataListVo>> summaryTeachDetailPage(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        PageInfo<TeachingDataListVo> voPageInfo = teachingRecordService.teachingStudentDataCount(queryTeachingRecordDto);
        return ActionResult.page(voPageInfo.getList(), FtbUtil.getPagination(voPageInfo));
    }

    /**
     * 带教汇总详情页-学员统计-导出
     * @param queryTeachingRecordDto
     * @return
     */
    @PostMapping("/studentDetailExport")
    public void studentDetailExport(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        teachingRecordService.studentDetailExport(queryTeachingRecordDto);
    }

    /**
     * 带教明细 - 分页列表查询
     * @param queryTeachingRecordDto
     * @return
     */
    @PostMapping("/detailItemTeachPage")
    public ActionResult<PageListVO<TeachingRecordVo>> detailItemTeachPage(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        queryTeachingRecordDto.setIsDataPermission(true);
        PageInfo<TeachingRecordVo> page = teachingRecordService.page(queryTeachingRecordDto);
        return ActionResult.page(page.getList(), FtbUtil.getPagination(page));
    }

    /**
     * 带教明细-导出
     * @param queryTeachingRecordDto
     */
    @PostMapping("/detailItemTeachExport")
    public void detailItemTeachExport(@RequestBody QueryTeachingRecordDto queryTeachingRecordDto) {
        teachingRecordService.detailItemTeachExport(queryTeachingRecordDto);
    }

    /**
     * 带教明细-批量删除
     * @param ids 记录id集合
     * @return Void
     */
    @DeleteMapping("/detailItemDelete")
    public ActionResult<Void> detailItemDelete(@RequestBody List<String> ids) {
        teachingRecordService.batchDeleteRecord(ids);
        return ActionResult.success();
    }
}