示例#1
0
        public HttpResponseMessage CommandEQM(string EqmUID, int Command)
        {
            var response = new MyHttpResponseMessage();

            response.apiNumber = "C052_EQMController_CommandEQM";
            var msg = "";

            try
            {
                var EqmU = eqm.eqm_EquipmentSugar.GetById(EqmUID);
                if (EqmU == null)
                {
                    response.SetContent(HttpStatus.error, "设备不存在", "", ResponseType.josn);
                    return(response);
                }
                var project = dict.dict_ProjectListSQLSugar.GetById(EqmU.ProjectCode);
                if (project == null)
                {
                    response.SetContent(HttpStatus.error, "项目不存在!", project, ResponseType.josn);
                    return(response);
                }
                var        sysManager = new ORM.SqlSugar.BLL.sysManager();
                var        model      = sysManager.AliConfigSQLSugar.GetById(1);
                PubManager pum        = new PubManager(model.AccessKey, model.SecretKey);
                var        rmsg       = "";
                var        pupstr     = "{\"method\":\"thing.service.property.set\",\"id\":\"222857295\",\"params\":{\"Command\":\"" + Command + "_1\"},\"version\":\"1.0.0\"}";
                var        presut     = pum.Pub(project.ProductKey, EqmU.DeviceName, pupstr, out rmsg);
                if (presut)
                {
                    response.SetContent(HttpStatus.ok, "指令下发成功", "", ResponseType.josn);
                    return(response);
                }
                else
                {
                    response.SetContent(HttpStatus.error, "与硬件通讯失败", rmsg, ResponseType.josn);
                }
            }
            catch (Exception ex)
            {
                msg = "ERROR";
                AddErrorLog(LogEnum.eqm, ex.Message, ex.StackTrace);
                response.SetContent(HttpStatus.error, ex.Message, msg, ResponseType.josn);
            }
            return(response);
        }
示例#2
0
        public HttpResponseMessage SendSms(string mobile)
        {
            var response = new MyHttpResponseMessage();

            response.apiNumber = "C021_SysController_SendSms";
            try
            {
                ORM.SqlSugar.BLL.sysManager sysManager = new ORM.SqlSugar.BLL.sysManager();
                var model    = sysManager.AliConfigSQLSugar.GetById(1);
                var instance = SMSManager.GetInstance(model.DyAccessKeyId, model.DyAccessKeySecret);
                var msgCode  = JVS_ADM.Common.Utils.Number(5);
                var result   = instance.SmsSendMesaage(mobile, "{\"code\":\"" + msgCode + "\"}", "SMS_147196393");
                if (result)
                {
                    if (dicRegCode.Keys.Contains(mobile))
                    {
                        dicRegCode[mobile] = msgCode;
                    }
                    else
                    {
                        dicRegCode.Add(mobile, msgCode);
                    }
                    response.SetContent(HttpStatus.ok, "发送成功", "", ResponseType.josn);
                }
                else
                {
                    response.SetContent(HttpStatus.error, "发送失败", "", ResponseType.josn);
                }
            }
            catch (Exception ex)
            {
                AddErrorLog(LogEnum.sys, ex.Message, ex.StackTrace);
                response.SetContent(HttpStatus.error, ex.Message, null, ResponseType.josn);
            }
            return(response);
        }
