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


import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zfire.mall.manager.annotation.ZfireList;
import com.zfire.mall.manager.bean.front.CustomerStockBean;
import com.zfire.mall.manager.bean.invoice.InvoiceNewListBean;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.invoice.InvoiceNewListLogic;
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.beans.factory.annotation.Autowired;
import org.springframework.integration.redis.util.RedisLockRegistry;
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.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author CHANGE
 */
@Slf4j
@RestController
@Api(value = "申请发货单新列表", tags = {"申请发货单新列表"})
@RequestMapping(value = "/invoiceNewList", produces = "application/json; charset=utf-8")
public class InvoiceNewListController {


    @Autowired
    InvoiceNewListLogic invoiceNewListLogic;

    @Autowired
    RedisLockRegistry redisLockRegistry;



    @ZfireList
    @PostMapping("/list")
    @ApiOperation("发货汇总列表")
    public ResponseHelper<IPage<InvoiceNewListBean>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws RemoteServiceException {
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        IPage<InvoiceNewListBean> stockBeanIPage = invoiceNewListLogic.list(new Page(zfireParam.getPageNum(), zfireParam.getPageSize()), zfireParam);
        return ResponseHelper.success(stockBeanIPage, new TypeReference<InvoiceNewListBean>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("发货汇总列表导出")
    public void listExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<InvoiceNewListBean> stockBeanIPage = invoiceNewListLogic.list(new Page(zfireParam.getPageNum(), zfireParam.getPageSize()), zfireParam);
        //3.导出
        FieldUtils.exportData(stockBeanIPage.getRecords(), zfireParam.getExportFields(), request, response);
    }

}