Exemplo n.º 1
0
        public HttpResponseMessage Modify([FromUri] int dtuId, [FromBody] DtuModel dtu)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var dtuEntity = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId);
                if (dtuEntity == null || dtuEntity.REMOTE_DTU_STATE == false)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("DTU不存在或已禁用")));
                }

                StringBuilder sb      = new StringBuilder();
                string        dtucode = dtuEntity.REMOTE_DTU_NUMBER;
                if (dtu.DtuNo != default(string) && dtu.DtuNo != dtuEntity.REMOTE_DTU_NUMBER)
                {
                    dtuEntity.REMOTE_DTU_NUMBER = dtu.DtuNo;
                    sb.AppendFormat("Dtu编号改为:{0},", dtu.DtuNo);
                }
                if (dtu.Granularity != default(int) && dtu.Granularity != dtuEntity.REMOTE_DTU_GRANULARITY)
                {
                    dtuEntity.REMOTE_DTU_GRANULARITY = (short)dtu.Granularity;
                    sb.AppendFormat("采集间隔改为:{0},", dtu.Granularity);
                }
                if (dtu.Sim != dtuEntity.REMOTE_DTU_SUBSCRIBER)
                {
                    dtuEntity.REMOTE_DTU_SUBSCRIBER = dtu.Sim;
                    sb.AppendFormat("sim卡号改为:{0},", dtu.Sim);
                }
                if (dtu.Ip != dtuEntity.DTU_IP)
                {
                    dtuEntity.DTU_IP = dtu.Ip;
                    sb.AppendFormat("Ip改为:{0},", dtu.Ip);
                }
                if (dtu.Port != dtuEntity.DTU_PORT)
                {
                    dtuEntity.DTU_PORT = dtu.Port;
                    sb.AppendFormat("端口改为:{0},", dtu.Port);
                }
                if (dtu.ProductId != default(int) && dtu.ProductId != dtuEntity.ProductDtuId)
                {
                    dtuEntity.ProductDtuId = dtu.ProductId;
                    var product = entity.T_DIM_DTU_PRODUCT.FirstOrDefault(p => p.ProductId == dtu.ProductId);
                    if (product != null)
                    {
                        sb.AppendFormat("产品厂商改为{0},型号改为:{1}", product.DtuFactory, product.DtuModel);
                    }
                    else
                    {
                        sb.AppendFormat("产品id改为{0}", dtu.ProductId);
                    }
                }
                if (dtu.P1 != dtuEntity.P1)
                {
                    dtuEntity.P1 = dtu.P1;
                    sb.AppendFormat("参数1改为:{0}", dtu.P1);
                }
                if (dtu.P2 != dtuEntity.P2)
                {
                    dtuEntity.P2 = dtu.P2;
                    sb.AppendFormat("参数2改为:{0}", dtu.P1);
                }
                if (dtu.P3 != dtuEntity.P3)
                {
                    dtuEntity.P3 = dtu.P3;
                    sb.AppendFormat("参数3改为:{0}", dtu.P1);
                }
                if (dtu.P4 != dtuEntity.P4)
                {
                    dtuEntity.P4 = dtu.P4;
                    sb.AppendFormat("参数4改为:{0}", dtu.P1);
                }

                #region 日志信息

                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(dtu);
                this.Request.Properties["ActionParameterShow"] = string.Format("dtu号:{0}:{1}", dtu.DtuNo ?? string.Empty, sb);
                #endregion

                try
                {
                    entity.SaveChanges();
                    var dtnod = new DtuNode
                    {
                        DtuId       = (uint)dtuEntity.ID,
                        Type        = DtuType.Gprs,
                        DtuCode     = dtuEntity.REMOTE_DTU_NUMBER,
                        NetworkType = dtuEntity.ProductDtuId == 2 ? NetworkType.hclocal : NetworkType.gprs,
                        Name        = dtuEntity.DESCRIPTION,
                        DacInterval = dtuEntity.REMOTE_DTU_GRANULARITY == null ? DtuNode.DefaultDacInterval : (uint)dtuEntity.REMOTE_DTU_GRANULARITY
                    };
                    if (dtnod.NetworkType == NetworkType.hclocal)
                    {
                        dtnod.AddProperty("param1", dtuEntity.P1);
                    }
                    WebClientService.SendToET(ConfigChangedMsgHelper.GetDtuConfigChangedMsg(ChangedStatus.Modify, dtnod, dtucode));
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("DTU信息修改成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("DTU信息修改失败")));
                }
            }
        }
Exemplo 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失败")));
                }
            }
        }