package com.zfire.mall.manager.controller.stock;


import cn.hutool.db.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.annotation.ApiNotAuth;
import com.zfire.mall.manager.bean.ExcelData;
import com.zfire.mall.manager.bean.sale.StorageFeeBean;
import com.zfire.mall.manager.bean.stock.KingDeePurchaseStockOutBean;
import com.zfire.mall.manager.bean.stock.StockStartAccVO;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.stock.StockStartAccLogic;
import com.zfire.mall.manager.utils.excel.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author CHANGE
 */
@Slf4j
@RestController
@Api(value = "广佛仓库区分", tags ={"广佛仓库区分"} )
@RequestMapping(value = "/stock/startAcc", produces = "application/json; charset=utf-8")
public class StockStartAccController {


    @Autowired
    StockStartAccLogic stockStartAccLogic;


    @ApiOperation(value = "广佛库存列表")
    @GetMapping("/stock")
    public ResponseHelper<IPage<StockStartAccVO>> list(
            @ApiParam(required = false, value = "仓库名称") @RequestParam(required = false) String correspondName,
            @ApiParam(required = false, value = "物料名称") @RequestParam(required = false) String materialName,
            @ApiParam(required = false, value = "物料编码") @RequestParam(required = false) String materialNumber,
            @ApiParam(required = false, value = "规格型号") @RequestParam(required = false) String specification,
            @ApiParam(required = false, value = "分页大小") @RequestParam(required = false) Integer pageSize,
            @ApiParam(required = false, value = "页数") @RequestParam(required = false) Integer pageNumber

    ) throws Exception {
        IPage<StockStartAccVO> stockStartAccVOIPage = stockStartAccLogic.list(correspondName,materialName,materialNumber,specification,pageSize,pageNumber);
        return ResponseHelper.success(stockStartAccVOIPage);
    }



    @ApiOperation(value = "广佛库存列表和库存对比结果")
    @GetMapping("/listDuiBi")
    public ResponseHelper listDuiBi(


    ) throws Exception {
        stockStartAccLogic.listDuiBi();
        return ResponseHelper.success();
    }


    @ApiOperation(value = "广佛库存列表1导出")
    @GetMapping("/stockExport")
    public void stockExport(
            @ApiParam(required = false, value = "仓库名称") @RequestParam(required = false) String correspondName,
            @ApiParam(required = false, value = "物料名称") @RequestParam(required = false) String materialName,
            @ApiParam(required = false, value = "物料编码") @RequestParam(required = false) String materialNumber,
            @ApiParam(required = false, value = "规格型号") @RequestParam(required = false) String specification,
            HttpServletRequest request, HttpServletResponse response
    ) throws Exception {
        List<StockStartAccVO> stockStartAccVOIPage = stockStartAccLogic.listExport(correspondName,materialName,materialNumber,
                specification,-1,1);

        ExcelData excelData = stockStartAccLogic.stockExport(stockStartAccVOIPage);
        ExcelUtils.exportExcel(request,response,"广佛库存1.xlsx",excelData);
    }

    @ApiOperation(value = "广佛库存列表2后导出")
    @GetMapping("/stockExport2")
    public void stockExport2(
            @ApiParam(required = false, value = "仓库名称") @RequestParam(required = false) String correspondName,
            @ApiParam(required = false, value = "物料名称") @RequestParam(required = false) String materialName,
            @ApiParam(required = false, value = "物料编码") @RequestParam(required = false) String materialNumber,
            @ApiParam(required = false, value = "规格型号") @RequestParam(required = false) String specification,
            HttpServletRequest request, HttpServletResponse response
    ) throws Exception {
        List<StockStartAccVO> stockStartAccVOIPage = stockStartAccLogic.listExport2(correspondName,materialName,materialNumber,
                specification,-1,1);


        ExcelData excelData = stockStartAccLogic.stockExport(stockStartAccVOIPage);
        ExcelUtils.exportExcel(request,response,"广佛库存2.xlsx",excelData);
    }


    @ApiOperation(value = "广佛库存列表3导出")
    @GetMapping("/stockExport3")
    public void stockExport3(
            @ApiParam(required = false, value = "仓库名称") @RequestParam(required = false) String correspondName,
            @ApiParam(required = false, value = "物料名称") @RequestParam(required = false) String materialName,
            @ApiParam(required = false, value = "物料编码") @RequestParam(required = false) String materialNumber,
            @ApiParam(required = false, value = "规格型号") @RequestParam(required = false) String specification,
            HttpServletRequest request, HttpServletResponse response
    ) throws Exception {
        List<StockStartAccVO> stockStartAccVOIPage = stockStartAccLogic.listExport3(correspondName,materialName,materialNumber,
                specification,-1,1);


        ExcelData excelData = stockStartAccLogic.stockExport(stockStartAccVOIPage);
        ExcelUtils.exportExcel(request,response,"广佛库存3.xlsx",excelData);
    }



    @ApiNotAuth
    @ApiOperation(value = "同步新入库机型到期初")
    @GetMapping("/syncStartAcc")
    public ResponseHelper test3(

    ) throws Exception {
        stockStartAccLogic.test3();
        return ResponseHelper.success();
    }


    @ApiNotAuth
    @ApiOperation(value = "同步机型库存")
    @GetMapping("/syncStartAccSync")
    public ResponseHelper test4(

    ) throws Exception {
        stockStartAccLogic.test4();
        return ResponseHelper.success();
    }
}