示例#3
0
        public HttpResponseMessage OpenMaintainEQM(string MemberCode, int Switch, string EqmUID, string MaintainProductCode, bool Discharge)
        {
            var response = new MyHttpResponseMessage();

            response.apiNumber = "A049_EQMController_OpenMaintainEQM";
            var msg = "";

            try
            {
                var EqmU = eqm.eqm_EquipmentSugar.GetById(EqmUID);
                if (EqmU == null)
                {
                    response.SetContent(HttpStatus.error, "设备不存在", "", ResponseType.josn);
                    return(response);
                }
                var exit_model = eqm.eqm_ExchangeListSugar.GetSingle(p => p.EqmUID == EqmUID && p.Status != 3 && p.Status != 9 && p.OverdueTime > DateTime.Now);
                if (exit_model != null)
                {
                    response.SetContent(HttpStatus.error, "设备正在使用中,请等待", exit_model.OverdueTime, ResponseType.josn);
                    return(response);
                }
                var pd = new pdMannager();

                var project = dict.dict_ProjectListSQLSugar.GetById(EqmU.ProjectCode);
                if (project == null)
                {
                    response.SetContent(HttpStatus.error, "项目不存在!", project, ResponseType.josn);
                    return(response);
                }
                var _switch = eqm.eqm_PartitionSwitchSugar.GetSingle(p => p.EqmUID == EqmUID && p.PartitionWallID == Switch);
                if (_switch == null)
                {
                    response.SetContent(HttpStatus.error, "该电池单元不可用!", project, ResponseType.josn);
                    return(response);
                }

                if (!string.IsNullOrEmpty(MaintainProductCode))
                {
                    var count = eqm.eqm_PartitionSwitchSugar.Count(p => p.ProductCode == MaintainProductCode);
                    if (count > 0)
                    {
                        response.SetContent(HttpStatus.error, "该电池已在设备中!", project, ResponseType.josn);
                        return(response);
                    }
                    var product = pd.pd_ProductListSugar.GetById(MaintainProductCode);
                    if (product == null)
                    {
                        response.SetContent(HttpStatus.error, "电池不存在!", product, ResponseType.josn);
                        return(response);
                    }

                    if (product.ProductType != _switch.ProductType)
                    {
                        response.SetContent(HttpStatus.error, "该单元不能放这个电池!", project, ResponseType.josn);
                        return(response);
                    }
                    var scount = mb.mb_StockLSugar.Count(p => p.Qty > 0 && p.ProductCode == MaintainProductCode);
                    if (scount > 0)
                    {
                        response.SetContent(HttpStatus.error, "这个电池已在会员使用中!", project, ResponseType.josn);
                        return(response);
                    }
                }
                var or_head = new ORM.SqlSugar.Model.eqm.eqm_ExchangeList();
                var ExRef   = "Exchange" + JVS_ADM.Common.Utils.GetRamCode();
                if (Discharge)
                {
                    ExRef = "Discharge" + JVS_ADM.Common.Utils.GetRamCode();
                }

                or_head.ExRef          = ExRef;
                or_head.ExTime         = DateTime.Now;
                or_head.MemberCode     = MemberCode;
                or_head.OverdueTime    = DateTime.Now.AddMinutes(1);
                or_head.Status         = 0;
                or_head.ShopID         = EqmU.ShopID;
                or_head.EqmUID         = EqmU.EqmUID;
                or_head.ProductCode    = MaintainProductCode;
                or_head.OldProductCode = "";
                or_head.Switch         = Switch;
                var result = db.SqlServerClient.Ado.UseTran(() =>
                {
                    var sysManager = new ORM.SqlSugar.BLL.sysManager();
                    var model      = sysManager.AliConfigSQLSugar.GetById(1);
                    PubManager pum = new PubManager(model.AccessKey, model.SecretKey);
                    var rmsg       = "";
                    Random rd      = new Random();


                    var pupstr = "{\"method\":\"thing.service.property.set\",\"id\":\"222940092\",\"params\":{\"MaintainLast\":\"" + ExRef + "_" + Switch + "_1\"},\"version\":\"1.0.0\"}";
                    if (Discharge)
                    {
                        pupstr = "{\"method\":\"thing.service.property.set\",\"id\":\"222940092\",\"params\":{\"Discharge\":\"" + ExRef + "_" + Switch + "_1\"},\"version\":\"1.0.0\"}";
                    }
                    var presut = pum.Pub(project.ProductKey, EqmU.DeviceName, pupstr, out rmsg);
                    if (presut)
                    {
                        eqm.eqm_ExchangeListSugar.Insert(or_head);
                    }
                    else
                    {
                        response.SetContent(HttpStatus.error, "与硬件通讯失败", or_head, ResponseType.josn);
                    }
                });
                if (result.IsSuccess)
                {
                    response.SetContent(HttpStatus.ok, "操作成功", or_head, ResponseType.josn);
                    return(response);
                }
                else
                {
                    response.SetContent(HttpStatus.error, result.ErrorMessage, or_head, ResponseType.josn);
                }
            }
            catch (Exception ex)
            {
                msg = "ERROR";
                AddErrorLog(LogEnum.eqm, ex.Message, ex.StackTrace);
                response.SetContent(HttpStatus.error, ex.Message, msg, ResponseType.josn);
            }
            return(response);
        }
