/* * resources.getEntityManagerContainer() // 实体管理容器. * resources.getContext() //上下文根. * resources.getOrganization() //组织访问接口. * requestText //请求内容. * request //请求对象. */ /* { "action": "add", "genderType": "m", "signature": "", "description": "", "name": "", "employee": "", "unique": "", "distinguishedName": "", "orderNumber": "", "controllerList": "", "superior": "", "mail": "", "weixin": "", "qq": "", "mobile": "", "officePhone": "", "boardDate": "", "birthday": "", "age": "", "dingdingId": "", "dingdingHash": "", "attributeList": [ { "name": "", "value": "", "description": "", "orderNumber": "" } ], "unitList": [ { "flag": "", "orderNumber": "", "description": "", "duty": "", "position": "" } ] } */ print("运行人员同步接口"); var File = Java.type('java.io.File'); var Config = { localPath : File.separator + "data" + File.separator + "OrganizationSyncRequest" + File.separator + "person" + File.separator, ignoreDuty : ["部门积分管理员","公司积分管理员","市、县公司普通员工"], ignorAttribute : ["市、县公司普通员工"] }; var applications = resources.getContext().applications(); var archiveFlag = false; var Utils = { getUserFlag : function( json ){ return json.flag || json.distinguishedName || json.unique || json.employee || json.mobile || json.id; }, getKeyEqualObjFromArray : function( sourceArray, sourceKey, value ){ for( var i=0; i -1 ) { this.identityId = s.id; return true; } } return false; }; //identityEquals: function( source, target ) { // var flag = false; // var sourceList = Utils.typeOf( source ) === "array" ? source : [source]; // var targetList = Utils.typeOf( target ) === "array" ? target : [target]; // for( var i=0; i -1 )return true; // }else if( s_type === "object" && t_type === "string" ){ // if( Utils.arrayIndexOf([s.unique, s.distinguishedName, s.id], t) > -1 )return true; // }else if( s_type === "object" && t_type === "object" ){ // if (t.id && t.id == s.id)return true; // if (t.unique && t.unique == s.unique)return true; // if (t.distinguishedName && t.distinguishedName == s.distinguishedName)return true; // } // } // } // return false; //} var IdentityAction = function( json ){ this.errorText = ""; var unit_new = []; //传入的用户所在部门 var unit_new_obj = this.unit_new_obj = {}; for( var i=0; i -1))return true; if (source.flag && (Utils.arrayIndexOf([target.flag, target.unique, target.distinguishedName, target.levelName, target.id], source.flag) > -1))return true; if (target.id && target.id == source.id)return true; if (target.unique && target.unique == source.unique)return true; if (target.distinguishedName && target.distinguishedName == source.distinguishedName)return true; if (target.levelName && target.levelName == source.levelName)return true; return false; }; function get( json ){ var errorText = ""; var flag = Utils.getUserFlag(json); var resp; var person_old; if( flag ){ try{ resp = applications.getQuery('x_organization_assemble_control', "person/"+flag ); //先获取人员信息 var json_old = Utils.parseResp( resp ); if( json_old.type && json_old.type == "success" ){ person_old = json_old.data; }else{ return Utils.getFailText( json_old ); } }catch(e){ return Utils.processError( e, "get() 出错: " ); } delete person_old.woIdentityList; delete person_old.woRoleList; delete person_old.woGroupList; delete person_old.woPersonAttributeList; //delete person_old.control; //delete person_old.controllerList; return person_old; //applications.putQuery('x_organization_assemble_control', "person/"+json.unique, json ); }else{ errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户"; print(errorText); return errorText; } } function add( requestJson ){ print("添加个人"); var json = Utils.objectClone(requestJson); var errorText; var response; var resp; try{ if( json.orderNumber ){ try{ json.orderNumber = parseInt( json.orderNumber).toString() }catch(e){} } if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在 var superiorData = get({ flag : json.superior }); if( typeof( superiorData ) != "object" ){ //不在则新建 archiveFlag = true; delete json.superior; } } var personData = get(json); if( typeof personData == "object" ){ if( json.forceFlag && json.forceFlag == "yes" ){ for( var key in json){ if( key !== "action" && key !== "attributeList" && key !== "unitList" ){ if( key == "orderNumber" && (!json[key] || json[key]=="") ){ }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){ }else{ personData[key] = json[key]; } } } if( !personData.controllerList || personData.controllerList == null )personData.controllerList = []; resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) ) }else{ errorText = "人员“"+ Utils.getUserFlag(json) +"”已经在系统内存在"; } }else{ if( json.controllerList === null )json.controllerList = []; var data = Utils.objectClone(json); if(data.attributeList)delete data.attributeList; if(data.unitList)delete data.unitList; data.controllerList = []; resp = applications.postQuery( "x_organization_assemble_control", 'person', JSON.stringify(data)); } if( resp && !errorText ){ response = Utils.parseResp( resp ); if( response.type && response.type == "success" ){ if( !json.attributeList )json.attributeList = []; var attributeAction = new AttributeAction( json ); errorText = attributeAction.errorText; if( !json.unitList )json.unitList = []; var identityAction = new IdentityAction( json ); errorText = identityAction.errorText; }else{ errorText = Utils.getFailText( response ); } } if( archiveFlag && !errorText ){ Utils.saveToLocal( requestJson ); //保存到本地 } }catch(e){ errorText = Utils.processError( e, "添加个人 add() 出错:" ); }finally{ var result = { "result" : errorText ? "error" : "success", "description" : errorText || "" }; if( response && response.data ){ result.id = response.data.id; } return result; } } function update(requestJson){ print("修改个人"); var json = Utils.objectClone(requestJson); var errorText; var response; try{ if( json.orderNumber ){ try{ json.orderNumber = parseInt( json.orderNumber ).toString() }catch(e){} } if( json.superior && json.superior != "" && json.ignoreFlag != "no" ){ //判断汇报对象在不在 var superiorData = get({ flag : json.superior }); if( typeof( superiorData ) != "object" ){ //不在则新建 archiveFlag = true; delete json.superior; } } var personData = get(json); if( typeof personData == "object" ){ for( var key in json){ if( key !== "action" && key !== "attributeList" && key !== "unitList" ){ if( key == "orderNumber" && (!json[key] || json[key]=="") ){ }else if( key == "id" || key == "unique" || key == "distinguishedName" || key == "changePasswordTime"){ }else{ personData[key] = json[key]; } } } if( !personData.controllerList || personData.controllerList == null )personData.controllerList = []; var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) ); var response = Utils.parseResp( resp ); if( response.type && response.type == "success" ){ if( !json.attributeList )json.attributeList = []; var attributeAction = new AttributeAction( json ); errorText = attributeAction.errorText; if( !json.unitList )json.unitList = []; var identityAction = new IdentityAction( json ); errorText = identityAction.errorText; }else{ errorText = Utils.getFailText( response ); } }else{ errorText = personData; } if( archiveFlag && !errorText){ Utils.saveToLocal( requestJson ); //保存到本地 } }catch(e){ errorText = Utils.processError( e, "修改个人 update() 出错:" ); }finally{ var result = { "result" : errorText ? "error" : "success", "description" : errorText || "" }; if( response && response.data ){ result.id = response.data.id; } return result; } } function updatePassword(json){ print("修改用户密码"); var errorText = ""; var response; var flag = Utils.getUserFlag(json); if( flag ){ try{ var data = { "value": json.password }; var resp = applications.putQuery('x_organization_assemble_control', "person/"+flag+"/set/password", JSON.stringify(data) ); //修改密码 response = Utils.parseResp( resp ); if( response.type && response.type == "success" ){ }else{ errorText = Utils.getFailText( response ); } }catch(e){ errorText = Utils.processError( e, "修改用户密码出错 " + flag + " updatePassword() 出错:" ); } }else{ errorText = "参数中没有个人标志:distinguishedName , unique, employee, mobile 或 id, 不能获取用户"; print(errorText); } var result = { "result" : errorText ? "error" : "success", "description" : errorText || "" }; //if( response && response.data ){ // result.id = response.data.id; //} return result; } function updateSuperior(json){ print("修改个人汇报对象"); var errorText; var response; try{ var personData = get(json); if( typeof personData == "object" ){ personData.superior = json.superior; if( !personData.controllerList )personData.controllerList = []; var resp = applications.putQuery('x_organization_assemble_control', "person/"+personData.id, JSON.stringify(personData) ); response = Utils.parseResp( resp ); if( response.type && response.type == "success" ){ }else{ errorText = Utils.getFailText( response ); } }else{ errorText = personData; } }catch(e){ errorText = Utils.processError( e, "修改个人 updateSuperior() 出错:" ); }finally{ var result = { "result" : errorText ? "error" : "success", "description" : errorText || "" }; if( response && response.data ){ result.id = response.data.id; } return result; } } function remove(json){ print("删除个人"); var errorText; var response; try{ var person = get(json); if( typeof person == "object" ){ var resp = applications.deleteQuery('x_organization_assemble_control', "person/"+person.id ); //s人员信息 response = Utils.parseResp( resp ); if( response.type && response.type == "success" ){ }else{ errorText = Utils.getFailText( response ); } }else{ errorText = person; } }catch(e){ errorText = Utils.processError( e, "删除个人 remove() 出错:" ); }finally{ var result = { "result" : errorText ? "error" : "success", "description" : errorText || "" }; if( response && response.data ){ result.id = response.data.id; } return result; } } function init(){ var result =""; var responseText = ""; try{ //print( "requestText="+requestText ); var requestJson = JSON.parse(requestText); //print( "type of requestJson = " + typeof( requestJson )); if( typeof(requestJson) === "string" ){ requestJson = JSON.parse(requestJson); } var action = requestJson.action; print("action="+action); switch( action ){ case "add": result = add( requestJson ); break; case "update": result = update( requestJson ); break; case "updatepwd": result = updatePassword( requestJson ); break; case "updateSuperior": result = updateSuperior( requestJson ); break; case "delete" : result = remove( requestJson ); break; default : result = { "result" : "error", "description" : "requestText未设置action,不执行操作" }; break; } }catch(e){ e.printStackTrace(); result = { "result" : "error", "description" : e.name + ": " + e.message }; }finally{ print("responseText="+JSON.stringify(result)); return result; } } init();