FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

176 строки
4.7 KiB

  1. "use server";
  2. // import { serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  3. // import { BASE_API_URL } from "@/config/api";
  4. import {
  5. serverFetchJson,
  6. serverFetchWithNoContent,
  7. } from "../../utils/fetchUtil";
  8. import { BASE_API_URL } from "../../../config/api";
  9. import { revalidateTag } from "next/cache";
  10. import { cache } from "react";
  11. export interface ShopAndTruck{
  12. id: number;
  13. name: String;
  14. code: String;
  15. addr1: String;
  16. addr2: String;
  17. addr3: String;
  18. contactNo: number;
  19. type: String;
  20. contactEmail: String;
  21. contactName: String;
  22. truckLanceCode: String;
  23. DepartureTime: String;
  24. LoadingSequence?: number | null;
  25. districtReference: Number;
  26. Store_id: Number;
  27. remark?: String | null;
  28. truckId?: number;
  29. }
  30. export interface Shop{
  31. id: number;
  32. name: String;
  33. code: String;
  34. addr3: String;
  35. }
  36. export interface Truck{
  37. id?: number;
  38. truckLanceCode: String;
  39. departureTime: String | number[];
  40. loadingSequence: number;
  41. districtReference: Number;
  42. storeId: Number | String;
  43. remark?: String | null;
  44. }
  45. export interface SaveTruckLane {
  46. id: number;
  47. truckLanceCode: string;
  48. departureTime: string;
  49. loadingSequence: number;
  50. districtReference: number;
  51. storeId: string;
  52. remark?: string | null;
  53. }
  54. export interface DeleteTruckLane {
  55. id: number;
  56. }
  57. export interface UpdateLoadingSequenceRequest {
  58. id: number;
  59. loadingSequence: number;
  60. }
  61. export interface SaveTruckRequest {
  62. id?: number | null;
  63. store_id: string;
  64. truckLanceCode: string;
  65. departureTime: string;
  66. shopId: number;
  67. shopName: string;
  68. shopCode: string;
  69. loadingSequence: number;
  70. districtReference?: number | null;
  71. remark?: string | null;
  72. }
  73. export interface MessageResponse {
  74. id: number | null;
  75. name: string | null;
  76. code: string | null;
  77. type: string;
  78. message: string;
  79. errorPosition: string | null;
  80. entity: Truck | null;
  81. }
  82. export const fetchAllShopsAction = cache(async (params?: Record<string, string | number | null>) => {
  83. const endpoint = `${BASE_API_URL}/shop/combo/allShop`;
  84. const qs = params
  85. ? Object.entries(params)
  86. .filter(([, v]) => v !== null && v !== undefined && String(v).trim() !== "")
  87. .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
  88. .join("&")
  89. : "";
  90. const url = qs ? `${endpoint}?${qs}` : endpoint;
  91. return serverFetchJson<ShopAndTruck[]>(url, {
  92. method: "GET",
  93. headers: { "Content-Type": "application/json" },
  94. });
  95. });
  96. export const findTruckLaneByShopIdAction = cache(async (shopId: number | string) => {
  97. const endpoint = `${BASE_API_URL}/truck/findTruckLane/${shopId}`;
  98. return serverFetchJson<Truck[]>(endpoint, {
  99. method: "GET",
  100. headers: { "Content-Type": "application/json" },
  101. });
  102. });
  103. export const updateTruckLaneAction = async (data: SaveTruckLane) => {
  104. const endpoint = `${BASE_API_URL}/truck/updateTruckLane`;
  105. return serverFetchJson<MessageResponse>(endpoint, {
  106. method: "POST",
  107. body: JSON.stringify(data),
  108. headers: { "Content-Type": "application/json" },
  109. });
  110. };
  111. export const deleteTruckLaneAction = async (data: DeleteTruckLane) => {
  112. const endpoint = `${BASE_API_URL}/truck/deleteTruckLane`;
  113. return serverFetchJson<MessageResponse>(endpoint, {
  114. method: "POST",
  115. body: JSON.stringify(data),
  116. headers: { "Content-Type": "application/json" },
  117. });
  118. };
  119. export const createTruckAction = async (data: SaveTruckRequest) => {
  120. const endpoint = `${BASE_API_URL}/truck/create`;
  121. return serverFetchJson<MessageResponse>(endpoint, {
  122. method: "POST",
  123. body: JSON.stringify(data),
  124. headers: { "Content-Type": "application/json" },
  125. });
  126. };
  127. export const findAllUniqueTruckLaneCombinationsAction = cache(async () => {
  128. const endpoint = `${BASE_API_URL}/truck/findAllUniqueTruckLanceCodeAndRemarkCombinations`;
  129. return serverFetchJson<Truck[]>(endpoint, {
  130. method: "GET",
  131. headers: { "Content-Type": "application/json" },
  132. });
  133. });
  134. export const findAllShopsByTruckLanceCodeAndRemarkAction = cache(async (truckLanceCode: string, remark: string) => {
  135. const endpoint = `${BASE_API_URL}/truck/findAllFromShopAndTruckByTruckLanceCodeAndRemarkAndDeletedFalse`;
  136. const url = `${endpoint}?truckLanceCode=${encodeURIComponent(truckLanceCode)}&remark=${encodeURIComponent(remark)}`;
  137. return serverFetchJson<ShopAndTruck[]>(url, {
  138. method: "GET",
  139. headers: { "Content-Type": "application/json" },
  140. });
  141. });
  142. export const updateLoadingSequenceAction = async (data: UpdateLoadingSequenceRequest) => {
  143. const endpoint = `${BASE_API_URL}/truck/updateLoadingSequence`;
  144. return serverFetchJson<MessageResponse>(endpoint, {
  145. method: "POST",
  146. body: JSON.stringify(data),
  147. headers: { "Content-Type": "application/json" },
  148. });
  149. };