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

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.engin.v2.info.EnginInfoOrderVO;
import com.zfire.mall.manager.bean.engin.v2.info.EnginInfoSaleExecVO;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.engin.v2.info.EnginInfoOrderV2Logic;
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-info-order", produces = "application/json; charset=utf-8")
public class EnginInfoOrderV2Controller {

    @Resource
    EnginInfoOrderV2Logic enginInfoOrderV2Logic;

    @ZfireList
    @ApiOperation(value = "工程信息单-列表")
    @PostMapping("/list")
    public ResponseHelper<IPage<EnginInfoOrderVO>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<EnginInfoOrderVO> list = enginInfoOrderV2Logic.v2ListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<EnginInfoOrderVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("工程信息单-导出")
    public void infoListExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<EnginInfoOrderVO> list = enginInfoOrderV2Logic.v2ListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }

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

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