modelOfMatter.ts 3.83 KB
import { BasicPageParams } from '../model/baseModel';
import {
  GetModelTslParams,
  ImportModelOfMatterType,
  ModelOfMatterParams,
} from './model/modelOfMatterModel';
import { defHttp } from '/@/utils/http/axios';
import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config';

enum ModelOfMatter {
  CREATE = '/things_model',
  UPDATE = '/things_model',
  DELETE = '/things_model',
  TSL = '/things_model',
  LIST = '/things_model/page',
  RELEASE = '/things_model',

  IMPORT = '/things_model/import',

  GET_MODEL_SERVICE = '/things_model/get_services',
  CATEGORY = '/things_model/category',
  CATEGORY_IMPORT = '/things_model/categoryImport',

  CATEGORY_EXPORT = '/things_model/categoryGetExport',

  IMPORT_CSV = '/things_model/csvImport',
}

export const getModelList = (
  params: BasicPageParams & {
    deviceProfileId?: string;
    functionTyp?: FunctionType;
    nameOrIdentifier?: string;
    selectType?: string | undefined;
    id?: string;
  }
) => {
  return defHttp.get({
    url: `${ModelOfMatter.LIST}`,
    params,
  });
};

export const getModelTsl = (params: GetModelTslParams) => {
  const { functionType, deviceProfileId } = params;
  return defHttp.get({
    url: `${ModelOfMatter.TSL}/${functionType}/${deviceProfileId}`,
  });
};

export const createModel = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.post({
    url: ModelOfMatter.CREATE,
    params,
  });
};

export const updateModel = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.put({
    url: ModelOfMatter.UPDATE,
    params,
  });
};

export const deleteModel = (params: string[]) => {
  return defHttp.delete({
    url: ModelOfMatter.DELETE,
    params: {
      ids: params,
    },
  });
};

export const releaseModel = (deviceProfileId: string) => {
  return defHttp.put({
    url: `${ModelOfMatter.RELEASE}/${deviceProfileId}`,
  });
};

export const getModelServices = (params: { deviceProfileId: string }) => {
  const { deviceProfileId } = params;
  return defHttp.get<ModelOfMatterParams[]>({
    url: `${ModelOfMatter.GET_MODEL_SERVICE}/${deviceProfileId}`,
  });
};

export const importModelOfMatter = (data: ImportModelOfMatterType) => {
  return defHttp.post({
    url: ModelOfMatter.IMPORT,
    data,
  });
};

// 产品品类接口

// 新增
export const createModelCategory = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.post({
    url: ModelOfMatter.CATEGORY,
    params,
  });
};

// 修改
export const updateModelCategory = (params: Partial<ModelOfMatterParams>) => {
  return defHttp.put({
    url: ModelOfMatter.CATEGORY,
    params,
  });
};

// 删除
export const deleteModelCategory = (params: string[]) => {
  return defHttp.delete({
    url: ModelOfMatter.CATEGORY,
    params: {
      ids: params,
    },
  });
};

// 导入
export const importModelCategory = (data: ImportModelOfMatterType) => {
  return defHttp.post({
    url: ModelOfMatter.CATEGORY_IMPORT,
    data,
  });
};

// 导出
export const ExportModelCategory = (params: any) => {
  const { functionType, deviceProfileId } = params;
  return defHttp.get({
    url: `${ModelOfMatter.CATEGORY_EXPORT}/${functionType}/${deviceProfileId}`,
    params,
  });
};

/**
 * 物模型产品品类界面excel导入
 */

export const importCsvCategory = (params: {
  categoryId?: string;
  deviceProfileId?: string;
  file: FormData;
}) => {
  const { categoryId } = params || {};

  return defHttp.post<any>({
    url: `${ModelOfMatter.IMPORT_CSV}?categoryId=${categoryId}`,
    params: params.file,
  });
};

/**
 * 物模型产品物模型界面excel导入
 */

export const importCsvDeviceProfileId = (params: {
  categoryId?: string;
  deviceProfileId?: string;
  file: FormData;
}) => {
  const { deviceProfileId } = params || {};

  return defHttp.post<any>({
    url: `${ModelOfMatter.IMPORT_CSV}?deviceProfileId=${deviceProfileId}`,
    params: params.file,
  });
};