preventive-maintenance.service.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import { HttpClient, HttpHeaders } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3. import { map } from 'rxjs';
  4. import { apiTemp } from '../../environments/environment.prod';
  5. @Injectable({
  6. providedIn: 'root',
  7. })
  8. export class PreventiveMaintenanceService {
  9. constructor(private _http: HttpClient) {}
  10. getWorkOrdersByDay(
  11. day: number,
  12. month: number,
  13. year: number,
  14. idUser: string,
  15. line: number
  16. ) {
  17. return this.getQuery(
  18. `get-work-orders-by-day/${day}/${month}/${year}/${idUser}/${line}`
  19. ).pipe(map((data: any) => data));
  20. }
  21. getWorkOrder(id: string, idUser: string, line: number) {
  22. return this.getQuery(`get-work-order/${id}/${idUser}/${line}`).pipe(
  23. map((data: any) => data)
  24. );
  25. }
  26. getStartedWorkOrders(idUser: string, line: number) {
  27. return this.getQuery(`get-started-work-orders/${idUser}/${line}`).pipe(
  28. map((data: any) => data)
  29. );
  30. }
  31. getExecRegister(date: string, idOrder: string, idUser: string, line: number) {
  32. return this.getQuery(
  33. `get-exec-register/${date}/${idOrder}/${idUser}/${line}`
  34. ).pipe(map((data: any) => data));
  35. }
  36. getWorkOrders(idUser: string, line: number) {
  37. return this.getQuery(`get-work-orders/${idUser}/${line}`).pipe(
  38. map((data: any) => data)
  39. );
  40. }
  41. getActiveWorkOrders(idUser: string, line: number) {
  42. return this.getQuery(`get-active-orders/${idUser}/${line}`).pipe(
  43. map((data: any) => data)
  44. );
  45. }
  46. getPreventiveCalendar(
  47. fecIni: string,
  48. fecFin: string,
  49. idUser: string,
  50. line: number
  51. ) {
  52. return this.getQuery(
  53. `get-preventive-calendar/${fecIni}/${fecFin}/${idUser}/${line}`
  54. ).pipe(map((data: any) => data));
  55. }
  56. getUnprogrammedVisits(idUser: string, line: number) {
  57. return this.getQuery(`get-unprogrammed-visits/${idUser}/${line}`).pipe(
  58. map((data: any) => data)
  59. );
  60. }
  61. getUnprogrammedVisit(idVisit: string, idUser: string, line: number) {
  62. return this.getQuery(
  63. `get-unprogrammed-visit/${idVisit}/${idUser}/${line}`
  64. ).pipe(map((data: any) => data));
  65. }
  66. getVisitAttendance(idVisit: string, idUser: string, line: number) {
  67. return this.getQuery(
  68. `get-visit-attendance/${idVisit}/${idUser}/${line}`
  69. ).pipe(map((data: any) => data));
  70. }
  71. getVisitStaff(idVisit: string, idUser: string, line: number) {
  72. return this.getQuery(`get-visit-staff/${idVisit}/${idUser}/${line}`).pipe(
  73. map((data: any) => data)
  74. );
  75. }
  76. getMaintenanceSimulation(idOrder: string, idUser: string, line: number) {
  77. return this.getQuery(
  78. `get-maintenance-simulation/${idOrder}/${idUser}/${line}`
  79. ).pipe(map((data: any) => data));
  80. }
  81. getOrderWithActivator(idOrder: string, idUser: string, line: number) {
  82. return this.getQuery(
  83. `get-order-with-activator/${idOrder}/${idUser}/${line}`
  84. ).pipe(map((data: any) => data));
  85. }
  86. printOrderSimulation(idOrder: string, idUser: string, line: number) {
  87. return this.getQuery(
  88. `print-order-simulation/${idOrder}/${idUser}/${line}`
  89. ).pipe(map((data: any) => data));
  90. }
  91. printOrderDetails(idOrder: string, idUser: string, line: number) {
  92. return this.getQuery(
  93. `print-order-details/${idOrder}/${idUser}/${line}`
  94. ).pipe(map((data: any) => data));
  95. }
  96. extractMaintenancePlan(idOrder: string, idUser: string, line: number) {
  97. return this.getQuery(
  98. `extract-maintenance-plan/${idOrder}/${idUser}/${line}`
  99. ).pipe(map((data: any) => data));
  100. }
  101. getMaintenancePlanAnalysis(idFile: string, idUser: string, line: number) {
  102. return this.getQuery(
  103. `get-maintenance-plan-analysis/${idFile}/${idUser}/${line}`
  104. ).pipe(map((data: any) => data));
  105. }
  106. getFileToMSProject(idOrder: string, idUser: string, line: number) {
  107. return this.getQuery(
  108. `get-file-to-ms-project/${idOrder}/${idUser}/${line}`
  109. ).pipe(map((data: any) => data));
  110. }
  111. getOrderStaff(idOrder: string, idUser: string, line: number) {
  112. return this.getQuery(`get-order-staff/${idOrder}/${idUser}/${line}`).pipe(
  113. map((data: any) => data)
  114. );
  115. }
  116. getOrderExecutionDetails(idExecution: string, idUser: string, line: number) {
  117. return this.getQuery(
  118. `get-order-execution-details/${idExecution}/${idUser}/${line}`
  119. ).pipe(map((data: any) => data));
  120. }
  121. getWorkOrdersByEquipment(
  122. equipmentCode: string,
  123. idUser: string,
  124. line: number
  125. ) {
  126. return this.getQuery(
  127. `get-work-orders-by-equipment/${equipmentCode}/${idUser}/${line}`
  128. ).pipe(map((data: any) => data));
  129. }
  130. getVisit(id: string, idUser: string, line: number) {
  131. return this.getQuery(`get-visit/${id}/${idUser}/${line}`).pipe(
  132. map((data: any) => data)
  133. );
  134. }
  135. getVisitStatusHistory(idOrder: string, idUser: string, line: number) {
  136. return this.getQuery(
  137. `get-visit-status-history/${idOrder}/${idUser}/${line}`
  138. ).pipe(map((data: any) => data));
  139. }
  140. assignOperariosToPreventiveVisit(body: any) {
  141. return this.postQuery('assign-operarios-to-visit', body).pipe(
  142. map((data: any) => data)
  143. );
  144. }
  145. setVisitAttendance(body: any) {
  146. return this.postQuery('attend-preventive-visit', body).pipe(
  147. map((data: any) => data)
  148. );
  149. }
  150. registerWorkOrder(body: any) {
  151. return this.postQuery('register-work-order', body).pipe(
  152. map((data: any) => data)
  153. );
  154. }
  155. executePreventiveWorkOrder(body: any) {
  156. return this.postQuery('execute-preventive-work-order', body).pipe(
  157. map((data: any) => data)
  158. );
  159. }
  160. cancelWorkOrder(body: any) {
  161. return this.postQuery('cancel-work-order', body).pipe(
  162. map((data: any) => data)
  163. );
  164. }
  165. deleteWorkOrder(body: any) {
  166. return this.postQuery('delete-work-order', body).pipe(
  167. map((data: any) => data)
  168. );
  169. }
  170. updateWorkOrder(body: any) {
  171. return this.postQuery('update-work-order', body).pipe(
  172. map((data: any) => data)
  173. );
  174. }
  175. endOrderExecution(body: any) {
  176. return this.postQuery('end-order-execution', body).pipe(
  177. map((data: any) => data)
  178. );
  179. }
  180. copyWorkOrder(body: any) {
  181. return this.postQuery('copy-work-order', body).pipe(
  182. map((data: any) => data)
  183. );
  184. }
  185. savePresetWorkOrder(body: any) {
  186. return this.postQuery('save-preset-work-order', body).pipe(
  187. map((data: any) => data)
  188. );
  189. }
  190. newUnprogrammedOrder(body: any) {
  191. return this.postQuery('new-unprogrammed-order', body).pipe(
  192. map((data: any) => data)
  193. );
  194. }
  195. updateVisitStatus(body: any) {
  196. return this.postQuery('update-visit-status', body).pipe(
  197. map((data: any) => data)
  198. );
  199. }
  200. startVisit(body: any) {
  201. return this.postQuery('start-preventive-visit', body).pipe(
  202. map((data: any) => data)
  203. );
  204. }
  205. registerOperatorClosingComment(body: any) {
  206. return this.postQuery('register-operator-closing-comment', body).pipe(
  207. map((data: any) => data)
  208. );
  209. }
  210. updateOrderStatus(body: any) {
  211. return this.postQuery('update-order-status', body).pipe(
  212. map((data: any) => data)
  213. );
  214. }
  215. setBudgetAnalysis(body: any) {
  216. return this.postQuery('set-budget-analysis', body).pipe(
  217. map((data: any) => data)
  218. );
  219. }
  220. updateOrderWithActivator(body: any) {
  221. return this.postQuery('update-order-with-activator', body).pipe(
  222. map((data: any) => data)
  223. );
  224. }
  225. saveOrderSimulation(body: any) {
  226. return this.postQuery('save-order-simulation', body).pipe(
  227. map((data: any) => data)
  228. );
  229. }
  230. getQuery(query: string, tk?: string) {
  231. const URL = `${apiTemp}${query}`;
  232. let token = '';
  233. if (tk == undefined || tk == null || tk == '') {
  234. token = `Bearer ${localStorage.getItem('token')!}`;
  235. } else {
  236. token = `Bearer ${tk!}`;
  237. }
  238. return this._http.get(URL, {
  239. headers: new HttpHeaders({
  240. Authorization: token,
  241. }),
  242. });
  243. }
  244. postQuery(query: string, body: any) {
  245. const JWT = `Bearer ${localStorage.getItem('token')}`;
  246. const URL = `${apiTemp}${query}`;
  247. return this._http.post(URL, body, {
  248. headers: new HttpHeaders({
  249. Authorization: JWT!,
  250. }),
  251. });
  252. }
  253. }