unit uCtrlQMS; interface {$I 'GlobalDefs.inc'} uses mvcframework, mvcframework.Commons, mvcframework.Serializer.Commons, uCtrlBase, uHeoObj_Base, uHeoObj_QMS {$IFDEF SWAGGER} ,MVCFramework.Swagger.Commons {$ENDIF} ; const {$I globalConsts.inc} type [MVCPath('/qms')] TQMSObecneController = class(TBaseController) public [MVCPath('/ciselnik/stavmeridel')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Číselníky', 'Vrací číselník stavů měřidel', 'QMSCiselnikGetStavMeridel')] [MVCSwagResponses(200, 'Success', TQMSCiselnik, true)] procedure GetCiselnikStavMeridel; // ciselnik-1, IdQMS-0 [MVCPath('/ciselnik/druhmeridel')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Číselníky', 'Vrací číselník druhů měřidel', 'QMSCiselnikGetDruhMeridel')] [MVCSwagResponses(200, 'Success', TQMSCiselnik, true)] procedure GetCiselnikDruhMeridel; // ciselnik-2, IdQMS-0 [MVCPath('/ciselnik/kategoriemeridel')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Číselníky', 'Vrací číselník kategorií měřidel', 'QMSCiselnikGetKategorieMeridel')] [MVCSwagResponses(200, 'Success', TQMSCiselnik, true)] procedure GetCiselnikKategorieMeridel; // ciselnik-3, IdQMS-0 [MVCPath('/ciselnik/stavyudrzby')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Číselníky', 'Vrací číselník stavů údržby strojů a zařízení', 'QMSCiselnikGetStavUdrzby')] [MVCSwagResponses(200, 'Success', TQMSCiselnik, true)] procedure GetCiselnikStavUdrzby; // ciselnik-1, IdQMS-1 [MVCPath('/ciselnik/druhyudrzby')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Číselníky', 'Vrací číselník druhů údržby strojů a zařízení', 'QMSCiselnikGetDruhUdrzby')] [MVCSwagResponses(200, 'Success', TQMSCiselnik, true)] procedure GetCiselnikDruhUdrzby; // ciselnik-2, IdQMS-1 end; [MVCPath('/udrzbastroju')] TQMSUdrzbaStrojuAZarizeniController = class(TBaseController) public [MVCPath('/meta')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Vraci metadata údržby strojů a zařízení', 'QMSUdrzbaGetMeta')] procedure GetMeta; [MVCPath('/hledej'), MVCHTTPMethod([httpPOST])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Hledá záznam údržby stroje či zařízení', 'QMSUdrzbaHledatUdrzbuStrojeAZarizeni')] [MVCConsumes(TMVCMediaType.APPLICATION_JSON)] [MVCSwagResponses(200, 'Success', TQMSUdrzbaStrojuAZarizeni, true)] procedure HledatUdrzbuStrojeAZarizeni; [MVCPath] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Vrací seznam všech údržeb strojů a zařízení', 'QMSUdrzbaGetAll')] [MVCSwagResponses(200, 'Success', TQMSUdrzbaStrojuAZarizeni, true)] procedure GetAll; [MVCPath] [MVCHTTPMethod([httpPOST])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Zápis hlavičky Údržby stroje či zařízení', 'QMSUdrzbaZapisUdrzbyStrojuAZarizeni')] [MVCConsumes(TMVCMediaType.APPLICATION_JSON)] procedure NovaUdrzbaStrojuAZarizeni (CTX: TWebContext); [MVCPath('/($id)')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Vrací detail údržeb strojů či zařízení', 'QMSUdrzbaGetByID')] [MVCSwagParam(plPath, 'id', 'ID zaznamu', ptString, false)] [MVCSwagParam(plQuery, 'utvar', 'Útvar/středisko', ptString, false)] [MVCSwagParam(plQuery, 'stav', 'Číslo stavu údržby, nikoliv id (viz /qms/ciselnik/stavyudrzby)', ptString, false)] [MVCSwagParam(plQuery, 'druh', 'Číslo druhu údržby, nikoliv id (viz /qms/ciselnik/druhyudrzby)', ptString, false)] [MVCSwagResponses(200, 'Success', TQMSUdrzbaStrojuAZarizeni, true)] procedure GetByID (id: string='0'; [MVCFromQueryString('utvar', '')] utvar: string=''; [MVCFromQueryString('stav', '')] stav: string=''; [MVCFromQueryString('druh', '')] druh: string='' ); [MVCPath('/($id)')] [MVCHTTPMethod([httpPUT])] [MVCSwagSummary('QMS - Údržba strojů a zařízení', 'Aktualizuje záznam údržby stroje či zařízení', 'QMSUdrzbaAktualizaceUdrzbyStrojuAZarizeni')] [MVCConsumes(TMVCMediaType.APPLICATION_JSON)] procedure AktualizaceUdrzbyStrojuAZarizeni (CTX: TWebContext; id: string=''); end; [MVCPath('/qms/kontrolnipostup')] // [MVCPath('/kontrolnipostup')] // [MVCSwagSummary('KontrolniPostupy', 'Kontrolní postupy', '')] TQMSKontrolniPostupyController = class(TBaseController) public [MVCPath('/meta')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní postupy', 'Vrátí meta informace', 'QMSKontrolniPostupGetMeta')] procedure GetMeta; [MVCPath('/($id)')] // [MVCProduces('application/json')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní postupy', 'Vratí detail kontrolního postupu', 'QMSKontrolniPostupGetByID')] [MVCSwagParam(plPath, 'id', 'ID kontrolního postupu', ptString, false)] [MVCSwagParam(plQuery, 'idpostup', 'ID výrobního postupu', ptString, false)] [MVCSwagParam(plQuery, 'params', 'Zobrazit parametry', ptBoolean, false)] [MVCSwagParam(plQuery, 'paramsFull', 'Zobrazit parametry', ptBoolean, false)] [MVCSwagResponses(200, 'Success', TQMSKontrolniPostup)] procedure GetByID (id: string='0'; [MVCFromQueryString('idpostup', '')] sIdPostup: string=''; [MVCFromQueryString('params', false)] params: Boolean=false; [MVCFromQueryString('paramsFull', false)] paramsFull: Boolean=false ); [MVCPath('')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní postupy', 'Vrátí seznam kontrolních postupů', 'QMSKontrolniPostupGetAll')] [MVCSwagResponses(200, 'Success', TQMSKontrolniPostup, true)] procedure GetAll; end; [MVCPath('/qms/kontrolniplan')] // [MVCPath('/kontrolniplan')] // [MVCDoc('QMS - kontrolní plány')] TQMSKontrolniPlanController = class(TBaseController) public [MVCPath('/meta')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní plán', 'Vrati meta informace', 'QMSKontrolniPlanGetMeta')] procedure GetMeta; [MVCPath('/($id)')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní plán', 'Vrati kontrolni plan', 'QMSKontrolniPlanGetByID')] [MVCSwagParam(plPath, 'id', 'ID kontrolního plánu', ptString, true)] [MVCSwagResponses(200, 'Success', TQMSKontrolniPlan, false)] procedure GetByID (id: string='0'); [MVCPath('')] [MVCHTTPMethod([httpGET])] [MVCSwagSummary('QMS - kontrolní plán', 'Vrati seznam kontrolnich planu', 'QMSKontrolniPlanGetAll')] [MVCSwagParam(plQuery, 'kategorie', 'Kategorie výrobního plánu', ptString, false)] [MVCSwagResponses(200, 'Success', TQMSKontrolniPlan, true)] procedure GetAll ([MVCFromQueryString('kategorie', '')] kategorie: string='' ); end; implementation uses uSvc_Base, uCommons, mvcframework.Serializer.Intf, System.Generics.Collections, System.RegularExpressions, System.StrUtils, System.SysUtils, Winapi.ActiveX, IdHTTP, System.JSON, JsonDataObjects, helTabsBIDs; { TQMSObecneController } procedure TQMSObecneController.GetCiselnikStavMeridel; begin try Render(ObjectDict().Add('data', GetQMSObecneService.GetCislenikQMS (1, 0))); // viz uSvc_QMS.pas except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSObecneController.GetCiselnikDruhMeridel; begin try Render(ObjectDict().Add('data', GetQMSObecneService.GetCislenikQMS (2, 0))); // viz uSvc_QMS.pas except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSObecneController.GetCiselnikKategorieMeridel; begin try Render(ObjectDict().Add('data', GetQMSObecneService.GetCislenikQMS (3, 0))); // viz uSvc_QMS.pas except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSObecneController.GetCiselnikStavUdrzby; begin try Render(ObjectDict().Add('data', GetQMSObecneService.GetCislenikQMS (1, 1))); // viz uSvc_QMS.pas except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSObecneController.GetCiselnikDruhUdrzby; begin try Render(ObjectDict().Add('data', GetQMSObecneService.GetCislenikQMS (2, 1))); except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; { TQMSUdrzbaStrojuAZarizeniController } procedure TQMSUdrzbaStrojuAZarizeniController.GetAll; begin try Render(ObjectDict().Add('data', GetQMSUdrzbaStrojuAZarizeniService.GetAll)); // viz uSvc_QMS.pas except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSUdrzbaStrojuAZarizeniController.GetByID (id: string='0'; utvar: string=''; stav: string=''; druh:string=''); var iId, iCislo: integer; typ: Byte; params: TDictionary; begin params:= TDictionary.Create; iId:= 0; id:= sanitizeSQLString(id); if not(TryStrToInt(id, iId)) then iId:= 0; if (iId>0) then params.Add('id', iId.ToString); utvar:= LeftStr(sanitizeSQLString(utvar), 30); if (utvar<>'') then params.Add('utvar', utvar); stav:= LeftStr(sanitizeSQLString(stav), 3); if (stav<>'') then params.Add('stav', stav); druh:= LeftStr(sanitizeSQLString(druh), 3); if (druh<>'') then params.Add('druh', druh); try Render(ObjectDict().Add('data', GetQMSUdrzbaStrojuAZarizeniService.GetByParams (params))); except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; params.Free; end; procedure TQMSUdrzbaStrojuAZarizeniController.GetMeta; begin try Render(ObjectDict().Add('data', GetQMSUdrzbaStrojuAZarizeniService.GetMeta)); except on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 404); end else raise; end; end; procedure TQMSUdrzbaStrojuAZarizeniController.HledatUdrzbuStrojeAZarizeni; var params: TJsonObject; udrzby: TObjectList; begin params:= TJsonBaseObject.Parse(Context.Request.Body) as TJsonObject; // udrzby:= GetQMSUdrzbaStrojuAZarizeniService.GetByFindParams (Params.S['hledej']); end; procedure TQMSUdrzbaStrojuAZarizeniController.AktualizaceUdrzbyStrojuAZarizeni (CTX: TWebContext; id: string=''); var jsonData, respStr: string; begin try jsonData:= CTX.Request.Body; // if (jsonData<>'') then // GetVyrobniOperaceService.ZapisDZTasku (jsonData, respStr); ResponseStatus(HTTP_STATUS.OK, 'OK'); Render(respStr); except RenderStatusMessage (200); end; end; procedure TQMSUdrzbaStrojuAZarizeniController.NovaUdrzbaStrojuAZarizeni (CTX: TWebContext); var jsonData, respStr: string; o: System.JSON.TJSONObject; begin respStr:= ''; o:= System.JSON.TJSONObject.Create; try jsonData:= CTX.Request.Body; // if (jsonData<>'') then ResponseStatus(HTTP_STATUS.OK, 'OK'); Render(respStr); except RenderStatusMessage (200); end; if (o<>nil) then o.Free; end; { TQMSKontrolniPostupyController } procedure TQMSKontrolniPostupyController.GetAll; begin try Render(ObjectDict().Add('data', GetQMSKontrolniPostupyService.GetAll)); // viz uSvc_Vyroba.pas except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; end; procedure TQMSKontrolniPostupyController.GetByID (id: string='0'; sIdPostup: string=''; params: boolean = false; paramsFull: boolean = false); var iId, idPostup: integer; typ: byte; begin id:= sanitizeSQLString(id); if not(TryStrToInt(id, iId)) then iId:= 0; sIdPostup:= sanitizeSQLString(sIdPostup); if not(TryStrToInt(sIdPostup, idPostup)) then idPostup:= 0; typ:= 255; if (iId>0) then typ:= 0; if (idPostup>0) then typ:= 1; if (iId>0) and (params) then typ:= 2; if (iId>0) and (paramsFull) then typ:= 3; try case typ of 0: Render(ObjectDict().Add('data', GetQMSKontrolniPostupyService.GetByID(iId))); 1: Render(ObjectDict().Add('data', GetQMSKontrolniPostupyService.GetListByIDPostup(idPostup))); 2: Render(ObjectDict().Add('data', GetQMSKontrolniPostupyService.GetParamsByIDHlav(iId))); end; except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; end; procedure TQMSKontrolniPostupyController.GetMeta; begin try Render(ObjectDict().Add('data', GetQMSKontrolniPostupyService.GetMeta)); except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; end; { TQMSKontrolniPlanController } procedure TQMSKontrolniPlanController.GetMeta; begin try Render(ObjectDict().Add('data', GetQMSKontrolniPlanService.GetMeta)); except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; end; procedure TQMSKontrolniPlanController.GetByID (id: string = '0'); var iId: integer; begin id:= sanitizeSQLString (id); if not(TryStrToInt(id, iId)) then iId:= 0; if (iId>0) then begin try Render(ObjectDict().Add('data', GetQMSKontrolniPlanService.GetByID(iId))); except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; end else RenderStatusMessage (200); end; procedure TQMSKontrolniPlanController.GetAll (kategorie: string=''); var p: TDictionary; begin p:= TDictionary.Create; kategorie:= sanitizeSQLString (kategorie); if (kategorie<>'') then p.Add ('kategorie', kategorie); try Render(ObjectDict().Add('data', GetQMSKontrolniPlanService.GetByParams (p) )); // viz uSvc_Vyroba.pas except RenderStatusMessage (200); { on E: EServiceException do begin raise EMVCException.Create(E.Message, '', 0, 200); end else raise; } end; p.Free; end; end.