package connect;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import Allclass.CameraMessage;
import Allclass.GroupDomainMessage;
import Allclass.GroupsMessge;
public class GroupDomainID {
/**
* 查询所有GroupDomain
* @return
* @throws SQLException
*/
public List<GroupDomainMessage> getlist(int userid) throws SQLException
{
List<GroupDomainMessage> list=new ArrayList<GroupDomainMessage>();
Connectionsql con=new Connectionsql();
con.openConnection();
//where gd.GroupDomainParent=0
String sql="select * from GroupDomain gd "+
"UNION select gpd.* from Groups gs,users us,UserGroupItem ugt,UserCamera uc, "+
"GroupDomain gpd where us.UserID = ugt.UserID and ugt.UserCameraID = uc.UserCameraID "+
"and uc.GroupID = gs.GroupID and gpd.GroupDomainID = gs.GroupDomainID and us.UserID ="+userid
+" UNION select gpd.* from GroupDomain gpd where gpd.GroupDomainID in ( "+
"select gpd.GroupDomainParent from Groups gs,users us,UserGroupItem ugt,UserCamera uc, "+
"GroupDomain gpd where "+
"us.UserID = ugt.UserID and ugt.UserCameraID = uc.UserCameraID "+
"and uc.GroupID = gs.GroupID and gpd.GroupDomainID = gs.GroupDomainID and "+
"us.UserID ="+userid+")";
ResultSet res=con.executeSelectResult(sql);
res.last();
int rows = res.getRow();
res.beforeFirst();
try {
while(res.next()){
GroupDomainMessage message=new GroupDomainMessage();
message.setGroupDomainID(res.getInt(1));
message.setGroupDomainParent(res.getInt(2));
message.setGroupType(res.getInt(3));
message.setServerIP(res.getString(4));
message.setServerPort(res.getInt(5));
message.setForeignDomainID(res.getInt(6));
message.setUserName(res.getString(7));
message.setPassWord(res.getString(8));
message.setGroupDomainName(res.getString(9));
message.setListCount(rows);
list.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("GroupDomain===="+list.size());
return list;
}
/**
* 查询所有GroupDomain移动光标
* @return
*/
public Long getlistcount(int userid)
{
Connectionsql con=new Connectionsql();
con.openConnection();
String sql="select count(*) from GroupDomain gd where gd.GroupDomainParent=0 "+
"UNION select gpd.* from Groups gs,users us,UserGroupItem ugt,UserCamera uc, "+
"GroupDomain gpd where us.UserID = ugt.UserID and ugt.UserCameraID = uc.UserCameraID "+
"and uc.GroupID = gs.GroupID and gpd.GroupDomainID = gs.GroupDomainID and us.UserID ="+userid
+" UNION select gpd.* from GroupDomain gpd where gpd.GroupDomainID in ( "+
"select gpd.GroupDomainParent from Groups gs,users us,UserGroupItem ugt,UserCamera uc, "+
"GroupDomain gpd where "+
"us.UserID = ugt.UserID and ugt.UserCameraID = uc.UserCameraID "+
"and uc.GroupID = gs.GroupID and gpd.GroupDomainID = gs.GroupDomainID and "+
"us.UserID ="+userid+")";
ResultSet res=con.executeSelect(sql);
try {
while(res.next()){
return res.getLong(0);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0l;
}
/**
* 查询所有Groups
* @return
*/
public List<GroupsMessge> getGroupslist(int userid)
{
List<GroupsMessge> list=new ArrayList<GroupsMessge>();
Connectionsql con=new Connectionsql();
con.openConnection();
//and uc.GroupID = gs.GroupID
String sql= "select distinct gs.* from Groups gs,users us,UserGroupItem ugt,UserCamera uc "+
"where us.UserID = ugt.UserID and ugt.UserCameraID = uc.UserCameraID "+
" and "+
"us.UserID ="+userid;
ResultSet res=con.executeSelect(sql);
try {
while(res.next()){
GroupsMessge message=new GroupsMessge();
message.setGroupID(res.getInt("GroupID"));
message.setUserID(res.getInt("UserID"));
message.setName(res.getString("Name"));
message.setPrivater(res.getInt("private"));//res.getInt(4)
message.setType(res.getInt("Type"));
message.setDescription(res.getString("Description"));
message.setGroupDomainID(res.getInt("GroupDomainID"));//res.getInt(7)
list.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Groups===="+list.size());
return list;
}
public List<GroupsMessge> getGrouplist()
{
List<GroupsMessge> list=new ArrayList<GroupsMessge>();
Connectionsql con=new Connectionsql();
con.openConnection();
//and uc.GroupID = gs.GroupID
String sql= "select * from Groups";
ResultSet res=con.executeSelect(sql);
try {
while(res.next()){
GroupsMessge message=new GroupsMessge();
message.setGroupID(res.getInt("GroupID"));
message.setUserID(res.getInt("UserID"));
message.setName(res.getString("Name"));
message.setPrivater(res.getInt("private"));//res.getInt(4)
message.setType(res.getInt("Type"));
message.setDescription(res.getString("Description"));
message.setGroupDomainID(res.getInt("GroupDomainID"));//res.getInt(7)
list.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Groups===="+list.size());
return list;
}
/**
* 查询所有的底层数据
* @return
*/
public List<Map<String,Object>> getAllist()
{
List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
Connectionsql con=new Connectionsql();
con.openConnection();
String sql="select distinct u.UserCameraID,u.GroupID,u.CameraID,c.Name,s.InternalIP from UserCamera u ,Camera c ,Groups gs , Server s, "+
"users ust "+
"where u.CameraID = c.CameraID and u.GroupID = gs.GroupID "+
"and c.multicastip = s.serverid ";
ResultSet res=con.executeSelect(sql);
try {
while(res.next()){
Map<String,Object> message=new HashMap<String, Object>();
message.put("UserCameraID",res.getInt("UserCameraID")); //1
message.put("GroupID",res.getInt("GroupID"));//2
message.put("CameraID",res.getInt("CameraID"));//3
message.put("CameraName",res.getString("Name"));//Server.InternalIP 8
message.put("InternalIP",res.getString("InternalIP"));//26
list.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Camera===="+list.size());
return list;
}
public List<CameraMessage> getAlllist(int userid)
{
List<CameraMessage> list=new ArrayList<CameraMessage>();
Connectionsql con=new Connectionsql();
con.openConnection();
String sql="select distinct u.UserCameraID,u.GroupID,u.CameraID,c.Name,s.InternalIP from UserCamera u ,Camera c ,Groups gs , Server s, "+
"users us,UserGroupItem ugt "+
"where us.UserID = ugt.UserID and ugt.UserCameraID = u.UserCameraID "+
"and u.CameraID = c.CameraID and u.GroupID = gs.GroupID "+
"and c.multicastip = s.serverid "+
"and us.UserID ="+userid;
ResultSet res=con.executeSelect(sql);
try {
while(res.next()){
CameraMessage message=new CameraMessage();
message.setUserCameraID(res.getInt("UserCameraID")); //1
message.setGroupID(res.getInt("GroupID"));
message.setCameraID(res.getInt("CameraID"));//3
message.setName(res.getString("Name"));//Server.InternalIP 8
message.setInternalIP(res.getString("InternalIP"));
list.add(message);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Camera===="+list.size());
return list;
}
}