package com.yonge.cooleshow.auth.service.impl;

import java.util.List;

import com.yonge.toolset.mybatis.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yonge.cooleshow.auth.api.entity.SysUserRole;
import com.yonge.cooleshow.auth.dal.dao.SysUserRoleDao;
import com.yonge.cooleshow.auth.service.SysUserRoleService;
import com.yonge.toolset.mybatis.dal.BaseDAO;

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

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

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

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

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

}