|
@@ -0,0 +1,178 @@
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
+using H3;
|
|
|
+
|
|
|
+public class D2796247609923b101140e689622d8b39651b39: H3.SmartForm.SmartFormController
|
|
|
+{
|
|
|
+ public D2796247609923b101140e689622d8b39651b39(H3.SmartForm.SmartFormRequest request): base(request)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response)
|
|
|
+ {
|
|
|
+ // 获取、工号、姓名;委托人姓名[默认登录人]
|
|
|
+ if(this.Request.IsCreateMode)
|
|
|
+ {
|
|
|
+ this.Request.BizObject["inputPersonName"] = this.Request.UserContext.User.Name;
|
|
|
+ this.Request.BizObject["inputPersonCode"] = this.Request.UserContext.User.EmployeeNumber;
|
|
|
+ this.Request.BizObject["agentPerson"] = this.Request.UserContext.User.Name;
|
|
|
+ }
|
|
|
+ base.OnLoad(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response)
|
|
|
+ {
|
|
|
+ // 默认值处理
|
|
|
+ if((actionName == "Submit" || actionName == "Save") && this.Request.IsCreateMode)
|
|
|
+ {
|
|
|
+ if(postValue.Data["inputPersonCode"] + string.Empty == "")
|
|
|
+ {
|
|
|
+ response.Infos.Add("未维护工号信息,请联系管理员!");
|
|
|
+ }
|
|
|
+ // 赋值兼容,避免数据丢失
|
|
|
+ string[] compIds = { "inputPersonName", "inputPersonCode", "agentPerson" };
|
|
|
+ foreach(string compId in compIds)
|
|
|
+ {
|
|
|
+ this.Request.BizObject[compId] = postValue.Data[compId] + string.Empty;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 审批通过
|
|
|
+ if(this.Request.ActivityCode == "Activity23" && actionName == "Submit")
|
|
|
+ {
|
|
|
+ this.syncContract(actionName, this.Request.ActivityCode, true);
|
|
|
+ }
|
|
|
+ // 类型列表
|
|
|
+ if(actionName == "types")
|
|
|
+ {
|
|
|
+ Dictionary < string, object > bodys = new Dictionary<string, object>();
|
|
|
+ List < H3.BizBus.ItemSchema > structures = new List<H3.BizBus.ItemSchema>(); // 响应类型
|
|
|
+ structures.Add(new H3.BizBus.ItemSchema("types", "合同类型", H3.Data.BizDataType.String, null));
|
|
|
+ H3.BizBus.BizStructure data = this.invokeVendorService("types", bodys, structures); // 请求处理
|
|
|
+ response.ReturnData = new Dictionary<string, object>();
|
|
|
+ response.ReturnData.Add("types", data["types"]);
|
|
|
+ }
|
|
|
+ // 所属部门【返所属部门列表】
|
|
|
+ if(actionName == "purchaseDepart")
|
|
|
+ {
|
|
|
+ //根据人员Id查询其所有的部门Id
|
|
|
+ H3.Organization.User user = (H3.Organization.User) this.Engine.Organization.GetUnit(this.Request.UserContext.UserId);
|
|
|
+ string[] pIds = user.ParentIds;
|
|
|
+ List < string > fIds = new List<string>();
|
|
|
+ foreach(string pId in pIds)
|
|
|
+ {
|
|
|
+ fIds.Add(string.Format("'{0}'", pId));
|
|
|
+ }
|
|
|
+ System.Data.DataTable depts = this.Engine.Query.QueryTable(string.Format("select Name from H_Organizationunit where ObjectId in ({0})", string.Join(",", fIds)), null);
|
|
|
+ response.ReturnData = new Dictionary<string, object>();
|
|
|
+ response.ReturnData.Add("purchaseDepart", this.Serialize(depts));
|
|
|
+ }
|
|
|
+ // 代理人
|
|
|
+ if(actionName == "agentPerson")
|
|
|
+ {
|
|
|
+ System.Data.DataTable user = this.Engine.Query.QueryTable(string.Format("select * from h_user where ObjectId = '{0}'", this.Request["agentId"]), null);
|
|
|
+ response.ReturnData = new Dictionary<string, object>();
|
|
|
+ response.ReturnData.Add("agentPerson", this.Serialize(user));
|
|
|
+ }
|
|
|
+ base.OnSubmit(actionName, postValue, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 盖章附件【后补】流程事件:只有审批人变更才会触发,发起、自动通过不会
|
|
|
+ protected override void OnWorkflowInstanceStateChanged(H3.Workflow.Instance.WorkflowInstanceState oldState, H3.Workflow.Instance.WorkflowInstanceState newState)
|
|
|
+ {
|
|
|
+ // 流程审批结束事件(先执行业务规则,在执行该方法)
|
|
|
+ if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Running && newState == H3.Workflow.Instance.WorkflowInstanceState.Finished)
|
|
|
+ { /** 执行业务代码逻辑 **/
|
|
|
+ this.syncContract("OnWorkflowInstanceStateChanged", "Finished", false);
|
|
|
+ }
|
|
|
+ //流程审批结束后,重新激活事件(先执行业务规则,在执行该方法)
|
|
|
+ if(oldState == H3.Workflow.Instance.WorkflowInstanceState.Finished && newState == H3.Workflow.Instance.WorkflowInstanceState.Running) { /** 执行业务代码逻辑 **/ }
|
|
|
+ base.OnWorkflowInstanceStateChanged(oldState, newState);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步合同【公共】
|
|
|
+ private void syncContract(string actionName, string activityCode, bool isApprove) {
|
|
|
+ Dictionary < string, object > bodys = new Dictionary<string, object>();
|
|
|
+ bodys.Add("actionName", actionName); // 动作名称
|
|
|
+ bodys.Add("activityCode", activityCode); // 流程节点
|
|
|
+ // 氚云默认字段冲突: cSummary as summary, cTelephone as telephone [select * 后,两个字段都会同时存在, 若字段相同则会被 * 覆盖, 如 DATE_FORMAT,需要另开一个字段]
|
|
|
+ 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);
|
|
|
+ bodys.Add("bizObject", this.Serialize(records)); // 合同记录
|
|
|
+ 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);
|
|
|
+ bodys.Add("termsObject", this.Serialize(terms)); // 合同条款
|
|
|
+ H3.DataModel.BizObjectFileHeader[] files = (H3.DataModel.BizObjectFileHeader[]) this.Request.BizObject[isApprove ? "attachment" : "F0000002"]; // 附件控件 [注意:新增的时候获取不了ID,新增包含审批节点]
|
|
|
+ bodys.Add("attachments", this.Serialize(files)); // 合同附件
|
|
|
+ bodys.Add("fileNames", this.Request.BizObject["fileNames"]); // 盖章附件
|
|
|
+ List < H3.BizBus.ItemSchema > structures = new List<H3.BizBus.ItemSchema>(); // 响应类型
|
|
|
+ structures.Add(new H3.BizBus.ItemSchema("fileNames", "文件名称", H3.Data.BizDataType.String, null));
|
|
|
+ H3.BizBus.BizStructure data = this.invokeVendorService(isApprove ? "approve" : "file", bodys, structures); // 请求处理
|
|
|
+ // 拼接与氚云记录, 服务删除逻辑
|
|
|
+ this.Engine.Query.QueryTable(string.Format("update i_D2796247609923b101140e689622d8b39651b39 set fileNames = '{0}' where ObjectId = '{1}'", data["fileNames"], this.Request.BizObjectId), null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 氚云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<string, string>();
|
|
|
+ Dictionary < string, string > querys = new Dictionary<string, string>();
|
|
|
+ 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("系统异常,接口无响应");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|