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.WebsitPartsRefundRecordVO;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.material.manage.WebsitPartsRefundRecordLogic;
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.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 = "配件退款记录", tags = {"配件退款记录"})
@RequestMapping(value = "/parts/refund-record", produces = "application/json; charset=utf-8")
public class WebsitRefundRecordController {

    @Resource
    WebsitPartsRefundRecordLogic websitPartsRefundRecordLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation("配件退款记录列表")
    public ResponseHelper<IPage<WebsitPartsRefundRecordVO>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<WebsitPartsRefundRecordVO> page = websitPartsRefundRecordLogic.pageList(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<WebsitPartsRefundRecordVO>() {
        });
    }

    @PostMapping("/list/export")
    @ApiOperation("配件退款记录导出")
    public void listExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //2.查询要导出的内容
        IPage<WebsitPartsRefundRecordVO> page = websitPartsRefundRecordLogic.pageList(zfireParamBean);
        //3.导出
        FieldUtils.exportData(page.getRecords(), zfireParamBean.getExportFields(), request, response);
    }

}
