固定资产项目前端文件
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
7.8 KiB

2 years ago
import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { JwResponse, NullableProps } from 'app/types'
import { Utils } from 'app/utils'
import { NzTreeNodeOptions } from 'ng-zorro-antd/tree'
import { BehaviorSubject, map, of, tap } from 'rxjs'
import {
AuthDTO,
AuthorizeItemDTO,
ConsoleClientTopDTO,
ConsoleCountDTO,
ConsoleExpireDTO,
EntityDTO,
EntityDetailDTO,
PermissionDTO,
ProductDTO,
RoleFormDTO,
RoleListDTO,
UserDTO,
} from './api.dto'
import { PermissionService } from 'app/shared/permission/permission.service'
import { NzSafeAny } from 'ng-zorro-antd/core/types'
2 years ago
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'
2 years ago
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
2 years ago
}
removeAuthData() {
localStorage.removeItem(this.AUTH_KEY_NAME)
2 years ago
}
upload(data: FormData) {
return this.http.post<JwResponse>('/api/common/upload', data)
2 years ago
}
login(data: {}) {
return this.http.post<JwResponse>('/api/oauth/login', data).pipe(
tap((res) => {
localStorage.setItem(this.AUTH_KEY_NAME, JSON.stringify(res.body))
}),
)
2 years ago
}
logout() {
return this.http.post<JwResponse>('/api/oauth/logout', null)
2 years ago
}
getOrgTree() {
return this.http.post<JwResponse>('/api/umsOrganization/tree', null)
2 years ago
}
saveOrg(data: NzSafeAny) {
if (Utils.isEmpty(data.organizationId)) {
return this.http.post<JwResponse>('/api/umsOrganization/add', data)
}
return this.http.post<JwResponse>('/api/umsOrganization/update', data)
2 years ago
}
deleteOrg(id: number) {
return this.http.post<JwResponse>('/api/umsOrganization/delete', [id])
2 years ago
}
getUserPage(data: {}) {
return this.http.post<JwResponse>('/api/umsUser/list', data)
2 years ago
}
2 years ago
getUserDetail(id: number) {
return this.http.post<JwResponse>(`/api/umsUser/query?userId=${id}`, null)
}
2 years ago
deleteUser(ids: number[]) {
return this.http.post<JwResponse>(`/api/umsUser/delete`, ids)
2 years ago
}
saveUser(data: NzSafeAny) {
if (Utils.isEmpty(data.userId)) {
return this.http.post<JwResponse>('/api/umsUser/add', data)
2 years ago
}
return this.http.post<JwResponse>('/api/umsUser/update', data)
2 years ago
}
2 years ago
getAssetPage(data: {}) {
return this.http.post<JwResponse>('/api/eamAsset/list', data)
}
copyAsset(num: number, id: number) {
return this.http.post<JwResponse>(`/api/eamAsset/copyByNum?num=${num}&id=${id}`, null)
}
deleteAsset(ids: number[]) {
return this.http.post<JwResponse>('/api/eamAsset/delete', ids)
}
uploadAsset(data: FormData) {
return this.http.post<JwResponse>('/api/eamAsset/importData', data)
}
confirmAsset(ids: number[]) {
return this.http.post<JwResponse>('/api/eamAsset/confirm', ids)
}
assetQrcode(id: number) {
return this.http.post<JwResponse>(`/api/qr/generate?id=${id}`, null, {
observe: 'response',
responseType: 'blob' as 'json',
})
}
downloadAssetTemplate() {
return this.http.post<JwResponse>(`/api/eamAsset/importTemplate`, null, {
observe: 'response',
responseType: 'blob' as 'json',
})
}
exportAsset(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamAsset/export`, ids, {
observe: 'response',
responseType: 'blob' as 'json',
})
}
saveAsset(data: NzSafeAny) {
if (Utils.isEmpty(data.assetId)) {
return this.http.post<JwResponse>('/api/eamAsset/add', data)
}
return this.http.post<JwResponse>('/api/eamAsset/update', data)
}
getBasicPositionPage(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicPosition/list', data)
2 years ago
}
2 years ago
getBasicPositionTree() {
return this.http.post<JwResponse>('/api/eamBasicPosition/tree', null)
}
saveBasicPosition(data: NzSafeAny) {
if (Utils.isEmpty(data.positionId)) {
return this.http.post<JwResponse>('/api/eamBasicPosition/add', data)
2 years ago
}
return this.http.post<JwResponse>('/api/eamBasicPosition/update', data)
2 years ago
}
deleteBasicPosition(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamBasicPosition/delete`, ids)
2 years ago
}
getBasicMaintenanceVendorPage(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicMaintenanceVendor/list', data)
2 years ago
}
saveBasicMaintenanceVendor(data: NzSafeAny) {
if (Utils.isEmpty(data.maintenanceVendorId)) {
return this.http.post<JwResponse>('/api/eamBasicMaintenanceVendor/add', data)
}
return this.http.post<JwResponse>('/api/eamBasicMaintenanceVendor/update', data)
2 years ago
}
deleteBasicMaintenanceVendor(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamBasicMaintenanceVendor/delete`, ids)
2 years ago
}
getBasicManufacturersVendorPage(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicManufacturersVendor/list', data)
2 years ago
}
saveBasicManufacturersVendor(data: NzSafeAny) {
if (Utils.isEmpty(data.manufacturersVendorId)) {
return this.http.post<JwResponse>('/api/eamBasicManufacturersVendor/add', data)
}
return this.http.post<JwResponse>('/api/eamBasicManufacturersVendor/update', data)
2 years ago
}
deleteBasicManufacturersVendor(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamBasicManufacturersVendor/delete`, ids)
2 years ago
}
getBasicSupplierVendorPage(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicSupplierVendor/list', data)
}
saveBasicSupplierVendor(data: NzSafeAny) {
if (Utils.isEmpty(data.supplierVendorId)) {
return this.http.post<JwResponse>('/api/eamBasicSupplierVendor/add', data)
2 years ago
}
return this.http.post<JwResponse>('/api/eamBasicSupplierVendor/update', data)
2 years ago
}
deleteBasicSupplierVendor(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamBasicSupplierVendor/delete`, ids)
2 years ago
}
getBasicWarehousePage(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicWarehouse/list', data)
2 years ago
}
saveBasicWarehouse(data: NzSafeAny) {
if (Utils.isEmpty(data.warehouseId)) {
return this.http.post<JwResponse>('/api/eamBasicWarehouse/add', data)
}
return this.http.post<JwResponse>('/api/eamBasicWarehouse/update', data)
2 years ago
}
deleteBasicWarehouse(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamBasicWarehouse/delete`, ids)
2 years ago
}
2 years ago
categoryTree: NzSafeAny[] = []
getBasicCategoryTree(force?: boolean) {
if (this.categoryTree.length > 0 && !force) {
return of({
body: this.categoryTree,
} as JwResponse)
}
return this.http.post<JwResponse>('/api/eamBasicCategory/tree', null).pipe(
tap((res) => {
this.categoryTree = res.body
}),
)
2 years ago
}
addBasicCategoryTree(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicCategory/add', data)
2 years ago
}
updateBasicCategoryTree(data: {}) {
return this.http.post<JwResponse>('/api/eamBasicCategory/update', data)
2 years ago
}
deleteBasicCategory(ids: number[]) {
return this.http.post<JwResponse>('/api/eamBasicCategory/delete', ids)
2 years ago
}
getStocktakingJobPage(data: {}) {
return this.http.post<JwResponse>('/api/eamStocktakingJob/list', data)
2 years ago
}
saveStocktakingJob(data: NzSafeAny) {
if (Utils.isEmpty(data.stocktakingJobId)) {
return this.http.post<JwResponse>('/api/eamStocktakingJob/add', data)
2 years ago
}
return this.http.post<JwResponse>('/api/eamStocktakingJob/update', data)
2 years ago
}
deleteStocktakingJob(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamStocktakingJob/delete`, ids)
2 years ago
}
beginStocktakingJob(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamStocktakingJob/start`, ids)
2 years ago
}
stopStocktakingJob(ids: number[]) {
return this.http.post<JwResponse>(`/api/eamStocktakingJob/complete`, ids)
2 years ago
}
/**
*
*
* -------------------------------
*
*
*/
2 years ago
getEntityPage(p: {}, q: {}) {
const params = Utils.objectToURLSearchParams({ ...p, ...q })
return this.http.get<JwResponse>(`/api/client/pages?${params}`)
2 years ago
}
}