package com.xtd.project.assets.controller;

import java.util.List;
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.DbAssetsStockOut;
import com.xtd.project.assets.service.IDbAssetsStockOutService;
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-16
 */
@RestController
@RequestMapping("/assets/out")
public class DbAssetsStockOutController extends BaseController
{
    @Autowired
    private IDbAssetsStockOutService dbAssetsStockOutService;

    /**
     * 查询资产出库列表
     */
    @PreAuthorize("@ss.hasPermi('assets:out:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbAssetsStockOut dbAssetsStockOut)
    {
        startPage();
        List<DbAssetsStockOut> list = dbAssetsStockOutService.selectDbAssetsStockOutList(dbAssetsStockOut);
        return getDataTable(list);
    }

    /**
     * 导出资产出库列表
     */
    @PreAuthorize("@ss.hasPermi('assets:out:export')")
    @Log(title = "资产出库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DbAssetsStockOut dbAssetsStockOut)
    {
        List<DbAssetsStockOut> list = dbAssetsStockOutService.selectDbAssetsStockOutList(dbAssetsStockOut);
        ExcelUtil<DbAssetsStockOut> util = new ExcelUtil<DbAssetsStockOut>(DbAssetsStockOut.class);
        return util.exportExcel(list, "out");
    }

    /**
     * 获取资产出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:out:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId)
    {
        return AjaxResult.success(dbAssetsStockOutService.selectDbAssetsStockOutById(aId));
    }
    /**
     * 提交流程
     */
    @PostMapping(value = "/commit/{aId}/{processId}")
    public AjaxResult commit(@PathVariable("aId") Long aId, @PathVariable("processId") String processId) {
        dbAssetsStockOutService.commit(aId, processId);
        return AjaxResult.success();
    }

    /**
     * 重新提交流程
     */
    @PostMapping(value = "/recommit")
    public AjaxResult recommit(@RequestBody DbAssetsStockOut dbAssetsStockOut) {
        dbAssetsStockOutService.recommit(dbAssetsStockOut);
        return AjaxResult.success();
    }
    /**
     * 新增资产出库
     */
    @PreAuthorize("@ss.hasPermi('assets:out:add')")
    @Log(title = "资产出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbAssetsStockOut dbAssetsStockOut)
    {
        return toAjax(dbAssetsStockOutService.insertDbAssetsStockOut(dbAssetsStockOut));
    }

    /**
     * 修改资产出库
     */
    @PreAuthorize("@ss.hasPermi('assets:out:edit')")
    @Log(title = "资产出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbAssetsStockOut dbAssetsStockOut)
    {
        return toAjax(dbAssetsStockOutService.updateDbAssetsStockOut(dbAssetsStockOut));
    }

    /**
     * 删除资产出库
     */
    @PreAuthorize("@ss.hasPermi('assets:out:remove')")
    @Log(title = "资产出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds)
    {
        return toAjax(dbAssetsStockOutService.deleteDbAssetsStockOutByIds(aIds));
    }
}
