package com.zfire.mall.manager.controller.record.order.exec.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.record.order.exec.v2.OrderExecRecordVO;
import com.zfire.mall.manager.bean.record.order.exec.v2.RetailOrderExecRecordVO;
import com.zfire.mall.manager.bean.record.order.exec.v2.TradeEOrderExecRecordVO;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.record.order.exec.v2.OrderExecRecordV2Logic;
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;

@Slf4j
@RestController
@Api(value = "订单执行记录", tags ={"订单执行记录"} )
@RequestMapping(value = "/v2/order", produces = "application/json; charset=utf-8")
public class OrderExecRecordV2Controller {

    @Resource
    OrderExecRecordV2Logic orderExecRecordV2Logic;

    @ZfireList
    @ApiOperation(value = "订单执行-列表")
    @PostMapping("/exec/list")
    public ResponseHelper<IPage<OrderExecRecordVO>> v2ExecListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<OrderExecRecordVO> list = orderExecRecordV2Logic.v2ExecListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<OrderExecRecordVO>() {});
    }

    @PostMapping("/exec/list/export")
    @ApiOperation("订单执行-导出")
    public void v2ExecListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<OrderExecRecordVO> list = orderExecRecordV2Logic.v2ExecListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }

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

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

    @ZfireList
    @ApiOperation(value = "零售订单执行-列表")
    @PostMapping("/other/exec/list")
    public ResponseHelper<IPage<RetailOrderExecRecordVO>> v2RetailOtherExecListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<RetailOrderExecRecordVO> list = orderExecRecordV2Logic.v2RetailOtherExecListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<RetailOrderExecRecordVO>() {});
    }

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

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

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