FPSMS-frontend
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.ts 23 KiB

3週間前
2週間前
1ヶ月前
2ヶ月前
2週間前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
1ヶ月前
2ヶ月前
1ヶ月前
2ヶ月前
2ヶ月前
1ヶ月前
4週間前
2週間前
4週間前
1ヶ月前
1ヶ月前
4週間前
3週間前
3週間前
4週間前
2週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
3週間前
1ヶ月前
3週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
1ヶ月前
2週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
4週間前
4週間前
3週間前
4週間前
1ヶ月前
4週間前
4週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
4週間前
2週間前
4週間前
1ヶ月前
4週間前
1ヶ月前
2週間前
1ヶ月前
4週間前
1ヶ月前
1ヶ月前
1ヶ月前
2週間前
1ヶ月前
2週間前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
1ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
3週間前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
3週間前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. "use server";
  2. import { cache } from 'react';
  3. import { Pageable, 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. export interface SaveJo {
  9. bomId: number;
  10. planStart: string;
  11. planEnd: string;
  12. reqQty: number;
  13. type: string;
  14. //jobType?: string;
  15. jobTypeId?: number;
  16. }
  17. export interface SaveJoResponse {
  18. id: number;
  19. }
  20. export interface SearchJoResultRequest extends Pageable {
  21. code: string;
  22. itemName?: string;
  23. planStart?: string;
  24. planStartTo?: string;
  25. jobTypeName?: string;
  26. }
  27. export interface productProcessLineQtyRequest {
  28. productProcessLineId: number;
  29. outputFromProcessQty: number;
  30. outputFromProcessUom: string;
  31. defectQty: number;
  32. defectUom: string;
  33. scrapQty: number;
  34. scrapUom: string;
  35. }
  36. export interface SearchJoResultResponse {
  37. records: JobOrder[];
  38. total: number;
  39. }
  40. // DEPRECIATED
  41. export interface SearchJoResult {
  42. id: number;
  43. code: string;
  44. itemCode: string;
  45. name: string;
  46. reqQty: number;
  47. uom: string;
  48. status: JoStatus;
  49. }
  50. export interface UpdateJoRequest {
  51. id: number;
  52. status: string;
  53. }
  54. // For Jo Button Actions
  55. export interface CommonActionJoRequest {
  56. id: number;
  57. }
  58. export interface CommonActionJoResponse {
  59. id: number;
  60. entity: { status: JoStatus }
  61. }
  62. // For Jo Process
  63. export interface IsOperatorExistResponse<T> {
  64. id: number | null;
  65. name: string;
  66. code: string;
  67. type?: string;
  68. message: string | null;
  69. errorPosition: string | keyof T;
  70. entity: T;
  71. }
  72. export interface isCorrectMachineUsedResponse<T> {
  73. id: number | null;
  74. name: string;
  75. code: string;
  76. type?: string;
  77. message: string | null;
  78. errorPosition: string | keyof T;
  79. entity: T;
  80. }
  81. export interface JobOrderDetail {
  82. id: number;
  83. code: string;
  84. name: string;
  85. reqQty: number;
  86. uom: string;
  87. pickLines: any[];
  88. jobTypeName: string;
  89. status: string;
  90. }
  91. export interface UnassignedJobOrderPickOrder {
  92. pickOrderId: number;
  93. pickOrderCode: string;
  94. pickOrderConsoCode: string;
  95. pickOrderTargetDate: string;
  96. pickOrderStatus: string;
  97. jobOrderId: number;
  98. jobOrderCode: string;
  99. jobOrderName: string;
  100. reqQty: number;
  101. uom: string;
  102. planStart: string;
  103. planEnd: string;
  104. }
  105. export interface AssignJobOrderResponse {
  106. id: number | null;
  107. code: string | null;
  108. name: string | null;
  109. type: string | null;
  110. message: string | null;
  111. errorPosition: string | null;
  112. }
  113. export interface PrintPickRecordRequest{
  114. pickOrderId: number;
  115. printerId: number;
  116. printQty: number;
  117. }
  118. export interface PrintPickRecordResponse{
  119. success: boolean;
  120. message?: string
  121. }
  122. export const recordSecondScanIssue = cache(async (
  123. pickOrderId: number,
  124. itemId: number,
  125. data: {
  126. qty: number; // verified qty (actual pick qty)
  127. missQty?: number; // 添加:miss qty
  128. badItemQty?: number; // 添加:bad item qty
  129. isMissing: boolean;
  130. isBad: boolean;
  131. reason: string;
  132. createdBy: number;
  133. type?: string; // type 也应该是可选的
  134. }
  135. ) => {
  136. return serverFetchJson<any>(
  137. `${BASE_API_URL}/jo/second-scan-issue/${pickOrderId}/${itemId}`,
  138. {
  139. method: "POST",
  140. headers: { "Content-Type": "application/json" },
  141. body: JSON.stringify(data),
  142. next: { tags: ["jo-second-scan"] },
  143. },
  144. );
  145. });
  146. export interface ProductProcessResponse {
  147. id: number;
  148. productProcessCode: string;
  149. status: string;
  150. startTime?: string;
  151. endTime?: string;
  152. date: string;
  153. bomId?: number;
  154. jobOrderId?: number;
  155. }
  156. export interface ProductProcessLineResponse {
  157. id: number,
  158. bomprocessId: number,
  159. operatorId: number,
  160. operatorName: string,
  161. equipmentId: number,
  162. handlerId: number,
  163. seqNo: number,
  164. name: string,
  165. description: string,
  166. equipment_name: string,
  167. equipmentDetailCode: string,
  168. status: string,
  169. byproductId: number,
  170. byproductName: string,
  171. byproductQty: number,
  172. byproductUom: string,
  173. scrapQty: number,
  174. defectQty: number,
  175. defectUom: string,
  176. outputFromProcessQty: number,
  177. outputFromProcessUom: string,
  178. durationInMinutes: number,
  179. prepTimeInMinutes: number,
  180. postProdTimeInMinutes: number,
  181. startTime: string,
  182. endTime: string,
  183. }
  184. export interface ProductProcessWithLinesResponse {
  185. id: number;
  186. productProcessCode: string;
  187. status: string;
  188. startTime?: string;
  189. endTime?: string;
  190. date: string;
  191. bomId?: number;
  192. jobOrderId?: number;
  193. jobOrderCode: string;
  194. jobOrderStatus: string;
  195. jobType: string;
  196. isDark: string;
  197. isDense: number;
  198. isFloat: string;
  199. scrapRate: number;
  200. allergicSubstance: string;
  201. itemId: number;
  202. itemCode: string;
  203. itemName: string;
  204. outputQty: number;
  205. outputQtyUom: string;
  206. productionPriority: number;
  207. jobOrderLines: JobOrderLineInfo[];
  208. productProcessLines: ProductProcessLineResponse[];
  209. }
  210. export interface UpdateProductProcessLineQtyRequest {
  211. productProcessLineId: number;
  212. outputFromProcessQty: number;
  213. outputFromProcessUom: string;
  214. byproductName: string;
  215. byproductQty: number;
  216. byproductUom: string;
  217. defectQty: number;
  218. defectUom: string;
  219. defect2Qty: number;
  220. defect2Uom: string;
  221. defect3Qty: number;
  222. defect3Uom: string;
  223. defectDescription: string;
  224. defectDescription2: string;
  225. defectDescription3: string;
  226. scrapQty: number;
  227. scrapUom: string;
  228. }
  229. export interface UpdateProductProcessLineQtyResponse {
  230. id: number;
  231. outputFromProcessQty: number;
  232. outputFromProcessUom: string;
  233. defectQty: number;
  234. defectUom: string;
  235. defect2Qty: number;
  236. defect2Uom: string;
  237. defect3Qty: number;
  238. defect3Uom: string;
  239. defectDescription: string;
  240. defectDescription2: string;
  241. defectDescription3: string;
  242. scrapQty: number;
  243. scrapUom: string;
  244. byproductName: string;
  245. byproductQty: number;
  246. byproductUom: string;
  247. }
  248. export interface AllProductProcessResponse {
  249. id: number;
  250. productProcessCode: string;
  251. status: string;
  252. startTime?: string;
  253. endTime?: string;
  254. date: string;
  255. bomId?: number;
  256. }
  257. export interface AllJoborderProductProcessInfoResponse {
  258. id: number;
  259. productProcessCode: string;
  260. status: string;
  261. startTime?: string;
  262. endTime?: string;
  263. date: string;
  264. bomId?: number;
  265. itemName: string;
  266. requiredQty: number;
  267. jobOrderId: number;
  268. stockInLineId: number;
  269. jobOrderCode: string;
  270. productProcessLineCount: number;
  271. FinishedProductProcessLineCount: number;
  272. lines: ProductProcessInfoResponse[];
  273. }
  274. export interface ProductProcessInfoResponse {
  275. id: number;
  276. operatorId?: number;
  277. operatorName?: string;
  278. equipmentId?: number;
  279. equipmentName?: string;
  280. startTime?: string;
  281. endTime?: string;
  282. status: string;
  283. }
  284. export interface ProductProcessLineQrscanUpadteRequest {
  285. productProcessLineId: number;
  286. //operatorId?: number;
  287. //equipmentId?: number;
  288. equipmentTypeSubTypeEquipmentNo?: string;
  289. staffNo?: string;
  290. }
  291. export interface ProductProcessLineDetailResponse {
  292. id: number,
  293. productProcessId: number,
  294. bomProcessId: number,
  295. operatorId: number,
  296. equipmentType: string,
  297. operatorName: string,
  298. handlerId: number,
  299. seqNo: number,
  300. isDark: string,
  301. isDense: number,
  302. isFloat: string,
  303. outputQtyUom: string,
  304. outputQty: number,
  305. pickOrderId: number,
  306. jobOrderCode: string,
  307. jobOrderId: number,
  308. name: string,
  309. description: string,
  310. equipment: string,
  311. startTime: string,
  312. endTime: string,
  313. defectQty: number,
  314. defectUom: string,
  315. scrapQty: number,
  316. scrapUom: string,
  317. byproductId: number,
  318. byproductName: string,
  319. byproductQty: number,
  320. byproductUom: string | undefined,
  321. totalStockQty: number,
  322. insufficientStockQty: number,
  323. sufficientStockQty: number,
  324. productionPriority: number,
  325. productProcessLines: ProductProcessLineInfoResponse[],
  326. jobOrderLineInfo: JobOrderLineInfo[],
  327. }
  328. export interface JobOrderProcessLineDetailResponse {
  329. id: number;
  330. productProcessId: number;
  331. bomProcessId: number;
  332. operatorId: number;
  333. equipmentType: string | null;
  334. operatorName: string;
  335. handlerId: number;
  336. seqNo: number;
  337. durationInMinutes: number;
  338. name: string;
  339. description: string;
  340. equipmentId: number;
  341. startTime: string | number[]; // API 返回的是数组格式
  342. endTime: string | number[]; // API 返回的是数组格式
  343. status: string;
  344. outputFromProcessQty: number;
  345. outputFromProcessUom: string;
  346. defectQty: number;
  347. defectUom: string;
  348. defectDescription: string;
  349. defectQty2: number;
  350. defectUom2: string;
  351. defectDescription2: string;
  352. defectQty3: number;
  353. defectUom3: string;
  354. defectDescription3: string;
  355. scrapQty: number;
  356. scrapUom: string;
  357. byproductId: number;
  358. byproductName: string;
  359. byproductQty: number;
  360. byproductUom: string;
  361. }
  362. export interface JobOrderLineInfo {
  363. id: number,
  364. jobOrderId: number,
  365. jobOrderCode: string,
  366. itemId: number,
  367. itemCode: string,
  368. itemName: string,
  369. reqQty: number,
  370. stockQty: number,
  371. uom: string,
  372. shortUom: string,
  373. availableStatus: string,
  374. bomProcessId: number,
  375. bomProcessSeqNo: number,
  376. }
  377. export interface ProductProcessLineInfoResponse {
  378. id: number,
  379. bomprocessId: number,
  380. operatorId: number,
  381. operatorName: string,
  382. equipmentId: number,
  383. handlerId: number,
  384. seqNo: number,
  385. name: string,
  386. description: string,
  387. equipment_name: string,
  388. equipmentDetailCode: string,
  389. status: string,
  390. byproductId: number,
  391. byproductName: string,
  392. byproductQty: number,
  393. byproductUom: string,
  394. scrapQty: number,
  395. defectQty: number,
  396. defectUom: string,
  397. durationInMinutes: number,
  398. prepTimeInMinutes: number,
  399. postProdTimeInMinutes: number,
  400. outputFromProcessQty: number,
  401. outputFromProcessUom: string,
  402. startTime: string,
  403. endTime: string
  404. }
  405. export interface AllJoPickOrderResponse {
  406. id: number;
  407. pickOrderId: number | null;
  408. pickOrderCode: string | null;
  409. jobOrderId: number | null;
  410. jobOrderCode: string | null;
  411. jobOrderTypeId: number | null;
  412. jobOrderType: string | null;
  413. itemId: number;
  414. itemName: string;
  415. reqQty: number;
  416. uomId: number;
  417. uomName: string;
  418. jobOrderStatus: string;
  419. finishedPickOLineCount: number;
  420. }
  421. export interface UpdateJoPickOrderHandledByRequest {
  422. pickOrderId: number;
  423. itemId: number;
  424. userId: number;
  425. }
  426. export interface JobTypeResponse {
  427. id: number;
  428. name: string;
  429. }
  430. export const deleteJobOrder=cache(async (jobOrderId: number) => {
  431. return serverFetchJson<any>(
  432. `${BASE_API_URL}/jo/demo/deleteJobOrder/${jobOrderId}`,
  433. {
  434. method: "POST",
  435. }
  436. );
  437. });
  438. export const fetchAllJobTypes = cache(async () => {
  439. return serverFetchJson<JobTypeResponse[]>(
  440. `${BASE_API_URL}/jo/jobTypes`,
  441. {
  442. method: "GET",
  443. }
  444. );
  445. });
  446. export const updateJoPickOrderHandledBy = cache(async (request: UpdateJoPickOrderHandledByRequest) => {
  447. return serverFetchJson<any>(
  448. `${BASE_API_URL}/jo/update-jo-pick-order-handled-by`,
  449. {
  450. method: "POST",
  451. body: JSON.stringify(request),
  452. headers: { "Content-Type": "application/json" },
  453. },
  454. );
  455. });
  456. export const fetchJobOrderLotsHierarchicalByPickOrderId = cache(async (pickOrderId: number) => {
  457. return serverFetchJson<any>(
  458. `${BASE_API_URL}/jo/all-lots-hierarchical-by-pick-order/${pickOrderId}`,
  459. {
  460. method: "GET",
  461. next: { tags: ["jo-hierarchical"] },
  462. },
  463. );
  464. });
  465. export const fetchAllJoPickOrders = cache(async () => {
  466. return serverFetchJson<AllJoPickOrderResponse[]>(
  467. `${BASE_API_URL}/jo/AllJoPickOrder`,
  468. {
  469. method: "GET",
  470. }
  471. );
  472. });
  473. export const fetchProductProcessLineDetail = cache(async (lineId: number) => {
  474. return serverFetchJson<JobOrderProcessLineDetailResponse>(
  475. `${BASE_API_URL}/product-process/Demo/ProcessLine/detail/${lineId}`,
  476. {
  477. method: "GET",
  478. }
  479. );
  480. });
  481. export const updateProductProcessLineQty = cache(async (request: UpdateProductProcessLineQtyRequest) => {
  482. return serverFetchJson<UpdateProductProcessLineQtyResponse>(
  483. `${BASE_API_URL}/product-process/Demo/ProcessLine/update/qty/${request.productProcessLineId}`,
  484. {
  485. method: "POST",
  486. headers: { "Content-Type": "application/json" },
  487. body: JSON.stringify(request),
  488. }
  489. );
  490. });
  491. export const updateProductProcessLineQrscan = cache(async (request: ProductProcessLineQrscanUpadteRequest) => {
  492. const requestBody: any = {
  493. productProcessLineId: request.productProcessLineId,
  494. //operatorId: request.operatorId,
  495. //equipmentId: request.equipmentId,
  496. equipmentTypeSubTypeEquipmentNo: request.equipmentTypeSubTypeEquipmentNo,
  497. staffNo: request.staffNo,
  498. };
  499. if (request.equipmentTypeSubTypeEquipmentNo !== undefined) {
  500. requestBody["EquipmentType-SubType-EquipmentNo"] = request.equipmentTypeSubTypeEquipmentNo;
  501. }
  502. return serverFetchJson<any>(
  503. `${BASE_API_URL}/product-process/Demo/update`,
  504. {
  505. method: "POST",
  506. headers: { "Content-Type": "application/json" },
  507. body: JSON.stringify(requestBody),
  508. }
  509. );
  510. });
  511. export const fetchAllJoborderProductProcessInfo = cache(async () => {
  512. return serverFetchJson<AllJoborderProductProcessInfoResponse[]>(
  513. `${BASE_API_URL}/product-process/Demo/Process/all`,
  514. {
  515. method: "GET",
  516. next: { tags: ["productProcess"] },
  517. }
  518. );
  519. });
  520. /*
  521. export const updateProductProcessLineQty = async (request: UpdateProductProcessLineQtyRequest) => {
  522. return serverFetchJson<UpdateProductProcessLineQtyResponse>(
  523. `${BASE_API_URL}/product-process/lines/${request.productProcessLineId}/update/qty`,
  524. {
  525. method: "POST",
  526. headers: { "Content-Type": "application/json" },
  527. body: JSON.stringify(request),
  528. }
  529. );
  530. };
  531. */
  532. export const startProductProcessLine = async (lineId: number) => {
  533. return serverFetchJson<any>(
  534. `${BASE_API_URL}/product-process/Demo/ProcessLine/start/${lineId}`,
  535. {
  536. method: "POST",
  537. headers: { "Content-Type": "application/json" },
  538. }
  539. );
  540. };
  541. export const completeProductProcessLine = async (lineId: number) => {
  542. return serverFetchJson<any>(
  543. `${BASE_API_URL}/product-process/demo/ProcessLine/complete/${lineId}`,
  544. {
  545. method: "POST",
  546. headers: { "Content-Type": "application/json" },
  547. }
  548. );
  549. };
  550. // 查询所有 production processes
  551. export const fetchProductProcesses = cache(async () => {
  552. return serverFetchJson<{ content: ProductProcessResponse[] }>(
  553. `${BASE_API_URL}/product-process`,
  554. {
  555. method: "GET",
  556. next: { tags: ["productProcess"] },
  557. }
  558. );
  559. });
  560. // 根据 ID 查询
  561. export const fetchProductProcessById = cache(async (id: number) => {
  562. return serverFetchJson<ProductProcessResponse>(
  563. `${BASE_API_URL}/product-process/${id}`,
  564. {
  565. method: "GET",
  566. next: { tags: ["productProcess"] },
  567. }
  568. );
  569. });
  570. // 根据 Job Order ID 查询
  571. export const fetchProductProcessesByJobOrderId = cache(async (jobOrderId: number) => {
  572. return serverFetchJson<ProductProcessWithLinesResponse[]>(
  573. `${BASE_API_URL}/product-process/demo/joid/${jobOrderId}`,
  574. {
  575. method: "GET",
  576. next: { tags: ["productProcess"] },
  577. }
  578. );
  579. });
  580. // 获取 process 的所有 lines
  581. export const fetchProductProcessLines = cache(async (processId: number) => {
  582. return serverFetchJson<ProductProcessLineResponse[]>(
  583. `${BASE_API_URL}/product-process/${processId}/lines`,
  584. {
  585. method: "GET",
  586. next: { tags: ["productProcessLines"] },
  587. }
  588. );
  589. });
  590. // 创建 production process
  591. export const createProductProcess = async (data: {
  592. bomId: number;
  593. jobOrderId?: number;
  594. date?: string;
  595. }) => {
  596. return serverFetchJson<{ id: number; productProcessCode: string; linesCreated: number }>(
  597. `${BASE_API_URL}/product-process`,
  598. {
  599. method: "POST",
  600. headers: { "Content-Type": "application/json" },
  601. body: JSON.stringify(data),
  602. }
  603. );
  604. };
  605. // 更新 line 产出数据
  606. export const updateLineOutput = async (lineId: number, data: {
  607. outputQty?: number;
  608. outputUom?: string;
  609. defectQty?: number;
  610. defectUom?: string;
  611. scrapQty?: number;
  612. scrapUom?: string;
  613. byproductName?: string;
  614. byproductQty?: number;
  615. byproductUom?: string;
  616. }) => {
  617. return serverFetchJson<ProductProcessLineResponse>(
  618. `${BASE_API_URL}/product-process/lines/${lineId}/output`,
  619. {
  620. method: "PUT",
  621. headers: { "Content-Type": "application/json" },
  622. body: JSON.stringify(data),
  623. }
  624. );
  625. };
  626. export const updateSecondQrScanStatus = cache(async (pickOrderId: number, itemId: number, userId: number, qty: number) => {
  627. return serverFetchJson<any>(
  628. `${BASE_API_URL}/jo/update-match-status`,
  629. {
  630. method: "POST",
  631. body: JSON.stringify({
  632. pickOrderId,
  633. itemId,
  634. userId,
  635. qty
  636. }),
  637. headers: {
  638. 'Content-Type': 'application/json',
  639. },
  640. next: { tags: ["update-match-status"] },
  641. },
  642. );
  643. });
  644. export const submitSecondScanQuantity = cache(async (
  645. pickOrderId: number,
  646. itemId: number,
  647. data: { qty: number; isMissing?: boolean; isBad?: boolean; reason?: string }
  648. ) => {
  649. return serverFetchJson<any>(
  650. `${BASE_API_URL}/jo/second-scan-submit/${pickOrderId}/${itemId}`,
  651. {
  652. method: "POST",
  653. headers: { "Content-Type": "application/json" },
  654. body: JSON.stringify(data),
  655. next: { tags: ["jo-second-scan"] },
  656. },
  657. );
  658. });
  659. // 获取未分配的 Job Order pick orders
  660. export const fetchUnassignedJobOrderPickOrders = cache(async () => {
  661. return serverFetchJson<UnassignedJobOrderPickOrder[]>(
  662. `${BASE_API_URL}/jo/unassigned-job-order-pick-orders`,
  663. {
  664. method: "GET",
  665. next: { tags: ["jo-unassigned"] },
  666. },
  667. );
  668. });
  669. // 分配 Job Order pick order 给用户
  670. export const assignJobOrderPickOrder = async (pickOrderId: number, userId: number) => {
  671. return serverFetchJson<AssignJobOrderResponse>(
  672. `${BASE_API_URL}/jo/assign-job-order-pick-order/${pickOrderId}/${userId}`,
  673. {
  674. method: "POST",
  675. headers: { "Content-Type": "application/json" },
  676. }
  677. );
  678. };
  679. // 获取 Job Order 分层数据
  680. export const fetchJobOrderLotsHierarchical = cache(async (userId: number) => {
  681. return serverFetchJson<any>(
  682. `${BASE_API_URL}/jo/all-lots-hierarchical/${userId}`,
  683. {
  684. method: "GET",
  685. next: { tags: ["jo-hierarchical"] },
  686. },
  687. );
  688. });
  689. export const fetchCompletedJobOrderPickOrders = cache(async (userId: number) => {
  690. return serverFetchJson<any>(
  691. `${BASE_API_URL}/jo/completed-job-order-pick-orders/${userId}`,
  692. {
  693. method: "GET",
  694. next: { tags: ["jo-completed"] },
  695. },
  696. );
  697. });
  698. // 获取已完成的 Job Order pick orders
  699. export const fetchCompletedJobOrderPickOrdersrecords = cache(async (userId: number) => {
  700. return serverFetchJson<any>(
  701. `${BASE_API_URL}/jo/completed-job-order-pick-orders-only/${userId}`,
  702. {
  703. method: "GET",
  704. next: { tags: ["jo-completed"] },
  705. },
  706. );
  707. });
  708. // 获取已完成的 Job Order pick order records
  709. export const fetchCompletedJobOrderPickOrderRecords = cache(async (userId: number) => {
  710. return serverFetchJson<any[]>(
  711. `${BASE_API_URL}/jo/completed-job-order-pick-order-records/${userId}`,
  712. {
  713. method: "GET",
  714. next: { tags: ["jo-records"] },
  715. },
  716. );
  717. });
  718. export const fetchJobOrderDetailByCode = cache(async (code: string) => {
  719. return serverFetchJson<JobOrderDetail>(
  720. `${BASE_API_URL}/jo/detailByCode/${code}`,
  721. {
  722. method: "GET",
  723. next: { tags: ["jo"] },
  724. },
  725. );
  726. });
  727. export const isOperatorExist = async (username: string) => {
  728. const isExist = await serverFetchJson<IsOperatorExistResponse<Operator>>(
  729. `${BASE_API_URL}/jop/isOperatorExist`,
  730. {
  731. method: "POST",
  732. body: JSON.stringify({ username }),
  733. headers: { "Content-Type": "application/json" },
  734. },
  735. );
  736. revalidateTag("po");
  737. return isExist;
  738. };
  739. export const isCorrectMachineUsed = async (machineCode: string) => {
  740. const isExist = await serverFetchJson<isCorrectMachineUsedResponse<Machine>>(
  741. `${BASE_API_URL}/jop/isCorrectMachineUsed`,
  742. {
  743. method: "POST",
  744. body: JSON.stringify({ machineCode }),
  745. headers: { "Content-Type": "application/json" },
  746. },
  747. );
  748. revalidateTag("po");
  749. return isExist;
  750. };
  751. export const fetchJos = cache(async (data?: SearchJoResultRequest) => {
  752. const queryStr = convertObjToURLSearchParams(data)
  753. console.log("queryStr", queryStr)
  754. const response = serverFetchJson<SearchJoResultResponse>(
  755. `${BASE_API_URL}/jo/getRecordByPage?${queryStr}`,
  756. {
  757. method: "GET",
  758. headers: { "Content-Type": "application/json" },
  759. next: {
  760. tags: ["jos"]
  761. }
  762. }
  763. )
  764. return response
  765. })
  766. export const updateJo = cache(async (data: UpdateJoRequest) => {
  767. return serverFetchJson<SaveJoResponse>(`${BASE_API_URL}/jo/update`,
  768. {
  769. method: "POST",
  770. body: JSON.stringify(data),
  771. headers: { "Content-Type": "application/json" },
  772. })
  773. })
  774. export const releaseJo = cache(async (data: CommonActionJoRequest) => {
  775. const response = serverFetchJson<CommonActionJoResponse>(`${BASE_API_URL}/jo/release`,
  776. {
  777. method: "POST",
  778. body: JSON.stringify(data),
  779. headers: { "Content-Type": "application/json" },
  780. })
  781. // Invalidate the cache after releasing
  782. revalidateTag("jo");
  783. return response;
  784. })
  785. export const startJo = cache(async (data: CommonActionJoRequest) => {
  786. const response = serverFetchJson<CommonActionJoResponse>(`${BASE_API_URL}/jo/start`,
  787. {
  788. method: "POST",
  789. body: JSON.stringify(data),
  790. headers: { "Content-Type": "application/json" },
  791. })
  792. // Invalidate the cache after starting
  793. revalidateTag("jo");
  794. return response;
  795. })
  796. export const manualCreateJo = cache(async (data: SaveJo) => {
  797. return serverFetchJson<SaveJoResponse>(`${BASE_API_URL}/jo/manualCreate`, {
  798. method: "POST",
  799. body: JSON.stringify(data),
  800. headers: { "Content-Type": "application/json" }
  801. })
  802. })
  803. export const fetchCompletedJobOrderPickOrdersWithCompletedSecondScan = cache(async (userId: number) => {
  804. return serverFetchJson<any[]>(`${BASE_API_URL}/jo/completed-job-order-pick-orders-with-completed-second-scan/${userId}`, {
  805. method: "GET",
  806. headers: { "Content-Type": "application/json" }
  807. })
  808. })
  809. export const fetchCompletedJobOrderPickOrderLotDetails = cache(async (pickOrderId: number) => {
  810. return serverFetchJson<any[]>(`${BASE_API_URL}/jo/completed-job-order-pick-order-lot-details/${pickOrderId}`, {
  811. method: "GET",
  812. headers: { "Content-Type": "application/json" }
  813. })
  814. })
  815. export const fetchCompletedJobOrderPickOrderLotDetailsForCompletedPick = cache(async (pickOrderId: number) => {
  816. return serverFetchJson<any[]>(`${BASE_API_URL}/jo/completed-job-order-pick-order-lot-details-completed-pick/${pickOrderId}`, {
  817. method: "GET",
  818. headers: { "Content-Type": "application/json" }
  819. })
  820. })
  821. export async function PrintPickRecord(request: PrintPickRecordRequest){
  822. const params = new URLSearchParams();
  823. params.append('pickOrderId', request.pickOrderId.toString())
  824. params.append('printerId', request.printerId.toString())
  825. if (request.printQty !== null && request.printQty !== undefined) {
  826. params.append('printQty', request.printQty.toString());
  827. }
  828. //const response = await serverFetchWithNoContent(`${BASE_API_URL}/jo/print-PickRecord?${params.toString()}`,{
  829. const response = await serverFetchWithNoContent(`${BASE_API_URL}/jo/newPrint-PickRecord?${params.toString()}`,{
  830. method: "GET"
  831. });
  832. return { success: true, message: "Print job sent successfully (Pick Record)" } as PrintPickRecordResponse;
  833. }