示例#4
0
        public HttpResponseMessage OpenEQM(string MemberCode, string EqmUID, string OldProductCode, decimal UnitPrice, decimal Qty, decimal PayAmount, decimal DiscountedAmt)
        {
            var response = new MyHttpResponseMessage();

            response.apiNumber = "C045_EQMController_OpenEQM";
            var msg = "";

            try
            {
                var member = mb.mb_BaseInfoSQLSugar.GetById(MemberCode);
                if (member == null || member.ExpirationDate == null || member.ExpirationDate < DateTime.Now)
                {
                    response.SetContent(HttpStatus.error, "您还不是VIP会员!", "chongqian", ResponseType.josn);
                    return(response);
                }

                var EqmU = eqm.eqm_EquipmentSugar.GetById(EqmUID);
                if (EqmU == null)
                {
                    response.SetContent(HttpStatus.error, "设备不存在", "", ResponseType.josn);
                    return(response);
                }
                var exit_model = order.order_HeaderSugar.GetSingle(p => p.EqmUID == EqmUID && p.Status != 3 && p.Status != 9 && p.OverdueTime > DateTime.Now);
                if (exit_model != null)
                {
                    response.SetContent(HttpStatus.error, "设备正在使用中,请稍后重试", exit_model.OverdueTime, ResponseType.josn);
                    return(response);
                }

                var productOld = pd.pd_ProductListSugar.GetById(OldProductCode);
                if (productOld == null)
                {
                    response.SetContent(HttpStatus.error, "电池代码无效!", productOld, ResponseType.josn);
                    return(response);
                }

                var project = dict.dict_ProjectListSQLSugar.GetById(EqmU.ProjectCode);
                if (project == null)
                {
                    response.SetContent(HttpStatus.error, "项目不存在!", project, ResponseType.josn);
                    return(response);
                }
                if (productOld == null)
                {
                    response.SetContent(HttpStatus.error, "电池不存在!", productOld, ResponseType.josn);
                    return(response);
                }
                var list        = pd.pd_ProductTypeSugar.GetList(p => p.ProjectCode == "cabinet");
                var ProductType = pd.GetSaleCardType(list, productOld.ProductType.ToInt32());

                var vipCount = mb.mb_Assets.Count(p => p.MemberCode == MemberCode && p.ProductType == ProductType && p.ExpiryDate > DateTime.Now);
                if (vipCount <= 0)
                {
                    response.SetContent(HttpStatus.error, "您还没开通VIP会员或是会员已过期!", project, ResponseType.josn);
                    return(response);
                }
                var count = eqm.eqm_PartitionSwitchSugar.Count(p => p.EqmUID == EqmUID && p.ProductType == productOld.ProductType && p.Switch == 1);
                if (count <= 0)
                {
                    response.SetContent(HttpStatus.error, "没有可用的单元,请稍后重试!", project, ResponseType.josn);
                    return(response);
                }
                var or_head  = new ORM.SqlSugar.Model.order.order_Header();
                var or_List  = new ORM.SqlSugar.Model.order.order_List();
                var OrderRef = "Battery" + JVS_ADM.Common.Utils.GetRamCode();
                or_head.OrderRef       = OrderRef;
                or_head.OrderTime      = DateTime.Now;
                or_head.ProjectCode    = EqmU.ProjectCode;
                or_head.MemberCode     = MemberCode;
                or_head.TotalAmount    = UnitPrice * Qty;
                or_head.PayAmount      = PayAmount;
                or_head.DiscountedAmt  = DiscountedAmt;
                or_head.mbAddressID    = 0;
                or_head.OverdueTime    = DateTime.Now.AddMinutes(1);
                or_head.Status         = 0;
                or_head.ShopID         = EqmU.ShopID;
                or_head.EqmUID         = EqmU.EqmUID;
                or_head.Para1          = 0;
                or_head.Msg            = productOld.ProductType.ToString() + "类型的电池";
                or_List.OrderRef       = OrderRef;
                or_List.ProductCode    = "";
                or_List.MemberCode     = MemberCode;
                or_List.Qty            = Qty;
                or_List.CreditsNo      = 0;
                or_List.OldProductCode = OldProductCode;
                var Reservelist = order.order_ReservedSugar.GetList(p => p.MemberCode == MemberCode && p.EvaluateTime > DateTime.Now && p.Status == 1);


                var result = db.SqlServerClient.Ado.UseTran(() =>
                {
                    var sysManager = new ORM.SqlSugar.BLL.sysManager();
                    var model      = sysManager.AliConfigSQLSugar.GetById(1);
                    PubManager pum = new PubManager(model.AccessKey, model.SecretKey);
                    var rmsg       = "";
                    Random rd      = new Random();
                    var pupstr     = "{\"method\":\"thing.service.property.set\",\"id\":\"222857295\",\"params\":{\"SwitchLast\":\"" + OrderRef + "_" + productOld.ProductType + "\"},\"version\":\"1.0.0\"}";
                    var presut     = pum.Pub(project.ProductKey, EqmU.DeviceName, pupstr, out rmsg);
                    if (presut)
                    {
                        order.order_HeaderSugar.Insert(or_head);
                        order.order_ListSugar.Insert(or_List);
                        foreach (var item in Reservelist)
                        {
                            item.Status = 3;
                            order.order_ReservedSugar.Update(item);
                        }
                    }
                    else
                    {
                        response.SetContent(HttpStatus.error, "与硬件通讯失败", or_head, ResponseType.josn);
                    }
                });
                if (result.IsSuccess)
                {
                    response.SetContent(HttpStatus.ok, "操作成功", or_head, ResponseType.josn);
                }
                else
                {
                    response.SetContent(HttpStatus.error, result.ErrorMessage, or_head, ResponseType.josn);
                }
            }
            catch (Exception ex)
            {
                msg = "ERROR";
                AddErrorLog(LogEnum.eqm, ex.Message, ex.StackTrace);
                response.SetContent(HttpStatus.error, ex.Message, msg, ResponseType.josn);
            }
            return(response);
        }
