package com.ywt.mg.web.controllers;


import com.ywt.mg.core.MGRight;
import com.ywt.mg.core.MGRightTypeDef;
import com.ywt.mg.params.downloadRecord.DownloadFileRequest;
import com.ywt.mg.params.downloadRecord.QueryDownloadRecordListRequest;
import com.ywt.mg.services.AuthService;
import com.ywt.mg.services.DownloadRecordService;
import com.ywt.mg.web.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController("/downloadRecord")
@RequestMapping({"/downloadRecord"})
@MGRight
@Api(description = "公司后台-下载记录相关接口，前缀：downloadRecord")
public class DownloadRecordController {

    private static Logger logger = LoggerFactory.getLogger(DownloadRecordController.class);

    @Autowired
    private AuthService authService;

    @Autowired
    private DownloadRecordService downloadRecordService;

    @ApiOperation(value = "按条件查询下载记录列表")
    @RequestMapping(value = {"/downloadRecordList"}, method = RequestMethod.POST)
    @MGRight(menuCode = {"/downloadRecord/queryDownloadRecordList"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    BaseResponse queryDownloadRecordList(@Validated @RequestBody QueryDownloadRecordListRequest request) throws Exception {
        request.setHospitalId(0);
        int adminId = authService.getCurrentAdminId();
        request.setAdminId(adminId);
         return downloadRecordService.queryDownloadRecordList(request);
    }

    @ApiOperation(value = "下载文件")
    @RequestMapping(value = {"/downloadFile"}, method = RequestMethod.GET)
    @MGRight(menuCode = {"/downloadRecord/downloadFile"}, type = MGRightTypeDef.Menu | MGRightTypeDef.Logined)
    public void downloadFile(@Validated DownloadFileRequest request, HttpServletResponse httpServletResponse) {
        downloadRecordService.downloadFile(request, httpServletResponse);
    }

}
