1266bf1e33f4ca0b18337eeb623eb253628747b2.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import net.sf.json.JSONObject;
  11. import org.apache.log4j.Logger;
  12. import com.persistence.DbConnection;
  13. import com.sinosoft.lz.system.sms.vo.Json;
  14. import com.sinosoft.lz.system.sms.vo.JsonVo;
  15. public class JsonDao {
  16. private Logger log = Logger.getLogger(this.getClass());
  17. public String getMsgType(String userId,String deptId) throws ClassNotFoundException{
  18. String sql = "select distinct msg_type from sys_msg_manage where is_del=? and ((send_user_tel = ?) or (rec_user_tel in (select mobile from sys_user_info g, sys_dept_user h ,sys_department k where g.USER_ID=h.USER_ID and h.dept_id=k.dept_id and k.dept_id=?)))";
  19. Connection conn = null;
  20. PreparedStatement ps = null;
  21. ResultSet rs = null;
  22. DbConnection db = new DbConnection();
  23. JsonVo json = null;
  24. Json js = new Json();
  25. List<Object> list1 = new ArrayList<Object>();
  26. try {
  27. conn = db.getConnection();
  28. ps = conn.prepareStatement(sql);
  29. ps.setString(1, "0");
  30. ps.setString(2, userId);
  31. ps.setString(3, deptId);
  32. rs = ps.executeQuery();
  33. json = new JsonVo();
  34. json.setKey("全部");
  35. json.setValue("0000");
  36. list1.add(json);
  37. while (rs.next()){
  38. json = new JsonVo();
  39. json.setKey(rs.getString("MSG_TYPE"));
  40. json.setValue(rs.getString("MSG_TYPE"));
  41. list1.add(json);
  42. }
  43. js.setName("短信类型");
  44. js.setClassName("MSG_TYPE");
  45. js.setList(list1);
  46. }
  47. catch (SQLException e) {
  48. log.error(e.getMessage(), e);
  49. }finally{
  50. db.close(rs);
  51. db.close(ps);
  52. db.close(conn);
  53. }
  54. log.info(JSONObject.fromObject(js).toString());
  55. return JSONObject.fromObject(js).toString();
  56. }
  57. public String getContactInfo(String userId) throws ClassNotFoundException{
  58. String sql = "select distinct contact_dept , contact_comp from sms_common_user_contact where msg_user_id = ? and is_del=?";
  59. Connection conn = null;
  60. PreparedStatement ps = null;
  61. ResultSet rs = null;
  62. JsonVo json = null;
  63. JsonVo json2 = null;
  64. Json js = new Json();
  65. Json js2 = new Json();
  66. DbConnection db = new DbConnection();
  67. List<Object> list1 = new ArrayList<Object>();
  68. List<Object> list2 = new ArrayList<Object>();
  69. Map<String,String> map = new HashMap<String,String>();
  70. Map<String,String> map1 = new HashMap<String,String>();
  71. try {
  72. conn = db.getConnection();
  73. ps = conn.prepareStatement(sql);
  74. ps.setString(1, userId);
  75. ps.setString(2, "0");
  76. rs = ps.executeQuery();
  77. json = new JsonVo();
  78. json.setKey("全部");
  79. json.setValue("0000");
  80. list1.add(json);
  81. json2 = new JsonVo();
  82. json2.setKey("全部");
  83. json2.setValue("0000");
  84. list2.add(json2);
  85. while(rs.next()){
  86. if(!"".equals(rs.getString("contact_dept"))&&rs.getString("contact_dept")!=null&&map.get(rs.getString("contact_dept"))==null){
  87. json = new JsonVo();
  88. json.setKey(rs.getString("contact_dept"));
  89. json.setValue(rs.getString("contact_dept"));
  90. list1.add(json);
  91. map.put(rs.getString("contact_dept"), rs.getString("contact_dept"));
  92. }
  93. if(!"".equals(rs.getString("contact_comp"))&&rs.getString("contact_comp")!=null&&map1.get(rs.getString("contact_comp"))==null){
  94. json2 = new JsonVo();
  95. json2.setKey(rs.getString("contact_comp"));
  96. json2.setValue(rs.getString("contact_comp"));
  97. list2.add(json2);
  98. map1.put(rs.getString("contact_comp"), rs.getString("contact_comp"));
  99. }
  100. }
  101. js.setName("联系人部门");
  102. js.setClassName("CONTACT_DEPT");
  103. js.setList(list1);
  104. js2.setName("联系人公司");
  105. js2.setClassName("CONTACT_COMP");
  106. js2.setList(list2);
  107. } catch (SQLException e) {
  108. log.error(e.getMessage(), e);
  109. }finally{
  110. db.close(rs);
  111. db.close(ps);
  112. db.close(conn);
  113. }
  114. return JSONObject.fromObject(js).toString()+"__"+JSONObject.fromObject(js2).toString();
  115. }
  116. public String getContactGroupComp(String userId) throws ClassNotFoundException{
  117. String sql = "select distinct group_people_comp from sms_contact_group where user_id = ? and is_del=? " ;
  118. Connection conn = null;
  119. PreparedStatement ps = null;
  120. ResultSet rs = null;
  121. DbConnection db = new DbConnection();
  122. JsonVo json = null;
  123. Json js = new Json();
  124. List<Object> list = new ArrayList<Object>();
  125. try {
  126. conn = db.getConnection();
  127. ps = conn.prepareStatement(sql);
  128. ps.setString(1, userId);
  129. ps.setString(2, "0");
  130. rs = ps.executeQuery();
  131. json = new JsonVo();
  132. json.setKey("全部");
  133. json.setValue("0000");
  134. list.add(json);
  135. while(rs.next()){
  136. json = new JsonVo();
  137. json.setKey(rs.getString("group_people_comp"));
  138. json.setValue(rs.getString("group_people_comp"));
  139. list.add(json);
  140. }
  141. } catch (SQLException e) {
  142. log.error(e.getMessage(), e);
  143. }finally{
  144. db.close(rs);
  145. db.close(ps);
  146. db.close(conn);
  147. }
  148. js.setName("联系组人员公司");
  149. js.setClassName("GROUP_PEOPLE_COMP");
  150. js.setList(list);
  151. return JSONObject.fromObject(js).toString();
  152. }
  153. }