doomiwork 4.1.0 → 4.1.2

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.
@@ -3,7 +3,9 @@ const fs = require('fs');
3
3
  class appsetting{
4
4
  constructor(){
5
5
  let config = process.env.CONFIGFILE || 'configuration.json';
6
+
6
7
  let configfile = path.join(process.cwd(), config);
8
+ console.log('configfile', configfile)
7
9
  if (!fs.existsSync(configfile)) {
8
10
  throw new Error('missing app configuration file')
9
11
  }
@@ -107,6 +107,7 @@ module.exports.loadController=(app, routes)=> {
107
107
  ///包含文件
108
108
  if (element.include) {
109
109
  let includeRouteJson = path.join(startupRoot, element.include);
110
+ console.log('includeRouteJson', includeRouteJson)
110
111
  ///如果包含文件存在,则加载这个文件里面的路由
111
112
  if (fs.existsSync(includeRouteJson)) {
112
113
  this.loadController(app, require(includeRouteJson));
@@ -127,7 +128,8 @@ module.exports.loadController=(app, routes)=> {
127
128
  ////单个文件的加载
128
129
  if (modules.length > 0) {
129
130
  for (const modulePath of modules) {
130
- if (app.logger) app.logger.trace('initlize controller [%s] for baseUrl [%s]', modulePath, baseUrl);
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);
131
133
  const controllModule = require(modulePath);
132
134
  const controller = new controllModule(app);
133
135
  app.use(baseUrl, controller.router);
@@ -42,7 +42,7 @@ class controller {
42
42
  /**
43
43
  * 权限的业务sql过滤
44
44
  */
45
- PermissonBusiness(req){
45
+ PermissonBusiness(_req){
46
46
  return null;
47
47
  }
48
48
  /**
@@ -227,11 +227,11 @@ class controller {
227
227
  /*
228
228
  * 获取详细记录的方法
229
229
  */
230
- async getDataById(req, dataKey, sqlCommand) {
230
+ async getDataById(req, dataKey, sqlCommand,idValue) {
231
231
  if (this.logger) this.logger.trace("准备获取dataconfig文件中对应的 %s 详细数据",dataKey)
232
232
  const detailinfo = getDetailInfo(req, dataKey);
233
233
  if (!detailinfo) return { successed: false, errcode: -10, errmsg: `缺失${dataKey}对应的详情配置` };
234
- let beforeData = await this.beforeAccessDB(req, sqlCommand || this._daoModel.getByIdSql(), req.params.id, "detail", this);
234
+ let beforeData = await this.beforeAccessDB(req, sqlCommand || this._daoModel.getByIdSql(), idValue ||req.params.id, "detail", this);
235
235
  ////如果返回Null,则表示不加载数据了
236
236
  if (beforeData.canceled===true) return { successed: false, errorcode: 1, errormessage: "操作已取消" };
237
237
  /////处理SQL中的一些定义符
@@ -362,7 +362,7 @@ class controller {
362
362
  */
363
363
  async delete(req, id, sqlCommand) {
364
364
  if (this.logger) this.logger.trace("准备删除数据",id)
365
- let beforeData = await this.beforeAccessDB(req, sqlCommand || this._daoModel.deleteSql(), id, "delete", this);
365
+ let beforeData = await this.beforeAccessDB(req, sqlCommand || this._daoModel.deleteSql(id), id, "delete", this);
366
366
  ////如果返回Null,则表示不加载数据了
367
367
  if (beforeData.canceled) return { successed: false, errorcode: 1, errormessage: "操作取消" };
368
368
  /////处理SQL中的一些定义符
@@ -89,7 +89,7 @@ class mysqlDao extends dao{
89
89
  /**
90
90
  * 更改记录
91
91
  */
92
- updateSql() {
92
+ updateSql(id) {
93
93
  return `update ${this.tableoption.tableName} set ? where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
94
94
  }
95
95
  /**
@@ -101,16 +101,17 @@ class mysqlDao extends dao{
101
101
  /**
102
102
  * 删除记录
103
103
  */
104
- deleteSql() {
104
+ deleteSql(id) {
105
+ const ids = (id + '').trim().split(',').map(x => '\'' + x + '\'');
105
106
  ////如果是逻辑删除,则只将记录的删除状态设置为1
106
107
  if(this.tableoption.logicDelete) {
107
108
 
108
- let sqlDelete = `update ${this.tableoption.tableName} set #DELETEBY# #DELETEDATE# ${this.tableoption.logicDeleteField || 'rec_isdeleted'} =1 where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
109
+ let sqlDelete = `update ${this.tableoption.tableName} set #DELETEBY# #DELETEDATE# ${this.tableoption.logicDeleteField || 'rec_isdeleted'} =1 where ${this.tableoption.primaryKey} in (?) ${this.tableoption.forcefilter}`;
109
110
  sqlDelete = sqlDelete.replace('#DELETEBY#', this.tableoption.logDeleteBy?`${this.tableoption.logDeleteBy}=?,`:'')
110
111
  sqlDelete = sqlDelete.replace('#DELETEDATE#', this.tableoption.logDeleteDate ? `${this.tableoption.logDeleteDate}=now(),` : '');
111
112
  return sqlDelete;
112
113
  }
113
- return `delete from ${this.tableoption.tableName} where ${this.tableoption.primaryKey}=? ${this.tableoption.forcefilter}`;
114
+ return `delete from ${this.tableoption.tableName} where ${this.tableoption.primaryKey} in (?) ${this.tableoption.forcefilter}`;
114
115
  }
115
116
 
116
117
  /**
@@ -128,10 +129,11 @@ class mysqlDao extends dao{
128
129
  async update(Sql, model, id) {return this.executeSql(Sql, [model, id]);}
129
130
  ///删除记录
130
131
  async delete(Sql, id,userid) {
132
+ const ids = (id + '').trim().split(',').map(x => '\'' + x + '\'');
131
133
  if (this.tableoption.logicDelete && this.tableoption.logDeleteBy){
132
- return this.executeSql(Sql, [userid,id]);
134
+ return this.executeSql(Sql, [userid, ids.join(',')]);
133
135
  }
134
- return this.executeSql(Sql, id);
136
+ return this.executeSql(Sql, ids.join(','));
135
137
  ///
136
138
  //return this.executeSql(Sql, id);
137
139
  /*if (result.successed && this.tableoption.logicDelete && userid && (this.tableoption.logDeleteBy || this.tableoption.logDeleteDate)){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiwork",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "doomisoft nodejs web framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@ module.exports.getSearchCondition = (option) => {
30
30
  const request = paraCopy.request;
31
31
  let retSearch = [];
32
32
  paraCopy.refer.forEach(element => {
33
- retSearch.push(this.parseTagInSql(request, element.pattern, false));
33
+ retSearch.push(this.parseTagInSql(request, element.pattern, false,true));
34
34
  });
35
35
  return retSearch.join('');
36
36
  }
@@ -42,7 +42,7 @@ module.exports.getSearchCondition = (option) => {
42
42
  * @param {*} allowNull
43
43
  * @returns
44
44
  */
45
- module.exports.parseTagInSql = (req, sql, allowNull = true) => {
45
+ module.exports.parseTagInSql = (req, sql, allowNull = true,isSearch=false) => {
46
46
  if (!sql) return '';
47
47
  ///定义正则准备查找sql中的特定关键字
48
48
  const matched = sql.match(/@.*?@/g);
@@ -67,7 +67,7 @@ module.exports.parseTagInSql = (req, sql, allowNull = true) => {
67
67
  if (!keyValue) {
68
68
  parseKeyWordIsNull = true;
69
69
  } else if (typeof (keyValue) === 'string') {
70
- keyValue = noQuoteProtect ? checkSqlInjection(mysql.escape(keyValue)) : mysql.escape(keyValue)
70
+ keyValue = noQuoteProtect || isSearch ? checkSqlInjection(mysql.escape(keyValue)) : mysql.escape(keyValue)
71
71
  keyValue = keyValue.substr(1, keyValue.length - 2);
72
72
  ///验证参数的格式合法性
73
73
  if (keyValue && validformat.length > 1) {
@@ -108,14 +108,14 @@ module.exports.getListInfo = (req, dataKey, cfgType = 0, dao) => {
108
108
  // 防止页面数据传入非数字
109
109
  if (!page || isNaN(page)) page = 1
110
110
  ///最大允许获取100条数据
111
- pageSize = Math.min(pageSize, 100);
111
+ pageSize =Math.max(0,Math.min(pageSize, 10000));
112
112
  ///拼接排序的语句
113
113
  if (order && sort && ORDER_STRING.includes(order.toLowerCase())) sort = sort + ' ' + order
114
114
  //req.order =req.sort? utility.ifNull((req.body.order || req.query.order), ""):'';
115
115
  const dataConfig = dataconfig.getConfig(dataKey, cfgType);
116
116
  if (dataConfig && dataConfig.list) {
117
117
  req.dataConfig = dataConfig
118
- let { sql, countsql, sqltype = 'sql', field, footer, search, sort: constsort } = dataConfig.list
118
+ let { sql, listsql, countsql, sqltype = 'sql', field, footer, search, sort: constsort } = dataConfig.list
119
119
  /**解析查询条件 */
120
120
  const searchCondition = this.getSearchCondition({ request: req, refer: search });
121
121
  /**排序方式 *///
@@ -134,7 +134,7 @@ module.exports.getListInfo = (req, dataKey, cfgType = 0, dao) => {
134
134
  sql = this.parseTagInSql(req, sql) +
135
135
  ' ' + searchCondition + clientfilter +
136
136
  (sort ? (' order by ' + sort) : '') +
137
- (export2Excel ? '' : ' limit ' + Number(pageSize) + ' OFFSET ' + (Number(page) - 1) * Number(pageSize)) +
137
+ (export2Excel ? '' : ' limit ' + Number(pageSize) + ' OFFSET ' + (Math.max(Number(page), 1) - 1) * Number(pageSize)) +
138
138
  /////在Sql中再放入获取总记录数的语句
139
139
  ';SELECT FOUND_ROWS() AS total;';
140
140
  /*** 如果存在汇总列的sql,则把SQL放置在最末尾 */