• java删除、动态增加


     /**
      * 删除检查单类型
      * @param dct_type
      * @return
      */
     public static String deleteChecklistType(String [] dct_type){
       String str = "";
       for(int i= 0; i < dct_type.length; i++)
       {
        if(i == dct_type.length -2)
        {
         str += dct_type[i] + "','";
        }
        if(i == dct_type.length -1)
        {
         str += dct_type[i];
        }
       }
       StringBuffer sql = new StringBuffer();
       sql.append("DELETE FROM CSS_CM_CHECKLIST_TYPE T WHERE T.CHECKLIST_TYPE_CODE IN ('"+ str + "')");   
       return sql.toString();
       
      }

    public void stopCheckListType(RequestKit requestKit) {
       String [] dct_types = requestKit.getParameterValues("dcp_type");
       String action = requestKit.getParameter("action", "");
       Connection conn = null;
       try {
        conn = this.getConnection();
        DataBaseExecutor executor = DataBaseExecutor.getExecutor(conn);
        //conn.setAutoCommit(false);
        RecordSet recordSet = new RecordSet();
        for(int i=0; i<dct_types.length; i++)
        {
          Record rd= new Record();
          rd.setEntityName("CSS_CM_CHECKLIST_TYPE");
          rd.setPrimaryKey("CHECKLIST_TYPE_CODE");
          rd.addData("CHECKLIST_TYPE_CODE", dct_types[i]);
          if(action.equals("start"))
          {
           rd.addData("STATE", Constants.JCDTYPE_ON);
          }else if(action.equals("stop"))
          {
           rd.addData("STATE", Constants.JCDTYPE_OFF);
          }
          recordSet.add(rd);
        }
        executor.update(recordSet);
        //executor.execute(DdmenuListSql.deleteChecklistSession(dct_type));
        //executor.execute(DdmenuListSql.deleteChecklistType(dct_type));
        //conn.commit();
        //conn.setAutoCommit(true);
       } catch (SQLException e) {
        log.error("根据检查单类型UUID批量删除检查单类型,数据库操作失败" + e);
        throw new BaseException(ErrorCode.SQL_EXCEPTION, e);
       }
       finally{
        try {
         if(null!=conn){
         conn.close();
         }
        } catch (SQLException e) {
         log.error("根据检查单类型UUID批量删除检查单类型,关闭数据库连接失败" + e);
         e.printStackTrace();
        }
       }
      } 

    /**
      * 保存检查单类型数据
      *
      * @param requestKit
      */
     public Record saveChecklistType(RequestKit kit) {
      Connection conn = null;
      try {
       conn = this.getConnection();
       DataBaseExecutor dbe = DataBaseExecutor.getExecutor(conn);
       conn.setAutoCommit(false);
       //检查单内容
       Record record = kit.getRecordWithPrefix("CK_");
       record.setConnection(conn);
       record.setEntityName("CSS_CM_CHECKLIST_TYPE");
       record.setPrimaryKey("CHECKLIST_TYPE_CODE");
       record.store();
       //章节项内容
       String [] ucsc = kit.getParameterValues("UP_CHECKLIST_SECTION_CODE");
       String [] ucsn = kit.getParameterValues("UP_CHECKLIST_SECTION_NAME");
       String [] ucss = kit.getParameterValues("UP_CHECKLIST_SECTION_SORTNO");
       //检查单类型编码
       String ctc = record.getString("CHECKLIST_TYPE_CODE", "");
       Record zjRecord = null;
       RecordSet recordZjSet = new RecordSet();
       for(int i=0; i<ucsc.length; i++)
       {
        zjRecord = new Record();
        zjRecord.setEntityName("CSS_CM_CHECKLIST_SECTION");
        zjRecord.setPrimaryKey("UUID");
        zjRecord.addData("CHECKLIST_SECTION_CODE", ucsc[i].trim());
        zjRecord.addData("CHECKLIST_SECTION_NAME", ucsn[i].trim());
        zjRecord.addData("CHECKLIST_SECTION_SORTNO", ucss[i].trim());
        zjRecord.addData("CHECKLIST_TYPE_CODE", ctc.trim());
        zjRecord.addData("STATE", Constants.JCDTYPE_ON);
        recordZjSet.add(zjRecord);
       }
       String delJHSql = "DELETE FROM CSS_CM_CHECKLIST_SECTION T WHERE T.CHECKLIST_TYPE_CODE='"+ ctc + "'";
       if(recordZjSet!=null && recordZjSet.size()>0)
       {
         dbe.execute(delJHSql);
         dbe.create(recordZjSet);
       }
       conn.commit();
       conn.setAutoCommit(true);
       return record;
      } catch (SQLException e) {
       log.error("保存检查单类型数据信息,数据库操作失败" + e);
       throw new BaseException(ErrorCode.SQL_EXCEPTION, e);
      } finally {
       if (conn != null) {
        try {
         conn.close();
        } catch (SQLException e) {
         log.error("保存检查单类型数据信息,关闭数据库连接失败" + e);
         throw new BaseException(ErrorCode.CON_NOT_CLOSE, e);
        }
       }
      }
     }

     

    每一天都要行动,在前进中寻求卓越。
  • 相关阅读:
    转char varchar nvarchar区别
    NHibernate和Spring.Net框架介绍(一)
    ASP.NET面试题(一)
    存储过程编写经验和优化措施
    软件工程师不可不知的10个概念
    优化数据库前问自己的10个问题
    ZOJ 1610 Count the Colors (线段树)
    POJ 3667 Hotel (线段树)
    HDU Best Reward (扩展KMP)
    POJ 3277 City Horizon (线段树)
  • 原文地址:https://www.cnblogs.com/wshsdlau/p/2571030.html
Copyright © 2020-2023  润新知