package com.ruoyi.web.controller.warehouse.reportManagement;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.reportManagement.domain.TWhgenleg;
import com.ruoyi.reportManagement.service.ITWhgenlegService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 库存总账Controller
 *
 * @author ruoyi
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/warehouseBusiness/whgenleg")
public class TWhgenlegController extends BaseController {
    @Autowired
    private ITWhgenlegService tWhgenlegService;

    /**
     * 查询库存总账列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWhgenleg tWhgenleg) {
        startPage();
        List<Map<String, Object>> list = tWhgenlegService.selectInventoryList(tWhgenleg);
        return getDataTable(list);
    }

    /**
     * 导出库存总账列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:export')")
    @Log(title = "库存总账", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWhgenleg tWhgenleg) {
        List<TWhgenleg> list = tWhgenlegService.selectTWhgenlegList(tWhgenleg);
        ExcelUtil<TWhgenleg> util = new ExcelUtil<TWhgenleg>(TWhgenleg.class);
        return util.exportExcel(list, "whgenleg");
    }

    /**
     * 获取库存总账详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        if (StringUtils.isNull(fId)) {
            return AjaxResult.error("未获取到库存总账信息");
        }
        return AjaxResult.success(tWhgenlegService.selectTWhgenlegById(fId));
    }

    /**
     * 新增库存总账
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:add')")
    @Log(title = "库存总账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWhgenleg tWhgenleg) {
        return toAjax(tWhgenlegService.insertTWhgenleg(tWhgenleg));
    }

    /**
     * 修改库存总账
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:edit')")
    @Log(title = "库存总账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWhgenleg tWhgenleg) {
        return toAjax(tWhgenlegService.updateTWhgenleg(tWhgenleg));
    }

    /**
     * 删除库存总账
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:remove')")
    @Log(title = "库存总账", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fAccyears}")
    public AjaxResult remove(@PathVariable Long[] fAccyears) {
        return toAjax(tWhgenlegService.deleteTWhgenlegByIds(fAccyears));
    }

    /**
     *  统计图  商品 库存 结余 毛重 / 总库容
     */
    // @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:list')")
    @GetMapping("/goodsList/{fId}")
    public AjaxResult goodsList(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWhgenlegService.selectGoodsList(fId));
    }

    /**
     *  统计图  仓库 毛重 / 库容
     */
    // @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:list')")
    @GetMapping("/wareHouseList")
    public TableDataInfo wareHouseList() {
        startPage();
       // List<Map<String, Object>> list = tWhgenlegService.selectWareHouseList();
        List<Map<String, Object>> list = tWhgenlegService.selectWareHouseLists();
        return getDataTable(list);
    }

    /**
     *  统计图  客户   毛重 / 库容
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:list')")
    @GetMapping("/corpsList/{fId}")
    public AjaxResult corpsList(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWhgenlegService.selectCorpsList(fId));
    }

    /**
     *  当天 往前推一周  每日入库数量
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:whgenleg:list')")
    @GetMapping("/dateFQtyblcList")
    public TableDataInfo dateFQtyblcList() {
        startPage();
        List<Map<String, Object>> list = tWhgenlegService.selectDateFQtyblcListList();
        return getDataTable(list);
    }



}
