2f2b14f65edf73cf415d2e93a059d8cb3e137ff2.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. package com.sinosoft.am.org.linkman.dao;
  2. import java.io.UnsupportedEncodingException;
  3. import java.sql.Connection;
  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.List;
  11. import java.util.Map;
  12. import org.apache.log4j.Logger;
  13. import com.persistence.DbConnection;
  14. import com.sinosoft.am.org.dept.indept.dao.OrgInDeptDao;
  15. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  16. import com.sinosoft.am.org.linkman.vo.LinkManInfo;
  17. import com.sinosoft.common.excel.JsonPluginsUtil;
  18. public class LinkManDao {
  19. private static final Logger log = Logger.getLogger(LinkManDao.class);
  20. public String getOriginalData(String virtual_org_id) {
  21. ORGTemplate template = new ORGTemplate();
  22. ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();
  23. String sql = "select A.SORT_NO,D.FD_DESCRIPTION AS EMC_ROLE,A.INLINK_NAME,B.PROVINCE_NAME_TWO AS PARENT_ORG_ID, C.DEPT_NAME AS PARENT_DEPT_ID, A.PHONE,A.MAN_REMARKS,A.EMAIL"
  24. + " from EMC_AM_ORG_INLINK A,DEPARTMENT_ABBR B ,SYS_DEPARTMENT C,BM_MAPVALUECANST D"
  25. + " where VIRTUAL_ORG_ID =? and"
  26. + " (A.PARENT_DEPT_ID = B.FD_OBJECTID OR A.PARENT_ORG_ID = B.FD_OBJECTID) and"
  27. + " A.PARENT_DEPT_ID = C.DEPT_ID and"
  28. + " (A.EMC_ROLE= D.FD_CODE and FD_TYPE='BM_EMC_ROLE')"
  29. + " and A.IS_DEL ='0'";
  30. log.info("sql========="+sql);
  31. StringBuffer json = new StringBuffer();
  32. try {
  33. list = template.getSerachResult(sql, virtual_org_id);
  34. if(list.size()>0){
  35. for(int i=0;i<list.size();i++){
  36. json.append("{");
  37. json.append("\"SORT_NO_211\":\""+list.get(i).get("SORT_NO")+"\",");
  38. json.append("\"EMC_ROLE_211_SHOW\":\""+list.get(i).get("EMC_ROLE")+"\",");
  39. json.append("\"INLINK_NAME_211\":\""+list.get(i).get("INLINK_NAME")+"\",");
  40. json.append("\"PARENT_ORG_ID_211_SHOW\":\""+list.get(i).get("PARENT_ORG_ID")+"\",");
  41. json.append("\"PARENT_DEPT_ID_211\":\""+list.get(i).get("PARENT_DEPT_ID")+"\",");
  42. json.append("\"PHONE_211\":\""+list.get(i).get("PHONE")+"\",");
  43. json.append("\"INLINK_INDEX_211\":\""+list.get(i).get("EMAIL")+"\",");
  44. json.append("\"MAN_REMARKS_211\":\""+list.get(i).get("MAN_REMARKS")+"\"");
  45. json.append("},");
  46. }
  47. }
  48. if(list.size()>0){
  49. json.deleteCharAt(json.lastIndexOf(","));
  50. }
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
  54. String result = "{\"rows\":["+json.toString()+"]}";
  55. log.info("result================"+result);
  56. return result;
  57. }
  58. public String confirmCorp(String login_name, String corp_name) {
  59. String result = "false";
  60. String dept_id = "";
  61. String org_id = "";
  62. ORGTemplate template = new ORGTemplate();
  63. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  64. ArrayList <Map<String,String>> list1 = new ArrayList<Map<String,String>>();
  65. String sql1 = "select dept_id from sys_user_info where login_name = ?";
  66. String sql2 = "select province_name_two as corp_name from department_abbr where fd_objectid =?";
  67. try {
  68. list = template.getSerachResult(sql1, login_name);
  69. if(list.size()>0){
  70. dept_id = list.get(0).get("DEPT_ID");
  71. }
  72. org_id = getOrgId(dept_id);
  73. list1 = template.getSerachResult(sql2, org_id);
  74. if(list1.size()>0){
  75. if(list1.get(0).get("CORP_NAME").equals(corp_name)){
  76. result ="true";
  77. }
  78. }
  79. } catch (Exception e) {
  80. e.printStackTrace();
  81. }
  82. return result;
  83. }
  84. public String getOrgId(String dept_id){
  85. String org_id ="";
  86. ORGTemplate template = new ORGTemplate();
  87. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  88. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  89. try {
  90. list = template.getSerachResult(sql, dept_id);
  91. if(list.size()>0){
  92. if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
  93. org_id = getOrgId1(list.get(0).get("PARENT_ID"));
  94. }else{
  95. org_id = list.get(0).get("DEPT_ID");
  96. }
  97. }
  98. } catch (Exception e) {
  99. e.printStackTrace();
  100. }
  101. return org_id;
  102. }
  103. private String getOrgId1(String dept_id){
  104. String org_id ="";
  105. ORGTemplate template = new ORGTemplate();
  106. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  107. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  108. try {
  109. list = template.getSerachResult(sql, dept_id);
  110. if(list.size()>0){
  111. if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
  112. org_id = getOrgId2(list.get(0).get("PARENT_ID"));
  113. }else{
  114. org_id = list.get(0).get("DEPT_ID");
  115. }
  116. }
  117. } catch (Exception e) {
  118. e.printStackTrace();
  119. }
  120. return org_id;
  121. }
  122. private String getOrgId2(String dept_id){
  123. String org_id ="";
  124. ORGTemplate template = new ORGTemplate();
  125. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  126. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  127. try {
  128. list = template.getSerachResult(sql, dept_id);
  129. if(list.size()>0){
  130. if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
  131. org_id = getOrgId3(list.get(0).get("PARENT_ID"));
  132. }else{
  133. org_id = list.get(0).get("DEPT_ID");
  134. }
  135. }
  136. } catch (Exception e) {
  137. e.printStackTrace();
  138. }
  139. return org_id;
  140. }
  141. private String getOrgId3(String dept_id){
  142. String org_id ="";
  143. ORGTemplate template = new ORGTemplate();
  144. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  145. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  146. try {
  147. list = template.getSerachResult(sql, dept_id);
  148. if(list.size()>0){
  149. if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
  150. org_id = getOrgId4(list.get(0).get("PARENT_ID"));
  151. }else{
  152. org_id = list.get(0).get("DEPT_ID");
  153. }
  154. }
  155. } catch (Exception e) {
  156. e.printStackTrace();
  157. }
  158. return org_id;
  159. }
  160. private String getOrgId4(String dept_id){
  161. String org_id ="";
  162. ORGTemplate template = new ORGTemplate();
  163. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  164. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  165. try {
  166. list = template.getSerachResult(sql, dept_id);
  167. if(list.size()>0){
  168. if(!("1".equals(list.get(0).get("DEPT_TYPE")))){
  169. org_id = getOrgId5(list.get(0).get("PARENT_ID"));
  170. }else{
  171. org_id = list.get(0).get("DEPT_ID");
  172. }
  173. }
  174. } catch (Exception e) {
  175. e.printStackTrace();
  176. }
  177. return org_id;
  178. }
  179. private String getOrgId5(String dept_id){
  180. String org_id ="";
  181. ORGTemplate template = new ORGTemplate();
  182. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  183. String sql = "select dept_id,parent_id,dept_type from sys_department where dept_id =? ";
  184. try {
  185. list = template.getSerachResult(sql, dept_id);
  186. if(list.size()>0){
  187. if("1".equals(list.get(0).get("DEPT_TYPE"))){
  188. org_id = list.get(0).get("DEPT_ID");
  189. }
  190. }
  191. } catch (Exception e) {
  192. e.printStackTrace();
  193. }
  194. return org_id;
  195. }
  196. public String confirmName(String login_name, String real_name) {
  197. String result = "false";
  198. ORGTemplate template = new ORGTemplate();
  199. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  200. String sql = "select real_name from sys_user_info where login_name =?";
  201. try {
  202. list = template.getSerachResult(sql, login_name);
  203. if(list.size()>0){
  204. if(list.get(0).get("REAL_NAME").equals(real_name)){
  205. result = "true";
  206. }
  207. }
  208. } catch (Exception e) {
  209. e.printStackTrace();
  210. }
  211. return result;
  212. }
  213. public String getDeptList(String corp_id) {
  214. ORGTemplate template = new ORGTemplate();
  215. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  216. StringBuffer json = new StringBuffer();
  217. String sql = "select dept_name from sys_department where dept_type!='1' and is_del='0' and parent_id=?";
  218. try {
  219. list = template.getSerachResult(sql, corp_id);
  220. if(list.size()>0){
  221. for(int i=0;i<list.size();i++){
  222. json.append("{");
  223. json.append("\"key\":\""+list.get(i).get("DEPT_NAME")+"\",");
  224. json.append("\"value\":\""+list.get(i).get("DEPT_NAME")+"\"");
  225. json.append("},");
  226. }
  227. json.deleteCharAt(json.lastIndexOf(","));
  228. }
  229. } catch (Exception e) {
  230. e.printStackTrace();
  231. }
  232. String result = "{\"list\":["+json.toString()+"]}";
  233. return result;
  234. }
  235. public String saveData(String json, String virtual_org_id,String made_man_id, String made_man,
  236. String made_man_phone, String made_man_dept,String name, String is_issue) {
  237. String result = "";
  238. int num = 0 ;
  239. ORGTemplate template = new ORGTemplate();
  240. OrgInDeptDao orgIndeptDao = new OrgInDeptDao();
  241. //先删除表中原先保存的记录
  242. String sql1 = "update EMC_AM_ORG_INLINK_HISTORY set is_del = '1' where virtual_org_id =? and is_issue = '0' ";
  243. //插入新的数据
  244. String sql2 = "insert into EMC_AM_ORG_INLINK_HISTORY "+
  245. " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
  246. " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
  247. " IS_SHOW_TEL,MADE_MAN,MADE_MAN_PHONE,MADE_MAN_ID,MADE_MAN_DEPT,IS_ISSUE,NAME,LAST_OPERATION_DATE,V_REMARK) "
  248. + "values "
  249. + "(?,?,?,?,?,?,?,?,?,?,"
  250. + "?,?,?,?,?,?,?,?,?,?,"
  251. + "?,?,?,?,?,?,?,?,?)";
  252. try {
  253. json = java.net.URLDecoder.decode(json, "UTF-8");
  254. } catch (UnsupportedEncodingException e1) {
  255. e1.printStackTrace();
  256. }
  257. try {
  258. template.update(sql1, virtual_org_id);
  259. } catch (Exception e) {
  260. e.printStackTrace();
  261. }
  262. List<Map<String, String>> rows = JsonPluginsUtil.jsonToMapList(json);
  263. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  264. String update_date = sdf.format(new Date());
  265. name = name+"成员名单("+update_date+")";
  266. try {
  267. for(int i=0;i<rows.size();i++){
  268. String login_name = rows.get(i).get("INLINK_INDEX_211");
  269. LinkManInfo linkMan = null;
  270. linkMan = getLinkMan(login_name);
  271. String fd_objectid = createMsgId(getEmcInlinkId());
  272. String inlink_index = linkMan.getInlink_index();
  273. String inlink_name = rows.get(i).get("INLINK_NAME_211");
  274. String emc_type = "";
  275. String emc_role = getRole(rows.get(i).get("EMC_ROLE_211_SHOW"));
  276. String manager_dept = "";
  277. String landline = "";
  278. String phone = rows.get(i).get("PHONE_211");
  279. String Email = login_name;
  280. String parent_org ="";
  281. String parent_dept = virtual_org_id;
  282. String job = "";
  283. String is_del = "0";
  284. String updateDate = update_date;
  285. String parent_dept_id = linkMan.getDept_id();
  286. String parent_org_id = getOrgId(parent_dept_id);
  287. //virtual_org_id;
  288. String man_remarks = rows.get(i).get("MAN_REMARKS_211");
  289. // made_man_id;
  290. String sort_no ="";
  291. if(!orgIndeptDao.checkhaveId(virtual_org_id)){
  292. sort_no =String.valueOf(555555551+i);
  293. }else{
  294. sort_no =String.valueOf(orgIndeptDao.houxuzhi(virtual_org_id)+i+1);
  295. }
  296. String is_show_tel = "";
  297. //made_man
  298. //made_man_phone
  299. //made_man_id
  300. //made_man_dept
  301. //is_issue
  302. //name
  303. String last_operation_date = updateDate;
  304. String v_remark ="";
  305. System.out.println("==================="+i);
  306. int flag = template.update(sql2, fd_objectid,inlink_index,inlink_name,emc_type,emc_role,manager_dept,landline,phone,Email,parent_org,
  307. parent_dept,job,is_del,updateDate,parent_dept_id,parent_org_id,virtual_org_id,man_remarks,made_man_id,sort_no,
  308. is_show_tel,made_man,made_man_phone,made_man_id,made_man_dept,is_issue,name,last_operation_date,v_remark);
  309. if(flag>0){
  310. num++;
  311. }
  312. }
  313. } catch (Exception e) {
  314. e.printStackTrace();
  315. }
  316. if(num==rows.size()){
  317. result = "success";
  318. }
  319. return result;
  320. }
  321. public String issueData(String json, String virtual_org_id,
  322. String made_man_id, String made_man, String made_man_phone,String made_man_dept,
  323. String name, String is_issue) {
  324. //先删除EMC_AM_ORG_INLINK 表中存在的数据
  325. String result = "";
  326. int num1 = 0 ;
  327. int num2 = 0 ;
  328. int num3 = 0 ;
  329. int num4 = 0 ;
  330. ORGTemplate template = new ORGTemplate();
  331. OrgInDeptDao orgIndeptDao = new OrgInDeptDao();
  332. String sql1 = "update EMC_AM_ORG_INLINK set is_del ='1' where virtual_org_id = ? ";
  333. String sql4 = "update EMC_AM_ORG_INLINK_HISTORY set is_del ='0' where virtual_org_id =? and is_issue = '2'";
  334. try {
  335. num1 = template.update(sql1, virtual_org_id);
  336. log.info("EMC_AM_ORG_INLINK删除结果============"+num1);
  337. num4 = template.update(sql4, virtual_org_id);
  338. log.info("EMC_AM_ORG_INLINK_HISTORY删除结果============"+num4);
  339. } catch (Exception e) {
  340. e.printStackTrace();
  341. }
  342. String sql2 = "insert into EMC_AM_ORG_INLINK_HISTORY "+
  343. " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
  344. " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
  345. " IS_SHOW_TEL,MADE_MAN,MADE_MAN_PHONE,MADE_MAN_ID,MADE_MAN_DEPT,IS_ISSUE,NAME,LAST_OPERATION_DATE,V_REMARK) "
  346. + "values "
  347. + "(?,?,?,?,?,?,?,?,?,?,"
  348. + "?,?,?,?,?,?,?,?,?,?,"
  349. + "?,?,?,?,?,?,?,?,?)";
  350. String sql3 = "insert into EMC_AM_ORG_INLINK "+
  351. " (FD_OBJECTID,INLINK_INDEX,INLINK_NAME,EMC_TYPE,EMC_ROLE,MANAGER_DEPT,LANDLINE,PHONE,EMAIL,PARENT_ORG,"+
  352. " PARENT_DEPT,JOB,IS_DEL,UPDATEDATE,PARENT_DEPT_ID,PARENT_ORG_ID,VIRTUAL_ORG_ID,MAN_REMARKS,ENTRY_MAN_ID,SORT_NO,"+
  353. " IS_SHOW_TEL) "
  354. + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  355. try {
  356. json = java.net.URLDecoder.decode(json, "UTF-8");
  357. } catch (UnsupportedEncodingException e1) {
  358. // TODO Auto-generated catch block
  359. e1.printStackTrace();
  360. }
  361. List<Map<String, String>> rows = JsonPluginsUtil.jsonToMapList(json);
  362. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  363. String update_date = sdf.format(new Date());
  364. name = name+"成员名单("+update_date+")";
  365. try {
  366. for(int i=0;i<rows.size();i++){
  367. String login_name = rows.get(i).get("INLINK_INDEX_211");
  368. LinkManInfo linkMan = null;
  369. linkMan = getLinkMan(login_name);
  370. String fd_objectid = createMsgId(getEmcInlinkId());
  371. String inlink_index = linkMan.getInlink_index();
  372. String inlink_name = rows.get(i).get("INLINK_NAME_211");
  373. String emc_type = "";
  374. String emc_role = getRole(rows.get(i).get("EMC_ROLE_211_SHOW"));
  375. String manager_dept = "";
  376. String landline = "";
  377. String phone = rows.get(i).get("PHONE_211");
  378. String Email = login_name;
  379. String parent_org ="";
  380. String parent_dept = virtual_org_id;
  381. String job = "";
  382. String is_del = "0";
  383. String updateDate = update_date;
  384. String parent_dept_id = linkMan.getDept_id();
  385. String parent_org_id = getOrgId(parent_dept_id);
  386. //virtual_org_id;
  387. String man_remarks = rows.get(i).get("MAN_REMARKS_211");
  388. // made_man_id;
  389. String sort_no ="";
  390. if(!orgIndeptDao.checkhaveId(virtual_org_id)){
  391. sort_no =String.valueOf(555555551+i);
  392. }else{
  393. sort_no =String.valueOf(orgIndeptDao.houxuzhi(virtual_org_id)+i+1);
  394. }
  395. String is_show_tel = "";
  396. //made_man
  397. //made_man_phone
  398. //made_man_id
  399. //made_man_dept
  400. //is_issue
  401. //name
  402. String last_operation_date = updateDate;
  403. String v_remark ="";
  404. System.out.println("==================="+i);
  405. int flag1 = template.update(sql2, fd_objectid, inlink_index, inlink_name, emc_type, emc_role, manager_dept, landline, phone, Email, parent_org,
  406. parent_dept, job, is_del, updateDate, parent_dept_id, parent_org_id, virtual_org_id, man_remarks, made_man_id, sort_no,
  407. is_show_tel, made_man, made_man_phone, made_man_id, made_man_dept, is_issue,name, last_operation_date, v_remark);
  408. int flag2 = template.update(sql3, fd_objectid, inlink_index, inlink_name, emc_type, emc_role, manager_dept, landline, phone, Email, parent_org,
  409. parent_dept, job, is_del, updateDate, parent_dept_id, parent_org_id, virtual_org_id, man_remarks, made_man_id, sort_no,
  410. is_show_tel);
  411. if(flag1>0){
  412. num2++;
  413. }
  414. if(flag2>0){
  415. num3++;
  416. }
  417. }
  418. } catch (Exception e) {
  419. e.printStackTrace();
  420. }
  421. if((num2==rows.size())&&(num3==rows.size())){
  422. result = "success";
  423. }
  424. return result;
  425. }
  426. private LinkManInfo getLinkMan(String login_name) {
  427. LinkManInfo linkMan = null;
  428. ORGTemplate template = new ORGTemplate();
  429. ArrayList <Map<String,String>> list = new ArrayList<Map<String,String>>();
  430. String sql = "select dept_id,user_id from sys_user_info where login_name =? ";
  431. try {
  432. list = template.getSerachResult(sql, login_name);
  433. if(list.size()>0){
  434. linkMan = new LinkManInfo();
  435. linkMan.setDept_id(list.get(0).get("DEPT_ID"));
  436. linkMan.setInlink_index(list.get(0).get("USER_ID"));
  437. }
  438. } catch (Exception e) {
  439. e.printStackTrace();
  440. }
  441. return linkMan;
  442. }
  443. private String getRole(String emc_role) {
  444. //根据select * from "NWYJ"."BM_MAPVALUECANST" where fd_type ='BM_EMC_ROLE'查得
  445. String role = "";
  446. if("总指挥".equals(emc_role)){
  447. role = "1";
  448. }else if("常务副总指挥".equals(emc_role)){
  449. role = "2";
  450. }else if ("副总指挥".equals(emc_role)) {
  451. role = "3";
  452. }else if ("主任".equals(emc_role)) {
  453. role = "4";
  454. }else if ("常务副主任".equals(emc_role)) {
  455. role = "5";
  456. }else if ("副主任".equals(emc_role)) {
  457. role = "6";
  458. }else if ("成员".equals(emc_role)) {
  459. role = "7";
  460. }
  461. return role;
  462. }
  463. /**
  464. * 获得内部联系人的fd_objectId集合
  465. * @return 内部联系人的fd_objectId集合
  466. * @throws ClassNotFoundException
  467. */
  468. @SuppressWarnings({ "unchecked", "rawtypes" })
  469. private List<String> getEmcInlinkId() throws ClassNotFoundException {
  470. String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK UNION SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK_HISTORY";
  471. Connection conn = null;
  472. Statement stat = null;
  473. ResultSet rs = null;
  474. DbConnection db = new DbConnection();
  475. try {
  476. conn = db.getConnection();
  477. stat = conn.createStatement();
  478. rs = stat.executeQuery(sql);
  479. List<String> list = new ArrayList();
  480. while (rs.next()) {
  481. list.add(rs.getString("FD_OBJECTID"));
  482. }
  483. return list;
  484. } catch (SQLException e) {
  485. log.error(e.getMessage(), e);
  486. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  487. + sql, e);
  488. } finally {
  489. db.close(rs);
  490. db.close(stat);
  491. db.close(conn);
  492. }
  493. }
  494. /**
  495. * 为新增的内部联系人创建一个fd_objectid
  496. * @param list
  497. * @return
  498. * @throws ClassNotFoundException
  499. */
  500. private String createMsgId(List<String> list) throws ClassNotFoundException{
  501. long l=(long) ((Math.random()+1)*1000000000);
  502. String msgId=l+"";
  503. if(list.contains(msgId)){
  504. return createMsgId(list);
  505. }
  506. else{
  507. log.info("EMC_AM_ORG_INLINK_ID==="+msgId);
  508. return msgId;
  509. }
  510. }
  511. public void updateOrgId(){
  512. ORGTemplate template = new ORGTemplate();
  513. ArrayList<Map<String,String >> list1 = null;
  514. ArrayList<Map<String,String >> list2 = null;
  515. String sql1 = "select inlink_index from EMC_AM_ORG_INLINK ";//找到所有的用户id
  516. String sql2 = "select user_id,login_name,real_name,dept_id,org_id,office_phone,mobile from sys_user_info where user_id =?";//匹配相应的dept_id
  517. String sql3 = "update EMC_AM_ORG_INLINK set email =?,inlink_name =?, PARENT_DEPT_ID=?,PARENT_ORG_ID=?,landline = ?,phone=? where inlink_index =?";//更新inlink表中的inlink_index对应的parent_org_id
  518. try {
  519. int i = 0;
  520. list1 = template.getSerachResult(sql1);
  521. log.info("sql1==================="+sql1);
  522. for(Map<String,String> map:list1){
  523. String user_id =map.get("INLINK_INDEX")==null?"":map.get("INLINK_INDEX");
  524. if(!"".equals(user_id)){
  525. i++;
  526. list2 = template.getSerachResult(sql2, user_id);
  527. log.info("sql2==================="+sql2+"参数为user_id====="+user_id);
  528. int j =i;
  529. if(list2.size()>0){
  530. String user_id1 = list2.get(0).get("USER_ID");
  531. String login_name = list2.get(0).get("LOGIN_NAME")==null?"":list2.get(0).get("LOGIN_NAME");
  532. String real_name = list2.get(0).get("REAL_NAME")==null?"":list2.get(0).get("REAL_NAME");
  533. String dept_id = list2.get(0).get("DEPT_ID")==null?"":list2.get(0).get("DEPT_ID");
  534. String office_phone = list2.get(0).get("OFFICE_PHONE")==null?"":list2.get(0).get("OFFICE_PHONE");
  535. String mobile = list2.get(0).get("MOBILE")==null?"":list2.get(0).get("MOBILE");
  536. String org_id = getOrgId(dept_id);//根据dept_id获取对应的org_id
  537. template.update(sql3, login_name,real_name,dept_id,org_id,office_phone,mobile,user_id1);
  538. log.info("sql3==================="+sql3+",参数为user_id1=="+user_id1+";dept_id===="+dept_id+";org_id===="+org_id);
  539. System.out.println("更新的行数================="+j);
  540. }
  541. System.out.println("数据总行数============="+i);
  542. }
  543. }
  544. } catch (Exception e) {
  545. e.printStackTrace();
  546. }
  547. }
  548. public void updateUserId() {
  549. ORGTemplate template = new ORGTemplate();
  550. ArrayList<Map<String,String>> list1 = new ArrayList<Map<String,String>>();
  551. ArrayList<Map<String,String>> list2 = new ArrayList<Map<String,String>>();
  552. String sql1 = "select distinct email from EMC_AM_ORG_INLINK where email is not null";//找出所有4a账号不为空的数据
  553. String sql2 = "select user_id,login_name from sys_user_info where login_name=?";//根据4a账号查找相应的user_id
  554. String sql3 = "update EMC_AM_ORG_INLINK set inlink_index =? where email=? ";
  555. try {
  556. list1 = template.getSerachResult(sql1);
  557. log.info("sql1==============="+sql1);
  558. for(int i=0;i<list1.size();i++){
  559. list2 = template.getSerachResult(sql2, list1.get(i).get("EMAIL"));
  560. log.info("sql2==============="+sql2+",4a账号为===="+list1.get(i).get("EMAIL"));
  561. for(int j=0;j<list2.size();j++){//一个4a账号对应可能有几个index
  562. int result = template.update(sql3, list2.get(j).get("USER_ID"),list2.get(j).get("LOGIN_NAME"));
  563. log.info("sql3============"+sql3+"参数为login_name===="+list2.get(j).get("LOGIN_NAME")+";user_id======="+list2.get(j).get("USER_ID"));
  564. log.info("更新影响行数==========="+result);
  565. }
  566. }
  567. } catch (Exception e) {
  568. e.printStackTrace();
  569. }
  570. }
  571. public String getCorpId(String org_id) {
  572. ORGTemplate template = new ORGTemplate();
  573. ArrayList<Map<String,String>> list = new ArrayList<Map<String,String>>();
  574. String sql ="select corp_id from v_department where org_id =?";
  575. try {
  576. list = template.getSerachResult(sql, org_id);
  577. } catch (Exception e) {
  578. e.printStackTrace();
  579. }
  580. if(list.size()>0){
  581. return list.get(0).get("CORP_ID");
  582. }else{
  583. return "";
  584. }
  585. }
  586. }