Example #1
0
        /// <summary>
        /// 生成主键查询条件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyList"></param>
        /// <returns></returns>
        SuuchaExpression KeyCondition <T>(List <object[]> keyList)
        {
            var condition = SuuchaExpression.Equal(SuuchaExpression.Constant(0), SuuchaExpression.Constant(1));

            PropertyInfo[] pis = EntityTool.GetKeyProperty <T>();
            foreach (var values in keyList)
            {
                if (values.Length != pis.Length)
                {
                    throw new Exception("主键值数量必须为:" + pis.Length);
                }
                SuuchaBinaryExpression kExp = null;
                for (int i = 0; i < pis.Length; i++)
                {
                    kExp = 0 == i?SuuchaExpression.Equal(pis[i].Name, values[i]) : SuuchaExpression.And(kExp, SuuchaExpression.Equal(pis[i].Name, values[i]));
                }
                condition = SuuchaExpression.Or(condition, kExp);
            }
            return(condition);
        }
Example #2
0
        private void PushOddsToIntegration(int index)
        {
            try
            {
                if (index + 1 > OddsDt.Rows.Count)
                {
                    Log.Info($"賽事編號:{MatchId},第{index + 1}次賠率資料送完");
                    CacheTool.MatchRemove(MatchId);
                    return;
                }

                var lodData = OddsDt.Rows[index]["JsonData"].ToString();

                ToMq("odds", "odds.replaylive", EntityTool.Serialize(lodData));
                Log.Info($"賽事編號:{MatchId},第{index + 1}次發送賠率資料:{lodData}");

                int timer = 0;
                if (index <= Odds.Length - 1)
                {
                    timer = avgTimeForOdds;
                }
                else
                {
                    timer = modTimeForOdds;
                }

                Nami.Delay(timer).Do(() =>
                {
                    PushOddstToSportServer(index + 1);
                });
            }
            catch (Exception ex)
            {
                var lodData = JsonConvert.SerializeObject(Odds[index]);
                Log.Info($"賽事編號:{MatchId},第{index + 1}次失敗,失敗原因:{ex.Message},失敗原因:{ex.StackTrace}");
            }
        }
        public void GetRoots()
        {
            var roots = EntityTool.GetRoots <Department>();

            Assert.AreEqual(EntityTool.GetRootCount <Department>(), roots.Count);
        }
