package com.yida.data.school.transaction.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.apply.EduProductNoticeStudent;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.transaction.ListBuyStudentDTO;
import com.yida.data.school.transaction.service.EduProductNoticeService;
import com.yida.data.school.transaction.service.EduProductNoticeStudentService;
import com.yida.data.user.vo.ListParentByStudentIdsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 催缴通知对应接收学生表 Controller
 *
 * @author ccl
 * @date 2021-09-03 15:33:47
 */

@Api(tags = "交易-商品催缴学生")
@Slf4j
@Validated
@RestController
@RequestMapping("/transaction/productNoticeStudent")
@RequiredArgsConstructor
public class EduProductNoticeStudentController {

    private final EduProductNoticeStudentService eduProductNoticeStudentService;
    private final EduProductNoticeService eduProductNoticeService;

    @PostMapping("/batchPutNotice")
    @ApiOperation("批量催缴")
    public ResultBean<String> batchPutNotice(@RequestBody List<EduProductNoticeStudent> eduProductNoticeStudents) {
        eduProductNoticeStudentService.batchPutNotice(eduProductNoticeStudents);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("全部催缴")
    @PostMapping("/allPutNotice")
    public ResultBean allPutNotice(@RequestBody EduProductNoticeStudent eduProductNoticeStudent) {
        eduProductNoticeStudentService.allPutNotice(eduProductNoticeStudent);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("通知记录")
    @GetMapping("/findRecordList")
    public ResultBean<IPage<EduProductNoticeStudent>> findRecordList(@RequestParam Long productId,
                                                                    @RequestParam Integer size,
                                                                    @RequestParam Integer pageNum) {
        Page page = new Page();
        page.setSize(size);
        page.setCurrent(pageNum);
        return ResultBean.buildSuccess(eduProductNoticeStudentService.findRecordList(page, productId));
    }

    @ApiOperation("查询通知记录对应家长")
    @GetMapping("/findRecordParent")
    public ResultBean<IPage<ListParentByStudentIdsVO>> findRecordParent(@RequestParam Long noticeId,
                                                                        @RequestParam Integer size,
                                                                        @RequestParam Integer pageNum) {
        Page page = new Page();
        page.setSize(size);
        page.setCurrent(pageNum);

        return ResultBean.buildSuccess(eduProductNoticeStudentService.findRecordParent(page, noticeId));
    }

    /**
     * 导出excel
     */
    @ApiOperation("导出未购买学生")
    @PostMapping("/StudentNotBuyExport")
    public void studentNotBuyExport(ListBuyStudentDTO listBuyStudentDTO, HttpServletResponse response) {

        Long deptId = FebsUtil.getCurrentUser().getDeptId();
        listBuyStudentDTO.setSchoolId(deptId);
        eduProductNoticeStudentService.studentNotBuyExport(listBuyStudentDTO, response);
    }

    /**
     * 导出excel
     */
    @ApiOperation("导出需要续费的学生")
    @ResponseBody
    @PostMapping("/studentBuyExport")
    public void studentBuyExport(@RequestBody ListBuyStudentDTO listBuyStudentDTO, HttpServletResponse response) {

        eduProductNoticeStudentService.studentBuyExport(listBuyStudentDTO, response);
    }
}
