📄 codedao.java
字号:
package cn.bway.common.code;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.bway.common.LoginConstants;
import cn.bway.common.dao.HibernateSessionFactory;
import cn.bway.foreigntrade.auditmanagement.auditorder.model.Auditorder;
import cn.bway.foreigntrade.information.model.Information;
public class codeDao {
// 根据table,得到将插入表id值;code 是指单号
public String[] getId(String table, String id, String code) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String[] sum = new String[2];
try {
List uid = (List) se.createSQLQuery("select max(" + id + ")+1 from " + table + "").list();
for (int i = 0; i < uid.size(); i++) {
BigInteger str = (BigInteger) uid.get(i);
sum[0] = code + String.valueOf(str);
sum[1] = String.valueOf(str);
System.out.println("=========================sum==========================="+ sum[0]);
}
} catch (Exception e) {
e.printStackTrace();
}
tr.commit();
// se.close();
return sum;
}
public String getMaxId(String table, String id, String code) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sum="";
try {
List uid = (List) se.createSQLQuery("select max(" + id + ")+1 from " + table + "").list();
for (int i = 0; i < uid.size(); i++) {
Integer str = (Integer) uid.get(i);
sum= String.valueOf(str);
// sum[1] = String.valueOf(str);
System.out.println("=========================sum==========================="+ sum);
}
} catch (Exception e) {
e.printStackTrace();
}
tr.commit();
return sum;
}
// 将表单号,插入table中()
public void insertCode(String table, String menu, String id, String code) {
String[] co = new codeDao().getId(table, id, code);
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
Code c = new Code(menu, code, co[1], co[0]);
se.save(c);
tr.commit();
// se.close();
}
// 根据table,得到相应字段值
public List getColume(String table, String getCol) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
List list = se.createSQLQuery("select " + getCol + " from " + table + "").list();
tr.commit();
return list;
}
public String getColume(String table, String getCol, String str1,
String str2) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String name = se.createSQLQuery("select " + getCol + " from " + table + " where " + str1 + "="+ str2 + "").toString();
tr.commit();
return name;
}
public String getColumes(String table, String getCol, String str1,
String str2) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sql=("select " + getCol + " from " + table + " where " + str1 + "='"+ str2 + "'");
Query query=se.createQuery(sql);
Iterator name=query.iterate();
String oo = null;
while(name.hasNext()){
oo=(String) name.next();
}
tr.commit();
return oo;
}
public List getColumeList(String table, String getCol, String str1,String str2) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
List name = se.createSQLQuery("select " + getCol + " from " + table + " where " + str1 + "='"+ str2 + "'").list();
tr.commit();
return name;
}
public List getColumeList(String table, String getCol, String str1,int str2) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
List name = se.createSQLQuery("select " + getCol + " from " + table + " where " + str1 + "="+ str2 + "").list();
tr.commit();
return name;
}
// 根据tabel,得到该表所有字段
public List getAll(String table) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
List list = se.createSQLQuery("select * from " + table + "").list();
tr.commit();
// se.close();
return list;
}
// 根据tabel,得到该表两个字段
public String[] getTwo(String table,String col1,String col2) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String[] sum = new String[2];
List list = se.createSQLQuery("select "+col1+","+col2+" from " + table + "").list();
for (int i = 0; i < list.size(); i++) {
String[] str = (String[]) list.get(i);
for(int s=0;s<str.length;s++){
sum[0]=str[0];
sum[1]=str[1];
System.out.println(sum[0]+"================="+sum[1]);
}
System.out.println(str[i]+"----------------------------");
}
tr.commit();
// se.close();
return sum;
}
public String getDate() {
String sum = "";
Date date = new Date();
sum += "" + (1900 + Integer.parseInt(sum += date.getYear()));
sum += "-" + (1 + Integer.parseInt("" + date.getMonth()));
sum += "-" + date.getDate();
return sum;
}
public String getAuditname(String orderid) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sql="select s.staffname from Auditstaff as s,Audittable as t where s.auditorderid=t.audittype and s.orderid=t.auditstaffid and t.auditstaffid="+orderid;
Query query=se.createQuery(sql);
String user="";
List list=query.list();
Iterator it=list.iterator();
while(it.hasNext()){
user=(String) it.next();
}
// tr.commit();
return user;
}
public void removeAudit(String type,String orderid) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sql="delete from Audittable where audittype='"+type+"' and orderid="+orderid+"";
Query query=se.createQuery(sql);
query.executeUpdate();
tr.commit();
}
public void updateState(String id,String table,String auditing) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sql="update "+table+" set checks="+auditing+" where id="+id;
Query query=se.createQuery(sql);
query.executeUpdate();
// tr.commit();
}
public void updateAuditState(String id,String table,String auditing) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
String sql="update "+table+" set checks="+auditing+" where id="+id;
Query query=se.createQuery(sql);
query.executeUpdate();
// tr.commit();
}
public void insertInfor(String inforid, String infortype, String inforcontent, String inforurl, String infortime, String informan, String inforget,String tablename,String isaudit ) {
Session se = HibernateSessionFactory.currentSession();
Transaction tr = se.beginTransaction();
Information info=new Information(inforid,infortype,inforcontent,inforurl,infortime,informan,inforget,tablename,isaudit);
se.save(info);
// tr.commit();
// se.close();
}
public static void main(String[] args) throws SQLException {
String typess=new codeDao().getColumes("Storymanagement","types","names","材料仓库");
System.out.println(typess+"=====================");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -