c5874f9f98dee2597532736c2b4d4a85f0c34e99.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /***************************************************
  2. * Copyright 2014-7-23, -sinosoft.com.cn All rights reserved.
  3. *【创建日期】 : 2014-7-23
  4. *【创建人】 : 徐杨
  5. *【类名】:SysCustomMenuDaoImpl.java
  6. *【功能】:本类是菜单角色自定义数据层实现类
  7. *【修改日志】
  8. * --------------------------------------------------
  9. * VERSION DATE 修改人 修改内容
  10. * --------------------------------------------------
  11. * 1.0 2014-7-23
  12. * --------------------------------------------------
  13. **************************************************/
  14. package com.sinosoft.lz.system.menu.dao;
  15. import java.sql.Connection;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Date;
  22. import java.util.List;
  23. import org.apache.log4j.Logger;
  24. import com.formaction.Utils;
  25. import com.persistence.DbConnection;
  26. import com.persistence.service.PersistenceFactory;
  27. import com.persistence.service.SysPersistence;
  28. import com.persistence.service.assitant.generator.IdentityGenerator;
  29. import com.persistence.service.exception.PersistenceException;
  30. import com.sinosoft.lz.system.menu.vo.IndexMenu;
  31. import com.sinosoft.lz.system.menu.vo.SysMenu;
  32. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  33. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  34. public class SysCustomMenuDaoImpl implements ISysCustomMenuDao{
  35. private static SysModel sysmodel = ModelFactory.getSysmodel();
  36. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  37. private final static Logger log = Logger.getLogger(SysCustomMenuDaoImpl.class);
  38. /**
  39. * 功能: 查询源菜单数据
  40. *
  41. * @return List
  42. */
  43. @SuppressWarnings("rawtypes")
  44. @Override
  45. public List loadMenuInfo() {
  46. /* String sql = "select code id, parentcode pid, RightName name, "
  47. + " sort sort, Handler handler, RightType type,img img,functionlink functionlink "
  48. + " from Sys_Menu where RightType='1' and is_del='0' order by sort asc ";*/
  49. String sql = "select m.menu_id id, m.parent_menu_id pid, m.menu_name name, "
  50. + " m.sortno sort, m.menu_statu type,m.menu_img img,m.menu_url functionlink "
  51. + " from Sys_Menu m where m.is_del='0' order by m.menu_id asc ";
  52. log.info(sql);
  53. return this.loadInfo(sql);
  54. }
  55. /**
  56. * 功能: 根据角色查询源菜单数据
  57. *
  58. * @param roleid
  59. * 角色编号
  60. * @return List
  61. */
  62. @SuppressWarnings("rawtypes")
  63. @Override
  64. public List loadMenuInfoByRoleId(String roleid) {
  65. /* String sql = " select code id, parentcode pid, RightName name, t1.sort sort, "
  66. + " t1.Handler handler, t1.RightType type, roleid, menuid "
  67. + " from Sys_Menu t1 left join "
  68. + " (select * from SYS_CUSTOM_MENU where roleid='"
  69. + roleid
  70. + "' )t2 "
  71. + " on t1.code = t2.menuid where t1.RightType='1' and t1.is_del='0' order by t1.sort asc ";*/
  72. String roleids = "";
  73. if(roleid != null && !"".equals(roleid)){
  74. String[] ids = roleid.split(",");
  75. for(int i=0;i<ids.length;i++){
  76. roleids += "'"+ids[i]+"',";
  77. }
  78. roleids = roleids.substring(0, roleids.lastIndexOf(","));
  79. }
  80. String sql = " select m.menu_id id, m.parent_menu_id pid, m.menu_name name, m.sortno sort, "
  81. + " m.menu_statu type, r.role_id, m.menu_id "
  82. + " from Sys_Menu m, sys_role_right_rel r "
  83. + " where m.menu_id = r.menu_id and m.is_del='0' "
  84. + " and r.role_id in ("+roleids+")"
  85. + " order by m.menu_id asc ";
  86. return this.loadInfo(sql);
  87. }
  88. /**
  89. * 功能:根据角色查询自定义菜单数据
  90. *
  91. * @param roleid
  92. * 角色编号
  93. * @return List
  94. */
  95. @SuppressWarnings("rawtypes")
  96. @Override
  97. public List loadCustomMenuInfoByRoleId(String roleid) {
  98. StringBuffer sql = new StringBuffer();
  99. /* sql.append("select id, pid, name, roleid, RightName srcname, t1.sort, type, t1.handler,t2.img,t2.functionlink "
  100. + " from "
  101. + " SYS_CUSTOM_MENU t1"
  102. + " left join "
  103. + " Sys_Menu t2"
  104. + " on t1.menuid = t2.code"
  105. + " where roleid = '"
  106. + roleid
  107. + "' and t2.is_del='0' and type='1' order by t1.sort asc");*/
  108. String roleids = "";
  109. if(roleid != null && !"".equals(roleid)){
  110. String[] ids = roleid.split(",");
  111. for(int i=0;i<ids.length;i++){
  112. roleids += "'"+ids[i]+"',";
  113. }
  114. roleids = roleids.substring(0, roleids.lastIndexOf(","));
  115. }
  116. sql.append("select m.menu_id id, m.parent_menu_id pid, menu_name name, r.role_id roleid, m.sortno sort,menu_statu type,m.menu_img img, m.menu_url functionlink "
  117. + " from "
  118. + " Sys_Menu m , "
  119. + " sys_role_right_rel r "
  120. + " where m.menu_id = r.menu_id and r.role_id in ("
  121. + roleids
  122. + ") and m.is_del='0' order by m.menu_id asc");
  123. return this.loadInfo(sql.toString());
  124. }
  125. /**
  126. * 根据角色查询显示的菜单信息
  127. *
  128. * @param roleid
  129. * @param nodeId
  130. * @return
  131. */
  132. @SuppressWarnings("rawtypes")
  133. @Override
  134. public List loadShowMenuInfoByRoleId(String roleid) {
  135. /* String sql = "select id, pid , name text, Target target,"
  136. + " FunctionLink href, Method method, Width width, Height height,"
  137. + " t1.handler hashandler, t1.type, t2.Img img, t1.sort "
  138. + " from SYS_CUSTOM_MENU t1 " + " left join Sys_Menu t2 "
  139. + " on t1.menuid = t2.code" + " where t1.roleid='" + roleid
  140. + "' and t2.is_del='0' order by t1.sort asc";*/
  141. String roleids = "";
  142. if(roleid != null && !"".equals(roleid)){
  143. String[] ids = roleid.split(",");
  144. for(int i=0;i<ids.length;i++){
  145. roleids += "'"+ids[i]+"',";
  146. }
  147. roleids = roleids.substring(0, roleids.lastIndexOf(","));
  148. }
  149. String sql = "select m.menu_id id, m.parent_menu_id pid , m.menu_name text, "
  150. + " m.menu_url href, "
  151. + " m.menu_statu type, m.menu_img img, m.sortno sort "
  152. + " from SYS_MENU m Sys_Role_right_rel r "
  153. + " where m.menu_id = r.menu_id and r.role_id in (" + roleids
  154. + " ) and m.is_del='0' order by m.menu_id asc";
  155. return this.loadInfo(sql);
  156. }
  157. /**
  158. * 功能:根据角色清空自定义菜单表数据
  159. *
  160. * @param roleid
  161. * 角色编号
  162. * @return int 影响的行数
  163. */
  164. @Override
  165. public int clearCustomMenuByRoleId(String roleid) {
  166. String roleids = "";
  167. if(roleid != null && !"".equals(roleid)){
  168. String[] ids = roleid.split(",");
  169. for(int i=0;i<ids.length;i++){
  170. roleids += "'"+ids[i]+"',";
  171. }
  172. roleids = roleids.substring(0, roleids.lastIndexOf(","));
  173. }
  174. String sql = "delete from sys_role_right_rel where role_id in (" + roleids + ")";
  175. int res = 0;
  176. try {
  177. res = persistence.executeUpdateSQL(886, sql);
  178. } catch (PersistenceException e) {
  179. log.error(e.getMessage());
  180. }
  181. return res;
  182. }
  183. /***
  184. * 功能:根据菜单编号级联删除自定义菜单
  185. *
  186. * @param menuid
  187. * @return int 影响条数
  188. */
  189. @Override
  190. public int deleteById(String menuid) {
  191. String sql = "delete from SYS_CUSTOM_MENU where menuid = '" + menuid + "'";
  192. int res = 0;
  193. try {
  194. res = persistence.executeUpdateSQL(892, sql);
  195. } catch (PersistenceException e) {
  196. log.error(e.getMessage());
  197. }
  198. return res;
  199. }
  200. /**
  201. * 查询数据
  202. *
  203. * @param sql
  204. * @return
  205. */
  206. @SuppressWarnings("rawtypes")
  207. private List loadInfo(String sql) {
  208. List list = null;
  209. try {
  210. log.info("sql-- " + sql);
  211. list = persistence.getSearchResultToMap(99, sql);
  212. } catch (PersistenceException e) {
  213. log.error(e.getMessage());
  214. }
  215. return list;
  216. }
  217. public List<SysMenu> getIndexMenu(String menuId,String roleIds){
  218. String[] rids = roleIds.split(",");
  219. String ins = "";
  220. for(int i=0;i<rids.length;i++){
  221. ins += "?,";
  222. }
  223. ins = ins.substring(0, ins.lastIndexOf(","));
  224. StringBuffer sql = new StringBuffer();
  225. // sql.append(" select distinct m.fd_objectid,m.menu_id,m.menu_name,m.menu_url,m.parent_menu_id,m.menu_info,m.sortno,m.menu_statu,m.is_leaf,m.in_control,m.is_del,m.mod_date,m.menu_img ");
  226. // sql.append(" from sys_menu m ");
  227. // sql.append(" inner join sys_role_right_rel r on m.menu_id = r.menu_id and r.role_id in ( "+ins+")");
  228. //
  229. // sql.append(" where CHAR_LENGTH(m.menu_id)>3 ");
  230. // sql.append(" START WITH m.MENU_ID= ? ");
  231. // sql.append(" CONNECT BY PRIOR m.menu_ID=m.PARENT_MENU_ID ");
  232. // sql.append(" order by m.menu_id ");
  233. sql.append(" select distinct m.fd_objectid,m.menu_id,m.menu_name,m.menu_url,m.parent_menu_id,m.menu_info,m.sortno,m.menu_statu,m.is_leaf,m.in_control,m.is_del,m.mod_date,m.menu_img ");
  234. sql.append(" from sys_menu m ");
  235. sql.append(" inner join sys_role_right_rel r on m.menu_id = r.menu_id and r.role_id in ( "+ins+")");
  236. sql.append(" where CHAR_LENGTH(m.menu_id)>3 ");
  237. sql.append(" and left(m.menu_id,1)= ? ");
  238. sql.append(" and m.IS_DEL = '0' ");
  239. sql.append(" order by m.menu_id ");
  240. log.info(sql.toString());
  241. DbConnection dbConn = new DbConnection();
  242. Connection conn = null;
  243. PreparedStatement pstm = null;
  244. ResultSet rs = null;
  245. List<SysMenu> menuList = new ArrayList<SysMenu>();
  246. try{
  247. conn = dbConn.getConnection();
  248. pstm = conn.prepareStatement(sql.toString());
  249. for(int i=0;i<rids.length;i++){
  250. //ins += "?,";
  251. pstm.setString(i+1, rids[i]);
  252. }
  253. pstm.setString(rids.length+1, menuId);
  254. rs = pstm.executeQuery();
  255. while(rs.next()){
  256. SysMenu menu = new SysMenu();
  257. menu.setFd_objectid(rs.getString("fd_objectid"));
  258. menu.setMenu_id(rs.getString("menu_id"));
  259. menu.setMenu_name(rs.getString("menu_name"));
  260. menu.setMenu_url(rs.getString("menu_url"));
  261. menu.setParent_menu_id(rs.getString("parent_menu_id"));
  262. menu.setMenu_info(rs.getString("menu_info"));
  263. menu.setSortno(rs.getString("sortno"));
  264. menu.setMenu_statu(rs.getString("menu_statu"));
  265. menu.setIs_leaf(rs.getString("is_leaf"));
  266. menu.setIn_control(rs.getString("in_control"));
  267. menu.setIs_del(rs.getString("is_del"));
  268. menu.setMod_date(rs.getString("mod_date"));
  269. menu.setMenu_img(rs.getString("menu_img"));
  270. menuList.add(menu);
  271. }
  272. }catch(Exception e){
  273. log.error("查询菜单错误"+e.getMessage());
  274. }finally{
  275. try {
  276. if(rs!=null)
  277. rs.close();
  278. if(pstm!=null)
  279. pstm.close();
  280. if(conn!=null)
  281. conn.close();
  282. } catch (SQLException e) {
  283. log.error("关闭数据库连接错误:"+e.getMessage());
  284. }
  285. }
  286. return menuList;
  287. }
  288. public List<SysMenu> queryIndexMenu(String menuName,String roleIds){
  289. String[] rids = roleIds.split(",");
  290. String ins = "";
  291. for(int i=0;i<rids.length;i++){
  292. ins += "?,";
  293. }
  294. ins = ins.substring(0, ins.lastIndexOf(","));
  295. StringBuffer sql = new StringBuffer();
  296. sql.append(" select distinct c.menu_id,c.menu_name ");
  297. sql.append(" from sys_menu a ");
  298. sql.append(" inner join sys_menu b on a.parent_menu_id = b.menu_id ");
  299. sql.append(" inner join sys_menu c on b.parent_menu_id = c.menu_id ");
  300. sql.append(" inner join sys_role_right_rel r on a.menu_id = r.menu_id and r.role_id in ( "+ins+")");
  301. if(menuName!=null&&!"".equals(menuName)){
  302. sql.append(" where a.menu_name like ? ");
  303. }
  304. sql.append(" order by c.menu_id ");
  305. log.info(sql.toString());
  306. DbConnection dbConn = new DbConnection();
  307. Connection conn = null;
  308. PreparedStatement pstm = null;
  309. ResultSet rs = null;
  310. List<SysMenu> menuList = new ArrayList<SysMenu>();
  311. try{
  312. conn = dbConn.getConnection();
  313. pstm = conn.prepareStatement(sql.toString());
  314. for(int i=0;i<rids.length;i++){
  315. //ins += "?,";
  316. pstm.setString(i+1, rids[i]);
  317. }
  318. pstm.setString(rids.length+1, "%"+menuName+"%");
  319. rs = pstm.executeQuery();
  320. while(rs.next()){
  321. SysMenu menu = new SysMenu();
  322. menu.setMenu_id(rs.getString("menu_id"));
  323. menu.setMenu_name(rs.getString("menu_name"));
  324. menuList.add(menu);
  325. }
  326. }catch(Exception e){
  327. log.error("查询菜单错误"+e.getMessage());
  328. }finally{
  329. try {
  330. if(rs!=null){
  331. rs.close();
  332. }
  333. pstm.close();
  334. conn.close();
  335. } catch (SQLException e) {
  336. log.error("关闭数据库连接错误:"+e.getMessage());
  337. }
  338. }
  339. return menuList;
  340. }
  341. public List<SysMenu> queryIndexSubMenu(String menuName,String roleIds){
  342. String[] rids = roleIds.split(",");
  343. String ins = "";
  344. for(int i=0;i<rids.length;i++){
  345. ins += "?,";
  346. }
  347. ins = ins.substring(0, ins.lastIndexOf(","));
  348. StringBuffer sql = new StringBuffer();
  349. sql.append(" select distinct a.MENU_ID,a.MENU_NAME,a.MENU_URL,a.SORTNO,a.MENU_IMG,c.menu_id as parent_menu_id ");
  350. sql.append(" from sys_menu a ");
  351. sql.append(" inner join sys_menu b on a.parent_menu_id = b.menu_id ");
  352. sql.append(" inner join sys_menu c on b.parent_menu_id = c.menu_id ");
  353. sql.append(" inner join sys_role_right_rel r on a.menu_id = r.menu_id and r.role_id in ( "+ins+")");
  354. if(menuName!=null&&!"".equals(menuName)){
  355. sql.append(" where a.menu_name like ? ");
  356. }
  357. sql.append(" order by a.menu_id ");
  358. log.info(sql.toString());
  359. DbConnection dbConn = new DbConnection();
  360. Connection conn = null;
  361. PreparedStatement pstm = null;
  362. ResultSet rs = null;
  363. List<SysMenu> menuList = new ArrayList<SysMenu>();
  364. try{
  365. conn = dbConn.getConnection();
  366. pstm = conn.prepareStatement(sql.toString());
  367. for(int i=0;i<rids.length;i++){
  368. //ins += "?,";
  369. pstm.setString(i+1, rids[i]);
  370. }
  371. pstm.setString(rids.length+1, "%"+menuName+"%");
  372. rs = pstm.executeQuery();
  373. while(rs.next()){
  374. SysMenu menu = new SysMenu();
  375. menu.setMenu_id(rs.getString("menu_id"));
  376. menu.setMenu_name(rs.getString("menu_name"));
  377. menu.setMenu_url(rs.getString("menu_url"));
  378. menu.setParent_menu_id(rs.getString("parent_menu_id"));
  379. menu.setSortno(rs.getString("sortno"));
  380. menu.setMenu_img(rs.getString("menu_img"));
  381. menuList.add(menu);
  382. }
  383. }catch(Exception e){
  384. log.error("查询菜单错误"+e.getMessage());
  385. }finally{
  386. try {
  387. rs.close();
  388. pstm.close();
  389. conn.close();
  390. } catch (SQLException e) {
  391. log.error("关闭数据库连接错误:"+e.getMessage());
  392. }
  393. }
  394. return menuList;
  395. }
  396. public String addIndexMenu(IndexMenu indexMenu){
  397. String result = "error";
  398. String sql = "INSERT INTO SYS_INDEX_MENU (FD_OBJECTID, IMAGE_URL, TITLE_NAME, BUSINESS_URL, IS_DEL, USER_ID, SORT, STATE, UPDATEDATE, MENU_ID, CLICK_NUM) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  399. DbConnection dbConn = new DbConnection();
  400. Connection conn = null;
  401. PreparedStatement pstm = null;
  402. try {
  403. conn = dbConn.getConnection();
  404. pstm = conn.prepareStatement(sql);
  405. //设置参数值
  406. pstm.setString(1, indexMenu.getFD_OBJECTID());
  407. pstm.setString(2, indexMenu.getIMAGE_URL());
  408. pstm.setString(3, indexMenu.getTITLE_NAME());
  409. pstm.setString(4, indexMenu.getBUSINESS_URL());
  410. pstm.setString(5, indexMenu.getIS_DEL());
  411. pstm.setString(6, indexMenu.getUSER_ID());
  412. pstm.setString(7, indexMenu.getSORT());
  413. pstm.setString(8, indexMenu.getSTATE());
  414. pstm.setString(9, indexMenu.getUPDATEDAE());
  415. pstm.setString(10, indexMenu.getMENU_ID());
  416. pstm.setInt(11, indexMenu.getCLICK_NUM());
  417. int rs = pstm.executeUpdate();
  418. if(rs==1){
  419. result = "ok";
  420. }
  421. } catch (ClassNotFoundException e) {
  422. // TODO Auto-generated catch block
  423. e.printStackTrace();
  424. } catch (SQLException e) {
  425. // TODO Auto-generated catch block
  426. e.printStackTrace();
  427. }finally{
  428. try {
  429. pstm.close();
  430. conn.close();
  431. } catch (SQLException e) {
  432. // TODO Auto-generated catch block
  433. log.error("关闭数据库连接错误:"+e.getMessage());
  434. }
  435. }
  436. return result;
  437. }
  438. public int checkAddMenu(String user_id, String menu_id) {
  439. int result = 0;
  440. String sql = "update SYS_INDEX_MENU set STATE=0,UPDATEDATE=? where USER_ID=? and MENU_ID=?";
  441. DbConnection dbConn = new DbConnection();
  442. Connection conn = null;
  443. PreparedStatement pstm = null;
  444. try {
  445. conn = dbConn.getConnection();
  446. pstm = conn.prepareStatement(sql);
  447. //设置参数值
  448. Date date = new Date();
  449. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  450. pstm.setString(1, sdf.format(date));
  451. pstm.setString(2, user_id);
  452. pstm.setString(3, menu_id);
  453. result = pstm.executeUpdate();
  454. } catch (ClassNotFoundException e) {
  455. // TODO Auto-generated catch block
  456. e.printStackTrace();
  457. } catch (SQLException e) {
  458. // TODO Auto-generated catch block
  459. e.printStackTrace();
  460. }finally{
  461. try {
  462. pstm.close();
  463. conn.close();
  464. } catch (SQLException e) {
  465. // TODO Auto-generated catch block
  466. log.error("关闭数据库连接错误:"+e.getMessage());
  467. }
  468. }
  469. return result;
  470. }
  471. public String deleteAddMenu(String fd_id) {
  472. String result = "error";
  473. String sql = "update SYS_INDEX_MENU set STATE=1 where FD_OBJECTID=?";
  474. DbConnection dbConn = new DbConnection();
  475. Connection conn = null;
  476. PreparedStatement pstm = null;
  477. try {
  478. conn = dbConn.getConnection();
  479. pstm = conn.prepareStatement(sql);
  480. //设置参数值
  481. pstm.setString(1, fd_id);
  482. int i = pstm.executeUpdate();
  483. if(i==1){
  484. result = "success";
  485. }
  486. } catch (ClassNotFoundException e) {
  487. // TODO Auto-generated catch block
  488. e.printStackTrace();
  489. } catch (SQLException e) {
  490. // TODO Auto-generated catch block
  491. e.printStackTrace();
  492. }finally{
  493. try {
  494. pstm.close();
  495. conn.close();
  496. } catch (SQLException e) {
  497. // TODO Auto-generated catch block
  498. log.error("关闭数据库连接错误:"+e.getMessage());
  499. }
  500. }
  501. return result;
  502. }
  503. /**
  504. * 根据user_id查询个人偏好菜单
  505. * @param user_id
  506. * @return
  507. */
  508. public List<IndexMenu> queryIndexMenu(String user_id){
  509. StringBuffer sql = new StringBuffer();
  510. //sql.append(" select FD_OBJECTID,IMAGE_URL,TITLE_NAME,BUSINESS_URL,IS_DEL,USER_ID,SORT,STATE,UPDATEDATE,MENU_ID from SYS_INDEX_MENU where IS_DEL = '0' and STATE = '0' ");
  511. sql.append(" select SIM.FD_OBJECTID,SM.MENU_URL,SM.MENU_ID,SM.MENU_NAME,SM.MENU_IMG from SYS_MENU SM LEFT JOIN SYS_INDEX_MENU SIM ON SM.MENU_ID = SIM.MENU_ID where SM.IS_DEL = '0' AND SIM.STATE = '0' ");
  512. sql.append(" and SIM.user_id = ");
  513. sql.append("'"+user_id+"'");
  514. sql.append(" ORDER BY SIM.CLICK_NUM DESC ");
  515. log.info(sql);
  516. DbConnection dbConn = new DbConnection();
  517. Connection conn = null;
  518. PreparedStatement pstm = null;
  519. ResultSet rs = null;
  520. List<IndexMenu> menuList = new ArrayList<IndexMenu>();
  521. try{
  522. conn = dbConn.getConnection();
  523. pstm = conn.prepareStatement(sql.toString());
  524. rs = pstm.executeQuery();
  525. while(rs.next()){
  526. IndexMenu menu = new IndexMenu();
  527. menu.setFD_OBJECTID(rs.getString("FD_OBJECTID"));
  528. menu.setBUSINESS_URL(rs.getString("MENU_URL"));
  529. menu.setMENU_ID(rs.getString("MENU_ID"));
  530. menu.setTITLE_NAME(rs.getString("MENU_NAME"));
  531. menu.setIMAGE_URL(rs.getString("MENU_IMG"));
  532. menuList.add(menu);
  533. }
  534. }catch(Exception e){
  535. log.error("查询菜单错误"+e.getMessage());
  536. }finally{
  537. try {
  538. rs.close();
  539. pstm.close();
  540. conn.close();
  541. } catch (SQLException e) {
  542. log.error("关闭数据库连接错误:"+e.getMessage());
  543. }
  544. }
  545. return menuList;
  546. }
  547. public String setUserClickNum(String menu_id, String user_id) {
  548. String result = "error";
  549. String sql = "update SYS_INDEX_MENU set CLICK_NUM=CLICK_NUM+1 where MENU_ID=? AND USER_ID=?";
  550. DbConnection dbConn = new DbConnection();
  551. Connection conn = null;
  552. PreparedStatement pstm = null;
  553. try {
  554. conn = dbConn.getConnection();
  555. pstm = conn.prepareStatement(sql);
  556. //设置参数值
  557. pstm.setString(1, menu_id);
  558. pstm.setString(2, user_id);
  559. int i = pstm.executeUpdate();
  560. if(i==1){
  561. result = "success";
  562. }
  563. } catch (ClassNotFoundException e) {
  564. // TODO Auto-generated catch block
  565. e.printStackTrace();
  566. } catch (SQLException e) {
  567. // TODO Auto-generated catch block
  568. e.printStackTrace();
  569. }finally{
  570. try {
  571. pstm.close();
  572. conn.close();
  573. } catch (SQLException e) {
  574. // TODO Auto-generated catch block
  575. log.error("关闭数据库连接错误:"+e.getMessage());
  576. }
  577. }
  578. return result;
  579. }
  580. }