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

486 lines
18 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 设备抄表
* Version: 3.8.30
* Author: zdc/kang
* Date: 2022/8/17
*/
angular.module('nurseApp').controller('inspectionCtrl',['$scope','$rootScope','$modal','$q','balert','bconfirm','inspectionSevice','equipmentService',
function($scope,$rootScope,$modal,$q,balert,bconfirm,inspectionSevice,equipmentService){
$scope.allInspectionSignalList = []
$scope.inspectionSelect = {
equipmentID:'',
allSelected:false,
signals:[]
}
var regularPushPatrolConfig = {
InspectionId:0,//定时邮件推送巡检Id 拿不到数据就给0
TimingStatus:0,//定时状态 0关1开
TimingPeriod:30,//定时任务执行秒数
TimingDelay:30,//定时任务延迟执行秒数
EmployeeId:"",//人员表ID
SendNameMail:"",//发送者邮件
MailPwd:"",//发送者邮件密码
SMTPService:"",//SMTP服务
MailPort:"465",//邮件端口
MailTitle:"Title",//邮件标题
SendName:"Admin",//发送者名称
Auth:true,//是否验证默认已验证
SSL:true//是否SLL认证默认已认证
}
$scope.timingStatus = $scope.languageJson.inspection.Close //定时状态
//获取所有巡检配置
inspectionSevice.getEquipmentInspectionSignalList().then(function(data){
if(data){
$scope.allInspectionSignalList = data
$scope.tableParams.onChange('',undefined)
}
})
//获取邮件推送设置
inspectionSevice.getRegularPushPatrol().then(function(data){
if(data){
regularPushPatrolConfig = data
$scope.timingStatus = regularPushPatrolConfig.TimingStatus == 0 ? $scope.languageJson.inspection.Close : $scope.languageJson.inspection.Open
}
})
function getAllEquipment(){
var allEquipment = []
var deferred = $q.defer();
equipmentService.getAllEquipment().then(function (data) {
if(data){
data.forEach(function(item){
allEquipment.push({
id:item.EquipmentId,
name:item.EquipmentName
})
})
deferred.resolve(allEquipment)
}
});
return deferred.promise;
}
function getAllEquipmentDel(){
var allEquipment = []
var deferred = $q.defer();
inspectionSevice.getEquipmentList().then(function (data) {
if(data){
data.forEach(function(item){
allEquipment.push({
id:item.EquipmentId,
name:item.EquipmentName
})
})
deferred.resolve(allEquipment)
}
});
return deferred.promise;
}
/* 数组分页
pageNo 页码
pageSize 显示条数
array allArrlList
*/
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.allInspectionSignalList)
$scope.tableParams.totalItems = $scope.allInspectionSignalList.length
$rootScope.$emit('resultTotal', {});
$scope.loading = false;
}
};
$scope.getCheckState = function(state){
if(state){
if(state == 'checkHalf'){
return 'fa-check-square-o'
}else{
return 'fa-check-square'
}
}else{
return 'fa-square-o'
}
}
//全选
$scope.selectListAll = function(selectedArr){
selectedArr.allSelected = !selectedArr.allSelected
if(selectedArr.allSelected) {
selectedArr.signals.forEach(function (item) {
item.checked = true;
})
}else {
selectedArr.signals.forEach(function (item) {
item.checked = false;
})
}
}
//单选
$scope.selectListOne = function(selectedArr,row){
row.checked = !row.checked
var allCount = 0
selectedArr.signals.forEach(function(item){
if(item.checked){
allCount++
}
})
if(allCount == selectedArr.signals.length){
selectedArr.allSelected = true
}else{
if(allCount > 0){
selectedArr.allSelected = 'checkHalf'
}else{
selectedArr.allSelected = false
}
}
}
//添加巡检配置
var inspectionDialog = $modal({
scope: $scope,
templateUrl: 'partials/inspectionDialog.html',
show: false
})
$scope.addInspectionParameter = function(){
$scope.inspectionSelect.allSelected = false
getAllEquipment().then(function(data){
if(data){
$scope.allEquipment = data
$scope.inspectionSelect.equipmentID = $scope.allEquipment[0].id
inspectionSevice.getSignalList($scope.inspectionSelect.equipmentID).then(function (data) {
if(data){
$scope.inspectionSelect.signals = data
inspectionDialog.$promise.then(inspectionDialog.show);
}
});
}
})
}
//切换设备
$scope.changeDevice = function(deviceId){
$scope.inspectionSelect.allSelected = false
inspectionSevice.getSignalList(deviceId).then(function (data) {
if(data){
$scope.inspectionSelect.signals = data
}
});
}
//保存巡检信号配置
$scope.saveInspectionConfig = function(){
if(!$scope.inspectionSelect.allSelected){
balert.show('danger', $scope.languageJson.inspection.Prompt.NoSignalList, 3000);//'请选择信号'
return
}
var req = {
"deviceId": $scope.inspectionSelect.equipmentID,
"BaseTypeId":""
}
$scope.inspectionSelect.signals.forEach(function(item){
if(item.checked){
req.BaseTypeId += item.BaseTypeId + ','
}
})
req.BaseTypeId = req.BaseTypeId.substring(0,req.BaseTypeId.lastIndexOf(','))
$scope.loading = true
inspectionSevice.addInspectionParameter(req).then(function(data){
if(data){
balert.show('success', $scope.languageJson.inspection.Prompt.AddSignalSuess, 3000);
inspectionSevice.getEquipmentInspectionSignalList().then(function(data){
if(data){
$scope.allInspectionSignalList = data
$scope.loading = false
$scope.tableParams.onChange('',undefined)
inspectionDialog.hide()
}
})
}
})
}
//删除巡检配置
$scope.removeInspection = function(InspectionConfig){
bconfirm.show($scope, $scope.languageJson.inspection.Prompt.DeleteConfirm).then(function (data) {
if(data){
$scope.loading = true
inspectionSevice.removeInspection(InspectionConfig.InspectionConfigId).then(function(data){
if(data == "OK"){
inspectionSevice.getEquipmentInspectionSignalList().then(function(data){
if(data){
$scope.allInspectionSignalList = data
$scope.tableParams.onChange('',undefined)
$scope.loading = false
}
})
}
})
}
})
}
//删除单个设备所有巡检配置 start.....
var inspectionDelDialog = $modal({
scope: $scope,
templateUrl: 'partials/inspectionDelDialog.html',
show: false
})
$scope.delInspectionParameter = function() {
getAllEquipmentDel().then(function(data){
if(data){
$scope.allEquipment = data
$scope.inspectionSelect.equipmentID = $scope.allEquipment[0].id
inspectionSevice.getSignalList($scope.inspectionSelect.equipmentID).then(function (data) {
if(data){
$scope.inspectionSelect.signals = data
inspectionDelDialog.$promise.then(inspectionDelDialog.show);
}
});
}
})
}
$scope.removeEquipmentInspection = function(equipmentId){
bconfirm.show($scope, $scope.languageJson.inspection.Prompt.DeleteConfirm).then(function (data) {
if(data){
$scope.loading = true
inspectionSevice.removeEquipmentInspection(equipmentId).then(function(data){
if(data == "OK"){
inspectionSevice.getEquipmentInspectionSignalList().then(function(data){
if(data){
$scope.allInspectionSignalList = data
$scope.tableParams.onChange('',undefined);
$scope.loading = false;
inspectionDelDialog.hide();
}
})
}
})
}
})
}
//删除单个设备所有巡检配置 end.....
//邮件推送配置
var pushPatrolDialog = $modal({
scope: $scope,
templateUrl: 'partials/pushPatrolDialog.html',
show: false
})
$scope.RegularPushPatrolConfig = function(){
$scope.EmployeeId = []
// $scope.regularPushPatrolConfig = angular.copy(regularPushPatrolConfig)
$scope.loading = true
inspectionSevice.getRegularPushPatrolEmployee().then(function(employees){
if(employees){
inspectionSevice.getRegularPushPatrol().then(function(data){
if(data){
$scope.regularPushPatrolConfig = data
parseMailDict(angular.fromJson(data.Regularly));
}else{
$scope.regularPushPatrolConfig = angular.copy(regularPushPatrolConfig)
}
if($scope.regularPushPatrolConfig.EmployeeId){
$scope.EmployeeId = $scope.regularPushPatrolConfig.EmployeeId.split(',')
}else{
$scope.EmployeeId = []
}
for (var i = 0; i < $scope.EmployeeId.length; i++) {
var Employee = _.findWhere(employees,{EmployeeId:$scope.EmployeeId[i]})
if(Employee){
$scope.EmployeeId[i] = Employee
}else{
$scope.EmployeeId[i] = {
Employeeid:$scope.EmployeeId[i],
EmployeeName:$scope.EmployeeId[i]
}
continue
}
}
$scope.loading = false
pushPatrolDialog.$promise.then(pushPatrolDialog.show);
})
}
})
}
$scope.mailTim = {
isMonth: false,
isWeek: false,
isTime: false
};
function parseMailDict(data) {
$scope.mailTim.type = data.Type;
$scope.mailTim.day = data.Data.day;
$scope.mailTim.week = data.Data.week;
$scope.mailTim.hour = data.Data.hour;
$scope.mailTim.minute = data.Data.minute;
$scope.changeMail(data.Type);
}
$scope.changeMail = function (type) {
$scope.mailTim.isTime = false;
$scope.mailTim.isMonth = false;
$scope.mailTim.isWeek = false;
if (type != 'all') {
$scope.mailTim.isTime = true;
}
if (type == 'month') {
$scope.mailTim.isMonth = true;
} else if (type == 'week') {
$scope.mailTim.isWeek = true;
}
};
//保存邮件推送配置
$scope.saveRegularPushPatrol = function(){
var req = $scope.regularPushPatrolConfig
var EmployeeId = ''
$scope.EmployeeId.forEach(function(item){
EmployeeId += item.EmployeeId + ','
})
req.EmployeeId = EmployeeId.substring(0,EmployeeId.lastIndexOf(','))
var danger = checkSaveRegularPushPatrolData(req)
if(danger){
balert.show('danger', danger, 3000);
return
}
if ($scope.mailTim.type != "all") {
if ($scope.mailTim.type == "month") {
if (($scope.mailTim.day == undefined || $scope.mailTim.day == "") ||
($scope.mailTim.day < 1 || $scope.mailTim.day > 31) || isNaN($scope.mailTim.day)) {
balert.show('danger', $scope.languageJson.AlarmNotice.EditorCtrl.Mailbox.Date, 3000);/*'日期不合法!'*/
return;
}
}
if ($scope.mailTim.type == "week") {
if (($scope.mailTim.week == undefined || $scope.mailTim.week == "") ||
($scope.mailTim.week < 1 || $scope.mailTim.week > 7) || isNaN($scope.mailTim.week)) {
balert.show('danger', $scope.languageJson.AlarmNotice.EditorCtrl.Mailbox.Legal, 3000);/*'星期数不合法!'*/
return;
}
}
var hour = parseInt($scope.mailTim.hour);
if (($scope.mailTim.hour == undefined || $scope.mailTim.hour == "") ||
(hour < 0 || hour > 23) || isNaN($scope.mailTim.hour)) {
balert.show('danger', $scope.languageJson.AlarmNotice.EditorCtrl.Mailbox.Hours, 3000);/*'小时数不合法!'*/
return;
}
var minute = parseInt($scope.mailTim.minute);
if (($scope.mailTim.minute == undefined || $scope.mailTim.minute == "") ||
(minute < 0 || minute > 59) || isNaN($scope.mailTim.minute)) {
balert.show('danger', $scope.languageJson.AlarmNotice.EditorCtrl.Mailbox.Minutes, 3000);/*'分钟数不合法!'*/
return;
}
}
$scope.loading = true
inspectionSevice.addUpdRegularPushPatrol($scope.mailTim,req).then(function(data){
if(data){
inspectionSevice.getRegularPushPatrol().then(function(dates){
$scope.loading = false
$scope.regularPushPatrolConfig = dates
$scope.timingStatus = dates.TimingStatus == 0 ? $scope.languageJson.inspection.Close : $scope.languageJson.inspection.Open
pushPatrolDialog.hide()
})
}
})
}
//发送巡检
$scope.emailPush = function(){
$scope.loading = true;
inspectionSevice.emailPush().then(function(data){
$scope.loading = false;
if (data){
balert.show('success',$scope.languageJson.inspection.sendInspectionSuccess, 3000);
}else {
balert.show('danger',$scope.languageJson.inspection.sendInspectionFail, 3000);
}
});
}
$scope.FaEye = "fa-eye-slash";
$scope.isShowPwd = function () {
if ($scope.FaEye == "fa-eye") {
$scope.FaEye = "fa-eye-slash";
$("#Pwd2").hide();
$("#Pwd1").show();
} else {
$scope.FaEye = "fa-eye";
$("#Pwd1").hide();
$("#Pwd2").show();
}
};
//邮件推送配置数据验证
function checkSaveRegularPushPatrolData(RegularPushPatrolConfig){
var result = ''
var prompt = $scope.languageJson.inspection.Prompt
if(RegularPushPatrolConfig.EmployeeId.length <= 0){
result = prompt.EmployeeIdErr
return result
}
if(!verifyEmail(RegularPushPatrolConfig.SendNameMail)){
result = $scope.languageJson.Person.ErrorMailbox
return result
}
if(RegularPushPatrolConfig.MailPwd.length <= 0){
result = prompt.EmailPassWordErr
return result
}
if(!parseInt(RegularPushPatrolConfig.MailPort)){
result = prompt.EmailPortErr
return result
}
if(RegularPushPatrolConfig.SMTPService.length <= 0){
result = prompt.EmailSmtpErr
return result
}
return result
}
//校验邮箱格式
function verifyEmail(email) {
if (email == undefined || email == "") return false;
var re = /\w+@[a-z0-9]+\.[a-z]{2,4}/;
return re.test(email);
};
}])