package com.zfire.mall.manager.controller.k3.v2;


import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.annotation.ZfireList;
import com.zfire.mall.manager.bean.k3.v2.KingDeePurchaseStockInVO;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.k3.v2.K3PurchaseStockInV2Logic;
import com.zfire.mall.manager.zfire.bean.ZfireParamBean;
import com.zfire.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author CHANGE
 */
@Slf4j
@RestController
@Api(value = "采购入库单", tags ={"采购入库单"} )
@RequestMapping(value = "/v2/purchaseStockIn", produces = "application/json; charset=utf-8")
public class K3PurchaseStockInV2Controller {


    @Resource
    K3PurchaseStockInV2Logic k3PurchaseStockInV2Logic;

    @ZfireList
    @ApiOperation(value = "采购入库单-列表")
    @PostMapping("/list")
    public ResponseHelper<IPage<KingDeePurchaseStockInVO>> v2ListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws Exception {
        IPage<KingDeePurchaseStockInVO> page = k3PurchaseStockInV2Logic.v2ListPage(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<KingDeePurchaseStockInVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("采购入库单-导出")
    public void v2ListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<KingDeePurchaseStockInVO> list = k3PurchaseStockInV2Logic.v2ListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }

}
