package com.yunyan.web.controller.business;

import com.yunyan.business.pojo.admin.dto.ReportAttachmentDto;
import com.yunyan.business.pojo.admin.dto.ReportAttachmentItemDto;
import com.yunyan.business.service.IReportFileService;
import com.yunyan.common.annotation.Log;
import com.yunyan.common.core.controller.BaseController;
import com.yunyan.common.core.domain.AjaxResult;
import com.yunyan.common.core.domain.AjaxResultVo;
import com.yunyan.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 报告的附件文件Controller
 *
 * @author yunyan
 * @date 2023-12-21
 */
@Api(tags = "报告-文件相关(附件)")
@RestController
@RequestMapping("/business/reportFile")
public class ReportFileController extends BaseController
{
    @Autowired
    private IReportFileService reportFileService;

    @PostMapping(value = "/reportAttachmentImport")
    @ApiOperation(value="300-报告附件上传(目前只有预算)", notes="300-报告附件上传(目前只有预算)")
    @Log(title = "报告附件上传", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('business:reportFile:reportAttachmentImport')")
    public AjaxResultVo reportAttachmentImport(@Validated @RequestBody ReportAttachmentDto dto) throws Exception
    {
        return reportFileService.reportAttachmentImport(dto);
    }

    @PreAuthorize("@ss.hasPermi('business:reportFile:reportAttachmentInfo')")
    @ApiOperation(value="300-查询报告的附件", notes="查询报告的附件")
    @GetMapping(value = "/reportAttachmentInfo/{reportId}")
    public AjaxResultVo<List<ReportAttachmentItemDto>> reportAttachmentInfo(@PathVariable Long reportId)
    {
        return reportFileService.reportAttachmentInfo(reportId);
    }

    @ApiOperation(value="300-删除报告的附件文件", notes="删除报告的附件文件")
    @PreAuthorize("@ss.hasPermi('business:reportFile:remove')")
    @Log(title = "删除报告的附件文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/remove/{ids}")
    public AjaxResultVo remove(@PathVariable Long[] ids)
    {

        //去掉 json中的 文件名
        //return toAjax(reportFileService.removeByIds(Arrays.asList(ids)));
        return reportFileService.remove(ids);
    }

}
