package com.ssj.sys.controller;

import com.ssj.bean.common.framework.core.domain.Response;
import com.ssj.bean.weixin.libmy.domain.TbLibJoin;
import com.ssj.bean.weixin.sales.domain.*;
import com.ssj.framework.basic.common.bean.SplitPage;
import com.ssj.framework.core.common.controller.BaseController;
import com.ssj.service.sys.sort.service.SortService;
import com.ssj.service.weixin.library.service.ILibJoinService;
import com.ssj.service.weixin.sales.service.*;
import com.ssj.service.weixin.zuoyb.service.ZuoybStudentPushSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** 
 * @author  ZhangCaibao 
 * @version 2017年4月24日 上午11:27:25 
 * 类说明  运营后台 销售人员的基础配置
 */
@RequestMapping("sys/sales")
@Controller
public class SysSalesController extends BaseController {
	
	 @Autowired
	 private LibStaffingService libStaffingService;
	 @Autowired
	 private LibSalesPriceService libSalesPriceService;
	 @Autowired
	 private LibCommissionService libCommissionService;
	 @Autowired
	 private SortService sortService;
	 
	@Autowired
	private LibOrderDetailsService libOrderDetailsService;
	@Autowired
	private LibVipCodeService libVipCodeService;
	@Autowired
	private LibBorrowedServiceService  libBorrowedServiceService;
	@Autowired
	private LibVipServiceService  libVipServiceService;
	@Autowired
	private ZuoybStudentPushSerivce zuoybStudentPushSerivce;
	
	@Autowired
    private ILibJoinService libJoinService;
	 
	   /**
		 * 初始化总部销售人员管理
		 */
		@RequestMapping("/libStaffingList")
		public String libStaffingList(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("EQ_orgCode", "SSJ-SSJ-XX");
			params.put("LIKE_user.name",request.getParameter("LIKE_user.name")==null?"":request.getParameter("LIKE_user.name"));
			SplitPage sp = new SplitPage();
		        sp.setAction(request.getRequestURI().toString());
		        sp.setPageNo(pageNo);
		        sp.setPageSize(pageSize);
		        sp.setParams(params);
		    Page<LibStaffing> page= libStaffingService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
			sp.setRowCnt((int) page.getTotalElements());
			model.addAttribute("list", page.getContent());
			model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
			model.addAttribute("page", sp);
			model.addAttribute("search", params);
			return "sys/sales/libStaffingList";
		}
		 @RequestMapping(value = "/libStaffingDelete", method = RequestMethod.POST)
		 @ResponseBody
		 public Response libStaffingDelete(String id){
			 Response response = new  Response();
			 LibStaffing libStaffing= libStaffingService.getById(id);
			 libStaffing.setStat(2);
			 libStaffing=libStaffingService.save(libStaffing);
			 if("SSJ-SSJ-SD".equals(libStaffing.getType())){
				 libStaffingService.updateStatByUserId(libStaffing.getUserId(), 2);
			 }
			 response.success();
			 return response;
		 }
		 @RequestMapping(value = "/libStaffingSave", method = RequestMethod.POST)
		 @ResponseBody
		 public Response libStaffingSave(@RequestParam(value = "orgCode")String orgCode,
				    @RequestParam(value = "libId")String libId, 
		 			@RequestParam(value = "ids[]")String[] ids,String type) {
		 	        Response response = new Response();
		 	        try {
		 	        	libStaffingService.libStaffingSave(orgCode,libId, ids,type);
		 	            response.success("添加成功");
		 	        } catch (Exception e) {
		 	            e.printStackTrace();
		 	            response.failure("添加失败：" + e.getMessage());
		 	        }
		 	        return response;
		 	 } 
		 @RequestMapping(value = "/libStaffingZBSave", method = RequestMethod.POST)
		 @ResponseBody
		 public Response libStaffingZBSave(@RequestParam(value = "orgCode")String orgCode,
				 @RequestParam(value = "libId")String libId, 
				 @RequestParam(value = "ids[]")String[] ids,String type) {
			 Response response = new Response();
			 try {
				 libStaffingService.libStaffingZBSave(orgCode,libId, ids,type);
				 response.success("添加成功");
			 } catch (Exception e) {
				 e.printStackTrace();
				 response.failure("添加失败：" + e.getMessage());
			 }
			 return response;
		 } 
		 
