emsApplication/applications/WebConfigure/web/js/script/alarmExpertConfigCtrl.js

449 lines
17 KiB
JavaScript
Raw Permalink Normal View History

2024-05-24 12:19:45 +08:00
angular.module('nurseApp').controller('alarmExpertConfigCtrl',['$scope','$filter','$rootScope','$modal','balert','bconfirm','baseTypeService','alarmExpertService','TemplateService','equipmentTemplateService','$q',
function($scope,$filter,$rootScope,$modal,balert,bconfirm,baseTypeService,alarmExpertService,TemplateService,equipmentTemplateService,$q){
(function(){
$scope.selectEvent = {
EquipmentId:'',
baseEquipmentId:'',
keyWor:'',
expired:'NULL' //'NULL' 全部 0 未过期 1 过期
}
$scope.alarmexpertList = []
$scope.equipmentTemplates = []
$scope.alarmexpertInfo = {}
$scope.uploadFileList = []
$scope.allDevice = []
$scope.allTemplate = []
$scope.query = {
baseEquipmentName:''
}
equipmentTemplateService.getAllEquipmentTemplate().then(function (data) {
$scope.allTemplates = data;
baseTypeService.getDeviceList().then(function(data){
data.forEach(function(Equipment) {
$scope.allDevice.push({
EquipmentId:Equipment.EquipmentId,
EquipmentName:Equipment.EquipmentName,
EquipmentTemplateId:Equipment.EquipmentTemplateId,
baseEquipmentId:_.findWhere($scope.allTemplates,{EquipmentTemplateId:Equipment.EquipmentTemplateId}).EquipmentBaseType
});
});
})
});
TemplateService.GetEquipmentBaseType().then(function (data) {
$scope.equipmentTemplates = data;
$scope.serch()
});
})();
var setAlarmExpertDialog = $modal({
scope: $scope,
templateUrl: 'partials/alarmExpert/setAlarmExpert.html',
show: false
});
$scope.alarmExpertDialog = {
title:'',
type:''
}
$scope.serch = function(){
alarmExpertService.getAlarmexpert($scope.selectEvent).then(function(data){
if(data){
$scope.alarmexpertList = data
$scope.tableParams.onChange('',undefined)
}
})
}
$scope.getEquipmentBaseTypeName = function(baseId){
if(baseId == '2200') return "ALL"
var result = _.find($scope.equipmentTemplates, function (item) {
return item.baseEquipmentId == baseId
});
if(result){
return result.baseEquipmentName
}
return baseId
}
$scope.getEquipmentNameByID = function(Id){
var result = _.find($scope.allDevice, function (item) {
return item.EquipmentId == Id
});
if(result){
return result.EquipmentName
}
return baseId
}
$scope.changeEquipmentBaseType = function(id){
}
$scope.changeEquipment = function(id,selectEvent){
var deferred = $q.defer();
var TemplateId = _.findWhere($scope.allDevice,{EquipmentId:id}).EquipmentTemplateId
TemplateService.GetEventByEquipmentTemplateId(TemplateId).then(function (data) {
if(data){
$scope.EquipmentEvent = data
deferred.resolve(data);
}
// if(selectEvent){
// $scope.alarmexpertInfo.EventId = selectEvent
// }else{
// $scope.alarmexpertInfo.EventId = $scope.EquipmentEvent[0].EventId
// }
});
return deferred.promise;
}
//导出
$scope.exportToHtml = function () {
$scope.loading = true
alarmExpertService.getAlarmexpertAll().then(function (data) {
if(data == "OK"){
$scope.loading = false
downloadAlarmexpertURI("/upload/exportData.xls","/upload/exportData.xls")
}
else{
$scope.loading = false
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.ExportFailed, 3000);
}
});
};
//导入 star--------------------
var addAlarmExpertDialog = $modal({
scope: $scope,
templateUrl: 'partials/alarmExpert/addAlarmExpert.html',
show: false
});
$scope.$on("fileSelected", function (event, msg) {
$scope.file = msg;
});
$scope.addAlarmExpertExcel = function () {
addAlarmExpertDialog.$promise.then(addAlarmExpertDialog.show);
};
$scope.analysisHtml = function () {
$scope.loading = true;
var file = $scope.file;
if (file === undefined) return;
console.log($scope.file);
if ($scope.file.name != "exportData.xls"){
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.fileName, 3000); //文件名不同禁止导入
$scope.loading = false
return;
}
alarmExpertService.ImportAlarmExpert($scope.file).then(function(data){
if(data == 'OK'){
balert.show("success", $scope.languageJson.alarmExpert.Prompt.addSuess, 3000);//添加成功
addAlarmExpertDialog.hide();
$scope.serch()
}else{
$scope.loading = false
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.addFail, 3000);//添加失败
}
})
}
//导入 end--------------------
function downloadAlarmexpertURI(uri,name){
var link = document.createElement('a')
link.download = name
link.target = '_blank'
link.href = uri
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
/*
pageNo 页码
pageSize 显示条数
array AllSignalList
*/
function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}
$scope.tableParams = {
currentPage: 1,//当前页面
itemsPerPage: 10,//显示条数
pagesLength: 10,
totalItems: 0,//总条数
hint: {
the: $scope.languageJson.Paging.The,
page: $scope.languageJson.Paging.Page,
articel: $scope.languageJson.Paging.Articel,
eachPage: $scope.languageJson.Paging.EachPage,
total: $scope.languageJson.Paging.Total,
noData: $scope.languageJson.Paging.NoData
},
list: [],
perPageOptions: [10, 20, 30, 40, 50],
onChange: function (newValue, oldValue) {
if (newValue == undefined) return;
$scope.loading = true;
var index = $scope.tableParams.currentPage;//当前页面
var size = $scope.tableParams.itemsPerPage;//显示条数
// var filterList = $filter('filter')(newValue,$scope.serch);//数据筛选
//分页
$scope.tableParams.list = pagination(index,size,$scope.alarmexpertList)
$scope.tableParams.totalItems = $scope.alarmexpertList.length
$rootScope.$emit('resultTotal', {});
$scope.loading = false;
}
};
$scope.setAlarmExpert = function(alarm){
console.log(alarm)
$scope.uploadFileList = []
$scope.alarmexpertInfo = {}
$scope.alarmExpertDialog.title = $scope.languageJson.alarmExpert.add + $scope.languageJson.alarmExpert.alarmList
$scope.alarmExpertDialog.type = 'add'
$scope.alarmexpertInfo.keyWord = alarm.meanings
$scope.alarmexpertInfo.alarmexpertattachment = $scope.uploadFileList
$scope.alarmexpertInfo.EquipmentId = alarm.deviceId
$scope.changeEquipment($scope.alarmexpertInfo.EquipmentId).then(function(data){
if(data){
var event = _.findWhere(data,{EventName:alarm.eventName})
if(event){
$scope.alarmexpertInfo.EventId = event.EventId
}else{
$scope.alarmexpertInfo.EventId = data[0].EventId
}
}
})
TemplateService.GetEquipmentBaseType().then(function (data) {
if(data){
$scope.equipmentTemplates = data;
alarmExpertService.getEquipmentBaseType(alarm.deviceId).then(function(baseId){
if(baseId){
$scope.alarmexpertInfo.baseEquipmentId = baseId
setAlarmExpertDialog.show()
}
})
}
});
}
//点击添加
$scope.addAlarmexpert = function(){
$scope.uploadFileList = []
$scope.alarmexpertInfo = {}
$scope.alarmExpertDialog.title = $scope.languageJson.alarmExpert.add + $scope.languageJson.alarmExpert.alarmList
$scope.alarmExpertDialog.type = 'add'
$scope.alarmexpertInfo.alarmexpertattachment = $scope.uploadFileList
// $scope.alarmexpertInfo.baseEquipmentId = $scope.equipmentTemplates[0].baseEquipmentId
// var a = _.findWhere($scope.allDevice,{baseEquipmentId:$scope.alarmexpertInfo.baseEquipmentId}).EquipmentId
$scope.alarmexpertInfo.EquipmentId = $scope.allDevice[0].EquipmentId
$scope.changeEquipment($scope.alarmexpertInfo.EquipmentId).then(function(data){
if(data){
$scope.alarmexpertInfo.EventId = data[0].EventId
}
})
// $scope.alarmexpertInfo.baseEquipmentId = _.findWhere($scope.equipmentTemplates,{baseEquipmentId:$scope.allDevice[0].baseEquipmentId}).baseEquipmentId
setAlarmExpertDialog.show()
}
//点击编辑
$scope.editAlarmexpert = function(rowData){
$scope.uploadedFileList = JSON.parse(JSON.stringify(rowData.alarmexpertattachment))
$scope.uploadFileList = []
$scope.alarmExpertDialog.title = $scope.languageJson.alarmExpert.edit + $scope.languageJson.alarmExpert.alarmList
$scope.alarmExpertDialog.type = 'edit'
$scope.alarmexpertInfo = JSON.parse(JSON.stringify(rowData))
$scope.alarmexpertInfo.EquipmentId = $scope.alarmexpertInfo.equipmentId
$scope.alarmexpertInfo.EventId = $scope.alarmexpertInfo.eventId
$scope.changeEquipment($scope.alarmexpertInfo.EquipmentId).then(function(data){
if(data){
$scope.alarmexpertInfo.EventId = $scope.alarmexpertInfo.eventId
}
})
$scope.alarmexpertInfo.verification == 1 ? $scope.isVerify = true : $scope.isVerify = false
$scope.alarmexpertInfo.alarmexpertattachment = $scope.uploadFileList
// $scope.uploadFileList = getUplodList($scope.alarmexpertInfo.alarmexpertattachment)
setAlarmExpertDialog.show()
}
//点击详情
$scope.showAlarmexpert = function(rowData){
$scope.uploadedFileList = JSON.parse(JSON.stringify(rowData.alarmexpertattachment))
$scope.uploadFileList = []
$scope.alarmExpertDialog.title = $scope.languageJson.alarmExpert.alarmList + $scope.languageJson.alarmExpert.info
$scope.alarmExpertDialog.type = 'info'
$scope.alarmexpertInfo = rowData
$scope.alarmexpertInfo.EquipmentId = $scope.alarmexpertInfo.equipmentId
$scope.changeEquipment($scope.alarmexpertInfo.EquipmentId).then(function(data){
if(data){
$scope.alarmexpertInfo.EventId = $scope.alarmexpertInfo.eventId
}
})
$scope.alarmexpertInfo.verification == 1 ? $scope.isVerify = true : $scope.isVerify = false
// $scope.uploadFileList = getUplodList($scope.alarmexpertInfo.alarmexpertattachment)
setAlarmExpertDialog.show()
}
function getUplodList(arr){
var result = []
for (var i = 0; i < arr.length; i++) {
result.push(
{
id:i+1,
FileName:arr[i].attachmentName,
File:arr[i].attachmentPath
}
)
}
return result
}
//点击保存
$scope.setAlarmexpertInfo = function(alarmExpertDialog,alarmexpertInfo){
$scope.alarmexpertInfo = alarmexpertInfo
$scope.loading = true;
$scope.alarmexpertInfo.createrUser = localStorage.getItem("username")
var danger = cheakFilterData($scope.alarmexpertInfo)
if(danger){
balert.show("danger", danger, 3000);
$scope.loading = false;
return
}
if($scope.alarmexpertInfo.keyWord){
$scope.alarmexpertInfo.keyWord = $scope.alarmexpertInfo.keyWord.replaceAll('',',')
}
switch (alarmExpertDialog.type) {
case 'add':
alarmexpertAdd()
break;
case 'edit':
alarmexpertEdit()
break;
default:
break;
}
}
//告警专家知识录入
function alarmexpertAdd(){
alarmExpertService.alarmexpertAdd($scope.alarmexpertInfo).then(function(data){
if(data == 'OK'){
balert.show("success", $scope.languageJson.alarmExpert.Prompt.addSuess, 3000);//添加成功
$scope.serch()
$scope.loading = false
setAlarmExpertDialog.hide()
}else{
$scope.loading = false
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.addFail, 3000);//添加失败
}
})
}
//告警专家知识编辑
function alarmexpertEdit(){
$scope.alarmexpertInfo.alarm_Id = $scope.alarmexpertInfo.alarmId
var req = {
alarm_Id:$scope.alarmexpertInfo.alarmId,
title:$scope.alarmexpertInfo.title,
problem:$scope.alarmexpertInfo.problem,
solution:$scope.alarmexpertInfo.solution,
// baseEquipmentId:$scope.alarmexpertInfo.baseEquipmentId,
equipmentId:$scope.alarmexpertInfo.EquipmentId,//设备id
eventId:$scope.alarmexpertInfo.EventId,//事件id
keyWord:$scope.alarmexpertInfo.keyWord,
verificationUser:$scope.alarmexpertInfo.verification == '1' ? $scope.alarmexpertInfo.createrUser : "",
verification:$scope.alarmexpertInfo.verification,
remarks:$scope.alarmexpertInfo.remarks,
alarmexpertattachment:$scope.alarmexpertInfo.alarmexpertattachment
}
alarmExpertService.alarmexpertModify(req).then(function(data){
if(data == 'OK'){
balert.show("success", $scope.languageJson.alarmExpert.Prompt.editSuess, 3000);//修改成功
$scope.serch()
$scope.loading = false
setAlarmExpertDialog.hide()
}else{
$scope.loading = false
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.editFail, 3000);//修改失败
}
})
}
//配置无效
$scope.confNotEffective = function(){
//确认配置无效?
bconfirm.show($scope, $scope.languageJson.alarmExpert.save + $scope.languageJson.alarmExpert.notEffective + '?').then(function (data) {
if (data) {
$scope.loading = true
var req = {
alarm_Id:$scope.alarmexpertInfo.alarmId,
expired:1
}
alarmExpertService.alarmexpertModify(req).then(function(data){
if(data == 'OK'){
balert.show("success", $scope.languageJson.alarmExpert.Prompt.editSuess, 3000);//修改成功
$scope.serch()
$scope.loading = false
setAlarmExpertDialog.hide()
}else{
$scope.loading = false
balert.show("danger", $scope.languageJson.alarmExpert.Prompt.editFail, 3000);//修改失败
}
})
}
});
}
function cheakFilterData(checkData){
var result = false
if(!checkData.title){
return result = $scope.languageJson.alarmExpert.Prompt.titleNULL
}
if(!checkData.problem){
return result = $scope.languageJson.alarmExpert.Prompt.problemNULL
}
if(!checkData.solution){
return result = $scope.languageJson.alarmExpert.Prompt.solutionNULL
}
return result
}
$scope.$on("fileSelected", function (event, msg) {
$scope.File = msg;
$scope.loading=true;
if ($scope.File == undefined) {
// balert.show('danger', $scope.languageJson.Configuration.ImageControl.UploadError, 3000);
$scope.loading=false;
return;
}
if($scope.File.size > 512000){
balert.show('danger', "请选择小于500k的文件", 3000);
$scope.loading=false;
return;
}
var reader = new FileReader();
//读取文件
reader.readAsDataURL($scope.File);
//读取成功
reader.addEventListener('load', function(e) {
var str = this.result;
var id = $scope.uploadFileList.length + 1
$scope.uploadFileList.push(
{
id:id,
FileName:$scope.File.name,
File:str
}
)
$scope.loading=false;
});
});
$scope.uploadFile = function(){
var $file = $('#file1')
$file.focus().click();
}
$scope.removeUpload = function(index){
$scope.uploadFileList.splice(index,1)
}
}])