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

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.deposit.DepositManageVO;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.engin.v2.deposit.DepositManageV2Logic;
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/deposit-manage", produces = "application/json; charset=utf-8")
public class DepositMangeV2Controller {

    @Resource
    DepositManageV2Logic depositManageV2Logic;

    @ZfireList
    @ApiOperation(value = "家用押金管理-列表")
    @PostMapping("/home/list")
    public ResponseHelper<IPage<DepositManageVO>> v2HomeListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        IPage<DepositManageVO> list = depositManageV2Logic.v2HomeListPage(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<DepositManageVO>() {});
    }

    @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<DepositManageVO> list = depositManageV2Logic.v2HomeListPage(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 = depositManageV2Logic.v2HomeCountList(zfireParamBean);
        return ResponseHelper.success(bean);
    }
}
