|
|
@ -1,9 +1,9 @@ |
|
|
import { HttpClient, HttpParams, HttpResponse } from "@angular/common/http"; |
|
|
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http' |
|
|
import { Inject, Injectable, InjectionToken } from "@angular/core"; |
|
|
import { Inject, Injectable, InjectionToken } from '@angular/core' |
|
|
import { AnyObject, Augmented, OptionItemInterface, PageResult, ResponseType } from "@cdk/types"; |
|
|
import { AnyObject, Augmented, OptionItemInterface, PageResult, ResponseType } from '@cdk/types' |
|
|
import { format, addDays } from "date-fns"; |
|
|
import { format, addDays } from 'date-fns' |
|
|
import { Utils } from "@cdk/utils"; |
|
|
import { Utils } from '@cdk/utils' |
|
|
import { Observable, map, of, tap } from "rxjs"; |
|
|
import { Observable, map, of, tap } from 'rxjs' |
|
|
import { |
|
|
import { |
|
|
PermItemDTO, |
|
|
PermItemDTO, |
|
|
UserDTO, |
|
|
UserDTO, |
|
|
@ -15,185 +15,187 @@ import { |
|
|
OrgConfigDTO, |
|
|
OrgConfigDTO, |
|
|
CategoryDTO, |
|
|
CategoryDTO, |
|
|
NutrientDTO, |
|
|
NutrientDTO, |
|
|
} from "@cdk/public-api"; |
|
|
} from '@cdk/public-api' |
|
|
|
|
|
|
|
|
export const PROJECT_NAME = new InjectionToken<string>("projectName"); |
|
|
export const PROJECT_NAME = new InjectionToken<string>('projectName') |
|
|
|
|
|
|
|
|
@Injectable({ |
|
|
@Injectable({ |
|
|
providedIn: "root", |
|
|
providedIn: 'root', |
|
|
}) |
|
|
}) |
|
|
export class ApiService { |
|
|
export class ApiService { |
|
|
constructor(private http: HttpClient, @Inject(PROJECT_NAME) public project: string) { |
|
|
constructor(private http: HttpClient, @Inject(PROJECT_NAME) public project: string) { |
|
|
this.initAccount(); |
|
|
this.initAccount() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public account!: ClientAccountDTO; |
|
|
public account!: ClientAccountDTO |
|
|
|
|
|
|
|
|
public adminAccount!: AdminAccountDTO; |
|
|
public adminAccount!: AdminAccountDTO |
|
|
|
|
|
|
|
|
public accountKey = this.project === "admin" ? "CATERING_ADMIN_ACCOUNT" : "CATERING_CLIENT_ACCOUNT"; |
|
|
public accountKey = this.project === 'admin' ? 'CATERING_ADMIN_ACCOUNT' : 'CATERING_CLIENT_ACCOUNT' |
|
|
|
|
|
|
|
|
globalEnum!: GlobalEnum; |
|
|
globalEnum!: GlobalEnum |
|
|
|
|
|
|
|
|
// 能量、蛋白质、脂肪、碳水化合物、糖、钠/食盐、钙、铁、锌、维生素A、维生素B1、维生素B2、维生素C、膳食纤维
|
|
|
// 能量、蛋白质、脂肪、碳水化合物、糖、钠/食盐、钙、铁、锌、维生素A、维生素B1、维生素B2、维生素C、膳食纤维
|
|
|
nutrientSort = new Map([ |
|
|
nutrientSort = new Map([ |
|
|
["energy", { sort: 0 }], |
|
|
['energy', { sort: 0 }], |
|
|
["protein", { sort: 1 }], |
|
|
['protein', { sort: 1 }], |
|
|
["fat", { sort: 2 }], |
|
|
['fat', { sort: 2 }], |
|
|
["carbs", { sort: 3 }], |
|
|
['carbs', { sort: 3 }], |
|
|
["sugar", { sort: 4 }], |
|
|
['sugar', { sort: 4 }], |
|
|
["sodium", { sort: 5 }], |
|
|
['sodium', { sort: 5 }], |
|
|
["calcium", { sort: 6 }], |
|
|
['calcium', { sort: 6 }], |
|
|
["iron", { sort: 7 }], |
|
|
['iron', { sort: 7 }], |
|
|
["zinc", { sort: 8 }], |
|
|
['zinc', { sort: 8 }], |
|
|
["va", { sort: 9 }], |
|
|
['va', { sort: 9 }], |
|
|
["vb1", { sort: 10 }], |
|
|
['vb1', { sort: 10 }], |
|
|
["vb2", { sort: 11 }], |
|
|
['vb2', { sort: 11 }], |
|
|
["vc", { sort: 12 }], |
|
|
['vc', { sort: 12 }], |
|
|
["fiber", { sort: 13 }], |
|
|
['fiber', { sort: 13 }], |
|
|
]); |
|
|
]) |
|
|
|
|
|
|
|
|
initAccount() { |
|
|
initAccount() { |
|
|
try { |
|
|
try { |
|
|
const stragedAccount = localStorage.getItem(this.accountKey); |
|
|
const stragedAccount = localStorage.getItem(this.accountKey) |
|
|
if (stragedAccount) { |
|
|
if (stragedAccount) { |
|
|
if (this.project === "admin") { |
|
|
if (this.project === 'admin') { |
|
|
this.adminAccount = JSON.parse(stragedAccount); |
|
|
this.adminAccount = JSON.parse(stragedAccount) |
|
|
} else { |
|
|
} else { |
|
|
this.account = JSON.parse(stragedAccount); |
|
|
this.account = JSON.parse(stragedAccount) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error("获取用户信息失败", error); |
|
|
console.error('获取用户信息失败', error) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
upload(data: FormData) { |
|
|
upload(data: FormData) { |
|
|
return this.http.put<ResponseType>("/api/icon", data); |
|
|
return this.http.put<ResponseType>('/api/icon', data) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private _formatEnum(v: CategoryDTO[]): OptionItemInterface[] { |
|
|
private _formatEnum(v: CategoryDTO[]): OptionItemInterface[] { |
|
|
return v.map((i) => ({ label: i.key, value: i.value })); |
|
|
return v.map((i) => ({ label: i.key, value: i.value })) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private _sortNutrient(n: NutrientDTO[]) { |
|
|
private _sortNutrient(n: NutrientDTO[]) { |
|
|
return n.map((i) => { |
|
|
return n |
|
|
return { ...i, ...this.nutrientSort.get(i.key) }; |
|
|
.map((i) => { |
|
|
}); |
|
|
return { ...i, ...(this.nutrientSort.get(i.key) ?? { sort: 100 }) } |
|
|
|
|
|
}) |
|
|
|
|
|
.sort((a, b) => a.sort - b.sort) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAllEnum(force?: boolean): Observable<GlobalEnum> { |
|
|
getAllEnum(force?: boolean): Observable<GlobalEnum> { |
|
|
if (this.globalEnum && !force) { |
|
|
if (this.globalEnum && !force) { |
|
|
return of(this.globalEnum); |
|
|
return of(this.globalEnum) |
|
|
} |
|
|
} |
|
|
return this.http.get<ResponseType<any>>("/api/enum").pipe( |
|
|
return this.http.get<ResponseType<any>>('/api/enum').pipe( |
|
|
map((res) => { |
|
|
map((res) => { |
|
|
return { |
|
|
return { |
|
|
...res.body, |
|
|
...res.body, |
|
|
mealType: this._formatEnum(res.body.mealType), |
|
|
mealType: this._formatEnum(res.body.mealType), |
|
|
menuStatus: this._formatEnum(res.body.menuStatus), |
|
|
menuStatus: this._formatEnum(res.body.menuStatus), |
|
|
nutrient: this._sortNutrient(res.body.nutrient), |
|
|
nutrient: this._sortNutrient(res.body.nutrient), |
|
|
}; |
|
|
} |
|
|
}), |
|
|
}), |
|
|
tap((r) => { |
|
|
tap((r) => { |
|
|
this.globalEnum = r; |
|
|
this.globalEnum = r |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
login(v: AnyObject) { |
|
|
login(v: AnyObject) { |
|
|
v["admin"] = this.project === "admin"; |
|
|
v['admin'] = this.project === 'admin' |
|
|
const params = Utils.objectToHttpParams(v); |
|
|
const params = Utils.objectToHttpParams(v) |
|
|
return this.http.get<ResponseType>("/api/login", { params }).pipe( |
|
|
return this.http.get<ResponseType>('/api/login', { params }).pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
localStorage.setItem(this.accountKey, JSON.stringify(res.body)); |
|
|
localStorage.setItem(this.accountKey, JSON.stringify(res.body)) |
|
|
this.initAccount(); |
|
|
this.initAccount() |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
logout() { |
|
|
logout() { |
|
|
return this.http.get<ResponseType>("/api/logout").pipe( |
|
|
return this.http.get<ResponseType>('/api/logout').pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
if (res.success) { |
|
|
if (res.success) { |
|
|
localStorage.removeItem(this.accountKey); |
|
|
localStorage.removeItem(this.accountKey) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getOrgInfo() { |
|
|
getOrgInfo() { |
|
|
return this.http.get<ResponseType>("/api/vender/info").pipe( |
|
|
return this.http.get<ResponseType>('/api/vender/info').pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
this.account["vender"] = res.body; |
|
|
this.account['vender'] = res.body |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getOrgConfig() { |
|
|
getOrgConfig() { |
|
|
return this.http.get<ResponseType<OrgConfigDTO>>("/api/vender/config"); |
|
|
return this.http.get<ResponseType<OrgConfigDTO>>('/api/vender/config') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveOrgConfig(config: AnyObject) { |
|
|
saveOrgConfig(config: AnyObject) { |
|
|
const body = Utils.objectToFormData(config); |
|
|
const body = Utils.objectToFormData(config) |
|
|
return this.http.post<ResponseType>("/api/vender/config", body); |
|
|
return this.http.post<ResponseType>('/api/vender/config', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updatePassword(v: {}) { |
|
|
updatePassword(v: {}) { |
|
|
const body = Utils.objectToFormData(v); |
|
|
const body = Utils.objectToFormData(v) |
|
|
return this.http.post<ResponseType>("/api/password", body); |
|
|
return this.http.post<ResponseType>('/api/password', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getRoleList() { |
|
|
getRoleList() { |
|
|
return this.http.get<ResponseType<UserRoleDTO[]>>("/api/role"); |
|
|
return this.http.get<ResponseType<UserRoleDTO[]>>('/api/role') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteRole(roleId: string) { |
|
|
deleteRole(roleId: string) { |
|
|
const params = new HttpParams().set("roleId", roleId); |
|
|
const params = new HttpParams().set('roleId', roleId) |
|
|
return this.http.delete<ResponseType>("/api/role", { |
|
|
return this.http.delete<ResponseType>('/api/role', { |
|
|
params, |
|
|
params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updateRole(rule: AnyObject) { |
|
|
updateRole(rule: AnyObject) { |
|
|
const body = Utils.objectToFormData(rule, true); |
|
|
const body = Utils.objectToFormData(rule, true) |
|
|
const method = rule["roleId"] ? "post" : "put"; |
|
|
const method = rule['roleId'] ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/role", body); |
|
|
return this.http[method]<ResponseType>('/api/role', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getRolePerms() { |
|
|
getRolePerms() { |
|
|
return this.http.get<ResponseType<PermItemDTO[]>>("/api/role/item"); |
|
|
return this.http.get<ResponseType<PermItemDTO[]>>('/api/role/item') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getUserList() { |
|
|
getUserList() { |
|
|
return this.http.get<ResponseType<UserDTO[]>>("/api/user"); |
|
|
return this.http.get<ResponseType<UserDTO[]>>('/api/user') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
checkUid(uid: string) { |
|
|
checkUid(uid: string) { |
|
|
const params = new HttpParams().set("uid", uid); |
|
|
const params = new HttpParams().set('uid', uid) |
|
|
return this.http.delete<ResponseType>("/api/user/check", { |
|
|
return this.http.delete<ResponseType>('/api/user/check', { |
|
|
params, |
|
|
params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveUser(user: AnyObject, edit: boolean) { |
|
|
saveUser(user: AnyObject, edit: boolean) { |
|
|
const body = Utils.objectToFormData(user); |
|
|
const body = Utils.objectToFormData(user) |
|
|
const method = edit ? "post" : "put"; |
|
|
const method = edit ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/user", body); |
|
|
return this.http[method]<ResponseType>('/api/user', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteUser(uid: string) { |
|
|
deleteUser(uid: string) { |
|
|
const params = new HttpParams().set("uid", uid); |
|
|
const params = new HttpParams().set('uid', uid) |
|
|
return this.http.delete<ResponseType>("/api/user", { |
|
|
return this.http.delete<ResponseType>('/api/user', { |
|
|
params, |
|
|
params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
orgList: (OrgDTO & { value: string; text: string })[] = []; |
|
|
orgList: (OrgDTO & { value: string; text: string })[] = [] |
|
|
|
|
|
|
|
|
getOrgList(query?: { vendors?: number[]; keyword?: string }, force?: boolean) { |
|
|
getOrgList(query?: { vendors?: number[]; keyword?: string }, force?: boolean) { |
|
|
if (this.orgList.length && !force) { |
|
|
if (this.orgList.length && !force) { |
|
|
return of(this.orgList); |
|
|
return of(this.orgList) |
|
|
} |
|
|
} |
|
|
// const q = Utils.objectStringify(query);
|
|
|
// const q = Utils.objectStringify(query);
|
|
|
return this.http.get<ResponseType<OrgDTO[]>>(`/api/vender/select?keyword= `).pipe( |
|
|
return this.http.get<ResponseType<OrgDTO[]>>(`/api/vender/select?keyword= `).pipe( |
|
|
@ -203,45 +205,45 @@ export class ApiService { |
|
|
value: i.id.toString(), |
|
|
value: i.id.toString(), |
|
|
text: i.name, |
|
|
text: i.name, |
|
|
label: i.name, |
|
|
label: i.name, |
|
|
})); |
|
|
})) |
|
|
}), |
|
|
}), |
|
|
tap((r) => { |
|
|
tap((r) => { |
|
|
this.orgList = r; |
|
|
this.orgList = r |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getOrgPage(p: {}, q: {}) { |
|
|
getOrgPage(p: {}, q: {}) { |
|
|
let params = Utils.objectStringify({ ...p, ...q }, { skipEmptyString: false, skipNull: false }); |
|
|
let params = Utils.objectStringify({ ...p, ...q }, { skipEmptyString: false, skipNull: false }) |
|
|
|
|
|
|
|
|
return this.http.get<ResponseType<PageResult<OrgDTO>>>(`/api/vender?${params}`); |
|
|
return this.http.get<ResponseType<PageResult<OrgDTO>>>(`/api/vender?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
checkOrgAccount(account: string) { |
|
|
checkOrgAccount(account: string) { |
|
|
const params = new HttpParams().set("account", account); |
|
|
const params = new HttpParams().set('account', account) |
|
|
return this.http.get<ResponseType<boolean>>("/api/vender/check/account", { |
|
|
return this.http.get<ResponseType<boolean>>('/api/vender/check/account', { |
|
|
params, |
|
|
params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
checkOrgName(name: string) { |
|
|
checkOrgName(name: string) { |
|
|
const params = new HttpParams().set("name", name); |
|
|
const params = new HttpParams().set('name', name) |
|
|
return this.http.get<ResponseType<boolean>>("/api/vender/check/name", { |
|
|
return this.http.get<ResponseType<boolean>>('/api/vender/check/name', { |
|
|
params, |
|
|
params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteOrg(id: number) { |
|
|
deleteOrg(id: number) { |
|
|
const params = Utils.objectToFormData({ venderId: id }); |
|
|
const params = Utils.objectToFormData({ venderId: id }) |
|
|
return this.http.delete<ResponseType>("/api/vender", { |
|
|
return this.http.delete<ResponseType>('/api/vender', { |
|
|
body: params, |
|
|
body: params, |
|
|
}); |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveOrg(org: AnyObject) { |
|
|
saveOrg(org: AnyObject) { |
|
|
const body = Utils.objectToFormData(org); |
|
|
const body = Utils.objectToFormData(org) |
|
|
const method = org["id"] ? "post" : "put"; |
|
|
const method = org['id'] ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/vender", body); |
|
|
return this.http[method]<ResponseType>('/api/vender', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// getOrgConfig() {
|
|
|
// getOrgConfig() {
|
|
|
@ -249,7 +251,7 @@ export class ApiService { |
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
getFoodPage(p: {}, q: {}) { |
|
|
getFoodPage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/ingredient?${params}`).pipe( |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/ingredient?${params}`).pipe( |
|
|
map((r) => { |
|
|
map((r) => { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
@ -257,86 +259,86 @@ export class ApiService { |
|
|
return { |
|
|
return { |
|
|
...o, |
|
|
...o, |
|
|
nutrientArr: Object.entries(o.nutrient).map(([k, v]) => { |
|
|
nutrientArr: Object.entries(o.nutrient).map(([k, v]) => { |
|
|
const nutrient = this.globalEnum.nutrient.find((f) => f.key === k); |
|
|
const nutrient = this.globalEnum.nutrient.find((f) => f.key === k) |
|
|
return { |
|
|
return { |
|
|
key: k, |
|
|
key: k, |
|
|
value: v, |
|
|
value: v, |
|
|
label: nutrient?.value, |
|
|
label: nutrient?.value, |
|
|
measurement: nutrient?.measurement, |
|
|
measurement: nutrient?.measurement, |
|
|
}; |
|
|
} |
|
|
}), |
|
|
}), |
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
return r; |
|
|
|
|
|
}) |
|
|
}) |
|
|
); |
|
|
} |
|
|
|
|
|
return r |
|
|
|
|
|
}), |
|
|
|
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getFoodList(query: {}) { |
|
|
getFoodList(query: {}) { |
|
|
const q = Utils.objectStringify(query); |
|
|
const q = Utils.objectStringify(query) |
|
|
return this.http.get<ResponseType<any[]>>(`/api/ingredient/select?${q}`); |
|
|
return this.http.get<ResponseType<any[]>>(`/api/ingredient/select?${q}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getFoodExcelTemplate() { |
|
|
getFoodExcelTemplate() { |
|
|
return this.http.get("/api/ingredient/excel", { observe: "response", responseType: "blob" as "json" }).pipe( |
|
|
return this.http.get('/api/ingredient/excel', { observe: 'response', responseType: 'blob' as 'json' }).pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
this.downLoadFile(res); |
|
|
this.downLoadFile(res) |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
downLoadFile(response: HttpResponse<Object>, defaultName = `${Date.now()}.xlsx`) { |
|
|
downLoadFile(response: HttpResponse<Object>, defaultName = `${Date.now()}.xlsx`) { |
|
|
const fileNameFromHeader = response.headers.get("Content-Disposition"); |
|
|
const fileNameFromHeader = response.headers.get('Content-Disposition') |
|
|
if (fileNameFromHeader) { |
|
|
if (fileNameFromHeader) { |
|
|
const fileName = fileNameFromHeader.trim()?.split("''")?.[1]?.replace(/"/g, "") ?? defaultName; |
|
|
const fileName = fileNameFromHeader.trim()?.split("''")?.[1]?.replace(/"/g, '') ?? defaultName |
|
|
const blob = new Blob([response.body as any]); |
|
|
const blob = new Blob([response.body as any]) |
|
|
const downloadLink = document.createElement("a"); |
|
|
const downloadLink = document.createElement('a') |
|
|
downloadLink.href = URL.createObjectURL(blob); |
|
|
downloadLink.href = URL.createObjectURL(blob) |
|
|
downloadLink.download = decodeURIComponent(fileName); |
|
|
downloadLink.download = decodeURIComponent(fileName) |
|
|
document.body.appendChild(downloadLink); |
|
|
document.body.appendChild(downloadLink) |
|
|
downloadLink.click(); |
|
|
downloadLink.click() |
|
|
document.body.removeChild(downloadLink); |
|
|
document.body.removeChild(downloadLink) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveFood(food: AnyObject, isEdit?: boolean) { |
|
|
saveFood(food: AnyObject, isEdit?: boolean) { |
|
|
const body = Utils.objectToFormData(food); |
|
|
const body = Utils.objectToFormData(food) |
|
|
const method = isEdit ? "post" : "put"; |
|
|
const method = isEdit ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/ingredient", body); |
|
|
return this.http[method]<ResponseType>('/api/ingredient', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteFoods(ids: number[]) { |
|
|
deleteFoods(ids: number[]) { |
|
|
const params = Utils.objectToFormData({ keys: ids.join(",") }); |
|
|
const params = Utils.objectToFormData({ keys: ids.join(',') }) |
|
|
return this.http.delete<ResponseType>(`/api/ingredient`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/ingredient`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
importFood(f: FormData) { |
|
|
importFood(f: FormData) { |
|
|
// return this.http.put<ResponseType>("/api/ingredient/upload", f);
|
|
|
// return this.http.put<ResponseType>("/api/ingredient/upload", f);
|
|
|
return this.http |
|
|
return this.http |
|
|
.put<ResponseType>("/api/ingredient/excel", f, { |
|
|
.put<ResponseType>('/api/ingredient/excel', f, { |
|
|
observe: "response", |
|
|
observe: 'response', |
|
|
responseType: "blob" as "json", |
|
|
responseType: 'blob' as 'json', |
|
|
}) |
|
|
}) |
|
|
.pipe |
|
|
.pipe |
|
|
// tap((res) => {
|
|
|
// tap((res) => {
|
|
|
// this.downLoadFile(res);
|
|
|
// this.downLoadFile(res);
|
|
|
// })
|
|
|
// })
|
|
|
(); |
|
|
() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
markFood(mark: string, key: string) { |
|
|
markFood(mark: string, key: string) { |
|
|
const params = Utils.objectToFormData({ mark, key }); |
|
|
const params = Utils.objectToFormData({ mark, key }) |
|
|
return this.http.put<ResponseType>("/api/ingredient/mark", params); |
|
|
return this.http.put<ResponseType>('/api/ingredient/mark', params) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
removeFoodMark(key: string) { |
|
|
removeFoodMark(key: string) { |
|
|
const params = Utils.objectToFormData({ key }); |
|
|
const params = Utils.objectToFormData({ key }) |
|
|
return this.http.delete<ResponseType>("/api/ingredient/mark", { body: params }); |
|
|
return this.http.delete<ResponseType>('/api/ingredient/mark', { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getStandardPage(p: {}, q: {}) { |
|
|
getStandardPage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/nutrition?${params}`).pipe( |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/nutrition?${params}`).pipe( |
|
|
map((r) => { |
|
|
map((r) => { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
@ -347,54 +349,54 @@ export class ApiService { |
|
|
return { |
|
|
return { |
|
|
peopleGroupName: k, |
|
|
peopleGroupName: k, |
|
|
...((v as any) ?? {}), |
|
|
...((v as any) ?? {}), |
|
|
}; |
|
|
} |
|
|
}), |
|
|
}), |
|
|
}; |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
return r; |
|
|
|
|
|
}) |
|
|
}) |
|
|
); |
|
|
} |
|
|
|
|
|
return r |
|
|
|
|
|
}), |
|
|
|
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
standardList: (AnyObject & OptionItemInterface)[] = []; |
|
|
standardList: (AnyObject & OptionItemInterface)[] = [] |
|
|
|
|
|
|
|
|
getStandard(q?: { id?: string; name?: string }, force?: boolean) { |
|
|
getStandard(q?: { id?: string; name?: string }, force?: boolean) { |
|
|
// if (this.standardList.length && !force) {
|
|
|
// if (this.standardList.length && !force) {
|
|
|
// return of(this.standardList);
|
|
|
// return of(this.standardList);
|
|
|
// }
|
|
|
// }
|
|
|
const query = q ? Utils.objectStringify(q) : "keyword=&name="; |
|
|
const query = q ? Utils.objectStringify(q) : 'keyword=&name=' |
|
|
return this.http.get<ResponseType<any>>(`/api/nutrition/select?${query}`).pipe( |
|
|
return this.http.get<ResponseType<any>>(`/api/nutrition/select?${query}`).pipe( |
|
|
map((r) => { |
|
|
map((r) => { |
|
|
return r.body.map((i: any) => ({ |
|
|
return r.body.map((i: any) => ({ |
|
|
...i, |
|
|
...i, |
|
|
value: i.id.toString(), |
|
|
value: i.id.toString(), |
|
|
label: i.name, |
|
|
label: i.name, |
|
|
})); |
|
|
})) |
|
|
}), |
|
|
}), |
|
|
tap((r) => { |
|
|
tap((r) => { |
|
|
this.standardList = r; |
|
|
this.standardList = r |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
getStandardById(q: { id?: string; name?: string }) { |
|
|
getStandardById(q: { id?: string; name?: string }) { |
|
|
const query = Utils.objectStringify(q); |
|
|
const query = Utils.objectStringify(q) |
|
|
return this.http.get<ResponseType<any>>(`/api/nutrition/select?${query}`); |
|
|
return this.http.get<ResponseType<any>>(`/api/nutrition/select?${query}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveStandard(v: AnyObject, isEdit?: boolean) { |
|
|
saveStandard(v: AnyObject, isEdit?: boolean) { |
|
|
const body = Utils.objectToFormData({ ...v, vendors: v["vendors"]?.join(",") }); |
|
|
const body = Utils.objectToFormData({ ...v, vendors: v['vendors']?.join(',') }) |
|
|
const method = v["id"] ? "post" : "put"; |
|
|
const method = v['id'] ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/nutrition", body); |
|
|
return this.http[method]<ResponseType>('/api/nutrition', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteStandard(id: string) { |
|
|
deleteStandard(id: string) { |
|
|
const params = Utils.objectToFormData({ id }); |
|
|
const params = Utils.objectToFormData({ id }) |
|
|
return this.http.delete<ResponseType>(`/api/nutrition`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/nutrition`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getDishPage(p: {}, q: {}) { |
|
|
getDishPage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/dish?${params}`).pipe( |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/dish?${params}`).pipe( |
|
|
map((r) => { |
|
|
map((r) => { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
if (Array.isArray(r.body.content)) { |
|
|
@ -411,13 +413,13 @@ export class ApiService { |
|
|
// };
|
|
|
// };
|
|
|
// });
|
|
|
// });
|
|
|
} |
|
|
} |
|
|
return r; |
|
|
return r |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getDishLabel(ids: (string | number)[]) { |
|
|
getDishLabel(ids: (string | number)[]) { |
|
|
const query = Utils.objectStringify({ ids }); |
|
|
const query = Utils.objectStringify({ ids }) |
|
|
return this.http.get<ResponseType<any[]>>(`/api/dish/label?${query}`).pipe( |
|
|
return this.http.get<ResponseType<any[]>>(`/api/dish/label?${query}`).pipe( |
|
|
map((res) => { |
|
|
map((res) => { |
|
|
return { |
|
|
return { |
|
|
@ -429,156 +431,159 @@ export class ApiService { |
|
|
.map((c) => { |
|
|
.map((c) => { |
|
|
return { |
|
|
return { |
|
|
...c, |
|
|
...c, |
|
|
...this.nutrientSort.get(c["key"]), |
|
|
...this.nutrientSort.get(c['key']), |
|
|
}; |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.sort((a, b) => a["sort"]! - b["sort"]!), |
|
|
.sort((a, b) => a['sort']! - b['sort']!), |
|
|
}; |
|
|
} |
|
|
}), |
|
|
}), |
|
|
}; |
|
|
} |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveDish(v: AnyObject) { |
|
|
saveDish(v: AnyObject) { |
|
|
const body = Utils.objectToFormData(v); |
|
|
const body = Utils.objectToFormData(v) |
|
|
const method = v["id"] ? "post" : "put"; |
|
|
const method = v['id'] ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/dish", body); |
|
|
return this.http[method]<ResponseType>('/api/dish', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteDish(ids: string[]) { |
|
|
deleteDish(ids: string[]) { |
|
|
const params = Utils.objectToFormData({ ids: ids.join(",") }); |
|
|
const params = Utils.objectToFormData({ ids: ids.join(',') }) |
|
|
return this.http.delete<ResponseType>(`/api/dish`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/dish`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuStatusPage(p: {}, q: {}) { |
|
|
getMenuStatusPage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu/review?${params}`); |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu/review?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuPage(p: {}, q: {}) { |
|
|
getMenuPage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu?${params}`); |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuItem(id: string | number) { |
|
|
getMenuItem(id: string | number) { |
|
|
const params = Utils.objectStringify({ id }); |
|
|
const params = Utils.objectStringify({ id }) |
|
|
return this.http.get<ResponseType>(`/api/menu?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getCountByStatus() { |
|
|
getCountByStatus() { |
|
|
return this.http.get<ResponseType>(`/api/menu/review/count`); |
|
|
return this.http.get<ResponseType>(`/api/menu/review/count`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveMenu(v: AnyObject) { |
|
|
saveMenu(v: AnyObject) { |
|
|
const body = Utils.objectToFormData(v); |
|
|
const body = Utils.objectToFormData(v) |
|
|
const method = v["id"] ? "post" : "put"; |
|
|
const method = v['id'] ? 'post' : 'put' |
|
|
return this.http[method]<ResponseType>("/api/menu", body); |
|
|
return this.http[method]<ResponseType>('/api/menu', body) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 提交审核
|
|
|
// 提交审核
|
|
|
submitMenuForReview(id: string | number) { |
|
|
submitMenuForReview(id: string | number) { |
|
|
const params = Utils.objectToFormData({ id }); |
|
|
const params = Utils.objectToFormData({ id }) |
|
|
return this.http.put<ResponseType>(`/api/menu/review`, params); |
|
|
return this.http.put<ResponseType>(`/api/menu/review`, params) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
disableMenu(id: string | number) { |
|
|
disableMenu(id: string | number) { |
|
|
const params = Utils.objectToFormData({ id }); |
|
|
const params = Utils.objectToFormData({ id }) |
|
|
return this.http.delete<ResponseType>(`/api/menu/review`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/menu/review`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
reviewMenu(id: number, pass: boolean, reason?: string) { |
|
|
reviewMenu(id: number, pass: boolean, reason?: string) { |
|
|
const params = Utils.objectToFormData({ id, pass, reason }); |
|
|
const params = Utils.objectToFormData({ id, pass, reason }) |
|
|
return this.http.post<ResponseType>(`/api/menu/review`, params); |
|
|
return this.http.post<ResponseType>(`/api/menu/review`, params) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
release(id: string | number, startTime: Date, amount: number) { |
|
|
release(id: string | number, startTime: Date, amount: number) { |
|
|
// const endTime = addDays(startTime, amount);
|
|
|
// const endTime = addDays(startTime, amount);
|
|
|
const params = Utils.objectToFormData({ |
|
|
const params = Utils.objectToFormData({ |
|
|
id, |
|
|
id, |
|
|
startTime: format(startTime, "yyyy-MM-dd"), |
|
|
startTime: format(startTime, 'yyyy-MM-dd'), |
|
|
// endTime: format(endTime, "yyyy-MM-dd"),
|
|
|
// endTime: format(endTime, "yyyy-MM-dd"),
|
|
|
}); |
|
|
}) |
|
|
return this.http.put<ResponseType>(`/api/menu/release`, params); |
|
|
return this.http.put<ResponseType>(`/api/menu/release`, params) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
cancelRelease(id: string | number) { |
|
|
cancelRelease(id: string | number) { |
|
|
const params = Utils.objectToFormData({ id }); |
|
|
const params = Utils.objectToFormData({ id }) |
|
|
return this.http.delete<ResponseType>(`/api/menu/release`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/menu/release`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
deleteMenu(id: string | number) { |
|
|
deleteMenu(id: string | number) { |
|
|
const params = Utils.objectToFormData({ id }); |
|
|
const params = Utils.objectToFormData({ id }) |
|
|
return this.http.delete<ResponseType>(`/api/menu`, { body: params }); |
|
|
return this.http.delete<ResponseType>(`/api/menu`, { body: params }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuDist(menuId: number | string) { |
|
|
getMenuDist(menuId: number | string) { |
|
|
return this.http.get<ResponseType>(`/api/menu/dish?menuId=${menuId}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/dish?menuId=${menuId}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
saveMenuDist(d: {}) { |
|
|
saveMenuDist(d: {}) { |
|
|
return this.http.put<ResponseType>(`/api/menu/dish/batch`, d); |
|
|
return this.http.put<ResponseType>(`/api/menu/dish/batch`, d) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuReleasePage(p: {}, q: {}) { |
|
|
getMenuReleasePage(p: {}, q: {}) { |
|
|
const params = Utils.objectStringify({ ...p, ...q }); |
|
|
const params = Utils.objectStringify({ ...p, ...q }) |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu/release?${params}`).pipe( |
|
|
return this.http.get<ResponseType<PageResult>>(`/api/menu/release?${params}`).pipe( |
|
|
map((res) => { |
|
|
map((res) => { |
|
|
if (Array.isArray(res.body.content)) { |
|
|
if (Array.isArray(res.body.content)) { |
|
|
res.body.content = res.body.content.map((i) => ({ |
|
|
res.body.content = res.body.content.map((i) => ({ |
|
|
...i, |
|
|
...i, |
|
|
dateRange: `${format(new Date(i.startTime), "yyyy-MM-dd")}至${format(new Date(i.endTime), "yyyy-MM-dd")}`, |
|
|
dateRange: `${format(new Date(i.startTime), 'yyyy-MM-dd')}至${format( |
|
|
})); |
|
|
new Date(i.endTime), |
|
|
|
|
|
'yyyy-MM-dd', |
|
|
|
|
|
)}`,
|
|
|
|
|
|
})) |
|
|
} |
|
|
} |
|
|
return res; |
|
|
return res |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
exportMenu(id: number | string) { |
|
|
exportMenu(id: number | string) { |
|
|
return this.http |
|
|
return this.http |
|
|
.get<ResponseType>(`/api/menu/dish/export?id=${id}`, { |
|
|
.get<ResponseType>(`/api/menu/dish/export?id=${id}`, { |
|
|
observe: "response", |
|
|
observe: 'response', |
|
|
responseType: "blob" as "json", |
|
|
responseType: 'blob' as 'json', |
|
|
}) |
|
|
}) |
|
|
.pipe( |
|
|
.pipe( |
|
|
tap((res) => { |
|
|
tap((res) => { |
|
|
this.downLoadFile(res); |
|
|
this.downLoadFile(res) |
|
|
}) |
|
|
}), |
|
|
); |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAnalysis(id: string, day?: number, crow?: string) { |
|
|
getAnalysis(id: string, day?: number, crow?: string) { |
|
|
const params = Utils.objectStringify({ id, day, crow }); |
|
|
const params = Utils.objectStringify({ id, day, crow }) |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAnalysisEnergy(id: string, day?: number, crow?: string) { |
|
|
getAnalysisEnergy(id: string, day?: number, crow?: string) { |
|
|
const params = Utils.objectStringify({ id, day, crow }); |
|
|
const params = Utils.objectStringify({ id, day, crow }) |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/energy?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/energy?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAnalysisSugar(id: string, crow?: string) { |
|
|
getAnalysisSugar(id: string, crow?: string) { |
|
|
const params = Utils.objectStringify({ id, crow }); |
|
|
const params = Utils.objectStringify({ id, crow }) |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/sugar?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/sugar?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAnalysisPoly(id: string, crow?: string) { |
|
|
getAnalysisPoly(id: string, crow?: string) { |
|
|
const params = Utils.objectStringify({ id, crow }); |
|
|
const params = Utils.objectStringify({ id, crow }) |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/poly?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/poly?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getAnalysisRule(id: string, day?: number, crow?: string) { |
|
|
getAnalysisRule(id: string, day?: number, crow?: string) { |
|
|
const params = Utils.objectStringify({ id, day, crow }); |
|
|
const params = Utils.objectStringify({ id, day, crow }) |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/types?${params}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/analysis/types?${params}`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getCurrentDayDataVisList() { |
|
|
getCurrentDayDataVisList() { |
|
|
return this.http.get<ResponseType>(`/api/menu/display`); |
|
|
return this.http.get<ResponseType>(`/api/menu/display`) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getMenuDataVis(menuId: number) { |
|
|
getMenuDataVis(menuId: number) { |
|
|
// return this.http.get<ResponseType>(`/api/menu/dish`);
|
|
|
// return this.http.get<ResponseType>(`/api/menu/dish`);
|
|
|
return this.http.get<ResponseType>(`/api/menu/display?menuId=${menuId}`); |
|
|
return this.http.get<ResponseType>(`/api/menu/display?menuId=${menuId}`) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|