fcd3ff31c886366482c530984fc420c6f58d8c14.svn-base 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. /**
  2. *
  3. */
  4. package com.sinosoft.am.org.dept.indept.dao;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.text.SimpleDateFormat;
  11. import java.util.ArrayList;
  12. import java.util.Date;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import com.formaction.Parameter;
  17. import com.formaction.vo.Msg;
  18. import com.persistence.DbConnection;
  19. import com.persistence.service.PersistenceFactory;
  20. import com.persistence.service.SysPersistence;
  21. import com.persistence.service.assitant.generator.IdentityGenerator;
  22. import com.persistence.service.exception.PersistenceException;
  23. import com.sinosoft.am.filemanger.laws.vo.FileBean;
  24. import com.sinosoft.am.org.dept.indept.vo.OrgInDeptStatistics;
  25. import com.sinosoft.am.org.dept.indept.vo.OrgInDeptVo;
  26. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  27. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  28. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  29. import org.apache.log4j.Logger;
  30. import net.sf.json.JSONArray;
  31. import net.sf.json.JSONObject;
  32. /**
  33. * @author 蒋云涛
  34. *
  35. */
  36. public class OrgInDeptDao {
  37. private static SysModel sysmodel = ModelFactory.getSysmodel();
  38. @SuppressWarnings("unused")
  39. private static SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  40. private Logger log = Logger.getLogger(OrgInDeptDao.class);
  41. /**
  42. *
  43. * @param sql
  44. * @return 返回带有InDeptVo的ArrayList集合
  45. */
  46. public ArrayList<OrgInDeptVo> getDeptList(String sql) throws ClassNotFoundException{
  47. Connection conn = null;
  48. Statement st = null;
  49. ResultSet rs = null;
  50. DbConnection db = new DbConnection();
  51. try {
  52. conn = db.getConnection();
  53. st = conn.createStatement();
  54. rs = st.executeQuery(sql);
  55. ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
  56. while(rs.next()){
  57. result.add(getInDeptVo(rs));
  58. }
  59. return result;
  60. } catch (SQLException e) {
  61. this.log.error(e.getMessage(),e);
  62. throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e);
  63. }finally{
  64. db.close(conn);
  65. db.close(st);
  66. db.close(rs);
  67. }
  68. }
  69. public ArrayList<OrgInDeptVo> getAllDeptList() throws ClassNotFoundException{
  70. Connection conn = null;
  71. Statement st = null;
  72. ResultSet rs = null;
  73. String sql = "select * from SYS_DEPARTMENT";
  74. DbConnection db = new DbConnection();
  75. try {
  76. conn = db.getConnection();
  77. st = conn.createStatement();
  78. rs = st.executeQuery(sql);
  79. ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
  80. while(rs.next()){
  81. result.add(getInDeptVo(rs));
  82. }
  83. return result;
  84. } catch (SQLException e) {
  85. this.log.error(e.getMessage(),e);
  86. throw new ClassNotFoundException("DAO Layou: 取得InDeptVo集合" + sql, e);
  87. }finally{
  88. db.close(conn);
  89. db.close(st);
  90. db.close(rs);
  91. }
  92. }
  93. /**
  94. *
  95. * @param id
  96. * @return InDeptVo 类对象
  97. * @throws ClassNotFoundException
  98. */
  99. public OrgInDeptVo getInDeptVoById(String id) throws ClassNotFoundException{
  100. OrgInDeptVo result = new OrgInDeptVo();
  101. Connection conn = null;
  102. Statement st = null;
  103. ResultSet rs = null;
  104. DbConnection db = new DbConnection();
  105. String sql = "select * from SYS_DEPARTMENT where DEPT_ID='"+id+"' and is_del='0'";
  106. try {
  107. conn = db.getConnection();
  108. st = conn.createStatement();
  109. rs = st.executeQuery(sql);
  110. if(rs.next()){
  111. result = getInDeptVo(rs);
  112. return result;
  113. };
  114. } catch (SQLException e) {
  115. this.log.error(e.getMessage(),e);
  116. throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e);
  117. }finally{
  118. db.close(conn);
  119. db.close(st);
  120. db.close(rs);
  121. }
  122. return result;
  123. }
  124. /**
  125. * 获取给定部门id的下一级部门
  126. * @param id
  127. * @return
  128. * @throws ClassNotFoundException
  129. */
  130. public ArrayList<OrgInDeptVo> getNextLevelTreeById(String id) throws ClassNotFoundException{
  131. Connection conn = null;
  132. Statement st = null;
  133. ResultSet rs = null;
  134. DbConnection db = new DbConnection();
  135. String sql = "select * from SYS_DEPARTMENT where PARENT_ID='"+id+"' AND IS_DEL='0'";
  136. try {
  137. conn = db.getConnection();
  138. st = conn.createStatement();
  139. rs = st.executeQuery(sql);
  140. ArrayList<OrgInDeptVo> result = new ArrayList<OrgInDeptVo>();
  141. while(rs.next()){
  142. result.add(getInDeptVo(rs));
  143. }
  144. return result;
  145. } catch (SQLException e) {
  146. this.log.error(e.getMessage(),e);
  147. throw new ClassNotFoundException("DAO Layou: 取得InDeptVo" + sql, e);
  148. }finally{
  149. db.close(conn);
  150. db.close(st);
  151. db.close(rs);
  152. }
  153. }
  154. /**
  155. *
  156. * @param id
  157. * @return
  158. * @throws ClassNotFoundException
  159. */
  160. public ArrayList<OrgInDeptVo> getDeptTreeNodesById(String id) throws ClassNotFoundException{
  161. ArrayList<OrgInDeptVo> list = new ArrayList<OrgInDeptVo>();
  162. list = getAllDeptList();
  163. OrgInDeptVo dept = getInDeptVoById(id);
  164. ArrayList<OrgInDeptVo> nodesTree = getTreeNodesByInDeptVo(dept,list);
  165. return nodesTree;
  166. }
  167. /**
  168. * 这个递归存在问题
  169. * @param dept
  170. * @param list
  171. * @return
  172. */
  173. @SuppressWarnings("unused")
  174. public ArrayList<OrgInDeptVo> getTreeNodesByInDeptVo(OrgInDeptVo dept,ArrayList<OrgInDeptVo> list){
  175. ArrayList<OrgInDeptVo> deptTree = new ArrayList<OrgInDeptVo>();
  176. if(!deptTree.contains(dept)){
  177. deptTree.add(dept);
  178. };
  179. for(int i = 0; i<list.size();i++){
  180. OrgInDeptVo tdept = list.get(i);
  181. //System.out.println(tdept+"输出tdept");
  182. if(dept.getID().equals(tdept.getPARENT_ID())){
  183. if(!deptTree.contains(tdept)){
  184. deptTree.add(tdept);
  185. }
  186. ArrayList<OrgInDeptVo> tlist = getTreeNodesByInDeptVo(tdept,list);
  187. deptTree.addAll(getTreeNodesByInDeptVo(tdept,list));
  188. //System.out.println(tdept);
  189. }
  190. }
  191. return deptTree;
  192. }
  193. /**
  194. * @param rs
  195. * @return dv 将部门结果集放在InDeptVo类中
  196. */
  197. private OrgInDeptVo getInDeptVo(ResultSet rs) {
  198. OrgInDeptVo dv = new OrgInDeptVo();
  199. try{
  200. dv.setCODE(rs.getString("DEPT_CODE"));
  201. dv.setDEPT_DESC(rs.getString("DEPT_DESC"));
  202. dv.setID(rs.getString("DEPT_ID"));
  203. dv.setDEPT_LEVEL(rs.getString("DEPT_LEVEL"));
  204. dv.setNAME(rs.getString("DEPT_NAME"));
  205. dv.setDEPT_PATH(rs.getString("DEPT_PATH"));
  206. dv.setDEPT_TYPE(rs.getString("DEPT_TYPE"));
  207. dv.setFD_OBJECTID(rs.getString("FD_OBJECTID"));
  208. dv.setIS_DEL(rs.getString("IS_DEL"));
  209. dv.setIS_VIRTUAL(rs.getString("IS_VIRTUAL"));
  210. dv.setMOD_DATE(rs.getString("MOD_DATE"));
  211. dv.setPARENT_ID(rs.getString("PARENT_ID"));
  212. dv.setSHORT_NAME(rs.getString("SHORT_NAME"));
  213. dv.setSORT(rs.getString("SORT"));
  214. dv.setUNICODE(rs.getString("UNICODE"));
  215. }catch(SQLException e){
  216. this.log.error(e.getMessage(),e);
  217. }
  218. return dv;
  219. }
  220. /**
  221. * 根据部门Id,上级部门Id 部门名称
  222. * @param deptId
  223. * @param parentId
  224. * @param deptName
  225. * @return 是否新增内部虚拟机构成功
  226. */
  227. public boolean addOrgInDept(String deptId, String parentId, String deptName) {
  228. Connection conn = null;
  229. PreparedStatement ps = null;
  230. DbConnection db = new DbConnection();
  231. StringBuffer sql = new StringBuffer();
  232. String objectId = deptId;
  233. sql.append("--新增内部虚拟组织机构 \n");
  234. sql.append("INSERT INTO SYS_DEPARTMENT (FD_OBJECTID,DEPT_ID,PARENT_ID,NAME,IS_DEL,IS_VIRTUAL)VALUES(?,?,?,?,?,?) \n");
  235. try {
  236. conn = db.getConnection();
  237. ps = conn.prepareStatement(sql.toString());
  238. ps.setString(1, objectId);
  239. ps.setString(2, deptId);
  240. ps.setString(3, parentId);
  241. ps.setString(4, deptName);
  242. ps.setString(5, "0");
  243. ps.setString(6, "1");
  244. log.info("新增内部机构sql="+sql);
  245. return ps.executeUpdate() == 1;
  246. } catch (Exception e) {
  247. log.error("新增内部组织机构根节点错误", e);
  248. } finally {
  249. db.close(conn);
  250. db.close(ps);
  251. }
  252. return false;
  253. }
  254. /**
  255. *
  256. * @param deptId
  257. * @param deptName
  258. * @return 是否成功修改内部虚拟机构的名称
  259. */
  260. public boolean updateOrgInDeptName(String deptId, String deptName) {
  261. Connection conn = null;
  262. PreparedStatement ps = null;
  263. PreparedStatement ps2 = null;
  264. PreparedStatement ps3 = null;
  265. DbConnection db = new DbConnection();
  266. //修改机构名称sql语句
  267. StringBuffer sql1 = new StringBuffer();
  268. //修改外部人员表的 部门 和部门名称
  269. StringBuffer sql2 = new StringBuffer();
  270. StringBuffer sql3 = new StringBuffer();
  271. sql1.append("--修改内部组织机构名称 \n");
  272. sql1.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET NAME=? WHERE ID=? AND IS_DEL=? \n");
  273. log.info(sql1 + "-------------------sql1");
  274. sql2.append("--修改内部人员表的部门名称 \n");
  275. sql2.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_DEPT=? WHERE PARENT_DEPT_ID=? \n");
  276. log.info("修改内部人员表的部门名称sql="+sql2 );
  277. sql3.append("--修改内部人员表的单位名称 \n");
  278. sql3.append("UPDATE EMC_AM_ORG_INLINK SET PARENT_ORG=? WHERE PARENT_ORG_ID=? \n");
  279. log.info("修改内部人员表的单位名称 sql="+sql3);
  280. try {
  281. //原子性还没做
  282. conn = db.getConnection();
  283. // conn.setAutoCommit(false);
  284. ps = conn.prepareStatement(sql1.toString());
  285. ps.setString(1, deptName);
  286. ps.setString(2, deptId);
  287. ps.setString(3,"0");
  288. boolean updateOrgName = ps.executeUpdate()>=1;
  289. boolean updateInLinkDeptName=true;
  290. //boolean updateInLinkOrgName = true;
  291. if(hasStaff(deptId)){
  292. ps2 = conn.prepareStatement(sql2.toString());
  293. ps2.setString(1, deptName);
  294. ps2.setString(2, deptId);
  295. updateInLinkDeptName = ps2.executeUpdate()>=1;
  296. }
  297. if(hasParentOrg(deptId)){
  298. ps3 = conn.prepareStatement(sql3.toString());
  299. ps3.setString(1, deptName);
  300. ps3.setString(2, deptId);
  301. ps3.executeUpdate();
  302. }
  303. boolean isUpdate = updateOrgName && updateInLinkDeptName;
  304. // conn.commit();
  305. return isUpdate;
  306. } catch (Exception e) {
  307. log.error("修改内部组织机构的名称出错", e);
  308. } finally {
  309. db.close(conn);
  310. db.close(ps);
  311. db.close(ps2);
  312. db.close(ps3);
  313. }
  314. return false;
  315. }
  316. /**
  317. *
  318. * @param deptId
  319. * @return 是否成功删除(改变IS_DEL状态)内部虚拟组织机构
  320. */
  321. public boolean shamDeleteOrgInDept(String deptId){
  322. //先进行判断能否删除(判断机构下是否还有子机构存在)
  323. if(hasChildNode(deptId)){
  324. return false;
  325. }
  326. //判断机构下是否还有员工存在
  327. if(hasStaff(deptId)){
  328. return false;
  329. }
  330. Connection conn = null;
  331. PreparedStatement ps = null;
  332. DbConnection db = new DbConnection();
  333. StringBuffer sql = new StringBuffer();
  334. sql.append("--删除内部组织机构名称 \n");
  335. sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n");
  336. try {
  337. conn = db.getConnection();
  338. ps = conn.prepareStatement(sql.toString());
  339. ps.setString(1, "1");
  340. ps.setString(2, deptId);
  341. log.info("删除内部虚拟机构sql="+sql);
  342. return ps.executeUpdate() == 1;
  343. } catch (Exception e) {
  344. log.error("删除内部组织机构名称错误", e);
  345. } finally {
  346. db.close(conn);
  347. db.close(ps);
  348. }
  349. return false;
  350. }
  351. /**
  352. * 判断该机构下是否存在人员
  353. * @param deptId
  354. * @return 返回当前机构是否还有未删除的员工
  355. */
  356. public boolean hasStaff(String deptId) {
  357. Connection conn = null;
  358. PreparedStatement ps = null;
  359. ResultSet rs = null;
  360. DbConnection db = new DbConnection();
  361. StringBuffer sql = new StringBuffer();
  362. sql.append("--查询该机构是否有没有删除的员工 \n");
  363. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_DEPT_ID=? AND IS_DEL=? \n");
  364. try {
  365. conn = db.getConnection();
  366. ps = conn.prepareStatement(sql.toString());
  367. ps.setString(1, deptId);
  368. ps.setString(2, "0");
  369. log.info("查询该内部机构是否有未删除的员工sql="+sql);
  370. rs =ps.executeQuery();
  371. if(rs.next()){
  372. //log.info("该内部机构是否有员工"+rs.getBoolean(1));
  373. return rs.getBoolean(1);
  374. };
  375. } catch (Exception e) {
  376. log.error("查询该内部机构是否存在员工", e);
  377. } finally {
  378. db.close(conn);
  379. db.close(ps);
  380. db.close(rs);
  381. }
  382. return false;
  383. }
  384. /**
  385. * 判断是否存在下一级的机构
  386. * @param deptId
  387. * @return 返回当前虚拟机构是否还有子机构
  388. */
  389. public boolean hasChildNode(String deptId) {
  390. Connection conn = null;
  391. PreparedStatement ps = null;
  392. ResultSet rs = null;
  393. DbConnection db = new DbConnection();
  394. StringBuffer sql = new StringBuffer();
  395. sql.append("--查询该机构是否有子机构 \n");
  396. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? \n");
  397. try {
  398. conn = db.getConnection();
  399. ps = conn.prepareStatement(sql.toString());
  400. ps.setString(1, deptId);
  401. ps.setString(2, "0");
  402. log.info("查询是否有子机构 sql="+sql);
  403. rs =ps.executeQuery();
  404. if(rs.next()){
  405. log.info("是否有子机构"+rs.getBoolean(1));
  406. return rs.getBoolean(1);
  407. };
  408. } catch (Exception e) {
  409. log.error("修改内部组织机构根节点错误", e);
  410. } finally {
  411. db.close(conn);
  412. db.close(ps);
  413. db.close(rs);
  414. }
  415. return false;
  416. }
  417. /**
  418. * 判断是否存上级部门
  419. * @param deptId
  420. * @return
  421. */
  422. public boolean hasParentOrg(String deptId) {
  423. Connection conn = null;
  424. Statement st = null;
  425. ResultSet rs = null;
  426. DbConnection db = new DbConnection();
  427. String sql = "SELECT COUNT(1) FROM EMC_AM_ORG_DEPARTMENT_TEST a,"+
  428. "(SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0') b WHERE a.ID=b.PARENT_ID AND a.IS_DEL='0'";
  429. try {
  430. conn = db.getConnection();
  431. st = conn.createStatement();
  432. log.info("是否上级单位sql="+sql);
  433. rs = st.executeQuery(sql);
  434. if(rs.next()){
  435. return rs.getBoolean(1);
  436. };
  437. } catch (Exception e) {
  438. log.error("查询是否存在上级单位出错", e);
  439. }finally {
  440. db.close(conn);
  441. db.close(st);
  442. db.close(rs);
  443. }
  444. return false;
  445. }
  446. /*******************生成内部机构双选树开始***************************************************/
  447. public OrgInDeptVo getInOrgDoubleTreeRoot(String deptId){
  448. OrgInDeptVo ov = new OrgInDeptVo();
  449. Connection conn = null;
  450. Statement st = null;
  451. ResultSet rs = null;
  452. String sql = "SELECT * FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE ID='"+deptId+"' AND IS_DEL='0'";
  453. DbConnection db = new DbConnection();
  454. try {
  455. conn = db.getConnection();
  456. st = conn.createStatement();
  457. rs = st.executeQuery(sql);
  458. if(rs.next()){
  459. ov = getInDeptVo(rs);
  460. return ov;
  461. };
  462. } catch (Exception e) {
  463. log.error("查询双向选择树的根级单位出错", e);
  464. }finally{
  465. db.close(conn);
  466. db.close(st);
  467. db.close(rs);
  468. }
  469. return ov;
  470. }
  471. public String getInOrgTree(String id,String type) {
  472. log.info("id-- " + id);
  473. SysModel sysmodel = ModelFactory.getSysmodel();
  474. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  475. StringBuffer json = new StringBuffer();
  476. StringBuffer sql = new StringBuffer();
  477. sql.append("-- 查询内部组织机构根节点 \n");
  478. // sql.append(" SELECT ID,NAME,PARENT_ID \n");
  479. sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n");
  480. sql.append(" FROM SYS_DEPARTMENT where IS_DEL='0' \n");
  481. // if (id.equals("")) {
  482. // sql.append(" and PARENT_ID='0'");
  483. // } else {
  484. // sql.append(" and PARENT_ID='" + id + "'");
  485. // }
  486. sql.append(" and DEPT_ID='" + id + "'");
  487. // sql.append(" ORDER BY SORT asc \n");
  488. log.info(sql.toString());
  489. try {
  490. ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
  491. String[] temp = listRoot.get(0);
  492. String deptId = temp[0];
  493. String deptName = temp[1];
  494. String parentId = temp[2];
  495. json.append("{fromList:[");
  496. // if (listRoot.size() > 1) {
  497. // /**
  498. // * 加载人员信息 if(this.hasPersonLeaf(id)&&"per".equals(type)){
  499. // * json.append(this.getPersonJson(id)); }
  500. // */
  501. // if(this.hasStaff(id)&&"per".equals(type)){
  502. // json.append(this.getPersonJson(id));
  503. // };
  504. //// json.append(this.getDeptChlidrenJson(id, type));
  505. // } else {
  506. json.append("{");
  507. json.append(" id:'" + deptId + "',parentId:'0', ");
  508. json.append(" parentId:'" + parentId + "', ");
  509. json.append(" name:'" + deptName + "', ");
  510. json.append("oldParentId:'null',");
  511. json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', ");
  512. json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  513. json.append("},");
  514. /** 加载人员信息 */
  515. // if (this.hasStaff(deptId) && "per".equals(type)) {
  516. json.append(this.getPersonJson(deptId));
  517. // }
  518. // json.append(this.getDeptChlidrenJson(deptId, type));
  519. // }
  520. if (json.lastIndexOf(",") > -1) {
  521. json.deleteCharAt(json.lastIndexOf(","));
  522. }
  523. json.append("],toList:[]}");
  524. } catch (PersistenceException e) {
  525. log.error("查询组织机构错误", e);
  526. }
  527. log.info("组织机构json========"+JSONObject.fromObject(json.toString()).toString());
  528. return JSONObject.fromObject(json.toString()).toString();
  529. }
  530. // /**
  531. // * 返回部门节点json字符串
  532. // *
  533. // * @param unitCode
  534. // * @return
  535. // */
  536. // private String getDeptChlidrenJson(String unitCode, String type) {
  537. // SysModel sysmodel = ModelFactory.getSysmodel();
  538. // SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  539. //
  540. // StringBuffer json = new StringBuffer();
  541. // StringBuffer sql = new StringBuffer();
  542. // sql.append("-- 查询组织机构子节点 \n");
  543. //// sql.append(" SELECT ID,NAME,FD_OBJECTID \n");
  544. // sql.append(" SELECT DEPT_ID,DEPT_NAME,PARENT_ID \n");
  545. // sql.append(" FROM SYS_DEPARTMENT WHERE PARENT_ID='" + unitCode + "' \n");
  546. // sql.append(" ORDER BY SORT asc \n");
  547. // try {
  548. // ArrayList<String[]> listDept = persistence.getSearchResult(99, sql.toString());
  549. // int num = listDept.size();
  550. //
  551. // for (int i = 0; i < num; i++) {
  552. // String[] temp = listDept.get(i);
  553. // String deptId = temp[0];
  554. // String deptName = temp[1];
  555. // String objectId = temp[2];
  556. // json.append("{ ");
  557. // json.append(" id:'" + deptId + "', parentId:'" + unitCode + "',");
  558. // json.append(" classId:'800',objectId:'" + objectId + "',");
  559. // json.append(" name:'" + deptName + "',");
  560. // json.append("oldParentId:'null',");
  561. // json.append(" type:'unit',menuType:'nonLeafMenu', drag:'false', ");
  562. // json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  563. // json.append("}, ");
  564. //
  565. // if (this.hasStaff(deptId)&&"per".equals(type)){
  566. // json.append(this.getPersonJson(deptId));
  567. // }
  568. // if (this.hasChildNode(deptId)) {
  569. // json.append(this.getDeptChlidrenJson(deptId, type));
  570. // }
  571. //
  572. // }
  573. //
  574. // } catch (PersistenceException e) {
  575. // log.error("查询组织机构子节点错误", e);
  576. // }
  577. //
  578. // return json.toString();
  579. // }
  580. private String getPersonJson(String deptId) {
  581. SysModel sysmodel = ModelFactory.getSysmodel();
  582. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  583. StringBuffer json = new StringBuffer();
  584. String sql = "SELECT FD_OBJECTID,COMPANY_ID,REAL_NAME FROM SYS_USER_INFO WHERE IS_DEL='0' and COMPANY_ID='"
  585. + deptId + "' AND FD_OBJECTID NOT IN (SELECT FD_OBJECTID FROM EMC_AM_EMERGENCY_EXPERT WHERE IS_DEL='0') ORDER BY COMPANY_ID ASC "; //
  586. // log.info("=="+sql);
  587. try {
  588. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  589. int num = list.size();
  590. for (int i = 0; i < num; i++) {
  591. String[] temp = list.get(i);
  592. String objectId = temp[0];
  593. String pCode = temp[1];
  594. String name = temp[2];
  595. json.append("{ ");
  596. json.append(" id:'" + objectId + "', parentId:'" + pCode + "',");
  597. json.append(" classId:'880',objectId:'" + objectId + "',");
  598. json.append(" type:'per', name:'" + name + "',");
  599. json.append("oldParentId:'"+ deptId+"', ");
  600. json.append(" menuType:'leafMenu',");
  601. json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'");
  602. /*
  603. * if(sex.equals("0")){ json.append(
  604. * " icon:'../../../scripts/qui/libs/icons/user_female.gif'");
  605. * }else{
  606. * json.append(" icon:'../../../scripts/qui/libs/icons/user.gif'"
  607. * ); }
  608. */
  609. json.append("}, ");
  610. }
  611. } catch (PersistenceException e) {
  612. log.error("查询内部人员数据错误-- ", e);
  613. }
  614. log.info("json=========="+json.toString());
  615. return json.toString();
  616. }
  617. /*******************内部机构双选树结束***************************************************/
  618. /*******************人力资源双选树开始***************************************************/
  619. /**
  620. * 获取人力资源树
  621. * @param comp_id
  622. * @return
  623. * @throws Exception
  624. */
  625. public String getDoubleTreeRoot(String comp_id,String toDeptId) throws Exception{
  626. StringBuffer json=new StringBuffer();
  627. SysModel sysmodel = ModelFactory.getSysmodel();
  628. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  629. String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE DEPT_ID='"+comp_id+"'";
  630. log.info("getDoubleTreeRoot.sql==="+sql+"===comp_id==="+comp_id);
  631. ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
  632. log.info(userTree.size());
  633. String dept_id=userTree.get(0)[0];
  634. String dept_name=userTree.get(0)[2];
  635. json.append("{\"fromList\":[");
  636. json.append("{");
  637. json.append(" id:'"+dept_id+"', parentId:'0', ");
  638. json.append(" objectId:'000', ");
  639. json.append(" name:'"+dept_name+"', ");
  640. json.append(" drag:'false', ");
  641. json.append(" open:true, ");
  642. json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  643. json.append("},");
  644. json.append(getDoubleTreeDao(comp_id,toDeptId));
  645. if (json.lastIndexOf(",") > -1) {
  646. json.deleteCharAt(json.lastIndexOf(","));
  647. }
  648. json.append("],\"toList\":[");
  649. //json.append("{");
  650. //json.append(" id:'"+toDeptId+"', ");
  651. //json.append(" parentId:'"+comp_id+"', ");
  652. //json.append(" name:'"+getInDeptVoById(toDeptId).getNAME()+"', ");
  653. //json.append(" oldParentId:'"+comp_id+"', ");
  654. //json.append(" drag:'false', ");
  655. //json.append(" open:true, ");
  656. //json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  657. //json.append("}");
  658. json.append("]}");
  659. log.info("json==="+json);
  660. return JSONObject.fromObject(json.toString()).toString();
  661. }
  662. /**
  663. * 获得下级的机构节点
  664. * @param comp_id
  665. * @return
  666. * @throws Exception
  667. */
  668. public String getDoubleTreeDao(String comp_id,String toDeptId) throws Exception{
  669. SysModel sysmodel = ModelFactory.getSysmodel();
  670. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  671. StringBuffer json=new StringBuffer();
  672. String sql="SELECT DEPT_ID,PARENT_ID,DEPT_NAME FROM SYS_DEPARTMENT WHERE PARENT_ID='"+comp_id+"'";
  673. ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
  674. log.info("getDoubleTreeDao.userTree.size===="+userTree.size());
  675. for(int i=0;i<userTree.size();i++){
  676. String dept_id=userTree.get(i)[0];
  677. String dept_name=userTree.get(i)[2];
  678. String temp=getDoubleTreeEle(dept_id,toDeptId);
  679. if(!"".equals(temp)){
  680. json.append(temp);
  681. json.append("{ ");
  682. json.append(" id:'" + dept_id + "', parentId:'"+comp_id+"',");
  683. json.append(" objectId:'" + dept_id + "',");
  684. json.append(" name:'" + dept_name + "',");
  685. json.append("oldParentId:'"+comp_id+"',");
  686. json.append(" drag:'false', ");
  687. json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  688. json.append("}, ");
  689. }
  690. }
  691. return json.toString();
  692. }
  693. /**
  694. * 获得机构下的人员信息
  695. * @param dept_id
  696. * @return
  697. * @throws Exception
  698. */
  699. public String getDoubleTreeEle(String dept_id,String toDeptId) throws Exception{
  700. SysModel sysmodel = ModelFactory.getSysmodel();
  701. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  702. StringBuffer json=new StringBuffer();
  703. String sql="select a.user_id,b.dept_id,a.real_name from sys_dept_user b,sys_user_info a where a.user_id=b.user_id and b.dept_id='"+dept_id+"' and a.user_id not in (select inlink_index from emc_am_org_inlink where virtual_org_id ='"+toDeptId+"' and is_del='0')";
  704. ArrayList<String[]> userTree = persistence.getSearchResult(99, sql.toString());
  705. log.info("getDoubleTreeEle.sql===="+sql);
  706. log.info("getDoubleTreeEle.userTree.size===="+userTree.size());
  707. if(userTree.size()>0){
  708. for(int i=0;i<userTree.size();i++){
  709. String user_id=userTree.get(i)[0];
  710. String user_name=userTree.get(i)[2];
  711. json.append("{ ");
  712. json.append(" id:'" + user_id + "', parentId:'"+dept_id+"',");
  713. json.append(" objectId:'" + user_id + "',");
  714. json.append(" name:'" + user_name + "',");
  715. json.append(" type:'unit',menuType:'nonLeafMenu',");
  716. json.append("oldParentId:'"+dept_id+"', ");
  717. json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'");
  718. json.append("}, ");
  719. }
  720. }
  721. return json.toString();
  722. }
  723. /**
  724. * 批量存储内部人员信息
  725. * @param id
  726. * @param deptId
  727. * @param deptName
  728. * @param orgName
  729. * @param orgId
  730. * @return Msg
  731. * @throws ClassNotFoundException
  732. */
  733. public Msg saveOrg(String linkid,String deptId,String deptName,String orgName,String entryManId,String virtualOrgId) {
  734. Msg m=new Msg();
  735. if(linkid.contains(",")){
  736. linkid= linkid.replace(",", "','");
  737. }
  738. log.info("id================"+linkid);
  739. String mySql ="merge into emc_am_org_inlink p1 "+
  740. "using(select sys_guid() as fdid,b.user_id,b.real_name,b.contingency_type,b.mobile,b.email,b.company_id,b.org_id,b.position,'"+virtualOrgId+"' as virtualId ,b.is_del from SYS_USER_INFO b "+
  741. "where b.is_del='0' and b.user_id in ('"+linkid+"')) p2 "
  742. + "on (p1.inlink_index = p2.user_id and p1.is_del='0' and p1.virtual_org_id=p2.virtualId)when not matched then insert "
  743. + "(p1.fd_objectid,p1.inlink_index,p1.inlink_name,p1.emc_type,p1.phone,p1.email,p1.parent_org_id,p1.parent_dept_id,p1.job,p1.virtual_org_id,p1.is_del,p1.entry_man_id) "
  744. + "values(p2.fdid,p2.user_id,p2.real_name,p2.contingency_type,p2.mobile,p2.email,p2.company_id,p2.org_id,p2.position,p2.virtualId,'0','"+entryManId+"') ";
  745. ORGTemplate org = new ORGTemplate();
  746. log.info("mySql===================\n"+mySql);
  747. int ex;
  748. try {
  749. ex = org.update(mySql);
  750. if(ex>0){
  751. m.setSucsess(new Boolean(true).toString());
  752. //m.setInfo(Parameter.CREATE_SUCSESS);
  753. m.setInfo("right");
  754. return m;
  755. }else{
  756. m.setSucsess(new Boolean(false).toString());
  757. //m.setInfo(Parameter.CREATE_FAILURE);
  758. m.setInfo("error");
  759. return m;
  760. }
  761. } catch (SQLException e) {
  762. e.printStackTrace();
  763. }
  764. return m;
  765. }
  766. /**
  767. * 更具classid设置主键的方法
  768. * @param string
  769. * @return
  770. */
  771. private String setPrimaryId(int classid) {
  772. String fd_id = IdentityGenerator.getIdentityGenerator().gerenalIdentity(classid);
  773. return fd_id;
  774. }
  775. /**
  776. * 根据id获取表中的数据信息 放到map集合中
  777. * @param arr
  778. * @return
  779. * @throws ClassNotFoundException
  780. */
  781. @SuppressWarnings({ "unchecked", "rawtypes" })
  782. public Map<String, List<String>> getUserInfo(String[]arr) throws ClassNotFoundException{
  783. Map<String, List<String>> map=new HashMap<String, List<String>>();
  784. for(int i=0;i<arr.length;i++){
  785. String sql="select real_name,user_id,mobile,email from sys_user_info where user_id='"+arr[i]+"'";
  786. Connection conn = null;
  787. Statement stat = null;
  788. ResultSet rs = null;
  789. DbConnection db = new DbConnection();
  790. try {
  791. conn = db.getConnection();
  792. stat = conn.createStatement();
  793. rs = stat.executeQuery(sql);
  794. List<String> list = new ArrayList();
  795. while (rs.next()) {
  796. list.add(rs.getString("REAL_NAME"));
  797. list.add(rs.getString("MOBILE"));
  798. list.add(rs.getString("USER_ID"));
  799. list.add(rs.getString("EMAIL"));
  800. map.put(rs.getString("USER_ID"), list);
  801. }
  802. } catch (SQLException e) {
  803. this.log.error(e.getMessage(), e);
  804. throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
  805. + sql, e);
  806. } finally {
  807. db.close(rs);
  808. db.close(stat);
  809. db.close(conn);
  810. }
  811. }
  812. log.info("map.size===="+map.size());
  813. return map;
  814. }
  815. /**
  816. * 获得内部联系人的fd_objectId集合
  817. * @return 内部联系人的fd_objectId集合
  818. * @throws ClassNotFoundException
  819. */
  820. @SuppressWarnings({ "unchecked", "rawtypes" })
  821. public List<String> getEmcInlinkId() throws ClassNotFoundException {
  822. String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK";
  823. Connection conn = null;
  824. Statement stat = null;
  825. ResultSet rs = null;
  826. DbConnection db = new DbConnection();
  827. try {
  828. conn = db.getConnection();
  829. stat = conn.createStatement();
  830. rs = stat.executeQuery(sql);
  831. List<String> list = new ArrayList();
  832. while (rs.next()) {
  833. list.add(rs.getString("FD_OBJECTID"));
  834. }
  835. return list;
  836. } catch (SQLException e) {
  837. this.log.error(e.getMessage(), e);
  838. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  839. + sql, e);
  840. } finally {
  841. db.close(rs);
  842. db.close(stat);
  843. db.close(conn);
  844. }
  845. }
  846. /**
  847. * 格式化日期
  848. * @param d
  849. * @return
  850. */
  851. public String formatDate(Date d) {
  852. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  853. String date = sd.format(d);
  854. return date;
  855. }
  856. public String formatDateExpert(Date d) {
  857. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  858. String date = sd.format(d);
  859. return date;
  860. }
  861. /**
  862. * 为新增的内部联系人创建一个fd_objectid
  863. * @param list
  864. * @return
  865. * @throws ClassNotFoundException
  866. */
  867. public String createMsgId(List<String> list) throws ClassNotFoundException{
  868. long l=(long) ((Math.random()+1)*1000000000);
  869. String msgId=l+"";
  870. if(list.contains(msgId)){
  871. return createMsgId(list);
  872. }
  873. else{
  874. log.info("EMC_AM_ORG_INLINK_ID==="+msgId);
  875. return msgId;
  876. }
  877. }
  878. /*******************人力资源双选树结束***************************************************/
  879. /*******************存储专家信息开始***************************************************/
  880. public Msg saveExpert(String id,String compId,String userId) throws Exception{
  881. Msg m=new Msg();
  882. // String[]idArr=id.split("%")[0].split(",");
  883. String[]idArr=id.split(",");
  884. Map<String, List<String>>userMap=new HashMap<String, List<String>>();
  885. userMap=getInlinkInfo(idArr);
  886. Connection conn = null;
  887. PreparedStatement st = null;
  888. DbConnection db = new DbConnection();
  889. log.info("idArr.length================"+idArr.length);
  890. try {
  891. String sql = "INSERT INTO EMC_AM_EMERGENCY_EXPERT(FD_OBJECTID,EXPERT_ID,EXPERT_NAME,EXPERT_CAL,EXPERT_EMAIL,EXPERT_UNIT,IS_SNSTAFF,IS_DEL,UPDATEDATE,CHANGE_TYPE,COLUMN_1,COLUMN_2,COLUMN_3,EXPERT_TEL,EXPERT_SEX,EXPERT_RESUME)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  892. conn = db.getConnection();
  893. int num=0;
  894. conn.setAutoCommit(false);
  895. st = conn.prepareStatement(sql);
  896. for(int i=0;i<idArr.length;i++){
  897. st.setString(1, userMap.get(idArr[i]).get(7));//获取源数据的id做主键
  898. // st.setString(1, createMsgId(getEmcExpertId()));//随机生成主键
  899. st.setString(2, userMap.get(idArr[i]).get(5));//Expert_ID
  900. st.setString(3, userMap.get(idArr[i]).get(0));//EXPERT_NAME
  901. st.setString(4, userMap.get(idArr[i]).get(2));//EXPERT_CAL
  902. st.setString(5, userMap.get(idArr[i]).get(3));//EXPERT_EMAIL
  903. st.setString(6, compId);//EXPERT_UNIT
  904. st.setString(7, "0");//IS_SNSTAFF
  905. st.setString(8, "0");//IS_DEL
  906. st.setString(9, formatDateExpert(new Date()));//UPDATEDATE
  907. st.setString(10, "1");//CHANGE_TYPE
  908. st.setString(11, "0");
  909. st.setString(12, "0");
  910. st.setString(13, "0");
  911. st.setString(14, userMap.get(idArr[i]).get(1));
  912. if(userMap.get(idArr[i]).get(6)=="女"){
  913. st.setString(15, "0");
  914. }else{
  915. st.setString(15, "1");
  916. }
  917. st.setString(16, userId);
  918. st.executeUpdate();
  919. num++;
  920. }
  921. log.info("num====="+num);
  922. if(num==idArr.length){
  923. log.info("保存成功");
  924. conn.commit();
  925. m.setSucsess(new Boolean(true).toString());
  926. m.setInfo(Parameter.CREATE_SUCSESS);
  927. return m;
  928. }else{
  929. m.setSucsess(new Boolean(false).toString());
  930. m.setInfo(Parameter.CREATE_FAILURE);
  931. // st.executeBatch();
  932. conn.rollback();
  933. log.info("保存失败");
  934. return m;}
  935. } catch (SQLException e) {
  936. this.log.error(e.getMessage(), e);
  937. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  938. } finally {
  939. db.close(st);
  940. db.close(conn);
  941. }
  942. }
  943. public Msg saveOrg2(String id,String deptId,String deptName,String orgName,String entryManId,String virtualOrgId) throws Exception{
  944. Msg m=new Msg();
  945. // String[]idArr=id.split("%")[0].split(",");
  946. String[]idArr=id.split(",");
  947. Map<String, List<String>>userMap=new HashMap<String, List<String>>();
  948. userMap=getInlinkInfo2(idArr);
  949. Connection conn = null;
  950. PreparedStatement st = null;
  951. DbConnection db = new DbConnection();
  952. log.info("idArr.length================"+idArr.length);
  953. try {
  954. String sql = "INSERT INTO emc_am_org_inlink(FD_OBJECTID,inlink_index,inlink_name,emc_type,phone,email,parent_org_id,parent_dept_id,job,virtual_org_id,is_del,sort_no,entry_man_id,UPDATEDATE,PARENT_DEPT)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  955. conn = db.getConnection();
  956. int num=0;
  957. conn.setAutoCommit(false);
  958. st = conn.prepareStatement(sql);
  959. for(int i=0;i<idArr.length;i++){
  960. st.setString(1, createMsgId(getEmcExpertId()));//随机生成主键
  961. st.setString(2, userMap.get(idArr[i]).get(0));//序号
  962. log.info("inlink_index:"+ userMap.get(idArr[i]).get(0));
  963. st.setString(3, userMap.get(idArr[i]).get(1));//姓名
  964. log.info("inlink_name:"+userMap.get(idArr[i]).get(1));
  965. st.setString(4, userMap.get(idArr[i]).get(2));//应急类别
  966. log.info("emc_type:"+userMap.get(idArr[i]).get(2));
  967. st.setString(5, userMap.get(idArr[i]).get(3));//手机
  968. log.info("phone:"+userMap.get(idArr[i]).get(3));
  969. st.setString(6, userMap.get(idArr[i]).get(4));//邮件
  970. log.info("email:"+userMap.get(idArr[i]).get(4));
  971. st.setString(7, getCorpId(userMap.get(idArr[i]).get(6)));//所属单位 应该根据人所在的部门ID转换单位ID
  972. log.info("parent_org_id:"+userMap.get(idArr[i]).get(5));
  973. st.setString(8, userMap.get(idArr[i]).get(6));
  974. log.info("parent_dept_id:"+userMap.get(idArr[i]).get(6));
  975. st.setString(9, userMap.get(idArr[i]).get(7));
  976. log.info("job:"+userMap.get(idArr[i]).get(7));
  977. st.setString(10, virtualOrgId);
  978. log.info("virtual_org_id:"+virtualOrgId);
  979. st.setString(11, "0");//删除标志
  980. log.info("is_del:"+ "0");
  981. //判断有没有初始值
  982. if(!checkhaveId(virtualOrgId)){
  983. st.setString(12, String.valueOf(555555551+i));
  984. log.info("sort_no:"+ String.valueOf(555555551+i));
  985. }else{
  986. st.setString(12, String.valueOf(houxuzhi(virtualOrgId)+i+1));
  987. log.info("sort_no:"+ String.valueOf(houxuzhi(virtualOrgId)+i+1));
  988. }
  989. st.setString(13, entryManId);
  990. log.info("entry_man_id:"+ entryManId);
  991. st.setString(14, formatDateExpert(new Date()));
  992. log.info("UPDATEDATE:"+ formatDateExpert(new Date()));
  993. st.setString(15, deptId);
  994. log.info("PARENT_DEPT:"+ deptId);
  995. st.executeUpdate();
  996. num++;
  997. }
  998. log.info("num====="+num);
  999. if(num==idArr.length){
  1000. log.info("保存成功");
  1001. conn.commit();
  1002. m.setSucsess(new Boolean(true).toString());
  1003. m.setInfo(Parameter.CREATE_SUCSESS);
  1004. return m;
  1005. }else{
  1006. m.setSucsess(new Boolean(false).toString());
  1007. m.setInfo(Parameter.CREATE_FAILURE);
  1008. // st.executeBatch();
  1009. conn.rollback();
  1010. log.info("保存失败");
  1011. return m;}
  1012. } catch (SQLException e) {
  1013. this.log.error(e.getMessage(), e);
  1014. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  1015. } finally {
  1016. db.close(st);
  1017. db.close(conn);
  1018. }
  1019. }
  1020. //将dept_id转换为单位ID
  1021. public String getCorpId(String id){
  1022. DbConnection db = new DbConnection();
  1023. Connection conn = null;
  1024. PreparedStatement pstm = null;//sql语句的执行者
  1025. ResultSet rs = null;//结果集
  1026. String sql ="";
  1027. String result ="";
  1028. sql="select CORP_ID from sys_department where dept_id ='"+id+"'";
  1029. try {
  1030. conn = db.getConnection();
  1031. pstm = conn.prepareStatement(sql);
  1032. rs = pstm.executeQuery();
  1033. while(rs.next()){
  1034. result = rs.getString("CORP_ID") == null ? "" : rs.getString("CORP_ID");//单位ID
  1035. log.info("==================================================================="+result);
  1036. }
  1037. } catch (ClassNotFoundException e) {
  1038. // TODO Auto-generated catch block
  1039. e.printStackTrace();
  1040. } catch (SQLException e) {
  1041. // TODO Auto-generated catch block
  1042. e.printStackTrace();
  1043. }finally{
  1044. try {
  1045. if(rs!= null){
  1046. rs.close();
  1047. }
  1048. if(pstm!= null){
  1049. pstm.close();
  1050. }
  1051. if(conn!= null){
  1052. conn.close();
  1053. }
  1054. } catch (SQLException e) {
  1055. e.printStackTrace();
  1056. }
  1057. }
  1058. return result;
  1059. }
  1060. public boolean checkhaveId(String id) {
  1061. try{
  1062. String sql="select * from emc_am_org_inlink where virtual_org_id ='"+id+"' and is_del = '0' and sort_no is not null";
  1063. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  1064. if(tempList==null||tempList.size()==0){
  1065. return false;
  1066. }else{
  1067. return true;
  1068. }}catch(Exception e){
  1069. this.log.error(e.getMessage(), e);
  1070. return false;
  1071. }
  1072. }
  1073. public int houxuzhi(String id) throws ClassNotFoundException {
  1074. try{
  1075. String sql="select sort_no from emc_am_org_inlink where virtual_org_id ='"+id+"' and is_del = '0' and sort_no is not null order by sort_no desc";
  1076. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  1077. return Integer.parseInt(tempList.get(0)[0]);
  1078. }catch(Exception e){
  1079. this.log.error(e.getMessage(), e);
  1080. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  1081. }
  1082. }
  1083. /**
  1084. * 根据id获取表中的数据信息 放到map集合中
  1085. * @param arr
  1086. * @return
  1087. * @throws ClassNotFoundException
  1088. */
  1089. @SuppressWarnings({ "unchecked", "rawtypes" })
  1090. public Map<String, List<String>> getInlinkInfo(String[]arr) throws ClassNotFoundException{
  1091. Map<String, List<String>> map=new HashMap<String, List<String>>();
  1092. for(int i=0;i<arr.length;i++){
  1093. String sql="select REAL_NAME,OFFICE_PHONE,MOBILE,EMAIL,COMPANY_ID,FD_OBJECTID,EMPLOY_NO,GENDER,FD_OBJECTID from sys_user_info where FD_OBJECTID='"+arr[i]+"'";
  1094. Connection conn = null;
  1095. Statement stat = null;
  1096. ResultSet rs = null;
  1097. DbConnection db = new DbConnection();
  1098. try {
  1099. conn = db.getConnection();
  1100. stat = conn.createStatement();
  1101. rs = stat.executeQuery(sql);
  1102. List<String> list = new ArrayList();
  1103. while (rs.next()) {
  1104. list.add(rs.getString("REAL_NAME"));
  1105. list.add(rs.getString("OFFICE_PHONE"));
  1106. list.add(rs.getString("MOBILE"));
  1107. list.add(rs.getString("EMAIL"));
  1108. list.add(rs.getString("COMPANY_ID"));
  1109. list.add(rs.getString("EMPLOY_NO"));
  1110. list.add(rs.getString("GENDER"));
  1111. list.add(rs.getString("FD_OBJECTID"));
  1112. map.put(rs.getString("FD_OBJECTID"), list);
  1113. }
  1114. } catch (SQLException e) {
  1115. this.log.error(e.getMessage(), e);
  1116. throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
  1117. + sql, e);
  1118. } finally {
  1119. db.close(conn);
  1120. db.close(stat);
  1121. db.close(rs);
  1122. }
  1123. }
  1124. log.info("map.size===="+map.size());
  1125. return map;
  1126. }
  1127. /**
  1128. *
  1129. * @param arr
  1130. * @return
  1131. * @throws ClassNotFoundException
  1132. */
  1133. @SuppressWarnings({ "rawtypes", "unchecked" })
  1134. public Map<String, List<String>> getInlinkInfo2(String[]arr) throws ClassNotFoundException{
  1135. Map<String, List<String>> map=new HashMap<String, List<String>>();
  1136. for(int i=0;i<arr.length;i++){
  1137. String sql="select FD_OBJECTID,user_id,real_name,contingency_type,mobile,login_name,company_id,org_id,position from sys_user_info where FD_OBJECTID='"+arr[i]+"'";
  1138. Connection conn = null;
  1139. Statement stat = null;
  1140. ResultSet rs = null;
  1141. DbConnection db = new DbConnection();
  1142. try {
  1143. conn = db.getConnection();
  1144. stat = conn.createStatement();
  1145. rs = stat.executeQuery(sql);
  1146. List<String> list = new ArrayList();
  1147. while (rs.next()) {
  1148. list.add(rs.getString("USER_ID"));
  1149. list.add(rs.getString("REAL_NAME"));
  1150. list.add(rs.getString("CONTINGENCY_TYPE"));
  1151. list.add(rs.getString("MOBILE"));
  1152. list.add(rs.getString("LOGIN_NAME"));
  1153. list.add(rs.getString("COMPANY_ID"));
  1154. list.add(rs.getString("ORG_ID"));
  1155. list.add(rs.getString("POSITION"));
  1156. map.put(rs.getString("FD_OBJECTID"), list);
  1157. }
  1158. } catch (SQLException e) {
  1159. this.log.error(e.getMessage(), e);
  1160. throw new ClassNotFoundException("DAO Layou: 取得用户最近联系人"
  1161. + sql, e);
  1162. } finally {
  1163. db.close(conn);
  1164. db.close(stat);
  1165. db.close(rs);
  1166. }
  1167. }
  1168. log.info("map.size===="+map.size());
  1169. return map;
  1170. }
  1171. @SuppressWarnings({ "unchecked", "rawtypes" })
  1172. public List<String> getEmcExpertId() throws ClassNotFoundException {
  1173. String sql = "SELECT FD_OBJECTID FROM EMC_AM_ORG_INLINK";
  1174. Connection conn = null;
  1175. Statement stat = null;
  1176. ResultSet rs = null;
  1177. DbConnection db = new DbConnection();
  1178. try {
  1179. conn = db.getConnection();
  1180. stat = conn.createStatement();
  1181. rs = stat.executeQuery(sql);
  1182. List<String> list = new ArrayList();
  1183. while (rs.next()) {
  1184. list.add(rs.getString("FD_OBJECTID"));
  1185. }
  1186. return list;
  1187. } catch (SQLException e) {
  1188. this.log.error(e.getMessage(), e);
  1189. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  1190. + sql, e);
  1191. } finally {
  1192. db.close(rs);
  1193. db.close(stat);
  1194. db.close(conn);
  1195. }
  1196. }
  1197. /*******************存储专家信息结束***************************************************/
  1198. /*******************存储队伍人员信息开始***************************************************/
  1199. /**
  1200. * @param id
  1201. * @param teamId
  1202. * @return
  1203. */
  1204. public Msg saveTeamPerson(String id, String teamId)throws Exception {
  1205. Msg m=new Msg();
  1206. String[]idArr=id.split("%")[0].split(",");
  1207. Map<String, List<String>>userMap=new HashMap<String, List<String>>();
  1208. userMap=getInlinkInfo(idArr);
  1209. Connection conn = null;
  1210. PreparedStatement st = null;
  1211. DbConnection db = new DbConnection();
  1212. log.info("idArr.length================"+idArr.length);
  1213. try {
  1214. String sql = "INSERT INTO EMC_AM_TEAM_PERSONNEL(FD_OBJECTID,TEAM_NAME,CODE,NAME,DEPT_ID,TELEPHONE,IS_DEL,UPDATEDATE,TEAM_SYSTEM)VALUES(?,?,?,?,?,?,?,?,?)";
  1215. conn = db.getConnection();
  1216. int num=0;
  1217. conn.setAutoCommit(false);
  1218. st = conn.prepareStatement(sql);
  1219. for(int i=0;i<idArr.length;i++){
  1220. st.setString(1, createMsgId(getEmcTeamPersonId()));
  1221. st.setString(2, teamId);//TEAM_NAME
  1222. st.setString(3, idArr[i]);//CODE
  1223. st.setString(4, userMap.get(idArr[i]).get(0));//NAME
  1224. st.setString(5, userMap.get(idArr[i]).get(4));//DEPT_ID
  1225. st.setString(6, userMap.get(idArr[i]).get(1));//TELEPHONE
  1226. st.setString(7, "0");//IS_DEL
  1227. st.setString(8, formatDateExpert(new Date()));//DPDATEDATE
  1228. st.setString(9, "0");//TEAM_SYSTEM
  1229. st.executeUpdate();
  1230. num++;
  1231. }
  1232. log.info("num====="+num);
  1233. if(num==idArr.length){
  1234. log.info("保存成功");
  1235. conn.commit();
  1236. m.setSucsess(new Boolean(true).toString());
  1237. m.setInfo(Parameter.CREATE_SUCSESS);
  1238. return m;
  1239. }else{
  1240. m.setSucsess(new Boolean(false).toString());
  1241. m.setInfo(Parameter.CREATE_FAILURE);
  1242. // st.executeBatch();
  1243. conn.rollback();
  1244. log.info("保存失败");
  1245. return m;}
  1246. } catch (SQLException e) {
  1247. this.log.error(e.getMessage(), e);
  1248. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  1249. } finally {
  1250. db.close(st);
  1251. db.close(conn);
  1252. }
  1253. }
  1254. /**
  1255. * @return
  1256. */
  1257. @SuppressWarnings({ "unchecked", "rawtypes" })
  1258. private List<String> getEmcTeamPersonId() throws Exception{
  1259. String sql = "SELECT FD_OBJECTID FROM EMC_AM_TEAM_PERSONNEL";
  1260. Connection conn = null;
  1261. Statement stat = null;
  1262. ResultSet rs = null;
  1263. DbConnection db = new DbConnection();
  1264. try {
  1265. conn = db.getConnection();
  1266. stat = conn.createStatement();
  1267. rs = stat.executeQuery(sql);
  1268. List<String> list = new ArrayList();
  1269. while (rs.next()) {
  1270. list.add(rs.getString("FD_OBJECTID"));
  1271. }
  1272. return list;
  1273. } catch (SQLException e) {
  1274. this.log.error(e.getMessage(), e);
  1275. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  1276. + sql, e);
  1277. } finally {
  1278. db.close(rs);
  1279. db.close(stat);
  1280. db.close(conn);
  1281. }
  1282. }
  1283. /**根据部门ID获得其下的所有人员-内部人员(外部机构添加时联动部门下的联系人)
  1284. *
  1285. * @param id
  1286. * @return
  1287. */
  1288. public String getInlinkById(String id,String type) {
  1289. SysModel sysmodel = ModelFactory.getSysmodel();
  1290. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1291. StringBuffer json = new StringBuffer();
  1292. String sql;
  1293. if(type=="1"||"1".equals(type)){
  1294. sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and VIRTUAL_ORG_ID='"
  1295. + id + "' ORDER BY INLINK_INDEX ASC ";
  1296. }else{
  1297. sql = "SELECT FD_OBJECTID,INLINK_INDEX,INLINK_NAME FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' and PARENT_DEPT_ID='"
  1298. + id + "' ORDER BY INLINK_INDEX ASC ";
  1299. }
  1300. log.info("=="+sql);
  1301. json.append("{\"treeNodes\":[");
  1302. /*json.append("{ ");
  1303. json.append(" \"id\":\"" + id + "\", \"parentId\":\"0\",");
  1304. json.append(" \"name\":\"人员列表\",");
  1305. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\" ");
  1306. json.append("}, ");*/
  1307. try {
  1308. ArrayList<String[]> list = persistence.getSearchResult(210, sql.toString());
  1309. int num = list.size();
  1310. for (int i = 0; i < num; i++) {
  1311. String[] temp = list.get(i);
  1312. String pCode = temp[0];
  1313. String name = temp[2];
  1314. json.append("{ ");
  1315. json.append(" \"id\":\"" + pCode + "\", \"parentId\":\"" + id + "\",");
  1316. json.append(" \"name\":\"" + name + "\",");
  1317. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user_group.gif\" ");
  1318. json.append("}, ");
  1319. }
  1320. } catch (PersistenceException e) {
  1321. log.error("查询内部人员数据错误-- ", e);
  1322. }
  1323. //清除最后一个‘,’
  1324. if (json.lastIndexOf(",") > -1) {
  1325. json.deleteCharAt(json.lastIndexOf(","));
  1326. }
  1327. json.append("]}");
  1328. return json.toString();
  1329. }
  1330. /*******************************************************内部人员统计开始************************/
  1331. public String InlinkStatisticsInit(String id){
  1332. StringBuffer json = new StringBuffer();
  1333. json.insert(0, "{\"rows\":[");
  1334. json.append(InlinkNumInit(id));
  1335. json.append("]}");
  1336. return json.toString();
  1337. }
  1338. /** 初始化数据(数据格式 {rows:[{}} )
  1339. *1.先获取实体机构信息(根据传来的id)如果存在下级单位显示“+”
  1340. 2.统计该机构下的所有虚拟机构的人员信息
  1341. * 2.1递归查询该实体机构下的所有虚拟机构获得机构id
  1342. * 2.2查询人员表 获得该虚拟机构下的所有人员信息
  1343. * 2.3对人员信息进行分类统计(应急类别的人数和应急角色的人数)将统计信息填充到该机构对应的OrgInDeptStatistics中
  1344. * 2.4汇总每个虚拟机构的OrgInDeptStatistics信息得到实体机构的OrgInDeptStatistics信息
  1345. 3.获得实体机构下所有虚拟机构的实际人数
  1346. *3.1递归获得该实体机构下的所有虚拟机构的id
  1347. *3.2在人员表中统计出存在id下的所有人员个数,去重(根据inlink_index)
  1348. * @param id
  1349. * @return
  1350. */
  1351. public String InlinkNumInit(String id) {
  1352. SysModel sysmodel = ModelFactory.getSysmodel();
  1353. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1354. StringBuffer json = new StringBuffer();
  1355. StringBuffer sql = new StringBuffer();
  1356. /*//是否存在虚拟子机构
  1357. boolean hasVirtualDept =hasVirtualDept(id);*/
  1358. //是否存在子机构 实体的
  1359. boolean hasChildDept = hasEntityChildDept(id);
  1360. //存储统计信息的实体类
  1361. OrgInDeptStatistics OIDS = new OrgInDeptStatistics();
  1362. /*//获得该机构下的所有虚拟机构id
  1363. ArrayList<String> virtualDeptIds = new ArrayList<String>();
  1364. if(hasVirtualDept){
  1365. virtualDeptIds = getVirtualDeptIds(id);
  1366. }*/
  1367. //获得该实体机构下所有人员的统计信息
  1368. OIDS = getStatisticsByIds(id);
  1369. //获得该实体机构下的所有人员的总数
  1370. int staffNum = getStaffNum(id);
  1371. sql.append("--查询传来id的机构信息 \n");
  1372. sql.append("SELECT ID , NAME ,PARENT_ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n ");
  1373. if (id.equals("")) {
  1374. sql.append(" AND ID='1'");
  1375. } else {
  1376. sql.append(" AND ID='" + id + "'");
  1377. }
  1378. sql.append(" ORDER BY SORT asc \n");
  1379. try {
  1380. ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
  1381. String[] temp = listRoot.get(0);
  1382. String deptId = temp[0];
  1383. String deptName = temp[1];
  1384. String parentId = temp[2];
  1385. //json.append("{rows:[");
  1386. json.append("{");
  1387. json.append(" \"dept_id\":\"" + deptId + "\", ");
  1388. json.append(" \"parentId\":\"" + parentId + "\", ");
  1389. json.append(" \"name\":\"" + deptName + "\", ");
  1390. //统计信息的赋值
  1391. //json.append(" \"AccNum\":\"" + OIDS.getAccNum() + "\", ");
  1392. //json.append(" \"EmergencyRoleNum\":\"" + OIDS.getEmergencyRoleNum() + "\", ");
  1393. json.append(" \"AccNum\":\"" + staffNum + "\", ");
  1394. json.append(" \"EmergencyRoleNum\":\"" + staffNum + "\", ");
  1395. json.append(" \"LifeAcc\":\"" + OIDS.getLifeAcc() + "\", ");
  1396. json.append(" \"PowerNetWorkAcc\":\"" + OIDS.getPowerNetWorkAcc() + "\", ");
  1397. json.append(" \"WindFloodAcc\":\"" + OIDS.getWindFloodAcc() + "\", ");
  1398. json.append(" \"EquipmentAcc\":\"" + OIDS.getEquipmentAcc() + "\", ");
  1399. json.append(" \"ElseAcc\":\"" + OIDS.getElseAcc() + "\", ");
  1400. json.append(" \"GeneralDirector\":\"" + OIDS.getGeneralDirector() + "\", ");
  1401. json.append(" \"DetupyDirector\":\"" + OIDS.getDetupyDirector() + "\", ");
  1402. json.append(" \"Chairman\":\"" + OIDS.getChairman() + "\", ");
  1403. json.append(" \"DetupyChairman\":\"" + OIDS.getDetupyChairman() + "\", ");
  1404. json.append(" \"Member\":\"" + OIDS.getMember() + "\", ");
  1405. json.append(" \"Administrator\":\"" + OIDS.getAdministrator() + "\", ");
  1406. if(hasChildDept){
  1407. json.append(" \"isParent\":true, ");
  1408. json.append(" \"open\":false, ");
  1409. }else{
  1410. json.append(" \"isParent\":false, ");
  1411. json.append(" \"open\":true, ");
  1412. }
  1413. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  1414. json.append("}");
  1415. //json.append("]}");
  1416. } catch (PersistenceException e) {
  1417. e.printStackTrace();
  1418. }
  1419. return json.toString();
  1420. }
  1421. /**
  1422. * @param id
  1423. * @return
  1424. */
  1425. private boolean hasEntityChildDept(String deptId) {
  1426. /*
  1427. Connection conn = null;
  1428. PreparedStatement ps = null;
  1429. ResultSet rs = null;
  1430. DbConnection db = new DbConnection();
  1431. StringBuffer sql = new StringBuffer();
  1432. sql.append("--查询该机构是否有子机构 \n");
  1433. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
  1434. try {
  1435. conn = db.getConnection();
  1436. ps = conn.prepareStatement(sql.toString());
  1437. ps.setString(1, deptId);
  1438. ps.setString(2, "0");
  1439. ps.setString(3, "0");
  1440. //log.info("查询是否有子机构 sql="+sql);
  1441. rs =ps.executeQuery();
  1442. if(rs.next()){
  1443. //log.info("是否有子机构"+rs.getBoolean(1));
  1444. return rs.getBoolean(1);
  1445. };
  1446. } catch (Exception e) {
  1447. log.error("查询是否存在子机构", e);
  1448. } finally {
  1449. db.close(conn);
  1450. db.close(ps);
  1451. db.close(rs);
  1452. }
  1453. return false;
  1454. */
  1455. Connection conn = null;
  1456. PreparedStatement ps = null;
  1457. ResultSet rs = null;
  1458. DbConnection db = new DbConnection();
  1459. StringBuffer sql = new StringBuffer();
  1460. sql.append("--查询该机构是否有子机构 \n");
  1461. sql.append("SELECT COUNT(1) c FROM EMC_DEPARTMENT_IN WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
  1462. try {
  1463. conn = db.getConnection();
  1464. ps = conn.prepareStatement(sql.toString());
  1465. ps.setString(1, deptId);
  1466. ps.setString(2, "0");
  1467. ps.setString(3, "0");
  1468. //log.info("查询是否有子机构 sql="+sql);
  1469. rs =ps.executeQuery();
  1470. if(rs.next()){
  1471. //log.info("是否有子机构"+rs.getBoolean(1));
  1472. return rs.getBoolean(1);
  1473. };
  1474. } catch (Exception e) {
  1475. log.error("查询是否存在子机构", e);
  1476. } finally {
  1477. db.close(conn);
  1478. db.close(ps);
  1479. db.close(rs);
  1480. }
  1481. return false;
  1482. }
  1483. /**
  1484. * @param id
  1485. * @return
  1486. */
  1487. private int getStaffNum(String id) {
  1488. int staffNum=0;
  1489. SysModel sysmodel = ModelFactory.getSysmodel();
  1490. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1491. StringBuffer sql = new StringBuffer();
  1492. sql.append("-- 统计给定id的机构下的人员总数 \n");
  1493. sql.append(" SELECT DISTINCT INLINK_INDEX FROM EMC_AM_ORG_INLINK WHERE IS_DEL='0' \n");
  1494. sql.append(" AND PARENT_ORG_ID ='"+id+"' \n");
  1495. try {
  1496. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  1497. staffNum = list.size();
  1498. } catch (PersistenceException e) {
  1499. e.printStackTrace();
  1500. }
  1501. return staffNum;
  1502. }
  1503. /**
  1504. * @param virtualDeptIds
  1505. * @return
  1506. */
  1507. private OrgInDeptStatistics getStatisticsByIds(String id) {
  1508. OrgInDeptStatistics OIDS = new OrgInDeptStatistics();
  1509. SysModel sysmodel = ModelFactory.getSysmodel();
  1510. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1511. StringBuffer sql = new StringBuffer();
  1512. sql.append("SELECT COUNT(1) AS 应急类别总数, COUNT(1) AS 应急角色总数, COUNT(DECODE(EMC_TYPE,'1',1,0)) AS 人身事故, COUNT(DECODE(EMC_TYPE,'2',1,0)) AS 电网事故, COUNT(DECODE(EMC_TYPE,'4',1,0)) AS 防风防汛, COUNT(DECODE(EMC_TYPE,'3',1,0)) AS 设备事故, COUNT(DECODE(EMC_TYPE,'5',1,0)) AS 其他, \n");
  1513. sql.append("COUNT(DECODE(EMC_ROLE,'1',1,0)) AS 总指挥, COUNT(DECODE(EMC_ROLE,'2',1,0)) AS 副总指挥, COUNT(DECODE(EMC_ROLE,'3',1,0)) AS 主任, COUNT(DECODE(EMC_ROLE,'4',1,0)) AS 副主任, COUNT(DECODE(EMC_ROLE,'5',1,0)) AS 成员,COUNT(DECODE(EMC_ROLE,'6 ',1,0)) AS 管理人员 \n");
  1514. sql.append("FROM EMC_AM_ORG_INLINK WHERE IS_DEL = '0' \n ");
  1515. sql.append(" AND VIRTUAL_ORG_ID IN ("+" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0'"+") \n");
  1516. log.info("sql=========="+sql);
  1517. try {
  1518. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  1519. for(int i = 0;i<list.size();i++){
  1520. String[] temp = list.get(i);
  1521. //将每条结果对应的数据合并到OIDS中
  1522. OIDS.setAccNum(OIDS.getAccNum()+Integer.parseInt(temp[0]));//应急类型总数
  1523. OIDS.setEmergencyRoleNum(OIDS.getEmergencyRoleNum()+Integer.parseInt(temp[1]));//应急角色--总数
  1524. OIDS.setLifeAcc(OIDS.getLifeAcc()+Integer.parseInt(temp[2]));//应急类型--人身事故
  1525. OIDS.setPowerNetWorkAcc(OIDS.getPowerNetWorkAcc()+Integer.parseInt(temp[3]));//应急类别--电网事故
  1526. OIDS.setWindFloodAcc(OIDS.getWindFloodAcc()+Integer.parseInt(temp[4]));//应急类别--防风防汛
  1527. OIDS.setEquipmentAcc(OIDS.getEquipmentAcc()+Integer.parseInt(temp[5]));//应急类别--设备事故
  1528. OIDS.setElseAcc(OIDS.getElseAcc()+Integer.parseInt(temp[6]));//应急类别--其他应急类别
  1529. OIDS.setGeneralDirector(OIDS.getGeneralDirector()+Integer.parseInt(temp[7]));//应急角色--总指挥
  1530. OIDS.setDetupyDirector(OIDS.getDetupyDirector()+Integer.parseInt(temp[8]));//应急角色--副总指挥
  1531. OIDS.setChairman(OIDS.getChairman()+Integer.parseInt(temp[9]));//应急角色--主任
  1532. OIDS.setDetupyChairman(OIDS.getDetupyChairman()+Integer.parseInt(temp[10]));//应急角色--副主任
  1533. OIDS.setMember(OIDS.getMember()+Integer.parseInt(temp[11]));//应急角色--成员
  1534. OIDS.setAdministrator(OIDS.getAdministrator()+Integer.parseInt(temp[12]));//应急角色--管理人员
  1535. }
  1536. } catch (PersistenceException e) {
  1537. // TODO Auto-generated catch block
  1538. e.printStackTrace();
  1539. }
  1540. /*for(int i =0;i<virtualDeptIds.size();i++){
  1541. String tempId = virtualDeptIds.get(i);
  1542. if(hasStaff(tempId)){
  1543. StringBuffer sql = new StringBuffer();
  1544. sql.append("-- 统计给定id的机构信息 \n");
  1545. sql.append("SELECT COUNT(1) AS 应急类别总数, COUNT(1) AS 应急角色总数, SUM(DECODE(EMC_TYPE,'1',1,0)) AS 人身事故, SUM(DECODE(EMC_TYPE,'2',1,0)) AS 电网事故, SUM(DECODE(EMC_TYPE,'4',1,0)) AS 防风防汛, SUM(DECODE(EMC_TYPE,'3',1,0)) AS 设备事故, SUM(DECODE(EMC_TYPE,'5',1,0)) AS 其他, \n");
  1546. sql.append("SUM(DECODE(EMC_ROLE,'1',1,0)) AS 总指挥, SUM(DECODE(EMC_ROLE,'2',1,0)) AS 副总指挥, SUM(DECODE(EMC_ROLE,'3',1,0)) AS 主任, SUM(DECODE(EMC_ROLE,'4',1,0)) AS 副主任, SUM(DECODE(EMC_ROLE,'5',1,0)) AS 成员,SUM(DECODE(EMC_ROLE,'6 ',1,0)) AS 管理人员 \n");
  1547. sql.append("FROM EMC_AM_ORG_INLINK WHERE IS_DEL = '0' \n ");
  1548. sql.append(" AND PARENT_DEPT_ID='"+tempId+"' \n");
  1549. log.info("sql=========="+sql);
  1550. //sql.append(" GROUP BY PARENT_DEPT_ID \n");
  1551. try {
  1552. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  1553. String[] temp = list.get(0);
  1554. //将每条结果对应的数据合并到OIDS中
  1555. OIDS.setAccNum(OIDS.getAccNum()+Integer.parseInt(temp[0]));//应急类型总数
  1556. OIDS.setEmergencyRoleNum(OIDS.getEmergencyRoleNum()+Integer.parseInt(temp[1]));//应急角色--总数
  1557. OIDS.setLifeAcc(OIDS.getLifeAcc()+Integer.parseInt(temp[2]));//应急类型--人身事故
  1558. OIDS.setPowerNetWorkAcc(OIDS.getPowerNetWorkAcc()+Integer.parseInt(temp[3]));//应急类别--电网事故
  1559. OIDS.setWindFloodAcc(OIDS.getWindFloodAcc()+Integer.parseInt(temp[4]));//应急类别--防风防汛
  1560. OIDS.setEquipmentAcc(OIDS.getEquipmentAcc()+Integer.parseInt(temp[5]));//应急类别--设备事故
  1561. OIDS.setElseAcc(OIDS.getElseAcc()+Integer.parseInt(temp[6]));//应急类别--其他应急类别
  1562. OIDS.setGeneralDirector(OIDS.getGeneralDirector()+Integer.parseInt(temp[7]));//应急角色--总指挥
  1563. OIDS.setDetupyDirector(OIDS.getDetupyDirector()+Integer.parseInt(temp[8]));//应急角色--副总指挥
  1564. OIDS.setChairman(OIDS.getChairman()+Integer.parseInt(temp[9]));//应急角色--主任
  1565. OIDS.setDetupyChairman(OIDS.getDetupyChairman()+Integer.parseInt(temp[10]));//应急角色--副主任
  1566. OIDS.setMember(OIDS.getMember()+Integer.parseInt(temp[11]));//应急角色--成员
  1567. OIDS.setAdministrator(OIDS.getAdministrator()+Integer.parseInt(temp[12]));//应急角色--管理人员
  1568. } catch (PersistenceException e) {
  1569. e.printStackTrace();
  1570. }
  1571. }
  1572. }*/
  1573. return OIDS;
  1574. }
  1575. /** 根据传来的id获得该机构下的所有虚拟机构id
  1576. * @param id
  1577. * @return
  1578. */
  1579. private ArrayList<String> getVirtualDeptIds(String id) {
  1580. /*
  1581. ArrayList<String> listIds = new ArrayList<String>();
  1582. SysModel sysmodel = ModelFactory.getSysmodel();
  1583. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1584. StringBuffer sql = new StringBuffer();
  1585. sql.append(" --查询给定机构下的子虚拟机构ids \n");
  1586. sql.append(" SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0' \n");
  1587. sql.append(" ORDER BY SORT asc \n");
  1588. try {
  1589. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  1590. String[] temp;
  1591. for(int i = 0;i<list.size();i++){
  1592. temp = list.get(i);
  1593. String deptId = temp[0];
  1594. listIds.add(deptId);
  1595. if(hasVirtualDept(deptId)){
  1596. listIds.addAll(getVirtualDeptIds(deptId));
  1597. }
  1598. }
  1599. } catch (PersistenceException e) {
  1600. e.printStackTrace();
  1601. }
  1602. return listIds;
  1603. */
  1604. ArrayList<String> listIds = new ArrayList<String>();
  1605. SysModel sysmodel = ModelFactory.getSysmodel();
  1606. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1607. StringBuffer sql = new StringBuffer();
  1608. sql.append(" --查询给定机构下的子虚拟机构ids \n");
  1609. sql.append(" SELECT ORG_ID FROM EMC_DEPARTMENT_IN WHERE INSTR(PATH_ID,'_"+id+"_')>0 AND IS_VIRTUAL='1' AND IS_DEL='0' \n");
  1610. ArrayList<String[]> list = new ArrayList<String[]>();
  1611. try {
  1612. list = persistence.getSearchResult(99, sql.toString());
  1613. } catch (PersistenceException e) {
  1614. e.printStackTrace();
  1615. }
  1616. String[] temp;
  1617. for(int i = 0;i<list.size();i++){
  1618. temp = list.get(i);
  1619. String deptId = temp[0];
  1620. listIds.add(deptId);
  1621. }
  1622. return listIds;
  1623. }
  1624. /**查询机构下是否存在虚拟机构
  1625. * @param id
  1626. * @return
  1627. */
  1628. private boolean hasVirtualDept(String deptId) {
  1629. /*
  1630. Connection conn = null;
  1631. PreparedStatement ps = null;
  1632. ResultSet rs = null;
  1633. DbConnection db = new DbConnection();
  1634. StringBuffer sql = new StringBuffer();
  1635. sql.append("--查询该机构是否有子机构 \n");
  1636. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
  1637. try {
  1638. conn = db.getConnection();
  1639. ps = conn.prepareStatement(sql.toString());
  1640. ps.setString(1, deptId);
  1641. ps.setString(2, "0");
  1642. ps.setString(3, "1");
  1643. //log.info("查询是否有子机构 sql="+sql);
  1644. rs =ps.executeQuery();
  1645. if(rs.next()){
  1646. //log.info("是否有子机构"+rs.getBoolean(1));
  1647. return rs.getBoolean(1);
  1648. };
  1649. } catch (Exception e) {
  1650. log.error("查询内部组织机构是否存在虚拟机构错误", e);
  1651. } finally {
  1652. db.close(conn);
  1653. db.close(ps);
  1654. db.close(rs);
  1655. }
  1656. return false;
  1657. */
  1658. Connection conn = null;
  1659. PreparedStatement ps = null;
  1660. ResultSet rs = null;
  1661. DbConnection db = new DbConnection();
  1662. StringBuffer sql = new StringBuffer();
  1663. sql.append("--查询该机构是否有子机构 \n");
  1664. sql.append("SELECT COUNT(1) c FROM EMC_DEPARTMENT_IN WHERE PARENT_ID=? AND IS_DEL=? AND IS_VIRTUAL=? \n");
  1665. try {
  1666. conn = db.getConnection();
  1667. ps = conn.prepareStatement(sql.toString());
  1668. ps.setString(1, deptId);
  1669. ps.setString(2, "0");
  1670. ps.setString(3, "1");
  1671. //log.info("查询是否有子机构 sql="+sql);
  1672. rs =ps.executeQuery();
  1673. if(rs.next()){
  1674. //log.info("是否有子机构"+rs.getBoolean(1));
  1675. return rs.getBoolean(1);
  1676. };
  1677. } catch (Exception e) {
  1678. log.error("查询内部组织机构是否存在虚拟机构错误", e);
  1679. } finally {
  1680. db.close(conn);
  1681. db.close(ps);
  1682. db.close(rs);
  1683. }
  1684. return false;
  1685. }
  1686. /**异步加载数据
  1687. * @param id
  1688. * @return
  1689. */
  1690. public String getInlinkStatistics(String id) {
  1691. SysModel sysmodel = ModelFactory.getSysmodel();
  1692. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1693. StringBuffer json = new StringBuffer();
  1694. StringBuffer sql = new StringBuffer();
  1695. ArrayList<String> compIds = new ArrayList<String>();
  1696. sql.append("--查询传来id的机构信息 \n");
  1697. sql.append("SELECT ID FROM EMC_AM_ORG_DEPARTMENT_TEST WHERE IS_DEL='0' \n ");
  1698. sql.append(" AND PARENT_ID='" + id + "' \n");
  1699. sql.append(" AND IS_VIRTUAL ='0' \n");
  1700. sql.append(" ORDER BY SORT asc \n");
  1701. try {
  1702. ArrayList<String[]> listCompIds = persistence.getSearchResult(99, sql.toString());
  1703. //获得传来id下的所有实体机构
  1704. for(int i = 0;i<listCompIds.size();i++){
  1705. String temp = listCompIds.get(i)[0];
  1706. compIds.add(temp);
  1707. }
  1708. log.info("compIds.size()====="+compIds.size());
  1709. //遍历实际机构ids(compIds)
  1710. json.append("{\"rows\":[");
  1711. for(int i = 0;i<compIds.size();i++){
  1712. log.info("compIds.get(i)========"+compIds.get(i));
  1713. json.append(InlinkNumInit(compIds.get(i)));
  1714. json.append(",");
  1715. }
  1716. if(json.lastIndexOf(",")>-1){
  1717. json.deleteCharAt(json.lastIndexOf(","));
  1718. }
  1719. json.append("]}");
  1720. } catch (PersistenceException e) {
  1721. e.printStackTrace();
  1722. }
  1723. log.info("json==========s"+json);
  1724. return json.toString();
  1725. }
  1726. public boolean hasStaffs(String deptId) {
  1727. Connection conn = null;
  1728. PreparedStatement ps = null;
  1729. ResultSet rs = null;
  1730. DbConnection db = new DbConnection();
  1731. StringBuffer sql = new StringBuffer();
  1732. sql.append("--查询该机构是否有没有删除的员工 \n");
  1733. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE PARENT_ORG_ID=? AND IS_DEL=? \n");
  1734. try {
  1735. conn = db.getConnection();
  1736. ps = conn.prepareStatement(sql.toString());
  1737. ps.setString(1, deptId);
  1738. ps.setString(2, "0");
  1739. log.info("查询该内部机构是否有未删除的员工sql="+sql);
  1740. rs =ps.executeQuery();
  1741. if(rs.next()){
  1742. //log.info("该内部机构是否有员工"+rs.getBoolean(1));
  1743. return rs.getBoolean(1);
  1744. };
  1745. } catch (Exception e) {
  1746. log.error("查询该内部机构是否存在员工", e);
  1747. } finally {
  1748. db.close(conn);
  1749. db.close(ps);
  1750. db.close(rs);
  1751. }
  1752. return false;
  1753. }
  1754. /*******************************************************内部人员统计结束************************/
  1755. /**
  1756. * @param deptId
  1757. * @return
  1758. */
  1759. public boolean shamDeleteOrgInDept2(String deptId) {
  1760. //先进行判断能否删除(判断机构下是否还有子机构存在)
  1761. if(hasChildNode(deptId)){
  1762. return false;
  1763. }
  1764. //判断机构下是否还有员工存在
  1765. if(hasStaff2(deptId)){
  1766. return false;
  1767. }
  1768. Connection conn = null;
  1769. PreparedStatement ps = null;
  1770. DbConnection db = new DbConnection();
  1771. StringBuffer sql = new StringBuffer();
  1772. sql.append("--删除内部组织机构名称 \n");
  1773. sql.append("UPDATE EMC_AM_ORG_DEPARTMENT_TEST SET IS_DEL=? WHERE ID=? \n");
  1774. try {
  1775. conn = db.getConnection();
  1776. ps = conn.prepareStatement(sql.toString());
  1777. ps.setString(1, "1");
  1778. ps.setString(2, deptId);
  1779. log.info("删除内部虚拟机构sql="+sql);
  1780. return ps.executeUpdate() == 1;
  1781. } catch (Exception e) {
  1782. log.error("删除内部组织机构名称错误", e);
  1783. } finally {
  1784. db.close(conn);
  1785. db.close(ps);
  1786. }
  1787. return false;
  1788. }
  1789. /**
  1790. * @param deptId
  1791. * @return
  1792. */
  1793. private boolean hasStaff2(String deptId) {
  1794. Connection conn = null;
  1795. PreparedStatement ps = null;
  1796. ResultSet rs = null;
  1797. DbConnection db = new DbConnection();
  1798. StringBuffer sql = new StringBuffer();
  1799. sql.append("--查询该机构是否有没有删除的员工 \n");
  1800. sql.append("SELECT COUNT(1) c FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID=? AND IS_DEL=? \n");
  1801. try {
  1802. conn = db.getConnection();
  1803. ps = conn.prepareStatement(sql.toString());
  1804. ps.setString(1, deptId);
  1805. ps.setString(2, "0");
  1806. log.info("查询该内部机构是否有未删除的员工sql="+sql);
  1807. rs =ps.executeQuery();
  1808. if(rs.next()){
  1809. //log.info("该内部机构是否有员工"+rs.getBoolean(1));
  1810. return rs.getBoolean(1);
  1811. };
  1812. } catch (Exception e) {
  1813. log.error("查询该内部机构是否存在员工", e);
  1814. } finally {
  1815. db.close(conn);
  1816. db.close(ps);
  1817. db.close(rs);
  1818. }
  1819. return false;
  1820. }
  1821. /*******************存储队伍人员信息结束***************************************************/
  1822. public Msg getMove(String fd_id, String up_id,String fd_sort,String up_sort)throws Exception {
  1823. Msg m=new Msg();
  1824. SysModel sysmodel = ModelFactory.getSysmodel();
  1825. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1826. int sqlExecute = 0;
  1827. StringBuffer sqlmoveUp = new StringBuffer();
  1828. sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+up_sort+"' where FD_OBJECTID='"+fd_id+"';");
  1829. sqlmoveUp.append("update EMC_AM_ORG_INLINK set SORT_NO = '"+fd_sort+"' where FD_OBJECTID='"+up_id+"';");
  1830. log.info(sqlmoveUp);
  1831. try {
  1832. sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
  1833. //判定是否删除数据成功
  1834. if(sqlExecute==1){
  1835. log.info("保存成功");
  1836. m.setSucsess(new Boolean(true).toString());
  1837. m.setInfo(Parameter.CREATE_SUCSESS);
  1838. return m;
  1839. }else{
  1840. log.info("保存失败");
  1841. m.setSucsess(new Boolean(false).toString());
  1842. m.setInfo(Parameter.CREATE_FAILURE);
  1843. return m;
  1844. }
  1845. } catch (PersistenceException e) {
  1846. e.printStackTrace();
  1847. }
  1848. return m;
  1849. }
  1850. public Msg exeGetMove(String tableName,String fillName,String max,String id, String idFille,String fd_id)throws Exception {
  1851. String no =sortNo(tableName, fillName, max, id, idFille);
  1852. int fillerNo = Integer.valueOf(no).intValue();
  1853. int fillerNo1 = fillerNo-1;
  1854. String no1 = fillerNo1 + "";
  1855. Msg m=new Msg();
  1856. SysModel sysmodel = ModelFactory.getSysmodel();
  1857. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1858. int sqlExecute = 0;
  1859. StringBuffer sqlmoveUp = new StringBuffer();
  1860. sqlmoveUp.append("update "+tableName+" set SORT_NO = '"+no1+"' where FD_OBJECTID='"+fd_id+"';");
  1861. log.info(sqlmoveUp);
  1862. try {
  1863. sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
  1864. //判定是否删除数据成功
  1865. if(sqlExecute==1){
  1866. log.info("保存成功");
  1867. m.setSucsess(new Boolean(true).toString());
  1868. m.setInfo(Parameter.CREATE_SUCSESS);
  1869. return m;
  1870. }else{
  1871. log.info("保存失败");
  1872. m.setSucsess(new Boolean(false).toString());
  1873. m.setInfo(Parameter.CREATE_FAILURE);
  1874. return m;
  1875. }
  1876. } catch (PersistenceException e) {
  1877. e.printStackTrace();
  1878. }
  1879. return m;
  1880. }
  1881. //根据传过来的id号取本id下最小的排序序号
  1882. public String sortNo(String tableName,String fillName,String max,String id, String idFille){
  1883. String sql="select min(to_number("+fillName+")) from "+tableName+" where "+idFille+" ='"+id+"' and is_del='0';";
  1884. List<String[]> list = null;
  1885. try {
  1886. list = PersistenceFactory.getInstance( ModelFactory.getSysmodel()).getSearchResult(99, sql);
  1887. } catch (PersistenceException e) {
  1888. log.error(e.getMessage());
  1889. }
  1890. String result = "";
  1891. if(list.size()>0){
  1892. result=list.get(0)[0];
  1893. }
  1894. log.info("============================================="+result);
  1895. return result;
  1896. }
  1897. }