⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 researchbean.java

📁 电信的网厅的整站代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.doone.fj1w.fjmgr.research;

import com.doone.data.DacClient;
import com.doone.data.ConnectionLocator;
import com.doone.data.DataTable;
import com.doone.util.FileLogger;
import com.doone.data.*;
import java.util.*;
import java.text.SimpleDateFormat;
import java.sql.SQLException;

/**
 *
 * <p>Title:网上调查模块 </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: New Doone</p>
 *
 * @author wull
 * @version 1.0
 */
public class ResearchBean {
    private int pagecount = 15; //默认每页的记录数

    private DacClient _dac = null;

    private DataTable dt = null;

    public ResearchBean() {
        try {
            _dac = new DacClient();
//            try {
//                 _dac.beginTransaction(10000);
//                 _dac.endTransaction(true);
//                 _dac.endTransaction(false);
//             } catch (Exception ex1) {
//             }

        } catch (Exception ex) {
            FileLogger.getLogger().warn("数据库连接出错!", ex);
        }

    }
    /**
     * 创建工厂
     */
    private static Object initLock = new Object();
    private static ResearchBean factory = null;

    public static ResearchBean getInstance() {
        if (factory == null) {
            //使用synchronzed保证一次只有一个实例能访问对象
            synchronized (initLock) {
                if (factory == null) {
                    try {
                        //创建ResearchBean的一个实例
                        factory = new ResearchBean();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        return factory;
    }


    /**
     * 进行分页进行分页处理
     * @param rid String父ID为0的为根。其它为节点。
     * @param tablename String
     * @param citycode String
     * @return int
     */
    public int getPageCount(String rid, String citycode,String title,String desc,
                            String objecttype,String issuancestate,String starttime,String endtime) {
        //表名tablename暂时不用。wull注
        DataTable dt = null;
        int rowCount = 0;
        int pageNo = 0;
        try {
            String str = "";
            Object[] _object = null;

            String sql_str = "";
            if (title != null && !"".equals(title)) {
                sql_str += " and TITLE like '%" + title + "%'";
            }
            if (desc != null && !"".equals(desc)) {
                sql_str += " and DESCIPTION like '%" + desc + "%'";
            }
//OBJECTTYPE
            if (objecttype != null && !"".equals(objecttype)) {
                sql_str += " and OBJECTTYPE='" + objecttype + "'";
            }
//ISSUANCESTATE
            if (issuancestate != null && !"".equals(issuancestate)) {
                sql_str += " and ISSUANCESTATE='" + issuancestate + "'";
            }
//STARTTIME
            if (starttime != null && !"".equals(starttime)) {
                //SYSDATE>=NVL(STARTTIME,TO_DATE('1900-1-1','YYYY-MM-DD'));
                sql_str += " and TO_DATE('" + starttime +
                        "','YYYY-MM-DD')>=STARTTIME";
            }
//ENDTIME
            if (endtime != null && !"".equals(endtime)) {
                //SYSDATE>=NVL(STARTTIME,TO_DATE('1900-1-1','YYYY-MM-DD'));
                sql_str += " and TO_DATE('" + endtime +
                        "','YYYY-MM-DD')<=ENDTIME";
            }

          if(citycode == null || "null".equalsIgnoreCase(citycode) || "".equals(citycode) || "0590".equals(citycode)){
              str = "select count(*) count from tf_researchmain  where UPRESEARCHID=? "+sql_str;
              _object = new Object[1];
              _object[0] = rid;

          }else{
             str = "select count(*) count from tf_researchmain  where UPRESEARCHID=? AND CITYCODE=? "+sql_str;
             _object = new Object[2];
             _object[0] = rid;
             _object[1] = citycode;

          }
           //System.out.print("str===="+str);
            dt = _dac.executeQuery(str, _object);
            rowCount = dt.getRow(0).getInt("count");
            if (rowCount % pagecount == 0)
                pageNo = rowCount / pagecount;
            else
                pageNo = rowCount / pagecount + 1;
            return pageNo;
        } catch (Exception ex) {
            FileLogger.getLogger().warn("查询表页数出错了!", ex);
            return pageNo;

        }

    }
    /**
     * 用于查询问卷的名称,如果地市为空,或0590则可以看全省。
     * @param pageNo 第几页
     * @return
     */
    public DataTable query(int pageNo, String citycode, String title,
                           String desc,
                           String objecttype, String issuancestate,
                           String starttime, String endtime) {
        dt = null;
        try {
            int start = (pagecount * (pageNo - 1))+1;
            int end = pagecount * pageNo;
            String sql = null;
             Object[] _object = null;
             String sql_str="";
             if(title != null && !"".equals(title)){
                sql_str += " and TITLE like '%"+title+"%'";
             }
             if(desc != null && !"".equals(desc)){
                sql_str += " and DESCIPTION like '%"+desc+"%'";
             }
             //OBJECTTYPE
             if(objecttype != null && !"".equals(objecttype)){
                sql_str += " and OBJECTTYPE='"+objecttype+"'";
             }
             //ISSUANCESTATE
             if(issuancestate != null && !"".equals(issuancestate)){
                sql_str += " and ISSUANCESTATE='"+issuancestate+"'";
             }
             //STARTTIME
             if(starttime != null && !"".equals(starttime)){
                 //SYSDATE>=NVL(STARTTIME,TO_DATE('1900-1-1','YYYY-MM-DD'));
                sql_str += " and TO_DATE('"+starttime+"','YYYY-MM-DD')>=STARTTIME";
             }
             //ENDTIME
             if(endtime != null && !"".equals(endtime)){
                 //SYSDATE>=NVL(STARTTIME,TO_DATE('1900-1-1','YYYY-MM-DD'));
                sql_str += " and TO_DATE('"+endtime+"','YYYY-MM-DD')<=ENDTIME";
             }

            if(citycode == null || "null".equalsIgnoreCase(citycode) || "".equals(citycode) || "0590".equals(citycode)){
                 sql = "select * from (select a.*,rownum num from (select RESEARCHID,CITYCODE,TITLE,DESCIPTION," +
                             " to_char(CREATETIME,'yyyy-mm-dd  hh24:mi:ss') CREATETIME,ITEMTYPE,OBJECTTYPE,GOTTA,ORDERNO," +
                             " UPRESEARCHID,ISSUANCESTATE,to_char(STARTTIME,'yyyy-mm-dd') STARTTIME,to_char(ENDTIME,'yyyy-mm-dd') ENDTIME from tf_researchmain where UPRESEARCHID=? " +sql_str+
                             " order by ORDERNO DESC,RESEARCHID DESC) a) where num >= " +
                             String.valueOf(start) + " and num<= " +
                             String.valueOf(end);
                       _object = new Object[1];
                       _object[0] = "0";
            }else{
                sql = "select * from (select a.*,rownum num from (select RESEARCHID,CITYCODE,TITLE,DESCIPTION," +
                               " to_char(CREATETIME,'yyyy-mm-dd  hh24:mi:ss') CREATETIME,ITEMTYPE,OBJECTTYPE,GOTTA,ORDERNO," +
                               " UPRESEARCHID,ISSUANCESTATE,to_char(STARTTIME,'yyyy-mm-dd') STARTTIME,to_char(ENDTIME,'yyyy-mm-dd') ENDTIME from tf_researchmain where UPRESEARCHID=? AND CITYCODE=?"  +sql_str+
                               " order by ORDERNO DESC,RESEARCHID DESC) a) where num >= " +
                               String.valueOf(start) + " and num<= " +
                               String.valueOf(end);
                         _object = new Object[2];
                         _object[0] = "0";
                         _object[1] = citycode;

            }
            //System.out.println("数据库:"+sql);

            dt = _dac.executeQuery(sql, _object);
        } catch (Exception ex) {
            FileLogger.getLogger().warn("query数据库查询出错!", ex);
            dt = null;
        }
        return dt;
    }

    /**
     * 用于查询问卷的题目
     * @param id --》UPRESEARCHID
     * @param pageNo
     * @return
     */
    public DataTable queryRe(String id, int pageNo) {
        dt = null;
        try {
//            int start = (pagecount * (pageNo - 1))+1;
//            int end = pagecount * pageNo;
//            String sql = "select * from (select a.*,rownum num from (select * from tf_researchmain where UPRESEARCHID=?  order by RESEARCHID) a) where num >= " +
//                         String.valueOf(start) + " and  num <= " +
//                         String.valueOf(end);
            String sql ="select RESEARCHID,CITYCODE,TITLE,DESCIPTION,to_char(CREATETIME,'yyyy-mm-dd  hh24:mi:ss') CREATETIME,ITEMTYPE,OBJECTTYPE,GOTTA,ORDERNO,UPRESEARCHID,ISSUANCESTATE  from tf_researchmain where UPRESEARCHID=? order by ORDERNO,RESEARCHID";
            Object[] _object = new Object[1];
            _object[0] = id;
            dt = _dac.executeQuery(sql, _object);
        } catch (Exception ex) {
            FileLogger.getLogger().warn("数据库查询出错!", ex);
            dt = null;
        }
        return dt;
    }

    /**
     * 用语查询tf_researchmain中指定的记录
     * @param id
     * @return
     */
    public DataTable queryRid(String id) {
        dt = null;
        try {
            String sql =
                    "SELECT RESEARCHID,UPRESEARCHID,CITYCODE,TITLE,DESCIPTION,to_char(CREATETIME,'YYYY-MM-DD') CREATETIME,ITEMTYPE,OBJECTTYPE,GOTTA,ORDERNO,ISSUANCESTATE,to_char(STARTTIME,'YYYY-MM-DD') STARTTIME,to_char(ENDTIME,'YYYY-MM-DD') ENDTIME,GOTTACOUNT  FROM TF_RESEARCHMAIN  WHERE RESEARCHID=? ORDER BY RESEARCHID";
            Object[] _object = new Object[1];
            _object[0] = id;
            dt = _dac.executeQuery(sql, _object);
        } catch (Exception ex) {
            FileLogger.getLogger().warn("数据库查询出错!", ex);
            dt = null;
        }
        return dt;
    }

    /**
     * 用于在tf_researchmain中添加记录,也就是添加问卷
     * @param CityCode
     * @param Title
     * @param Desciption
     * @param ObjectType
     * @param OrderNo
     * @param IssuanceState
     * @param UPRESEARCHID
     * @return
     */
    public int updateAdd(String CityCode, String Title, String Desciption,
                         String ObjectType, String OrderNo,
                         String IssuanceState,
                         String UPRESEARCHID,String starttime,String endtime) {
        int i = 0;
        try {
            String sqlstr = "Insert into tf_researchmain(ResearchId,CityCode,Title,Desciption,CREATETIME,ObjectType,OrderNo,IssuanceState,UPRESEARCHID,STARTTIME,ENDTIME) values(seq_researchid.nextval,?,?,?,sysdate,?,?,?,?,?,?)";

            Object[] _object = new Object[9];
            _object[0] = CityCode;
            _object[1] = Title;
            _object[2] = Desciption;
            _object[3] = ObjectType;
            _object[4] = OrderNo;
            _object[5] = IssuanceState;
            _object[6] = UPRESEARCHID;

            SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd");
            //Date startdate = sdt.parse(starttime);
            _object[7] = sdt.parse(starttime);
            _object[8] = sdt.parse(endtime);
            //_dac.beginTransaction(10000);
            i = _dac.executeUpdate(sqlstr, 10000, _object);
            //_dac.endTransaction(true);
        } catch (Exception ex) {
            FileLogger.getLogger("数据库入库出错!" + ex.getMessage().toString());
        }
        return i;
    }

    /**
     * 用于在tf_researchmain中添加记录,也就是添加题目
     * @param CityCode
     * @param Title
     * @param Desciption
     * @param ItemType
     * @param ObjectType
     * @param Gotta
     * @param UPRESEARCHID
     * @param OrderNo
     * @param IssuanceState
     * @return
     */
    public int updateReAdd(String CityCode, String Title, String Desciption,
                           String ItemType, String ObjectType, String Gotta,
                           String UPRESEARCHID, String OrderNo,
                           String IssuanceState,String gottacount) {
        int i = 0;
        try

        {
            String sqlstr = "Insert into tf_researchmain(researchid,CityCode,Title,Desciption,CREATETIME,ItemType,ObjectType,Gotta,UPRESEARCHID,OrderNo,IssuanceState,GOTTACOUNT)"+
                    " values(seq_researchid.nextval,?,?,?,sysdate,?,?,?,?,?,?,?)";

            Object[] _object = new Object[10];
            _object[0] = CityCode;
            _object[1] = Title;
            _object[2] = Desciption;
            _object[3] = ItemType;
            _object[4] = ObjectType;
            _object[5] = Gotta;
            _object[6] = UPRESEARCHID;
            _object[7] = OrderNo;
            _object[8] = IssuanceState;
            _object[9] = gottacount;
            //_dac.beginTransaction(10000);
            i = _dac.executeUpdate(sqlstr, 10000, _object);
            //_dac.endTransaction(true);
        } catch (Exception ex) {
            FileLogger.getLogger("数据库入库出错!" + ex.getMessage().toString());

        }
        return i;
    }


    /**
     * wull 更新题目。12.24
     * @param Title String
     * @param Desciption String
     * @param ItemType String
     * @param ObjectType String
     * @param Gotta String
     * @param ORDERNO String
     * @param IssuanceState String
     * @param ResearchId String
     * @return int
     */
    public int updateRe(String Title, String Desciption,
                    String ItemType, String ObjectType, String Gotta,
                    String ORDERNO,
                    String IssuanceState, String ResearchId,String gottacount) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -