123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947 |
- MWF.xApplication.query = MWF.xApplication.query || {};
- MWF.xApplication.query.Query = MWF.xApplication.query.Query || {};
- MWF.require("MWF.widget.Common", null, false);
- MWF.require("MWF.xScript.Macro", null, false);
- MWF.require("o2.widget.Dialog", null, false);
- MWF.xDesktop.requireApp("query.Query", "lp."+o2.language, null, false);
- /** @classdesc Importer 数据中心的导入模型。
- * @class
- * @o2cn 导入模型
- * @o2category QueryImporter
- * @o2range {QueryImporter}
- * @hideconstructor
- * @example
- * //在导入模型的事件中获取该类
- * var view = this.target;
- * */
- MWF.xApplication.query.Query.Importer = MWF.QImporter = new Class(
- /** @lends MWF.xApplication.query.Query.Importer# */
- {
- Implements: [Options, Events],
- Extends: MWF.widget.Common,
- options: {
- "style": "default",
- "moduleEvents": [
- /**
- * 加载importer(导入模型对象)的时候执行。可通过this.target获取当前对象。
- * @event MWF.xApplication.query.Query.Importer#queryLoad
- */
- "queryLoad",
- /**
- * 导入前触发,this.event指向导入的数据,您可以通过修改this.event来修改数据。
- * @event MWF.xApplication.query.Query.Importer#beforeImport
- * @example
- * <caption>this.event数据格式如下:</caption>
- *[
- * [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
- * [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ] //第二行数据
- *]
- */
- "beforeImport",
- /**
- * 前台校验成功,并且后台执行完导入后触发,this.event指向后台返回的导入结果。
- * @event MWF.xApplication.query.Query.Importer#afterImport
- * @example
- * <caption>this.event格式如下:</caption>
- * {
- * "status": "导入成功", //导入结果:状态有 "导入成功","部分成功","导入失败"
- * "data": {}, //前台组织好的需要导入的数据
- * "rowList": [], //前台组织的行对象数组
- * "count" : 10, //导入总数量
- * "failCount": 0, //失败数量
- * "distribution": "" //导入时候时的错误信息
- * }
- */
- "afterImport",
- /**
- * 数据已经生成,前台进行数据校验时触发,this.event指向导入的数据。
- * @event MWF.xApplication.query.Query.Importer#validImport
- * @example
- * <caption>this.event数据格式如下:</caption>
- * {
- * "data" : [
- * [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
- * [ "标题二","李四","男","大学专科","数学","1998-1-2","2018-9-2" ] //第二行数据
- * ],
- * "rowList": [], //导入的行对象,数据格式常见本章API的afterCreateRowData说明。
- * "validted" : true //是否校验通过,可以在本事件中修改该参数,确定是否强制导入
- * }
- */
- "validImport",
- /**
- * 创建每行需要导入的数据前触发,this.event指向当前行对象,您可以通过修改this.event.importData来修改数据。
- * @event MWF.xApplication.query.Query.Importer#beforeCreateRowData
- */
- "beforeCreateRowData",
- /**
- * 创建每行需要导入的数据后触发,this.event指向当前行对象。
- * @event MWF.xApplication.query.Query.Importer#afterCreateRowData
- * @example
- * <caption>this.event格式如下:</caption>
- * {
- * "importedData": [ "标题一","张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //导入的数据
- * "data" : {//根据导入模型生成的业务数据
- * {
- * "subject", "标题一", //subject为导入模型列配置的路径
- * "name" : "张三",
- * ...
- * },
- * "document": { //如果导入目标是内容管理,则包含document对象
- * "title": "标题一"
- * "identity": "xxx@xxx@I"
- * ...
- * },
- * "work": { //如果导入目标是流程管理,则包含work对象
- * "title": "标题一"
- * "identity": "xxx@xxx@I"
- * ...
- * },
- * "errorTextList" : [], //错误信息
- * "errorTextListExcel": [] //在出错界面导出Excel时的错误信息
- * }
- */
- "afterCreateRowData"
- ]
- },
- initialize: function(container, json, options, app, parentMacro){
- this.setOptions(options);
- this.path = "../x_component_query_Query/$Importer/";
- this.cssPath = "../x_component_query_Query/$Importer/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.lp = MWF.xApplication.query.Query.LP;
- this.app = app;
- this.json = json;
- this.container = container;
- this.parentMacro = parentMacro;
- this.lookupAction = MWF.Actions.get("x_query_assemble_surface");
- },
- load: function(){
- this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils();
- this.getImporterJSON( function () {
- this.loadMacro( function () {
- this._loadModuleEvents();
- this.fireEvent("queryLoad");
- this.importFromExcel();
- }.bind(this));
- }.bind(this));
- },
- loadMacro: function (callback) {
- MWF.require("MWF.xScript.Macro", function () {
- this.Macro = new MWF.Macro.ViewContext(this);
- if (callback) callback();
- }.bind(this));
- },
- createLoadding: function(){
- this.loadingAreaNode = new Element("div", {"styles": this.css.viewLoadingAreaNode}).inject(this.contentAreaNode);
- new Element("div", {"styles": {"height": "5px"}}).inject(this.loadingAreaNode);
- var loadingNode = new Element("div", {"styles": this.css.viewLoadingNode}).inject(this.loadingAreaNode);
- new Element("div", {"styles": this.css.viewLoadingIconNode}).inject(loadingNode);
- var loadingTextNode = new Element("div", {"styles": this.css.viewLoadingTextNode}).inject(loadingNode);
- loadingTextNode.set("text", "loading...");
- },
- getImporterJSON: function(callback){
- if( this.importerJson && this.json ){
- if (callback) callback();
- }else{
- if (this.json.name){
- this.lookupAction.getImportModel(this.json.name, this.json.application, function(json){
- this.importerId = json.data.id;
- this.importerJson = JSON.decode(json.data.data);
- json.data.data = this.importerJson;
- this.json = Object.merge(this.json, json.data);
- if (callback) callback();
- }.bind(this));
- }else{
- this.lookupAction.getImportModelById(this.json.id, function(json){
- this.importerId = json.data.id;
- this.importerJson = JSON.decode(json.data.data);
- json.data.data = this.importerJson;
- this.json.application = json.data.query;
- this.json = Object.merge(this.json, json.data);
- if (callback) callback();
- }.bind(this));
- }
- }
- },
- _loadModuleEvents : function(){
- Object.each(this.json.data.events, function(e, key){
- if (e.code){
- if (this.options.moduleEvents.indexOf(key)!==-1){
- this.addEvent(key, function(event, target){
- return this.Macro.fire(e.code, target || this, event);
- }.bind(this));
- }
- }
- }.bind(this));
- },
- getDateColIndexArray: function(){
- var dateColIndexArray = [];
- this.json.data.columnList.each(function(columnJson, index){
- var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
- if( ["date","dateTime"].contains(dataType) )dateColIndexArray.push( index );
- }.bind(this));
- return dateColIndexArray;
- },
- getOrgColIndexArray : function(){
- var orgColIndexArray = [];
- this.json.data.columnList.each(function(columnJson, index){
- if( columnJson.isName ) {
- orgColIndexArray.push(index);
- }
- // }else if( this.json.type === "cms" ){
- // if( columnJson.isPublisher || columnJson.isAuthor || columnJson.isReader ){
- // orgColIndexArray.push( index );
- // }
- // }
- }.bind(this));
- return orgColIndexArray;
- },
- importFromExcel : function(){
- this.rowList = [];
- this.identityMapImported = {};
- this.personMapImported = {};
- this.unitMapImported = {};
- this.groupMapImported = {};
- this.lookupAction.getUUID( function (json){
- this.recordId = json.data;
- }.bind(this), null, false);
- this.excelUtils.upload( this.getDateColIndexArray(), function (importedData) {
- importedData = importedData.filter(function (array) {
- for( var i=0; i<array.length; i++ ){
- if(array[i])return true;
- }
- return false;
- });
- if( !importedData.length )return;
- var titleLength = importedData[0].length;
- importedData.each(function (array) {
- for( var i=0; i<titleLength; i++){
- if( typeOf(array[i]) === "null" )array[i] = "";
- }
- })
- this.progressBar = new MWF.xApplication.query.Query.Importer.ProgressBar( this, {
- "onPostShow": function(){
- this.progressBar.showCheckData();
- debugger;
- this.importedData = importedData;
- if( this.importedData.length > 0 )this.importedData.shift();
- this.fireEvent("beforeImport", [this.importedData]);
- Promise.resolve( this.importedData.promise ).then(function () {
- this.listOrgDataFromDb(
- this.getImportedOrgData(),
- function () {
- this.importedData.each( function( lineData, lineIndex ){
- this.rowList.push( new MWF.xApplication.query.Query.Importer.Row( this, lineData, lineIndex ) )
- }.bind(this));
- var isValid = this.json.enableValid ? this.checkImportedData() : this.checkNecessaryImportedData();
- Promise.resolve(isValid).then(function ( isValid1 ) {
- if( isValid1 ){
- this.doImportData();
- }else{
- this.openImportedErrorDlg();
- }
- }.bind(this));
- }.bind(this)
- );
- }.bind(this));
- }.bind(this)
- });
- this.progressBar.importerId = this.importerId;
- }.bind(this));
- },
- getData : function(){
- var data = ( this.rowList || [] ).map( function(row){
- return row.getResult();
- });
- return data;
- },
- doImportData: function(){
- //创建数据
- // this.rowList.each( function( row, i ){
- // row.createData();
- // }.bind(this));
- //再次校验数据(计算的内容)
- var date = new Date();
- //var flag = true;
- // this.rowList.each( function(row, index){
- // if( row.errorTextList.length )flag = false;
- // }.bind(this));
- // var arg = {
- // validted : flag,
- // data : this.importedData,
- // rowList : this.rowList
- // };
- // this.fireEvent( "import", [arg] );
- // Promise.resolve( arg.promise ).then(function(){
- // flag = arg.validted;
- //
- // if( !flag ){
- // this.openImportedErrorDlg();
- // return;
- // }
- var data = this.getData();
- // this.lookupAction.getUUID(function(json){
- // this.recordId = json.data;
- this.lookupAction.executImportModel(this.json.id, {
- "recordId": this.recordId,
- "data" : data
- }, function () {
- //this.showImportingStatus( data, date )
- this.progressBar.showImporting( this.recordId, function( data ){
- data.data = data;
- data.rowList = this.rowList;
- this.fireEvent("afterImport", data);
- return data;
- }.bind(this), date);
- }.bind(this), function (xhr) {
- var requestJson = JSON.parse(xhr.responseText);
- this.app.notice(requestJson.message, "error");
- this.progressBar.close();
- }.bind(this))
- // }.bind(this))
- // }.bind(this))
- },
- objectToString: function (obj, type) {
- if(!obj)return "";
- var arr = [];
- Object.each(obj, function (value, key) {
- if( type === "style" ){
- arr.push( key + ":"+ value +";" );
- }else{
- arr.push( key + "='"+ value +"'" );
- }
- })
- return arr.join( " " )
- },
- openImportedErrorDlg : function(){
- if(this.progressBar)this.progressBar.close();
- var _self = this;
- var div = new Element("div", { style : "padding:10px;" });
- var dlg = o2.DL.open({
- "style" : "user",
- "title": this.lp.importFail,
- "content": div,
- "offset": {"y": 0},
- "isMax": true,
- "width": 1000,
- "height": 700,
- "buttonList": [
- {
- "type": "exportWithError",
- "text": this.lp.exportExcel,
- "action": function () { _self.exportWithImportDataToExcel(); }
- },
- {
- "type": "cancel",
- "text": this.lp.cancel,
- "action": function () { dlg.close(); }
- }
- ],
- "onPostShow": function () {
- var htmlArray = ["<table "+ this.objectToString( this.css.properties ) +" style='"+this.objectToString( this.css.tableStyles, "style" )+"'>"];
- var titleStyle = this.objectToString( this.css.titleStyles, "style" );
- var vaildTitleStyles = this.objectToString( this.css.vaildTitleStyles, "style" );
- htmlArray.push( "<tr>" );
- this.json.data.columnList.each( function (columnJson, i) {
- htmlArray.push( "<th style='"+titleStyle+"'>"+columnJson.displayName+"</th>" );
- });
- htmlArray.push( "<th style='"+vaildTitleStyles+"'> "+this.lp.validationInfor +"</th>" );
- htmlArray.push( "</tr>" );
- var contentStyles = Object.clone( this.css.contentStyles );
- if( !contentStyles[ "border-bottom" ] && !contentStyles[ "border" ] )contentStyles[ "border-bottom" ] = "1px solid #eee";
- var contentStyle = this.objectToString( Object.merge( contentStyles, {"text-align":"left"}) , "style" );
- var validContentStyles = this.objectToString( this.css.validContentStyles, "style" );
- this.rowList.each( function( row, lineIndex ){
- var lineData = row.importedData;
- htmlArray.push( "<tr>" );
- this.json.data.columnList.each( function (columnJson, i) {
- var d = lineData[ i ];
- var text = typeOf(d) === "string" ? ( d || '' ).replace(/ /g,"<br/>") : d;
- htmlArray.push( "<td style='"+contentStyle+"'>"+ text +"</td>" ); //换行符
- });
- htmlArray.push( "<td style='"+validContentStyles+"'>"+( row.errorTextList ? row.errorTextList.join("<br/>") : "" )+"</td>" );
- htmlArray.push( "</tr>" );
- }.bind(this));
- htmlArray.push( "</table>" );
- div.set("html" , htmlArray.join(""));
- }.bind(this),
- "onPostClose": function(){
- dlg = null;
- }.bind(this)
- });
- },
- //必须校验的数据
- checkNecessaryImportedData: function(){
- var flag = true;
- var ps = this.rowList.each( function(row, index){
- return row.checkNecessary();
- }.bind(this));
- return Promise.all( ps ).then(function (arr) {
- for( var i=0; i<arr.length; i++ ){
- if( arr[i] === false )flag = false;
- }
- var arg = {
- validted : flag,
- data : this.importedData,
- rowList : this.rowList
- };
- this.fireEvent( "validImport", [arg] );
- return Promise.resolve( arg.promise ).then(function () {
- return arg.validted;
- });
- })
- },
- //校验Excel中的数据
- checkImportedData : function(){
- var flag = true;
- var ps = this.rowList.map( function(row, index){
- return row.checkValid();
- }.bind(this));
- return Promise.all(ps).then(function (arr) {
- for( var i=0; i<arr.length; i++ ){
- if( arr[i] === false )flag = false
- }
- var arg = {
- validted : flag,
- data : this.importedData,
- rowList : this.rowList
- };
- this.fireEvent( "validImport", [arg] );
- return Promise.resolve( arg.promise ).then(function () {
- return arg.validted;
- });
- }.bind(this));
- },
- getOrgData : function( str, ignoreNone, isParse ){
- str = str.trim();
- var flag = str.substr(str.length-2, 2);
- var d;
- switch (flag.toLowerCase()){
- case "@i":
- d = this.identityMapImported[str];
- break;
- case "@p":
- d = this.personMapImported[str];
- break;
- case "@u":
- d = this.unitMapImported[str];
- break;
- case "@g":
- d = this.groupMapImported[str];
- break;
- default:
- d = this.identityMapImported[str] ||
- this.personMapImported[str] ||
- this.unitMapImported[str] ||
- this.groupMapImported[str];
- break;
- }
- if( d )return isParse ? MWF.org.parseOrgData(d, true, true) : d;
- if( ignoreNone ) {
- return null;
- }else{
- return {"errorText": str + this.lp.notExistInSystem };
- }
- },
- getOrgExtendData: function( orgList ){
- var identityList = [], personList = [], unitList = [], groupList = [];
- orgList.each(function (org) {
- var a;
- switch (typeOf( org )) {
- case "string":
- a = org; break;
- case "object":
- a = org.distinguishedName || org.unique || org.employee; break;
- }
- if( !a )return;
- var d = this.getOrgData(a, true, false);
- if( d )return;
- var flag = a.substr(a.length - 2, 2);
- switch (flag.toLowerCase()) {
- case "@i":
- identityList.push(a);
- break;
- case "@p":
- personList.push(a);
- break;
- case "@u":
- unitList.push(a);
- break;
- case "@g":
- groupList.push(a);
- break;
- default:
- identityList.push(a);
- personList.push(a);
- unitList.push(a);
- groupList.push(a);
- break;
- }
- }.bind(this));
- return this.listOrgDataFromDb({
- identityList: identityList,
- personList: personList,
- unitList: unitList,
- groupList: groupList
- });
- },
- stringToArray: function(string){
- return string.replace(/[\n\r]/g,",").replace(/ /g,",").split(/\s*,\s*/g ).filter(function(s){
- return !!s;
- });
- },
- getImportedOrgData: function() {
- var orgColIndexArray = this.getOrgColIndexArray();
- var identityList = [], personList = [], unitList = [], groupList = [];
- if( orgColIndexArray.length > 0 ) {
- this.importedData.each(function (lineData, lineIndex) {
- // if( lineIndex === 0 )return;
- orgColIndexArray.each(function (colIndex, i) {
- if (!lineData[colIndex]) return;
- var arr = this.stringToArray(lineData[colIndex]);
- arr.each(function (a) {
- a = a.trim();
- var flag = a.substr(a.length - 2, 2);
- switch (flag.toLowerCase()) {
- case "@i":
- identityList.push(a);
- break;
- case "@p":
- personList.push(a);
- break;
- case "@u":
- unitList.push(a);
- break;
- case "@g":
- groupList.push(a);
- break;
- default:
- identityList.push(a);
- personList.push(a);
- unitList.push(a);
- groupList.push(a);
- break;
- }
- })
- }.bind(this))
- }.bind(this));
- };
- return {
- identityList: identityList,
- personList: personList,
- unitList: unitList,
- groupList: groupList
- };
- },
- listOrgDataFromDb : function (importedOrgData, callback ) {
- var identityList = importedOrgData.identityList;
- var personList = importedOrgData.personList;
- var unitList = importedOrgData.unitList;
- var groupList = importedOrgData.groupList;
- var pIdentity;
- if( identityList && identityList.length ){
- pIdentity = o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : identityList.unique() });
- }
- var pPerson;
- if( personList && personList.length ){
- pPerson = o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : personList.unique() });
- }
- var pUnit;
- if( unitList && unitList.length ){
- pUnit = o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList : unitList.unique() });
- }
- var pGroup;
- if( groupList && groupList.length ){
- pGroup = o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ groupList : groupList.unique() });
- }
- return Promise.all( [pIdentity, pPerson, pUnit, pGroup] ).then(function (arr) {
- if( arr[0] && arr[0].data && arr[0].data.length ){
- arr[0].data.each( function (d) { if(d)this.identityMapImported[ d.matchKey ] = d; }.bind(this));
- }
- if( arr[1] && arr[1].data && arr[1].data.length ){
- arr[1].data.each( function (d) { if(d)this.personMapImported[ d.matchKey ] = d; }.bind(this));
- }
- if( arr[2] && arr[2].data && arr[2].data.length ){
- arr[2].data.each( function (d) { if(d)this.unitMapImported[ d.matchKey ] = d; }.bind(this));
- }
- if( arr[3] && arr[3].data && arr[3].data.length ){
- arr[3].data.each( function (d) { if(d)this.groupMapImported[ d.matchKey ] = d; }.bind(this));
- }
- if( callback )callback();
- return;
- }.bind(this))
- },
- // listOrgDataFromDb : function (importedOrgData, callback ) {
- //
- // var identityList = importedOrgData.identityList;
- // var personList = importedOrgData.personList;
- // var unitList = importedOrgData.unitList;
- // var groupList = importedOrgData.groupList;
- //
- // var identityLoaded, personLoaded, unitLoaded, groupLoaded;
- // var check = function () {
- // if( identityLoaded && personLoaded && unitLoaded && groupLoaded ){
- // if(callback)callback();
- // }
- // };
- //
- // if( identityList && identityList.length ){
- // identityList = identityList.unique();
- // o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : identityList }, function (json) {
- // json.data.each( function (d) { if(d)this.identityMapImported[ d.matchKey ] = d; }.bind(this));
- // identityLoaded = true;
- // check();
- // }.bind(this))
- // }else{
- // identityLoaded = true;
- // check();
- // }
- //
- // if( personList && personList.length ){
- // personList = personList.unique();
- // o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : personList }, function (json) {
- // json.data.each( function (d) { if(d)this.personMapImported[ d.matchKey ] = d; }.bind(this));
- // personLoaded = true;
- // check();
- // }.bind(this))
- // }else{
- // personLoaded = true;
- // check();
- // }
- //
- // if( unitList && unitList.length ){
- // unitList = unitList.unique();
- // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList : unitList }, function (json) {
- // json.data.each( function (d) { if(d)this.unitMapImported[ d.matchKey ] = d; }.bind(this));
- // unitLoaded = true;
- // check();
- // }.bind(this))
- // }else{
- // unitLoaded = true;
- // check();
- // }
- //
- // if( groupList && groupList.length ){
- // groupList = groupList.unique();
- // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ groupList : groupList }, function (json) {
- // json.data.each( function (d) { if(d)this.groupMapImported[ d.matchKey ] = d; }.bind(this));
- // groupLoaded = true;
- // check();
- // }.bind(this))
- // }else{
- // groupLoaded = true;
- // check();
- // }
- // },
- // showImportingStatus: function( improtedData, date ){
- // this.progressBar.showImporting( this.recordId, function( data ){
- // data.data = improtedData;
- // data.rowList = this.rowList;
- // this.fireEvent("afterImport", data)
- // }.bind(this), date);
- // },
- exportWithImportDataToExcel : function ( importData ) {
- if( !this.excelUtils ){
- this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils();
- }
- var exportTo = function () {
- var resultArr = [];
- var titleArr = this.getTitleArray();
- titleArr.push( this.lp.validationInfor );
- resultArr.push( titleArr );
- if( importData ){
- importData.each( function (lineData, lineIndex) {
- var array = [];
- if( o2.typeOf(lineData)==="array" ) {
- lineData.each(function (d, i) {
- array.push((d || '').replace(/ /g, "\n"));
- });
- }else if(o2.typeOf(lineData)==="object"){
- this.json.data.columnList.each( function (columnJson, i) {
- array.push( lineData[columnJson.path] || "" )
- }.bind(this));
- if( lineData["o2ErrorText"] ){
- array.push( lineData["o2ErrorText"] );
- }
- }
- resultArr.push( array );
- }.bind(this));
- }else{
- this.rowList.each( function( row, lineIndex ){
- var lineData = row.importedData;
- var array = [];
- for( var i=0; i<lineData.length; i++ ){
- var d = ( lineData[i] || '' ).replace(/ /g, "\n");
- array.push( d );
- }
- // lineData.each( function (d, i) {
- // array.push( ( d || '' ).replace(/ /g, "\n") );
- // });
- array.push( row.errorTextListExcel ? row.errorTextListExcel.join("\n") : "" );
- resultArr.push( array );
- }.bind(this));
- }
- var colWidthArray = this.getColWidthArray();
- colWidthArray.push(260);
- var arg = {
- data : resultArr,
- colWidthArray : colWidthArray,
- title : this.getFileName()
- };
- this.fireEvent("export", [arg]);
- this.excelUtils.exportToExcel(
- arg.data,
- arg.title,
- arg.colWidthArray,
- this.getDateIndexArray()
- )
- }.bind(this);
- if( !this.importerJson ){
- this.getImporterJSON( function () {
- exportTo();
- }.bind(this))
- }else{
- exportTo();
- }
- },
- downloadTemplate: function(fileName, callback){
- if( this.Macro ){
- this._downloadTemplate(fileName, callback);
- }else{
- this.loadMacro(function (){
- this._downloadTemplate(fileName, callback);
- }.bind(this));
- }
- },
- _downloadTemplate: function(fileName, callback){
- if( !this.excelUtils ){
- this.excelUtils = new MWF.xApplication.query.Query.Importer.ExcelUtils({
- isTemplate: true
- });
- }
- var doExport = function () {
- var arg = {
- data : [this.getTitleArray()],
- colWidthArray : this.getColWidthArray(),
- title : this.getFileName(fileName)
- };
- if(callback)callback(arg);
- this.excelUtils.exportToExcel(
- arg.data,
- arg.title,
- arg.colWidthArray,
- this.getDateIndexArray()
- )
- }.bind(this)
- if( !this.importerJson ){
- this.getImporterJSON( function () {
- doExport()
- }.bind(this))
- }else{
- doExport();
- }
- },
- getFileName: function(fileName){
- var title = fileName || this.json.name;
- var titleA = title.split(".");
- if( ["xls","xlst"].contains( titleA[titleA.length-1].toLowerCase() ) ){
- titleA.splice( titleA.length-1 );
- }
- title = titleA.join(".");
- return title;
- },
- getTitleArray: function(){
- return this.json.data.columnList.map( function (columnJson, i) {
- var obj = {
- text: columnJson.displayName
- };
- if( columnJson.optionScript ){
- obj.options = this.Macro.exec(columnJson.optionScript, this);
- }
- return obj;
- }.bind(this));
- },
- getColWidthArray : function(){
- var colWidthArr = [];
- this.json.data.columnList.each( function (columnJson, i) {
- var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
- switch ( dataType ) {
- case "string":
- case "stringList":
- if( columnJson.isName ){
- colWidthArr.push( 340 );
- }else if( columnJson.isSummary ){
- colWidthArr.push( 260 );
- }else{
- colWidthArr.push( 150 );
- }
- break;
- case "number":
- case "integer":
- case "long":
- case "double":
- case "numberList":
- case "integerList":
- case "longList":
- case "doubleList":
- colWidthArr.push(150);
- break;
- case "date":
- case "dateTime":
- case "dateList":
- case "dateTimeList":
- colWidthArr.push(150);
- break;
- default:
- colWidthArr.push(150);
- break;
- }
- }.bind(this));
- return colWidthArr;
- },
- getDateIndexArray : function(){
- var dateIndexArr = []; //日期格式列下标
- this.json.data.columnList.each( function (columnJson, i) {
- var dataType = this.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
- switch ( dataType ) {
- case "date":
- case "dateTime":
- case "dateList":
- case "dateTimeList":
- dateIndexArr.push(i);
- break;
- default:
- break;
- }
- }.bind(this));
- return dateIndexArr;
- },
- //api 使用 开始
- confirm: function (type, e, title, text, width, height, ok, cancel, callback, mask, style) {
- this.app.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style)
- },
- alert: function (type, title, text, width, height) {
- this.app.alert(type, "center", title, text, width, height);
- },
- notice: function (content, type, target, where, offset, option) {
- this.app.notice(content, type, target, where, offset, option)
- }
- //api 使用 结束
- });
- MWF.xApplication.query.Query.Importer.Row = new Class({
- initialize: function(importer, importedData, rowIndex){
- this.importer = importer;
- this.importedData = importedData;
- this.clazzType = "row";
- this.lp = this.importer.lp;
- this.data = {};
- this.errorTextList = [];
- this.errorTextListExcel = [];
- this.calculateFieldDataMap = {};
- },
- checkValid : function(){
- var lp = this.lp;
- var columnText = lp.importValidationColumnText;
- var columnTextExcel = lp.importValidationColumnTextExcel;
- var errorTextList = [];
- var errorTextListExcel = [];
- this.importer.json.data.columnList.each( function (columnJson, i) {
- var colName = this.importer.excelUtils.index2ColName( i );
- var colInfor = columnText.replace( "{n}", (i+1)+"("+colName+")" );
- var colInforExcel = columnTextExcel.replace( "{n}", colName );
- var value = this.importedData[i] || "";
- var dataType = this.importer.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
- if( !columnJson.allowEmpty && !value ){
- errorTextList.push( colInfor + lp.canNotBeEmpty + lp.fullstop );
- errorTextListExcel.push( colInforExcel + lp.canNotBeEmpty + lp.fullstop );
- }
- if( columnJson.validInOption && columnJson.optionScript && value ){
- var options = this.importer.Macro.exec(columnJson.optionScript, this);
- if( !options.contains(value) ){
- errorTextList.push( colInfor + lp.notInOptions +":"+ options.join(",") + lp.fullstop );
- errorTextListExcel.push( colInforExcel + lp.notInOptions +":"+ options.join(",") + lp.fullstop );
- }
- }
- if( columnJson.validFieldType !== false && value ){
- switch ( dataType ) {
- case "string":
- case "stringList":
- if( columnJson.isName ){
- var arr = this.stringToArray(value);
- arr.each( function(d, idx){
- var obj = this.importer.getOrgData( d );
- if( obj.errorText ){
- errorTextList.push( colInfor + obj.errorText + lp.fullstop );
- errorTextListExcel.push( colInforExcel + obj.errorText + lp.fullstop );
- }
- }.bind(this));
- }
- break;
- case "number":
- case "integer":
- case "long":
- case "double":
- value = value.replace(/ /g,"");
- if (isNaN(value)){
- errorTextList.push( colInfor + value + lp.notValidNumber + lp.fullstop );
- errorTextListExcel.push( colInforExcel + value + lp.notValidNumber + lp.fullstop );
- }
- break;
- case "numberList":
- case "integerList":
- case "longList":
- case "doubleList":
- var arr = this.stringToArray(value);
- arr.each( function(d, idx){
- if (isNaN(d)){
- errorTextList.push( colInfor + d + lp.notValidNumber + lp.fullstop );
- errorTextListExcel.push( colInforExcel + d + lp.notValidNumber + lp.fullstop );
- }
- }.bind(this));
- break;
- case "date":
- case "dateTime":
- value = value.replace(/ /g,"");
- if( !( new Date(value).isValid() )){
- errorTextList.push(colInfor + value + lp.notValidDate + lp.fullstop );
- errorTextListExcel.push( colInforExcel + value + lp.notValidDate + lp.fullstop );
- }
- break;
- case "dateList":
- case "dateTimeList":
- var arr = this.stringToArray(value);
- arr.each( function(d, idx){
- if( !( new Date(d).isValid() )){
- errorTextList.push(colInfor + d + lp.notValidDate + lp.fullstop );
- errorTextListExcel.push( colInforExcel + d + lp.notValidDate + lp.fullstop );
- }
- }.bind(this));
- break;
- case "boolean":
- value = value.replace(/ /g,"");
- if( !["true","false"].contains(value.trim().toLowerCase()) ){
- errorTextList.push(colInfor + value + lp.notValidBoolean + lp.fullstop );
- errorTextListExcel.push( colInforExcel + value + lp.notValidBoolean + lp.fullstop );
- }
- break;
- case "booleanList":
- var arr = this.stringToArray(value);
- arr.each( function(d, idx){
- if( !["true","false"].contains(d.trim().toLowerCase())){
- errorTextList.push(colInfor + d + lp.notValidBoolean + lp.fullstop );
- errorTextListExcel.push( colInforExcel + d + lp.notValidBoolean + lp.fullstop );
- }
- }.bind(this));
- break;
- case "json":
- case "stringMap":
- value = value.replace(/ /g,"");
- try{
- var d = JSON.parse(value);
- }catch (e) {
- errorTextList.push(colInfor + value + lp.notValidJson + lp.fullstop );
- errorTextListExcel.push( colInforExcel + value + lp.notValidJson + lp.fullstop );
- }
- break;
- default:
- break;
- }
- }
- }.bind(this));
- this.errorTextList = this.errorTextList.concat( errorTextList );
- this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
- if(this.errorTextList.length>0){
- return false;
- }
- var p = this.createData();
- return Promise.resolve( p ).then(function (flag) {
- this.importer.json.data.calculateFieldList.each( function (fieldJson, i) {
- if( !fieldJson.path )return;
- if( fieldJson.isName ){
- var sourceData = this.calculateFieldDataMap[fieldJson.path];
- var arr = typeOf( sourceData ) === "array" ? sourceData : [sourceData];
- arr = typeOf( arr ) === "array" ? arr : [arr];
- arr.each(function (d, idx) {
- if( !d )return d;
- var a;
- switch (typeOf( d )) {
- case "string":
- a = d; break;
- case "object":
- a = d.distinguishedName || d.unique || d.employee; break;
- }
- if( !a )return d;
- var obj = this.importer.getOrgData( a );
- if( obj.errorText ){
- var errorText = (fieldJson.displayName || fieldJson.path) + ":" + obj.errorText + lp.fullstop;
- errorTextList.push( errorText );
- errorTextListExcel.push( errorText );
- }
- }.bind(this));
- }
- }.bind(this));
- this.errorTextList = this.errorTextList.concat( errorTextList );
- this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
- if( this.errorTextList.length > 0 )return false;
- if( this.importer.json.type === "cms" ){
- this.checkCMS( true );
- }else if( this.importer.json.type === "process" ){
- this.checkProcess( true );
- }
- if(this.errorTextList.length>0){
- return false;
- }
- return true;
- }.bind(this));
- },
- checkNecessary: function(){
- var lp = this.lp;
- var columnText = lp.importValidationColumnText;
- var columnTextExcel = lp.importValidationColumnTextExcel;
- var errorTextList = [];
- var errorTextListExcel = [];
- this.importer.json.data.columnList.each( function (columnJson, i) {
- var colName = this.importer.excelUtils.index2ColName( i );
- var colInfor = columnText.replace( "{n}", (i+1)+"("+colName+")" );
- var colInforExcel = columnTextExcel.replace( "{n}", colName );
- var value = this.importedData[i] || "";
- var dataType = this.importer.json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess;
- if( columnJson.validFieldType !== false && value ){
- switch ( dataType ) {
- case "json":
- case "stringMap":
- value = value.replace(/ /g,"");
- try{
- var d = JSON.parse(value);
- }catch (e) {
- errorTextList.push(colInfor + value + lp.notValidJson + lp.fullstop );
- errorTextListExcel.push( colInforExcel + value + lp.notValidJson + lp.fullstop );
- }
- break;
- default:
- break;
- }
- }
- }.bind(this));
- this.errorTextList = this.errorTextList.concat( errorTextList );
- this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
- if(this.errorTextList.length>0){
- return false;
- }
- var p = this.createData();
- return Promise.resolve(p).then(function () {
- if( this.importer.json.type === "cms" ){
- this.checkCMS();
- }else if( this.importer.json.type === "process" ){
- this.checkProcess();
- }
- if(this.errorTextList.length>0){
- return false;
- }
- return true;
- }.bind(this))
- },
- getCol: function(key, isExcel){
- var text, lp = this.lp;
- if( this.pathIndexMap && typeOf(this.pathIndexMap[key]) === "number"){
- var i = this.pathIndexMap[key];
- if( isExcel ){
- text = lp.importValidationColumnTextExcel;
- return text.replace( "{n}", this.importer.excelUtils.index2ColName( i ) );
- }else{
- text = lp.importValidationColumnText;
- return text.replace( "{n}", i+1 );
- }
- }
- return "";
- },
- checkCMS : function( notCheckName ){
- var lp = this.lp;
- var errorTextList = [];
- var errorTextListExcel = [];
- var data = this.document.identity;
- if(!data){
- errorTextList.push( this.getCol("identity", false) + lp.noDrafter + lp.fullstop );
- errorTextListExcel.push( this.getCol("identity", true) + lp.noDrafter + lp.fullstop );
- }else if(data.split("@").getLast().toLowerCase() !== "i"){
- errorTextList.push( this.getCol("identity", false) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
- errorTextListExcel.push( this.getCol("identity", true) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
- }
- data = this.document.publishTime;
- if(!data){
- errorTextList.push(this.getCol("publishTime", false) + lp.noPublishTime + lp.fullstop );
- errorTextListExcel.push(this.getCol("publishTime", false) + lp.noPublishTime + lp.fullstop );
- }else if( ! new Date(data).isValid() ){
- errorTextList.push(this.getCol("publishTime", false) + '"'+ data +'"'+ lp.publishTimeFormatError + lp.fullstop );
- errorTextListExcel.push(this.getCol("publishTime", false) + '"'+ data +'"'+ lp.publishTimeFormatError + lp.fullstop );
- }
- data = this.document.title;
- if( data && data.length > 70){
- errorTextList.push(this.getCol("title", false) + '"'+ data +'"'+ lp.cmsTitleLengthInfor + lp.fullstop );
- errorTextListExcel.push(this.getCol("title", false) + '"'+ data +'"'+ + lp.cmsTitleLengthInfor + lp.fullstop );
- }
- data = this.document.summary;
- if( data && data.length > 70 ){
- errorTextList.push(this.getCol("summary", false) + '"'+ data +'"'+ lp.cmsSummaryLengthInfor + lp.fullstop );
- errorTextListExcel.push( this.getCol("summary", false) + '"'+ data +'"'+ lp.cmsSummaryLengthInfor + lp.fullstop );
- }
- this.errorTextList = this.errorTextList.concat( errorTextList );
- this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
- if(errorTextList.length > 0){
- return false;
- }
- return true;
- },
- checkProcess : function( notCheckName ){
- var lp = this.lp;
- var json = this.importer.json;
- var columnText = lp.importValidationColumnText;
- var columnTextExcel = lp.importValidationColumnTextExcel;
- var errorTextList = [];
- var errorTextListExcel = [];
- var data = this.work.identity;
- if(!data){
- errorTextList.push( this.getCol("identity", false) + lp.noDrafter + lp.fullstop );
- errorTextListExcel.push( this.getCol("identity", true) + lp.noDrafter + lp.fullstop );
- }else if(data.split("@").getLast().toLowerCase() !== "i"){
- errorTextList.push( this.getCol("identity", false) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
- errorTextListExcel.push( this.getCol("identity", true) + '"'+ data +'"'+ lp.drafterIsNotIdentity + lp.fullstop );
- }
- if( json.data.processStatus === "completed" ){
- if(!this.work.form){
- errorTextList.push( lp.noForm + lp.fullstop );
- errorTextListExcel.push( lp.noForm + lp.fullstop );
- }
- data = this.work.startTime;
- if(!data){
- errorTextList.push(this.getCol("startTime", false) + lp.noStartTime + lp.fullstop );
- errorTextListExcel.push(this.getCol("startTime", false) + lp.noStartTime + lp.fullstop );
- }else if( ! new Date(data).isValid() ){
- errorTextList.push(this.getCol("startTime", false) + '"'+ data +'"'+ lp.startTimeFormatError + lp.fullstop );
- errorTextListExcel.push(this.getCol("startTime", false) + '"'+ data +'"'+ lp.startTimeFormatError + lp.fullstop );
- }
- data = this.work.completeTime;
- if(!data){
- errorTextList.push(this.getCol("completeTime", false) + lp.noEndTime + lp.fullstop );
- errorTextListExcel.push(this.getCol("completeTime", false) + lp.noEndTime + lp.fullstop );
- }else if( ! new Date(data).isValid() ){
- errorTextList.push(this.getCol("completeTime", false) + '"'+ data +'"'+ lp.endTimeFormatError + lp.fullstop );
- errorTextListExcel.push(this.getCol("completeTime", false) + '"'+ data +'"'+ lp.endTimeFormatError + lp.fullstop );
- }
- }
- this.errorTextList = this.errorTextList.concat( errorTextList );
- this.errorTextListExcel = this.errorTextListExcel.concat( errorTextListExcel );
- if(errorTextList.length > 0){
- return false;
- }
- return true;
- },
- createData : function(){
- var json = this.importer.json;
- if( json.type === "cms" ){
- this.document = {
- categoryId : json.data.category.id,
- readerList : [],
- authorList : [],
- docData : this.data
- };
- }else if( json.type === "process" ){
- this.work = {
- processFlag : json.data.process.id,
- data: this.data
- };
- }
- this.importer.fireEvent("beforeCreateRowData", [this]);
- json.data.columnList.each( function (columnJson, i) {
- if(!columnJson.path)return;
- var value = this.importedData[i] || "";
- if( !value && columnJson.defaultValueScript ){
- value = this.importer.Macro.exec(columnJson.defaultValueScript, this);
- }
- var dataType = (json.type === "dynamicTable" ? columnJson.dataType_Querytable : columnJson.dataType_CMSProcess);
- if( !value && ["number","double","integer","long"].contains(dataType) ){
- value = 0;
- }
- if( !value && (typeOf(value) === "null" || value === "") )return;
- var data = this.parseData(value, dataType, columnJson);
- if( !data && data !== 0 && data !== false )return;
- if( json.type === "dynamicTable" ){
- this.data[ columnJson.path ] = data;
- }else{
- this.setDataWithPath(this.data, columnJson.path, data);
- }
- var array;
- if( json.type === "cms" ){
- if( columnJson.isName ) {
- if (columnJson.isAuthor) {
- array = this.parseCMSReadAndAuthor(data, "作者");
- this.document.authorList = this.document.authorList.concat(array)
- }
- if (columnJson.isReader) {
- array = this.parseCMSReadAndAuthor(data, "阅读");
- this.document.readerList = this.document.readerList.concat(array)
- }
- }
- }
- }.bind(this));
- var calculateOrgData = [], caculateMap = {};
- json.data.calculateFieldList.each( function (fieldJson, i) {
- if( !fieldJson.path )return;
- if( !fieldJson.valueScript )return;
- var data = this.importer.Macro.exec(fieldJson.valueScript, this);
- this.calculateFieldDataMap[fieldJson.path] = data;
- caculateMap[fieldJson.path] = data;
- if( fieldJson.isName && data ){
- switch (o2.typeOf(data)) {
- case "array":
- if(data.length)calculateOrgData = calculateOrgData.concat(data); break;
- default:
- calculateOrgData.push(data); break;
- }
- }
- }.bind(this));
- var p = this.importer.getOrgExtendData( calculateOrgData );
- return Promise.resolve(p).then(function () {
- json.data.calculateFieldList.each( function (fieldJson, i) {
- if( !fieldJson.path )return;
- if( !fieldJson.valueScript )return;
- var data;
- if( fieldJson.isName ){
- var arr = caculateMap[fieldJson.path];
- arr = typeOf( arr ) === "array" ? arr : [arr];
- data = arr.map(function (d, idx) {
- if( !d )return d;
- var a;
- switch (typeOf( d )) {
- case "string":
- a = d; break;
- case "object":
- a = d.distinguishedName || d.unique || d.employee; break;
- }
- if( !a )return d;
- return this.importer.getOrgData( a, true, true );
- }.bind(this));
- data = data.clean();
- }else{
- data = caculateMap[fieldJson.path];
- }
- if( o2.typeOf(data) === "null" )return;
- if( json.type === "dynamicTable" ){
- this.data[ fieldJson.path ] = data;
- }else{
- this.setDataWithPath(this.data, fieldJson.path, data);
- }
- if( json.type === "cms" ){
- if( fieldJson.isAuthor ){
- var array = this.parseCMSReadAndAuthor( data, "作者" );
- this.document.authorList = this.document.authorList.concat( array )
- }
- if( fieldJson.isReader ){
- var array = this.parseCMSReadAndAuthor( data, "阅读" );
- this.document.readerList = this.document.readerList.concat( array )
- }
- }
- }.bind(this));
- var array;
- if( json.type === "cms" ){
- this.document.docData = this.data;
- if( json.data.documentPublisher === "importer" ){
- array = layout.session.user.identityList;
- if( array && array.length ){
- this.document.identity = array[0].distinguishedName;
- }
- }else{
- this.setDataWithField(this.document, "documentPublisherField", "identity", true);
- }
- if( json.data.documentPublishTime === "importer" ){
- this.document.publishTime = new Date().format("db");
- }else{
- this.setDataWithField(this.document, "documentPublisherTimeField", "publishTime", false);
- }
- this.setDataWithField(this.document, "documentTitleField", "title", false);
- if( !this.document.title )this.document.title = "无标题";
- this.setDataWithField(this.document, "documentSummaryField", "summary", false);
- }else if( json.type === "process" ){
- this.work.data = this.data;
- if( json.data.processDrafter === "importer" ){
- array = layout.session.user.identityList;
- if( array && array.length ){
- this.work.identity = array[0].distinguishedName
- }
- }else{
- this.setDataWithField(this.work, "processDrafterField", "identity", true);
- }
- this.setDataWithField(this.work, "processTitleField", "title", false);
- if( !this.work.title )this.work.title = "无标题";
- if( json.data.processStatus === "completed" ){
- this.work.form = json.data.processForm || "";
- this.setDataWithField(this.work, "processSerialField", "serial", false);
- this.setDataWithField(this.work, "processStartTimeField", "startTime", false);
- this.setDataWithField(this.work, "processCompleteTimeField", "completeTime", false);
- }
- }
- this.importer.fireEvent("afterCreateRowData", [ this]);
- }.bind(this));
- },
- parseData: function(value, dataType, json){
- var data;
- var type = this.importer.json.type;
- switch ( dataType ) {
- case "string":
- case "stringList":
- if( json.isName ){
- var arr = this.stringToArray(value);
- if( type === "dynamicTable" ){
- data = arr
- }else{
- data = arr.map( function(d, idx){
- return this.importer.getOrgData( d, true, true ) || d;
- }.bind(this)).clean();
- }
- }else{
- if( dataType === "string" ){
- var linebreak = type === "dynamicTable" ? json.lineBreak_Querytable : json.lineBreak_CMSProcess;
- if( typeOf(value) !== 'string' ){
- data = value.toString ? value.toString() : (value || "");
- }else{
- data = value.replace(/ /g, linebreak || "" );
- }
- }else{
- data = this.stringToArray(value);
- }
- }
- break;
- case "number":
- case "double":
- debugger;
- if( value === 0 ){
- data = 0;
- }else{
- value = value.replace(/ /g,"");
- data = parseFloat(value);
- }
- break;
- case "integer":
- case "long":
- if( value === 0 ){
- data = 0;
- }else {
- value = value.replace(/ /g, "");
- data = parseInt(value);
- }
- break;
- case "numberList":
- case "doubleList":
- data = this.stringToArray(value).map( function(d, idx){ return parseFloat( d ); }.bind(this)).clean();
- break;
- case "integerList":
- case "longList":
- data = this.stringToArray(value).map( function(d, idx){ return parseInt( d ); }.bind(this)).clean();
- break;
- case "date":
- value = value.replace(/ /g,"");
- data = Date.parse(value).format( "%Y-%m-%d" );
- break;
- case "dateTime":
- value = value.replace(/ /g,"");
- data = Date.parse(value).format( "db" );
- break;
- case "dateList":
- data = this.stringToArray(value).map( function(d, idx){ return Date.parse(d).format( "%Y-%m-%d" ); }.bind(this)).clean();
- break;
- case "dateTimeList":
- data = this.stringToArray(value).map( function(d, idx){ return Date.parse(d).format( "db" ); }.bind(this)).clean();
- break;
- case "boolean":
- value = value.replace(/ /g,"");
- data = value.trim().toLowerCase() !== "false";
- break;
- case "booleanList":
- data = this.stringToArray(value).map( function(d, idx){ return value.trim().toLowerCase() !== "false"; }.bind(this)).clean();
- break;
- case "json":
- case "stringMap":
- value = value.replace(/ /g,"");
- data = JSON.parse(value);
- break;
- default:
- data = value.replace(/ /g,"");
- break;
- }
- return data;
- },
- stringToArray: function(string){
- return string.replace(/[\n\r]/g,",").replace(/ /g,",").split(/\s*,\s*/g ).filter(function(s){
- return !!s;
- });
- },
- setDataWithPath: function(obj, path, data){
- var names = path.split(".");
- var d = obj;
- Array.each(names, function (n, idx) {
- if( idx === names.length -1 )return;
- if ( !d[n] ){
- var value = this.isNumberString( names[idx+1] ) ? [] : {};
- var n1 = this.isNumberString( n ) ? n.toInt() : n;
- d[n1] = value;
- d = d[n1];
- }else{
- d = d[n];
- }
- }.bind(this));
- d[names[names.length -1]] = data;
- },
- setDataWithField: function(obj, fieldName, path, isName){
- if(!this.pathIndexMap)this.pathIndexMap = {};
- if( !path )return;
- var json = this.importer.json;
- if( json.data[fieldName] ){
- var f = json.data[fieldName];
- json.data.columnList.each(function(json, i){
- if(json.path === f)this.pathIndexMap[path] = i;
- }.bind(this));
- var d = this.data;
- Array.each( f.split("."), function (n) {
- if(this.isNumberString(n))n = n.toInt();
- if (d) d = d[n];
- }.bind(this));
- if(!d)return;
- var _d = (typeOf(d) === "array" && d.length) ? d[0] : d;
- if( _d ){
- if(isName){
- obj[path] = typeOf(_d) === "object" ? _d.distinguishedName : _d;
- }else{
- obj[path] = d;
- }
- }
- }
- },
- isNumberString: function(string){
- return string.toInt().toString() === string;
- },
- parseCMSReadAndAuthor : function( data, t ){
- var cnArray = ["组织","群组","人员","人员","角色"];
- var keyArray = ["U","G","I","P","R"];
- if( typeOf(data) !== "array" )data = [data];
- return data.map( function( d ){
- var dn = typeOf( d ) === "string" ? d : d.distinguishedName;
- var name;
- if( typeOf(d) === "object" && d.name ){
- name = d.name;
- }else if( MWF.name && MWF.name.cn ){
- name = MWF.name.cn( dn );
- }else{
- name = dn.split("@")[0];
- }
- var index = keyArray.indexOf(dn.substr(dn.length-1, 1));
- if( index > -1 ){
- return {
- "permission" : t,
- "permissionObjectType": cnArray[ index ],
- "permissionObjectName": name,
- "permissionObjectCode": dn
- }
- }
- }).clean()
- },
- getSrcData: function(){
- var srcData = {};
- this.importer.json.data.columnList.each( function (columnJson, i) {
- if(columnJson.path)srcData[ columnJson.path ] = this.importedData[i] || "";
- }.bind(this));
- return srcData;
- },
- getResult: function(){
- if( this.importer.json.type === "cms" ){
- this.document.srcData = this.getSrcData(); //this.importedData;
- return this.document;
- }else if( this.importer.json.type === "process" ){
- this.work.srcData = this.getSrcData(); //this.importedData;
- return this.work;
- }else if( this.importer.json.type === "dynamicTable" ){
- this.data.srcData = this.getSrcData(); //this.importedData;
- return this.data;
- }
- }
- });
- MWF.xDesktop.requireApp("Template", "utils.ExcelUtils", null, false);
- MWF.xApplication.query.Query.Importer.ExcelUtils = new Class({
- Extends: MWF.xApplication.Template.utils.ExcelUtils,
- initialize: function( options ){
- if(options)this.setOptions(options);
- this.sheet2JsonOptions = {header:1};
- this.pollyfill();
- }
- });
- MWF.xApplication.query.Query.Importer.ProgressBar = new Class({
- Implements: [Options, Events],
- Extends: o2.widget.Common,
- options: {
- zindex: null,
- disableDetailButton: false
- },
- initialize : function( importer, options ){
- this.setOptions(options);
- this.importer = importer;
- this.actions = this.importer.lookupAction;
- this.lp = MWF.xApplication.query.Query.LP;
- this.css = importer.css;
- this.openDlg();
- this.status = "ready";
- },
- openDlg: function () {
- var _self = this;
- this.contentNode = new Element("div",{"styles": this.css.processContentNode});
- var opt = {
- "style" : "user",
- "title": this.lp.importRecordDetail,
- "content": this.contentNode,
- "offset": {"y": 0},
- "isMax": false,
- "width": 500,
- "height": 200,
- "zindex": this.options.zindex,
- "buttonList": [
- {
- "type": "openImportRecordDetail",
- "text": this.lp.openImportRecordDetail,
- "action": function () { _self.openImportRecordDetail(); }
- },
- {
- "type": "cancel",
- "text": this.lp.close,
- "action": function () { this.dlg.close(); }.bind(this)
- }
- ],
- "onPostShow": function(){
- this.fireEvent("postShow");
- }.bind(this),
- "onPostLoad": function () {
- this.titleAction.hide();
- this.button.hide();
- },
- "onPostClose": function(){
- this.dlg = null;
- }.bind(this)
- };
- if( this.options.disableDetailButton ){
- opt.buttonList.splice(0, 1);
- }
- this.dlg = o2.DL.open(opt);
- },
- createNode: function( noProgress ){
- // var lp = this.lp;
- // this.maskNode = new Element("div",{"styles": this.css.maskNode}).inject(this.importer.container);
- //
- // this.node = new Element("div", {"styles": this.css.progressBarNode}).inject(this.importer.container);
- //
- // this.topNode = new Element("div",{"styles": this.css.progressTopNode}).inject(this.node);
- //
- // this.subjectNode = new Element("div",{"styles": this.css.progressSubjectNode}).inject(this.topNode);
- //
- // this.topCloseAction = new Element("div.topCloseAction", {
- // "styles": this.css.progressTopCloseAction,
- // "text": "x"
- // }).inject(this.topNode);
- // this.topCloseAction.hide();
- // this.topCloseAction.addEvent("click", function(){
- // this.close();
- // }.bind(this))
- //
- // this.contentNode = new Element("div",{"styles": this.css.processContentNode}).inject(this.node);
- //
- // this.bottomNode = new Element("div", {"styles": this.css.progressBottomNode}).inject(this.node);
- // this.bottomNode.hide();
- //
- // this.closeAction = new Element("div.closeAction", {
- // "styles": this.css.progressCloseAction,
- // "text": lp.close
- // }).inject(this.bottomNode);
- // this.closeAction.addEvent("click", function(){
- // this.close();
- // }.bind(this))
- },
- setContentHtml: function(noProgress){
- var lp = this.lp;
- var contentHTML = "";
- if (noProgress){
- // contentHTML = "<div style=\"height: 20px; line-height: 20px\">"+lp.readyToImportData1+"</div></div>" ;
- contentHTML =
- "<div style=\"overflow: hidden\">" +
- " <div class='mwf_progressInforNode'>"+lp.readyToImportData1+"</div>"+
- "</div>" ;
- this.contentNode.set("html", contentHTML );
- this.progressNode = null;
- this.progressPercentNode = null;
- this.progressInforNode = this.contentNode.getElement(".mwf_progressInforNode");
- this.progressInforNode.setStyles(this.css.progressInforNode)
- }else{
- contentHTML =
- "<div style=\"overflow: hidden\">"+
- " <div class='mwf_progressNode'>" +
- " <div class='mwf_progressPercentNode'></div>"+
- " </div>" +
- " <div class='mwf_progressInforNode'>"+lp.readyToImportData1+"</div>"+
- "</div>" ;
- this.contentNode.set("html", contentHTML );
- this.progressNode = this.contentNode.getElement(".mwf_progressNode");
- this.progressNode.setStyles(this.css.progressNode);
- this.progressPercentNode = this.contentNode.getElement(".mwf_progressPercentNode");
- this.progressPercentNode.setStyles(this.css.progressPercentNode);
- this.progressInforNode = this.contentNode.getElement(".mwf_progressInforNode");
- this.progressInforNode.setStyles(this.css.progressInforNode)
- }
- },
- showCheckData : function(){
- // this.node.show();
- this.setContentHtml(true);
- this.setMessageTitle( this.lp.checkDataTitle );
- this.setMessageText( this.lp.checkDataContent );
- this.status = "check";
- // this.setSize();
- },
- showImporting: function( recordId, callback, date ){
- // this.node.show();
- this.setContentHtml();
- this.recordId = recordId;
- this.currentDate = date || new Date();
- this.intervalId = window.setInterval( function(){
- this.actions.getImportModelRecordStatus( this.recordId, function( json ){
- var data = json.data;
- this.status = data.status;
- if( data.status === "待导入" ) { //有其他人正在导入或上次导入还未完成
- this.setMessageTitle(this.lp.importWaitingTitle);
- this.setMessageText(this.lp.importWaitingContent);
- }else if( data.status === "导入中" ){ //导入中
- this.setMessageTitle( this.lp.importDataTitle );
- this.setMessageText( this.lp.importDataContent.replace( "{count}", data.executeCount));
- this.updateProgress( data );
- }else{ //已经结束, 状态有 "导入成功","部分成功","导入失败"
- if( callback )callback( data );
- if( data.promise && typeOf(data.promise.then) === "function" ){
- Promise.resolve( data.promise ).then(function () {
- if(this.intervalId)window.clearInterval( this.intervalId );
- this.transferComplete( data );
- }.bind(this))
- }else{
- if(this.intervalId)window.clearInterval( this.intervalId );
- this.transferComplete( data );
- }
- }
- }.bind(this), null)
- }.bind(this), 500 );
- // this.setSize();
- },
- showCloseAction: function(){
- this.dlg.titleAction.show();
- this.dlg.button.show();
- // if( this.bottomNode )this.bottomNode.show();
- // if( this.topCloseAction )this.topCloseAction.show();
- // this.setSize();
- },
- close: function(){
- // this.maskNode.destroy();
- // this.node.destroy();
- this.dlg.close();
- },
- // setSize: function(){
- // var containerSize = this.importer.container.getSize();
- // var nodeSize = this.node.getSize();
- // var top = (containerSize.y - nodeSize.y) / 2;
- // var left = (containerSize.x - nodeSize.x) / 2;
- // this.node.setStyles({
- // "top": (top-40)+"px",
- // "left": left+"px"
- // })
- // },
- updateProgress: function(data){
- //status, data.executeCount, data.count, data.failCount
- var lp = this.lp;
- var total = data.count.toInt();
- var processed = data.executeCount.toInt();
- var failCount = data.failCount.toInt();
- var percent = 100*(processed/total);
- var sendDate = new Date();
- var lastDate = this.lastTime || this.currentDate;
- var ms = sendDate.getTime() - lastDate.getTime();
- var speed = ( (processed - ( this.lastProcessed || 0 )) * 1000)/ms ;
- var u = lp.importSpeed;
- speed = speed.round(2);
- this.progressPercentNode.setStyle("width", ""+percent+"%");
- var text = lp.importingDataContent.replace("{speed}",speed).replace("{total}",total).replace("{remaining}",( total - processed ));
- text += failCount ? lp.importingDataErrorContent.replace("{errorCount}",failCount) : "";
- this.progressInforNode.set("text", text);
- this.lastProcessed = processed;
- this.lastTime = new Date();
- },
- transferComplete: function( data ){
- var lp = this.lp;
- var sendDate = new Date();
- var ms = sendDate.getTime()-this.currentDate.getTime();
- if(ms<1000)ms = 1000;
- var timeStr = "";
- if (ms>3600000){
- var h = ms/3600000;
- var m_s = ms % 3600000;
- var m = m_s / 60000;
- var s_s = m_s % 60000;
- var s = s_s/1000;
- timeStr = ""+h.toInt()+lp.hour+m.toInt()+lp.mintue+s.toInt()+lp.second;
- }else if (ms>60000){
- var m = ms / 60000;
- var s_s = ms % 60000;
- var s = s_s/1000;
- timeStr = ""+m.toInt()+lp.mintue+s.toInt()+lp.second;
- }else{
- var s = ms/1000;
- timeStr = ""+s.toInt()+lp.second;
- }
- if( data.status === "导入成功" ){
- var size = data.count;
- var speed = (size * 1000)/ms ;
- var u = lp.importSpeed;
- speed = speed.round(2);
- this.setMessageTitle( lp.importSuccessTitle );
- var text = lp.importSuccessContent.replace("{total}",size).replace("{speed}",speed).replace("{timeStr}",timeStr);
- this.setMessageText( text );
- }else if(data.status === "部分成功"){
- var size = data.count;
- var speed = (size * 1000)/ms ;
- var u = lp.importSpeed;
- speed = speed.round(2);
- this.setMessageTitle( lp.importPartSuccessTitle );
- var text = lp.importPartSuccessContent.replace("{total}",size).replace("{speed}",speed).replace("{errorCount}",data.failCount).replace("{timeStr}",timeStr);
- this.setMessageText( text );
- }else{ //导入失败
- var size = data.count;
- this.setMessageTitle( lp.importFailTitle );
- var text = lp.importFailContent.replace("{errorInfo}",data.distribution || "").replace("{total}",size).replace("{timeStr}",timeStr);
- this.setMessageText( text );
- }
- this.clearMessageProgress();
- this.showCloseAction();
- },
- setMessageText: function( text){
- this.progressInforNode.set("text", text);
- },
- setMessageTitle: function( text){
- this.dlg.titleText.set("text", text);
- },
- clearMessageProgress: function(){
- this.progressNode.destroy();
- },
- openImportRecordDetail: function () {
- MWF.xDesktop.requireApp("query.Query", "ImporterRecord", function () {
- var detail = new MWF.xApplication.query.Query.ImporterRecord.Detail(
- this.importer.container,
- this.importer.app,
- { importerId: this.importerId, recordId: this.recordId }
- );
- detail.load();
- this.dlg.close();
- }.bind(this), false);
- }
- });
|