|
|
|
|
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'
|
|
|
|
|
|
|
|
|
|
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<JwResponse>('/api/common/upload', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
login(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/oauth/login', data).pipe(
|
|
|
|
|
tap((res) => {
|
|
|
|
|
localStorage.setItem(this.AUTH_KEY_NAME, JSON.stringify(res.body))
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
|
return this.http.post<JwResponse>('/api/oauth/logout', null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getOrgTree() {
|
|
|
|
|
return this.http.post<JwResponse>('/api/umsOrganization/tree', null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteOrg(id: number) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/umsOrganization/delete', [id])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getUserPage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/umsUser/list', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deleteUser(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/umsUser/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveUser(data: NzSafeAny) {
|
|
|
|
|
if (Utils.isEmpty(data.userId)) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/umsUser/add', data)
|
|
|
|
|
}
|
|
|
|
|
return this.http.post<JwResponse>('/api/umsUser/update', data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBasicPositionPage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicPosition/list', data)
|
|
|
|
|
}
|
|
|
|
|
saveBasicPosition(data: NzSafeAny) {
|
|
|
|
|
if (Utils.isEmpty(data.positionId)) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicPosition/add', data)
|
|
|
|
|
}
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicPosition/update', data)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicPosition(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamBasicPosition/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBasicMaintenanceVendorPage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicMaintenanceVendor/list', data)
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicMaintenanceVendor(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamBasicMaintenanceVendor/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBasicManufacturersVendorPage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicManufacturersVendor/list', data)
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicManufacturersVendor(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamBasicManufacturersVendor/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicSupplierVendor/update', data)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicSupplierVendor(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamBasicSupplierVendor/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBasicWarehousePage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicWarehouse/list', data)
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicWarehouse(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamBasicWarehouse/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getBasicCategoryTree() {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicCategory/tree', null)
|
|
|
|
|
}
|
|
|
|
|
addBasicCategoryTree(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicCategory/add', data)
|
|
|
|
|
}
|
|
|
|
|
updateBasicCategoryTree(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicCategory/update', data)
|
|
|
|
|
}
|
|
|
|
|
deleteBasicCategory(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamBasicCategory/delete', ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getStocktakingJobPage(data: {}) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamStocktakingJob/list', data)
|
|
|
|
|
}
|
|
|
|
|
saveStocktakingJob(data: NzSafeAny) {
|
|
|
|
|
if (Utils.isEmpty(data.stocktakingJobId)) {
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamStocktakingJob/add', data)
|
|
|
|
|
}
|
|
|
|
|
return this.http.post<JwResponse>('/api/eamStocktakingJob/update', data)
|
|
|
|
|
}
|
|
|
|
|
deleteStocktakingJob(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamStocktakingJob/delete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beginStocktakingJob(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamStocktakingJob/start`, ids)
|
|
|
|
|
}
|
|
|
|
|
stopStocktakingJob(ids: number[]) {
|
|
|
|
|
return this.http.post<JwResponse>(`/api/eamStocktakingJob/complete`, ids)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* -------------------------------
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
getEntityPage(p: {}, q: {}) {
|
|
|
|
|
const params = Utils.objectToURLSearchParams({ ...p, ...q })
|
|
|
|
|
return this.http.get<JwResponse>(`/api/client/pages?${params}`)
|
|
|
|
|
}
|
|
|
|
|
}
|