		  @RequestMapping("/getUserList")
		  public String getUserList(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("name", request.getParameter("name")==null?"":request.getParameter("name"));
		    	params.put("libId", request.getParameter("libId"));
		    	params.put("type", request.getParameter("type"));
		    	params.put("orgCode", request.getParameter("orgCode"));
		    	SplitPage sp = new SplitPage();
		    	sp.setAction(request.getRequestURI().toString());
		    	sp.setPageNo(pageNo);
		    	sp.setPageSize(pageSize);
		    	sp.setParams(params);
		    	Page<Map<String, Object>> page= libStaffingService.getUserList(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);
		    	return "sys/sales/getUserList";
		 }
		  /**
		   * 添加总部销售
		  * @param model
		  * @param pageSize
		  * @param pageNo
		  * @return
		  * @throws Exception
		  * 创建人：ZhangCaibao 
		  * 2017年9月18日 上午9:34:57 
		  * @String
		   */
		  @RequestMapping("/getUserListZB")
		  public String getUserListZB(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("name", request.getParameter("name")==null?"":request.getParameter("name"));
			  params.put("libId", request.getParameter("libId"));
			  params.put("type", request.getParameter("type"));
			  params.put("orgCode", request.getParameter("orgCode"));
			  params.put("orglibId", "SSJ-SSJ-XX");
			  SplitPage sp = new SplitPage();
			  sp.setAction(request.getRequestURI().toString());
			  sp.setPageNo(pageNo);
			  sp.setPageSize(pageSize);
			  sp.setParams(params);
			  Page<Map<String, Object>> page= libStaffingService.getUserListZB(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);
			  return "sys/sales/getUserListZB";
		  }
		  /**
		   * 添加总部SD
		  * @param model
		  * @param pageSize
		  * @param pageNo
		  * @return
		  * @throws Exception
		  * 创建人：ZhangCaibao 
		  * 2017年9月18日 上午10:03:05 
		  * @String
		   */
		  @RequestMapping("/getUserListSD")
		  public String getUserListSD(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("name", request.getParameter("name")==null?"":request.getParameter("name"));
			  params.put("libId", request.getParameter("libId"));
			  params.put("type", request.getParameter("type"));
			  params.put("orgCode", request.getParameter("orgCode"));
			  params.put("orglibId", "SSJ-SSJ-SD");
			  SplitPage sp = new SplitPage();
			  sp.setAction(request.getRequestURI().toString());
			  sp.setPageNo(pageNo);
			  sp.setPageSize(pageSize);
			  sp.setParams(params);
			  Page<Map<String, Object>> page= libStaffingService.getUserListZB(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);
			  return "sys/sales/getUserListSD";
		  }
		  /**
		   *  作业吧管理员，从总部SR挑选
		  * @param model
		  * @param pageSize
		  * @param pageNo
		  * @return
		  * @throws Exception
		  * 创建人：ZhangCaibao 
		  * 2017年9月15日 下午2:32:37 
		  * @String
		   */
		  @RequestMapping("/getUserListSR")
		  public String getUserListSR(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("name", request.getParameter("name")==null?"":request.getParameter("name"));
			  params.put("libId", request.getParameter("libId"));
			  params.put("type", request.getParameter("type"));
			  params.put("orgCode", request.getParameter("orgCode"));
			  params.put("orglibId", "SSJ-SSJ-SR");
			  SplitPage sp = new SplitPage();
			  sp.setAction(request.getRequestURI().toString());
			  sp.setPageNo(pageNo);
			  sp.setPageSize(pageSize);
			  sp.setParams(params);
			  Page<Map<String, Object>> page= libStaffingService.getUserListSR(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);
			  return "sys/sales/getUserListSR";
		  }
		  
