184 lines
7.5 KiB
Transact-SQL
184 lines
7.5 KiB
Transact-SQL
SET NOCOUNT ON;
|
|
SET XACT_ABORT ON;
|
|
|
|
IF N'$(JudgeDJ2Password)' = N'__REQUIRED__'
|
|
OR N'$(JudgeDT1Password)' = N'__REQUIRED__'
|
|
OR N'$(JudgeDT2Password)' = N'__REQUIRED__'
|
|
OR N'$(JudgeP2Password)' = N'__REQUIRED__'
|
|
THROW 51000, N'请通过 sqlcmd -v 提供四名裁判的密码。', 1;
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
IF NOT EXISTS (
|
|
SELECT 1 FROM dbo.EventSession
|
|
WHERE Id = 468424868974597 AND EventId = 466884260081669 AND DeleteMark = 0
|
|
)
|
|
THROW 51001, N'目标 QA 场次不存在,已停止七席补齐。', 1;
|
|
|
|
IF NOT EXISTS (SELECT 1 FROM dbo.Referee WHERE Id = 9004 AND Mobile = '13800000004' AND DeleteMark = 0)
|
|
OR NOT EXISTS (SELECT 1 FROM dbo.Referee WHERE Id = 9005 AND Mobile = '13800000005' AND DeleteMark = 0)
|
|
THROW 51002, N'赵裁判或陈裁判档案与预期不一致。', 1;
|
|
|
|
IF EXISTS (
|
|
SELECT 1 FROM dbo.AppUser
|
|
WHERE (Id IN (9004,9005,9006,9007) OR Mobile IN ('13800000004','13800000005','13800000006','13800000007'))
|
|
AND NOT ((Id = 9004 AND Mobile = '13800000004')
|
|
OR (Id = 9005 AND Mobile = '13800000005')
|
|
OR (Id = 9006 AND Mobile = '13800000006')
|
|
OR (Id = 9007 AND Mobile = '13800000007'))
|
|
)
|
|
THROW 51003, N'预留 AppUser ID 或手机号已被其他账号占用。', 1;
|
|
|
|
IF EXISTS (
|
|
SELECT 1 FROM dbo.Referee
|
|
WHERE (Id IN (9006,9007) OR Mobile IN ('13800000006','13800000007'))
|
|
AND NOT ((Id = 9006 AND Mobile = '13800000006') OR (Id = 9007 AND Mobile = '13800000007'))
|
|
)
|
|
THROW 51004, N'预留裁判档案 ID 或手机号已被占用。', 1;
|
|
|
|
IF EXISTS (
|
|
SELECT 1 FROM dbo.EventReferee
|
|
WHERE Id IN (8004,8005,8006,8007)
|
|
AND NOT ((Id = 8004 AND RefereeId = 9004)
|
|
OR (Id = 8005 AND RefereeId = 9005)
|
|
OR (Id = 8006 AND RefereeId = 9006)
|
|
OR (Id = 8007 AND RefereeId = 9007))
|
|
)
|
|
THROW 51005, N'预留赛事裁判 ID 已被其他档案占用。', 1;
|
|
|
|
IF EXISTS (
|
|
SELECT 1 FROM dbo.EventJudgeAssignment
|
|
WHERE Id IN (9104,9105,9106,9107)
|
|
AND NOT ((Id = 9104 AND RefereeId = 9004)
|
|
OR (Id = 9105 AND RefereeId = 9005)
|
|
OR (Id = 9106 AND RefereeId = 9006)
|
|
OR (Id = 9107 AND RefereeId = 9007))
|
|
)
|
|
THROW 51006, N'预留裁判席位 ID 已被占用。', 1;
|
|
|
|
DECLARE @Accounts TABLE (
|
|
UserId BIGINT NOT NULL,
|
|
RefereeId BIGINT NOT NULL,
|
|
EventRefereeId BIGINT NOT NULL,
|
|
AssignmentId BIGINT NOT NULL,
|
|
Name NVARCHAR(64) NOT NULL,
|
|
Mobile VARCHAR(20) NOT NULL,
|
|
RoleMask INT NOT NULL,
|
|
JudgeRole VARCHAR(32) NOT NULL,
|
|
JudgeRoleType VARCHAR(16) NOT NULL,
|
|
PasswordPrefix VARCHAR(16) NOT NULL,
|
|
PlainPassword VARCHAR(64) NOT NULL
|
|
);
|
|
|
|
INSERT INTO @Accounts VALUES
|
|
(9004,9004,8004,9104,N'赵裁判','13800000004',4,'DJ2','DJ','WaMM','$(JudgeDJ2Password)'),
|
|
(9005,9005,8005,9105,N'陈裁判','13800000005',4,'DT1','DT','YlOL','$(JudgeDT1Password)'),
|
|
(9006,9006,8006,9106,N'QA裁判-DT2','13800000006',4,'DT2','DT','aRq5','$(JudgeDT2Password)'),
|
|
(9007,9007,8007,9107,N'QA裁判-P2','13800000007',2,'P2','P','yekr','$(JudgeP2Password)');
|
|
|
|
MERGE dbo.AppUser AS target
|
|
USING @Accounts AS source ON target.Id = source.UserId
|
|
WHEN MATCHED THEN UPDATE SET
|
|
target.Name = source.Name,
|
|
target.Mobile = source.Mobile,
|
|
target.Password = LOWER(CONVERT(VARCHAR(32), HASHBYTES('MD5', source.PasswordPrefix + source.PlainPassword), 2)),
|
|
target.MiniProgramRole = 2,
|
|
target.AuditStatus = 2,
|
|
target.Status = 0,
|
|
target.DeleteMark = 0,
|
|
target.UpdatedUserId = 0,
|
|
target.UpdatedTime = GETDATE()
|
|
WHEN NOT MATCHED THEN INSERT
|
|
(Id, Name, Gender, Mobile, AuditStatus, Status, DeleteMark, CreatedUserId, CreatedTime,
|
|
PersonType, Password, AuthType, MiniProgramRole, AuditTime, Remark)
|
|
VALUES
|
|
(source.UserId, source.Name, 0, source.Mobile, 2, 0, 0, 0, GETDATE(),
|
|
0, LOWER(CONVERT(VARCHAR(32), HASHBYTES('MD5', source.PasswordPrefix + source.PlainPassword), 2)),
|
|
0, 2, GETDATE(), N'交互绳七席端到端 QA 裁判账号');
|
|
|
|
MERGE dbo.Referee AS target
|
|
USING (SELECT * FROM @Accounts WHERE RefereeId IN (9006,9007)) AS source ON target.Id = source.RefereeId
|
|
WHEN MATCHED THEN UPDATE SET
|
|
target.Name = source.Name,
|
|
target.Mobile = source.Mobile,
|
|
target.AppUserId = source.UserId,
|
|
target.Roles = source.RoleMask,
|
|
target.AuditStatus = 2,
|
|
target.Status = 0,
|
|
target.DeleteMark = 0,
|
|
target.UpdatedUserId = 0,
|
|
target.UpdatedTime = GETDATE()
|
|
WHEN NOT MATCHED THEN INSERT
|
|
(Id,Name,Mobile,AppUserId,ProvinceCode,ProvinceName,CityCode,CityName,DistrictCode,DistrictName,
|
|
Level,CertificateUrl,Roles,AuditStatus,AuditRemark,AuditUserId,AuditTime,Status,DeleteMark,CreatedUserId,CreatedTime)
|
|
VALUES
|
|
(source.RefereeId,source.Name,source.Mobile,source.UserId,'310000',N'上海市','310100',N'上海市','310101',N'QA测试区',
|
|
3,'',source.RoleMask,2,N'交互绳七席端到端 QA 专用',0,GETDATE(),0,0,0,GETDATE());
|
|
|
|
UPDATE referee SET
|
|
referee.AppUserId = account.UserId,
|
|
referee.Roles = account.RoleMask,
|
|
referee.AuditStatus = 2,
|
|
referee.Status = 0,
|
|
referee.DeleteMark = 0,
|
|
referee.UpdatedUserId = 0,
|
|
referee.UpdatedTime = GETDATE()
|
|
FROM dbo.Referee referee
|
|
INNER JOIN @Accounts account ON account.RefereeId = referee.Id;
|
|
|
|
MERGE dbo.EventReferee AS target
|
|
USING @Accounts AS source ON target.Id = source.EventRefereeId
|
|
WHEN MATCHED THEN UPDATE SET
|
|
target.EventId = 466884260081669,
|
|
target.RefereeId = source.RefereeId,
|
|
target.SourceType = 1,
|
|
target.Status = 0,
|
|
target.DeleteMark = 0,
|
|
target.UpdatedUserId = 0,
|
|
target.UpdatedTime = GETDATE()
|
|
WHEN NOT MATCHED THEN INSERT
|
|
(Id,EventId,RefereeId,RefereeApplicationId,SourceType,Status,DeleteMark,CreatedUserId,CreatedTime)
|
|
VALUES
|
|
(source.EventRefereeId,466884260081669,source.RefereeId,NULL,1,0,0,0,GETDATE());
|
|
|
|
IF EXISTS (
|
|
SELECT 1 FROM dbo.EventJudgeAssignment
|
|
WHERE SessionId = 468424868974597 AND AssignmentStatus = 1 AND DeleteMark = 0
|
|
AND JudgeRole IN ('DJ2','DT1','DT2','P2') AND Id NOT IN (9104,9105,9106,9107)
|
|
)
|
|
THROW 51007, N'目标席位已存在其他有效分配,请先人工核对。', 1;
|
|
|
|
MERGE dbo.EventJudgeAssignment AS target
|
|
USING @Accounts AS source ON target.Id = source.AssignmentId
|
|
WHEN MATCHED THEN UPDATE SET
|
|
target.EventId = 466884260081669,
|
|
target.SessionId = 468424868974597,
|
|
target.EventRefereeId = source.EventRefereeId,
|
|
target.RefereeId = source.RefereeId,
|
|
target.JudgeUserId = source.UserId,
|
|
target.JudgeRole = source.JudgeRole,
|
|
target.JudgeRoleType = source.JudgeRoleType,
|
|
target.AssignmentStatus = 1,
|
|
target.SubmittedTime = GETDATE(),
|
|
target.Remark = N'交互绳七席端到端 QA 席位',
|
|
target.Status = 0,
|
|
target.DeleteMark = 0,
|
|
target.UpdatedUserId = 0,
|
|
target.UpdatedTime = GETDATE()
|
|
WHEN NOT MATCHED THEN INSERT
|
|
(Id,EventId,SessionId,EventRefereeId,RefereeId,JudgeUserId,JudgeRole,JudgeRoleType,
|
|
AssignmentStatus,SubmittedTime,Remark,Status,DeleteMark,CreatedUserId,CreatedTime)
|
|
VALUES
|
|
(source.AssignmentId,466884260081669,468424868974597,source.EventRefereeId,source.RefereeId,source.UserId,
|
|
source.JudgeRole,source.JudgeRoleType,1,GETDATE(),N'交互绳七席端到端 QA 席位',0,0,0,GETDATE());
|
|
|
|
IF (SELECT COUNT(*) FROM dbo.EventJudgeAssignment
|
|
WHERE SessionId = 468424868974597 AND AssignmentStatus = 1 AND Status = 0 AND DeleteMark = 0
|
|
AND JudgeRole IN ('DJ1','DJ2','DT1','DT2','P1','P2','T')) <> 7
|
|
THROW 51008, N'交互绳七个有效席位校验失败。', 1;
|
|
|
|
COMMIT TRANSACTION;
|
|
|
|
SELECT a.Mobile,a.Name,a.JudgeRole,a.JudgeRoleType,a.RoleMask
|
|
FROM @Accounts a ORDER BY a.AssignmentId;
|