package com.ssj.service.kmt.kmtsys.service.impl;

import com.ssj.bean.kmt.kmtsys.domain.KmtSysUser;
import com.ssj.dao.kmt.kmt.dao.KmtQueryDao;
import com.ssj.dao.kmt.kmtsys.dao.KmtSysUserDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.kmt.dto.KmtSysUserDTO;
import com.ssj.service.kmt.service.KmtSysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service
public class KmtSysUserServiceImpl extends BaseServiceImpl<KmtSysUser, String> implements KmtSysUserService {
	
	@Autowired
	private KmtSysUserDao dao;
	
	@Autowired
	private KmtQueryDao queryDao;

	@Override
	public PagingAndSortingRepository<KmtSysUser, String> getDao() {
		return dao;
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<KmtSysUser> findKmtSysUser() {
		return dao.findKmtSysUser();
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<KmtSysUser> findKmtSysUserByLoginName(String loginName) {
		return dao.findKmtSysUserByLoginName(loginName);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Integer countAddUserNum(String addUserId, Integer state) {
		return queryDao.countAddUserNum(addUserId, state);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public Integer countAddUserBySettlementNum(String addUserId,Integer settlement) {
		return queryDao.countAddUserBySettlementNum(addUserId, settlement);
	}

    @Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<KmtSysUserDTO> getDistributeCondition(int dealType) {
		String type;
		if (dealType == 1) {//题目加工员
			type = "QPM";
		} else {//dealType=2 题目审核员
			type = "SYS";
		}
		return queryDao.getDistributeCondition(type);
    }

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<KmtSysUser> findKmtSysUserByIds(List<String> ids) {
		return dao.findByIdIn(ids);
	}

	@Override
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public KmtSysUser findKmtSysUserById(String id) {
		return dao.getOne(id);
	}

	@Override
	public KmtSysUser findKmtSysUserByLoginNameAndType(String loginName, String type) {
		return dao.findKmtSysUserByLoginNameAndType(loginName, type);
	}

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