package com.keao.edu.auth.service.impl;

import java.util.List;

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

import com.keao.edu.auth.api.entity.SysUserRole;
import com.keao.edu.auth.dal.dao.SysUserRoleDao;
import com.keao.edu.auth.service.SysUserRoleService;
import com.keao.edu.common.dal.BaseDAO;
import com.keao.edu.common.service.impl.BaseServiceImpl;

@Service
public class SysUserRoleServiceImpl extends BaseServiceImpl<Integer, SysUserRole>  implements SysUserRoleService {
	
	@Autowired
	private SysUserRoleDao sysUserRoleDao;

	@Override
	public BaseDAO<Integer, SysUserRole> getDAO() {
		return sysUserRoleDao;
	}

	@Override
	public List<Integer> queryRoleIdListByUserId(Integer userId) {
		return sysUserRoleDao.queryRoleIdListByUserId(userId);
	}
	@Override
	public List<String> queryRoleCodeListByUserId(Integer userId) {
		return sysUserRoleDao.queryRoleCodeListByUserId(userId);
	}

	@Override
	public boolean batchInsert(Integer userId, String roleIds) {
		SysUserRole sysUserRole = new SysUserRole();
		sysUserRole.setUserId(userId);
		String[] split = roleIds.split(",");
		for (String string:split) {
			sysUserRole.setRoleId(Integer.parseInt(string));
			sysUserRoleDao.insert(sysUserRole);
		}
		return true;
	}

	@Override
	public boolean batchDel(Integer userId, String roleIds) {
		SysUserRole sysUserRole = new SysUserRole();
		sysUserRole.setUserId(userId);
		String[] split = roleIds.split(",");
		for (String string:split) {
			sysUserRole.setRoleId(Integer.parseInt(string));
			sysUserRoleDao.delete(sysUserRole);
		}
		return true;
	}

}