MP之插件开发-事务
来源:互联网 发布:mac用破解版软件风险 编辑:程序博客网 时间:2024/06/04 17:54
MP平台在批处理数据时,一般是使用LoopDo规则,进行循环处理。
该方法的缺点是:没有事务,使得批处理在失败时,没有回滚。
开发准备--导入dll:
LY.EAP.Workflow.Plugin.dll
LY.TEC.Data.Common.dll
LY.TEC.Data.Data2.dll
LY.TEC.Excel.dll
插件代码1:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using LY.TEC.Data.Data2;using System.Data.Common;namespace LY.CLP.MP.Plugin.DunTask{ /// <summary> /// 说明:催收分配管理 /// 作者:叶晓东 /// 时间:2015-10-22 /// </summary> public class DunTaskAllot { /// <summary> /// 电话催收分配 /// </summary> /// <param name="userID">最后更新人员ID</param> /// <param name="alloterID">任务处理人ID</param> /// <param name="dt">数据集,包含催收任务ID,并发ID</param> /// <returns name="dicResult">Dictionary<string,object></returns> public Dictionary<string, object> PhoneAllot(string userID,string alloterID,DataTable dt) { Dictionary<string,object> dicResult = new Dictionary<string,object>(); string msg ="成功"; Gateway gateway = Gateway.Default; DbTransaction tran = gateway.BeginTransaction(); //CustomSqlSection custom = gateway.FromCustomSql("."); //custom.SetTransaction(tran); try { foreach(DataRow dr in dt.Rows) { msg = UpdateAllot(gateway, tran, userID, alloterID, dr["BU_DUN_TASK_ID"].ToString(), dr["UPDATE_CONTROL_ID"].ToString()); if(msg!="成功") { tran.Rollback(); dicResult.Add("msg",msg); return dicResult; } } } catch(Exception e) { tran.Rollback(); dicResult.Add("msg",e.ToString()); return dicResult; } tran.Commit(); dicResult.Add("msg", msg); return dicResult; } /// <summary> /// 修改催收任务表 /// </summary> /// <param name="gateway">连接数据库</param> /// <param name="tran">事务</param> /// <param name="userID">最后更新人员ID</param> /// <param name="alloterID">任务处理人ID</param> /// <param name="dunID">催收任务ID</param> /// <param name="controlID">并发ID</param> /// <returns></returns> public string UpdateAllot(Gateway gateway,DbTransaction tran,string userID,string alloterID,string dunID,string controlID) { try { CustomSqlSection custom = gateway.FromCustomSql("."); string sql = string.Format(@"UPDATE T_CLP_BU_DUN_TASK SET STATUS='0', MODIFIER='{0}', LAST_UPDATED_DATE=systimestamp, BU_DUN_TASK_MAN_ID='{1}', ASSIGN_DATE=systimestamp WHERE BU_DUN_TASK_ID='{2}' AND UPDATE_CONTROL_ID='{3}' ", userID, alloterID, dunID, controlID ); custom.Sql = sql; custom.SetTransaction(tran); if (custom.ExecuteNonQuery() > 0) return "成功"; else return "失败"; } catch (Exception e) { return e.ToString(); } } }}
步骤:
1.连接数据库;
2.创建事务;
3.生成sql;
4.添加事务;
5.执行;
6.提交/回滚。
代码分析:
连接数据库
Gateway gateway = Gateway.Default;
default表示使用默认的连接方式,这里的默认是MP配置配置文件的连接。
单元测试用:
Gateway gateway = new Gateway(DatabaseType.Oracle, "user id=zuchekf;Data Source=KFYCXMS;Password=zuchekf;Persist Security Info=True");
初始化SQL语句
CustomSqlSection custom = gateway.FromCustomSql(".");其中“."是一个SQL语句,由于同事们都这样使用,在这里本人跟风了一把。
其实这样使用会导致后面需要有:
custom.Sql = sql;
添加事务
custom.SetTransaction(tran);
所以可以在PhoneAllot方法中做统一的提交和回滚。
执行SQL
执行SQL
custom.ExecuteNonQuery()返回影响行数。
感谢
感谢,同事李磊的指导。
0 0
- MP之插件开发-事务
- MP-visual studio 插件管理
- MP之高级表单
- wap2.0之XHTML MP
- Android 数据库开发之事务
- Android开发之使用事务
- jQuery之插件开发
- openfire之插件开发
- 产品开发阶段 EVT DVT PVT MP
- WAP网站设计之xhtml mp
- 项目开发-iBatis事务源码之开启新事务
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- Eclipse插件开发之FindBugs插件
- WIFI营销读书笔记之一:Wifi营销基础知识
- UIView与CALayer
- FZU2203--比赛--10.1训练赛
- JSP include
- ios:数据持久化的几种方法浅谈
- MP之插件开发-事务
- info.plist
- I/O多路复用
- ssoj2437打字游戏
- 采用CXF框架开发HelloWorld WebService客户端
- 类的扩展
- hdu1009FatMouse's Trade
- C#学习之多线程开发技术(一)
- $在php里