package cn.pluss.platform.controller.merchantTranfer;

import cn.pluss.platform.api.PageInfo;
import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.controller.BaseNoModelController;
import cn.pluss.platform.entity.MerchantTransfer;
import cn.pluss.platform.transfer.MerchantTransferService;
import cn.pluss.platform.util.PageUtils;
import cn.pluss.platform.util.StringUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequiredArgsConstructor
@RequestMapping("merchantTransfer")
public class MerchantTransferController extends BaseNoModelController {

    private final MerchantTransferService merchantTransferService;

    @GetMapping("index")
    public String index() {
        return "merchantTransfer/list";
    }

    @GetMapping("page")
    @ResponseBody
    public Result<PageInfo<MerchantTransfer>> page(Page<MerchantTransfer> page,MerchantTransfer transfer) {
        QueryWrapper<MerchantTransfer> queryWrapper = new QueryWrapper<MerchantTransfer>().orderByDesc("createDt");
        if(StringUtil.isNotEmpty(transfer.getAlias())){
            queryWrapper.like("alias",transfer.getAlias());
        }
        if(StringUtil.isNotEmpty(transfer.getOrderNo())){
            queryWrapper.eq("orderNo",transfer.getOrderNo());
        }
        page = merchantTransferService.page(page, queryWrapper);
        return ResultGenerator.genSuccessResult(PageUtils.page(page));
    }
}