
package com.tmerclub.cloud.supplier.controller.admin;

import com.tmerclub.cloud.common.database.dto.PageDTO;
import com.tmerclub.cloud.common.database.vo.PageVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.security.AuthUserContext;
import com.tmerclub.cloud.common.util.ExcelUtil;
import com.tmerclub.cloud.supplier.dto.SupplierWalletLogSearchDTO;
import com.tmerclub.cloud.supplier.mongo.MongoSupplierWalletLogBO;
import com.tmerclub.cloud.supplier.service.SupplierWalletLogService;
import com.tmerclub.cloud.supplier.service.SupplierWalletService;
import com.tmerclub.cloud.supplier.vo.SupplierWalletLogExcelVO;
import com.tmerclub.cloud.supplier.vo.SupplierWalletVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 供应商钱包日志
 *
 * @author Pineapple
 * @date 2021/6/8 19:46
 */
@RestController("adminSupplierWalletController")
@RequestMapping("/mp/supplier_wallet")
@Tag(name = "admin-供应商供应商钱包")
public class SupplierWalletController {

    @Autowired
    private SupplierWalletLogService supplierWalletLogService;

    @Autowired
    private SupplierWalletService supplierWalletService;

    @GetMapping("/page")
    @Operation(summary = "分页查询", description = "分页查询")
    public ServerResponseEntity<PageVO<MongoSupplierWalletLogBO>> getSupplierWalletLogPage(PageDTO pageDTO, SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        supplierWalletLogSearchDTO.setSupplierId(AuthUserContext.get().getTenantId());
        PageVO<MongoSupplierWalletLogBO> page = supplierWalletLogService.pageByParam(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(page);
    }

    @GetMapping("/get_all_supplier_wallet")
    @Operation(summary = "查看所有供应商钱包总信息")
    public ServerResponseEntity<SupplierWalletVO> getAllSupplierWalletVoBySupplierId(SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        SupplierWalletVO supplierWallet = supplierWalletService.getAllSupplier(supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(supplierWallet);
    }

    @GetMapping("/page_supplier_wallet_by_time")
    @Operation(summary = "分页查看供应商钱包总信息")
    public ServerResponseEntity<PageVO<SupplierWalletVO>> pageSupplierWalletByTime(PageDTO pageDTO, SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        PageVO<SupplierWalletVO> pageSupplierWalletByTime = supplierWalletService.pageSupplierWalletByTime(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(pageSupplierWalletByTime);
    }

    @GetMapping("/page_all_supplier")
    @Operation(summary = "查看所有供应商供应商的钱包记录日志")
    public ServerResponseEntity<PageVO<MongoSupplierWalletLogBO>> getAllSupplierWalletLogPage(PageDTO pageDTO, SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        PageVO<MongoSupplierWalletLogBO> page = supplierWalletLogService.pageAllSupplier(pageDTO, supplierWalletLogSearchDTO);
        return ServerResponseEntity.success(page);
    }

    @GetMapping("/get_supplier_wallet_log_form")
    @Operation(summary = "导出供应商结算报表", description = "导出供应商结算报表")
    public ServerResponseEntity<Void> getSupplierWalletLogForm(HttpServletResponse response, SupplierWalletLogSearchDTO supplierWalletLogSearchDTO) {
        List<SupplierWalletLogExcelVO> list = supplierWalletLogService.listSupplierWalletLogExcel(supplierWalletLogSearchDTO);
        ExcelUtil.soleExcel(response, list, SupplierWalletLogExcelVO.EXCEL_NAME, SupplierWalletLogExcelVO.MERGE_ROW_INDEX, SupplierWalletLogExcelVO.MERGE_COLUMN_INDEX, SupplierWalletLogExcelVO.class);
        return ServerResponseEntity.success();
    }

    @GetMapping("/get_supplier_wallet")
    @Operation(summary = "查看供应商钱包信息", description = "根据供应商id查看供应商钱包信息")
    public ServerResponseEntity<SupplierWalletVO> getSupplierWalletVoBySupplierId() {
        SupplierWalletVO supplierWallet = supplierWalletService.getBySupplierId(AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success(supplierWallet);
    }
}
