上海市委-列表.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using H3;
  5. public class D2796247609923b101140e689622d8b39651b39_ListViewController: H3.SmartForm.ListViewController
  6. {
  7. public D2796247609923b101140e689622d8b39651b39_ListViewController(H3.SmartForm.ListViewRequest request): base(request)
  8. {
  9. }
  10. protected override void OnLoad(H3.SmartForm.LoadListViewResponse response)
  11. {
  12. base.OnLoad(response);
  13. }
  14. protected override void OnSubmit(string actionName, H3.SmartForm.ListViewPostValue postValue, H3.SmartForm.SubmitListViewResponse response)
  15. {
  16. if(actionName == "Remove")
  17. {
  18. // 删除数据ID:氚云列表页面,批量删除只能监听后端事件【最终执行】且若执行代码报错,删除会自动回滚。前端只能监听到点击删除,但监听不到确认、取消的回调。
  19. Dictionary < string, object > data = postValue.Data;
  20. object selectIds = null; // 获取勾选ID集合
  21. if(data.TryGetValue("ObjectIds", out selectIds))
  22. {
  23. Dictionary < string, object > bodys = new Dictionary<string, object>();
  24. bodys.Add("actionName", actionName); // 动作名称
  25. // 处理氚云sql格式,in查询实例必须添加单引号,否则不能匹配
  26. string[] objectIds = (string[]) selectIds;
  27. List < string > fIds = new List<string>();
  28. foreach(string objectId in objectIds)
  29. {
  30. fIds.Add(string.Format("'{0}'", objectId));
  31. }
  32. 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);
  33. bodys.Add("bizObjects", this.Serialize(records)); // 合同记录【生效数据过滤,代码处理】
  34. // 氚云默认字段冲突: sOrigionContractCode as origionContractCode [select * 后,两个字段都会同时存在,若字段相同则会被 * 覆盖, 如 DATE_FORMAT,需要另开一个字段]
  35. 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);
  36. bodys.Add("termsObject", this.Serialize(terms)); // 合同条款
  37. List < H3.BizBus.ItemSchema > structures = new List<H3.BizBus.ItemSchema>(); // 响应类型
  38. this.invokeVendorService("delete", bodys, structures); // 请求处理
  39. }
  40. }
  41. base.OnSubmit(actionName, postValue, response);
  42. }
  43. /**
  44. * 氚云HTTP
  45. * 1. code 公用请求,code区分业务逻辑
  46. * 2. bodys 请求参数,默认POST,application/json
  47. * 3. structures 返回数据格式定义, 统一使用对象响应
  48. */
  49. private H3.BizBus.BizStructure invokeVendorService(string code, Dictionary < string, object > bodys, List < H3.BizBus.ItemSchema > structures) {
  50. H3.IEngine engine = this.Engine;
  51. // 请求信息
  52. Dictionary < string, string > headers = new Dictionary<string, string>();
  53. Dictionary < string, string > querys = new Dictionary<string, string>();
  54. querys.Add("code", code);
  55. // 定义响应数据整体结构体
  56. H3.BizBus.BizStructureSchema structureSchema = new H3.BizBus.BizStructureSchema();
  57. structureSchema.Add(new H3.BizBus.ItemSchema("code", "结果状态码", H3.Data.BizDataType.Int, null));
  58. structureSchema.Add(new H3.BizBus.ItemSchema("success", "请求状态位", H3.Data.BizDataType.Bool, null));
  59. structureSchema.Add(new H3.BizBus.ItemSchema("message", "描述信息", H3.Data.BizDataType.String, null));
  60. // 定义响应数据的 data 属性 的结构体
  61. H3.BizBus.BizStructureSchema dataSchema = new H3.BizBus.BizStructureSchema();
  62. foreach(H3.BizBus.ItemSchema itemSchame in structures)
  63. {
  64. dataSchema.Add(itemSchame);
  65. }
  66. //将 data 属性的结构体添加进整体的响应数据结构体 [H3.Data.BizDataType.BizStructureArray 集合,H3.Data.BizDataType.BizStructure 对象]
  67. structureSchema.Add(new H3.BizBus.ItemSchema("data", "响应数据", H3.Data.BizDataType.BizStructure, dataSchema));
  68. //调用Invoke接口,系统底层访问第三方接口的Invoke方法
  69. H3.BizBus.InvokeResult response = engine.BizBus.InvokeApi(
  70. H3.Organization.User.SystemUserId, //固定值,无需改变
  71. H3.BizBus.AccessPointType.ThirdConnection, //固定值,无需改变
  72. "h3yun-http", //连接编码,对应 插件中心 中配置的连接的编码
  73. "POST", //请求方式,取值:GET / POST
  74. "application/json", //请求数据类型: json - "application/json";xml - "text/html;charset=utf-8"
  75. headers, querys, bodys, structureSchema);
  76. if(response != null)
  77. {
  78. // 氚云调用是否成功
  79. if(response.Code == 0)
  80. {
  81. // 获取返回数据,此实例对应完整的响应JSON
  82. H3.BizBus.BizStructure rspData = response.Data;
  83. if(((bool) rspData["success"]) == true)
  84. {
  85. // 对象响应【氚云自定义字段,需要通过[]直接取值才有效,序列化后返回前端,仅会保留结构】
  86. // H3.BizBus.BizStructure[] datas = rspData["data"] as H3.BizBus.BizStructure[]; // 集合解析
  87. // H3.BizBus.BizStructure data = rspData["data"] as H3.BizBus.BizStructure; // 对象解析
  88. return rspData["data"] as H3.BizBus.BizStructure;
  89. } else
  90. {
  91. throw new Exception("接口异常," + rspData["message"]);
  92. }
  93. }
  94. else
  95. {
  96. throw new Exception("氚云异常," + response.Message);
  97. }
  98. } else
  99. {
  100. throw new Exception("系统异常,接口无响应");
  101. }
  102. }
  103. }