diff --git a/console/constants/enums.js b/console/constants/enums.js index 477edc8..4b39596 100644 --- a/console/constants/enums.js +++ b/console/constants/enums.js @@ -44,6 +44,13 @@ function Enums() { this.ADMIN_TYPE_IREXT = 1; this.ADMIN_TYPE_EXTERNAL = 2; + + this.COLLECT_REMOTE_STATUS_INIT = 0; + this.COLLECT_REMOTE_STATUS_GENERATED = 1; + this.COLLECT_REMOTE_STATUS_CONFIRMED = 2; + this.COLLECT_REMOTE_STATUS_UPLOADED = 3; + this.COLLECT_REMOTE_STATUS_PUBLISHED = 4; + this.COLLECT_REMOTE_STATUS_DUPLICATED = 5; } module.exports = Enums; \ No newline at end of file diff --git a/console/model/collect_remote_dao.js b/console/model/collect_remote_dao.js new file mode 100644 index 0000000..a05d2f4 --- /dev/null +++ b/console/model/collect_remote_dao.js @@ -0,0 +1,174 @@ +/** + * Created by strawmanbobi + * 2020-05-07 + */ + +// 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 Enums = require('../constants/enums'); + +var errorCode = new ErrorCode(); +var enums = new Enums(); + +var 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) { + var date = dateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss"); + var 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 (var 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; \ No newline at end of file diff --git a/console/web/code/js/manage.js b/console/web/code/js/manage.js index fb106fc..4253c3e 100644 --- a/console/web/code/js/manage.js +++ b/console/web/code/js/manage.js @@ -70,7 +70,6 @@ $(document).ready(function() { token = localStorage.getItem(LS_KEY_TOKEN); client = getParameter('client'); - // showMenu(id, token, 'remote'); initializeSelectors(); $('#remote_file').change(function() { @@ -192,38 +191,35 @@ function loadRemoteList(isSearch, remoteMap) { valign: 'middle', sortable: true, clickToSelect: true - }, { - field: 'contributor', - title: '贡献者', - align: 'left', - valign: 'middle', - sortable: true, - clickToSelect: true, - visible: false }] }).on('check.bs.table', function (e, row) { onSelectRemote(row); }).on('uncheck.bs.table', function (e, row) { selectedRemote = null; }).on('load-success.bs.table', function (e, data) { - var i = 0; + var i; for (i = 0; i < data.length; i++) { - if(data[i].status == '1') { - data[i].status = '已发布'; - } else if(data[i].status == '2') { - data[i].status = '待验证'; - } else if(data[i].status == '3') { - data[i].status = '通过'; - } else if(data[i].status == '4') { - data[i].status = '未通过'; - } else if(data[i].status == '5') { - data[i].status = '重复' + if (data[i].para === 0) { + if (data[i].status == '1') { + data[i].status = '已发布'; + } else if (data[i].status == '2') { + data[i].status = '待验证'; + } else if (data[i].status == '3') { + data[i].status = '通过'; + } else if (data[i].status == '4') { + data[i].status = '未通过'; + } else if (data[i].status == '5') { + data[i].status = '重复' + } + } else { + data[i].status = 'From IRIS'; } $('#remote_table').bootstrapTable('updateRow', { index: i, row: { - status: data[i].status + status: data[i].status, + para: data[i].para, } }); } @@ -233,30 +229,36 @@ function loadRemoteList(isSearch, remoteMap) { function rowStyle(row, index) { var style = null; - if (row.status == '已发布') { - style = { - classes: 'default' - }; - } else if (row.status == '待验证') { + if (row.para === 0) { + if (row.status == '已发布') { + style = { + classes: 'default' + }; + } else if (row.status == '待验证') { + style = { + classes: 'info' + }; + } else if (row.status == '通过') { + style = { + classes: 'success' + }; + } else if (row.status == '未通过') { + style = { + classes: 'danger' + }; + } else if (row.status == '重复') { + style = { + classes: 'warning' + }; + } else { + style = { + classes: '' + } + } + } else { style = { classes: 'info' }; - } else if (row.status == '通过') { - style = { - classes: 'success' - }; - } else if (row.status == '未通过') { - style = { - classes: 'danger' - }; - } else if (row.status == '重复') { - style = { - classes: 'warning' - }; - } else { - style = { - classes: '' - } } return style; } diff --git a/console/work_unit/code_manage_logic.js b/console/work_unit/code_manage_logic.js index 8512bfa..2c638d2 100644 --- a/console/work_unit/code_manage_logic.js +++ b/console/work_unit/code_manage_logic.js @@ -19,6 +19,7 @@ var IRProtocol = require('../model/ir_protocol_dao.js'); var City = require('../model/city_dao.js'); var RemoteIndex = require('../model/remote_index_dao.js'); var StbOperator = require('../model/stb_operator_dao.js'); +var CollectRemote = require('../model/collect_remote_dao.js'); var RequestSender = require('../mini_poem/http/request.js'); var Map = require('../mini_poem/mem/map.js'); @@ -95,8 +96,9 @@ exports.listOperatorsWorkUnit = function (cityCode, from, count, callback) { exports.listRemoteIndexesWorkUnit = function (categoryID, brandID, cityCode, operatorID, from, count, callback) { var conditions; + var listCollectRemotesConditions; - if (categoryID == enums.CATEGORY_STB) { + if (parseInt(categoryID) === enums.CATEGORY_STB) { if (null == operatorID) { conditions = { category_id: categoryID, @@ -111,33 +113,80 @@ exports.listRemoteIndexesWorkUnit = function (categoryID, brandID, cityCode, ope status: orm.gt(enums.ITEM_INVALID) }; } - - } else if (categoryID == enums.CATEGORY_AC || - categoryID == enums.CATEGORY_TV || - categoryID == enums.CATEGORY_NW || - categoryID == enums.CATEGORY_IPTV || - categoryID == enums.CATEGORY_DVD || - categoryID == enums.CATEGORY_FAN || - categoryID == enums.CATEGORY_PROJECTOR || - categoryID == enums.CATEGORY_STEREO || - categoryID == enums.CATEGORY_LIGHT_BULB || - categoryID == enums.CATEGORY_BSTB || - categoryID == enums.CATEGORY_CLEANING_ROBOT || - categoryID == enums.CATEGORY_AIR_CLEANER || - categoryID == enums.CATEGORY_DYSON) { + RemoteIndex.listRemoteIndexes(conditions, from, count, "priority", + function(listRemoteIndexesErr, remoteIndexes) { + for (var i = 0; i < remoteIndexes.length; i++) { + remoteIndexes[i].para = 0; + } + if (!operatorID) { + listCollectRemotesConditions = { + category_id: parseInt(categoryID), + city_code: cityCode, + status: parseInt(enums.COLLECT_REMOTE_STATUS_CONFIRMED) + }; + } else { + listCollectRemotesConditions = { + category_id: parseInt(categoryID), + city_code: cityCode, + operator_id: operatorID, + status: parseInt(enums.COLLECT_REMOTE_STATUS_CONFIRMED) + }; + } + CollectRemote.listCollectRemotes(listCollectRemotesConditions, + from, count, "update_time", function(listCollectRemotesErr, collectRemotes) { + if (null != collectRemotes && collectRemotes.length > 0) { + for (var i = 0; i < collectRemotes.length; i++) { + collectRemotes[i].para = 0; + } + } + remoteIndexes.push.apply(remoteIndexes, collectRemotes); + callback(listRemoteIndexesErr, remoteIndexes); + }); + }); + } else if (parseInt(categoryID) === enums.CATEGORY_AC || + parseInt(categoryID) === enums.CATEGORY_TV || + parseInt(categoryID) === enums.CATEGORY_NW || + parseInt(categoryID) === enums.CATEGORY_IPTV || + parseInt(categoryID) === enums.CATEGORY_DVD || + parseInt(categoryID) === enums.CATEGORY_FAN || + parseInt(categoryID) === enums.CATEGORY_PROJECTOR || + parseInt(categoryID) === enums.CATEGORY_STEREO || + parseInt(categoryID) === enums.CATEGORY_LIGHT_BULB || + parseInt(categoryID) === enums.CATEGORY_BSTB || + parseInt(categoryID) === enums.CATEGORY_CLEANING_ROBOT || + parseInt(categoryID) === enums.CATEGORY_AIR_CLEANER || + parseInt(categoryID) === enums.CATEGORY_DYSON) { conditions = { category_id: categoryID, brand_id: brandID, status: orm.gt(enums.ITEM_INVALID) }; + RemoteIndex.listRemoteIndexes(conditions, from, count, "priority", + function(listRemoteIndexesErr, remoteIndexes) { + for (var i = 0; i < remoteIndexes.length; i++) { + remoteIndexes[i].para = 0; + } + // append IRIS indexes + listCollectRemotesConditions = { + category_id: parseInt(categoryID), + brand_id: parseInt(brandID), + status: parseInt(enums.COLLECT_REMOTE_STATUS_CONFIRMED) + } + CollectRemote.listCollectRemotes(listCollectRemotesConditions, + from, count, "update_time", + function(listCollectRemotesErr, collectRemotes) { + if (null != collectRemotes && collectRemotes.length > 0) { + for (var i = 0; i < collectRemotes.length; i++) { + collectRemotes[i].para = 1; + } + } + remoteIndexes.push.apply(remoteIndexes, collectRemotes); + callback(listRemoteIndexesErr, remoteIndexes); + }); + }); } else { callback(errorCode.INVALID_CATEGORY, null); - return; } - - RemoteIndex.listRemoteIndexes(conditions, from, count, "priority", function(listRemoteIndexesErr, remoteIndexes) { - callback(listRemoteIndexesErr, remoteIndexes); - }); }; exports.searchRemoteIndexesWorkUnit = function (remoteMap, from, count, callback) {