2020-01-12 19:15:08 +08:00
|
|
|
/**
|
|
|
|
|
* Created by strawmanbobi
|
|
|
|
|
* 2016-11-27
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// global inclusion
|
2020-06-14 11:56:18 +08:00
|
|
|
let orm = require('orm');
|
|
|
|
|
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
|
|
|
|
let logger = require('../mini_poem/logging/logger4js').helper;
|
2020-01-12 19:15:08 +08:00
|
|
|
|
|
|
|
|
// local inclusion
|
2020-06-14 11:56:18 +08:00
|
|
|
let ErrorCode = require('../constants/error_code');
|
|
|
|
|
let errorCode = new ErrorCode();
|
2020-01-12 19:15:08 +08:00
|
|
|
|
2020-06-14 11:56:18 +08:00
|
|
|
let StbOperator = dbOrm.define('stb_operator',
|
2020-01-12 19:15:08 +08:00
|
|
|
{
|
|
|
|
|
id: Number,
|
|
|
|
|
operator_id: String,
|
|
|
|
|
operator_name: String,
|
|
|
|
|
city_code: String,
|
|
|
|
|
city_name: String,
|
|
|
|
|
status: Number,
|
|
|
|
|
operator_name_tw: String
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
cache: false
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
StbOperator.listStbOperators = function(conditions, from, count, sortField, callback) {
|
|
|
|
|
if("id" == sortField && 0 != from) {
|
|
|
|
|
conditions.id = orm.lt(from);
|
|
|
|
|
StbOperator.find(conditions).limit(parseInt(count)).orderRaw("?? DESC", [sortField])
|
|
|
|
|
.run(function (error, stbOperators) {
|
|
|
|
|
if (error) {
|
|
|
|
|
logger.error("list stbOperators error : " + error);
|
|
|
|
|
callback(errorCode.FAILED, null);
|
|
|
|
|
} else {
|
|
|
|
|
callback(errorCode.SUCCESS, stbOperators);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
StbOperator.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? DESC", [sortField])
|
|
|
|
|
.run(function (error, stbOperators) {
|
|
|
|
|
if (error) {
|
|
|
|
|
logger.error("list stbOperators error : " + error);
|
|
|
|
|
callback(errorCode.FAILED, null);
|
|
|
|
|
} else {
|
|
|
|
|
callback(errorCode.SUCCESS, stbOperators);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StbOperator.findStbOperatorsByConditions = function(conditions, callback) {
|
|
|
|
|
StbOperator.find(conditions, function (error, stbOperators) {
|
|
|
|
|
if (error) {
|
|
|
|
|
logger.error("find stbOperators error : " + error);
|
|
|
|
|
callback(errorCode.FAILED, null);
|
|
|
|
|
} else {
|
|
|
|
|
callback(errorCode.SUCCESS, stbOperators);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = StbOperator;
|