package com.gree.mall.manager.controller.material.manage;

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.material.manage.WebsitTradeVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.material.manage.WebsitTradeLogic;
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.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
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;

@Slf4j
@RestController
@Api(value = "交易管理API", tags ={"交易管理API"} )
@Validated
@RequestMapping(value = "/websit/trade", produces = "application/json; charset=utf-8")
public class WebsitTradeController {

    @Resource
    WebsitTradeLogic websitTradeLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "网点销售订单-列表")
    public ResponseHelper<IPage<WebsitTradeVO>> page(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<WebsitTradeVO> page = websitTradeLogic.page(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<WebsitTradeVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("网点销售订单-导出")
    public void listExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //2.查询要导出的内容
        IPage<WebsitTradeVO> baseVOIPage = websitTradeLogic.page(zfireParamBean);
        //3.导出
        FieldUtils.exportData(baseVOIPage.getRecords(), zfireParamBean.getExportFields(), request, response);
    }
}
