package com.zfire.mall.manager.controller.refund.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.refund.RefundOrderBean;
import com.zfire.mall.manager.bean.refund.v2.RetailOtherRefundOrderVO;
import com.zfire.mall.manager.bean.refund.v2.RetailRefundOrderVO;
import com.zfire.mall.manager.bean.refund.v2.TradeERefundOrderVO;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.refund.v2.RefundOrderV2Logic;
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 io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

@Slf4j
@RestController
@Api(value = "退订单", tags ={"退订单"} )
@RequestMapping(value = "/v2/refund", produces = "application/json; charset=utf-8")
public class RefundOrderV2Controller {

    @Resource
    RefundOrderV2Logic refundOrderV2Logic;

    @ZfireList
    @ApiOperation(value = "销售政策退订单-列表")
    @PostMapping("/retail/list")
    public ResponseHelper<IPage<RetailRefundOrderVO>> v2RetailListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<RetailRefundOrderVO> list = refundOrderV2Logic.v2RetailListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<RetailRefundOrderVO>() {});
    }

    @PostMapping("/retail/list/export")
    @ApiOperation("销售政策退订单-导出")
    public void v2RetailListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<RetailRefundOrderVO> list = refundOrderV2Logic.v2RetailListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }

    @PostMapping("/detail")
    @ApiOperation("退订单-详情")
    public ResponseHelper<RefundOrderBean> retailDetail(
            @ApiParam(value = "销售政策退订单id", required = true) @RequestParam String refundOrderId
    ) throws Exception {
        RefundOrderBean bean = refundOrderV2Logic.retailDetail(refundOrderId);
        return ResponseHelper.success(bean);
    }

    @ZfireList
    @ApiOperation(value = "零售退订单-列表")
    @PostMapping("/other/list")
    public ResponseHelper<IPage<RetailOtherRefundOrderVO>> v2RetailOtherListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<RetailOtherRefundOrderVO> list = refundOrderV2Logic.v2RetailOtherListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<RetailOtherRefundOrderVO>() {});
    }

    @PostMapping("/other/list/export")
    @ApiOperation("零售退订单-导出")
    public void v2RetailOtherListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<RetailOtherRefundOrderVO> list = refundOrderV2Logic.v2RetailOtherListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }

    @ZfireList
    @ApiOperation(value = "商用工程退订单-列表")
    @PostMapping("/trade-e/list")
    public ResponseHelper<IPage<TradeERefundOrderVO>> v2TradeEListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<TradeERefundOrderVO> list = refundOrderV2Logic.v2TradeEListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<TradeERefundOrderVO>() {});
    }

    @PostMapping("/trade-e/list/export")
    @ApiOperation("商用工程退订单-导出")
    public void v2TradeEListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<TradeERefundOrderVO> list = refundOrderV2Logic.v2TradeEListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }
}
