package com.xtd.project.assets.controller;

import com.xtd.common.utils.poi.ExcelUtil;
import com.xtd.framework.aspectj.lang.annotation.Log;
import com.xtd.framework.aspectj.lang.enums.BusinessType;
import com.xtd.framework.web.controller.BaseController;
import com.xtd.framework.web.domain.AjaxResult;
import com.xtd.framework.web.page.TableDataInfo;
import com.xtd.project.assets.domain.DbAssetsStockAllot;
import com.xtd.project.assets.domain.DbAssetsStockAllotVo;
import com.xtd.project.assets.service.IDbAssetsStockAllotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 资产调拨Controller
 *
 * @author xtd
 * @date 2020-04-20
 */
@RestController
@RequestMapping("/assets/allot")
public class DbAssetsStockAllotController extends BaseController
{
    @Autowired
    private IDbAssetsStockAllotService dbAssetsStockAllotService;

    /**
     * 查询资产调拨列表
     */
    @PreAuthorize("@ss.hasPermi('assets:allot:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbAssetsStockAllotVo dbAssetsStockAllotForm)
    {
        startPage();
        List<DbAssetsStockAllotVo> list = dbAssetsStockAllotService.selectDbAssetsStockAllotList(dbAssetsStockAllotForm);
        return getDataTable(list);
    }

//    /**
//     * 导出资产调拨列表
//     */
//    @PreAuthorize("@ss.hasPermi('assets:allot:export')")
//    @Log(title = "资产调拨", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(DbAssetsStockAllotVo dbAssetsStockAllotForm)
//    {
//        List<DbAssetsStockAllotVo> list = dbAssetsStockAllotService.selectDbAssetsStockAllotList(dbAssetsStockAllotForm);
//        ExcelUtil<DbAssetsStockAllot> util = new ExcelUtil<DbAssetsStockAllot>(DbAssetsStockAllot.class);
//        return util.exportExcel(list, "allot");
//    }

    /**
     * 获取资产调拨详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:allot:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId)
    {
        return AjaxResult.success(dbAssetsStockAllotService.selectDbAssetsStockAllotById(aId));
    }

    /**
     * 新增资产调拨
     */
    @PreAuthorize("@ss.hasPermi('assets:allot:add')")
    @Log(title = "资产调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbAssetsStockAllot dbAssetsStockAllot)
    {
        return toAjax(dbAssetsStockAllotService.insertDbAssetsStockAllot(dbAssetsStockAllot));
    }

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

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

    /**
     * 修改资产调拨
     */
    @PreAuthorize("@ss.hasPermi('assets:allot:edit')")
    @Log(title = "资产调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbAssetsStockAllot dbAssetsStockAllot)
    {
        return toAjax(dbAssetsStockAllotService.updateDbAssetsStockAllot(dbAssetsStockAllot));
    }

    /**
     * 删除资产调拨
     */
    @PreAuthorize("@ss.hasPermi('assets:allot:remove')")
    @Log(title = "资产调拨", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds)
    {
        return toAjax(dbAssetsStockAllotService.deleteDbAssetsStockAllotByIds(aIds));
    }
}
