modelOfMatter.ts 5.04 KB
import { BasicPageParams } from '../model/baseModel';
import {
  BatchGetObjectModelItemType,
  GetModelTslParams,
  ImportModelOfMatterType,
  ModelOfMatterItemRecordType,
  ModelOfMatterParams,
  Tsl,
  UpdateSortThingsModeItemType,
} from './model/modelOfMatterModel';
import { FunctionTypeEnum } from '/@/enums/objectModelEnum';
import { defHttp } from '/@/utils/http/axios';

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',
  EXCEL_EXPORT = '/things_model/download/template',

  BATCH_GET_TSL_BY_DEVICE_PROFILES = '/things_model/batch/get_tsl',
  UPDATE_SORT = '/things_model/updateSort',
}

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

export const getModelTsl = (params: GetModelTslParams) => {
  const { functionType = 'all', deviceProfileId } = params;
  return defHttp.get<Tsl[]>({
    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;
  type?: string;
}) => {
  const { categoryId, type } = params || {};

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

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

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

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

/**
 * 物模型excel导出模板
 */
export const excelExport = (type?: string) => {
  return defHttp.get({
    url: `${ModelOfMatter.EXCEL_EXPORT}`,
    params: { type },
    responseType: 'blob',
  });
};

export const batchGetObjectModel = ({
  deviceProfileIds,
  functionTypeEnum = 'all',
}: {
  deviceProfileIds: string[];
  functionTypeEnum?: FunctionTypeEnum | 'all';
}) => {
  return defHttp.post<BatchGetObjectModelItemType[]>(
    {
      url: ModelOfMatter.BATCH_GET_TSL_BY_DEVICE_PROFILES,
      data: { deviceProfileIds, functionTypeEnum },
    },
    { withShareToken: true }
  );
};

//物模型排序
export const updateSortThingsModel = (data: UpdateSortThingsModeItemType) => {
  return defHttp.post({
    url: `${ModelOfMatter.UPDATE_SORT}?id=${data.id}&isCategory=${data.isCategory}&sortType=${data.sortType}`,
  });
};