030d536129aac3ce09fdf01e90ae5bc1ffabfe5c.svn-base 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758
  1. package com.sinosoft.lz.system.sms.dao;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.OutputStreamWriter;
  7. import java.nio.channels.FileChannel;
  8. import java.sql.Connection;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.text.SimpleDateFormat;
  14. import java.util.ArrayList;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.Random;
  20. import java.util.UUID;
  21. import net.sf.json.JSONArray;
  22. import org.apache.log4j.Logger;
  23. import com.formaction.Parameter;
  24. import com.formaction.vo.Msg;
  25. import com.persistence.DaMengBasicApp;
  26. import com.persistence.DbConnection;
  27. import com.persistence.service.PersistenceFactory;
  28. import com.persistence.service.SysPersistence;
  29. import com.persistence.service.assitant.generator.IdentityGenerator;
  30. import com.persistence.service.exception.PersistenceException;
  31. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  32. import com.sinosoft.lz.system.sms.dao.ws.MsgDao;
  33. import com.sinosoft.lz.system.sms.vo.MSGBean;
  34. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  35. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  36. public class SmsDao {
  37. private Logger log = Logger.getLogger(this.getClass());
  38. private String fileName="";
  39. /**
  40. * 保存短信和调用保存短信文件
  41. * @param title
  42. * @param recList
  43. * @param time
  44. * @param content
  45. * @param sendId
  46. * @return
  47. * @throws ClassNotFoundException
  48. */
  49. public Msg saveSms(String title,List<String> recList,String time,String content,String sendId) throws ClassNotFoundException{
  50. Msg m=new Msg();
  51. Connection conn = null;
  52. PreparedStatement st = null;
  53. DbConnection db = new DbConnection();
  54. // log.info("recid.size===="+recList.size());
  55. try {
  56. String sql = "INSERT INTO SYS_MSG_MANAGE(REC_USER_TEL,MSG_TYPE,MSG_CONTENT,SEND_USER_TEL,MSG_STAT,MSG_TIME,FD_OBJECTID,IS_DEL,MSG_TITLE)VALUES(?,?,?,?,?,?,?,?,?)";
  57. conn = db.getConnection();
  58. int num=0;
  59. conn.setAutoCommit(false);
  60. st = conn.prepareStatement(sql);
  61. List<String>fdList=new ArrayList<String>();
  62. for(int i=0;i<recList.size();i++){
  63. String fd_id= getFdId(776+i,(i+1));/*IdentityGenerator.getIdentityGenerator().gerenalIdentity(776);*/
  64. fdList.add(fd_id);
  65. st.setString(1, recList.get(i));
  66. st.setString(2, "短信发送");
  67. // log.info("formatDate(new Date())==="+formatDate(new Date()));
  68. st.setString(3, content);
  69. st.setString(4,sendId);
  70. st.setString(5, "0");
  71. st.setString(6, time);
  72. st.setString(7, fd_id);
  73. st.setString(8, "0");
  74. st.setString(9, title);
  75. st.executeUpdate();
  76. num++;
  77. }
  78. // log.info("num====="+num);
  79. if(num==recList.size()){
  80. log.info("保存成功");
  81. conn.commit();
  82. m.setSucsess(new Boolean(true).toString());
  83. m.setInfo(Parameter.DELETE_SUCSESS);
  84. if(content.length()<=64){
  85. sendNote(recList,fdList,content);
  86. }else{
  87. saveMsg(recList,fdList,content);
  88. }
  89. return m;
  90. }else{
  91. m.setSucsess(new Boolean(false).toString());
  92. m.setInfo(Parameter.DELETE_FAILURE);
  93. // st.executeBatch();
  94. conn.rollback();
  95. log.info("保存失败");
  96. return m;}
  97. } catch (SQLException e) {
  98. this.log.error(e.getMessage(), e);
  99. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  100. } finally {
  101. db.close(st);
  102. db.close(conn);
  103. }
  104. }
  105. /**
  106. * 保存短信和调用保存短信文件
  107. * @param title
  108. * @param recList
  109. * @param time
  110. * @param content
  111. * @param sendId
  112. * @return
  113. * @throws ClassNotFoundException
  114. */
  115. public Msg saveMessage(String realName,List<String> recList,String time,String content,String sendId,List<String>people,String type) throws ClassNotFoundException{
  116. log.info("lianjian,修改短信版本日期:2017-11-03");
  117. Msg m=new Msg();
  118. MsgDao msgDao = new MsgDao();
  119. Connection conn = null;
  120. PreparedStatement st = null;
  121. DbConnection db = new DbConnection();
  122. //String msgId = msgDao.getSmID();
  123. // log.info("recid.sizesaveMessage===="+recList.size());
  124. try {
  125. String sql = "INSERT INTO SYS_MSG_MANAGE(REC_USER_TEL,MSG_TYPE,MSG_CONTENT,SEND_USER_TEL,MSG_STAT,MSG_TIME,FD_OBJECTID,IS_DEL,REAL_NAME,REC_NAME)VALUES(?,?,?,?,?,?,?,?,?,?)";
  126. conn = db.getConnection();
  127. int num=0;
  128. int num1=0;
  129. //boolean flag = false;
  130. conn.setAutoCommit(false);
  131. st = conn.prepareStatement(sql);
  132. List<String>fdList=new ArrayList<String>();
  133. String[] mobiles = new String[recList.size()];
  134. Map<String,String> map = new HashMap<String, String>();
  135. for(int i=0;i<recList.size();i++){
  136. String tel=recList.get(i);
  137. if(!"".equals(tel)&&tel!=null){//接收人号码
  138. mobiles[i]=tel;
  139. num1++;
  140. String fd_id= getFdId(776+i,(i+1));/*IdentityGenerator.getIdentityGenerator().gerenalIdentity(776)*/
  141. fdList.add(fd_id);
  142. map.put(fd_id, tel);
  143. st.setString(1, recList.get(i));//接收人号码
  144. st.setString(2, type); //短信类型
  145. // log.info("formatDate(new Date())==="+formatDate(new Date()));
  146. st.setString(3, content);//短信内容
  147. st.setString(4,sendId); //发送人员的ID
  148. st.setString(5, "0");//短信状态
  149. st.setString(6, time);//创建时间
  150. st.setString(7, fd_id);//主键
  151. st.setString(8, "0"); //是否删除
  152. st.setString(9, realName);//短信发送人
  153. if(i<people.size()){
  154. st.setString(10, people.get(i));
  155. //短信收件人
  156. }else{
  157. st.setString(10, "");
  158. }
  159. /*st.setString(11, deptName);*/
  160. //st.setString(11, msgId);
  161. st.executeUpdate();
  162. num++;
  163. }
  164. }
  165. if(num==num1){
  166. log.info("保存成功");
  167. conn.commit();
  168. // m.setSucsess(new Boolean(true).toString());
  169. m.setInfo(Parameter.CREATE_SUCSESS);
  170. //lj
  171. for (int i = 0; i < fdList.size(); i++) {
  172. String msgID=fdList.get(i);
  173. String[] phones={map.get(msgID)};
  174. boolean flag = msgDao.sendShortMessage(phones, content, msgID);
  175. if(flag) {
  176. msgDao.updateMsg("DELIVRD",msgID);
  177. }else{
  178. msgDao.updateMsg("fail",msgID);
  179. }
  180. }
  181. m.setSucsess(new Boolean(true).toString());
  182. return m;
  183. }else{
  184. m.setSucsess(new Boolean(false).toString());
  185. m.setInfo(Parameter.DELETE_FAILURE);
  186. // st.executeBatch();
  187. conn.rollback();
  188. log.info("保存失败");
  189. return m;}
  190. } catch (SQLException e) {
  191. this.log.error(e.getMessage(), e);
  192. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  193. } finally {
  194. db.close(st);
  195. db.close(conn);
  196. }
  197. }
  198. /**
  199. * 重写 ----ljp
  200. * 保存短信和调用保存短信文件
  201. * @param tempList
  202. * @param type
  203. * @return
  204. * @throws ClassNotFoundException
  205. */
  206. public Msg saveMessage(List<MSGBean> tempList,String type) throws ClassNotFoundException{
  207. Msg m=new Msg();
  208. Connection conn = null;
  209. PreparedStatement st = null;
  210. DbConnection db = new DbConnection();
  211. String cont = "";
  212. log.info("recid.sizesaveMessage===="+tempList.size());
  213. try {
  214. String sql = "INSERT INTO SYS_MSG_MANAGE(REC_USER_TEL,MSG_TYPE,MSG_CONTENT,SEND_USER_TEL,MSG_STAT,MSG_TIME,FD_OBJECTID,IS_DEL,REAL_NAME,REC_NAME)VALUES(?,?,?,?,?,?,?,?,?,?)";
  215. conn = db.getConnection();
  216. int num=0;
  217. int num1=0;
  218. //boolean flag = false;
  219. conn.setAutoCommit(false);
  220. st = conn.prepareStatement(sql);
  221. List<String>fdList=new ArrayList<String>();
  222. List<String>recList1=new ArrayList<String>();
  223. if(tempList.size()>0){
  224. cont = tempList.get(0).getMSG_CONTENT();
  225. }
  226. for(int i=0;i<tempList.size();i++){
  227. MSGBean msg = tempList.get(i);
  228. String tel=msg.getREC_USER_TEL();
  229. if(!"".equals(tel)&&tel!=null){
  230. num1++;
  231. String fd_id= getFdId(776+i,(i+1));/*IdentityGenerator.getIdentityGenerator().gerenalIdentity(776)*/
  232. msg.setFD_OBJECTID(fd_id);
  233. st.setString(1, msg.getREC_USER_TEL());
  234. st.setString(2, type);
  235. st.setString(3, msg.getMSG_CONTENT());
  236. st.setString(4,msg.getSEND_USER_TEL());
  237. st.setString(5, "0");
  238. st.setString(6, msg.getMSG_TIME());
  239. st.setString(7, fd_id);
  240. st.setString(8, "0");
  241. st.setString(9, msg.getREAL_NAME());
  242. st.setString(10, msg.getREC_NAME());
  243. st.executeUpdate();
  244. num++;
  245. }
  246. }
  247. if(num==num1){
  248. log.info("保存成功");
  249. conn.commit();
  250. m.setSucsess(new Boolean(true).toString());
  251. m.setInfo(Parameter.DELETE_SUCSESS);
  252. if(cont.length()<=64){
  253. sendNote(tempList);
  254. /* if(flag){
  255. sendNote(recList2,fdList2,content);
  256. }*/
  257. }else{
  258. saveMsg(tempList);
  259. /* if(flag){
  260. saveMsg(recList2,fdList2,content);
  261. }*/
  262. }
  263. return m;
  264. }else{
  265. m.setSucsess(new Boolean(false).toString());
  266. m.setInfo(Parameter.DELETE_FAILURE);
  267. // st.executeBatch();
  268. conn.rollback();
  269. log.info("保存失败");
  270. return m;}
  271. } catch (SQLException e) {
  272. this.log.error(e.getMessage(), e);
  273. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  274. } finally {
  275. db.close(st);
  276. db.close(conn);
  277. }
  278. }
  279. /**
  280. * 重写 ---ljp
  281. * 保存短信文件
  282. * @param tempList
  283. * @return
  284. */
  285. private boolean saveMsg(List<MSGBean> tempList) {
  286. try {
  287. // log.debug("发送短信内容" + content);
  288. long t1=System.currentTimeMillis();
  289. // 先根据类型获取接收此预警的用户群的手机号列表
  290. File smsFile = createSMSFile();
  291. StringBuffer fileContent =new StringBuffer();
  292. for(int i=0;i<tempList.size();i++){
  293. MSGBean msg = tempList.get(i);
  294. fileContent.append(createSMSContent(msg.getREC_USER_TEL(), msg.getFD_OBJECTID(),msg.getMSG_CONTENT()));
  295. }
  296. fileContent.append("end");
  297. // log.info("短信文件内容====="+fileContent.toString());
  298. writeFile(smsFile, fileContent+"\n");
  299. // Process process = Runtime.getRuntime().exec("mv /home/beaimon/user/pzc/sms/"+fileName+" /home/beaimon/gts02/sms/");
  300. long t2 = System.currentTimeMillis();
  301. log.info("消耗时间为:" + (t2 - t1));
  302. } catch (Exception e) {
  303. log.error("发送短信异常 type:", e);
  304. return false;
  305. }
  306. return true;
  307. }
  308. /**
  309. * 重写 ----ljp
  310. * 保存短信文件
  311. * @param tempList
  312. * @return
  313. */
  314. private boolean sendNote(List<MSGBean> tempList) {
  315. try {
  316. // log.debug("发送短信内容" + content);
  317. long t1=System.currentTimeMillis();
  318. // 先根据类型获取接收此预警的用户群的手机号列表
  319. File smsFile = createSMSFile();
  320. StringBuffer fileContent =new StringBuffer();
  321. for(int i=0;i<tempList.size();i++){
  322. MSGBean msg = tempList.get(i);
  323. fileContent.append(createSMSContent(msg.getREC_USER_TEL(), msg.getFD_OBJECTID(),msg.getMSG_CONTENT()));
  324. }
  325. fileContent.append("end");
  326. // log.info("短信文件内容====="+fileContent.toString());
  327. writeFile(smsFile, fileContent+"\n");
  328. // Process process = Runtime.getRuntime().exec("mv /home/beaimon/user/pzc/sms/"+fileName+" /home/beaimon/gts02/sms/");
  329. long t2 = System.currentTimeMillis();
  330. log.info("消耗时间为:" + (t2 - t1));
  331. } catch (Exception e) {
  332. log.error("发送短信异常 type:", e);
  333. return false;
  334. }
  335. return true;
  336. }
  337. /**
  338. * 初始化grid表格和查询grid表格的内容(范本)
  339. * @param modelTitle
  340. * @param modelContent
  341. * @param modelType
  342. * @param modelRange
  343. * @param deptName
  344. * @param userName
  345. * @param modelTime
  346. * @return
  347. */
  348. public String getmodelGrid(String modelTitle,String modelContent,String modelType,String modelRange,String deptName,String userName,String modelTime ,String end_time,int page,int pageSize,String dept){
  349. String sql="SELECT TOP "+(page-1)*pageSize+","+pageSize+" a.*,C.REAL_NAME,D.DEPT_NAME FROM SYS_MSG_MODEL A,SYS_DEPT_USER B,SYS_USER_INFO C ,SYS_DEPARTMENT D WHERE A.MSG_MODEL_USER=c.USER_ID AND b.user_id=C.USER_ID and b.dept_id=d.dept_id and a.is_del='0' and (D.DEPT_NAME ='"+dept+"' or a.msg_model_range='1')";
  350. String sql1="SELECT a.*,C.REAL_NAME,D.DEPT_NAME FROM SYS_MSG_MODEL A,SYS_DEPT_USER B,SYS_USER_INFO C ,SYS_DEPARTMENT D WHERE A.MSG_MODEL_USER=c.USER_ID AND b.user_id=C.USER_ID and b.dept_id=d.dept_id and a.is_del='0' and (D.DEPT_NAME = '"+dept+"' or a.msg_model_range='1')";
  351. // log.info(sql1+"==============getmodelGrid.sql1");
  352. Connection conn = null;
  353. Statement stat = null;
  354. Statement stat1 = null;
  355. ResultSet rs = null;
  356. ResultSet rs1 = null;
  357. DbConnection db = new DbConnection();
  358. if(!"".equals(modelTitle)){
  359. sql+="AND A.MSG_MODEL_TITLE LIKE '%"+modelTitle+"%'";
  360. sql1+="AND A.MSG_MODEL_TITLE LIKE '%"+modelTitle+"%'";
  361. }
  362. if(!"".equals(modelContent)){
  363. sql+="AND A.MSG_MODEL_CONTENT LIKE '%"+modelContent+"%'";
  364. sql1+="AND A.MSG_MODEL_CONTENT LIKE '%"+modelContent+"%'";
  365. }
  366. if(!"".equals(modelType)){
  367. sql+="AND A.MSG_MODEL_TYPE = '"+modelType+"'";
  368. sql1+="AND A.MSG_MODEL_TYPE = '"+modelType+"'";
  369. }
  370. if(!"".equals(modelRange)){
  371. sql+="AND A.MSG_MODEL_RANGE = '"+modelRange+"'";
  372. sql1+="AND A.MSG_MODEL_RANGE = '"+modelRange+"'";
  373. }
  374. if(!"".equals(deptName)){
  375. sql+="AND D.DEPT_NAME LIKE '%"+deptName+"%'";
  376. sql1+="AND D.DEPT_NAME LIKE '%"+deptName+"%'";
  377. }
  378. if(!"".equals(userName)){
  379. sql+="AND C.REAL_NAME LIKE '%"+userName+"%'";
  380. sql1+="AND C.REAL_NAME LIKE '%"+userName+"%'";
  381. }
  382. if(!"".equals(modelTime)&&!"".equals(end_time)){
  383. sql+="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') >='"+modelTime.substring(0,10)+"' AND SUBSTR(A.MSG_MODEL_TIME,'0','10')<='"+end_time.substring(0,10)+"'";
  384. sql1+="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') >='"+modelTime.substring(0,10)+"' AND SUBSTR(A.MSG_MODEL_TIME,'0','10')<='"+end_time.substring(0,10)+"'";
  385. }
  386. if(!"".equals(modelTime)&&"".equals(end_time)){
  387. sql +="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') >='"+modelTime.substring(0, 10)+"'";
  388. sql1 +="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') >='"+modelTime.substring(0, 10)+"'";
  389. }
  390. if("".equals(modelTime)&&!"".equals(end_time)){
  391. sql +="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') <= '"+end_time.substring(0, 10)+"'";
  392. sql1 +="AND SUBSTR(A.MSG_MODEL_TIME,'0','10') <= '"+end_time.substring(0, 10)+"'";
  393. }
  394. sql += "ORDER BY MSG_MODEL_TIME DESC";
  395. sql1 += "ORDER BY MSG_MODEL_TIME DESC";
  396. log.info("getmodelGrid.sql===="+sql);
  397. List list = new ArrayList<String>();
  398. StringBuffer json = new StringBuffer();
  399. int num = 0;
  400. try {
  401. conn = db.getConnection();
  402. stat = conn.createStatement();
  403. rs = stat.executeQuery(sql);
  404. while(rs.next()){
  405. json.append("{");
  406. json.append("\"FD_OBJECTID\""+":"+"\""+rs.getString("FD_OBJECTID")+"\""+",");
  407. json.append("\"MSG_MODEL_TYPE\""+":"+"\""+rs.getString("MSG_MODEL_TYPE")+"\""+",");
  408. json.append("\"MSG_MODEL_TITLE\""+":"+"\""+rs.getString("MSG_MODEL_TITLE")+"\""+",");
  409. json.append("\"MSG_MODEL_CONTENT\""+":"+"\""+rs.getString("MSG_MODEL_CONTENT")+"\""+",");
  410. json.append("\"MSG_MODEL_RANGE\""+":"+"\""+rs.getString("MSG_MODEL_RANGE")+"\""+",");
  411. json.append("\"MSG_MODEL_COMP\""+":"+"\""+rs.getString("MSG_MODEL_COMP")+"\""+",");
  412. json.append("\"MSG_MODEL_USER\""+":"+"\""+rs.getString("MSG_MODEL_USER")+"\""+",");
  413. json.append("\"MSG_MODEL_TIME\""+":"+"\""+rs.getString("MSG_MODEL_TIME")+"\""+",");
  414. json.append("\"IS_DEL\""+":"+"\""+rs.getString("IS_DEL")+"\""+",");
  415. json.append("\"REAL_NAME\""+":"+"\""+rs.getString("REAL_NAME")+"\""+",");
  416. json.append("\"DEPT_NAME\""+":"+"\""+rs.getString("DEPT_NAME")+"\"");
  417. json.append("},");
  418. }
  419. if (json.lastIndexOf(",") > -1) {
  420. json.deleteCharAt(json.lastIndexOf(","));
  421. }
  422. list.add(json);
  423. stat1 = conn.createStatement();
  424. rs1 = stat1.executeQuery(sql1);
  425. while(rs1.next()){
  426. num+=1;
  427. }
  428. } catch (Exception e) {
  429. log.error(e.getMessage());
  430. }finally{
  431. db.close(rs);
  432. db.close(stat);
  433. db.close(rs1);
  434. db.close(stat1);
  435. db.close(conn);
  436. }
  437. // log.info("获取范本条数===="+num);
  438. String result = "{\"pager.totalRows\":"+num+",\"pager.pageNo\":"+page+","+"\"rows\":" + list.toString()+ "}";
  439. // log.info(result+"=========result");
  440. return result;
  441. }
  442. /**获取短信表格
  443. *
  444. * @param recName
  445. * @param recTel
  446. * @param msg_type
  447. * @param msg_content
  448. * @param send_user
  449. * @param send_dept
  450. * @param msg_stat
  451. * @param msg_time
  452. * @return
  453. */
  454. public String getSmsGrid(String title,String recName,String recTel,String sub_stat,String msg_content,String send_user,String send_dept,String msg_stat,String msg_time,String end_time,int page,int pageSize,String id,String dept_id){
  455. String sql="SELECT TOP "+(page-1)*pageSize+","+pageSize+" A.FD_OBJECTID,A.MSG_TIME,A.REC_NAME,A.REC_USER_TEL,A.MSG_TYPE,A.MSG_STAT,A.REPLY_CONTENT,B.REAL_NAME SENDNAME,C.DEPT_NAME,A.MSG_CONTENT ,A .MSG_TITLE,A.SUB_STAT FROM SYS_MSG_MANAGE A,SYS_USER_INFO B,SYS_DEPT_USER D,SYS_DEPARTMENT C WHERE A.SEND_USER_TEL=D.USER_ID AND A.SEND_USER_TEL=B.USER_ID AND C.DEPT_ID=D.DEPT_ID AND A.IS_DEL='0' and ((a.SEND_USER_TEL='"+id+"') or (A.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='"+dept_id+"')))";
  456. String sql1 = "SELECT A.FD_OBJECTID,A.MSG_TIME,A.REC_NAME,A.REC_USER_TEL,A.MSG_TYPE,A.MSG_STAT,A.REPLY_CONTENT,B.REAL_NAME SENDNAME,C.DEPT_NAME,A.MSG_CONTENT ,A .MSG_TITLE,A.SUB_STAT FROM SYS_MSG_MANAGE A,SYS_USER_INFO B,SYS_DEPT_USER D,SYS_DEPARTMENT C WHERE A.SEND_USER_TEL=D.USER_ID AND A.SEND_USER_TEL=B.USER_ID AND C.DEPT_ID=D.DEPT_ID AND A.IS_DEL='0' and ((a.SEND_USER_TEL='"+id+"') or (A.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='"+dept_id+"')))";
  457. // String sql = "SELECT TOP "+(page-1)*pageSize+ ","+pageSize+" FD_OBJECTID,MSG_TIME,REC_NAME,REC_USER_TEL,MSG_TYPE,MSG_STAT,REAL_NAME SENDNAME ";
  458. // String sql1 ="";
  459. Connection conn = null;
  460. Statement stat = null;
  461. Statement stat1 = null;
  462. ResultSet rs = null;
  463. ResultSet rs1 = null;
  464. DbConnection db = new DbConnection();
  465. if(!"".equals(title)){
  466. sql+=" AND A.MSG_TITLE LIKE '%"+title+"%'";
  467. sql1+=" AND A.MSG_TITLE LIKE '%"+title+"%'";
  468. }
  469. if(!"".equals(recName)){
  470. sql+=" AND A.REC_NAME LIKE '%"+recName+"%'";
  471. sql1+=" AND A.REC_NAME LIKE '%"+recName+"%'";
  472. }
  473. if(!"".equals(recTel)){
  474. sql+=" AND A.REC_USER_TEL LIKE '%"+recTel+"%'";
  475. sql1+=" AND A.REC_USER_TEL LIKE '%"+recTel+"%'";
  476. }
  477. if("0".equals(sub_stat)){
  478. sql+=" AND (A.SUB_STAT IS NULL OR A.SUB_STAT='')";
  479. sql1+=" AND (A.SUB_STAT IS NULL OR A.SUB_STAT='') ";
  480. }
  481. if("1".equals(sub_stat)){
  482. sql+=" AND A.SUB_STAT ='0'";
  483. sql1+=" AND A.SUB_STAT ='0'";
  484. }
  485. if("2".equals(sub_stat)){
  486. sql +="AND A.SUB_STAT IS NOT NULL AND A.SUB_STAT <> '0'";
  487. sql1 +="AND A.SUB_STAT IS NOT NULL AND A.SUB_STAT <> '0'";
  488. }
  489. if(!"".equals(msg_content)){
  490. sql+=" AND A.MSG_CONTENT LIKE '%"+msg_content+"%'";
  491. sql1+=" AND A.MSG_CONTENT LIKE '%"+msg_content+"%'";
  492. }
  493. if(!"".equals(send_user)){
  494. sql+=" AND B.REAL_NAME LIKE '%"+send_user+"%'";
  495. sql1+=" AND B.REAL_NAME LIKE '%"+send_user+"%'";
  496. }
  497. if(!"".equals(send_dept)){
  498. sql+=" AND C.DEPT_NAME LIKE '%"+send_dept+"%'";
  499. sql1+=" AND C.DEPT_NAME LIKE '%"+send_dept+"%'";
  500. }
  501. if("1".equals(msg_stat)){
  502. /*sql+=" AND A.MSG_STAT = '"+msg_stat+"'";
  503. sql1+=" AND A.MSG_STAT = '"+msg_stat+"'";*/
  504. log.info(msg_stat+"==========");
  505. /*if(msg_stat=="0"){
  506. sql +="AND A.MSG_STAT IS NULL";
  507. sql1 +="AND A.MSG_STAT IS NULL";
  508. log.info(sql);
  509. }*/
  510. sql +="AND A.MSG_STAT = 'DELIVRD'";
  511. sql1 +="AND A.MSG_STAT = 'DELIVRD'";
  512. /*if(msg_stat=="2"){
  513. sql +="AND A.MSG_STAT IS NOT NULL AND A.MSG_STAT <> 'DELIVRD'";
  514. sql1 +="AND A.MSG_STAT IS NOT NULL AND A.MSG_STAT <> 'DELIVRD'";
  515. }*/
  516. }
  517. if("0".equals(msg_stat)){
  518. sql +="AND (A.MSG_STAT IS NULL OR A.MSG_STAT='')";
  519. sql1 +="AND (A.MSG_STAT IS NULL OR A.MSG_STAT='')";
  520. }
  521. if("2".equals(msg_stat)){
  522. sql +="AND A.MSG_STAT IS NOT NULL AND A.MSG_STAT <> 'DELIVRD'";
  523. sql1 +="AND A.MSG_STAT IS NOT NULL AND A.MSG_STAT <> 'DELIVRD'";
  524. }
  525. if(!"".equals(msg_time)&&!"".equals(end_time)){
  526. sql+="AND SUBSTR(A.MSG_TIME ,'0','10') >='"+msg_time.substring(0, 10)+"' AND SUBSTR(A.MSG_TIME ,'0','10')<='"+end_time.substring(0,10)+"'";
  527. sql1+="AND SUBSTR(A.MSG_TIME ,'0','10') >='"+msg_time.substring(0, 10)+"' AND SUBSTR(A.MSG_TIME ,'0','10')<='"+end_time.substring(0,10)+"'";
  528. }
  529. if(!"".equals(msg_time)&&"".equals(end_time)){
  530. sql +="AND SUBSTR(A.MSG_TIME ,'0','10') >='"+msg_time.substring(0,10)+"'";
  531. sql1 +="AND SUBSTR(A.MSG_TIME ,'0','10') >='"+msg_time.substring(0,10)+"'";
  532. }
  533. if("".equals(msg_time)&&!"".equals(end_time)){
  534. sql +="AND SUBSTR(A.MSG_TIME ,'0','10') <='"+end_time.substring(0,10)+"'";
  535. sql1 +="AND SUBSTR(A.MSG_TIME ,'0','10') <='"+end_time.substring(0,10)+"'";
  536. }
  537. sql += " ORDER BY MSG_TIME DESC";
  538. sql1 += " ORDER BY MSG_TIME DESC";
  539. log.info("getSmsGrid.sql===="+sql);
  540. List list = new ArrayList<String>();
  541. StringBuffer json = new StringBuffer();
  542. int num=0;
  543. try {
  544. conn = db.getConnection();
  545. stat = conn.createStatement();
  546. rs = stat.executeQuery(sql);
  547. /*String msg_status ;
  548. String sub_status ;*/
  549. while(rs.next()){
  550. /*msg_status = rs.getString("MSG_STAT");
  551. if(msg_status==null){
  552. msg_status = "发送中";
  553. }else if(msg_status=="DELIVRD"){
  554. msg_status = "发送成功";
  555. }else{
  556. msg_status = "发送失败";
  557. }*/
  558. /* sub_status = rs.getString("SUB_STAT");
  559. if(sub_status ==null){
  560. sub_status = "提交中";
  561. }else if(sub_status=="0"){
  562. sub_status = "提交成功";
  563. }else{
  564. sub_status = "提交失败";
  565. }*/
  566. json.append("{");
  567. json.append("\"FD_OBJECTID\""+":"+"\""+rs.getString("FD_OBJECTID")+"\""+",");
  568. json.append("\"MSG_TIME\""+":"+"\""+rs.getString("MSG_TIME")+"\""+",");
  569. json.append("\"REC_NAME\""+":"+"\""+rs.getString("REC_NAME")+"\""+",");
  570. json.append("\"REC_USER_TEL\""+":"+"\""+rs.getString("REC_USER_TEL")+"\""+",");
  571. json.append("\"MSG_TYPE\""+":"+"\""+rs.getString("MSG_TYPE")+"\""+",");
  572. json.append("\"MSG_STAT\""+":"+"\""+rs.getString("MSG_STAT")+"\""+",");
  573. json.append("\"SENDNAME\""+":"+"\""+rs.getString("SENDNAME")+"\""+",");
  574. json.append("\"DEPT_NAME\""+":"+"\""+rs.getString("DEPT_NAME")+"\""+",");
  575. json.append("\"MSG_CONTENT\""+":"+"\""+rs.getString("MSG_CONTENT")+"\""+",");
  576. json.append("\"MSG_TITLE\""+":"+"\""+rs.getString("MSG_TITLE")+"\""+",");
  577. json.append("\"SUB_STAT\""+":"+"\""+rs.getString("SUB_STAT")+"\""+",");
  578. json.append("\"REPLY_CONTENT\""+":"+"\""+rs.getString("REPLY_CONTENT")+"\"");
  579. json.append("},");
  580. }
  581. // 去除多余逗号
  582. if (json.lastIndexOf(",") > -1) {
  583. json.deleteCharAt(json.lastIndexOf(","));
  584. list.add(json);
  585. }
  586. stat1 = conn.createStatement();
  587. rs1 = stat1.executeQuery(sql1);
  588. while(rs1.next()){
  589. num+=1;
  590. }
  591. } catch (Exception e) {
  592. log.error(e.getMessage());
  593. }finally{
  594. db.close(rs);
  595. db.close(stat);
  596. db.close(rs1);
  597. db.close(stat1);
  598. db.close(conn);
  599. }
  600. log.info("获取短信条数===="+num);
  601. String result = "{\"pager.totalRows\":"+num+",\"pager.pageNo\":"+page+","+"\"rows\":" + list + "}";
  602. // log.info(result+"=========result");
  603. return result;
  604. }
  605. /**
  606. * 保存范本
  607. * @param user_id
  608. * @param model_title
  609. * @param model_type
  610. * @param model_content
  611. * @param model_range
  612. * @param model_time
  613. * @return
  614. * @throws Exception
  615. */
  616. public Msg saveModel(String user_id,String model_title,String model_type,String model_content,String model_range,String model_time,String model_comp,String real_name,String msg_model_dept) throws Exception{
  617. Msg m=new Msg();
  618. Connection conn = null;
  619. PreparedStatement st = null;
  620. DbConnection db = new DbConnection();
  621. try {
  622. String sql="INSERT INTO SYS_MSG_MODEL(FD_OBJECTID,MSG_MODEL_TYPE,MSG_MODEL_TITLE,MSG_MODEL_CONTENT,MSG_MODEL_RANGE,MSG_MODEL_USER,MSG_MODEL_TIME,IS_DEL,MSG_MODEL_COMP,REAL_NAME,MSG_MODEL_DEPT)VALUES(?,?,?,?,?,?,?,?,?,?,?)";
  623. conn = db.getConnection();
  624. int num=0;
  625. conn.setAutoCommit(false);
  626. st = conn.prepareStatement(sql);
  627. List<String>fdList=new ArrayList<String>();
  628. String fd_id=IdentityGenerator.getIdentityGenerator()
  629. .gerenalIdentity(778);
  630. fdList.add(fd_id);
  631. st.setString(1, fd_id);
  632. st.setString(2, model_type);
  633. // log.info("formatDate(new Date())==="+formatDate(new Date()));
  634. st.setString(3, model_title);
  635. st.setString(4,model_content);
  636. st.setString(5, model_range);
  637. st.setString(6, user_id);
  638. st.setString(7, model_time);
  639. st.setString(8, "0");
  640. st.setString(9, model_comp);
  641. st.setString(10, real_name);
  642. st.setString(11, msg_model_dept);
  643. st.executeUpdate();
  644. num++;
  645. log.info("num====="+num);
  646. log.info(sql+"====saveModel.sql");
  647. if(num==1){
  648. log.info("保存成功");
  649. conn.commit();
  650. m.setSucsess(new Boolean(true).toString());
  651. m.setInfo(Parameter.DELETE_SUCSESS);
  652. return m;
  653. }else{
  654. m.setSucsess(new Boolean(false).toString());
  655. m.setInfo(Parameter.DELETE_FAILURE);
  656. // st.executeBatch();
  657. conn.rollback();
  658. log.info("保存失败");
  659. return m;}
  660. } catch (SQLException e) {
  661. this.log.error(e.getMessage(), e);
  662. throw new ClassNotFoundException("DAO Layou: 消息范本保存", e);
  663. } finally {
  664. db.close(st);
  665. db.close(conn);
  666. }
  667. }
  668. public String formatDate(Date d) {
  669. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  670. String date = sd.format(d);
  671. return date;
  672. }
  673. public List<String> getMsgId() throws ClassNotFoundException {
  674. String sql = "SELECT FD_OBJECTID FROM SYS_MSG_MANAGE";
  675. Connection conn = null;
  676. Statement stat = null;
  677. ResultSet rs = null;
  678. DbConnection db = new DbConnection();
  679. try {
  680. conn = db.getConnection();
  681. stat = conn.createStatement();
  682. rs = stat.executeQuery(sql);
  683. List<String> list = new ArrayList();
  684. while (rs.next()) {
  685. list.add(rs.getString("FD_OBJECTID"));
  686. }
  687. return list;
  688. } catch (SQLException e) {
  689. this.log.error(e.getMessage(), e);
  690. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  691. + sql, e);
  692. } finally {
  693. db.close(rs);
  694. db.close(stat);
  695. db.close(conn);
  696. }
  697. }
  698. public List<String> getModelId() throws ClassNotFoundException {
  699. String sql = "SELECT FD_OBJECTID FROM SYS_MSG_MODEL";
  700. Connection conn = null;
  701. Statement stat = null;
  702. ResultSet rs = null;
  703. DbConnection db = new DbConnection();
  704. try {
  705. conn = db.getConnection();
  706. stat = conn.createStatement();
  707. rs = stat.executeQuery(sql);
  708. List<String> list = new ArrayList();
  709. while (rs.next()) {
  710. list.add(rs.getString("FD_OBJECTID"));
  711. }
  712. return list;
  713. } catch (SQLException e) {
  714. this.log.error(e.getMessage(), e);
  715. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  716. + sql, e);
  717. } finally {
  718. db.close(rs);
  719. db.close(stat);
  720. db.close(conn);
  721. }
  722. }
  723. public String createMsgId(List<String> list) throws ClassNotFoundException{
  724. long l=(long) ((Math.random()+1)*1000000000);
  725. String msgId=l+"";
  726. if(list.contains(msgId)){
  727. return createMsgId(list);
  728. }
  729. else{
  730. // log.info("msgid==="+msgId);
  731. return msgId;
  732. }
  733. }
  734. private void writeFile(File file, String content) throws Exception {
  735. BufferedWriter bw = null;
  736. try {
  737. bw = new BufferedWriter(new OutputStreamWriter(
  738. new FileOutputStream(file), "GB18030"));
  739. // bw = new BufferedWriter(new OutputStreamWriter(
  740. // new FileOutputStream(file), "utf-8"));
  741. bw.write(content);
  742. bw.flush();
  743. } finally {
  744. if (bw != null) {
  745. bw.close();
  746. }
  747. }
  748. }
  749. /**
  750. *
  751. * <DL>
  752. * <p>
  753. * <DD>组织短信内容</DD>
  754. * </DL>
  755. * <p>
  756. */
  757. private String createSMSContent(String tel,String fd_id, String msg) {
  758. StringBuffer sb = new StringBuffer();
  759. // 添加手机号 12位
  760. sb.append(getClientName());
  761. // 添加短信内容 200位
  762. sb.append(getSerialno(fd_id));
  763. sb.append(getSendPort());
  764. sb.append(getMobileNo(tel));
  765. sb.append(getContent(msg));
  766. sb.append(getMsgType());
  767. sb.append(getSrr());
  768. sb.append("\n");
  769. //sb.append("end");
  770. // sb.append(dealStr(msg, 200));
  771. // // 添加优先级2位
  772. // sb.append("01");
  773. // // 添加收条标志1位
  774. // sb.append("0");
  775. // // 添加机构码 8位
  776. // sb.append(dealStr(getOrgan1(), 8));
  777. return sb.toString();
  778. }
  779. /**
  780. * 生成客户端名称
  781. * @return
  782. */
  783. public String getClientName(){
  784. StringBuffer sb=new StringBuffer();
  785. sb.append("<clientname>");
  786. sb.append("S0045");
  787. sb.append("</clientname>");
  788. return sb.toString();
  789. }
  790. /**
  791. * 生成短信文件序列号
  792. * @return
  793. */
  794. public String getSerialno(String fd_id){
  795. StringBuffer sb=new StringBuffer();
  796. sb.append("<serialno>");
  797. sb.append("S004500XX");
  798. sb.append("_");
  799. sb.append(getTimeStr());
  800. sb.append("_");
  801. sb.append(fd_id);
  802. sb.append("</serialno>");
  803. return sb.toString();
  804. }
  805. /**
  806. * 生成短信文件发送端口
  807. * @return
  808. */
  809. public String getSendPort(){
  810. StringBuffer sb=new StringBuffer();
  811. sb.append("<sendport>955980045</sendport>");
  812. return sb.toString();
  813. }
  814. /**
  815. * 生成短信文件接收号码
  816. * @return
  817. */
  818. public String getMobileNo(String tel){
  819. StringBuffer sb=new StringBuffer();
  820. sb.append("<mobileno>");
  821. sb.append(tel);
  822. sb.append("</mobileno>");
  823. return sb.toString();
  824. }
  825. /**
  826. * 生成短信文件短信内容
  827. * @return
  828. */
  829. public String getContent(String content){
  830. StringBuffer sb=new StringBuffer();
  831. sb.append("<content>");
  832. sb.append(content);
  833. sb.append("</content>");
  834. return sb.toString();
  835. }
  836. /**
  837. * 生成短信文件短信类型
  838. * @return
  839. */
  840. public String getMsgType(){
  841. StringBuffer sb=new StringBuffer();
  842. sb.append("<mesgtype>1</mesgtype>");
  843. return sb.toString();
  844. }
  845. /**
  846. * 生成短信文件srr
  847. * @return
  848. */
  849. public String getSrr(){
  850. StringBuffer sb=new StringBuffer();
  851. sb.append("<srr>1</srr>");
  852. return sb.toString();
  853. }
  854. /**
  855. * 保存短信文件
  856. * @param recList
  857. * @param fdList
  858. * @param content
  859. * @return
  860. */
  861. public boolean sendNote(List<String>recList , List<String>fdList,String content) {
  862. try {
  863. // log.debug("发送短信内容" + content);
  864. long t1=System.currentTimeMillis();
  865. // 先根据类型获取接收此预警的用户群的手机号列表
  866. File smsFile = createSMSFile();
  867. StringBuffer fileContent =new StringBuffer();
  868. for(int i=0;i<recList.size();i++){
  869. fileContent.append(createSMSContent(recList.get(i), fdList.get(i),content));
  870. }
  871. fileContent.append("end");
  872. // log.info("短信文件内容====="+fileContent.toString());
  873. writeFile(smsFile, fileContent+"\n");
  874. // Process process = Runtime.getRuntime().exec("mv /home/beaimon/user/pzc/sms/"+fileName+" /home/beaimon/gts02/sms/");
  875. long t2 = System.currentTimeMillis();
  876. log.info("消耗时间为:" + (t2 - t1));
  877. } catch (Exception e) {
  878. log.error("发送短信异常 type:", e);
  879. return false;
  880. }
  881. return true;
  882. }
  883. /**
  884. * 生成超长短信序列号
  885. * @return
  886. */
  887. public String getLongSerialno (String fd_id,int i){
  888. StringBuffer sb = new StringBuffer();
  889. sb.append("<serialno>");
  890. sb.append("S004500XX");
  891. sb.append("_");
  892. sb.append(getTimeStr());
  893. sb.append("_");
  894. sb.append(fd_id);
  895. sb.append("_"+i);
  896. sb.append("</serialno>");
  897. return sb.toString();
  898. }
  899. /**
  900. * 生成超长短信客户端
  901. * @return
  902. */
  903. public String getLongClientname(){
  904. StringBuffer sb = new StringBuffer();
  905. sb.append("<clientname>");
  906. sb.append("S0045");
  907. sb.append("</clientname>");
  908. return sb.toString();
  909. }
  910. /**
  911. * 生成超长短信发送端口
  912. * @return
  913. */
  914. public String getLongSendPort(){
  915. StringBuffer sb = new StringBuffer();
  916. sb.append("<sendport>955980045</sendport>");
  917. return sb.toString();
  918. }
  919. /**
  920. * 生成超长短信接收号码
  921. */
  922. public String getLongMobile(String tel){
  923. StringBuffer sb = new StringBuffer();
  924. sb.append("<mobileno>");
  925. sb.append(tel);
  926. sb.append("</mobileno>");
  927. return sb.toString();
  928. }
  929. /**
  930. * 生成超长短信内容
  931. * @return
  932. */
  933. public String getLongContent(String content,int i,int a,int number){
  934. StringBuffer sb = new StringBuffer();
  935. sb.append("<content>");
  936. sb.append("<1>"+i+"</1>");
  937. sb.append("<2>"+a+"</2>");
  938. sb.append("<3>"+content+"</3>");
  939. sb.append("<4>"+number+"</4>");
  940. sb.append("</content>");
  941. return sb.toString();
  942. }
  943. /**
  944. * 获取超长短信类型
  945. * @return
  946. */
  947. public String getLongMsgType(){
  948. StringBuffer sb = new StringBuffer();
  949. sb.append("<mesgtype>1</mesgtype>");
  950. return sb.toString();
  951. }
  952. /**
  953. * 获取超长短信的srr
  954. */
  955. public String getLongSrr(){
  956. StringBuffer sb = new StringBuffer();
  957. sb.append("<srr>1</srr>");
  958. return sb.toString();
  959. }
  960. /**
  961. * 组装超长短信内容
  962. */
  963. public String getMsgContent(String content,String tel,String fd_id){
  964. StringBuffer sb = new StringBuffer();
  965. int length = content.length()/66+1;
  966. List<String> list = new ArrayList<String>();
  967. for(int i=0;i<length;i++){
  968. if(i==length-1){
  969. list.add(content.substring(i*66));
  970. }else{
  971. list.add(content.substring(i*66,i*66+66));
  972. }
  973. }
  974. int number=(int)(Math.random()*255);
  975. for(int j=0;j<list.size();j++){
  976. // log.info(number+"==========number");
  977. sb.append(getLongSerialno(fd_id,j));
  978. sb.append(getLongClientname());
  979. sb.append(getLongSendPort());
  980. sb.append(getLongMobile(tel));
  981. sb.append(getLongContent(list.get(j),length,j+1,number));
  982. sb.append(getLongMsgType());
  983. sb.append(getLongSrr());
  984. sb.append("\n");
  985. }
  986. //sb.append("\n");
  987. // sb.append("end");
  988. return sb.toString();
  989. }
  990. /**
  991. * 保存短信文件
  992. * @param recList
  993. * @param fdList
  994. * @param content
  995. * @return
  996. */
  997. public boolean saveMsg(List<String>recList , List<String>fdList,String content){
  998. try {
  999. // log.debug("发送短信内容" + content);
  1000. long t1=System.currentTimeMillis();
  1001. // 先根据类型获取接收此预警的用户群的手机号列表
  1002. File smsFile = createSMSFile();
  1003. StringBuffer fileContent =new StringBuffer();
  1004. for(int i=0;i<recList.size();i++){
  1005. fileContent.append(getMsgContent(content, recList.get(i),fdList.get(i))+"\n");
  1006. }
  1007. // log.info("短信文件内容====="+fileContent.toString());
  1008. writeFile(smsFile, fileContent+"\n");
  1009. // Process process = Runtime.getRuntime().exec("mv /home/beaimon/user/pzc/sms/"+fileName+" /home/beaimon/gts02/sms/");
  1010. long t2 = System.currentTimeMillis();
  1011. log.info("消耗时间为:" + (t2 - t1));
  1012. } catch (Exception e) {
  1013. log.error("发送短信异常 type:", e);
  1014. return false;
  1015. }
  1016. return true;
  1017. }
  1018. /**
  1019. *
  1020. * <DL>
  1021. * <p>
  1022. * <DD>创建文件</DD>
  1023. * </DL>
  1024. * <p>
  1025. *
  1026. * @return
  1027. */
  1028. private File createSMSFile() {
  1029. // 组装文件名
  1030. fileName = createFileName();
  1031. File smsFile = new File(getDirPath(), fileName);
  1032. if (smsFile.exists()) {
  1033. // 如果已经存在 则递归 从新获取名字 建立文件
  1034. return createSMSFile();
  1035. }
  1036. return smsFile;
  1037. }
  1038. /**
  1039. *
  1040. * <DL>
  1041. * <p>
  1042. * <DD>获得短信文件目录</DD>
  1043. * </DL>
  1044. * <p>
  1045. *
  1046. * @return
  1047. */
  1048. private String getDirPath() {
  1049. // File configDir = new File(Platform.getConfigurationLocation().getURL()
  1050. // .getFile());
  1051. //File dir = new File("D://test//t1");
  1052. /// File dir=new File("/smsclient/data/QFCS/sendfiledir");
  1053. // File dir = new File("/home/beaimon/user/pzc", "sms");
  1054. /*if (!dir.exists()) {
  1055. dir.mkdirs();
  1056. }*/
  1057. return "";
  1058. }
  1059. /**
  1060. *
  1061. * <DL>
  1062. * <p>
  1063. * <DD>组装文件名</DD>
  1064. * </DL>
  1065. * <p>
  1066. *
  1067. * @return
  1068. */
  1069. private String createFileName() {
  1070. StringBuffer sb = new StringBuffer();
  1071. //发送标识
  1072. sb.append("send");
  1073. // 时间
  1074. sb.append(getTimeStr());
  1075. // 流水号
  1076. sb.append(getRandom());
  1077. // 机构码
  1078. sb.append(".txt");
  1079. // 时间
  1080. // sb.append(getDateTime());
  1081. // // 添加序列号
  1082. // sb.append(getRandom());
  1083. return sb.toString();
  1084. }
  1085. /**
  1086. * 获取发送时间
  1087. * @return
  1088. */
  1089. public String getTimeStr(){
  1090. Date d = new Date();
  1091. SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
  1092. String timeStr=sdf.format(d);
  1093. return timeStr;
  1094. }
  1095. /**
  1096. *
  1097. * <DL>
  1098. * <p>
  1099. * <DD>获取10000-19999的随机数</DD>
  1100. * </DL>
  1101. * <p>
  1102. *
  1103. * @return
  1104. */
  1105. private static String getRandom() {
  1106. Random random = new Random();
  1107. int i = 0;
  1108. while (i < 10000||i>19999) {
  1109. i = random.nextInt(1000)+10000;
  1110. }
  1111. return "_" + i;
  1112. }
  1113. // public void run() {
  1114. // if (warnMap != null && warnMap.size() > 0) {
  1115. // for (String type : warnMap.keySet()) {
  1116. // sendNote(type, warnMap.get(type));
  1117. // }
  1118. // }
  1119. // if (smsList != null && smsList.size() > 0) {
  1120. // sendNote(smsType, smsList);
  1121. //
  1122. // }
  1123. //
  1124. // }
  1125. /**
  1126. * 拷贝文件到gtp发送目录
  1127. * @param s源文件
  1128. * @param t目标文件
  1129. */
  1130. public static void fileChannelCopy(File s, File t) {
  1131. FileInputStream fi = null;
  1132. FileOutputStream fo = null;
  1133. FileChannel in = null;
  1134. FileChannel out = null;
  1135. try {
  1136. fi = new FileInputStream(s);
  1137. fo = new FileOutputStream(t);
  1138. in = fi.getChannel();
  1139. out = fo.getChannel();
  1140. in.transferTo(0, in.size(), out);
  1141. } catch (Exception e) {
  1142. e.printStackTrace();
  1143. } finally {
  1144. try {
  1145. fi.close();
  1146. in.close();
  1147. fo.close();
  1148. out.close();
  1149. } catch (Exception e) {
  1150. e.printStackTrace();
  1151. }
  1152. }
  1153. }
  1154. public String getSysUserInfo(List<String>uidList){
  1155. StringBuffer condition=new StringBuffer();
  1156. for(int i=0;i<uidList.size();i++){
  1157. condition.append("'"+uidList.get(i)+"',");
  1158. }
  1159. if (condition.lastIndexOf(",") > -1) {
  1160. condition.deleteCharAt(condition.lastIndexOf(","));
  1161. }
  1162. String sql="SELECT * FROM SYS_USER_INFO WHERE USER_ID NOT IN("+condition+")";
  1163. List list = null;
  1164. try {
  1165. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  1166. } catch (PersistenceException e) {
  1167. log.error(e.getMessage());
  1168. }
  1169. log.info("获取范本条数===="+list.size());
  1170. String result = "{\"rows\":" + JSONArray.fromObject(list).toString() + "}";
  1171. return result;
  1172. }
  1173. /**
  1174. * 删除范本和短信
  1175. * @param fd_id
  1176. * @param stat
  1177. * @return
  1178. * @throws Exception
  1179. */
  1180. public Msg delSms(String fd_id,String stat) throws Exception{
  1181. String sql="";
  1182. // log.info("stat==="+stat);
  1183. // log.info("fd_id==="+fd_id);
  1184. Msg m=new Msg();
  1185. String []arr=fd_id.split(";");
  1186. if("".equals(stat)){
  1187. m.setSucsess(new Boolean(false).toString());
  1188. m.setInfo(Parameter.DELETE_FAILURE);
  1189. return m;
  1190. }else if("SMS".equals(stat)){
  1191. sql="UPDATE SYS_MSG_MANAGE SET IS_DEL='1' WHERE FD_OBJECTID=?";
  1192. }else if("MODEL".equals(stat)){
  1193. sql="UPDATE SYS_MSG_MODEL SET IS_DEL='1' WHERE FD_OBJECTID=?";
  1194. }else{
  1195. m.setSucsess(new Boolean(false).toString());
  1196. m.setInfo(Parameter.DELETE_FAILURE);
  1197. return m;
  1198. }
  1199. log.info(sql);
  1200. Connection conn = null;
  1201. PreparedStatement st = null;
  1202. int num=0;
  1203. DbConnection db = new DbConnection();
  1204. try {
  1205. conn = db.getConnection();
  1206. conn.setAutoCommit(false);
  1207. st = conn.prepareStatement(sql);
  1208. for(int i=0;i<arr.length;i++){
  1209. st.setString(1, arr[i]);
  1210. st.executeUpdate();
  1211. num++;
  1212. }
  1213. if(num==arr.length){
  1214. log.info("删除----num===="+num);
  1215. m.setSucsess(new Boolean(true).toString());
  1216. m.setInfo(Parameter.DELETE_SUCSESS);
  1217. conn.commit();
  1218. return m;
  1219. }else{
  1220. m.setSucsess(new Boolean(false).toString());
  1221. m.setInfo(Parameter.DELETE_FAILURE);
  1222. conn.rollback();
  1223. return m;
  1224. }
  1225. }catch (SQLException e) {
  1226. this.log.error(e.getMessage(), e);
  1227. throw new ClassNotFoundException("DAO Layou: 删除消息"
  1228. + sql, e);
  1229. } finally {
  1230. db.close(st);
  1231. db.close(conn);
  1232. }
  1233. }
  1234. // public Msg editSms(String fd_id,String title,List<String> recList,String time,String content,String sendId){
  1235. // Msg m=new Msg();
  1236. // String sql1="INSERT INTO SYS_MSG_MANAGE(REC_USER_TEL,MSG_TYPE,MSG_CONTENT,SEND_USER_TEL,MSG_STAT,MSG_TIME,FD_OBJECTID,IS_DEL,MSG_TITLE)VALUES(?,?,?,?,?,?,?,?,?)";
  1237. // String sql="UPDATE SYS_MSG_MANAGE SET ";
  1238. // return m;
  1239. // }
  1240. /**
  1241. * 修改范本
  1242. * @param fd_id
  1243. * @param user_id
  1244. * @param model_title
  1245. * @param model_type
  1246. * @param model_content
  1247. * @param model_range
  1248. * @param model_time
  1249. * @return
  1250. * @throws Exception
  1251. */
  1252. public Msg editModel(String fd_id,String model_title,String model_type,String model_content,String model_range,String model_time) throws Exception{
  1253. Msg m=new Msg();
  1254. // String sql1="INSERT INTO SYS_MSG_MODEL(FD_OBJECTID,MSG_MODEL_TYPE,MSG_MODEL_TITLE,MSG_MODEL_CONTENT,MSG_MODEL_RANGE,MSG_MODEL_USER,MSG_MODEL_TIME,IS_DEL)VALUES(?,?,?,?,?,?,?,?)";
  1255. String sql="UPDATE SYS_MSG_MODEL SET MSG_MODEL_TYPE=?,MSG_MODEL_TITLE=?,MSG_MODEL_CONTENT=?,MSG_MODEL_RANGE=?,MSG_MODEL_TIME=? WHERE FD_OBJECTID=?";
  1256. log.info(sql+"==========editModel.sql");
  1257. Connection conn = null;
  1258. PreparedStatement st = null;
  1259. int num=0;
  1260. DbConnection db = new DbConnection();
  1261. try {
  1262. conn = db.getConnection();
  1263. conn.setAutoCommit(false);
  1264. st = conn.prepareStatement(sql);
  1265. st.setString(1, model_type);
  1266. st.setString(2, model_title);
  1267. st.setString(3, model_content);
  1268. st.setString(4, model_range);
  1269. /*st.setString(5, user_id);*/
  1270. st.setString(5, model_time);
  1271. st.setString(6, fd_id);
  1272. num=st.executeUpdate();
  1273. if(num==1){
  1274. // log.info("删除----num===="+num);
  1275. m.setSucsess(new Boolean(true).toString());
  1276. m.setInfo(Parameter.DELETE_SUCSESS);
  1277. conn.commit();
  1278. return m;
  1279. }else{
  1280. m.setSucsess(new Boolean(false).toString());
  1281. m.setInfo(Parameter.DELETE_FAILURE);
  1282. conn.rollback();
  1283. return m;
  1284. }
  1285. }catch (SQLException e) {
  1286. this.log.error(e.getMessage(), e);
  1287. throw new ClassNotFoundException("DAO Layou:更新MODEL"
  1288. + sql, e);
  1289. } finally {
  1290. db.close(st);
  1291. db.close(conn);
  1292. }
  1293. }
  1294. //获取登录人员
  1295. public String getPeople(String real_name,String dept ,String comp ,String mobile,int page,int pageSize,String comp_id){
  1296. String sql="select top "+(page-1)*pageSize+","+pageSize+" a.real_name , a.fd_objectid , a.user_id, a.mobile , c.dept_name dept ,c.corp_name ,c.dept_id from "
  1297. + " sys_user_info a, sys_dept_user b ,sys_department c where (( a.user_id = b.user_id"
  1298. + " and b.dept_id = c.dept_id and c.corp_id='"+comp_id+"') or ( a.user_id = b.user_id"
  1299. + " and b.dept_id = c.dept_id and c.parent_id='"+comp_id+"'))";
  1300. log.info(sql+"=======getPeoplesql");
  1301. String sql1 = "select a.real_name , a.fd_objectid , a.user_id, a.mobile , c.dept_name dept, c.corp_name ,c.dept_id from "
  1302. + " sys_user_info a, sys_dept_user b ,sys_department c where (( a.user_id = b.user_id"
  1303. + " and b.dept_id = c.dept_id and c.corp_id='"+comp_id+"') or ( a.user_id = b.user_id"
  1304. + " and b.dept_id = c.dept_id and c.parent_id='"+comp_id+"'))";
  1305. Connection conn = null;
  1306. Statement stat = null;
  1307. Statement stat1 = null;
  1308. ResultSet rs = null;
  1309. ResultSet rs1 = null;
  1310. DbConnection db = new DbConnection();
  1311. int num = 0;
  1312. if(!"".equals(real_name)){
  1313. sql+=" AND A.REAL_NAME LIKE '%"+real_name+"%'";
  1314. sql1+=" AND A.REAL_NAME LIKE '%"+real_name+"%'";
  1315. }
  1316. if(!"".equals(dept)){
  1317. sql+=" AND C.DEPT_NAME LIKE '%"+dept+"%'";
  1318. sql1+=" AND C.DEPT_NAME LIKE '%"+dept+"%'";
  1319. }
  1320. if(!"".equals(comp)){
  1321. sql+=" AND C.CORP_NAME LIKE '%"+comp+"%'";
  1322. sql1+=" AND C.CORP_NAME LIKE '%"+comp+"%'";
  1323. }
  1324. if(!"".equals(mobile)){
  1325. sql+=" AND A.MOBILE LIKE '%"+mobile+"%'";
  1326. sql1+=" AND A.MOBILE LIKE '%"+mobile+"%'";
  1327. }
  1328. // log.info("getpeope===="+sql);
  1329. // log.info("getpeope1===="+sql1);
  1330. List list = new ArrayList<String>();
  1331. StringBuffer sb = new StringBuffer();
  1332. try {
  1333. //list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  1334. conn = db.getConnection();
  1335. stat = conn.createStatement();
  1336. rs = stat.executeQuery(sql);
  1337. while(rs.next()){
  1338. sb.append("{");
  1339. sb.append("\"FD_OBJECTID\""+":"+"\""+rs.getString("FD_OBJECTID")+"\""+",");
  1340. sb.append("\"REAL_NAME\""+":"+"\""+rs.getString("REAL_NAME")+"\""+",");
  1341. sb.append("\"USER_ID\""+":"+"\""+rs.getString("USER_ID")+"\""+",");
  1342. sb.append("\"MOBILE\""+":"+"\""+rs.getString("MOBILE")+"\""+",");
  1343. sb.append("\"DEPT\""+":"+"\""+rs.getString("DEPT")+"\""+",");
  1344. sb.append("\"DEPT_NAME\""+":"+"\""+rs.getString("CORP_NAME")+"\"");
  1345. sb.append("},");
  1346. }
  1347. if(sb.lastIndexOf(",")>-1){
  1348. sb.deleteCharAt(sb.lastIndexOf(","));
  1349. }
  1350. list.add(sb);
  1351. stat1 = conn.createStatement();
  1352. rs1 = stat1.executeQuery(sql1);
  1353. while(rs1.next()){
  1354. num+=1;
  1355. }
  1356. } catch (Exception e) {
  1357. log.error(e.getMessage());
  1358. e.printStackTrace();
  1359. }finally{
  1360. db.close(rs);
  1361. db.close(stat);
  1362. db.close(rs1);
  1363. db.close(stat1);
  1364. db.close(conn);
  1365. }
  1366. // log.info("获取人员条数===="+num);
  1367. String result = "{\"pager.totalRows\":"+num+",\"pager.pageNo\":"+page+","+"\"rows\":" + list.toString() + "}";
  1368. // log.info(result+"==========result");
  1369. return result;
  1370. }
  1371. public String getDeptName(String id,String name){
  1372. String result="";
  1373. String sql="select b.dept_name from sys_department a,sys_department b where a.parent_id=b.dept_id and a.dept_id='"+id+"'";
  1374. // log.info("getDeptName======"+sql);
  1375. try {
  1376. SysModel sysmodel = ModelFactory.getSysmodel();
  1377. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1378. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  1379. if(tempList==null||tempList.size()==0){
  1380. result=name;
  1381. }else{
  1382. result=tempList.get(0)[0];
  1383. }
  1384. } catch (PersistenceException e) {
  1385. log.error(e.getMessage());
  1386. }
  1387. // log.info(result+"========getDeptnameResult");
  1388. return result;
  1389. }
  1390. public boolean updateStat(String statKey, String statVal,String fd_objectid){
  1391. boolean flag = false;
  1392. Connection conn = null;
  1393. PreparedStatement pstm = null;
  1394. DbConnection db = new DbConnection();
  1395. // DaMengBasicApp app = new DaMengBasicApp();
  1396. try {
  1397. String sql = "update SYS_MSG_MANAGE set "+statKey+" = ? where fd_objectid = ? ";
  1398. //conn = db.getConnection();
  1399. conn = db.getConnection();
  1400. pstm = conn.prepareStatement(sql);
  1401. pstm.setString(1, statVal);
  1402. pstm.setString(2,fd_objectid);
  1403. pstm.executeUpdate();
  1404. conn.commit();
  1405. flag = true;
  1406. }catch(Exception e){
  1407. e.printStackTrace();
  1408. }finally{
  1409. db.close(pstm);
  1410. db.close(conn);
  1411. }
  1412. return flag;
  1413. }
  1414. public void saveRevSms(String serialno,String content){
  1415. // log.info("serialno:"+serialno+",clientname:"+clientname+",sendport:"+sendport+",mobileno:"+mobileno+",content:"+content+",crttime:"+crttime);
  1416. Msg m=new Msg();
  1417. Connection conn = null;
  1418. PreparedStatement st = null;
  1419. // DbConnection db = new DbConnection();
  1420. DbConnection db = new DbConnection();
  1421. try {
  1422. // String sql = "INSERT INTO SYS_MSG_MANAGE(REC_USER_TEL,MSG_TYPE,MSG_CONTENT,SEND_USER_TEL,MSG_STAT,MSG_TIME,FD_OBJECTID,IS_DEL,MSG_TITLE,SUB_STAT)VALUES(?,?,?,?,?,?,?,?,?,?)";
  1423. String sql="update sys_msg_manage set reply_content=reply_content||?||'\n' where fd_objectid=?";
  1424. //conn = db.getConnection();
  1425. conn = db.getConnection();
  1426. conn.setAutoCommit(false);
  1427. st = conn.prepareStatement(sql);
  1428. st.setString(1, content+"\n");
  1429. st.setString(2, serialno);
  1430. st.executeUpdate();
  1431. conn.commit();
  1432. conn.setAutoCommit(true);
  1433. } catch (SQLException e) {
  1434. this.log.error(e.getMessage(), e);
  1435. } /*catch (ClassNotFoundException e) {
  1436. e.printStackTrace();*/
  1437. //}
  1438. catch (Exception e) {
  1439. e.printStackTrace();
  1440. } finally {
  1441. db.close(st);
  1442. db.close(conn);
  1443. }
  1444. }
  1445. /**
  1446. * 增加常用联系人
  1447. * @return
  1448. */
  1449. public Msg addContact(String user_id,String contact_user_id,String contact_user_name,String contact_dept,String contact_comp,String contact_tel){
  1450. Msg m=new Msg();
  1451. String sql="insert into SMS_COMMON_USER_CONTACT(FD_OBJECTID,MSG_USER_ID,CONTACT_USER_ID,CONTACT_USER_NAME,CONTACT_DEPT,CONTACT_COMP,CONTACT_TEL,UPDATEDATE,IS_DEL) values(?,?,?,?,?,?,?,?,?)";
  1452. String[]contact_id=contact_user_id.split(",");
  1453. String[]contact_name=contact_user_name.split(",");
  1454. String[]dept=contact_dept.split(",");
  1455. String[]comp=contact_comp.split(",");
  1456. String[]tel=contact_tel.split(",");
  1457. Connection conn = null;
  1458. PreparedStatement st = null;
  1459. DbConnection db = new DbConnection();
  1460. try {
  1461. conn = db.getConnection();
  1462. int num=0;
  1463. conn.setAutoCommit(false);
  1464. st = conn.prepareStatement(sql);
  1465. SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1466. for(int i=0;i<contact_id.length;i++){
  1467. st.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(337));
  1468. st.setString(2, user_id);
  1469. st.setString(3, contact_id[i]);
  1470. st.setString(4, contact_name[i]);
  1471. st.setString(5, dept[i]);
  1472. st.setString(6, comp[i]);
  1473. st.setString(7, tel[i]);
  1474. st.setString(8, sdf.format(new Date()));
  1475. st.setString(9, "0");
  1476. st.executeUpdate();
  1477. num++;
  1478. }
  1479. if(num==contact_id.length){
  1480. log.info("保存成功");
  1481. conn.commit();
  1482. m.setSucsess(new Boolean(true).toString());
  1483. m.setInfo(Parameter.DELETE_SUCSESS);
  1484. return m;
  1485. }else{
  1486. m.setSucsess(new Boolean(false).toString());
  1487. m.setInfo(Parameter.DELETE_FAILURE);
  1488. // st.executeBatch();
  1489. conn.rollback();
  1490. log.info("保存失败");
  1491. return m;
  1492. }
  1493. } catch (ClassNotFoundException e) {
  1494. e.printStackTrace();
  1495. } catch (SQLException e) {
  1496. e.printStackTrace();
  1497. }finally{
  1498. db.close(st);
  1499. db.close(conn);
  1500. }
  1501. return m;
  1502. }
  1503. public String getContactList(String user_id){
  1504. String result="";
  1505. String sql="select CONTACT_USER_ID from SMS_COMMON_USER_CONTACT where MSG_USER_ID='"+user_id+"' and is_del='0'";
  1506. try {
  1507. List list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  1508. if(list!=null&&list.size()>0){
  1509. result="{\"list\":"+JSONArray.fromObject(list).toString()+"}";
  1510. }
  1511. } catch (PersistenceException e) {
  1512. e.printStackTrace();
  1513. }
  1514. return result;
  1515. }
  1516. public String getContactTel(String user_id){
  1517. String result = "";
  1518. String sql = "select group_people_tel from sms_contact_group where user_id ='"+user_id+"' and is_del='0'";
  1519. try {
  1520. List list = PersistenceFactory.getInstance(ModelFactory.getSysmodel()).getSearchResultToMap(99, sql);
  1521. if(list!=null&&list.size()>0){
  1522. result="{\"list\":"+JSONArray.fromObject(list).toString()+"}";
  1523. }
  1524. } catch (PersistenceException e) {
  1525. e.printStackTrace();
  1526. }
  1527. return result;
  1528. }
  1529. public String getMsgContents(String fd_id){
  1530. String result = "";
  1531. String sql = "select msg_content from sys_msg_manage where fd_objectid = ? and is_del=?";
  1532. Connection conn = null;
  1533. PreparedStatement ps = null;
  1534. ResultSet rs = null;
  1535. List<String> list = new ArrayList<String>();
  1536. DbConnection db = new DbConnection();
  1537. StringBuffer sb = new StringBuffer();
  1538. try {
  1539. conn = db.getConnection();
  1540. ps = conn.prepareStatement(sql);
  1541. ps.setString(1, fd_id);
  1542. ps.setString(2, "0");
  1543. rs = ps.executeQuery();
  1544. while(rs.next()){
  1545. sb.append("{");
  1546. sb.append("\"MSG_CONTENT\""+":"+"\""+rs.getString("MSG_CONTENT")+"\"");
  1547. sb.append("},");
  1548. }
  1549. if(sb.lastIndexOf(",")>-1){
  1550. sb.deleteCharAt(sb.lastIndexOf(","));
  1551. list.add(sb.toString());
  1552. }
  1553. } catch (ClassNotFoundException e) {
  1554. log.error(e.getMessage(),e);
  1555. } catch (SQLException e) {
  1556. log.error(e.getMessage(),e);
  1557. }finally{
  1558. db.close(rs);
  1559. db.close(ps);
  1560. db.close(conn);
  1561. }
  1562. result = "{\"rows\":"+list+"}";
  1563. // log.info(result+"=====getMsgs");
  1564. return result;
  1565. }
  1566. public String getMsgContentInfo(String fd_id){
  1567. String result = "";
  1568. String sql = "select msg_content,rec_name,rec_user_tel,msg_stat,real_name,msg_time from sys_msg_manage where fd_objectid = ? and is_del=?";
  1569. Connection conn = null;
  1570. PreparedStatement ps = null;
  1571. ResultSet rs = null;
  1572. List<String> list = new ArrayList<String>();
  1573. DbConnection db = new DbConnection();
  1574. StringBuffer sb = new StringBuffer();
  1575. try {
  1576. conn = db.getConnection();
  1577. ps = conn.prepareStatement(sql);
  1578. ps.setString(1, fd_id);
  1579. ps.setString(2, "0");
  1580. rs = ps.executeQuery();
  1581. while(rs.next()){
  1582. sb.append("{");
  1583. sb.append("\"MSG_CONTENT\""+":"+"\""+rs.getString("MSG_CONTENT")+"\",");
  1584. sb.append("\"REC_NAME\""+":"+"\""+rs.getString("REC_NAME")+"\",");
  1585. sb.append("\"REC_USER_TEL\""+":"+"\""+rs.getString("REC_USER_TEL")+"\",");
  1586. sb.append("\"MSG_STAT\""+":"+"\""+rs.getString("MSG_STAT")+"\",");
  1587. sb.append("\"REAL_NAME\""+":"+"\""+rs.getString("REAL_NAME")+"\",");
  1588. sb.append("\"MSG_TIME\""+":"+"\""+rs.getString("MSG_TIME")+"\"");
  1589. sb.append("},");
  1590. }
  1591. if(sb.lastIndexOf(",")>-1){
  1592. sb.deleteCharAt(sb.lastIndexOf(","));
  1593. list.add(sb.toString());
  1594. }
  1595. } catch (ClassNotFoundException e) {
  1596. log.error(e.getMessage(),e);
  1597. } catch (SQLException e) {
  1598. log.error(e.getMessage(),e);
  1599. }finally{
  1600. db.close(rs);
  1601. db.close(ps);
  1602. db.close(conn);
  1603. }
  1604. result = "{\"rows\":"+list+"}";
  1605. // log.info(result+"=====getMsgs");
  1606. return result;
  1607. }
  1608. //生成短信的fd_id
  1609. public String getFdId(int classid,int i){
  1610. /*Random r = new Random();*/
  1611. /*int i = r.nextInt(1001);*/
  1612. long time = System.currentTimeMillis()+(classid*i);
  1613. String result = String.valueOf(classid)+time;
  1614. return result;
  1615. }
  1616. public String getPepTel(String comp_id){
  1617. String sql = " select a.real_name,a.MOBILE from sys_user_info a,SYS_USER_ROLE_REL b,sys_department c"
  1618. + " where a.user_id=b.USER_ID and b.ROLE_ID ='R002105430205' and a.dept_id = c.dept_id and c.corp_id = ? and a.MOBILE is not null";
  1619. List<Map<String,String>> list = null;
  1620. String peoples = "";
  1621. String tels = "";
  1622. try {
  1623. list = new ORGTemplate().query(sql, comp_id);
  1624. if(list!=null && list.size()>0){
  1625. for(int i=0;i<list.size();i++){
  1626. Map<String,String> map = new HashMap<String,String>();
  1627. map = list.get(i);
  1628. peoples += map.get("REAL_NAME")+";";
  1629. tels += map.get("MOBILE")+";";
  1630. }
  1631. }
  1632. } catch (SQLException e) {
  1633. // TODO Auto-generated catch block
  1634. e.printStackTrace();
  1635. }
  1636. return peoples+":"+tels;
  1637. }
  1638. }