package com.ruoyi.web.controller.warehouse.approvalFlow;

import java.util.List;
import java.util.Map;

import com.ruoyi.approvalFlow.domain.AuditPaths;
import com.ruoyi.approvalFlow.domain.AuditPathsActs;
import com.ruoyi.approvalFlow.service.IAuditPathsActsService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审批流配置明细Controller
 *
 * @author ruoyi
 * @date 2021-01-21
 */
@RestController
@RequestMapping("/warehouse/pathsActs")
public class AuditPathsActsController extends BaseController {
    @Autowired
    private IAuditPathsActsService auditPathsActsService;

    /**
     * 查询审批流配置明细列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuditPathsActs auditPathsActs) {
        startPage();
        List<AuditPathsActs> list = auditPathsActsService.selectAuditPathsActsList(auditPathsActs);
        return getDataTable(list);
    }

    /**
     * 查询审批流配置主列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:list')")
    @GetMapping("/auditPathslist")
    public Map<String, Object> auditPathslist(AuditPathsActs auditPathsActs) {
        startPage();
        return auditPathsActsService.selectAuditPathsList(auditPathsActs);
    }

    /**
     * 导出审批流配置明细列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:export')")
    @Log(title = "审批流配置明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AuditPathsActs auditPathsActs) {
        List<AuditPathsActs> list = auditPathsActsService.selectAuditPathsActsList(auditPathsActs);
        ExcelUtil<AuditPathsActs> util = new ExcelUtil<AuditPathsActs>(AuditPathsActs.class);
        return util.exportExcel(list, "acts");
    }

    /**
     * 获取审批流配置明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(auditPathsActsService.selectAuditPathsActsById(id));
    }

    /**
     * 新增审批流配置明细
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:add')")
    @Log(title = "审批流配置明细", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestParam("auditPathsActs") String auditPathsActs) {
        if (StringUtils.isEmpty(auditPathsActs) || "[]".equals(auditPathsActs)) {
            return AjaxResult.error("未找到内容，请确认");
        }
        return auditPathsActsService.insertAuditPathsActs(auditPathsActs);
    }

    /**
     * 修改审批流配置明细
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:edit')")
    @Log(title = "审批流配置明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuditPathsActs auditPathsActs) {
        return toAjax(auditPathsActsService.updateAuditPathsActs(auditPathsActs));
    }

    /**
     * 删除审批流配置明细
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pathsActs:remove')")
    @Log(title = "审批流配置明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(auditPathsActsService.deleteAuditPathsActsByIds(ids));
    }
}
