package com.gree.mall.manager.controller.comlist;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.comlist.ComListAllLogic;
import com.gree.mall.manager.logic.comlist.ComListLogic;
import com.gree.mall.manager.plus.entity.ComDetailLog;
import com.gree.mall.manager.plus.entity.ComList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@RestController
@Api(value = "文件下发api", tags = {"文件下发api"})
@RequestMapping(value = "/comAll/list", produces = "application/json; charset=utf-8")
public class ComListAllController {

    @Autowired
    ComListAllLogic comListAllLogic;


    @GetMapping("/list")
    @ApiOperation(value = "万能通用附件列表")
    public ResponseHelper<ComList> list(
            @ApiParam(required = false, value = "标题") @RequestParam(required = false) String title,
            @ApiParam(required = false, value = "备注") @RequestParam(required = false) String remark,
            @ApiParam(required = false, value = "是否强制提醒 true/false") @RequestParam(required = false) Boolean isNotice,
            @ApiParam(required = true, value = "页号") @RequestParam(required = true) Integer pageNo,
            @ApiParam(required = true, value = "页大小") @RequestParam(required = true) Integer pageSize,
            HttpServletRequest request
    ) {
        IPage<ComList> list = comListAllLogic.list(title, remark, isNotice, pageNo, pageSize, request);
        return ResponseHelper.success(list);
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除万能通用附件")
    public ResponseHelper list(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id,
            HttpServletRequest request
    ) {
        comListAllLogic.delete(id, request);
        return ResponseHelper.success();
    }

    @PostMapping("/yonge")
    @ApiOperation(value = "上传万能通用列表附件")
    public ResponseHelper yonge(
            @ApiParam(required = true, value = "标题") @RequestParam(required = true) String title,
            @ApiParam(required = false, value = "备注") @RequestParam(required = false) String remark,
            @ApiParam(required = true, value = "file") @RequestParam(required = true) String file,
            @ApiParam(required = false, value = "是否强制通知 true=是 false=否") @RequestParam(required = false) Boolean isNotice,
            @ApiParam(required = false, value = "下载密码") @RequestParam(required = false) String downloadPwd,
            HttpServletRequest request
    ) throws Exception {
        comListAllLogic.yonge(title, remark, file, isNotice, downloadPwd, request);
        return ResponseHelper.success();
    }

    @GetMapping("/download")
    @ApiOperation(value = "下载万能通用列表附件")
    public void down(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id,
            @ApiParam(required = false, value = "下载密码") @RequestParam(required = false) String downloadPwd,
            HttpServletRequest request, HttpServletResponse response
    ) throws Exception {
        comListAllLogic.download(id, downloadPwd, request, response);
        //return ResponseHelper.success(download);
    }
    @GetMapping("/download/log")
    @ApiOperation(value = "下载记录")
    public ResponseHelper<IPage<ComDetailLog>> downlog(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id,
            @ApiParam(required = true, value = "页号") @RequestParam(required = true) Integer pageNo,
            @ApiParam(required = true, value = "页大小") @RequestParam(required = true) Integer pageSize,
            HttpServletRequest request
    ) throws Exception {
        IPage<ComDetailLog> comDetailLogIPage = comListAllLogic.logList(id, pageNo, pageSize, request);
        return ResponseHelper.success(comDetailLogIPage);
    }



}
