using System; using System.Collections.Generic; using System.Text; using H3; public class D2796247609923b101140e689622d8b39651b39_ListViewController: H3.SmartForm.ListViewController { public D2796247609923b101140e689622d8b39651b39_ListViewController(H3.SmartForm.ListViewRequest request): base(request) { } protected override void OnLoad(H3.SmartForm.LoadListViewResponse response) { base.OnLoad(response); } protected override void OnSubmit(string actionName, H3.SmartForm.ListViewPostValue postValue, H3.SmartForm.SubmitListViewResponse response) { if(actionName == "Remove") { // 删除数据ID:氚云列表页面,批量删除只能监听后端事件【最终执行】且若执行代码报错,删除会自动回滚。前端只能监听到点击删除,但监听不到确认、取消的回调。 Dictionary < string, object > data = postValue.Data; object selectIds = null; // 获取勾选ID集合 if(data.TryGetValue("ObjectIds", out selectIds)) { Dictionary < string, object > bodys = new Dictionary(); bodys.Add("actionName", actionName); // 动作名称 // 处理氚云sql格式,in查询实例必须添加单引号,否则不能匹配 string[] objectIds = (string[]) selectIds; List < string > fIds = new List(); foreach(string objectId in objectIds) { fIds.Add(string.Format("'{0}'", objectId)); } System.Data.DataTable records = this.Engine.Query.QueryTable(string.Format("select origionContractCode, SeqNo, fileNames, Status from i_D2796247609923b101140e689622d8b39651b39 where ObjectId in ({0})", string.Join(",", fIds)), null); bodys.Add("bizObjects", this.Serialize(records)); // 合同记录【生效数据过滤,代码处理】 // 氚云默认字段冲突: sOrigionContractCode as origionContractCode [select * 后,两个字段都会同时存在,若字段相同则会被 * 覆盖, 如 DATE_FORMAT,需要另开一个字段] System.Data.DataTable terms = this.Engine.Query.QueryTable(string.Format("select DATE_FORMAT(cDateTime,'%Y-%m-%d') dateTime, agreementType from i_D279624F24d78c5510764cba928395c32b9406d6 where ParentObjectId in ({0})", string.Join(",", fIds)), null); bodys.Add("termsObject", this.Serialize(terms)); // 合同条款 List < H3.BizBus.ItemSchema > structures = new List(); // 响应类型 this.invokeVendorService("delete", bodys, structures); // 请求处理 } } base.OnSubmit(actionName, postValue, response); } /** * 氚云HTTP * 1. code 公用请求,code区分业务逻辑 * 2. bodys 请求参数,默认POST,application/json * 3. structures 返回数据格式定义, 统一使用对象响应 */ private H3.BizBus.BizStructure invokeVendorService(string code, Dictionary < string, object > bodys, List < H3.BizBus.ItemSchema > structures) { H3.IEngine engine = this.Engine; // 请求信息 Dictionary < string, string > headers = new Dictionary(); Dictionary < string, string > querys = new Dictionary(); querys.Add("code", code); // 定义响应数据整体结构体 H3.BizBus.BizStructureSchema structureSchema = new H3.BizBus.BizStructureSchema(); structureSchema.Add(new H3.BizBus.ItemSchema("code", "结果状态码", H3.Data.BizDataType.Int, null)); structureSchema.Add(new H3.BizBus.ItemSchema("success", "请求状态位", H3.Data.BizDataType.Bool, null)); structureSchema.Add(new H3.BizBus.ItemSchema("message", "描述信息", H3.Data.BizDataType.String, null)); // 定义响应数据的 data 属性 的结构体 H3.BizBus.BizStructureSchema dataSchema = new H3.BizBus.BizStructureSchema(); foreach(H3.BizBus.ItemSchema itemSchame in structures) { dataSchema.Add(itemSchame); } //将 data 属性的结构体添加进整体的响应数据结构体 [H3.Data.BizDataType.BizStructureArray 集合,H3.Data.BizDataType.BizStructure 对象] structureSchema.Add(new H3.BizBus.ItemSchema("data", "响应数据", H3.Data.BizDataType.BizStructure, dataSchema)); //调用Invoke接口,系统底层访问第三方接口的Invoke方法 H3.BizBus.InvokeResult response = engine.BizBus.InvokeApi( H3.Organization.User.SystemUserId, //固定值,无需改变 H3.BizBus.AccessPointType.ThirdConnection, //固定值,无需改变 "h3yun-http", //连接编码,对应 插件中心 中配置的连接的编码 "POST", //请求方式,取值:GET / POST "application/json", //请求数据类型: json - "application/json";xml - "text/html;charset=utf-8" headers, querys, bodys, structureSchema); if(response != null) { // 氚云调用是否成功 if(response.Code == 0) { // 获取返回数据,此实例对应完整的响应JSON H3.BizBus.BizStructure rspData = response.Data; if(((bool) rspData["success"]) == true) { // 对象响应【氚云自定义字段,需要通过[]直接取值才有效,序列化后返回前端,仅会保留结构】 // H3.BizBus.BizStructure[] datas = rspData["data"] as H3.BizBus.BizStructure[]; // 集合解析 // H3.BizBus.BizStructure data = rspData["data"] as H3.BizBus.BizStructure; // 对象解析 return rspData["data"] as H3.BizBus.BizStructure; } else { throw new Exception("接口异常," + rspData["message"]); } } else { throw new Exception("氚云异常," + response.Message); } } else { throw new Exception("系统异常,接口无响应"); } } }