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

import com.ruoyi.basicData.service.ITCorpsService;
import com.ruoyi.basicData.service.ITWarehouseUserService;
import com.ruoyi.common.annotation.DataScope;
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.poi.ExcelUtil;
import com.ruoyi.reportManagement.domain.TWareHouseItemsExcel;
import com.ruoyi.reportManagement.service.ITWhgenlegService;
import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
import com.ruoyi.warehouseBusiness.service.ITWarehouseAgreementService;
import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
import com.ruoyi.warehouseBusiness.service.ITWarehousebillsitemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 出入库汇总Controller
 * 总账统计
 *
 * @author ruoyi
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/warehouseBusiness/summary")
public class TWarehousebillsitemsSummaryController extends BaseController {

    @Autowired
    private ITWarehouseBillsService itWarehouseBillsService;

    @Autowired
    private ITWhgenlegService itWhgenlegService;

    @Autowired
    private ITCorpsService itCorpsService;

    @Autowired
    private ITWarehousebillsitemsService itWarehousebillsitemsService;

    @Autowired
    private ITWarehouseAgreementService itWarehouseAgreementService;

    @Autowired
    private ITWarehouseUserService itWarehouseUserService;

    /**
     * 查询库存总账列表
     */
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo list(TWarehouseBills tWarehouseBills) {
        startPage();
        List<Map<String, Object>> list = itWarehouseBillsService.selectInventoryList(tWarehouseBills);
        return getDataTable(list);
    }

    /**
     * 导出库存总账列表
     */
    @Log(title = "出入库统计", businessType = BusinessType.EXPORT)
    @DataScope(deptAlias = "d", userAlias = "u")
    @GetMapping("/export")
    public AjaxResult export(TWarehouseBills tWarehouseBills) {
        List<TWareHouseItemsExcel> list = itWarehouseBillsService.selectTWarehousebillsItemsList(tWarehouseBills);
        ExcelUtil<TWareHouseItemsExcel> util = new ExcelUtil<>(TWareHouseItemsExcel.class);
        return util.statisticsExportExcel(list, "总账统计");
    }

    /**
     * 出入库、库存统计
     */
    @GetMapping("/stockStatistics")
    public AjaxResult stockStatistics() {
        return AjaxResult.success(itWarehouseBillsService.stockStatistics());
    }

    /**
     * 周期库存统计
     */
    @GetMapping("/cycleStockStatistics")
    public AjaxResult cycleStockStatistics() {
        return AjaxResult.success(itWarehouseBillsService.cycleStockStatistics());
    }

    /**
     * 出入库列表
     */
    @GetMapping("/inAndOutStockList")
    public TableDataInfo inAndOutStockList() {
        startPage();
        return getDataTable(itWarehouseBillsService.inAndOutStockList());
    }

    /**
     * 库龄超过60天的库存列表
     */
    @GetMapping("/stockAfterMonthList")
    public TableDataInfo stockAfterMonthList() {
        startPage();
        return getDataTable(itWhgenlegService.stockAfterMonthList());
    }

    /**
     * bi大屏仓库列表
     */
    @GetMapping("/biWarehouseList")
    public AjaxResult biWarehouseList() {
        return AjaxResult.success(itWarehouseUserService.biWarehouseList());
    }

    /**
     * bi大屏客户列表
     */
    @GetMapping("/biCustomerList")
    public AjaxResult biCustomerList() {
        return AjaxResult.success(itCorpsService.biCustomerList());
    }

    /**
     * bi大屏客户数量
     */
    @GetMapping("/biCustomerCount")
    public AjaxResult biCustomerCount(Long warehouseId, Long customerId) {
        return AjaxResult.success(itCorpsService.biCustomerCount(warehouseId, customerId));
    }

    /**
     * bi大屏客户概况
     */
    @GetMapping("/biCustomerInfo")
    public AjaxResult biCustomerInfo(Long warehouseId, Long customerId) {
        return AjaxResult.success(itWhgenlegService.biCustomerInfo(warehouseId, customerId));
    }

    /**
     * bi当日入库量
     */
    @GetMapping("/biTodayInStockCount")
    public AjaxResult biTodayInStockCount(Long warehouseId, Long customerId, String mode) {
        return AjaxResult.success(itWarehousebillsitemsService.biTodayInAndOutStockCount("SJRK", warehouseId, customerId, mode));
    }

    /**
     * bi当日出库量
     */
    @GetMapping("/biTodayOutStockCount")
    public AjaxResult biTodayOutStockCount(Long warehouseId, Long customerId, String mode) {
        return AjaxResult.success(itWarehousebillsitemsService.biTodayInAndOutStockCount("SJCK", warehouseId, customerId, mode));
    }

    /**
     * bi库存数量
     */
    @GetMapping("/biStockCount")
    public AjaxResult biStockCount(Long warehouseId, Long customerId, String mode) {
        return AjaxResult.success(itWhgenlegService.biStockCount(warehouseId, customerId, mode));
    }

    /**
     * bi大屏协议数量
     */
    @GetMapping("/biContractCount")
    public AjaxResult biContractCount(Long customerId) {
        return AjaxResult.success(itWarehouseAgreementService.biContractCount(customerId));
    }

    /**
     * bi大屏毛重概况
     */
    @GetMapping("/biWeightInfo")
    public AjaxResult biWeightInfo(Long warehouseId, Long customerId, String mode) {
        return AjaxResult.success(itWhgenlegService.biWeightInfo(warehouseId, customerId, mode));
    }

    /**
     * bi大屏最大库龄
     */
    @GetMapping("/biMaxStockDays")
    public AjaxResult biMaxStockDays(Long warehouseId, Long customerId) {
        return AjaxResult.success(itWhgenlegService.biMaxStockDays(warehouseId, customerId));
    }

    /**
     * bi大屏库龄概况
     */
    @GetMapping("/biStockDaysInfo")
    public AjaxResult biStockDaysInfo(Long warehouseId, Long customerId) {
        return AjaxResult.success(itWhgenlegService.biStockDaysInfo(warehouseId, customerId));
    }

    /**
     * bi大屏入库列表
     */
    @GetMapping("/biInStockList")
    public TableDataInfo biInStockList(Long warehouseId, Long customerId) {
        startPage();
        return getDataTable(itWarehousebillsitemsService.biInAndOutStockList("SJRK", warehouseId, customerId, null));
    }

    /**
     * bi大屏出库列表
     */
    @GetMapping("/biOutStockList")
    public TableDataInfo biOutStockList(Long warehouseId, Long customerId) {
        startPage();
        return getDataTable(itWarehousebillsitemsService.biInAndOutStockList("SJCK", warehouseId, customerId, null));
    }

    /**
     * bi大屏仓储协议列表
     */
    @GetMapping("/biContractList")
    public TableDataInfo biContractList(Long customerId) {
        startPage();
        return getDataTable(itWarehouseAgreementService.biContractList(customerId));
    }

}
