TAffair.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:37k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.affair.affairdao;
- import java.io.File;
- import java.io.FileInputStream;
- import java.lang.reflect.InvocationTargetException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.beanutils.BeanUtils;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import org.jdom.Document;
- import org.jdom.Element;
- import org.jdom.input.SAXBuilder;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import com.oa.module.affair.affair.Transstep;
- import com.oa.module.affair.affairreq.AffairReqForm;
- import com.oa.module.affair.affairreq.Transreq;
- import com.oa.module.affair.affairtype.AffairTypeForm;
- import com.oa.module.affair.affairtype.Transtype;
- import com.oa.util.ToolUtil;
- import com.oa.util.XPage;
- /**
- * 事务定制DAO接口实现
- * @author admin
- *
- */
- public class TAffair implements IAffair {
- private SessionFactory sf;
- Session session = null;
- Transaction tx = null;
- // private HibernateTemplate ht = null;
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- public boolean checkName(AffairTypeForm affairForm) {
- session = sf.openSession();
- Query query = session.createQuery("select a from Transtype a where a.tname=:tname");
- query.setParameter("tname",affairForm.getTname());
- int count = query.list().size();
- if(count>0)return true;
- else return false;
- }
- public boolean addAffairType(Transtype type, HttpServletRequest request) {
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- session.save(type);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- public boolean isused(String transID){
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- session = sf.openSession();
- sql = "select * from transreq t where t.tno =" + transID;
- session = sf.openSession();
- conn =session.connection();
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- if(rs.next()){
- return true;
- }
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return false;
- }
- public HashMap getrole(String transID) {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- String roleid = "";
- String rolename = "";
- HashMap role = new HashMap();
- session = sf.openSession();
- conn =session.connection();
- try {
- stmt = conn.createStatement();
- sql = "select t.trid from transtype t where t.rtid =" + transID;
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- if (roleid.equals("")) {
- roleid = rs.getString("trid");
- } else {
- roleid = roleid + "," + rs.getString("trid");
- }
- }
- role.put("roleid", roleid);
- sql = "select t.rid ,t.rname from trole t where t.rid in (" + roleid + ") order by t.rid";
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- if (rolename.equals("")) {
- rolename = rs.getString("rname");
- } else {
- rolename = rolename + "," + rs.getString("rname");
- }
- }
- role.put("rolename", rolename);
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return role;
- }
- public Map getaffair(String transID) {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- HashMap affair = new HashMap();
- session = sf.openSession();
- sql = "select * from transtype t where t.rtid =" + transID;
- conn =session.connection();
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- if (rs.next()) {
- affair.put("rtid", rs.getString("rtid"));
- affair.put("tname", rs.getString("tname"));
- affair.put("txmlpath", rs.getString("txmlpath"));
- affair.put("tstep", rs.getString("tstep"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return affair;
- }
- public List getSteps(String dir, int count) {
- Map map = null;
- List translist = null;
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- session = sf.openSession();
- conn =session.connection();
- try{
- stmt = conn.createStatement();
- translist = new ArrayList();
- String userids = "";
- String roleids = "";
- SAXBuilder sb = new SAXBuilder();
- Document dos = sb.build(new FileInputStream(dir));
- Element root = dos.getRootElement();
- List list = root.getChildren();
- for (int i = 0; i < count; i++) {
- userids = "";//拥有的用户
- roleids = "";//拥有的角色
- Element allnode = (Element) list.get(i);
- List nodeList = allnode.getChildren();
- for (int j = 0; j < nodeList.size(); j++) {
- Element node = (Element) nodeList.get(j);
- if (node.getName().equals("userid")) {
- if (j == 0 || userids.trim().equals("")) {
- userids = userids + node.getText();
- }
- } else if (node.getName().equals("roleid")) {
- if (j == 0 || roleids.trim().equals("")) {
- roleids = roleids + node.getText();
- }
- }
- }
- map = new HashMap();
- if (userids != null && !userids.trim().equals("")) {
- // 获得用户名称
- String usernames = "";
- String[] users = userids.split(",");
- for (int j=0 ;j<users.length;j++){
- sql = "select UNO,UTRUENAME from tuser where UNO="+ users[j];
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- if (usernames.equals("")) {
- usernames = rs.getString("utruename");
- } else {
- usernames = usernames + ","+ rs.getString("utruename");
- }
- }
- }
- map.put("username", usernames);
- // map.put("userids", "userid" + i);
- map.put("userid", userids);
- }
- if (roleids != null && !roleids.trim().equals("")) {
- // 获得角色名
- String rolenames = "";
- String[] roles = roleids.split(",");
- for(int k=0;k<roles.length;k++){
- sql = "select t.rid,t.rname from trole t where t.rid =" + roles[k];
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- if (rolenames.equals("")) {
- rolenames = rs.getString("rname");
- } else {
- rolenames = rolenames + "," + rs.getString("rname");
- }
- }
- }
- map.put("rolename", rolenames);
- // map.put("roleids", "roleids" + i);
- map.put("roleid", roleids);
- }
- translist.add(map);
- }
- }catch(Exception e){
- // e.printStackTrace();
- return null;
- }
- finally{
- }
- return translist;
- }
- public XPage gettypelist(int currentPage, int count, Transtype typebean) {
- String hql="select a from Transtype a where 1=1";
- String path="/oa/affairType.do?task=getlist&";
- XPage page = new XPage();
- //开始设置xpage
- page.setCurrentPage(currentPage);
- page.setCount(count);
- //动态的构建hql语句和xpage的path
- if(typebean!=null){
- if(typebean.getTname()!=null&&!typebean.getTname().trim().equals("")){
- hql+=" and a.tname like :name";
- path+="tname="+typebean.getTname()+"&";
- }
- }
- //设置分页路径
- page.setPath(path);
- Session session = null;
- Query query =null;
- List list = null;
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- //设置查询参数
- if(typebean!=null){
- if(typebean.getTname()!=null&&!typebean.getTname().trim().equals("")){
- query.setParameter("name","%"+typebean.getTname()+"%");
- }
- }
- //获取总记录数
- int allcount = query.list().size();
- page.setAllCount(allcount);
- //得到分页显示数据
- query.setFirstResult((currentPage-1)*count);
- query.setMaxResults(count);
- list = query.list();
- page.setList(list);
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return page;
- }
- public boolean updateType(String transID ,HttpServletRequest request ) {
- Transtype type = new Transtype();
- int id = Integer.parseInt(transID);
- try {
- session = sf.openSession();
- type = (Transtype)session.get(Transtype.class,new Long(id));
- type.setTname(request.getParameter("tname"));
- tx = session.beginTransaction();
- session.update(type);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- public boolean deltyperole(String transID) {
- String sqls[] =new String[transID.length()];
- for(int i=0;i<sqls.length;i++){
- sqls[i] = "delete from ttyperole where rtid = "+transID;
- }
- boolean flag = this.executeUpdates(sqls);
- if(flag){
- return true;
- }
- return false;
- }
- public boolean delaffair(String rtid, String dir) {
- boolean flag = false;
- Session session = null;
- Transaction tx = null;
- // 先删除XML文件
- if (this.delXml(rtid, dir)) {
- try {
- int id = Integer.parseInt(rtid);
- session = this.sf.openSession();
- tx = session.beginTransaction();
- Transtype transtype = (Transtype)session.get(Transtype.class, new Long(id));
- session.delete(transtype);
- tx.commit();
- session.flush();
- flag = true;
- } catch (Exception e) {
- tx.rollback();
- e.printStackTrace();
- } finally {
- session.close();
- this.sf.close();
- }
- }else{
- try {
- int id = Integer.parseInt(rtid);
- session = this.sf.openSession();
- tx = session.beginTransaction();
- Transtype transtype = (Transtype)session.get(Transtype.class, new Long(id));
- session.delete(transtype);
- tx.commit();
- session.flush();
- flag = true;
- } catch (Exception e) {
- tx.rollback();
- e.printStackTrace();
- } finally {
- session.close();
- this.sf.close();
- }
- }
- return flag;
- }
- private boolean delXml(String rtid, String dir) {
- Session session = null;
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- boolean flag = false;
- sql = "select * from transtype where rtid =" + rtid;
- session = this.sf.openSession();
- conn = session.connection();
- try {
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- if (rs.next()) {
- File file = new File(dir + "/" + rs.getString("txmlpath"));
- file.delete();
- flag = true;
- }
- } catch (SQLException e) {
- flag = false;
- e.printStackTrace();
- } finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return flag;
- }
- public List init(String uno) {
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- session = this.sf.openSession();
- conn = session.connection();
- List list = new ArrayList();
- try {
- sql = "select a.* from transtype a ,tuserrole b ,ttyperole c where b.uno = " + uno
- + " and b.rid = c.rid and c.rtid = a.rtid";
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- Map map = new HashMap();
- map.put("rtid", rs.getString("rtid"));
- map.put("tname", rs.getString("tname"));
- map.put("txmlpath", rs.getString("txmlpath"));
- map.put("tstep", rs.getString("tstep"));
- list.add(map);
- }
- } catch (Exception e) {
- e.printStackTrace();
- list = null;
- } finally {
- try {
- rs.close();
- stmt.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return list;
- }
- public void addtyperole(long rtid, String[] rid) {
- String[] sqls = new String[rid.length];
- for(int i=0 ;i<rid.length;i++){
- sqls[i] = "insert into TTYPEROLE (TR_ID, RTID, RID)";
- sqls[i] =sqls[i] +" values(seq_t_typerole.nextval,'"+String.valueOf(rtid)+"','"+rid[i]+"')";
- }
- boolean flag = this.executeUpdates(sqls);
- if(flag){
- }
- }
- public boolean executeUpdates(String[] sqls){
- Connection conn = null;
- Statement st = null;
- session = sf.openSession();
- conn =session.connection();
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- for(int i=0;i<sqls.length;i++){
- st.addBatch(sqls[i]);
- }
- int[] re=st.executeBatch();
- conn.commit();//提交事务
- if(re.length>0){
- return true;
- }
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return false;
- }
- public List getroles(String roleid) {
- List list = new ArrayList();
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- String sql =null;
- int count1 = 0 ;
- int count2 = 0 ;
- String[] roleids = roleid.split(",");
- session = sf.openSession();
- conn= session.connection();
- try {
- st = conn.createStatement();
- for (int i = 0; i < roleids.length; i++) {
- sql = "select uno from tuserrole t where t.rid =" + roleids[i];
- rs = st.executeQuery(sql);
- String userids = "";
- String username = "";
- Map userMap = new HashMap();
- while (rs.next()) {
- if (userids.equals("")) {
- userids = rs.getString("uno");
- } else {
- userids = userids + "," + rs.getString("uno");
- }
- count1 += 1;
- }
- if (!userids.equals("")) {
- String[] users = userids.split(",");
- count2 = users.length-1;
- for (int j = 0; j < users.length; j++) {
- sql = "select t.uno,t.utruename from tuser t where t.uno = "+ users[j] + " and t.uislocked=0";
- rs = st.executeQuery(sql);
- while (rs.next()) {
- if (username.equals("")) {
- username = rs.getString("utruename");
- } else {
- username = username + ","+ rs.getString("utruename");
- }
- }
- }
- if(count1>count2){
- userids ="";
- for(int m = 0;m<count2;m++){
- if (userids.equals("")) {
- userids = users[m];
- } else {
- userids = userids + "," +users[m];
- }
- }
- userMap.put("userid", userids);
- userMap.put("username", username);
- }else{
- userMap.put("userid", userids);
- userMap.put("username", username);
- }
- }
- list.add(userMap);
- }
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- // TODO: handle exception
- }finally{
- try {
- rs.close();
- st.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return list;
- }
- public boolean AffairReq(AffairReqForm affairReqForm,HttpServletRequest request) {
- Connection conn = null;
- Statement st = null;
- Statement st2 = null;
- boolean flag = true;
- Transreq affaireq = new Transreq();
- Transstep affairstep = new Transstep();
- try {
- BeanUtils.copyProperties(affaireq, affairReqForm);
- } catch (IllegalAccessException e2) {
- // TODO 自动生成 catch 块
- e2.printStackTrace();
- } catch (InvocationTargetException e2) {
- // TODO 自动生成 catch 块
- e2.printStackTrace();
- }
- String ReqSql = null;
- String StepSql = null;
- long ReqID = getReqID();
- ReqSql = "insert into TRANSREQ (RQID, RTITLE, UNO, TNO, RGRADE, RSTARTTIME, RENDTIME, RNEXTTIME, RLASTTIME, RDETAIL, RSTATUS, RMEMO)";
- ReqSql = ReqSql + "values ("+ReqID+","+"'"+affaireq.getRtitle()+"','";
- ReqSql = ReqSql +affaireq.getUno()+"','";
- ReqSql = ReqSql +affaireq.getTno()+"','";
- ReqSql = ReqSql +affaireq.getRgrade()+"','";
- ReqSql = ReqSql +affaireq.getRstarttime()+"','";
- ReqSql = ReqSql +affaireq.getRendtime()+"','";
- ReqSql = ReqSql +affaireq.getRnexttime()+"','";
- ReqSql = ReqSql +affaireq.getRlasttime()+"','";
- ReqSql = ReqSql +affaireq.getRdetail()+"','";
- ReqSql = ReqSql +affaireq.getRstatus()+"','";
- ReqSql = ReqSql +affaireq.getRmemo()+"')";
- affairstep.setRqid(ReqID);
- affairstep.setScurrentid(1);
- affairstep.setUno(request.getParameter("userid"));
- affairstep.setSstatus("0");//当前状态
- affairstep.setSresult("0");
- affairstep.setSprestep(0);
- StepSql ="insert into TRANSSTEP (SID, RQID, SCURRENTID, UNO, SSTATUS, SPRESTEP, SNEXTUNO, SCURRENTTIME, SNEXTTIME, SRESULT, SDETAIL, SNAME, SPATH)";
- StepSql = StepSql+ "values ( SEQ_T_RANSSTEP.nextval,";
- StepSql = StepSql +ReqID+",";
- StepSql = StepSql +affairstep.getScurrentid()+",'";
- StepSql = StepSql +affairstep.getUno()+"','";
- StepSql = StepSql +affairstep.getSstatus()+"',";
- StepSql = StepSql +affairstep.getSprestep()+",'";
- StepSql = StepSql +affairstep.getSnextuno()+"','";
- StepSql = StepSql +affairstep.getScurrenttime()+"','";
- StepSql = StepSql +affairstep.getSnexttime()+"','";
- StepSql = StepSql +affairstep.getSresult()+"','";
- StepSql = StepSql +affairstep.getSdetail()+"','";
- StepSql = StepSql +affairstep.getSname()+"','";
- StepSql = StepSql +affairstep.getSpath()+"')";
- session = sf.openSession();
- conn =session.connection();
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st2 = conn.createStatement();
- st.execute(ReqSql);
- st2.execute(StepSql);
- conn.commit();//提交事务
- } catch (SQLException e) {
- try {
- flag = false;
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- st2.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return flag;
- }
- public boolean addaffairstep(Transstep ransstep) {
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- session.save(ransstep);
- tx.commit();
- session.flush();
- return true;
- }catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- private long getReqID(){
- long ReqID = 0;
- PreparedStatement ps = null;
- ResultSet rs = null;
- Connection conn = null;
- session = sf.openSession();
- conn =session.connection();
- String Sql = null;
- try {
- Sql = "select SEQ_T_RANSREQ.NEXTVAL as ReqID FROM dual";
- ps = conn.prepareStatement(Sql);
- rs = ps.executeQuery();
- while (rs.next()) {
- ReqID = rs.getInt("ReqID");
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.close();
- sf.close();
- }
- return ReqID;
- }
- public List reqList(int currentPage, int count, Transreq reqbean,HttpServletRequest request) {
- StringBuffer sql = new StringBuffer();
- StringBuffer centent = new StringBuffer();
- String rgrade = request.getParameter("rgrade");
- if(reqbean.getReqUsername()!=null&&!reqbean.getReqUsername().trim().equals("")){
- centent.append(" and usr.utruename like '%").append(reqbean.getReqUsername().trim()).append("%'");
- }
- if(rgrade !=null && !rgrade.trim().equals("")){
- centent.append(" and req.rgrade =").append(rgrade.trim()).append("");
- }
- if(reqbean.getRstarttime()!=null &&!reqbean.getRstarttime().trim().equals("")){
- centent.append(" and req.rlasttime between'").append(reqbean.getRstarttime().trim()).append("'");
- centent.append(" and '").append(reqbean.getRendtime().trim()).append("'");
- }
- sql.append("SELECT * FROM(")
- .append("select typ.tname,req.*,usr.utruename,ROWNUM AS num from transreq req ")
- .append("inner join tuser usr on req.uno = usr.uno ")
- .append("inner join transtype typ on typ.rtid = req.tno where 1 = 1 and req.rstatus = '0' ")
- .append(centent)
- .append(")t WHERE ");
- sql.append(" t.num<=").append(currentPage*count);
- sql.append(" AND t.num>").append((currentPage-1)*count);
- sql.append(" order by t.rqid");
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- session = sf.openSession();
- conn = session.connection();
- List list = null;
- Transreq reqbeans = null;
- try {
- int i = 0 ;
- st = conn.createStatement();
- rs = st.executeQuery(sql.toString());
- list = new ArrayList();
- while (rs.next()) {
- i = i +1;
- reqbeans = new Transreq();
- reqbeans.setRqid(rs.getInt("RQID"));
- reqbeans.setRtitle(rs.getString("RTITLE"));
- reqbeans.setTname(rs.getString("TNAME"));
- reqbeans.setReqUsername(rs.getString("utruename"));
- reqbeans.setRgrade(rs.getString("rgrade"));
- reqbeans.setRlasttime(rs.getString("RLASTTIME"));
- list.add(reqbeans);
- }
- if (i == 0 ){
- list = null;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- session.close();
- sf.close();
- }
- return list;
- }
- public List getaudit(HttpServletRequest request) {
- List list = new ArrayList();
- Connection conn = null;
- Statement stmt = null;
- ResultSet rs = null;
- String sql = null;
- session = sf.openSession();
- conn = session.connection();
- Map affair = null;
- Map req = null;
- try {
- stmt = conn.createStatement();
- sql = "select a.rgrade ,a.tno ,a.rdetail ,a.rtitle ,b.tname,b.tstep ,c.sprestep ,a.rlasttime,c.sid";
- sql = sql +" from transreq a inner join transtype b on a.tno = b.rtid";
- sql = sql +" inner join transstep c on a.rqid = c.rqid where c.sstatus = '0' and a.rqid = ";
- String rqid = "0";
- if (request.getParameter("rqids")!=null && !request.getParameter("rqids").equals("")){
- rqid = request.getParameter("rqids");
- }
- sql = sql +rqid ;
- rs = stmt.executeQuery(sql);
- if (rs.next()) {
- affair = new HashMap();
- affair.put("sid",rs.getString("sid"));
- affair.put("rdetail", rs.getString("rdetail"));
- affair.put("rtitle", rs.getString("rtitle"));
- affair.put("tstep", rs.getString("tstep"));
- affair.put("rgrade", rs.getString("rgrade"));
- affair.put("tno", rs.getString("tno"));
- affair.put("rqid", rqid);
- affair.put("tname", rs.getString("tname"));
- affair.put("rlasttime", rs.getString("rlasttime"));
- affair.put("sprestep", rs.getString("sprestep"));
- }
- sql = "select a.rqid,a.rtitle,a.rgrade,a.rnexttime,a.rdetail,b.utruename ,a.rmemo";
- sql = sql +" from transreq a inner join tuser b on a.uno = b.uno where a.rqid = ";
- sql = sql +rqid ;
- rs = stmt.executeQuery(sql);
- if (rs.next()) {
- req = new HashMap();
- req.put("rqid",rs.getString("rqid"));
- req.put("rtitle",rs.getString("rtitle"));
- req.put("rgrade",rs.getString("rgrade"));
- req.put("rnexttime",rs.getString("rnexttime"));
- req.put("rdetail",rs.getString("rdetail"));
- req.put("utruename",rs.getString("utruename"));
- req.put("rmemo",rs.getString("rmemo"));
- }
- sql = "select c.rqid,c.scurrentid,e.utruename,c.scurrenttime,c.snexttime,c.sname,c.spath "
- + " from transstep c "
- + " inner join transreq d on c.rqid = d.rqid "
- + " inner join tuser e on d.uno = e.uno"
- + " where c.sstatus='1' and c.rqid = ";
- sql = sql +rqid +" order by c.scurrentid";
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- Map steps = new HashMap();
- steps.put("rqid",rs.getString("rqid"));
- steps.put("scurrentid",rs.getString("scurrentid"));
- steps.put("utruename",rs.getString("utruename"));
- steps.put("scurrenttime",rs.getString("scurrenttime"));
- steps.put("snexttime",rs.getString("snexttime"));
- steps.put("sname",rs.getString("sname"));
- steps.put("spath",rs.getString("spath"));
- list.add(steps);
- }
- request.setAttribute("req", req);
- request.setAttribute("affair", affair);
- } catch (SQLException e) {
- e.printStackTrace();
- list = null;
- }finally{
- session.close();
- sf.close();
- }
- return list;
- }
- public void setread(String rqid) {
- Connection conn = null;
- Statement st = null;
- String sql = "";
- sql = "update transstep set sstatus ='1' where rqid =" + rqid;
- session = sf.openSession();
- conn =session.connection();
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st.execute(sql);
- conn.commit();//提交事务
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- }
- public boolean affairPass(String tag, HttpServletRequest request, AffairReqForm affairReqForm) {
- Connection conn = null;
- Statement st = null;
- Statement st2 = null;
- Transstep affairstep = new Transstep();
- String sql = "";
- String StepSql = "";
- String sid = request.getParameter("sid");
- String rqid = request.getParameter("rqid");
- String stepid = request.getParameter("stepid");
- String nstepid = String.valueOf(Integer.parseInt(stepid)+1);
- session = sf.openSession();
- conn =session.connection();
- //审核通过
- if (tag.equals("noend")) {
- // 当前环节实际完成时间
- String date = ToolUtil.getDate();
- //先把上一环节的数据插入完整 ,并更改状态
- sql = "update transstep set scurrenttime ='"+date+"',";
- sql = sql +" snextuno='"+request.getParameter("userid")+"',";
- sql = sql +" snexttime='"+request.getParameter("snexttime")+"',";
- sql = sql +" sresult='3',";//0:待办,1:审核中,2:未通过,3:通过
- sql = sql +" sdetail='"+request.getParameter("memo")+"',";
- sql = sql +" sname='"+affairReqForm.getSname()+"',";
- sql = sql +" spath='"+affairReqForm.getSpath()+"'";
- sql = sql + " where sid =" + sid;
- affairstep.setUno(request.getParameter("userid"));
- affairstep.setSstatus("0");//当前状态
- affairstep.setSresult("1");
- StepSql ="insert into TRANSSTEP (SID, RQID, SCURRENTID, UNO, SSTATUS, SPRESTEP, SNEXTUNO, SCURRENTTIME, SNEXTTIME, SRESULT, SDETAIL, SNAME, SPATH)";
- StepSql = StepSql+ "values ( SEQ_T_RANSSTEP.nextval,";
- StepSql = StepSql +rqid+",";
- StepSql = StepSql +nstepid+",'";
- StepSql = StepSql +affairstep.getUno()+"','";
- StepSql = StepSql +affairstep.getSstatus()+"',";
- StepSql = StepSql +stepid+",'";
- StepSql = StepSql +affairstep.getSnextuno()+"','";
- StepSql = StepSql +affairstep.getScurrenttime()+"','";
- StepSql = StepSql +affairstep.getSnexttime()+"','";
- StepSql = StepSql +affairstep.getSresult()+"','";
- StepSql = StepSql +affairstep.getSdetail()+"','";
- StepSql = StepSql +affairstep.getSname()+"','";
- StepSql = StepSql +affairstep.getSpath()+"')";
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st2 = conn.createStatement();
- st.execute(sql);
- st2.execute(StepSql);
- conn.commit();//提交事务
- return true;
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- st2.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- //插入下一环节的数据
- }
- //审核通过并完结该事务
- if (tag.equals("end")) {
- String date = ToolUtil.getDate();
- //插入发起表 的事务结束时间
- String seqSql = "";
- seqSql =" update transreq set rendtime = '"+date+"',RSTATUS ='3' where rqid='"+rqid+"'";
- //先把上一环节的数据插入完整 ,并更改状态
- sql = "update transstep set scurrenttime ='"+date+"',";
- sql = sql +" snextuno='"+request.getParameter("userid")+"',";
- sql = sql +" snexttime='"+request.getParameter("snexttime")+"',";
- sql = sql +" sresult='3',";//0:待办,1:审核中,2:未通过,3:通过
- sql = sql +" sdetail='"+request.getParameter("memo")+"',";
- sql = sql +" sname='"+affairReqForm.getSname()+"',";
- sql = sql +" spath='"+affairReqForm.getSpath()+"'";
- sql = sql + " where sid =" + sid;
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st2 = conn.createStatement();
- st.execute(sql);
- st2.execute(seqSql);
- conn.commit();//提交事务
- return true;
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- st2.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- }
- //审核不通过返回上一环节
- if (tag.equals("back")) {
- //如果是第一环节,要把
- int id = Integer.parseInt(stepid);
- String tmpid = "";
- String seqSql = "";
- if(id>1){
- tmpid = String.valueOf(id-1);
- sql = "delete from transstep where rqid = '"+ rqid +"'";
- seqSql =" update transstep set sstatus ='0' where rqid ='"+tmpid+"'";
- }else{
- sql = "update transstep set sstatus ='0' where rqid =" + rqid;
- }
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st2 = conn.createStatement();
- st.execute(sql);
- st2.execute(seqSql);
- conn.commit();//提交事务
- return true;
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- st2.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- }
- // 审核不通过并完结该事务
- if (tag.equals("nopass")) {
- String date = ToolUtil.getDate();
- //插入发起表 的事务结束时间
- String seqSql = "";
- seqSql =" update transreq set rendtime = '"+date+"' and RSTATUS ='1' where rqid='"+rqid+"'";
- //先把上一环节的数据插入完整 ,并更改状态
- sql = "update transstep set scurrenttime ='"+date+"',";
- sql = sql +" snextuno='"+request.getParameter("userid")+"',";
- sql = sql +" snexttime='"+request.getParameter("snexttime")+"',";
- sql = sql +" sresult='2',";//0:待办,1:审核中,2:未通过,3:通过
- sql = sql +" sdetail='"+request.getParameter("memo")+"',";
- sql = sql +" sname='"+affairReqForm.getSname()+"',";
- sql = sql +" spath='"+affairReqForm.getSpath()+"'";
- sql = sql + " where sid =" + sid;
- try {
- conn.setAutoCommit(false);//设置不自动提交
- st = conn.createStatement();
- st2 = conn.createStatement();
- st.execute(sql);
- st2.execute(seqSql);
- conn.commit();//提交事务
- return true;
- } catch (SQLException e) {
- try {
- conn.rollback();//事务回顾
- } catch (SQLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- e.printStackTrace();
- }finally{
- try {
- st.close();
- st2.close();
- conn.close();
- } catch (SQLException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- }
- return false;
- }
- public List mydealList(AffairReqForm affairReqForm, HttpServletRequest request) {
- // TODO 自动生成方法存根
- return null;
- }
- public List mysendList(AffairReqForm affairReqForm, HttpServletRequest request) {
- // TODO 自动生成方法存根
- return null;
- }
- public List myreqList(int currentPage, int count, Transreq reqbean, HttpServletRequest request) {
- String uno = (String) request.getAttribute("uno");
- StringBuffer sql = new StringBuffer();
- StringBuffer centent = new StringBuffer();
- String rgrade = request.getParameter("rgrade");
- if(reqbean.getReqUsername()!=null&&!reqbean.getReqUsername().trim().equals("")){
- centent.append(" and c.utruename like '%").append(reqbean.getReqUsername().trim()).append("%'");
- }
- if(rgrade !=null && !rgrade.trim().equals("")){
- centent.append("and b.rgrade =").append(rgrade.trim()).append("");
- }
- if(reqbean.getRstarttime()!=null &&!reqbean.getRstarttime().trim().equals("")){
- centent.append(" and b.rlasttime between'").append(reqbean.getRstarttime().trim()).append("'");
- centent.append(" and '").append(reqbean.getRendtime().trim()).append("'");
- }
- sql.append("SELECT * FROM(")
- .append("select a.SCURRENTID,b.rqid , c.utruename,b.rtitle,b.rgrade,a.scurrenttime,d.tname,a.sresult,ROWNUM as num from transstep a ")
- .append(" left join transreq b on a.rqid = b.rqid ")
- .append(" left join tuser c on b.uno = c.uno")
- .append(" left join transtype d on d.rtid = b.tno where a.sstatus<>'0' and c.uno = '").append(uno).append("'")
- .append(centent)
- .append(")t WHERE ");
- sql.append(" t.num<=").append(currentPage*count);
- sql.append(" AND t.num>").append((currentPage-1)*count);
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- session = sf.openSession();
- conn = session.connection();
- List list = null;
- Transreq reqbeans = null;
- try {
- int i = 0 ;
- st = conn.createStatement();
- rs = st.executeQuery(sql.toString());
- list = new ArrayList();
- while (rs.next()) {
- i = i +1;
- reqbeans = new Transreq();
- reqbeans.setRqid(rs.getInt("RQID"));
- reqbeans.setCurrentid(rs.getString("SCURRENTID"));
- reqbeans.setRtitle(rs.getString("RTITLE"));
- reqbeans.setTname(rs.getString("TNAME"));
- reqbeans.setRresult(rs.getString("sresult"));
- reqbeans.setReqUsername(rs.getString("utruename"));
- reqbeans.setRgrade(rs.getString("rgrade"));
- reqbeans.setRlasttime(rs.getString("scurrenttime"));
- list.add(reqbeans);
- }
- // request.setAttribute("currentid",);
- if (i == 0 ){
- list = null;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- session.close();
- sf.close();
- }
- return list;
- }
- public List myarrairList(int currentPage, int count, Transreq reqbean, HttpServletRequest request) {
- String uno = (String) request.getAttribute("uno");
- StringBuffer sql = new StringBuffer();
- StringBuffer centent = new StringBuffer();
- String rgrade = request.getParameter("rgrade");
- if(rgrade !=null && !rgrade.trim().equals("")){
- centent.append("and a.rgrade =").append(rgrade.trim()).append("");
- }
- if(reqbean.getRstarttime()!=null &&!reqbean.getRstarttime().trim().equals("")){
- centent.append(" and a.rlasttime between'").append(reqbean.getRstarttime().trim()).append("'");
- centent.append(" and '").append(reqbean.getRendtime().trim()).append("'");
- }
- sql.append("SELECT * FROM(")
- .append("select a.rqid,a.rtitle,a.rgrade,b.tname,a.rstatus, a.rlasttime, ")
- .append(" ROWNUM as num from transreq a left join transtype b on b.rtid = a.tno ")
- .append(" left join tuser c on c.uno = a.uno where 1= 1 and c.uno = '").append(uno).append("'")
- .append(centent)
- .append(")t WHERE ");
- sql.append(" t.num<=").append(currentPage*count);
- sql.append(" AND t.num>").append((currentPage-1)*count);
- Connection conn = null;
- Statement st = null;
- ResultSet rs = null;
- session = sf.openSession();
- conn = session.connection();
- List list = null;
- Transreq reqbeans = null;
- try {
- int i = 0 ;
- st = conn.createStatement();
- rs = st.executeQuery(sql.toString());
- list = new ArrayList();
- while (rs.next()) {
- i = i +1;
- reqbeans = new Transreq();
- reqbeans.setRqid(rs.getInt("RQID"));
- reqbeans.setRtitle(rs.getString("RTITLE"));
- reqbeans.setTname(rs.getString("TNAME"));
- reqbeans.setRresult(rs.getString("rstatus"));
- reqbeans.setRgrade(rs.getString("rgrade"));
- reqbeans.setRlasttime(rs.getString("rlasttime"));
- list.add(reqbeans);
- }
- if (i == 0 ){
- list = null;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- session.close();
- sf.close();
- }
- return list;
- }
- }