package com.iamberry.wechat.service.drp;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iamberry.app.tool.log.RatFWLogger;
import com.iamberry.wechat.core.entity.PageBean;
import com.iamberry.wechat.core.entity.drp.PlaceLogs;
import com.iamberry.wechat.face.admin.SystemService;
import com.iamberry.wechat.face.drp.PlaceLogsService;
import com.iamberry.wechat.face.member.MemberService;
import com.iamberry.wechat.service.mapper.PlaceInfoMapper;
import com.iamberry.wechat.service.mapper.PlaceLogsMapper;
import com.iamberry.wechat.tools.StaticInfo;

/**
 * @description 分销代理现金收支记录处理逻辑
 * @author 欧阳明
 * @date 2016-4-19
 */
@Service("placeLogsServiceImpl")
@SuppressWarnings(value="unchecked")
public class PlaceLogsServiceImpl implements PlaceLogsService {

	@Autowired
	private PlaceLogsMapper  placeLogsMapper;
	
	@Autowired
	private PlaceInfoMapper placeInfoMapper;
	
	@Autowired
	private SystemService  systemService;
	
	@Autowired
	private RatFWLogger logger;
	
	@Autowired
	private MemberService  memberService;
	
	
	
	//获取查询用户条件的openid字符串
	public String getConditionString(List<String> list){
		int size=list.size();
		StringBuffer sbf=new StringBuffer();
		for(int i=0;i<size;i++){
			 String openid2=list.get(i);
			 if(i!=size-1){
				 sbf.append("'"+openid2+"',");
			 }else{
				 sbf.append("'"+openid2+"'");
			 }
		 }
		
		return "("+sbf.toString()+")";
	}
	
	
	//获取分销商收入支出现金记录综合查询-分页
	public Map SearchPlaceLogsPage(PageBean page) {
		Map hm=new HashMap();
		PageBean pageIndex=new PageBean();
		PlaceLogs placeLogs=(PlaceLogs)page.getCondition();
		
		String str=placeLogs.getEndDate();
		if(str!=null && !"".equals(str)){
			placeLogs.setEndDate(str+StaticInfo.endDateC);
		}
		
		pageIndex.setPageNumber(page.getPageNumber());
		pageIndex.setPageSize(page.getPageSize());
		
		if(page.getPageCount()>0){
			pageIndex.setCount(page.getPageCount());
		}else{
			pageIndex.setCount(placeLogsMapper.getAllCount(placeLogs));
		}
		
		pageIndex.initRecordBegin();
		placeLogs.setPage(pageIndex);
		List<PlaceLogs> lists=placeLogsMapper.selectAll(placeLogs);
		
        hm.put("data",lists);
		hm.put("page",pageIndex);
		return hm;
	}

	//===================================分销订单收入记录========================================
	//分销订单收入记录
	/*public Map searchDrpRecord(PageBean page) {
		HashMap conditionMap=new HashMap();
		Map hm=new HashMap();
		PageBean pageIndex=new PageBean();
		PlaceInfo placeInfo=(PlaceInfo)page.getCondition();
		//获取收入账的类型
		int type=placeInfo.getType();
		placeInfo=placeInfoMapper.getOnePlaceInfoByInitcode(placeInfo);
	
		if(placeInfo.getType()==1){
			conditionMap=(HashMap) getUnIncomeOrderListForTopDrp(placeInfo);
		}else if(placeInfo.getType()==2){
			conditionMap=(HashMap) getUnIncomeOrderListForSecondDrp(placeInfo);
		}else{
			conditionMap=(HashMap)getUnIncomeOrderListForThreeDrp(placeInfo);
		}
		if(conditionMap.get("openids1")==null || conditionMap.get("openids1").equals("()")){
			hm.put("data", null);
			hm.put("page",null);
			return hm;
		}
		page.initRecordBegin();
		conditionMap.put("recordBegin",page.getRecordBegin());
		conditionMap.put("pageSize", page.getPageSize());
		pageIndex.setPageSize(page.getPageSize());
		pageIndex.setPageNumber(page.getPageNumber());
		//是否入账
		conditionMap.put("isReward", type);
		List<IncomeRecord> records=placeLogsMapper.getSearchInComeRecord(conditionMap);
		
		pageIndex.setCount(placeLogsMapper.getSearchInComeRecordCount(conditionMap));
		 hm.put("data", records);
		 hm.put("page", pageIndex);
		
		return hm;
	}*/
	
	
}
