FPSMS-frontend
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 

144 wiersze
3.8 KiB

  1. "use server";
  2. import { cache } from 'react';
  3. import { Pageable, serverFetchBlob, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  4. //import { JobOrder, JoStatus, Machine, Operator } from ".";
  5. import { BASE_API_URL } from "@/config/api";
  6. import { revalidateTag } from "next/cache";
  7. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  8. import { FileResponse } from "@/app/api/pdf/actions";
  9. export interface GetBagInfoResponse {
  10. id: number;
  11. bagId: number;
  12. bagName: string;
  13. lotId: number;
  14. lotNo: string;
  15. stockOutLineId: number;
  16. code: string;
  17. balanceQty: number;
  18. }
  19. export const getBagInfo = cache(async () => {
  20. return serverFetchJson<GetBagInfoResponse[]>(
  21. `${BASE_API_URL}/bag/bagInfo`,
  22. {
  23. method: "GET",
  24. next: { tags: ["bagInfo"] },
  25. }
  26. );
  27. });
  28. export interface CreateJoBagConsumptionRequest {
  29. bagId: number;
  30. bagLotLineId: number;
  31. jobId: number;
  32. //startQty: number;
  33. consumedQty: number;
  34. scrapQty: number;
  35. }
  36. export const createJoBagConsumption = cache(async (request: CreateJoBagConsumptionRequest) => {
  37. return serverFetchJson<any>(
  38. `${BASE_API_URL}/bag/createJoBagConsumption`,
  39. {
  40. method: "POST",
  41. headers: { "Content-Type": "application/json" },
  42. body: JSON.stringify(request),
  43. }
  44. );
  45. });
  46. export interface BagUsageRecordResponse {
  47. id: number;
  48. bagId: number;
  49. bagLotLineId: number;
  50. jobId: number;
  51. jobOrderCode: string;
  52. stockOutLineId: number;
  53. startQty: number;
  54. consumedQty: number;
  55. scrapQty: number;
  56. endQty: number;
  57. date: string;
  58. time: string;
  59. bagName?: string;
  60. bagCode?: string;
  61. lotNo?: string;
  62. }
  63. // 添加 API 调用函数:
  64. export const getBagUsageRecords = cache(async () => {
  65. return serverFetchJson<BagUsageRecordResponse[]>(
  66. `${BASE_API_URL}/bag/bagUsageRecords`,
  67. {
  68. method: "GET",
  69. next: { tags: ["bagUsageRecords"] },
  70. }
  71. );
  72. });
  73. export interface BagSummaryResponse {
  74. id: number;
  75. bagName: string;
  76. bagCode: string;
  77. takenBagBalance: number;
  78. deleted: boolean;
  79. }
  80. export interface BagLotLineResponse {
  81. id: number;
  82. bagId: number;
  83. lotNo: string;
  84. stockOutLineId: number;
  85. startQty: number;
  86. consumedQty: number;
  87. scrapQty: number;
  88. balanceQty: number;
  89. firstUseDate: string;
  90. lastUseDate: string;
  91. }
  92. export interface BagConsumptionResponse {
  93. id: number;
  94. bagId: number;
  95. bagLotLineId: number;
  96. jobId: number;
  97. jobOrderCode: string;
  98. stockOutLineId: number;
  99. startQty: number;
  100. consumedQty: number;
  101. scrapQty: number;
  102. endQty: number;
  103. date: string;
  104. time: string;
  105. }
  106. export const fetchBags = cache(async () =>
  107. serverFetchJson<BagSummaryResponse[]>(`${BASE_API_URL}/bag/bags`, { method: "GET" })
  108. );
  109. export const fetchBagLotLines = cache(async (bagId: number) =>
  110. serverFetchJson<BagLotLineResponse[]>(`${BASE_API_URL}/bag/bags/${bagId}/lot-lines`, { method: "GET" })
  111. );
  112. export const fetchBagConsumptions = cache(async (bagLotLineId: number) =>
  113. serverFetchJson<BagConsumptionResponse[]>(`${BASE_API_URL}/bag/lot-lines/${bagLotLineId}/consumptions`, { method: "GET" })
  114. );
  115. export interface SoftDeleteBagResponse {
  116. id: number | null;
  117. code: string | null;
  118. name: string | null;
  119. type: string | null;
  120. message: string | null;
  121. errorPosition: string | null;
  122. entity: any | null;
  123. }
  124. export const softDeleteBagByItemId = async (itemId: number): Promise<SoftDeleteBagResponse> => {
  125. const response = await serverFetchJson<SoftDeleteBagResponse>(
  126. `${BASE_API_URL}/bag/by-item/${itemId}/soft-delete`,
  127. {
  128. method: "PUT",
  129. headers: { "Content-Type": "application/json" },
  130. }
  131. );
  132. revalidateTag("bagInfo");
  133. revalidateTag("bags");
  134. return response;
  135. };