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

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.weixin.zyb.domain.ZuoybKnowHowDetailsSort;
import com.ssj.dao.weixin.zuoyb.dao.ZuoybKnowHowDetailsSortDao;
import com.ssj.dao.weixin.zuoyb.dao.ZuoybQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.persistence.DynamicSpecifications;
import com.ssj.framework.core.persistence.SearchFilter;
import com.ssj.mapper.knowledge.KmtKnowledgeMapper;
import com.ssj.service.weixin.zuoyb.service.ZuoybKnowHowDetailsSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

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


/** 
 * @author  ZhangCaibao 
 * @version 2018年3月11日 上午8:27:27 
 * 类说明 
 */
@Service(version="1.0")
@Transactional
public class ZuoybKnowHowDetailsSortServiceImpl extends BaseServiceImpl<ZuoybKnowHowDetailsSort, String> implements ZuoybKnowHowDetailsSortService {

	@Autowired
	private  ZuoybKnowHowDetailsSortDao  zuoybKnowHowDetailsSortDao;
	@Autowired
	private ZuoybQueryDao queryDao;
	@Autowired
	private KmtKnowledgeMapper kmtKnowledgeMapper;
	@Override
	public PagingAndSortingRepository<ZuoybKnowHowDetailsSort, String> getDao() {
		return zuoybKnowHowDetailsSortDao;
	}

	@Override
	public ZuoybKnowHowDetailsSort findByHowDetailsIdAndType(
			String howDetailsId, Integer type) {
		return zuoybKnowHowDetailsSortDao.findByHowDetailsIdAndType(howDetailsId, type);
	}

	@Override
	public Page<ZuoybKnowHowDetailsSort> findByPage(Map<String, Object> params,
			Pageable sp) {
		Map<String, SearchFilter> filters = SearchFilter.parse(params);
		Specification<ZuoybKnowHowDetailsSort> specification = DynamicSpecifications.bySearchFilter(filters.values(), ZuoybKnowHowDetailsSort.class);    
		return  zuoybKnowHowDetailsSortDao.findAll(specification, sp);
	}

	@Override
	public void updateKnowHowDetailSortNum(String id, Integer num) {
		zuoybKnowHowDetailsSortDao.updateKnowHowDetailSortNum(id, num);
	}

	@Override
	public List<Map<String, Object>> getKonwVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howName) {
		return queryDao.getKonwVersion(libId, courseName, grade, banben, semester, howName);
	}

	@Override
	public List<Map<String, Object>> getKonwDetailVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howDetailsName) {
		return queryDao.getKonwDetailVersion(libId, courseName, grade, banben, semester, howDetailsName);
	}

	@Override
	public List<Map<String, Object>> getKonwDetailKdVersion(String libId,
			String courseName, String grade, Integer banben, Integer semester,
			String howDetailsKdName) {
		return queryDao.getKonwDetailKdVersion(libId, courseName, grade, banben, semester, howDetailsKdName);
	}

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

	@Override
	public String getZuoybKnowHowDetailsKdName(String courseName, String grade,
			String banben, String semester, String howDetailsId) {
		return zuoybKnowHowDetailsSortDao.getZuoybKnowHowDetailsKdName(courseName, grade, banben, semester, howDetailsId);
	}


	@Override
	public void updateBeforeKd(String beforeKdId, String sortId) {
		zuoybKnowHowDetailsSortDao.updateBeforeKd(beforeKdId, sortId);
	}

    @Override
    public List<ZuoybKnowHowDetailsSort> findByHowDetailsKdIdIn(List<String> knowHowDetailsKdIdList) {
        return zuoybKnowHowDetailsSortDao.findByHowDetailsIdInAndStat(knowHowDetailsKdIdList, 3);
    }

	@Override
	public List<ZuoybKnowHowDetailsSort> findByHowDetailsId(String knowHowDetailId) {
		return zuoybKnowHowDetailsSortDao.findByHowDetailsIdAndStat(knowHowDetailId, 2);
	}

	@Override
	public ZuoybKnowHowDetailsSort findByHowId(String howId) {
		return zuoybKnowHowDetailsSortDao.findByHowIdAndStat(howId, 1);
	}

    @Override
    public List<ZuoybKnowHowDetailsSort> findByTypeAndHowDetailsIdIn(Integer type, List<String> knowHowDetailsIdList) {
        return zuoybKnowHowDetailsSortDao.findByTypeAndStatAndHowDetailsIdIn(type, 2, knowHowDetailsIdList);
    }

	@Override
	public List<ZuoybKnowHowDetailsSort> findByCourseNameAndGradeAndSemesterAndTypeAndStatAndHowId(String courseName, String grade, int semester, int type, int stat, String howId) {
		return zuoybKnowHowDetailsSortDao.findByCourseNameAndGradeAndSemesterAndTypeAndStatAndHowIdOrderByNum(courseName, grade, semester, type, stat, howId);
	}

	@Override
	public ZuoybKnowHowDetailsSort findKnowHowByTypeAndHowId(int type, String howId) {
		return zuoybKnowHowDetailsSortDao.findTopByTypeAndHowIdAndStat(type, howId, 1);
	}

	@Override
	public List<ZuoybKnowHowDetailsSort> findByHowDetailIdAndTypeAndGradeAndSemester(List<String> howDetailIds, String grade, int semester, int type) {
		return kmtKnowledgeMapper.findByHowDetailIdAndTypeAndGradeAndSemester(howDetailIds, grade, semester, type);
	}
}
