updated console and server repo name
This commit is contained in:
146
private-console/model/brand_dao.js
Normal file
146
private-console/model/brand_dao.js
Normal file
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
let dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let Enums = require('../constants/enums');
|
||||
|
||||
let errorCode = new ErrorCode();
|
||||
let enums = new Enums();
|
||||
|
||||
let 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) {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
let 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
private-console/model/category_dao.js
Normal file
137
private-console/model/category_dao.js
Normal file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
let dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let errorCode = new ErrorCode();
|
||||
|
||||
let 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) {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
let 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
private-console/model/city_dao.js
Normal file
95
private-console/model/city_dao.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let errorCode = new ErrorCode();
|
||||
|
||||
let City = dbOrm.define('city',
|
||||
{
|
||||
id: Number,
|
||||
code: String,
|
||||
name: String,
|
||||
longitude: Number,
|
||||
latitude: Number,
|
||||
name_tw: String
|
||||
},
|
||||
{
|
||||
cache: false
|
||||
}
|
||||
);
|
||||
|
||||
City.listProvinces = function(callback) {
|
||||
let 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) {
|
||||
let 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;
|
||||
174
private-console/model/collect_remote_dao.js
Normal file
174
private-console/model/collect_remote_dao.js
Normal file
@@ -0,0 +1,174 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2020-05-07
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let Enums = require('../constants/enums');
|
||||
|
||||
let errorCode = new ErrorCode();
|
||||
let enums = new Enums();
|
||||
|
||||
let CollectRemote = dbOrm.define('collect_remote',
|
||||
{
|
||||
id: Number,
|
||||
name: String,
|
||||
category_id: Number,
|
||||
category_name: String,
|
||||
brand_id: Number,
|
||||
brand_name: String,
|
||||
city_code: String,
|
||||
city_name: String,
|
||||
operator_id: Number,
|
||||
operator_name: String,
|
||||
protocol: String,
|
||||
remote: String,
|
||||
remote_map: String,
|
||||
status: Number,
|
||||
update_time: String,
|
||||
contributor: String,
|
||||
},
|
||||
{
|
||||
cache: true
|
||||
}
|
||||
);
|
||||
|
||||
CollectRemote.createCollectRemote = function(collectRemote, callback) {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
let newCollectRemote = new CollectRemote({
|
||||
name: collectRemote.name,
|
||||
category_id: collectRemote.category_id,
|
||||
category_name: collectRemote.category_name,
|
||||
brand_id: collectRemote.brand_id,
|
||||
brand_name: collectRemote.brand_name,
|
||||
city_code: collectRemote.city_code,
|
||||
city_name: collectRemote.city_name,
|
||||
operator_id: collectRemote.operator_id,
|
||||
operator_name: collectRemote.operator_name,
|
||||
protocol: collectRemote.protocol,
|
||||
remote: collectRemote.remote,
|
||||
remote_map: collectRemote.remote_map,
|
||||
status: enums.COLLECT_REMOTE_STATUS_INIT,
|
||||
update_time: date,
|
||||
contributor: collectRemote.contributor,
|
||||
});
|
||||
newCollectRemote.save(function(error, createdCollectRemote) {
|
||||
if(error) {
|
||||
logger.error('failed to create collectRemote : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, createdCollectRemote);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CollectRemote.deleteCollectRemote = function(collectRemoteID, callback) {
|
||||
CollectRemote.get(collectRemoteID, function (err, collectRemote) {
|
||||
if (null !== collectRemote) {
|
||||
collectRemote.remove(function (err) {
|
||||
if(err) {
|
||||
logger.error('failed to remove collectRemote ' + collectRemoteID);
|
||||
callback(errorCode.FAILED);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
logger.error('remove collectRemote successfully ' + collectRemoteID);
|
||||
callback(errorCode.SUCCESS);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CollectRemote.findCollectRemotesByCondition = function(conditions, callback) {
|
||||
CollectRemote.find(conditions)
|
||||
.run(function (error, collectRemotes) {
|
||||
if (error) {
|
||||
logger.error("find collectRemote error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, collectRemotes);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CollectRemote.listCollectRemotes = function(conditions, from, count, sortField, callback) {
|
||||
if("id" === sortField && 0 !== from) {
|
||||
conditions.id = orm.lt(from);
|
||||
CollectRemote.find(conditions).limit(parseInt(count)).orderRaw("?? DESC", [sortField])
|
||||
.run(function (listCollectRemotesErr, collectRemotes) {
|
||||
if (listCollectRemotesErr) {
|
||||
logger.error("list collectRemotes error : " + listCollectRemotesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, collectRemotes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
CollectRemote.find(conditions).limit(parseInt(count)).offset(parseInt(from)).orderRaw("?? ASC", [sortField])
|
||||
.run(function (listCollectRemotesErr, collectRemotes) {
|
||||
if (listCollectRemotesErr) {
|
||||
logger.error("list remoteIndexes error : " + listCollectRemotesErr);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, collectRemotes);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
CollectRemote.countCollectRemotes = function(conditions, callback) {
|
||||
CollectRemote.count(conditions, function(countCollectRemotesErr, collectRemotesCount) {
|
||||
if (countCollectRemotesErr) {
|
||||
logger.error("count collectRemotes error : " + countCollectRemotesErr);
|
||||
callback(errorCode.FAILED, 0);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, collectRemotesCount);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CollectRemote.getCollectRemoteByID = function(collectRemoteID, callback) {
|
||||
CollectRemote.get(collectRemoteID, function(error, collectRemote) {
|
||||
if (error) {
|
||||
logger.error("get collectRemote by ID error : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, collectRemote);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
CollectRemote.updateCollectRemote = function(collectRemoteID, newCollectRemote, callback) {
|
||||
CollectRemote.get(collectRemoteID, function(error, collectRemote) {
|
||||
if (error) {
|
||||
logger.error("get collectRemote by ID error in update collectRemote : " + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
logger.info("get collectRemote by ID successfully in update collectRemote");
|
||||
|
||||
for (let prop in collectRemote) {
|
||||
if (undefined !== newCollectRemote[prop] && null !== newCollectRemote[prop]) {
|
||||
collectRemote[prop] = newCollectRemote[prop];
|
||||
}
|
||||
}
|
||||
|
||||
collectRemote.save(function(error, updatedCollectRemote) {
|
||||
if(error) {
|
||||
logger.error('failed to update collectRemote : ' + error);
|
||||
callback(errorCode.FAILED, null);
|
||||
} else {
|
||||
callback(errorCode.SUCCESS, updatedCollectRemote);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = CollectRemote;
|
||||
126
private-console/model/ir_protocol_dao.js
Normal file
126
private-console/model/ir_protocol_dao.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
let dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let errorCode = new ErrorCode();
|
||||
|
||||
let Enums = require('../constants/enums');
|
||||
let enums = new Enums();
|
||||
|
||||
let 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) {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
let 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;
|
||||
252
private-console/model/remote_index_dao.js
Normal file
252
private-console/model/remote_index_dao.js
Normal file
@@ -0,0 +1,252 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
let dateUtils = require('../mini_poem/utils/date_utils.js');
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let Enums = require('../constants/enums');
|
||||
|
||||
let errorCode = new ErrorCode();
|
||||
let enums = new Enums();
|
||||
|
||||
let 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) {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
let 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 {
|
||||
let date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss");
|
||||
for (let prop in remoteIndex) {
|
||||
if (undefined != newRemoteIndex[prop] && null != newRemoteIndex[prop]) {
|
||||
remoteIndex[prop] = newRemoteIndex[prop];
|
||||
}
|
||||
}
|
||||
remoteIndex.update_time = date;
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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
private-console/model/stb_operator_dao.js
Normal file
66
private-console/model/stb_operator_dao.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let orm = require('orm');
|
||||
let dbOrm = require('../mini_poem/db/mysql/mysql_connection').mysqlDB;
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let errorCode = new ErrorCode();
|
||||
|
||||
let 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
private-console/model/virtual_remote_dao.js
Normal file
52
private-console/model/virtual_remote_dao.js
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Created by strawmanbobi
|
||||
* 2016-11-27
|
||||
*/
|
||||
|
||||
// global inclusion
|
||||
let kvConn = require('../mini_poem/db/mongodb/mongodb_connection');
|
||||
let logger = require('../mini_poem/logging/logger4js').helper;
|
||||
let Map = require('../mini_poem/mem/map');
|
||||
|
||||
// local inclusion
|
||||
let ErrorCode = require('../constants/error_code');
|
||||
let errorCode = new ErrorCode();
|
||||
|
||||
let VirtualRemote = function() {
|
||||
};
|
||||
|
||||
let remoteMap = new Map();
|
||||
|
||||
VirtualRemote.prototype.findRemoteByKey = function(protocol, remote, remoteKey, code, callback) {
|
||||
// traverse all collections per remote
|
||||
let collectionName = remote + "_" + protocol;
|
||||
let 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