FPSMS-frontend
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.
 
 

130 line
3.2 KiB

  1. "use server";
  2. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  3. import { serverFetchJson } from "@/app/utils/fetchUtil";
  4. import { BASE_API_URL } from "@/config/api";
  5. import { cache } from "react";
  6. import { DetailedProdScheduleLineBomMaterialResult, DetailedProdScheduleLineResult, ScheduleType } from ".";
  7. import { revalidateTag } from "next/cache";
  8. export interface SearchProdSchedule {
  9. scheduleAt?: string;
  10. schedulePeriod?: string;
  11. schedulePeriodTo?: string;
  12. totalEstProdCount?: number;
  13. types?: ScheduleType[];
  14. pageSize?: number;
  15. pageNum?: number;
  16. }
  17. export interface ProdScheduleResult {
  18. id: number;
  19. scheduleAt: number[];
  20. schedulePeriod: number[];
  21. schedulePeriodTo: number[];
  22. totalEstProdCount: number;
  23. totalFGType: number;
  24. type: string;
  25. }
  26. export interface ProdScheduleResultByPage {
  27. total: number;
  28. records: ProdScheduleResult[];
  29. }
  30. export interface ReleaseProdScheduleInputs {
  31. id: number;
  32. demandQty: number;
  33. }
  34. export interface ReleaseProdScheduleResponse {
  35. id: number;
  36. code: string;
  37. entity: {
  38. prodScheduleLines: DetailedProdScheduleLineResult[];
  39. };
  40. message: string;
  41. }
  42. export interface SaveProdScheduleResponse {
  43. id: number;
  44. code: string;
  45. entity: {
  46. bomMaterials: DetailedProdScheduleLineBomMaterialResult[]
  47. };
  48. message: string;
  49. }
  50. export const fetchProdSchedules = cache(
  51. async (data: SearchProdSchedule | null) => {
  52. const params = convertObjToURLSearchParams<SearchProdSchedule>(data);
  53. // console.log(params)
  54. return serverFetchJson<ProdScheduleResultByPage>(
  55. `${BASE_API_URL}/productionSchedule/getRecordByPage?${params}`,
  56. {
  57. method: "GET",
  58. headers: { "Content-Type": "application/json" },
  59. next: {
  60. tags: ["prodSchedules"],
  61. },
  62. },
  63. );
  64. },
  65. );
  66. export const testRoughSchedule = cache(async () => {
  67. return serverFetchJson(
  68. `${BASE_API_URL}/productionSchedule/testRoughSchedule`,
  69. {
  70. method: "GET",
  71. headers: { "Content-Type": "application/json" },
  72. next: {
  73. tags: ["prodSchedules"],
  74. },
  75. },
  76. );
  77. });
  78. export const testDetailedSchedule = cache(async (date?: string) => {
  79. const queryStr = convertObjToURLSearchParams({genDate: date})
  80. return serverFetchJson(
  81. `${BASE_API_URL}/productionSchedule/testDetailedSchedule?${queryStr}`,
  82. {
  83. method: "GET",
  84. headers: { "Content-Type": "application/json" },
  85. next: {
  86. tags: ["prodSchedules"],
  87. },
  88. },
  89. );
  90. });
  91. export const releaseProdScheduleLine = cache(async (data: ReleaseProdScheduleInputs) => {
  92. const response = serverFetchJson<ReleaseProdScheduleResponse>(
  93. `${BASE_API_URL}/productionSchedule/detail/detailed/releaseLine`,
  94. {
  95. method: "POST",
  96. body: JSON.stringify(data),
  97. headers: { "Content-Type": "application/json" },
  98. }
  99. );
  100. revalidateTag("prodSchedules");
  101. return response;
  102. })
  103. export const saveProdScheduleLine = cache(async (data: ReleaseProdScheduleInputs) => {
  104. const response = serverFetchJson<SaveProdScheduleResponse>(
  105. `${BASE_API_URL}/productionSchedule/detail/detailed/save`,
  106. {
  107. method: "POST",
  108. body: JSON.stringify(data),
  109. headers: { "Content-Type": "application/json" },
  110. }
  111. );
  112. revalidateTag("prodSchedules");
  113. return response;
  114. })