关于事务处理过程中,查询事务相关表的处理方式

关于事务处理过程中,查询事务相关表的处理方式

DBServerProvider.SqlDapper 与 repository 的区别及应用场景
        public override WebResponseContent Audit(object[] keys, int? auditStatus, string auditReason)
        {
            Tools tools = new Tools();
            int laststep = tools.LastStep((string)keys[0], "ST_LockUnlock");

            //status当前审批状态,lastAudit是否最后一个审批节点
            AuditWorkFlowExecuting = (ST_LockUnlock lockUnlock, AuditStatus status, bool lastAudit) =>
            {
                return webResponse.OK();
            };
            //status当前审批状态,nextUserIds下一个节点审批人的帐号id(可以从sys_user表中查询用户具体信息),lastAudit是否最后一个审批节点
            AuditWorkFlowExecuted = (ST_LockUnlock lockUnlock, AuditStatus status, List<int> nextUserIds, bool lastAudit) =>
            {
                if (!lastAudit)
                {
                    if (laststep == 1 && auditStatus == 1)
                    {
                        //获取表码调整记录及对应的日记录信息
                        //对事务相关的表进行访问,要放到事务中处理,因为这些表会被锁定,事务结束后才能访问,
                        //用DBServerProvider.SqlDapper.QueryDynamicListAsync(sql, "")这种方法要等到事务结束才能执行,与事务无关的表,可以用这种方法
                        //因此要用repository.FromSql(bql)这种方法

                        string bql = $@"
                            SELECT *
                            FROM ST_LockUnlock
                            WHERE LockUnlockID={keys[0]}
                        ";
                        var data = repository.FromSql(bql);//sql 必须返回所有字段
                        if (data==null)
                        {
                            return webResponse.Error("无数据!");
                        }
                        if (data[0].MeterID == null) { return webResponse.Error("无仪表信息!"); }
                        if (data[0].ReqType == null) { return webResponse.Error("开关类型为空!"); }
                        if (data[0].WorkDate == null) { return webResponse.Error("施工日期为空!"); }
                        //更新到仪表信息表 ST_CodeMeter
                        string cql = $@"UPDATE ST_CodeMeter
                            SET ValveState='{data[0].ReqType}',LockunlockDate='{data[0].WorkDate}' 
                            WHERE MeterID={data[0].MeterID}";
                        repository.ExecuteSqlCommand(cql);
                    }
                }

                return webResponse.OK();
            };
            return base.Audit(keys, auditStatus, auditReason);
        }

    }

 

posted @ 2024-03-18 11:00  中国结  阅读(18)  评论(0编辑  收藏  举报