package com.xintong.visualinspection.service.impl;

import java.util.ArrayList;
import java.util.List;

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

import com.mysql.jdbc.StringUtils;
import com.xintong.visualinspection.bean.User;
import com.xintong.visualinspection.bean.UserClass;
import com.xintong.visualinspection.dao.master.UserClassDao;
import com.xintong.visualinspection.service.BaseService;
import com.xintong.visualinspection.service.UserClassService;
import com.xintong.visualinspection.util.CacheUtil;

/**
 * 文件名：UserServiceImpl
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@Service
public class UserClassServiceImpl extends BaseService implements UserClassService {

    private static final org.slf4j.Logger logger = LoggerFactory.getLogger(UserClassServiceImpl.class);

    @Autowired
    UserClassDao userClassDao ;
    
	@Override
	public void insertList(List<UserClass> list) {
		// TODO Auto-generated method stub
		for(int i=0;i<list.size();i++){
			userClassDao.insert(list.get(i));
		}
	}

	@Override
	public void updateList(List<UserClass> list) {
		userClassDao.delete(list.get(0));
		for(int i=0;i<list.size();i++){
			userClassDao.insert(list.get(i));
		}
	}

	@Override
	public List<UserClass> selectList(UserClass obj) {
		return userClassDao.selectList(obj);
	}

	@Override
	public List<User> getUsersByTeamId(Integer user_class_id) {
		// TODO Auto-generated method stub
		String users= userClassDao.getUsersByTeamId(user_class_id);
		if(!StringUtils.isNullOrEmpty(users)) {
			String[] userArr = users.split(",");
			List<User> userList = new ArrayList<User>();
			for(String s:userArr) {
				userList.add(CacheUtil.userMap.get(Long.parseLong(s)));
			}
			return userList;
		}
		return null;
	}
   
}
