GO IF object_id('dbo.PGetBizConfig','P') IS NOT NULL BEGIN DROP PROCEDURE dbo.PGetBizConfig END GO CREATE PROCEDURE PGetBizConfig ( @CompId BIGINT, --公司ID @Key VARCHAR(128), --参数代码 @Value VARCHAR(1024) OUTPUT --返回参数 ) AS BEGIN IF OBJECT_ID('TBizConfig') IS NOT NULL AND EXISTS(SELECT 1 FROM TBizConfig) BEGIN SELECT @Value = ISNULL(FValue,'') FROM TBizConfig WITH(NOLOCK) WHERE FKey = @Key AND FCompId = @CompId RETURN END IF @CompId = 1 --总公司 BEGIN SELECT @Value = ISNULL(FValue,'') FROM TSystemParam WITH(NOLOCK) WHERE FKey = @Key END ELSE BEGIN SELECT @Value = ISNULL(TB.FValue,T.FValue) FROM TSystemParam AS T LEFT JOIN TSystemParamSub AS TB ON TB.FParamKey=T.FKey AND TB.FCompId=@CompId AND T.FKey = TB.FParamKey WHERE T.FKey = @Key END END GO DROP TABLE #BizCompany DROP TABLE #SMSCompany DELETE TBizConfig SELECT B.FCompId INTO #BizCompany FROM TSystemParam AS A,TSystemParamSub AS B WHERE A.FKey = B.FParamKey AND A.FValue != B.FValue AND A.FCategory != 'SMS' GROUP BY B.FCompId SELECT B.FCompId INTO #SmsCompany FROM TSystemParam AS A,TSystemParamSub AS B WHERE A.FKey = B.FParamKey AND A.FValue != B.FValue AND A.FCategory = 'SMS' GROUP BY B.FCompId --这都是同步的 INSERT TBasicDataSyncControl (FId,FCompId,FCategory,FMode) SELECT dbo.FNNewId(),A.FId,'BizConfig',1 FROM TCompany AS A WHERE A.FId > 0 AND A.FId NOT IN(SELECT FCompId FROM #BizCompany) INSERT TBasicDataSyncControl (FId,FCompId,FCategory,FMode) SELECT dbo.FNNewId(),A.FId,'SMSConfig',1 FROM TCompany AS A WHERE A.FId > 0 AND A.FId NOT IN(SELECT FCompId FROM #SMSCompany) --这是不同步的 INSERT TBasicDataSyncControl (FId,FCompId,FCategory,FMode) SELECT dbo.FNNewId(),A.FId,'BizConfig',0 FROM TCompany AS A WHERE A.FId > 0 AND A.FId IN(SELECT FCompId FROM #BizCompany) INSERT TBasicDataSyncControl (FId,FCompId,FCategory,FMode) SELECT dbo.FNNewId(),A.FId,'SMSConfig',0 FROM TCompany AS A WHERE A.FId > 0 AND A.FId IN(SELECT FCompId FROM #SMSCompany) --这是同步的 INSERT INTO TBizConfig(FCompId,FKey,FDataType,FValue,FDescription,FCategory) SELECT C.FId,A.FKey,A.FDataType,A.FValue,A.FDescription,A.FCategory FROM TSystemParam AS A,TCompany AS C WHERE A.FCategory != 'SMS' AND C.FId NOT IN(SELECT FCompId FROM #BizCompany) AND C.FId != 0 INSERT INTO TBizConfig(FCompId,FKey,FDataType,FValue,FDescription,FCategory) SELECT C.FId,A.FKey,A.FDataType,A.FValue,A.FDescription,A.FCategory FROM TSystemParam AS A,TCompany AS C WHERE A.FCategory = 'SMS' AND C.FId NOT IN(SELECT FCompId FROM #SMSCompany) AND C.FId != 0 --这是不同步的 INSERT INTO TBizConfig(FCompId,FKey,FDataType,FValue,FDescription,FCategory) SELECT C.FId,A.FKey,A.FDataType,A.FValue,A.FDescription,A.FCategory FROM TSystemParam AS A,TCompany AS C WHERE A.FCategory != 'SMS' AND C.FId IN(SELECT FCompId FROM #BizCompany) AND C.FId != 0 INSERT INTO TBizConfig(FCompId,FKey,FDataType,FValue,FDescription,FCategory) SELECT C.FId,A.FKey,A.FDataType,A.FValue,A.FDescription,A.FCategory FROM TSystemParam AS A,TCompany AS C WHERE A.FCategory = 'SMS' AND C.FId IN(SELECT FCompId FROM #SMSCompany) AND C.FId != 0