package com.zfire.mall.manager.controller.customer;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.bean.engin.deposit.CustomerEnginDepositBean;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.customer.CustomerEnginDepositLogic;
import com.zfire.mall.manager.plus.entity.ComList;
import com.zfire.mall.manager.plus.entity.CustomerEnginDeposit;
import com.zfire.mall.manager.utils.CommonUtils;
import com.zfire.mall.manager.utils.excel.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@Api(value = "经销商工程机押金", tags ={"经销商工程机押金"} )
@RequestMapping(value = "/customer/deposit", produces = "application/json; charset=utf-8")
public class CustomerEnginDepositController {

    @Autowired
    CustomerEnginDepositLogic customerEnginDepositLogic;

    @GetMapping("/list")
    @ApiOperation(value = "经销商工程机配置列表")
    public ResponseHelper<IPage<CustomerEnginDepositBean>> list(
            @ApiParam(required = false, value = "搜索内容") @RequestParam(required = false) String keyword,
            @ApiParam(required = false, value = "当前状态 1.未开始 2.生效中 3.已结束") @RequestParam(required = false) String currentStatus,
            @ApiParam(required = true, value = "页号") @RequestParam(required = true) Integer pageNum,
            @ApiParam(required = true, value = "页大小") @RequestParam(required = true) Integer pageSize
    ){
        IPage<CustomerEnginDepositBean> list = customerEnginDepositLogic.list(keyword,currentStatus,pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @GetMapping("/detailList")
    @ApiOperation(value = "经销商工程机配置详情列表")
    public ResponseHelper<IPage<CustomerEnginDepositBean>> detailList(
            @ApiParam(required = true, value = "工程机ID") @RequestParam(required = true) String id,
            @ApiParam(required = true, value = "页号") @RequestParam(required = true) Integer pageNum,
            @ApiParam(required = true, value = "页大小") @RequestParam(required = true) Integer pageSize
    ){
        IPage<CustomerEnginDepositBean> list = customerEnginDepositLogic.listDetail(id, pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增经销商工程机配置")
    public ResponseHelper add(
            @ApiParam(required = true, value = "object") @RequestBody(required = true) CustomerEnginDeposit customerEnginDeposit
    ){
        customerEnginDepositLogic.add(customerEnginDeposit);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改经销商工程机配置")
    public ResponseHelper update(
            @ApiParam(required = true, value = "object") @RequestBody(required = true) CustomerEnginDeposit customerEnginDeposit
    ){
        customerEnginDepositLogic.update(customerEnginDeposit);
        return ResponseHelper.success();
    }

    @GetMapping("/detail")
    @ApiOperation(value = "经销商工程机配置详情")
    public ResponseHelper<CustomerEnginDeposit> update(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id
    ){
        CustomerEnginDeposit detail = customerEnginDepositLogic.detail(id);
        return ResponseHelper.success(detail);
    }


    @PostMapping("/delete")
    @ApiOperation(value = "删除经销商工程机配置")
    public ResponseHelper delete(
            @ApiParam(required = true, value = "id") @RequestParam(required = true) String id
    ){
        customerEnginDepositLogic.delete(id);
        return ResponseHelper.success();
    }


    @PostMapping("/import")
    @ApiOperation(value = "导入工程押金单数据")
    public ResponseHelper importData(MultipartFile file) throws Exception{
        List<Object> objects = ExcelUtils.importExcel(file);
        customerEnginDepositLogic.importData(objects);
        return ResponseHelper.success();
    }

    @GetMapping("/downModel")
    @ApiOperation("下载工程押金单模板")
    public void download(
            HttpServletResponse response
    ) throws IOException {
        CommonUtils.downloadFile("deposit_order.xlsx",response);
    }

}
