import { RhQmpService } from './../../qmp.service'; import { EmployeeMessageNotifyEmployeeGroupConfigDto, EmployeeMessageNotifyGroupConfigDto, EmployeeMessageNotifyGroupConfigQueryDto, MessageEngineConfigQueryDto, GetMessageEngineConfigListOutput } from './../../qmp-model'; import { Component, OnInit, ViewChild } from '@angular/core'; import { CodeClassModel, DataResultT, OpMode, RhDynamicTableFieldDto, RhSafeAny, RhSelectableDto, RhTableButtonInfoDto, RhTableQueryOptionDto, RhBaseDto, RhDynamicComponentFieldType } from 'rh-base/model'; import { MsgHelper, ObjectHelper } from 'rh-base/core'; import { DynamicFormComponent } from 'rh-base/shared'; import { RhAuxiliaryBasicInformationService } from '../auxiliary-basic-information.service'; type tabType = 'edit' | 'bindingDatas'; @Component({ selector: 'rh-inspector-management', templateUrl: './inspector-management.component.html', styleUrls: ['./inspector-management.component.less'] }) export class RhInspectorManagementComponent implements OnInit { @ViewChild('employeeMessageNotifyGroupConfigQueryForm', { static: false }) employeeMessageNotifyGroupConfigQueryFormCmt!: DynamicFormComponent; @ViewChild('linkEmployeeQueryForm', { static: false }) linkEmployeeQueryFormCmt!: DynamicFormComponent; selectedIndex = 0; dataLoading = false; employeeDataLoading = false; dataresult!: DataResultT; employeeDataResult!: DataResultT; selectedBindingDataset: RhSelectableDto[] = []; editGroupDto: EmployeeMessageNotifyGroupConfigDto | null = null; defaultFieldDataset: RhDynamicComponentFieldType[] = []; linkEmployeeDefaultFieldDataset: RhDynamicComponentFieldType[] = []; editButtonDataset: RhTableButtonInfoDto[] = []; titleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('link', '绑定', 'primary', false, 'link', false, null, () => this.openEditTab(), true) ]; extraButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto( 'disconnect', '批量解绑', 'primary', true, 'disconnect', true, null, (datas) => this.batchUnBinding(datas as RhSelectableDto[]), false ) ]; linkEmployeeTitleButtonDataset: RhTableButtonInfoDto[] = [ new RhTableButtonInfoDto('links', '批量绑定', 'primary', false, 'link', false, null, () => this.batchBinding(), false) ]; messageNotifyGroups: EmployeeMessageNotifyGroupConfigDto[] = []; selectedMessageNotifyGroup!: EmployeeMessageNotifyGroupConfigDto; messageNotifyGroupsLoading = false; isShowAddBusinessGroupModal = false; moduleKey = 'QualityManagement'; moduleName = '质量管理'; defaultQueryDto = { ModuleKey: this.moduleKey }; /** 发送配置 */ SendModeConfig = { Mail: false, //是否发送邮件 IsMailAudit: false, //是否生成邮件审计记录 IsMailRecord: false, //是否生成邮件收件记录 EnterpriseWeChat: false, //是否发送企业微信 IsEnterpriseWeChatAudit: false, //是否生成企业微信审计记录 IsEnterpriseWeChatRecord: false, //是否生成企业微信收件记录 DingTalk: false, // 是否发送钉钉 IsDingTalkAudit: false, // 是否生成钉钉审计记录 IsDingTalkRecord: false // 是否生成钉钉收件记录 }; /** 消息引擎配置 */ MsgEngineConfigInfo = { EnterpriseWeChatConfigName: null, //企业微信配置 MailConfigName: null, //邮箱服务器配置 DingTalkConfigName: null // 钉钉服务器配置 }; mailConfigList: GetMessageEngineConfigListOutput[] = []; enterpriseWechatConfigList: GetMessageEngineConfigListOutput[] = []; dingTalkConfigList: GetMessageEngineConfigListOutput[] = []; beforeSubmit = (data: RhBaseDto) => { if (this.SendModeConfig.Mail && !this.MsgEngineConfigInfo.MailConfigName) { MsgHelper.ShowWarningMessage('必须选择邮件服务器!'); return false; } if (this.SendModeConfig.EnterpriseWeChat && !this.MsgEngineConfigInfo.EnterpriseWeChatConfigName) { MsgHelper.ShowWarningMessage('必须选择企业微信服务器!'); return false; } if (this.SendModeConfig.DingTalk && !this.MsgEngineConfigInfo.DingTalkConfigName) { MsgHelper.ShowWarningMessage('必须选择钉钉服务器!'); return false; } if (!this.SendModeConfig.Mail) { this.SendModeConfig.IsMailAudit = false; this.SendModeConfig.IsMailRecord = false; this.MsgEngineConfigInfo.MailConfigName = null; } if (!this.SendModeConfig.EnterpriseWeChat) { this.SendModeConfig.IsEnterpriseWeChatAudit = false; this.SendModeConfig.IsEnterpriseWeChatRecord = false; this.MsgEngineConfigInfo.EnterpriseWeChatConfigName = null; } if (!this.SendModeConfig.DingTalk) { this.SendModeConfig.IsDingTalkAudit = false; this.SendModeConfig.IsDingTalkRecord = false; this.MsgEngineConfigInfo.DingTalkConfigName = null; } data['SendConfigDto'] = { SendModeConfig: this.SendModeConfig, MsgEngineConfigInfo: this.MsgEngineConfigInfo }; return true; }; constructor(private operator: RhAuxiliaryBasicInformationService, private qmpSer: RhQmpService) { // } ngOnInit(): void { this.getEmployeeMessageNotifyGroupConfigDatas(); this.getMessageEngineConfigListAsync(MessageEngineConfigQueryDto.create('Mail')); this.getMessageEngineConfigListAsync(MessageEngineConfigQueryDto.create('EnterpriseWeChat')); this.getMessageEngineConfigListAsync(MessageEngineConfigQueryDto.create('DingTalk')); } openEditTab() { if (!this.selectedMessageNotifyGroup) { MsgHelper.ShowWarningMessage('请先选择业务组!'); return; } this.selectedIndex = 1; } closeEditTab() { // this.selectedIndex = 0; } batchBinding() { if (!this.selectedBindingDataset || this.selectedBindingDataset.length === 0) { MsgHelper.ShowWarningMessage('请先选择绑定数据!'); return; } let dataset: EmployeeMessageNotifyEmployeeGroupConfigDto[] = []; dataset = this.selectedBindingDataset.map((f) => { const temp = EmployeeMessageNotifyEmployeeGroupConfigDto.create(); temp.EmployeeCode = f['EmployeeCode']; temp.GroupKey = this.selectedMessageNotifyGroup?.GroupKey; temp.GroupName = this.selectedMessageNotifyGroup?.GroupName; temp.GroupDescription = this.selectedMessageNotifyGroup?.GroupDescription; temp.ModuleKey = this.selectedMessageNotifyGroup?.ModuleKey; temp.ModuleName = this.selectedMessageNotifyGroup?.ModuleName; // 默认启用 temp.IsEnable = true; return temp; }); this.linkEmployeeTitleButtonDataset[0].loading = true; this.linkEmployeeTitleButtonDataset = [...this.linkEmployeeTitleButtonDataset]; this.operator.StoreEmployeeMessageNotifyEmployeeGroupDatas(dataset).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('批量绑定成功!'); this.getDatas(); this.closeEditTab(); } else { MsgHelper.ShowWarningMessage(`批量绑定失败!${result.Message}`); } this.linkEmployeeTitleButtonDataset[0].loading = false; this.linkEmployeeTitleButtonDataset = [...this.linkEmployeeTitleButtonDataset]; }, () => { this.linkEmployeeTitleButtonDataset[0].loading = false; this.linkEmployeeTitleButtonDataset = [...this.linkEmployeeTitleButtonDataset]; } ); } batchUnBinding(datas: RhSelectableDto[]) { const tempDatas = datas.map((f) => { const temp = EmployeeMessageNotifyEmployeeGroupConfigDto.create(); ObjectHelper.MapT(f, temp); return temp; }); this.extraButtonDataset[0].loading = true; this.extraButtonDataset = [...this.extraButtonDataset]; this.operator.RemoveEmployeeMessageNotifyEmployeeGroupDatas(tempDatas).subscribe( (result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('批量解绑成功!'); this.getDatas(); } else { MsgHelper.ShowWarningMessage(`批量解绑失败!${result.Message}`); } this.extraButtonDataset[0].loading = false; this.extraButtonDataset = [...this.extraButtonDataset]; }, () => { this.extraButtonDataset[0].loading = false; this.extraButtonDataset = [...this.extraButtonDataset]; } ); } getBindingDatas(datas: RhSelectableDto[]) { if (datas) { this.selectedBindingDataset = datas; } else { this.selectedBindingDataset = []; } } setDatas(dataset: DataResultT) { this.dataresult = dataset; if (!this.dataresult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.dataresult?.Message}`); } } setLinkEmployeeDatas(dataset: DataResultT) { this.employeeDataResult = dataset; if (!this.employeeDataResult?.Success) { MsgHelper.ShowWarningMessage(`搜索无数据!${this.employeeDataResult?.Message}`); } } dataLoadingChange(status: boolean) { this.dataLoading = status; } employeeDataLoadingChange(status: boolean) { this.employeeDataLoading = status; } setInitFieldDatset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.defaultFieldDataset = [...tempDatas]; } setLinkEmployeeInitFieldDatset(item: CodeClassModel) { const tempDatas: RhDynamicComponentFieldType[] = []; item.CodeProperties.forEach((ele) => { const temp = RhDynamicTableFieldDto.create(); temp.name = ele.PropertyName; temp.displayName = ele.Descirption; tempDatas.push(temp); }); this.linkEmployeeDefaultFieldDataset = [...tempDatas]; } refreshDatas(option: RhTableQueryOptionDto) { this.getDatas(option); } refreshLinkEmployeeDatas(option: RhTableQueryOptionDto) { this.getLinkEmployeeDatas(option); } onStoreData(result: DataResultT) { if (result && result.Success) { const msg = this.editGroupDto?.OpSign === OpMode.OpAdd ? '新增' : '编辑'; MsgHelper.ShowSuccessMessage(`${msg}业务组数据成功!`); if (this.editGroupDto?.OpSign === OpMode.OpEdit) { this.closeAddBusinessGroupModal(); } this.editGroupDto = this.initEmployeeMessageNotifyGroupConfigDto(); this.resetSendConfig(); this.getEmployeeMessageNotifyGroupConfigDatas(); this.selectedMessageNotifyGroup = result.Attach; this.getDatas(); } else { MsgHelper.ShowWarningModal(`新增业务组数据失败!${result.Message}`); } } //调用子组件中的接口 private getDatas(option?: RhTableQueryOptionDto) { if (this.employeeMessageNotifyGroupConfigQueryFormCmt) { this.employeeMessageNotifyGroupConfigQueryFormCmt.submitDefaultForm(null, option); } } private getLinkEmployeeDatas(option?: RhTableQueryOptionDto) { if (this.linkEmployeeQueryFormCmt) { this.linkEmployeeQueryFormCmt.submitDefaultForm(null, option); } } getEmployeeMessageNotifyGroupConfigDatas() { const queryDto = EmployeeMessageNotifyGroupConfigQueryDto.create(); queryDto.ModuleKey = this.moduleKey; queryDto.IsEnable = true; queryDto.Mode = 8; this.messageNotifyGroupsLoading = true; this.qmpSer.GetEmployeeMessageNotifyGroupConfigDatas(queryDto).subscribe( (result) => { if (result.Success) { this.messageNotifyGroups = result.Attach; if (this.selectedMessageNotifyGroup) { const temp = this.messageNotifyGroups.find( (f) => f.ModuleKey === this.selectedMessageNotifyGroup.ModuleKey && f.GroupKey === this.selectedMessageNotifyGroup.GroupKey ); if (temp) { temp.select = true; } } } else { this.messageNotifyGroups = []; MsgHelper.ShowWarningMessage(`查询无数据!${result.Message}`); } this.messageNotifyGroupsLoading = false; }, () => { this.messageNotifyGroupsLoading = false; } ); } initEmployeeMessageNotifyGroupConfigDto() { const dto = EmployeeMessageNotifyGroupConfigDto.create(); dto.ModuleKey = this.moduleKey; dto.ModuleName = this.moduleName; dto.OpSign = OpMode.OpAdd; return dto; } openAddBusinessGroupModal() { this.editGroupDto = this.initEmployeeMessageNotifyGroupConfigDto(); this.isShowAddBusinessGroupModal = true; } closeAddBusinessGroupModal() { this.editGroupDto = null; this.isShowAddBusinessGroupModal = false; this.resetSendConfig(); } resetSendConfig() { // 重置发送配置 Object.keys(this.SendModeConfig).forEach((key) => (this.SendModeConfig[key as keyof typeof this.SendModeConfig] = false)); Object.keys(this.MsgEngineConfigInfo).forEach((key) => (this.MsgEngineConfigInfo[key as keyof typeof this.MsgEngineConfigInfo] = null)); } editGroup(group: EmployeeMessageNotifyGroupConfigDto, event: Event) { if (event) { event.preventDefault(); event.stopImmediatePropagation(); } this.editGroupDto = group; this.editGroupDto.OpSign = OpMode.OpEdit; // 重置发送配置 const sendConfig = JSON.parse(this.editGroupDto['JsonSendConfig']); const sendModeConfig = sendConfig?.SendModeConfig || {}; const msgEngineConfig = sendConfig?.MsgEngineConfigInfo || {}; Object.keys(this.SendModeConfig).forEach((key) => ((this.SendModeConfig as RhSafeAny)[key] = sendModeConfig[key] || false)); Object.keys(this.MsgEngineConfigInfo).forEach((key) => ((this.MsgEngineConfigInfo as RhSafeAny)[key] = msgEngineConfig[key] || null)); this.isShowAddBusinessGroupModal = true; } removeGroup(group: EmployeeMessageNotifyGroupConfigDto, event: Event) { if (event) { event.preventDefault(); event.stopImmediatePropagation(); } MsgHelper.ShowDeleteConfirm('删除业务组数据会同时删除绑定的员工数据,是否确定?', () => { const dto = EmployeeMessageNotifyEmployeeGroupConfigDto.create(); ObjectHelper.MapT(group, dto); this.operator .RemoveEmployeeMessageNotifyEmployeeGroupDatasByGroupKey(dto as EmployeeMessageNotifyGroupConfigDto) .subscribe((result) => { if (result.Success) { MsgHelper.ShowSuccessMessage('移除业务组数据成功!'); this.getEmployeeMessageNotifyGroupConfigDatas(); } else { MsgHelper.ShowWarningMessage(`移除业务组数据失败!${result.Message}`); } }); }); } getCheckedData(data: EmployeeMessageNotifyGroupConfigDto) { this.selectedMessageNotifyGroup = data; this.defaultQueryDto = { ModuleKey: this.moduleKey, GroupKey: data.GroupKey, GroupName: data.GroupName } as RhSafeAny; setTimeout(() => { this.getDatas(); }); } getMessageEngineConfigListAsync(dto: MessageEngineConfigQueryDto) { this.operator.GetMessageEngineConfigListAsync(dto).subscribe( (result) => { if (result.Success) { if (dto.ConfigType === 'Mail') { this.mailConfigList = result.Attach; } else if (dto.ConfigType === 'EnterpriseWeChat') { this.enterpriseWechatConfigList = result.Attach; } else if (dto.ConfigType === 'DingTalk') { this.dingTalkConfigList = result.Attach; } } else { if (dto.ConfigType === 'Mail') { this.mailConfigList = []; } else if (dto.ConfigType === 'EnterpriseWeChat') { this.enterpriseWechatConfigList = []; } else if (dto.ConfigType === 'DingTalk') { this.dingTalkConfigList = []; } } }, () => { if (dto.ConfigType === 'Mail') { this.mailConfigList = []; } else if (dto.ConfigType === 'EnterpriseWeChat') { this.enterpriseWechatConfigList = []; } else if (dto.ConfigType === 'DingTalk') { this.dingTalkConfigList = []; } } ); } }