9a55cfaf5ccaa1ca08a1edc0d1e9e09b5e88496e.svn-base 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. package com.sinosoft.cm.matic.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import org.apache.commons.logging.Log;
  7. import org.apache.commons.logging.LogFactory;
  8. import com.sinosoft.cm.DBUtils;
  9. import com.sinosoft.cm.chart.dao.ChartDaoImpl;
  10. import com.sinosoft.cm.common.service.ChartDaoServiceImpl;
  11. import com.sinosoft.cm.common.vo.ResultState;
  12. import com.sinosoft.cm.vo.Result;
  13. public class MaticDaoImpl extends ChartDaoImpl {
  14. private Log log = LogFactory.getLog(ChartDaoServiceImpl.class);
  15. public MaticDaoImpl(){
  16. /**
  17. * 关联查询查询所有视图信息
  18. */
  19. map.put("getMatic", "SELECT A.TM_BEX SORT1, A.AREA_NAME AREA_NAME, B.FD_OBJECTID FD_OBJECTID,B.TM_NAME TM_NAME,B."
  20. + "TM_URL TM_URL,B.TM_IMGURL TM_IMGURL,B.TM_LAYERID TM_LAYERID,B.TM_USE TM_USE,"
  21. + "B.TM_AREAID TM_AREAID,B.IS_DEL IS_DEL, B.UPDATEDATE UPDATEDATE ,B.TM_BEX TM_BEX,"
  22. + "B.SC_DEPT_ID SC_DEPT_ID, B.IS_SYNTHESIZE "
  23. + " FROM ECM_CM_MATICMAP A LEFT JOIN ECM_CM_THEMATIC B "
  24. + " ON B.TM_USE=1 AND A.AREA_ID=B.TM_AREAID AND A.IS_USED='0' AND A.IS_DEL ='0' AND B.IS_DEL = '0'"
  25. + " AND (SC_DEPT_ID='' OR SC_DEPT_ID IS NULL OR SC_DEPT_ID=?) ORDER BY to_number(A.TM_BEX),B.TM_NAME;");
  26. /**
  27. * 模糊查询查询
  28. */
  29. map.put("getLikeMatic", "SELECT A.AREA_NAME AREA_NAME, B.FD_OBJECTID FD_OBJECTID,B.TM_NAME TM_NAME,B."
  30. + "TM_URL TM_URL,B.TM_IMGURL TM_IMGURL,B.TM_LAYERID TM_LAYERID,B.TM_USE TM_USE,"
  31. + "B.TM_AREAID TM_AREAID,B.IS_DEL IS_DEL, B.UPDATEDATE UPDATEDATE ,B.TM_BEX TM_BEX,"
  32. + "B.SC_DEPT_ID SC_DEPT_ID "
  33. + " FROM ECM_CM_MATICMAP A,ECM_CM_THEMATIC B "
  34. + " WHERE B.TM_USE=1 AND A.AREA_ID=B.TM_AREAID AND A.IS_USED='0' AND A.IS_DEL ='0' "
  35. + " AND (SC_DEPT_ID='' OR SC_DEPT_ID IS NULL OR SC_DEPT_ID=?) AND B.TM_NAME LIKE ? ORDER BY A.AREA_NAME,B.TM_NAME;");
  36. /**
  37. * 获取默认布局
  38. */
  39. map.put("getOftenDefaultLayoutAndView", "SELECT IS_COMMONUSE FROM ECM_CM_SYSLAYOUT WHERE (IS_COMMONUSE IS NOT NULL OR IS_COMMONUSE <> '') AND SL_USERID=? AND SCREEN_STATE=?;");
  40. /**
  41. * 查询布局视图
  42. */
  43. map.put("queryLayoutById", "select FD_OBJECTID,IS_DEL,SL_LAYOUTID,SL_NAME,SL_PARAMENT,TM_BEX,SL_USERID,SCREEN_STATE from ECM_CM_SYSLAYOUT where FD_OBJECTID=?");
  44. /**
  45. * 查询视图
  46. */
  47. this.map.put("queryViewByAreaId", "SELECT OL_CONID,OL_MATICID FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?");
  48. /**
  49. * 查询布局列表
  50. * ? 屏幕状态
  51. * ? 用户ID
  52. */
  53. map.put("getLayout", "SELECT * FROM ECM_CM_SYSLAYOUT WHERE SCREEN_STATE=? AND (SL_USERID='R002105430214' OR SL_USERID=?) AND IS_DEL='0';");
  54. /**
  55. * 通过布局ID查询相关布局信息
  56. */
  57. map.put("getMaticView", "SELECT * FROM LAYOUT_MATIC_VIEW WHERE OL_AREAID=?;");
  58. /**
  59. * 获取默认布局
  60. */
  61. map.put("getDefaultLayout","SELECT * FROM ECM_CM_SYSLAYOUT WHERE TM_BEX='1'"
  62. + " AND SCREEN_STATE=? AND (SL_USERID=? OR SL_USERID='R002105430214')");
  63. /**
  64. * 获取默认布局的信息
  65. */
  66. map.put("getDefaultLayoutView","SELECT * FROM LAYOUT_MATIC_VIEW WHERE OL_AREAID =?;");
  67. /**
  68. * 保存默认的自定义样式
  69. * ?主键id
  70. * ?样式名称
  71. * ?样式
  72. *
  73. */
  74. map.put("saveDefalutStyle","insert into ECM_CM_USER_SELF_STYLE"
  75. + "(FD_OBJECTID, STYLE_NAME, STYLE, IS_DEL, UPDATE_DATE)"
  76. + " VALUES(?,?,?,'0',SYSDATE())");
  77. /**
  78. * 修改默认的样式
  79. * ?样式
  80. * ?样式默认样式的id
  81. */
  82. map.put("updateStyleOfDefalutStyle", "UPDATE ECM_CM_USER_SELF_STYLE SET STYLE=?,UPDATE_DATE=SYSDATE() WHERE FD_OBJECTID=?;");
  83. /**
  84. * 查询默认的样式
  85. */
  86. map.put("searchDefaultStyleByUserId", "SELECT * FROM ECM_CM_USER_SELF_STYLE WHERE STYLE_NAME=?;");
  87. }
  88. public int update(String sqlName,Object...args) throws SQLException{
  89. String sql=null;
  90. int state=-1;
  91. sql=map.get(sqlName);
  92. if(sql.toUpperCase()=="NULL"&&"".equals(sql.trim())) throw new SQLException("sql语句不合法--->"+sql);
  93. state = cmt.update(sql, args);
  94. return state;
  95. }
  96. /**
  97. * 保存视图
  98. * @param name
  99. * @param params
  100. * @param userId
  101. * @param conId
  102. * @param maticId
  103. * @param setOften
  104. * @param screenState
  105. * @return
  106. */
  107. public String saveLayoutAndView(String name,String params,String userId,String[] conId,String[] maticId,String setOften,String screenState){
  108. String saveLayoutStr="insert into NWYJ.ECM_CM_SYSLAYOUT"
  109. + "( FD_OBJECTID, SL_NAME, SL_PARAMENT, SL_USERID, IS_DEL, UPDATEDATE, TM_BEX,IS_COMMONUSE,SCREEN_STATE) "
  110. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0, SYSDATE(), 0,?,?)";
  111. String LayoutStr="SELECT FD_OBJECTID,UPDATEDATE,SL_NAME FROM NWYJ.ECM_CM_SYSLAYOUT "
  112. + " WHERE UPDATEDATE=(SELECT MAX(UPDATEDATE) "
  113. + " FROM NWYJ.ECM_CM_SYSLAYOUT WHERE SL_USERID= ? AND SCREEN_STATE=?)";
  114. String saveOpenMatic="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) "
  115. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)";
  116. String result=null;
  117. Connection conn=null;
  118. PreparedStatement ps=null;
  119. ResultSet rs=null;
  120. int flag=0;
  121. try {
  122. conn=DBUtils.getConnection();
  123. /* conn.setAutoCommit(false);*/
  124. //保存视图
  125. log.info("===saveLayou()===sql==="+saveLayoutStr);
  126. ps=conn.prepareStatement(saveLayoutStr);
  127. ps.setString(1, name);
  128. if(params==null || params.toLowerCase().trim().equals("null")){
  129. ps.setString(2, "");
  130. }else{
  131. ps.setString(2, params);
  132. }
  133. ps.setString(3, userId);
  134. ps.setString(4, setOften);
  135. ps.setString(5, screenState);
  136. ps.executeUpdate();
  137. //获取保存视图后的主键id
  138. log.info("===saveLayou()===sql==="+LayoutStr);
  139. ps=conn.prepareStatement(LayoutStr);
  140. ps.setString(1, userId);
  141. ps.setString(2, screenState);
  142. rs=ps.executeQuery();
  143. //System.out.println(flag);
  144. //保存各个容器的专题图
  145. System.out.println("conId.length"+conId.length);
  146. String objectId=null;
  147. String viewName=null;
  148. while(rs.next()){
  149. objectId= rs.getString("FD_OBJECTID");
  150. viewName=rs.getString("SL_NAME");
  151. System.out.println("objectId="+objectId+";viewName="+viewName);
  152. }
  153. for(int count=0;count<conId.length;count++){
  154. log.info("===saveLayou()===sql==="+saveOpenMatic);
  155. ps=conn.prepareStatement(saveOpenMatic);
  156. ps.setString(1, conId[count]);
  157. ps.setString(2, objectId);
  158. ps.setString(3,maticId[count]);
  159. ps.setString(4, viewName);
  160. ps.executeUpdate();
  161. }
  162. /*conn.commit();*/
  163. result=ResultState.SUCCESS;
  164. } catch (Exception e) {
  165. e.printStackTrace();
  166. conn.rollback();
  167. log.error(e.getMessage());
  168. result=ResultState.FAILURE;
  169. }finally{
  170. DBUtils.close(rs, ps, conn);
  171. return result;
  172. }
  173. }
  174. /**
  175. * 删除视图
  176. * @param FD_OBJECTID
  177. * @param SCREEN_STATE
  178. * @return
  179. */
  180. public int deleteLayoutAndView(String FD_OBJECTID,String SCREEN_STATE){
  181. Connection conn=null;
  182. PreparedStatement ps=null;
  183. try {
  184. conn=DBUtils.getConnection();
  185. conn.setAutoCommit(false);
  186. ps=conn.prepareStatement("delete from ECM_CM_SYSLAYOUT where FD_OBJECTID=? AND SCREEN_STATE = ?");
  187. ps.setString(1, FD_OBJECTID);
  188. ps.setString(2, SCREEN_STATE);
  189. ps.executeUpdate();
  190. ps=conn.prepareStatement("delete from NWYJ.ECM_CM_OPENLAYERMATIC where OL_AREAID=?");
  191. ps.setString(1, FD_OBJECTID);
  192. ps.executeUpdate();
  193. conn.commit();
  194. return 1;
  195. } catch (SQLException e) {
  196. try {
  197. conn.rollback();
  198. } catch (SQLException e1) {
  199. e1.printStackTrace();
  200. }
  201. e.printStackTrace();
  202. return 0;
  203. }finally{
  204. DBUtils.close(null, ps, conn);
  205. }
  206. }
  207. /**
  208. * 设置默认视图
  209. * @param userId
  210. * @param FD_OBJECTID
  211. * @param screenState
  212. * @return
  213. */
  214. public int setDefaultSysLayou(String userId,String FD_OBJECTID,String screenState){
  215. Connection conn=null;
  216. PreparedStatement ps=null;
  217. try {
  218. conn=DBUtils.getConnection();
  219. conn.setAutoCommit(false);
  220. ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='0' WHERE SL_USERID=? AND SCREEN_STATE=?");
  221. ps.setString(1, userId);
  222. ps.setString(2, screenState);
  223. ps.executeUpdate();
  224. ps=conn.prepareStatement("UPDATE ECM_CM_SYSLAYOUT SET TM_BEX='1' WHERE SL_USERID=? AND FD_OBJECTID=? AND SCREEN_STATE=?");
  225. ps.setString(1, userId);
  226. ps.setString(2, FD_OBJECTID);
  227. ps.setString(3, screenState);
  228. ps.executeUpdate();
  229. conn.commit();
  230. return 1;
  231. } catch (SQLException e) {
  232. try {
  233. conn.rollback();
  234. } catch (SQLException e1) {
  235. e1.printStackTrace();
  236. }
  237. e.printStackTrace();
  238. return 0;
  239. }finally{
  240. DBUtils.close(null, ps, conn);
  241. }
  242. }
  243. /**
  244. * 修改视图
  245. * @param name
  246. * @param id
  247. * @param conId
  248. * @param maticId
  249. * @return
  250. */
  251. public String editLayouAndView(String name,String id,String[] conId,String[] maticId){
  252. Connection conn=null;
  253. PreparedStatement ps=null;
  254. String setViewName="update ECM_CM_SYSLAYOUT set SL_NAME=? where FD_OBJECTID=?";
  255. String deleteMatics="DELETE FROM ECM_CM_OPENLAYERMATIC WHERE OL_AREAID=?";
  256. String insertMatics="insert into NWYJ.ECM_CM_OPENLAYERMATIC(FD_OBJECTID, OL_CONID, OL_AREAID, OL_MATICID, IS_DEL, UPDATEDATE, OL_BEX) "
  257. + " VALUES(sq_num.NEXTVAL, ?, ?, ?, 0,SYSDATE(), ?)";
  258. String result=null;
  259. try {
  260. conn=DBUtils.getConnection();
  261. conn.setAutoCommit(false);
  262. //修改视图名称
  263. ps=conn.prepareStatement(setViewName);
  264. ps.setString(1, name);
  265. ps.setString(2, id);
  266. ps.executeUpdate();
  267. ps.close();
  268. //删除视图
  269. ps=conn.prepareStatement(deleteMatics);
  270. ps.setString(1,id);
  271. ps.executeUpdate();
  272. //
  273. for(int i=0;i<conId.length;i++){
  274. ps=conn.prepareStatement(insertMatics);
  275. ps.setString(1, conId[i]);
  276. ps.setString(2, id);
  277. ps.setString(3, maticId[i]);
  278. ps.setString(4, name);
  279. ps.executeUpdate();
  280. }
  281. conn.commit();
  282. result=ResultState.SUCCESS;
  283. } catch (SQLException e) {
  284. conn.rollback();
  285. e.printStackTrace();
  286. result=ResultState.FAILURE;
  287. }finally{
  288. DBUtils.close(null, ps, conn);
  289. return result;
  290. }
  291. }
  292. }