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.DbAssetsStock;
import com.xtd.project.assets.domain.DbAssetsStockListVo;
import com.xtd.project.assets.domain.DbAssetsStockSelectVo;
import com.xtd.project.assets.service.IDbAssetsStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存管理Controller
 *
 * @author xtd
 * @date 2020-04-09
 */
@RestController
@RequestMapping("/assets/stock")
public class DbAssetsStockController extends BaseController
{
    @Autowired
    private IDbAssetsStockService dbAssetsStockService;

    /**
     * 查询库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbAssetsStock dbAssetsStock)
    {
        startPage();
        List<DbAssetsStockListVo> list = dbAssetsStockService.selectDbAssetsStockList(dbAssetsStock);
        return getDataTable(list);
    }

    /**
     * 查询库存管理列表
     * @param dbMaterielId 类型id
     * @param status 0 查询被未锁定数据 1 查询被锁定数据
     * @return
     */
    @GetMapping("/select/list")
    public AjaxResult selectlist(@RequestParam Long dbMaterielId,@RequestParam(required=false) Integer status)
    {
        List<DbAssetsStockSelectVo> list = dbAssetsStockService.selectlist(dbMaterielId,status);
        return AjaxResult.success(list);
    }
    /**
     * 出库管理列表
     */
    @GetMapping("/out/list")
    public AjaxResult out(@RequestParam("depId") Long depId,@RequestParam("leadUserId")  Long leadUserId,@RequestParam(value = "status",required = false) Integer status)
    {
        List<DbAssetsStockSelectVo> list = dbAssetsStockService.out(depId,leadUserId,status);
        return AjaxResult.success(list);
    }


    /**
     * 导出库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:export')")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HttpServletResponse response, DbAssetsStock dbAssetsStock) throws Exception {
        List<DbAssetsStockListVo> list = dbAssetsStockService.export(dbAssetsStock);
        ExcelUtil<DbAssetsStockListVo> util = new ExcelUtil<DbAssetsStockListVo>(DbAssetsStockListVo.class);
        return util.exportExcel(list, "库存表格");
    }


    /**
     * 获取库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId)
    {
        return AjaxResult.success(dbAssetsStockService.selectDbAssetsStockById(aId));
    }

    /**
     * 新增库存管理
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbAssetsStock dbAssetsStock)
    {
        return toAjax(dbAssetsStockService.insertDbAssetsStock(dbAssetsStock));
    }

    /**
     * 修改库存管理
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbAssetsStock dbAssetsStock)
    {
        return toAjax(dbAssetsStockService.updateDbAssetsStock(dbAssetsStock));
    }

    /**
     * 删除库存管理
     */
    @PreAuthorize("@ss.hasPermi('assets:stock:remove')")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds)
    {
        return toAjax(dbAssetsStockService.deleteDbAssetsStockByIds(aIds));
    }
}
