package com.xtd.project.assets.controller;

import java.util.List;

import com.xtd.project.assets.domain.DbAssetsStockInForm;
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.DbAssetsStockIn;
import com.xtd.project.assets.service.IDbAssetsStockInService;
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-09
 */
@RestController
@RequestMapping("/assets/input")
public class DbAssetsStockInController extends BaseController {
    @Autowired
    private IDbAssetsStockInService dbAssetsStockInService;

    /**
     * 查询资产入库列表
     */
    @PreAuthorize("@ss.hasPermi('assets:input:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbAssetsStockIn dbAssetsStockIn) {
        startPage();
        List<DbAssetsStockIn> list = dbAssetsStockInService.selectDbAssetsStockInList(dbAssetsStockIn);
        return getDataTable(list);
    }

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

    /**
     * 获取资产入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:input:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId) {
        return AjaxResult.success(dbAssetsStockInService.selectDbAssetsStockInById(aId));
    }

    /**
     * 获取资产入库表单详细信息
     */
    @GetMapping(value = "/form/{aId}")
    public AjaxResult form(@PathVariable("aId") Long aId) {
        DbAssetsStockInForm dbAssetsStockInForm = dbAssetsStockInService.form(aId);
        return AjaxResult.success(dbAssetsStockInForm);
    }


    /**
     * 新增资产入库
     */
    @PreAuthorize("@ss.hasPermi('assets:input:add')")
    @Log(title = "资产入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbAssetsStockIn dbAssetsStockIn) {
        return toAjax(dbAssetsStockInService.insertDbAssetsStockIn(dbAssetsStockIn));
    }


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

    /**
     * 重新提交表单
     */
    @PostMapping(value = "/recommit")
    public AjaxResult recommit( @RequestBody DbAssetsStockIn dbAssetsStockIn) {
        dbAssetsStockInService.recommit(dbAssetsStockIn);
        return AjaxResult.success();
    }

    /**
     * 修改资产入库
     */
    @PreAuthorize("@ss.hasPermi('assets:input:edit')")
    @Log(title = "资产入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbAssetsStockIn dbAssetsStockIn) {
        return toAjax(dbAssetsStockInService.updateDbAssetsStockIn(dbAssetsStockIn));
    }

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