package com.gree.mall.manager.controller.goods;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.goods.GoodsMaterialVO;
import com.gree.mall.manager.bean.listvo.goods.GoodsMaterialStockAccVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.goods.GoodsMaterialStockAccLogic;
import com.gree.mall.manager.zfire.bean.WebsitGoodsParamBean;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ：lijh
 * @description：TODO
 * @date ：2024/2/18 10:52
 */
@RequiredArgsConstructor
@Slf4j
@RestController
@Api(value = "商品物料三级帐API", tags ={"商品物料三级帐API"} )
@RequestMapping(value = "/goods/material/stock/acc", produces = "application/json; charset=utf-8")
public class GoodsMaterialStockAccController {

    private final GoodsMaterialStockAccLogic goodsMaterialStockAccLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<IPage<GoodsMaterialStockAccVO>> page(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws Exception {
        IPage<GoodsMaterialStockAccVO> page = goodsMaterialStockAccLogic.list(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<GoodsMaterialStockAccVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("导出")
    public void listExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //2.查询要导出的内容
        IPage<GoodsMaterialStockAccVO> baseVOIPage = goodsMaterialStockAccLogic.list(zfireParamBean);
        //3.导出
        FieldUtils.exportData(baseVOIPage.getRecords(), zfireParamBean.getExportFields(), request, response);
    }

}
