套打二开打印工作流节点处理人对应的部门示例
第一步:套打模板绑定数据源,先绑定节点的审批意见,然后导出模板,再把审批意见字段名称改成部门(自定义,本例子用FDepartment),修改后后导入模板。截图如下:
第二步:表单插件,本例以表单插件为例,代码如下:
public class NotePrintDepartment : AbstractBillPlugIn
{
private string[] activityFields = { "ReceiverNames", "Disposition", "Result", "CompletedTime", "ReceiverESignature", "FDepartment" };
public override void OnPrepareNotePrintData(Core.DynamicForm.PlugIn.Args.PreparePrintDataEventArgs e)
{
base.OnPrepareNotePrintData(e);
if (e.DataSourceId.Equals("workflow.5534d341bc132e", StringComparison.OrdinalIgnoreCase))
{
var aa = GetQueryData(this.View.Model.GetPKValue().ToString(), e.DataSourceId);
e.DataObjects = aa.ToArray();
e.DynamicObjectType = aa[0].DynamicObjectType;
}
}
private DynamicObjectCollection GetQueryData(string billId, string dataSourceId)
{
string[] dataSourceArgs = dataSourceId.Split('.');
if (dataSourceArgs.Length < 2)
return null;
string procDefId = dataSourceArgs[1];
return GetWorkFlowData(procDefId, billId);
}
private DynamicObjectCollection GetWorkFlowData(string procDefId, string billId)
{
string formId = this.View.BusinessInfo.GetForm().Id;
string processId = WorkflowChartServiceHelper.GetProcInstIdByBillInst(Context, formId, billId);
if (processId.IsNullOrEmptyOrWhiteSpace())
return null;
return GetWorkflowData(billId, procDefId, processId);
}
private DynamicObjectCollection GetWorkflowData(string billId, string procDefId, string processId)
{
bool isHisProcInst = WorkflowChartServiceHelper.HasHisProcInst(Context, processId);
NotePrintProcessInstance[] procInstArray = LoadWorkflowInstance(billId, this.View.BusinessInfo.GetForm().Id, procDefId, isHisProcInst);
NotePrintProcessInstance procInst = null;
if (procInstArray == null)
{
return null;
}
foreach (var ins in procInstArray)
{
if (procInst == null)
{
procInst = ins;
}
else if (ins.CreateTime > procInst.CreateTime)
{
procInst = ins;
}
}
if (procInst == null)
{
return null;
}
//支持终止状态的工作流普通节点取数
var activityIDs = new List<string>();
foreach (var assign in procInst.Assigns)
{
if (!activityIDs.Contains(assign.ActivityId.ToString()))
{
activityIDs.Add(assign.ActivityId.ToString());
}
}
DynamicObjectType type = new DynamicObjectType("tempObject");
foreach (var actId in activityIDs)
{
foreach (var actField in activityFields)
{
string key = actId + "_" + actField;
string name = "ac_" + key;
if (type.Properties.Contains(name) == false)
{
if (actField.Equals("ReceiverESignature"))
{
type.RegisterSimpleProperty(
name,
typeof(byte[]),
attributes: new SimplePropertyAttribute() { Alias = key }
);
}
else
{
type.RegisterSimpleProperty(
name,
typeof(string),
attributes: new SimplePropertyAttribute() { Alias = key }
);
}
}
}
}
DynamicObject workFlowDataObj = new DynamicObject(type);
foreach (var actID in activityIDs)
{
NotePrintAssign lastActivityAssign = procInst.GetLastActivityAssign(int.Parse(actID));
if (lastActivityAssign == null)
{
continue;
}
Type t = lastActivityAssign.GetType();
foreach (var actField in activityFields)
{
foreach (PropertyInfo pi in t.GetProperties())
{
if (!actField.EqualsIgnoreCase(pi.Name))
continue;
string propKey = string.Format("ac_{0}_{1}", actID, actField);
object value = pi.GetValue(lastActivityAssign, null);
if (actField.Equals("ReceiverESignature"))
workFlowDataObj[propKey] = value;
else
{
if (value != null)
{
workFlowDataObj[propKey] = value.ToString();
}
else
{
workFlowDataObj[propKey] = string.Empty;
}
}
if (actField == "ReceiverNames")
{
var receiverIds = lastActivityAssign.ApprovalAssigns[0].ApprovalItems.Select(p => p.ReceiverId).ToArray();
workFlowDataObj[string.Format("ac_{0}_FDepartment", actID)] = GetDepartmentByUserIds(receiverIds);
}
}
}
}
DynamicObjectCollection result = new DynamicObjectCollection(type);
result.Add(workFlowDataObj);
return result;
}
private NotePrintProcessInstance[] LoadWorkflowInstance(object pkValue, string formId, string procDefId, bool isHisProcInst)
{
QueryBuilderParemeter qbPara = new QueryBuilderParemeter();
qbPara.FilterClauseWihtKey = string.Format("FProcInstId IN (SELECT FProcInstID FROM V_WF_PIBIMAPALL WHERE FObjectTypeId = '{0}' AND FKeyValue = '{1}')",
formId, pkValue);
DynamicObject[] dataObjs;
if (isHisProcInst)//查归档流程信息
{
qbPara.FormId = WFBillConst.ProcManageProcInstEndHis;
dataObjs = BusinessDataServiceHelper.Load(Context, NotePrintProcessInstanceHis.ProcessInstanceHisType, qbPara);
}
else
{
qbPara.FormId = WFBillConst.ProcManageProcInst;
dataObjs = BusinessDataServiceHelper.Load(Context, NotePrintProcessInstance.ProcessInstanceType, qbPara);
}
var procInsts = (from p in dataObjs select new NotePrintProcessInstance(p)).ToArray();
//判断当前选择的字段是否是审批路线字段.
if (procDefId.Equals("approveLine"))
{
return procInsts.ToArray();
}
else
{
//return procInsts.Where(p => (p.ProcDefId.Equals(procDefId))).ToArray();
string documentStatus = GetBillStatus(pkValue.ToString());
if (documentStatus == "A" || documentStatus == "D")
return null;
//获取时间最新的流程实例
var procInst = procInsts.OrderByDescending(p => p.CreateTime).FirstOrDefault();
if (procInst != null && procInst.ProcDefId.Equals(procDefId))
return new NotePrintProcessInstance[] { procInst };
else
return null;
}
}
private string GetBillStatus(string billId)
{
BillStatusField billStatusField = this.View.BillBusinessInfo.GetBillStatusField();
if (billStatusField == null)
return string.Empty;
var selectedKey = new List<SelectorItemInfo>();
selectedKey.Add(new SelectorItemInfo(billStatusField.Key));
//考虑字符型主键 单据
bool isIntPk = this.View.BillBusinessInfo.GetF
orm().PkFieldType == EnumPkFieldType.INT ||
this.View.BillBusinessInfo.GetForm().PkFieldType == EnumPkFieldType.LONG;
OQLFilter oFilter = new OQLFilter();
OQLFilterHeadEntityItem oFilterItem = new OQLFilterHeadEntityItem
{
FilterString =
String.Format(" {0} = ({1})", this.View.BillBusinessInfo.GetEntity(0).EntryPkFieldName,
isIntPk ? billId : "'" + billId + "'")
};
oFilter.Add(oFilterItem);
DynamicObject[] billStatusValues = BusinessDataServiceHelper.Load(Context, this.View.BillBusinessInfo.GetForm().Id,
selectedKey, oFilter);
string docStatus = (string)billStatusField.DynamicProperty.GetValue(billStatusValues[0]);
return docStatus;
}
private string GetDepartmentByUserIds(long[] userIds)
{
string deptName = string.Empty;
string sql = string.Format(@"SELECT T3.FNAME
FROM T_HR_EMPINFO T0
INNER JOIN T_SEC_USER T1 ON T0.FPERSONID=T1.FLINKOBJECT
INNER JOIN T_BD_STAFF T2 ON T0.FID=T2.FEMPINFOID
INNER JOIN T_BD_DEPARTMENT_L T3 ON T2.FDEPTID=T3.FDEPTID
WHERE T1.FUSERID IN ({0}) AND T1.FTYPE=1 AND T3.FLOCALEID=2052", string.Join(",", userIds));
DynamicObjectCollection obj = DBServiceHelper.ExecuteDynamicObject(this.View.Context, sql, paramList: null);
if (!obj.IsEmpty())
{
var names = obj.Select(p => p["FNAME"]).ToArray();
deptName= string.Join(",",names);
}
return deptName;
}
}
执行结果如下:
套打二开打印工作流节点处理人对应的部门示例
本文2024-09-23 04:19:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-164613.html