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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.bean.engin.info.EnginInfoBean;
import com.zfire.mall.manager.bean.engin.info.EnginInfoListBean;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.engin.info.EnginInfoLogic;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api(value = "工程信息", tags ={"工程信息"} )
@RequestMapping(value = "/engin-info", produces = "application/json; charset=utf-8")
public class EnginInfoController {

    @Resource
    EnginInfoLogic enginInfoLogic;

    @ApiOperation(value = "工程信息列表")
    @GetMapping("/list")
    public ResponseHelper<IPage<EnginInfoListBean>> list(
            @ApiParam(value = "工程信息单号") @RequestParam(required = false) String enginInfoNo,
            @ApiParam(value = "产品大类") @RequestParam(required = false) String productCategoryId,
            @ApiParam(value = "客户编码/客户名称") @RequestParam(required = false) String customerKeyWord,
            @ApiParam(value = "项目名称") @RequestParam(required = false) String projectName,
            @ApiParam(value = "单据类型") @RequestParam(required = false) String orderType,
            @ApiParam(value = "使用单位") @RequestParam(required = false) String useUnit,
            @ApiParam(value = "安装地址") @RequestParam(required = false) String installAddress,
            @ApiParam(value = "工程编号") @RequestParam(required = false) String projectNo,
            @ApiParam(value = "厂工程编号") @RequestParam(required = false) String enginFactoryNo,
            @ApiParam(value = "工程登录类型") @RequestParam(required = false) String enginSignType,
            @ApiParam(value = "合同有效期-开始") @RequestParam(required = false) String startContractExpireDate,
            @ApiParam(value = "合同有效期-结束") @RequestParam(required = false) String endContractExpireDate,
            @ApiParam(value = "创建人名称") @RequestParam(required = false) String createName,
            @ApiParam(value = "审核人名称") @RequestParam(required = false) String confirmName,
            @ApiParam(value = "单据状态") @RequestParam(required = false) String examineStatus,
            @ApiParam(value = "业务员") @RequestParam(required = false) String serviceId,
            @ApiParam(value = "规格型号") @RequestParam(required = false) String specification,
            @ApiParam(value = "是否关闭 true=关闭 false=正常") @RequestParam(required = false) Boolean isClose,
            @ApiParam(value = "页号",required = true)@RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true)@RequestParam Integer pageSize
    ) throws Exception {
        IPage<EnginInfoListBean> listPage = enginInfoLogic.listPage(enginInfoNo, productCategoryId, customerKeyWord, projectName, orderType,
                useUnit, installAddress, projectNo, enginFactoryNo, enginSignType, startContractExpireDate,
                endContractExpireDate, createName, confirmName, examineStatus, serviceId, specification,isClose, pageNum, pageSize);
        return ResponseHelper.success(listPage);
    }

    @ApiOperation(value = "工程信息详情")
    @GetMapping("/detail")
    public ResponseHelper<EnginInfoBean> detail(
            @ApiParam(value = "工程信息id", required = true) @RequestParam String id
    ) throws Exception {
        EnginInfoBean enginInfoBean = enginInfoLogic.detail(id);
        return ResponseHelper.success(enginInfoBean);
    }

    @ApiOperation(value = "工程信息详情(工程订单引用)")
    @GetMapping("/ref/detail")
    public ResponseHelper<EnginInfoBean> refDetail(
            @ApiParam(value = "工程信息单号", required = true) @RequestParam String recordNo,
            @ApiParam(value = "商用工程订单号") @RequestParam(required = false) String enginOrderId,
            @ApiParam(value = "经销商id") @RequestParam(required = false) String customerId
    ) throws Exception {
        EnginInfoBean enginInfoBean = enginInfoLogic.queryDetailByRecordNo(recordNo, enginOrderId, customerId);
        return ResponseHelper.success(enginInfoBean);
    }
}
