7b2bfa1f1c95e675097ec1cfec1cbcd49b461868.svn-base 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. package com.sinosoft.lz.system.userFriend.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.text.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import net.sf.json.JSONArray;
  14. import org.apache.log4j.Logger;
  15. import com.formaction.Parameter;
  16. import com.formaction.vo.Msg;
  17. import com.persistence.DbConnection;
  18. import com.persistence.service.PersistenceFactory;
  19. import com.persistence.service.SysPersistence;
  20. import com.persistence.service.assitant.generator.IdentityGenerator;
  21. import com.persistence.service.exception.PersistenceException;
  22. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  23. import com.sinosoft.common.excel.JsonPluginsUtil;
  24. import com.sinosoft.em.baobiao.xianlutingyun.dao.BaoBiaoDao;
  25. import com.sinosoft.lz.system.userFriend.vo.MsgInfo;
  26. import com.sinosoft.lz.system.userFriend.vo.Person;
  27. import com.sinosoft.lz.system.userFriend.vo.PlanBean;
  28. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  29. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  30. import com.system.push.MessagePush;
  31. public class SendMsgDao {
  32. private Logger log = Logger.getLogger(SendMsgDao.class);
  33. /**
  34. * 保存消息都数据库
  35. * @param mg
  36. * @return
  37. * @throws ClassNotFoundException
  38. */
  39. public Msg saveMsg(MsgInfo mg) throws ClassNotFoundException {
  40. Msg m=new Msg();
  41. String msg = mg.getSendMsg();
  42. String user = mg.getSendUser();
  43. List<String> recid = mg.getRecivedUser();
  44. Connection conn = null;
  45. PreparedStatement st = null;
  46. DbConnection db = new DbConnection();
  47. // log.info("recid.size===="+recid.size());
  48. try {
  49. String sql = "INSERT INTO SYS_USER_MSG(FD_OBJECTID,MSG_SEND_TIME,MSG_CONTENT,SEND_USER_ID,RECEIVE_USER_ID,MSG_STATUS,SEND_DELETE_STAT,RECIVED_DELETE_STAT,read_stat) VALUES(?,?,?,?,?,?,?,?,?)";
  50. conn = db.getConnection();
  51. int num=0;
  52. conn.setAutoCommit(false);
  53. st = conn.prepareStatement(sql);
  54. for(int i=0;i<recid.size();i++){
  55. st.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(99));
  56. // log.info("createMsgId(getMsgId())==="+createMsgId(getMsgId()));
  57. st.setString(2, formatDate(new Date()));
  58. // log.info("formatDate(new Date())==="+formatDate(new Date()));
  59. st.setString(3, msg);
  60. // log.info("msg===="+msg);
  61. st.setString(4, user);
  62. // log.info("user"+user);
  63. st.setString(5, recid.get(i));
  64. // log.info("recid.get(0)"+recid.get(0));
  65. st.setString(6, "0");
  66. st.setString(7, "0");
  67. st.setString(8, "0");
  68. st.setString(9, "0");
  69. st.executeUpdate();
  70. num++;
  71. // if(!"".equals(mg.getFlag())&&mg.getFlag().equals("1")){
  72. // }else{
  73. //if("1".equals(mg.getFlag())){
  74. String user_ids=recid.get(i);
  75. log.info(user_ids+"==========user_ids");
  76. MessagePush.showMsg(null,user_ids,"<a href=\"javascript:void(0)\" onclick=\"openZ('/nwyj/page/system/message/recivedListMsg.jsp')\">"+msg+"</a>","sendMessage");
  77. //}
  78. // }
  79. }
  80. // log.info("num====="+num);
  81. if(num==recid.size()){
  82. log.info("保存成功");
  83. conn.commit();
  84. m.setSucsess(new Boolean(true).toString());
  85. m.setInfo(Parameter.DELETE_SUCSESS);
  86. return m;
  87. }else{
  88. m.setSucsess(new Boolean(false).toString());
  89. m.setInfo(Parameter.DELETE_FAILURE);
  90. // st.executeBatch();
  91. conn.rollback();
  92. log.info("保存失败");
  93. return m;}
  94. } catch (SQLException e) {
  95. this.log.error(e.getMessage(), e);
  96. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  97. } finally {
  98. db.close(st);
  99. db.close(conn);
  100. }
  101. }
  102. public String formatDate(Date d) {
  103. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  104. String date = sd.format(d);
  105. return date;
  106. }
  107. @SuppressWarnings({ "unchecked", "rawtypes" })
  108. public List<String> getMsgId() throws ClassNotFoundException {
  109. String sql = "SELECT FD_OBJECTID FROM SYS_USER_MSG";
  110. Connection conn = null;
  111. Statement stat = null;
  112. ResultSet rs = null;
  113. DbConnection db = new DbConnection();
  114. try {
  115. conn = db.getConnection();
  116. stat = conn.createStatement();
  117. rs = stat.executeQuery(sql);
  118. List<String> list = new ArrayList();
  119. while (rs.next()) {
  120. list.add(rs.getString("FD_OBJECTID"));
  121. }
  122. return list;
  123. } catch (SQLException e) {
  124. this.log.error(e.getMessage(), e);
  125. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  126. + sql, e);
  127. } finally {
  128. db.close(rs);
  129. db.close(stat);
  130. db.close(conn);
  131. }
  132. }
  133. public String createMsgId(List<String> list) throws ClassNotFoundException{
  134. long l=(long) ((Math.random()+1)*1000000000);
  135. String msgId=l+"";
  136. if(list.contains(msgId)){
  137. return createMsgId(list);
  138. }
  139. else{
  140. // log.info("msgid==="+msgId);
  141. return msgId;
  142. }
  143. }
  144. /**
  145. * 删除消息(将数据库状态更改)
  146. * @param fd_objectid 消息ID
  147. * @param stat 删除标志--SEND删除发件信息/REC删除收件信息
  148. * @throws ClassNotFoundException
  149. */
  150. public Msg deleteMsg(String stat,String fd_objectid) throws ClassNotFoundException{
  151. String sql="";
  152. // log.info("stat==="+stat);
  153. Msg m=new Msg();
  154. String []arr=fd_objectid.split(";");
  155. if("".equals(stat)){
  156. m.setSucsess(new Boolean(false).toString());
  157. m.setInfo(Parameter.DELETE_FAILURE);
  158. return m;
  159. }else if("SEND".equals(stat)){
  160. sql="UPDATE SYS_USER_MSG SET SEND_DELETE_STAT='1' WHERE FD_OBJECTID=?";
  161. }else if("REC".equals(stat)){
  162. sql="UPDATE SYS_USER_MSG SET RECIVED_DELETE_STAT='1' WHERE FD_OBJECTID=?";
  163. }else{
  164. m.setSucsess(new Boolean(false).toString());
  165. m.setInfo(Parameter.DELETE_FAILURE);
  166. return m;
  167. }
  168. log.info(sql);
  169. Connection conn = null;
  170. PreparedStatement st = null;
  171. int num=0;
  172. DbConnection db = new DbConnection();
  173. try {
  174. conn = db.getConnection();
  175. conn.setAutoCommit(false);
  176. st = conn.prepareStatement(sql);
  177. for(int i=0;i<arr.length;i++){
  178. st.setString(1, arr[i]);
  179. st.executeUpdate();
  180. num++;
  181. }
  182. if(num==arr.length){
  183. log.info("删除----num===="+num);
  184. m.setSucsess(new Boolean(true).toString());
  185. m.setInfo(Parameter.DELETE_SUCSESS);
  186. conn.commit();
  187. return m;
  188. }else{
  189. m.setSucsess(new Boolean(false).toString());
  190. m.setInfo(Parameter.DELETE_FAILURE);
  191. conn.rollback();
  192. return m;
  193. }
  194. }catch (SQLException e) {
  195. this.log.error(e.getMessage(), e);
  196. throw new ClassNotFoundException("DAO Layou: 删除消息"
  197. + sql, e);
  198. } finally {
  199. db.close(st);
  200. db.close(conn);
  201. }
  202. }
  203. /**
  204. * 获取接收信息列表
  205. * @param userId
  206. * @return
  207. */
  208. @SuppressWarnings("rawtypes")
  209. public String getRecMsgList(String userId,String name,int page,int pageSize){
  210. // log.info("name==="+name+"====================");
  211. String sql="SELECT top "+(page-1)*pageSize+","+pageSize+" a.FD_OBJECTID,a.MSG_SEND_TIME,SUBSTR(a.MSG_CONTENT,'0','20') MSG_CONTENT,a.SEND_USER_ID,a.RECEIVE_USER_ID,a.MSG_STATUS,a.SEND_DELETE_STAT,B.REAL_NAME,A.READ_STAT FROM SYS_USER_MSG a,SYS_USER_INFO B WHERE RECIVED_DELETE_STAT ='0' AND A.RECEIVE_USER_ID='"+userId+"' AND B.REAL_NAME LIKE '%"+name+"%' AND A.SEND_USER_ID=B.USER_ID ORDER BY A.MSG_SEND_TIME DESC";
  212. log.info(sql+"==================sql111");
  213. String sql2 = "SELECT COUNT(*) FROM ( SELECT a.FD_OBJECTID,a.MSG_SEND_TIME,SUBSTR(a.MSG_CONTENT,'0','20') MSG_CONTENT,a.SEND_USER_ID,a.RECEIVE_USER_ID,a.MSG_STATUS,a.SEND_DELETE_STAT,B.REAL_NAME,A.READ_STAT FROM SYS_USER_MSG a,SYS_USER_INFO B WHERE RECIVED_DELETE_STAT ='0' AND A.RECEIVE_USER_ID=? AND B.REAL_NAME LIKE ? AND A.SEND_USER_ID=B.USER_ID ORDER BY A.MSG_SEND_TIME DESC)";
  214. // String sql1=" AND a.SEND_USER_ID LIKE '%"+userId+"%'";
  215. // sql+=sql1;
  216. // log.info("getRecMsgList.sql==="+sql);
  217. List list = null;
  218. List <Map<String,String>> list2 = null;
  219. try {
  220. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  221. try {
  222. list2 = new ORGTemplate().query(sql2, userId,"%"+name+"%") ;
  223. } catch (SQLException e) {
  224. log.error(e.getMessage(),e);
  225. }
  226. log.info(list2.get(0)+"=================get(0)");
  227. } catch (PersistenceException e) {
  228. log.error(e.getMessage());
  229. }
  230. // log.info("获取已接收消息条数===="+list.size());
  231. String result = "{\"pager.totalRows\":"+list2.get(0).get("COUNT(*)")+",\"pager.pageNo\":"+page+","+"\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  232. // log.info("获取已接收消息条数===="+result);
  233. return result;
  234. }
  235. /**
  236. * 获取接收信息详细内容
  237. * @param userId
  238. * @return
  239. */
  240. @SuppressWarnings("rawtypes")
  241. public String getRecMsgInfo(String userId,String objectId){
  242. String sql="SELECT A.*,B.REAL_NAME,B.MOBILE,B.DEPT_ID,D.DEPT_NAME FROM SYS_USER_MSG A,SYS_USER_INFO B, SYS_DEPARTMENT D WHERE A.SEND_USER_ID=B.USER_ID AND B.DEPT_ID = D.DEPT_ID AND A.FD_OBJECTID='"+objectId+"'";
  243. String sql1="update sys_user_msg set read_stat='1' where fd_objectid='"+objectId+"'";
  244. try {
  245. int num=PersistenceFactory.getInstance( ModelFactory.getSysmodel()).executeUpdateSQL(99, sql1);
  246. } catch (PersistenceException e1) {
  247. e1.printStackTrace();
  248. }
  249. List list = null;
  250. try {
  251. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  252. } catch (PersistenceException e) {
  253. log.error(e.getMessage());
  254. }
  255. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  256. // log.info("获取已接收消息信息==="+result);
  257. return result;
  258. }
  259. /**
  260. * 获取已发送信息列表
  261. * @param userId
  262. * @return
  263. */
  264. @SuppressWarnings("rawtypes")
  265. public String getSendMsgList(String userId,String userName,int page,int pageSize){
  266. // log.info("getSendMsgList.userId===="+userId);
  267. String sql="SELECT top "+(page-1)*pageSize+","+pageSize+" a.FD_OBJECTID,a.MSG_SEND_TIME,SUBSTR(a.MSG_CONTENT,'0','20') MSG_CONTENT,a.SEND_USER_ID,a.RECEIVE_USER_ID,a.MSG_STATUS,a.SEND_DELETE_STAT,B.REAL_NAME FROM SYS_USER_MSG a,SYS_USER_INFO B WHERE SEND_DELETE_STAT ='0' AND A.SEND_USER_ID='"+userId+"' AND B.REAL_NAME LIKE '%"+userName+"%' AND A.RECEIVE_USER_ID=B.USER_ID ORDER BY A.MSG_SEND_TIME DESC";
  268. String sql2 ="SELECT COUNT(*) FROM (SELECT a.FD_OBJECTID,a.MSG_SEND_TIME,SUBSTR(a.MSG_CONTENT,'0','20') MSG_CONTENT,a.SEND_USER_ID,a.RECEIVE_USER_ID,a.MSG_STATUS,a.SEND_DELETE_STAT,B.REAL_NAME FROM SYS_USER_MSG a,SYS_USER_INFO B WHERE SEND_DELETE_STAT ='0' AND A.SEND_USER_ID=? AND B.REAL_NAME LIKE ? AND A.RECEIVE_USER_ID=B.USER_ID ORDER BY A.MSG_SEND_TIME DESC)";
  269. List list = null;
  270. List<Map<String,String>> list2 = null;
  271. try {
  272. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  273. try {
  274. list2 = new ORGTemplate().query(sql2, userId,"%"+userName+"%");
  275. } catch (SQLException e) {
  276. log.error(e.getMessage(),e);
  277. }
  278. } catch (PersistenceException e) {
  279. log.error(e.getMessage());
  280. }
  281. log.info("获取已发送信息条数===="+list.size());
  282. String result = "{\"pager.totalRows\":"+list2.get(0).get("COUNT(*)")+",\"pager.pageNo\":"+page+","+"\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  283. return result;
  284. }
  285. /**
  286. * 获取已发送息详细内容
  287. * @param userId
  288. * @return
  289. */
  290. @SuppressWarnings("rawtypes")
  291. public String getSendMsgInfo(String userId,String objectId){
  292. String sql="SELECT A.*,B.REAL_NAME,B.MOBILE,B.DEPT_ID,D.DEPT_NAME FROM SYS_USER_MSG A,SYS_USER_INFO B,SYS_DEPARTMENT D WHERE A.RECEIVE_USER_ID=B.USER_ID AND B.DEPT_ID = D.DEPT_ID AND A.FD_OBJECTID='"+objectId+"'";
  293. List list = null;
  294. try {
  295. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  296. } catch (PersistenceException e) {
  297. log.error(e.getMessage());
  298. }
  299. // log.info(sql);
  300. // log.info("获取已发送信息==="+list.size());
  301. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  302. // log.info("获取已发送信息==="+result);
  303. return result;
  304. }
  305. /**
  306. * 增加用户最近联系人
  307. * @param userId 用户ID
  308. * @param frId 需要增加在联系人id串,格式(id;id;id)
  309. * @return
  310. * @throws ClassNotFoundException
  311. */
  312. public boolean addRecentUser(String userId,String frId) throws ClassNotFoundException{
  313. List<String>list=new ArrayList<String>();
  314. String[]arr=frId.split(";");
  315. for(int i=0;i<arr.length;i++){
  316. list.add(arr[i]);
  317. }
  318. Connection conn = null;
  319. PreparedStatement st = null;
  320. DbConnection db = new DbConnection();
  321. try {
  322. String sql="MERGE INTO SYS_USER_CONTACTS A USING(SELECT ? a,? b,? c,? d from dual) S ON(A.USER_ID=S.B AND A.USER_CONTACT_ID=S.C) WHEN MATCHED THEN UPDATE SET A.LAST_CONTACTTIME=S.D WHEN NOT MATCHED THEN INSERT(FD_OBJECTID,USER_ID,USER_CONTACT_ID,LAST_CONTACTTIME)VALUES(S.A,S.B,S.C,S.D)";
  323. conn = db.getConnection();
  324. conn.setAutoCommit(false);
  325. st = conn.prepareStatement(sql);
  326. for(int i=0;i<list.size();i++){
  327. st.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(99));
  328. st.setString(2, userId);
  329. st.setString(3, list.get(i));
  330. st.setString(4, formatDate(new Date()));
  331. st.executeUpdate();
  332. }
  333. // st.executeBatch();
  334. conn.commit();
  335. // log.info("最近联系人爆粗成功");
  336. return true;
  337. } catch (SQLException e) {
  338. this.log.error(e.getMessage(), e);
  339. throw new ClassNotFoundException("DAO Layou: 新增用户最近联系人", e);
  340. } finally {
  341. db.close(st);
  342. db.close(conn);
  343. }
  344. }
  345. @SuppressWarnings({ "unchecked", "rawtypes" })
  346. public List<String> getFriendId() throws ClassNotFoundException{
  347. String sql="SELECT FD_OBJECTID,USER_ID,USER_CONTACT_ID,LAST_CONTACTTIME FROM SYS_USER_CONTACTS";
  348. Connection conn = null;
  349. Statement stat = null;
  350. ResultSet rs = null;
  351. DbConnection db = new DbConnection();
  352. try {
  353. conn = db.getConnection();
  354. stat = conn.createStatement();
  355. rs = stat.executeQuery(sql);
  356. List<String> list = new ArrayList();
  357. while (rs.next()) {
  358. list.add(rs.getString("FD_OBJECTID"));
  359. }
  360. return list;
  361. } catch (SQLException e) {
  362. this.log.error(e.getMessage(), e);
  363. throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
  364. + sql, e);
  365. } finally {
  366. db.close(rs);
  367. db.close(stat);
  368. db.close(conn);
  369. }
  370. }
  371. @SuppressWarnings("rawtypes")
  372. public String getUserNameById(String name){
  373. String sql="SELECT USER_ID,REAL_NAME FROM SYS_USER_INFO WHERE REAL_NAME='"+name+"'";
  374. // log.info("getUserNameById.sql====="+sql);
  375. List list = null;
  376. try {
  377. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  378. } catch (PersistenceException e) {
  379. log.error(e.getMessage());
  380. }
  381. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  382. // log.info("获取已接收消息信息==="+result);
  383. return result;
  384. }
  385. //返回通知应急联系人的JSON
  386. //应急预案
  387. public String getOrgLinkInfo(String file_id,String grade_type){
  388. Person per = new Person();
  389. String FRIST_GRADE="";
  390. String SECOND_GRADE="";
  391. String THRID_GRADE="";
  392. String FOURTH_GRADE="";
  393. //存入人的对象
  394. Map<String,Person> map = new HashMap<String,Person>();
  395. String sql="select * from EMC_EM_PLAN_GRADE_NEXUS where FILLER1='"+file_id+"' and GRADE_TYPE like '"+grade_type+"'";
  396. log.info(sql);
  397. List<Map<String, String>> list = null;
  398. List<Person>pList=new ArrayList<Person>();
  399. try {
  400. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  401. if(list!=null&&list.size()>0){
  402. Map<String, String>tempMap=list.get(0);
  403. FRIST_GRADE=tempMap.get("FRIST_GRADE");
  404. SECOND_GRADE=tempMap.get("SECOND_GRADE");
  405. THRID_GRADE=tempMap.get("THRID_GRADE");
  406. FOURTH_GRADE=tempMap.get("FOURTH_GRADE");
  407. //转换成数组对象
  408. String[] arr1 = FRIST_GRADE.split("\\|");
  409. String[] arr2 = SECOND_GRADE.split("\\|");
  410. String[] arr3 = THRID_GRADE.split("\\|");
  411. String[] arr4 = FOURTH_GRADE.split("\\|");
  412. int ff = arr1.length;
  413. String[] arr11 = null;
  414. String[] arr22 = null;
  415. String[] arr33 = null;
  416. String[] arr44 = null;
  417. String name = "";
  418. String id = "";
  419. String tel = "";
  420. //一级
  421. //遍历数组
  422. if(arr1.length>0){
  423. for(int i=0;i<arr1.length;i++){
  424. String arr1temp = arr1[i];
  425. arr11 = arr1temp.split("\\*");
  426. name = arr11[0];
  427. tel = arr11[1];
  428. id = arr11[2];
  429. if(map.containsKey(id)){
  430. Person p = map.get(id);
  431. p.setName(name);
  432. p.setTel(tel);
  433. p.setLevel1("true");
  434. map.put(id, p);
  435. }else{
  436. Person p = new Person();
  437. p.setId(id);
  438. p.setName(name);
  439. p.setTel(tel);
  440. p.setLevel1("true");
  441. map.put(id, p);
  442. pList.add(p);
  443. }
  444. }
  445. }
  446. //二级
  447. //遍历数组
  448. if(arr2.length>0){
  449. for(int i=0;i<arr2.length;i++){
  450. String arr2temp = arr2[i];
  451. arr22 = arr2temp.split("\\*");
  452. if(map.containsKey(arr22[2])){
  453. Person p = map.get(arr22[2]);
  454. p.setName(arr22[0]);
  455. p.setTel(arr22[1]);
  456. p.setLevel2("true");
  457. map.put(arr22[2], p);
  458. }else{
  459. Person p = new Person();
  460. p.setId(arr22[2]);
  461. p.setName(arr22[0]);
  462. p.setTel(arr22[1]);
  463. p.setLevel1("true");
  464. map.put(arr22[2], p);
  465. pList.add(p);
  466. }
  467. }
  468. }
  469. //三级
  470. //遍历数组
  471. if(arr3.length>0){
  472. for(int i=0;i<arr3.length;i++){
  473. String arr3temp = arr3[i];
  474. arr33 = arr3temp.split("\\*");
  475. if(map.containsKey(arr33[2])){
  476. Person p = map.get(arr33[2]);
  477. p.setName(arr33[0]);
  478. p.setTel(arr33[1]);
  479. p.setLevel3("true");
  480. map.put(arr33[2], p);
  481. }else{
  482. Person p = new Person();
  483. p.setId(arr33[2]);
  484. p.setName(arr33[0]);
  485. p.setTel(arr33[1]);
  486. p.setLevel3("true");
  487. map.put(arr33[2], p);
  488. pList.add(p);
  489. }
  490. }
  491. }
  492. //四级
  493. //遍历数组
  494. if(arr4.length>0){
  495. for(int i=0;i<arr4.length;i++){
  496. String arr4temp = arr4[i];
  497. arr44 = arr4temp.split("\\*");
  498. if(map.containsKey(arr44[2])){
  499. Person p = map.get(arr44[2]);
  500. p.setName(arr44[0]);
  501. p.setTel(arr44[1]);
  502. p.setLevel4("true");
  503. map.put(arr44[2], p);
  504. }else{
  505. Person p = new Person();
  506. p.setId(arr44[2]);
  507. p.setName(arr44[0]);
  508. p.setTel(arr44[1]);
  509. p.setLevel4("true");
  510. map.put(arr44[2], p);
  511. pList.add(p);
  512. }
  513. }
  514. }
  515. }
  516. } catch (PersistenceException e) {
  517. log.error(e.getMessage());
  518. }
  519. String result = "{\"rows\":" + JSONArray.fromObject(map).toString() + "}";
  520. result="{\"rows\":"+JsonPluginsUtil.beanListToJson(pList) + "}";;
  521. // log.info("获取getPlanInfo信息==="+result);
  522. return result;
  523. }
  524. //应急预案215绑定关系表
  525. public String getPlanInfo(String file_id,String grade_type,String dept_type){
  526. String sql = "";
  527. if(dept_type.equals("1")){
  528. sql="select * from EMC_EM_PLAN_GRADE_NEXUS where FILLER1=(select FD_OBJECTID from ECM_AM_YJYASERVER where units = "
  529. + "(select parent_id from SYS_DEPARTMENT where dept_id = (select UNITS from ECM_AM_YJYASERVER where FD_OBJECTID = '"+file_id+"'))"
  530. + "and PLAN_REFINE_CATEGORY = (select PLAN_REFINE_CATEGORY from ECM_AM_YJYASERVER where FD_OBJECTID = '"+file_id+"')"
  531. + "and is_del = '0' and PLAN_STAT = '1')and GRADE_TYPE like '"+grade_type+"'";
  532. }else{
  533. sql="select * from EMC_EM_PLAN_GRADE_NEXUS where FILLER1='"+file_id+"' and GRADE_TYPE like '"+grade_type+"'";
  534. //sql="select a.* from ECM_AM_YJYASERVER a,ECM_AM_YJYASERVER b where a.plan_type=b.plan_type and a.bysuness_type=b.bysuness_type and b.fd_objectid='"+file_id+"'and a.units='C984DC9C294A486096C25FAA78C99AED' and a.PLAN_REFINE_CATEGORY=b.PLAN_REFINE_CATEGORY and a.is_del='0' and a.plan_stat='1'";
  535. }
  536. log.info(sql);
  537. List<Map<String, String>> list = null;
  538. try {
  539. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  540. } catch (PersistenceException e) {
  541. log.error(e.getMessage());
  542. }
  543. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  544. return result;
  545. }
  546. //通过单位ID和预案类型查询该单位下的该类型预案,如果有,返回预案ID
  547. public String getZhuanxiang(String parent_id,String grade_type){
  548. String sql="select * from ECM_AM_YJYASERVER where PLAN_REFINE_CATEGORY='"+grade_type+"' and UNITS = '"+parent_id+"' and is_del='0'" ;
  549. log.info(sql);
  550. List<Map<String, String>> list = null;
  551. try {
  552. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  553. } catch (PersistenceException e) {
  554. log.error(e.getMessage());
  555. }
  556. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  557. return result;
  558. }
  559. //应急预案
  560. public String getPlanInfoEM(String file_id,String grade_type){
  561. String sql="select a.*,b.PLAN_REFINE_CATEGORY from EMC_EM_PLAN_GRADE_NEXUS a,ECM_AM_YJYASERVER b where filler1 in(select a.fd_objectid from ECM_AM_YJYASERVER a,ECM_AM_YJYASERVER b where a.plan_type=b.plan_type and a.bysuness_type=b.bysuness_type and b.fd_objectid='"+file_id+"'and a.units='C984DC9C294A486096C25FAA78C99AED' and a.PLAN_REFINE_CATEGORY=b.PLAN_REFINE_CATEGORY and a.is_del='0' and a.plan_stat='1') and grade_type like '"+grade_type+"' and a.filler1=b.fd_objectid";
  562. if(file_id.indexOf(",")>-1){//假如是非省级发布通知单,预案id字段存的是:plan9,9类型数据,表示预案细分类型等于9
  563. String plan_num = file_id.substring(file_id.lastIndexOf(",")+1);
  564. sql="select a.*,b.PLAN_REFINE_CATEGORY from EMC_EM_PLAN_GRADE_NEXUS a,ECM_AM_YJYASERVER b where filler1 in(select a.fd_objectid from ECM_AM_YJYASERVER a where a.units ='C984DC9C294A486096C25FAA78C99AED' and a.is_del ='0' and a.plan_stat ='1' and a.PLAN_REFINE_CATEGORY='"+plan_num+"' and a.PLAN_TYPE=103 order by updatedate desc) and grade_type like '"+grade_type+"' and a.filler1=b.fd_objectid";
  565. }
  566. log.info(sql);
  567. List list = null;
  568. try {
  569. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  570. } catch (PersistenceException e) {
  571. log.error(e.getMessage());
  572. }
  573. //String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  574. // log.info("获取getPlanInfo信息==="+result);
  575. return JSONArray.fromObject(list).toString();
  576. }
  577. //应急预案--短信
  578. public String getPlanInfoMsg(String file_id,String grade_type){
  579. String sql="select FRIST_GRADE,SECOND_GRADE,THRID_GRADE,FOURTH_GRADE from EMC_EM_PLAN_GRADE_NEXUS where FILLER1='"+file_id+"' and GRADE_TYPE='"+grade_type+"'";
  580. log.info(sql);
  581. PlanBean pb=new PlanBean();
  582. String result="";
  583. List<String[]> list = null;
  584. try {
  585. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResult(99,sql);
  586. } catch (PersistenceException e) {
  587. log.error(e.getMessage());
  588. }
  589. if(list==null){
  590. return null;
  591. }else{
  592. if(list.size()==1){
  593. // result=changeName(list)
  594. String firstName=list.get(0)[0];
  595. String secondName=list.get(0)[1];
  596. String thirdName=list.get(0)[2];
  597. String fourthName=list.get(0)[3];
  598. // log.info("firstName===" + firstName);
  599. // log.info("secondName===" + secondName);
  600. // log.info("thirdName===" + thirdName);
  601. // log.info("fourthName===" + fourthName);
  602. result=getInfoString(firstName,secondName,thirdName,fourthName);
  603. // String []firstNameArr=firstName.split("[|][|]");
  604. // pb.setFIRST_DEPT(changeName2(firstNameArr[0]));
  605. // pb.setFIRST_EXPERT(changeName2(firstNameArr[1]));
  606. // pb.setFIRST_TEAM(changeName2(firstNameArr[2]));
  607. //
  608. // String []secondNameArr=secondName.split("[|][|]");
  609. // pb.setSECOND_DEPT(changeName2(secondNameArr[0]));
  610. // pb.setSECOND_EXPERT(changeName2(secondNameArr[1]));
  611. // pb.setSECOND_TEAM(changeName2(secondNameArr[2]));
  612. //
  613. // String []thirdNameArr=thirdName.split("[|][|]");
  614. // pb.setTHIRD_DEPT(changeName2(thirdNameArr[0]));
  615. // pb.setTHIRD_EXPERT(changeName2(thirdNameArr[1]));
  616. // pb.setTHIRD_TEAM(changeName2(thirdNameArr[2]));
  617. //
  618. // String []fourthNameArr=fourthName.split("[|][|]");
  619. // pb.setFOURTH_DEPT(changeName2(fourthNameArr[0]));
  620. // pb.setFOURTH_EXPERT(changeName2(fourthNameArr[1]));
  621. // pb.setFOURTH_TEAM(changeName2(fourthNameArr[2]));
  622. //龙志伟#13811111114@唐群胜#13800110505@||输电一队#88888888@||李思思#13312345678@龙志伟#13811111111@张三#13574766666@||
  623. // log.info("result===" + result);
  624. }
  625. }
  626. // String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  627. // log.info("获取getPlanInfo信息==="+result);
  628. return result;
  629. }
  630. public String getInfoString(String firstName,String secondName,String thirdName,String fourthName){
  631. PlanBean pb=new PlanBean();
  632. String []firstNameArr=firstName.split("[|][|]");
  633. if(firstNameArr==null||firstNameArr.length!=3){
  634. return null;
  635. }
  636. // log.info("firstNameArr[0]=========="+changeName2(firstNameArr[0]));
  637. pb.setFIRST_DEPT(firstNameArr[0]);
  638. pb.setFIRST_EXPERT(firstNameArr[1]);
  639. pb.setFIRST_TEAM(firstNameArr[2]);
  640. // log.info("firstNameArr[0]=========="+changeName2(firstNameArr[0]));
  641. String []secondNameArr=secondName.split("[|][|]");
  642. if(secondNameArr==null||secondNameArr.length!=3){
  643. return null;
  644. }
  645. pb.setSECOND_DEPT(secondNameArr[0]);
  646. pb.setSECOND_EXPERT(secondNameArr[1]);
  647. pb.setSECOND_TEAM(secondNameArr[2]);
  648. String []thirdNameArr=thirdName.split("[|][|]");
  649. if(thirdNameArr==null||thirdNameArr.length!=3){
  650. return null;
  651. }
  652. pb.setTHIRD_DEPT(thirdNameArr[0]);
  653. pb.setTHIRD_EXPERT(thirdNameArr[1]);
  654. pb.setTHIRD_TEAM(thirdNameArr[2]);
  655. String []fourthNameArr=fourthName.split("[|][|]");
  656. if(fourthNameArr==null||fourthNameArr.length!=3){
  657. return null;
  658. }
  659. pb.setFOURTH_DEPT(fourthNameArr[0]);
  660. pb.setFOURTH_EXPERT(fourthNameArr[1]);
  661. pb.setFOURTH_TEAM(fourthNameArr[2]);
  662. String result=JSONArray.fromObject(pb).toString();
  663. // log.info(result);
  664. return result;
  665. }
  666. public String changeName(String name){
  667. return null;
  668. }
  669. //同一类型不同部门需要换行
  670. // public String changeName2(String name){
  671. // StringBuffer sb=new StringBuffer();
  672. // Map<String, String>map=new HashMap<String, String>();
  673. // if(!"".equals(name)){
  674. // String[]arr=name.split("[@]");
  675. // log.info("arr====="+arr[0]);
  676. // for(int i=0;i<arr.length;i++){
  677. // String[] arr1=arr[i].split("[#]");
  678. // log.info("arr1"+arr1[i]);
  679. // if(arr1==null||arr1.length!=3){
  680. // return null;
  681. // }
  682. //// String deptName=getDeptById(arr1[0]);
  683. // log.info("测试");
  684. // String deptName=arr1[0];
  685. // String userName=arr1[1];
  686. // String tel=arr1[2];
  687. // String ss=deptName+":"+userName+","+tel+";";
  688. // if(map.containsKey(arr1[0])){
  689. // ss=userName+","+tel+";";
  690. // map.put(arr1[0], map.get(arr1[0])+ss);
  691. // }else{
  692. // map.put(arr1[0], ss);
  693. // }
  694. //
  695. // }
  696. // Set set = map.keySet();
  697. // for (Object key : set) {
  698. // sb.append(map.get(key)+"\r\n");
  699. // }
  700. // }
  701. // return sb.toString();
  702. // }
  703. public String getDeptById(String id){
  704. SysModel sysmodel = ModelFactory.getSysmodel();
  705. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  706. String sql="select name from sys_department_0827 where id='"+id+"'";
  707. try {
  708. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  709. if(tempList==null||tempList.size()==0){
  710. return "无部门";
  711. }else{
  712. String name=tempList.get(0)[0];
  713. // log.info("name===="+name);
  714. return name;
  715. }
  716. } catch (PersistenceException e) {
  717. e.printStackTrace();
  718. return "无部门";
  719. }
  720. }
  721. public int getReadedCount(String userId) throws ClassNotFoundException{
  722. String sql = "select count(1) from sys_user_msg a ,sys_user_info b where a.read_stat=? and receive_user_id = ? and recived_delete_stat = ? and a.send_user_id= b.user_id";
  723. Connection conn = null;
  724. PreparedStatement ps = null;
  725. ResultSet rs = null;
  726. DbConnection db = new DbConnection();
  727. int num=0;
  728. try {
  729. conn = db.getConnection();
  730. ps = conn.prepareStatement(sql);
  731. ps.setString(1, "0");
  732. ps.setString(2, userId);
  733. ps.setString(3, "0");
  734. rs = ps.executeQuery();
  735. while(rs.next()){
  736. num = Integer.parseInt(rs.getString("COUNT(1)"));
  737. }
  738. } catch (SQLException e) {
  739. log.info(e.getMessage(),e);
  740. }finally{
  741. db.close(rs);
  742. db.close(ps);
  743. db.close(conn);
  744. }
  745. log.info(num+"===============num");
  746. return num;
  747. }
  748. public String getReportAndPlanTime(String event_type_id, String event_level,String comp_id) {
  749. if("29".equals(event_level)){//一级响应
  750. event_level = "1";
  751. }else if("30".equals(event_level)){//二级响应
  752. event_level = "2";
  753. }else if("31".equals(event_level)){//三级响应
  754. event_level = "3";
  755. }else if("32".equals(event_level)){//四级响应
  756. event_level = "4";
  757. }else if("35".equals(event_level)){//红色预警
  758. event_level = "5";
  759. }else if("36".equals(event_level)){//橙色预警
  760. event_level = "6";
  761. }else if("37".equals(event_level)){//黄色预警
  762. event_level = "7";
  763. }else if("38".equals(event_level)){//蓝色预警
  764. event_level = "8";
  765. }
  766. String dept_level = new BaoBiaoDao().getDeptLevel(comp_id);
  767. String sql="select b.report_name, c.report_time, b.SERIAL_NUMBER,b.role_id,b.is_type from ECM_EM_EMERGENCY_TYPE a , ECM_EM_EMERGENCY_TYPE_CONFIG b, ECM_EM_EVENT_REPORT c where a.fd_objectid=b.event_type_id and b.fd_objectid=c.report_id and a.fd_objectid='"+event_type_id+"' and war_rep_level='"+event_level+"' ";
  768. log.info(sql);
  769. String sql1 = "";
  770. List<Map<String,String>> list = null;
  771. List<Map<String,String>> list1 = null;
  772. StringBuffer sb = new StringBuffer();
  773. sb.append("");
  774. try {
  775. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  776. for (int i = 0; i < list.size(); i++) {
  777. Map<String,String> map = list.get(i);
  778. String report_name = map.get("REPORT_NAME");//报表名称
  779. String report_time = map.get("REPORT_TIME");//填报时间
  780. String serial_number = map.get("SERIAL_NUMBER");//报表对应编号
  781. if(("2".equals(dept_level) && "2".equals(serial_number)) || (!"2".equals(dept_level) && "101".equals(serial_number))){
  782. continue;
  783. }
  784. String role_id = map.get("ROLE_ID");//报表对应角色
  785. String is_type = map.get("IS_TYPE");//报告还是报表
  786. sb.append(is_type+"~"+serial_number+"~"+report_name+"~"+report_time+"~"+role_id);
  787. sb.append("_&_");
  788. if("1".equals(is_type)){//如果是报表
  789. StringBuffer sb1 = new StringBuffer();
  790. sb1.append("");
  791. sql1 = "select distinct d.COMP_NAME, d.COMP_ID,d.DEPT_TYPE from ECM_EM_EMERGENCY_TYPE a , ECM_EM_EMERGENCY_TYPE_CONFIG b, REPORT_COMP_DICTIONARY d where a.fd_objectid=b.event_type_id and a.fd_objectid=d.AFFAIR and d.report_type=b.serial_number and a.fd_objectid='"+event_type_id+"' and d.report_view_id='"+comp_id+"' and b.serial_number='"+serial_number+"' order by d.DEPT_TYPE ";
  792. list1 = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql1);
  793. for (int j = 0; j < list1.size(); j++) {//突发事件类型绑定的单位
  794. Map<String,String> map1 = list1.get(j);
  795. String COMP_NAME = map1.get("COMP_NAME");
  796. String DEPT_TYPE = map1.get("DEPT_TYPE");
  797. String COMP_ID = map1.get("COMP_ID");
  798. if("corp".equals(DEPT_TYPE)){
  799. sb.append(COMP_ID+",");
  800. }else{
  801. sb1.append(COMP_ID+",");
  802. }
  803. }
  804. sb.append("__"+sb1);
  805. }
  806. sb.append("||@");
  807. }
  808. } catch (PersistenceException e) {
  809. log.error(e.getMessage());
  810. }
  811. //String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  812. // log.info("获取getPlanInfo信息==="+result);
  813. return sb.toString();
  814. }
  815. }