personAsycn.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. data.attributeList = typeof( data.value == "string" ) ? [data.value] : data.value;
  172. try {
  173. var resp = applications.postQuery('x_organization_assemble_control', 'personattribute', JSON.stringify( data ));
  174. var json = Utils.parseResp( resp );
  175. if( json.type && json.type == "success" ){
  176. return "";
  177. }else{
  178. return Utils.getFailText( json );
  179. }
  180. }catch(e){
  181. return Utils.processError( e, "新增用户属性AttributeAction.add() 出错: " );
  182. }
  183. },
  184. remove : function( data ){
  185. try {
  186. var resp = applications.deleteQuery('x_organization_assemble_control', 'personattribute/'+data.id );
  187. var json = Utils.parseResp( resp );
  188. if( json.type && json.type == "success" ){
  189. return "";
  190. }else{
  191. return Utils.getFailText( json );
  192. }
  193. }catch(e){
  194. return Utils.processError( e, "删除用户属性AttributeAction.remove() 出错: " );
  195. }
  196. },
  197. update : function( flag, data_new, data_old ){
  198. for( var key in data_new ){
  199. if( key != "distinguishedName" ){
  200. data_old[key] = data_new[key];
  201. }
  202. }
  203. data_old.person = flag;
  204. data_old.attributeList = typeof( data_new.value == "string" ) ? [data_new.value] : data_new.value;
  205. try {
  206. var resp = applications.putQuery('x_organization_assemble_control', 'personattribute/'+data_old.id, JSON.stringify(data_old) );
  207. var json = Utils.parseResp( resp );
  208. if( json.type && json.type == "success" ){
  209. return "";
  210. }else{
  211. return Utils.getFailText( json );
  212. }
  213. }catch(e){
  214. return Utils.processError( e, "修改用户属性AttributeAction.update() 出错: " );
  215. }
  216. },
  217. compare : function( json ){
  218. var attribute_new = json.attributeList; //传入的用户属性
  219. var errorText = "";
  220. var flag = Utils.getUserFlag( json );
  221. if( flag ){
  222. try{
  223. var resp = applications.getQuery('x_organization_assemble_control', 'personattribute/list/person/'+flag );
  224. var json_attribute_old = Utils.parseResp( resp );
  225. var attribute_old;
  226. if( json_attribute_old.type && json_attribute_old.type == "success" ){
  227. attribute_old = json_attribute_old.data;
  228. }else{
  229. attribute_old = [];
  230. //return Utils.getFailText(json_attribute_old);
  231. }
  232. for( var i=0; i<attribute_old.length; i++ ){
  233. var obj_new = Utils.getKeyEqualObjFromArray( attribute_new, "name", attribute_old[i].name );
  234. if( obj_new == null ){ //老的不在了,要删除
  235. errorText = AttributeAction.remove( attribute_old[i] )
  236. }else{ //已经存在,要修改
  237. errorText = AttributeAction.update( flag, obj_new, attribute_old[i] );
  238. }
  239. }
  240. for( var i=0; i<attribute_new.length; i++ ){
  241. var obj_old = Utils.getKeyEqualObjFromArray( attribute_old, "name", attribute_new[i].name );
  242. if( obj_old == null ){ //需要新增
  243. errorText = AttributeAction.add( flag, attribute_new[i] );
  244. }
  245. }
  246. return errorText;
  247. }catch(e){
  248. return Utils.processError( e, "修改用户属性AttributeAction.compare() 出错: " );
  249. }
  250. }
  251. }
  252. };
  253. var IdentityAction = {
  254. add :function( flag, unit, personName, ignoreFlag ){
  255. //flag: "", //组织唯一编码unique/组织的distinguishedName/组织id
  256. // orderNumber: "", //在组织里的排序号,升序排列,为空在最后
  257. // description: "", //描述
  258. // duty : "", //用户在该组织的职务
  259. // position : "" //用户在该组织的岗位
  260. var data = {
  261. name : personName,
  262. person : flag,
  263. unit : unit.flag,
  264. description : unit.description
  265. };
  266. try {
  267. var resp = applications.postQuery('x_organization_assemble_control', 'identity', JSON.stringify( data ));
  268. var json = Utils.parseResp( resp );
  269. if( json.type === "success" ){
  270. return "";
  271. }else{
  272. if( ignoreFlag != "no" ){
  273. archiveFlag = true;
  274. }else{
  275. return Utils.getFailText( json );
  276. }
  277. //if( json.prompt == "com.x.organization.assemble.control.jaxrs.identity.ExceptionUnitNotExist" ){ //组织不存在,创建组织
  278. //var u_data = { name : unit.flag, unique : unit.flag };
  279. //var json = Utils.parseResp( applications.postQuery('x_organization_assemble_control', 'unit', JSON.stringify( u_data )));
  280. //if( json.type == "success" ){
  281. // return IdentityAction.add( flag, unit );
  282. //}
  283. //}else{
  284. // return Utils.getFailText( json );
  285. //}
  286. }
  287. return "";
  288. }catch(e){
  289. return Utils.processError( e, "新增用户身份IdentityAction.add() 出错: " );
  290. }
  291. },
  292. remove : function( data ){
  293. try {
  294. var resp = applications.deleteQuery('x_organization_assemble_control', 'identity/'+data.id );
  295. var json = Utils.parseResp( resp );
  296. if( json.type && json.type == "success" ){
  297. return "";
  298. }else{
  299. return Utils.getFailText( json );
  300. }
  301. }catch(e){
  302. return Utils.processError( e, "删除用户身份IdentityAction.remove() 出错: " );
  303. }
  304. },
  305. update : function( identity, unit_new, unit_old ){
  306. //flag: "", //组织唯一编码unique/组织的distinguishedName/组织id
  307. // orderNumber: "", //在组织里的排序号,升序排列,为空在最后
  308. // description: "", //描述
  309. // duty : "", //用户在该组织的职务
  310. // position : "" //用户在该组织的岗位
  311. if( identity.orderNumber != unit_new.orderNumber || identity.description != unit_new.description ){
  312. identity.orderNumber = unit_new.orderNumber;
  313. identity.description = unit_new.description;
  314. try {
  315. var resp = applications.putQuery('x_organization_assemble_control', 'identity/'+identity.id, JSON.stringify(identity) );
  316. var json = Utils.parseResp( resp );
  317. if( json.type && json.type == "success" ){
  318. return "";
  319. }else{
  320. return Utils.getFailText( json );
  321. }
  322. }catch(e){
  323. return Utils.processError( e, "修改用户身份IdentityAction.update() 出错: " );
  324. }
  325. }
  326. },
  327. compare : function( json ){
  328. var errorText = "";
  329. var unit_new = json.unitList; //传入的用户所在部门
  330. var flag = Utils.getUserFlag( json );
  331. if( !flag )return "修改用户身份IdentityAction.compare() 出错: 未能找到用户标志";
  332. try{
  333. var resp = applications.getQuery('x_organization_assemble_control', 'identity/list/person/'+flag );
  334. var json_identityList = Utils.parseResp( resp );
  335. var identityList;
  336. if( json_identityList.type == "success" ){
  337. identityList = json_identityList.data || [];
  338. }else{
  339. identityList = [];
  340. //return Utils.getFailText( json_identityList );
  341. }
  342. var req = {"personList":[flag]};
  343. var unitResq = applications.postQuery('x_organization_assemble_express', 'unit/list/person/object', JSON.stringify( req ) );
  344. var json_unit_old = Utils.parseResp( unitResq );
  345. var unit_old;
  346. if( json_unit_old.type == "success" ){
  347. unit_old = json_unit_old.data || [];
  348. }else{
  349. return Utils.getFailText( json_unit_old );
  350. }
  351. for( var i=0; i<unit_old.length; i++ ){
  352. var obj_new = IdentityAction.getEqualUnitFromArray( unit_new, unit_old[i] );
  353. if( obj_new == null ){ //老的不在了,要删除
  354. print("删除身份");
  355. var identity = IdentityAction.getIdentityByUnit( identityList, unit_old[i] );
  356. errorText = IdentityAction.remove( identity )
  357. }else{ //已经存在,要修改
  358. print("修改身份");
  359. var identity = IdentityAction.getIdentityByUnit( identityList, unit_old[i] );
  360. errorText = IdentityAction.update( identity, obj_new, unit_old[i] );
  361. }
  362. }
  363. for( var i=0; i<unit_new.length; i++ ){
  364. if( !unit_new[i].flag || unit_new[i].flag == "" )continue;
  365. var obj_old = IdentityAction.getEqualUnitFromArray( unit_old, unit_new[i] );
  366. if( obj_old == null ){ //需要新增
  367. print("新增身份");
  368. errorText = IdentityAction.add( flag, unit_new[i], json.name, json.ignoreFlag );
  369. }
  370. }
  371. return errorText;
  372. }catch(e){
  373. return Utils.processError( e, "修改用户身份IdentityAction.compare() 出错: " );
  374. }
  375. },
  376. getIdentityByUnit: function(identityList, unit){
  377. for( var i = 0; i<identityList.length; i++ ){
  378. var identity = identityList[i];
  379. if( identity.unitLevelName === unit.levelName ){
  380. return identity;
  381. }
  382. }
  383. },
  384. getEqualUnitFromArray : function( sourceUnitArray, targetUnit ){
  385. for( var i=0; i<sourceUnitArray.length; i++ ){
  386. if( IdentityAction.unitEquals( sourceUnitArray[i], targetUnit ) ){
  387. return sourceUnitArray[i];
  388. }
  389. }
  390. return null;
  391. },
  392. unitEquals: function( source, target ) {
  393. if (target.flag && (Utils.arrayIndexOf([source.flag, source.unique, source.distinguishedName, source.levelName, source.id], target.flag) > -1))return true;
  394. if (source.flag && (Utils.arrayIndexOf([target.flag, target.unique, target.distinguishedName, target.levelName, target.id], source.flag) > -1))return true;
  395. if (target.id && target.id == source.id)return true;
  396. if (target.unique && target.unique == source.unique)return true;
  397. if (target.distinguishedName && target.distinguishedName == source.distinguishedName)return true;
  398. if (target.levelName && target.levelName == source.levelName)return true;
  399. return false;
  400. }
  401. };
  402. function get( json ){
  403. var errorText = "";
  404. var flag = Utils.getUserFlag(json);
  405. var resp;
  406. var person_old;
  407. if( flag ){
  408. try{
  409. resp = applications.getQuery('x_organization_assemble_control', "person/"+flag ); //先获取人员信息
  410. var json_old = Utils.parseResp( resp );
  411. if( json_old.type && json_old.type == "success" ){
  412. person_old = json_old.data;
  413. }else{
  414. return Utils.getFailText( json );
  415. }
  416. }catch(e){
  417. return Utils.processError( e, "get() 出错: " );
  418. }
  419. delete person_old.woIdentityList;
  420. delete person_old.woRoleList;
  421. delete person_old.woGroupList;
  422. delete person_old.woPersonAttributeList;
  423. //delete person_old.control;
  424. //delete person_old.controllerList;
  425. return person_old;
  426. //applications.putQuery('x_organization_assemble_control', "person/"+json.unique, json );
  427. }else{
  428. errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户";
  429. print(errorText);
  430. return errorText;
  431. }
  432. }
  433. function add( requestJson ){
  434. print("添加个人");
  435. var json = Utils.objectClone(requestJson);
  436. var errorText;
  437. var response;
  438. var resp;
  439. try{
  440. if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在
  441. var superiorData = get({ flag : json.superior });
  442. if( typeof( superiorData ) != "object" ){ //不在则新建
  443. archiveFlag = true;
  444. delete json.superior;
  445. }
  446. }
  447. var personData = get(json);
  448. if( typeof personData == "object" ){
  449. if( json.forceFlag && json.forceFlag == "yes" ){
  450. for( var key in json){
  451. if( key !== "action" && key !== "attributeList" && key !== "unitList" ){
  452. if( key == "orderNumber" && (!json[key] || json[key]=="") ){
  453. }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){
  454. }else{
  455. personData[key] = json[key];
  456. }
  457. }
  458. }
  459. if( !personData.controllerList || personData.controllerList == null )personData.controllerList = [];
  460. resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) )
  461. }else{
  462. errorText = "人员“"+ Utils.getUserFlag(json) +"”已经在系统内存在";
  463. }
  464. }else{
  465. if( json.controllerList === null )json.controllerList = [];
  466. var data = Utils.objectClone(json);
  467. if(data.attributeList)delete data.attributeList;
  468. if(data.unitList)delete data.unitList;
  469. data.controllerList = [];
  470. resp = applications.postQuery( "x_organization_assemble_control", 'person', JSON.stringify(data));
  471. }
  472. if( resp && !errorText ){
  473. response = Utils.parseResp( resp );
  474. if( response.type && response.type == "success" ){
  475. if( !json.attributeList )json.attributeList = [];
  476. errorText = AttributeAction.compare( json );
  477. if( !json.unitList )json.unitList = [];
  478. errorText = IdentityAction.compare( json );
  479. }else{
  480. errorText = Utils.getFailText( response );
  481. }
  482. }
  483. if( archiveFlag && !errorText ){
  484. Utils.saveToLocal( requestJson ); //保存到本地
  485. }
  486. }catch(e){
  487. errorText = Utils.processError( e, "添加个人 add() 出错:" );
  488. }finally{
  489. var result = {
  490. "result" : errorText ? "error" : "success",
  491. "description" : errorText || ""
  492. };
  493. if( response && response.data ){
  494. result.id = response.data.id;
  495. }
  496. return result;
  497. }
  498. }
  499. function update(requestJson){
  500. print("修改个人");
  501. var json = Utils.objectClone(requestJson);
  502. var errorText;
  503. var response;
  504. try{
  505. if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在
  506. var superiorData = get({ flag : json.superior });
  507. if( typeof( superiorData ) != "object" ){ //不在则新建
  508. archiveFlag = true;
  509. delete json.superior;
  510. }
  511. }
  512. var personData = get(json);
  513. if( typeof personData == "object" ){
  514. for( var key in json){
  515. if( key !== "action" && key !== "attributeList" && key !== "unitList" ){
  516. if( key == "orderNumber" && (!json[key] || json[key]=="") ){
  517. }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){
  518. }else{
  519. personData[key] = json[key];
  520. }
  521. }
  522. }
  523. if( !personData.controllerList || personData.controllerList == null )personData.controllerList = [];
  524. var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) );
  525. var response = Utils.parseResp( resp );
  526. if( response.type && response.type == "success" ){
  527. if( !json.attributeList )json.attributeList = [];
  528. errorText = AttributeAction.compare( json );
  529. if( !json.unitList )json.unitList = [];
  530. errorText = IdentityAction.compare( json );
  531. }else{
  532. errorText = Utils.getFailText( response );
  533. }
  534. }else{
  535. errorText = personData;
  536. }
  537. if( archiveFlag && !errorText){
  538. Utils.saveToLocal( requestJson ); //保存到本地
  539. }
  540. }catch(e){
  541. errorText = Utils.processError( e, "修改个人 update() 出错:" );
  542. }finally{
  543. var result = {
  544. "result" : errorText ? "error" : "success",
  545. "description" : errorText || ""
  546. };
  547. if( response && response.data ){
  548. result.id = response.data.id;
  549. }
  550. return result;
  551. }
  552. }
  553. function updatePassword(json){
  554. print("修改用户密码");
  555. var errorText = "";
  556. var response;
  557. var flag = Utils.getUserFlag(json);
  558. if( flag ){
  559. try{
  560. var data = { "value": json.password };
  561. var resp = applications.putQuery('x_organization_assemble_control', "person/"+flag+"/set/password", JSON.stringify(data) ); //修改密码
  562. response = Utils.parseResp( resp );
  563. if( response.type && response.type == "success" ){
  564. }else{
  565. errorText = Utils.getFailText( response );
  566. }
  567. }catch(e){
  568. errorText = Utils.processError( e, "修改用户密码出错 " + flag + " updatePassword() 出错:" );
  569. }
  570. }else{
  571. errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户";
  572. print(errorText);
  573. }
  574. var result = {
  575. "result" : errorText ? "error" : "success",
  576. "description" : errorText || ""
  577. };
  578. //if( response && response.data ){
  579. // result.id = response.data.id;
  580. //}
  581. return result;
  582. }
  583. function updateSuperior(json){
  584. print("修改个人汇报对象");
  585. var errorText;
  586. var response;
  587. try{
  588. var personData = get(json);
  589. if( typeof personData == "object" ){
  590. personData.superior = json.superior;
  591. if( !personData.controllerList )personData.controllerList = [];
  592. var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) );
  593. response = Utils.parseResp( resp );
  594. if( response.type && response.type == "success" ){
  595. }else{
  596. errorText = Utils.getFailText( response );
  597. }
  598. }else{
  599. errorText = personData;
  600. }
  601. }catch(e){
  602. errorText = Utils.processError( e, "修改个人 updateSuperior() 出错:" );
  603. }finally{
  604. var result = {
  605. "result" : errorText ? "error" : "success",
  606. "description" : errorText || ""
  607. };
  608. if( response && response.data ){
  609. result.id = response.data.id;
  610. }
  611. return result;
  612. }
  613. }
  614. function remove(json){
  615. print("删除个人");
  616. var errorText;
  617. var response;
  618. try{
  619. var person = get(json);
  620. if( typeof person == "object" ){
  621. var resp = applications.deleteQuery('x_organization_assemble_control', "person/"+person.id ); //s人员信息
  622. response = Utils.parseResp( resp );
  623. if( response.type && response.type == "success" ){
  624. }else{
  625. errorText = Utils.getFailText( response );
  626. }
  627. }else{
  628. errorText = person;
  629. }
  630. }catch(e){
  631. errorText = Utils.processError( e, "删除个人 remove() 出错:" );
  632. }finally{
  633. var result = {
  634. "result" : errorText ? "error" : "success",
  635. "description" : errorText || ""
  636. };
  637. if( response && response.data ){
  638. result.id = response.data.id;
  639. }
  640. return result;
  641. }
  642. }
  643. function init(){
  644. var result ="";
  645. var responseText = "";
  646. try{
  647. print( "requestText="+requestText );
  648. var requestJson = JSON.parse(requestText);
  649. print( "type of requestJson = " + typeof( requestJson ));
  650. if( typeof(requestJson) === "string" ){
  651. requestJson = JSON.parse(requestJson);
  652. }
  653. var action = requestJson.action;
  654. print("action="+action);
  655. switch( action ){
  656. case "add":
  657. result = add( requestJson );
  658. break;
  659. case "update":
  660. result = update( requestJson );
  661. break;
  662. case "updatepwd":
  663. result = updatePassword( requestJson );
  664. break;
  665. case "updateSuperior":
  666. result = updateSuperior( requestJson );
  667. break;
  668. case "delete" :
  669. result = remove( requestJson );
  670. break;
  671. default :
  672. result = {
  673. "result" : "error",
  674. "description" : "requestText未设置action,不执行操作"
  675. };
  676. break;
  677. }
  678. }catch(e){
  679. e.printStackTrace();
  680. result = {
  681. "result" : "error",
  682. "description" : e.name + ": " + e.message
  683. };
  684. }finally{
  685. print("responseText="+JSON.stringify(result));
  686. return result;
  687. }
  688. }
  689. init();