e232035226c54c866d0cd2622124a4fe3cc8647f.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. package com.sinosoft.lz.system.sms.service;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.text.SimpleDateFormat;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10. import javax.ws.rs.POST;
  11. import javax.ws.rs.Path;
  12. import javax.ws.rs.ProduceMime;
  13. import net.sf.json.JSONArray;
  14. import net.sf.json.JSONObject;
  15. import org.apache.log4j.Logger;
  16. import com.formaction.Parameter;
  17. import com.formaction.Utils;
  18. import com.formaction.vo.Msg;
  19. import com.persistence.DbConnection;
  20. import com.persistence.service.PersistenceFactory;
  21. import com.persistence.service.SysPersistence;
  22. import com.persistence.service.assitant.generator.IdentityGenerator;
  23. import com.persistence.service.exception.PersistenceException;
  24. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  25. import com.sinosoft.em.event.service.EventServiceImpl;
  26. import com.sinosoft.lz.system.sms.vo.SearchPeople;
  27. import com.sinosoft.lz.system.sms.vo.SelectPeopleTree;
  28. import com.sinosoft.lz.system.sms.vo.Tree;
  29. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  30. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  31. @Path("/GetDeptTreeService/")
  32. public class GetDeptTreeService {
  33. private static final Logger log = Logger.getLogger(EventServiceImpl.class);
  34. /*private static SysModel sysmodel = ModelFactory.getSysmodel();
  35. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);*/
  36. @POST
  37. @ProduceMime("application/json")
  38. @Path("/getDeptTree/")
  39. public String getJGpeopleTrees(String params){
  40. Tree t = new Tree();
  41. String id=Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
  42. String user_id = Utils.getParameter("user_id", params) == null ? "" : Utils.getParameter("user_id", params);
  43. if(id==null||"".equals(id)){
  44. t.setTreeNodes(getRootTree());
  45. List<Object>l4=getRootTree();
  46. List<Object>l5=getUserContactPeople(user_id);
  47. for(int i=0;i<l4.size();i++){
  48. l5.add(l4.get(i));
  49. }
  50. t.setTreeNodes(l5);
  51. }else{
  52. List<Object>l1=getChildDeptTree(id);
  53. List<Object>l2=getChildPeopleTree(id);
  54. for(int i=0;i<l2.size();i++){
  55. l1.add(l2.get(i));
  56. }
  57. t.setTreeNodes(l1);
  58. }
  59. log.info(JSONObject.fromObject(t).toString());
  60. return JSONObject.fromObject(t).toString();
  61. }
  62. @POST
  63. @ProduceMime("application/json")
  64. @Path("/createContact/")
  65. public Msg createContacts(String params){
  66. String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
  67. String contactId = Utils.getParameter("contactId", params) == null ? "" : Utils.getParameter("contactId", params);
  68. Msg m = null;
  69. try {
  70. m = createContact(userId,contactId);
  71. } catch (ClassNotFoundException e) {
  72. e.printStackTrace();
  73. }
  74. return m;
  75. }
  76. @POST
  77. @ProduceMime("application/json")
  78. @Path("/delUserContacts/")
  79. public Msg delUserContacts(String params){
  80. log.info(1+"===============aaaccc");
  81. Msg m = null;
  82. String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
  83. String contactId = Utils.getParameter("contactId", params) == null ? "" : Utils.getParameter("contactId", params);
  84. try {
  85. m = delUserContact("1",userId,contactId);
  86. } catch (ClassNotFoundException e) {
  87. e.printStackTrace();
  88. }
  89. return m;
  90. }
  91. @POST
  92. @ProduceMime("application/json")
  93. @Path("/getUserTree/")
  94. public String getUserTree(String params){
  95. Tree t = new Tree();
  96. String id=Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
  97. if(id==null||"".equals(id)){
  98. t.setTreeNodes(getRootTree());
  99. }else{
  100. List<Object>l1=getChildDeptTree(id);
  101. List<Object>l2=getChildPeopleTree(id);
  102. for(int i=0;i<l2.size();i++){
  103. l1.add(l2.get(i));
  104. }
  105. t.setTreeNodes(l1);
  106. }
  107. log.info(JSONObject.fromObject(t).toString());
  108. return JSONObject.fromObject(t).toString();
  109. }
  110. public boolean checkParent(String dept_id){
  111. boolean flag=false;
  112. SysModel sysmodel = ModelFactory.getSysmodel();
  113. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  114. String sql="select dept_id from sys_department where parent_id='"+dept_id+"' union select b.user_id dept_id from sys_user_info b where b.dept_id='"+dept_id+"'";
  115. try {
  116. List<String[]> list = persistence.getSearchResult(779, sql);
  117. if(list!=null&&list.size()>0){
  118. flag=true;
  119. }
  120. } catch (PersistenceException e) {
  121. e.printStackTrace();
  122. }
  123. return flag;
  124. }
  125. public List<Object>getRootTree(){
  126. SysModel sysmodel = ModelFactory.getSysmodel();
  127. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  128. List<Object>tempList=new ArrayList<Object>();
  129. String sql="select dept_id,dept_name from sys_department where dept_id='C984DC9C294A486096C25FAA78C99AED'";
  130. List<String[]> list=new ArrayList<String[]>();
  131. try {
  132. list = persistence.getSearchResult(99, sql);
  133. for(int i=0;i<list.size();i++){
  134. String[]arr=list.get(i);
  135. SelectPeopleTree pepTree = new SelectPeopleTree();
  136. pepTree.setName(arr[1]);
  137. pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
  138. pepTree.setId(arr[0]);
  139. pepTree.setParentId("1");
  140. pepTree.setTitle(arr[1]);
  141. pepTree.setType("corp");
  142. if(checkParent(arr[0])){
  143. pepTree.setIsParent("true");
  144. }else{
  145. pepTree.setIsParent("false");
  146. }
  147. tempList.add(pepTree);
  148. }
  149. } catch (PersistenceException e) {
  150. e.printStackTrace();
  151. }
  152. return tempList;
  153. }
  154. public List<Object> getChildDeptTree(String dept_id){
  155. List<Object>tempList=new ArrayList<Object>();
  156. SysModel sysmodel = ModelFactory.getSysmodel();
  157. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  158. String sql="select dept_id,dept_name from sys_department where parent_id='"+dept_id+"'";
  159. try {
  160. List<String[]> list = persistence.getSearchResult(779, sql);
  161. if(list!=null&&list.size()>0){
  162. for(int i=0;i<list.size();i++){
  163. String[]arr=list.get(i);
  164. SelectPeopleTree pepTree = new SelectPeopleTree();
  165. pepTree.setName(arr[1]);
  166. pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
  167. pepTree.setId(arr[0]);
  168. pepTree.setParentId("1");
  169. pepTree.setTitle(arr[1]);
  170. pepTree.setType("corp");
  171. if(checkParent(arr[0])){
  172. pepTree.setIsParent("true");
  173. }else{
  174. pepTree.setIsParent("false");
  175. }
  176. tempList.add(pepTree);
  177. }
  178. }
  179. } catch (PersistenceException e) {
  180. e.printStackTrace();
  181. }
  182. return tempList;
  183. }
  184. public List<Object> getChildPeopleTree(String dept_id){
  185. List<Object>tempList=new ArrayList<Object>();
  186. SysModel sysmodel = ModelFactory.getSysmodel();
  187. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  188. String sql="select distinct b.user_id,b.dept_id,b.real_name,b.user_id from sys_user_info b where b.dept_id='"+dept_id+"'";
  189. try {
  190. List<String[]> list = persistence.getSearchResult(779, sql);
  191. if(list!=null&&list.size()>0){
  192. for(int i=0;i<list.size();i++){
  193. String[]arr=list.get(i);
  194. SelectPeopleTree pepTree = new SelectPeopleTree();
  195. pepTree.setName(arr[2]);
  196. /*pepTree.setTel(arr[3]);*/
  197. pepTree.setIcon("/nwyj/scripts/qui/libs/icons/user_group.gif");
  198. pepTree.setId(arr[3]);
  199. pepTree.setParentId(arr[1]);
  200. pepTree.setTitle(arr[2]);
  201. pepTree.setIsParent("false");
  202. pepTree.setType("people"+arr[3]);
  203. tempList.add(pepTree);
  204. }
  205. }
  206. } catch (PersistenceException e) {
  207. e.printStackTrace();
  208. }
  209. return tempList;
  210. }
  211. public List<Object> getUserContactPeople(String userId){
  212. List<Object>tempList=new ArrayList<Object>();
  213. SysModel sysmodel = ModelFactory.getSysmodel();
  214. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  215. String sql = "select t.fd_objectid,t.user_id,t.last_contacttime,t.user_contact_id,t.real_name from (SELECT a.FD_OBJECTID,a.USER_ID,a.last_contacttime,a.USER_CONTACT_ID,b.real_name FROM SYS_USER_CONTACTS a,sys_user_info b WHERE a.USER_ID='"
  216. + userId
  217. + "' and a.USER_CONTACT_ID=b.user_id and a.is_del='0' ORDER BY TO_DATE(a.LAST_CONTACTTIME,'YYYY-MM-DD HH24:MI:SS') desc)t where ROWNUM<50 ";
  218. log.info(sql+"================sql111");
  219. List<String[]> list;
  220. try {
  221. list = persistence.getSearchResult(99, sql);
  222. SelectPeopleTree pepTree = new SelectPeopleTree();
  223. pepTree.setIcon("/nwyj/scripts/qui/libs/icons/home.gif");
  224. pepTree.setId("0_cylxr");
  225. pepTree.setName("最近联系人");
  226. pepTree.setParentId("0");
  227. pepTree.setType("corp");
  228. if(list!=null&&list.size()>0){
  229. pepTree.setIsParent("true");
  230. pepTree.setOpen("true");
  231. }else{
  232. pepTree.setIsParent("false");
  233. SelectPeopleTree spt = new SelectPeopleTree();
  234. spt.setIcon("/nwyj/scripts/qui/libs/icons/add.png");
  235. spt.setId("1_xzz");
  236. spt.setNocheck("true");
  237. spt.setIsParent("false");
  238. spt.setName("新增最近联系人");
  239. spt.setTitle("新增最近联系人");
  240. spt.setClick("addUserContact()");
  241. spt.setParentId("0_cylxr");
  242. spt.setType("addContact");
  243. tempList.add(spt);
  244. }
  245. tempList.add(pepTree);
  246. String parentId= "0_cylxr";
  247. if(list!=null&&list.size()>0){
  248. for(int i=0;i<list.size();i++){
  249. String []arr=list.get(i);
  250. SelectPeopleTree spt = new SelectPeopleTree();
  251. spt.setName(arr[4]);
  252. spt.setIcon("/nwyj/scripts/qui/libs/icons/user_group.gif");
  253. spt.setId(arr[3]);
  254. spt.setParentId(parentId);
  255. spt.setTitle(arr[4]);
  256. spt.setType(arr[3]+"people_cylxr");
  257. tempList.add(spt);
  258. }
  259. SelectPeopleTree spt = new SelectPeopleTree();
  260. spt.setIcon("/nwyj/scripts/qui/libs/icons/add.png");
  261. spt.setId("1_xzz");
  262. spt.setNocheck("true");
  263. spt.setIsParent("false");
  264. spt.setName("新增最近联系人");
  265. spt.setTitle("新增最近联系人");
  266. spt.setClick("addUserContact()");
  267. spt.setParentId("0_cylxr");
  268. spt.setType("addContact");
  269. tempList.add(spt);
  270. }
  271. } catch (PersistenceException e) {
  272. e.printStackTrace();
  273. }
  274. return tempList;
  275. }
  276. @POST
  277. @ProduceMime("application/json")
  278. @Path("/getPeople/")
  279. public String getPeople(String params){
  280. String pageSize = Utils.getParameter("pageSize", params) == null ? "10" : Utils
  281. .getParameter("pageSize", params);
  282. String page = Utils.getParameter("page", params) == null ? "1" : Utils
  283. .getParameter("page", params);
  284. String name = Utils.getParameter("name", params) == null ? "" : Utils
  285. .getParameter("name", params);
  286. String id = Utils.getParameter("id", params) == null ? "" : Utils
  287. .getParameter("id", params);
  288. String result = "";
  289. try {
  290. result = getPeople(name,Integer.parseInt(pageSize),Integer.parseInt(page),id);
  291. } catch (NumberFormatException e) {
  292. log.info(e.getMessage(),e);
  293. } catch (PersistenceException e) {
  294. log.info(e.getMessage(),e);
  295. }
  296. return result;
  297. }
  298. public String getPeople(String name,int pageSize,int page,String id) throws PersistenceException{
  299. if(name.contains("'")){
  300. name = name.replaceAll("'", "");
  301. }
  302. String sql = "select distinct top "+(page-1)*pageSize+","+pageSize+" b.user_id,b.dept_id,b.real_name from sys_user_info b where b.real_name like ?";
  303. String sql1 = "select distinct b.user_id,b.dept_id,b.real_name from sys_user_info b where b.real_name like ?";
  304. StringBuffer sb = new StringBuffer();
  305. if(!"".equals(id)){
  306. id = id.substring(0, id.lastIndexOf(","));
  307. for(int i=0;i<id.split(",").length;i++){
  308. sb.append("?,");
  309. }
  310. sb.deleteCharAt(sb.lastIndexOf(","));
  311. sql+="and b.user_id not in ("+sb.toString()+")";
  312. sql1 += " and b.user_id not in ("+sb.toString()+")";
  313. }
  314. String sql2 = "select distinct count(*) from ("+sql1+")";
  315. List<String[]> list1 = null;
  316. List<String[]> list2 = null;
  317. if(!"".equals(id)){
  318. try {
  319. list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%",id+"_needUsein");
  320. list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%",id+"_needUsein");
  321. } catch (SQLException e) {
  322. e.printStackTrace();
  323. }
  324. }else{
  325. try {
  326. list1 = new ORGTemplate().getSearchResult(sql,"%"+name+"%");
  327. list2 = new ORGTemplate().getSearchResult(sql2,"%"+name+"%");
  328. } catch (SQLException e) {
  329. e.printStackTrace();
  330. }
  331. }
  332. List<Object> list = new ArrayList<Object>();
  333. Tree t = new Tree();
  334. SearchPeople sp = null;
  335. for(String[] s:list1){
  336. sp = new SearchPeople();
  337. sp.setKey(s[2]);
  338. sp.setValue(s[0]);
  339. list.add(sp);
  340. }
  341. String totalRows = list2.get(0)[0];
  342. t.setTreeNodes(list);
  343. t.setTotalRows(totalRows);
  344. return JSONObject.fromObject(t).toString();
  345. }
  346. //删除常用联系人
  347. public Msg delUserContact(String...args) throws ClassNotFoundException{
  348. String sql = "update SYS_USER_CONTACTS set is_del=? where user_id=? and user_contact_id =?";
  349. Connection conn = null;
  350. PreparedStatement ps = null;
  351. DbConnection db = new DbConnection();
  352. Msg m = new Msg();
  353. try {
  354. conn = db.getConnection();
  355. conn.setAutoCommit(false);
  356. ps = conn.prepareStatement(sql);
  357. if(args!=null&&args.length>0){
  358. for(int i=0;i<args.length;i++){
  359. ps.setString(i+1, args[i]);
  360. }
  361. }
  362. ps.executeUpdate();
  363. conn.commit();
  364. m.setSucsess(new Boolean(true).toString());
  365. m.setInfo(Parameter.DELETE_SUCSESS);
  366. } catch (SQLException e) {
  367. log.info(e.getMessage(),e);
  368. m.setSucsess(new Boolean(false).toString());
  369. m.setInfo(Parameter.DELETE_FAILURE);
  370. }finally{
  371. db.close(ps);
  372. db.close(conn);
  373. }
  374. return m;
  375. }
  376. @POST
  377. @ProduceMime("application/json")
  378. @Path("/getgetUserContactIds/")
  379. public String getgetUserContactIds(String params){
  380. String result = "";
  381. String userId = Utils.getParameter("userId", params) == null ? "" : Utils.getParameter("userId", params);
  382. try {
  383. result = getUserContactId(userId);
  384. } catch (ClassNotFoundException e) {
  385. e.printStackTrace();
  386. }
  387. return result;
  388. }
  389. public String getUserContactId(String userId) throws ClassNotFoundException{
  390. String sql = "select user_contact_id from sys_user_contacts where user_id = ? and is_del = ?";
  391. Connection conn = null;
  392. PreparedStatement ps = null;
  393. ResultSet rs = null;
  394. DbConnection db = new DbConnection();
  395. List<String> list = new ArrayList<String>();
  396. try {
  397. conn = db.getConnection();
  398. conn.setAutoCommit(false);
  399. ps = conn.prepareStatement(sql);
  400. ps.setString(1, userId);
  401. ps.setString(2, "0");
  402. rs = ps.executeQuery();
  403. while (rs.next()) {
  404. list.add(rs.getString("user_contact_id"));
  405. }
  406. } catch (SQLException e) {
  407. log.info(e.getMessage(),e);
  408. }finally{
  409. try {
  410. if(rs!=null){
  411. rs.close();
  412. }
  413. } catch (SQLException e) {
  414. e.printStackTrace();
  415. }
  416. db.close(ps);
  417. db.close(conn);
  418. }
  419. return JSONArray.fromObject(list).toString();
  420. }
  421. public Msg createContact(String userId,String contactId) throws ClassNotFoundException{
  422. String sql = "insert into sys_user_contacts values(?,?,?,?,?)";
  423. String[] contactArr = null;
  424. Msg m = new Msg();
  425. if(contactId!=null&&!"".equals(contactId)){
  426. contactArr = contactId.split(",");
  427. }
  428. Connection conn = null;
  429. PreparedStatement ps = null;
  430. DbConnection db = new DbConnection();
  431. try {
  432. if(contactArr!=null&&contactArr.length>0){
  433. conn = db.getConnection();
  434. conn.setAutoCommit(false);
  435. ps = conn.prepareStatement(sql);
  436. for(int i=0;i<contactArr.length;i++){
  437. ps.setString(1, IdentityGenerator.getIdentityGenerator().gerenalIdentity(99));
  438. ps.setString(2, userId);
  439. ps.setString(3, contactArr[i]);
  440. ps.setString(4, format(new Date()));
  441. ps.setString(5, "0");
  442. ps.executeUpdate();
  443. }
  444. m.setSucsess(new Boolean(true).toString());
  445. m.setInfo(Parameter.DELETE_SUCSESS);
  446. conn.commit();
  447. }
  448. } catch (SQLException e) {
  449. m.setSucsess(new Boolean(false).toString());
  450. m.setInfo(Parameter.DELETE_FAILURE);
  451. try {
  452. conn.rollback();
  453. } catch (SQLException e1) {
  454. e1.printStackTrace();
  455. }
  456. log.error(e.getMessage(),e);
  457. }finally{
  458. db.close(ps);
  459. db.close(conn);
  460. }
  461. return m;
  462. }
  463. public String format(Date date){
  464. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  465. String dates = sdf.format(date);
  466. return dates;
  467. }
  468. }