Esempio n. 1
0
    def actual_add_asset_type(self, assetClass, assetClassEn, lpathList, nLen):
        try:
            checkList = []
            checkList.append(assetClass)
            checkList.append(assetClassEn)
            if not all(checkList):
                LOG.error("add new asset class params are empty!!!")
                return -1, u"填写内容为空,请检查"
            # 得到ltree路径
            leafNode = lpathList[nLen - 1]
            assetPath = self.getAssetTypePath(leafNode)
            newPath = assetPath + "." + assetClassEn.lower()

            ast = AssetTypeDal()
            assetTypeModel = ast.get_asset_type_by_name_or_path(assetClass, newPath)
            if assetTypeModel:
                return -1, assetClass + "或者" + newPath + "已经存在,添加失败"
            ast.add_asset_type(assetClass, newPath)
            return 0, u"添加成功"
        except Exception as _ex:
            LOG.error("error occured while add asset class: %s" % str(_ex))
            return -1, u"添加失败"
Esempio n. 2
0
 def get_id_by_at_asset_ch_name(self, asset_type):
     atd = AssetTypeDal()
     assetType = atd.get_asset_type_id_by_ch_name(asset_type)
     return self.actual_return_id_val(assetType)
Esempio n. 3
0
    def addAssetClass(self, data):
        """ 添加资产类别
        """
        lPath = data.get("lpath")
        if not lPath:
            LOG.error("lpath value is empty!!!")
            return -1, u"添加失败"
        lpathList = lPath.split(".")
        nLen = len(lpathList)
        if 1 == nLen:
            # 说明添加资产类别
            assetClass = data.get("add_asset_class")
            assetClassEn = data.get("add_asset_class_en")
            return self.actual_add_asset_type(assetClass, assetClassEn, lpathList, nLen)
        elif 2 == nLen:
            # 添加设备类型
            newAssetType = data.get("new_asset_type")
            newAssetTypeEn = data.get("new_asset_type_en")
            return self.actual_add_asset_type(newAssetType, newAssetTypeEn, lpathList, nLen)
        else:
            try:
                # 添加品牌、型号
                checkList = []
                providerCh = data.get("add_provider")
                providerEn = data.get("add_provider_en")
                modelName = data.get("add_model")
                checkList.append(providerCh)
                checkList.append(providerEn)
                checkList.append(modelName)
                if not all(checkList):
                    LOG.error("add new provider model params are empty!!!")
                    return -1, u"填写内容为空,请检查"

                # 得到对应的资产类型id
                assetTypeName = lpathList[nLen - 1]
                atd = AssetTypeDal()
                assetTypeModel = atd.get_asset_type_id_by_ch_name(assetTypeName)
                assetTypeId = assetTypeModel.id if assetTypeModel else None

                # 添加品牌
                # 判断新添加的品牌是不是已有的品牌
                pd = ProviderDal()
                providerEn = providerEn.upper()
                providerModel = pd.get_prov_by_id_and_at(assetTypeId, providerEn)
                if providerModel:
                    # 现有的品牌,直接添加型号
                    LOG.info("add device provider is have device")
                    # 判断型号是否存在,如果存在,直接return重复,否则添加
                    provId = providerModel.id
                    md = ModelDal()
                    modelD = md.get_model_by_pd_ch(provId, modelName)
                    if modelD:
                        return -1, u"品牌:" + providerEn + "型号:" + modelName + "已经存在,请勿重复添加"
                    else:
                        md.add_model(provId, modelName)
                else:
                    # 新品牌
                    LOG.info("add device provider is new device")
                    pd.add_new_provider(assetTypeId, providerEn, providerCh)
                    md = ModelDal()
                    provModel = pd.get_prov_by_id_and_at(assetTypeId, providerEn)
                    md.add_model(provModel.id, modelName)
                return 0, u"添加成功"
            except Exception as _ex:
                LOG.error("error occured while add provider model: %s" % str(_ex))
                return -1, u"添加失败"
Esempio n. 4
0
 def get_asset_type_name_by_num(self, asset_type_id):
     atd = AssetTypeDal()
     assetType = atd.get_asset_type_name_by_id(asset_type_id)
     return self.actual_return_ch_name_val(assetType)