示例#5
0
        public HttpResponseMessage RegisterDevice(string productKey, string deviceName)
        {
            var response = new MyHttpResponseMessage();

            response.apiNumber = "S001_IoTController_RegisterDevice";
            var msg = "";

            try
            {
                if (string.IsNullOrEmpty(productKey) || string.IsNullOrEmpty(deviceName))
                {
                    response.SetContent(HttpStatus.error, "参数不齐", "ERROR", ResponseType.text);
                    return(response);
                }

                ORM.SqlSugar.BLL.sysManager sysManager = new ORM.SqlSugar.BLL.sysManager();
                var model = sysManager.AliConfigSQLSugar.GetById(1);
                if (model == null)
                {
                    response.SetContent(HttpStatus.error, "没有阿里的配置信息", "ERROR", ResponseType.text);
                    return(response);
                }
                var lotManager = new DeviceManager(model.AccessKey, model.SecretKey);
                var project    = dm.dict_ProjectListSQLSugar.GetSingle(p => p.ProductKey == productKey);
                if (project == null)
                {
                    response.SetContent(HttpStatus.error, "没有找到ProductKey:" + productKey + "的项目", "ERROR_没有找到ProductKey", ResponseType.text);
                    return(response);
                }
                var exit = eqm.eqm_EquipmentSugar.Count(p => p.DeviceName == deviceName);
                if (exit > 0)
                {
                    response.SetContent(HttpStatus.error, "已存在deviceName:" + deviceName + "的设备", "ERROR_已存在", ResponseType.text);
                    return(response);
                }
                var equipment = new ORM.SqlSugar.Model.eqm.eqm_Equipment();
                equipment.EqmUID        = project.ProjectCode + "_" + Guid.NewGuid().ToString();
                equipment.CorpCode      = "35003";
                equipment.DeviceName    = deviceName;
                equipment.OnLine        = false;
                equipment.ProjectCode   = project.ProjectCode;
                equipment.ShopID        = 1;
                equipment.RegisterDate  = DateTime.Now;
                equipment.DeviceSecret  = "";
                equipment.EquipmentName = project.ProjectName;
                var result = lotManager.RegisterDevice(productKey, deviceName, out msg);
                if (result)
                {
                    equipment.DeviceSecret = msg;
                    result = eqm.eqm_EquipmentSugar.Insert(equipment);
                    if (result)
                    {
                        response.SetContent(HttpStatus.ok, "设置成功", "OK_" + msg + "", ResponseType.text);
                        return(response);
                    }
                    else
                    {
                        lotManager.DeleteDevice(productKey, deviceName, out msg);
                        response.SetContent(HttpStatus.error, "设置端服务失败", "ERROR_设置端服务失败", ResponseType.text);
                        return(response);
                    }
                }
                else
                {
                    response.SetContent(HttpStatus.error, "设置失败", "ERROR_" + msg + "", ResponseType.text);
                    return(response);
                }
            }
            catch (Exception ex)
            {
                msg = "ERROR_" + ex.Message + "";
                AddErrorLog(LogEnum.sys, ex.Message, ex.StackTrace);
                response.SetContent(HttpStatus.error, ex.Message, msg, ResponseType.text);
            }

            return(response);
        }