public ResponseResult Update(ProductOrderEntity entity)
 {
     return Update<ProductOrderEntity>(entity);
 }
 public ResponseResult<dynamic> Insert(ProductOrderEntity entity)
 {
     return Insert<ProductOrderEntity>(entity);
 }
        /// <summary>
        /// 快递发货
        /// </summary>
        /// <param name="entity"></param>
        public WfAppResult Delivery(ProductOrderEntity entity)
        {
            var appResult = WfAppResult.Default();
            var wfas = new WfAppInteropService();
            var session = SessionFactory.CreateSession();
            try
            {
                session.BeginTrans();

                //流程运行
                var actionParameterInternal = new ActionParameterInternal();
                actionParameterInternal.MethodParameters = new object[] {"alexsenda"};
               
                WfAppRunner.ActionMethodParameters = new Dictionary<string, ActionParameterInternal>();
                WfAppRunner.ActionMethodParameters.Add("CallHello", actionParameterInternal);

                var result = wfas.RunProcess(session, WfAppRunner, WfAppRunner.Conditions);
                if (result.Status == WfExecutedStatus.Success)
                {
                    //写步骤记录表
                    Write(session, WfAppRunner, "发货", entity.ID.ToString(), entity.OrderCode, "完成发货");

                    //业务数据处理部分,此处是简单示例...
                    short status = GetProductOrderStatusByActivityCode(WfAppRunner.ProcessGUID, WfAppRunner.Version, 
                        WfAppRunner.NextActivityPerformers.Keys.ElementAt<string>(0));
                    UpdateStatus(entity.ID, status, session);
                    session.Commit();
                    appResult = WfAppResult.Success();
                }
                else
                {
                    session.Rollback();
                    appResult = WfAppResult.Error(result.Message);
                }
            }
            catch (System.Exception ex)
            {
                session.Rollback();
                appResult = WfAppResult.Error(ex.Message);
            }
            finally
            {
                session.Dispose();
            }
            return appResult;
        }
        /// <summary>
        /// 称重
        /// </summary>
        /// <param name="entity"></param>
        public WfAppResult Weight(ProductOrderEntity entity)
        {
            var appResult = WfAppResult.Default();
            var wfas = new WfAppInteropService();
            var session = SessionFactory.CreateSession();
            try
            {
                session.BeginTrans();

                //流程运行
                var result = wfas.RunProcess(session, WfAppRunner, WfAppRunner.Conditions);
                if (result.Status == WfExecutedStatus.Success)
                {
                    //写步骤记录表
                    Write(session, WfAppRunner, "称重", entity.ID.ToString(), entity.OrderCode, "完成称重");

                    //业务数据处理部分,此处是简单示例...
                    short status = GetProductOrderStatusByActivityCode(WfAppRunner.ProcessGUID, WfAppRunner.Version,
                        WfAppRunner.NextActivityPerformers.Keys.ElementAt<string>(0));
                    UpdateStatus(entity.ID, status, session);
                    session.Commit();
                    appResult = WfAppResult.Success();
                }
                else
                {
                    session.Rollback();
                    appResult = WfAppResult.Error(result.Message);
                }
            }
            catch (System.Exception ex)
            {
                session.Rollback();
                appResult = WfAppResult.Error(ex.Message);
            }
            finally
            {
                session.Dispose();
            }
            return appResult;
        }
        /// <summary>
        /// 派单
        /// </summary>
        /// <param name="entity"></param>
        public WfAppResult Dispatch(ProductOrderEntity entity)
        {
            //启动流程
            var appResult = WfAppResult.Default();
            var wfas = new WfAppInteropService();

            try
            {
                //判断流程有没有已经启动
                var isRunning = wfas.CheckProcessInstanceRunning(WfAppRunner);
                if (isRunning == false)
                {
                    var startedResult = wfas.StartProcess(WfAppRunner);
                    if (startedResult.Status != WfExecutedStatus.Success)
                    {
                        appResult = WfAppResult.Error(startedResult.Message);
                        return appResult;
                    }
                }
            }
            catch (System.Exception ex)
            {
                appResult = WfAppResult.Error(ex.Message);
                return appResult;
            }

            //运行流程部分
            //继续下一步运行
            var session = SessionFactory.CreateSession();
            try
            {
                session.BeginTrans();

                //运行流程
                var runResult = wfas.RunProcess(session, WfAppRunner, WfAppRunner.Conditions);
                if (runResult.Status == WfExecutedStatus.Success)
                {

                    //写步骤记录表
                    Write(session, WfAppRunner, "派单", entity.ID.ToString(), entity.OrderCode, "完成派单");

                    //业务数据处理部分,此处是简单示例...
                    short status = GetProductOrderStatusByActivityCode(WfAppRunner.ProcessGUID, WfAppRunner.Version,
                        WfAppRunner.NextActivityPerformers.Keys.ElementAt<string>(0));
                    UpdateStatus(entity.ID, status, session);
                    session.Commit();
                    appResult = WfAppResult.Success();
                }
                else
                {
                    session.Rollback();
                    appResult = WfAppResult.Error(runResult.Message);
                }
            }
            catch (System.Exception ex)
            {
                session.Rollback();
                appResult = WfAppResult.Error(ex.Message);
            }
            finally
            {
                session.Dispose();
            }
            return appResult;
        }
        /// <summary>
        /// 同步订单
        /// </summary>
        /// <param name="entity"></param>
        public ProductOrderEntity SyncOrder()
        {
            var entity = new ProductOrderEntity();
            var rnd = new Random();
            entity.OrderCode = string.Format("TB{0}", rnd.Next(100000, 999999).ToString());
            entity.Status = (short)ProductOrderStatusEnum.Ready;
            entity.ProductName = pruducttype[rnd.Next(1, 7)-1];
            entity.Quantity = rnd.Next(1, 10);
            entity.UnitPrice = 1000;
            entity.TotalPrice = entity.Quantity * entity.UnitPrice;

            var a = rnd.Next(1, 10) - 1;
            entity.CustomerName = customertype[a];
            entity.Address = addresstype[a];

            entity.Mobile = rnd.Next(100000, 999999).ToString();
            entity.Remark = shoptype[rnd.Next(1, 6)-1];
            entity.CreatedTime = System.DateTime.Now;

            QuickRepository.Insert<ProductOrderEntity>(entity);

            return entity;
        }