		  @RequestMapping("/staffingList")
		 public String staffingList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId,String orgCode)
					throws Exception {
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("EQ_libId",EQ_libId);
				params.put("EQ_stat","1");
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				params.put("LIKE_user.name",request.getParameter("LIKE_user.name")==null?"":request.getParameter("LIKE_user.name"));
				SplitPage sp = new SplitPage();
			        sp.setAction(request.getRequestURI().toString());
			        sp.setPageNo(pageNo);
			        sp.setPageSize(pageSize);
			        sp.setParams(params);
			    Page<LibStaffing> page= libStaffingService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
				sp.setRowCnt((int) page.getTotalElements());
				TbLibJoin join = libJoinService.getById(EQ_libId);
				params.put("orgCode",orgCode);
				model.addAttribute("list", page.getContent());
				model.addAttribute("listNavigatHtml", sp.getSysPaginHtml());
				model.addAttribute("page", sp);
				model.addAttribute("search", params);
				model.addAttribute("libtype", join.getLibtype());
				model.addAttribute("sortlist", sortService.getParamValByCode("staffing"));
				return "sys/sales/staffingList";
			} 
		  @RequestMapping("/staffingEdit")
		  public String staffingEdit(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
			  LibStaffing libStaffing= libStaffingService.getById(id);
				 if(libStaffing==null) {
					 libStaffing = new LibStaffing();
					 libStaffing.setLibId("SSJ");
				 }
				 model.addAttribute("staffing", libStaffing);
				 return "sys/sales/staffingEdit";
		 } 
		  
		  @RequestMapping(value = "/staffingListSave", method = RequestMethod.POST)
			@ResponseBody
			public Response staffingListSave(  LibStaffing libStaffing){
				    	Response response = new  Response();
				    	libStaffingService.save(libStaffing);
				    	List<LibStaffing> list = libStaffingService.findByUserId(libStaffing.getUserId());
				    	for (LibStaffing libStaffing2 : list) {
				    		if(libStaffing.getName()!=null){
				    			libStaffing2.setName(libStaffing.getName());
				    		}
				    		if(libStaffing.getTelephone()!=null){
				    			libStaffing2.setTelephone(libStaffing.getTelephone());
				    		}
				    		if(libStaffing.getSex()!=null){
				    			libStaffing2.setSex(libStaffing.getSex());
				    		}
						}
				    	libStaffingService.save(list);
				    	response.success();
				    	return response;
			}
		  
		  /**
		   * 总部初始化销售卡片类型价格表
		  * 创建人：ZhangCaibao 
		  * 2017年4月25日 上午11:08:54 
		  * @String
		   */
		  @RequestMapping("/libSalesPriceList")
		  public String libSalesPriceList(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("EQ_libId", "SSJ");
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				params.put("EQ_species", request.getParameter("EQ_species")==null?"":request.getParameter("EQ_species"));
				SplitPage sp = new SplitPage();
			    sp.setAction(request.getRequestURI().toString());
			    sp.setPageNo(pageNo);
			    sp.setPageSize(pageSize);
			    sp.setParams(params);
			    Page<LibSalesPrice> page= libSalesPriceService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
				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("cardType", sortService.getParamValByCode("cardType"));
				model.addAttribute("species", sortService.getParamValByCode("species"));
				return "sys/sales/libSalesPriceList";
			}
		  @RequestMapping("/libSalesPriceAdd")
		  public String libSalesPriceAdd(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
			  LibSalesPrice salesPrice= libSalesPriceService.getById(id);
				 if(salesPrice==null) {
					 salesPrice = new LibSalesPrice();
					 salesPrice.setLibId("SSJ");
				 }
				 model.addAttribute("salesPrice", salesPrice);
				 model.addAttribute("cardType", sortService.getParamValByCode("cardType"));
				 model.addAttribute("species", sortService.getParamValByCode("species"));
				 return "sys/sales/libSalesPriceAdd";
		 } 
		  
		@RequestMapping(value = "/libSalesPriceSave", method = RequestMethod.POST)
		@ResponseBody
		public Response libSalesPriceSave(  LibSalesPrice salesPrice){
			    	Response response = new  Response();
			    	salesPrice.setCreateTime(new Date());
			    	libSalesPriceService.save(salesPrice);
			    	response.success();
			    	return response;
		}
		 @RequestMapping(value = "/libSalesPriceDelete", method = RequestMethod.POST)
		 @ResponseBody
		 public Response libSalesPriceDelete( String id){
			 Response response = new  Response();
			 libSalesPriceService.delete(id);
			 response.success();
			 return response;
		 }
		 @RequestMapping("/salesPriceList")
		  public String salesPriceList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId)
					throws Exception {
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("EQ_libId",EQ_libId);
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				params.put("EQ_species", request.getParameter("EQ_species")==null?"":request.getParameter("EQ_species"));
				SplitPage sp = new SplitPage();
			    sp.setAction(request.getRequestURI().toString());
			    sp.setPageNo(pageNo);
			    sp.setPageSize(pageSize);
			    sp.setParams(params);
			    Page<LibSalesPrice> page= libSalesPriceService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "species" }));
				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("cardType", sortService.getParamValByCode("cardType"));
				model.addAttribute("species", sortService.getParamValByCode("species"));
				return "sys/sales/salesPriceList";
			}
		 @RequestMapping(value = "/updatePrice", method = RequestMethod.POST)
		 @ResponseBody
		 public Response updatePrice( String id,BigDecimal price){
			 Response response = new  Response();
			 libSalesPriceService.updatePrice(id, price);
			 response.success();
			 return response;
		 }
		 @RequestMapping(value = "/updateName", method = RequestMethod.POST)
		 @ResponseBody
		 public Response updateName( String id,String name){
			 Response response = new  Response();
			 libSalesPriceService.updateName(id, name);
			 response.success();
			 return response;
		 }
		 
		 /**
		  * 总部指定默认初始价格
		 * 创建人：ZhangCaibao 
		 * 2017年4月26日 上午11:41:33 
		 * @String
		  */
		 @RequestMapping("/libCommissionList")
		  public String libCommissionList(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("EQ_libId", "SSJ");
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				SplitPage sp = new SplitPage();
			    sp.setAction(request.getRequestURI().toString());
			    sp.setPageNo(pageNo);
			    sp.setPageSize(pageSize);
			    sp.setParams(params);
			    Page<LibCommission> page= libCommissionService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
				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("sortlist", sortService.getParamValByCode("staffing"));
				return "sys/sales/libCommissionList";
			}
		 /**
		  * 总部指定默认初始价格   新增页面
		 * 创建人：ZhangCaibao 
		 * 2017年4月26日 上午11:41:33 
		 * @String
		  */
		  @RequestMapping("/libCommissionAdd")
		  public String libCommissionAdd(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
			  LibCommission commission= libCommissionService.getById(id);
				 if(commission==null) {
					 commission = new LibCommission();
					 commission.setLibId("SSJ");
				 }
				 model.addAttribute("commission", commission);
				 model.addAttribute("sortlist", sortService.getParamValByCode("staffing"));
				 return "sys/sales/libCommissionAdd";
		 }
		@RequestMapping(value = "/libCommissionDelete", method = RequestMethod.POST)
		@ResponseBody
		public Response libCommissionDelete( String id){
				 Response response = new  Response();
				 libCommissionService.delete(id);
				 response.success();
				 return response;
		}
		
		@RequestMapping(value = "/libCommissionSave", method = RequestMethod.POST)
		@ResponseBody
		public Response libCommissionSave( LibCommission commission){
			    	Response response = new  Response();
			    	commission.setCreateTime(new Date());
			    	libCommissionService.save(commission);
			    	response.success();
			    	return response;
		}
		
		
		 @RequestMapping("/commissionList")
		  public String commissionList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId)
					throws Exception {
			    Map<String, Object> params = new HashMap<String, Object>();
				params.put("EQ_libId", "SSJ");
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				SplitPage sp = new SplitPage();
			    sp.setAction(request.getRequestURI().toString());
			    sp.setPageNo(pageNo);
			    sp.setPageSize(pageSize);
			    sp.setParams(params);
			    Page<LibCommission> page= libCommissionService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
				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("sortlist", sortService.getParamValByCode("staffing"));
				return "sys/sales/commissionList";
			}
		 @RequestMapping(value = "/updateNewSign", method = RequestMethod.POST)
		 @ResponseBody
		 public Response updateNewSign( String id,BigDecimal newSign){
			 Response response = new  Response();
			 libCommissionService.updateNewSign(id, newSign);
			 response.success();
			 return response;
		 }
		 @RequestMapping(value = "/updateXSign", method = RequestMethod.POST)
		 @ResponseBody
		 public Response updateXSign( String id,BigDecimal xSign){
			 Response response = new  Response();
			 libCommissionService.updateXSign(id, xSign);
			 response.success();
			 return response;
		 }
		 
		 
		 /**
			 * 销售VIP卡的订单记录
			* @param model
			* @param pageSize
			* @param pageNo
			* @return
			* @throws Exception
			* 创建人：ZhangCaibao 
			* 2017年5月8日 上午10:32:18 
			* @String
			 */
			@RequestMapping("/orderList")
			public String orderList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String libId)
							throws Exception {
				
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("order_status", request.getParameter("order_status")==null?"":request.getParameter("order_status"));
				params.put("order_type", request.getParameter("order_type")==null?"":request.getParameter("order_type"));
				params.put("beginDate", request.getParameter("beginDate")==null?"":request.getParameter("beginDate"));
				params.put("endDate", request.getParameter("endDate")==null?"":request.getParameter("endDate"));
				params.put("libId", libId);
				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= libOrderDetailsService.findForPageList(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);
				return "sys/sales/orderList";
			}

			@RequestMapping("/vipsellOrderList")
			public String vipsellOrderList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId)
							throws Exception {
				
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("baby_name", request.getParameter("baby_name")==null?"":request.getParameter("baby_name"));
				params.put("name", request.getParameter("name")==null?"":request.getParameter("name"));
				 params.put("EQ_libId",EQ_libId);
				SplitPage sp = new SplitPage();
				sp.setAction(request.getRequestURI().toString());
				sp.setPageNo(pageNo);
				sp.setPageSize(pageSize);
				sp.setParams(params);
				Page<Map<String, Object>>  page= libOrderDetailsService.findForsellPageList(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);
				return "sys/sales/vipsellOrderList";
			}
			
			
            /**
             *  邀请码
            * @param model
            * @param pageSize
            * @param pageNo
            * @return
            * @throws Exception
            * 创建人：ZhangCaibao 
            * 2017年6月6日 下午4:11:55 
            * @String
             */
			  @RequestMapping("/libVipCodeList")
			  public String libVipCodeList(Model model,
						@RequestParam(required = false, defaultValue = "10") int pageSize,
						@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId)
						throws Exception {
					Map<String, Object> params = new HashMap<String, Object>();
					params.put("EQ_libId", EQ_libId);
					params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
					SplitPage sp = new SplitPage();
				    sp.setAction(request.getRequestURI().toString());
				    sp.setPageNo(pageNo);
				    sp.setPageSize(pageSize);
				    sp.setParams(params);
				    Page<LibVipCode> page= libVipCodeService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
					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("cardType", sortService.getParamValByCode("cardType"));
					model.addAttribute("species", sortService.getParamValByCode("species"));
					return "sys/sales/libVipCodeList";
				}
				@RequestMapping(value = "/libVipCodeDelete", method = RequestMethod.POST)
				@ResponseBody
				public Response libVipCodeDelete( String id){
						 Response response = new  Response();
						 libVipCodeService.delete(id);
						 response.success();
						 return response;
				}
				
				  @RequestMapping("/libVipCodeAdd")
				  public String libVipCodeAdd(Model model,String libId) throws Exception {
						 model.addAttribute("libId", libId);
						 return "sys/sales/libVipCodeAdd";
				 }
				  
				 @RequestMapping(value = "/libVipCodeSave", method = RequestMethod.POST)
				 @ResponseBody
				 public Response libVipCodeSave(String libId,Integer num,String discount){
				    	Response response = new  Response();
				    	if(libId!=null && libId.length()>0){
				    		if(num!=null && num>0){
				    			for (int i = 0; i <num; i++) {
				    				libVipCodeService.inserLibVipCode(libId, discount);
								}
				    		}
				    	}
				    	response.success();
				    	return response;
				 }	
				 
				 
				 
				 
			/**	 
			 * 初始化卡片服务的功能--初始值
			* @param model
			* @param pageSize
			* @param pageNo
			* @return
			* @throws Exception
			* 创建人：ZhangCaibao 
			* 2017年6月22日 下午3:06:29 
			* @String
			 */
		    @RequestMapping("/libBorrowedServiceList")
			public String libBorrowedServiceList(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("EQ_libId", "SSJ");
						params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
						params.put("EQ_species", request.getParameter("EQ_species")==null?"":request.getParameter("EQ_species"));
						SplitPage sp = new SplitPage();
					    sp.setAction(request.getRequestURI().toString());
					    sp.setPageNo(pageNo);
					    sp.setPageSize(pageSize);
					    sp.setParams(params);
					    Page<LibBorrowedService> page= libBorrowedServiceService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
						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("cardType", sortService.getParamValByCode("cardType"));
						model.addAttribute("species", sortService.getParamValByCode("species"));
						return "sys/sales/libBorrowedServiceList";
		  }
		/**    
		 * 删除卡的服务
		* @param id
		* @return
		* 创建人：ZhangCaibao 
		* 2017年6月22日 下午3:10:46 
		* @Response
		 */
		@RequestMapping(value = "/libBorrowedServiceDelete", method = RequestMethod.POST)
		@ResponseBody
		 public Response libBorrowedServiceDelete( String id){
				 Response response = new  Response();
				 libBorrowedServiceService.delete(id);
				 response.success();
				 return response;
		 }
		  @RequestMapping("/libBorrowedServiceAdd")
		  public String libBorrowedServiceAdd(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
			  LibBorrowedService salesPrice= libBorrowedServiceService.getById(id);
				 if(salesPrice==null) {
					 salesPrice = new LibBorrowedService();
					 salesPrice.setLibId("SSJ");
				 }
				 model.addAttribute("salesPrice", salesPrice);
				 model.addAttribute("cardType", sortService.getParamValByCode("cardType"));
				 model.addAttribute("species", sortService.getParamValByCode("species"));
				 return "sys/sales/libBorrowedServiceAdd";
		 } 
		  
		@RequestMapping(value = "/libBorrowedServiceSave", method = RequestMethod.POST)
		@ResponseBody
		public Response libBorrowedServiceSave( LibBorrowedService libBorrowedService){
			    	Response response = new  Response();
			    	libBorrowedService.setCreateTime(new Date());
			    	libBorrowedServiceService.save(libBorrowedService);
			    	response.success();
			    	return response;
		}
		/**
		 * 图书馆对应卡片服务功能
		* @param model
		* @param pageSize
		* @param pageNo
		* @param EQ_libId
		* @return
		* @throws Exception
		* 创建人：ZhangCaibao 
		* 2017年6月22日 下午3:30:00 
		* @String
		 */
		 @RequestMapping("/borrowedServiceList")
		  public String borrowedServiceList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId)
					throws Exception {
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("EQ_libId",EQ_libId);
				params.put("EQ_type", request.getParameter("EQ_type")==null?"":request.getParameter("EQ_type"));
				params.put("EQ_species", request.getParameter("EQ_species")==null?"":request.getParameter("EQ_species"));
				SplitPage sp = new SplitPage();
			    sp.setAction(request.getRequestURI().toString());
			    sp.setPageNo(pageNo);
			    sp.setPageSize(pageSize);
			    sp.setParams(params);
			    Page<LibBorrowedService> page= libBorrowedServiceService.findByPage(params, initPage(pageNo,pageSize,Direction.DESC, new String[] { "createTime" }));
				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("cardType", sortService.getParamValByCode("cardType"));
				model.addAttribute("species", sortService.getParamValByCode("species"));
				return "sys/sales/borrowedServiceList";
			}
		 
		  @RequestMapping("/borrowedServiceAdd")
		  public String borrowedServiceAdd(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
			  LibBorrowedService salesPrice= libBorrowedServiceService.getById(id);
				 model.addAttribute("salesPrice", salesPrice);
				 model.addAttribute("cardType", sortService.getParamValByCode("cardType"));
				 model.addAttribute("species", sortService.getParamValByCode("species"));
				 return "sys/sales/borrowedServiceAdd";
		 } 
		  
		  /**
		   *  馆长查询有哪些会员购买该馆的服务
		  * @param model
		  * @param pageSize
		  * @param pageNo
		  * @return
		  * @throws Exception
		  * 创建人：ZhangCaibao 
		  * 2017年6月27日 下午2:52:50 
		  * @String
		   */
		    @RequestMapping("/libVipServiceList")
			public String libVipServiceList(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("child_name",request.getParameter("child_name") == null ? "" : request.getParameter("child_name"));
				params.put("level",request.getParameter("level") == null ? "" : request.getParameter("level"));
				params.put("flow_id",request.getParameter("flow_id") == null ? "" : request.getParameter("flow_id"));
				params.put("type",request.getParameter("type") == null ? "" : request.getParameter("type"));
				params.put("libId", request.getParameter("libId")==null?"":request.getParameter("libId"));
				if(!"admin".equals(loginName())){
					params.put("orgCode",orgCodeStr());
				}else{
					if(params.get("libId").toString().equals("")){
						params.put("orgCode","1");
					}
				}

				SplitPage sp = new SplitPage();
				sp.setAction(request.getRequestURI().toString());
				sp.setPageNo(pageNo);
				sp.setPageSize(pageSize);
				sp.setParams(params);
				Page<Map<String, Object>> page = libVipServiceService.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("cardType", sortService.getParamValByCode("cardType"));
				model.addAttribute("species", sortService.getParamValByCode("species"));
				model.addAttribute("libList",libJoinService.getLibJoinByCode(orgcodeList()));
				return "sys/sales/libVipServiceList";
			}

	/**
	 *  馆长查询有哪些会员购买该馆的服务
	 * @param model
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * @throws Exception
	 * 创建人：ZhangCaibao
	 * 2017年6月27日 下午2:52:50
	 * @String
	 */
	@RequestMapping("/readVipServiceList")
	public String readVipServiceList(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("child_name",request.getParameter("child_name") == null ? "" : request.getParameter("child_name"));
		params.put("level",request.getParameter("level") == null ? "" : request.getParameter("level"));
		params.put("flow_id",request.getParameter("flow_id") == null ? "" : request.getParameter("flow_id"));
		params.put("type",request.getParameter("type") == null ? "" : request.getParameter("type"));
		params.put("libId", request.getParameter("libId")==null?"":request.getParameter("libId"));
		if(!"admin".equals(loginName())){
			params.put("orgCode",orgCodeStr());
		}else{
			if(params.get("libId").toString().equals("")){
				params.put("orgCode","1");
			}
		}

		SplitPage sp = new SplitPage();
		sp.setAction(request.getRequestURI().toString());
		sp.setPageNo(pageNo);
		sp.setPageSize(pageSize);
		sp.setParams(params);
		Page<Map<String, Object>> page = libVipServiceService.findForPage2(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("cardType", sortService.getParamValByCode("cardType"));
		model.addAttribute("species", sortService.getParamValByCode("species"));
		model.addAttribute("libList",libJoinService.getLibJoinByCode(orgcodeList()));
		return "sys/sales/libVipServiceList2";
	}
		
		    
		      @RequestMapping("/libVipServiceUpdate")
			  public String libVipServiceUpdate(Model model,@RequestParam( defaultValue = "0")String id) throws Exception {
		    	  LibVipService libVipService= libVipServiceService.getById(id);
					 model.addAttribute("vip", libVipService);
					 model.addAttribute("cardType", sortService.getParamValByCode("cardType"));
					 return "sys/sales/libVipServiceUpdate";
			 } 	
		      
		@RequestMapping(value = "/libVipServieUpdateSave", method = RequestMethod.POST)
		@ResponseBody
		public Response libVipServieUpdateSave(  LibVipService libVipService){
					    	Response response = new  Response();
					    	libVipServiceService.save(libVipService);
					    	response.success();
					    	return response;
		}
		
		
		 @RequestMapping(value = "/showIndex", method = RequestMethod.POST)
		 @ResponseBody
		 public Response showIndex(String id,Integer stat){
			 Response response = new  Response();
			 Integer i= libVipServiceService.updateStat(id, stat);
			 if(i>0){
				 response.success();
			 }else{
				 response.failure();
			 }
			 return response;
		 }
		 @RequestMapping("/ssjzybmemberList")
		  public String ssjzybmemberList(Model model,
					@RequestParam(required = false, defaultValue = "10") int pageSize,
					@RequestParam(required = false, defaultValue = "1") int pageNo,String EQ_libId) throws Exception {
			  Map<String, Object> params = new HashMap<String, Object>();
				 params.put("EQ_libId", EQ_libId);
				 params.put("child_name", request.getParameter("child_name")==null?"":request.getParameter("child_name"));
				 params.put("parent_name", request.getParameter("parent_name")==null?"":request.getParameter("parent_name"));
				SplitPage sp = new SplitPage();
			        sp.setAction(request.getRequestURI().toString());
			        sp.setPageNo(pageNo);
			        sp.setPageSize(pageSize);
			        sp.setParams(params);
			    Page<Map<String, Object>>  page= zuoybStudentPushSerivce.zuoybStudentPushList(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);
					return "sys/sales/ssjzybmemberList";
		 }			 
}
