package com.xtd.project.assets.controller;

import java.util.List;

import com.xtd.project.assets.domain.DbAssetsStockOut;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xtd.framework.aspectj.lang.annotation.Log;
import com.xtd.framework.aspectj.lang.enums.BusinessType;
import com.xtd.project.assets.domain.DbAssetsStockScrap;
import com.xtd.project.assets.service.IDbAssetsStockScrapService;
import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.common.utils.poi.ExcelUtil;
import com.xtd.framework.web.page.TableDataInfo;

/**
 * 资产报废Controller
 *
 * @author xtd
 * @date 2020-04-17
 */
@RestController
@RequestMapping("/assets/scrap")
public class DbAssetsStockScrapController extends BaseController
{
    @Autowired
    private IDbAssetsStockScrapService dbAssetsStockScrapService;

    /**
     * 查询资产报废列表
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbAssetsStockScrap dbAssetsStockScrap)
    {
        startPage();
        List<DbAssetsStockScrap> list = dbAssetsStockScrapService.selectDbAssetsStockScrapList(dbAssetsStockScrap);
        return getDataTable(list);
    }

    /**
     * 导出资产报废列表
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:export')")
    @Log(title = "资产报废", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbAssetsStockScrap dbAssetsStockScrap)
    {
        List<DbAssetsStockScrap> list = dbAssetsStockScrapService.selectDbAssetsStockScrapList(dbAssetsStockScrap);
        ExcelUtil<DbAssetsStockScrap> util = new ExcelUtil<DbAssetsStockScrap>(DbAssetsStockScrap.class);
        return util.exportExcel(list, "scrap");
    }

    /**
     * 获取资产报废详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId)
    {
        return AjaxResult.success(dbAssetsStockScrapService.selectDbAssetsStockScrapById(aId));
    }

    /**
     * 新增资产报废
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:add')")
    @Log(title = "资产报废", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbAssetsStockScrap dbAssetsStockScrap)
    {
        return toAjax(dbAssetsStockScrapService.insertDbAssetsStockScrap(dbAssetsStockScrap));
    }


    /**
     * 提交流程
     */
    @PostMapping(value = "/commit/{aId}/{processId}")
    public AjaxResult commit(@PathVariable("aId") Long aId, @PathVariable("processId") String processId) {
        dbAssetsStockScrapService.commit(aId, processId);
        return AjaxResult.success();
    }

    /**
     * 重新提交流程
     */
    @PostMapping(value = "/recommit")
    public AjaxResult recommit(@RequestBody DbAssetsStockScrap dbAssetsStockScrap) {
        dbAssetsStockScrapService.recommit(dbAssetsStockScrap);
        return AjaxResult.success();
    }

    /**
     * 修改资产报废
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:edit')")
    @Log(title = "资产报废", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbAssetsStockScrap dbAssetsStockScrap)
    {
        return toAjax(dbAssetsStockScrapService.updateDbAssetsStockScrap(dbAssetsStockScrap));
    }

    /**
     * 删除资产报废
     */
    @PreAuthorize("@ss.hasPermi('assets:scrap:remove')")
    @Log(title = "资产报废", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds)
    {
        return toAjax(dbAssetsStockScrapService.deleteDbAssetsStockScrapByIds(aIds));
    }
}
