IF COL_LENGTH('dbo.asr_wrk_detl', 'pic') IS NULL
BEGIN
    ALTER TABLE [dbo].[asr_wrk_detl]
        ADD [pic] NVARCHAR(MAX) NULL;
END
GO

IF COL_LENGTH('dbo.asr_wrk_detl_log', 'pic') IS NULL
BEGIN
    ALTER TABLE [dbo].[asr_wrk_detl_log]
        ADD [pic] NVARCHAR(MAX) NULL;
END
GO

IF COL_LENGTH('dbo.asr_loc_detl', 'pic') IS NULL
BEGIN
    ALTER TABLE [dbo].[asr_loc_detl]
        ADD [pic] NVARCHAR(MAX) NULL;
END
GO

IF NOT EXISTS (SELECT 1 FROM sys_config WHERE code = N'InboundCameraCapture')
BEGIN
    INSERT INTO sys_config (name, code, value, type, status)
    VALUES (
        N'入库站点抓拍配置',
        N'InboundCameraCapture',
        N'{"enabled":true,"captureUrl":"http://192.168.160.11:8000/startPic","imageUrlPrefix":"http://192.168.160.11/","stations":{"101":[{"ip":"10.10.16.13","port":554,"user":"admin","password":"a327482030"},{"ip":"10.10.16.14","port":554,"user":"admin","password":"a327482030"}]}}',
        2,
        1
    );
END
GO

UPDATE sys_config
SET value = REPLACE(value, N'"captureUrl":"http://192.168.10.11:8000/startPic"', N'"captureUrl":"http://192.168.160.11:8000/startPic"')
WHERE code = N'InboundCameraCapture'
  AND value LIKE N'%"captureUrl":"http://192.168.10.11:8000/startPic"%';
GO

UPDATE sys_config
SET value = REPLACE(value, N'"imageUrlPrefix":"http://192.168.10.11:8000/image/"', N'"imageUrlPrefix":"http://192.168.160.11/"')
WHERE code = N'InboundCameraCapture'
  AND value LIKE N'%"imageUrlPrefix":"http://192.168.10.11:8000/image/"%';
GO
