package com.ssj.service.weixin.problem.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.fx.domain.MerchantOut;
import com.ssj.bean.weixin.problem.domain.CnArea;
import com.ssj.dao.weixin.problem.dao.CnAreaDao;
import com.ssj.dao.weixin.problem.dao.ProblemQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.weixin.problem.service.CnAreaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

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


@Service(version="1.0")
@Transactional
public class CnAreaServiceImpl extends BaseServiceImpl<CnArea, String> implements CnAreaService{
	@Autowired
	private CnAreaDao  cnAreaDao;
	@Autowired
	private ProblemQueryDao  problemQueryDao;

	@Override
	public Page<Map<String, Object>> findCnAreaPage(
			Map<String, Object> searchParams, Pageable pageable) {
		return problemQueryDao.findCnAreaPage(searchParams, pageable);
	}

	@Override
	public PagingAndSortingRepository<CnArea, String> getDao() {
		return cnAreaDao;
	}

	@Override
	public String getName(String city, String name) {
		return cnAreaDao.getName(city, name);
	}
	
	@Override
	public List<CnArea> findByTypeList(String type) {
		return cnAreaDao.findByTypeList(type);
	}
	
	@Override
	public List<CnArea> findByTypeList(String type,String upId) {
		return cnAreaDao.findByTypeList(type,upId);
	}

	@Override
	public String getLocationArea(String league_lat, String league_lng,
			Integer type) {
		return cnAreaDao.getLocationArea(league_lat, league_lng, type);
	}

	@Override
	public List<CnArea> findListByCreateTime(String createTime) {
		return cnAreaDao.findListByCreateTime(createTime);
	}

	@Override
	public List<CnArea> findLatLngIsNullList() {
		return cnAreaDao.findLatLngIsNullList();
	}

	@Override
	public int getTextBookBanben(String schoolName) {
		CnArea cnArea =  cnAreaDao.findFirstByName(schoolName);
		if(cnArea == null) {
			//默认广州人教版
			return 2;
		}
		return cnArea.getBanben();
	}

	@Override
	public List<String> findByName(String name) {
		return cnAreaDao.findByName(name);
	}

	@Override
	public List<String> findBySchoolName(String startTime, String endTime) {
		return cnAreaDao.findBySchoolName(startTime,endTime);
	}

	@Override
	public List<Map<String, Object>> findCnAreaAll(Map<String, Object> params) {
		return problemQueryDao.findCnAreaAll(params);
	}

	@Override
	public Page<MerchantOut> findMerchantByPage(Map<String, Object> params, Pageable initPage) {
		return problemQueryDao.findMerchantByPage(params,initPage);
	}

	@Override
	public List<CnArea> findByTypeList(String type, String upId, String name, Integer pageNo, Integer pageSize) {
		if(StringUtils.isNotEmpty(name)) {
			return cnAreaDao.findByTypeList(type,upId,name,(pageNo-1)*pageSize,pageSize);
		}else {
			return cnAreaDao.findByTypeList(type,upId,(pageNo-1)*pageSize,pageSize);
		}
	}

	@Override
	public Long countByTypeList(String type, String upId, String name) {
		if(StringUtils.isNotEmpty(name)) {
			return cnAreaDao.countByTypeList(type, upId, name);
		}else {
			return cnAreaDao.countByTypeList(type, upId);
		}
	}

}
