/// <summary>
        /// 获取参数坐标
        /// </summary>
        /// <param name="templateId">获取模板参数</param>
        /// <returns>模板参数列表</returns>
        private List <ExpressParamViewModel> GetExpressParams(string templateId)
        {
            var exParams = new List <ExpressParamViewModel>();

            if (cache.Contains(templateId))
            {
                exParams = cache.Get(templateId) as List <ExpressParamViewModel>;
            }
            else
            {
                var cc = new ConditionCollection();
                cc.Add(new Condition("template_id", templateId));
                var list = this.GetRepository <McpTemplateParamInfo>().ListModel(cc);
                if (list != null)
                {
                    foreach (var param in list)
                    {
                        exParams.Add(new ExpressParamViewModel()
                        {
                            param_code = TryConvertUtil.ToString(param.ParamCode),
                            loc_x      = TryConvertUtil.ToDecimal(param.LocX),
                            loc_y      = TryConvertUtil.ToDecimal(param.LocY),
                            param_type = param.ParamType,
                            is_need    = TryConvertUtil.ToBool(param.IsNeed)
                        });
                    }
                }

                cache.Add(templateId, exParams, DateTimeOffset.Now.AddHours(24));
            }

            return(exParams);
        }
        /// <summary>
        /// 获取访问令牌
        /// </summary>
        /// <param name="app">应用参数</param>
        /// <returns>访问令牌</returns>
        public object GetAccessToken(AppViewModel app)
        {
            try
            {
                //1.校验应用信息
                CheckApp(app.app_id, app.app_key);

                //2.获取访问令牌
                var tokenDic           = new Dictionary <string, object>();
                ConditionCollection cc = new ConditionCollection();
                cc.Add(new Condition("app_id", TryConvertUtil.ToString(app.app_id)));
                cc.Add(new Condition("app_key", TryConvertUtil.ToString(app.app_key)));
                var accToken = this.GetRepository <McpAppTokenInfo>().GetModel(cc);

                var dbNow = CommonUtil.GetDBDateTime();
                if (accToken != null)
                {
                    //更新token及有效期
                    tokenDic = UpdateAccessToken(app);

                    #region 原版日期判断代码 2018-3-28 13:52:34 out

                    //if (accToken.CreatedOn.AddSeconds(accToken.ExpiresIn).AddSeconds(60) <= dbNow)
                    //{
                    //    //更新token及有效期
                    //    tokenDic = UpdateAccessToken(app);
                    //}
                    //else
                    //{
                    //    //有效期内直接返回
                    //    TimeSpan span = dbNow - accToken.CreatedOn;
                    //    double newExpiresIn = accToken.ExpiresIn - span.TotalSeconds;
                    //    tokenDic.Add("access_token", TryConvertUtil.ToString(accToken.AccessToken));
                    //    tokenDic.Add("expires_in", newExpiresIn);
                    //}

                    #endregion
                }
                else
                {
                    //创建新token及有效期
                    tokenDic = CreateAccessToken(app);
                }
                return(tokenDic);
            }
            catch (Exception ex)
            {
                throw new MessageException(ex.Message);
            }
        }
 /// <summary>
 /// 获取201命令任务
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public McpCmdOrderInfo GetCmdOrder(string orderId)
 {
     try
     {
         ConditionCollection cc = new ConditionCollection();
         cc.Add(new Condition("order_id", TryConvertUtil.ToString(orderId)));
         return(this.GetRepository <McpCmdOrderInfo>().GetModel(cc));
     }
     catch (Exception ex)
     {
         LogUtil.Info(string.Format("获取命令订单错误,参考信息:{0},order_id:{1}", ex.Message, orderId));
         LogUtil.Error(string.Format($"获取命令订单错误,order_id:{orderId}"), ex);
         return(null);
     }
 }
        /// <summary>
        /// 获取AppId
        /// </summary>
        /// <param name="accessToken">访问令牌</param>
        /// <returns></returns>
        public string GetAppIdByAccessToken(string accessToken)
        {
            var cc = new ConditionCollection();

            cc.Add(new Condition("access_token", TryConvertUtil.ToString(accessToken)));
            var token = this.GetRepository <McpAppTokenInfo>().GetModel(cc);

            if (token != null)
            {
                return(token.CreatedOn.AddSeconds(token.ExpiresIn) > CommonUtil.GetDBDateTime() ? token.AppId : string.Empty);
            }
            else
            {
                return(string.Empty);
            }
        }