Example #4
0
        public async Task <object> Modify(string token, dynamic data, string json = "")
        {
            try
            {
                data = data ?? JsonConvert.DeserializeObject <dynamic>(json);
                if (data == null)
                {
                    throw new Exception("解析Json对象失败");
                }
                PropertyInfo[] pis = EntityTool.GetKeyProperty <T>();
                if (data.GetType() == typeof(JObject))
                {
                    string str = data.ToString();
                    T      t   = JsonConvert.DeserializeObject <T>(str);
                    if (t is BaseEntity)
                    {
                        (t as BaseEntity).Modifier = new UserService().GetByToken(token).Name;
                    }
                    JObject       jObject = data as JObject;
                    List <object> ids     = new List <object>();
                    foreach (var p in pis)
                    {
                        PropertyInfo tp = t.GetType().GetProperty(p.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                        if (tp == null)
                        {
                            throw new Exception("实体未包含主键:" + p.Name);
                        }
                        ids.Add(tp.GetValue(t));
                    }
                    T model = await Get(ids.ToArray());

                    if (model == null)
                    {
                        throw new Exception("查找修改对象失败");
                    }
                    foreach (var item in jObject)
                    {
                        PropertyInfo mp = model.GetType().GetProperty(item.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                        if (mp != null)
                        {
                            PropertyInfo tp = t.GetType().GetProperty(item.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                            mp.SetValue(model, tp.GetValue(t));
                        }
                    }
                    List <T> list = new List <T>()
                    {
                        model
                    };
                    OnEntityModifing?.Invoke(ref list);
                    int r = await Put(model);

                    OnEntityModified?.Invoke(ref list);
                    return(r);
                }
                else if (data.GetType() == typeof(JArray))
                {
                    string   str       = data.ToString();
                    JArray   jarray    = JsonConvert.DeserializeObject(str) as JArray;
                    List <T> list      = JsonConvert.DeserializeObject <List <T> >(str);
                    List <T> modellist = new List <T>();
                    for (int i = 0; i < list.Count; i++)
                    {
                        var           t       = list[i];
                        JObject       jObject = jarray[i] as JObject;
                        List <object> ids     = new List <object>();
                        if (t is BaseEntity)
                        {
                            (t as BaseEntity).Modifier = new UserService().GetByToken(token).Name;
                        }
                        foreach (var p in pis)
                        {
                            PropertyInfo tp = t.GetType().GetProperty(p.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                            if (tp == null)
                            {
                                throw new Exception("实体未包含主键:" + p.Name);
                            }
                            ids.Add(tp.GetValue(t));
                        }
                        T model = await Get(ids.ToArray());

                        if (model == null)
                        {
                            throw new Exception("查找修改对象失败");
                        }
                        foreach (var item in jObject)
                        {
                            PropertyInfo mp = model.GetType().GetProperty(item.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                            if (mp != null)
                            {
                                PropertyInfo tp = t.GetType().GetProperty(item.Key, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                                mp.SetValue(model, tp.GetValue(t));
                            }
                        }
                        modellist.Add(model);
                    }
                    OnEntityModifing?.Invoke(ref modellist);
                    int r = await PutList(modellist);

                    OnEntityModified?.Invoke(ref modellist);
                    return(r);
                }
                throw new Exception("解析Json对象失败");
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #5
0
        /// <summary>
        /// 添加客单
        /// </summary>
        /// <returns></returns>
        public bool AddOrder(Curorder order, IList <CurorderDetail> details, int channel, string paycode)
        {
            int    UserId         = 0;
            string Phone          = string.Empty;
            string HmeFlowId_Last = string.Empty;

            if (order == null || details.Count < 1)
            {
                throw new Exception("客单或客单明细不能为空");
            }

            if (channel > 0)  //如果非现金支付
            {
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交预结账流水", "结账");
                //提交消费流水(预流水)
                MsgArgs msg = (new HttpSubmitConsumeSerial("0")).Request(order, details);
                if (msg.Code != 1)
                {
                    throw new Exception("提交流水失败\n" + msg.ErrMessage);
                }
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始支付", "结账");
                //提交扫码支付
                msg = (new HttpMicropay()).Request(order.HmeOrderId, channel, paycode);
                if (msg.Code != 1)
                {
                    throw new Exception("付款失败\n" + msg.ErrMessage);
                }
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n支付返回", "结账");
                JObject jobj = JObject.Parse(msg.Content);
                if (string.IsNullOrEmpty(jobj["data"]["userId"].ToString()))
                {
                    UserId = 0;
                }
                else
                {
                    UserId = int.Parse(jobj["data"]["userId"].ToString());
                }
                Phone = jobj["data"]["phone"].ToString();
            }

            //转换当前客单及明细为历史客单及明细
            Hisorder h = CurorderToHisorder(order);

            order.HmeUserId = UserId;
            h.HmeUserId     = UserId;
            List <HisorderDetail> hlist = new List <HisorderDetail>();
            Bill bill = CreateBill(h);

            for (int i = 0; i < details.Count; i++)
            {
                hlist.Add(CurorderDetailToHisorderDetail(details[i]));
            }
            try
            {
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始保存本地账单", "结账");
                OdbcTransTool tran = new OdbcTransTool();
                OdbcCommand   cmd;
                DataTable     dtHisorder = EntityTool.EntityToDataTable <Hisorder>(h, out cmd);
                tran.UpdateDataTableUsingTrans(dtHisorder, cmd);
                DataTable dtHisorderDetail = EntityTool.EntityListToDataTable(hlist, out cmd);
                tran.UpdateDataTableUsingTrans(dtHisorderDetail, cmd);
                DataTable dtBill = EntityTool.EntityToDataTable <Bill>(bill, out cmd);
                tran.UpdateDataTableUsingTrans(dtBill, cmd);
                tran.Commit();
                Debug.WriteLine(DateTime.Now.ToString() + "\r\n本地账单保存完成", "结账");
                try
                {
                    Debug.WriteLine(DateTime.Now.ToString() + "\r\n开始提交最终结账流水", "结账");
                    //提交消费流水(最终流水),就算失败也不影响结账流程
                    MsgArgs msg = (new HttpSubmitConsumeSerial("1")).Request(order, details);
                    if (msg.Code != 1)
                    {
                        MessageBox.Show("结账成功但提交流水失败\n" + msg.ErrMessage, "提示信息");
                    }
                    Debug.WriteLine(DateTime.Now.ToString() + "\r\n最终结账流水提交完成", "结账");
                    HmeFlowId_Last = JObject.Parse(msg.Content)["data"].ToString();
                }
                catch (Exception e)
                {
                    MessageBox.Show("结账成功但提交流水失败\n" + e.Message, "提示信息");
                }
                string sql = "update hisorder set hme_id = ? where hisorder_id = ?";
                OdbcTool.ExecuteSql(sql, HmeFlowId_Last, h.HisorderId.Substring(0, 18));
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception("添加客单失败\n" + e.Message);
            }
        }