a6543c231b371316b7b3a595eede2aac8641f154.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /**
  2. *
  3. */
  4. package com.sinosoft.am.org.dept.indept.service;
  5. import java.util.ArrayList;
  6. import java.util.Iterator;
  7. import java.util.List;
  8. import javax.ws.rs.POST;
  9. import javax.ws.rs.Path;
  10. import javax.ws.rs.ProduceMime;
  11. import org.apache.log4j.Logger;
  12. import com.formaction.Parameter;
  13. import com.formaction.Utils;
  14. import com.formaction.vo.Msg;
  15. import com.persistence.service.PersistenceFactory;
  16. import com.persistence.service.SysPersistence;
  17. import com.persistence.service.exception.PersistenceException;
  18. import com.sinosoft.am.org.dept.indept.busi.PlanGlOrgBean;
  19. import com.sinosoft.am.org.dept.indept.dao.PlanGlOrgDao;
  20. import com.sinosoft.am.org.dept.indept.vo.PlanGlOrgVo;
  21. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  22. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  23. /**
  24. * @author 徐威
  25. * 2015-09-19
  26. * tel:13811395647
  27. */
  28. @Path("/PlanGlOrgService/")
  29. public class PlanGlOrgService{
  30. private Logger log = Logger.getLogger(this.getClass());
  31. /**
  32. * 根据部门异步加载下一级节点
  33. *
  34. * @param params
  35. * @return 部门树的所有一级子结构json对象
  36. */
  37. @ProduceMime("application/json")
  38. @POST
  39. @Path("/getDeptTreeByIdAsync/")
  40. public String getDeptTreeByIdAsync(String params) {
  41. // 转换参数deptId
  42. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  43. "deptId", params);
  44. log.info("deptId"+"****************"+deptId);
  45. StringBuffer sb = new StringBuffer();
  46. PlanGlOrgBean deptBean = new PlanGlOrgBean();
  47. String classId="211";
  48. // 根据部门Id获得其下的所有子部门
  49. sb.append("{\"treeNodes\":[");
  50. ArrayList<PlanGlOrgVo> list;
  51. try {
  52. list = deptBean.getInDeptVoByIdAsync(deptId);
  53. log.info("list"+"**************"+list.size());
  54. Iterator<PlanGlOrgVo> iter = list.iterator();
  55. while (iter.hasNext()) {
  56. PlanGlOrgVo dv = iter.next();
  57. sb.append("{");
  58. sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
  59. + "\", \"name\": \"" + dv.getNAME()
  60. +"\", \"classId\":\""+classId+"\", \"objectId\":\""+dv.getFD_OBJECTID()
  61. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
  62. + dv.getIS_VIRTUAL() + "\"");
  63. sb.append("},");
  64. }
  65. } catch (ClassNotFoundException e) {
  66. log.error("异步加载内部组织机构下一级部门出错", e);
  67. }
  68. // 去除多余逗号
  69. if (sb.lastIndexOf(",") > -1) {
  70. sb.deleteCharAt(sb.lastIndexOf(","));
  71. }
  72. sb.append("]}");
  73. log.info("json:" + sb);
  74. return sb.toString();
  75. }
  76. /**
  77. * 根据当前登录用户所属单位的ID获取当前根节点的信息
  78. *
  79. * @param params
  80. * @return
  81. */
  82. @ProduceMime("application/json")
  83. @POST
  84. @Path("/getDeptRootById/")
  85. public String getDeptRootById(String params) {
  86. StringBuffer sb = new StringBuffer();
  87. boolean flag=false;
  88. PlanGlOrgBean deptBean = new PlanGlOrgBean();
  89. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  90. "id", params);
  91. if("".equals(id)){
  92. flag =true;
  93. id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  94. "deptId", params);
  95. }
  96. log.info("传过来的参数 为"+params);
  97. log.info("根据用户获得的部门Id= "+id);
  98. sb.append("{\"treeNodes\":[");
  99. PlanGlOrgVo dv;
  100. try {
  101. if(flag){
  102. dv = deptBean.getDeptRootById(id);
  103. sb.append("{");
  104. sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
  105. + "\", \"name\": \"" + dv.getNAME()
  106. +"\", \"isParent\": \"true"
  107. +"\", \"open\": \"true"
  108. +"\", \"nocheck\": \"true"
  109. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
  110. + dv.getIS_VIRTUAL() + "\"");
  111. sb.append("},");
  112. if(checkInLink(id)){
  113. //该单位下如果有人,加载该单位下人员的数据。
  114. PlanGlOrgDao pgd = new PlanGlOrgDao();
  115. sb.append(pgd.getPersonJson(id));
  116. }
  117. }
  118. // 去除多余的逗号
  119. else{if(checkId(id)||checkInLink(id)){
  120. List<String>childList=new ArrayList<String>();
  121. childList=getChildList(id);
  122. for(int i=0;i<childList.size();i++){
  123. PlanGlOrgVo dvo=new PlanGlOrgVo();
  124. dvo=deptBean.getDeptRootById(childList.get(i));
  125. log.info("*****dvo===================****"+childList.size());
  126. sb.append("{");
  127. sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
  128. + "\", \"name\": \"" + dvo.getNAME()
  129. +"\", \"isParent\": \"true"
  130. +"\", \"nocheck\": \"true"
  131. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
  132. + dvo.getIS_VIRTUAL() + "\"");
  133. sb.append("},");
  134. }
  135. if(checkInLink(id)){
  136. //该单位下如果有人,加载该单位下人员的数据。
  137. PlanGlOrgDao pgd = new PlanGlOrgDao();
  138. sb.append(pgd.getPersonJson(id));
  139. }
  140. }}
  141. if (sb.lastIndexOf(",") > -1) {
  142. sb.deleteCharAt(sb.lastIndexOf(","));
  143. }
  144. sb.append("]}");
  145. log.info("json:" + sb);
  146. return sb.toString();
  147. } catch (Exception e) {
  148. log.error("查询内部组织机构根节点错误", e);
  149. }
  150. return null;
  151. }
  152. /**
  153. * 根据当前登录用户所属单位的ID获取上级单位根节点的信息
  154. *
  155. * @param params
  156. * @return
  157. */
  158. @ProduceMime("application/json")
  159. @POST
  160. @Path("/getDeptById/")
  161. public String getDeptById(String params) {
  162. StringBuffer sb = new StringBuffer();
  163. PlanGlOrgBean deptBean = new PlanGlOrgBean();
  164. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  165. "id", params);
  166. if("".equals(id)){
  167. id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  168. "deptId", params);
  169. }
  170. log.info("传过来的参数 为"+params);
  171. log.info("根据用户获得的部门Id= "+id);
  172. sb.append("{\"treeNodes\":[");
  173. PlanGlOrgVo dv;
  174. try {
  175. dv = deptBean.getDeptRootById(id);
  176. sb.append("{");
  177. sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
  178. + "\", \"name\": \"" + dv.getNAME()
  179. +"\", \"isParent\": \"true"
  180. +"\", \"open\": \"true"
  181. +"\", \"nocheck\": \"true"
  182. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\", \"isV\":\""
  183. + dv.getIS_VIRTUAL() + "\"");
  184. sb.append("},");
  185. // 去除多余的逗号
  186. if(checkId(id)){
  187. List<String>childList=new ArrayList<String>();
  188. childList=getChildList(id);
  189. for(int i=0;i<childList.size();i++){
  190. PlanGlOrgVo dvo=new PlanGlOrgVo();
  191. dvo=deptBean.getDeptRootById(childList.get(i));
  192. log.info("*****dvo=====****"+dvo);
  193. sb.append("{");
  194. sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
  195. + "\", \"name\": \"" + dvo.getNAME()
  196. +"\", \"isParent\": \"false"
  197. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.png\", \"isV\":\""
  198. + dvo.getIS_VIRTUAL() + "\"");
  199. sb.append("},");
  200. }
  201. }
  202. if (sb.lastIndexOf(",") > -1) {
  203. sb.deleteCharAt(sb.lastIndexOf(","));
  204. }
  205. sb.append("]}");
  206. log.info("json:" + sb);
  207. return sb.toString();
  208. } catch (Exception e) {
  209. log.error("查询内部组织机构根节点错误", e);
  210. }
  211. return null;
  212. }
  213. /**
  214. * 根据当前登录用户所属单位的ID获取上级单位根节点的信息
  215. *
  216. * @param params
  217. * @return
  218. */
  219. @ProduceMime("application/json")
  220. @POST
  221. @Path("/getDeptByIdDeptId/")
  222. public String getDeptByIdDeptId(String params) {
  223. StringBuffer sb = new StringBuffer();
  224. PlanGlOrgBean deptBean = new PlanGlOrgBean();
  225. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  226. "id", params);
  227. if("".equals(id)){
  228. id= Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  229. "deptId", params);
  230. }
  231. log.info("传过来的参数 为"+params);
  232. log.info("根据用户获得的部门Id= "+id);
  233. sb.append("{\"treeNodes\":[");
  234. PlanGlOrgVo dv;
  235. try {
  236. dv = deptBean.getDeptRootById(id);
  237. sb.append("{");
  238. sb.append(" \"id\":\"" + dv.getID() + "\", \"parentId\":\"" + dv.getPARENT_ID()
  239. + "\", \"name\": \"" + dv.getNAME()
  240. +"\", \"isParent\": \"true"
  241. +"\", \"open\": \"true"
  242. +"\", \"nocheck\": \"true"
  243. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
  244. + dv.getIS_VIRTUAL() + "\"");
  245. sb.append("},");
  246. // 去除多余的逗号
  247. if(checkIdDeptID(id)){
  248. List<String>getChildDeptList=new ArrayList<String>();
  249. getChildDeptList=getChildList(id);
  250. for(int i=0;i<getChildDeptList.size();i++){
  251. PlanGlOrgVo dvo=new PlanGlOrgVo();
  252. dvo=deptBean.getDeptRootById(getChildDeptList.get(i));
  253. log.info("*****dvo=====****"+dvo);
  254. sb.append("{");
  255. sb.append(" \"id\":\"" + dvo.getID() + "\", \"parentId\":\"" + dvo.getPARENT_ID()
  256. + "\", \"name\": \"" + dvo.getNAME()
  257. +"\", \"isParent\": \"false"
  258. + "\", \"icon\":\"/nwyj/scripts/qui/libs/icons/home.gif\", \"isV\":\""
  259. + dvo.getIS_VIRTUAL() + "\"");
  260. sb.append("},");
  261. }
  262. }
  263. if (sb.lastIndexOf(",") > -1) {
  264. sb.deleteCharAt(sb.lastIndexOf(","));
  265. }
  266. sb.append("]}");
  267. log.info("json:" + sb);
  268. return sb.toString();
  269. } catch (Exception e) {
  270. log.error("查询内部组织机构根节点错误", e);
  271. }
  272. return null;
  273. }
  274. /**
  275. * 查询当前单位下面的子节点(部门或下属单位)
  276. * 返回的是一个List,里面放着的是部门ID
  277. *
  278. * */
  279. public List<String> getChildList(String id){
  280. SysModel sysmodel = ModelFactory.getSysmodel();
  281. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  282. // String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0'";
  283. String sql="select * from V_DEPARTMENT where parent_id='"+id+"' AND IS_DEL='0' AND (ORG_NAME LIKE '%供电局%' OR ORG_NAME LIKE '%电网公司')";
  284. try {
  285. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  286. //循环遍历返回的ArrayLiist,判断下面是否有人,有人可以判断为部门。没有人可以判断为单位
  287. if(list==null||list.size()==0){
  288. return new ArrayList<String>();
  289. }else{
  290. List<String>tempList=new ArrayList<String>();
  291. for(int i=0;i<list.size();i++){
  292. tempList.add(list.get(i)[0]);
  293. }
  294. return tempList;
  295. }
  296. } catch (PersistenceException e) {
  297. // TODO Auto-generated catch block
  298. e.printStackTrace();
  299. return new ArrayList<String>();
  300. }
  301. }
  302. //查询当前部门是否有子部门加载人的时候所用
  303. public boolean checkId(String id){
  304. SysModel sysmodel = ModelFactory.getSysmodel();
  305. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  306. String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL='1' AND IS_DEL='0'";
  307. try {
  308. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  309. if(list==null||list.size()==0){
  310. return false;
  311. }else{
  312. return true;
  313. }
  314. } catch (PersistenceException e) {
  315. // TODO Auto-generated catch block
  316. e.printStackTrace();
  317. return false;
  318. }
  319. }
  320. //查询当前部门是否有子部门加载单位的时候所用
  321. public boolean checkIdDeptID(String id){
  322. SysModel sysmodel = ModelFactory.getSysmodel();
  323. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  324. String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL!='1' AND IS_DEL='0'";
  325. try {
  326. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  327. if(list==null||list.size()==0){
  328. return false;
  329. }else{
  330. return true;
  331. }
  332. } catch (PersistenceException e) {
  333. // TODO Auto-generated catch block
  334. e.printStackTrace();
  335. return false;
  336. }
  337. }
  338. /**
  339. * 查询当前单位下面的子节点(部门或下属单位)
  340. * 返回的是一个List,里面放着的是部门ID
  341. *
  342. * */
  343. public List<String> getChildDeptList(String id){
  344. SysModel sysmodel = ModelFactory.getSysmodel();
  345. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  346. String sql="select * from EMC_AM_ORG_DEPARTMENT_TEST where parent_id='"+id+"' AND IS_VIRTUAL!='1' AND IS_DEL='0'";
  347. try {
  348. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  349. //循环遍历返回的ArrayLiist,判断下面是否有人,有人可以判断为部门。没有人可以判断为单位
  350. if(list==null||list.size()==0){
  351. return new ArrayList<String>();
  352. }else{
  353. List<String>tempList=new ArrayList<String>();
  354. for(int i=0;i<list.size();i++){
  355. tempList.add(list.get(i)[0]);
  356. }
  357. return tempList;
  358. }
  359. } catch (PersistenceException e) {
  360. // TODO Auto-generated catch block
  361. e.printStackTrace();
  362. return new ArrayList<String>();
  363. }
  364. }
  365. //查询该ID在人员信息表里是否有人
  366. public boolean checkInLink(String id){
  367. SysModel sysmodel = ModelFactory.getSysmodel();
  368. SysPersistence persistence = PersistenceFactory.getInstance(sysmodel);
  369. //查询该ID在人员信息表里是否有人
  370. String sql="SELECT * FROM EMC_AM_ORG_INLINK WHERE VIRTUAL_ORG_ID='"+id+"'";
  371. try {
  372. ArrayList<String[]> list = persistence.getSearchResult(99, sql.toString());
  373. if(list==null||list.size()==0){
  374. return false;
  375. }else{
  376. return true;
  377. }
  378. } catch (PersistenceException e) {
  379. // TODO Auto-generated catch block
  380. e.printStackTrace();
  381. return false;
  382. }
  383. }
  384. @ProduceMime("application/json")
  385. @POST
  386. @Path("/addOrgInDept")
  387. public String addOrgInDept(String params){
  388. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  389. "deptId", params);
  390. String parentId = Utils.getParameter("parentId", params) == null ? "" : Utils.getParameter(
  391. "parentId", params);
  392. String deptName = Utils.getParameter("deptName", params) == null ? "" : Utils.getParameter(
  393. "deptName", params);
  394. StringBuffer sb = new StringBuffer();
  395. log.info(deptId + "-------------------deptId");
  396. log.info(parentId + "-------------------parentId");
  397. log.info(deptName + "-------------------deptName");
  398. PlanGlOrgBean ob = new PlanGlOrgBean();
  399. if (ob.addOrgInDept(deptId, parentId, deptName)) {
  400. sb.append("{\"msg\":\"success\"}");
  401. } else {
  402. sb.append("{\"msg\":\"fail\"}");
  403. }
  404. return sb.toString();
  405. }
  406. @ProduceMime("application/json")
  407. @POST
  408. @Path("/shamDeleteOrgInDept")
  409. public String shamDeleteOrgInDept(String params){
  410. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  411. "deptId", params);
  412. log.info("要移出的外部机构Id="+deptId);
  413. StringBuffer sb = new StringBuffer();
  414. PlanGlOrgBean ob = new PlanGlOrgBean();
  415. boolean canDelete =ob.shamDeleteOrgInDept(deptId);
  416. if (canDelete) {
  417. sb.append("{\"msg\":\"success\"}");
  418. } else if(!canDelete){
  419. sb.append("{\"msg\":\"fail\"}");
  420. }
  421. return sb.toString();
  422. }
  423. @ProduceMime("application/json")
  424. @POST
  425. @Path("/getInOrgDoubleTree")
  426. public String getInOrgTree(String params) throws Exception{
  427. String json="";
  428. String comp_id=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter(
  429. "comId", params);
  430. String type=Utils.getParameter("type", params) == null ? "" : Utils.getParameter(
  431. "type", params);
  432. log.info("compId===="+comp_id);
  433. if(!"".equals(comp_id)){
  434. PlanGlOrgDao odd=new PlanGlOrgDao();
  435. json=odd.getInOrgTree(comp_id, type);
  436. }
  437. return json;
  438. }
  439. /**加载双向选择树*/
  440. @ProduceMime("application/json")
  441. @POST
  442. @Path("/getDoubleTree")
  443. public String getDoubleTree(String params) throws Exception{
  444. String json="";
  445. String comp_id=Utils.getParameter("comId", params) == null ? "" : Utils.getParameter(
  446. "comId", params);
  447. log.info("comp_id===="+comp_id);
  448. if(!"".equals(comp_id)){
  449. PlanGlOrgDao odd=new PlanGlOrgDao();
  450. json=odd.getDoubleTreeRoot(comp_id);
  451. }
  452. return json;
  453. }
  454. @ProduceMime("application/json")
  455. @POST
  456. @Path("/saveInLinkUser")
  457. public Msg saveInLinkUser(String params) throws ClassNotFoundException{
  458. Msg m=new Msg();
  459. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  460. "id", params);
  461. String deptId = Utils.getParameter("deptId", params) == null ? "" : Utils.getParameter(
  462. "deptId", params);
  463. String deptName = Utils.getParameter("deptName", params) == null ? "" : Utils.getParameter(
  464. "deptName", params);
  465. String orgName = Utils.getParameter("orgName", params) == null ? "" : Utils.getParameter(
  466. "orgName", params);
  467. String orgId = Utils.getParameter("orgId", params) == null ? "" : Utils.getParameter(
  468. "orgId", params);
  469. log.info(params);
  470. if(!"".equals(id)){
  471. PlanGlOrgDao odd=new PlanGlOrgDao();
  472. m=odd.saveOrg(id, deptId, deptName, orgName, orgId);
  473. }else{
  474. m.setSucsess(new Boolean(false).toString());
  475. m.setInfo(Parameter.CREATE_FAILURE);
  476. }
  477. return m;
  478. }
  479. @ProduceMime("application/json")
  480. @POST
  481. @Path("/saveExpertInfo")
  482. public Msg saveExpertInfo(String params) throws Exception{
  483. Msg m=new Msg();
  484. String id = Utils.getParameter("id", params) == null ? "" : Utils.getParameter(
  485. "id", params);
  486. if(!"".equals(id)){
  487. PlanGlOrgDao addExpert=new PlanGlOrgDao();
  488. m=addExpert.saveExpert(id);
  489. }else{
  490. m.setSucsess(new Boolean(false).toString());
  491. m.setInfo(Parameter.CREATE_FAILURE);
  492. }
  493. return m;
  494. }
  495. }