merged private server and console to private-cloud
This commit is contained in:
146
console/model/brand_dao.js
Normal file
146
console/model/brand_dao.js
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var Enums = require('../constants/enums');
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
var enums = new Enums();
|
||||
|
||||
var Brand = dbOrm.define('brand',
|
||||
{
|
||||
id: Number,
|
||||
name: String,
|
||||
category_id: Number,
|
||||
category_name: String,
|
||||
status: Number,
|
||||
update_time: String,
|
||||
priority: Number,
|
||||
name_en: String,
|
||||
name_tw: String,
|
||||
contributor: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
Brand.createBrand = function(brand, callback) {
|
||||
var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
var newBrand = new Brand({
|
||||
name: brand.name,
|
||||
category_id: brand.category_id,
|
||||
category_name: brand.category_name,
|
||||
status: enums.ITEM_VERIFY,
|
||||
update_time: date,
|
||||
priority: brand.priority,
|
||||
name_en: brand.name_en,
|
||||
name_tw: brand.name_tw,
|
||||
contributor: brand.contributor
|
||||
});
|
||||
newBrand.save(function(error, createdBrand) {
|
||||
if(error) {
|
||||
logger.error('failed to create brand : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdBrand);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Brand.findBrandByConditions = function(conditions, callback) {
|
||||
Brand.find(conditions)
|
||||
.run(function (error, brands) {
|
||||
if (error) {
|
||||
logger.error("find brand error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, brands);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Brand.listBrands = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.gt(from);
|
||||
Brand.find(conditions).limit(parseInt(count)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listBrandsErr, brands) {
|
||||
if (listBrandsErr) {
|
||||
logger.error("list brands error : " + listBrandsErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, brands);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Brand.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listBrandsErr, brands) {
|
||||
if (listBrandsErr) {
|
||||
logger.error("list brands error : " + listBrandsErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, brands);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Brand.countBrands = function(conditions, callback) {
|
||||
Brand.count(conditions, function(countBrandsErr, brandsCount) {
|
||||
if (countBrandsErr) {
|
||||
logger.error("count brands error : " + countBrandsErr);
|
||||
callback(errorCode.FAILED, 0);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, brandsCount);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Brand.getBrandByID = function(brandID, callback) {
|
||||
Brand.get(brandID, function(error, brand) {
|
||||
if (error) {
|
||||
logger.error("get brand by ID error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, brand);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Brand.updateBrandByID = function(brandID, newBrand, callback) {
|
||||
Brand.get(brandID, function(error, brand) {
|
||||
if (error) {
|
||||
logger.error("get brand by ID error in update brand : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
brand.name = newBrand.name;
|
||||
brand.category_id = newBrand.category_id;
|
||||
brand.category_name = newBrand.category_name;
|
||||
brand.status = newBrand.status;
|
||||
brand.update_time = newBrand.update_time;
|
||||
brand.priority = newBrand.priority;
|
||||
brand.name_en = newBrand.name_en;
|
||||
brand.name_tw = newBrand.name_tw;
|
||||
brand.contributor = newBrand.contributor;
|
||||
brand.save(function(error, createdBrand) {
|
||||
if(error) {
|
||||
logger.error('failed to create brand in update brand : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdBrand);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Brand;
|
||||
137
console/model/category_dao.js
Normal file
137
console/model/category_dao.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var Category = dbOrm.define('category',
|
||||
{
|
||||
id: Number,
|
||||
name: String,
|
||||
status: Number,
|
||||
update_time: String,
|
||||
name_en: String,
|
||||
name_tw: String,
|
||||
contributor: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
Category.createCategory = function(category, callback) {
|
||||
var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
var newCategory = new Category({
|
||||
name: category.name,
|
||||
status: 1,
|
||||
update_time: date,
|
||||
name_en: category.name_en,
|
||||
name_tw: category.name_tw,
|
||||
contributor: category.contributor
|
||||
});
|
||||
newCategory.save(function (error, createdCategory) {
|
||||
if (error) {
|
||||
logger.error('failed to create category : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdCategory);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Category.findCategoryByConditions = function(conditions, callback) {
|
||||
Category.find(conditions)
|
||||
.run(function (error, categories) {
|
||||
if (error) {
|
||||
logger.error("find category error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categories);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Category.listCategories = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.gt(from);
|
||||
Category.find(conditions).limit(parseInt(count)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listCategoriesErr, categories) {
|
||||
if (listCategoriesErr) {
|
||||
logger.error("list categories error : " + listCategoriesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categories);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Category.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listCategoriesErr, categories) {
|
||||
if (listCategoriesErr) {
|
||||
logger.error("list categories error : " + listCategoriesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categories);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Category.countCategories = function(conditions, callback) {
|
||||
Category.count(conditions, function(countCategoriesErr, categoriesCount) {
|
||||
if (countCategoriesErr) {
|
||||
logger.error("count categories error : " + countCategoriesErr);
|
||||
callback(errorCode.FAILED, 0);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categoriesCount);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Category.getCategoryByID = function(categoryID, callback) {
|
||||
Category.get(categoryID, function(error, category) {
|
||||
if (error) {
|
||||
logger.error("get category by ID error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, category);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* For internal use only */
|
||||
Category.listRemoteCategories = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.gt(from);
|
||||
Category.find(conditions).limit(parseInt(count)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listCategoriesErr, categories) {
|
||||
if (listCategoriesErr) {
|
||||
logger.error("list categories error : " + listCategoriesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categories);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Category.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listCategoriesErr, categories) {
|
||||
if (listCategoriesErr) {
|
||||
logger.error("list categories error : " + listCategoriesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, categories);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Category;
|
||||
95
console/model/city_dao.js
Normal file
95
console/model/city_dao.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var City = dbOrm.define('city',
|
||||
{
|
||||
id: Number,
|
||||
code: String,
|
||||
name: String,
|
||||
longitude: Number,
|
||||
latitude: Number,
|
||||
name_tw: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
City.listProvinces = function(callback) {
|
||||
var error = errorCode.SUCCESS;
|
||||
dbOrm.driver.execQuery("SELECT * FROM city WHERE code LIKE '__0000'", function(getProvincesErr, result) {
|
||||
if (getProvincesErr) {
|
||||
logger.info("get provinces failed : " + getProvincesErr);
|
||||
error = errorCode.FAILED;
|
||||
callback(error,null);
|
||||
} else {
|
||||
callback(error, result);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
City.listCities = function(provincePrefix, callback) {
|
||||
var error = errorCode.SUCCESS;
|
||||
// dbOrm is object of ORM
|
||||
dbOrm.driver.execQuery("SELECT * FROM city WHERE code LIKE '" + provincePrefix + "__00' AND code NOT LIKE '__0000'", function(getCitiesErr, result) {
|
||||
if (getCitiesErr) {
|
||||
logger.info("get cities failed : " + getCitiesErr);
|
||||
error = errorCode.FAILED;
|
||||
callback(error,null);
|
||||
} else {
|
||||
callback(error, result);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
City.countCities = function(conditions, callback) {
|
||||
dbOrm.driver.execQuery("SELECT COUNT(id) AS number FROM city WHERE " + conditions,
|
||||
function (countCitiesErr, result) {
|
||||
if (countCitiesErr) {
|
||||
logger.info("count cities failed : " + countCitiesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, result);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
City.findCitiesByConditions = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.lt(from);
|
||||
City.find(conditions).limit(parseInt(count)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (error, cities) {
|
||||
if (error) {
|
||||
logger.error("find city error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, cities);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
City.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (error, cities) {
|
||||
if (error) {
|
||||
logger.error("find city error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, cities);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
module.exports = City;
|
||||
126
console/model/ir_protocol_dao.js
Normal file
126
console/model/ir_protocol_dao.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var Enums = require('../constants/enums');
|
||||
var enums = new Enums();
|
||||
|
||||
var IRProtocol = dbOrm.define('ir_protocol',
|
||||
{
|
||||
id: Number,
|
||||
name: String,
|
||||
type: Number,
|
||||
status: Number,
|
||||
update_time: String,
|
||||
contributor: String,
|
||||
boot_code: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
IRProtocol.createIRProtocol = function(protocol, callback) {
|
||||
var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
var newProtocol = new IRProtocol({
|
||||
name: protocol.name,
|
||||
status: protocol.status,
|
||||
type: protocol.type,
|
||||
update_time: date,
|
||||
contributor: protocol.contributor,
|
||||
boot_code: protocol.boot_code
|
||||
});
|
||||
newProtocol.save(function(error, createdProtocol) {
|
||||
if(error) {
|
||||
logger.error('failed to create protocol : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdProtocol);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
IRProtocol.updateProtocolByID = function(protocolID, newProtocol, callback) {
|
||||
IRProtocol.get(protocolID, function(error, protocol) {
|
||||
if (error) {
|
||||
logger.error("get protocol by ID error in update protocol : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
protocol.name = newProtocol.name;
|
||||
protocol.type = newProtocol.type;
|
||||
protocol.status = newProtocol.status;
|
||||
protocol.update_time = newProtocol.update_time;
|
||||
protocol.boot_code = null;
|
||||
protocol.contributor = newProtocol.contributor;
|
||||
protocol.save(function(error, createdProtocol) {
|
||||
if(error) {
|
||||
logger.error('failed to create protocol in update protocol : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdProtocol);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
IRProtocol.findIRProtocolByConditions = function(conditions, callback) {
|
||||
IRProtocol.find(conditions)
|
||||
.run(function (error, protocols) {
|
||||
if (error) {
|
||||
logger.error("find protocol error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, protocols);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
IRProtocol.listIRProtocols = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.gt(from);
|
||||
IRProtocol.find(conditions).limit(parseInt(count)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listProtocolsErr, protocols) {
|
||||
if (listProtocolsErr) {
|
||||
logger.error("list protocols error : " + listProtocolsErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, protocols);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
IRProtocol.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listProtocolsErr, protocols) {
|
||||
if (listProtocolsErr) {
|
||||
logger.error("list protocols error : " + listProtocolsErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, protocols);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
IRProtocol.getIRProtocolByID = function(protocolID, callback) {
|
||||
IRProtocol.get(protocolID, function(error, protocol) {
|
||||
if (error) {
|
||||
logger.error("get protocol by ID error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, protocol);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = IRProtocol;
|
||||
281
console/model/remote_index_dao.js
Normal file
281
console/model/remote_index_dao.js
Normal file
@@ -0,0 +1,281 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var Enums = require('../constants/enums');
|
||||
|
||||
var errorCode = new ErrorCode();
|
||||
var enums = new Enums();
|
||||
|
||||
var RemoteIndex = dbOrm.define('remote_index',
|
||||
{
|
||||
id: Number,
|
||||
category_id: Number,
|
||||
category_name: String,
|
||||
brand_id: Number,
|
||||
brand_name: String,
|
||||
city_code: String,
|
||||
city_name: String,
|
||||
operator_id: String,
|
||||
operator_name: String,
|
||||
protocol: String,
|
||||
remote: String,
|
||||
remote_map: String,
|
||||
status: Number,
|
||||
sub_cate: Number,
|
||||
priority: Number,
|
||||
remote_number: String,
|
||||
operator_name_tw: String,
|
||||
category_name_tw: String,
|
||||
brand_name_tw: String,
|
||||
city_name_tw: String,
|
||||
binary_md5: String,
|
||||
contributor: String,
|
||||
update_time: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
RemoteIndex.createRemoteIndex = function(remoteIndex, callback) {
|
||||
var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
var newRemoteIndex = new RemoteIndex({
|
||||
name: remoteIndex.name,
|
||||
category_id: remoteIndex.category_id,
|
||||
category_name: remoteIndex.category_name,
|
||||
brand_id: remoteIndex.brand_id,
|
||||
brand_name: remoteIndex.brand_name,
|
||||
city_code: remoteIndex.city_code,
|
||||
city_name: remoteIndex.city_name,
|
||||
operator_id: remoteIndex.operator_id,
|
||||
operator_name: remoteIndex.operator_name,
|
||||
// TODO: To form remoteMap sequence according to category and brand selected
|
||||
protocol: remoteIndex.protocol,
|
||||
remote: remoteIndex.remote,
|
||||
remote_map: remoteIndex.remote_map,
|
||||
priority: remoteIndex.priority,
|
||||
status: enums.ITEM_VERIFY,
|
||||
sub_cate: remoteIndex.sub_cate,
|
||||
remote_number: remoteIndex.remote_number,
|
||||
operator_name_tw: remoteIndex.operator_name_tw,
|
||||
category_name_tw: remoteIndex.category_name_tw,
|
||||
brand_name_tw: remoteIndex.brand_name_tw,
|
||||
city_name_tw: remoteIndex.city_name_tw,
|
||||
binary_md5: remoteIndex.binary_md5,
|
||||
contributor: remoteIndex.contributor,
|
||||
update_time: date
|
||||
});
|
||||
newRemoteIndex.save(function(error, createdRemoteIndex) {
|
||||
if(error) {
|
||||
logger.error('failed to create remoteIndex : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdRemoteIndex);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.deleteRemoteIndex = function(remoteIndexID, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function (err, remoteIndex) {
|
||||
if (null != remoteIndex) {
|
||||
remoteIndex.remove(function (err) {
|
||||
if(err) {
|
||||
logger.error('failed to remove remote index ' + remoteIndexID);
|
||||
callback(errorCode.FAILED);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error('remove remote index successfully ' + remoteIndexID);
|
||||
callback(errorCode.SUCCESS);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.findRemoteIndexByCondition = function(conditions, callback) {
|
||||
RemoteIndex.find(conditions)
|
||||
.run(function (error, remoteIndexes) {
|
||||
if (error) {
|
||||
logger.error("find remoteIndex error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remoteIndexes);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.listRemoteIndexes = function(conditions, from, count, sortField, callback) {
|
||||
if("id" == sortField && 0 != from) {
|
||||
conditions.id = orm.lt(from);
|
||||
RemoteIndex.find(conditions).limit(parseInt(count)).orderRaw("?? DESC", [sortField])
|
||||
.run(function (listRemoteIndexesErr, remoteIndexes) {
|
||||
if (listRemoteIndexesErr) {
|
||||
logger.error("list remoteIndexes error : " + listRemoteIndexesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remoteIndexes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
RemoteIndex.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listRemoteIndexesErr, remoteIndexes) {
|
||||
if (listRemoteIndexesErr) {
|
||||
logger.error("list remoteIndexes error : " + listRemoteIndexesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remoteIndexes);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
RemoteIndex.countRemoteIndexes = function(conditions, callback) {
|
||||
RemoteIndex.count(conditions, function(countRemoteIndexesErr, remoteIndexesCount) {
|
||||
if (countRemoteIndexesErr) {
|
||||
logger.error("count remoteIndexes error : " + countRemoteIndexesErr);
|
||||
callback(errorCode.FAILED, 0);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remoteIndexesCount);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.getRemoteIndexByID = function(remoteIndexID, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function(error, remoteIndex) {
|
||||
if (error) {
|
||||
logger.error("get remoteIndex by ID error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remoteIndex);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.updateRemoteIndex = function(remoteIndexID, newRemoteIndex, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function(error, remoteIndex) {
|
||||
if (error) {
|
||||
logger.error("get remoteIndex by ID error in update remote index : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
logger.info("get remoteIndex by ID successfully in update remote index");
|
||||
/*
|
||||
remoteIndex.name = newRemoteIndex.name;
|
||||
remoteIndex.category_id = newRemoteIndex.category_id;
|
||||
remoteIndex.category_name = newRemoteIndex.category_name;
|
||||
remoteIndex.brand_id = newRemoteIndex.brand_id;
|
||||
remoteIndex.brand_name = newRemoteIndex.brand_name;
|
||||
remoteIndex.city_code = newRemoteIndex.city_code;
|
||||
remoteIndex.city_name = newRemoteIndex.city_name;
|
||||
remoteIndex.operator_id = newRemoteIndex.operator_id;
|
||||
remoteIndex.operator_name = newRemoteIndex.operator_name;
|
||||
remoteIndex.protocol = newRemoteIndex.protocol;
|
||||
remoteIndex.remote = newRemoteIndex.remote;
|
||||
remoteIndex.remote_map = newRemoteIndex.remote_map;
|
||||
remoteIndex.priority = newRemoteIndex.priority;
|
||||
remoteIndex.status = enums.ITEM_VERIFY;
|
||||
remoteIndex.sub_cate = newRemoteIndex.sub_cate;
|
||||
remoteIndex.remote_number = newRemoteIndex.remote_number;
|
||||
remoteIndex.operator_name_tw = newRemoteIndex.operator_name_tw;
|
||||
remoteIndex.category_name_tw = newRemoteIndex.category_name_tw;
|
||||
remoteIndex.brand_name_tw = newRemoteIndex.brand_name_tw;
|
||||
remoteIndex.city_name_tw = newRemoteIndex.city_name_tw;
|
||||
remoteIndex.binary_md5 = newRemoteIndex.binary_md5;
|
||||
remoteIndex.contributor = newRemoteIndex.contributor;
|
||||
remoteIndex.update_time = date;
|
||||
*/
|
||||
|
||||
for (var prop in remoteIndex) {
|
||||
if (undefined != newRemoteIndex[prop] && null != newRemoteIndex[prop]) {
|
||||
remoteIndex[prop] = newRemoteIndex[prop];
|
||||
}
|
||||
}
|
||||
remoteIndex.update_time = data;
|
||||
|
||||
remoteIndex.save(function(error, updatedRemoteIndex) {
|
||||
if(error) {
|
||||
logger.error('failed to update remoteIndex : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, updatedRemoteIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.verifyRemoteIndex = function(remoteIndexID, status, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function(error, remoteIndex) {
|
||||
if (error) {
|
||||
logger.error("get remoteIndex by ID error in verify remote index : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("get remoteIndex by ID successfully in verify remote index");
|
||||
remoteIndex.status = status;
|
||||
|
||||
remoteIndex.save(function(error, updatedRemoteIndex) {
|
||||
if(error) {
|
||||
logger.error('failed to verify remoteIndex : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, updatedRemoteIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.fallbackRemoteIndex = function(remoteIndexID, status, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function(error, remoteIndex) {
|
||||
if (error) {
|
||||
logger.error("get remoteIndex by ID error in fallback remote index : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("get remoteIndex by ID successfully in fallback remote index");
|
||||
remoteIndex.status = status;
|
||||
|
||||
remoteIndex.save(function(error, updatedRemoteIndex) {
|
||||
if(error) {
|
||||
logger.error('failed to fallback remoteIndex : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, updatedRemoteIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RemoteIndex.publishRemoteIndex = function(remoteIndexID, status, callback) {
|
||||
RemoteIndex.get(remoteIndexID, function(error, remoteIndex) {
|
||||
if (error) {
|
||||
logger.error("get remoteIndex by ID error in verify remote index : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("get remoteIndex by ID successfully in publish remote index");
|
||||
remoteIndex.status = status;
|
||||
|
||||
remoteIndex.save(function(error, updatedRemoteIndex) {
|
||||
if(error) {
|
||||
logger.error('failed to publish remoteIndex : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, updatedRemoteIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = RemoteIndex;
|
||||
66
console/model/stb_operator_dao.js
Normal file
66
console/model/stb_operator_dao.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var orm = require('orm');
|
||||
var dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var StbOperator = dbOrm.define('stb_operator',
|
||||
{
|
||||
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;
|
||||
52
console/model/virtual_remote_dao.js
Normal file
52
console/model/virtual_remote_dao.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
var kvConn = require('../mini_poem/db/mongodb/mongodb_connection');
|
||||
var logger = require('../mini_poem/logging/logger4js').helper;
|
||||
var Map = require('../mini_poem/mem/map');
|
||||
|
||||
// local inclusion
|
||||
var ErrorCode = require('../constants/error_code');
|
||||
var errorCode = new ErrorCode();
|
||||
|
||||
var VirtualRemote = function() {
|
||||
};
|
||||
|
||||
var remoteMap = new Map();
|
||||
|
||||
VirtualRemote.prototype.findRemoteByKey = function(protocol, remote, remoteKey, code, callback) {
|
||||
// traverse all collections per remote
|
||||
var collectionName = remote + "_" + protocol;
|
||||
var vRemote = remoteMap.get(collectionName);
|
||||
if(null == vRemote) {
|
||||
try {
|
||||
vRemote = kvConn.defineByCollection(collectionName, {
|
||||
key_name: String,
|
||||
key_value: String,
|
||||
key_codes: String
|
||||
},
|
||||
collectionName);
|
||||
logger.info("this is a new remote collection, add it to remote map");
|
||||
remoteMap.set(collectionName, vRemote);
|
||||
} catch(e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
vRemote.findOne({
|
||||
$or:[ {key_name : remoteKey}, {key_name : remoteKey.toUpperCase()} ]
|
||||
}, function(findOneRemoteByKeyErr, remote) {
|
||||
if(findOneRemoteByKeyErr) {
|
||||
logger.error("find one remote by key error : " + findOneRemoteByKeyErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, remote);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = VirtualRemote;
|
||||
Reference in New Issue
Block a user