| 1 |
- print("运行组织同步接口");var File=Java.type("java.io.File");var Config={localPath:File.separator+"data"+File.separator+"OrganizationSyncRequest"+File.separator+"unit"+File.separator};var applications=resources.getContext().applications();var Utils={getUnitFlag:function(t){return t.flag||t.distinguishedName||t.unique||t.id||t.name},getKeyEqualObjFromArray:function(t,e,r){for(var i=0;i<t.length;i++){if(t[i][e]===r){return t[i]}}return null},parseResp:function(t){if(!t||t===null){return{type:"error",message:"服务响应是null,需要管理员查看后台日志"}}else{var e=JSON.parse(t.toString());return e}},getFailText:function(t){var e;if(t.message){e=t.message+(t.prompt?"("+t.prompt+")":"")}else if(t.prompt){e=t.prompt}else{e="未知异常"}print(e);return e},processError:function(t,e){t.printStackTrace();var r=e+" "+t.name+": "+t.message;print(r);return r},arrayIndexOf:function(t,e){for(var r=0;r<t.length;r++){if(t[r]==e)return r}return-1},objectClone:function(t){if(null==t||"object"!=typeof t)return t;if(typeof t.length==="number"){var e=[];for(var r=0,i=t.length;r<i;++r){e[r]=Utils.objectClone(t[r])}return e}else{var e={};for(var a in t){e[a]=Utils.objectClone(t[a])}return e}},saveToLocal:function(t){if(t.saveFlag&&t.saveFlag=="no"){print("不保存文件");return}print("保存文件开始");if(File==null)File=Java.type("java.io.File");var e=new File(Config.localPath);if(!e.exists()){if(!e.mkdirs()){print("创建文件夹失败:"+recordPath);return null}}var r=t.name?t.name:Utils.getUnitFlag(t);var i=t.unique?t.unique:"";var a=Config.localPath+r+"_"+i+".json";print("path="+a);var s=new File(a);if(s.exists()){s.delete()}if(!s.createNewFile()){print("不能创建文件:"+a);return null}var n=new java.io.PrintWriter(s,"GBK");n.write(JSON.stringify(t));n.close();print("保存文件结束 path="+a)}};var AttributeAction={add:function(t,e){e.unit=t;e.attributeList=typeof e.value=="string"?[e.value]:e.value;try{var r=applications.postQuery("x_organization_assemble_control","unitattribute",JSON.stringify(e));var i=Utils.parseResp(r);if(i.type&&i.type=="success"){return""}else{return Utils.getFailText(i)}}catch(t){return Utils.processError(t,"新增组织属性AttributeAction.add() 出错: ")}},remove:function(t){try{var e=applications.deleteQuery("x_organization_assemble_control","unitattribute/"+t.id);var r=Utils.parseResp(e);if(r.type&&r.type=="success"){return""}else{return Utils.getFailText(r)}}catch(t){return Utils.processError(t,"删除组织属性AttributeAction.remove() 出错: ")}},update:function(t,e,r){for(var i in e){if(i!="distinguishedName"){r[i]=e[i]}}r.unit=t;r.attributeList=typeof e.value=="string"?[e.value]:e.value;try{var a=applications.putQuery("x_organization_assemble_control","unitattribute/"+r.id,JSON.stringify(r));var s=Utils.parseResp(a);if(s.type&&s.type=="success"){return""}else{return Utils.getFailText(s)}}catch(t){return Utils.processError(t,"修改组织属性AttributeAction.update() 出错: ")}},compare:function(t){var e=t.attributeList;var r="";var i=Utils.getUnitFlag(t);if(i){try{var a=applications.getQuery("x_organization_assemble_control","unitattribute/list/unit/"+i);var s=Utils.parseResp(a);var n;if(s.type&&s.type=="success"){n=s.data}else{n=[]}for(var o=0;o<n.length;o++){var l=Utils.getKeyEqualObjFromArray(e,"name",n[o].name);if(l==null){r=AttributeAction.remove(n[o])}else{r=AttributeAction.update(i,l,n[o])}}for(var o=0;o<e.length;o++){var u=Utils.getKeyEqualObjFromArray(n,"name",e[o].name);if(u==null){r=AttributeAction.add(i,e[o])}}return r}catch(t){return Utils.processError(t,"修改组织属性AttributeAction.compare() 出错: ")}}}};function get(t){var e="";var r=Utils.getUnitFlag(t);var i;var a;if(r){try{i=applications.getQuery("x_organization_assemble_control","unit/"+r);var s=Utils.parseResp(i);if(s.type&&s.type=="success"){a=s.data}else{return Utils.getFailText(t)}}catch(t){return Utils.processError(t,"get() 出错: ")}delete a.woSupDirectUnit;delete a.woSubDirectIdentityList;delete a.woUnitAttributeList;delete a.woUnitDutyList;return a}else{e="参数中没有组织标志:distinguishedName , unique, name 或 id, 不能获取用户";print(e);return e}}function add(t){print("添加组织");var e=Utils.objectClone(t);var r;var i;var a;try{if(e.superior&&e.superior!=""){var s=get({flag:e.superior});if(typeof s!="object"){var n={name:e.superior,unique:e.superior};a=applications.postQuery("x_organization_assemble_control","unit",JSON.stringify(n))}}var o=get(e);if(typeof o=="object"){print("组织已存在,强制保存");for(var l in e){if(l!=="action"&&l!=="attributeList"&&l!=="dutyList"){if(l=="orderNumber"&&(!e[l]||e[l]=="")){}else if(l=="typeList"&&(!e[l]||e[l]==""||e[l].length==0)){}else if(l=="id"||l=="unique"||l=="distinguishedName"){}else{o[l]=e[l]}}}if(!o.controllerList||o.controllerList==null)o.controllerList=[];if(!o.typeList){o.typeList=[]}else{if(typeof o.typeList=="string")o.typeList=[o.typeList]}var u=o.id;print("unitData="+JSON.stringify(o));a=applications.putQuery("x_organization_assemble_control","unit/"+u,JSON.stringify(o))}else{if(!e.controllerList){e.controllerList=[]}else{if(typeof e.controllerList=="string")e.controllerList=[e.controllerList]}if(!e.typeList){e.typeList=[]}else{if(typeof e.typeList=="string")e.typeList=[e.typeList]}var p=Utils.objectClone(e);if(p.attributeList)delete p.attributeList;if(p.dutyList)delete p.dutyList;a=applications.postQuery("x_organization_assemble_control","unit",JSON.stringify(p))}if(a){var i=Utils.parseResp(a);if(i.type&&i.type=="success"){if(e.attributeList){r=AttributeAction.compare(e)}}else{r=Utils.getFailText(i)}}}catch(t){r=Utils.processError(t,"添加组织 add() 出错:")}finally{var c={result:r?"error":"success",description:r||""};if(i&&i.data){c.id=i.data.id}return c}}function update(t){print("修改组织");var e=Utils.objectClone(t);var r;var i;try{if(e.superior&&e.superior!=""){var a=get({flag:e.superior});if(typeof a!="object"){var s={name:e.superior,unique:e.superior};l=applications.postQuery("x_organization_assemble_control","unit",JSON.stringify(s))}}var n=get(e);if(typeof n=="object"){for(var o in e){if(o!=="action"&&o!=="attributeList"&&o!=="dutyList"){if(o=="orderNumber"&&(!e[o]||e[o]=="")){}else if(o=="typeList"&&(!e[o]||e[o]==""||e[o].length==0)){}else if(o=="id"||o=="unique"||o=="distinguishedName"){}else{n[o]=e[o]}}}if(!n.controllerList||n.controllerList==null)n.controllerList=[];if(!n.typeList){n.typeList=[]}else{if(typeof n.typeList=="string")n.typeList=[n.typeList]}var l=applications.putQuery("x_organization_assemble_control","unit/"+n.id,JSON.stringify(n));var i=Utils.parseResp(l);if(i.type&&i.type=="success"){if(!e.attributeList)e.attributeList=[];r=AttributeAction.compare(e)}else{r=Utils.getFailText(i)}}else{r=n}}catch(t){r=Utils.processError(t,"修改组织 update() 出错:")}finally{var u={result:r?"error":"success",description:r||""};if(i&&i.data){u.id=i.data.id}return u}}function remove(t){print("删除组织");var e;var r;try{var i=get(t);if(typeof i=="object"){var a=applications.deleteQuery("x_organization_assemble_control","unit/"+i.id);r=Utils.parseResp(a);if(r.type&&r.type=="success"){}else{e=Utils.getFailText(r)}}else{e=i}}catch(t){e=Utils.processError(t,"删除组织 remove() 出错:")}finally{var s={result:e?"error":"success",description:e||""};if(r&&r.data){s.id=r.data.id}return s}}function init(){var e="";var t="";try{print("requestText="+requestText);var r=JSON.parse(requestText);print("type of requestJson = "+typeof r);if(typeof r==="string"){r=JSON.parse(r)}var i=r.action;print("action="+i);switch(i){case"add":e=add(r);break;case"update":e=update(r);break;case"delete":e=remove(r);break;default:e={result:"error",description:"requestText未设置action,不执行操作"};break}}catch(t){t.printStackTrace();e={result:"error",description:t.name+": "+t.message}}finally{print("responseText="+JSON.stringify(e));return e}}init();
|