Ejemplo n.º 1
0
        /// <summary>
        /// 更新DTU远程配置
        /// </summary>
        /// <param name="dtuEntity"></param>
        /// <param name="jObj"></param>
        /// <param name="dtuConfig"></param>
        public static void UpdateDtuConfig(T_DIM_REMOTE_DTU dtuEntity, JObject jObj, DtuConfig dtuConfig)
        {
            // JToken tokenDtuId = jObj["dtuId"];
            var cmds = from cmd in jObj["cmds"].Children()
                       select new { cmd = (string)cmd["cmd"], result = (string)cmd["result"] };

            foreach (var cmd in cmds)
            {
                switch (cmd.cmd)
                {
                case "setCount":
                    if (cmd.result != "OK")
                    {
                        return;
                    }
                    break;

                case "setIP1":
                    if (cmd.result == "OK" && dtuConfig.Ip != default(string) && dtuConfig.Ip != dtuEntity.DTU_IP)
                    {
                        dtuEntity.DTU_IP = dtuConfig.Ip;
                    }
                    break;

                case "setPort1":
                    if (cmd.result == "OK" && dtuConfig.Port != default(int?) && dtuConfig.Port != dtuEntity.DTU_PORT)
                    {
                        dtuEntity.DTU_PORT = dtuConfig.Port;
                    }
                    break;

                case "setIP2":
                    if (cmd.result == "OK" && dtuConfig.Ip2 != default(string) && dtuConfig.Ip2 != dtuEntity.DtuIp2)
                    {
                        dtuEntity.DtuIp2 = dtuConfig.Ip2;
                    }
                    break;

                case "setPort2":
                    if (cmd.result == "OK" && dtuConfig.Port2 != default(int?) && dtuConfig.Port2 != dtuEntity.DtuPort2)
                    {
                        dtuEntity.DtuPort2 = dtuConfig.Port2;
                    }
                    break;

                case "setMode":
                    if (cmd.result == "OK" && dtuConfig.DtuMode != default(string) && dtuConfig.DtuMode.ToUpper() != dtuEntity.DtuMode)
                    {
                        dtuEntity.DtuMode = dtuConfig.DtuMode.ToUpper();
                    }
                    break;

                case "setByteInterval":
                    if (cmd.result == "OK" && dtuConfig.PacketInterval != default(int?) && dtuConfig.PacketInterval != dtuEntity.PacketInterval)
                    {
                        dtuEntity.PacketInterval = dtuConfig.PacketInterval;
                    }
                    break;

                case "setRetry":
                    if (cmd.result == "OK" && dtuConfig.ReconnectionCount != default(int?) && dtuConfig.ReconnectionCount != dtuEntity.ReconnectionCount)
                    {
                        dtuEntity.ReconnectionCount = dtuConfig.ReconnectionCount;
                    }
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Add([FromBody] DtuModel dtu)
        {
            using (var entity = new SecureCloud_Entities())
            {
                // 新增dtu
                var dtuEntity = new T_DIM_REMOTE_DTU();
                dtuEntity.REMOTE_DTU_NUMBER      = dtu.DtuNo;
                dtuEntity.REMOTE_DTU_SUBSCRIBER  = dtu.Sim;
                dtuEntity.REMOTE_DTU_GRANULARITY = (short)dtu.Granularity;
                dtuEntity.DTU_IP           = dtu.Ip;
                dtuEntity.DTU_PORT         = dtu.Port;
                dtuEntity.P1               = dtu.P1;
                dtuEntity.P2               = dtu.P2;
                dtuEntity.P3               = dtu.P3;
                dtuEntity.P4               = dtu.P4;
                dtuEntity.ProductDtuId     = dtu.ProductId;
                dtuEntity.REMOTE_DTU_STATE = true;

                var entry = entity.Entry(dtuEntity);
                entry.State = System.Data.EntityState.Added;

                // 添加关联关系
                var sdEntity = new T_DIM_STRUCT_DTU();
                sdEntity.DtuId       = dtuEntity.ID;
                sdEntity.StructureId = dtu.StructId;

                var entry2 = entity.Entry(sdEntity);
                entry2.State = System.Data.EntityState.Added;

                #region 日志信息

                var stc        = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == dtu.StructId);
                var product    = entity.T_DIM_DTU_PRODUCT.FirstOrDefault(p => p.ProductId == dtu.ProductId);
                var paramName1 = (product != null && product.NetworkType.ToLower().Contains("local")) ? "文件路径" : "参数1";
                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(dtu);
                this.Request.Properties["ActionParameterShow"] =
                    string.Format(
                        "dtu号:{0},结构物:{1},采集粒度:{3},产品厂商:{6},产品型号:{7},sim卡号:{2},ip地址:{4},端口:{5},[{12}:{8},参数2:{9},参数3:{10},参数4:{11}]",
                        dtu.DtuNo ?? string.Empty,
                        stc == null ? string.Empty : stc.STRUCTURE_NAME_CN,
                        dtu.Sim ?? string.Empty,
                        dtu.Granularity,
                        dtu.Ip,
                        dtu.Port,
                        product != null ? product.DtuFactory : string.Empty,
                        product != null ? product.DtuModel : string.Empty,
                        dtu.P1,
                        dtu.P2,
                        dtu.P3,
                        dtu.P4,
                        paramName1);
                #endregion

                try
                {
                    entity.SaveChanges();
                    var dtnod = new DtuNode
                    {
                        DtuId       = (uint)dtuEntity.ID,
                        Type        = DtuType.Gprs,
                        DtuCode     = dtuEntity.REMOTE_DTU_NUMBER,
                        Name        = dtuEntity.DESCRIPTION,
                        DacInterval = dtuEntity.REMOTE_DTU_GRANULARITY == null ? DtuNode.DefaultDacInterval : (uint)(dtuEntity.REMOTE_DTU_GRANULARITY * 60),
                        NetworkType = dtuEntity.ProductDtuId == 2 ? NetworkType.hclocal : NetworkType.gprs
                    };
                    if (dtnod.NetworkType == NetworkType.hclocal)
                    {
                        dtnod.AddProperty("param1", dtuEntity.P1);
                    }
                    WebClientService.SendToET(ConfigChangedMsgHelper.GetDtuConfigChangedMsg(ChangedStatus.Add, dtnod));
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("添加DTU成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("添加DTU失败")));
                }
            }
        }