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

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.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.finance.excel.FleetExcel;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
import com.ruoyi.warehouseBusiness.excel.QueryMenu;
import com.ruoyi.warehouseBusiness.service.ITWarehousebillsfeesService;
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 ruoyi
 * @date 2020-12-11
 */
@RestController
@RequestMapping("/warehouseBusiness/warehousebillsfees")
public class TWarehousebillsfeesController extends BaseController {
    @Autowired
    private ITWarehousebillsfeesService tWarehousebillsfeesService;

    /**
     * 查询仓库费用明细列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:list')")
    @GetMapping("/list")
    public TableDataInfo list(TWarehousebillsfees tWarehousebillsfees) {
        startPage();
        List<TWarehousebillsfees> list = tWarehousebillsfeesService.selectTWarehousebillsfeesList(tWarehousebillsfees);
        return getDataTable(list);
    }

    /**
     * 导出仓库费用明细列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:export')")
    @Log(title = "仓库费用明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TWarehousebillsfees tWarehousebillsfees) {
        List<TWarehousebillsfees> list = tWarehousebillsfeesService.selectTWarehousebillsfeesList(tWarehousebillsfees);
        ExcelUtil<TWarehousebillsfees> util = new ExcelUtil<TWarehousebillsfees>(TWarehousebillsfees.class);
        return util.exportExcel(list, "warehousebillsfees");
    }

    /**
     * 查询仓库费用明细列表
     */
    @GetMapping("/financialStatistics")
    public TableDataInfo financialStatistics(TWarehousebillsfees tWarehousebillsfees) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        tWarehousebillsfees.setCreateBy(loginUser.getUser().getNickName());
        startPage();
        List<FleetExcel> list = tWarehousebillsfeesService.selectFleetExcelList(tWarehousebillsfees);
        return getDataTable(list);
    }

    @GetMapping("/feesExport")
    public AjaxResult exportExcel(TWarehousebillsfees tWarehousebillsfees) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        tWarehousebillsfees.setCreateBy(loginUser.getUser().getNickName());
        List<FleetExcel> list = tWarehousebillsfeesService.selectFleetExcelList(tWarehousebillsfees);
        ExcelUtil<FleetExcel> util = new ExcelUtil<FleetExcel>(FleetExcel.class);
        return util.exportExcel(list, "总账统计");
    }

    /**
     * 获取仓库费用明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:query')")
    @GetMapping(value = "/{fId}")
    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
        return AjaxResult.success(tWarehousebillsfeesService.selectTWarehousebillsfeesById(fId));
    }

    /**
     * 新增仓库费用明细
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:add')")
    @Log(title = "仓库费用明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TWarehousebillsfees tWarehousebillsfees) {
        return toAjax(tWarehousebillsfeesService.insertTWarehousebillsfees(tWarehousebillsfees));
    }

    /**
     * 修改仓库费用明细
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:edit')")
    @Log(title = "仓库费用明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TWarehousebillsfees tWarehousebillsfees) {
        return toAjax(tWarehousebillsfeesService.updateTWarehousebillsfees(tWarehousebillsfees));
    }

    /**
     * 删除仓库费用明细
     */
    @PreAuthorize("@ss.hasPermi('warehouseBusiness:warehousebillsfees:remove')")
    @Log(title = "仓库费用明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fIds}")
    public AjaxResult remove(@PathVariable Long[] fIds) {
        return toAjax(tWarehousebillsfeesService.deleteTWarehousebillsfeesByIds(fIds));
    }

    /**
     * 获取查询菜单数据
     */
    @GetMapping("/queryMenuList")
    public TableDataInfo selectQueryMenuList(TWarehousebillsfees tWarehousebillsfees) {
        startPage();
        return getDataTable(tWarehousebillsfeesService.selectQueryMenuList(tWarehousebillsfees));
    }

    /**
     * 导出查询菜单列表
     */
    @GetMapping("/queryMenuExport")
    public AjaxResult queryMenuExport(TWarehousebillsfees tWarehousebillsfees) throws Exception {
        List<QueryMenu> list = tWarehousebillsfeesService.queryMenuExport(tWarehousebillsfees);
        ExcelUtil<QueryMenu> util = new ExcelUtil<>(QueryMenu.class);
        return util.exportExcel(list, "账单明细");
    }
}
