production-task.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. import request from '@/utils/http'
  2. export type ProductionTaskOperateScope = 'mine' | 'manage'
  3. function scopeQuery(scope?: ProductionTaskOperateScope) {
  4. return scope === 'mine' ? { operateScope: 'mine' } : undefined
  5. }
  6. export function fetchCreateProductionTask(data: Record<string, any>) {
  7. return request.post({ url: '/web/admin/production-tasks', params: data })
  8. }
  9. export function fetchProductionTaskList(params?: {
  10. page?: number
  11. pageSize?: number
  12. keyword?: string
  13. taskStatus?: string
  14. workOrderId?: string
  15. startedTimeStart?: string
  16. startedTimeEnd?: string
  17. includeStepSummary?: boolean
  18. }) {
  19. return request.get<{
  20. list: any[]
  21. total: number
  22. page: number
  23. pageSize: number
  24. totalPages: number
  25. }>({ url: '/web/admin/production-tasks', params })
  26. }
  27. /** 批量拉取当前页工单下的生产任务(含步骤摘要),POST 避免 GET URL 过长 */
  28. export function fetchProductionTasksByWorkOrderIds(workOrderIds: string[]) {
  29. const ids = workOrderIds.map((id) => String(id || '').trim()).filter(Boolean)
  30. if (!ids.length) {
  31. return Promise.resolve({ list: [] as any[], total: 0, page: 1, pageSize: 0, totalPages: 0 })
  32. }
  33. return request.post<{
  34. list: any[]
  35. total: number
  36. page: number
  37. pageSize: number
  38. totalPages: number
  39. }>({
  40. url: '/web/admin/production-tasks/list-by-work-orders',
  41. params: {
  42. workOrderIds: ids,
  43. includeStepSummary: true,
  44. pageSize: Math.min(500, ids.length * 100)
  45. }
  46. })
  47. }
  48. export function groupProductionTasksByWorkOrderId(
  49. tasks: Record<string, any>[]
  50. ): Record<string, Record<string, any>[]> {
  51. const map: Record<string, Record<string, any>[]> = {}
  52. for (const task of tasks || []) {
  53. const workOrderId = String(task.workOrderId || '').trim()
  54. if (!workOrderId) continue
  55. if (!map[workOrderId]) map[workOrderId] = []
  56. map[workOrderId].push(task)
  57. }
  58. return map
  59. }
  60. export function fetchMyProductionTasks(params: {
  61. page?: number
  62. pageSize?: number
  63. keyword?: string
  64. taskStatus?: string
  65. workOrderType?: string
  66. receptionSource?: string
  67. bizType?: string
  68. scope: 'current' | 'history'
  69. includeStepSummary?: boolean
  70. excludeVoidProtocol?: boolean
  71. plannedStartTimeStart?: string
  72. plannedStartTimeEnd?: string
  73. }) {
  74. return request.get<{
  75. list: any[]
  76. total: number
  77. page: number
  78. pageSize: number
  79. totalPages: number
  80. }>({ url: '/web/admin/production-tasks/mine', params })
  81. }
  82. export function fetchForwardProductionTask(
  83. id: string,
  84. data: { toUserId: string; remark?: string },
  85. operateScope: ProductionTaskOperateScope = 'mine'
  86. ) {
  87. return request.post({
  88. url: `/web/admin/production-tasks/${id}/forward`,
  89. data,
  90. params: { operateScope }
  91. })
  92. }
  93. export function fetchReassignProductionTask(
  94. id: string,
  95. data: { assigneeUserId: string; remark?: string }
  96. ) {
  97. return request.put({
  98. url: `/web/admin/production-tasks/${id}/assignee`,
  99. data
  100. })
  101. }
  102. export function fetchDispatchProductionTaskSteps(
  103. taskId: string,
  104. data: {
  105. steps: Array<{
  106. stepId: string
  107. assigneeUserIds: string[]
  108. plannedStartTime?: string | null
  109. }>
  110. },
  111. operateScope?: ProductionTaskOperateScope
  112. ) {
  113. return request.put<any>({
  114. url: `/web/admin/production-tasks/${taskId}/steps/dispatch`,
  115. data,
  116. params: scopeQuery(operateScope)
  117. })
  118. }
  119. export function fetchProductionTaskDetail(
  120. id: string,
  121. options?: { includeStepSubTables?: boolean }
  122. ) {
  123. const params =
  124. options?.includeStepSubTables === false ? { includeStepSubTables: false } : undefined
  125. return request.get<any>({ url: `/web/admin/production-tasks/${id}`, params })
  126. }
  127. export type ProductionTaskEditorInitPayload = {
  128. task: Record<string, any>
  129. processLibrary?: Record<string, any>[]
  130. options?: {
  131. processCategories: Record<string, any>[]
  132. sops: Record<string, any>[]
  133. outputTypes: Record<string, any>[]
  134. equipments: Record<string, any>[]
  135. reagents: Record<string, any>[]
  136. consumables: Record<string, any>[]
  137. itemUnits: Record<string, any>[]
  138. }
  139. }
  140. /** 编辑生产任务弹窗初始化(任务详情 + 工艺库 + 步骤配置参考数据,聚合为单次请求) */
  141. export function fetchProductionTaskEditorInit(
  142. id: string,
  143. options?: { includeReference?: boolean }
  144. ) {
  145. const params = options?.includeReference === false ? { includeReference: false } : undefined
  146. return request.get<ProductionTaskEditorInitPayload>({
  147. url: `/web/admin/production-tasks/${id}/editor-init`,
  148. params
  149. })
  150. }
  151. export function fetchUpdateProductionTask(id: string, data: Record<string, any>) {
  152. return request.put({ url: `/web/admin/production-tasks/${id}`, params: data })
  153. }
  154. export function fetchUpdateProductionTaskStatus(
  155. id: string,
  156. data: Record<string, any>,
  157. operateScope?: ProductionTaskOperateScope
  158. ) {
  159. return request.put({
  160. url: `/web/admin/production-tasks/${id}/status`,
  161. data,
  162. params: scopeQuery(operateScope)
  163. })
  164. }
  165. export function fetchDeleteProductionTask(id: string) {
  166. return request.del({ url: `/web/admin/production-tasks/${id}` })
  167. }
  168. export function fetchAddTaskStep(
  169. taskId: string,
  170. data: Record<string, any>,
  171. operateScope?: ProductionTaskOperateScope
  172. ) {
  173. return request.post({
  174. url: `/web/admin/production-tasks/${taskId}/steps`,
  175. data,
  176. params: scopeQuery(operateScope)
  177. })
  178. }
  179. export function fetchUpdateTaskStep(
  180. taskId: string,
  181. stepId: string,
  182. data: Record<string, any>,
  183. operateScope?: ProductionTaskOperateScope
  184. ) {
  185. return request.put({
  186. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}`,
  187. data,
  188. params: scopeQuery(operateScope)
  189. })
  190. }
  191. export function fetchDeleteTaskStep(
  192. taskId: string,
  193. stepId: string,
  194. operateScope?: ProductionTaskOperateScope
  195. ) {
  196. return request.del({
  197. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}`,
  198. params: scopeQuery(operateScope)
  199. })
  200. }
  201. export function fetchReplaceStepReagents(
  202. taskId: string,
  203. stepId: string,
  204. data: any[],
  205. operateScope?: ProductionTaskOperateScope
  206. ) {
  207. return request.put({
  208. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/reagents`,
  209. data,
  210. params: scopeQuery(operateScope)
  211. })
  212. }
  213. export function fetchReplaceStepConsumables(
  214. taskId: string,
  215. stepId: string,
  216. data: any[],
  217. operateScope?: ProductionTaskOperateScope
  218. ) {
  219. return request.put({
  220. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/consumables`,
  221. data,
  222. params: scopeQuery(operateScope)
  223. })
  224. }
  225. export function fetchReplaceStepConfiguredReagents(
  226. taskId: string,
  227. stepId: string,
  228. data: any[],
  229. operateScope?: ProductionTaskOperateScope
  230. ) {
  231. return request.put({
  232. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/configured-reagents`,
  233. data,
  234. params: scopeQuery(operateScope)
  235. })
  236. }
  237. export function fetchReplaceStepDataCollection(
  238. taskId: string,
  239. stepId: string,
  240. data: any[],
  241. operateScope?: ProductionTaskOperateScope
  242. ) {
  243. return request.put({
  244. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/data-collection`,
  245. data,
  246. params: scopeQuery(operateScope)
  247. })
  248. }
  249. export function fetchSetTaskInputs(
  250. taskId: string,
  251. data: any[] | Record<string, any>,
  252. operateScope?: ProductionTaskOperateScope
  253. ) {
  254. return request.post({
  255. url: `/web/admin/production-tasks/${taskId}/inputs`,
  256. data,
  257. params: scopeQuery(operateScope)
  258. })
  259. }
  260. export interface SpawnTemporaryWorkOrderResult {
  261. workOrder: {
  262. id: string
  263. workOrderNo: string
  264. workOrderStatus: string
  265. remark?: string
  266. }
  267. sourceTaskId: string
  268. sourceTaskNo: string
  269. inputItems: Array<{
  270. inputType: string
  271. inputId?: string
  272. inputCode?: string
  273. inputName?: string
  274. remark?: string
  275. }>
  276. }
  277. export function fetchSpawnTemporaryWorkOrderFromTask(
  278. taskId: string,
  279. data: { remark?: string },
  280. operateScope?: ProductionTaskOperateScope
  281. ) {
  282. return request.post<SpawnTemporaryWorkOrderResult>({
  283. url: `/web/admin/production-tasks/${taskId}/spawn-temporary-work-order`,
  284. data,
  285. params: scopeQuery(operateScope)
  286. })
  287. }
  288. export function fetchSetTaskOutputs(
  289. taskId: string,
  290. data: any[] | Record<string, any>,
  291. operateScope?: ProductionTaskOperateScope
  292. ) {
  293. return request.post({
  294. url: `/web/admin/production-tasks/${taskId}/outputs`,
  295. data,
  296. params: scopeQuery(operateScope)
  297. })
  298. }
  299. export function fetchReorderTaskSteps(
  300. data: { taskId: string; stepIds: string[] },
  301. operateScope?: ProductionTaskOperateScope
  302. ) {
  303. return request.put({
  304. url: '/web/admin/production-tasks/step/reorder',
  305. data,
  306. params: scopeQuery(operateScope)
  307. })
  308. }
  309. export function fetchCopyTaskStep(
  310. data: { taskId: string; stepId: string },
  311. operateScope?: ProductionTaskOperateScope
  312. ) {
  313. return request.post({
  314. url: `/web/admin/production-tasks/${data.taskId}/steps/${data.stepId}/copy`,
  315. data: {},
  316. params: scopeQuery(operateScope)
  317. })
  318. }
  319. export function fetchReplaceStepOutputs(
  320. taskId: string,
  321. stepId: string,
  322. data: any[],
  323. operateScope?: ProductionTaskOperateScope
  324. ) {
  325. return request.put({
  326. url: `/web/admin/production-tasks/${taskId}/steps/${stepId}/outputs`,
  327. data,
  328. params: scopeQuery(operateScope)
  329. })
  330. }