package cn.pluss.platform.controller.userProfit;


import cn.pluss.platform.api.PageInfo;
import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.entity.UserProfit;
import cn.pluss.platform.user.UserProfitService;
import cn.pluss.platform.util.DateUtils;
import cn.pluss.platform.util.PageUtils;
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.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>
 * 用户流水统计控制器
 * </p>
 *
 * @author bzg
 * @since 2022-01-13
 */
@Controller
@RequestMapping("/userProft")
public class UserProfitController extends BaseModelController<UserProfitService, UserProfit> {

    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = "/flow")
    public String index(HttpServletRequest request) {
        return "countData/userFlowList";
    }


    @GetMapping("pageData")
    @ResponseBody
    public Result<PageInfo<UserProfit>> pageData(Page<UserProfit> page, UserProfit condition) {
        if(condition.getProfitDate() == null){
            Date date = DateUtils.add(Calendar.DAY_OF_MONTH, DateUtils.currentDate(), -1);
            condition.setProfitDate(date);
        }
        page = this.baseService.pageData(page, condition);
        return ResultGenerator.genSuccessResult(PageUtils.page(page));
    }
}
