package org.well.well.manager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.well.well.core.hibernate.HibernateEntityDao;
import org.well.well.core.util.StringUtils;
import org.well.well.domain.BusWell;
import org.well.well.domain.SysUser;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserManager extends HibernateEntityDao<SysUser> {


    @Resource
    UserClientManager userClientManager;
    private static final String[] strings={"1","2","3"};//状态(1：启用 2：冻结 3：删除）
    public  List<SysUser> getUsersByWell(BusWell busWell){//根据井编号查负责人
        List<SysUser> sysUsers = new ArrayList<SysUser>();
        if(null!=busWell&& StringUtils.isNotBlank(busWell.getDeptid())){
            Criteria criteria = getSession().createCriteria(SysUser.class);
            criteria.add(Restrictions.eq("deptid", Long.valueOf(busWell.getResponsibleDeptid())));
            criteria.add(Restrictions.eq("status", strings[0]));
            sysUsers = criteria.list();
        }
       return  sysUsers;
    }

    public List<String> getClients(BusWell busWell){
        List<String> cids= new ArrayList<String>();
        List<SysUser> sysUsers=getUsersByWell(busWell);
        for(SysUser sysUser:sysUsers){
            String cid=userClientManager.getClientByUser(sysUser);
            cids.add(cid);
        }
        return cids;
    }
}