a6755ba2b66bfab663ceceb90ae8f73f9956f284.svn-base 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. package com.sinosoft.lz.system.sms.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import net.sf.json.JSONObject;
  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.exception.PersistenceException;
  14. import com.sinosoft.em.event.dao.EventDaoImpl;
  15. import com.sinosoft.lz.system.sms.vo.SearchPeople;
  16. import com.sinosoft.lz.system.sms.vo.Tree;
  17. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  18. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  19. public class ContactTreeDao {
  20. private static final Logger log = Logger.getLogger(EventDaoImpl.class);
  21. private static SysModel sysmodel = ModelFactory.getSysmodel();
  22. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  23. public List<String[]> getContactPeople(String userId) throws PersistenceException{
  24. String sql = "select contact_tel , contact_user_name from sms_common_user_contact where msg_user_id ='"+userId+"' and is_del='0'";
  25. List<String[]> list=persistence.getSearchResult(779, sql);
  26. if(list.size()>0&&list!=null){
  27. return list;
  28. }else{
  29. return null;
  30. }
  31. }
  32. public String getGroupPeole(String params,String userId) throws ClassNotFoundException{
  33. String rex = "^\\d+$";
  34. String sql2 = "select distinct group_people,group_people_tel from sms_contact_group where user_id=? and is_del=? ";
  35. Tree t = new Tree();
  36. SearchPeople sp = null;
  37. List<Object> fromList = new ArrayList<Object>();
  38. if(params.matches(rex)){
  39. sql2 +=" and group_people_tel like ?";
  40. }else{
  41. if(params.contains("'")){
  42. params = params.replaceAll("'", "");
  43. }
  44. sql2 +=" and (group_people||group_name like ?)";
  45. }
  46. Connection conn = null;
  47. PreparedStatement ps = null;
  48. DbConnection db = new DbConnection();
  49. ResultSet rs = null;
  50. try {
  51. conn = db.getConnection();
  52. ps = conn.prepareStatement(sql2);
  53. ps.setString(1, userId);
  54. ps.setString(2, "0");
  55. ps.setString(3, "%"+params+"%");
  56. rs = ps.executeQuery();
  57. while(rs.next()){
  58. sp = new SearchPeople();
  59. sp.setValue(rs.getString("group_people_tel"));
  60. sp.setKey(rs.getString("group_people"));
  61. fromList.add(sp);
  62. }
  63. } catch (SQLException e) {
  64. log.info(e.getMessage(),e);
  65. }finally{
  66. try {
  67. if(rs!=null){
  68. rs.close();
  69. }
  70. if(ps!=null){
  71. ps.close();
  72. }
  73. if(conn!=null){
  74. conn.close();
  75. }
  76. } catch (SQLException e) {
  77. e.printStackTrace();
  78. }
  79. }
  80. log.info(sql2+"============getContactPeole.sql2");
  81. /*List<String[]> list2 = persistence.getSearchResult(781, sql2);
  82. if(list2!=null&&list2.size()>0){
  83. for(String[] s:list2){
  84. }
  85. }*/
  86. t.setTreeNodes(fromList);
  87. log.info(JSONObject.fromObject(t).toString()+"===================JSONObject.fromObject(tree).toString()");
  88. return JSONObject.fromObject(t).toString();
  89. }
  90. public String ContactPeoples (String params,String userId) throws ClassNotFoundException{
  91. String rex = "^\\d+$";
  92. String sql = "select contact_user_name ,contact_tel from sms_common_user_contact where msg_user_id =? and is_del=?";
  93. Tree t = new Tree();
  94. SearchPeople sp = null;
  95. List<Object> fromList = new ArrayList<Object>();
  96. if(params.matches(rex)){
  97. sql += " and contact_tel like ?";
  98. }else {
  99. if(params.contains("'")){
  100. params = params.replaceAll("'", "");
  101. }
  102. sql += " and contact_user_name like ?";
  103. }
  104. Connection conn = null;
  105. PreparedStatement ps = null;
  106. ResultSet rs = null;
  107. DbConnection db = new DbConnection();
  108. try {
  109. conn = db.getConnection();
  110. ps = conn.prepareStatement(sql);
  111. ps.setString(1, userId);
  112. ps.setString(2, "0");
  113. ps.setString(3, "%"+params+"%");
  114. rs = ps.executeQuery();
  115. while(rs.next()){
  116. sp = new SearchPeople();
  117. sp.setKey(rs.getString("contact_user_name"));
  118. sp.setValue(rs.getString("contact_tel"));
  119. fromList.add(sp);
  120. }
  121. } catch (SQLException e) {
  122. log.error(e.getMessage(),e);
  123. }finally{
  124. try {
  125. if(rs!=null){
  126. rs.close();
  127. }
  128. if(ps!=null){
  129. ps.close();
  130. }
  131. if(conn!=null){
  132. conn.close();
  133. }
  134. } catch (SQLException e) {
  135. e.printStackTrace();
  136. }
  137. }
  138. log.info("sql====================================peoples"+sql);
  139. //List<String[]> list = persistence.getSearchResult(779, sql);
  140. /*if(list!=null&&list.size()>0){
  141. for(String[] s:list){
  142. }
  143. }*/
  144. t.setTreeNodes(fromList);
  145. log.info(JSONObject.fromObject(t).toString()+"===================JSONObject.fromObject(tree).toString()");
  146. return JSONObject.fromObject(t).toString();
  147. }
  148. public String getSearchPeople(String params,String userId,String tel,int pageSize,int page) throws PersistenceException{
  149. String rex = "^\\d+$";
  150. // String sql ="select a.user_id,a.dept_id,b.real_name,b.mobile from sys_dept_user a,sys_user_info b where a.dept_id='"+dept_id+"' and a.user_id=b.user_id and b.mobile is not null";
  151. String sql = "select a.real_name,a.mobile from sys_user_info a , sys_department c where a.dept_id = c.dept_id and (a.mobile is not null or a.mobile <> '')";
  152. String sql1 = "select contact_user_name real_name ,contact_tel mobile from sms_common_user_contact where msg_user_id='"+userId+"'";
  153. String sql3 = "select group_people real_name , group_people_tel mobile from sms_contact_group where user_id='"+userId+"'";
  154. String sql6 = "select name real_name,telphone mobile from SYS_MSG_USER where COMPETENCY is not null and is_del='0'";
  155. List<Object> list = new ArrayList<Object>();
  156. Tree t = new Tree();
  157. SearchPeople sp = null;
  158. if(params.matches(rex)){
  159. sql += " and a.mobile like '%"+params+"%'";
  160. sql1 +=" and contact_tel like'%"+params+"%'";
  161. sql3 +=" and group_people_tel like '%"+params+"%'";
  162. sql6 +=" and telphone like '%"+params+"%'";
  163. }else{
  164. if(params.contains("'")){
  165. params = params.replaceAll("'", "");
  166. }
  167. sql += " and a.real_name like '%"+params+"%'";
  168. sql1 += " and contact_user_name like '%"+params+"%'";
  169. sql3 +=" and group_people like '%"+params+"%'";
  170. sql6 +=" and name like '%"+params+"%'";
  171. }
  172. log.info(tel+"===============tel");
  173. if(!"".equals(tel)){
  174. tel = tel.substring(0,tel.lastIndexOf(","));
  175. tel = "("+tel+")";
  176. sql += " and a.mobile not in"+tel;
  177. sql1 += " and contact_tel not in"+tel;
  178. sql3 += " and group_people_tel not in"+tel;
  179. sql6 += " and telphone not in"+tel;
  180. }
  181. String sql4 = "select distinct top "+(page-1)*pageSize+","+pageSize+" a.* from ("+sql +" union "+sql1+" union "+sql3+" union "+sql6+") a order by a.mobile";
  182. String sql5 = "select count(*) from ("+sql+" union "+sql1+" union "+sql3+")";
  183. log.info(sql4+"====================sql4");
  184. List<String[]> list1 = persistence.getSearchResult(99, sql4);
  185. List<String[]> list2 = persistence.getSearchResult(99, sql5);
  186. for(String[] s:list1){
  187. sp = new SearchPeople();
  188. sp.setKey(s[0]);
  189. sp.setValue(s[1]);
  190. list.add(sp);
  191. }
  192. String totalRows = list2.get(0)[0];
  193. t.setTreeNodes(list);
  194. t.setTotalRows(totalRows);
  195. return JSONObject.fromObject(t).toString();
  196. }
  197. public String getSearchPeoples(String params,String userId,String tel,int page,int pageSize) throws PersistenceException{
  198. String rex = "^\\d+$";
  199. String sql = "select distinct top "+(page-1)*pageSize+","+pageSize+" a.real_name,a.mobile, c.dept_name , c.corp_name from sys_user_info a , sys_department c where a.dept_id = c.dept_id and a.mobile is not null ";
  200. String sql2 = "select a.real_name,a.mobile, c.dept_name , c.corp_name from sys_user_info a , sys_department c where a.dept_id = c.dept_id and a.mobile is not null ";
  201. List<Object> list = new ArrayList<Object>();
  202. Tree t = new Tree();
  203. SearchPeople sp = null;
  204. if(params.matches(rex)){
  205. sql += " and a.mobile like '%"+params+"%'";
  206. sql2 += " and a.mobile like '%"+params+"%'";
  207. }else{
  208. if(params.contains("'")){
  209. params = params.replaceAll("'", "");
  210. }
  211. sql += " and a.real_name like '%"+params+"%'";
  212. sql2 +=" and a.real_name like '%"+params+"%'";
  213. }
  214. log.info(tel+"===============tel");
  215. if(!"".equals(tel)){
  216. tel = tel.substring(0,tel.lastIndexOf(","));
  217. tel = "("+tel+")";
  218. sql += " and a.mobile not in"+tel;
  219. sql2 +=" and a.mobile not in"+tel;
  220. }
  221. sql +=" order by a.mobile";
  222. log.info(sql+"====================getSearchPeoples");
  223. String sql3 = "select count(*) from ("+sql2+")";
  224. List<String[]> list1 = persistence.getSearchResult(99, sql);
  225. List<String[]> list2 = persistence.getSearchResult(99, sql3);
  226. String totalRows = list2.get(0)[0];
  227. for(String[] s:list1){
  228. sp = new SearchPeople();
  229. sp.setKey(s[0]);
  230. sp.setValue(s[1]);
  231. sp.setCorpName(s[3]);
  232. sp.setDeptName(s[2]);
  233. list.add(sp);
  234. }
  235. t.setTreeNodes(list);
  236. t.setTotalRows(totalRows);
  237. return JSONObject.fromObject(t).toString();
  238. }
  239. public List<String[]> getContactGroupPeople(String userId) throws PersistenceException{
  240. String sql = "select group_name ,group_people,group_people_tel,fd_objectid from sms_contact_group where user_id ='"+userId+"' and is_del='0'";
  241. List<String[]> list=persistence.getSearchResult(781, sql);
  242. log.info(list+"==============getContactGroupPeople.list");
  243. if(list.size()>0&&list!=null){
  244. return list;
  245. }else{
  246. return null;
  247. }
  248. }
  249. /*public List<String[]> getPeoplebyTel(String[] tel,String userId){
  250. String sql = "select contact_tel ,contact_user_name from sms_common_user_contact where msg_user_id =_'"+userId+"' and is_del='0'";
  251. String sql2 = "select group_name ,group_people,group_people_tel,fd_objectid from sms_contact_group where user_id ='"+userId+"' and is_del='0'";
  252. for(int i=0;i<tel.length;i++){
  253. String arr = tel[i];
  254. }
  255. return null;
  256. }*/
  257. public List<String[]> getContactGroupPeoples(String userId) throws PersistenceException{
  258. String sql = "select group_name ,group_people,group_people_tel,fd_objectid from sms_contact_group where user_id ='"+userId+"' and is_del='0' ";
  259. List<String[]> list=persistence.getSearchResult(779, sql);
  260. if(list.size()>0&&list!=null){
  261. return list;
  262. }else{
  263. return null;
  264. }
  265. }
  266. }