Commit 93023e5c by Sxy

Merge branch 'center-manage' of gitlab.gongsibao.com:jiangyong/zhichan into center-manage

parents f57aa41f 77e01456
......@@ -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;
......@@ -159,7 +159,7 @@ class Dao {
console.log(qc);
return qc;
}
buildaggs(qobj) {
buildaggs (qobj) {
var aggsinfos = [];
if (qobj.aggsinfo) {
qobj.aggsinfo.sum.forEach(aggitem => {
......@@ -173,7 +173,7 @@ class Dao {
}
return aggsinfos;
}
async findAggs(qobj, qcwhere) {
async findAggs (qobj, qcwhere) {
var aggArray = this.buildaggs(qobj);
if (aggArray.length != 0) {
qcwhere["attributes"] = {};
......@@ -192,7 +192,7 @@ class Dao {
}
}
async findAndCountAll(qobj, t) {
async findAndCountAll (qobj, t) {
var qc = this.buildQuery(qobj);
let findList = {}
let count = await this.findCount({ where: qc.where })
......@@ -205,18 +205,22 @@ class Dao {
rtn.aggresult = aggresult;
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 });
await this.model.update(obj2, { where: { id: obj2.id }, transaction: tm });
let n = await this.model.findOne({ where: { id: obj2.id }, transaction: tm });
return n
} else {
return this.model.update(obj2, { where: { id: obj2.id } });
await this.model.update(obj2, { where: { id: obj2.id } });
let n = await this.model.findById(obj2.id)
return n
}
}
async bulkCreate(ids, t) {
async bulkCreate (ids, t) {
if (t != null && t != 'undefined') {
return await this.model.bulkCreate(ids, { transaction: t });
} else {
......@@ -224,7 +228,7 @@ class Dao {
}
}
async updateByWhere(setObj, whereObj, t) {
async updateByWhere (setObj, whereObj, t) {
let inWhereObj = {}
if (t && t != 'undefined') {
if (whereObj && whereObj != 'undefined') {
......@@ -238,10 +242,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') {
......@@ -256,15 +260,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;
......@@ -285,20 +289,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 });
}
}
......
......@@ -103,7 +103,7 @@ class ProductService extends ServiceBase {
if (productprices.length > 0) {
await self.priceDao.bulkCreate(productprices, t)
}
return {};
return currentProduct;
});
}
}
......
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