package com.jeethink.manage.controller;

import java.util.List;

import com.jeethink.bean.domain.ArchivesMaster;
import com.jeethink.bean.vo.Approval;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.manage.service.IDestroyService;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 销毁清册Controller
 * 
 * @author zjt
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/manage/destroy")
public class DestroyController extends BaseController
{
    @Autowired
    private IDestroyService service;

    /**
     * 申请销毁
     */
    @PreAuthorize("@ss.hasPermi('manage:destroy:add')")
    @GetMapping
    public AjaxResult apply(@RequestParam String archivesId)
    {
        service.applyDestroy(archivesId);
        return AjaxResult.success();
    }

    @PreAuthorize("@ss.hasPermi('manage:destroy:revocation')")
    @GetMapping("/revocation")
    public AjaxResult revocation(@RequestParam String archivesId) {

        service.revocationDestroy(archivesId);
        return AjaxResult.success();
    }
    /**
     * 查询待销毁列表
     */
    @PreAuthorize("@ss.hasPermi('manage:destroy:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchivesMaster archiveDestroy)
    {
        startPage();
        List<ArchivesMaster> list = service.selectDestroyList(archiveDestroy);
        return getDataTable(list);
    };

    @PreAuthorize("@ss.hasPermi('manage:destroy:query')")
    @GetMapping("/archives")
    public AjaxResult getArchives(@RequestParam String archivesId) {

        return AjaxResult.success(service.seelectArchivesById(archivesId));
    }

    /**
     * 导出销毁清册列表
     */
    @PreAuthorize("@ss.hasPermi('manage:destroy:export')")
    @Log(title = "销毁清册", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArchivesMaster archiveDestroy)
    {
        List<ArchivesMaster> list = service.selectDestroyList(archiveDestroy);
        ExcelUtil<ArchivesMaster> util = new ExcelUtil<ArchivesMaster>(ArchivesMaster.class);
        return util.exportExcel(list, "destroy");
    }

    /**
     * 审核销毁清册
     */
    @PreAuthorize("@ss.hasPermi('manage:destroy:approval')")
    @PutMapping("/approval")
    public AjaxResult check(@RequestBody Approval approval)
    {
        service.approvalDestroy(approval);
        return AjaxResult.success();
    }
}