Beispiel #5
0
        /// <summary>
        /// 校验统计年月字符传
        /// </summary>
        /// <param name="month">统计年月</param>
        public void CheckMonthIsValid(string month)
        {
            month = TryConvertUtil.ToString(month);
            CheckMonth(month);

            try
            {
                string   yy = month.Substring(0, 4);
                string   mm = month.Substring(4, 2);
                DateTime dt = new DateTime(TryConvertUtil.ToInt(yy), TryConvertUtil.ToInt(mm), 1);
            }
            catch
            {
                throw new MessageException("参数错误!");
            }
        }
        /// <summary>
        /// 更新访问令牌
        /// </summary>
        /// <param name="app">应用参数</param>
        /// <returns>访问令牌</returns>
        private Dictionary <string, object> UpdateAccessToken(AppViewModel app)
        {
            var tokenDic = new Dictionary <string, object>();
            var token    = new McpAppTokenInfo()
            {
                AppId       = app.app_id,
                AppKey      = app.app_key,
                AccessToken = CommonUtil.GetGuidNoSeparator(),
                ExpiresIn   = ConfigUtil.TokenExpireIn,
                CreatedOn   = CommonUtil.GetDBDateTime(),
            };

            this.GetRepository <McpAppTokenInfo>().Update(token, "access_token,expires_in,created_on");
            tokenDic.Add("access_token", TryConvertUtil.ToString(token.AccessToken));
            tokenDic.Add("expires_in", token.ExpiresIn);
            return(tokenDic);
        }
        /// <summary>
        /// 校验访问令牌
        /// </summary>
        /// <param name="appId">应用ID</param>
        /// <param name="accessToken">访问令牌</param>
        /// <returns>是否合法</returns>
        public bool CheckAccessToken(string appId, string accessToken)
        {
            ConditionCollection c1 = new ConditionCollection();

            c1.Add(new Condition("app_id", TryConvertUtil.ToString(appId)));
            c1.Add(new Condition("access_token", TryConvertUtil.ToString(accessToken)));
            var token = this.GetRepository <McpAppTokenInfo>().GetModel(c1);

            if (token != null)
            {
                return(token.CreatedOn.AddSeconds(token.ExpiresIn) > CommonUtil.GetDBDateTime());
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        ///  获取用户openID
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static string GetWechatOpenId(string code)
        {
            string openId          = String.Empty;
            string wechatAppId     = ConfigUtil.WechatAppIdForIot;
            string wechatAppSecret = ConfigUtil.WechatAppSecretForIot;

            string url        = String.Format(WeChatConsts.WECHAT_GET_OPENID, wechatAppId, wechatAppSecret, code);
            string resultText = NetUtil.WechatSendPostRequest(url, string.Empty);

            LogUtil.Debug(string.Format("GetWechatOpenId: code: {0}, res: {1}", code, resultText));
            Dictionary <string, object> dicWechat = JsonUtil.Deserialize <Dictionary <string, object> >(resultText);

            if (dicWechat.ContainsKey("openid"))
            {
                openId = TryConvertUtil.ToString(dicWechat["openid"], string.Empty);
            }
            return(openId);
        }
        /// <summary>
        /// 校验应用
        /// </summary>
        /// <param name="appId">应用ID</param>
        /// <param name="appKey">应用Key</param>
        /// <returns>是否有效</returns>
        public bool CheckApp(string appId, string appKey = "")
        {
            bool isOk = false;
            ConditionCollection c1 = new ConditionCollection();

            c1.Add(new Condition("app_id", TryConvertUtil.ToString(appId)));
            if (!string.IsNullOrWhiteSpace(appKey))
            {
                c1.Add(new Condition("app_key", TryConvertUtil.ToString(appKey)));
            }
            var application = this.GetRepository <McpApplicationInfo>().GetModel(c1);

            if (application != null)
            {
                switch (application.StatusCode)
                {
                case (int)StatusCodeType.New:
                    throw new MessageException(string.Format("应用处于{0}状态!", StatusCodeType.New.GetRemark()));

                case (int)StatusCodeType.Disabled:

                    throw new MessageException(string.Format("应用处于{0}状态!", StatusCodeType.Disabled.GetRemark()));

                case (int)StatusCodeType.Deleted:
                    throw new MessageException(string.Format("应用处于{0}状态!", StatusCodeType.Deleted.GetRemark()));

                default: break;
                }
                ;

                isOk = true;
            }
            else
            {
                throw new MessageException("无效应用,app_id或app_key参数错误!");
            }
            return(isOk);
        }
Beispiel #10
0
        /// <summary>
        /// 生成单据编号
        /// </summary>
        /// <returns>单据编号</returns>
        private string GetNewBillCode()
        {
            int maxNum             = 99999;
            ParameterCollection pc = new ParameterCollection();
            string strCondition    = OtherCondition;
            var    newCode         = string.Empty;
            var    lastCode        = string.Empty;
            var    querySql        = string.Format("SELECT `{0}` FROM {1} {2}  ORDER BY `{0}` DESC LIMIT 0,1", CodeField, TableName, strCondition);

            lastCode = TryConvertUtil.ToString(DbUtil.DataManager.DataManagerMcp.IData.ExecuteScalar(querySql), string.Empty);
            var lastNum        = -1;
            var prefixLength   = 0;
            var billSerialCode = string.Empty;
            var day            = CommonUtil.GetDBDateTime().Date.ToString("yyMMdd");

            if (ConfigUtil.IsTestModel)
            {
                day = CommonUtil.GetDBDateTime().Date.AddYears(-10).ToString("yyMMdd");//测试环境使用

                querySql = string.Format("SELECT `{0}` FROM {1} WHERE LEFT({0},{3})='{2}'  ORDER BY `{0}` DESC LIMIT 0,1", CodeField, TableName, Prefix + day, Prefix.Length + day.Length);
                lastCode = TryConvertUtil.ToString(DbUtil.DataManager.DataManagerMcp.IData.ExecuteScalar(querySql), string.Empty);
            }
            if (lastCode != null && !string.IsNullOrWhiteSpace(lastCode.ToString()))
            {
                if (!string.IsNullOrWhiteSpace(Prefix))
                {
                    //单据号类似: T2013041100001
                    billSerialCode = lastCode.ToString().TrimStart(Prefix.ToCharArray());
                    prefixLength   = Prefix.Length;
                }
                else
                {
                    //单据号类似: 130411000001
                    billSerialCode = lastCode;
                }

                var dateLen = 6;    //日期长度
                if (billSerialCode.Length == dateLen + SerialLength)
                {
                    //比较日期
                    var y = TryConvertUtil.ToInt(lastCode.Substring(prefixLength + 0, 2), 10);
                    if (ConfigUtil.IsTestModel)
                    {
                        var temp = TryConvertUtil.ToInt(lastCode.Substring(prefixLength + 0, 2), 10);
                        y = temp > 10 ? temp - 5 : temp;//测试环境使用
                    }
                    var m = TryConvertUtil.ToInt(lastCode.Substring(prefixLength + 2, 2), 1);
                    var d = TryConvertUtil.ToInt(lastCode.Substring(prefixLength + 4, 2), 1);
                    var n = billSerialCode.Substring(6);

                    //日期相等
                    if (day == (new DateTime(y, m, d)).ToString("yyMMdd"))
                    {
                        lastNum = TryConvertUtil.ToInt(n.TrimStart('0'), 1);
                    }
                }
            }
            if (lastNum == -1)
            {
                lastNum = 0;
            }
            lastNum += 1;
            if (lastNum > maxNum)
            {
                throw new BusinessException("当日数据异常");
            }
            newCode = string.Format("{0}{1}{2}", !string.IsNullOrWhiteSpace(Prefix) ? string.Format("{0}", Prefix) : string.Empty, day, lastNum.ToString().PadLeft(SerialLength, '0'));
            return(newCode);
        }
Beispiel #11
0
        /// <summary>
        /// 检查版本信息
        /// </summary>
        /// <param name="verModel">版本信息参数</param>
        /// <returns>版本信息结果</returns>
        public object CheckVersion(VerViewModel verModel)
        {
            //校验设备表示
            bool isExist = SingleInstance <PrinterService> .Instance.CheckEquipmentIsExists(verModel.Mac);

            if (!isExist)
            {
                LogUtil.Info($"设备不存在-{JsonUtil.Serialize(verModel)}");
                throw new MessageException("设备不存在!");
            }

            //更改设备对应版本号
            bool result = SingleInstance <PrinterService> .Instance.UpdatePrintVersion(verModel);

            if (!result)
            {
                throw new MessageException($"更新打印机{verModel.Mac}版本号失败,请重试");
            }

            //获取版本
            Dictionary <string, object> verDic = new Dictionary <string, object>();
            ConditionCollection         cc     = new ConditionCollection();

            cc.Add(new Condition("objec_type", TryConvertUtil.ToString(verModel.Type)));
            cc.Add(new Condition("status_code", StatusCodeType.Valid.GetHashCode()));

            int isNeed = 0;

            string newVer   = string.Empty;
            string filePath = string.Empty;
            var    lastVer  = this.GetRepository <McpSysVersionInfo>().GetModel(cc);

            if (lastVer != null)
            {
                var isUpdate  = false;
                var serVer    = 0;
                var curVer    = 0;
                var serVers   = lastVer.ObjectVersion.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                var curVers   = verModel.Ver.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                var maxLength = Math.Max(serVers.Length, curVers.Length);

                for (var i = 0; i < maxLength; i++)
                {
                    serVer = i < serVers.Length ? TryConvertUtil.ToInt(serVers[i]) : 0;
                    curVer = i < curVers.Length ? TryConvertUtil.ToInt(curVers[i]) : 0;
                    if (serVer != curVer)
                    {
                        isUpdate = serVer > curVer;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }

                if (isUpdate)
                {
                    isNeed   = lastVer.IsForce > 0 ? 2 : 1;
                    newVer   = lastVer.ObjectVersion;
                    filePath = lastVer.VersionFile;
                }
            }

            verDic.Add("IsNeedUpdate", isNeed);
            verDic.Add("NewVer", newVer);
            verDic.Add("UpdateFilePath", filePath);

            LogUtil.Info(string.Format("设备:{0},当前版本:{1},获取新版本...", verModel.Mac, verModel.Ver));

            return(verDic);
        }