package com.fgkj.dao.impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.fgkj.dao.BaseDAO; import com.fgkj.dao.CallBack; import com.fgkj.dao.DAOHelper; import com.fgkj.dao.UinfDaoFactory; import com.fgkj.db.DBUtil; import com.fgkj.db.IDatabaseName; import com.fgkj.dto.BattInf; import com.fgkj.dto.User_battgroup_baojigroup; import com.fgkj.dto.User_battgroup_baojigroup_battgroup; import com.fgkj.dto.User_inf; import com.fgkj.dto.User_log; import com.fgkj.services.User_logService; public class User_battgroup_baojigroup_battgroupImpl implements BaseDAO,CallBack{ public List getResults(ResultSet rs) { List list = new ArrayList(); try { while (rs.next()) { User_battgroup_baojigroup_battgroup userbattgroup = new User_battgroup_baojigroup_battgroup(); userbattgroup.setNum(Integer.parseInt(rs.getString("num"))); userbattgroup.setBaoji_group_id(Integer.parseInt(rs.getString("baoji_group_id"))); userbattgroup.setStationId(Integer.parseInt(rs.getString("StationId"))); userbattgroup.setBattGroupId(Integer.parseInt(rs.getString("BattGroupId"))); list.add(userbattgroup); } } catch (SQLException e) { e.printStackTrace(); } return list; } //5.3添加选取电池组或者机房或者维护区 public boolean add(Object obj) { User_battgroup_baojigroup_battgroup ugroup=(User_battgroup_baojigroup_battgroup) obj; String sql="insert into db_user.tb_user_battgroup_baojigroup_battgroup(baoji_group_id,StationId,BattGroupId) values(?,?,?)"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ugroup.getBaoji_group_id(),ugroup.getStationId(), ugroup.getBattGroupId()}); return bl; } //5.3添加选取电池组或者机房或者维护区(多笔数据) public boolean addPro(Object obj) { List list=(List) obj; ArrayList sql_strs=new ArrayList(); List listU=new ArrayList();//存放user_log if(list!=null&&list.size()>0){ for (User_battgroup_baojigroup_battgroup ugroup : list) { String sql="insert into db_user.tb_user_battgroup_baojigroup_battgroup(baoji_group_id,StationId,BattGroupId) values("+ugroup.getBaoji_group_id()+","+ugroup.getStationId()+","+ugroup.getBattGroupId()+")"; sql_strs.add(sql); { String msg="添加"+ugroup.getNote()+"至"+ugroup.getBaoji_group_name()+"包机组中"; User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Increase, msg); listU.add(ulog); } } } boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_strs); (new User_logService()).addPro(listU);//将用户的操作记录下来 return bl; } public boolean update(Object obj) { User_battgroup_baojigroup_battgroup ugroup=(User_battgroup_baojigroup_battgroup) obj; String sql="update db_user.tb_user_battgroup_baojigroup_battgroup set baoji_group_id=?,StationId=?,BattGroupId=? where num=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ugroup.getBaoji_group_id(),ugroup.getStationId(), ugroup.getBattGroupId(),ugroup.getNum()}); return bl; } //5.3删除选取的电池组 public boolean del(Object obj) { User_battgroup_baojigroup_battgroup ugroup=(User_battgroup_baojigroup_battgroup) obj; String sql="delete from db_user.tb_user_battgroup_baojigroup_battgroup where baoji_group_id=? and battgroupid=? and stationid=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ugroup.getBaoji_group_id(),ugroup.getBattGroupId(),ugroup.getStationId()}); return bl; } //5.3删除选取的电池组(多笔数据) public boolean delPro(Object obj) { List list=(List) obj; ArrayList sql_strs=new ArrayList(); List listU=new ArrayList();//存放user_log if(list!=null&&list.size()>0){ for (User_battgroup_baojigroup_battgroup ugroup : list) { String sql="delete from db_user.tb_user_battgroup_baojigroup_battgroup where baoji_group_id="+ugroup.getBaoji_group_id()+" and battgroupid="+ugroup.getBattGroupId()+" and stationid="+ugroup.getStationId(); sql_strs.add(sql); { String msg="删除"+ugroup.getBaoji_group_name()+"包机组中"+ugroup.getNote()+"电池组"; User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Delete, msg); listU.add(ulog); } } } boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_strs); (new User_logService()).addPro(listU);//将用户的操作记录下来 return bl; } //5.3删除(删除指定包机组下所有用户) public String delAll(Object obj) { User_battgroup_baojigroup ubao=(User_battgroup_baojigroup) obj; String sql = "delete from db_user.tb_user_battgroup_baojigroup_battgroup where baoji_group_id="+ubao.getBaoji_group_id(); return sql; } public List searchAll() { String sql = "select * from db_user.tb_user_battgroup_baojigroup_battgroup"; List list = DAOHelper .executeQuery(sql, DBUtil.getConn(), null, new User_battgroup_baojigroup_battgroupImpl()); return list; } //5.1根据uid查机房和电池组 public List serchByCondition(Object obj) { User_inf uinf=(User_inf) obj; String sql="select distinct(db_battinf.tb_battinf.stationname),db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.stationid,db_battinf.tb_battinf.battgroupid,db_battinf.tb_battinf.battgroupname " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? ORDER BY db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.BattGroupId"; //System.out.println(sql); List list = DAOHelper .executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId()}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ BattInf binf=new BattInf(); binf.setStationName1(rs.getString("stationName1")); binf.setStationName(rs.getString("stationName")); binf.setStationId(rs.getString("stationid")); binf.setBattGroupName(rs.getString("battGroupName")); binf.setBattGroupId(rs.getInt("battgroupid")); list.add(binf); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } }); return list; } //放电测试(查询用户管理的维护区) public List serchStationName1InGroup(Object obj){ User_inf uinf=(User_inf) obj; String sql="select distinct db_battinf.tb_battinf.stationname1 " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? ORDER BY db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.BattGroupId"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId()}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ list.add(rs.getString("stationName1")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } }); return list; } //放电测试(查询用户管理的维护区对应的机房) public List serchStationNameInGroup(Object obj){ User_inf uinf=(User_inf) obj; String sql="select distinct db_battinf.tb_battinf.stationname " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? and db_battinf.tb_battinf.stationname1 like ? ORDER BY db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.BattGroupId"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId(),"%"+uinf.getUNote()+"%"}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ list.add(rs.getString("stationname")); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } }); return list; } //首页(查询用户管理的维护区对应的机房和机房ID以及设备id) public List serchStationByStationName1(Object obj){ User_inf uinf=(User_inf) obj; String sql="select distinct db_battinf.tb_battinf.stationname,db_battinf.tb_battinf.stationid,db_battinf.tb_battinf.fBSDeviceId " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.stationid=db_battinf.tb_battinf.stationid " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? and db_battinf.tb_battinf.stationname1 like ? ORDER BY db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.BattGroupId"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId(),"%"+uinf.getUNote()+"%"}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ BattInf binf=new BattInf(); binf.setStationName(rs.getString("stationName")); binf.setStationId(rs.getString("stationId")); binf.setFBSDeviceId(rs.getInt("fBSDeviceId")); list.add(binf); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } }); return list; } //放电测试(查询用户管理的维护区对应的机房对应的battgroupid) public List serchBattgroupidInGroup(Object obj){ User_inf uinf=(User_inf) obj; String sql="select distinct db_battinf.tb_battinf.battgroupid,db_battinf.tb_battinf.stationName,db_battinf.tb_battinf.battgroupname,db_battinf.tb_battinf.moncount,db_battinf.tb_battinf.GroupIndexInFBSDevice,db_battinf.tb_battinf.FBSDeviceId " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.BattGroupId=db_battinf.tb_battinf.BattGroupId " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? and db_battinf.tb_battinf.stationname1 like ? and db_battinf.tb_battinf.stationname like ? ORDER BY db_battinf.tb_battinf.stationname1,db_battinf.tb_battinf.BattGroupId"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId(),"%"+uinf.getUNote()+"%","%"+uinf.getUName()+"%"}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ BattInf binf=new BattInf(); binf.setBattGroupId(rs.getInt("battGroupId")); binf.setStationName(rs.getString("stationName")); binf.setBattGroupName(rs.getString("battGroupName")); binf.setMonCount(rs.getInt("monCount")); binf.setGroupIndexInFBSDevice(rs.getInt("GroupIndexInFBSDevice")); binf.setFBSDeviceId(rs.getInt("fBSDeviceId")); list.add(binf); } } catch (SQLException e) { e.printStackTrace(); } return list; } }); return list; } //6185下拉(查询用户管理的维护区对应的机房对应的battgroupid) public List serch61850DevidInGroup(Object obj){ User_inf uinf=(User_inf) obj; String sql="select distinct db_battinf.tb_battinf.battgroupid,db_battinf.tb_battinf.stationName,db_battinf.tb_battinf.battgroupname,db_battinf.tb_battinf.moncount,db_battinf.tb_battinf.GroupIndexInFBSDevice,db_battinf.tb_battinf.FBSDeviceId " + "from db_battinf.tb_battinf " + "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.BattGroupId=db_battinf.tb_battinf.BattGroupId " + "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id=db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id " + "left outer join db_user.tb_user_inf on tb_user_inf.uid=db_user.tb_user_battgroup_baojigroup_usr.uid " + "where db_user.tb_user_inf.uid=? and db_battinf.tb_battinf.FBSDeviceId like '%6185%'"; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{uinf.getUId()}, new CallBack() { public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ BattInf binf=new BattInf(); binf.setBattGroupId(rs.getInt("battGroupId")); binf.setStationName(rs.getString("stationName")); binf.setBattGroupName(rs.getString("battGroupName")); binf.setMonCount(rs.getInt("monCount")); binf.setGroupIndexInFBSDevice(rs.getInt("GroupIndexInFBSDevice")); binf.setFBSDeviceId(rs.getInt("fBSDeviceId")); list.add(binf); } } catch (SQLException e) { e.printStackTrace(); } return list; } }); return list; } public List serchByInfo(Object obj) { // TODO Auto-generated method stub return null; } public static void main(String[] args) { User_battgroup_baojigroup_battgroupImpl ub= new User_battgroup_baojigroup_battgroupImpl(); /*List list =ub.searchAll(); for (User_battgroup_baojigroup_battgroup u : list) { System.out.println(u); }*/ User_battgroup_baojigroup_battgroup u=new User_battgroup_baojigroup_battgroup(); u.setNum(4); User_inf uinf=new User_inf(); uinf.setUId(1001); List list =ub.serchByCondition(uinf); for (BattInf uu : list) { System.out.println(uu); } System.out.println(list.size()); } }