import { HttpClient } from '@angular/common/http' import { Injectable } from '@angular/core' import { JwResponse } from 'app/types' import { Utils } from 'app/utils' import { of, tap } from 'rxjs' import { AuthDTO } from './api.dto' import { PermissionService } from 'app/shared/permission/permission.service' import { NzSafeAny } from 'ng-zorro-antd/core/types' export interface UserGroupTreeItem { name: string id: string parentId: string children: UserGroupTreeItem[] } @Injectable({ providedIn: 'root', }) export class ApiService { constructor( private http: HttpClient, private permission: PermissionService, ) {} AUTH_KEY_NAME = 'auth' get authInfo(): AuthDTO | null { let authInfo: AuthDTO | null = null try { const strData = localStorage.getItem(this.AUTH_KEY_NAME) if (strData) { authInfo = JSON.parse(strData) this.permission.loadPermission(authInfo?.permissions ?? []) } } catch (error) {} return authInfo } removeAuthData() { localStorage.removeItem(this.AUTH_KEY_NAME) } upload(data: FormData) { return this.http.post('/api/common/upload', data) } login(data: {}) { return this.http.post('/api/oauth/login', data).pipe( tap((res) => { localStorage.setItem(this.AUTH_KEY_NAME, JSON.stringify(res.body)) }), ) } logout() { return this.http.post('/api/oauth/logout', null) } getOrgTree() { return this.http.post('/api/umsOrganization/tree', null) } saveOrg(data: NzSafeAny) { if (Utils.isEmpty(data.organizationId)) { return this.http.post('/api/umsOrganization/add', data) } return this.http.post('/api/umsOrganization/update', data) } deleteOrg(id: number) { return this.http.post('/api/umsOrganization/delete', [id]) } getUserPage(data: {}) { return this.http.post('/api/umsUser/list', data) } getUserDetail(id: number) { return this.http.post(`/api/umsUser/query?userId=${id}`, null) } deleteUser(ids: number[]) { return this.http.post(`/api/umsUser/delete`, ids) } saveSelfAccount(data: NzSafeAny) { return this.http.post('/api/umsUser/update/selfInfo', data) } savePassword(data: NzSafeAny) { return this.http.post('/api/umsUser/update/selfPassword', data) } saveUser(data: NzSafeAny) { if (Utils.isEmpty(data.userId)) { return this.http.post('/api/umsUser/add', data) } return this.http.post('/api/umsUser/update', data) } getRolePage(data: {}) { return this.http.post('/api/umsRole/list', data) } getRoleDetail(id: number) { return this.http.post(`/api/umsRole/query?roleId=${id}`, null) } deleteRole(ids: number[]) { return this.http.post(`/api/umsRole/delete`, ids) } saveRole(data: NzSafeAny) { if (Utils.isEmpty(data.roleId)) { return this.http.post('/api/umsRole/add', data) } return this.http.post('/api/umsRole/update', data) } getAssetPage(data: {}) { return this.http.post('/api/eamAsset/list', data) } getAssetListByIds(ids: number[]) { return this.http.post('/api/eamAsset/queryByIds', ids) } getAssetLog(data: {}) { return this.http.post('/api/eamAssetLog/list', data) } getAssetRepairLog(data: {}, id: number) { return this.http.post(`/api/eamAsset/repair/list?id=${id}`, data) } copyAsset(num: number, id: number) { return this.http.post(`/api/eamAsset/copyByNum?num=${num}&id=${id}`, null) } deleteAsset(ids: number[]) { return this.http.post('/api/eamAsset/delete', ids) } uploadAsset(data: FormData) { return this.http.post('/api/eamAsset/importData', data) } confirmAsset(ids: number[]) { return this.http.post('/api/eamAsset/confirm', ids) } assetQrcode(id: number) { return this.http.post(`/api/qr/generate?id=${id}`, null, { observe: 'response', responseType: 'blob' as 'json', }) } downloadAssetTemplate() { return this.http.post(`/api/eamAsset/importTemplate`, null, { observe: 'response', responseType: 'blob' as 'json', }) } exportAsset(ids: number[]) { return this.http.post(`/api/eamAsset/export`, ids, { observe: 'response', responseType: 'blob' as 'json', }) } saveAsset(data: NzSafeAny) { if (Utils.isEmpty(data.assetId)) { return this.http.post('/api/eamAsset/add', data) } return this.http.post('/api/eamAsset/update', data) } getAlertBorrow(data: {}) { return this.http.post('/api/eamAsset/warning/borrow', data) } getAlertMaintenance(data: {}) { return this.http.post('/api/eamAsset/warning/maintenance', data) } getAlertSafety(data: {}) { return this.http.post('/api/eamAsset/warning/safety', data) } getAlertSafetyUp(data: {}) { return this.http.post('/api/eamAsset/warning/up', data) } getAlertSafetyDown(data: {}) { return this.http.post('/api/eamAsset/warning/down', data) } getBasicPositionPage(data: {}) { return this.http.post('/api/eamBasicPosition/list', data) } getBasicPositionTree() { return this.http.post('/api/eamBasicPosition/tree', null) } saveBasicPosition(data: NzSafeAny) { if (Utils.isEmpty(data.positionId)) { return this.http.post('/api/eamBasicPosition/add', data) } return this.http.post('/api/eamBasicPosition/update', data) } deleteBasicPosition(ids: number[]) { return this.http.post(`/api/eamBasicPosition/delete`, ids) } getBasicMaintenanceVendorPage(data: {}) { return this.http.post('/api/eamBasicMaintenanceVendor/list', data) } saveBasicMaintenanceVendor(data: NzSafeAny) { if (Utils.isEmpty(data.maintenanceVendorId)) { return this.http.post('/api/eamBasicMaintenanceVendor/add', data) } return this.http.post('/api/eamBasicMaintenanceVendor/update', data) } deleteBasicMaintenanceVendor(ids: number[]) { return this.http.post(`/api/eamBasicMaintenanceVendor/delete`, ids) } getBasicManufacturersVendorPage(data: {}) { return this.http.post('/api/eamBasicManufacturersVendor/list', data) } saveBasicManufacturersVendor(data: NzSafeAny) { if (Utils.isEmpty(data.manufacturersVendorId)) { return this.http.post('/api/eamBasicManufacturersVendor/add', data) } return this.http.post('/api/eamBasicManufacturersVendor/update', data) } deleteBasicManufacturersVendor(ids: number[]) { return this.http.post(`/api/eamBasicManufacturersVendor/delete`, ids) } getBasicSupplierVendorPage(data: {}) { return this.http.post('/api/eamBasicSupplierVendor/list', data) } saveBasicSupplierVendor(data: NzSafeAny) { if (Utils.isEmpty(data.supplierVendorId)) { return this.http.post('/api/eamBasicSupplierVendor/add', data) } return this.http.post('/api/eamBasicSupplierVendor/update', data) } deleteBasicSupplierVendor(ids: number[]) { return this.http.post(`/api/eamBasicSupplierVendor/delete`, ids) } getBasicWarehousePage(data: {}) { return this.http.post('/api/eamBasicWarehouse/list', data) } saveBasicWarehouse(data: NzSafeAny) { if (Utils.isEmpty(data.warehouseId)) { return this.http.post('/api/eamBasicWarehouse/add', data) } return this.http.post('/api/eamBasicWarehouse/update', data) } deleteBasicWarehouse(ids: number[]) { return this.http.post(`/api/eamBasicWarehouse/delete`, ids) } categoryTree: NzSafeAny[] = [] getBasicCategoryTree(force?: boolean) { if (this.categoryTree.length > 0 && !force) { return of({ body: this.categoryTree, } as JwResponse) } return this.http.post('/api/eamBasicCategory/tree', null).pipe( tap((res) => { this.categoryTree = res.body }), ) } addBasicCategoryTree(data: {}) { return this.http.post('/api/eamBasicCategory/add', data) } updateBasicCategoryTree(data: {}) { return this.http.post('/api/eamBasicCategory/update', data) } deleteBasicCategory(ids: number[]) { return this.http.post('/api/eamBasicCategory/delete', ids) } getStocktakingPlanPage(data: {}) { return this.http.post('/api/eamStocktakingPlan/list', data) } saveStocktakingPlan(data: NzSafeAny) { if (Utils.isEmpty(data.stocktakingJobId)) { return this.http.post('/api/eamStocktakingPlan/add', data) } return this.http.post('/api/eamStocktakingPlan/update', data) } deleteStocktakingPlan(ids: number[]) { return this.http.post(`/api/eamStocktakingPlan/delete`, ids) } createStocktakingJobByPlan(ids: number[]) { return this.http.post(`/api/eamStocktakingPlan/job`, ids) } getStocktakingJobDetailPage(data: {}) { return this.http.post('/api/eamStocktakingDetails/list', data) } saveStocktakingJobDetail(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamStocktakingDetails/add', data) } return this.http.post('/api/eamStocktakingDetails/update', data) } deleteStocktakingDetail(ids: number[]) { return this.http.post(`/api/eamStocktakingDetails/delete`, ids) } getStocktakingJobPage(data: {}) { return this.http.post('/api/eamStocktakingJob/list', data) } saveStocktakingJob(data: NzSafeAny) { if (Utils.isEmpty(data.stocktakingJobId)) { return this.http.post('/api/eamStocktakingJob/add', data) } return this.http.post('/api/eamStocktakingJob/update', data) } deleteStocktakingJob(ids: number[]) { return this.http.post(`/api/eamStocktakingJob/delete`, ids) } beginStocktakingJob(ids: number[]) { return this.http.post(`/api/eamStocktakingJob/start`, ids) } stopStocktakingJob(ids: number[]) { return this.http.post(`/api/eamStocktakingJob/complete`, ids) } getBusinessStoragePage(data: {}) { return this.http.post('/api/eamBusinessStorage/list', data) } saveBusinessStorage(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { Reflect.deleteProperty(data, 'id') return this.http.post('/api/eamBusinessStorage/add', data) } return this.http.post('/api/eamBusinessStorage/update', data) } deleteBusinessStorage(ids: number[]) { return this.http.post(`/api/eamBusinessStorage/delete`, ids) } confirmBusinessStorage(ids: number[]) { return this.http.post(`/api/eamBusinessStorage/confirm`, ids) } getBusinessCollectionPage(data: {}) { return this.http.post('/api/eamBusinessCollection/list', data) } saveBusinessCollection(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessCollection/add', data) } return this.http.post('/api/eamBusinessCollection/update', data) } deleteBusinessCollection(ids: number[]) { return this.http.post(`/api/eamBusinessCollection/delete`, ids) } confirmBusinessCollection(ids: number[]) { return this.http.post(`/api/eamBusinessCollection/confirm`, ids) } getBusinessReturnInventoryPage(data: {}) { return this.http.post('/api/eamBusinessReturnInventory/list', data) } saveBusinessReturnInventory(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessReturnInventory/add', data) } return this.http.post('/api/eamBusinessReturnInventory/update', data) } deleteBusinessReturnInventory(ids: number[]) { return this.http.post(`/api/eamBusinessReturnInventory/delete`, ids) } confirmBusinessReturnInventory(ids: number[]) { return this.http.post(`/api/eamBusinessReturnInventory/confirm`, ids) } getBusinessBorrowPage(data: {}) { return this.http.post('/api/eamBusinessBorrow/list', data) } saveBusinessBorrow(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessBorrow/add', data) } return this.http.post('/api/eamBusinessBorrow/update', data) } deleteBusinessBorrow(ids: number[]) { return this.http.post(`/api/eamBusinessBorrow/delete`, ids) } confirmBusinessBorrow(ids: number[]) { return this.http.post(`/api/eamBusinessBorrow/confirm`, ids) } getBusinessRevertPage(data: {}) { return this.http.post('/api/eamBusinessReturn/list', data) } saveBusinessRevert(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessReturn/add', data) } return this.http.post('/api/eamBusinessReturn/update', data) } deleteBusinessRevert(ids: number[]) { return this.http.post(`/api/eamBusinessReturn/delete`, ids) } confirmBusinessRevert(ids: number[]) { return this.http.post(`/api/eamBusinessReturn/confirm`, ids) } getBusinessAllocatePage(data: {}) { return this.http.post('/api/eamBusinessAllocate/list', data) } saveBusinessAllocate(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessAllocate/add', data) } return this.http.post('/api/eamBusinessAllocate/update', data) } deleteBusinessAllocate(ids: number[]) { return this.http.post(`/api/eamBusinessAllocate/delete`, ids) } confirmBusinessAllocate(ids: number[]) { return this.http.post(`/api/eamBusinessAllocate/confirm`, ids) } getBusinessTransferPage(data: {}) { return this.http.post('/api/eamBusinessTransfer/list', data) } saveBusinessTransfer(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamBusinessTransfer/add', data) } return this.http.post('/api/eamBusinessTransfer/update', data) } deleteBusinessTransfer(ids: number[]) { return this.http.post(`/api/eamBusinessTransfer/delete`, ids) } confirmBusinessTransfer(ids: number[]) { return this.http.post(`/api/eamBusinessTransfer/confirm`, ids) } getRepairTypePage(data: {}) { return this.http.post('/api/eamRepairType/list', data) } saveRepairType(data: NzSafeAny) { if (Utils.isEmpty(data.repairTypeId)) { return this.http.post('/api/eamRepairType/add', data) } return this.http.post('/api/eamRepairType/update', data) } deleteRepairType(ids: number[]) { return this.http.post(`/api/eamRepairType/delete`, ids) } getRepairPage(data: {}) { return this.http.post('/api/eamRepair/list', data) } saveRepair(data: NzSafeAny) { if (Utils.isEmpty(data.id)) { return this.http.post('/api/eamRepair/add', data) } return this.http.post('/api/eamRepair/update', data) } deleteRepair(ids: number[]) { return this.http.post(`/api/eamRepair/delete`, ids) } getRepairFaultPage(data: {}) { return this.http.post('/api/eamRepairFault/list', data) } saveRepairFault(data: NzSafeAny) { if (Utils.isEmpty(data.faultId)) { return this.http.post('/api/eamRepairFault/add', data) } return this.http.post('/api/eamRepairFault/update', data) } deleteRepairFault(ids: number[]) { return this.http.post(`/api/eamRepairFault/delete`, ids) } // flow getFlowForms(data: {}) { return this.http.post(`/api/flForm/all`, data) } setFlowFormsAssignee(data: {}) { return this.http.post(`/api/flForm/assignee`, null, { params: data, }) } getMyApplyAssetFlow(data: {}) { return this.http.post(`/api/flowable/task/myProcess`, data) } getMyTodoAssetFlow(data: {}) { return this.http.post(`/api/flowable/task/todoList`, data) } getMyFinishedAssetFlow(data: {}) { return this.http.post(`/api/flowable/task/finishedList`, data) } startFlow(json: {}, form_key: string) { return this.http.post(`/api/flowable/definition/start/${form_key}`, json) } }