2c0f2c96ff4f1a03b873b930eb86e4f662225c2f.svn-base 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. package com.sinosoft.lz.system.department;
  2. import java.io.UnsupportedEncodingException;
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.ArrayList;
  8. import java.util.Arrays;
  9. import javax.ws.rs.POST;
  10. import javax.ws.rs.Path;
  11. import javax.ws.rs.ProduceMime;
  12. import net.sf.json.JSONObject;
  13. import org.apache.log4j.Logger;
  14. import com.formaction.Utils;
  15. import com.persistence.DbConnection;
  16. import com.persistence.service.PersistenceFactory;
  17. import com.persistence.service.SysPersistence;
  18. import com.persistence.service.exception.PersistenceException;
  19. import com.sinosoft.em.response.equipment.records.service.RespEquipmentService;
  20. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  21. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  22. /**
  23. *
  24. * 1 组织机构管理tree,通过循环查询表800,807返回json数据
  25. *
  26. */
  27. @Path("/DeptService/")
  28. public class DepartExc{
  29. private Logger log = Logger.getLogger(this.getClass());
  30. @ProduceMime("application/json")
  31. @POST
  32. @Path("/getDepartTree")
  33. public String getDepartTree(String params) {
  34. String id = Utils.getParameter("id", params) == null ? "" : Utils
  35. .getParameter("id", params);
  36. String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",
  37. params);
  38. /**
  39. * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info
  40. */
  41. String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",
  42. params);
  43. String dept = Utils.getParameter("dept", params) == null ? "" : Utils.getParameter("dept",
  44. params);
  45. log.info("id-- " + id + " -------name---" + name);
  46. SysModel sysmodel = ModelFactory.getSysmodel();
  47. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  48. StringBuffer json = new StringBuffer();
  49. StringBuffer sql = new StringBuffer();
  50. sql.append("-- 查询组织机构根节点 \n");
  51. sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n");
  52. sql.append(" from Sys_Department where 1=1 \n");
  53. if (id.equals("")) {
  54. sql.append(" and PARENT_ID='0'");
  55. } else {
  56. sql.append(" and PARENT_ID='" + id + "'");
  57. }
  58. if(!dept.equals("")){
  59. sql.append(" and dept_type='"+dept+"'");
  60. }
  61. sql.append(" ORDER BY SORT asc \n");
  62. log.info(sql.toString());
  63. try {
  64. ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
  65. String[] temp = listRoot.get(0);
  66. String deptId = temp[0];
  67. String deptName = temp[1];
  68. String objectId = temp[2];
  69. json.append("{treeNodes:[");
  70. if (listRoot.size() > 1) {
  71. if(this.hasPersonLeaf(id)&&"per".equals(type)){
  72. json.append(this.getPersonJson(id)); }
  73. json.append(this.getDeptChlidrenJson(id, type));
  74. } else {
  75. json.append("{");
  76. json.append(" id:'" + deptId + "',parentId:'0', ");
  77. json.append(" classId:'800',objectId:'" + objectId + "', ");
  78. json.append(" name:'" + deptName + "', ");
  79. json.append(" type:'unit',menuType:'nonLeafMenu',");
  80. json.append(" icon:'/nwyj/scripts/qui/libs/icons/home.gif'");
  81. json.append("},");
  82. /** 加载人员信息 */
  83. if (this.hasPersonLeaf(deptId) && "per".equals(type)) {
  84. json.append(this.getPersonJson(deptId));
  85. }
  86. json.append(this.getDeptChlidrenJson(deptId, type));
  87. }
  88. if (json.lastIndexOf(",") > -1) {
  89. json.deleteCharAt(json.lastIndexOf(","));
  90. }
  91. json.append("]}");
  92. } catch (PersistenceException e) {
  93. log.error("查询组织机构错误", e);
  94. }
  95. log.info(JSONObject.fromObject(json.toString()).toString());
  96. return JSONObject.fromObject(json.toString()).toString();
  97. }
  98. @ProduceMime("application/json")
  99. @POST
  100. @Path("/getCompanyTree")
  101. public String getCompanyTree(String params) {
  102. String id = Utils.getParameter("id", params) == null ? "" : Utils
  103. .getParameter("id", params);
  104. String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",
  105. params);
  106. /**
  107. * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info
  108. */
  109. String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",
  110. params);
  111. log.info("id-- " + id + " -------name---" + name);
  112. SysModel sysmodel = ModelFactory.getSysmodel();
  113. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  114. StringBuffer json = new StringBuffer();
  115. StringBuffer sql = new StringBuffer();
  116. sql.append("-- 查询组织机构根节点 \n");
  117. sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n");
  118. sql.append(" from Sys_Department where 1=1 \n");
  119. // sql.append(" from Sys_Department where sort>=11 and sort<=29 and fd_objectid!='03E6F6D693F94335B242739D5D2A53E0' and fd_objectid!='0C1FE77E3C314D24B3D15FE38A3250AB' and fd_objectid!='106E3F1BC3914EA5B8E69E6EED7E4F0A' \n");
  120. if (id.equals("")) {
  121. sql.append(" and PARENT_ID='0'");
  122. } else {
  123. sql.append(" and PARENT_ID='" + id + "'");
  124. }
  125. sql.append(" ORDER BY SORT asc \n");
  126. log.info("*********"+sql.toString());
  127. try {
  128. ArrayList<String[]> listRoot = persistence.getSearchResult(99, sql.toString());
  129. String[] temp = listRoot.get(0);
  130. String deptId = temp[0];
  131. String deptName = temp[1];
  132. String objectId = temp[2];
  133. json.append("{fromList:[");
  134. if (listRoot.size() > 1) {
  135. if(this.hasPersonLeaf(id)&&"per".equals(type)){
  136. json.append(this.getPersonJson(id)); }
  137. json.append(this.getCompanyChlidrenJson(id, type));
  138. } else {
  139. json.append("{");
  140. json.append(" value:'" + deptId + "',parentId:'0', ");
  141. json.append(" key:'" + deptName + "'");
  142. json.append("},");
  143. json.append(this.getCompanyChlidrenJson(deptId, type));
  144. }
  145. if (json.lastIndexOf(",") > -1) {
  146. json.deleteCharAt(json.lastIndexOf(","));
  147. }
  148. json.append("],'toList':[]}");
  149. } catch (PersistenceException e) {
  150. log.error("查询组织机构错误", e);
  151. }
  152. log.info(JSONObject.fromObject(json.toString()).toString());
  153. return JSONObject.fromObject(json.toString()).toString();
  154. }
  155. @ProduceMime("application/json")
  156. @POST
  157. @Path("/getCompanyTreeTeamAndEquip")
  158. public String getCompanyTreeTeamAndEquip(String params) {//队伍需求(之前的------备份--20160815)
  159. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
  160. String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",params);
  161. String needUnit = Utils.getParameter("deptId_self", params) == null ? "" : Utils.getParameter("deptId_self", params);//需求单位
  162. /**
  163. * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info
  164. */
  165. String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params);
  166. log.info("id-- " + id + " -------name---" + name);
  167. SysModel sysmodel = ModelFactory.getSysmodel();
  168. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  169. StringBuffer json = new StringBuffer();
  170. StringBuffer sql = new StringBuffer();
  171. String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1"+
  172. " and PARENT_ID='"+id+"' and dept_type='1' and dept_level=3 and DEPT_ID != '"+needUnit+"' ORDER BY SORT asc ";
  173. ArrayList<String[]> listRoot;
  174. try {
  175. json.append("{'fromList':[ ");
  176. listRoot = persistence.getSearchResult(99, sql1);
  177. if(listRoot!=null&&listRoot.size()>0){
  178. for(int i=0;i<listRoot.size();i++){
  179. String[]arr=listRoot.get(i);
  180. json.append("{ ");
  181. json.append(" value:'" + arr[0] + "', parentId:'" + id + "',");
  182. json.append(" key:'" + arr[1] + "',");
  183. json.append("}, ");
  184. }
  185. }
  186. } catch (PersistenceException e) {
  187. // TODO Auto-generated catch block
  188. e.printStackTrace();
  189. }
  190. if (json.lastIndexOf(",") > -1) {
  191. json.deleteCharAt(json.lastIndexOf(","));
  192. }
  193. json.append("],'toList':[]}");
  194. log.info(JSONObject.fromObject(json.toString()).toString());
  195. return JSONObject.fromObject(json.toString()).toString();
  196. }
  197. @ProduceMime("application/json")
  198. @POST
  199. @Path("/getEquipType")
  200. public String getEquipType(String params) {//装备需求
  201. String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID
  202. StringBuffer sb = new StringBuffer();
  203. RespEquipmentService res = new RespEquipmentService();
  204. sb.append("{\"equipTypes\":[");//单选下拉框
  205. /**
  206. *需求信息表--ID:383--表名:ECM_EM_EQUIPMENT_DEMAND_DETAIL 该表中EQUIPMENT_NAME字段的值代表装备类型
  207. *(0:发电车--ID:265--表名:EMC_AM_GENERATOR_CAR--状态:IS_USED='1')
  208. *(1:发电机--ID:266--表名:EMC_AM_GENERATOR--状态:USED_STAT='1')
  209. *(2:移动餐车--ID:270--表名:EMC_AM_DINING_CAR--状态:IS_USED='1')
  210. *(3:指挥通信车--ID:269--表名:EMC_AM_EMERGENCY_COMMAND_CAR--状态:USED_STAT='1')
  211. *
  212. */
  213. //1 通过需求id382在表ECM_EM_EQUIPMENT_DEMAND_DETAIL中查出需求下的各种装备类型(可能不是一个)
  214. String equipTypes = res.getEquipTypes(fdId_382);
  215. int n = equipTypes.split(",").length;//装备类型的个数
  216. for(int i=0;i<n;i++){
  217. if("0".equals(equipTypes.split(",")[i])){
  218. sb.append("{\"equipType\":\"发电车\"},");
  219. }else if("1".equals(equipTypes.split(",")[i])){
  220. sb.append("{\"equipType\":\"发电机\"},");
  221. }
  222. }
  223. if (sb.lastIndexOf(",") > -1) {
  224. sb.deleteCharAt(sb.lastIndexOf(","));
  225. }
  226. sb.append("]}");
  227. System.out.println("**********"+sb.toString());
  228. // log.info(JSONObject.fromObject(sb.toString()).toString());
  229. return sb.toString();
  230. }
  231. /*@ProduceMime("application/json")
  232. @POST
  233. @Path("/getCompanyTreeTeamAndEquip")
  234. public String getCompanyTreeTeamAndEquip(String params) {//队伍需求
  235. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);
  236. String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",params);
  237. String needUnit = Utils.getParameter("deptId_self", params) == null ? "" : Utils.getParameter("deptId_self", params);//需求单位
  238. String recipDept = Utils.getParameter("deptid", params) == null ? "" : Utils.getParameter("deptid",params);//需求申请单位
  239. String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//队伍需求ID
  240. // 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info
  241. String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params);
  242. log.info("id-- " + id + " -------name---" + name);
  243. SysModel sysmodel = ModelFactory.getSysmodel();
  244. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  245. StringBuffer json = new StringBuffer();
  246. StringBuffer sql = new StringBuffer();
  247. // String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1 and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID != '"+needUnit+"' ORDER BY SORT asc ";
  248. String sql1=" select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where 1=1 and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID != '"+recipDept+"' ORDER BY SORT asc ";
  249. ArrayList<String[]> listRoot;
  250. try {
  251. listRoot = persistence.getSearchResult(99, sql1);
  252. if(listRoot!=null&&listRoot.size()>0){
  253. // json.append("{'fromList':[ ");//双选器
  254. // json.append("{'list':[ ");//单选下拉框
  255. json.append("{'treeNodes':[ ");//多选下拉框
  256. for(int i=0;i<listRoot.size();i++){
  257. String[]arr=listRoot.get(i);
  258. json.append("{ ");
  259. json.append(" \"name\":\"" + arr[1] + "\", \"parentId\":\"" + id + "\", \"id\":\"" + arr[0] + "\"");
  260. json.append("}, ");
  261. }
  262. }
  263. } catch (PersistenceException e) {
  264. // TODO Auto-generated catch block
  265. e.printStackTrace();
  266. }
  267. if (json.lastIndexOf(",") > -1) {
  268. json.deleteCharAt(json.lastIndexOf(","));
  269. }
  270. // json.append("],'toList':[]}");
  271. json.append("]}");
  272. log.info(JSONObject.fromObject(json.toString()).toString());
  273. return JSONObject.fromObject(json.toString()).toString();
  274. }*/
  275. @ProduceMime("application/json")
  276. @POST
  277. @Path("/getCompanyTreeEquip")
  278. public String getCompanyTreeEquip(String params) {//装备需求
  279. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter("id", params);//登录人单位id
  280. String name = Utils.getParameter("name", params) == null ? "" : Utils.getParameter("name",params);//空值(“”)
  281. String recipDept = Utils.getParameter("deptid", params) == null ? "" : Utils.getParameter("deptid",params);//需求申请单位ID
  282. String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID
  283. /**
  284. * 组织机构树,需加载到人员时,传参 type='per' 注:人员表读取的sys_user_info
  285. */
  286. String type = Utils.getParameter("type", params) == null ? "" : Utils.getParameter("type",params);
  287. log.info("id-- " + id + " -------name---" + name);
  288. SysModel sysmodel = ModelFactory.getSysmodel();
  289. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  290. StringBuffer json = new StringBuffer();
  291. RespEquipmentService res = new RespEquipmentService();
  292. String sql1 = " select DEPT_ID,DEPT_NAME,FD_OBJECTID from Sys_Department where '1'='1' and PARENT_ID='"+id+"' and dept_type='1' and dept_name like'%供电%' and DEPT_ID!='"+recipDept+"' ORDER BY SORT asc ";
  293. ArrayList<String[]> listRoot;
  294. try {
  295. listRoot = persistence.getSearchResult(99, sql1);
  296. if(listRoot!=null&&listRoot.size()>0){
  297. //json.append("{'treeNodes':[ ");//多选下拉框
  298. json.append("{\"treeNodes\":[");//多选下拉框
  299. for(int i=0;i<listRoot.size();i++){
  300. String[]arr=listRoot.get(i);
  301. json.append("{");
  302. // json.append("value:'" + arr[0] + "', parentId:'" + id + "',key:'" + arr[1] + "',");//单选下拉框
  303. /**
  304. *需求信息表--ID:383--表名:ECM_EM_EQUIPMENT_DEMAND_DETAIL 该表中EQUIPMENT_NAME字段的值代表装备类型
  305. *(0:发电车--ID:265--表名:EMC_AM_GENERATOR_CAR--状态:IS_USED='1')
  306. *(1:发电机--ID:266--表名:EMC_AM_GENERATOR--状态:USED_STAT='1')
  307. *(2:移动餐车--ID:270--表名:EMC_AM_DINING_CAR--状态:IS_USED='1')
  308. *(3:指挥通信车--ID:269--表名:EMC_AM_EMERGENCY_COMMAND_CAR--状态:USED_STAT='1')
  309. */
  310. //1 先通过需求id382在表ECM_EM_EQUIPMENT_DEMAND_DETAIL中查出需求下的各种装备类型(可能不是一个)
  311. String equipTypes = res.getEquipTypes(fdId_382);
  312. //2 再通过装备类型查各装备在表中可调拨的数量
  313. String equipTypeAndCount = "";
  314. if(!"".equals(equipTypes)){
  315. String[] str = equipTypes.split(",");
  316. equipTypeAndCount = res.getEquipNumUseful(str,arr[0]);
  317. }
  318. //3 把上述装备数量拼接到下面JSON中返回前台
  319. /*json.append("id:'" + arr[0] + "', parentId:'" + id + "',name:'" + arr[1] + "--" + equipTypeAndCount + "',");//多选下拉框
  320. json.append("}, ");*/
  321. json.append("\"id\":\"" + arr[0] + "\",\"parentId\":\"" + id + "\",\"name\":\"" + arr[1] + "--" + equipTypeAndCount + "\"");//多选下拉框
  322. json.append("},");
  323. }
  324. }
  325. } catch (PersistenceException e) {
  326. // TODO Auto-generated catch block
  327. e.printStackTrace();
  328. }
  329. if (json.lastIndexOf(",") > -1) {
  330. json.deleteCharAt(json.lastIndexOf(","));
  331. }
  332. json.append("]}");
  333. log.info(JSONObject.fromObject(json.toString()).toString());
  334. return JSONObject.fromObject(json.toString()).toString();
  335. }
  336. private String getCompanyChlidrenJsonTeamAndEquip(String unitCode, String type) {
  337. SysModel sysmodel = ModelFactory.getSysmodel();
  338. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  339. StringBuffer json = new StringBuffer();
  340. StringBuffer sql = new StringBuffer();
  341. sql.append("-- 查询组织机构子节点 \n");
  342. sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n");
  343. // sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n");
  344. sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n");
  345. sql.append(" and sort>=11 and sort<=29 and fd_objectid!='03E6F6D693F94335B242739D5D2A53E0' and fd_objectid!='0C1FE77E3C314D24B3D15FE38A3250AB' and fd_objectid!='106E3F1BC3914EA5B8E69E6EED7E4F0A' \n");
  346. sql.append(" ORDER BY SORT asc \n");
  347. log.info("=="+sql);
  348. try {
  349. ArrayList<String[]> listDept = persistence.getSearchResult(99, sql.toString());
  350. int num = listDept.size();
  351. for (int i = 0; i < num; i++) {
  352. String[] temp = listDept.get(i);
  353. String deptId = temp[0];
  354. String deptName = temp[1];
  355. String objectId = temp[2];
  356. json.append("{ ");
  357. json.append(" value:'" + deptId + "', parentId:'" + unitCode + "',");
  358. json.append(" key:'" + deptName + "',");
  359. json.append("}, ");
  360. /**
  361. * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){
  362. * json.append(this.getPersonJson(deptId)); }
  363. */
  364. /*if (this.isExitLeaf(deptId)) {
  365. json.append(this.getDeptChlidrenJson(deptId, type));
  366. }*/
  367. }
  368. } catch (PersistenceException e) {
  369. log.error("查询组织机构子节点错误", e);
  370. }
  371. return json.toString();
  372. }
  373. /**
  374. * 返回部门节点json字符串
  375. *
  376. * @param unitCode
  377. * @return
  378. */
  379. private String getDeptChlidrenJson(String unitCode, String type) {
  380. SysModel sysmodel = ModelFactory.getSysmodel();
  381. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  382. StringBuffer json = new StringBuffer();
  383. StringBuffer sql = new StringBuffer();
  384. sql.append("-- 查询组织机构子节点 \n");
  385. sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n");
  386. sql.append(" from Sys_Department where parent_id='" + unitCode + "' \n");
  387. sql.append(" ORDER BY SORT asc \n");
  388. log.info("=="+sql);
  389. try {
  390. ArrayList<String[]> listDept = persistence.getSearchResult(99, sql.toString());
  391. int num = listDept.size();
  392. for (int i = 0; i < num; i++) {
  393. String[] temp = listDept.get(i);
  394. String deptId = temp[0];
  395. String deptName = temp[1];
  396. String objectId = temp[2];
  397. json.append("{ ");
  398. json.append(" id:'" + deptId + "', parentId:'" + unitCode + "',");
  399. json.append(" classId:'800',objectId:'" + objectId + "',");
  400. json.append(" name:'" + deptName + "',");
  401. json.append(" type:'unit',menuType:'nonLeafMenu',");
  402. json.append(" icon:'/nwyj/scripts/qui/libs/icons/user_group.gif'");
  403. json.append("}, ");
  404. /**
  405. * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){
  406. * json.append(this.getPersonJson(deptId)); }
  407. */
  408. /*if (this.isExitLeaf(deptId)) {
  409. json.append(this.getDeptChlidrenJson(deptId, type));
  410. }*/
  411. }
  412. } catch (PersistenceException e) {
  413. log.error("查询组织机构子节点错误", e);
  414. }
  415. return json.toString();
  416. }
  417. /**
  418. * 返回部门节点json字符串
  419. *
  420. * @param unitCode
  421. * @return
  422. */
  423. private String getCompanyChlidrenJson(String unitCode, String type) {
  424. SysModel sysmodel = ModelFactory.getSysmodel();
  425. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  426. StringBuffer json = new StringBuffer();
  427. StringBuffer sql = new StringBuffer();
  428. sql.append("-- 查询组织机构子节点 \n");
  429. sql.append(" select DEPT_ID,DEPT_NAME,FD_OBJECTID \n");
  430. sql.append(" from Sys_Department where dept_type='CORP' and parent_id='" + unitCode + "' \n");
  431. sql.append(" ORDER BY SORT asc \n");
  432. log.info("=="+sql);
  433. try {
  434. ArrayList<String[]> listDept = persistence.getSearchResult(99, sql.toString());
  435. int num = listDept.size();
  436. for (int i = 0; i < num; i++) {
  437. String[] temp = listDept.get(i);
  438. String deptId = temp[0];
  439. String deptName = temp[1];
  440. String objectId = temp[2];
  441. json.append("{ ");
  442. json.append(" value:'" + deptId + "', parentId:'" + unitCode + "',");
  443. json.append(" key:'" + deptName + "',");
  444. json.append("}, ");
  445. /**
  446. * 加载人员信息 if(this.hasPersonLeaf(deptId)&&"per".equals(type)){
  447. * json.append(this.getPersonJson(deptId)); }
  448. */
  449. /*if (this.isExitLeaf(deptId)) {
  450. json.append(this.getDeptChlidrenJson(deptId, type));
  451. }*/
  452. }
  453. } catch (PersistenceException e) {
  454. log.error("查询组织机构子节点错误", e);
  455. }
  456. return json.toString();
  457. }
  458. /**
  459. * 判断是否有子节点
  460. *
  461. * @param persistence
  462. * @param mId
  463. * @return
  464. */
  465. private boolean isExitLeaf(String unitCode) {
  466. SysModel sysmodel = ModelFactory.getSysmodel();
  467. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  468. boolean flag = false;
  469. try {
  470. String sql = " select count(dept_id) from Sys_Department where parent_ID='" + unitCode
  471. + "' ";
  472. ArrayList<String[]> list = persistence.getSearchResult(99, sql);
  473. int num = Integer.parseInt(list.get(0)[0]);
  474. if (num > 0) {
  475. flag = true;
  476. }
  477. } catch (PersistenceException e) {
  478. log.error("是否存在子节点-- ", e);
  479. }
  480. return flag;
  481. }
  482. /**
  483. * 根据部门id 查询人员 返回人员数据json
  484. *
  485. * @param deptId
  486. * @return
  487. */
  488. private String getPersonJson(String deptId) {
  489. SysModel sysmodel = ModelFactory.getSysmodel();
  490. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  491. StringBuffer json = new StringBuffer();
  492. // String sql =
  493. // "select FD_OBJECTID,PERSON_CODE,NAME ,SEX from Sys_Person where IS_DEL='0' and DEPT_ID='"+deptId+"' ORDER BY PERSON_CODE ASC ";
  494. String sql = "select FD_OBJECTID,USER_ID,DISPLAY_NAME,NAME from sys_user_info where IS_DEL='0' and UNIT_CODE='"
  495. + deptId + "' ORDER BY user_id ASC ";
  496. // log.info("=="+sql);
  497. try {
  498. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  499. int num = list.size();
  500. for (int i = 0; i < num; i++) {
  501. String[] temp = list.get(i);
  502. String objectId = temp[0];
  503. String pCode = temp[1];
  504. String name = temp[2];
  505. // String sex = temp[3]== null ? "0" : temp[3];
  506. json.append("{ ");
  507. json.append(" id:'" + pCode + "', parentId:'" + deptId + "',");
  508. json.append(" classId:'807',objectId:'" + objectId + "',");
  509. // json.append(" name:'"+name+"',nocheck:true,");
  510. json.append(" type:'per',name:'" + name + "',");
  511. json.append(" menuType:'leafMenu'");
  512. /*
  513. * if(sex.equals("0")){ json.append(
  514. * " icon:'../../../scripts/qui/libs/icons/user_female.gif'");
  515. * }else{
  516. * json.append(" icon:'../../../scripts/qui/libs/icons/user.gif'"
  517. * ); }
  518. */
  519. json.append("}, ");
  520. }
  521. } catch (PersistenceException e) {
  522. log.error("查询人员数据错误-- ", e);
  523. }
  524. return json.toString();
  525. }
  526. private boolean hasPersonLeaf(String deptId) {
  527. SysModel sysmodel = ModelFactory.getSysmodel();
  528. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  529. /*String sql = "select count(FD_OBJECTID) from sys_user_info where IS_DEL='0' and UNIT_CODE='"
  530. + deptId + "' ORDER BY user_id ASC ";*/
  531. String sql = "select count(FD_OBJECTID) from sys_user_info where IS_DEL='0' ORDER BY user_id ASC ";
  532. // log.info("=="+sql);
  533. boolean flag = false;
  534. try {
  535. ArrayList<String[]> list = persistence.getSearchResult(99, sql);
  536. int num = Integer.parseInt(list.get(0)[0]);
  537. if (num > 0) {
  538. flag = true;
  539. }
  540. } catch (PersistenceException e) {
  541. log.error("是否存在人员-- ", e);
  542. }
  543. return flag;
  544. }
  545. /**
  546. * 新增机构或人员时,生成编号Id
  547. *
  548. * @param params
  549. * @return
  550. */
  551. @ProduceMime("application/json")
  552. @POST
  553. @Path("/getCreateNodeNum")
  554. public String getCreateNodeNum(String params) {
  555. params = decode(params);
  556. // 树节点id
  557. String node = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  558. "deptId", params);
  559. // 800 机构; 807人员
  560. Integer classid = Integer.parseInt(Utils.getParameter("classid", params) == null ? ""
  561. : Utils.getParameter("classid", params));
  562. SysModel sysmodel = ModelFactory.getSysmodel();
  563. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  564. String num = "";
  565. try {
  566. String sql = "";
  567. if (classid == 800) {
  568. sql = "select Max(Dept_Id) from Sys_Department where Depts_Id='" + node + "'";
  569. } else if (classid == 807) {
  570. sql = "select Max(user_id) from sys_user_info where UNIT_CODE='" + node + "'";
  571. }
  572. ArrayList<String[]> list = persistence.getSearchResult(classid, sql);
  573. // 如果节点下没有子节点,返回节点nodeid+‘01’,作为该节点的第一个子节点。
  574. if (list.get(0)[0] == null) {
  575. num = node + "01";
  576. } else {
  577. String deptCode = list.get(0)[0];
  578. num = Long.valueOf(deptCode) + 1 + "";
  579. }
  580. } catch (PersistenceException e) {
  581. log.error("生成机构人员编码错误", e);
  582. }
  583. log.info("num--- " + num);
  584. return num;
  585. }
  586. // 根据单位deptid获取单位名称
  587. public String getBMTableByNameIds(String tablename, String fdCode) {
  588. SysModel sysmodel = ModelFactory.getSysmodel();
  589. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  590. String sql = "";
  591. // 单位部门表时,查询字段特殊
  592. if (tablename.equalsIgnoreCase("Sys_Department")) {
  593. sql = "select DEPT_NAME,Dept_Id from " + tablename + " where is_del ='0' and Dept_Id='"
  594. + fdCode + "'";
  595. } else {
  596. sql = "select fd_description,fd_code from BM$_MapValueCanst where fd_type='"
  597. + tablename + "' and fd_code='" + fdCode + "' ";
  598. }
  599. ArrayList<String[]> codes;
  600. String value = "";
  601. try {
  602. codes = persistence.getSearchResult(99, sql);
  603. if (codes.size() > 0) {
  604. for (String[] s : codes) {
  605. if (s[1].equals(fdCode)) {
  606. value = s[0];
  607. }
  608. }
  609. }
  610. } catch (Exception e) {
  611. e.printStackTrace();
  612. log.error("" + e);
  613. }
  614. return value;
  615. }
  616. // 编码解析
  617. protected String decode(String params) {
  618. try {
  619. params = java.net.URLDecoder.decode(params, "UTF-8");
  620. } catch (UnsupportedEncodingException e) {
  621. e.printStackTrace();
  622. }
  623. return params;
  624. }
  625. /**
  626. * 根据部门deptid删除人员信息
  627. *
  628. * @param params
  629. */
  630. @ProduceMime("application/json")
  631. @POST
  632. @Path("/delPersonByDeptId")
  633. public void delPersonByDeptId(String params) {
  634. SysModel sysmodel = ModelFactory.getSysmodel();
  635. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  636. String depts = Utils.getParameter("DEPT_ID", params).trim() == null ? "" : Utils
  637. .getParameter("DEPT_ID", params).trim();
  638. String sql = "update sys_user_info set is_del='1' where UNIT_CODE='" + depts + "'";
  639. log.info(sql);
  640. try {
  641. persistence.getSearchResult(99, sql);
  642. } catch (Exception e) {
  643. log.error("" + e);
  644. }
  645. }
  646. /**
  647. * 根据人员Id删除人员信息
  648. *
  649. * @param params
  650. */
  651. @ProduceMime("application/json")
  652. @POST
  653. @Path("/delPersonByPid")
  654. public String delPersonByPid(String params) {
  655. SysModel sysmodel = ModelFactory.getSysmodel();
  656. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  657. String objectId = Utils.getParameter("ObjectID", params).trim() == null ? "" : Utils
  658. .getParameter("ObjectID", params).trim();
  659. String sql = "update sys_user_info set is_del='1' where FD_OBJECTID='" + objectId + "'";
  660. log.info(sql);
  661. boolean flag = false;
  662. try {
  663. int num = persistence.executeUpdateSQL(99, sql);
  664. if (num > 0) {
  665. flag = true;
  666. }
  667. } catch (Exception e) {
  668. log.error("" + e);
  669. }
  670. return new Boolean(flag).toString();
  671. }
  672. /**
  673. * 根据人员Id删除人员信息
  674. *
  675. * @param params
  676. */
  677. @ProduceMime("application/json")
  678. @POST
  679. @Path("/delDeptById")
  680. public String delDeptById(String params) {
  681. SysModel sysmodel = ModelFactory.getSysmodel();
  682. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  683. String objectId = Utils.getParameter("ObjectID", params).trim() == null ? "" : Utils
  684. .getParameter("ObjectID", params).trim();
  685. String sql = "update Sys_Department set is_del='1' where FD_OBJECTID='" + objectId + "'";
  686. log.info(sql);
  687. boolean flag = false;
  688. try {
  689. int num = persistence.executeUpdateSQL(99, sql);
  690. if (num > 0) {
  691. flag = true;
  692. }
  693. } catch (Exception e) {
  694. log.error("" + e);
  695. }
  696. return new Boolean(flag).toString();
  697. }
  698. @ProduceMime("application/json")
  699. @POST
  700. @Path("/getEquipArg")
  701. public String getEquipArg(String params) {////查询装备属性(通过工器具类型ID)
  702. try {
  703. params = java.net.URLDecoder.decode(params, "UTF-8");
  704. } catch (UnsupportedEncodingException e) {
  705. e.printStackTrace();
  706. }
  707. String equipmentTypeID = Utils.getParameter("equipTypeID", params) == null ? "" : Utils.getParameter("equipTypeID", params);//工器具类型ID
  708. // String sql = "select ID,COLUMN_NAME from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER where INSTRUMENT_TYPE_ID in ( select ID from NWYJ_SERVICE.SP_SS_INSTRUMENT_TYPE where PROVINCE_CODE=? and BUREAU_CODE=? and INSTRUMENT_NAME=? )";
  709. String sql = "select ID,COLUMN_NAME from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER where INSTRUMENT_TYPE_ID=?";
  710. StringBuffer sb = new StringBuffer();
  711. sb.append("{\"equipResult\":[");
  712. DbConnection dbConn = new DbConnection();
  713. Connection conn = null;
  714. PreparedStatement pstm = null;
  715. ResultSet rs = null;
  716. try {
  717. conn = dbConn.getConnection();
  718. pstm = conn.prepareStatement(sql);
  719. pstm.setString(1, equipmentTypeID);
  720. rs = pstm.executeQuery();
  721. while(rs.next()){
  722. // sb.append(rs.getString("EQUIPMENT_NAME") == null ? "" : rs.getString("EQUIPMENT_NAME"));
  723. // sb.append(",");
  724. sb.append("{\"equipArg\":\""+(rs.getString("COLUMN_NAME") == null ? "" : rs.getString("COLUMN_NAME"))+"\","
  725. +"\"equipArgId\":\""+(rs.getString("ID") == null ? "" : rs.getString("ID"))+"\""
  726. +"},");
  727. }
  728. if (sb.lastIndexOf(",") > -1) {
  729. sb.deleteCharAt(sb.lastIndexOf(","));
  730. // sb.deleteCharAt(sb.length()-1);
  731. }
  732. sb.append("]}");
  733. } catch (SQLException e) {
  734. e.printStackTrace();
  735. } catch (ClassNotFoundException e) {
  736. e.printStackTrace();
  737. }finally{
  738. try {
  739. if(rs!=null)
  740. rs.close();
  741. if(pstm!=null)
  742. pstm.close();
  743. if(conn!=null)
  744. conn.close();
  745. } catch (SQLException e) {
  746. e.printStackTrace();
  747. }
  748. }
  749. // System.out.println("******************"+sb.toString());
  750. return sb.toString();
  751. }
  752. @ProduceMime("application/json")
  753. @POST
  754. @Path("/getEquipArgVal")
  755. public String getEquipArgVal(String params) {//获取满足条件的装备类型属性的值和id
  756. try {
  757. params = java.net.URLDecoder.decode(params, "UTF-8");
  758. } catch (UnsupportedEncodingException e) {
  759. e.printStackTrace();
  760. }
  761. // String equipArg = Utils.getParameter("equipArg", params) == null ? "" : Utils.getParameter("equipArg", params);//装备属性
  762. String equipArgId = Utils.getParameter("equipArgId", params) == null ? "" : Utils.getParameter("equipArgId",params);//装备属性值
  763. // String equipArg = Utils.getParameter("equipArg", params) == null ? "" : Utils.getParameter("equipArg",params);//装备属性值
  764. String sql = "select ID,COLUMN_NAME,COLUMN_CODE,COLUMN_VALUE from NWYJ_SERVICE.SP_SS_EMERGENCY_PARAMETER_VAL where EMERGENCY_PARAMETER_ID=?";
  765. StringBuffer sb = new StringBuffer();
  766. sb.append("{\"equipVal\":[");
  767. DbConnection dbConn = new DbConnection();
  768. Connection conn = null;
  769. PreparedStatement pstm = null;
  770. ResultSet rs = null;
  771. try {
  772. conn = dbConn.getConnection();
  773. pstm = conn.prepareStatement(sql);
  774. pstm.setString(1, equipArgId);
  775. rs = pstm.executeQuery();
  776. while(rs.next()){
  777. sb.append("{"+
  778. "\"equipArgValId\":\""+(rs.getString("ID") == null ? "" : rs.getString("ID"))+"\","+
  779. "\"equipArgValName\":\""+(rs.getString("COLUMN_NAME") == null ? "" : rs.getString("COLUMN_NAME"))+"\","+
  780. "\"equipArgValCode\":\""+(rs.getString("COLUMN_CODE") == null ? "" : rs.getString("COLUMN_CODE"))+"\","+
  781. "\"equipArgVal\":\""+(rs.getString("COLUMN_VALUE") == null ? "" : rs.getString("COLUMN_VALUE"))+"\""+
  782. "},");
  783. }
  784. if (sb.lastIndexOf(",") > -1) {
  785. sb.deleteCharAt(sb.lastIndexOf(","));
  786. // sb.deleteCharAt(sb.length()-1);
  787. }
  788. sb.append("]}");
  789. } catch (SQLException e) {
  790. e.printStackTrace();
  791. } catch (ClassNotFoundException e) {
  792. e.printStackTrace();
  793. }finally{
  794. try {
  795. if(rs!=null)
  796. rs.close();
  797. if(pstm!=null)
  798. pstm.close();
  799. if(conn!=null)
  800. conn.close();
  801. } catch (SQLException e) {
  802. e.printStackTrace();
  803. }
  804. }
  805. // System.out.println("******************"+sb.toString());
  806. return sb.toString();
  807. }
  808. @POST
  809. @ProduceMime("application/json")
  810. @Path("/getIdByEquipMsg")
  811. public String getIdByEquipMsg(String params) {//获取工器具类型ID
  812. try {
  813. params = java.net.URLDecoder.decode(params, "UTF-8");
  814. } catch (UnsupportedEncodingException e) {
  815. e.printStackTrace();
  816. }
  817. String equipmentType = Utils.getParameter("jkEquipmentType", params) == null ? "" : Utils.getParameter("jkEquipmentType",params);//装备类型(PARENT_NAME)
  818. String sql = "select ID from NWYJ_SERVICE.SP_SS_INSTRUMENT_TYPE where INSTRUMENT_NAME=?";
  819. StringBuffer sb = new StringBuffer();
  820. DbConnection dbConn = new DbConnection();
  821. Connection conn = null;
  822. PreparedStatement pstm = null;
  823. ResultSet rs = null;
  824. try {
  825. conn = dbConn.getConnection();
  826. pstm = conn.prepareStatement(sql);
  827. pstm.setString(1, params);
  828. rs = pstm.executeQuery();
  829. while(rs.next()){
  830. sb.append(rs.getString("ID") == null ? "" : rs.getString("ID"));
  831. }
  832. } catch (SQLException e) {
  833. e.printStackTrace();
  834. } catch (ClassNotFoundException e) {
  835. e.printStackTrace();
  836. }finally{
  837. try {
  838. if(rs!=null)
  839. rs.close();
  840. if(pstm!=null)
  841. pstm.close();
  842. if(conn!=null)
  843. conn.close();
  844. } catch (SQLException e) {
  845. e.printStackTrace();
  846. }
  847. }
  848. // System.out.println("******************"+sb.toString());
  849. return sb.toString();
  850. }
  851. @POST
  852. @ProduceMime("application/json")
  853. @Path("/getTeamMsg")
  854. public String getTeamMsg(String params) {//获取队伍
  855. try {
  856. params = java.net.URLDecoder.decode(params, "UTF-8");
  857. } catch (UnsupportedEncodingException e) {
  858. e.printStackTrace();
  859. }
  860. String unite_id = Utils.getParameter("uniteID", params) == null ? "" : Utils.getParameter("uniteID",params);//单位ID
  861. String teamType = Utils.getParameter("teamType", params) == null ? "" : Utils.getParameter("teamType",params);//队伍类型
  862. String teamTypeCode = "";//队伍类型常量值(select * from bm_mapvaluecanst where fd_type='BM_TEAMTYPE')
  863. if(teamType == "输电"){//"输电".equals(teamType)
  864. teamTypeCode="124";
  865. } else if(teamType == "变电"){
  866. teamTypeCode="125";
  867. } else if(teamType == "配电"){
  868. teamTypeCode="126";
  869. } else if(teamType == "通信"){
  870. teamTypeCode="127";
  871. } else if(teamType.equals("网络信息")){//--------------------------------------
  872. teamTypeCode="124";//--------------------------------------
  873. } else if(teamType == "试验"){
  874. teamTypeCode="129";
  875. } else if(teamType == "其他"){
  876. teamTypeCode="130";
  877. }
  878. String sql = "select FD_OBJECTID,TEAM_NAME,TEAM_MEMBER_NUMBER from ECM_AM_EMERGENCY_TEAM where TEAM_COMP_ID=? and TEAM_TYPE=? and TEAM_STAT='1'";
  879. StringBuffer sb = new StringBuffer();
  880. DbConnection dbConn = new DbConnection();
  881. Connection conn = null;
  882. PreparedStatement pstm = null;
  883. ResultSet rs = null;
  884. try {
  885. conn = dbConn.getConnection();
  886. pstm = conn.prepareStatement(sql);
  887. pstm.setString(1, unite_id);
  888. pstm.setString(2, teamTypeCode);
  889. rs = pstm.executeQuery();
  890. sb.append("{\"treeNodes\":[");
  891. while(rs.next()){
  892. // sb.append("{\"id\":\""+rs.getString("FD_OBJECTID")==null ? "" : rs.getString("FD_OBJECTID")+"\",\"parentId\":\"0\",\"name\":\""+rs.getString("TEAM_NAME")==null ? "" : rs.getString("TEAM_NAME")+"("+rs.getString("TEAM_MEMBER_NUMBER") == null ? "" : rs.getString("TEAM_MEMBER_NUMBER")+")\"},");
  893. sb.append("{\"id\":\""+rs.getString("FD_OBJECTID")+"\",\"parentId\":\"0\",\"name\":\""+rs.getString("TEAM_NAME")+"("+rs.getString("TEAM_MEMBER_NUMBER")+")\"},");
  894. }
  895. if(sb.lastIndexOf(",")>-1){
  896. sb.deleteCharAt(sb.lastIndexOf(","));
  897. }
  898. sb.append("]}");
  899. } catch (SQLException e) {
  900. e.printStackTrace();
  901. } catch (ClassNotFoundException e) {
  902. e.printStackTrace();
  903. }finally{
  904. try {
  905. if(rs!=null)
  906. rs.close();
  907. if(pstm!=null)
  908. pstm.close();
  909. if(conn!=null)
  910. conn.close();
  911. } catch (SQLException e) {
  912. e.printStackTrace();
  913. }
  914. }
  915. // System.out.println("******************"+sb.toString());
  916. return sb.toString();
  917. }
  918. @ProduceMime("application/json")
  919. @POST
  920. @Path("/initZtree_unitAndEquipMsg")
  921. public String initZtree_unitAndEquipMsg(String params) {//单位及装备、装备属性、属性值的下拉树
  922. try {
  923. params = java.net.URLDecoder.decode(params, "UTF-8");
  924. } catch (UnsupportedEncodingException e1) {
  925. // TODO Auto-generated catch block
  926. e1.printStackTrace();
  927. }
  928. String id = Utils.getParameter("corpId", params) == null ? "" : Utils.getParameter("corpId", params);//登录人单位id
  929. String corpName = Utils.getParameter("corpName", params) == null ? "" : Utils.getParameter("corpName",params);//登录人单位name
  930. String recipDept = Utils.getParameter("equipNeedUnit", params) == null ? "" : Utils.getParameter("equipNeedUnit",params);//需求申请单位ID
  931. String fdId_382 = Utils.getParameter("fdId", params) == null ? "" : Utils.getParameter("fdId", params);//装备需求ID
  932. StringBuffer sb = new StringBuffer();
  933. RespEquipmentService res = new RespEquipmentService();
  934. String sql =" select DEPT_ID,DEPT_NAME,FD_OBJECTID,UNICODE "+
  935. " from Sys_Department "+
  936. " where 1=1 and "+
  937. " PARENT_ID='"+id+"' and "+
  938. " dept_type='1' and "+
  939. " dept_name like'%供电%' and "+
  940. " DEPT_ID!='"+recipDept+"' "+
  941. " ORDER BY SORT asc ";
  942. DbConnection dbConn = new DbConnection();
  943. Connection conn = null;
  944. PreparedStatement pstm = null;
  945. ResultSet rs = null;
  946. try {
  947. conn = dbConn.getConnection();
  948. pstm = conn.prepareStatement(sql);
  949. rs = pstm.executeQuery();
  950. sb.append("{\"treeNodes\":[");
  951. sb.append("{\"id\":\""+id+"\",\"parentId\":\"99999\",\"name\":\""+corpName+"\",\"open\":\"true\"},");//第一级--本级单位(制定调拨令的人的单位)
  952. while(rs.next()){
  953. String deptId = rs.getString("DEPT_ID") == null ? "" : rs.getString("DEPT_ID");//下级单位id
  954. String deptName = rs.getString("DEPT_NAME") == null ? "" : rs.getString("DEPT_NAME");//下级单位NAME
  955. String unitcode = rs.getString("UNICODE") == null ? "" : rs.getString("UNICODE");//单位编码
  956. /******************************************************************************************************/
  957. sb.append("{\"id\":\""+deptId+"\",\"parentId\":\""+id+"\",\"name\":\""+deptName+"\"},");//第二级--下级单位
  958. /**
  959. *需求信息表--ID:383--表名:ECM_EM_EQUIPMENT_DEMAND_DETAIL 该表中EQUIPMENT_NAME字段的值代表装备类型
  960. *(0:发电车--ID:265--表名:EMC_AM_GENERATOR_CAR--状态:IS_USED='1')
  961. *(1:发电机--ID:266--表名:EMC_AM_GENERATOR--状态:USED_STAT='1')
  962. *(2:移动餐车--ID:270--表名:EMC_AM_DINING_CAR--状态:IS_USED='1')
  963. *(3:指挥通信车--ID:269--表名:EMC_AM_EMERGENCY_COMMAND_CAR--状态:USED_STAT='1')
  964. */
  965. //先通过需求id382在表ECM_EM_EQUIPMENT_DEMAND_DETAIL中查出需求下的各种装备类型(可能不是一个)
  966. String equipTypes = res.getEquipTypes(fdId_382);
  967. int equipTypesNum = 0;//装备类型的数量(多少种装备)
  968. equipTypesNum = equipTypes.split(",").length;
  969. for(int i=0;i<equipTypesNum;i++){//装备类型
  970. if("0".equals(equipTypes.split(",")[i])){//发电车
  971. sb.append("{\"id\":\""+deptId+","+"fadianche\",\"parentId\":\""+deptId+"\",\"name\":\"发电车\"},");//第三级--装备类型
  972. String gqjlxId = getIdByEquipMsg("发电车");//查询“工器具类型”
  973. String equipArg = res.getEquipArg(gqjlxId);//查询装备属性(通过工器具类型ID)【属性,属性ID;属性,属性ID;...】
  974. int equipArgNum = 0;//装备属性的个数
  975. equipArgNum = equipArg.split(";").length;
  976. String idAndParentId = "";
  977. for(int j=0;j<equipArgNum;j++){//装备属性
  978. idAndParentId = equipArg.split(";")[j].split(",")[1];
  979. sb.append("{\"id\":\""+deptId+","+idAndParentId+","+"0"+"\",\"parentId\":\""+deptId+","+"fadianche\",\"name\":\""+equipArg.split(";")[j].split(",")[0]+"\"},");//第四级--装备属性
  980. String equipArgValMsg = res.getEquipArgVal(equipArg.split(";")[j].split(",")[1]);//获取装备属性值信息【具体信息排序,可以查看方法RespEquipmentService.getEquipArgVal】
  981. int equipArgValMsgNum = 0;//装备属性值的个数
  982. equipArgValMsgNum = equipArgValMsg.split(";").length;
  983. for(int k=0;k<equipArgValMsgNum;k++){//装备属性值
  984. sb.append("{\"id\":\""+equipArgValMsg.split(";")[k].split(",")[1]+"\",\"parentId\":\""+deptId+","+idAndParentId+","+"0"+"\",\"name\":\""+equipArgValMsg.split(";")[k].split(",")[0]+"\","+
  985. "\"appendMsg\":\""+deptName+"-发电车-"+equipArg.split(";")[j].split(",")[0]+":"+equipArgValMsg.split(";")[k].split(",")[0]+"\","+//XX供电局-发电车-属性:属性值
  986. "\"deptMsg\":\""+deptId+","+deptName+","+"发电车"+"\","+
  987. "\"queryEquipNum_JK\":\""+
  988. gqjlxId+","+//工器具类型ID
  989. unitcode+","+//单位编码
  990. equipArgValMsg.split(";")[k].split(",")[1]+","+//属性值ID
  991. equipArgValMsg.split(";")[k].split(",")[2]+","+//属性
  992. equipArgValMsg.split(";")[k].split(",")[0]+//属性值
  993. "\"},");//第五级--装备属性值(queryEquipNum_JK:工器具类型ID,单位编码,属性值ID,属性,属性值)
  994. }
  995. }
  996. }else if("1".equals(equipTypes.split(",")[i])){//发电机
  997. sb.append("{\"id\":\""+deptId+","+"fadianji\",\"parentId\":\""+deptId+"\",\"name\":\"发电机\"},");//第三级--装备类型
  998. String gqjlxId = getIdByEquipMsg("发电机");//查询“工器具类型”
  999. String equipArg = res.getEquipArg(gqjlxId);//查询装备属性(通过工器具类型ID)【属性,属性ID;属性,属性ID;...】
  1000. int equipArgNum = 0;//装备属性的个数
  1001. equipArgNum = equipArg.split(";").length;
  1002. String idAndParentId = "";
  1003. for(int j=0;j<equipArgNum;j++){//装备属性
  1004. idAndParentId = equipArg.split(";")[j].split(",")[1];//属性ID
  1005. sb.append("{\"id\":\""+deptId+","+idAndParentId+","+"1"+"\",\"parentId\":\""+deptId+","+"fadianji\",\"name\":\""+equipArg.split(";")[j].split(",")[0]+"\"},");//第四级--装备属性
  1006. String equipArgValMsg = res.getEquipArgVal(equipArg.split(";")[j].split(",")[1]);//获取装备属性值信息【具体信息排序,可以查看方法RespEquipmentService.getEquipArgVal】
  1007. int equipArgValMsgNum = 0;//装备属性值的个数
  1008. equipArgValMsgNum = equipArgValMsg.split(";").length;
  1009. for(int k=0;k<equipArgValMsgNum;k++){//装备属性值
  1010. sb.append("{\"id\":\""+equipArgValMsg.split(";")[k].split(",")[1]+"\",\"parentId\":\""+deptId+","+idAndParentId+","+"1"+"\",\"name\":\""+equipArgValMsg.split(";")[k].split(",")[0]+"\","+
  1011. "\"appendMsg\":\""+deptName+"-发电机-"+equipArg.split(";")[j].split(",")[0]+":"+equipArgValMsg.split(";")[k].split(",")[0]+"\","+//XX供电局-发电车-属性:属性值
  1012. "\"deptMsg\":\""+deptId+","+deptName+","+"发电机"+"\","+//单位ID,单位NAME,装备类型,,,
  1013. "\"queryEquipNum_JK\":\""+
  1014. gqjlxId+","+//工器具类型ID
  1015. unitcode+","+//单位编码
  1016. equipArgValMsg.split(";")[k].split(",")[1]+","+//属性值ID
  1017. equipArgValMsg.split(";")[k].split(",")[2]+","+//属性
  1018. equipArgValMsg.split(";")[k].split(",")[0]+//属性值
  1019. "\"},");//第五级--装备属性值(queryEquipNum_JK:工器具类型ID,单位编码,属性值ID,属性,属性值)
  1020. }
  1021. }
  1022. }//else if("2".endsWith(equipTypes.split(",")[i])){}
  1023. }
  1024. }
  1025. if(sb.lastIndexOf(",") > -1){
  1026. sb.deleteCharAt(sb.lastIndexOf(","));
  1027. }
  1028. sb.append("]}");
  1029. } catch (ClassNotFoundException e) {
  1030. // TODO Auto-generated catch block
  1031. e.printStackTrace();
  1032. } catch (SQLException e) {
  1033. // TODO Auto-generated catch block
  1034. e.printStackTrace();
  1035. }finally{
  1036. try {
  1037. if(rs!=null)
  1038. rs.close();
  1039. if(pstm!=null)
  1040. pstm.close();
  1041. if(conn!=null)
  1042. conn.close();
  1043. } catch (SQLException e) {
  1044. e.printStackTrace();
  1045. }
  1046. }
  1047. //System.out.println("///////////****************"+sb.toString());
  1048. return sb.toString();
  1049. }
  1050. }