Skip to content
create-property.component.ts 12.6 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, OnInit, Output, EventEmitter} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
import {InfomationService} from '../../infomation.service';
import {NzMessageService} from 'ng-zorro-antd';
import {asset_type} from '../../information.constans';
wangqinghua's avatar
wangqinghua committed
import {MonitorService} from '../../../monitor/monitor.service';
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'smart-create-property',
    templateUrl: './create-property.component.html',
    styles: []
})
export class CreatePropertyComponent implements OnInit {
    @Output() done = new EventEmitter<any>();

    modal = {
        isVisiable: false,
        title: '',
        id: '',
    };

    validateForm: FormGroup;
    controlArray = [];
    controlArrayDemo = [];
    assetType = asset_type;
    assetTypeForHtml;
    classification;

    constructor(private fb: FormBuilder, private infoSer: InfomationService,
wangqinghua's avatar
wangqinghua committed
                private message: NzMessageService,
                private monitorSer: MonitorService) {
wangqinghua's avatar
wangqinghua committed
    }

    ngOnInit() {
        this.initForm();
    }

    initForm() {
        this.controlArrayDemo = [];
        this.controlArrayDemo.push(
wangqinghua's avatar
wangqinghua committed
            {label: '设备编码', value: 'equipmentCode', type: 'input', isRequire: false,},
wangqinghua's avatar
wangqinghua committed
            {label: '资产名称', value: 'name', type: 'input', isRequire: true, isDiff: false},
            {label: '资产分类', value: 'classification', type: 'select', isRequire: true,},
wangqinghua's avatar
wangqinghua committed
            {label: '版本型号', value: 'versionMode', type: 'input', isRequire: false},
            {label: '购买合同日期', value: 'buyDate', type: 'date', isRequire: false},
            {label: '资产单价', value: 'unitPrice', type: 'input', isRequire: false},
            {label: '资产总价', value: 'totalPrice', type: 'input', isRequire: false},
            {label: '归属项目', value: 'attributionProject', type: 'input', isRequire: false},
            {label: '归属部门', value: 'attributionDepartments', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '供应商', value: 'supplier', type: 'input', isRequire: false},
            {label: '联系人', value: 'contacts', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '操作系统', value: 'operatingSystem', type: 'input', isRequire: false},
            {label: '保修到期时间', value: 'expirationDate', type: 'date', isRequire: false},
            {label: '序列号', value: 'serialNumber', type: 'input', isRequire: false},
            {label: 'cpu型号', value: 'cpuModel', type: 'input', isRequire: false},
            {label: 'cpu核数', value: 'cpuMultiNumber', type: 'input', isRequire: false},
            {label: '初始内存数量', value: 'memoryCount', type: 'input', isRequire: false},
            {label: '内存变化时间', value: 'memoryChangeDate', type: 'date', isRequire: false},
            {label: '虚拟化软件', value: 'virtualizationSoftware', type: 'input', isRequire: false},
            {label: '安装软件', value: 'installedSoftware', type: 'input', isRequire: false},
            {label: '已使用的软件授权', value: 'softwareAuthorization', type: 'input', isRequire: false},
            {label: '内部ip地址', value: 'ipInternalAddress', type: 'input', isRequire: false},
            {label: '外部IP地址', value: 'ipExternalAddress', type: 'input', isRequire: false},
            {label: '所在网络', value: 'locatedNetwork', type: 'input', isRequire: false},
            {label: '维修情况', value: 'maintenanceSituation', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '备注', value: 'remark', type: 'textarea', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '机柜名称', value: 'cabinetName', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '存放地点', value: 'place', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
            {label: '登录方式', value: 'loginMode', type: 'input', isRequire: false},
            {label: '登录密码', value: 'loginPassword', type: 'input', isRequire: false},
            {label: '新密码', value: 'newPassword', type: 'input', isRequire: false},
wangqinghua's avatar
wangqinghua committed
        );
        this.validateForm = this.fb.group({
wangqinghua's avatar
wangqinghua committed
            equipmentCode: [null], name: [null, [Validators.required]],
            classification: ['1', [Validators.required]], versionMode: [null],
            buyDate: [null], unitPrice: [null],
            totalPrice: [null], attributionProject: [null],
            attributionDepartments: [null], supplier: [null],
            contacts: [null], operatingSystem: [null],
            expirationDate: [null], serialNumber: [null],
            cpuNumber: [null], cpuModel: [null],
            cpuMultiNumber: [null], hyperthreads: [null],
            memoryCount: [null], memoryChangeCount: [null],
            memoryChangeDate: [null], disksNumber: [null],
            disksCapacity: [null], disksRaid: [null],
            disksAvailableCapacity: [null], isVirtualization: [null],
            virtualizationSoftware: [null], disksMountArrays: [null],
            installedSoftware: [null], softwareAuthorization: [null],
            ipInternalAddress: [null], ipExternalAddress: [null],
            networkPortConnection: [null], locatedNetwork: [null],
            domainName: [null], relatedApplicationProcess: [null],
            maintenanceSituation: [null], remark: [null],
            cabinetName: [null], place: [null],
            relatedEntityServer: [null], diskSystemCapacity: [null],
            diskDataCapacity: [null], relatedStorage: [null],
            changeSituation: [null], deploymentDomain: [null],
wangqinghua's avatar
wangqinghua committed
            uses: [null],
wangqinghua's avatar
wangqinghua committed
            loginMode: [null], loginPassword: [null],
            newPassword: [null],
wangqinghua's avatar
wangqinghua committed
        });

        this.assetTypeForHtml = {
            one: [
                {label: '超线程数', value: 'hyperthreads', type: 'input', isRequire: false},  //实体服务器独有属性
wangqinghua's avatar
wangqinghua committed
                {label: '内存变化数量', value: 'memoryChangeCount', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '磁盘数量', value: 'disksNumber', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '磁盘容量', value: 'disksCapacity', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '磁盘raid', value: 'disksRaid', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '可用磁盘容量', value: 'disksAvailableCapacity', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '是否虚拟化', value: 'isVirtualization', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '挂载磁盘阵列', value: 'disksMountArrays', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '网络端口连接', value: 'networkPortConnection', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '网络域名', value: 'domainName', type: 'input', isRequire: false},  //实体服务器独有属性
                {label: '关联开通服务器申请流程', value: 'relatedApplicationProcess', type: 'textarea', isRequire: false},  //实体服务器独有属性
wangqinghua's avatar
wangqinghua committed
            ],  //实体服务器
            two: [
wangqinghua's avatar
wangqinghua committed
                {label: '关联实体服务器', value: 'relatedEntityServer', type: 'input', isRequire: false},  //虚拟服务器
                {label: '关联存储', value: 'relatedStorage', type: 'input', isRequire: false},  //虚拟服务器
                {label: '系统盘容量', value: 'diskSystemCapacity', type: 'input', isRequire: false}, //政务云服务器&&虚拟服务器
                {label: '数据盘容量', value: 'diskDataCapacity', type: 'input', isRequire: false},  //政务云服务器&&虚拟服务器
                {label: '变化情况', value: 'changeSituation', type: 'input', isRequire: false},  //政务云服务器&&虚拟服务器
wangqinghua's avatar
wangqinghua committed
            ],  //虚拟服务器
            three: [
wangqinghua's avatar
wangqinghua committed
                {label: '系统盘容量', value: 'diskSystemCapacity', type: 'input', isRequire: false}, //政务云服务器&&虚拟服务器
                {label: '数据盘容量', value: 'diskDataCapacity', type: 'input', isRequire: false},  //政务云服务器&&虚拟服务器
                {label: '变化情况', value: 'changeSituation', type: 'input', isRequire: false},  //政务云服务器&&虚拟服务器
                {label: '部署域', value: 'deploymentDomain', type: 'input', isRequire: false},  //政务云服务器
wangqinghua's avatar
wangqinghua committed
                {label: '用途', value: 'uses', type: 'input', isRequire: false}, //政务云服务器
            ],  //政务云服务器
        };
        this.controlArray = this.controlArray.concat(this.controlArrayDemo);
        console.log(this.controlArray);
    }

    //
    showAddModal(title) {
        this.modal.isVisiable = true;
        this.modal.title = title;
    }

    showEditModal(title, id) {
        this.modal.isVisiable = true;
        this.modal.title = title;
        this.modal.id = id;
        this.getDetail();
    }

    handleCancel() {
        this.modal.isVisiable = false;
        this.initForm();
    }

    //查询详情
    getDetail() {
        this.infoSer.propertyFindById(this.modal.id).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.validateForm.patchValue(res.data);
                }
            }
        );
    }

    //改变分类
    changeType(e) {
        this.controlArray = [];
        console.log('change_type');
        if (e == '1') this.controlArray = this.controlArray.concat(this.controlArrayDemo, this.assetTypeForHtml.one);
        if (e == '2') this.controlArray = this.controlArray.concat(this.controlArrayDemo, this.assetTypeForHtml.two);
        if (e == '3') this.controlArray = this.controlArray.concat(this.controlArrayDemo, this.assetTypeForHtml.three);
    }

    //判断
    handleOk() {
        for (let i in this.validateForm.controls) {
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if (this.validateForm.invalid) {
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        if (this.validateForm.value.buyDate) this.validateForm.patchValue({'buyDate': new Date(this.validateForm.value.buyDate).getTime()});
        if (this.validateForm.value.expirationDate) this.validateForm.patchValue({'expirationDate': new Date(this.validateForm.value.expirationDate).getTime()});
        if (this.validateForm.value.memoryChangeDate) this.validateForm.patchValue({'memoryChangeDate': new Date(this.validateForm.value.memoryChangeDate).getTime()});
wangqinghua's avatar
wangqinghua committed
        if (this.modal.title.includes('新增')) this.create();
        if (this.modal.title.includes('编辑')) this.update();
    }

    //新增
    create() {
        console.log(this.validateForm.value);
        this.infoSer.propertyAdd(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.initForm();
                    this.done.emit();
                    this.modal.isVisiable = false;
                    this.message.success('新增成功');
wangqinghua's avatar
wangqinghua committed
                    this.monitorProperty(res.data);
wangqinghua's avatar
wangqinghua committed
    //3D模型增加
    monitorProperty(id) {
        const data = {
            module: 'PEMS',
            data: [
                {
                    id: id,
                    name: this.validateForm.value.name, //资产名称
                    description: '',
                    parentId: '',   //required
                    dataTypeId: '',  //required

                }
            ]
        };
        this.monitorSer.asset(data).subscribe(
            (res) => {

            }
        );
    }

wangqinghua's avatar
wangqinghua committed
    //更新
    update() {
wangqinghua's avatar
wangqinghua committed
        this.validateForm.addControl('id', new FormControl(this.modal.id));
wangqinghua's avatar
wangqinghua committed
        this.infoSer.propertyUpdate(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.initForm();
                    this.done.emit();
                    this.modal.isVisiable = false;
wangqinghua's avatar
wangqinghua committed
                    this.updateMonitor(res.data);
wangqinghua's avatar
wangqinghua committed
                    this.message.success('更新成功');
                }
            }
        );
    }

wangqinghua's avatar
wangqinghua committed
    //3D模型更新
    updateMonitor(id) {
        const data = {
            module: 'PEMS',
            data: {
                    id: id,
                    name: this.validateForm.value.name, //资产名称
                    description: '',
                    parentId: '',   //required
                    dataTypeId: '',  //required
                }
        };
        this.monitorSer.assetPut(id, data).subscribe(
            (res) => {

            }
        );
    }

wangqinghua's avatar
wangqinghua committed
}