📄 util.java
字号:
HibernateSessionFactory.closeSession();
}
return wages;
}
//判断出货单是否已审核
public static boolean checkOutOrder(HttpServletRequest request,
String ordernumber) throws BwayHibernateException, BwayException {
boolean outs = false;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
Session sess;
try {
sql = "select * from bwayoutorder where ordernumber = '"
+ ordernumber + "' and auditstatus='2' ";
sess = HibernateSessionFactory.currentSession();
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
outs = true;
}
} catch (Exception e) {
e.printStackTrace();
throw new BwayException(e);
} finally {
HibernateSessionFactory.closeSession();
}
return outs;
}
//检查工资/奖惩/借款等是否已添加
public static boolean checkUserWage(String staffId, Session sess,
String tmpTableName) throws BwayHibernateException {
boolean isadd = false;
String sql = "";
ResultSet rs = null;
PreparedStatement stat = null;
try {
sql = "select * from " + tmpTableName + " where staffid ='"
+ staffId + "' ";
stat = sess.connection().prepareStatement(sql);
rs = stat.executeQuery();
if (rs.next()) {
isadd = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return isadd;
}
public static List getNotInDeptList(HttpServletRequest request,
String workname) throws BwayHibernateException {
List lst = new ArrayList();
String sql = "";
Session sess;
ResultSet rs = null;
Departments p = null;
try {
sql = "select * from departments where id not in "
+ " (select deptid from auditprocess where workname = '"
+ workname + "')";
sess = HibernateSessionFactory.currentSession();
rs = sess.connection().prepareStatement(sql).executeQuery();
while (rs.next()) {
p = p = new Departments();
p.setId(String.valueOf(rs.getInt("id")));
p.setDeptname(rs.getString("deptname"));
lst.add(p);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return lst;
}
//获得组的名字
public static String getDeptName(String deptid, Connection conn)
throws BwayHibernateException {
String deptname = "";
String sql = "";
ResultSet rs = null;
try {
sql = "select * from departments where id ='" + deptid + "' ";
rs = conn.prepareStatement(sql).executeQuery();
if (rs.next()) {
deptname = rs.getString("deptname");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != rs)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return deptname;
}
//获得EXCEL名字
public static String getExcelName(String id, Session sess)
throws BwayHibernateException {
String filename = "";
String sql = "";
ResultSet rs = null;
try {
sql = "select * from mgeattendance where id ='" + id + "' ";
rs = sess.connection().prepareStatement(sql).executeQuery();
if (rs.next()) {
filename = rs.getString("filename");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != rs)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return filename;
}
//获得EXCEL名字
public static String getExcelName(String id, Connection conn)
throws BwayHibernateException {
String filename = "";
String sql = "";
ResultSet rs = null;
try {
sql = "select * from mgeattendance where id ='" + id + "' ";
rs = conn.prepareStatement(sql).executeQuery();
if (rs.next()) {
filename = rs.getString("filename");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != rs)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return filename;
}
//求得用户的部门
public static List getUserInDeptList(HttpServletRequest request)
throws BwayHibernateException {
List lst = new ArrayList();
String sql = "";
Session sess;
ResultSet rs = null;
Staffinfo p = null;
try {
sql = "select DISTINCT deptid,deptname from staffinfo";
sess = HibernateSessionFactory.currentSession();
rs = sess.connection().prepareStatement(sql).executeQuery();
while (rs.next()) {
p = new Staffinfo();
p.setDeptid(String.valueOf(rs.getInt("deptid")));
p.setDeptname(rs.getString("deptname"));
lst.add(p);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return lst;
}
//求得用户的部门
public static List getNewUserInDeptList(HttpServletRequest request)
throws BwayHibernateException {
List lst = new ArrayList();
String sql = "";
Session sess;
ResultSet rs = null;
Staffinfo p = null;
try {
sql = "select DISTINCT id,deptname from dept ";
sess = HibernateSessionFactory.currentSession();
rs = sess.connection().prepareStatement(sql).executeQuery();
while (rs.next()) {
p = new Staffinfo();
p.setDeptid(String.valueOf(rs.getInt("id")));
p.setDeptname(rs.getString("deptname"));
lst.add(p);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return lst;
}
//求得用户的部门
public static List getDeptUserList(HttpServletRequest request,
String userdeptname) throws BwayHibernateException {
List lst = new ArrayList();
String sql = "";
Session sess;
ResultSet rs = null;
Staffinfo p = null;
try {
sql = "select staffname,staffcnname, deptid ,deptname from staffinfo where deptid='"
+ userdeptname + "' ";
sess = HibernateSessionFactory.currentSession();
rs = sess.connection().prepareStatement(sql).executeQuery();
while (rs.next()) {
p = new Staffinfo();
p.setDeptid(String.valueOf(rs.getInt("deptid")));
p.setDeptname(rs.getString("deptname"));
p.setStaffcnname(rs.getString("staffcnname"));
p.setStaffname(rs.getString("staffname"));
lst.add(p);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return lst;
}
//判断会员是否存在
public static Staffinfo getStaffinfo(Connection conn, String staffname)
throws BwayHibernateException {
Staffinfo staffIsExist = null;
ResultSet rs = null;
String sql = "";
try {
sql = "select * from staffinfo where staffname='" + staffname+ "' ";
rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
staffIsExist = new Staffinfo();
staffIsExist.setDeptid(rs.getString("deptid"));
staffIsExist.setId(String.valueOf(rs.getInt("id")));
staffIsExist.setStaffid(String.valueOf(rs.getInt("staffid")));
staffIsExist.setStaffname(rs.getString("staffname"));
staffIsExist.setSex(rs.getString("sex"));
staffIsExist.setStaffcnname(rs.getString("staffcnname"));
staffIsExist.setPhone(rs.getString("phone"));
staffIsExist.setEmail(rs.getString("email"));
staffIsExist.setMobile(rs.getString("mobile"));
}
} catch (Exception e) {
e.printStackTrace();
}
// finally {
// try {
// if (null != rs) {
// rs.close();
// }
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
return staffIsExist;
}
//判断会员是否存在
public static Staffinfo getStaffinfo(Session sess, String staffname)
throws BwayHibernateException {
Staffinfo staffIsExist = null;
ResultSet rs = null;
String sql = "";
try {
sql = "select * from staffinfo where staffname='" + staffname
+ "' ";
rs = sess.connection().createStatement().executeQuery(sql);
if (rs.next()) {
staffIsExist = new Staffinfo();
staffIsExist.setDeptid(rs.getString("deptid"));
staffIsExist.setId(String.valueOf(rs.getInt("id")));
staffIsExist.setStaffid(String.valueOf(rs.getInt("staffid")));
staffIsExist.setStaffname(rs.getString("staffname"));
staffIsExist.setSex(rs.getString("sex"));
staffIsExist.setStaffcnname(rs.getString("staffcnname"));
staffIsExist.setPhone(rs.getString("phone"));
staffIsExist.setEmail(rs.getString("email"));
staffIsExist.setMobile(rs.getString("mobile"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != rs) {
rs.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return staffIsExist;
}
//判断会员对象
public static boolean checkstaffIsExist(Session sess, String staffname)
throws BwayHibernateException {
boolean staffIsExist = false;
ResultSet rs = null;
String sql = "";
try {
sql = "select * from staffinfo where staffname='" + staffname
+ "' ";
rs = sess.connection().createStatement().executeQuery(sql);
if (rs.next()) {
staffIsExist = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return staffIsExist;
}
//判断会员对象
public static boolean checkstaffIsExist(Connection conn, String staffname)
throws BwayHibernateException {
boolean staffIsExist = false;
ResultSet rs = null;
String sql = "";
try {
sql = "select * from staffinfo where staffname='" + staffname
+ "' ";
rs = conn.createStatement().executeQuery(sql);
if (rs.next()) {
staffIsExist = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return staffIsExist;
}
//目前所在的级别
public static Departments getDepartmentsObject(Session sess, String workname)
throws BwayHibernateException {
Departments d = null;
ResultSet rs = null;
String sql = "";
try {
sql = "select a.deptid,a.deptname,a.workname,d.staffid,d.deptmanager"
+ " from auditprocess a,departments d "
+ " where d.id = a.deptid and a.workname='"
+ workname
+ "' order by d.deptlavel desc";
rs = sess.connection().createStatement().executeQuery(sql);
if (rs.next()) {
d = new Departments();
String auditDeptid = String.valueOf(rs.getInt("deptid"));
d.setId(auditDeptid);
d.setStaffid(String.valueOf(rs.getInt("staffid")));
d.setDeptmanager(rs.getString("deptmanager"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != rs) {
rs.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return d;
}
public static List getStaffDeptList(Session sess, String autoid)
throws BwayHibernateException {
List lst = new ArrayList();
ResultSet rs = null;
String sql = "";
String makename = "";
String staffname = "";
String staffnamecn = "";
String deptname = "";
try {
sql = " select s.staffid,s.staffname,s.staffcnname,d.deptname "
+ " from useowned us,staffinfo s,departments d "
+ "where us.staffid=s.staffname and us.owntype='filework' "
+ "and s.deptid=d.id and us.autodoid='" + autoid + "' ";
rs = sess.connection().createStatement().executeQuery(sql);
while (rs.next()) {
staffname = rs.getString("staffname");
staffnamecn = rs.getString("staffcnname");
deptname = rs.getString("deptname");
makename = deptname + ":" + staffnamecn + ":" + deptname + ","
+ staffname;
lst.add(makename);
}
} catch (Exception e) {
e.printStackTrace();
}
return lst;
}
//删除所有属于用户的
public static void deleteUseowned(Session sess, String autoid,
String owntype) throws BwayHibernateException {
ResultSet rs = null;
String sql = "";
try {
sql = "delete from useowned where autodoid ='" + autoid
+ "' and owntype='" + owntype + "' ";
sess.connection().createStatement().executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
}
}
//查看当天是否考勤
public static boolean currentDateAttendance(Session sess, String staffid)
throws BwayHibernateException {
boolean currentdate = false;
String sql = "";
ResultSet rs = null;
String currentdates = Util.fotmatDate4(new java.util.Date());
try {
sql = "select * from workattendance where staffid ='" + staffid
+ "' " + "and attendancedate= '" + currentdates + "' ";
rs = sess.connection().createStatement().executeQuery(sql);
if (rs.next()) {
currentdate = true;
}
} catch (Exception e) {
e.printStackTrace();
}
return currentdate;
}
//收到邮箱
public static List getEmailCount(HttpServletRequest req)
throws BwayHibernateException, BwayException {
List lst = null;
Session sess;
String sql = "";
try {
sess = HibernateSessionFactory.currentSession();
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return lst;
}
//部门内容
public static Dept getDetpObject(HttpServletRequest req, String id)
throws BwayHibernateException, BwayException {
Dept d = new Dept();
Session sess;
try {
sess = HibernateSessionFactory.currentSession();
d = (Dept) sess.get(Dept.class, id);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return d;
}
//个人文件夹
public static Folders getFoldersObject(HttpServletRequest req, String id)
throws BwayHibernateException, BwayException {
Folders d = new Folders();
Session sess;
try {
sess = HibernateSessionFactory.currentSession();
d = (Folders) sess.get(Folders.class, id);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return d;
}
//图书类别
public static Bookmanager getBookmanagerObject(HttpServletRequest req,
String id) throws BwayHibernateException, BwayException {
Bookmanager d = new Bookmanager();
Session sess;
try {
sess = HibernateSessionFactory.currentSession();
d = (Bookmanager) sess.get(Bookmanager.class, id);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return d;
}
//档案类别
public static Filemanager getFilemanagerObject(HttpServletRequest req,
String id) throws BwayHibernateException, BwayException {
Filemanager f = new Filemanager();
Session sess;
try {
sess = HibernateSessionFactory.currentSession();
f = (Filemanager) sess.get(Filemanager.class, id);
} catch (Exception e) {
e.printStackTrace();
} finally {
HibernateSessionFactory.closeSession();
}
return f;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -