144 lines
11 KiB
Transact-SQL
144 lines
11 KiB
Transact-SQL
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
|
||
VALUES ( '1','建设方')
|
||
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
|
||
VALUES ( '2','总承包商')
|
||
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
|
||
VALUES ( '3','监理')
|
||
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
|
||
VALUES ( '4','检测')
|
||
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
|
||
VALUES ( '5','施工')
|
||
GO
|
||
|
||
ALTER TABLE dbo.Sys_DataInTemp ADD Value35 nvarchar(100) NULL
|
||
GO
|
||
|
||
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[Sys_RolePower]') AND name = N'IX_Sys_RolePower_RoleId_ProjectId')
|
||
DROP INDEX [IX_Sys_RolePower_RoleId_ProjectId] ON [dbo].[Sys_RolePower] WITH ( ONLINE = OFF )
|
||
GO
|
||
|
||
CREATE UNIQUE NONCLUSTERED INDEX [IX_Sys_RolePower_RoleId_MenuId] ON [dbo].[Sys_RolePower]
|
||
(
|
||
[RoleId] ASC,
|
||
[MenuId] ASC
|
||
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||
GO
|
||
|
||
ALTER PROCEDURE [dbo].[SpGetNewCode]
|
||
@tableName VARCHAR(50),/*表名*/
|
||
@columnName VARCHAR(50),/*列名*/
|
||
@projectId NVARCHAR(50),/*项目*/
|
||
@prefix VARCHAR(50),/*流水号编码前缀*/
|
||
@returnVal NVARCHAR(50) OUTPUT
|
||
AS
|
||
/*获取一个新的流水号(后五位上增加)*/
|
||
DECLARE
|
||
@sql NVARCHAR(500),
|
||
@old NVARCHAR(50),
|
||
@newid VARCHAR(50),
|
||
@maxId NVARCHAR(50)/*已分配的最大值*/
|
||
SELECT @sql=N'SELECT @maxId=MAX('+@columnName+') from '+@tableName+' where ProjectId = ''' + @projectId + ''' and ' + @columnName+' like ' + '''%' + @prefix + '%'''
|
||
EXEC sp_executesql @sql, N'@maxId nvarchar(50) OUTPUT', @maxId OUTPUT
|
||
/*因为最后字串包括R1,K1,所以这么处理*/
|
||
SET @old=REVERSE(SUBSTRING(REVERSE(@maxId),1,CHARINDEX('-',REVERSE(@maxId))-1))
|
||
|
||
IF(@old IS NULL)
|
||
BEGIN
|
||
SET @newid=@prefix+'00001'
|
||
END
|
||
|
||
ELSE
|
||
BEGIN
|
||
SET @newid = (SELECT MAX(LEFT(@old,5)))+1
|
||
SET @newid = @prefix +RIGHT('00000'+@newid,5)
|
||
END
|
||
|
||
SET @returnVal=@newid
|
||
|
||
GO
|
||
|
||
|
||
CREATE PROCEDURE [dbo].[SpGetThreeNumber]
|
||
@tableName VARCHAR(50),/*表名*/
|
||
@columnName VARCHAR(50),/*列名*/
|
||
@projectId NVARCHAR(50),/*项目*/
|
||
@prefix VARCHAR(50),/*流水号编码前缀*/
|
||
@returnVal NVARCHAR(50) OUTPUT
|
||
AS
|
||
/*获取三位流水号(后三位上增加)*/
|
||
DECLARE
|
||
@sql NVARCHAR(500),
|
||
@old NVARCHAR(50),
|
||
@newid VARCHAR(50),
|
||
@maxId NVARCHAR(50)/*已分配的最大值*/
|
||
SELECT @sql=N'SELECT @maxId=MAX('+@columnName+') from '+@tableName+' where ProjectId = ''' + @projectId + ''' and ' + @columnName+' like ' + '''%' + @prefix + '%'''
|
||
EXEC sp_executesql @sql, N'@maxId nvarchar(50) OUTPUT', @maxId OUTPUT
|
||
SET @old=@maxId
|
||
|
||
IF(@old IS NULL)
|
||
BEGIN
|
||
SET @newid=@prefix+'001'
|
||
END
|
||
|
||
ELSE
|
||
BEGIN
|
||
SET @newid = (SELECT MAX(RIGHT(@old,3)))+1
|
||
SET @newid = @prefix +RIGHT('000'+@newid,3)
|
||
END
|
||
|
||
SET @returnVal=@newid
|
||
|
||
GO
|
||
|
||
|
||
ALTER VIEW [dbo].[View_GenerateTrust]
|
||
AS
|
||
-------正常点口生成委托-----------
|
||
SELECT point.ProjectId,point.InstallationId,pipe.WorkAreaId ,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId,'1' AS PointState,CAST(0 AS BIT) AS IsCheckRepair, NULL AS TrustBatchCode
|
||
FROM dbo.Batch_PointBatchItem pointItem
|
||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
|
||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pointItem.WeldJointId
|
||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
|
||
WHERE pointItem.PointState ='1' AND point.EndDate IS NOT NULL AND pointItem.CutDate IS NULL
|
||
AND (pointItem.IsBuildTrust IS NULL OR pointItem.IsBuildTrust=0) AND point.IsTrust=0
|
||
AND pointItem.IsCheckRepair=0
|
||
GROUP BY point.ProjectId,point.InstallationId,pipe.WorkAreaId,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId
|
||
|
||
UNION ALL
|
||
-------扩透生成委托-----------
|
||
SELECT point.ProjectId,point.InstallationId,pipe.WorkAreaId ,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId,'2' AS PointState,CAST(0 AS BIT) AS IsCheckRepair, trust.TrustBatchCode
|
||
FROM dbo.Batch_PointBatchItem pointItem
|
||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
|
||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pointItem.WeldJointId
|
||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
|
||
LEFT JOIN dbo.Batch_BatchTrustItem trustItem ON trustItem.PointBatchItemId=pointItem.ToPointBatchItemId
|
||
LEFT JOIN dbo.Batch_BatchTrust trust ON trust.TrustBatchId = trustItem.TrustBatchId
|
||
WHERE pointItem.PointState ='2' AND point.EndDate IS NOT NULL
|
||
AND pointItem.CutDate IS NULL AND (pointItem.IsBuildTrust IS NULL OR pointItem.IsBuildTrust=0) AND point.IsTrust=0
|
||
GROUP BY point.ProjectId,point.InstallationId,pipe.WorkAreaId,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId,trust.TrustBatchCode
|
||
|
||
UNION ALL
|
||
-------返修生成委托-----------
|
||
SELECT point.ProjectId,point.InstallationId,pipe.WorkAreaId ,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId,'1' AS PointState,CAST(1 AS BIT) AS IsCheckRepair, trust.TrustBatchCode
|
||
FROM dbo.Batch_PointBatchItem pointItem
|
||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
|
||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pointItem.WeldJointId
|
||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
|
||
LEFT JOIN dbo.Batch_BatchTrustItem trustItem ON trustItem.PointBatchItemId=pointItem.PointBatchItemId
|
||
LEFT JOIN dbo.Batch_BatchTrust trust ON trust.TrustBatchId = trustItem.TrustBatchId
|
||
WHERE pointItem.PointState ='1' AND pointItem.IsCheckRepair=1 AND point.EndDate IS NOT NULL
|
||
AND pointItem.CutDate IS NULL AND (pointItem.IsBuildTrust IS NULL OR pointItem.IsBuildTrust=0) AND point.IsTrust=0
|
||
GROUP BY point.ProjectId,point.InstallationId,pipe.WorkAreaId,point.UnitId,point.DetectionTypeId,
|
||
jot.PipelineId,trust.TrustBatchCode
|
||
GO
|
||
|
||
|
||
|
||
|
||
|