f92dcbf532127ad0b070f0baae10cddd2de3f33c.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. package com.sinosoft.common.excel;
  2. import java.io.FileInputStream;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.sql.Connection;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.text.ParseException;
  11. import java.text.SimpleDateFormat;
  12. import java.util.ArrayList;
  13. import java.util.Date;
  14. import java.util.HashMap;
  15. import java.util.Iterator;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.UUID;
  19. import java.util.Vector;
  20. import javax.ws.rs.POST;
  21. import javax.ws.rs.Path;
  22. import javax.ws.rs.ProduceMime;
  23. import org.apache.log4j.Logger;
  24. import org.apache.poi.hssf.usermodel.HSSFCell;
  25. import org.apache.poi.hssf.usermodel.HSSFDateUtil;
  26. import org.apache.poi.hssf.usermodel.HSSFRow;
  27. import org.apache.poi.hssf.usermodel.HSSFSheet;
  28. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  29. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  30. import org.apache.poi.ss.usermodel.Cell;
  31. import org.apache.poi.ss.usermodel.DateUtil;
  32. import org.apache.poi.xssf.usermodel.XSSFCell;
  33. import org.apache.poi.xssf.usermodel.XSSFRow;
  34. import org.apache.poi.xssf.usermodel.XSSFSheet;
  35. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  36. import com.formaction.Parameter;
  37. import com.formaction.Utils;
  38. import com.formaction.vo.Msg;
  39. import com.persistence.DbConnection;
  40. import com.persistence.service.PersistenceFactory;
  41. import com.persistence.service.SysPersistence;
  42. import com.persistence.service.exception.PersistenceException;
  43. import com.sinosoft.lz.system.util.JsonUtil;
  44. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  45. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  46. /**
  47. * 读取Excel将数据返回到頁面
  48. *
  49. * @author 徐威
  50. *
  51. */
  52. @Path("/findPlanInfo/")
  53. public class findPlanInfo {
  54. private static final Logger log = Logger.getLogger(findPlanInfo.class);
  55. @ProduceMime("application/json")
  56. @POST
  57. @Path("/getTeamExcel")
  58. public String readExcelByName(String params) throws Exception {
  59. findPlanInfo tool = new findPlanInfo();
  60. String fileName=Utils.getParameter("fileName", params) == null ? "" : Utils.getParameter(
  61. "fileName", params);
  62. // String fileName="E:\\javaDemo\\person.xls";
  63. int i=fileName.lastIndexOf(".");
  64. String type=fileName.substring(i+1);
  65. log.info("fileName===="+fileName);
  66. String result="";
  67. if("xls".equals(type)){
  68. result=tool.readExcel(fileName,"person");
  69. }else if("xlsx".equals(type)){
  70. result= tool.readExcel2007(fileName,"person");
  71. }
  72. result="{\"rows\":"+result+"}";
  73. log.info(result);
  74. return result;
  75. }
  76. // public void readExcel2007(DBModel dbConn, String filePath, String tableName)
  77. @SuppressWarnings({ "unchecked", "resource", "unused", "rawtypes" })
  78. public String readExcel2007( String filePath, String tableName)
  79. throws Exception {
  80. String result="";
  81. try {
  82. // InputStream inp = new FileInputStream(filePath);
  83. // Workbook wb = WorkbookFactory.create(inp);
  84. XSSFWorkbook wb = new XSSFWorkbook(filePath);
  85. int sheetSize = wb.getNumberOfSheets();
  86. // for (int i = 0; i < sheetSize; i++) {
  87. List list=new ArrayList();
  88. XSSFSheet sheet = wb.getSheetAt(0);
  89. // Sheet sheet = wb.getSheetAt(i);
  90. for (Iterator rit = sheet.rowIterator(); rit.hasNext();) {
  91. // 迭代行
  92. XSSFRow row = (XSSFRow) rit.next();
  93. // 迭代单元格
  94. Vector datas = new Vector();
  95. StringBuffer sb=new StringBuffer();
  96. Map<String, String>lineMap=new HashMap<String, String>();
  97. for (Iterator cit = row.cellIterator(); cit.hasNext();) {
  98. // 定义集合datas用于存Excel中一个行的数据
  99. XSSFCell cell = (XSSFCell) cit.next();
  100. String value = getValue2007(cell);
  101. sb.append(value+"|");
  102. // 注意行和列是基于0索引的
  103. // System.out.print(cell.getRowIndex() + ":" + cell.getColumnIndex() + " ");
  104. datas.add(value);
  105. // System.out.println();
  106. // 开始操作单元格
  107. }
  108. String[] arr=sb.toString().split("[|]");
  109. list.add(arr);
  110. // result = fillMap(list);;
  111. // 向表中插入数据
  112. // DBFactory.insertData(dbConn, tableName, datas);
  113. }
  114. result = fillMap(list);
  115. System.out.println(result);
  116. // }
  117. } catch (FileNotFoundException e) {
  118. e.printStackTrace();
  119. throw e;
  120. } catch (IOException e) {
  121. e.printStackTrace();
  122. throw e;
  123. }
  124. return result;
  125. }
  126. /**
  127. * 將数据转换成json
  128. * @param list
  129. * @return
  130. */
  131. public String fillMap(List<String[]> list){
  132. List<Map<String, String>>dataList=new ArrayList<Map<String,String>>();
  133. for(int i=0;i<list.size();i++){
  134. Map<String, String>tempMap=new HashMap<String, String>();
  135. String[]arr=list.get(i);
  136. tempMap.put("TEAM_SYSTEM_261", arr[0]);
  137. tempMap.put("", arr[1]);
  138. tempMap.put("TEAM_COMP_ID_261", arr[2]);
  139. tempMap.put("TEAM_NAME_261", arr[3]);
  140. tempMap.put("TEAM_TYPE_261", arr[4]);
  141. tempMap.put("TEAM_STAT_261", arr[5]);
  142. tempMap.put("TEAM_AEAR_261", arr[6]);
  143. tempMap.put("TEAM_ADDRESS_261", arr[7]);
  144. tempMap.put("TEAM_LEADER_261", arr[8]);
  145. tempMap.put("TEAM_TEL_261", arr[9]);
  146. tempMap.put("TEAM_PHONE_261", arr[10]);
  147. tempMap.put("TEAM_OFFICE_TEL_261", arr[11]);
  148. tempMap.put("TEAM_MEMBER_NUMBER_261", arr[12]);
  149. tempMap.put("TEAM_MEMBER_INFO_261", arr[13]);
  150. tempMap.put("TEAM_LEVEL_261", arr[14]);
  151. tempMap.put("TEAM_SPECIALITY_261", arr[15]);
  152. dataList.add(tempMap);
  153. }
  154. String result=JsonUtil.list2json(dataList);
  155. return result;
  156. }
  157. /**
  158. * 将Excel数据导入到表中
  159. *
  160. * @param filePath
  161. * Excel路径
  162. * @param tableName
  163. * 表名
  164. */
  165. // public void readExcel(DBModel dbConn, String filePath, String tableName)
  166. @SuppressWarnings({ "rawtypes", "unchecked", "resource", "deprecation" })
  167. public String readExcel( String filePath, String tableName)
  168. throws Exception {
  169. String result="";
  170. try {
  171. POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( filePath));
  172. // 创建工作簿
  173. HSSFWorkbook workBook = new HSSFWorkbook(fs);
  174. log.info(workBook.getNumberOfSheets());
  175. // System.out.println("工作表个数 :" + workBook.getNumberOfSheets());
  176. for (int i = 0; i < workBook.getNumberOfSheets(); i++) {
  177. // 创建工作表
  178. HSSFSheet sheet = workBook.getSheetAt(i);
  179. int rows = sheet.getPhysicalNumberOfRows(); // 获得行数
  180. if (rows > 0) {
  181. sheet.getMargin(HSSFSheet.TopMargin);
  182. List list=new ArrayList();
  183. for (int r = 0; r < rows; r++) { // 行循环
  184. HSSFRow row = sheet.getRow(r);
  185. if (row != null && r != 0) {// 不取第一行
  186. int cells = row.getLastCellNum();// 获得列数
  187. // 定义集合datas用于存Excel中一个行的数据
  188. Vector datas = new Vector();
  189. String[]arr=new String[cells];
  190. List<String>paramList=new ArrayList<String>();
  191. for (short c = 0; c < cells; c++) { // 列循环
  192. HSSFCell cell = row.getCell(c);
  193. if (cell != null) {
  194. String value = getValue(cell);
  195. // System.out.println("第" + r + "行 " + "第" + c + "列:" + value);
  196. datas.add(value);
  197. paramList.add(value);
  198. arr[c]=value;
  199. }
  200. }
  201. list.add(arr);
  202. result = fillMap(list);
  203. // dataIntoDb(tableName, paramList);
  204. // 向表中插入数据
  205. // DBFactory.insertData(dbConn, tableName, datas);
  206. }
  207. }
  208. } else {
  209. }
  210. }
  211. } catch (Exception ex) {
  212. ex.printStackTrace();
  213. log.info(ex);
  214. throw ex;
  215. }
  216. return result;
  217. }
  218. public String getValue2007(XSSFCell cell) {
  219. String value = "";
  220. switch (cell.getCellType()) {
  221. case Cell.CELL_TYPE_STRING:
  222. // System.out.println(cell.getRichStringCellValue().getString());
  223. break;
  224. case Cell.CELL_TYPE_NUMERIC:
  225. if (DateUtil.isCellDateFormatted(cell)) {
  226. // System.out.println(cell.getDateCellValue());
  227. java.util.Date date = cell.getDateCellValue();
  228. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  229. value = format.format(date);
  230. } else {
  231. // System.out.println(cell.getNumericCellValue());
  232. value = String.valueOf(cell.getNumericCellValue());
  233. }
  234. break;
  235. case Cell.CELL_TYPE_BOOLEAN:
  236. // System.out.println(cell.getBooleanCellValue());
  237. value = " " + cell.getBooleanCellValue();
  238. break;
  239. case Cell.CELL_TYPE_FORMULA:
  240. // System.out.println(cell.getCellFormula());
  241. value = cell.getCellFormula();
  242. break;
  243. default:
  244. System.out.println();
  245. }
  246. return value;
  247. }
  248. /**
  249. * 获取Excel中某个单元格的值
  250. *
  251. * @param cell
  252. * @return
  253. * @throws ParseException
  254. */
  255. @SuppressWarnings("deprecation")
  256. public String getValue(HSSFCell cell) throws ParseException {
  257. String value = "";
  258. switch (cell.getCellType()) {
  259. case HSSFCell.CELL_TYPE_NUMERIC: // 数值型
  260. System.out.println("数字类型");
  261. if (HSSFDateUtil.isCellDateFormatted(cell)) {
  262. // 如果是date类型则 ,获取该cell的date值
  263. value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue())
  264. .toString();
  265. java.util.Date date1 = new Date(value);
  266. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  267. value = format.format(date1);
  268. } else {// 纯数字
  269. value = String.valueOf(cell.getNumericCellValue()).split("[.]")[0];
  270. }
  271. break;
  272. /* 此行表示单元格的内容为string类型 */
  273. case HSSFCell.CELL_TYPE_STRING: // 字符串型
  274. value = cell.getStringCellValue();
  275. break;
  276. case HSSFCell.CELL_TYPE_FORMULA:// 公式型
  277. // 读公式计算值
  278. value = String.valueOf(cell.getNumericCellValue());
  279. if (value.equals("NaN")) {// 如果获取的数据值为非法值,则转换为获取字符串
  280. value = cell.getStringCellValue().toString();
  281. }
  282. cell.getCellFormula();
  283. break;
  284. case HSSFCell.CELL_TYPE_BOOLEAN:// 布尔
  285. value = " " + cell.getBooleanCellValue();
  286. break;
  287. /* 此行表示该单元格值为空 */
  288. case HSSFCell.CELL_TYPE_BLANK: // 空值
  289. value = "";
  290. break;
  291. case HSSFCell.CELL_TYPE_ERROR: // 故障
  292. value = "";
  293. break;
  294. default:
  295. value = cell.getStringCellValue().toString();
  296. }
  297. return value;
  298. }
  299. // public boolean dataIntoDb(String tabName,List<String>list) throws ClassNotFoundException, SQLException{
  300. // Class.forName("dm.jdbc.driver.DmDriver");
  301. // Connection conn = DriverManager.getConnection("jdbc:dm://192.168.1.16:5236","NWYJ","NWYJ123456");
  302. // String sql="INSERT INTO SYS_MSG_MODEL(FD_OBJECTID,MSG_MODEL_TYPE,MSG_MODEL_CONTENT,MSG_MODEL_RANGE,MSG_MODEL_COMP,MSG_MODEL_USER,MSG_MODEL_TIME,IS_DEL)VALUES(?,?,?,?,?,?,?,?)";
  303. // PreparedStatement ps=null;
  304. // conn.setAutoCommit(false);
  305. // ps = conn.prepareStatement(sql);
  306. // ps.setString(1, (long) ((Math.random()+1)*1000000000)+"");
  307. // ps.setString(2, list.get(0));
  308. // ps.setString(3,list.get(1));
  309. // ps.setString(4, list.get(2));
  310. // ps.setString(5, list.get(3));
  311. // ps.setString(6, list.get(4));
  312. // ps.setString(7, list.get(5));
  313. // ps.setString(8,list.get(6));
  314. // int k=ps.executeUpdate();
  315. // conn.commit();
  316. //// System.out.println("k====="+k);
  317. // return false;
  318. // }
  319. /**
  320. * 将界面传输过来的数据保存到数据库
  321. * @param params
  322. * @return
  323. * @throws ClassNotFoundException
  324. */
  325. @SuppressWarnings("static-access")
  326. @ProduceMime("application/json")
  327. @POST
  328. @Path("/teamToDb")
  329. public Msg expertToDb(String params) throws ClassNotFoundException{
  330. Msg m=new Msg();
  331. String json = Utils.getParameter("json", params) == null ? "" : Utils.getParameter(
  332. "json", params);
  333. log.info("json===" + json);
  334. String classId = Utils.getParameter("classId", params) == null ? "" : Utils
  335. .getParameter("classId", params);
  336. log.info("classId===" + classId);
  337. json=json.replace("_"+classId, "");
  338. Connection conn = null;
  339. PreparedStatement st = null;
  340. DbConnection db = new DbConnection();
  341. List<TeamBean> list = JsonPluginsUtil.jsonToBeanList(json, TeamBean.class);
  342. String sql="INSERT INTO ECM_AM_EMERGENCY_TEAM (FD_OBJECTID,TEAM_SYSTEM,TEAM_COMP_ID,TEAM_NAME,TEAM_TYPE,"
  343. + "TEAM_STAT,TEAM_AEAR,TEAM_ADDRESS,TEAM_LEADER,TEAM_TEL,TEAM_PHONE,TEAM_OFFICE_TEL,"
  344. + "TEAM_MEMBER_NUMBER,TEAM_MEMBER_INFO,TEAM_LEVEL,TEAM_SPECIALITY, "
  345. + "UPDATEDATE,IS_DEL) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  346. try {
  347. conn = db.getConnection();
  348. int num=0;
  349. conn.setAutoCommit(false);
  350. st = conn.prepareStatement(sql);
  351. for(int i=0;i<list.size();i++){
  352. TeamBean eb=list.get(i);
  353. log.info(" eb.getEXPERT_AREA()===="+ eb.getTEAM_AEAR());
  354. st.setString(1, createMsgId(getMsgId()));
  355. st.setString(2, eb.getTEAM_SYSTEM());
  356. st.setString(3, eb.getTEAM_COMP_ID());//队伍所属单位,以后要改成绑定登陆用户的单位id
  357. st.setString(4, eb.getTEAM_NAME());
  358. st.setString(5, eb.getTEAM_TYPE());
  359. st.setString(6, eb.getTEAM_STAT());
  360. st.setString(7, eb.getTEAM_AEAR());
  361. st.setString(8, eb.getTEAM_ADDRESS());
  362. st.setString(9, eb.getTEAM_LEADER());
  363. st.setString(10, eb.getTEAM_TEL());
  364. st.setString(11, eb.getTEAM_PHONE());
  365. st.setString(12, eb.getTEAM_OFFICE_TEL());
  366. st.setString(13, eb.getTEAM_MEMBER_NUMBER());
  367. // st.setString(14, eb.getTEAM_MEMBER_INFO());
  368. st.setString(15, eb.getTEAM_LEVEL());
  369. st.setString(16, eb.getTEAM_SPECIALITY());
  370. st.setString(17, formatDate(new Date()));
  371. st.setString(18, "0");
  372. st.executeUpdate();
  373. num++;
  374. }
  375. if(num==list.size()){
  376. log.info("保存成功");
  377. conn.commit();
  378. m.setSucsess(new Boolean(true).toString());
  379. m.setInfo(Parameter.DELETE_SUCSESS);
  380. return m;
  381. }else{
  382. m.setSucsess(new Boolean(false).toString());
  383. m.setInfo(Parameter.DELETE_FAILURE);
  384. // st.executeBatch();
  385. conn.rollback();
  386. log.info("保存失败");
  387. return m;
  388. }
  389. } catch (SQLException e) {
  390. this.log.error(e.getMessage(), e);
  391. throw new ClassNotFoundException("DAO Layou: 消息保存", e);
  392. } finally {
  393. db.close(st);
  394. db.close(conn);
  395. }
  396. }
  397. public String formatDate(Date d) {
  398. SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
  399. String date = sd.format(d);
  400. return date;
  401. }
  402. @SuppressWarnings({ "unchecked", "rawtypes" })
  403. public List<String> getMsgId() throws ClassNotFoundException {
  404. String sql = "SELECT FD_OBJECTID FROM ECM_AM_EMERGENCY_TEAM";
  405. Connection conn = null;
  406. Statement stat = null;
  407. ResultSet rs = null;
  408. DbConnection db = new DbConnection();
  409. try {
  410. conn = db.getConnection();
  411. stat = conn.createStatement();
  412. rs = stat.executeQuery(sql);
  413. List<String> list = new ArrayList();
  414. while (rs.next()) {
  415. list.add(rs.getString("FD_OBJECTID"));
  416. }
  417. return list;
  418. } catch (SQLException e) {
  419. // this.log.error(e.getMessage(), e);
  420. throw new ClassNotFoundException("DAO Layou: 获得数据库消息ID集合"
  421. + sql, e);
  422. } finally {
  423. db.close(rs);
  424. db.close(stat);
  425. db.close(conn);
  426. }
  427. }
  428. public String createMsgId(List<String> list) throws ClassNotFoundException{
  429. long l=(long) ((Math.random()+1)*1000000000);
  430. String msgId=l+"";
  431. if(list.contains(msgId)){
  432. return createMsgId(list);
  433. }
  434. else{
  435. // log.info("msgid==="+msgId);
  436. return msgId;
  437. }
  438. }
  439. @SuppressWarnings("unused")
  440. public String getRootTeam(String id){//获取本单位的树数据
  441. StringBuffer json=new StringBuffer();//应急预案的名称和ID
  442. String sql="SELECT FD_OBJECTID,PLAN_NAME FROM ECM_AM_YJYASERVER WHERE IS_DEL='0' AND UNITS ='"+id+"'";
  443. SysModel sysmodel = ModelFactory.getSysmodel();
  444. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  445. try {
  446. ArrayList<String[]> teamList = persistence.getSearchResult(99, sql.toString());
  447. int num = teamList.size();
  448. if (num > 0) {
  449. String selRootId=UUID.randomUUID()+"";
  450. for (int i = 0; i < num; i++) {
  451. String[] temp = teamList.get(i);
  452. String objectId = temp[0];
  453. String PLAN_NAME = temp[1];
  454. json.append("{");
  455. json.append(" \"id\":\"" + objectId + "\", \"parentId\":\""+selRootId
  456. + "\", \"name\": \"" + PLAN_NAME
  457. +"\", \"isParent\": \"false"
  458. +"\", \"open\": \"false"
  459. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/swf.gif\"");
  460. json.append("},");
  461. }
  462. // json.append("{");//增加本单位节点
  463. // json.append(" \"id\":\""+selRootId+"\", \"parentId\":\""+id
  464. // + "\", \"name\": \"本部"
  465. // +"\", \"isParent\": \"true"
  466. // +"\", \"open\": \"true"
  467. // + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  468. // json.append("},");
  469. }
  470. } catch (PersistenceException e) {
  471. log.error("查预案异常", e);
  472. }
  473. return json.toString();
  474. }
  475. public String getRootJson(String id){
  476. String sql="SELECT NAME FROM SYS_DEPARTMENT_0827 WHERE ID='"+id+"'";
  477. SysModel sysmodel = ModelFactory.getSysmodel();
  478. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  479. StringBuffer json=new StringBuffer();
  480. try {
  481. ArrayList<String[]> teamList = persistence.getSearchResult(99, sql.toString());
  482. int num = teamList.size();
  483. if (num > 0) {
  484. for (int i = 0; i < num; i++) {
  485. if(checkTeam(id)){
  486. String[] temp = teamList.get(i);
  487. String name=temp[0];
  488. json.append("{");//增加本单位节点
  489. json.append(" \"id\":\""+id+"\", \"parentId\":\"0"
  490. + "\", \"name\": \""+name
  491. +"\", \"isParent\": \"true"
  492. +"\", \"open\": \"true"
  493. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  494. json.append("},");
  495. }else{
  496. String[] temp = teamList.get(i);
  497. String name=temp[0];
  498. json.append("{");//增加本单位节点
  499. json.append(" \"id\":\""+id+"\", \"parentId\":\"0"
  500. + "\", \"name\": \""+name
  501. +"\", \"isParent\": \"false"
  502. +"\", \"open\": \"false"
  503. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  504. json.append("},");
  505. }
  506. }
  507. }
  508. }catch(Exception e){
  509. log.error("查询应急预案异常", e);
  510. }
  511. return json.toString();
  512. }
  513. @SuppressWarnings("unused")
  514. public String getChildJson(String id){
  515. StringBuffer json=new StringBuffer();
  516. SysModel sysmodel = ModelFactory.getSysmodel();
  517. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  518. String sql="SELECT ID,NAME FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"'";
  519. List<String>list=new ArrayList<String>();
  520. try {
  521. ArrayList<String[]> teamList = persistence.getSearchResult(99, sql.toString());
  522. int num = teamList.size();
  523. if (num > 0) {
  524. for (int i = 0; i < num; i++) {
  525. String[] temp = teamList.get(i);
  526. String name=temp[1];
  527. String comp_id=temp[0];
  528. if(checkTeam(comp_id)){
  529. json.append("{");//增加本单位节点
  530. json.append(" \"id\":\""+comp_id+"\", \"parentId\":\""+id
  531. + "\", \"name\": \""+name
  532. +"\", \"isParent\": \"true"
  533. +"\", \"open\": \"false"
  534. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  535. json.append("},");
  536. }
  537. // else{
  538. // json.append("{");//增加本单位节点
  539. // json.append(" \"id\":\""+comp_id+"\", \"parentId\":\""+id
  540. // + "\", \"name\": \""+name
  541. // +"\", \"isParent\": \"false"
  542. // +"\", \"open\": \"false"
  543. // + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\"");
  544. // json.append("},");
  545. // }
  546. }
  547. }
  548. }catch(Exception e){
  549. log.error("查询预案异常", e);
  550. }
  551. return json.toString();
  552. }
  553. public boolean checkTeam(String id){
  554. String sql="SELECT * FROM ECM_AM_EMERGENCY_TEAM WHERE TEAM_COMP_ID IN(SELECT ID FROM SYS_DEPARTMENT_0827 WHERE PARENT_ID='"+id+"') OR TEAM_COMP_ID='"+id+"'";
  555. SysModel sysmodel = ModelFactory.getSysmodel();
  556. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  557. try {
  558. ArrayList<String[]> teamList = persistence.getSearchResult(99, sql.toString());
  559. int num = teamList.size();
  560. if (num > 0) {
  561. return true;
  562. }
  563. }catch(Exception e){
  564. log.error("查询队伍异常", e);
  565. }
  566. return false;
  567. }
  568. @ProduceMime("application/json")
  569. @POST
  570. @Path("/getTeamByCompId/")
  571. public String getTeamByCompId(String params) {
  572. StringBuffer sb = new StringBuffer();
  573. log.info("传过来的参数 为"+params);
  574. boolean flag=false;
  575. sb.append("{\"treeNodes\":[");
  576. String deptid = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  577. "deptId", params);
  578. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  579. "id", params);
  580. if(id==null||"".equals(id)){
  581. id=deptid;
  582. flag=true;
  583. }
  584. if(flag){
  585. String root=getRootJson(id);
  586. sb.append(root);
  587. }
  588. String rootExpert=getRootTeam(id);
  589. sb.append(rootExpert);
  590. // String childList=getChildJson(id);
  591. // sb.append(childList);
  592. if (sb.lastIndexOf(",") > -1) {
  593. sb.deleteCharAt(sb.lastIndexOf(","));
  594. }
  595. sb.append("]}");
  596. log.info("json:" + sb);
  597. return sb.toString();
  598. }
  599. }