package com.fzm.mall.server.admin.goods_center.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzm.mall.server.admin.goods_center.entity.dto.ExternalTokenDTO;
import com.fzm.mall.server.admin.goods_center.entity.dto.ExternalTokenTradeDTO;
import com.fzm.mall.server.admin.goods_center.service.IExternalTokenService;
import com.fzm.mall.server.admin.goods_center.service.IExternalTokenTradeService;
import com.fzm.mall.server.admin.repo.ResponseFactory;
import com.fzm.mall.server.admin.repo.ResponseVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 外部商品通证 前端控制器
 * </p>
 *
 * @author fzm
 * @since 2021-08-10
 */
@Api(tags = "商品中心-外部商品通证")
@RestController
@RequestMapping("/externalTokenTrade")
public class ExternalTokenTradeController {

    @Autowired
    private IExternalTokenTradeService externalTokenTradeService;

    @Autowired
    private ResponseFactory resFac;

    @ApiOperation(value = "商品中心-外部商品通证-交易记录-列表查询")
    @ApiOperationSupport(order = 1)
    @GetMapping("/list")
    public ResponseVO list(@ApiParam(value = "管理员id", required = true) @RequestHeader String adminId,
                           @ApiParam(value = "每页条数") @RequestParam(required = false) Long pageSize,
                           @ApiParam(value = "页码") @RequestParam(required = false) Long pageNum,
                           @ApiParam(value = "外部商品通证编号", required = true) @RequestParam String commodityPassId,
                           @ApiParam(value = "对方地址") @RequestParam(required = false) String oppositeAddress,
                           @ApiParam(value = "交易类型(1.库存充值 2.商品销售 3.商品退货)") @RequestParam(required = false) Integer tradeType,
                           @ApiParam(value = "开始时间") @RequestParam(required = false) Long startTime,
                           @ApiParam(value = "结束时间") @RequestParam(required = false) Long endTime) {
        Page<ExternalTokenTradeDTO> page = new Page<>();
        if (ObjectUtils.isNotEmpty(pageSize) && ObjectUtils.isNotEmpty(pageNum)) {
            page.setSize(pageSize);
            page.setCurrent(pageNum);
        }

        IPage<ExternalTokenTradeDTO> result = externalTokenTradeService.page(page, commodityPassId, oppositeAddress, tradeType,
                startTime, endTime);
        return resFac.getSuccessResponseWithData(result);
    }
}
