package com.zfire.mall.manager.controller.engin.v2.order;

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.PoySaleCountBean;
import com.zfire.mall.manager.bean.engin.v2.order.HomeEnginOrderVO;
import com.zfire.mall.manager.bean.engin.v2.order.TradeEnginOrderVO;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.engin.v2.order.EnginOrderV2Logic;
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 = "工程订单管理v2", tags ={"工程订单管理v2"} )
@RequestMapping(value = "/v2/engin-order", produces = "application/json; charset=utf-8")
public class EnginOrderV2Controller {

    @Resource
    EnginOrderV2Logic enginOrderV2Logic;

    @ZfireList
    @ApiOperation(value = "家用工程订单-列表")
    @PostMapping("/home/list")
    public ResponseHelper<IPage<HomeEnginOrderVO>> v2HomeListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<HomeEnginOrderVO> list = enginOrderV2Logic.v2HomeListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<HomeEnginOrderVO>() {});
    }

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

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

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

    @ZfireList
    @ApiOperation(value = "家用工程订单-列表统计")
    @PostMapping("/home/count-list")
    public ResponseHelper<PoySaleCountBean> v2HomeCountList(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        PoySaleCountBean bean = enginOrderV2Logic.v2HomeCountList(zfireParamBean);
        return ResponseHelper.success(bean);
    }

    @ZfireList
    @ApiOperation(value = "商用工程订单-列表统计")
    @PostMapping("/trade/count-list")
    public ResponseHelper<PoySaleCountBean> v2TradeCountList(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        PoySaleCountBean bean = enginOrderV2Logic.v2TradeCountList(zfireParamBean);
        return ResponseHelper.success(bean);
    }

}
