5c53255e4af52a66c363469515018c5c982ff0f5.svn-base 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package com.sinosoft.cm.impl;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import nl.justobjects.pushlet.util.Sys;
  10. import org.apache.log4j.Logger;
  11. import com.sinosoft.cm.CMHandlerResultSet;
  12. import com.sinosoft.cm.CMTemplate;
  13. import com.sinosoft.cm.DBUtils;
  14. import com.sinosoft.cm.common.StringUtils;
  15. import com.sinosoft.cm.common.vo.ResultState;
  16. import com.sinosoft.cm.dao.SysLayoutDao;
  17. import com.sinosoft.cm.ex.SQLStringException;
  18. import com.sinosoft.cm.vo.SysLayout;
  19. import flex.messaging.io.ArrayList;
  20. public class SysLayoutDaoImpl extends CMDaoImpl<SysLayout> implements SysLayoutDao {
  21. public SysLayoutDaoImpl() {
  22. this.cmt=new CMTemplate();
  23. this.map=new HashMap<String,String>();
  24. //旧代码
  25. this.map.put("update", "update ECM_CM_SYSLAYOUT set IS_DEL=? where FD_OBJECTID=?");
  26. this.map.put("delete", "delete from ECM_CM_SYSLAYOUT where FD_OBJECTID=?");
  27. this.map.put("insert", "insert into ECM_CM_SYSLAYOUT (FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID) "
  28. + "values(?,?,?,?,?,?,?)");
  29. this.map.put("queryById", "select FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID,SCREEN_STATE from ECM_CM_SYSLAYOUT where FD_OBJECTID=?");
  30. this.map.put("queryAll", "select FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID,UPDATEDATE from ECM_CM_SYSLAYOUT");
  31. //新代码
  32. this.map.put("getView","SELECT FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID "+
  33. "FROM ECM_CM_SYSLAYOUT "+
  34. " WHERE SL_USERID='R002105430214' OR SL_USERID=? ORDER BY SL_USERID,UPDATEDATE");
  35. this.map.put("getSingleView", "SELECT OL_CONID,OL_MATICID FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?");
  36. this.map.put("getOften", "SELECT IS_COMMONUSE FROM ECM_CM_SYSLAYOUT WHERE IS_COMMONUSE <> '' AND SL_USERID=? AND SCREEN_STATE='1';");
  37. }
  38. public String saveLayou(String name,String params,String userId,String[] conId,String[] maticId,String setOften ){
  39. String saveLayoutStr="insert into NWYJ.ECM_CM_SYSLAYOUT( FD_OBJECTID, SL_NAME, SL_PARAMENT, SL_USERID, IS_DEL, UPDATEDATE, TM_BEX,IS_COMMONUSE) "
  40. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0, SYSDATE(), 0,?)";
  41. String LayoutStr="SELECT FD_OBJECTID,UPDATEDATE,SL_NAME FROM NWYJ.ECM_CM_SYSLAYOUT "
  42. + " WHERE UPDATEDATE=(SELECT MAX(UPDATEDATE) "
  43. + " FROM NWYJ.ECM_CM_SYSLAYOUT WHERE SL_USERID= ? )";
  44. String saveOpenMatic="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) "
  45. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)";
  46. String result=null;
  47. Connection conn=null;
  48. PreparedStatement ps=null;
  49. ResultSet rs=null;
  50. int flag=0;
  51. try {
  52. conn=DBUtils.getConnection();
  53. conn.setAutoCommit(false);
  54. //保存视图
  55. log.info("===saveLayou()===sql==="+saveLayoutStr);
  56. ps=conn.prepareStatement(saveLayoutStr);
  57. ps.setString(1, name);
  58. ps.setString(2, params);
  59. ps.setString(3, userId);
  60. ps.setString(4, setOften);
  61. ps.executeUpdate();
  62. //获取保存视图后的主键id
  63. log.info("===saveLayou()===sql==="+LayoutStr);
  64. ps=conn.prepareStatement(LayoutStr);
  65. ps.setString(1, userId);
  66. rs=ps.executeQuery();
  67. //System.out.println(flag);
  68. //保存各个容器的专题图
  69. System.out.println("conId.length"+conId.length);
  70. String objectId=null;
  71. String viewName=null;
  72. while(rs.next()){
  73. objectId= rs.getString("FD_OBJECTID");
  74. viewName=rs.getString("SL_NAME");
  75. }
  76. for(int count=0;count<conId.length;count++){
  77. log.info("===saveLayou()===sql==="+saveOpenMatic);
  78. ps=conn.prepareStatement(saveOpenMatic);
  79. ps.setString(1, conId[count]);
  80. ps.setString(2, objectId);
  81. ps.setString(3,maticId[count]);
  82. ps.setString(4, viewName);
  83. ps.executeUpdate();
  84. }
  85. conn.commit();
  86. result=ResultState.SUCCESS;
  87. } catch (Exception e) {
  88. conn.rollback();
  89. log.error(e.getMessage());
  90. result=ResultState.FAILURE;
  91. }finally{
  92. DBUtils.close(rs, ps, conn);
  93. return result;
  94. }
  95. }
  96. public List<Map<String,String>> findAll(String sqlName,Object...args) throws SQLStringException{
  97. List<String> list=StringUtils.sqlStringToListLabel(map.get(sqlName).trim().toUpperCase(), ",");
  98. log.info("======findAll(String sqlName,Object...args)==sqlLabel="+list);
  99. if(map.get(sqlName).toLowerCase()==null&&"".equals(map.get(sqlName).trim()))
  100. throw new SQLStringException("查询语句为空");
  101. log.info("======findAll(String sqlName,Object...args)==sql="+map.get(sqlName).trim().toUpperCase());
  102. return cmt.queryMoreTypeToMap(map.get(sqlName), list, args);
  103. }
  104. //更改视图名称
  105. @SuppressWarnings("finally")
  106. public String updateName(String name,String id,String[] conId,String[] maticId){
  107. Connection conn=null;
  108. PreparedStatement ps=null;
  109. String setViewName="update ECM_CM_SYSLAYOUT set SL_NAME=? where FD_OBJECTID=?";
  110. String deleteMatics="DELETE FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?";
  111. String insertMatics="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) "
  112. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)";
  113. String result=null;
  114. try {
  115. conn=DBUtils.getConnection();
  116. conn.setAutoCommit(false);
  117. //修改视图名称
  118. ps=conn.prepareStatement(setViewName);
  119. ps.setString(1, name);
  120. ps.setString(2, id);
  121. ps.executeUpdate();
  122. ps.close();
  123. //删除视图
  124. ps=conn.prepareStatement(deleteMatics);
  125. ps.setString(1,id);
  126. ps.executeUpdate();
  127. //
  128. for(int i=0;i<conId.length;i++){
  129. ps=conn.prepareStatement(insertMatics);
  130. ps.setString(1, conId[i]);
  131. ps.setString(2, id);
  132. ps.setString(3, maticId[i]);
  133. ps.setString(4, name);
  134. ps.executeUpdate();
  135. }
  136. conn.commit();
  137. result=ResultState.SUCCESS;
  138. } catch (SQLException e) {
  139. conn.rollback();
  140. e.printStackTrace();
  141. result=ResultState.FAILURE;
  142. }finally{
  143. DBUtils.close(null, ps, conn);
  144. return result;
  145. }
  146. }
  147. //删除视图
  148. public int deleteSysLayou(String FD_OBJECTID){
  149. Connection conn=null;
  150. PreparedStatement ps=null;
  151. try {
  152. conn=DBUtils.getConnection();
  153. conn.setAutoCommit(false);
  154. ps=conn.prepareStatement("delete from ECM_CM_SYSLAYOUT where FD_OBJECTID=?");
  155. ps.setString(1, FD_OBJECTID);
  156. ps.executeUpdate();
  157. ps=conn.prepareStatement("delete from NWYJ.ECM_CM_OPENLAYERMATIC where OL_AREAID=?");
  158. ps.setString(1, FD_OBJECTID);
  159. ps.executeUpdate();
  160. conn.commit();
  161. return 1;
  162. } catch (SQLException e) {
  163. try {
  164. conn.rollback();
  165. } catch (SQLException e1) {
  166. e1.printStackTrace();
  167. }
  168. e.printStackTrace();
  169. return 0;
  170. }finally{
  171. DBUtils.close(null, ps, conn);
  172. }
  173. }
  174. //设置默认视图
  175. public int setDefaultSysLayou(String userId,String FD_OBJECTID){
  176. Connection conn=null;
  177. PreparedStatement ps=null;
  178. try {
  179. conn=DBUtils.getConnection();
  180. conn.setAutoCommit(false);
  181. ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='0' WHERE SL_USERID=? AND SCREEN_STATE='1'");
  182. ps.setString(1, userId);
  183. ps.executeUpdate();
  184. ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='1' WHERE SL_USERID=? AND FD_OBJECTID=?");
  185. ps.setString(1, userId);
  186. ps.setString(2, FD_OBJECTID);
  187. ps.executeUpdate();
  188. conn.commit();
  189. return 1;
  190. } catch (SQLException e) {
  191. try {
  192. conn.rollback();
  193. } catch (SQLException e1) {
  194. e1.printStackTrace();
  195. }
  196. e.printStackTrace();
  197. return 0;
  198. }finally{
  199. DBUtils.close(null, ps, conn);
  200. }
  201. }
  202. @Override
  203. public SysLayout findById(String id) throws SQLException {
  204. log.info(map.get("queryById"));
  205. if(map.get("queryById").toLowerCase()==null&&"".equals(map.get("queryById").trim())) {
  206. throw new SQLStringException("查询语句异常");};
  207. log.info(id);
  208. if(id.toLowerCase()==null&&"".equals(id)&&"".equals(id.trim())){
  209. throw new SQLStringException("查询参数异常");};
  210. return (SysLayout)cmt.query(map.get("queryById"), new CMHandlerResultSet() {
  211. @Override
  212. public Object doHandler(ResultSet rs) throws SQLException {
  213. SysLayout sy=new SysLayout();
  214. while(rs.next()){
  215. sy.setFD_OBJECTID(rs.getString("FD_OBJECTID"));
  216. sy.setIS_DEL(rs.getString("IS_DEL"));
  217. sy.setSL_LAYOUTID(rs.getString("SL_LAYOUTID"));
  218. sy.setSL_NAME(rs.getString("SL_NAME"));
  219. sy.setSL_PARAMENT(rs.getString("SL_PARAMENT"));
  220. sy.setTM_BEX(rs.getString("TM_BEX"));
  221. sy.setSL_USERID(rs.getString("SL_USERID"));
  222. //sy.setUPDATEDATE(rs.getDate("UPDATEDATE"));
  223. }
  224. return sy;
  225. }
  226. }, id);
  227. }
  228. @Override
  229. public List<SysLayout> findAll() throws SQLException {
  230. log.info(map.get("queryAll"));
  231. if(map.get("queryAll").toLowerCase()==null&&"".equals(map.get("update").trim())) {
  232. throw new SQLStringException("查询语句异常");};
  233. return (List<SysLayout>) cmt.query(map.get("queryAll"),new CMHandlerResultSet() {
  234. @Override
  235. public Object doHandler(final ResultSet rs) throws SQLException {
  236. final List<SysLayout> list=new ArrayList();
  237. while(rs.next()){
  238. SysLayout sy=new SysLayout();
  239. sy.setFD_OBJECTID(rs.getString("FD_OBJECTID"));
  240. sy.setIS_DEL(rs.getString("IS_DEL"));
  241. sy.setSL_LAYOUTID(rs.getString("SL_LAYOUTID"));
  242. sy.setSL_NAME(rs.getString("SL_NAME"));
  243. sy.setSL_PARAMENT(rs.getString("SL_PARAMENT"));
  244. sy.setTM_BEX(rs.getString("TM_BEX"));
  245. sy.setSL_USERID(rs.getString("SL_USERID"));
  246. //sy.setUPDATEDATE(rs.getDate("UPDATEDATE"));
  247. list.add(sy);
  248. }
  249. return list;
  250. }
  251. });
  252. }
  253. //Result res=new Result(JsonPluginsUtil.beanListToJson(list), Result.STATE_SUCCESS, 0, listString.size());
  254. /* public static void main(String[] args) {
  255. Logger log1 = Logger.getLogger(SysLayoutDaoImpl.class);
  256. SysLayoutDaoImpl sld=new SysLayoutDaoImpl();
  257. int add=sld.add("1","1","1","1","1","1","1");
  258. Assert.equals(1, add);
  259. int update=sld.update(1,2);
  260. int delete=sld.delete(1);
  261. Assert.equals(1, delete);
  262. SysLayout sl=sld.findById("2");
  263. System.out.println(sl.toJSONString());
  264. List<SysLayout> list=sld.findAll();
  265. System.out.println(JsonPluginsUtil.beanListToJson(list));
  266. //sld.updateName();
  267. }*/
  268. }