app.controller('devManageCtrl', ['$scope', '$filter', '$http', '$state', '$stateParams', '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'QRCodeOptions', 'FileUploader', function ($scope, $filter, $http, $state, $stateParams, $timeout, uiGridConstants, i18nService, toaster, QRCodeOptions, FileUploader) { i18nService.setCurrentLang("zh-cn"); moment.locale('zh-cn'); var managerId = $stateParams.managerId; var agentId = $stateParams.agentId; var dealerId = $stateParams.dealerId; var searchKey = $stateParams.searchKey || ""; $scope.gridOptions = { data: 'myData', showGridFooter: true, //是否显示grid footer // rowHeight: 80, //-------- 分页属性 ---------------- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项 paginationCurrentPage: 1, //当前页码 paginationPageSize: 10, //每页显示个数 totalItems: 0,// 总数量 useExternalPagination: true,//是否使用分页按钮 //过滤 // enableFiltering: true, columnDefs: [], //---------------api--------------------- onRegisterApi: function (gridApi) { $scope.gridApi = gridApi; gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) { if ($scope.setPagingData) { $scope.getPagedDataAsync(newPage, pageSize, true);//翻页是强制刷新 } }); } }; //查询条件 var condition = $scope.condition = { registered: {value: true, label: "已注册"}, online: {value: "", label: "-选择在线状态-"}, logicalCode: '', searchKey: searchKey, fileContent: '' }; //枚举常量 $scope.enum = {}; $scope.enum.registered = [ {value: "", label: "-选择注册状态-"}, {value: true, label: "已注册"}, {value: false, label: "未注册"} ]; $scope.enum.online = [ {value: "", label: "-选择在线状态-"}, {value: 0, label: "离线设备"}, {value: 1, label: "在线设备"}, ]; //事件 $scope.event = { statusChange: function (key, item) { condition[key].value = item.value; condition[key].label = item.label; this.search() }, search: function () { // 就在当前 厂商|代理商|经销商的域下进行搜索 if (condition.searchKey === "") { $.confirm({ content: '条件为空,数据量较大,确定继续?', buttons: { ok: { text: '搜索', action: function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize, true); } }, } }); } else { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }, searchByLogicalCode: function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize); } }; $scope.batchQuery = function () { $(".devManageMain #batchQueryForm").modal(); $scope.dialogData = {} } $scope.batchQueryOk = function () { $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize, true); }; $scope.changeFile = function (files) { if (files.length) { var file = files[0]; var reader = new FileReader(); // 文件不能大于1M if (file.size > 1000 * 1024) { toaster.pop("info", "提示", "文件太大,请重新选择"); } else { reader.onload = function () { if (reader.result) { var text = reader.result $scope.condition.fileContent = text $scope.dialogData.fileName = file.name $scope.$apply(); } }; reader.readAsText(file); } } } function getLogicalList(logicalCodeList) { var needList = logicalCodeList.split("\n") for (var i = needList.length - 1; i >= 0; i--) { var item = needList[i]; needList[i] = $.trim(item); if (needList[i] === '') { needList.splice(i, 1) } } needList = needList.filter(function (item, i, self) { var flag = self.indexOf(item) === i return flag; }) return needList } // 查询条件缓存,用于导出报表用 $scope.queryCache = {} // 导出查询设备的报表 $scope.exportDevice = function () { if ($.isEmptyObject($scope.queryCache)) { toaster.pop("info", "提示", "请先根据条件查询一次数据"); return } $http({ method: 'POST', url: '/superadmin/exportDevice', data: $scope.queryCache }).then(function (response) { toaster.pop("success", "提示", "操作成功,请到结果页面下载报表"); $state.go('app.tool.offlineTask', { searchKey: response.data.payload }); }, function (response) { toaster.pop("error", "提示", "保存失败!"); }); } $scope.modelEvent = { //根据条件搜索粉丝详情 searchDetail: function () { //重新加载 折线图 loadChartData(); }, startTimeOpen: false, endTimeOpen: false, timeChange: function (passDay) { $scope.modelEvent.startTimeOpen = false; $scope.modelEvent.endTimeOpen = false; }, quickTime: function (evt, passDay) { $scope.chartCondition.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD"); $scope.chartCondition.endTime = moment().format("YYYY-MM-DD"); }, }; $scope.powerModelEvent = { //根据条件搜索粉丝详情 searchDetail: function () { //重新加载 折线图 loadPowerChartData(); }, startTimeOpen: false, endTimeOpen: false, timeChange: function (passDay) { $scope.powerModelEvent.startTimeOpen = false; $scope.powerModelEvent.endTimeOpen = false; }, quickTime: function (evt, passDay) { $scope.powerChartCondition.startTime = moment().add(-(passDay - 1), "day").format("YYYY-MM-DD"); $scope.powerChartCondition.endTime = moment().format("YYYY-MM-DD"); }, }; function setColumnDefs() { $scope.gridOptions.columnDefs = [ { field: 'oper', displayName: '查看', width: 230, enableFiltering: false, enableSorting: false, enableHiding: false,//禁止在列选择器中隐藏 enableColumnMenu: false,// 是否显示列头部菜单按钮 cellTemplate: '
' + '' + '' + '' + '
' }, { field: 'logicalCode', displayName: '逻辑编号', width: 80, cellTemplate: '
{{row.entity.logicalCode}}
' }, { field: 'devNo', displayName: '设备编号', cellTemplate: '
{{row.entity.devNo}}
' }, { field: 'devTypeCode', displayName: '设备Code', cellTemplate: '
{{row.entity.devType.code}}
' }, { field: 'simStatus', displayName: 'sim卡状态', }, { field: 'owner', displayName: '经销商', width: 140, cellTemplate: '
{{row.entity.dealer.nickname + " " + row.entity.dealer.username}}
' }, { field: 'softVer', displayName: '软件版本', width: 60 }, { field: 'hwVer', displayName: '硬件版本', width: 60 }, { field: 'coreVer', displayName: '核心版本', width: 60, }, { field: 'driverCode', displayName: '驱动编码', width: 60, }, { field: 'online', displayName: '在线状态', width: 80, cellTemplate: '
' }, { field: 'lastOffTime', displayName: '最近离线时间', cellTemplate: '
', width: 140 }, { field: 'registered', displayName: '注册状态', width: 80, cellTemplate: '
{{row.entity.registered==false?"未注册":"已注册"}}
' }, { field: 'createdTime', displayName: '注册时间', width: 140, }, { field: 'iccid', displayName: 'ICCID', width: 120, cellTemplate: '
{{row.entity.iccid}}
' }, { field: 'simExpireDate', displayName: '过期时间', width: 140, }, { field: 'server', displayName: '服务器', width: 140, }, { field: 'oper', displayName: '操作', enableFiltering: false, enableSorting: false, enableHiding: false,//禁止在列选择器中隐藏 enableColumnMenu: false,// 是否显示列头部菜单按钮 width: 480, cellTemplate: '
' + '' + '' + '' + '' + '' + '' + '
' }, ]; var fields = $scope.gridOptions.columnDefs; for (var index in fields) { var item = fields[index]; if (item && item['minWidth'] == null) { item['minWidth'] = 100; } } } $scope.setPagingData = function (data) { var pagedData = data.data.dataList; $scope.myData = pagedData; $scope.gridOptions.totalItems = data.data.total; }; $scope.getPagedDataAsync = function (curPage, pageSize, force) { if ($scope.gridOptionsLoading) { return; } var params = { pageSize: pageSize, pageIndex: curPage, }; if (condition.registered.value !== '') { params.registered = condition.registered.value } if (condition.online.value !== '') { params.online = condition.online.value } if (condition.logicalCode !== "") { params.logicalCode = condition.logicalCode } if (condition.searchKey !== "") { params.searchKey = condition.searchKey } if (dealerId) { params.dealerId = dealerId; } if (agentId) { params.agentId = agentId; } if (managerId) { params.managerId = managerId; } // 如果没有条件,则不查询,因为数据量太大,加载太卡! if (force) { // nothing } else if (!params.dealerId && !params.agentId && !params.managerId && !params.logicalCode && !params.searchKey) { toaster.pop("info", "温馨提示", "请输入查询条件进行查询"); return } // 批量查询时候的条件 var logicalCodeList = getLogicalList($scope.condition.fileContent) if (logicalCodeList.length > 0) { params.logicalCodeList = logicalCodeList } $scope.queryCache = params; $scope.gridOptionsLoading = true; $http.get('/superadmin/getDeviceDetailList', { params: params }).then(function (data) { data = data.data $scope.gridOptionsLoading = false; $scope.setPagingData(data, curPage, pageSize); }).catch(function (data) { toaster.pop("error", "提示", "获取数据列表失败"); }); }; function initDataGrid(force) { //首次加载表格 $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize, force); } setColumnDefs(); initDataGrid(); $scope.getQRCode = function (entity) { $(".devManageMain #devQRCodePanel").modal(); var currentDomain = location.protocol + "//" + location.host; var dataURL = QRCodeOptions.getQRCodeImageData({ text: currentDomain + "/userLogin?l=" + entity.logicalCode, label: entity.logicalCode, // logoDom: $("#qrcodeOptPreviewLogo")[0] }); $(".devManageMain #previewImg").attr({ "width": 200, "height": 240, "src": dataURL }); }; $scope.closeQRCode = function () { $(".devManageMain #devQRCodePanel").modal('hide'); }; //强制解绑 $scope.unbindDevice = function (entity) { $.confirm({ content: '确定解绑?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: "/superadmin/unbindDevByAdmin", data: {logicalCode: entity.logicalCode} }).then(function (response) { $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); toaster.pop("info", "提示", "解绑成功!"); }, function (response) { toaster.pop("error", "提示", "操作失败!"); }); } }, } }); }; // 清理缓存 $scope.cleanCache = function (entity) { $.confirm({ content: '确定清理?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: "/superadmin/device/clearCache", data: {devNo: entity.devNo} }).then(function (response) { $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); toaster.pop("info", "提示", "清理成功!"); }, function (response) { toaster.pop("error", "提示", "清理失败!"); }); } }, } }); }; //设置调试标记 $scope.setDebugFlag = function (entity) { $(".devManageMain #deviceDebugPanel").modal(); $scope.devNo = entity.devNo; }; var dialogData = $scope.dialogData = {}; $scope.devNo = ""; //发送指令 $scope.sendCommand = function (entity) { $scope.commandInfoPanel.$setPristine(); $scope.commandInfoPanel.$setUntouched(); $scope.devNo = entity.devNo; $http.get('/superadmin/getCommandByDevice', { params: {logicalCode: entity.logicalCode} }).then(function (data) { data = data.data if (data.result == 1) { dialogData.commandList = data.payload.dataList $scope.currentCmdIndex = -1 $scope.currentCmd = null; } }).catch(function (data) { toaster.pop("error", "提示", "获取常用命令列表失败"); }); $(".devManageMain #commandInfoPanel").modal(); }; $scope.selectCommand = function (index, item) { $scope.currentCmdIndex = index $scope.currentCmd = item; }; $scope.sendCommandConfirm = function () { if ($scope.commandInfoPanel.$invalid) { return; } var currentCmd = $scope.currentCmd if (!$scope.currentCmd.id) { toaster.pop("info", "提示", "请选择指令!"); return } var params = [] for (var index in currentCmd.params) { var item = currentCmd.params[index] params.push({ id: item.id, default: item.default, }) } $http({ method: 'POST', url: '/superadmin/sendCommand', data: {id: currentCmd.id, devNo: $scope.devNo, params: params} }).then(function (response) { var data = response.data; if (data.result == 1) { toaster.pop("success", "提示", "操作成功!"); $scope.currentResult = JSON.parse(data.data); } }, function (response) { toaster.pop("error", "提示", "操作失败!"); }); }; $scope.closeCommandPanel = function () { $(".devManageMain #commandInfoPanel").modal("hide"); delete dialogData.command; }; $scope.leaseDev = function (entity) { $.confirm({ content: '确定出租设备?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: '/superadmin/rentDevice', data: {logicalCode: entity.logicalCode} }).then(function (response) { var data = response.data; if (data.result == 1) { toaster.pop("success", "提示", "操作成功!"); } }, function () { toaster.pop("error", "提示", "操作失败!"); }); } }, } }); } $scope.sendDeviceDebugConfirm = function () { $http({ method: 'POST', url: '/superadmin/device/setDebug', data: {devNo: $scope.devNo, debugFlag: dialogData.debugFlag} }).then(function (response) { $scope.devNo = ""; var data = response.data; if (data.result == 1) { toaster.pop("success", "提示", "操作成功!"); } }, function (response) { $scope.devNo = ""; toaster.pop("error", "提示", "操作失败!"); }); }; $scope.closeDeviceDebugPanel = function () { $(".devManageMain #deviceDebugPanel").modal("hide"); delete dialogData.debugFlag; $scope.devNo = ""; }; //展示设备属主信息 $scope.showDevOwnerInfo = function (title, content) { var owner = { dealer: content.dealer, agent: content.agent, manager: content.manager } $scope.infoDetail = {title: title, content: owner}; $(".devManageMain #detailInfoPanel").modal(); }; //展示设备类型详情 $scope.showDevTypeDetailInfo = function (title, content) { $scope.infoDetail = {title: title, content: content}; $(".devManageMain #detailInfoPanel").modal(); }; //展示设备详情 $scope.showDevDetailInfo = function (title, content) { var detail = { server: content.server, softVer: content.softVer, hwVer: content.hwVer, coreVer: content.coreVer, driverVersion: content.driverVersion, cycle: content.cycle, washConfig: content.washConfig, pulseInterval1: content.pulseInterval1, remarks: content.remarks, battery: content.battery, groupId: content.groupId, groupName: content.groupName, address: content.address, pulseWidth1: content.pulseWidth1, mcuVersion: content.mcuVersion, boardValid: content.boardValid, simStatus: content.simStatus, dateTimeBinded: content.dateTimeBinded, } $scope.infoDetail = {title: title, content: detail}; $(".devManageMain #detailInfoPanel").modal(); }; //显示SIM卡信息 $scope.showSimCard = function (iccid) { $http.get('/superadmin/sim/get', { params: {iccid: iccid} }).then(function (data) { data = data.data if (data.result == 1) { $scope.infoDetail = {title: 'SIM详细信息', content: data.payload}; $(".devManageMain #detailInfoPanel").modal(); } }).catch(function () { toaster.pop("error", "提示", "获取SIM卡信息失败"); }); }; $scope.closeDetailPanel = function () { $(".devManageMain #detailInfoPanel").modal("hide"); }; // 信号趋势图 var chartCondition = $scope.chartCondition = { "logicalCode": null, startTime: moment().format("YYYY-MM-DD"), endTime: moment().format("YYYY-MM-DD") }; var signalChartPanel; $scope.showChart = function (entity, type) { $("#chartInfoPanel").modal(); chartCondition.logicalCode = entity.logicalCode; //展示趋势图 signalChartPanel = echarts.init(document.getElementById('signalChartPanel')); //resize事件绑定 $(window).off("resize.signalChartPanel").on("resize.signalChartPanel", function () { signalChartPanel.resize(); }); loadChartData(); }; $scope.closeChart = function () { $("#chartInfoPanel").modal('hide'); }; $scope.closeChart = function () { $("#chartInfoPanel").modal('hide'); }; var loadChartData = $scope.loadChartData = function () { var params = chartCondition; let url = '/superadmin/getSignalTrendByDevice' //获取数据 $http.get(url, { params: { logicalCode: params.logicalCode, startTime: params.startTime + ' 00:00:00', endTime: params.endTime + ' 23:59:59', } }).then(function (data) { var payload = data.data.payload var option = signalChartOption(payload.dataList); signalChartPanel.setOption(option); }); }; function signalChartOption(dataList) { var xData = []; var seriesData = []; function getColor(v) { if (v > 8 && v <= 20) { return '#FFC000' } else if (v > 20) { return '#07C160' } else { return '#ED6066' } } var min = 31; var max = 0; for (var index in dataList) { var item = dataList[index] xData.push(moment(item.dateStr).format("MM-DD HH:mm:ss")); seriesData.push(parseFloat(item.signal)); if (min > item.signal) { min = item.signal } if (max < item.signal) { max = item.signal } } var option = { legend: { show: false }, tooltip: { trigger: 'axis', axisPointer: { lineStyle: { color: '#108EE9', width: .3, } } }, grid: { x: 40, x2: 15, y: 45, y2: 40, }, xAxis: [ { type: 'category', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, data: xData } ], yAxis: [ { type: 'value', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, splitLine: { lineStyle: { color: '#ccc', width: 0.3, type: 'dotted' } }, }, ], series: [] }; option.yAxis[0].max = 31 option.visualMap = { show: false, pieces: [{ gt: 0, lte: 8, color: '#ED6066' }, { gt: 8, lte: 20, color: '#FFC000' }, { gt: 20, lte: 31, color: '#07C160' }] } option.series.push({ name: '信号', stack: '信号', type: 'line', symbolSize: 0, markPoint: { data: [ {type: 'max', name: '信号最强', itemStyle: {color: getColor(max)}}, { type: 'min', name: '信号最差', symbolRotate: 180, label: {position: 'insideBottom', distance: 8}, itemStyle: {color: getColor(min)} } ] }, itemStyle: { normal: { color: "rgba(244,81,108,0.8)", } }, data: seriesData, }); return option } // 功率趋势图 var powerChartCondition = $scope.powerChartCondition = { "logicalCode": null, "port": null, startTime: moment().format("YYYY-MM-DD"), endTime: moment().format("YYYY-MM-DD") }; var powerChartPanel; $scope.showPowerChart = function (entity) { $("#powerChartInfoPanel").modal(); powerChartCondition.logicalCode = entity.logicalCode; powerChartCondition.port = entity.port; //展示趋势图 powerChartPanel = echarts.init(document.getElementById('powerChartPanel')); //resize事件绑定 $(window).off("resize.powerChartPanel").on("resize.powerChartPanel", function () { powerChartPanel.resize(); }); loadPowerChartData(); }; $scope.closePowerChart = function () { $("#powerChartInfoPanel").modal('hide'); }; var loadPowerChartData = $scope.loadPowerChartData = function () { var params = powerChartCondition; let url = '/common/getPowerGraph' //获取数据 $http.get(url, { params: { logicalCode: params.logicalCode, port: params.port, startTime: params.startTime + ' 00:00:00', endTime: params.endTime + ' 23:59:59', } }).then(function (data) { var payload = data.data.payload var option = powerChartOption(payload.dataList); powerChartPanel.setOption(option); }); }; function powerChartOption(dataList) { var xData = []; var seriesData = []; for (var index in dataList) { var item = dataList[index] xData.push(moment(item.dateStr).format("MM-DD HH:mm:ss")); seriesData.push(parseFloat(item.power)); } var option = { legend: { show: false }, tooltip: { trigger: 'axis', axisPointer: { lineStyle: { color: '#108EE9', width: .3, } } }, grid: { x: 40, x2: 15, y: 45, y2: 40, }, xAxis: [ { type: 'category', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, data: xData } ], yAxis: [ { type: 'value', axisLabel: { textStyle: { color: "#aaa", fontSize: "12px" } }, axisTick: { show: false, }, axisLine: { show: false, }, splitLine: { lineStyle: { color: '#ccc', width: 0.3, type: 'dotted' } }, }, ], series: [] }; option.series.push({ name: '功率', stack: '功率', type: 'line', symbolSize: 0, itemStyle: { normal: { color: "rgba(244,81,108,0.8)", } }, data: seriesData, }); return option } // 续费记录 $scope.chargeRecord = []; // 查询记录 $scope.queryChargeRecord = function (entity) { $scope.chargeRecord = entity.chargeRecord || [] $("#chargeRecordForm").modal(); } function getSelectRows() { var rows = $scope.gridApi.selection.getSelectedRows(); if (rows.length === 0) { toaster.pop("info", "提示", "请选择数据!"); return false; } var ids = []; for (var i = 0; i < rows.length; i++) { ids.push(rows[i].logicalCode); } $scope.selectedIds = ids; return ids } $scope.manualRechargeSimCard = function () { var ids = getSelectRows() if (!ids) { return } $.confirm({ content: '您选择的设备为 ' + ids + ' ,确认手动续费?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: '/superadmin/manualRechargeSimCard', data: {logicalCode: ids} }).then(function (response) { initDataGrid(); }, function (response) { toaster.pop("error", "提示", "续费失败!"); }); } }, } }); } $scope.lockDeviceSimStatus = function () { var ids = getSelectRows() if (!ids) { return } $.confirm({ content: '您选择的设备为 ' + ids + ' ,确认操作?', buttons: { ok: { btnClass: 'btn-red', text: '锁定', action: function () { $http({ method: 'POST', url: '/superadmin/lockDeviceSimStatus', data: {logicalCode: ids} }).then(function (response) { initDataGrid(true); toaster.pop("success", "提示", "锁定成功!"); }, function (response) { toaster.pop("error", "提示", "锁定失败!"); }); } }, unlock: { btnClass: 'btn-green', text: '解锁', action: function () { $http({ method: 'POST', url: '/superadmin/unlockDeviceSimStatus', data: {logicalCode: ids} }).then(function (response) { initDataGrid(true); toaster.pop("success", "提示", "解锁成功!"); }, function (response) { toaster.pop("error", "提示", "解锁失败!"); }); } }, close: { isHidden: true }, } }); } $scope.changeDevCode = function (entity) { $scope.changeDevCodeForm.$setPristine(); $scope.changeDevCodeForm.$setUntouched(); var ids = getSelectRows() if (!ids) { return } $scope.dialogData = {logicalCodeList: ids}; $("#changeDevCodeForm").modal(); } $scope.changeDevCodeSave = function () { if ($scope.changeDevCodeForm.$invalid) { return; } $.confirm({ content: '您选择的设备为 ' + $scope.dialogData.logicalCodeList + ' ,确认修改Code?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: '/superadmin/modifyDeviceCode', data: { logicalCodeList: $scope.dialogData.logicalCodeList, code: $scope.dialogData.code } }).then(function (response) { console.log(response.data.description, response.data.payload) toaster.pop("success", "提示", response.data.description); $('#changeDevCodeForm').modal('hide'); $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize); }, function (response) { toaster.pop("error", "提示", "修改Code失败!"); }); } }, } }); } $scope.serviceSwitch = function (key, value) { var ids = getSelectRows() if (!ids) { return } let data = { logicalCode: ids, } data[key] = value $.confirm({ content: '您选择的设备为 ' + ids + ' ,确认操作?', buttons: { ok: { btnClass: 'btn-red', action: function () { $http({ method: 'POST', url: '/superadmin/setServiceButtonStatus', data: data }).then(function (response) { toaster.pop("success", "提示", '操作成功'); }, function (response) { toaster.pop("error", "提示", "操作失败!"); }); } }, } }); } }]);