package cn.pluss.platform.controller.realFans;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.base.BaseModelController;
import cn.pluss.platform.entity.RealFans;
import cn.pluss.platform.realFans.RealFansService;
import cn.pluss.platform.util.StringUtil;
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;
import org.springframework.web.servlet.ModelAndView;


@Controller
@RequiredArgsConstructor
@RequestMapping("realFans")
public class RealFansController extends BaseModelController<RealFansService, RealFans> {

    private final RealFansService realFansService;

    /**
     * 引导页
     * @return
     */
    @GetMapping("index")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("realFans/realFansList");
        return view;
    }


    @RequestMapping(value = "/pageData")
    @ResponseBody
    public Result<Page<RealFans>> page(Page<RealFans> page, RealFans realFans) {
        if(StringUtil.isNotEmpty(realFans.getNickName())){
            String nickName = null;
            try {
                nickName = URLEncoder.encode(realFans.getNickName(),"UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            realFans.setNickName(nickName);
        }
        Page<RealFans> pageData = realFansService.pageData(page,realFans);
        return ResultGenerator.genSuccessResult(pageData);
    }
}


