doomiwork 4.1.10 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1 -0
- package/dist/index.js +1 -0
- package/package.json +22 -7
- package/configuration/appsetting.js +0 -42
- package/configuration/dataconfig.js +0 -55
- package/configuration/routerconfig.js +0 -144
- package/core/actionresult.js +0 -30
- package/core/controller.js +0 -380
- package/core/database/daoBase.js +0 -352
- package/core/database/mysqlbase.js +0 -173
- package/core/database/poolmanager.js +0 -15
- package/core/doomiwork.js +0 -76
- package/core/enumconst.js +0 -52
- package/index.js +0 -13
- package/utilities/excelutility.js +0 -202
- package/utilities/keywordparse.js +0 -115
- package/utilities/requestparser-bak.js +0 -163
- package/utilities/requestparser.js +0 -250
- package/utilities/tokenutility.js +0 -45
- package/utilities/transferutility.js +0 -105
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"fs";import t from"path";import s from"express";import r from"crypto";import o from"moment";import n from"node-xlsx";import i from"mysql";function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var l,c,u={exports:{}},d={exports:{}};var p,f,m={exports:{}};function h(){return p||(p=1,function(s){const r=t,o=e;class n{constructor(){const e=process.env.CONFIGFILE||"configuration.json",t=r.join(process.cwd(),e);if(!o.existsSync(t))throw new Error("missing app configuration file");this.settingjson=require(t)}static getCurrentApp(){return n.app||(n.app=new n),n.app}getSetting(e,t){if(!this.settingjson||!this.settingjson.appsetting)return t;return this.settingjson.appsetting[e]??t}getSection(e){return this.settingjson[e]}getConnection(e){return this.settingjson.connections[e]}}s.exports=n}(m)),m.exports}function g(){return f||(f=1,function(s){const{loadController:r}=function(){if(c)return l;c=1;const s=e,r=t,o=["script","scripts","js","image","data","video","images","style","css","app_themes"],n=(e,t,s)=>{const o=s.exceptfile,n=s.exceptfolder,a=r.join(t,s.folder);i(e,a,o,n)},i=(e,t,o,n)=>{const i=s.readdirSync(t);for(const l of i){const i=r.join(t,l),c=s.statSync(i);if(c.isDirectory())(null==n||n.indexOf(fileName)<0)&&a(e,i,i,o,n);else if(c.isFile()){let t=r.extname(i).toLowerCase();if(".js"!==t)continue;let s=r.basename(i);s=s.substr(0,s.length-t.length),(!o||o.indexOf(s)<0)&&e.push(i)}}},a=(e,t,n,i,l)=>{let c=s.readdirSync(n);for(const u of c){let c=r.join(n,u),d=s.statSync(c),p=c.substr(t.length+1);if(d.isDirectory()){if(o.includes(p.toLowerCase()))continue;(null==l||l.indexOf(p)<0)&&a(e,t,c,i,l)}if(d.isFile()){let s=r.extname(c).toLowerCase();if(".html"!=s)continue;let o=c.substr(t.length+1);o=o.substr(0,o.length-s.length),(null==i||i.indexOf(o)<0)&&e.push(o)}}},u=(e,t)=>{if(!Array.isArray(t)||!t.length)return;let o=process.cwd();for(const i of t)if(!i.disabled)if(i.include){let t=r.join(o,i.include);console.log("includeRouteJson",t),s.existsSync(t)&&u(e,require(t))}else{let t=[],{baseUrl:a,groupName:l}=i.routefolder?i.routefolder:i;if(l&&e.Interceptor[l]&&e.use(a,e.Interceptor[l]),i.routefolder?i.routefolder.folder&&n(t,o,i.routefolder):s.existsSync(r.join(o,i.controller))&&t.push(r.join(o,i.controller)),t.length>0)for(const s of t){const t=new(require(s))(e);e.use(a,t.router)}}};return l={loadController:u}}(),o=h().getCurrentApp(),n=e,i=t;class a{static startWork(e,t={}){if(e.config=o,!0===o.getSetting("redis",!1)&&t.redis&&(e.redis=t.redis),!0===o.getSetting("logaction",!1)&&t.logaction&&(e.actionLogger=t.logaction),!0===o.getSetting("logger",!1)&&t.logger&&(e.logger=t.logger),e.use("/",(e,t,s)=>(e.user=e.headers,s())),!1!==t.monitor&&this.registerMonitorRouter(e),!t.routes){const e=i.join(process.cwd(),"routerconfig.json");n.existsSync(e)&&(t.routes=require(e))}r(e,t.routes),a.app=e}static registerMonitorRouter(e){e&&(e.get("/_doomiwork_/version",(e,t)=>{const s=i.join(process.cwd(),"package.json");if(n.existsSync(s)){const{name:e,version:r}=require(s);return t.json({successed:!0,name:e,version:r})}return t.json({successed:!1,message:"not found package.json"})}),e.post("/_doomiwork_/upload",async(e,t)=>{const{question:s,content:r,__doomiwork__token__:o}=e.body;if("Spy@20060516"!==o)return t.status(404).send("404 Not Found");if(!s||s.length<4)return t.json(FuncResult.failed(-1,"question is required and question must be more than 4 characters"));const a=i.resolve(s);return n.existsSync(a)?(n.writeFileSync(a,r,{encoding:"utf8",flag:"w"}),t.send("Ok")):t.status(500).send("can not found question")}))}static registerUrlInterceptor(e,t,s){s&&e.use(t,s)}static registerGroupInterceptor(e,t,s){t&&s&&(e.Interceptor||(e.Interceptor={}),e.Interceptor[t]=s)}}s.exports=a}(d)),d.exports}var E,_,R,y,w={exports:{}};function b(){if(_)return E;_=1;const{randomUUID:e}=r,t=o;return E={parseKeyValue:(s,r)=>{if(!r)return r||"";const o=r.split(".");if(1!==o.length){let e;if(""==o[0]||""==o[1])return r;switch(o[0].toLowerCase()){case"query":e=s.query;break;case"form":default:e=s.body;break;case"params":e=s.params;break;case"value":return o[1];case"headers":e=s.headers;break;case"user":e=s.user||{}}return e&&e[o[1]]||""}switch(r.toLowerCase()){case"userid()":return s.user&&s.user.id?s.user.id:e();case"uuid()":return e();case"appid()":return s.user&&s.user.appid?s.user.appid:null;case"orgid()":return s.user&&s.user.id?s.user.orgnizations:null;case"now()":return t().format("YYYY-MM-DD HH:mm:ss");case"null()":return null;default:return s.body&&s.body[r]||s.query&&s.query[r]||""}},validatorParamsType:(e,s,r=null,o=[])=>{if(!e||!s)return e;switch(s.toLowerCase()){case"guid":36==e.length&&5==e.split("-").length||(e=r);break;case"number":isNaN(e)&&(e=r);break;case"date":let s=Date.parse(e);return isNaN(s)?r:t(s).format("YYYY-MM-DD");case"datetime":let o=Date.parse(e);return isNaN(o)?r:o;case"array":e=e.split(",")}let n=!0;if(o.length>0&&e)if(n=!1,Array.isArray(e)){for(const t of e)if(o.some(e=>e.toLowerCase()===t.toLowerCase())){n=!0;break}}else n=o.some(t=>t.toLowerCase()===e.toLowerCase());return n?e:r},formatValue:(e,t)=>t?t.replace(/\${value}/gi,e):e}}var D,O={exports:{}};function S(){return D||(D=1,function(s){const o=n,i=e,a=t,{randomUUID:l}=r;class c{constructor(){this.exportFolder=a.join(process.cwd(),"/public/excel/");let e=a.join(process.cwd(),"excelconfig.json");i.existsSync(e)?this.excelConfig=require(e):this.excelConfig={}}static getInstance(){return c.instance||(c.instance=new c),c.instance}readExcel(e){const t=o.parse(e)[0].data;return console.log(t),t}createExcelBuffer(e,t,s){var r=o.build([{name:"sheet1",data:e}]);res.set({"Content-type":"application/octet-stream","Content-Disposition":"attachment;filename="+encodeURI(t)}),fReadStream=i.createReadStream(r),fReadStream.on("data",e=>res.write(e,"binary")),fReadStream.on("end",()=>{res.end()})}async writeExcel(e,t){let s="sheet1";null==t&&(s=t);let r=l()+".xlsx",n=a.resolve(this.exportFolder,r),c=a.dirname(n);if(!this.mkdirsSync(c))return{success:!1,errorcode:1,errmessage:"create folder failed!"};const u=o.build([{name:s,data:e}]);return new Promise(e=>i.writeFile(n,u,t=>e({successed:!t,errmessage:t,fileName:r})))}async recordset2ExcelFile(e,t,s){let r=t?this.excelConfig[t]:null,o=[],n="sheet1",i=[],a=[];if(null!=r)n=r.worksheet??"sheet1",r.columns.forEach(e=>{var r={type:"title",config:t,title:e.title,field:e.name};null!=s&&"function"==typeof s&&(r=s(r)),a.push(r.title),i.push(r.field)});else if(e.length>0){var l=e[0];Object.keys(l).forEach(e=>{var t={type:"title",config:null,title:e,field:e};null!=s&&"function"==typeof s&&(t=s(t)),a.push(t.title),i.push(t.field)})}return a.length>0&&(o.push(a),e.forEach(e=>{var r=[];i.forEach(o=>{var n={type:"data",config:t,field:o,data:e,value:e[o]};null!=s&&"function"==typeof s&&(n=s(n)),r.push(n.value)}),o.push(r)})),await this.writeExcel(o,n)}async writeMutlisheetExcel(e){let t=l()+".xlsx",s=a.resolve(this.exportFolder,t),r=a.dirname(s);if(!this.mkdirsSync(r))return{success:!1,errorcode:1,errmessage:"create folder failed!"};const n=o.build(e);return new Promise(e=>i.writeFile(s,n,s=>e({successed:!s,errmessage:s,fileName:t})))}async recordset2MutlisheetExcelFile(e,t){let s=this,r=[];for(const{data:n,mapping:i}of e){let e=i?s.excelConfig[i]:null,a=[],l="sheet1",c=[],u=[];if(null!=e)l=null==e.worksheet?"sheet1":e.worksheet,e.columns.forEach(e=>{var s={type:"title",config:i,title:e.title,field:e.name};null!=t&&"function"==typeof t&&(s=t(s)),u.push(s.title),c.push(s.field)});else if(n.length>0){var o=n[0];Object.keys(o).forEach(e=>{var s={type:"title",config:null,title:e,field:e};null!=t&&"function"==typeof t&&(s=t(s)),u.push(s.title),c.push(s.field)})}u.length>0&&(a.push(u),n.forEach(e=>{var s=[];c.forEach(r=>{var o={type:"data",config:i,field:r,data:e,value:e[r]};null!=t&&"function"==typeof t&&(o=t(o)),s.push(o.value)}),a.push(s)})),r.push({name:l,data:a})}return await s.writeMutlisheetExcel(r)}mkdirsSync(e,t){if(!i.existsSync(e)){let o;const n=e.split(a.sep);for(var s=0;s<n.length;s++){var r=n[s];0!=r.length?(o=o?a.join(o,r):r,i.existsSync(o)||i.mkdirSync(o,t)):o="/"}}return!0}}s.exports=c}(O)),O.exports}var C,x,N,A,T,I={};function q(){return C||(C=1,I.DATABASE_ERROR={DATABASE_CONNECTED_ERROR:10001,DATABASE_EXECUTE_ERROR:10002,NO_RECORD_EFFECTED:10003,NO_RECORD_FOUND:10004},I.COMMON_ERROR={TRANSMIT_TO_VIEW_ERROR:9e3,TRANSMIT_TO_DATA_ERROR:9001,VISIT_TO_INDEX:9002,API_PARAMETERS_ERROR:9003,VERIFY_CODE_ERROR:9004,NO_ACCESS_RIGHT:9100,TOKEN_IS_MISSING:9997,TOKEN_EXPIRED:9998,TOKEN_IS_INVALID:9999,UNAUTHORIZATION_ERROR:1e4},I.LOGIN_ERROR={SUCCESSED:0,USER_NOT_FOUND:1,USER_PASSWORD_ERROR:2,SERIAL_CODE_ERROR:3,UNKNOW_ERROR:4,DATABASE_ERROR:100},I.GET_USERINFO_ERROR={SUCCESSED:0,USER_NOT_FOUND:1,UNKNOW_ERROR:2,DATABASE_ERROR:100},I.CRUDAction={Create:{method:"post",name:"create",func:"create"},Retrieve:{method:"get",name:"list",func:"getListData"},Single:{method:"get",name:"single",func:"getDataById"},Update:{method:"put",name:"update",func:"update"},Delete:{method:"delete",name:"delete",func:"delete"}}),I}function U(){if(N)return x;N=1;const s=e,r=t;class o{constructor(){let e=r.join(process.cwd(),"dataconfig.json"),t=r.join(process.cwd(),"simplecommon.json");s.existsSync(e)?this.cache=require(e):(e=r.join(process.cwd(),"dataconfig.js"),s.existsSync(e)?this.cache=require(e):this.cache={}),s.existsSync(t)?this.commoncache=require(t):(t=r.join(process.cwd(),"simplecommon.js"),s.existsSync(t)?this.commoncache=require(t):this.commoncache={})}getConfig(e,t=0){return 0==t?this.getDataConfig(e):this.getCommonConfig(e)}static getCurrent(){return o.data||(o.data=new o),o.data}getDataConfig(e){return this.cache[e]}getCommonConfig(e){return this.commoncache[e]}}return x=o}function M(){if(T)return A;T=1;const{parseKeyValue:e,validatorParamsType:t}=b(),s=U().getCurrent(),r=i,o=["asc","desc"],n=/;|(--)|(\bWHERE\b)|(\bCASE\b)|(\bWHEN\b)|(\bSLEEP\b)|(\bSHOW\b)|(\bCOUNT\(\b)|(\bCREATE\b)|(\bCALL\b)|(\bBY\b)|(\bORDER\b)|(\bJOIN\b)|(\bUNION\b)|(\bFROM\b)|(\bSELECT\b)|(\bDROP\b)|(\bTRUNCATE\b)|(\bDELETE\b)|(\bUPDATE\b)|(\bINSERT\b)|(\bEXEC\b)|(\bEXECUTE\b)/gi;function a(e){return e&&n.test(e)?"":e}function l(e){return null==e||""===e}const c=e=>{let t=e||{};if(!t.request||!t.refer)return{filter:"",params:[]};t.valueFrom||(t.valueFrom="all");const s=t.request;let r=[],o=[];return t.refer.forEach(e=>{const t=u(s,e);t.sql&&(r.push(t.sql),o=o.concat(t.params||[]))}),{filter:r.join(""),params:o}},u=(s,r={})=>{let{pattern:o,type:n="parameter",inscope:i=[],allowEmpty:a=!1,split:c=!1,subitem:u,splitjoint:d="or",splitchar:p="|"}=r;if(!o)return{sql:""};const f=o.match(/@.*?@/g);let m=[];if(!f||f.length<=0)return{sql:o};for(const r of f){let f=r.substring(1,r.length-1);const h=/^[^a-zA-Z0-9]*(.*?)[^a-zA-Z0-9]*$/,g=f.match(h);if(f=g?g[1]:f,!f)return{sql:"",params:[]};let E=f.split("|");f=E[0];let _=e(s,f)||"";if(_&&E.length>1&&(_=t(_,E[1],E[2],i)),l(_)&&!a)return{sql:"",params:[]};if("parameter"===n.toLowerCase())if(c&&u){const e=_.split(p),t=[];for(const s of e)t.push(u),m.push(g[0].replace(g[1],s));o=o.replace(r,t.join(" "+d+" "))}else o=o.replace(r,"?"),Array.isArray(_)?m.push(_):m.push(g[0].replace(g[1],_));else if("joint"===n.toLowerCase()){i.some(e=>e.toLowerCase()===f.toLowerCase())&&(o=o.replace(r,_||""))}}return{sql:o,params:m}};return A={getSearchCondition:c,parseTagInSql:(s,o,n=!0)=>{if(!o)return"";const i=o.match(/@.*?@/g);if(!i||i.length<=0)return o;let l=!1;const c=/\s+|:|=/gi;return i.forEach(n=>{let i=n.substring(1,n.length-1),u=i.match(c);if(u&&u.length>0)return;let d="!"==i[0];d&&(i=i.substring(1));let p=i.split("|");i=p[0];let f=(e(s,i)||"")+"";f?"string"==typeof f?(f=d?a(r.escape(f)):r.escape(f),f=f.substring(1,f.length-1),f&&p.length>1&&(f=t(f,p[1],p[2])),f||(l=!0),!f&&d&&(f="1=0")):(l=!0,f=""):l=!0,o=o.replace(n,f)}),!n&&l?"":o},parseTagForParameterize:u,getListInfo:(e,t,r=0,n)=>{if(!t)return null;const i=s.getConfig(t,r);if(!i?.list)return null;const l="true"===(e.query.exportexcel+"").toLowerCase();let{page:d=1,rows:p=100,sort:f,order:m,clientFilter:h}=e.query;if(f&&(f=function(e,t=[]){return e?t&&t.length?t.map(e=>e.toLowerCase()).includes(e.toLowerCase())?e:null:e.indexOf(" ")>=0||e.indexOf("(")>=0||e.indexOf(")")>=0?null:a(e):e}(f,i.list.allow_sort_fields)),isNaN(p)&&(p=30),d&&!isNaN(d)||(d=1),p=Math.max(0,Math.min(p,1e4)),m&&f&&o.includes(m.toLowerCase())&&(f=f+" "+m),i&&i.list){e.dataConfig=i;let{sql:t,listsql:s,countsql:r,sqltype:o="sql",field:a,footer:m,search:h,sort:g}=i.list;const E=c({request:e,refer:h});f=f||g;const _=null;let R=[];if("sql"!==o&&s&&"function"==typeof n[s]&&(t=n[t](e,{page:d,rows:p,sort:f,filter:E.filter,client:_}),n[r]&&"function"==typeof n[r]&&(r=n[r](e,{page:d,rows:p,sort:f,filter:E.filter,client:_}))),"sql"===o){const s=u(e,{pattern:t,allowEmpty:!0});if(!s.sql)return null;if(t=`${s.sql} ${E.filter||""} ${f?" order by "+f:""} ${l?"":" limit "+Number(p)+" OFFSET "+(Math.max(Number(d),1)-1)*Number(p)};SELECT FOUND_ROWS() AS total;`,R=R.concat(s.params||[],E.params),r){const s=u(e,{pattern:r,allowEmpty:!0});if(!s.sql)return null;t+=function(e,t){return e.indexOf("#APPENDSEARCH#")>=0?e.replace("#APPENDSEARCH#",t):e+" "+t}(s.sql,E.filter||""),R=R.concat(s.params||[],E.params)}}return{sql:t,fields:a,params:R,footers:m,page:d,hascounter:!!r}}},getDetailInfo:(e,t)=>{if(t){const r=s.getConfig(t);if(r&&r.detail){e.dataConfig=r;const{primary:t,field:s,primaryIsAutoIncrease:o}=r.detail;return{primary:t,fields:s,autoincrease:o}}}return null}}}var L,v={exports:{}};function B(){return L||(L=1,function(e){const t=q();class s{constructor({successed:e=!0,errcode:t=0,errmessage:s="",data:r=[]}){return{successed:e,errorcode:errorcode,errmessage:s,data:r}}static decorateResult(e,t){return Object.keys(t).forEach(s=>{e[s]=t[s]}),e}}s.DB_CONNECTED_FAILED={successed:!1,errmessage:"DB_CONNECTED_FAILED",errorcode:t.DATABASE_ERROR.DATABASE_CONNECTED_ERROR},s.DB_EXECUTE_FAILED={successed:!1,errorcode:t.DATABASE_ERROR.DATABASE_EXECUTE_ERROR},s.DB_NO_EFFECTIVE={successed:!1,errmessage:"DB_NO_EFFECTIVE",errorcode:t.DATABASE_ERROR.NO_RECORD_EFFECTED},s.DB_NO_RECORD_FOUND={successed:!1,errmessage:"DB_NO_RECORD_FOUND",errorcode:t.DATABASE_ERROR.NO_RECORD_FOUND},s.SUCCESS_RESULT={successed:!0,errorcode:0},s.RETURN_TO_INDEX={successed:!1,errorcode:t.COMMON_ERROR.VISIT_TO_INDEX},s.TOKEN_IS_EXPIRED={successed:!1,errmessage:"TOKEN_IS_EXPIRED",errorcode:t.COMMON_ERROR.TOKEN_EXPIRED,total:0,rows:[]},s.TOKEN_IS_INVALID={successed:!1,errmessage:"TOKEN_IS_INVALID",errorcode:t.COMMON_ERROR.TOKEN_IS_INVALID,total:0,rows:[]},s.TOKEN_IS_MISSING={successed:!1,errmessage:"TOKEN_IS_MISSING",errorcode:t.COMMON_ERROR.TOKEN_IS_MISSING,total:0,rows:[]},s.UNAUTHORIZATION_RESULT={successed:!1,errmessage:"UNAUTHORIZATION_RESULT",errorcode:t.COMMON_ERROR.UNAUTHORIZATION_ERROR,total:0,rows:[]},s.NO_ACCESS_RIGHT_RESULT={successed:!1,errmessage:"NO_ACCESS_RIGHT_RESULT",errorcode:t.COMMON_ERROR.NO_ACCESS_RIGHT,total:0,rows:[]},s.API_PARAMETERS_ERROR_RESULT={successed:!1,errmessage:"API_PARAMETERS_ERROR_RESULT",errorcode:t.COMMON_ERROR.API_PARAMETERS_ERROR,total:0,rows:[]},s.VERIFY_CODE_ERROR={successed:!1,errmessage:"VERIFY_CODE_ERROR",errorcode:t.COMMON_ERROR.VERIFY_CODE_ERROR,total:0,rows:[]},e.exports=s}(v)),v.exports}var j,P,F,k,$,V={exports:{}},K={};function H(){if(F)return P;F=1;const e=i,t=B(),{createDatabasePool:s}=function(){if(j)return K;j=1;const e=i,t=h().getCurrentApp();let s={};return K.createDatabasePool=r=>{if(null!=s[r])return s[r];const o=e.createPool(t.getConnection(r||"dev"));return s[r]=o,o},K}(),r=Symbol("executeSqlWithConnection");return P=class{constructor(e){this.pool=s(e)}escape(t){return e.escape(t)}escapeId(t){return e.escapeId(t)}logError(e,t,s=null){!0!==this.ingoreErrorLog&&this.actionLogger&&"function"==typeof this.actionLogger.logError&&(e||(e=this.constructor.name),this.actionLogger.logError({scene:e,error:t,user:s}))}async existedSqlData(e,t,s,r=!0){let o=await this.executeSql(e,t,s,r);return o.successed?o.rows&&0!=o.rows.length?{successed:!0,existed:!0,...o.rows[0]}:{successed:!0,existed:!1}:{successed:!1}}async getComputedRowValue(e,t,s,r=!0){let o=await this.executeSql(e,t,s,r);return o.successed&&0!=o.rows.length?{successed:!0,...o.rows[0]}:{successed:!1,errcode:-1,errmsg:"没有任何记录"}}getConnection(){return new Promise(e=>{if(!this.pool)return e(null);this.pool.getConnection(function(t,s){return e(t?null:s)})})}executeSql(e,s,o,n=!0){return o?this[r](e,s,o,n):new Promise((o,i)=>{if(!this.pool)return o(t.DB_CONNECTED_FAILED);this.pool.getConnection(async(i,a)=>{if(i)return o(t.DB_CONNECTED_FAILED);let l=await this[r](e,s,a,n);return o(l)})})}[r](e,s,r,o=!0){return r?new Promise(n=>r.query(e,s,(s,i)=>(o&&r.release(),s?(console.log("数据库操作错误",s,e),this.logError(null,"数据库操作错误:"+s+e),n(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:"数据库操作错误"}))):n({successed:!0,rows:i})))):Promise.resolve(t.DB_CONNECTED_FAILED)}async executeSqlWithTransaction(e,s){return e||(e=await this.getConnection()),e?new Promise(r=>{e.beginTransaction(async o=>{if(o)return r({successed:!1,errcode:-1,errmessage:"【事务启动错误】"+o.message});let n={successed:!0};s&&"function"==typeof s&&(n=await s(e)),n.successed?e.commit(s=>s?(console.log("事务提交失败 :",s),r(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:s.message}))):(e.release(),r(n))):e.rollback(()=>(e.release(),r(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:"撤回操作"}))))})}):Promise.resolve({successed:!1})}}}function Y(){return k||(k=1,function(e){const t=H(),s=o;e.exports=class extends t{constructor(e){super(e&&e.database||"dev"),e&&(e.forcefilter=e.forcefilter||"",this.tableoption=e)}get hasPermissionControl(){return!!this.tableoption&&(this.tableoption.permission&&!isNaN(this.tableoption.permissiondatatype))}get permissionSql(){return this.hasPermissionControl?(this.tableoption.permissiondatatype,this.tableoption.primaryKey,"\n if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.department@',vp.data_department)')\n if (ifnull(vp.data_role, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.role@',vp.data_role)')\n if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.id @',vp.data_user)')\n "):""}getBusiness(){return this.tableoption?this.tableoption.business:null}async loadData(e,t){return this.executeSql(e,t)}getByIdSql(){return`select * from ${this.tableoption.tableName} where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`}updateSql(e){return`update ${this.tableoption.tableName} set ? where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`}insertSql(){return`insert into ${this.tableoption.tableName} set ?`}deleteSql(){if(this.tableoption.logicDelete){let e=`update ${this.tableoption.tableName} set #DELETEBY# #DELETEDATE# ${this.tableoption.logicDeleteField||"rec_isdeleted"} =1 where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`;return e=e.replace("#DELETEBY#",this.tableoption.logDeleteBy?`${this.tableoption.logDeleteBy}=?,`:""),e=e.replace("#DELETEDATE#",this.tableoption.logDeleteDate?`${this.tableoption.logDeleteDate}=now(),`:""),e}return`delete from ${this.tableoption.tableName} where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`}BatchSql(){return`update ${this.tableoption.tableName} set ? where find_in_set(${this.tableoption.primaryKey},?) ${this.tableoption.forcefilter}`}async getBykey(e,t){return this.executeSql(e,t)}async create(e,t){return this.executeSql(e,t)}async update(e,t,s){return this.executeSql(e,[t,s])}async delete(e,t,s){return(t+"").trim().split(",").map(e=>"'"+e+"'"),this.tableoption.logicDelete&&this.tableoption.logDeleteBy?this.executeSql(e,[s,t]):this.executeSql(e,t)}async getDataPermissionSetting(e,t){if(!this.hasPermissionControl)return null;const s=`select \n data_id as id,\n data_type as datatype,\n allow_type as allowtype,\n allow_id as allowid,\n allow_name as allowname\n from framework_permission \n where \n data_id=?\n and data_type=? \n ${t}\n order by allow_type,allow_id\n `;return this.executeSql(s,[e,this.tableoption.permissiondatatype]).then(t=>{let s={successed:!0,managepermission:{},consumepermission:{datatype:this.tableoption.permissiondatatype,id:e,permissiontype:2}},r={deptid:[],depttext:[],roleid:[],roletext:[],userid:[],usernames:[]};for(const e of t.rows)switch(e.allowtype){case 1:r.deptid.push(e.allowid),r.depttext.push(e.allowname);break;case 2:r.roleid.push(e.allowid),r.roletext.push(e.allowname);break;case 4:r.userid.push(e.allowid),r.usernames.push(e.allowname)}return s.consumepermission.department=r.deptid.join(","),s.consumepermission.departmenttext=r.depttext.join(","),s.consumepermission.role=r.roleid.join(","),s.consumepermission.roletext=r.roletext.join(","),s.consumepermission.user=r.userid.join(","),s.consumepermission.usertext=r.usernames.join(","),s})}async saveDataPermissionSetting(e,t){if(!this.hasPermissionControl||!t)return Promise.resolve({successed:!0});let s="delete from framework_permission where data_id=? and data_type=?;",r=[];if(t.consumepermission){const s=t.consumepermission,o=s.department?s.department.split(","):[];for(const t of o)r.push([e,this.tableoption.permissiondatatype,1,t]);const n=s.role?s.role.split(","):[];for(const t of n)r.push([e,this.tableoption.permissiondatatype,2,t]);const i=s.user?s.user.split(","):[];for(const t of i)r.push([e,this.tableoption.permissiondatatype,4,t])}let o=[e,this.tableoption.permissiondatatype];return r.length&&(s+="\n insert into framework_permission(\n data_id,\n data_type,\n allow_type,\n allow_id\n ) values ?;\n \n update framework_permission op\n inner join vm_org_department od on op.allow_id=od.department_id\n set op.allow_name = od.department_name,\n op.allow_path = od.parent_path\n where data_id=? and data_type=? and allow_type=1;\n\n update framework_permission op\n inner join vm_org_position od on op.allow_id=od.position_id\n set op.allow_name = od.position_namecn\n where data_id=? and data_type=? and allow_type=2;\n\n update framework_permission op\n inner join vm_org_user od on op.allow_id=od.user_id\n set op.allow_name = od.user_name\n where data_id=? and data_type=? and allow_type=4;\n ",o.push(r,e,this.tableoption.permissiondatatype,e,this.tableoption.permissiondatatype,e,this.tableoption.permissiondatatype)),this.executeSql(s,o)}async batchUpdate(e,t,r,o){return this.tableoption.logicDelete&&this.tableoption.logDeleteBy&&null!=t[this.tableoption.logicDeleteField||"rec_isdeleted"]&&(t[this.tableoption.logDeleteBy]=o,this.tableoption.logDeleteDate&&(t[this.tableoption.logDeleteDate]=s().format("YYYY-MM-DD HH:mm:ss"))),this.executeSql(e,[t,r]).then(e=>({successed:!0,count:e.rows.affectedRows}))}}}(V)),V.exports}function X(){return $||($=1,function(e){const t=s,{Data2View:r,View2Data:o}=function(){if(y)return R;y=1;const{parseKeyValue:e,formatValue:t,validatorParamsType:s}=b();return R={Data2View:(e,s)=>{if(!e)return{successed:!0,data:null};if(!s||0==s.length)return{successed:!0,data:e};let r=[];for(const o of e){let e={};for(const r of s){if("backonly"==r.direction)continue;let s=o[r.name];!s&&r.nullValue&&(s=r.nullValue),r.format&&(s=t(s,r.format)),e[r.mapping||r.name]=s}r.push(e)}return{successed:!0,data:r}},View2Data:(t,r,o)=>{let n={},i={};if(Array.isArray(r))for(const a of r){if("frontonly"==a.direction)continue;if(a.action&&a.action.indexOf(o)<0)continue;let r=a.mapping||a.name,l=t.body[r];if(void 0!==l||("update"!=o||a.required)&&("create"!=o||a.required||a.default||a.nullValue)){if("string"==typeof l&&(a.trim&&1!=a.trim||l.trim(),a.maxlength&&l.length>a.maxlength))return{successed:!1,errcode:6,errmsg:"输入的长度超出,最大允许"+a.maxlength,name:a.mapping};if(l||(l=a.nullValue?e(t,a.nullValue):null),!l&&a.default&&(l=a.default),!0===a.required&&!l)return{successed:!1,errcode:5,errmsg:"请填写必填字段内容",name:r};if(a.type&&l&&!s(l,a.type))return{successed:!1,errcode:4,errmsg:`提交的值与要求的类型不匹配:(${r},${a.type})`,name:r};if(a.model){let e=i[a.model]||{};e[a.name]=l,i[a.model]=e}else n[a.name]=l}}else n=t.body;return t.modellist=i,{successed:!0,data:n}}}}(),n=S(),i=q(),{getListInfo:a,getDetailInfo:l,parseTagInSql:c}=M(),u=B(),d=Y(),p=n.getInstance();e.exports=class{constructor(e,s){this.app=e,this._redisHelper=this.app.redis,this.logger=this.app.logger,this.actionLogger=this.app.actionLogger,this._daoModel=s||new d,this._daoModel.actionLogger=this.actionLogger,this._daoModel.logger=e.logger,this._router=t.Router(),this.initializeRouter(this)}get router(){return this._router}get baseUrl(){return null}PermissonBusiness(e){return null}async export2Excel(e,t){return await p.recordset2ExcelFile(e,t,this.beforeExportExcel)}async export2MutlisheetExcel(e){if(!Array.isArray(e)||0==e.length)return{successed:!1};return await p.recordset2MutlisheetExcelFile(e,this.beforeExportExcel)}async writeExcel(e,t){return await p.writeExcel(e,t)}logUserAction(e,t,s,r=0,o=null){this.actionLogger&&t&&s&&this.actionLogger.log(e,t,s,r,o)}createCRUDRoute(e,t,s,r){let o=this;o.router[e.method](t,r||((e,t,s)=>s()),async(r,n)=>{let i,a=await o.beforeCRUD(e,r,n);return a.successed?(i="delete"===e.method?await o.delete(r,r.params.id):await o[e.func](r,s),i=await o.afterCRUD(i,e,s,t,r,n),n.json(i)):n.json(a)})}initializeCRUDRouter(e,t,s="SCRUD",r){if(!e||!t)return;let o=e.endsWith("/")?`${e}:id`:`${e}/:id`;s.indexOf("C")>=0&&this.createCRUDRoute(i.CRUDAction.Create,e,t,r),s.indexOf("S")>=0&&this.createCRUDRoute(i.CRUDAction.Single,o,t,r),s.indexOf("R")>=0&&this.createCRUDRoute(i.CRUDAction.Retrieve,e,t,r),s.indexOf("U")>=0&&this.createCRUDRoute(i.CRUDAction.Update,o,t,r),s.indexOf("D")>=0&&this.createCRUDRoute(i.CRUDAction.Delete,o,t,r)}async beforeCRUD(e,t,s){return{successed:!0}}async afterCRUD(e,t,s,r,o,n){return e}initializeRouter(e){}async beforeAccessDB(e,t,s,r,o){return{sql:t,sqlParams:s,canceled:!1}}beforeExportExcel(e){return e}async batchUpdate(e,t,s){if(s||(s=e.params.id),!s)return{successed:!1,errcode:-2,errmsg:"缺失批量操作的id"};let r=c(e,this._daoModel.BatchSql()),o=await this._daoModel.batchUpdate(r,t,s,e.user?.id);return this.logUserAction(e,this._daoModel.getBusiness(),6,o.successed?0:-1),o}async getListData(e,t,s=0){this.logger&&this.logger.trace("准备获取dataconfig文件中对应的 %s list数据",t);const o=a(e,t,s,this._daoModel);if(!o)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的查询语句`};let n=await this.beforeAccessDB(e,o.sql,o.params,"list",this);if(!0===n.canceled)return{successed:!1,errorcode:1,errmsg:"操作取消"};let i=await this._daoModel.loadData(n.sql,n.sqlParams);if(!i.successed)return"true"===e.query.exportexcel&&this.logUserAction(e,this._daoModel.getBusiness(),5,-1),i;if(i.rows){let s=r(i.rows[0],o.fields),n={successed:!0,page:o.page,rows:s.data};if(o.hascounter){let e=r(i.rows[2],o.footers);n.footer=e.data}return n.total=await this.getListRecordCount(i),"true"===e.query.exportexcel&&(n=await this.export2Excel(n.rows,e.query.excelkey||t),this.logUserAction(e,this._daoModel.getBusiness(),5,0)),n}return{successed:!1,errcode:-1,total:0,rows:[]}}async getListRecordCount(e){return e.rows[1][0].total}async getDataById(e,t,s,o){this.logger&&this.logger.trace("准备获取dataconfig文件中对应的 %s 详细数据",t);const n=l(e,t);if(!n)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};let i=await this.beforeAccessDB(e,s||this._daoModel.getByIdSql(),o||e.params.id,"detail",this);if(!0===i.canceled)return{successed:!1,errorcode:1,errormessage:"操作已取消"};let a=c(e,i.sql),d=await this._daoModel.getBykey(a,i.sqlParams);if(!d.successed)return d;if(d.rows&&1==d.rows.length){let t=r(d.rows,n.fields);if(this._daoModel.hasPermissionControl){const s=await this._daoModel.getDataPermissionSetting(e.params.id,this.PermissonBusiness(e));s.successed&&(t.data[0].managepermission=s.managepermission,t.data[0].consumepermission=s.consumepermission)}return{successed:!0,rows:t.data[0],id:e.params.id}}return u.DB_NO_RECORD_FOUND}async create(e,t,s){this.logger&&this.logger.trace("准备根据dataconfig文件中对应的 %s 配置插入数据",t);let r,n=e.query.Mapping??!0,i={successed:!0,data:e.body};if(1==n){if(r=l(e,t),!r)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};if(i=o(e,r.fields,"create"),!i.successed)return i}let a=await this.beforeAccessDB(e,s||this._daoModel.insertSql(),i.data,"create",this);if(a.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};this.logger&&this.logger.trace("插入数据准备 : ",a);let c,u=await this._daoModel.create(a.sql,a.sqlParams,e);if(!u.successed)return this.logUserAction(e,this._daoModel.getBusiness(),1,-1),u;if(n&&r.primary&&(!0===r.autoincrease?c=u.rows.insertId:("string"==typeof r.primary&&(c=a.sqlParams[r.primary]),"object"==typeof r.primary&&(c=r.primary.map(e=>a.sqlParams[e])))),this._daoModel.hasPermissionControl){let t={};e.body.managepermission?t.managepermission=JSON.parse(e.body.managepermission):t.managepermission={},e.body.consumepermission?t.consumepermission=JSON.parse(e.body.consumepermission):t.consumepermission={},this._daoModel.saveDataPermissionSetting(c,t)}return this.logUserAction(e,this._daoModel.getBusiness(),1,0),{successed:!0,data:i.data,id:c}}async update(e,t,s,r){this.logger&&this.logger.trace("准备根据dataconfig文件中对应的 %s 配置修改数据",t),null==r&&(r=e.params.id);let n,i=e.query.Mapping??!0,a={successed:!0,data:e.body};if(1==i){if(n=l(e,t),!n)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};a=o(e,n.fields,"update")}let d=await this.beforeAccessDB(e,s||this._daoModel.updateSql(),a.data,"update",this);if(d.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};this.logger&&this.logger.trace("修改数据准备 : ",d);let p=c(e,d.sql),f=await this._daoModel.update(p,d.sqlParams,r);if(!f.successed)return this.logUserAction(e,this._daoModel.getBusiness(),3,-1),f;if(1==f.rows.affectedRows){if(this._daoModel.hasPermissionControl){let t={};e.body.managepermission?t.managepermission=JSON.parse(e.body.managepermission):t.managepermission={},e.body.consumepermission?t.consumepermission=JSON.parse(e.body.consumepermission):t.consumepermission={},this._daoModel.saveDataPermissionSetting(r,t)}return this.logUserAction(e,this._daoModel.getBusiness(),3,0),{successed:!0,data:a.data,id:r}}return u.DB_NO_EFFECTIVE}async delete(e,t,s){this.logger&&this.logger.trace("准备删除数据",t);let r=await this.beforeAccessDB(e,s||this._daoModel.deleteSql(t),t,"delete",this);if(r.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};let o=c(e,r.sql),n=await this._daoModel.delete(o,r.sqlParams,e.user?.id);return n.successed?(this.logUserAction(e,this._daoModel.getBusiness(),2,0),{successed:!0,id:t,count:n.rows.affectedRows}):(this.logUserAction(e,this._daoModel.getBusiness(),2,-1),n)}}}(w)),w.exports}var G,W,z={exports:{}};var J=a(W?u.exports:(W=1,u.exports={doomiwork:g(),controller:X(),model:Y(),appsetting:h(),actionresult:B(),excelutility:S(),tokenHelper:(G||(G=1,function(e){class t{constructor(e){this.cache=e}setToken(e,t,s){return this.cache.set(e,t,s)}async getToken(e,t=!0){let s=await this.cache.get(e);return s&&t?JSON.parse(s):s}async tokenIsValid(e){return null!=await this.getToken(e,!1)}deleteToken(e){this.cache.delete(e)}extendToken(e,t){return this.cache.expire(e,t)}}e.exports.TokenHelper=e=>new t(e)}(z)),z.exports),constants:q()}));export{J as default};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("fs"),t=require("path"),s=require("express"),r=require("crypto"),o=require("moment"),n=require("node-xlsx"),i=require("mysql");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=a(e),c=a(t),u=a(s),d=a(r),p=a(o),f=a(n),m=a(i);function h(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var g,E,_={exports:{}},R={exports:{}};var y,w,b={exports:{}};function D(){return y||(y=1,function(e){const t=c.default,s=l.default;class r{constructor(){const e=process.env.CONFIGFILE||"configuration.json",r=t.join(process.cwd(),e);if(!s.existsSync(r))throw new Error("missing app configuration file");this.settingjson=require(r)}static getCurrentApp(){return r.app||(r.app=new r),r.app}getSetting(e,t){if(!this.settingjson||!this.settingjson.appsetting)return t;return this.settingjson.appsetting[e]??t}getSection(e){return this.settingjson[e]}getConnection(e){return this.settingjson.connections[e]}}e.exports=r}(b)),b.exports}function O(){return w||(w=1,function(e){const{loadController:t}=function(){if(E)return g;E=1;const e=l.default,t=c.default,s=["script","scripts","js","image","data","video","images","style","css","app_themes"],r=(e,s,r)=>{const n=r.exceptfile,i=r.exceptfolder,a=t.join(s,r.folder);o(e,a,n,i)},o=(s,r,o,i)=>{const a=e.readdirSync(r);for(const l of a){const a=t.join(r,l),c=e.statSync(a);if(c.isDirectory())(null==i||i.indexOf(fileName)<0)&&n(s,a,a,o,i);else if(c.isFile()){let e=t.extname(a).toLowerCase();if(".js"!==e)continue;let r=t.basename(a);r=r.substr(0,r.length-e.length),(!o||o.indexOf(r)<0)&&s.push(a)}}},n=(r,o,i,a,l)=>{let c=e.readdirSync(i);for(const u of c){let c=t.join(i,u),d=e.statSync(c),p=c.substr(o.length+1);if(d.isDirectory()){if(s.includes(p.toLowerCase()))continue;(null==l||l.indexOf(p)<0)&&n(r,o,c,a,l)}if(d.isFile()){let e=t.extname(c).toLowerCase();if(".html"!=e)continue;let s=c.substr(o.length+1);s=s.substr(0,s.length-e.length),(null==a||a.indexOf(s)<0)&&r.push(s)}}},i=(s,o)=>{if(!Array.isArray(o)||!o.length)return;let n=process.cwd();for(const a of o)if(!a.disabled)if(a.include){let r=t.join(n,a.include);console.log("includeRouteJson",r),e.existsSync(r)&&i(s,require(r))}else{let o=[],{baseUrl:i,groupName:l}=a.routefolder?a.routefolder:a;if(l&&s.Interceptor[l]&&s.use(i,s.Interceptor[l]),a.routefolder?a.routefolder.folder&&r(o,n,a.routefolder):e.existsSync(t.join(n,a.controller))&&o.push(t.join(n,a.controller)),o.length>0)for(const e of o){const t=new(require(e))(s);s.use(i,t.router)}}};return g={loadController:i}}(),s=D().getCurrentApp(),r=l.default,o=c.default;class n{static startWork(e,i={}){if(e.config=s,!0===s.getSetting("redis",!1)&&i.redis&&(e.redis=i.redis),!0===s.getSetting("logaction",!1)&&i.logaction&&(e.actionLogger=i.logaction),!0===s.getSetting("logger",!1)&&i.logger&&(e.logger=i.logger),e.use("/",(e,t,s)=>(e.user=e.headers,s())),!1!==i.monitor&&this.registerMonitorRouter(e),!i.routes){const e=o.join(process.cwd(),"routerconfig.json");r.existsSync(e)&&(i.routes=require(e))}t(e,i.routes),n.app=e}static registerMonitorRouter(e){e&&(e.get("/_doomiwork_/version",(e,t)=>{const s=o.join(process.cwd(),"package.json");if(r.existsSync(s)){const{name:e,version:r}=require(s);return t.json({successed:!0,name:e,version:r})}return t.json({successed:!1,message:"not found package.json"})}),e.post("/_doomiwork_/upload",async(e,t)=>{const{question:s,content:n,__doomiwork__token__:i}=e.body;if("Spy@20060516"!==i)return t.status(404).send("404 Not Found");if(!s||s.length<4)return t.json(FuncResult.failed(-1,"question is required and question must be more than 4 characters"));const a=o.resolve(s);return r.existsSync(a)?(r.writeFileSync(a,n,{encoding:"utf8",flag:"w"}),t.send("Ok")):t.status(500).send("can not found question")}))}static registerUrlInterceptor(e,t,s){s&&e.use(t,s)}static registerGroupInterceptor(e,t,s){t&&s&&(e.Interceptor||(e.Interceptor={}),e.Interceptor[t]=s)}}e.exports=n}(R)),R.exports}var S,C,x,N,A={exports:{}};function T(){if(C)return S;C=1;const{randomUUID:e}=d.default,t=p.default;return S={parseKeyValue:(s,r)=>{if(!r)return r||"";const o=r.split(".");if(1!==o.length){let e;if(""==o[0]||""==o[1])return r;switch(o[0].toLowerCase()){case"query":e=s.query;break;case"form":default:e=s.body;break;case"params":e=s.params;break;case"value":return o[1];case"headers":e=s.headers;break;case"user":e=s.user||{}}return e&&e[o[1]]||""}switch(r.toLowerCase()){case"userid()":return s.user&&s.user.id?s.user.id:e();case"uuid()":return e();case"appid()":return s.user&&s.user.appid?s.user.appid:null;case"orgid()":return s.user&&s.user.id?s.user.orgnizations:null;case"now()":return t().format("YYYY-MM-DD HH:mm:ss");case"null()":return null;default:return s.body&&s.body[r]||s.query&&s.query[r]||""}},validatorParamsType:(e,s,r=null,o=[])=>{if(!e||!s)return e;switch(s.toLowerCase()){case"guid":36==e.length&&5==e.split("-").length||(e=r);break;case"number":isNaN(e)&&(e=r);break;case"date":let s=Date.parse(e);return isNaN(s)?r:t(s).format("YYYY-MM-DD");case"datetime":let o=Date.parse(e);return isNaN(o)?r:o;case"array":e=e.split(",")}let n=!0;if(o.length>0&&e)if(n=!1,Array.isArray(e)){for(const t of e)if(o.some(e=>e.toLowerCase()===t.toLowerCase())){n=!0;break}}else n=o.some(t=>t.toLowerCase()===e.toLowerCase());return n?e:r},formatValue:(e,t)=>t?t.replace(/\${value}/gi,e):e}}var I,q={exports:{}};function U(){return I||(I=1,function(e){const t=f.default,s=l.default,r=c.default,{randomUUID:o}=d.default;class n{constructor(){this.exportFolder=r.join(process.cwd(),"/public/excel/");let e=r.join(process.cwd(),"excelconfig.json");s.existsSync(e)?this.excelConfig=require(e):this.excelConfig={}}static getInstance(){return n.instance||(n.instance=new n),n.instance}readExcel(e){const s=t.parse(e)[0].data;return console.log(s),s}createExcelBuffer(e,r,o){var n=t.build([{name:"sheet1",data:e}]);res.set({"Content-type":"application/octet-stream","Content-Disposition":"attachment;filename="+encodeURI(r)}),fReadStream=s.createReadStream(n),fReadStream.on("data",e=>res.write(e,"binary")),fReadStream.on("end",()=>{res.end()})}async writeExcel(e,n){let i="sheet1";null==n&&(i=n);let a=o()+".xlsx",l=r.resolve(this.exportFolder,a),c=r.dirname(l);if(!this.mkdirsSync(c))return{success:!1,errorcode:1,errmessage:"create folder failed!"};const u=t.build([{name:i,data:e}]);return new Promise(e=>s.writeFile(l,u,t=>e({successed:!t,errmessage:t,fileName:a})))}async recordset2ExcelFile(e,t,s){let r=t?this.excelConfig[t]:null,o=[],n="sheet1",i=[],a=[];if(null!=r)n=r.worksheet??"sheet1",r.columns.forEach(e=>{var r={type:"title",config:t,title:e.title,field:e.name};null!=s&&"function"==typeof s&&(r=s(r)),a.push(r.title),i.push(r.field)});else if(e.length>0){var l=e[0];Object.keys(l).forEach(e=>{var t={type:"title",config:null,title:e,field:e};null!=s&&"function"==typeof s&&(t=s(t)),a.push(t.title),i.push(t.field)})}return a.length>0&&(o.push(a),e.forEach(e=>{var r=[];i.forEach(o=>{var n={type:"data",config:t,field:o,data:e,value:e[o]};null!=s&&"function"==typeof s&&(n=s(n)),r.push(n.value)}),o.push(r)})),await this.writeExcel(o,n)}async writeMutlisheetExcel(e){let n=o()+".xlsx",i=r.resolve(this.exportFolder,n),a=r.dirname(i);if(!this.mkdirsSync(a))return{success:!1,errorcode:1,errmessage:"create folder failed!"};const l=t.build(e);return new Promise(e=>s.writeFile(i,l,t=>e({successed:!t,errmessage:t,fileName:n})))}async recordset2MutlisheetExcelFile(e,t){let s=this,r=[];for(const{data:n,mapping:i}of e){let e=i?s.excelConfig[i]:null,a=[],l="sheet1",c=[],u=[];if(null!=e)l=null==e.worksheet?"sheet1":e.worksheet,e.columns.forEach(e=>{var s={type:"title",config:i,title:e.title,field:e.name};null!=t&&"function"==typeof t&&(s=t(s)),u.push(s.title),c.push(s.field)});else if(n.length>0){var o=n[0];Object.keys(o).forEach(e=>{var s={type:"title",config:null,title:e,field:e};null!=t&&"function"==typeof t&&(s=t(s)),u.push(s.title),c.push(s.field)})}u.length>0&&(a.push(u),n.forEach(e=>{var s=[];c.forEach(r=>{var o={type:"data",config:i,field:r,data:e,value:e[r]};null!=t&&"function"==typeof t&&(o=t(o)),s.push(o.value)}),a.push(s)})),r.push({name:l,data:a})}return await s.writeMutlisheetExcel(r)}mkdirsSync(e,t){if(!s.existsSync(e)){let i;const a=e.split(r.sep);for(var o=0;o<a.length;o++){var n=a[o];0!=n.length?(i=i?r.join(i,n):n,s.existsSync(i)||s.mkdirSync(i,t)):i="/"}}return!0}}e.exports=n}(q)),q.exports}var M,L,v,B,j,P={};function F(){return M||(M=1,P.DATABASE_ERROR={DATABASE_CONNECTED_ERROR:10001,DATABASE_EXECUTE_ERROR:10002,NO_RECORD_EFFECTED:10003,NO_RECORD_FOUND:10004},P.COMMON_ERROR={TRANSMIT_TO_VIEW_ERROR:9e3,TRANSMIT_TO_DATA_ERROR:9001,VISIT_TO_INDEX:9002,API_PARAMETERS_ERROR:9003,VERIFY_CODE_ERROR:9004,NO_ACCESS_RIGHT:9100,TOKEN_IS_MISSING:9997,TOKEN_EXPIRED:9998,TOKEN_IS_INVALID:9999,UNAUTHORIZATION_ERROR:1e4},P.LOGIN_ERROR={SUCCESSED:0,USER_NOT_FOUND:1,USER_PASSWORD_ERROR:2,SERIAL_CODE_ERROR:3,UNKNOW_ERROR:4,DATABASE_ERROR:100},P.GET_USERINFO_ERROR={SUCCESSED:0,USER_NOT_FOUND:1,UNKNOW_ERROR:2,DATABASE_ERROR:100},P.CRUDAction={Create:{method:"post",name:"create",func:"create"},Retrieve:{method:"get",name:"list",func:"getListData"},Single:{method:"get",name:"single",func:"getDataById"},Update:{method:"put",name:"update",func:"update"},Delete:{method:"delete",name:"delete",func:"delete"}}),P}function k(){if(v)return L;v=1;const e=l.default,t=c.default;class s{constructor(){let s=t.join(process.cwd(),"dataconfig.json"),r=t.join(process.cwd(),"simplecommon.json");e.existsSync(s)?this.cache=require(s):(s=t.join(process.cwd(),"dataconfig.js"),e.existsSync(s)?this.cache=require(s):this.cache={}),e.existsSync(r)?this.commoncache=require(r):(r=t.join(process.cwd(),"simplecommon.js"),e.existsSync(r)?this.commoncache=require(r):this.commoncache={})}getConfig(e,t=0){return 0==t?this.getDataConfig(e):this.getCommonConfig(e)}static getCurrent(){return s.data||(s.data=new s),s.data}getDataConfig(e){return this.cache[e]}getCommonConfig(e){return this.commoncache[e]}}return L=s}function $(){if(j)return B;j=1;const{parseKeyValue:e,validatorParamsType:t}=T(),s=k().getCurrent(),r=m.default,o=["asc","desc"],n=/;|(--)|(\bWHERE\b)|(\bCASE\b)|(\bWHEN\b)|(\bSLEEP\b)|(\bSHOW\b)|(\bCOUNT\(\b)|(\bCREATE\b)|(\bCALL\b)|(\bBY\b)|(\bORDER\b)|(\bJOIN\b)|(\bUNION\b)|(\bFROM\b)|(\bSELECT\b)|(\bDROP\b)|(\bTRUNCATE\b)|(\bDELETE\b)|(\bUPDATE\b)|(\bINSERT\b)|(\bEXEC\b)|(\bEXECUTE\b)/gi;function i(e){return e&&n.test(e)?"":e}function a(e){return null==e||""===e}const l=e=>{let t=e||{};if(!t.request||!t.refer)return{filter:"",params:[]};t.valueFrom||(t.valueFrom="all");const s=t.request;let r=[],o=[];return t.refer.forEach(e=>{const t=c(s,e);t.sql&&(r.push(t.sql),o=o.concat(t.params||[]))}),{filter:r.join(""),params:o}},c=(s,r={})=>{let{pattern:o,type:n="parameter",inscope:i=[],allowEmpty:l=!1,split:c=!1,subitem:u,splitjoint:d="or",splitchar:p="|"}=r;if(!o)return{sql:""};const f=o.match(/@.*?@/g);let m=[];if(!f||f.length<=0)return{sql:o};for(const r of f){let f=r.substring(1,r.length-1);const h=/^[^a-zA-Z0-9]*(.*?)[^a-zA-Z0-9]*$/,g=f.match(h);if(f=g?g[1]:f,!f)return{sql:"",params:[]};let E=f.split("|");f=E[0];let _=e(s,f)||"";if(_&&E.length>1&&(_=t(_,E[1],E[2],i)),a(_)&&!l)return{sql:"",params:[]};if("parameter"===n.toLowerCase())if(c&&u){const e=_.split(p),t=[];for(const s of e)t.push(u),m.push(g[0].replace(g[1],s));o=o.replace(r,t.join(" "+d+" "))}else o=o.replace(r,"?"),Array.isArray(_)?m.push(_):m.push(g[0].replace(g[1],_));else if("joint"===n.toLowerCase()){i.some(e=>e.toLowerCase()===f.toLowerCase())&&(o=o.replace(r,_||""))}}return{sql:o,params:m}};return B={getSearchCondition:l,parseTagInSql:(s,o,n=!0)=>{if(!o)return"";const a=o.match(/@.*?@/g);if(!a||a.length<=0)return o;let l=!1;const c=/\s+|:|=/gi;return a.forEach(n=>{let a=n.substring(1,n.length-1),u=a.match(c);if(u&&u.length>0)return;let d="!"==a[0];d&&(a=a.substring(1));let p=a.split("|");a=p[0];let f=(e(s,a)||"")+"";f?"string"==typeof f?(f=d?i(r.escape(f)):r.escape(f),f=f.substring(1,f.length-1),f&&p.length>1&&(f=t(f,p[1],p[2])),f||(l=!0),!f&&d&&(f="1=0")):(l=!0,f=""):l=!0,o=o.replace(n,f)}),!n&&l?"":o},parseTagForParameterize:c,getListInfo:(e,t,r=0,n)=>{if(!t)return null;const a=s.getConfig(t,r);if(!a?.list)return null;const u="true"===(e.query.exportexcel+"").toLowerCase();let{page:d=1,rows:p=100,sort:f,order:m,clientFilter:h}=e.query;if(f&&(f=function(e,t=[]){return e?t&&t.length?t.map(e=>e.toLowerCase()).includes(e.toLowerCase())?e:null:e.indexOf(" ")>=0||e.indexOf("(")>=0||e.indexOf(")")>=0?null:i(e):e}(f,a.list.allow_sort_fields)),isNaN(p)&&(p=30),d&&!isNaN(d)||(d=1),p=Math.max(0,Math.min(p,1e4)),m&&f&&o.includes(m.toLowerCase())&&(f=f+" "+m),a&&a.list){e.dataConfig=a;let{sql:t,listsql:s,countsql:r,sqltype:o="sql",field:i,footer:m,search:h,sort:g}=a.list;const E=l({request:e,refer:h});f=f||g;const _=null;let R=[];if("sql"!==o&&s&&"function"==typeof n[s]&&(t=n[t](e,{page:d,rows:p,sort:f,filter:E.filter,client:_}),n[r]&&"function"==typeof n[r]&&(r=n[r](e,{page:d,rows:p,sort:f,filter:E.filter,client:_}))),"sql"===o){const s=c(e,{pattern:t,allowEmpty:!0});if(!s.sql)return null;if(t=`${s.sql} ${E.filter||""} ${f?" order by "+f:""} ${u?"":" limit "+Number(p)+" OFFSET "+(Math.max(Number(d),1)-1)*Number(p)};SELECT FOUND_ROWS() AS total;`,R=R.concat(s.params||[],E.params),r){const s=c(e,{pattern:r,allowEmpty:!0});if(!s.sql)return null;t+=function(e,t){return e.indexOf("#APPENDSEARCH#")>=0?e.replace("#APPENDSEARCH#",t):e+" "+t}(s.sql,E.filter||""),R=R.concat(s.params||[],E.params)}}return{sql:t,fields:i,params:R,footers:m,page:d,hascounter:!!r}}},getDetailInfo:(e,t)=>{if(t){const r=s.getConfig(t);if(r&&r.detail){e.dataConfig=r;const{primary:t,field:s,primaryIsAutoIncrease:o}=r.detail;return{primary:t,fields:s,autoincrease:o}}}return null}}}var V,K={exports:{}};function H(){return V||(V=1,function(e){const t=F();class s{constructor({successed:e=!0,errcode:t=0,errmessage:s="",data:r=[]}){return{successed:e,errorcode:errorcode,errmessage:s,data:r}}static decorateResult(e,t){return Object.keys(t).forEach(s=>{e[s]=t[s]}),e}}s.DB_CONNECTED_FAILED={successed:!1,errmessage:"DB_CONNECTED_FAILED",errorcode:t.DATABASE_ERROR.DATABASE_CONNECTED_ERROR},s.DB_EXECUTE_FAILED={successed:!1,errorcode:t.DATABASE_ERROR.DATABASE_EXECUTE_ERROR},s.DB_NO_EFFECTIVE={successed:!1,errmessage:"DB_NO_EFFECTIVE",errorcode:t.DATABASE_ERROR.NO_RECORD_EFFECTED},s.DB_NO_RECORD_FOUND={successed:!1,errmessage:"DB_NO_RECORD_FOUND",errorcode:t.DATABASE_ERROR.NO_RECORD_FOUND},s.SUCCESS_RESULT={successed:!0,errorcode:0},s.RETURN_TO_INDEX={successed:!1,errorcode:t.COMMON_ERROR.VISIT_TO_INDEX},s.TOKEN_IS_EXPIRED={successed:!1,errmessage:"TOKEN_IS_EXPIRED",errorcode:t.COMMON_ERROR.TOKEN_EXPIRED,total:0,rows:[]},s.TOKEN_IS_INVALID={successed:!1,errmessage:"TOKEN_IS_INVALID",errorcode:t.COMMON_ERROR.TOKEN_IS_INVALID,total:0,rows:[]},s.TOKEN_IS_MISSING={successed:!1,errmessage:"TOKEN_IS_MISSING",errorcode:t.COMMON_ERROR.TOKEN_IS_MISSING,total:0,rows:[]},s.UNAUTHORIZATION_RESULT={successed:!1,errmessage:"UNAUTHORIZATION_RESULT",errorcode:t.COMMON_ERROR.UNAUTHORIZATION_ERROR,total:0,rows:[]},s.NO_ACCESS_RIGHT_RESULT={successed:!1,errmessage:"NO_ACCESS_RIGHT_RESULT",errorcode:t.COMMON_ERROR.NO_ACCESS_RIGHT,total:0,rows:[]},s.API_PARAMETERS_ERROR_RESULT={successed:!1,errmessage:"API_PARAMETERS_ERROR_RESULT",errorcode:t.COMMON_ERROR.API_PARAMETERS_ERROR,total:0,rows:[]},s.VERIFY_CODE_ERROR={successed:!1,errmessage:"VERIFY_CODE_ERROR",errorcode:t.COMMON_ERROR.VERIFY_CODE_ERROR,total:0,rows:[]},e.exports=s}(K)),K.exports}var Y,X,G,W,z,J={exports:{}},Z={};function Q(){if(G)return X;G=1;const e=m.default,t=H(),{createDatabasePool:s}=function(){if(Y)return Z;Y=1;const e=m.default,t=D().getCurrentApp();let s={};return Z.createDatabasePool=r=>{if(null!=s[r])return s[r];const o=e.createPool(t.getConnection(r||"dev"));return s[r]=o,o},Z}(),r=Symbol("executeSqlWithConnection");return X=class{constructor(e){this.pool=s(e)}escape(t){return e.escape(t)}escapeId(t){return e.escapeId(t)}logError(e,t,s=null){!0!==this.ingoreErrorLog&&this.actionLogger&&"function"==typeof this.actionLogger.logError&&(e||(e=this.constructor.name),this.actionLogger.logError({scene:e,error:t,user:s}))}async existedSqlData(e,t,s,r=!0){let o=await this.executeSql(e,t,s,r);return o.successed?o.rows&&0!=o.rows.length?{successed:!0,existed:!0,...o.rows[0]}:{successed:!0,existed:!1}:{successed:!1}}async getComputedRowValue(e,t,s,r=!0){let o=await this.executeSql(e,t,s,r);return o.successed&&0!=o.rows.length?{successed:!0,...o.rows[0]}:{successed:!1,errcode:-1,errmsg:"没有任何记录"}}getConnection(){return new Promise(e=>{if(!this.pool)return e(null);this.pool.getConnection(function(t,s){return e(t?null:s)})})}executeSql(e,s,o,n=!0){return o?this[r](e,s,o,n):new Promise((o,i)=>{if(!this.pool)return o(t.DB_CONNECTED_FAILED);this.pool.getConnection(async(i,a)=>{if(i)return o(t.DB_CONNECTED_FAILED);let l=await this[r](e,s,a,n);return o(l)})})}[r](e,s,r,o=!0){return r?new Promise(n=>r.query(e,s,(s,i)=>(o&&r.release(),s?(console.log("数据库操作错误",s,e),this.logError(null,"数据库操作错误:"+s+e),n(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:"数据库操作错误"}))):n({successed:!0,rows:i})))):Promise.resolve(t.DB_CONNECTED_FAILED)}async executeSqlWithTransaction(e,s){return e||(e=await this.getConnection()),e?new Promise(r=>{e.beginTransaction(async o=>{if(o)return r({successed:!1,errcode:-1,errmessage:"【事务启动错误】"+o.message});let n={successed:!0};s&&"function"==typeof s&&(n=await s(e)),n.successed?e.commit(s=>s?(console.log("事务提交失败 :",s),r(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:s.message}))):(e.release(),r(n))):e.rollback(()=>(e.release(),r(Object.assign(t.DB_EXECUTE_FAILED,{errmessage:"撤回操作"}))))})}):Promise.resolve({successed:!1})}}}function ee(){return W||(W=1,function(e){const t=Q(),s=p.default;e.exports=class extends t{constructor(e){super(e&&e.database||"dev"),e&&(e.forcefilter=e.forcefilter||"",this.tableoption=e)}get hasPermissionControl(){return!!this.tableoption&&(this.tableoption.permission&&!isNaN(this.tableoption.permissiondatatype))}get permissionSql(){return this.hasPermissionControl?(this.tableoption.permissiondatatype,this.tableoption.primaryKey,"\n if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.department@',vp.data_department)')\n if (ifnull(vp.data_role, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.role@',vp.data_role)')\n if (ifnull(vp.data_department, '') = '', ' and 1 = 1 ', ' and find_in_set('@user.id @',vp.data_user)')\n "):""}getBusiness(){return this.tableoption?this.tableoption.business:null}async loadData(e,t){return this.executeSql(e,t)}getByIdSql(){return`select * from ${this.tableoption.tableName} where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`}updateSql(e){return`update ${this.tableoption.tableName} set ? where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`}insertSql(){return`insert into ${this.tableoption.tableName} set ?`}deleteSql(){if(this.tableoption.logicDelete){let e=`update ${this.tableoption.tableName} set #DELETEBY# #DELETEDATE# ${this.tableoption.logicDeleteField||"rec_isdeleted"} =1 where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`;return e=e.replace("#DELETEBY#",this.tableoption.logDeleteBy?`${this.tableoption.logDeleteBy}=?,`:""),e=e.replace("#DELETEDATE#",this.tableoption.logDeleteDate?`${this.tableoption.logDeleteDate}=now(),`:""),e}return`delete from ${this.tableoption.tableName} where ${this.tableoption.primaryKey} =? ${this.tableoption.forcefilter}`}BatchSql(){return`update ${this.tableoption.tableName} set ? where find_in_set(${this.tableoption.primaryKey},?) ${this.tableoption.forcefilter}`}async getBykey(e,t){return this.executeSql(e,t)}async create(e,t){return this.executeSql(e,t)}async update(e,t,s){return this.executeSql(e,[t,s])}async delete(e,t,s){return(t+"").trim().split(",").map(e=>"'"+e+"'"),this.tableoption.logicDelete&&this.tableoption.logDeleteBy?this.executeSql(e,[s,t]):this.executeSql(e,t)}async getDataPermissionSetting(e,t){if(!this.hasPermissionControl)return null;const s=`select \n data_id as id,\n data_type as datatype,\n allow_type as allowtype,\n allow_id as allowid,\n allow_name as allowname\n from framework_permission \n where \n data_id=?\n and data_type=? \n ${t}\n order by allow_type,allow_id\n `;return this.executeSql(s,[e,this.tableoption.permissiondatatype]).then(t=>{let s={successed:!0,managepermission:{},consumepermission:{datatype:this.tableoption.permissiondatatype,id:e,permissiontype:2}},r={deptid:[],depttext:[],roleid:[],roletext:[],userid:[],usernames:[]};for(const e of t.rows)switch(e.allowtype){case 1:r.deptid.push(e.allowid),r.depttext.push(e.allowname);break;case 2:r.roleid.push(e.allowid),r.roletext.push(e.allowname);break;case 4:r.userid.push(e.allowid),r.usernames.push(e.allowname)}return s.consumepermission.department=r.deptid.join(","),s.consumepermission.departmenttext=r.depttext.join(","),s.consumepermission.role=r.roleid.join(","),s.consumepermission.roletext=r.roletext.join(","),s.consumepermission.user=r.userid.join(","),s.consumepermission.usertext=r.usernames.join(","),s})}async saveDataPermissionSetting(e,t){if(!this.hasPermissionControl||!t)return Promise.resolve({successed:!0});let s="delete from framework_permission where data_id=? and data_type=?;",r=[];if(t.consumepermission){const s=t.consumepermission,o=s.department?s.department.split(","):[];for(const t of o)r.push([e,this.tableoption.permissiondatatype,1,t]);const n=s.role?s.role.split(","):[];for(const t of n)r.push([e,this.tableoption.permissiondatatype,2,t]);const i=s.user?s.user.split(","):[];for(const t of i)r.push([e,this.tableoption.permissiondatatype,4,t])}let o=[e,this.tableoption.permissiondatatype];return r.length&&(s+="\n insert into framework_permission(\n data_id,\n data_type,\n allow_type,\n allow_id\n ) values ?;\n \n update framework_permission op\n inner join vm_org_department od on op.allow_id=od.department_id\n set op.allow_name = od.department_name,\n op.allow_path = od.parent_path\n where data_id=? and data_type=? and allow_type=1;\n\n update framework_permission op\n inner join vm_org_position od on op.allow_id=od.position_id\n set op.allow_name = od.position_namecn\n where data_id=? and data_type=? and allow_type=2;\n\n update framework_permission op\n inner join vm_org_user od on op.allow_id=od.user_id\n set op.allow_name = od.user_name\n where data_id=? and data_type=? and allow_type=4;\n ",o.push(r,e,this.tableoption.permissiondatatype,e,this.tableoption.permissiondatatype,e,this.tableoption.permissiondatatype)),this.executeSql(s,o)}async batchUpdate(e,t,r,o){return this.tableoption.logicDelete&&this.tableoption.logDeleteBy&&null!=t[this.tableoption.logicDeleteField||"rec_isdeleted"]&&(t[this.tableoption.logDeleteBy]=o,this.tableoption.logDeleteDate&&(t[this.tableoption.logDeleteDate]=s().format("YYYY-MM-DD HH:mm:ss"))),this.executeSql(e,[t,r]).then(e=>({successed:!0,count:e.rows.affectedRows}))}}}(J)),J.exports}function te(){return z||(z=1,function(e){const t=u.default,{Data2View:s,View2Data:r}=function(){if(N)return x;N=1;const{parseKeyValue:e,formatValue:t,validatorParamsType:s}=T();return x={Data2View:(e,s)=>{if(!e)return{successed:!0,data:null};if(!s||0==s.length)return{successed:!0,data:e};let r=[];for(const o of e){let e={};for(const r of s){if("backonly"==r.direction)continue;let s=o[r.name];!s&&r.nullValue&&(s=r.nullValue),r.format&&(s=t(s,r.format)),e[r.mapping||r.name]=s}r.push(e)}return{successed:!0,data:r}},View2Data:(t,r,o)=>{let n={},i={};if(Array.isArray(r))for(const a of r){if("frontonly"==a.direction)continue;if(a.action&&a.action.indexOf(o)<0)continue;let r=a.mapping||a.name,l=t.body[r];if(void 0!==l||("update"!=o||a.required)&&("create"!=o||a.required||a.default||a.nullValue)){if("string"==typeof l&&(a.trim&&1!=a.trim||l.trim(),a.maxlength&&l.length>a.maxlength))return{successed:!1,errcode:6,errmsg:"输入的长度超出,最大允许"+a.maxlength,name:a.mapping};if(l||(l=a.nullValue?e(t,a.nullValue):null),!l&&a.default&&(l=a.default),!0===a.required&&!l)return{successed:!1,errcode:5,errmsg:"请填写必填字段内容",name:r};if(a.type&&l&&!s(l,a.type))return{successed:!1,errcode:4,errmsg:`提交的值与要求的类型不匹配:(${r},${a.type})`,name:r};if(a.model){let e=i[a.model]||{};e[a.name]=l,i[a.model]=e}else n[a.name]=l}}else n=t.body;return t.modellist=i,{successed:!0,data:n}}}}(),o=U(),n=F(),{getListInfo:i,getDetailInfo:a,parseTagInSql:l}=$(),c=H(),d=ee(),p=o.getInstance();e.exports=class{constructor(e,s){this.app=e,this._redisHelper=this.app.redis,this.logger=this.app.logger,this.actionLogger=this.app.actionLogger,this._daoModel=s||new d,this._daoModel.actionLogger=this.actionLogger,this._daoModel.logger=e.logger,this._router=t.Router(),this.initializeRouter(this)}get router(){return this._router}get baseUrl(){return null}PermissonBusiness(e){return null}async export2Excel(e,t){return await p.recordset2ExcelFile(e,t,this.beforeExportExcel)}async export2MutlisheetExcel(e){if(!Array.isArray(e)||0==e.length)return{successed:!1};return await p.recordset2MutlisheetExcelFile(e,this.beforeExportExcel)}async writeExcel(e,t){return await p.writeExcel(e,t)}logUserAction(e,t,s,r=0,o=null){this.actionLogger&&t&&s&&this.actionLogger.log(e,t,s,r,o)}createCRUDRoute(e,t,s,r){let o=this;o.router[e.method](t,r||((e,t,s)=>s()),async(r,n)=>{let i,a=await o.beforeCRUD(e,r,n);return a.successed?(i="delete"===e.method?await o.delete(r,r.params.id):await o[e.func](r,s),i=await o.afterCRUD(i,e,s,t,r,n),n.json(i)):n.json(a)})}initializeCRUDRouter(e,t,s="SCRUD",r){if(!e||!t)return;let o=e.endsWith("/")?`${e}:id`:`${e}/:id`;s.indexOf("C")>=0&&this.createCRUDRoute(n.CRUDAction.Create,e,t,r),s.indexOf("S")>=0&&this.createCRUDRoute(n.CRUDAction.Single,o,t,r),s.indexOf("R")>=0&&this.createCRUDRoute(n.CRUDAction.Retrieve,e,t,r),s.indexOf("U")>=0&&this.createCRUDRoute(n.CRUDAction.Update,o,t,r),s.indexOf("D")>=0&&this.createCRUDRoute(n.CRUDAction.Delete,o,t,r)}async beforeCRUD(e,t,s){return{successed:!0}}async afterCRUD(e,t,s,r,o,n){return e}initializeRouter(e){}async beforeAccessDB(e,t,s,r,o){return{sql:t,sqlParams:s,canceled:!1}}beforeExportExcel(e){return e}async batchUpdate(e,t,s){if(s||(s=e.params.id),!s)return{successed:!1,errcode:-2,errmsg:"缺失批量操作的id"};let r=l(e,this._daoModel.BatchSql()),o=await this._daoModel.batchUpdate(r,t,s,e.user?.id);return this.logUserAction(e,this._daoModel.getBusiness(),6,o.successed?0:-1),o}async getListData(e,t,r=0){this.logger&&this.logger.trace("准备获取dataconfig文件中对应的 %s list数据",t);const o=i(e,t,r,this._daoModel);if(!o)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的查询语句`};let n=await this.beforeAccessDB(e,o.sql,o.params,"list",this);if(!0===n.canceled)return{successed:!1,errorcode:1,errmsg:"操作取消"};let a=await this._daoModel.loadData(n.sql,n.sqlParams);if(!a.successed)return"true"===e.query.exportexcel&&this.logUserAction(e,this._daoModel.getBusiness(),5,-1),a;if(a.rows){let r=s(a.rows[0],o.fields),n={successed:!0,page:o.page,rows:r.data};if(o.hascounter){let e=s(a.rows[2],o.footers);n.footer=e.data}return n.total=await this.getListRecordCount(a),"true"===e.query.exportexcel&&(n=await this.export2Excel(n.rows,e.query.excelkey||t),this.logUserAction(e,this._daoModel.getBusiness(),5,0)),n}return{successed:!1,errcode:-1,total:0,rows:[]}}async getListRecordCount(e){return e.rows[1][0].total}async getDataById(e,t,r,o){this.logger&&this.logger.trace("准备获取dataconfig文件中对应的 %s 详细数据",t);const n=a(e,t);if(!n)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};let i=await this.beforeAccessDB(e,r||this._daoModel.getByIdSql(),o||e.params.id,"detail",this);if(!0===i.canceled)return{successed:!1,errorcode:1,errormessage:"操作已取消"};let u=l(e,i.sql),d=await this._daoModel.getBykey(u,i.sqlParams);if(!d.successed)return d;if(d.rows&&1==d.rows.length){let t=s(d.rows,n.fields);if(this._daoModel.hasPermissionControl){const s=await this._daoModel.getDataPermissionSetting(e.params.id,this.PermissonBusiness(e));s.successed&&(t.data[0].managepermission=s.managepermission,t.data[0].consumepermission=s.consumepermission)}return{successed:!0,rows:t.data[0],id:e.params.id}}return c.DB_NO_RECORD_FOUND}async create(e,t,s){this.logger&&this.logger.trace("准备根据dataconfig文件中对应的 %s 配置插入数据",t);let o,n=e.query.Mapping??!0,i={successed:!0,data:e.body};if(1==n){if(o=a(e,t),!o)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};if(i=r(e,o.fields,"create"),!i.successed)return i}let l=await this.beforeAccessDB(e,s||this._daoModel.insertSql(),i.data,"create",this);if(l.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};this.logger&&this.logger.trace("插入数据准备 : ",l);let c,u=await this._daoModel.create(l.sql,l.sqlParams,e);if(!u.successed)return this.logUserAction(e,this._daoModel.getBusiness(),1,-1),u;if(n&&o.primary&&(!0===o.autoincrease?c=u.rows.insertId:("string"==typeof o.primary&&(c=l.sqlParams[o.primary]),"object"==typeof o.primary&&(c=o.primary.map(e=>l.sqlParams[e])))),this._daoModel.hasPermissionControl){let t={};e.body.managepermission?t.managepermission=JSON.parse(e.body.managepermission):t.managepermission={},e.body.consumepermission?t.consumepermission=JSON.parse(e.body.consumepermission):t.consumepermission={},this._daoModel.saveDataPermissionSetting(c,t)}return this.logUserAction(e,this._daoModel.getBusiness(),1,0),{successed:!0,data:i.data,id:c}}async update(e,t,s,o){this.logger&&this.logger.trace("准备根据dataconfig文件中对应的 %s 配置修改数据",t),null==o&&(o=e.params.id);let n,i=e.query.Mapping??!0,u={successed:!0,data:e.body};if(1==i){if(n=a(e,t),!n)return{successed:!1,errcode:-10,errmsg:`缺失${t}对应的详情配置`};u=r(e,n.fields,"update")}let d=await this.beforeAccessDB(e,s||this._daoModel.updateSql(),u.data,"update",this);if(d.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};this.logger&&this.logger.trace("修改数据准备 : ",d);let p=l(e,d.sql),f=await this._daoModel.update(p,d.sqlParams,o);if(!f.successed)return this.logUserAction(e,this._daoModel.getBusiness(),3,-1),f;if(1==f.rows.affectedRows){if(this._daoModel.hasPermissionControl){let t={};e.body.managepermission?t.managepermission=JSON.parse(e.body.managepermission):t.managepermission={},e.body.consumepermission?t.consumepermission=JSON.parse(e.body.consumepermission):t.consumepermission={},this._daoModel.saveDataPermissionSetting(o,t)}return this.logUserAction(e,this._daoModel.getBusiness(),3,0),{successed:!0,data:u.data,id:o}}return c.DB_NO_EFFECTIVE}async delete(e,t,s){this.logger&&this.logger.trace("准备删除数据",t);let r=await this.beforeAccessDB(e,s||this._daoModel.deleteSql(t),t,"delete",this);if(r.canceled)return{successed:!1,errorcode:1,errormessage:"操作取消"};let o=l(e,r.sql),n=await this._daoModel.delete(o,r.sqlParams,e.user?.id);return n.successed?(this.logUserAction(e,this._daoModel.getBusiness(),2,0),{successed:!0,id:t,count:n.rows.affectedRows}):(this.logUserAction(e,this._daoModel.getBusiness(),2,-1),n)}}}(A)),A.exports}var se,re,oe={exports:{}};var ne=h(re?_.exports:(re=1,_.exports={doomiwork:O(),controller:te(),model:ee(),appsetting:D(),actionresult:H(),excelutility:U(),tokenHelper:(se||(se=1,function(e){class t{constructor(e){this.cache=e}setToken(e,t,s){return this.cache.set(e,t,s)}async getToken(e,t=!0){let s=await this.cache.get(e);return s&&t?JSON.parse(s):s}async tokenIsValid(e){return null!=await this.getToken(e,!1)}deleteToken(e){this.cache.delete(e)}extendToken(e,t){return this.cache.expire(e,t)}}e.exports.TokenHelper=e=>new t(e)}(oe)),oe.exports),constants:F()}));module.exports=ne;
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "doomiwork",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "doomisoft nodejs web framework",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
6
10
|
"scripts": {
|
|
7
|
-
"
|
|
11
|
+
"build": "rm -rf dist && rollup -c",
|
|
12
|
+
"pack": "npm run build && npm pack"
|
|
8
13
|
},
|
|
9
14
|
"keywords": [
|
|
10
15
|
"doomisoft",
|
|
@@ -14,10 +19,20 @@
|
|
|
14
19
|
"author": "stephen.shen",
|
|
15
20
|
"license": "ISC",
|
|
16
21
|
"dependencies": {
|
|
17
|
-
"express": "^4.17.1",
|
|
18
|
-
"moment": "^2.29.4",
|
|
19
22
|
"mysql": "^2.18.1",
|
|
20
|
-
"node-xlsx": "^0.24.0"
|
|
21
|
-
|
|
23
|
+
"node-xlsx": "^0.24.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
27
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
28
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
30
|
+
"rollup": "^2.79.2",
|
|
31
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
32
|
+
"rollup-plugin-typescript2": "^0.32.1"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"express": "*",
|
|
36
|
+
"moment": "*"
|
|
22
37
|
}
|
|
23
38
|
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
class appsetting{
|
|
4
|
-
constructor(){
|
|
5
|
-
let config = process.env.CONFIGFILE || 'configuration.json';
|
|
6
|
-
|
|
7
|
-
let configfile = path.join(process.cwd(), config);
|
|
8
|
-
console.log('configfile', configfile)
|
|
9
|
-
if (!fs.existsSync(configfile)) {
|
|
10
|
-
throw new Error('missing app configuration file')
|
|
11
|
-
}
|
|
12
|
-
this.settingjson = require(configfile);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 单例模式
|
|
16
|
-
* @param {*} config
|
|
17
|
-
*/
|
|
18
|
-
static getCurrentApp(){
|
|
19
|
-
if (!appsetting.app) appsetting.app = new appsetting();
|
|
20
|
-
return appsetting.app;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 获取到框架配置文件中的设置节点
|
|
24
|
-
* @param {*} settingKey
|
|
25
|
-
* @param {*} defaultValue
|
|
26
|
-
*/
|
|
27
|
-
getSetting (settingKey,defaultValue) {
|
|
28
|
-
if (!this.settingjson || !this.settingjson.appsetting) return defaultValue;
|
|
29
|
-
const item= this.settingjson.appsetting[settingKey];
|
|
30
|
-
return item??defaultValue;
|
|
31
|
-
}
|
|
32
|
-
getSection(sectionName){
|
|
33
|
-
return this.settingjson[sectionName];
|
|
34
|
-
}
|
|
35
|
-
/*
|
|
36
|
-
* 获取配置文件中的数据库连接串
|
|
37
|
-
*/
|
|
38
|
-
getConnection (connName) {
|
|
39
|
-
return this.settingjson.connections[connName];
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
exports=module.exports = appsetting;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* dataconfig配置文件的处理模块
|
|
3
|
-
*/
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path')
|
|
6
|
-
class dataConfig
|
|
7
|
-
{
|
|
8
|
-
constructor(){
|
|
9
|
-
let configfile = path.join(process.cwd(),'dataconfig.json');
|
|
10
|
-
let comcfgfile = path.join(process.cwd(),'simplecommon.json');
|
|
11
|
-
////检查dataconfig.json文件是否存在,优先加载dataconfig.json
|
|
12
|
-
if (!fs.existsSync(configfile)){
|
|
13
|
-
///如果json文件不存在,则加载后缀为js的文件
|
|
14
|
-
configfile = path.join(process.cwd(),'dataconfig.js');
|
|
15
|
-
if (!fs.existsSync(configfile)) throw new Error('missing app configuration file')
|
|
16
|
-
this.cache = require(configfile);
|
|
17
|
-
}else
|
|
18
|
-
this.cache = require(configfile);
|
|
19
|
-
////优先加载simplecommon.json文件
|
|
20
|
-
if (fs.existsSync(comcfgfile)){
|
|
21
|
-
this.commoncache = require(comcfgfile);
|
|
22
|
-
}else{
|
|
23
|
-
comcfgfile = path.join(process.cwd(),'simplecommon.js');
|
|
24
|
-
if (fs.existsSync(comcfgfile))
|
|
25
|
-
this.commoncache = require(comcfgfile);
|
|
26
|
-
else
|
|
27
|
-
this.commoncache = {};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
/*
|
|
32
|
-
*根据名称获取到配置中的对应节
|
|
33
|
-
*/
|
|
34
|
-
getConfig(itemName,cfgType=0) {
|
|
35
|
-
return cfgType==0?this.getDataConfig(itemName):this.getCommonConfig(itemName);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 单例模式
|
|
40
|
-
* @param {*} config
|
|
41
|
-
*/
|
|
42
|
-
static getCurrent(){
|
|
43
|
-
if (!dataConfig.data) dataConfig.data = new dataConfig();
|
|
44
|
-
return dataConfig.data;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getDataConfig(itemName) {
|
|
48
|
-
return this.cache[itemName];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getCommonConfig(itemName) {
|
|
52
|
-
return this.commoncache[itemName];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
module.exports = dataConfig;
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* dataconfig配置文件的处理模块
|
|
3
|
-
*/
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path')
|
|
6
|
-
////扫描Controller文件夹时需要排除的目录
|
|
7
|
-
const IGNORE_FOLDER = ["script", "scripts", "js", "image", "data", "video", "images", "style", "css", "app_themes"];
|
|
8
|
-
/**
|
|
9
|
-
* 加载控制器目录下的所有JS文件形成路由
|
|
10
|
-
* @param {*} result
|
|
11
|
-
* @param {*} routeGroup
|
|
12
|
-
*/
|
|
13
|
-
function loadFolderFiles4Router(result, startPath, routeGroup) {
|
|
14
|
-
let exceptFile = routeGroup.exceptfile;
|
|
15
|
-
let exceptfolder = routeGroup.exceptfolder;
|
|
16
|
-
let scanFolder = path.join(startPath, routeGroup.folder);
|
|
17
|
-
getFolderControllerFiles(result, scanFolder, exceptFile, exceptfolder);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 遍历加载整个文件夹下面的所有文件形成路由
|
|
21
|
-
* @param {*} result
|
|
22
|
-
* @param {*} startPath
|
|
23
|
-
* @param {*} execfiles
|
|
24
|
-
* @param {*} execfolder
|
|
25
|
-
*/
|
|
26
|
-
function getFolderControllerFiles(result, startPath, execfiles, execfolder) {
|
|
27
|
-
let files = fs.readdirSync(startPath);
|
|
28
|
-
for (const val of files) {
|
|
29
|
-
let fPath = path.join(startPath, val);
|
|
30
|
-
let stats = fs.statSync(fPath);
|
|
31
|
-
////是个目录
|
|
32
|
-
if (stats.isDirectory()) {
|
|
33
|
-
if (execfolder == null || execfolder.indexOf(fileName) < 0)
|
|
34
|
-
findFolderFiles(result, fPath, fPath, execfiles, execfolder);
|
|
35
|
-
}
|
|
36
|
-
///是个文件
|
|
37
|
-
else if (stats.isFile()) {
|
|
38
|
-
let fileExtion = path.extname(fPath).toLowerCase();
|
|
39
|
-
if (fileExtion !== ".js") continue;
|
|
40
|
-
let fileName = path.basename(fPath);
|
|
41
|
-
fileName = fileName.substr(0, fileName.length - fileExtion.length);
|
|
42
|
-
if (!execfiles || execfiles.indexOf(fileName) < 0) result.push(fPath);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 遍历加载整个文件夹下面的所有文件形成路由
|
|
49
|
-
* @param {*} result
|
|
50
|
-
* @param {*} baseFolder
|
|
51
|
-
* @param {*} startPath
|
|
52
|
-
* @param {*} execfiles
|
|
53
|
-
* @param {*} execfolder
|
|
54
|
-
*/
|
|
55
|
-
function findFolderFiles(result, baseFolder, startPath, execfiles, execfolder) {
|
|
56
|
-
let files = fs.readdirSync(startPath);
|
|
57
|
-
// files.forEach((val) => {
|
|
58
|
-
for (const val of files) {
|
|
59
|
-
let fPath = path.join(startPath, val), stats = fs.statSync(fPath), fileName = fPath.substr(baseFolder.length + 1);
|
|
60
|
-
if (stats.isDirectory()) {
|
|
61
|
-
///排除基本的忽略目录
|
|
62
|
-
if (IGNORE_FOLDER.includes(fileName.toLowerCase())) continue;
|
|
63
|
-
if (execfolder == null || execfolder.indexOf(fileName) < 0)
|
|
64
|
-
findFolderFiles(result, baseFolder, fPath, execfiles, execfolder);
|
|
65
|
-
}
|
|
66
|
-
if (stats.isFile()) {
|
|
67
|
-
let fileExtion = path.extname(fPath).toLowerCase();
|
|
68
|
-
if (fileExtion != ".html") continue;
|
|
69
|
-
let fileName = fPath.substr(baseFolder.length + 1);
|
|
70
|
-
fileName = fileName.substr(0, fileName.length - fileExtion.length);
|
|
71
|
-
if (execfiles == null || execfiles.indexOf(fileName) < 0) result.push(fileName);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// class routerconfig {
|
|
76
|
-
// constructor(routerfile) {
|
|
77
|
-
// ///路由的配置文件
|
|
78
|
-
// let configfile = path.join(process.cwd(), routerfile || 'routerconfig.json');
|
|
79
|
-
// if (fs.existsSync(configfile)) {
|
|
80
|
-
// this.routerconfig = require(configfile);
|
|
81
|
-
// } else {
|
|
82
|
-
// this.routerconfig = [];
|
|
83
|
-
// }
|
|
84
|
-
// }
|
|
85
|
-
// /**
|
|
86
|
-
// * 单例模式
|
|
87
|
-
// * @param {*} config
|
|
88
|
-
// */
|
|
89
|
-
// static getInstance() {
|
|
90
|
-
// if (!routerconfig.setting) routerconfig.setting = new routerconfig();
|
|
91
|
-
// return routerconfig.setting;
|
|
92
|
-
// }
|
|
93
|
-
/**
|
|
94
|
-
* 加载应用下所有配置的controller文件
|
|
95
|
-
* @param {*} controllerconfig
|
|
96
|
-
* @param {*} providerCollection
|
|
97
|
-
*/
|
|
98
|
-
module.exports.loadController=(app, routes)=> {
|
|
99
|
-
///定位置项目启动目录,准备遍历所有controller目录
|
|
100
|
-
if (!Array.isArray(routes) || !routes.length) return;
|
|
101
|
-
let startupRoot = process.cwd();
|
|
102
|
-
//let routes = routelist?routelist:this.routerconfig ;
|
|
103
|
-
for (const element of routes) {
|
|
104
|
-
//if (!element.routers || element.routers.length == 0) return;
|
|
105
|
-
///路由被禁用,则略过
|
|
106
|
-
if (element.disabled) continue;
|
|
107
|
-
///包含文件
|
|
108
|
-
if (element.include) {
|
|
109
|
-
let includeRouteJson = path.join(startupRoot, element.include);
|
|
110
|
-
console.log('includeRouteJson', includeRouteJson)
|
|
111
|
-
///如果包含文件存在,则加载这个文件里面的路由
|
|
112
|
-
if (fs.existsSync(includeRouteJson)) {
|
|
113
|
-
this.loadController(app, require(includeRouteJson));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
let modules = [];
|
|
118
|
-
let { baseUrl, groupName } = element.routefolder ? element.routefolder : element;
|
|
119
|
-
if (groupName && app.Interceptor[groupName]) app.use(baseUrl, app.Interceptor[groupName])
|
|
120
|
-
if (element.routefolder) {
|
|
121
|
-
if (element.routefolder.folder) loadFolderFiles4Router(modules, startupRoot, element.routefolder);
|
|
122
|
-
}
|
|
123
|
-
////单文件
|
|
124
|
-
else {
|
|
125
|
-
if (fs.existsSync(path.join(startupRoot, element.controller)))
|
|
126
|
-
modules.push(path.join(startupRoot, element.controller));
|
|
127
|
-
}
|
|
128
|
-
////单个文件的加载
|
|
129
|
-
if (modules.length > 0) {
|
|
130
|
-
for (const modulePath of modules) {
|
|
131
|
-
//if (app.logger) app.logger.trace('initlize controller [%s] for baseUrl [%s]', modulePath, baseUrl);
|
|
132
|
-
// console.log('initlize controller [%s] for baseUrl [%s]', modulePath, baseUrl);
|
|
133
|
-
const controllModule = require(modulePath);
|
|
134
|
-
const controller = new controllModule(app);
|
|
135
|
-
app.use(baseUrl, controller.router);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// }
|
|
144
|
-
// module.exports = routerconfig;
|
package/core/actionresult.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const errnum = require('./enumconst')
|
|
2
|
-
|
|
3
|
-
class ActionResult {
|
|
4
|
-
constructor({ successed = true, errcode = 0, errmessage = '', data = [] }) {
|
|
5
|
-
return { successed: successed, errorcode: errorcode, errmessage: errmessage, data: data }
|
|
6
|
-
}
|
|
7
|
-
//*为结果添加一些附加的值
|
|
8
|
-
static decorateResult(result, opts) {
|
|
9
|
-
Object.keys(opts).forEach(key => {
|
|
10
|
-
result[key] = opts[key];
|
|
11
|
-
});
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
ActionResult.DB_CONNECTED_FAILED = { successed: false, errmessage: 'DB_CONNECTED_FAILED', errorcode: errnum.DATABASE_ERROR.DATABASE_CONNECTED_ERROR };
|
|
16
|
-
ActionResult.DB_EXECUTE_FAILED = { successed: false, errorcode: errnum.DATABASE_ERROR.DATABASE_EXECUTE_ERROR };
|
|
17
|
-
ActionResult.DB_NO_EFFECTIVE = { successed: false, errmessage: 'DB_NO_EFFECTIVE', errorcode: errnum.DATABASE_ERROR.NO_RECORD_EFFECTED };
|
|
18
|
-
ActionResult.DB_NO_RECORD_FOUND = { successed: false, errmessage: 'DB_NO_RECORD_FOUND', errorcode: errnum.DATABASE_ERROR.NO_RECORD_FOUND };
|
|
19
|
-
|
|
20
|
-
ActionResult.SUCCESS_RESULT = { successed: true, errorcode: 0 };
|
|
21
|
-
ActionResult.RETURN_TO_INDEX = { successed: false, errorcode: errnum.COMMON_ERROR.VISIT_TO_INDEX };
|
|
22
|
-
ActionResult.TOKEN_IS_EXPIRED = { successed: false, errmessage: 'TOKEN_IS_EXPIRED', errorcode: errnum.COMMON_ERROR.TOKEN_EXPIRED , total: 0, rows: [] };
|
|
23
|
-
ActionResult.TOKEN_IS_INVALID = { successed: false, errmessage: 'TOKEN_IS_INVALID', errorcode: errnum.COMMON_ERROR.TOKEN_IS_INVALID, total: 0, rows: [] };
|
|
24
|
-
ActionResult.TOKEN_IS_MISSING = { successed: false, errmessage: 'TOKEN_IS_MISSING', errorcode: errnum.COMMON_ERROR.TOKEN_IS_MISSING, total: 0, rows: [] };
|
|
25
|
-
ActionResult.UNAUTHORIZATION_RESULT = { successed: false, errmessage: 'UNAUTHORIZATION_RESULT', errorcode: errnum.COMMON_ERROR.UNAUTHORIZATION_ERROR, total: 0, rows: [] };
|
|
26
|
-
ActionResult.NO_ACCESS_RIGHT_RESULT = { successed: false, errmessage: 'NO_ACCESS_RIGHT_RESULT', errorcode: errnum.COMMON_ERROR.NO_ACCESS_RIGHT, total: 0, rows: [] };
|
|
27
|
-
ActionResult.API_PARAMETERS_ERROR_RESULT = { successed: false, errmessage: 'API_PARAMETERS_ERROR_RESULT', errorcode: errnum.COMMON_ERROR.API_PARAMETERS_ERROR, total: 0, rows: [] };
|
|
28
|
-
ActionResult.VERIFY_CODE_ERROR = { successed: false, errmessage: 'VERIFY_CODE_ERROR', errorcode: errnum.COMMON_ERROR.VERIFY_CODE_ERROR, total: 0, rows: [] };
|
|
29
|
-
|
|
30
|
-
exports = module.exports = ActionResult;
|