实现功能
- 配置U9字段OA表单对映关系
- 同步U9子表至OA
- 同步U9附件至OA
- 通过U9第三方子表至OA
- 通过OA审批结果
- 查看OA审批进度
1. 创建U9单据与OA表单的对应关系
image.png- OA审批结果:使用U9扩展字段记录OA审批成功、审批失败原因
- OA流程标题:支持静态数据+动态数据(从单据取数)
- U9字段取值
例1:
应收单的私有段1存放的是客户编码(DescFlexField.PrivateDescSeg1),取客户的出货原则名称;
Entity:UFIDA.U9.CBO.SCM.Customer.Customer:Code=DescFlexField.PrivateDescSeg1:ShippmentRule.Name
例2:
应收单的私有段1存放的是客户主键(DescFlexField.PrivateDescSeg1),取客户的出货原则名称;
Entity:UFIDA.U9.CBO.SCM.Customer.Customer:ID=DescFlexField.PrivateDescSeg1:ShippmentRule.Name
1.1 同步U9子表数据
image.png2. 新建U9审批流
新建一个简单的审批流用于提交U9单据,U9提交时触发任务插件
3. 任务插件新建OA单据
U9单据提交后触发任务插件
using log4net;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using UFIDA.U9.Cust.IESLabBE.OAWorkFlowConfigBE;
using UFSoft.UBF.Business;
using UFSoft.UBF.PL;
using UFSoft.UBF.PL.ObjectAccess;
using UFIDA.U9.Cust.IESLabDocBE.OAServiceXML;
using UFIDA.U9.Cust.IESLabBE.OAWorkFlowRecordBE;
using UFIDA.U9.Base.Doc;
using UFIDA.U9.CS.Common.FileStorage;
using UFIDA.U9.Base.Attachment;
using UFIDA.U9.Base;
using UFIDA.U9.Cust.IESLabBP.Util;
using UFSoft.UBF.Util.Context;
namespace UFIDA.U9.Cust.IESLabDocBE.OAService
{
public class OAWorkflowService
{
public const string REQUESTLEVEL_NORMAL = "0";
public const string REQUESTLEVEL_MAJOR = "1";
public const string REQUESTLEVEL_URGENT = "2";
public const string FIELDTYPE_FILE = "base64:";
public const string PROFILE_APP_IP = "CUST_APP_IP";
//public const string PROFILE_APP_ENTERPRISE = "CUST_APP_ENTERPRISE";
public const string PROFILE_ATTACHMENT_DOWNLOAD_USERNAME = "CUST_ATTACHMENT_DOWNLOAD_USERNAME";
public const string PROFILE_ATTACHMENT_DOWNLOAD_PASSWORD = "CUST_ATTACHMENT_DOWNLOAD_PASSWORD";
private static readonly ILog log = LogManager.GetLogger(typeof(OAWorkflowService));
private WorkflowService workflowService = new WorkflowService();
private WorkflowServiceXml xmlWorkflowService = new WorkflowServiceXml();
private const int workflowType = 0;
/// <summary>
/// 创建、提交工作流
/// </summary>
public void createAndSubmitWorkflow(BusinessEntity businessEntity,int oaUserid)
{
CompositeValueHandler valueHandlers = new CompositeValueHandler(businessEntity);
OAWorkFlowConfig oAWorkFlowConfig = OAWorkFlowConfig.Finder.Find("EntityType.FullName='" + businessEntity.MDEntity.FullName + "'");
if (oAWorkFlowConfig == null)
{
throw new Exception("创建OA流程失败,请先配置OA流程配置");
}
WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();
workflowRequestInfo.canView = true;
workflowRequestInfo.canEdit = true;
workflowRequestInfo.requestName = valueHandlers.Handler(oAWorkFlowConfig.OARequestName) as string;// 请求标题
workflowRequestInfo.requestLevel = REQUESTLEVEL_NORMAL;
workflowRequestInfo.creatorId = oaUserid.ToString();
WorkflowBaseInfo worklfowBaseInfo = new WorkflowBaseInfo();
worklfowBaseInfo.workflowId = oAWorkFlowConfig.OAWorkFlowId;
worklfowBaseInfo.workflowName = oAWorkFlowConfig.OAWorkFlowName;
worklfowBaseInfo.workflowTypeName = oAWorkFlowConfig.OAWorkFlowTypeName;// 流程类型名称
workflowRequestInfo.workflowBaseInfo = worklfowBaseInfo;
workflowRequestInfo.workflowMainTableInfo = createMainTable(businessEntity,oAWorkFlowConfig);
workflowRequestInfo.workflowDetailTableInfos = createDetailTable(businessEntity, oAWorkFlowConfig);
string result = null;
try
{
result=xmlWorkflowService.doCreateWorkflowRequest(ObjectToXML(workflowRequestInfo), oaUserid);
AddOAWorkFlowRecord(businessEntity, Convert.ToInt32(result), oaUserid, oAWorkFlowConfig);
}
catch(Exception e)
{
throw new Exception("创建OA流程失败,请稍后重试。" + e.Message);
}
if (result != null)
{
if (int.Parse(result) <= 0)
{
throw new Exception("创建OA流程失败,请联系系统管理员,OA返回状态:"+result);
}
}
else
{
throw new Exception("创建OA流程失败,请联系系统管理员,OA返回状态:null");
}
}
/// <summary>
/// 删除流程
/// </summary>
/// <param name="businessEntity"></param>
/// <param name="oaUserid"></param>
public void deleteWorkflow(BusinessEntity businessEntity, int oaUserid)
{
OAWorkFlowRecord.EntityList workFlowRecords=QueryOAWorkFlowRecords(businessEntity);
if (workFlowRecords == null)
{
return;
}
foreach (OAWorkFlowRecord workFlowRecord in workFlowRecords)
{
bool result=workflowService.deleteRequest(workFlowRecord.OARequestID, oaUserid);
if (result)
{
DeleteOAWorkFlowRecord(workFlowRecord);
}
}
}
/// <summary>
/// 查询流程日志
/// </summary>
/// <param name="WorkflowID"></param>
/// <param name="OARequestID"></param>
/// <param name="OAUserID"></param>
/// <param name="PageSize"></param>
/// <param name="EndID"></param>
/// <returns></returns>
public WorkflowRequestLog[] GetWorkflowRequestLogs(string WorkflowID,string OARequestID,int OAUserID,int PageSize,int EndID)
{
return workflowService.getWorkflowRequestLogs(WorkflowID, OARequestID, OAUserID, PageSize, EndID);
}
/// <summary>
/// 添加OA流程记录
/// </summary>
/// <param name="entity"></param>
/// <param name="requestID"></param>
/// <param name="oaUserID"></param>
/// <param name="oAWorkFlowConfig"></param>
private void AddOAWorkFlowRecord(BusinessEntity entity,int requestID,int oaUserID, OAWorkFlowConfig oAWorkFlowConfig)
{
OAWorkFlowRecord oAWorkFlowRecord = OAWorkFlowRecord.Create();
oAWorkFlowRecord.EntityID = entity.ID;
oAWorkFlowRecord.OARequestID = requestID;
oAWorkFlowRecord.OAUserID = oaUserID;
oAWorkFlowRecord.WorkflowID = oAWorkFlowConfig.OAWorkFlowId;
oAWorkFlowRecord.OAWorkFlowName = oAWorkFlowConfig.OAWorkFlowName;
oAWorkFlowRecord.DocNo = (entity as Doc).DocNo;
using (ISession session = Session.Open())
{
session.InList(oAWorkFlowRecord);
session.Commit();
}
}
/// <summary>
/// 按单据查询OA流程记录
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
private OAWorkFlowRecord.EntityList QueryOAWorkFlowRecords(BusinessEntity entity)
{
return OAWorkFlowRecord.Finder.FindAll("EntityID=@EntityID", new OqlParam("EntityID", entity.ID));
}
/// <summary>
/// 删除OA流程记录
/// </summary>
/// <param name="workFlowRecord"></param>
private void DeleteOAWorkFlowRecord(OAWorkFlowRecord workFlowRecord)
{
using (ISession session = Session.Open())
{
session.Remove(workFlowRecord);
session.Commit();
}
}
/// <summary>
/// 创建主表
/// </summary>
/// <param name="businessEntity"></param>
/// <param name="oAWorkFlowConfig"></param>
/// <returns></returns>
private WorkflowMainTableInfo createMainTable(BusinessEntity businessEntity, OAWorkFlowConfig oAWorkFlowConfig)
{
WorkflowMainTableInfo workflowMainTableInfo = new WorkflowMainTableInfo();// 主表
workflowMainTableInfo.requestRecords = new WorkflowRequestTableRecord[] { createMainTableRecord(businessEntity, oAWorkFlowConfig.MainField) };
return workflowMainTableInfo;
}
/// <summary>
/// 创建明细表
/// </summary>
/// <param name="businessEntity"></param>
/// <param name="oAWorkFlowConfig"></param>
/// <returns></returns>
private WorkflowDetailTableInfo[] createDetailTable(BusinessEntity businessEntity, OAWorkFlowConfig oAWorkFlowConfig)
{
List<WorkflowDetailTableInfo> workflowDetailTableInfos = new List<WorkflowDetailTableInfo>();
List<MainField> detailTableConfig = GetDetailTableConfig(businessEntity,oAWorkFlowConfig);
CompositeValueHandler handler = new CompositeValueHandler(businessEntity);
foreach (MainField mainAttribute in detailTableConfig)
{
string attributeName = mainAttribute.MField == null ? mainAttribute.U9Field : mainAttribute.MField.Name;
POList <IPersistableObject> detailEntity = handler.Handler(attributeName) as POList<IPersistableObject>;
WorkflowDetailTableInfo workflowDetailTableInfo = new WorkflowDetailTableInfo();
workflowDetailTableInfo.workflowRequestTableRecords = createDetailTableRecord(detailEntity.ToArray(), mainAttribute.DetailField);
workflowDetailTableInfos.Add(workflowDetailTableInfo);
}
if (workflowDetailTableInfos.Count > 0)
{
return workflowDetailTableInfos.ToArray();
}
else
{
return null;
}
}
/// <summary>
/// 获取明细表字段信息
/// </summary>
/// <param name="oAWorkFlowConfig"></param>
/// <param name="businessEntity"></param>
/// <returns></returns>
private List<MainField> GetDetailTableConfig(BusinessEntity businessEntity, OAWorkFlowConfig oAWorkFlowConfig)
{
//var a=mainFields.Where(mainField => mainField.MFieldKey.GetEntity().IsCollection).OrderBy(item=>item.OAFieldName);
List<MainField> detailTableConfig = new List<MainField>();
EntityValueHandler entityValueHandler = new EntityValueHandler(businessEntity);
foreach (MainField mainField in oAWorkFlowConfig.MainField)
{
if ((mainField.MField!=null&&mainField.MField.IsCollection)||
(entityValueHandler.Support(mainField.U9Field) &&entityValueHandler.IsEntityies(mainField.U9Field)))
{
detailTableConfig.Add(mainField);
}
}
return detailTableConfig.OrderBy(item => item.OAFieldName).ToList<MainField>();
}
/// <summary>
/// 创建明细表行
/// </summary>
/// <param name="entities"></param>
/// <param name="detailFields"></param>
/// <returns></returns>
private WorkflowRequestTableRecord[] createDetailTableRecord(IPersistableObject[] entities, DetailField.EntityList detailFields)
{
List<WorkflowRequestTableRecord> workflowRequestTableRecords = new List<WorkflowRequestTableRecord>();
if (entities != null)
{
foreach (BusinessEntity entity in entities)
{
WorkflowRequestTableRecord record = new WorkflowRequestTableRecord();
record.workflowRequestTableFields = createWorkflowRequestTableField(entity, detailFields);
workflowRequestTableRecords.Add(record);
}
}
if (workflowRequestTableRecords.Count > 0)
{
return workflowRequestTableRecords.ToArray();
}
else
{
return null;
}
}
/// <summary>
/// 创建OA主表
/// </summary>
/// <param name="entity"></param>
/// <param name="mainFields"></param>
/// <returns></returns>
private WorkflowRequestTableRecord createMainTableRecord(BusinessEntity entity, MainField.EntityList mainFields)
{
var workflowRequestTableFields = new List<WorkflowRequestTableField>();// 主表的字段
foreach (MainField mainField in mainFields)
{
if (mainField.MField==null||!mainField.MField.IsCollection)
{
string fieldPath = null;
if (mainField.MField != null)
{
fieldPath = mainField.MField.Name;
if (mainField.U9DisplayField!=null)
{
fieldPath = fieldPath + "." + mainField.U9DisplayField.Name;
}
}
else
{
fieldPath = mainField.U9Field;
}
CompositeValueHandler valueHandlers = new CompositeValueHandler(entity);
workflowRequestTableFields.Add(createWorkflowRequestTableField(mainField.OAFieldName, valueHandlers.Handler(fieldPath), true, true));// 字段
}
}
WorkflowRequestTableRecord requestTableRecord = new WorkflowRequestTableRecord();
workflowRequestTableFields.AddRange(CreateFileField("fj", entity.ID));
requestTableRecord.workflowRequestTableFields = workflowRequestTableFields.ToArray();
return requestTableRecord;
}
/// <summary>
///
/// </summary>
/// <param name="U9Field"></param>
/// <param name="SubU9Field"></param>
/// <param name="U9Fieldstring"></param>
/// <returns></returns>
private string GetFieldPath(UBF.MD.Business.Attribute U9Field, UBF.MD.Business.Attribute SubU9Field,string U9Fieldstring)
{
string u9Fields = null;
if (U9Field != null)
{
u9Fields=U9Field.Name;
if (SubU9Field != null)
{
u9Fields= u9Fields+"."+SubU9Field.Name;
}
}
else
{
u9Fields = U9Fieldstring;
}
return u9Fields;
}
/// <summary>
/// 创建OA字段并赋值
/// </summary>
/// <param name="businessEntity"></param>
/// <param name="detailFields"></param>
/// <returns></returns>
private WorkflowRequestTableField[] createWorkflowRequestTableField(BusinessEntity businessEntity, DetailField.EntityList detailFields)
{
List<WorkflowRequestTableField> fields = new List<WorkflowRequestTableField>();
foreach (DetailField detailField in detailFields)
{
if (string.IsNullOrEmpty(detailField.OAFieldName)||(detailField.DField==null&&string.IsNullOrEmpty(detailField.U9Field)))
{
continue;
}
CompositeValueHandler valueHandlers = new CompositeValueHandler(businessEntity);
object fieldValue = valueHandlers.Handler(GetFieldPath(detailField.DField, detailField.U9DisplayField, detailField.U9Field));
if (fieldValue == null)
{
continue;
}
fields.Add(createWorkflowRequestTableField(detailField.OAFieldName,fieldValue,true,true));
}
return fields.ToArray();
}
/// <summary>
/// 根据字段名称获取实体字段值
/// </summary>
/// <param name="businessEntity"></param>
/// <param name="u9Fields">以.连接下层字段</param>
/// <returns></returns>
private string GetEntityValue(BusinessEntity businessEntity,string[] u9Fields)
{
if (u9Fields == null|| businessEntity==null)
{
return null;
}
string attributeName = null;
object value = null;
BusinessEntity entity = businessEntity;
for (int i = 0; i < u9Fields.Length; i++ )
{
string u9Field = u9Fields[i];
if (string.IsNullOrEmpty(u9Field))
{
break;
}
if (string.IsNullOrEmpty(attributeName))
{
attributeName = u9Field;
}
else
{
attributeName = attributeName + "." + u9Field;// 扩展字段,例如:DescFlexField.PubDescSeg2
}
if (!entity.MDEntity.GetHashFlatAttrsMap().Keys.Contains(attributeName))
{
continue;
}
value = entity[attributeName];
if(value != null)
{
if (value is BusinessEntity)
{
entity = value as BusinessEntity;
attributeName = null;
continue;
}
}
}
return value!=null?value.ToString():null;
}
/// <summary>
/// 创建OA字段并赋值
/// </summary>
/// <param name="fieldName"></param>
/// <param name="fieldValue"></param>
/// <param name="isView"></param>
/// <param name="isEdit"></param>
/// <returns></returns>
private WorkflowRequestTableField createWorkflowRequestTableField(string fieldName,object fieldValue,bool isView,bool isEdit)
{
if (fieldValue == null)
{
return null;
}
WorkflowRequestTableField field = new WorkflowRequestTableField() {
fieldName = fieldName,
fieldValue = fieldValue.ToString(),
view = isView,
edit = isEdit
};
return field;
}
/// <summary>
/// 查询可创建工作流程
/// </summary>
/// <param name="pageNo">页数</param>
/// <param name="pageSize">每页大小</param>
/// <param name="recordCount"></param>
/// <param name="oaUserid"></param>
public void getCreateWorkflowList(int pageNo,int pageSize,int recordCount,int oaUserid)
{
string[] conditions = new string[] { };
WorkflowBaseInfo[] workflowBaseInfos = workflowService.getCreateWorkflowList(pageNo, pageSize, recordCount, oaUserid, workflowType, conditions);
foreach (WorkflowBaseInfo workflowBaseInfo in workflowBaseInfos)
{
Console.WriteLine("流程名称:" + workflowBaseInfo.workflowName);
Console.WriteLine("流程id:" + workflowBaseInfo.workflowId);
Console.WriteLine("流程类型:" + workflowBaseInfo.workflowTypeId);
Console.WriteLine("流程类型名称:" + workflowBaseInfo.workflowTypeName);
}
}
/// <summary>
///
/// </summary>
/// <param name="entityID"></param>
/// <returns></returns>
private Attachment.EntityList GetAttachments(long entityID)
{
Attachment.EntityList attachments = Attachment.Finder.FindAll("EntityID=@EntityID",new OqlParam("EntityID", entityID));
return attachments;
}
/// <summary>
/// 获取base64格式文件内容
/// </summary>
/// <param name="attachment"></param>
/// <returns></returns>
private string GetAttachmentBase64Content(Attachment attachment)
{
Storage storage = new Storage();
CS.Common.FileDBService.FileInfo file = storage.GetFile(attachment.FileHandler);
if (file == null)
{
return null;
}
using (Stream stream = storage.GetFileContent(attachment.FileHandler))
{
stream.Seek(0, SeekOrigin.Begin);
byte[] data = new byte[stream.Length];
stream.Read(data,0,data.Length);
return Convert.ToBase64String(data);
}
}
private WorkflowRequestTableField[] CreateFileField(string fieldName, long entityID)
{
List<WorkflowRequestTableField> workflowRequestTableFields = new List<WorkflowRequestTableField>();
Attachment.EntityList attachments = GetAttachments(entityID);
foreach(Attachment attachment in attachments)
{
WorkflowRequestTableField workflowRequestTableField = new WorkflowRequestTableField();
workflowRequestTableField.fieldName = fieldName;
// 泛微V8不支持base64格式附件
workflowRequestTableField.fieldType = FIELDTYPE_FILE + attachment.Title;
workflowRequestTableField.fieldValue = FIELDTYPE_FILE + GetAttachmentBase64Content(attachment);
//workflowRequestTableField.fieldType = "http:" + attachment.Title;
//workflowRequestTableField.fieldValue = GetAutoLoginUrl(GetDownloadfileUrl(attachment));
workflowRequestTableField.isEdit = true.ToString();
workflowRequestTableField.isView = true.ToString();
workflowRequestTableFields.Add(workflowRequestTableField);
}
return workflowRequestTableFields.ToArray();
}
private string GetAutoLoginUrl(string returnUrl)
{
string url = "{0}/u9/api/v1/autologin.aspx?user_code={1}&user_password={2}" +
"&enterprise_id={3}&organization_id={4}&t=d&return_url={5}";
return string.Format(url, ProfileUtils.GetProfileValue(PROFILE_APP_IP),
ProfileUtils.GetProfileValue(PROFILE_ATTACHMENT_DOWNLOAD_USERNAME),
ProfileUtils.GetProfileValue(PROFILE_ATTACHMENT_DOWNLOAD_PASSWORD),
PlatformContext.ENTERPRISE_ID,
Context.LoginOrg.ID,Uri.EscapeDataString(returnUrl));
}
private string GetDownloadfileUrl(Attachment attachment)
{
string url = "{0}/u9/Common_Downloadfile.aspx?id={1}&handler={2}&viewinbrowser=false";
return string.Format(url, ProfileUtils.GetProfileValue(PROFILE_APP_IP), attachment.ID, attachment.FileHandler);
}
/// <summary>
/// 对象转xml string
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
private string ObjectToXML(object obj)
{
using (MemoryStream Stream = new MemoryStream())
{
XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
xmlSerializer.Serialize(Stream, obj, ns);
Stream.Position = 0;
StreamReader reader = new StreamReader(Stream);
return reader.ReadToEnd().Replace("<?xml version=\"1.0\"?>","")
.Replace("\r\n", "");
}
}
}
}
4. 中间表记录OA审批结果
5.定时任务同步OA审批结果
namespace UFIDA.U9.Cust.IESLabBP.OAServiceBP
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using UFIDA.U9.SM.SC;
using SM.Ship;
using UFIDA.U9.SM.SO;
using UFSoft.UBF.AopFrame;
using UFSoft.UBF.Util.Context;
using static UFSoft.UBF.Business.Entity;
using PM.Rcv;
using SM.SOModify;
using SM.ShipPlan;
using PM.PO;
using QC.MRBBE;
using CBO.QC.Enums;
using PR.PurchaseRequest;
using AP.Payment;
using CBO.FI.Enums;
using AR.ARBill;
using InvDoc.MiscShip;
using InvDoc.Enums;
using UFSoft.UBF.Business;
using UFIDA.U9.Base.Doc;
using UFSoft.UBF.PL;
using UFIDA.U9.Cust.IESLabBE.OAWorkFlowConfigBE;
using UFIDA.U9.Cust.IESLabBE.OAWorkFlowRecordBE;
using UFIDA.U9.Cust.IESLabBE.OAApproveResultBE;
using UFIDA.U9.CBO.SCM.Enums;
using UFIDA.U9.PPR.PurPriceAdjustment;
using UFSoft.UBF.Util.Log;
using UFIDA.U9.Base;
/// <summary>
/// 同步OA结果
/// </summary>
public partial class SyncOAApproveResult
{
internal BaseStrategy Select()
{
return new SyncOAApproveResultImpementStrategy();
}
}
#region implement strategy
/// <summary>
/// 同步OA结果
/// </summary>
internal partial class SyncOAApproveResultImpementStrategy : BaseStrategy
{
private static readonly ILogger logger = LoggerManager.GetLogger(typeof(SyncOAApproveResultImpementStrategy));
public SyncOAApproveResultImpementStrategy() { }
public override object Do(object obj)
{
UpdateApproveResult();
return null;
}
/// <summary>
/// 更新U9审批信息
/// </summary>
private void UpdateApproveResult()
{
EntityList<OAApproveResult> approveResults = QueryOAApproveResults();
foreach (OAApproveResult approveResult in approveResults)
{
approveResult.IsSync = true;
approveResult.SyncSuccess = true;
OAWorkFlowRecord oAWorkFlowRecord = QueryOAWorkFlowRecord(approveResult.OARequestID);
oAWorkFlowRecord.IsSync = true;
// U9单据进行了收回,OA未删除单据单据进行了归档
if (oAWorkFlowRecord == null)
{
continue;
}
OAWorkFlowConfig oAWorkFlowConfig = QueryOAWorkFlowConfig(oAWorkFlowRecord);
Doc doc = QueryDoc(oAWorkFlowConfig.EntityType.FullName, oAWorkFlowRecord.EntityID);
//if (doc == null)
//{
// continue;
//}
try
{
using (ISession session = Session.Open())
{
UpdateDocStatus(approveResult, oAWorkFlowRecord, doc);
session.InList(doc);
session.Commit();// 一个单据审批不通过后,不影响其它单据的审核
}
}
catch (Exception e)
{
approveResult.SyncSuccess = false;
approveResult.ApproveInfo = e.Message;
RollbackDocStatus(doc);
}
try
{
using (ISession session = Session.Open())
{
SetApproveInfo(doc, approveResult.ApproveInfo, oAWorkFlowConfig);
session.InList(approveResult);
oAWorkFlowRecord.ApproveInfo = approveResult.ApproveInfo;
session.Commit();
}
}
catch(Exception e)
{
using (ISession session = Session.Open())
{
oAWorkFlowRecord.ApproveInfo = e.Message;
session.Commit();
}
logger.Error(e.Message);
}
}
}
/// <summary>
/// 回写审批结果信息
/// </summary>
/// <param name="doc"></param>
/// <param name="value"></param>
/// <param name="oAWorkFlowConfig"></param>
private void SetApproveInfo(Doc doc, string value, OAWorkFlowConfig oAWorkFlowConfig)
{
doc.DescFlexField.SetValue(oAWorkFlowConfig.OAApproveResultField.Name, value);
}
/// <summary>
/// 回写单据状态
/// todo 功能放到接口中,实现接口注册
/// </summary>
/// <param name="oAApproveResult"></param>
/// <param name="oAWorkFlowRecord"></param>
/// <param name="doc"></param>
/// <returns></returns>
private void UpdateDocStatus(OAApproveResult oAApproveResult, OAWorkFlowRecord oAWorkFlowRecord, Doc doc)
{
if (oAWorkFlowRecord == null|| doc==null)
{
return;
}
switch (oAApproveResult.BusinessType.Value)
{
case 0:
SaleContract saleContract = doc as SaleContract;
if (saleContract == null)
return;
saleContract.Status = oAApproveResult.ApproveSuccess ? SCStatusEnum.Approved : SCStatusEnum.Opened;
saleContract.ApproveDate = DateTime.Now;
doc = saleContract;
break;
case 1:
SO so = doc as SO;
if (so == null)
return;
so.Status = oAApproveResult.ApproveSuccess ? SODocStatusEnum.Approved : SODocStatusEnum.Open;
doc = so;
break;
case 2:
Ship ship = doc as Ship;
if (ship == null)
return;
ship.Status = oAApproveResult.ApproveSuccess ? ShipStateEnum.Approved : ShipStateEnum.Creates;
ship.ApproveDate = DateTime.Now;
doc = ship;
break;
case 3:
Receivement receivement = doc as Receivement;
if (receivement == null)
return;
receivement.Status = oAApproveResult.ApproveSuccess ? RcvStatusEnum.InStoreConfirmed : RcvStatusEnum.Opened;
receivement.ApprovedOn = DateTime.Now;
doc = receivement;
break;
case 4:
SOModify sOModify= doc as SOModify;
if (sOModify == null)
return;
sOModify.Status = oAApproveResult.ApproveSuccess ? SOModifyStatusEnum.Approved : SOModifyStatusEnum.Openend;
sOModify.ApprovedOn = DateTime.Now;
doc = sOModify;
break;
case 5:
ShipPlan shipplan = doc as ShipPlan;
if (shipplan == null)
return;
shipplan.Status = oAApproveResult.ApproveSuccess ? ShipPlanDocStatusEnum.Posted : ShipPlanDocStatusEnum.Open;
shipplan.ApproveDate = DateTime.Now;
doc = shipplan;
break;
case 6:
PurchaseOrder purorder = doc as PurchaseOrder;
if (purorder == null)
return;
purorder.Status = oAApproveResult.ApproveSuccess ? PODOCStatusEnum.Approved : PODOCStatusEnum.Opened;
purorder.ApprovedOn = DateTime.Now;
doc = purorder;
break;
case 7:
MRB mrb = doc as MRB;
if (mrb == null)
return;
mrb.MRBState = oAApproveResult.ApproveSuccess ? MRBStateEnum.Approved : MRBStateEnum.Opening;
mrb.ApproveDate = DateTime.Now;
doc = mrb;
break;
case 8:
PR pr = doc as PR;
if (pr == null)
return;
pr.Status = oAApproveResult.ApproveSuccess ? PRStatusEnum.Approved : PRStatusEnum.OpenOpen;
pr.ApprovedOn = DateTime.Now;
pr.ApprovedBy = PlatformContext.Current.UserName;
pr.ActivityType = ActivityTypeEnum.UIUpdate;
foreach (PRLine line in pr.PRLineList)
{
line.Status = oAApproveResult.ApproveSuccess ? PRStatusEnum.Approved : PRStatusEnum.OpenOpen;
line.ApprovedOn = DateTime.Now;
line.ApprovedBy = PlatformContext.Current.UserName;
line.ActivityType = ActivityTypeEnum.UIUpdate;
}
doc = pr;
break;
case 9:
ConfirmReqFundHead crfh = doc as ConfirmReqFundHead;
if (crfh == null)
return;
crfh.DocStatus = oAApproveResult.ApproveSuccess ? ReqConfirmDocStatusEnum.BizClose : ReqConfirmDocStatusEnum.Opened;
crfh.ApprovedOn = DateTime.Now;
doc = crfh;
break;
case 10:
ARBillHead arbh = doc as ARBillHead;
if (arbh == null)
return;
arbh.DocStatus = oAApproveResult.ApproveSuccess ? BillStatusEnum.Approved : BillStatusEnum.Opened;
arbh.ApprovedOn = DateTime.Now;
doc = arbh;
break;
case 11:
PayReqFundHead prfh = doc as PayReqFundHead;
if (prfh == null)
return;
prfh.DocStatus = oAApproveResult.ApproveSuccess ? InDirectHandleBillDocStatusEnum.Approved : InDirectHandleBillDocStatusEnum.Open;
prfh.ApprovedOn = DateTime.Now;
doc = prfh;
break;
case 12:
MiscShipment miscship = doc as MiscShipment;
if (miscship == null)
return;
miscship.Status = oAApproveResult.ApproveSuccess ? INVDocStatus.Approved : INVDocStatus.Open;
miscship.CurrAction = ActivityEnum.UIUpdate;
miscship.ApprovedOn = DateTime.Now;
miscship.ApprovedBy = Context.LoginUser;
doc = miscship;
break;
case 13:
PurPriceAdjustment purPriceAdjustment = doc as PurPriceAdjustment;
if (purPriceAdjustment == null)
return;
purPriceAdjustment.Status = oAApproveResult.ApproveSuccess ? PPR.Enums.Status.Approved : UFIDA.U9.PPR.Enums.Status.Opened;
purPriceAdjustment.ApprovedOn = DateTime.Now;
doc = purPriceAdjustment;
break;
}
}
/// <summary>
/// 回滚单据原来状态
/// </summary>
/// <param name="doc"></param>
private void RollbackDocStatus(Doc doc)
{
if (doc==null)
{
return;
}
if(doc is PR)
{
PR pr = (PR)doc;
pr.Status = pr.OriginalData.Status;
pr.ActivityType = pr.OriginalData.ActivityType;
foreach (PRLine line in pr.PRLineList)
{
line.Status = pr.OriginalData.Status;
line.ActivityType = pr.OriginalData.ActivityType;
}
}else if (doc is ConfirmReqFundHead|| doc is ARBillHead||
doc is PayReqFundHead)
{
if (doc.MDEntity.GetHashFlatAttrsMap().Keys.Contains("DocStatus"))
{
doc.SetValue("DocStatus", doc.OriginalData.GetValue("DocStatus"));
}
}
else
{
if (doc.MDEntity.GetHashFlatAttrsMap().Keys.Contains("Status"))
{
doc.SetValue("Status", doc.OriginalData.GetValue("Status"));
}
}
}
/// <summary>
/// 查询未同步的审批记录列表
/// </summary>
/// <returns></returns>
private EntityList<OAApproveResult> QueryOAApproveResults()
{
return OAApproveResult.Finder.FindAll("IsSync=@IsSync", new OqlParam[] { new OqlParam("IsSync", false) });
}
/// <summary>
/// 查询U9审批结果存放字段名
/// </summary>
/// <param name="fullName"></param>
/// <returns></returns>
private string QueryOAApproveResultField(string fullName)
{
OAWorkFlowConfig oAWorkFlowConfig = OAWorkFlowConfig.Finder.Find("EntityType.FullName='" + fullName + "'");
if (oAWorkFlowConfig == null)
{
return null;
}
return oAWorkFlowConfig.OAApproveResultField.Name;
}
private OAWorkFlowRecord QueryOAWorkFlowRecord(Int32 OARequestID)
{
return OAWorkFlowRecord.Finder.Find("OARequestID=@OARequestID", new OqlParam("OARequestID", OARequestID));
}
private OAWorkFlowConfig QueryOAWorkFlowConfig(OAWorkFlowRecord oAWorkFlowRecord)
{
if (oAWorkFlowRecord == null)
{
return null;
}
OAWorkFlowConfig oAWorkFlowConfig = OAWorkFlowConfig.Finder.Find("OAWorkFlowId=@OAWorkFlowId",new OqlParam("OAWorkFlowId", oAWorkFlowRecord.WorkflowID));
return oAWorkFlowConfig;
}
private Doc QueryDoc(string entityFullName,long ID)
{
EntityFinder finder = new EntityFinder(entityFullName);
return (Doc)finder.FindByID(ID);
}
}
#endregion
}
网友评论