package com.gz.controller.archive;

import com.github.pagehelper.PageInfo;
import com.gz.core.exception.BusinessException;
import com.gz.dto.system.ArchiveFileDTO;
import com.gz.rvo.archive.ArchiveFileRVO;
import com.gz.service.archive.ArchiveFileService;
import com.gz.vo.archive.SearchArchiveFileVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * 文档附件控制器
 *
 * @author LiuchangLan
 * @date 2020/9/9 11:23
 */
@RestController
@RequestMapping("archive/archiveFile")
public class ArchiveFileController {

    @Resource
    private ArchiveFileService archiveFileService;

    @PostMapping("upload")
    public ArchiveFileDTO upload(@RequestBody MultipartFile file, Integer archiveId, Integer fileType, Integer secondaryArchiveId) throws IOException, BusinessException {
        return archiveFileService.upload(file, archiveId, fileType,secondaryArchiveId);
    }

    @DeleteMapping("delete")
    Integer delete(Integer id) {
        return archiveFileService.delete(id);
    }

    @GetMapping("selectByPage")
    PageInfo<ArchiveFileRVO> selectByPage(SearchArchiveFileVO vo) {
        return archiveFileService.selectByPage(vo);
    }

    @GetMapping("selectByArchiveId")
    List<ArchiveFileRVO> selectByArchiveId(SearchArchiveFileVO vo){
        return archiveFileService.selectByArchiveId(vo);
    }
}
