fc01bc1c5e1a43c53f482582786d768c5b273b02.svn-base 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543
  1. package com.sinosoft.am.org.department.inner.busi;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. import net.sf.json.JSONArray;
  13. import net.sf.json.JSONObject;
  14. import net.sf.json.JsonConfig;
  15. import org.apache.log4j.Logger;
  16. import org.jfree.util.Log;
  17. import com.formaction.Parameter;
  18. import com.formaction.vo.Msg;
  19. import com.persistence.DbConnection;
  20. import com.persistence.service.PersistenceFactory;
  21. import com.persistence.service.SysPersistence;
  22. import com.persistence.service.exception.PersistenceException;
  23. import com.sinosoft.am.org.jdbcUtil.ORGTemplate;
  24. import com.sinosoft.am.pinyin4j.Pinyin4jUtil;
  25. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  26. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  27. /**
  28. *
  29. * @author 云涛 此方法用于内部组织机构的增删改查所有方法
  30. *
  31. *
  32. */
  33. public class InDepartmentBusi {
  34. private Logger log = Logger.getLogger(this.getClass());
  35. /**
  36. * 加载给定机构的信息
  37. * @param id 传入的机构id
  38. * @param getPerson 是否带人
  39. * @param isFirstLoad 是否第一次加载
  40. * @return
  41. */
  42. public String getOrgInfoById(String id, boolean getPerson, boolean isFirstLoad,String deptLevel) {
  43. String result = new String();
  44. if (getPerson) {
  45. result = loadInDepartmentPerById(id, isFirstLoad,deptLevel);
  46. } else {
  47. result = loadInDepartmentById(id, isFirstLoad,deptLevel);
  48. }
  49. return result;
  50. }
  51. /**
  52. * 2016-11-06 唐群胜加 只显示应急机构
  53. * @param id
  54. * @param getPerson
  55. * @param isFirstLoad
  56. * @return
  57. */
  58. public String getOnlyOrgInfoById(String id, boolean getPerson, boolean isFirstLoad,String deptLevel) {
  59. String result = new String();
  60. // if (getPerson) {
  61. // result = loadInDepartmentPerById(id, isFirstLoad);
  62. // } else {
  63. result = onlyInDepartmentById(id, isFirstLoad,deptLevel);
  64. // }
  65. return result;
  66. }
  67. /**
  68. *
  69. * 根据传来的机构id加载下级节点信息加载人员的方法
  70. *
  71. * @param id
  72. * @param isFirstLoad
  73. * isFirstLoad= true 表示第一次加载(第一次调用该方法),那么就将他自己的节点信息和子节点信息加载出来
  74. * isFirstLoad= false 表示不是第一次调用该方法 就只加载当前节点的子节点信息
  75. * @return
  76. */
  77. public String loadInDepartmentPerById(String id, boolean isFirstLoad,String deptLevel) {
  78. SysModel sysmodel = ModelFactory.getSysmodel();
  79. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  80. StringBuffer sql = new StringBuffer();
  81. StringBuffer json = new StringBuffer();
  82. json.append("{\"treeNodes\":[");
  83. if (isFirstLoad) {
  84. sql.append("--查询给定id及其一级子机构的信息 \n");
  85. sql.append("SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, \n");
  86. sql.append("DECODE((SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID),'0','0','1') AS 是否有子机构 \n");
  87. sql.append("FROM V_DEPARTMENT A WHERE PARENT_ID = '"
  88. + id + "' OR ORG_ID='" + id + "' AND IS_DEL='0'\n ");
  89. } else {
  90. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  91. sql.append("SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, \n");
  92. sql.append("DECODE((SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID),'0','0','1') AS 是否有子机构 \n");
  93. sql.append("FROM V_DEPARTMENT A WHERE PARENT_ID = '"
  94. + id + "' AND IS_DEL='0' \n");
  95. }
  96. // log.info(sql);
  97. try {
  98. ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  99. sql.toString());
  100. // 显示人员
  101. json.append(getPersonById(id));
  102. int listLen = listRoot.size();
  103. for (int i = 0; i < listLen; i++) {
  104. String[] temp = listRoot.get(i);
  105. String orgId = temp[0];
  106. String orgName = getOrgAbbreviation(temp[0],deptLevel);//temp[1];
  107. String parentOrgId = temp[2];
  108. String orgLevel = temp[3];
  109. String isVirtual = temp[4];
  110. // 判定是否存在子节点
  111. boolean isHasChildOrg = !("0".equals(temp[5]));
  112. // 判定是否为第一次加载的id(用来展开初始化的节点)
  113. String isRootNode = id.equals(orgId) ? "true" : "false";
  114. // 判定是虚拟机构还是实体机构
  115. String icon = isVirtual == "1" ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  116. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  117. json.append("{");
  118. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  119. + parentOrgId + "\", \"name\": \"" + orgName
  120. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  121. //添加是否为虚拟机构的属性
  122. json.append("\"isVirtual\":\""+isVirtual+"\",");
  123. // 是否展开
  124. json.append("\"open\":\"" + isRootNode + "\",");
  125. //设定区别机构人员的属性
  126. json.append("\"leafType\":\"org\",");
  127. if (isHasChildOrg) {
  128. json.append("\"isParent\": \"true\" ");
  129. } else {
  130. json.append("\"isParent\": \"fasle\" ");
  131. }
  132. json.append(", \"icon\":" + icon + "");
  133. // json.append(", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  134. json.append("},");
  135. }
  136. // 去掉多余的","
  137. if (json.lastIndexOf(",") > -1) {
  138. json.deleteCharAt(json.lastIndexOf(","));
  139. }
  140. ;
  141. json.append("]}");
  142. log.info(json.toString());
  143. } catch (PersistenceException e) {
  144. e.printStackTrace();
  145. }
  146. return json.toString();
  147. }
  148. /**
  149. * 加载给定机构id的人员信息
  150. * @param deptId
  151. * @return
  152. */
  153. private String getPersonById(String deptId) {
  154. StringBuffer json = new StringBuffer();
  155. SysModel sysmodel = ModelFactory.getSysmodel();
  156. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  157. StringBuffer sql = new StringBuffer();
  158. sql.append("SELECT A.USER_ID,A.REAL_NAME,A.ORG_ID,A.HR_CODE,A.GENDER,A.POSITION, A.MOBILE "
  159. + "FROM SYS_USER_INFO A ,SYS_DEPARTMENT D,SYS_DEPT_USER DU "
  160. + " WHERE A.USER_ID = DU.USER_ID AND D.DEPT_ID = DU.DEPT_ID AND D.DEPT_ID='"
  161. + deptId + "'");
  162. // log.info("人员sql================="+sql);
  163. try {
  164. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  165. if (list.size() > 0) {
  166. for (int i = 0; i < list.size(); i++) {
  167. String[] temp = list.get(i);
  168. String id = temp[0];
  169. String name = temp[1];
  170. //String hr = temp[3];
  171. String gender = temp[4];
  172. String manDuty = temp[5];
  173. String manPhone = temp[6];
  174. json.append("{");
  175. json.append(" \"name\":\"" + name +"\",");
  176. json.append(" \"id\":\"" + id + "\",");
  177. json.append(" \"parentId\":\"" + deptId + "\",");
  178. json.append(" \"manDuty\":\"" + manDuty + "\",");
  179. json.append(" \"manPhone\":\"" + manPhone + "\",");
  180. json.append("\"leafType\":\"per\",");
  181. json.append("\"tagValue\":\"1\",");
  182. if ("男".equals(gender)) {
  183. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user-black.png\"");
  184. } else if ("女".equals(gender)) {
  185. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user-red-female.png\"");
  186. } else {
  187. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user-black.png\"");
  188. }
  189. json.append("},");
  190. }
  191. }
  192. } catch (PersistenceException e) {
  193. e.printStackTrace();
  194. }
  195. return json.toString();
  196. }
  197. /**
  198. *
  199. * 根据传来的机构id加载下级节点信息(排序字段为sort_no)
  200. *
  201. * @param id
  202. * @param isFirstLoad
  203. * isFirstLoad= true 表示第一次加载(第一次调用该方法),那么就将他自己的节点信息加载出来
  204. * isFirstLoad= false 表示不是第一次调用该方法 就只加载当前节点的子节点信息
  205. * @return
  206. */
  207. public String loadInDepartmentById(String id, boolean isFirstLoad,String deptLevel) {
  208. SysModel sysmodel = ModelFactory.getSysmodel();
  209. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  210. StringBuffer sql = new StringBuffer();
  211. StringBuffer json = new StringBuffer();
  212. json.append("{\"treeNodes\":[");
  213. if (isFirstLoad) {
  214. sql.append("--查询给定id及其一级子机构的信息 \n");
  215. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID,ORG_TYPE FROM V_DEPARTMENT A WHERE ( PARENT_ID = '"+id+"' OR ORG_ID IN (SELECT DEPT_ID FROM SYS_DEPARTMENT where dept_type='1' start with DEPT_ID = '"+id+"' connect by prior parent_id = dept_id ) OR (PARENT_ID IN (SELECT ORG_ID FROM V_DEPARTMENT where ORG_TYPE='1' and ORG_ID != '"+id+"' start with ORG_ID = '"+id+"' connect by prior parent_id = ORG_ID) and IS_VIRTUAL = '1')) AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' or org_name like '%输电%' or org_name like '%变电%' or org_name like '%抢修中心%' or org_name like '%调度%' or org_id='"+id+"' )and is_virtual='0' ) or is_virtual='1' ) AND ORG_LEVEL IS NOT NULL ORDER BY SORT_NO )");
  216. // sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID FROM V_DEPARTMENT A WHERE ( PARENT_ID = '"+id+"' OR ORG_ID = '"+id+"') AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' or org_name like '%输电%' or org_name like '%变电%' or org_name like '%抢修中心%' or org_name like '%调度%' or org_id='"+id+"' )and is_virtual='0' ) or is_virtual='1' ) AND ORG_LEVEL IS NOT NULL ORDER BY SORT_NO )");
  217. // sql.append("(SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL,A.SORT_NO, \n");
  218. // sql.append("DECODE((SELECT COUNT(1) FROM EMC_DEPARTMENT_IN B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL='0'),'0','0','1') AS 是否有子机构 \n");
  219. // sql.append("FROM EMC_DEPARTMENT_IN A WHERE (PARENT_ID = '"
  220. // + id + "' OR ORG_ID='" + id + "') AND IS_DEL='0' and ((org_name like '%供电局') or(org_name like '%供电分局') ) and is_virtual='0' ORDER BY SORT_NO\n)");
  221. } else {
  222. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  223. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID,ORG_TYPE FROM V_DEPARTMENT A WHERE ( PARENT_ID = '"+id+"') AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' )and is_virtual='0' ) or is_virtual='1' ) AND ORG_LEVEL IS NOT NULL ORDER BY SORT_NO )");
  224. // sql.append("SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL,A.SORT_NO, \n");
  225. // sql.append("DECODE((SELECT COUNT(1) FROM EMC_DEPARTMENT_IN B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL='0'),'0','0','1') AS 是否有子机构 \n");
  226. // sql.append("FROM EMC_DEPARTMENT_IN A WHERE PARENT_ID = '"
  227. // + id + "' AND IS_DEL='0' and ((org_name like '%供电局') or(org_name like '%供电分局') ) ORDER BY SORT_NO \n");
  228. }
  229. // log.info(sql);
  230. try {
  231. ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  232. sql.toString());
  233. int listLen = listRoot.size();
  234. for (int i = 0; i < listLen; i++) {
  235. String[] temp = listRoot.get(i);
  236. String orgId = temp[0];
  237. String orgName = getOrgAbbreviation(temp[0],deptLevel);
  238. String parentOrgId = temp[2];
  239. String orgLevel = temp[3];
  240. String isVirtual = temp[4];
  241. String sortNo = temp[5];
  242. // 判定是否存在子节点
  243. boolean isHasChildOrg = !("0".equals(temp[6]));
  244. String corpId = temp[7];
  245. String orgType = temp[8];//机构类型
  246. // 判定是否为第一次加载的id(用来展开初始化的节点)废弃 2017-09-20
  247. String isRootNode = id.equals(orgId) ? "true" : "false";
  248. // 判定是虚拟机构还是实体机构
  249. String icon = "1".equals(isVirtual) ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  250. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  251. json.append("{");
  252. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  253. + parentOrgId + "\", \"name\": \"" + orgName
  254. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  255. //添加排序标识
  256. json.append("\"sortNo\":\""+sortNo+"\",");
  257. //添加单位ID
  258. json.append("\"corpId\":\""+corpId+"\",");
  259. //添加是否为虚拟机构的属性
  260. json.append("\"isVirtual\":\""+isVirtual+"\",");
  261. json.append("\"orgtype\":\""+orgType+"\",");
  262. // 是否展开
  263. json.append("\"open\":\"" + (openoroff(id,orgId)?"true" : "false") + "\",");
  264. //设置标记字段值(用于额外的属性)
  265. json.append("\"tagValue\":\"1\",");
  266. if (isHasChildOrg) {
  267. json.append("\"isParent\": \"true\" ");
  268. } else {
  269. json.append("\"isParent\": \"fasle\" ");
  270. }
  271. json.append(", \"icon\":" + icon + "");
  272. // json.append(", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  273. json.append("},");
  274. }
  275. // 去掉多余的","
  276. if (json.lastIndexOf(",") > -1) {
  277. json.deleteCharAt(json.lastIndexOf(","));
  278. }
  279. ;
  280. json.append("]}");
  281. log.info(json.toString());
  282. } catch (PersistenceException e) {
  283. e.printStackTrace();
  284. }
  285. return json.toString();
  286. }
  287. //判断是否要展开节点
  288. private boolean openoroff(String id,String orgid) {
  289. SysModel sysmodel = ModelFactory.getSysmodel();
  290. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  291. try{
  292. String sql="select * from sys_department where dept_id in (select dept_id from sys_department where dept_type='1' start with DEPT_ID = '"+id+"' connect by prior parent_id = dept_id) and dept_id like '%"+orgid+"%' ";
  293. List<String[]> tempList = persistence.getSearchResult(99, sql.toString());
  294. if(tempList!=null&&tempList.size()>0){
  295. return true;
  296. }else{
  297. return false;
  298. }
  299. }catch(Exception e){
  300. e.printStackTrace();
  301. return false;
  302. }
  303. }
  304. public String onlyInDepartmentById(String id, boolean isFirstLoad,String deptlevel) {
  305. SysModel sysmodel = ModelFactory.getSysmodel();
  306. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  307. StringBuffer sql = new StringBuffer();
  308. StringBuffer json = new StringBuffer();
  309. json.append("{\"treeNodes\":[");
  310. if (isFirstLoad) {
  311. sql.append("--查询给定id及其一级子机构的信息 \n");
  312. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID FROM (select distinct * from V_DEPARTMENT where is_del = '0' start with fd_objectid in (select fd_objectid from EMC_DEPARTMENT_IN where is_del = '0') connect by prior parent_id = fd_objectid) A WHERE ( PARENT_ID = '"+id+"' OR ORG_ID ='"+id+"' ) AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' or org_name like '%输电%' or org_name like '%变电%' or org_name like '%抢修中心%' or org_name like '%调度%' or org_id='"+id+"' )and is_virtual='0' ) or is_virtual='1' ) ORDER BY SORT_NO )");
  313. } else {
  314. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  315. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID FROM (select distinct * from V_DEPARTMENT where is_del = '0' start with fd_objectid in (select fd_objectid from EMC_DEPARTMENT_IN where is_del = '0') connect by prior parent_id = fd_objectid) A WHERE ( PARENT_ID = '"+id+"') AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' )and is_virtual='0' ) or is_virtual='1' ) ORDER BY SORT_NO )");
  316. }
  317. log.info(sql);
  318. try {
  319. ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  320. sql.toString());
  321. int listLen = listRoot.size();
  322. log.info("listLen=========="+listLen);
  323. if(listLen==0 && isFirstLoad){
  324. String sql1 = "( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 ,CORP_ID FROM V_DEPARTMENT A WHERE ORG_ID ='"+id+"' AND IS_DEL='0' and ( ( (org_name like '%' or org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_name like '%电网有限责任公司' or org_name like '%输电%' or org_name like '%变电%' or org_name like '%抢修中心%' or org_name like '%调度%' or org_id='"+id+"' )and is_virtual='0' ) or is_virtual='1' ) ORDER BY SORT_NO )";
  325. listRoot = persistence.getSearchResult(99, sql1.toString());
  326. listLen = listRoot.size();
  327. log.info("listLen2=========="+listLen);
  328. }
  329. for (int i = 0; i < listLen; i++) {
  330. String[] temp = listRoot.get(i);
  331. String orgId = temp[0];
  332. String orgName = getOrgAbbreviation(temp[0],deptlevel);//temp[1];
  333. String parentOrgId = temp[2];
  334. String orgLevel = temp[3];
  335. String isVirtual = temp[4];
  336. String sortNo = temp[5];
  337. // 判定是否存在子节点
  338. boolean isHasChildOrg = !("0".equals(temp[6]));
  339. String corpId = temp[7];
  340. // 判定是否为第一次加载的id(用来展开初始化的节点)
  341. String isRootNode = id.equals(orgId) ? "true" : "false";
  342. // 判定是虚拟机构还是实体机构
  343. String icon = "1".equals(isVirtual) ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  344. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  345. json.append("{");
  346. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  347. + parentOrgId + "\", \"name\": \"" + orgName
  348. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  349. //添加排序标识
  350. json.append("\"sortNo\":\""+sortNo+"\",");
  351. //添加单位ID
  352. json.append("\"corpId\":\""+corpId+"\",");
  353. //添加是否为虚拟机构的属性
  354. json.append("\"isVirtual\":\""+isVirtual+"\",");
  355. // 是否展开
  356. json.append("\"open\":\"" + isRootNode + "\",");
  357. //设置标记字段值(用于额外的属性)
  358. json.append("\"tagValue\":\"1\",");
  359. if (isHasChildOrg) {
  360. json.append("\"isParent\": \"true\" ");
  361. } else {
  362. json.append("\"isParent\": \"fasle\" ");
  363. }
  364. json.append(", \"icon\":" + icon + "");
  365. // json.append(", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  366. json.append("},");
  367. }
  368. // 去掉多余的","
  369. if (json.lastIndexOf(",") > -1) {
  370. json.deleteCharAt(json.lastIndexOf(","));
  371. }
  372. ;
  373. json.append("]}");
  374. log.info(json.toString());
  375. } catch (PersistenceException e) {
  376. e.printStackTrace();
  377. }
  378. return json.toString();
  379. }
  380. /**
  381. *根据id获得机构信息以 treeNode 的形式返回(用于新增修改后返回json)
  382. * @param id
  383. * @return
  384. */
  385. public String getOrgInfoTree(String id ){
  386. SysModel sysmodel = ModelFactory.getSysmodel();
  387. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  388. StringBuffer sql = new StringBuffer();
  389. StringBuffer json = new StringBuffer();
  390. sql.append("SELECT ORG_ID,ORG_NAME,PARENT_ID,ORG_LEVEL,IS_VIRTUAL,SORT_NO,CORP_ID,");
  391. sql.append("DECODE((SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID),'0','0','1') AS 是否有子机构 ");
  392. sql.append("FROM V_DEPARTMENT A WHERE ORG_ID = '"+id+"' AND IS_DEL ='0'");
  393. try {
  394. ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  395. sql.toString());
  396. String[] temp = listRoot.get(0);
  397. String orgId = temp[0];
  398. String orgName = temp[1];
  399. String parentOrgId = temp[2];
  400. String orgLevel = temp[3];
  401. String isVirtual = temp[4];
  402. String sortNo = temp[5];
  403. String corpId = temp[6];
  404. // 判定是否存在子节点
  405. boolean isHasChildOrg = !("0".equals(temp[7]));
  406. // 判定是虚拟机构还是实体机构
  407. String icon = "1".equals(isVirtual) ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  408. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  409. json.append("{");
  410. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  411. + parentOrgId + "\", \"name\": \"" + orgName
  412. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  413. //添加排序标识
  414. json.append("\"sortNo\":\""+sortNo+"\",");
  415. //添加corpId
  416. json.append("\"corpId\":\""+corpId+"\",");
  417. //添加是否为虚拟机构的属性
  418. json.append("\"isVirtual\":\""+isVirtual+"\",");
  419. if (isHasChildOrg) {
  420. json.append("\"isParent\": \"true\" ");
  421. } else {
  422. json.append("\"isParent\": \"fasle\" ");
  423. }
  424. json.append(", \"icon\":" + icon + "");
  425. // json.append(", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  426. json.append("}");
  427. } catch (PersistenceException e) {
  428. e.printStackTrace();
  429. }
  430. return json.toString();
  431. }
  432. /**
  433. * 根据id查询机构的信息 包括机构所有字段的信息
  434. * @return
  435. */
  436. public String queryOrgInfoById(String id){
  437. // SysModel sysmodel = ModelFactory.getSysmodel();
  438. // SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  439. StringBuffer sql = new StringBuffer();
  440. StringBuffer sql2 = new StringBuffer();
  441. StringBuffer json = new StringBuffer();
  442. sql.append("SELECT FD_OBJECTID,ORG_NAME,ORG_ID,PARENT_ID,ORG_TYPE,ORG_PROP,OFFICE_TYPE,FORMATION_PEOPLE,");
  443. sql.append("HAVE_PEOPLE,ORG_ADDRESS,DUTY_TEL,DUTY_FAX,DUTY_EMAIL,EMERGENCY_TEL,EMERGENCY_FAX,EMERGENCY_EMAIL,");
  444. sql.append("ENTRY_MAN_ID,SORT_NO,IS_VIRTUAL,PATH_ID,PATH_NAME,PINYIN,JIANPIN,ORG_LEVEL,IS_DEL,UPDATEDATE,");
  445. sql.append("SHORT_NAME,UNICODE,HR_MRID,CORP_ID,CORP_NAME, ");
  446. //orgTypeshow
  447. sql.append("(SELECT FD_DESCRIPTION FROM BM_MAPVALUECANST WHERE FD_CODE =ORG_TYPE AND FD_TYPE IN ('BM_ENTITY_ORG_TYPE','BM_VIRTUAL_ORG_TYPE')) ORG_TYPE_SHOW ,");
  448. //orgPropshow
  449. sql.append("(SELECT FD_DESCRIPTION FROM BM_MAPVALUECANST WHERE FD_CODE =ORG_PROP AND FD_TYPE IN ('BM_ORG_PROP')) ORG_PROP_SHOW ,");
  450. //officeTypeshow
  451. sql.append("(SELECT FD_DESCRIPTION FROM BM_MAPVALUECANST WHERE FD_CODE =OFFICE_TYPE AND FD_TYPE IN ('BM_ORG_OFFICE_TYPE')) ORG_OFFICE_TYPE ,ENTRY_MAN_NAME ");
  452. sql.append("FROM V_DEPARTMENT WHERE FD_OBJECTID = ? AND IS_DEL =? ");
  453. log.info(sql);
  454. sql2.append("select sum(case EMC_ROLE when '1' then 1 else 0 end) as zzh, ");
  455. sql2.append("sum(case EMC_ROLE when '2' then 1 else 0 end) as fzzh, ");
  456. sql2.append("sum(case EMC_ROLE when '3' then 1 else 0 end) as zr, ");
  457. sql2.append("sum(case EMC_ROLE when '4' then 1 else 0 end) as fzr, ");
  458. sql2.append("sum(case when EMC_ROLE='5' or EMC_ROLE is null then 1 else 0 end) as cy ");
  459. sql2.append("from EMC_AM_ORG_INLINK where IS_DEL='0' AND VIRTUAL_ORG_ID=? AND INLINK_NAME IS NOT NULL ");
  460. log.info(sql2);
  461. Connection conn = null;
  462. PreparedStatement stat1 = null;
  463. ResultSet rs = null;
  464. DbConnection db = new DbConnection();
  465. try {
  466. /* conn = db.getConnection();
  467. stat1 = conn.prepareStatement(sql.toString());
  468. stat1.setString(1, id);
  469. stat1.setString(2, "0");
  470. rs = stat1.executeQuery();*/
  471. List<String[]> li = new ORGTemplate().getSearchResult(sql.toString(), id,"0");
  472. List<String[]> li2 = new ORGTemplate().getSearchResult(sql2.toString(), id);
  473. /* ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  474. sql.toString());*/
  475. String[] temp = li.get(0);
  476. String[] temp2 = li2.get(0);
  477. String fd_objectid = returnForDMNull(temp[0]);
  478. String orgName = returnForDMNull(temp[1]);
  479. String orgId = returnForDMNull(temp[2]);
  480. String parentId = returnForDMNull(temp[3]);
  481. String orgType = returnForDMNull(temp[4]);
  482. String orgProp = returnForDMNull(temp[5]);
  483. String officeType = returnForDMNull(temp[6]);
  484. String formationPeople = returnForDMNull(temp[7]);
  485. String havePeople = returnForDMNull(temp[8]);
  486. String orgAddress = returnForDMNull(temp[9]);
  487. String dutyTel = returnForDMNull(temp[10]);
  488. String dutyFax = returnForDMNull(temp[11]);
  489. String dutyEmail = returnForDMNull(temp[12]);
  490. String EmergencyTel = returnForDMNull(temp[13]);
  491. String EmergencyFax = returnForDMNull(temp[14]);
  492. String EmergencyEmail = returnForDMNull(temp[15]);
  493. String entryManId = returnForDMNull(temp[16]);
  494. String sortNo = returnForDMNull(temp[17]);
  495. String isVirtual = returnForDMNull(temp[18]);
  496. String pathId = returnForDMNull(temp[19]);
  497. String pathName = returnForDMNull(temp[20]);
  498. String pinyin = returnForDMNull(temp[21]);
  499. String jianpin = returnForDMNull(temp[22]);
  500. String orgLevel = returnForDMNull(temp[23]);
  501. String isDel = returnForDMNull(temp[24]);
  502. String updateDate = returnForDMNull(temp[25]);
  503. String shortName = returnForDMNull(temp[26]);
  504. String unicode = returnForDMNull(temp[27]);
  505. String hrMRID = returnForDMNull(temp[28]);
  506. String corpId = returnForDMNull(temp[29]);
  507. String corpName = returnForDMNull(temp[30]);
  508. String orgTypeShow = returnForDMNull(temp[31]);
  509. String orgPropShow = returnForDMNull(temp[32]);
  510. String officeTypeShow = returnForDMNull(temp[33]);
  511. String entryManName = returnForDMNull(temp[34]);
  512. String ZZH = returnForDMNull(temp2[0]);
  513. String FZZH = returnForDMNull(temp2[1]);
  514. String ZR = returnForDMNull(temp2[2]);
  515. String FZR = returnForDMNull(temp2[3]);
  516. String CY = returnForDMNull(temp2[4]);
  517. json.append("{");
  518. json.append("\"FD_OBJECTID\":\""+fd_objectid+"\",");
  519. json.append("\"ORG_NAME\":\""+orgName+"\",");
  520. json.append("\"ORG_ID\":\""+orgId+"\",");
  521. json.append("\"PARENT_ID\":\""+parentId+"\",");
  522. json.append("\"ORG_TYPE\":\""+orgType+"\",");
  523. json.append("\"ORG_PROP\":\""+orgProp+"\",");
  524. json.append("\"OFFICE_TYPE\":\""+officeType+"\",");
  525. json.append("\"FORMATION_PEOPLE\":\""+formationPeople+"\",");
  526. json.append("\"HAVE_PEOPLE\":\""+havePeople+"\",");
  527. json.append("\"ORG_ADDRESS\":\""+orgAddress+"\",");
  528. json.append("\"DUTY_TEL\":\""+dutyTel+"\",");
  529. json.append("\"DUTY_FAX\":\""+dutyFax+"\",");
  530. json.append("\"DUTY_EMAIL\":\""+dutyEmail+"\",");
  531. json.append("\"EMERGENCY_TEL\":\""+EmergencyTel+"\",");
  532. json.append("\"EMERGENCY_FAX\":\""+EmergencyFax+"\",");
  533. json.append("\"EMERGENCY_EMAIL\":\""+EmergencyEmail+"\",");
  534. json.append("\"ENTRY_MAN_ID\":\""+entryManId+"\",");
  535. json.append("\"ENTRY_MAN_NAME\":\""+entryManName+"\",");
  536. json.append("\"SORT_NO\":\""+sortNo+"\",");
  537. json.append("\"IS_VIRTUAL\":\""+isVirtual+"\",");
  538. json.append("\"PATH_ID\":\""+pathId+"\",");
  539. json.append("\"PATH_NAME\":\""+pathName+"\",");
  540. json.append("\"PINYIN\":\""+pinyin+"\",");
  541. json.append("\"JIANPIN\":\""+jianpin+"\",");
  542. json.append("\"ORG_LEVEL\":\""+orgLevel+"\",");
  543. json.append("\"IS_DEL\":\""+isDel+"\",");
  544. json.append("\"UPDATEDATE\":\""+updateDate+"\",");
  545. json.append("\"SHORT_NAME\":\""+shortName+"\",");
  546. json.append("\"UNICODE\":\""+unicode+"\",");
  547. json.append("\"HR_MRID\":\""+hrMRID+"\",");
  548. json.append("\"CORP_ID\":\""+corpId+"\",");
  549. json.append("\"ORG_TYPE_SHOW\":\""+orgTypeShow+"\",");
  550. json.append("\"ORG_PROP_SHOW\":\""+orgPropShow+"\",");
  551. json.append("\"OFFICE_TYPE_SHOW\":\""+officeTypeShow+"\",");
  552. json.append("\"CORP_NAME\":\""+corpName+"\",");
  553. json.append("\"ZONGZHIHUI\":\""+((ZZH==null||ZZH=="")?"0":ZZH)+"\",");
  554. json.append("\"FUZONGZHIHUI\":\""+((FZZH==null||FZZH=="")?"0":FZZH)+"\",");
  555. json.append("\"ZHUREN\":\""+((ZR==null||ZR=="")?"0":ZR)+"\",");
  556. json.append("\"FUZHUREN\":\""+((FZR==null||FZR=="")?"0":FZR)+"\",");
  557. json.append("\"CHENGYUAN\":\""+((CY==null||CY=="")?"0":CY)+"\"");
  558. json.append("}");
  559. }catch (SQLException e) {
  560. // TODO Auto-generated catch block
  561. e.printStackTrace();
  562. }finally{
  563. db.close(rs);
  564. db.close(stat1);
  565. db.close(conn);
  566. }
  567. return json.toString();
  568. }
  569. public String getDeptById(String id){
  570. StringBuffer sql = new StringBuffer();
  571. StringBuffer json = new StringBuffer();
  572. sql.append("select DECODE((select count(1) from sys_department A WHERE A.DEPT_ID = B.DEPT_ID AND A.DEPT_TYPE = '1'), '0',");
  573. sql.append("(SELECT SUBSTR((select DEPT_PATH_NAME from sys_department D where D.dept_id=B.dept_id),(select len(DEPT_PATH_NAME)");
  574. sql.append("from sys_department E where E.dept_id in (select G.CORP_ID from sys_department G where G.dept_id=B.dept_id))+2,");
  575. sql.append("(select len(DEPT_PATH_NAME) from sys_department F where F.dept_id=B.dept_id)) FROM DUAL),");
  576. sql.append("(select C.PROVINCE_NAME_TWO from DEPARTMENT_ABBR C WHERE C.FD_OBJECTID = B.DEPT_ID)) DEPT_NAME");
  577. sql.append(" from sys_department B where B.dept_id=?");
  578. log.info(sql);
  579. Connection conn = null;
  580. PreparedStatement stat1 = null;
  581. ResultSet rs = null;
  582. DbConnection db = new DbConnection();
  583. try {
  584. List<String[]> li = new ORGTemplate().getSearchResult(sql.toString(), id);
  585. String dept_name = "";
  586. if(li.size()>0){
  587. String[] temp = li.get(0);
  588. dept_name =returnForDMNull(temp[0]);
  589. }
  590. json.append("{");
  591. json.append("\"DEPT_NAME\":\""+dept_name+"\"");
  592. json.append("}");
  593. }catch (SQLException e) {
  594. // TODO Auto-generated catch block
  595. e.printStackTrace();
  596. }finally{
  597. db.close(rs);
  598. db.close(stat1);
  599. db.close(conn);
  600. }
  601. return json.toString();
  602. }
  603. /**
  604. * 调用此方法将拖动的节点的排序字段变更为目的节点的sort_no-0.00001
  605. *
  606. * @param dragNodeId
  607. * 拖动的节点Id
  608. * @param destNode
  609. * 拖动目的地的的排序值
  610. * @return
  611. */
  612. public String updateSortNo(String dragNodeId, String destNode) {
  613. SysModel sysmodel = ModelFactory.getSysmodel();
  614. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  615. StringBuffer sql = new StringBuffer();
  616. String result = "";
  617. sql.append("--更新拖动节点的排序号 \n");
  618. sql.append("UPDATE EMC_DEPARTMENT_IN SET SORT_NO ='"
  619. + (Float.parseFloat(destNode) + 0.123401) + "' WHERE ORG_ID ='"
  620. + dragNodeId + "'");
  621. try {
  622. result = String.valueOf(persistence.executeUpdateSQL(99,
  623. sql.toString()));
  624. } catch (PersistenceException e) {
  625. e.printStackTrace();
  626. }
  627. return result;
  628. }
  629. /**
  630. * 通过传入的模糊名称和 根节点的 id 进行搜索
  631. * @param name 模糊名称
  632. * @param rootId 根节点的id
  633. * @return
  634. */
  635. public String getOrgInfoByName(String name, String rootId) {
  636. StringBuffer json = new StringBuffer();
  637. SysModel sysmodel = ModelFactory.getSysmodel();
  638. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  639. StringBuffer sql = new StringBuffer();
  640. sql.append("WITH A AS(SELECT * FROM V_DEPARTMENT B WHERE INSTR(PATH_ID,'_"
  641. + rootId + "_')>0 AND B.IS_DEL ='0' ) \n");
  642. sql.append("SELECT TOP 0 , 30 C.ORG_ID,C.ORG_NAME,C.PATH_NAME \n");
  643. sql.append("FROM A C WHERE (C.ORG_NAME LIKE '%" + name + "%' \n");
  644. sql.append("OR C.PINYIN LIKE '%" + name + "%' \n");
  645. sql.append("OR C.JIANPIN LIKE '%" + name + "%') \n");
  646. sql.append("ORDER BY C.ORG_LEVEL ASC \n");
  647. // log.info(sql);
  648. try {
  649. ArrayList<String[]> listOrgInfo = persistence.getSearchResult(99,
  650. sql.toString());
  651. json.append("[");
  652. for (int i = 0; i < listOrgInfo.size(); i++) {
  653. String[] temp = listOrgInfo.get(i);
  654. String orgId = temp[0];
  655. String orgName = temp[1];
  656. String orgPath = temp[2];
  657. String orgSimplePath = orgPath.length() > 16 ? (orgPath
  658. .substring(0, 17) + "...") : orgPath;
  659. json.append("{");
  660. json.append("\"id\":\"" + orgId + "\", ");
  661. json.append("\"name\":\"" + orgName + "\", ");
  662. json.append("\"spath\":\"" + orgSimplePath + "\", ");
  663. json.append("\"path\":\"" + orgPath + "\" ");
  664. json.append("},");
  665. }
  666. if (json.lastIndexOf(",") > -1) {
  667. json.deleteCharAt(json.lastIndexOf(","));
  668. }
  669. ;
  670. json.append("]");
  671. } catch (PersistenceException e) {
  672. e.printStackTrace();
  673. }
  674. return json.toString();
  675. }
  676. /**
  677. * 查询出给定orgId的所有上级ids 已数组形式返回
  678. * @param orgId
  679. * @return
  680. */
  681. public String getHigherIds(String orgId){
  682. StringBuffer json = new StringBuffer();
  683. SysModel sysmodel = ModelFactory.getSysmodel();
  684. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  685. StringBuffer sql = new StringBuffer();
  686. json.append("[");
  687. sql.append("SELECT WM_CONCAT(ORG_ID) FROM V_DEPARTMENT START WITH ORG_ID = '"+orgId+"' CONNECT BY PRIOR PARENT_ID = ORG_ID ");
  688. try {
  689. ArrayList<String[]> listOrgInfo= persistence.getSearchResult(99, sql.toString());
  690. for (int i = 0; i < listOrgInfo.size(); i++) {
  691. String[] temp = listOrgInfo.get(i);
  692. json.append("\""+temp[0].replace(",","\",\"")+"\"");
  693. }
  694. } catch (PersistenceException e) {
  695. e.printStackTrace();
  696. }
  697. json.append("]");
  698. return json.toString();
  699. }
  700. /**
  701. * 显示录入人的信息 :姓名,电话号码, 4a的机构信息 ,岗位, 单位
  702. * @param entryManId 录入人的识别id
  703. * @return
  704. */
  705. public String queryEntryManInfo(String entryManId){
  706. StringBuffer json = new StringBuffer();
  707. SysModel sysmodel = ModelFactory.getSysmodel();
  708. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  709. StringBuffer sql = new StringBuffer();
  710. sql.append("--查询给定id录入人信息 \n");
  711. sql.append("SELECT U.USER_ID,U.REAL_NAME,U.MOBILE,D.DEPT_NAME,U.POSITION,D.CORP_NAME FROM SYS_USER_INFO U ,SYS_DEPT_USER DU, SYS_DEPARTMENT D \n");
  712. sql.append("WHERE U.USER_ID = DU.USER_ID AND DU.DEPT_ID = D.DEPT_ID AND U.USER_ID='"+entryManId+"' AND U.IS_DEL ='0' AND D.IS_DEL='0' AND DU.IS_DEL='0' \n");
  713. json.append("{\"entryInfo\":");
  714. try {
  715. ArrayList<String[]> listManInfo = persistence.getSearchResult(99, sql.toString());
  716. for (int i = 0; i < listManInfo.size(); i++) {
  717. String[] temp = listManInfo.get(i);
  718. String userId = temp[0];
  719. String real_name = temp[1];
  720. String mobile = temp[2];
  721. String deptName = temp[3];
  722. String job = temp[4];
  723. String corpName = temp[5];
  724. json.append(" \"userId\":\"" + userId + "\", \"real_name\":\"" + real_name
  725. + "\", \"mobile\": \"" + mobile + "\",\"deptName\":\"" + deptName + "\",");
  726. json.append("\"job\":\""+job+"\",\"corpName\":\""+corpName+"\"");
  727. }
  728. } catch (PersistenceException e) {
  729. e.printStackTrace();
  730. }
  731. json.append("");
  732. if (json.lastIndexOf(",") > -1) {
  733. json.deleteCharAt(json.lastIndexOf(","));
  734. };
  735. json.append("}");
  736. return json.toString();
  737. }
  738. public String updateEntryManTel(String userId,String tel){
  739. String result = "";
  740. SysModel sysmodel = ModelFactory.getSysmodel();
  741. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  742. StringBuffer sql = new StringBuffer();
  743. //正则验证
  744. if(!tel.matches("^[1]([3][0-9]{1}|59|58|88|89)[0-9]{8}$")){
  745. return result = "-2";
  746. }
  747. sql.append("UPDATE SYS_USER_INFO SET MOBILE ='"+tel+"' WHERE USER_ID =''"+userId+"' AND IS_DEL='0'");
  748. try {
  749. result =String.valueOf(persistence.executeUpdateSQL(99, sql.toString()));
  750. } catch (PersistenceException e) {
  751. e.printStackTrace();
  752. }
  753. return result;
  754. }
  755. /**
  756. * 根据传来的人员识别id 查询出 人员的信息 存入EMC_AM_DEPARTMENT_IN_LINKMAN ,其中 link_man_num 为当前该机构下的联系人数量+1
  757. * @param manID
  758. * @return
  759. */
  760. public String addMoreLinkMan(String manID){
  761. String result = "";
  762. SysModel sysmodel = ModelFactory.getSysmodel();
  763. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  764. StringBuffer sql = new StringBuffer();
  765. sql.append("--插入联系人 \n");
  766. sql.append("INSERT INTO EMC_AM_DEPARTMENT_IN_LINKMAN (SELECT SYS_GUID(), \n");
  767. sql.append("(SELECT NVL(MAX(A.LINK_MAN_NUM),0)+1 FROM V_DEPARTMENT_LINKMAN A WHERE A.LINK_ORG_ID= parent_org_id AND A.IS_DEL='0'), \n");
  768. sql.append("VIRTUAL_ORG_ID,INLINK_INDEX,INLINK_NAME,PHONE,'0',getDate() from emc_am_org_inlink where fd_objectid ='"+manID+"')");
  769. try {
  770. result =String.valueOf(persistence.executeUpdateSQL(99, sql.toString()));
  771. } catch (PersistenceException e) {
  772. e.printStackTrace();
  773. }
  774. return result;
  775. }
  776. public String queryOrg_LinkManInfo(String orgId){
  777. StringBuffer json = new StringBuffer();
  778. SysModel sysmodel = ModelFactory.getSysmodel();
  779. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  780. StringBuffer sql = new StringBuffer();
  781. ArrayList<String[]> listManInfo;
  782. try {
  783. listManInfo = persistence.getSearchResult(99, sql.toString());
  784. for (int i = 0; i < listManInfo.size(); i++) {
  785. String[] temp = listManInfo.get(i);
  786. String userId = temp[0];
  787. String real_name = temp[1];
  788. String mobile = temp[2];
  789. String deptName = temp[3];
  790. String job = temp[4];
  791. String corpName = temp[5];
  792. json.append(" \"userId\":\"" + userId + "\", \"real_name\":\"" + real_name
  793. + "\", \"mobile\": \"" + mobile + "\",\"deptName\":\"" + deptName + "\",");
  794. json.append("\"job\":\""+job+"\",\"corpName\":\""+corpName+"\"");
  795. }
  796. } catch (PersistenceException e) {
  797. e.printStackTrace();
  798. }
  799. return null;
  800. }
  801. /**
  802. * 根据传来的机构id查询出 该机构的上级单位id,如果他本身是corp 那么他 返回他自己的id 如果是部门dept 那找到离他最近的corp
  803. * 思路:1.查询出该机构的所有上级机构id(倒序排序如dept,dept,..,corp,corp,..),2.过滤掉dept 3.取出第一个结果就是离他最近的corp
  804. * @param id
  805. * @return
  806. */
  807. public String getCorpId(String id){
  808. String result = "";
  809. SysModel sysmodel = ModelFactory.getSysmodel();
  810. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  811. StringBuffer sql = new StringBuffer();
  812. sql.append("SELECT DEPT_ID FROM SYS_DEPARTMENT WHERE DEPT_TYPE='CORP' AND ROWNUM = 1 \n");
  813. sql.append(" START WITH DEPT_ID ='"+id+"' CONNECT BY PRIOR PARENT_ID = DEPT_ID \n");
  814. try {
  815. ArrayList<String[]> corpId = persistence.getSearchResult(99, sql.toString());
  816. if(corpId.size()>0){
  817. result = corpId.get(0)[0];
  818. }
  819. } catch (PersistenceException e) {
  820. e.printStackTrace();
  821. }
  822. return result;
  823. }
  824. /**
  825. * 思路同 getCorpId(String id)这个方法,
  826. */
  827. public void refreshAllCorpId(){
  828. SysModel sysmodel = ModelFactory.getSysmodel();
  829. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  830. StringBuffer sql = new StringBuffer();
  831. sql.append("MERGE INTO SYS_DEPARTMENT_1111_BACKUP P1 \n");
  832. sql.append("USING (SELECT B.ORG_NAME,B.ORG_ID,B.FD_OBJECTID,(SELECT A.ORG_ID FROM SYS_DEPARTMENT_1111_BACKUP A WHERE A.ORG_TYPE='CORP' AND ROWNUM =1 \n");
  833. sql.append("START WITH A.ORG_ID = B.ORG_ID \n");
  834. sql.append("CONNECT BY PRIOR A.PARENT_ORG_ID= A.ORG_ID) PCORPID FROM SYS_DEPARTMENT_1111_BACKUP B) P2 \n");
  835. sql.append("ON P1.FD_OBJECTID=P2.FD_OBJECTID \n");
  836. sql.append("WHEN MATCHED THEN \n");
  837. sql.append("UPDATE SET P1.CORP_ID = P2.PCORPID, \n");
  838. sql.append("P1.CORP_NAME = P2.ORG_NAME \n");
  839. try {
  840. persistence.executeUpdateSQL(99, sql.toString());
  841. } catch (PersistenceException e) {
  842. e.printStackTrace();
  843. }
  844. }
  845. /**
  846. * 新增虚拟机构信息 fd_objectid = org_id
  847. * @param params(map集合)
  848. * @return 新插入的主键id
  849. */
  850. // public String createVirtualOrg(Map<String,String> params){
  851. public String createVirtualOrg(String fd_objectid,String orgName,String parentId,String shortName,String orgType,String orgProp,String officeType,String formation_people,String
  852. havePeople,String orgAddress,String dutyTel,String dutyFax,String dutyEmail,String entryManId,String emergencyTel,String emergencyFax,String emergencyEmail,String entryManNAME){
  853. SysModel sysmodel = ModelFactory.getSysmodel();
  854. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  855. int sqlExecute = 0;
  856. String result = "";
  857. // String fd_objectid = params.get("FD_OBJECTID");
  858. fd_objectid = UUID.randomUUID().toString().replace("-", "");
  859. // String orgName = params.get("ORG_NAME");
  860. //String orgId = params.get("ORG_ID");
  861. // String parentId = params.get("PARENT_ID");
  862. //如果上级机构id为空 那么返回
  863. if("".equals(parentId)){
  864. return result;
  865. }
  866. // String shortName = params.get("SHORT_NAME");
  867. // String orgType = params.get("ORG_TYPE");
  868. // String orgProp = params.get("ORG_PROP");
  869. // String officeType = params.get("OFFICE_TYPE");
  870. // String formation_people = params.get("FORMATION_PEOPLE");
  871. // String havePeople = params.get("HAVE_PEOPLE");
  872. // String orgAddress = params.get("ORG_ADDRESS");
  873. // String dutyTel = params.get("DUTY_TEL");
  874. // String dutyFax = params.get("DUTY_FAX");
  875. // String dutyEmail = params.get("DUTY_EMAIL");
  876. // String entryManId = params.get("ENTRY_MAN_ID");
  877. // String emergencyTel = params.get("EMERGENCY_TEL");
  878. // String emergencyFax = params.get("EMERGENCY_FAX");
  879. // String emergencyEmail = params.get("EMERGENCY_EMAIL");
  880. //String pathId = params.get("PATH_ID");
  881. //String pathName = params.get("PATH_NAME");
  882. String pinyin = Pinyin4jUtil.getPinYin(orgName);
  883. String jianpin = Pinyin4jUtil.getPinYinHeadChar(orgName);
  884. //String sortNo = params.get("SORT_NO");
  885. StringBuffer sqlInsert = new StringBuffer();
  886. sqlInsert.append("INSERT INTO EMC_DEPARTMENT_IN (FD_OBJECTID,ENTRY_MAN_ID,ORG_NAME,SHORT_NAME,ORG_ID,PARENT_ID,ORG_TYPE,ORG_PROP,OFFICE_TYPE,FORMATION_PEOPLE,HAVE_PEOPLE, \n");
  887. sqlInsert.append("ORG_ADDRESS,DUTY_TEL,DUTY_FAX,DUTY_EMAIL,EMERGENCY_TEL,EMERGENCY_FAX,EMERGENCY_EMAIL,SORT_NO,IS_VIRTUAL,PATH_ID,PATH_NAME,PINYIN,JIANPIN,ORG_LEVEL,CORP_ID,CORP_NAME,IS_DEL,UPDATEDATE,ENTRY_MAN_NAME) \n");
  888. sqlInsert.append("VALUES('"+returnForDMNull(fd_objectid)+"','"+returnForDMNull(entryManId)+"','"+returnForDMNull(orgName)
  889. +"','"+returnForDMNull(shortName)+"','"+returnForDMNull(fd_objectid)+"','"+returnForDMNull(parentId)+"','"+returnForDMNull(orgType)
  890. +"','"+returnForDMNull(orgProp)+"','"+returnForDMNull(officeType)+"','"+returnForDMNull(formation_people)+"',");
  891. sqlInsert.append("'"+returnForDMNull(havePeople)+"','"+returnForDMNull(orgAddress)+"','"+returnForDMNull(dutyTel)+"','"+returnForDMNull(dutyFax)+"','"+returnForDMNull(dutyEmail)
  892. +"','"+returnForDMNull(emergencyTel)+"','"+returnForDMNull(emergencyFax)+"','"+returnForDMNull(emergencyEmail)+"',");
  893. //插入排序号 数据库序列,每查询一次自动增加"1",
  894. //sqlInsert.append(" (SELECT DEPARTMENT_SORT_SEQUENCE.NEXTVAL FROM DUAL),");
  895. //2016-06-07更改为固定值10
  896. sqlInsert.append("'10',");
  897. sqlInsert.append("'1',");
  898. //PATH_ID 的插入方法
  899. sqlInsert.append("(SELECT PATH_ID FROM V_DEPARTMENT WHERE ORG_ID ='"+parentId+"')||"+"'/_"+returnForDMNull(fd_objectid)+"_'");
  900. //PATH_NAME 的插入方法
  901. sqlInsert.append(",(SELECT PATH_NAME FROM V_DEPARTMENT WHERE ORG_ID ='"+parentId+"')||"+"'/"+returnForDMNull(orgName)+"'");
  902. sqlInsert.append(",'"+returnForDMNull(pinyin)+"','"+returnForDMNull(jianpin)+"'");
  903. //org_level 的插入方法
  904. sqlInsert.append(",NVL((SELECT ORG_LEVEL FROM V_DEPARTMENT WHERE ORG_ID ='"+parentId+"'),0)+1");
  905. //插入公司id 的方法(因为是新增的虚拟机构 写在一条sql里面 所以fd_id 不存在 所以用parent_id 作为起始节点)
  906. sqlInsert.append(",(SELECT ORG_ID FROM V_DEPARTMENT WHERE ROWNUM = 1 AND ORG_TYPE='1' START WITH ORG_ID ='"+parentId+"' CONNECT BY PRIOR PARENT_ID = ORG_ID )");
  907. //插入公司名称的方法
  908. sqlInsert.append(",(SELECT ORG_NAME FROM V_DEPARTMENT WHERE ROWNUM = 1 AND ORG_TYPE='1' START WITH ORG_ID ='"+parentId+"' CONNECT BY PRIOR PARENT_ID = ORG_ID)");
  909. sqlInsert.append(",'0',getDate(),'"+returnForDMNull(entryManNAME)+"')");
  910. log.info("sqlInsert=========="+sqlInsert);
  911. try {
  912. sqlExecute = persistence.executeUpdateSQL(99, sqlInsert.toString());
  913. //判定是否插入数据成功
  914. if(sqlExecute==1){
  915. result = getOrgInfoTree(fd_objectid);
  916. }
  917. } catch (PersistenceException e) {
  918. e.printStackTrace();
  919. }
  920. return result;
  921. }
  922. /**
  923. * 更新 EMC_DEPARTMENT_IN 中的 pathId 字段 规则 /_id_ PATH_NAME 规则 /name/name/name。。。。 org_level 设置 南方电网为1
  924. * @return
  925. */
  926. public String refreshOrgPathIdNameLevel(){
  927. SysModel sysmodel = ModelFactory.getSysmodel();
  928. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  929. StringBuffer sql = new StringBuffer();
  930. return null;
  931. }
  932. /**
  933. * 更新部门表
  934. * @param params
  935. * @return 更新成功返回主键id
  936. */
  937. public String updateVirtualOrg(Map<String,String> params){
  938. SysModel sysmodel = ModelFactory.getSysmodel();
  939. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  940. int sqlExecute = 0;
  941. String result = "";
  942. StringBuffer json = new StringBuffer();
  943. String fd_objectid = params.get("FD_OBJECTID");
  944. String orgName = params.get("ORG_NAME");
  945. String orgLevel = params.get("ORG_LEVEL");
  946. String sortNo = params.get("SORT_NO");
  947. String isVirtual = params.get("IS_VIRTUAL");
  948. //String orgId = params.get("ORG_ID");
  949. String parentId = params.get("PARENT_ID");
  950. //如果上级机构id为空 那么返回
  951. /*if("".equals(parentId)){
  952. return result;
  953. }*/
  954. String orgType = params.get("ORG_TYPE");
  955. String orgProp = params.get("ORG_PROP");
  956. String officeType = params.get("OFFICE_TYPE");
  957. //String formation_people = params.get("FORMATION_PEOPLE");
  958. //String havePeople = params.get("HAVE_PEOPLE");
  959. String orgAddress = params.get("ORG_ADDRESS");
  960. String dutyTel = params.get("DUTY_TEL");
  961. String dutyFax = params.get("DUTY_FAX");
  962. String dutyEmail = params.get("DUTY_EMAIL");
  963. String entryManId = params.get("ENTRY_MAN_ID");
  964. String entryManName = params.get("ENTRY_MAN_NAME");
  965. String shortName = params.get("SHORT_NAME");
  966. String emergencyTel = params.get("EMERGENCY_TEL");
  967. String emergencyFax = params.get("EMERGENCY_FAX");
  968. String emergencyEmail = params.get("EMERGENCY_EMAIL");
  969. //String pathId = params.get("PATH_ID");
  970. //String pathName = params.get("PATH_NAME");
  971. String pinyin = Pinyin4jUtil.getPinYin(orgName);
  972. String jianpin = Pinyin4jUtil.getPinYinHeadChar(orgName);
  973. StringBuffer sqlUpdate = new StringBuffer();
  974. sqlUpdate.append("UPDATE EMC_DEPARTMENT_IN SET ORG_NAME =NVL("+returnForDM(orgName)+",ORG_NAME) ,SHORT_NAME = NVL("+returnForDM(shortName)+",SHORT_NAME),OFFICE_TYPE = NVL("+returnForDM(officeType)+",OFFICE_TYPE),ORG_TYPE=NVL("+returnForDM(orgType)+",ORG_TYPE),");
  975. sqlUpdate.append("ORG_PROP=NVL("+returnForDM(orgProp)+",ORG_PROP),ORG_ADDRESS= NVL("+returnForDM(orgAddress)+",ORG_ADDRESS),DUTY_TEL=NVL("+returnForDM(dutyTel)+",DUTY_TEL),DUTY_FAX=NVL("+returnForDM(dutyFax)+",DUTY_FAX),");
  976. sqlUpdate.append("EMERGENCY_TEL=NVL("+returnForDM(emergencyTel)+",EMERGENCY_TEL),EMERGENCY_FAX=NVL("+returnForDM(emergencyFax)+",EMERGENCY_FAX),EMERGENCY_EMAIL=NVL("+returnForDM(emergencyEmail)
  977. +",EMERGENCY_EMAIL),ENTRY_MAN_ID=NVL("+returnForDM(entryManId)+",ENTRY_MAN_ID),ENTRY_MAN_NAME=NVL("+returnForDM(entryManName)+",ENTRY_MAN_NAME),");
  978. sqlUpdate.append("DUTY_EMAIL= NVL("+returnForDM(dutyEmail)+",DUTY_EMAIL),PINYIN = NVL("+returnForDM(pinyin)+",PINYIN),JIANPIN= NVL("+returnForDM(jianpin)+",JIANPIN),");
  979. //更新PATH_NAME
  980. sqlUpdate.append("PATH_NAME =REPLACE(PATH_NAME,ORG_NAME,NVL("+returnForDM(orgName)+",ORG_NAME)),");
  981. sqlUpdate.append("UPDATEDATE = getDate() WHERE FD_OBJECTID='"+fd_objectid+"' AND IS_DEL='0'");
  982. log.info(sqlUpdate);
  983. try {
  984. sqlExecute = persistence.executeUpdateSQL(99, sqlUpdate.toString());
  985. //判定是否更改数据成功
  986. if(sqlExecute==1){
  987. json.append("{");
  988. json.append(" \"id\":\"" + fd_objectid + "\", \"parentId\":\""
  989. + parentId + "\", \"name\": \"" + orgName
  990. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  991. //添加排序标识
  992. json.append("\"sortNo\":\""+sortNo+"\",");
  993. //添加是否为虚拟机构的属性
  994. json.append("\"isVirtual\":\""+isVirtual+"\",");
  995. json.append("\"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\"");
  996. json.append("}");
  997. result = json.toString();
  998. }
  999. } catch (PersistenceException e) {
  1000. e.printStackTrace();
  1001. }
  1002. return result;
  1003. }
  1004. //用于返回数据库(使用nvl时 判定传入参数 为null 就返回 null,不为null 需在数据库显示'str' 故加上单引号)
  1005. public String returnForDM(String str){
  1006. return str== null ? null :"'"+str+"'";
  1007. }
  1008. //用于返回数据库格式(当数据为null 时 保证存入的不会是'null' 存入"")
  1009. public String returnForDMNull(String str){
  1010. return str == null ? "" : str ;
  1011. }
  1012. /**
  1013. * 删除机构 将is_del 设置为 '1'
  1014. * @param orgId
  1015. * @return
  1016. */
  1017. public String deleteVirtualOrg(String orgId){
  1018. SysModel sysmodel = ModelFactory.getSysmodel();
  1019. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1020. int sqlExecute = 0;
  1021. String result = "";
  1022. //判定orgId是否为空
  1023. if("".equals(orgId)){
  1024. return result;
  1025. }
  1026. StringBuffer sqlDelete = new StringBuffer();
  1027. sqlDelete.append("UPDATE EMC_DEPARTMENT_IN B SET B.IS_DEL='1' WHERE B.FD_OBJECTID='"
  1028. +orgId+"' AND (SELECT COUNT(1) FROM V_DEPARTMENT A WHERE A.PARENT_ID = '"+orgId+"' AND A.IS_DEL='0' )<1 ");
  1029. sqlDelete.append(" AND (SELECT COUNT(1) FROM EMC_AM_ORG_INLINK A WHERE A.VIRTUAL_ORG_ID = '"+orgId+"' AND A.IS_DEL='0' )<1 ");
  1030. log.info(sqlDelete);
  1031. try {
  1032. sqlExecute = persistence.executeUpdateSQL(99, sqlDelete.toString());
  1033. //判定是否删除数据成功
  1034. if(sqlExecute==1){
  1035. result = "\""+orgId+"\"";
  1036. }
  1037. } catch (PersistenceException e) {
  1038. e.printStackTrace();
  1039. }
  1040. return result;
  1041. }
  1042. /**
  1043. *
  1044. * 删除第*联系人
  1045. * @param fdId EMC_AM_DEPARTMENT_IN_LINKMAN中的主键id
  1046. * @return 删除成功返回 fdId
  1047. */
  1048. public String deleteMoreLinkMan(String fdId){
  1049. SysModel sysmodel = ModelFactory.getSysmodel();
  1050. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1051. int sqlExecute = 0;
  1052. String result = "";
  1053. StringBuffer sqlDelete = new StringBuffer();
  1054. sqlDelete.append("UPDATE EMC_AM_DEPARTMENT_IN_LINKMAN SET IS_DEL='1' WHERE FD_OBJECTID='"+fdId+"'");
  1055. try {
  1056. sqlExecute = persistence.executeUpdateSQL(99, sqlDelete.toString());
  1057. //判定是否删除数据成功
  1058. if(sqlExecute==1){
  1059. result = fdId;
  1060. }
  1061. } catch (PersistenceException e) {
  1062. e.printStackTrace();
  1063. }
  1064. return result;
  1065. }
  1066. /**
  1067. * 异步加载还未加载出来的机构信息
  1068. * @param id
  1069. * @param level
  1070. * @param type
  1071. * @return
  1072. */
  1073. public String newOrgInfoById(String id, String level, String type) {
  1074. StringBuffer json = new StringBuffer();
  1075. SysModel sysmodel = ModelFactory.getSysmodel();
  1076. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1077. StringBuffer sql = new StringBuffer();
  1078. sql.append("WITH TA AS(SELECT * FROM V_DEPARTMENT WHERE IS_DEL='0') \n");
  1079. sql.append("SELECT B.ORG_ID,B.ORG_NAME,B.PARENT_ID,B.ORG_LEVEL , B.IS_VIRTUAL, B.SORT_NO,\n");
  1080. sql.append("DECODE((SELECT COUNT(1) FROM TA WHERE TA.PARENT_ID=B.ORG_ID),'0','0','1')AS 是否有子机构, \n");
  1081. sql.append("DECODE((SELECT COUNT(1) FROM SYS_USER_INFO U,SYS_DEPT_USER DU WHERE U.USER_ID=DU.USER_ID AND DU.DEPT_ID=B.ORG_ID),'0','0','1')AS 是否员工 \n");
  1082. sql.append("FROM TA B \n");
  1083. sql.append("WHERE B.PARENT_ID IN (SELECT C.ORG_ID FROM TA C \n");
  1084. sql.append("WHERE C.ORG_ID<>'" + id + "' \n");
  1085. sql.append("START WITH C.ORG_ID ='" + id + "' \n");
  1086. sql.append("CONNECT BY C.ORG_ID = PRIOR C.PARENT_ID AND C.ORG_LEVEL >= '" + level
  1087. + "') \n");
  1088. sql.append("ORDER BY B.ORG_LEVEL");
  1089. json.append("{\"treeNodes\":[");
  1090. try {
  1091. ArrayList<String[]> listOrgInfo = persistence.getSearchResult(99, sql.toString());
  1092. for (int i = 0; i < listOrgInfo.size(); i++) {
  1093. String[] temp = listOrgInfo.get(i);
  1094. String orgId = temp[0];
  1095. String orgName = temp[1];
  1096. String parentOrgId = temp[2];
  1097. String orgLevel = temp[3];
  1098. String isVirtual = temp[4];
  1099. String sortNo = temp[5];
  1100. // 判定是否存在子节点
  1101. boolean isHasChildOrg = !("0".equals(temp[6]));
  1102. //判断是否存在员工
  1103. boolean isHasStaff = ("1".equals(temp[7]));
  1104. // 判定是虚拟机构还是实体机构
  1105. String icon = isVirtual == "1" ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  1106. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  1107. json.append("{");
  1108. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  1109. + parentOrgId + "\", \"name\": \"" + orgName
  1110. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  1111. //添加排序标识
  1112. json.append("\"sortNo\":\""+sortNo+"\",");
  1113. //添加是否为虚拟机构的属性
  1114. json.append("\"isVirtual\":\""+isVirtual+"\",");
  1115. json.append("\"leafType\":\"org\",");
  1116. if("per".equals(type)){
  1117. if (isHasChildOrg||isHasStaff) {
  1118. json.append("\"isParent\": \"true\" ");
  1119. } else {
  1120. json.append("\"isParent\": \"fasle\" ");
  1121. }
  1122. }else{
  1123. if (isHasChildOrg) {
  1124. json.append("\"isParent\": \"true\" ");
  1125. } else {
  1126. json.append("\"isParent\": \"fasle\" ");
  1127. }
  1128. }
  1129. json.append(", \"icon\":"+icon);
  1130. json.append("},");
  1131. }
  1132. if("per".equals(type)){
  1133. json.append(addOrgInfoByIdHasPer(id,level));
  1134. }
  1135. if (json.lastIndexOf(",") > -1) {
  1136. json.deleteCharAt(json.lastIndexOf(","));
  1137. };
  1138. json.append("]}");
  1139. log.info(json.toString());
  1140. } catch (PersistenceException e) {
  1141. e.printStackTrace();
  1142. }
  1143. return json.toString();
  1144. }
  1145. /**
  1146. * 异步搜索查询方法(带人)
  1147. * 思路:查询出需要重新加载的id然后再汇总所有机构的parentId ,根据汇总的parentId 加载parentId 下的所有人员
  1148. *
  1149. * @param id
  1150. * @param level
  1151. * @return
  1152. */
  1153. public String addOrgInfoByIdHasPer(String id, String level) {
  1154. StringBuffer json = new StringBuffer();
  1155. SysModel sysmodel = ModelFactory.getSysmodel();
  1156. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1157. StringBuffer sql = new StringBuffer();
  1158. sql.append("--查询给定id下指定级别的 机构信息 \n");
  1159. sql.append("WITH TA AS(SELECT * FROM SYS_DEPARTMENT_1111) \n");
  1160. sql.append("SELECT B.USER_ID,B.REAL_NAME,B.GENDER,D.DEPT_ID,B.MOBILE,B.POSITION \n");
  1161. sql.append("FROM SYS_USER_INFO B,SYS_DEPT_USER D \n");
  1162. sql.append("WHERE B.USER_ID=D.USER_ID AND D.DEPT_ID IN (SELECT C.ORG_ID FROM TA C \n");
  1163. sql.append("WHERE C.ORG_ID<>'" + id + "' \n");
  1164. sql.append("START WITH C.ORG_ID ='" + id + "' \n");
  1165. sql.append("CONNECT BY C.ORG_ID = PRIOR C.PARENT_ORG_ID AND C.ORG_LEVEL >= '" + level
  1166. + "') \n");
  1167. //json.append("{\"treeNodes\":[");
  1168. log.info(sql);
  1169. try {
  1170. ArrayList<String[]> listOrgInfo = persistence.getSearchResult(99, sql.toString());
  1171. for (int i = 0; i < listOrgInfo.size(); i++) {
  1172. String[] temp = listOrgInfo.get(i);
  1173. String userId = temp[0];
  1174. String realName = temp[1];
  1175. String userGender = temp[2];
  1176. String parentOrgId = temp[3];
  1177. String manPhone = temp[4];
  1178. String manDuty = temp[5];
  1179. json.append("{");
  1180. json.append(" \"id\":\"" + userId + "\", \"parentId\":\"" + parentOrgId
  1181. + "\", \"name\": \"" + realName + "\",");
  1182. json.append("\"leafType\":\"per\",");
  1183. json.append("\"manPhone\":\""+manPhone+"\",");
  1184. json.append("\"leafType\":\""+manDuty+"\",");
  1185. if ("男".equals(userGender)) {
  1186. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user-black.png\"");
  1187. } else if ("女".equals(userGender)) {
  1188. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user-red-female.png\"");
  1189. } else {
  1190. json.append(" \"icon\":\"/nwyj/scripts/qui/libs/icons/user_group.gif\"");
  1191. }
  1192. json.append("},");
  1193. }
  1194. /*if (json.lastIndexOf(",") > -1) {
  1195. json.deleteCharAt(json.lastIndexOf(","));
  1196. };*/
  1197. //json.append("]}");
  1198. Log.info(json.toString());
  1199. } catch (PersistenceException e) {
  1200. e.printStackTrace();
  1201. }
  1202. return json.toString();
  1203. }
  1204. /***************************************************************************************************************************************************************************/
  1205. public String statisticInfo(Map<String, String> statisticMap) {
  1206. String statisticId = statisticMap.get("statisticId");
  1207. String orgProp = statisticMap.get("orgProp");
  1208. String fromDate = statisticMap.get("fromDate");
  1209. String toDate = statisticMap.get("toDate");
  1210. StringBuffer sql=new StringBuffer();
  1211. ORGTemplate org = new ORGTemplate();
  1212. StringBuffer result = new StringBuffer();
  1213. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1214. sql.append("WITH A AS(SELECT * FROM V_DEPARTMENT WHERE CORP_ID IN (SELECT ORG_ID FROM V_DEPARTMENT WHERE( \n");
  1215. sql.append("PARENT_ID = ? OR ORG_ID = ?)AND IS_VIRTUAL='0' AND IS_DEL ='0')AND(ORG_PROP = ? OR ORG_PROP IS NULL)AND IS_DEL ='0' and ( ( ( org_name like '%供电局' or org_name like '%供电分局' or org_name like '%供电所' or org_id='C984DC9C294A486096C25FAA78C99AED' )and is_virtual='0' ) or is_virtual='1' ) \n");//20160516广东电网id更改为C984DC9C294A486096C25FAA78C99AED
  1216. //时间过滤
  1217. if(fromDate!=null&&!"".equals(fromDate)){
  1218. sql.append("AND UPDATEDATE BETWEEN TO_DATE('"+fromDate+"','yyyy-mm-dd') \n");
  1219. if(toDate!=null&&!"".equals(toDate)){
  1220. sql.append(" AND TO_DATE('"+toDate+"','yyyy-mm-dd') \n");
  1221. }else{
  1222. sql.append(" AND getdate() \n");
  1223. }
  1224. }
  1225. sql.append(") \n");
  1226. sql.append("SELECT \n");
  1227. sql.append("(SELECT TO_NUMBER(SORT) FROM SYS_DEPARTMENT WHERE DEPT_ID = A.CORP_ID)AS SO, \n");
  1228. sql.append("CORP_ID AS ORGID, \n");
  1229. sql.append("(SELECT ORG_NAME FROM V_DEPARTMENT WHERE ORG_ID = A.CORP_ID)AS DWLB , \n");
  1230. sql.append("SUM(DECODE(OFFICE_TYPE, 'DDBG', 1, 0)) AS DDBG, \n");
  1231. sql.append("SUM(DECODE(OFFICE_TYPE, 'HSBG', 1, 0)) AS HSBG, \n");
  1232. sql.append("SUM(DECODE(IS_VIRTUAL, '1', 1, 0)) AS JGZS , \n");
  1233. sql.append("(SELECT COUNT(1)FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID IN (SELECT C.ORG_ID FROM V_DEPARTMENT C WHERE C.CORP_ID =A.CORP_ID AND(ORG_PROP = ? ) AND IS_DEL ='0')AND IS_DEL='0' \n");
  1234. //时间过滤
  1235. if(fromDate!=null&&!"".equals(fromDate)){
  1236. sql.append("AND UPDATEDATE BETWEEN TO_DATE('"+fromDate+"','yyyy-mm-dd') \n");
  1237. if(toDate!=null&&!"".equals(toDate)){
  1238. sql.append(" AND TO_DATE('"+toDate+"','yyyy-mm-dd') \n");
  1239. }else{
  1240. sql.append(" AND getdate() \n");
  1241. }
  1242. }
  1243. sql.append(" ) AS BZRS, \n");
  1244. sql.append("(SELECT COUNT(DISTINCT INLINK_INDEX) FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID IN ( SELECT C.ORG_ID FROM V_DEPARTMENT C WHERE C.CORP_ID =A.CORP_ID AND( ORG_PROP = ? ) AND IS_DEL ='0' )AND IS_DEL='0' \n");
  1245. //时间过滤
  1246. if(fromDate!=null&&!"".equals(fromDate)){
  1247. sql.append("AND UPDATEDATE BETWEEN TO_DATE('"+fromDate+"','yyyy-mm-dd') \n");
  1248. if(toDate!=null&&!"".equals(toDate)){
  1249. sql.append(" AND TO_DATE('"+toDate+"','yyyy-mm-dd') \n");
  1250. }else{
  1251. sql.append(" AND getdate() \n");
  1252. }
  1253. }
  1254. sql.append(" )AS DWRS \n");
  1255. sql.append("FROM \n");
  1256. sql.append(" A \n");
  1257. sql.append("GROUP BY \n");
  1258. sql.append("A.CORP_ID \n");
  1259. sql.append("ORDER BY SO \n");
  1260. log.info(sql.toString());
  1261. result.append("{\"rows\":[");
  1262. try {
  1263. list = org.query(sql.toString(),statisticId,statisticId,orgProp,orgProp,orgProp);
  1264. if(list.size()==0){return "";}
  1265. //添加总计
  1266. Map<String,String> totalList = new HashMap<String,String>();
  1267. for (Map.Entry<String, String> entry : list.get(0).entrySet()) {
  1268. totalList.put(entry.getKey(),"0");
  1269. }
  1270. totalList.put("ORGID", "ZJ");
  1271. totalList.put("DWLB", "合计");
  1272. totalList.put("SO", "排序");
  1273. for(int i = 0;i<list.size();i++){
  1274. for (Map.Entry<String, String> entry : list.get(i).entrySet()) {
  1275. //sb.append("\""+entry.getKey()+"\":\""+entry.getValue()+"\",");
  1276. if(!("ORGID".equals(entry.getKey())||"DWLB".equals(entry.getKey())||"SO".equals(entry.getKey()))){
  1277. totalList.put(entry.getKey(), Integer.toString(Integer.parseInt(entry.getValue())+Integer.parseInt(totalList.get(entry.getKey()))));
  1278. }
  1279. }
  1280. }
  1281. list.add(totalList);
  1282. result.append(org.listToString(list));
  1283. log.info(result);
  1284. } catch (SQLException e) {
  1285. e.printStackTrace();
  1286. }
  1287. result.append("]}");
  1288. return result.toString();
  1289. }
  1290. public String getOrgAndPerInfo(Map<String, String> loadOrgPerMap) {
  1291. String id = loadOrgPerMap.get("autoSubmitId");
  1292. boolean isFirstLoad = false;
  1293. if(id==null||"".equals(id)){
  1294. id=loadOrgPerMap.get("fromDeptId");
  1295. isFirstLoad=true;
  1296. }
  1297. String toDeptId = loadOrgPerMap.get("toDeptId");
  1298. ORGTemplate org = new ORGTemplate();
  1299. StringBuffer sql = new StringBuffer();
  1300. StringBuffer json = new StringBuffer();
  1301. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1302. json.append("{\"treeNodes\":[");
  1303. if (isFirstLoad) {
  1304. sql.append("--查询给定id及其一级子机构的信息 \n");
  1305. sql.append("WITH P AS(SELECT U.USER_ID \"id\",U.REAL_NAME \"name\",U.ORG_ID \"parentId\",'/nwyj/scripts/qui/libs/icons/user-black.png' \"icon\",U.POSITION \"orgLevel\", U.MOBILE \"perPhone\",U.GENDER \"isParent\",'per' \"leafType\" \n");
  1306. sql.append("FROM SYS_USER_INFO U ,SYS_DEPARTMENT D,SYS_DEPT_USER DU \n");
  1307. sql.append("WHERE U.USER_ID = DU.USER_ID AND D.DEPT_ID = DU.DEPT_ID AND D.DEPT_ID=? \n");
  1308. sql.append("AND U.USER_ID NOT IN (SELECT INLINK_INDEX FROM EMC_AM_ORG_INLINK X \n");
  1309. sql.append("WHERE X.VIRTUAL_ORG_ID =? AND X.IS_DEL ='0') ) , \n");
  1310. sql.append("O AS(SELECT A.DEPT_ID ,A.DEPT_NAME ,A.PARENT_ID ,'/nwyj/scripts/qui/libs/icons/home.png' icon,A.DEPT_LEVEL,A.CORP_ID e, \n");
  1311. sql.append("DECODE(DECODE((SELECT COUNT(1) FROM SYS_DEPARTMENT B WHERE B.PARENT_ID = A.DEPT_ID),0,0,1)+ \n");
  1312. sql.append("DECODE((SELECT COUNT(1) FROM SYS_USER_INFO U ,SYS_DEPARTMENT D,SYS_DEPT_USER DU \n");
  1313. sql.append("WHERE U.USER_ID = DU.USER_ID AND D.DEPT_ID = DU.DEPT_ID AND D.DEPT_ID=A.DEPT_ID \n");
  1314. sql.append("AND U.USER_ID NOT IN (SELECT INLINK_INDEX FROM EMC_AM_ORG_INLINK X \n");
  1315. sql.append("WHERE X.VIRTUAL_ORG_ID =? AND X.IS_DEL ='0') \n");
  1316. sql.append("),0,0,1),0,'false','true') AS isParent,'org' leafType \n");
  1317. sql.append("FROM SYS_DEPARTMENT A WHERE (A.PARENT_ID = ? OR A.DEPT_ID=?)) \n");
  1318. sql.append("SELECT * FROM P \n");
  1319. sql.append("UNION ALL \n");
  1320. sql.append("SELECT * FROM O \n");
  1321. try {
  1322. list = org.query(sql.toString(),id,toDeptId,toDeptId,id,id);
  1323. json.append(org.listToString(list));
  1324. } catch (SQLException e) {
  1325. e.printStackTrace();
  1326. }
  1327. } else {
  1328. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  1329. sql.append("WITH P AS(SELECT U.USER_ID \"id\",U.REAL_NAME \"name\",U.ORG_ID \"parentId\",'/nwyj/scripts/qui/libs/icons/user-black.png' \"icon\",U.POSITION \"orgLevel\", U.MOBILE \"perPhone\",U.GENDER \"gender\",'per' \"leafType\" \n");
  1330. sql.append("FROM SYS_USER_INFO U ,SYS_DEPARTMENT D,SYS_DEPT_USER DU \n");
  1331. sql.append("WHERE U.USER_ID = DU.USER_ID AND D.DEPT_ID = DU.DEPT_ID AND D.DEPT_ID=? \n");
  1332. sql.append("AND U.USER_ID NOT IN (SELECT INLINK_INDEX FROM EMC_AM_ORG_INLINK X \n");
  1333. sql.append("WHERE X.VIRTUAL_ORG_ID =? AND X.IS_DEL ='0') ) , \n");
  1334. sql.append("O AS(SELECT A.DEPT_ID ,A.DEPT_NAME ,A.PARENT_ID ,'/nwyj/scripts/qui/libs/icons/home.png' icon,A.DEPT_LEVEL,A.CORP_ID e, \n");
  1335. sql.append("DECODE(DECODE((SELECT COUNT(1) FROM SYS_DEPARTMENT B WHERE B.PARENT_ID = A.DEPT_ID),0,0,1)+ \n");
  1336. sql.append("DECODE((SELECT COUNT(1) FROM SYS_USER_INFO U ,SYS_DEPARTMENT D,SYS_DEPT_USER DU \n");
  1337. sql.append("WHERE U.USER_ID = DU.USER_ID AND D.DEPT_ID = DU.DEPT_ID AND D.DEPT_ID=A.DEPT_ID \n");
  1338. sql.append("AND U.USER_ID NOT IN (SELECT INLINK_INDEX FROM EMC_AM_ORG_INLINK X \n");
  1339. sql.append("WHERE X.VIRTUAL_ORG_ID =? AND X.IS_DEL ='0') \n");
  1340. sql.append("),0,0,1),0,'false','true') AS isParent,'org' leafType \n");
  1341. sql.append("FROM SYS_DEPARTMENT A WHERE A.PARENT_ID = ?) \n");
  1342. sql.append("SELECT * FROM P \n");
  1343. sql.append("UNION ALL \n");
  1344. sql.append("SELECT * FROM O \n");
  1345. try {
  1346. list = org.query(sql.toString(),id,toDeptId,toDeptId,id);
  1347. json.append(org.listToString(list));
  1348. } catch (SQLException e) {
  1349. e.printStackTrace();
  1350. }
  1351. }
  1352. //log.info(sql.toString());
  1353. json.append("]}");
  1354. return json.toString();
  1355. }
  1356. public String getDepartmentInfo(Map<String, String> departmentInfoMap) {
  1357. String adminRoleId = departmentInfoMap.get("adminRoleId");//权限id
  1358. String id = departmentInfoMap.get("autoSubmitId");//自动提交的id
  1359. boolean isFirstLoad = false;
  1360. if(id==null||"".equals(id)){
  1361. id=departmentInfoMap.get("FirstDeptId");
  1362. isFirstLoad=true;
  1363. }
  1364. ORGTemplate org = new ORGTemplate();
  1365. StringBuffer sql = new StringBuffer();
  1366. StringBuffer json = new StringBuffer();
  1367. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1368. json.append("{\"treeNodes\":[");
  1369. if (isFirstLoad) {
  1370. sql.append("--查询给定id一级子机构的信息 \n");
  1371. // sql.append("WITH T AS (SELECT * FROM SYS_DEPARTMENT WHERE INSTR(DEPT_PATH,'_'||?||'_')>0) \n");
  1372. sql.append("WITH T AS (SELECT * FROM SYS_DEPARTMENT ) \n");
  1373. sql.append("SELECT A.DEPT_ID \"id\",A.DEPT_NAME \"name\",A.PARENT_ID \"parentId\",A.DEPT_LEVEL \"orgLevel\", \n");
  1374. sql.append("'/nwyj/scripts/qui/libs/icons/home.png' \"icon\", \n");
  1375. sql.append("DECODE((SELECT COUNT(1) FROM T B WHERE B.PARENT_ID = A.DEPT_ID),0,'false','true') AS \"isParent\" \n");
  1376. sql.append(",'true' \"open\" \n ");
  1377. sql.append("FROM T A WHERE A.PARENT_ID = ? OR A.DEPT_ID =? order by sort \n ");
  1378. try {
  1379. list = org.query(sql.toString(),id,id);
  1380. json.append(org.listToString(list));
  1381. } catch (SQLException e) {
  1382. e.printStackTrace();
  1383. }
  1384. } else {
  1385. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  1386. // sql.append("WITH T AS (SELECT * FROM SYS_DEPARTMENT WHERE INSTR(DEPT_PATH,'_'||?||'_')>0) \n");
  1387. sql.append("WITH T AS (SELECT * FROM SYS_DEPARTMENT ) \n");
  1388. sql.append("--查询给定id及其一级子机构的信息 \n");
  1389. sql.append("SELECT A.DEPT_ID \"id\",A.DEPT_NAME \"name\",A.PARENT_ID \"parentId\",A.DEPT_LEVEL \"orgLevel\", \n");
  1390. sql.append("'/nwyj/scripts/qui/libs/icons/home.png' \"icon\", \n");
  1391. sql.append("DECODE((SELECT COUNT(1) FROM T B WHERE B.PARENT_ID = A.DEPT_ID),0,'false','true') AS \"isParent\" \n");
  1392. sql.append("FROM T A WHERE A.PARENT_ID = ? order by sort \n ");
  1393. try {
  1394. list = org.query(sql.toString(),id);
  1395. json.append(org.listToString(list));
  1396. } catch (SQLException e) {
  1397. e.printStackTrace();
  1398. }
  1399. }
  1400. log.info(sql.toString());
  1401. json.append("]}");
  1402. return json.toString();
  1403. }
  1404. /**
  1405. * 系统管理 组织机构 获取树
  1406. * @param params
  1407. * @return
  1408. */
  1409. public String getSysOrgInfoById(String id, boolean getPerson, boolean isFirstLoad) {
  1410. String result = new String();
  1411. if (getPerson) {
  1412. result = loadInDepartmentPerById(id, isFirstLoad,null);
  1413. } else {
  1414. result = loadSysInDepartmentById(id, isFirstLoad);
  1415. }
  1416. return result;
  1417. }
  1418. /**
  1419. * 系统管理 组织机构 获取树
  1420. * @param params
  1421. * @return
  1422. */
  1423. public String loadSysInDepartmentById(String id, boolean isFirstLoad) {
  1424. SysModel sysmodel = ModelFactory.getSysmodel();
  1425. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1426. StringBuffer sql = new StringBuffer();
  1427. StringBuffer json = new StringBuffer();
  1428. json.append("{\"treeNodes\":[");
  1429. if (isFirstLoad) {
  1430. sql.append("--查询给定id及其一级子机构的信息 \n");
  1431. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 FROM V_DEPARTMENT A WHERE ( PARENT_ID = '"+id+"' OR ORG_ID ='"+id+"' ) AND IS_DEL='0' and is_virtual='0' ORDER BY SORT_NO )");
  1432. // sql.append("(SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL,A.SORT_NO, \n");
  1433. // sql.append("DECODE((SELECT COUNT(1) FROM EMC_DEPARTMENT_IN B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL='0'),'0','0','1') AS 是否有子机构 \n");
  1434. // sql.append("FROM EMC_DEPARTMENT_IN A WHERE (PARENT_ID = '"
  1435. // + id + "' OR ORG_ID='" + id + "') AND IS_DEL='0' and ((org_name like '%供电局') or(org_name like '%供电分局') ) and is_virtual='0' ORDER BY SORT_NO\n)");
  1436. } else {
  1437. sql.append("--查询给定id一级子机构的信息(不包括他本身) \n");
  1438. sql.append("( SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL, A.SORT_NO,DECODE( ( SELECT COUNT(1) FROM V_DEPARTMENT B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL ='0' ),'0', '0', '1') AS 是否有子机构 FROM V_DEPARTMENT A WHERE ( PARENT_ID = '"+id+"') AND IS_DEL='0' and is_virtual='0' ORDER BY SORT_NO )");
  1439. // sql.append("SELECT A.ORG_ID,A.ORG_NAME,A.PARENT_ID,A.ORG_LEVEL,A.IS_VIRTUAL,A.SORT_NO, \n");
  1440. // sql.append("DECODE((SELECT COUNT(1) FROM EMC_DEPARTMENT_IN B WHERE B.PARENT_ID = A.ORG_ID AND B.IS_DEL='0'),'0','0','1') AS 是否有子机构 \n");
  1441. // sql.append("FROM EMC_DEPARTMENT_IN A WHERE PARENT_ID = '"
  1442. // + id + "' AND IS_DEL='0' and ((org_name like '%供电局') or(org_name like '%供电分局') ) ORDER BY SORT_NO \n");
  1443. }
  1444. // log.info(sql);
  1445. try {
  1446. ArrayList<String[]> listRoot = persistence.getSearchResult(99,
  1447. sql.toString());
  1448. int listLen = listRoot.size();
  1449. for (int i = 0; i < listLen; i++) {
  1450. String[] temp = listRoot.get(i);
  1451. String orgId = temp[0];
  1452. String orgName = temp[1];
  1453. String parentOrgId = temp[2];
  1454. String orgLevel = temp[3];
  1455. String isVirtual = temp[4];
  1456. String sortNo = temp[5];
  1457. // 判定是否存在子节点
  1458. boolean isHasChildOrg = !("0".equals(temp[6]));
  1459. // 判定是否为第一次加载的id(用来展开初始化的节点)
  1460. String isRootNode = id.equals(orgId) ? "true" : "false";
  1461. // 判定是虚拟机构还是实体机构
  1462. String icon = "1".equals(isVirtual) ? "\"/nwyj/scripts/qui/libs/icons/home.gif\""
  1463. : "\"/nwyj/scripts/qui/libs/icons/home.png\"";
  1464. json.append("{");
  1465. json.append(" \"id\":\"" + orgId + "\", \"parentId\":\""
  1466. + parentOrgId + "\", \"name\": \"" + orgName
  1467. + "\",\"orgLevel\":\"" + orgLevel + "\",");
  1468. //添加排序标识
  1469. json.append("\"sortNo\":\""+sortNo+"\",");
  1470. //添加是否为虚拟机构的属性
  1471. json.append("\"isVirtual\":\""+isVirtual+"\",");
  1472. // 是否展开
  1473. json.append("\"open\":\"" + isRootNode + "\",");
  1474. //设置标记字段值(用于额外的属性)
  1475. json.append("\"tagValue\":\"1\",");
  1476. if (isHasChildOrg) {
  1477. json.append("\"isParent\": \"true\" ");
  1478. } else {
  1479. json.append("\"isParent\": \"fasle\" ");
  1480. }
  1481. json.append(", \"icon\":" + icon + "");
  1482. // json.append(", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  1483. json.append("},");
  1484. }
  1485. // 去掉多余的","
  1486. if (json.lastIndexOf(",") > -1) {
  1487. json.deleteCharAt(json.lastIndexOf(","));
  1488. }
  1489. ;
  1490. json.append("]}");
  1491. log.info(json.toString());
  1492. } catch (PersistenceException e) {
  1493. e.printStackTrace();
  1494. }
  1495. return json.toString();
  1496. }
  1497. /**
  1498. * 更新常用联系人群的方法
  1499. * @param commonGroupMap
  1500. * @return
  1501. */
  1502. public String updateCommomGroupById(Map<String, String> commonGroupMap) {
  1503. String id = commonGroupMap.get("loginManId");
  1504. String name = commonGroupMap.get("editName");
  1505. ORGTemplate org = new ORGTemplate();
  1506. StringBuffer sql = new StringBuffer();
  1507. String json = "";
  1508. sql.append("--根据传入的id更改常用组的名称 \n");
  1509. sql.append("UPDATE EMC_AM_COMMON_MAN_GROUP SET GROUP_NAME=? WHERE GROUP_ID=?");
  1510. try {
  1511. json = String.valueOf(org.update(sql.toString(), name,id));
  1512. } catch (SQLException e) {
  1513. e.printStackTrace();
  1514. }
  1515. return json;
  1516. }
  1517. /**
  1518. * 删除常用群组人员的方法
  1519. * @param commonGroupMap
  1520. * @return
  1521. */
  1522. public String deleteCommGroupById(Map<String, String> commonGroupMap) {
  1523. String groupId = commonGroupMap.get("groupId");
  1524. String nodeType = commonGroupMap.get("nodeType");
  1525. String result = "fail";
  1526. log.info("==================="+groupId+"_____"+nodeType);
  1527. StringBuffer sql1 = new StringBuffer();
  1528. StringBuffer sql2 = new StringBuffer();
  1529. StringBuffer sql3 = new StringBuffer();
  1530. sql1.append("--根据id删除常用组 \n");
  1531. sql1.append("UPDATE EMC_AM_COMMON_MAN_GROUP SET IS_DEL = '1' WHERE GROUP_ID = ? AND IS_DEL='0' \n");
  1532. sql2.append("--根据groupid删除常用组织 \n");
  1533. sql2.append("UPDATE EMC_AM_COMMON_MAN SET IS_DEL = '1' WHERE GROUP_ID = ? AND IS_DEL='0' \n");
  1534. sql3.append("--根据id删除常用组织 \n");
  1535. sql3.append("UPDATE EMC_AM_COMMON_MAN SET IS_DEL = '1' WHERE MAN_ID= ? AND IS_DEL='0' \n");
  1536. ORGTemplate org = new ORGTemplate();
  1537. try {
  1538. if("commGroup".equals(nodeType)){
  1539. int i = org.update(sql1.toString(),groupId);
  1540. int j = org.update(sql2.toString(),groupId);
  1541. result = i+j==2?"success":"false";
  1542. }else if("commmMan".equals(nodeType)){
  1543. int i = org.update(sql3.toString(),groupId);
  1544. result = i==1?"success":"false";
  1545. }else{
  1546. result = "fail";
  1547. }
  1548. } catch (SQLException e) {
  1549. e.printStackTrace();
  1550. }
  1551. return result;
  1552. }
  1553. /**
  1554. * 添加自定义常用联系人组
  1555. * @param diyGroupMap
  1556. * @return
  1557. */
  1558. public String addDiyGroup(Map<String, String> diyGroupMap) {
  1559. StringBuffer result=new StringBuffer();
  1560. String linkLoginId = diyGroupMap.get("loginManId");
  1561. String diyName = diyGroupMap.get("diyName");
  1562. String uuid = getUUID();
  1563. if ("".equals(linkLoginId) || "".equals(diyName)) {
  1564. return result.toString();
  1565. }
  1566. StringBuffer sql = new StringBuffer();
  1567. sql.append("--根据id新增一个常用组 \n");
  1568. sql.append("INSERT INTO EMC_AM_COMMON_MAN_GROUP (FD_OBJECTID,GROUP_ID,GROUP_NAME,LOGIN_ID,IS_DEL,UPDATEDATE) \n");
  1569. sql.append("VALUES(?,?,?,?,'0',GETDATE()) \n");
  1570. ORGTemplate org = new ORGTemplate();
  1571. int excute = 0;
  1572. try {
  1573. excute = org.update(sql.toString(), uuid,uuid,diyName,linkLoginId);
  1574. } catch (SQLException e) {
  1575. e.printStackTrace();
  1576. }
  1577. if(excute==1){
  1578. result.append("[{");
  1579. result.append("\"id\":\"" + uuid + "\",");
  1580. result.append("\"parentId\":\"" + "0" + "\",");
  1581. result.append("\"name\":\"" + diyName+"(0)" + "\",");
  1582. result.append("\"realOrgName\":\"" + diyName + "\",");
  1583. result.append("\"childNums\":\"" + "0" + "\",");
  1584. result.append("\"fdId\":\"" + linkLoginId + "\",");
  1585. result.append("\"nodeType\":\"" + "father" + "\",");
  1586. result.append("\"linkOrgId\":\"" + linkLoginId + "\",");
  1587. result.append("\"icon\":\"/nwyj/scripts/qui/sample/tree/layers.gif\"");
  1588. result.append("},");
  1589. result.append("{");
  1590. result.append("\"id\":\"" + "virtual" + "\",");
  1591. result.append("\"parentId\":\"" + uuid + "\",");
  1592. result.append("\"name\":\"" + "添加常用联系人" + "\",");
  1593. result.append("\"font\":{\"color\":\"gray\"},");
  1594. result.append("\"click\":\"addCommonOrg('"+uuid+"','"+diyName+"');\",");
  1595. result.append("\"nodeType\":\"" + "virtual" + "\",");
  1596. result.append("\"linkOrgId\":\"" + "virtual" + "\",");
  1597. result.append("\"isParent\":\"" + "false" + "\",");
  1598. result.append("\"icon\":\"/nwyj/scripts/qui/libs/icons/add.png\"");
  1599. result.append("}]");
  1600. }
  1601. return result.toString();
  1602. }
  1603. /**
  1604. * 生成uuid
  1605. * @return
  1606. */
  1607. public static String getUUID(){
  1608. String s = UUID.randomUUID().toString();
  1609. //去掉“-”符号
  1610. return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
  1611. }
  1612. public String loadCommonLinkmanGroupInfo(Map<String, String> loadParamMap) {
  1613. String id = loadParamMap.get("loginId");//登陆人关联id
  1614. ORGTemplate org = new ORGTemplate();
  1615. StringBuffer sql = new StringBuffer();
  1616. StringBuffer json = new StringBuffer();
  1617. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1618. sql.append("WITH TA AS(SELECT *,(SELECT COUNT(1) FROM EMC_AM_COMMON_MAN M WHERE M.IS_DEL='0' AND M.GROUP_ID = CP.GROUP_ID) NUM \n");
  1619. /********群组*******/
  1620. sql.append("FROM EMC_AM_COMMON_MAN_GROUP CP WHERE CP.LOGIN_ID = ? AND CP.IS_DEL ='0' ) \n");
  1621. sql.append("SELECT TA.GROUP_ID \"id\",TA.GROUP_NAME||'('||TA.NUM||')' \"name\", '0' \"parentId\", \n");
  1622. sql.append("'/nwyj/scripts/qui/sample/tree/layers.gif' \"icon\", \n");
  1623. sql.append("TA.GROUP_NAME \"realName\", \n");
  1624. sql.append("'commGroup' \"leafType\", \n");
  1625. sql.append("'false' \"nocheck\", \n");
  1626. sql.append("TA.NUM \"childNums\"\n");
  1627. sql.append("FROM TA \n");
  1628. /********虚拟人员*******/
  1629. sql.append("UNION ALL \n");
  1630. sql.append("SELECT 'virtual'||GROUP_ID,'添加常用联系人组', GROUP_ID, \n");
  1631. sql.append("'/nwyj/scripts/qui/libs/icons/add.png' \"icon\", \n");
  1632. sql.append("TA.GROUP_NAME \"realName\", \n");
  1633. sql.append("'virtual' \"leafType\", \n");
  1634. sql.append("'true' \"nocheck\", \n");
  1635. sql.append("'' \"childNums\" \n");
  1636. sql.append("FROM TA \n");
  1637. sql.append("UNION ALL \n");
  1638. /********人员*******/
  1639. sql.append("SELECT A.MAN_ID,U.REAL_NAME,A.GROUP_ID, \n");
  1640. sql.append("DECODE(U.MAN_TYPE,'INNER','/nwyj/scripts/qui/libs/icons/user-black.png','/nwyj/scripts/qui/libs/icons/user_group.gif') \"icon\", \n");
  1641. sql.append("U.REAL_NAME \"realName\", \n");
  1642. sql.append("'commmMan' \"leafType\", \n");
  1643. sql.append("'true' \"nocheck\", \n");
  1644. sql.append("'' \"childNums\" \n");
  1645. sql.append("FROM EMC_AM_COMMON_MAN A,V_EMC_COMMON_MAN U WHERE A.MAN_ID=U.USER_ID AND GROUP_ID IN (SELECT GROUP_ID FROM TA ) AND A.IS_DEL='0' \n");
  1646. try {
  1647. list = org.query(sql.toString(), id);
  1648. } catch (SQLException e) {
  1649. e.printStackTrace();
  1650. }
  1651. json.append("{\"treeNodes\":[");
  1652. //处理list
  1653. for(int i= 0 ;i<list.size();i++){
  1654. Map<String,String> map = list.get(i);
  1655. Map<String,String> new_map = map;
  1656. if(("virtual"+map.get("parentId")).equals(map.get("id"))){
  1657. String orgGroupId = map.get("parentId");
  1658. String orgName = map.get("name");
  1659. new_map.put("font", "{\"color\":\"gray\"}");
  1660. new_map.put("click", "addCommonOrg('"+orgGroupId+"','"+orgName+"');");
  1661. }
  1662. list.set(i,new_map);
  1663. }
  1664. json.append(org.listToString(list));
  1665. json.append("]}");
  1666. return json.toString().replace("\"{", "{").replace("}\"", "}");
  1667. }
  1668. public String loadCommonLinkmanGroupInfo2(Map<String, String> loadParamMap) {
  1669. String corp_id = loadParamMap.get("corp_id");
  1670. String id = loadParamMap.get("loginId");//登陆人关联id
  1671. ORGTemplate org = new ORGTemplate();
  1672. StringBuffer sql = new StringBuffer();
  1673. StringBuffer json = new StringBuffer();
  1674. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1675. sql.append("WITH TA AS(SELECT *,(SELECT COUNT(1) FROM EMC_AM_COMMON_MAN M WHERE M.IS_DEL='0' AND M.GROUP_ID = CP.GROUP_ID) NUM \n");
  1676. /********群组*******/
  1677. sql.append("FROM EMC_AM_COMMON_MAN_GROUP CP WHERE CP.LOGIN_ID = ? AND CP.IS_DEL ='0' ) \n");
  1678. sql.append("SELECT TA.GROUP_ID \"id\",TA.GROUP_NAME||'('||TA.NUM||')' \"name\", '0' \"parentId\", \n");
  1679. sql.append("'/nwyj/scripts/qui/sample/tree/layers.gif' \"icon\", \n");
  1680. sql.append("TA.GROUP_NAME \"realName\", \n");
  1681. sql.append("'commGroup' \"leafType\", \n");
  1682. sql.append("'false' \"nocheck\", \n");
  1683. sql.append("TA.NUM \"childNums\"\n");
  1684. sql.append("FROM TA \n");
  1685. /*********固定群组**********/
  1686. //指挥中心
  1687. sql.append("UNION ALL \n");
  1688. sql.append("SELECT 'zhzx' \"id\",'默认应急指挥中心' \"name\", '0' \"parentId\", \n");
  1689. sql.append("'/nwyj/scripts/qui/sample/tree/layers.gif' \"icon\", \n");
  1690. sql.append("'默认应急指挥中心' \"realName\", \n");
  1691. sql.append("'commGroup' \"leafType\", \n");
  1692. sql.append("'false' \"nocheck\", \n");
  1693. sql.append("'' \"childNums\"\n");
  1694. sql.append("FROM EMC_AM_COMMON_MAN_GROUP where fd_objectid = 'zhzx' \n");
  1695. //应急办
  1696. sql.append("UNION ALL \n");
  1697. sql.append("SELECT 'zhyjb' \"id\",'默认应急办' \"name\", '0' \"parentId\", \n");
  1698. sql.append("'/nwyj/scripts/qui/sample/tree/layers.gif' \"icon\", \n");
  1699. sql.append("'默认应急办' \"realName\", \n");
  1700. sql.append("'commGroup' \"leafType\", \n");
  1701. sql.append("'false' \"nocheck\", \n");
  1702. sql.append("'' \"childNums\"\n");
  1703. sql.append("FROM EMC_AM_COMMON_MAN_GROUP where fd_objectid = 'zhyjb' \n");
  1704. /********添加按钮*******/
  1705. sql.append("UNION ALL \n");
  1706. sql.append("SELECT 'virtual'||GROUP_ID,'添加常用联系人组', GROUP_ID, \n");
  1707. sql.append("'/nwyj/scripts/qui/libs/icons/add.png' \"icon\", \n");
  1708. sql.append("TA.GROUP_NAME \"realName\", \n");
  1709. sql.append("'virtual' \"leafType\", \n");
  1710. sql.append("'true' \"nocheck\", \n");
  1711. sql.append("'' \"childNums\" \n");
  1712. sql.append("FROM TA \n");
  1713. /********人员*******/
  1714. //应急单位人员 指挥中心
  1715. sql.append("UNION ALL \n");
  1716. sql.append("SELECT L.FD_OBJECTID,L.INLINK_NAME, 'zhzx', \n");
  1717. sql.append("'/nwyj/scripts/qui/libs/icons/user-black.png' \"icon\", \n");
  1718. sql.append("L.INLINK_NAME \"realName\", \n");
  1719. sql.append("'commmMan' \"leafType\", \n");
  1720. sql.append("'true' \"nocheck\", \n");
  1721. sql.append("'' \"childNums\" \n");
  1722. sql.append("FROM EMC_DEPARTMENT_IN D, EMC_AM_ORG_INLINK L WHERE D.IS_DEL='0' AND L.IS_DEL='0' AND D.ORG_TYPE = 'ZHZX' AND L.VIRTUAL_ORG_ID = D.FD_OBJECTID AND D.CORP_ID = '"+corp_id+"' \n");
  1723. //应急办
  1724. sql.append("UNION ALL \n");
  1725. sql.append("SELECT L.FD_OBJECTID,L.INLINK_NAME, 'zhyjb', \n");
  1726. sql.append("'/nwyj/scripts/qui/libs/icons/user-black.png' \"icon\", \n");
  1727. sql.append("L.INLINK_NAME \"realName\", \n");
  1728. sql.append("'commmMan' \"leafType\", \n");
  1729. sql.append("'true' \"nocheck\", \n");
  1730. sql.append("'' \"childNums\" \n");
  1731. sql.append("FROM EMC_DEPARTMENT_IN D, EMC_AM_ORG_INLINK L WHERE D.IS_DEL='0' AND L.IS_DEL='0' AND D.ORG_TYPE = 'ZHZXYJB' AND L.VIRTUAL_ORG_ID = D.FD_OBJECTID AND D.CORP_ID = '"+corp_id+"' \n");
  1732. //联系人
  1733. sql.append("UNION ALL \n");
  1734. sql.append("SELECT A.MAN_ID,U.REAL_NAME,A.GROUP_ID, \n");
  1735. sql.append("DECODE(U.MAN_TYPE,'INNER','/nwyj/scripts/qui/libs/icons/user-black.png','/nwyj/scripts/qui/libs/icons/user_group.gif') \"icon\", \n");
  1736. sql.append("U.REAL_NAME \"realName\", \n");
  1737. sql.append("'commmMan' \"leafType\", \n");
  1738. sql.append("'true' \"nocheck\", \n");
  1739. sql.append("'' \"childNums\" \n");
  1740. sql.append("FROM EMC_AM_COMMON_MAN A,V_EMC_COMMON_MAN U WHERE A.MAN_ID=U.USER_ID AND GROUP_ID IN (SELECT GROUP_ID FROM TA ) AND A.IS_DEL='0' \n");
  1741. try {
  1742. list = org.query(sql.toString(), id);
  1743. } catch (SQLException e) {
  1744. e.printStackTrace();
  1745. }
  1746. json.append("{\"treeNodes\":[");
  1747. //处理list
  1748. for(int i= 0 ;i<list.size();i++){
  1749. Map<String,String> map = list.get(i);
  1750. Map<String,String> new_map = map;
  1751. if(("virtual"+map.get("parentId")).equals(map.get("id"))){
  1752. String orgGroupId = map.get("parentId");
  1753. String orgName = map.get("name");
  1754. new_map.put("font", "{\"color\":\"gray\"}");
  1755. new_map.put("click", "addCommonOrg('"+orgGroupId+"','"+orgName+"');");
  1756. }
  1757. list.set(i,new_map);
  1758. }
  1759. json.append(org.listToString(list));
  1760. json.append("]}");
  1761. return json.toString().replace("\"{", "{").replace("}\"", "}");
  1762. }
  1763. public String addCommonMan(Map<String, String> addCommonManMap) {
  1764. StringBuffer result=new StringBuffer();
  1765. String addManIds = addCommonManMap.get("addManIds");
  1766. String destGroupId = addCommonManMap.get("destGroupId");
  1767. if ("".equals(addManIds) || "".equals(addManIds)) {
  1768. return result.toString();
  1769. }
  1770. StringBuffer sql = new StringBuffer();
  1771. sql.append("MERGE INTO \n");
  1772. sql.append("EMC_AM_COMMON_MAN P1 \n");
  1773. sql.append("USING \n");
  1774. sql.append("(SELECT USER_ID,? GROUP_ID, MAN_TYPE FROM V_EMC_COMMON_MAN A \n");
  1775. sql.append("WHERE A.USER_ID IN ('_?my?_')) P2 \n");
  1776. sql.append("ON P1.MAN_ID = P2.USER_ID AND P1.GROUP_ID = P2.GROUP_ID AND P1.IS_DEL='0' AND P1.MAN_TYPE= P2.MAN_TYPE \n");
  1777. sql.append("WHEN NOT MATCHED THEN \n");
  1778. sql.append("INSERT (FD_OBJECTID,MAN_ID,GROUP_ID, MAN_TYPE, IS_DEL, UPDATEDATE) \n");
  1779. sql.append("VALUES( SYS_GUID() ,P2.USER_ID ,P2.GROUP_ID, P2.MAN_TYPE,'0', GETDATE()) \n");
  1780. String updateSql = sql.toString();
  1781. if(addManIds.contains(",")){
  1782. addManIds=addManIds.replace(",","','");
  1783. }
  1784. updateSql = updateSql.replaceFirst("\\_\\?my\\?\\_", addManIds);
  1785. log.info(updateSql);
  1786. ORGTemplate org = new ORGTemplate();
  1787. int excute = 0;
  1788. try {
  1789. excute = org.update(updateSql, destGroupId);
  1790. } catch (SQLException e) {
  1791. e.printStackTrace();
  1792. }
  1793. return String.valueOf(excute);
  1794. }
  1795. public String queryCommonLinkmanGroupInfo(Map<String, String> queryParamMap) {
  1796. String id = queryParamMap.get("loginId");//登陆人关联id
  1797. ORGTemplate org = new ORGTemplate();
  1798. StringBuffer sql = new StringBuffer();
  1799. StringBuffer json = new StringBuffer();
  1800. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1801. sql.append("WITH TA AS(SELECT *,(SELECT COUNT(1) FROM EMC_AM_COMMON_MAN M WHERE M.IS_DEL='0' AND M.GROUP_ID = CP.GROUP_ID) NUM \n");
  1802. /********群组*******/
  1803. sql.append("FROM EMC_AM_COMMON_MAN_GROUP CP WHERE CP.LOGIN_ID = ? AND CP.IS_DEL ='0' ) \n");
  1804. sql.append("SELECT TA.GROUP_ID \"id\",TA.GROUP_NAME||'('||TA.NUM||')' \"name\", '0' \"parentId\", \n");
  1805. sql.append("'/nwyj/scripts/qui/sample/tree/layers.gif' \"icon\", \n");
  1806. sql.append("TA.GROUP_NAME \"realName\", \n");
  1807. sql.append("'commGroup' \"leafType\", \n");
  1808. sql.append("TA.NUM \"childNums\"\n");
  1809. sql.append("FROM TA \n");
  1810. /********虚拟人员*******/
  1811. sql.append("UNION ALL \n");
  1812. sql.append("SELECT 'virtual'||GROUP_ID,'添加常用联系人组', GROUP_ID, \n");
  1813. sql.append("'/nwyj/scripts/qui/libs/icons/add.png' \"icon\", \n");
  1814. sql.append("TA.GROUP_NAME \"realName\", \n");
  1815. sql.append("'virtual' \"leafType\", \n");
  1816. sql.append("'' \"childNums\" \n");
  1817. sql.append("FROM TA \n");
  1818. sql.append("UNION ALL \n");
  1819. /********人员*******/
  1820. sql.append("SELECT A.MAN_ID,U.REAL_NAME,A.GROUP_ID, \n");
  1821. sql.append("DECODE(U.MAN_TYPE,'INNER','/nwyj/scripts/qui/libs/icons/user-black.png','/nwyj/scripts/qui/libs/icons/user_group.gif') \"icon\", \n");
  1822. sql.append("U.REAL_NAME \"realName\", \n");
  1823. sql.append("'commmMan' \"leafType\", \n");
  1824. sql.append("'' \"childNums\" \n");
  1825. sql.append("FROM EMC_AM_COMMON_MAN A,V_EMC_COMMON_MAN U WHERE A.MAN_ID=U.USER_ID AND GROUP_ID IN (SELECT GROUP_ID FROM TA ) AND A.IS_DEL='0' \n");
  1826. try {
  1827. list = org.query(sql.toString(), id);
  1828. } catch (SQLException e) {
  1829. e.printStackTrace();
  1830. }
  1831. json.append("{\"treeNodes\":[");
  1832. //处理list
  1833. for(int i= 0 ;i<list.size();i++){
  1834. Map<String,String> map = list.get(i);
  1835. Map<String,String> new_map = map;
  1836. if(("virtual"+map.get("parentId")).equals(map.get("id"))){
  1837. String orgGroupId = map.get("parentId");
  1838. new_map.put("font", "{\"color\":\"gray\"}");
  1839. new_map.put("click", "addCommonOrg('"+orgGroupId+"');");
  1840. }
  1841. list.set(i,new_map);
  1842. }
  1843. json.append(org.listToString(list));
  1844. json.append("]}");
  1845. return json.toString().replace("\"{", "{").replace("}\"", "}");
  1846. }
  1847. public String test(Map<String, String> queryParamMap) {
  1848. String id = queryParamMap.get("id");//登陆人关联id
  1849. ORGTemplate org = new ORGTemplate();
  1850. StringBuffer sql = new StringBuffer();
  1851. StringBuffer json = new StringBuffer();
  1852. List<Map<String,String>> list = new ArrayList<Map<String,String>>();
  1853. sql.append("select dept_id \"id\", dept_name \"name\",parent_id \"parentId\" from sys_department\n");
  1854. try {
  1855. list = org.query(sql.toString());
  1856. } catch (SQLException e) {
  1857. // TODO Auto-generated catch block
  1858. e.printStackTrace();
  1859. }
  1860. json.append("{\"treeNodes\":[");
  1861. json.append(org.listToString(list));
  1862. json.append("]}");
  1863. return json.toString();
  1864. }
  1865. public String getMoveUp(String id,String sortNo,String parentId){
  1866. SysModel sysmodel = ModelFactory.getSysmodel();
  1867. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1868. int sqlExecute = 0;
  1869. String result = "";
  1870. //判定sortNo是否为空
  1871. if("".equals(sortNo) || sortNo==null ){
  1872. return result;
  1873. }
  1874. StringBuffer sqlmoveUp = new StringBuffer();
  1875. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '0' where SORT = '"+sortNo+"' and PARENT_ID='"+parentId+"';");
  1876. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '"+sortNo+"' where SORT = '"+(Integer.parseInt(sortNo)-1)+"' and PARENT_ID='"+parentId+"';");
  1877. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '"+(Integer.parseInt(sortNo)-1)+"' where SORT = '0' and PARENT_ID='"+parentId+"';");
  1878. log.info(sqlmoveUp);
  1879. try {
  1880. sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
  1881. //判定是否删除数据成功
  1882. if(sqlExecute==1){
  1883. result = "\""+id+"\"";
  1884. // result = "1";
  1885. }
  1886. } catch (PersistenceException e) {
  1887. e.printStackTrace();
  1888. }
  1889. return result;
  1890. }
  1891. public String getMoveDown(String id,String sortNo,String parentId){
  1892. SysModel sysmodel = ModelFactory.getSysmodel();
  1893. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  1894. int sqlExecute = 0;
  1895. String result = "";
  1896. //判定sortNo是否为空
  1897. if("".equals(sortNo) || sortNo==null ){
  1898. return result;
  1899. }
  1900. StringBuffer sqlmoveUp = new StringBuffer();
  1901. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '0' where SORT = '"+sortNo+"' and PARENT_ID='"+parentId+"';");
  1902. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '"+sortNo+"' where SORT = '"+(Integer.parseInt(sortNo)+1)+"' and PARENT_ID='"+parentId+"';");
  1903. sqlmoveUp.append("update SYS_DEPARTMENT set SORT = '"+(Integer.parseInt(sortNo)+1)+"' where SORT = '0' and PARENT_ID='"+parentId+"';");
  1904. log.info(sqlmoveUp);
  1905. try {
  1906. sqlExecute = persistence.executeUpdateSQL(99, sqlmoveUp.toString());
  1907. //判定是否删除数据成功
  1908. if(sqlExecute==1){
  1909. result = "\""+id+"\"";
  1910. // result = "1";
  1911. }
  1912. } catch (PersistenceException e) {
  1913. e.printStackTrace();
  1914. }
  1915. return result;
  1916. }
  1917. public Msg getDepartmentUilt(String id,String sortNo, String corpName, String corpId, String type) throws ClassNotFoundException{
  1918. Msg m=new Msg();
  1919. String []arr=id.split(",");
  1920. String []arr1=sortNo.split(",");
  1921. String []arr2=corpName.split(",");
  1922. String []arr3=corpId.split(",");
  1923. String []arr4=type.split(",");
  1924. String sql="UPDATE SYS_DEPARTMENT SET SORT=?,CORP_NAME=?,CORP_ID=?,DEPT_TYPE=? where fd_objectid=?;"
  1925. + "UPDATE SYS_DEPARTMENT SET CORP_NAME='"+corpName+"',CORP_ID='"+corpId+"' where fd_objectid in (select fd_objectid from"
  1926. + " sys_department WHERE DEPT_ID!='"+id+"' start with dept_id='"+id+"' connect by prior dept_id = parent_id);";
  1927. Connection conn = null;
  1928. PreparedStatement st = null;
  1929. int num=0;
  1930. DbConnection db = new DbConnection();
  1931. try {
  1932. conn = db.getConnection();
  1933. conn.setAutoCommit(false);
  1934. st = conn.prepareStatement(sql);
  1935. for(int i=0;i<arr.length;i++){
  1936. st.setString(1, arr1[i]);
  1937. st.setString(2, arr2[i]);
  1938. st.setString(3, arr3[i]);
  1939. st.setString(4, arr4[i]);
  1940. st.setString(5, arr[i]);
  1941. st.executeUpdate();
  1942. num++;
  1943. }
  1944. if(num==arr.length){
  1945. m.setSucsess(new Boolean(true).toString());
  1946. m.setInfo(Parameter.OPER_SUCSESS);
  1947. conn.commit();
  1948. return m;
  1949. }else{
  1950. m.setSucsess(new Boolean(false).toString());
  1951. m.setInfo(Parameter.OPER_FAILURE);
  1952. conn.rollback();
  1953. return m;
  1954. }
  1955. }catch (SQLException e) {
  1956. this.log.error(e.getMessage(), e);
  1957. throw new ClassNotFoundException("DAO Layou: 发布消息"
  1958. + sql, e);
  1959. } finally {
  1960. db.close(st);
  1961. db.close(conn);
  1962. }
  1963. }
  1964. /******************2016-03-07谢仲铠 批量修改突发事件类型*************************/
  1965. public Msg getEmergencyTypeUilt(String id,String event_number, String event_type_name, String lead_department) throws ClassNotFoundException{
  1966. Msg m=new Msg();
  1967. String []arr=id.split(",");
  1968. String []arr1=event_number.split(",");
  1969. String []arr2=event_type_name.split(",");
  1970. String []arr3=lead_department.split(",");
  1971. String sql="UPDATE ECM_EM_EMERGENCY_TYPE SET EVENT_NUMBER=?,EVENT_TYPE_NAME=?,LEAD_DEPARTMENT=? where fd_objectid=?;";
  1972. Connection conn = null;
  1973. PreparedStatement st = null;
  1974. int num=0;
  1975. DbConnection db = new DbConnection();
  1976. try {
  1977. conn = db.getConnection();
  1978. conn.setAutoCommit(false);
  1979. st = conn.prepareStatement(sql);
  1980. for(int i=0;i<arr.length;i++){
  1981. st.setString(1, arr1[i]);
  1982. st.setString(2, arr2[i]);
  1983. st.setString(3, arr3[i]);
  1984. st.setString(4, arr[i]);
  1985. st.executeUpdate();
  1986. num++;
  1987. }
  1988. if(num==arr.length){
  1989. m.setSucsess(new Boolean(true).toString());
  1990. m.setInfo(Parameter.OPER_SUCSESS);
  1991. conn.commit();
  1992. return m;
  1993. }else{
  1994. m.setSucsess(new Boolean(false).toString());
  1995. m.setInfo(Parameter.OPER_FAILURE);
  1996. conn.rollback();
  1997. return m;
  1998. }
  1999. }catch (SQLException e) {
  2000. this.log.error(e.getMessage(), e);
  2001. throw new ClassNotFoundException("DAO Layou: 发布消息"
  2002. + sql, e);
  2003. } finally {
  2004. db.close(st);
  2005. db.close(conn);
  2006. }
  2007. }
  2008. /**********************2016-09-12 唐群胜新增 修改内部人员电话、邮箱****************************/
  2009. public Msg getMEupdate(String id,String mobile, String email) throws ClassNotFoundException{
  2010. Msg m=new Msg();
  2011. String []arr=id.split(",");
  2012. String []arr1=mobile.split(",");
  2013. String []arr2=email.split(",");
  2014. String sql="UPDATE SYS_USER_INFO SET MOBILE=?,EMAIL=? where fd_objectid=?";
  2015. Connection conn = null;
  2016. PreparedStatement st = null;
  2017. int num=0;
  2018. DbConnection db = new DbConnection();
  2019. try {
  2020. conn = db.getConnection();
  2021. conn.setAutoCommit(false);
  2022. st = conn.prepareStatement(sql);
  2023. for(int i=0;i<arr.length;i++){
  2024. st.setString(1, arr1[i]);
  2025. st.setString(2, arr2[i]);
  2026. st.setString(3, arr[i]);
  2027. st.executeUpdate();
  2028. num++;
  2029. }
  2030. if(num==arr.length){
  2031. m.setSucsess(new Boolean(true).toString());
  2032. m.setInfo(Parameter.OPER_SUCSESS);
  2033. conn.commit();
  2034. return m;
  2035. }else{
  2036. m.setSucsess(new Boolean(false).toString());
  2037. m.setInfo(Parameter.OPER_FAILURE);
  2038. conn.rollback();
  2039. return m;
  2040. }
  2041. }catch (SQLException e) {
  2042. this.log.error(e.getMessage(), e);
  2043. throw new ClassNotFoundException("DAO Layou: 发布消息"
  2044. + sql, e);
  2045. } finally {
  2046. db.close(st);
  2047. db.close(conn);
  2048. }
  2049. }
  2050. /**********************2016-09-13 唐群胜 机构类型****************************/
  2051. public String getOrgType(String id,String update){
  2052. log.info("update====="+update);
  2053. SysModel sysmodel = ModelFactory.getSysmodel();
  2054. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  2055. String sql="";
  2056. if(update.equals("updatetype")){
  2057. sql="select ORG_TYPE from V_DEPARTMENT where IS_DEL ='0' and ORG_ID !='"+id+"' and (ORG_TYPE = 'ZHZX' OR ORG_TYPE = 'ZHZXYJB') start with ORG_ID ='"+id+"' connect by prior PARENT_ID = ORG_ID";
  2058. }else{
  2059. sql="select ORG_TYPE from V_DEPARTMENT where IS_DEL ='0' and (ORG_TYPE = 'ZHZX' OR ORG_TYPE = 'ZHZXYJB') start with ORG_ID ='"+id+"' connect by prior PARENT_ID = ORG_ID";
  2060. }
  2061. log.info("sql====="+sql);
  2062. try {
  2063. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  2064. if(tempList==null||tempList.size()==0){
  2065. return "";
  2066. }else if(tempList.size()==1){
  2067. String name=tempList.get(0)[0];
  2068. log.info("name===="+name);
  2069. return name;
  2070. }else{
  2071. return "ZHZXZHZXYJB";
  2072. }
  2073. } catch (PersistenceException e) {
  2074. e.printStackTrace();
  2075. return "";
  2076. }
  2077. }
  2078. /*************************************2017-03-14 唐群胜 机构简称*********************************************/
  2079. public String getOrgAbbreviation(String id,String level) {
  2080. SysModel sysmodel = ModelFactory.getSysmodel();
  2081. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  2082. String sql = "";
  2083. if(level.equals("1")){
  2084. sql ="select NETWORK_NAME from \"NWYJ\".\"DEPARTMENT_ABBR\" where FD_OBJECTID ='"+id+"' ";
  2085. }else if(level.equals("2")){
  2086. sql ="select PROVINCE_NAME from \"NWYJ\".\"DEPARTMENT_ABBR\" where FD_OBJECTID ='"+id+"' ";
  2087. }else if(level.equals("3")){
  2088. sql ="select PREFECTURE_NAME from \"NWYJ\".\"DEPARTMENT_ABBR\" where FD_OBJECTID ='"+id+"' ";
  2089. }else if(level.equals("4")){
  2090. sql ="select COUNTY_NAME from \"NWYJ\".\"DEPARTMENT_ABBR\" where FD_OBJECTID ='"+id+"' ";
  2091. }else{
  2092. sql ="select FULL_NAME from \"NWYJ\".\"DEPARTMENT_ABBR\" where FD_OBJECTID ='"+id+"' ";
  2093. }
  2094. log.info("sql====="+sql);
  2095. try{
  2096. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  2097. log.info(tempList.size());
  2098. if(tempList==null||tempList.size()==0){
  2099. String sql2 ="select ORG_NAME from \"NWYJ\".\"V_DEPARTMENT\" where FD_OBJECTID ='"+id+"' ";
  2100. List<String[]>tempList2= persistence.getSearchResult(99, sql2.toString());
  2101. if(tempList2==null||tempList2.size()==0){
  2102. return "";
  2103. }else{
  2104. return tempList2.get(0)[0];
  2105. }
  2106. }else if(tempList.size()==1){
  2107. String name=tempList.get(0)[0];
  2108. log.info("name===="+name);
  2109. return name;
  2110. }else{
  2111. return "";
  2112. }
  2113. }catch(Exception e){
  2114. this.log.error(e.getMessage(), e);
  2115. return "";
  2116. }
  2117. }
  2118. //人员角色表插入信息
  2119. public String getRoleupdate(String id,String role) throws ClassNotFoundException{
  2120. String result = "";
  2121. SysModel sysmodel = ModelFactory.getSysmodel();
  2122. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  2123. if(role.equals("1")){//总指挥
  2124. role="R002105430201";
  2125. }else if(role.equals("2")||role.equals("3")){//副总指挥
  2126. role="R002105430202";
  2127. }else if(role.equals("4")){//主任
  2128. role="R002105430203";
  2129. }else if(role.equals("5")||role.equals("6")){//副主任
  2130. role="R002105430204";
  2131. }else if(role.equals("7")){//成员
  2132. role="R002105430205";
  2133. }else{
  2134. role="";
  2135. }
  2136. if(!role.equals("")){
  2137. StringBuffer sql = new StringBuffer();
  2138. sql.append("--插入联系人 \n");
  2139. sql.append("INSERT INTO SYS_USER_ROLE_REL (\"FD_OBJECTID\", \"ROLE_ID\", \"USER_ID\", \"IS_DEL\", \"MOD_DATE\") \n");
  2140. sql.append(" VALUES('"+createMsgId(getMsgId())+"','"+role+"','"+id+"','0',GETDATE()); ");
  2141. try {
  2142. result =String.valueOf(persistence.executeUpdateSQL(99, sql.toString()));
  2143. } catch (PersistenceException e) {
  2144. e.printStackTrace();
  2145. }
  2146. }
  2147. return result;
  2148. }
  2149. //去重复主键
  2150. @SuppressWarnings({ "unchecked", "rawtypes" })
  2151. public List<String> getMsgId() throws ClassNotFoundException {
  2152. String sql = "SELECT FD_OBJECTID FROM SYS_USER_ROLE_REL";
  2153. Connection conn = null;
  2154. Statement stat = null;
  2155. ResultSet rs = null;
  2156. DbConnection db = new DbConnection();
  2157. try {
  2158. conn = db.getConnection();
  2159. stat = conn.createStatement();
  2160. rs = stat.executeQuery(sql);
  2161. List<String> list = new ArrayList();
  2162. while (rs.next()) {
  2163. list.add(rs.getString("FD_OBJECTID"));
  2164. }
  2165. return list;
  2166. } catch (SQLException e) {
  2167. // this.log.error(e.getMessage(), e);
  2168. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  2169. + sql, e);
  2170. } finally {
  2171. db.close(rs);
  2172. db.close(stat);
  2173. db.close(conn);
  2174. }
  2175. }
  2176. //随机生成主键
  2177. public String createMsgId(List<String> list) throws ClassNotFoundException{
  2178. long l=(long) ((Math.random()+1)*1000000000);
  2179. String msgId=l+"";
  2180. if(list.contains(msgId)){
  2181. return createMsgId(list);
  2182. }
  2183. else{
  2184. // log.info("msgid==="+msgId);
  2185. return msgId;
  2186. }
  2187. }
  2188. //开发中,未完成
  2189. public String getOrgChart(String id) {
  2190. SysModel sysmodel = ModelFactory.getSysmodel();
  2191. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  2192. JSONArray array = null;
  2193. String sql = "SELECT ORG_ID,ORG_NAME,PARENT_ID,PATH_ID,(select count(*) from EMC_AM_ORG_INLINK where is_del='0' and VIRTUAL_ORG_ID=ORG_ID) num,ORG_TYPE,DUTY_TEL,EMERGENCY_TEL FROM V_DEPARTMENT WHERE CORP_ID = '"+id+"' AND IS_DEL='0' order by path_id ";
  2194. try {
  2195. List<String[]>tempList= persistence.getSearchResult(99, sql.toString());
  2196. List<TreeJson> list = new ArrayList<TreeJson>();
  2197. log.info(tempList.size());
  2198. for(int i=0;i<tempList.size();i++){
  2199. TreeJson tree = new TreeJson();
  2200. tree.setId(tempList.get(i)[0]);
  2201. tree.setPid(tempList.get(i)[2]);
  2202. tree.setName(tempList.get(i)[0].equals(id)?tempList.get(i)[1]:tempList.get(i)[1]+"("+tempList.get(i)[4]+"人)");
  2203. tree.setOrg_type(tempList.get(i)[5]);
  2204. tree.setDuty_tel(tempList.get(i)[6]);
  2205. tree.setEmergency_tel(tempList.get(i)[7]);
  2206. list.add(tree);
  2207. }
  2208. List<TreeJson> json = TreeJson.formatTree(list);
  2209. JsonConfig config = new JsonConfig();
  2210. config.setJsonPropertyFilter(new IgnoreFieldProcessorImpl(true, new String[]{"attributes"})); // 忽略掉name属性及集合对象
  2211. array = JSONArray.fromObject(json,config);
  2212. log.info(array);
  2213. } catch (PersistenceException e) {
  2214. // TODO Auto-generated catch block
  2215. e.printStackTrace();
  2216. }
  2217. return "{\"data\": "+array+"}";
  2218. }
  2219. }