2926bceef6a9715cbd7da6dcb5ca4ed65180b8db.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. package com.sinosoft.common.memoryCondition.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import org.apache.log4j.Logger;
  10. import com.persistence.DbConnection;
  11. import com.persistence.service.PersistenceFactory;
  12. import com.persistence.service.SysPersistence;
  13. import com.persistence.service.assitant.generator.IdentityGenerator;
  14. import com.sinosoft.common.memoryCondition.vo.MemoryCon;
  15. import com.sinosoft.em.alert.report.manage.dao.QueryReportProgrammeDaoImpl;
  16. import com.sinosoft.em.alert.report.manage.vo.ReportProgress;
  17. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  18. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  19. public class MemoryConditionDao {
  20. private static SysModel sysmodel = ModelFactory.getSysmodel();
  21. @SuppressWarnings("unused")
  22. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  23. private final static Logger log = Logger.getLogger(QueryReportProgrammeDaoImpl.class);
  24. public String addMemoryCondition(String userId, String menupageid, String name, ArrayList<MemoryCon> paramslist) throws Exception {
  25. DbConnection db = new DbConnection();
  26. Connection conn = null;
  27. PreparedStatement ps = null;
  28. PreparedStatement ps1 = null;
  29. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  30. String now = sdf.format(new Date());
  31. try {
  32. String sql = "insert into SYS_USER_SEARCH_CONDITIONS(FD_OBJECTID, USER_ID, MENU_ID, NAME, IS_DEL, INPUT_TIME, UPDATEDATE) VALUES(?,?,?,?,?,?,?)";
  33. String sql1 = "insert into SYS_USER_SEARCH_CONDITIONS_FU(FD_OBJECTID, CONDITION_ID, CONDITION_NAME, CONDITION_VALUE, CONDITION_TYPE) VALUES(?,?,?,?,?)";
  34. conn = db.getConnection();
  35. conn.setAutoCommit(false);
  36. int flag1 = 0;
  37. ps = conn.prepareStatement(sql);
  38. ps1 = conn.prepareStatement(sql1);
  39. String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(746);
  40. ps.setString(1, fd_id);
  41. ps.setString(2, userId);
  42. ps.setString(3, menupageid);
  43. ps.setString(4, name);
  44. ps.setString(5, "0");
  45. ps.setString(6, now);
  46. ps.setString(7, now);
  47. int flag = ps.executeUpdate();
  48. for (MemoryCon meCon : paramslist) {
  49. ps1.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(747));
  50. ps1.setString(2, fd_id);
  51. ps1.setString(3, meCon.getName());
  52. ps1.setString(4, meCon.getValue());
  53. ps1.setString(5, meCon.getType());
  54. ps1.addBatch();
  55. }
  56. ps1.executeBatch();
  57. flag1++;
  58. if(flag==1 && flag1==1){
  59. conn.commit();
  60. return "sucsess";
  61. }else{
  62. conn.rollback();
  63. return "error";
  64. }
  65. } catch (Exception e) {
  66. throw e;
  67. }finally{
  68. db.close(ps1);
  69. db.close(ps);
  70. db.close(conn);
  71. }
  72. }
  73. public void deleteMemoryCon(String fd_id) throws Exception {
  74. DbConnection db = new DbConnection();
  75. Connection conn = null;
  76. PreparedStatement ps = null;
  77. try {
  78. String sql = "update SYS_USER_SEARCH_CONDITIONS set IS_DEL='1' WHERE FD_OBJECTID=?";
  79. conn = db.getConnection();
  80. ps = conn.prepareStatement(sql);
  81. ps.setString(1, fd_id);
  82. ps.executeUpdate();
  83. } catch (Exception e) {
  84. throw e;
  85. }finally{
  86. db.close(ps);
  87. db.close(conn);
  88. }
  89. }
  90. public String queryMemoryCondition(String userId, String menupageid) throws Exception {
  91. DbConnection db = new DbConnection();
  92. Connection conn = null;
  93. PreparedStatement ps = null;
  94. ResultSet rs = null;
  95. StringBuffer sb = new StringBuffer();
  96. PreparedStatement ps1 = null;
  97. ResultSet rs1 = null;
  98. try {
  99. String sql = "select FD_OBJECTID,USER_ID,MENU_ID,NAME from SYS_USER_SEARCH_CONDITIONS where IS_DEL='0' AND USER_ID=? AND MENU_ID=?";
  100. conn = db.getConnection();
  101. ps = conn.prepareStatement(sql);
  102. ps.setString(1, userId);
  103. ps.setString(2, menupageid);
  104. rs = ps.executeQuery();
  105. sb.append("[");
  106. while(rs.next()){
  107. sb.append("{");
  108. String fd_id = rs.getString("FD_OBJECTID");
  109. String name = rs.getString("NAME");
  110. sb.append("\"fd_id\":\""+fd_id+"\"");
  111. sb.append(",\"name\":\""+name+"\"");
  112. String sql1 = "select CONDITION_NAME,CONDITION_VALUE,CONDITION_TYPE from SYS_USER_SEARCH_CONDITIONS_FU WHERE CONDITION_ID=? ";
  113. ps1 = conn.prepareStatement(sql1);
  114. ps1.setString(1, fd_id);
  115. rs1 = ps1.executeQuery();
  116. StringBuffer sb1 = new StringBuffer();
  117. while(rs1.next()){
  118. sb1.append("{");
  119. sb1.append("\"name\":\""+rs1.getString("CONDITION_NAME")+"\"");
  120. sb1.append(",\"value\":\""+rs1.getString("CONDITION_VALUE")+"\"");
  121. sb1.append(",\"type\":\""+rs1.getString("CONDITION_TYPE")+"\"");
  122. sb1.append("},");
  123. }
  124. if(sb1.length()>0){
  125. sb.append(",\"condition\":["+sb1.substring(0, sb1.length()-1)+"]");
  126. }else{
  127. sb.append(",\"condition\":[]");
  128. }
  129. sb.append("},");
  130. }
  131. String result = "";
  132. if(sb.length()>1){
  133. result = sb.substring(0,sb.length()-1);
  134. }else{
  135. result = sb.toString();
  136. }
  137. result += "]";
  138. return result;
  139. } catch (Exception e) {
  140. throw e;
  141. }finally{
  142. db.close(ps);
  143. db.close(conn);
  144. }
  145. }
  146. public String queryMenuId(String pageurl) throws Exception {
  147. DbConnection db = new DbConnection();
  148. Connection conn = null;
  149. PreparedStatement ps = null;
  150. ResultSet rs = null;
  151. String menu_id = "";
  152. try {
  153. String sql = "select menu_id from sys_menu where menu_url=? ";
  154. conn = db.getConnection();
  155. ps = conn.prepareStatement(sql);
  156. ps.setString(1, pageurl);
  157. rs = ps.executeQuery();
  158. while(rs.next()){
  159. menu_id = rs.getString("menu_id");
  160. }
  161. return menu_id;
  162. } catch (Exception e) {
  163. throw e;
  164. }finally{
  165. db.close(ps);
  166. db.close(conn);
  167. }
  168. }
  169. }