package com.ssj.sys.controller;

import com.ssj.framework.basic.common.bean.SplitPage;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.service.weixin.library.service.ILibJoinService;
import com.ssj.service.weixin.sales.service.ILibQdSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("sys/qdSales")
@Controller
public class QdSalesController extends BaseController {

	@Autowired
	private ILibQdSaleService qdSaleService;
	
	@Autowired
    private ILibJoinService libJoinService;
	
	/**
	 * 销售人员打款记录列表
	 * @param model
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/qdSalesList")
	public String qdSalesList(Model model,
			@RequestParam(required = false, defaultValue = "10") int pageSize,
			@RequestParam(required = false, defaultValue = "1") int pageNo)
			throws Exception {
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startTime", request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
		params.put("endTime", request.getParameter("endDate")==null?"":request.getParameter("endDate"));
		params.put("libId", request.getParameter("libId")==null?"":request.getParameter("libId"));
		params.put("stat", request.getParameter("stat")==null?"":request.getParameter("stat"));
		if(!"admin".equals(loginName())){
			params.put("orgCode", orgCodeStr());
		}
		SplitPage sp = new SplitPage();
	        sp.setAction(request.getRequestURI().toString());
	        sp.setPageNo(pageNo);
	        sp.setPageSize(pageSize);
	        sp.setParams(params);
	    Page<Map<String, Object>> page= qdSaleService.findForPage(params, initPage(pageNo, pageSize));
		sp.setRowCnt((int) page.getTotalElements());
		model.addAttribute("list", page.getContent());
		model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
		model.addAttribute("page", sp);
		model.addAttribute("search", params);
		model.addAttribute("libList",libJoinService.getLibJoinByCode(orgcodeList()));
		return "sys/qdsalse/qdSaleslist";
	}
}
