package cn.pluss.platform.controller.merchant;

import cn.pluss.platform.api.PageInfo;
import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.dto.MercActiveDataDTO;
import cn.pluss.platform.dto.MercOrderDataDTO;
import cn.pluss.platform.dto.MercTradeDataDTO;
import cn.pluss.platform.merchant.MerchantBaseInfoService;
import cn.pluss.platform.util.PageUtils;
import cn.pluss.platform.util.StringUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 商户交易数据统计
 *
 * @author: bzg
 * @time: 2021/12/30 17:36
 */
@RequestMapping("/mercData")
@Controller
public class MerchantCountDataController {

    @Resource
    private MerchantBaseInfoService merchantBaseInfoService;

    @Resource
    private HttpServletRequest request;

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/chain")
    public String index() {
        return "countData/mercChainList";
    }

    @GetMapping("page")
    @ResponseBody
    public Result<PageInfo<MercOrderDataDTO>> page(Page<MercOrderDataDTO> page, MercOrderDataDTO dto) {
        Page<MercOrderDataDTO> pageData = merchantBaseInfoService.pageData(page, dto);
        return ResultGenerator.genSuccessResult(PageUtils.page(pageData));
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/trade")
    public String tradeIndex() {
        return "countData/mercTradeList";
    }

    /**
     * 商户交易信息统计
     *
     * @param page:
     * @param dto:
     * @return cn.pluss.platform.api.Result<cn.pluss.platform.api.PageInfo < cn.pluss.platform.dto.MercTradeData>>
     * @date: 2021/12/31 13:43
     */
    @GetMapping("tradePage")
    @ResponseBody
    public Result<Page<MercTradeDataDTO>> tradePage(Page<MercTradeDataDTO> page, MercTradeDataDTO dto, OrderItem orderItem) {
        if (StringUtil.isEmpty(dto.getField())) {
            dto.setField("tradeSumAmt");
            dto.setOrder("desc");
        }

        Page<MercTradeDataDTO> pageData;
        pageData = merchantBaseInfoService.pageTradeData(page, dto);

        return ResultGenerator.genSuccessResult(pageData);
    }

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/active")
    public String silentIndex() {
        return "countData/mercActiveList";
    }

    @GetMapping("activePage")
    @ResponseBody
    public Result<PageInfo<MercActiveDataDTO>> activePage(Page<MercActiveDataDTO> page, MercActiveDataDTO dto) {
        Page<MercActiveDataDTO> pageData = merchantBaseInfoService.pageActiveData(page, dto);
        return ResultGenerator.genSuccessResult(PageUtils.page(pageData));
    }
}
