博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
带事务的存储过程
阅读量:5942 次
发布时间:2019-06-19

本文共 4633 字,大约阅读时间需要 15 分钟。

CREATE PROCEDURE [dbo].[Proc_SaveIDCardDetectInfo]     @IDInfoXml NVARCHAR(MAX),     @detectXml NVARCHAR(MAX),     @UserId int,     @DetectResult bit,     @Success bit output,     @Message NVARCHAR(50) output     ASBEGIN    BEGIN TRANSACTION;    BEGIN TRY        Set @Message =''        --- 保存身份证信息, 上传图片时创建记录,此处只保存信息        SET NOCOUNT ON;        DECLARE @hdoc INT        EXEC sp_xml_preparedocument @hdoc OUTPUT, @IDInfoXml                Set @Success =0        Declare @IDCardNum VARCHAR(20)                SELECT @IDCardNum=fxml.IDCardNum        FROM openxml(@hDoc,'/IndentityCardInfoEntity',2)         with(                      UserId     int                     ,IDCardNum VARCHAR(20)) as fxml        IF EXISTS(SELECT 1 FROM  dbo.RealNameCertResult r INNER JOIN  dbo.IndentityCardInfo ic ON ic.UserId=r.UserId               WHERE     ic.IDCardNum=@IDCardNum    and r.Result=1)           BEGIN               SET @Message ='此身份证号已通过实名认证,不能重复认证'                COMMIT TRANSACTION;                Return           END                                                            IF NOT EXISTS (SELECT 1 FROM dbo.IndentityCardInfo WHERE UserId=@UserId)        BEGIN            INSERT INTO dbo.IndentityCardInfo             ([UserId])     Values (@UserId)        END                UPDATE IndentityCardInfo                SET  --[UserId] =                IDCardNum=fxml.IDCardNum               ,[Name]=fxml.Name               ,Gender=fxml.Gender               ,Race=fxml.Race               ,[BirthDay]=fxml.[BirthDay]               ,[Address]=fxml.[Address]               ,ValidDate=fxml.ValidDate               ,IssuedBy=fxml.IssuedBy               , UpdateTime=GETDATE()                    FROM openxml(@hDoc,'/IndentityCardInfoEntity',2)                     with(                      UserId     int                     ,IDCardNum VARCHAR(20)                     ,Name     NVARCHAR(30)                     ,Gender   NVARCHAR(10)                      ,Race  NVARCHAR(30)                     ,[BirthDay]  datetime                     ,[Address]  NVARCHAR(100)                     ,ValidDate  VARCHAR(20)                     ,IssuedBy  NVARCHAR(100)                     --,[IdentityCardPic1]  NVARCHAR(150)                     --,[IdentityCardPic2] NVARCHAR(150)                                         ) as fxml                    WHERE IndentityCardInfo.UserId=@UserId            SET NOCOUNT OFF;        --- 保存检测结果        EXEC sp_xml_preparedocument @hdoc OUTPUT, @detectXml        DELETE dbo.IDCardLegalityResult WHERE UserId=@UserId        INSERT INTO IDCardLegalityResult           ([UserId]           ,[Side]           ,[IDPhoto]           ,[TemporaryIDPhoto]           ,[Photocopy]           ,[Screen]           ,[Edited])        SELECT @UserId,  *                FROM openxml(@hDoc,'/ArrayOfIDCardLegalityResultEntity/IDCardLegalityResultEntity',2)                     WITH(                      [Side]     INT                     ,[IDPhoto] DECIMAL(18,3)                     ,[TemporaryIDPhoto]    DECIMAL(18,3)                     ,[Photocopy]   DECIMAL(18,3)                     ,[Screen]  DECIMAL(18,3)                     ,[Edited]  DECIMAL(18,3))                             EXEC SP_XML_REMOVEDOCUMENT @hDoc                       if NOT EXISTS( Select 1 FROM  dbo.IDCardLegalityResult WHERE UserId=@UserId)        BEGIN             SET @Message ='合法性概率值参数错误'             ROLLBACK TRANSACTION;        END        ELSE BEGIN         Set @Success =1        END         --- 维护 实名认证结果数据        IF NOT EXISTS (SELECT 1 FROM dbo.RealNameCertResult WHERE UserId=@UserId)        BEGIN            INSERT INTO [RealNameCertResult]             (                [UserId]               ,[IDCardResult]               ,[IsCompleted]                )           VALUES               (@UserId               ,@DetectResult               ,0               )        END        ELSE BEGIN            UPDATE [RealNameCertResult]                 SET IDCardResult=@DetectResult                 WHERE UserId=@UserId        END             END TRY     BEGIN CATCH                         SELECT ERROR_NUMBER () AS ErrorNumber,                ERROR_SEVERITY () AS ErrorSeverity,                ERROR_STATE () AS ErrorState,                ERROR_PROCEDURE () AS ErrorProcedure,                ERROR_LINE () AS ErrorLine,                ERROR_MESSAGE () AS ErrorMessage;         SET @Message =ERROR_MESSAGE()         Set @Success =0         IF @@TRANCOUNT > 0            ROLLBACK TRANSACTION;      END CATCH;      COMTran:        IF @@TRANCOUNT > 0        BEGIN         COMMIT TRANSACTION;       ENDENDGO

 

转载于:https://www.cnblogs.com/czqbk/p/6550912.html

你可能感兴趣的文章
开发安全的 API 所需要核对的清单
查看>>
Mycat源码中的单例模式
查看>>
WPF Dispatcher介绍
查看>>
fiddler展示serverIP方法
查看>>
C语言中的随意跳转
查看>>
WPF中如何将ListViewItem双击事件绑定到Command
查看>>
《聚散两依依》
查看>>
小tips:你不知道的 npm init
查看>>
Mac笔记本中是用Idea开发工具在Java项目中调用python脚本遇到的环境变量问题解决...
查看>>
Jmeter也能IP欺骗!
查看>>
Rust 阴阳谜题,及纯基于代码的分析与化简
查看>>
ASP.NET Core的身份认证框架IdentityServer4(4)- 支持的规范
查看>>
(原創) array可以使用reference方式傳進function嗎? (C/C++)
查看>>
170多个Ionic Framework学习资源(转载)
查看>>
Azure:不能把同一个certificate同时用于Azure Management和RDP
查看>>
Directx11教程(15) D3D11管线(4)
查看>>
Microsoft Excel软件打开文件出现文件的格式与文件扩展名指定格式不一致?
查看>>
ios ble 参考
查看>>
linux中注册系统服务—service命令的原理通俗
查看>>
基于托管C++的增删改查及异步回调小程序
查看>>