上海市委.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using H3;
  5. public class D2796247609923b101140e689622d8b39651b39: H3.SmartForm.SmartFormController
  6. {
  7. public D2796247609923b101140e689622d8b39651b39(H3.SmartForm.SmartFormRequest request): base(request)
  8. {
  9. }
  10. protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
  11. {
  12. // 获取、工号、姓名;委托人姓名[默认登录人]
  13. if(this.Request.IsCreateMode)
  14. {
  15. this.Request.BizObject["inputPersonName"] = this.Request.UserContext.User.Name;
  16. this.Request.BizObject["inputPersonCode"] = this.Request.UserContext.User.EmployeeNumber;
  17. this.Request.BizObject["agentPerson"] = this.Request.UserContext.User.Name;
  18. }
  19. base.OnLoad(response);
  20. }
  21. protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response)
  22. {
  23. // 默认值处理
  24. if((actionName == "Submit" || actionName == "Save") && this.Request.IsCreateMode)
  25. {
  26. if(postValue.Data["inputPersonCode"] + string.Empty == "")
  27. {
  28. response.Infos.Add("未维护工号信息,请联系管理员!");
  29. }
  30. // 赋值兼容,避免数据丢失
  31. string[] compIds = { "inputPersonName", "inputPersonCode", "agentPerson" };
  32. foreach(string compId in compIds)
  33. {
  34. this.Request.BizObject[compId] = postValue.Data[compId] + string.Empty;
  35. }
  36. }
  37. // 审批通过
  38. if(this.Request.ActivityCode == "Activity23" && actionName == "Submit")
  39. {
  40. this.syncContract(actionName, this.Request.ActivityCode, true);
  41. }
  42. // 类型列表
  43. if(actionName == "types")
  44. {
  45. Dictionary < string, object > bodys = new Dictionary<string, object>();
  46. List < H3.BizBus.ItemSchema > structures = new List<H3.BizBus.ItemSchema>(); // 响应类型
  47. structures.Add(new H3.BizBus.ItemSchema("types", "合同类型", H3.Data.BizDataType.String, null));
  48. H3.BizBus.BizStructure data = this.invokeVendorService("types", bodys, structures); // 请求处理
  49. response.ReturnData = new Dictionary<string, object>();
  50. response.ReturnData.Add("types", data["types"]);
  51. }
  52. // 所属部门【返所属部门列表】
  53. if(actionName == "purchaseDepart")
  54. {
  55. //根据人员Id查询其所有的部门Id
  56. H3.Organization.User user = (H3.Organization.User) this.Engine.Organization.GetUnit(this.Request.UserContext.UserId);
  57. string[] pIds = user.ParentIds;
  58. List < string > fIds = new List<string>();
  59. foreach(string pId in pIds)
  60. {
  61. fIds.Add(string.Format("'{0}'", pId));
  62. }
  63. System.Data.DataTable depts = this.Engine.Query.QueryTable(string.Format("select Name from H_Organizationunit where ObjectId in ({0})", string.Join(",", fIds)), null);
  64. response.ReturnData = new Dictionary<string, object>();
  65. response.ReturnData.Add("purchaseDepart", this.Serialize(depts));
  66. }
  67. // 代理人
  68. if(actionName == "agentPerson")
  69. {
  70. System.Data.DataTable user = this.Engine.Query.QueryTable(string.Format("select * from h_user where ObjectId = '{0}'", this.Request["agentId"]), null);
  71. response.ReturnData = new Dictionary<string, object>();
  72. response.ReturnData.Add("agentPerson", this.Serialize(user));
  73. }
  74. base.OnSubmit(actionName, postValue, response);
  75. }
  76. // 盖章附件【后补】流程事件:只有审批人变更才会触发,发起、自动通过不会
  77. protected override void OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState oldState, H3.Workflow.Instance.WorkflowInstanceState newState)
  78. {
  79. // 流程审批结束事件(先执行业务规则,在执行该方法)
  80. if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Running && newState == H3.Workflow.Instance.WorkflowInstanceState.Finished)
  81. { /** 执行业务代码逻辑 **/
  82. this.syncContract("OnWorkflowInstanceStateChanged", "Finished", false);
  83. }
  84. //流程审批结束后,重新激活事件(先执行业务规则,在执行该方法)
  85. if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Finished && newState == H3.Workflow.Instance.WorkflowInstanceState.Running) { /** 执行业务代码逻辑 **/ }
  86. base.OnWorkflowInstanceStateChanged(oldState, newState);
  87. }
  88. // 同步合同【公共】
  89. private void syncContract(string actionName, string activityCode, bool isApprove) {
  90. Dictionary < string, object > bodys = new Dictionary<string, object>();
  91. bodys.Add("actionName", actionName); // 动作名称
  92. bodys.Add("activityCode", activityCode); // 流程节点
  93. // 氚云默认字段冲突: cSummary as summary, cTelephone as telephone [select * 后,两个字段都会同时存在, 若字段相同则会被 * 覆盖, 如 DATE_FORMAT,需要另开一个字段]
  94. System.Data.DataTable records = this.Engine.Query.QueryTable(string.Format("select *, cSummary as cummary, cTelephone as telephone, DATE_FORMAT(cOrderTime,'%Y-%m-%d') orderTime, DATE_FORMAT(cCompletionDate,'%Y-%m-%d') completionDate from i_D2796247609923b101140e689622d8b39651b39 where ObjectId = '{0}'", this.Request.BizObjectId), null);
  95. bodys.Add("bizObject", this.Serialize(records)); // 合同记录
  96. System.Data.DataTable terms = this.Engine.Query.QueryTable(string.Format("select *, DATE_FORMAT(cDateTime,'%Y-%m-%d') dateTime from i_D279624F24d78c5510764cba928395c32b9406d6 where ParentObjectId = '{0}'", this.Request.BizObjectId), null);
  97. bodys.Add("termsObject", this.Serialize(terms)); // 合同条款
  98. H3.DataModel.BizObjectFileHeader[] files = (H3.DataModel.BizObjectFileHeader[]) this.Request.BizObject[isApprove ? "attachment" : "F0000002"]; // 附件控件 [注意:新增的时候获取不了ID,新增包含审批节点]
  99. bodys.Add("attachments", this.Serialize(files)); // 合同附件
  100. bodys.Add("fileNames", this.Request.BizObject["fileNames"]); // 盖章附件
  101. List < H3.BizBus.ItemSchema > structures = new List<H3.BizBus.ItemSchema>(); // 响应类型
  102. structures.Add(new H3.BizBus.ItemSchema("fileNames", "文件名称", H3.Data.BizDataType.String, null));
  103. H3.BizBus.BizStructure data = this.invokeVendorService(isApprove ? "approve" : "file", bodys, structures); // 请求处理
  104. // 拼接与氚云记录, 服务删除逻辑
  105. this.Engine.Query.QueryTable(string.Format("update i_D2796247609923b101140e689622d8b39651b39 set fileNames = '{0}' where ObjectId = '{1}'", data["fileNames"], this.Request.BizObjectId), null);
  106. }
  107. /**
  108. * 氚云HTTP
  109. * 1. code 公用请求,code区分业务逻辑
  110. * 2. bodys 请求参数,默认POST,application/json
  111. * 3. structures 返回数据格式定义, 统一使用对象响应
  112. */
  113. private H3.BizBus.BizStructure invokeVendorService(string code, Dictionary < string, object > bodys, List < H3.BizBus.ItemSchema > structures) {
  114. H3.IEngine engine = this.Engine;
  115. // 请求信息
  116. Dictionary < string, string > headers = new Dictionary<string, string>();
  117. Dictionary < string, string > querys = new Dictionary<string, string>();
  118. querys.Add("code", code);
  119. // 定义响应数据整体结构体
  120. H3.BizBus.BizStructureSchema structureSchema = new H3.BizBus.BizStructureSchema();
  121. structureSchema.Add(new H3.BizBus.ItemSchema("code", "结果状态码", H3.Data.BizDataType.Int, null));
  122. structureSchema.Add(new H3.BizBus.ItemSchema("success", "请求状态位", H3.Data.BizDataType.Bool, null));
  123. structureSchema.Add(new H3.BizBus.ItemSchema("message", "描述信息", H3.Data.BizDataType.String, null));
  124. // 定义响应数据的 data 属性 的结构体
  125. H3.BizBus.BizStructureSchema dataSchema = new H3.BizBus.BizStructureSchema();
  126. foreach(H3.BizBus.ItemSchema itemSchame in structures)
  127. {
  128. dataSchema.Add(itemSchame);
  129. }
  130. //将 data 属性的结构体添加进整体的响应数据结构体 [H3.Data.BizDataType.BizStructureArray 集合,H3.Data.BizDataType.BizStructure 对象]
  131. structureSchema.Add(new H3.BizBus.ItemSchema("data", "响应数据", H3.Data.BizDataType.BizStructure, dataSchema));
  132. //调用Invoke接口,系统底层访问第三方接口的Invoke方法
  133. H3.BizBus.InvokeResult response = engine.BizBus.InvokeApi(
  134. H3.Organization.User.SystemUserId, //固定值,无需改变
  135. H3.BizBus.AccessPointType.ThirdConnection, //固定值,无需改变
  136. "h3yun-http", //连接编码,对应 插件中心 中配置的连接的编码
  137. "POST", //请求方式,取值:GET / POST
  138. "application/json", //请求数据类型: json - "application/json";xml - "text/html;charset=utf-8"
  139. headers, querys, bodys, structureSchema);
  140. if(response != null)
  141. {
  142. // 氚云调用是否成功
  143. if(response.Code == 0)
  144. {
  145. // 获取返回数据,此实例对应完整的响应JSON
  146. H3.BizBus.BizStructure rspData = response.Data;
  147. if(((bool) rspData["success"]) == true)
  148. {
  149. // 对象响应【氚云自定义字段,需要通过[]直接取值才有效,序列化后返回前端,仅会保留结构】
  150. // H3.BizBus.BizStructure[] datas = rspData["data"] as H3.BizBus.BizStructure[]; // 集合解析
  151. // H3.BizBus.BizStructure data = rspData["data"] as H3.BizBus.BizStructure; // 对象解析
  152. return rspData["data"] as H3.BizBus.BizStructure;
  153. } else
  154. {
  155. throw new Exception("响应异常," + rspData["message"]);
  156. }
  157. }
  158. else
  159. {
  160. throw new Exception("氚云异常," + response.Message);
  161. }
  162. } else
  163. {
  164. throw new Exception("系统异常,接口无响应");
  165. }
  166. }
  167. }