package com.yida.data.device.telephone.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.device.dto.telephone.RecordPageDTO;
import com.yida.data.device.telephone.service.EduTelephoneRecordService;
import com.yida.data.device.vo.telephone.FamilyRecordVO;
import com.yida.data.device.vo.telephone.RecordInfoVO;
import com.yida.data.device.vo.telephone.TelephoneSummaryVO;
import com.yida.data.school.vo.news.TelephoneCountVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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 zhanghaijun
 * @date 2021-08-10 17:01:40
 */
@Api(tags = "亲情电话-通话记录")
@Slf4j
@Validated
@RestController
@RequestMapping("/telephone/record")
@RequiredArgsConstructor
public class EduTelephoneRecordController {

    private final EduTelephoneRecordService eduTelephoneRecordService;

    @ApiOperation("分页查询通话记录")
    @GetMapping("/listRecordPage")
    public ResultBean<IPage<RecordInfoVO>> listRecordPage(RecordPageDTO dto) {
        return ResultBean.buildSuccess(eduTelephoneRecordService.listRecordPage(dto));
    }

    @ApiModelProperty("导出数据")
    @PostMapping("/export")
    public void exportRecord(RecordPageDTO dto, HttpServletResponse response) {
        eduTelephoneRecordService.exportRecord(dto, response);
    }


    @ApiModelProperty("查询实时电话数，充值总额，使用总人数")
    @GetMapping("/getTotalNum")
    public ResultBean<TelephoneCountVO> getTotalNum(@ApiParam("学校id") @RequestParam Long schoolId,
                                                    @ApiParam("0总计，1今日，2本月") @RequestParam Integer type) {

        return ResultBean.buildSuccess(eduTelephoneRecordService.getTotalNum(schoolId, type));
    }

    @ApiModelProperty("查询通话概况")
    @GetMapping("/callSummary")
    public ResultBean<List<TelephoneSummaryVO>> callSummary(@ApiParam("0全部，1近一个月内，2近一周内，3近一天") @RequestParam Integer type,
                                                      @ApiParam("学校id") @RequestParam Long schoolId) {

        return ResultBean.buildSuccess(eduTelephoneRecordService.callSummary(type, schoolId));
    }

    @ApiOperation("查询通话记录")
    @GetMapping("/listRecord")
    public ResultBean<IPage<RecordInfoVO>> listRecord(RecordPageDTO dto) {
        return ResultBean.buildSuccess(eduTelephoneRecordService.listRecordPage(dto));
    }

    @ApiOperation("前台使用通话记录查询")
    @GetMapping("/listFamilyRecord")
    public ResultBean<List<FamilyRecordVO>> listFamilyRecord(@ApiParam("IC卡Id") @RequestParam Long cardId) {
        return ResultBean.buildSuccess(eduTelephoneRecordService.listFamilyRecord(cardId));
    }

}
