Commit ad95aca8 by v_vjyjiang

d

parent 2e0b3d5a
......@@ -9,10 +9,10 @@ class Dao {
this.model = db.models[this.modelName];
console.log(this.modelName);
}
preCreate(u) {
preCreate (u) {
return u;
}
async create(u, t) {
async create (u, t) {
var u2 = this.preCreate(u);
if (t) {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
......@@ -26,10 +26,10 @@ class Dao {
});
}
}
static getModelName(ClassObj) {
static getModelName (ClassObj) {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase()
}
async refQuery(qobj) {
async refQuery (qobj) {
var w = qobj.refwhere ? qobj.refwhere : {};
if (qobj.levelinfo) {
w[qobj.levelinfo.levelfield] = qobj.levelinfo.level;
......@@ -48,7 +48,7 @@ class Dao {
return this.model.findAll({ where: w, attributes: qobj.fields });
}
}
async bulkDelete(ids, t) {
async bulkDelete (ids, t) {
if (t) {
var en = await this.model.destroy({ where: { id: { [this.db.Op.in]: ids } }, transaction: t });
return en;
......@@ -58,7 +58,7 @@ class Dao {
}
}
async bulkDeleteByWhere(whereParam, t) {
async bulkDeleteByWhere (whereParam, t) {
var en = null;
if (t != null && t != 'undefined') {
whereParam.transaction = t;
......@@ -67,7 +67,7 @@ class Dao {
return await this.model.destroy(whereParam);
}
}
async delete(qobj, t) {
async delete (qobj, t) {
var en = null
if (t != null && t != 'undefined') {
en = await this.model.findOne({ where: { id: qobj.id }, transaction: t });
......@@ -83,14 +83,14 @@ class Dao {
}
return null;
}
extraModelFilter(pobj) {
extraModelFilter (pobj) {
//return {"key":"include","value":{model:this.db.models.app}};
return null;
}
extraWhere(obj, where) {
extraWhere (obj, where) {
return where;
}
orderBy(qobj) {
orderBy (qobj) {
//return {"key":"include","value":{model:this.db.models.app}};
if (!qobj.orderInfo || qobj.orderInfo.length == 0) {
return [["created_at", "DESC"]];
......@@ -99,7 +99,7 @@ class Dao {
}
}
buildQuery(qobj) {
buildQuery (qobj) {
var linkAttrs = [];
const pageNo = qobj.pageInfo.pageNo;
const pageSize = qobj.pageInfo.pageSize;
......@@ -157,7 +157,7 @@ class Dao {
console.log(qc);
return qc;
}
buildaggs(qobj) {
buildaggs (qobj) {
var aggsinfos = [];
if (qobj.aggsinfo) {
qobj.aggsinfo.sum.forEach(aggitem => {
......@@ -171,7 +171,7 @@ class Dao {
}
return aggsinfos;
}
async findAggs(qobj, qcwhere) {
async findAggs (qobj, qcwhere) {
var aggArray = this.buildaggs(qobj);
if (aggArray.length != 0) {
qcwhere["attributes"] = {};
......@@ -190,7 +190,10 @@ class Dao {
}
}
async findAndCountAll(qobj, t) {
convertAggResult (aggresult) {
return aggresult
}
async findAndCountAll (qobj, t) {
var qc = this.buildQuery(qobj);
let findList = {}
let count = await this.findCount({ where: qc.where })
......@@ -198,15 +201,16 @@ class Dao {
findList["count"] = count
findList["rows"] = rows
var aggresult = await this.findAggs(qobj, qc);
let convertAggResult = this.convertAggResult(aggresult);
var rtn = {};
rtn.results = findList;
rtn.aggresult = aggresult;
rtn.aggresult = convertAggResult;
return rtn;
}
preUpdate(obj) {
preUpdate (obj) {
return obj;
}
async update(obj, tm) {
async update (obj, tm) {
var obj2 = this.preUpdate(obj);
if (tm != null && tm != 'undefined') {
return this.model.update(obj2, { where: { id: obj2.id }, transaction: tm });
......@@ -214,7 +218,7 @@ class Dao {
return this.model.update(obj2, { where: { id: obj2.id } });
}
}
async bulkCreate(ids, t) {
async bulkCreate (ids, t) {
if (t != null && t != 'undefined') {
return await this.model.bulkCreate(ids, { transaction: t });
} else {
......@@ -222,7 +226,7 @@ class Dao {
}
}
async updateByWhere(setObj, whereObj, t) {
async updateByWhere (setObj, whereObj, t) {
let inWhereObj = {}
if (t && t != 'undefined') {
if (whereObj && whereObj != 'undefined') {
......@@ -236,10 +240,10 @@ class Dao {
}
return this.model.update(setObj, inWhereObj);
}
async customExecAddOrPutSql(sql, paras = null) {
async customExecAddOrPutSql (sql, paras = null) {
return this.db.query(sql, paras);
}
async customQuery(sql, paras, t) {
async customQuery (sql, paras, t) {
var tmpParas = null;//||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') {
......@@ -254,15 +258,15 @@ class Dao {
}
return this.db.query(sql, tmpParas);
}
async findCount(whereObj = null) {
async findCount (whereObj = null) {
return this.model.count(whereObj, { logging: false }).then(c => {
return c;
});
}
async findSum(fieldName, whereObj = null) {
async findSum (fieldName, whereObj = null) {
return this.model.sum(fieldName, whereObj);
}
async getPageList(pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
async getPageList (pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
var tmpWhere = {};
tmpWhere.limit = pageSize;
tmpWhere.offset = (pageIndex - 1) * pageSize;
......@@ -283,20 +287,20 @@ class Dao {
}
return await this.model.findAndCountAll(tmpWhere);
}
async findOne(obj, attributes = []) {
async findOne (obj, attributes = []) {
if (attributes.length > 0) {
return this.model.findOne({ "where": obj, attributes, row: true });
} else {
return this.model.findOne({ "where": obj, row: true });
}
}
async findOneWithTm(obj, t) {
async findOneWithTm (obj, t) {
return this.model.findOne({ "where": obj, transaction: t });
}
async findById(oid) {
async findById (oid) {
return this.model.findById(oid);
}
async findAll(obj, include = [], other = {}) {
async findAll (obj, include = [], other = {}) {
return this.model.findAll({ "where": obj, include, row: true, ...other });
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment