Files
Fuchs_Intranet/Fuchs_Database/dbo/Stored Procedures/mfr__updt__steps.sql
T
Stefan 8bcec409c5 feat: Add Admin Groups Management Module
- Introduced a new module for managing user groups (`usrgrp`) in the administration interface.
- Implemented CRUD operations for user groups: list, create, rename, and delete.
- Added authorization checks to ensure only users with appropriate permissions can manage groups.
- Created corresponding frontend JavaScript and SCSS files for the new module.
- Updated documentation to reflect the new group management functionality and its authorization model.
- Added SQL stored procedures for group management operations.
- Established a new login script for database access, ensuring proper security practices.
2026-09-16 09:35:31 +02:00

164 lines
4.6 KiB
Transact-SQL

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[mfr__updt__steps]
@tblname as nvarchar(50)
, @referencetable nvarchar(50)
, @tgtid bigint
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;
BEGIN TRY
DECLARE @now datetime = GETUTCDATE();
DECLARE @tmp [dbo].[mfr__tt__steps];
DECLARE @ARCHIVE TABLE(
[ActionType] varchar(25),
[Id] [bigint] NULL,
[MobileId] [bigint] NULL,
[Version] [int] NULL,
[Name] [nvarchar](255) NULL,
[IsDone] [bit] NULL,
[HasError] [bit] NULL,
[TrackingId] [nvarchar](255) NULL,
[Type] [nvarchar](255) NULL,
[SortOrder] [int] NULL,
[Data] [nvarchar](max) NULL,
[DateModifiedOffline] [datetime] NULL,
[ServiceRequestId] [bigint] NULL,
[Description] [nvarchar](max) NULL,
[Comment] [nvarchar](max) NULL,
[InternalComment] [nvarchar](max) NULL,
[ServiceObjectId] [bigint] NULL,
[StepListTemplateId] [bigint] NULL,
[ParentId] [bigint] NULL
);
DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname
INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd;
DECLARE @olist TABLE ( [id] bigint );
DECLARE @check_reference as varchar(5) = '';
IF ISNULL(@referencetable,'') = 'mfr__servicerequests'
BEGIN
SET @check_reference = 'srq';
INSERT INTO @olist SELECT DISTINCT [ServiceRequestId] FROM @tmp WHERE ISNULL([ServiceRequestId],0) <> 0;
END
IF ISNULL(@referencetable,'') = 'mfr__steplisttemplates'
BEGIN
SET @check_reference = 'slt';
INSERT INTO @olist SELECT DISTINCT [StepListTemplateId] FROM @tmp WHERE ISNULL([StepListTemplateId],0) <> 0;
END
BEGIN TRANSACTION;
MERGE [dbo].[mfr__steps] as TARGET
USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id]
WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN
UPDATE
SET [Id] = SOURCE.[Id]
,[MobileId] = SOURCE.[MobileId]
,[Version] = SOURCE.[Version]
,[Name] = SOURCE.[Name]
,[IsDone] = SOURCE.[IsDone]
,[HasError] = SOURCE.[HasError]
,[TrackingId] = SOURCE.[TrackingId]
,[Type] = SOURCE.[Type]
,[SortOrder] = SOURCE.[SortOrder]
,[Data] = SOURCE.[Data]
,[DateModifiedOffline] = SOURCE.[DateModifiedOffline]
,[ServiceRequestId] = SOURCE.[ServiceRequestId]
,[Description] = SOURCE.[Description]
,[Comment] = SOURCE.[Comment]
,[InternalComment] = SOURCE.[InternalComment]
,[ServiceObjectId] = SOURCE.[ServiceObjectId]
,[StepListTemplateId] = SOURCE.[StepListTemplateId]
,[ParentId] = SOURCE.[ParentId]
WHEN NOT MATCHED BY TARGET THEN
INSERT
( [Id]
,[MobileId]
,[Version]
,[Name]
,[IsDone]
,[HasError]
,[TrackingId]
,[Type]
,[SortOrder]
,[Data]
,[DateModifiedOffline]
,[ServiceRequestId]
,[Description]
,[Comment]
,[InternalComment]
,[ServiceObjectId]
,[StepListTemplateId]
,[ParentId])
VALUES
(SOURCE.[Id]
,SOURCE.[MobileId]
,SOURCE.[Version]
,SOURCE.[Name]
,SOURCE.[IsDone]
,SOURCE.[HasError]
,SOURCE.[TrackingId]
,SOURCE.[Type]
,SOURCE.[SortOrder]
,SOURCE.[Data]
,SOURCE.[DateModifiedOffline]
,SOURCE.[ServiceRequestId]
,SOURCE.[Description]
,SOURCE.[Comment]
,SOURCE.[InternalComment]
,SOURCE.[ServiceObjectId]
,SOURCE.[StepListTemplateId]
,SOURCE.[ParentId])
WHEN NOT MATCHED BY SOURCE AND
(CASE WHEN @check_reference = 'srq' AND EXISTS (SELECT * FROM @olist as ol where ol.[id] = TARGET.[ServiceRequestId]) THEN 1
WHEN @check_reference = 'slt' AND EXISTS (SELECT * FROM @olist as ol where ol.[id] = TARGET.[StepListTemplateId]) THEN 1
ELSE 0 END) = 1 THEN
DELETE
OUTPUT
$action, deleted.*
INTO @ARCHIVE;
--INSERT INTO [dbo].[mfr__d_steps]
-- SELECT [Id]
-- ,[MobileId]
-- ,[Version]
-- ,[Name]
-- ,[IsDone]
-- ,[HasError]
-- ,[TrackingId]
-- ,[Type]
-- ,[SortOrder]
-- ,[Data]
-- ,[DateModifiedOffline]
-- ,[ServiceRequestId]
-- ,[Description]
-- ,[Comment]
-- ,[InternalComment]
-- ,[ServiceObjectId]
-- ,[StepListTemplateId]
-- ,[ParentId]
-- ,[DateDeleted] = @now
-- FROM @ARCHIVE
-- WHERE [ActionType] IN ( 'DELETE', 'UPDATE' );
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
INSERT INTO dbo.[fds__admin_dberrors] ([UserName], [ErrorNumber], [ErrorState], [ErrorSeverity], [ErrorLine], [ErrorProcedure], [ErrorMessage], [ErrorDateTime])
VALUES (SUSER_SNAME(), ERROR_NUMBER(), ERROR_STATE(), ERROR_SEVERITY(), ERROR_LINE(), ERROR_PROCEDURE(), ERROR_MESSAGE(), GETDATE());
THROW;
END CATCH;
END