unitAsycn.min.js 6.5 KB

1
  1. print("运行组织同步接口");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===null){return{type:"error",message:"服务响应是null,需要管理员查看后台日志"}}else{var e=JSON.parse(t.toString());return e}},getFailText:function(t){var e;if(t.message&&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 s in t){e[s]=Utils.objectClone(t[s])}return e}}};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 s=applications.putQuery("x_organization_assemble_control","unitattribute/"+r.id,JSON.stringify(r));var a=Utils.parseResp(s);if(a.type&&a.type=="success"){return""}else{return Utils.getFailText(a)}}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 s=applications.getQuery("x_organization_assemble_control","unitattribute/list/unit/"+i);var a=Utils.parseResp(s);var n;if(a.type&&a.type=="success"){n=a.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 s;if(r){try{i=applications.getQuery("x_organization_assemble_control","unit/"+r);var a=Utils.parseResp(i);if(a.type&&a.type=="success"){s=a.data}else{return Utils.getFailText(t)}}catch(t){return Utils.processError(t,"get() 出错: ")}delete s.woSupDirectUnit;delete s.woSubDirectIdentityList;delete s.woUnitAttributeList;delete s.woUnitDutyList;return s}else{e="参数中没有组织标志:distinguishedName , unique, name 或 id, 不能获取用户";print(e);return e}}function add(t){print("添加组织");var e;var r;var i;try{if(t.superior&&t.superior!=""){var s=get({flag:t.superior});if(typeof s!="object"){var a={name:t.superior,unique:t.superior};i=applications.postQuery("x_organization_assemble_control","unit",JSON.stringify(a))}}var n=get(t);if(typeof n=="object"){for(var o in t){if(o!=="action"&&o!=="attributeList"&&o!=="dutyList"){if(o=="orderNumber"&&(!t[o]||t[o]=="")){}else if(o=="typeList"&&(!t[o]||t[o]==""||t[o].length==0)){}else{n[o]=t[o]}}}if(!n.controllerList||n.controllerList==null)n.controllerList=[];if(!n.typeList){n.typeList=[]}else{if(typeof n.typeList=="string")n.typeList=[n.typeList]}i=applications.putQuery("x_organization_assemble_control","unit/"+n.id,JSON.stringify(n))}else{if(!t.controllerList){t.controllerList=[]}else{if(typeof t.controllerList=="string")t.controllerList=[t.controllerList]}if(!t.typeList){t.typeList=[]}else{if(typeof t.typeList=="string")t.typeList=[t.typeList]}var l=Utils.objectClone(t);if(l.attributeList)delete l.attributeList;if(l.dutyList)delete l.dutyList;i=applications.postQuery("x_organization_assemble_control","unit",JSON.stringify(l))}var r=Utils.parseResp(i);if(r.type&&r.type=="success"){if(t.attributeList){e=AttributeAction.compare(t)}}else{e=Utils.getFailText(r)}}catch(t){e=Utils.processError(t,"添加组织 add() 出错:")}finally{var u={result:e?"error":"success",description:e||""};if(r&&r.data){u.id=r.data.id}return u}}function update(t){print("修改组织");var e;var r;try{var i=get(t);if(typeof i=="object"){for(var s in t){if(s!=="action"&&s!=="attributeList"&&s!=="dutyList"){if(s=="orderNumber"&&(!t[s]||t[s]=="")){}else if(s=="typeList"&&(!t[s]||t[s]==""||t[s].length==0)){}else{i[s]=t[s]}}}if(!i.controllerList||i.controllerList==null)i.controllerList=[];if(!i.typeList){i.typeList=[]}else{if(typeof i.typeList=="string")i.typeList=[i.typeList]}var a=applications.putQuery("x_organization_assemble_control","unit/"+i.id,JSON.stringify(i));var r=Utils.parseResp(a);if(r.type&&r.type=="success"){if(!t.attributeList)t.attributeList=[];e=AttributeAction.compare(t)}else{e=Utils.getFailText(r)}}else{e=i}}catch(t){e=Utils.processError(t,"修改组织 update() 出错:")}finally{var n={result:e?"error":"success",description:e||""};if(r&&r.data){n.id=r.data.id}return n}}function remove(t){print("删除组织");var e;var r;try{var i=get(t);if(typeof i=="object"){var s=applications.deleteQuery("x_organization_assemble_control","unit/"+i.id);r=Utils.parseResp(s);if(r.type&&r.type=="success"){}else{e=Utils.getFailText(r)}}else{e=i}}catch(t){e=Utils.processError(t,"删除组织 remove() 出错:")}finally{var a={result:e?"error":"success",description:e||""};if(r&&r.data){a.id=r.data.id}return a}}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();