personSycnV1.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * resources.getEntityManagerContainer() // 实体管理容器.
  3. * resources.getContext() //上下文根.
  4. * resources.getOrganization() //组织访问接口.
  5. * requestText //请求内容.
  6. * request //请求对象.
  7. */
  8. /*
  9. {
  10. "action": "add",
  11. "genderType": "m",
  12. "signature": "",
  13. "description": "",
  14. "name": "",
  15. "employee": "",
  16. "unique": "",
  17. "distinguishedName": "",
  18. "orderNumber": "",
  19. "controllerList": "",
  20. "superior": "",
  21. "mail": "",
  22. "weixin": "",
  23. "qq": "",
  24. "mobile": "",
  25. "officePhone": "",
  26. "boardDate": "",
  27. "birthday": "",
  28. "age": "",
  29. "dingdingId": "",
  30. "dingdingHash": "",
  31. "attributeList": [
  32. {
  33. "name": "",
  34. "value": "",
  35. "description": "",
  36. "orderNumber": ""
  37. }
  38. ],
  39. "unitList": [
  40. {
  41. "flag": "",
  42. "orderNumber": "",
  43. "description": "",
  44. "duty": "",
  45. "position": ""
  46. }
  47. ]
  48. }
  49. */
  50. print("运行人员同步接口");
  51. var File = Java.type('java.io.File');
  52. var Config = {
  53. localPath : File.separator + "data" + File.separator + "OrganizationSyncRequest" + File.separator + "person" + File.separator
  54. };
  55. var applications = resources.getContext().applications();
  56. var archiveFlag = false;
  57. var Utils = {
  58. getUserFlag : function( json ){
  59. return json.flag || json.distinguishedName || json.unique || json.employee || json.mobile || json.id;
  60. },
  61. getKeyEqualObjFromArray : function( sourceArray, sourceKey, value ){
  62. for( var i=0; i<sourceArray.length; i++ ){
  63. if( sourceArray[i][sourceKey] === value ){
  64. return sourceArray[i];
  65. }
  66. }
  67. return null;
  68. },
  69. parseResp : function( resp ){
  70. if( !resp || resp === null ){
  71. return {
  72. "type": "error",
  73. message : "服务响应是null,需要管理员查看后台日志"
  74. }
  75. }else{
  76. var json = JSON.parse( resp.toString() );
  77. return json;
  78. }
  79. },
  80. getFailText : function( json ){
  81. //{
  82. // "type": "error",
  83. // "message": "手机号错误:15268803358, 手机号已有值重复.",
  84. // "date": "2018-08-05 02:51:35",
  85. // "spent": 5,
  86. // "size": -1,
  87. // "count": 0,
  88. // "position": 0,
  89. // "prompt": "com.x.organization.assemble.control.jaxrs.person.ExceptionMobileDuplicate"
  90. //}
  91. var text;
  92. if( json.message ){
  93. text = json.message + ( json.prompt ? "("+json.prompt + ")" : "" );
  94. }else if( json.prompt ){
  95. text = json.prompt;
  96. }else{
  97. text = "未知异常";
  98. }
  99. print(text);
  100. return text;
  101. },
  102. processError : function( e, text ){
  103. e.printStackTrace();
  104. var errorText = text + " " + e.name + ": " + e.message;
  105. print(errorText);
  106. return errorText;
  107. },
  108. arrayIndexOf : function( array, target ){
  109. for( var i=0; i<array.length; i++ ){
  110. if( array[i] == target )return i;
  111. }
  112. return -1;
  113. },
  114. objectClone : function (obj) {
  115. if (null == obj || "object" != typeof obj) return obj;
  116. if ( typeof obj.length==='number'){ //数组
  117. var copy = [];
  118. for (var i = 0, len = obj.length; i < len; ++i) {
  119. copy[i] = Utils.objectClone(obj[i]);
  120. }
  121. return copy;
  122. }else{
  123. var copy = {};
  124. for (var attr in obj) {
  125. copy[attr] = Utils.objectClone(obj[attr]);
  126. }
  127. return copy;
  128. }
  129. },
  130. saveToLocal : function( json ){
  131. if( json.saveFlag && json.saveFlag == "no" ){
  132. print( "不保存文件" );
  133. return;
  134. }
  135. print( "保存文件开始" );
  136. if( File == null )File = Java.type('java.io.File');
  137. var dir = new File( Config.localPath );
  138. if (!dir.exists()) {
  139. if(!dir.mkdirs()){
  140. print( "创建文件夹失败:"+ recordPath );
  141. return null;
  142. }
  143. }
  144. //var Date = Java.type( "java.util.Date" );
  145. //var now = new Date();
  146. //var nowStr = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(now);
  147. var name = json.name ? json.name : Utils.getUserFlag(json);
  148. var unique = json.unique ? json.unique : "";
  149. var path = Config.localPath + name + '_' + unique + '.json';
  150. var file = new File(path);
  151. if (file.exists()) { // 如果已存在,删除旧文件
  152. file.delete();
  153. }
  154. if(!file.createNewFile()){
  155. print("不能创建文件:"+path);
  156. return null;
  157. }
  158. var pw = new java.io.PrintWriter(file, "GBK");
  159. pw.write( JSON.stringify(json) );
  160. pw.close();
  161. print( "保存文件结束 path="+path );
  162. }
  163. };
  164. var AttributeAction = {
  165. add :function( flag, data ){
  166. //name string single 属性名称 级别
  167. //description string single 属性描述 级别描述
  168. //value string/array multi 属性值 1 / [ "1" ]
  169. //orderNumber string single 排序号,升序排列,为空在最后 18315158
  170. data.person = flag;
  171. var valueList = typeof( data.value ) == "string" ? [data.value] : data.value;
  172. for( var i=0; i<valueList.length; i++ ){
  173. valueList[i] = valueList[i].replace("@","-");
  174. }
  175. data.attributeList = valueList;
  176. try {
  177. var resp = applications.postQuery('x_organization_assemble_control', 'personattribute', JSON.stringify( data ));
  178. var json = Utils.parseResp( resp );
  179. if( json.type && json.type == "success" ){
  180. return "";
  181. }else{
  182. return Utils.getFailText( json );
  183. }
  184. }catch(e){
  185. return Utils.processError( e, "新增用户属性AttributeAction.add() 出错: " );
  186. }
  187. },
  188. remove : function( data ){
  189. try {
  190. var resp = applications.deleteQuery('x_organization_assemble_control', 'personattribute/'+data.id );
  191. var json = Utils.parseResp( resp );
  192. if( json.type && json.type == "success" ){
  193. return "";
  194. }else{
  195. return Utils.getFailText( json );
  196. }
  197. }catch(e){
  198. return Utils.processError( e, "删除用户属性AttributeAction.remove() 出错: " );
  199. }
  200. },
  201. update : function( flag, data_new, data_old ){
  202. for( var key in data_new ){
  203. if( key != "distinguishedName" ){
  204. data_old[key] = data_new[key];
  205. }
  206. }
  207. data_old.person = flag;
  208. data_old.attributeList = typeof( data_new.value ) == "string" ? [data_new.value] : data_new.value;
  209. try {
  210. var resp = applications.putQuery('x_organization_assemble_control', 'personattribute/'+data_old.id, JSON.stringify(data_old) );
  211. var json = Utils.parseResp( resp );
  212. if( json.type && json.type == "success" ){
  213. return "";
  214. }else{
  215. return Utils.getFailText( json );
  216. }
  217. }catch(e){
  218. return Utils.processError( e, "修改用户属性AttributeAction.update() 出错: " );
  219. }
  220. },
  221. compare : function( json ){
  222. var attribute_new = json.attributeList; //传入的用户属性
  223. var errorText = "";
  224. var flag = Utils.getUserFlag( json );
  225. if( flag ){
  226. try{
  227. var resp = applications.getQuery('x_organization_assemble_control', 'personattribute/list/person/'+flag );
  228. var json_attribute_old = Utils.parseResp( resp );
  229. var attribute_old;
  230. if( json_attribute_old.type && json_attribute_old.type == "success" ){
  231. attribute_old = json_attribute_old.data;
  232. }else{
  233. attribute_old = [];
  234. //return Utils.getFailText(json_attribute_old);
  235. }
  236. for( var i=0; i<attribute_old.length; i++ ){
  237. var obj_new = Utils.getKeyEqualObjFromArray( attribute_new, "name", attribute_old[i].name );
  238. if( obj_new == null ){ //老的不在了,要删除
  239. errorText = AttributeAction.remove( attribute_old[i] )
  240. }else{ //已经存在,要修改
  241. errorText = AttributeAction.update( flag, obj_new, attribute_old[i] );
  242. }
  243. }
  244. for( var i=0; i<attribute_new.length; i++ ){
  245. var obj_old = Utils.getKeyEqualObjFromArray( attribute_old, "name", attribute_new[i].name );
  246. if( obj_old == null ){ //需要新增
  247. errorText = AttributeAction.add( flag, attribute_new[i] );
  248. }
  249. }
  250. return errorText;
  251. }catch(e){
  252. return Utils.processError( e, "修改用户属性AttributeAction.compare() 出错: " );
  253. }
  254. }
  255. }
  256. };
  257. var IdentityAction = {
  258. add :function( flag, unit, personName, ignoreFlag ){
  259. //flag: "", //组织唯一编码unique/组织的distinguishedName/组织id
  260. // orderNumber: "", //在组织里的排序号,升序排列,为空在最后
  261. // description: "", //描述
  262. // duty : "", //用户在该组织的职务
  263. // position : "" //用户在该组织的岗位
  264. var data = {
  265. name : personName,
  266. person : flag,
  267. unit : unit.flag,
  268. description : unit.description
  269. };
  270. try {
  271. var resp = applications.postQuery('x_organization_assemble_control', 'identity', JSON.stringify( data ));
  272. var json = Utils.parseResp( resp );
  273. if( json.type === "success" ){
  274. return "";
  275. }else{
  276. if( ignoreFlag != "no" ){
  277. archiveFlag = true;
  278. }else{
  279. return Utils.getFailText( json );
  280. }
  281. //if( json.prompt == "com.x.organization.assemble.control.jaxrs.identity.ExceptionUnitNotExist" ){ //组织不存在,创建组织
  282. //var u_data = { name : unit.flag, unique : unit.flag };
  283. //var json = Utils.parseResp( applications.postQuery('x_organization_assemble_control', 'unit', JSON.stringify( u_data )));
  284. //if( json.type == "success" ){
  285. // return IdentityAction.add( flag, unit );
  286. //}
  287. //}else{
  288. // return Utils.getFailText( json );
  289. //}
  290. }
  291. return "";
  292. }catch(e){
  293. return Utils.processError( e, "新增用户身份IdentityAction.add() 出错: " );
  294. }
  295. },
  296. remove : function( data ){
  297. try {
  298. var resp = applications.deleteQuery('x_organization_assemble_control', 'identity/'+data.id );
  299. var json = Utils.parseResp( resp );
  300. if( json.type && json.type == "success" ){
  301. return "";
  302. }else{
  303. return Utils.getFailText( json );
  304. }
  305. }catch(e){
  306. return Utils.processError( e, "删除用户身份IdentityAction.remove() 出错: " );
  307. }
  308. },
  309. update : function( identity, unit_new, unit_old ){
  310. //flag: "", //组织唯一编码unique/组织的distinguishedName/组织id
  311. // orderNumber: "", //在组织里的排序号,升序排列,为空在最后
  312. // description: "", //描述
  313. // duty : "", //用户在该组织的职务
  314. // position : "" //用户在该组织的岗位
  315. if( identity.orderNumber != unit_new.orderNumber || identity.description != unit_new.description ){
  316. identity.orderNumber = unit_new.orderNumber;
  317. identity.description = unit_new.description;
  318. try {
  319. var resp = applications.putQuery('x_organization_assemble_control', 'identity/'+identity.id, JSON.stringify(identity) );
  320. var json = Utils.parseResp( resp );
  321. if( json.type && json.type == "success" ){
  322. return "";
  323. }else{
  324. return Utils.getFailText( json );
  325. }
  326. }catch(e){
  327. return Utils.processError( e, "修改用户身份IdentityAction.update() 出错: " );
  328. }
  329. }
  330. },
  331. compare : function( json ){
  332. var errorText = "";
  333. var unit_new = json.unitList; //传入的用户所在部门
  334. var flag = Utils.getUserFlag( json );
  335. if( !flag )return "修改用户身份IdentityAction.compare() 出错: 未能找到用户标志";
  336. try{
  337. var resp = applications.getQuery('x_organization_assemble_control', 'identity/list/person/'+flag );
  338. var json_identityList = Utils.parseResp( resp );
  339. var identityList;
  340. if( json_identityList.type == "success" ){
  341. identityList = json_identityList.data || [];
  342. }else{
  343. identityList = [];
  344. //return Utils.getFailText( json_identityList );
  345. }
  346. var req = {"personList":[flag]};
  347. var unitResq = applications.postQuery('x_organization_assemble_express', 'unit/list/person/object', JSON.stringify( req ) );
  348. var json_unit_old = Utils.parseResp( unitResq );
  349. var unit_old;
  350. if( json_unit_old.type == "success" ){
  351. unit_old = json_unit_old.data || [];
  352. }else{
  353. return Utils.getFailText( json_unit_old );
  354. }
  355. for( var i=0; i<unit_old.length; i++ ){
  356. var obj_new = IdentityAction.getEqualUnitFromArray( unit_new, unit_old[i] );
  357. if( obj_new == null ){ //老的不在了,要删除
  358. print("删除身份");
  359. var identity = IdentityAction.getIdentityByUnit( identityList, unit_old[i] );
  360. errorText = IdentityAction.remove( identity )
  361. }else{ //已经存在,要修改
  362. print("修改身份");
  363. var identity = IdentityAction.getIdentityByUnit( identityList, unit_old[i] );
  364. errorText = IdentityAction.update( identity, obj_new, unit_old[i] );
  365. }
  366. }
  367. for( var i=0; i<unit_new.length; i++ ){
  368. if( !unit_new[i].flag || unit_new[i].flag == "" )continue;
  369. var obj_old = IdentityAction.getEqualUnitFromArray( unit_old, unit_new[i] );
  370. if( obj_old == null ){ //需要新增
  371. print("新增身份");
  372. errorText = IdentityAction.add( flag, unit_new[i], json.name, json.ignoreFlag );
  373. }
  374. }
  375. return errorText;
  376. }catch(e){
  377. return Utils.processError( e, "修改用户身份IdentityAction.compare() 出错: " );
  378. }
  379. },
  380. getIdentityByUnit: function(identityList, unit){
  381. for( var i = 0; i<identityList.length; i++ ){
  382. var identity = identityList[i];
  383. if( identity.unitLevelName === unit.levelName ){
  384. return identity;
  385. }
  386. }
  387. },
  388. getEqualUnitFromArray : function( sourceUnitArray, targetUnit ){
  389. for( var i=0; i<sourceUnitArray.length; i++ ){
  390. if( IdentityAction.unitEquals( sourceUnitArray[i], targetUnit ) ){
  391. return sourceUnitArray[i];
  392. }
  393. }
  394. return null;
  395. },
  396. unitEquals: function( source, target ) {
  397. if (target.flag && (Utils.arrayIndexOf([source.flag, source.unique, source.distinguishedName, source.levelName, source.id], target.flag) > -1))return true;
  398. if (source.flag && (Utils.arrayIndexOf([target.flag, target.unique, target.distinguishedName, target.levelName, target.id], source.flag) > -1))return true;
  399. if (target.id && target.id == source.id)return true;
  400. if (target.unique && target.unique == source.unique)return true;
  401. if (target.distinguishedName && target.distinguishedName == source.distinguishedName)return true;
  402. if (target.levelName && target.levelName == source.levelName)return true;
  403. return false;
  404. }
  405. };
  406. function get( json ){
  407. var errorText = "";
  408. var flag = Utils.getUserFlag(json);
  409. var resp;
  410. var person_old;
  411. if( flag ){
  412. try{
  413. resp = applications.getQuery('x_organization_assemble_control', "person/"+flag ); //先获取人员信息
  414. var json_old = Utils.parseResp( resp );
  415. if( json_old.type && json_old.type == "success" ){
  416. person_old = json_old.data;
  417. }else{
  418. return Utils.getFailText( json_old );
  419. }
  420. }catch(e){
  421. return Utils.processError( e, "get() 出错: " );
  422. }
  423. delete person_old.woIdentityList;
  424. delete person_old.woRoleList;
  425. delete person_old.woGroupList;
  426. delete person_old.woPersonAttributeList;
  427. //delete person_old.control;
  428. //delete person_old.controllerList;
  429. return person_old;
  430. //applications.putQuery('x_organization_assemble_control', "person/"+json.unique, json );
  431. }else{
  432. errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户";
  433. print(errorText);
  434. return errorText;
  435. }
  436. }
  437. function add( requestJson ){
  438. print("添加个人");
  439. var json = Utils.objectClone(requestJson);
  440. var errorText;
  441. var response;
  442. var resp;
  443. try{
  444. if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在
  445. var superiorData = get({ flag : json.superior });
  446. if( typeof( superiorData ) != "object" ){ //不在则新建
  447. archiveFlag = true;
  448. delete json.superior;
  449. }
  450. }
  451. var personData = get(json);
  452. if( typeof personData == "object" ){
  453. if( json.forceFlag && json.forceFlag == "yes" ){
  454. for( var key in json){
  455. if( key !== "action" && key !== "attributeList" && key !== "unitList" ){
  456. if( key == "orderNumber" && (!json[key] || json[key]=="") ){
  457. }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){
  458. }else{
  459. personData[key] = json[key];
  460. }
  461. }
  462. }
  463. if( !personData.controllerList || personData.controllerList == null )personData.controllerList = [];
  464. resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) )
  465. }else{
  466. errorText = "人员“"+ Utils.getUserFlag(json) +"”已经在系统内存在";
  467. }
  468. }else{
  469. if( json.controllerList === null )json.controllerList = [];
  470. var data = Utils.objectClone(json);
  471. if(data.attributeList)delete data.attributeList;
  472. if(data.unitList)delete data.unitList;
  473. data.controllerList = [];
  474. resp = applications.postQuery( "x_organization_assemble_control", 'person', JSON.stringify(data));
  475. }
  476. if( resp && !errorText ){
  477. response = Utils.parseResp( resp );
  478. if( response.type && response.type == "success" ){
  479. if( !json.attributeList )json.attributeList = [];
  480. errorText = AttributeAction.compare( json );
  481. if( !json.unitList )json.unitList = [];
  482. errorText = IdentityAction.compare( json );
  483. }else{
  484. errorText = Utils.getFailText( response );
  485. }
  486. }
  487. if( archiveFlag && !errorText ){
  488. Utils.saveToLocal( requestJson ); //保存到本地
  489. }
  490. }catch(e){
  491. errorText = Utils.processError( e, "添加个人 add() 出错:" );
  492. }finally{
  493. var result = {
  494. "result" : errorText ? "error" : "success",
  495. "description" : errorText || ""
  496. };
  497. if( response && response.data ){
  498. result.id = response.data.id;
  499. }
  500. return result;
  501. }
  502. }
  503. function update(requestJson){
  504. print("修改个人");
  505. var json = Utils.objectClone(requestJson);
  506. var errorText;
  507. var response;
  508. try{
  509. if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在
  510. var superiorData = get({ flag : json.superior });
  511. if( typeof( superiorData ) != "object" ){ //不在则新建
  512. archiveFlag = true;
  513. delete json.superior;
  514. }
  515. }
  516. var personData = get(json);
  517. if( typeof personData == "object" ){
  518. for( var key in json){
  519. if( key !== "action" && key !== "attributeList" && key !== "unitList" ){
  520. if( key == "orderNumber" && (!json[key] || json[key]=="") ){
  521. }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){
  522. }else{
  523. personData[key] = json[key];
  524. }
  525. }
  526. }
  527. if( !personData.controllerList || personData.controllerList == null )personData.controllerList = [];
  528. var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) );
  529. var response = Utils.parseResp( resp );
  530. if( response.type && response.type == "success" ){
  531. if( !json.attributeList )json.attributeList = [];
  532. errorText = AttributeAction.compare( json );
  533. if( !json.unitList )json.unitList = [];
  534. errorText = IdentityAction.compare( json );
  535. }else{
  536. errorText = Utils.getFailText( response );
  537. }
  538. }else{
  539. errorText = personData;
  540. }
  541. if( archiveFlag && !errorText){
  542. Utils.saveToLocal( requestJson ); //保存到本地
  543. }
  544. }catch(e){
  545. errorText = Utils.processError( e, "修改个人 update() 出错:" );
  546. }finally{
  547. var result = {
  548. "result" : errorText ? "error" : "success",
  549. "description" : errorText || ""
  550. };
  551. if( response && response.data ){
  552. result.id = response.data.id;
  553. }
  554. return result;
  555. }
  556. }
  557. function updatePassword(json){
  558. print("修改用户密码");
  559. var errorText = "";
  560. var response;
  561. var flag = Utils.getUserFlag(json);
  562. if( flag ){
  563. try{
  564. var data = { "value": json.password };
  565. var resp = applications.putQuery('x_organization_assemble_control', "person/"+flag+"/set/password", JSON.stringify(data) ); //修改密码
  566. response = Utils.parseResp( resp );
  567. if( response.type && response.type == "success" ){
  568. }else{
  569. errorText = Utils.getFailText( response );
  570. }
  571. }catch(e){
  572. errorText = Utils.processError( e, "修改用户密码出错 " + flag + " updatePassword() 出错:" );
  573. }
  574. }else{
  575. errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户";
  576. print(errorText);
  577. }
  578. var result = {
  579. "result" : errorText ? "error" : "success",
  580. "description" : errorText || ""
  581. };
  582. //if( response && response.data ){
  583. // result.id = response.data.id;
  584. //}
  585. return result;
  586. }
  587. function updateSuperior(json){
  588. print("修改个人汇报对象");
  589. var errorText;
  590. var response;
  591. try{
  592. var personData = get(json);
  593. if( typeof personData == "object" ){
  594. personData.superior = json.superior;
  595. if( !personData.controllerList )personData.controllerList = [];
  596. var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) );
  597. response = Utils.parseResp( resp );
  598. if( response.type && response.type == "success" ){
  599. }else{
  600. errorText = Utils.getFailText( response );
  601. }
  602. }else{
  603. errorText = personData;
  604. }
  605. }catch(e){
  606. errorText = Utils.processError( e, "修改个人 updateSuperior() 出错:" );
  607. }finally{
  608. var result = {
  609. "result" : errorText ? "error" : "success",
  610. "description" : errorText || ""
  611. };
  612. if( response && response.data ){
  613. result.id = response.data.id;
  614. }
  615. return result;
  616. }
  617. }
  618. function remove(json){
  619. print("删除个人");
  620. var errorText;
  621. var response;
  622. try{
  623. var person = get(json);
  624. if( typeof person == "object" ){
  625. var resp = applications.deleteQuery('x_organization_assemble_control', "person/"+person.id ); //s人员信息
  626. response = Utils.parseResp( resp );
  627. if( response.type && response.type == "success" ){
  628. }else{
  629. errorText = Utils.getFailText( response );
  630. }
  631. }else{
  632. errorText = person;
  633. }
  634. }catch(e){
  635. errorText = Utils.processError( e, "删除个人 remove() 出错:" );
  636. }finally{
  637. var result = {
  638. "result" : errorText ? "error" : "success",
  639. "description" : errorText || ""
  640. };
  641. if( response && response.data ){
  642. result.id = response.data.id;
  643. }
  644. return result;
  645. }
  646. }
  647. function init(){
  648. var result ="";
  649. var responseText = "";
  650. try{
  651. print( "requestText="+requestText );
  652. var requestJson = JSON.parse(requestText);
  653. print( "type of requestJson = " + typeof( requestJson ));
  654. if( typeof(requestJson) === "string" ){
  655. requestJson = JSON.parse(requestJson);
  656. }
  657. var action = requestJson.action;
  658. print("action="+action);
  659. switch( action ){
  660. case "add":
  661. result = add( requestJson );
  662. break;
  663. case "update":
  664. result = update( requestJson );
  665. break;
  666. case "updatepwd":
  667. result = updatePassword( requestJson );
  668. break;
  669. case "updateSuperior":
  670. result = updateSuperior( requestJson );
  671. break;
  672. case "delete" :
  673. result = remove( requestJson );
  674. break;
  675. default :
  676. result = {
  677. "result" : "error",
  678. "description" : "requestText未设置action,不执行操作"
  679. };
  680. break;
  681. }
  682. }catch(e){
  683. e.printStackTrace();
  684. result = {
  685. "result" : "error",
  686. "description" : e.name + ": " + e.message
  687. };
  688. }finally{
  689. print("responseText="+JSON.stringify(result));
  690. return result;
  691. }
  692. }
  693. init();