package com.iamberry.wechat.handles.admin;

import com.iamberry.wechat.core.entity.page.PageRequest;
import com.iamberry.wechat.core.entity.page.PagedResult;
import com.iamberry.wechat.core.entity.report.Report;
import com.iamberry.wechat.face.report.ReportService;
import com.iamberry.wechat.utils.StitchAttrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 免费领取充电器
 * Created by wxm on 2017/10/11.
 */
@Controller
@RequestMapping("/admin/report")
public class AdminReportHandler {

	@Autowired
	private ReportService reportService;

	/**
	 * 查询积分记录 并分页 (支持查询条件模糊搜索)
	 * 2018年2月24日
	 * @author mzx
	 * @param pageNO	分页信息
	 * @return
	 */
	@RequestMapping("/listReport")
	public ModelAndView listIntegral(Report report,
									 @RequestParam(value= "pageSize",defaultValue= "15" ,required=false) Integer pageSize,
									 @RequestParam(value = "pageNO", defaultValue = "1",required=false) Integer pageNO,
									 @RequestParam(value = "totalNum", defaultValue = "0", required = false) Integer totalNum,
									 HttpServletRequest request) throws Exception {
		ModelAndView mv = new ModelAndView("admin/report/listReport");
		// 封装请求数据
		PageRequest<Report> pageRequest = new PageRequest<>(report, pageNO, pageSize, totalNum == 0);
		// 查询订单列表
		PagedResult<Report> result = reportService.listAdminReport(pageRequest);
		if (totalNum != 0) {
			result.setTotal(totalNum);
		}
		StitchAttrUtil.getSa().setModelAndView(report, mv, "/admin/report/listReport", result);
		return mv;
	}

}
