Ejemplo n.º 1
0
        public HttpResponseMessage UpdateStructureAggConfig([FromUri] int configId, [FromBody] AggConfigData model)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var config =
                        (from aggconfig in db.T_DIM_AGG_CONFIG where aggconfig.Id == configId select aggconfig).First();
                    if (config == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置不存在")));
                    }
                    if (!IsConfigChanged(config, model))
                    {
                        config.IsEnable = false;
                        config.IsDelete = true;
                        var newConfig = new T_DIM_AGG_CONFIG();
                        ToT_DIM_AGG_CONFIG(model, ref newConfig);
                        db.Entry(config).State    = System.Data.EntityState.Modified;
                        db.Entry(newConfig).State = System.Data.EntityState.Added;
                        db.SaveChanges();
                        SendAggConfigChangedMsg();
                    }

                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("聚集配置修改成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置修改失败")));
                }
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage RemoveOrg(int orgId)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var org = entity.T_DIM_ORGANIZATION.FirstOrDefault(o => o.ID == orgId && o.IsDeleted != true);
                if (org == null)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("组织不存在或已被删除")));
                }

                org.IsDeleted = true;

                var entry = entity.Entry(org);
                entry.State = System.Data.EntityState.Modified;

                /****start*remove 自动删除用户关注组织关系,与该组织相关绑定也一并 删除*****/
                var entryUserOrgs = from uo in entity.T_DIM_USER_ORG where uo.ORGANIZATION_ID == orgId select uo;
                foreach (var userOrg in entryUserOrgs)
                {
                    var entryUserOrg = entity.Entry(userOrg);
                    entryUserOrg.State = System.Data.EntityState.Deleted;
                }

                //用户与该组织下结构物的绑定,一并删除
                var userOrgStructs = from us in entity.T_DIM_USER_STRUCTURE
                                     from os in entity.T_DIM_ORG_STUCTURE
                                     where os.ORGANIZATION_ID == orgId && us.STRUCTURE_ID == os.STRUCTURE_ID
                                     select us;
                foreach (var userOrgstr in userOrgStructs)
                {
                    var entryUserOrgStr = entity.Entry(userOrgstr);
                    entryUserOrgStr.State = System.Data.EntityState.Deleted;
                }
                /****end******/

                #region 日志信息

                this.Request.Properties["ActionParameterShow"] = "组织名称:" + org.ABB_NAME_CN;
                #endregion

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("删除组织成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("删除组织失败")));
                }
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage AddGroupsJinRunXian([FromBody] SensorGroupJinRunXian model)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var group = new T_DIM_GROUP();
                    group.GROUP_NAME    = model.GroupName;
                    group.GROUP_TYPE_ID = 3;

                    var entry = db.Entry(group);
                    entry.State = System.Data.EntityState.Added;

                    var           sensorIds = model.SensorList.Select(s => s.SensorId);
                    var           sensors   = db.T_DIM_SENSOR.Where(s => sensorIds.Contains(s.SENSOR_ID)).ToList();
                    StringBuilder sb        = new StringBuilder();

                    foreach (var sensor in model.SensorList)
                    {
                        sb.AppendFormat(
                            "位置-{0}_高度-{1};",
                            sensors.Where(s => s.SENSOR_ID == sensor.SensorId)
                            .Select(s => s.SENSOR_LOCATION_DESCRIPTION)
                            .FirstOrDefault(),
                            sensor.Height);

                        var sensorGroupJinRunXian = new T_DIM_SENSOR_GROUP_JINRUNXIAN();
                        sensorGroupJinRunXian.GROUP_ID  = group.GROUP_ID;
                        sensorGroupJinRunXian.SENSOR_ID = sensor.SensorId;
                        sensorGroupJinRunXian.HEIGHT    = sensor.Height;

                        var test = db.Entry(sensorGroupJinRunXian);
                        test.State = System.Data.EntityState.Added;
                    }

                    #region 日志

                    this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                    this.Request.Properties["ActionParameterShow"] = string.Format("组:{0},传感器:{1}", model.GroupName, sb);
                    #endregion

                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("测斜传感器组新增成功")));
                }
                catch (NullReferenceException e)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("测斜传感器组新增失败:参数无效")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("测斜传感器组新增失败")));
                }
            }
        }
Ejemplo n.º 4
0
        public HttpResponseMessage RemoveReportConfigInfo([FromUri] int id)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var config = db.T_REPORT_CONFIG.FirstOrDefault(u => u.Id == id);

                    if (config == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置不存在或已被删除")));
                    }

                    var entry = db.Entry(config);
                    entry.State = System.Data.EntityState.Deleted;


                    IQueryable <T_REPORT_CONFIG_TEMPLATE> congigTemp = from q in db.T_REPORT_CONFIG_TEMPLATE
                                                                       where q.ReportConfigId == id
                                                                       select q;
                    foreach (var item in congigTemp)
                    {
                        var entry2 = db.Entry(item);
                        entry2.State = System.Data.EntityState.Deleted;
                    }


                    #region 日志信息
                    this.Request.Properties["ActionParameter"]     = "Id:" + id;
                    this.Request.Properties["ActionParameterShow"] =
                        string.Format("组织编号:{0}, 结构物编号: {1}, 报表名称:{2}",
                                      config.OrgId,
                                      config.StructId,
                                      config.ReportName
                                      );
                    #endregion

                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("报表配置删除成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置删除失败")));
                }
            }
        }
Ejemplo n.º 5
0
        // [LogInfo("修改进度信息", true)]

        public HttpResponseMessage ModifyProgress([FromUri] int progressId, [FromBody] ProgressConfig config)
        {
            using (var db = new SecureCloud_Entities())
            {
                var paraShow = new StringBuilder(100);
                try
                {
                    var configEntity = db.T_DIM_STRUCTUER_PROGRESS.FirstOrDefault(u => u.Id == progressId);
                    if (configEntity == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路进度配置不存在")));
                    }
                    if (config.LineId != default(int) && config.LineId != configEntity.Line_Id)
                    {
                        configEntity.Line_Id = config.LineId;
                        paraShow.AppendFormat("线路编号改为:{0},", config.LineId);
                    }
                    if (config.ConstructLength != default(decimal) && config.ConstructLength != configEntity.Construct_Length)
                    {
                        configEntity.Construct_Length = config.ConstructLength;
                        paraShow.AppendFormat("施工长度改为:{0},", config.ConstructLength);
                    }

                    if (config.Unit != default(string) && config.Unit != configEntity.Unit)
                    {
                        configEntity.Unit = config.Unit;
                        paraShow.AppendFormat("长度单位改为:{0},", config.Unit);
                    }

                    //if (config.Color != default(string) && config.Color != configEntity.Color)
                    //{
                    //    configEntity.Color = config.Color;
                    //    paraShow.AppendFormat("颜色改为:{0},", config.Color);
                    //}

                    if (config.dataTime != default(DateTime) && config.dataTime != configEntity.Up_Datatime)
                    {
                        configEntity.Up_Datatime = config.dataTime;
                        paraShow.AppendFormat("修改时间改为:{0},", config.dataTime);
                    }
                    var entry = db.Entry(configEntity);
                    entry.State = System.Data.EntityState.Modified;

                    //#region 日志信息
                    //this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config);
                    //this.Request.Properties["ActionParameterShow"] = paraShow.ToString();

                    //#endregion

                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路配置信息修改成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置信息修改失败")));
                }
            }
        }
Ejemplo n.º 6
0
        public HttpResponseMessage RemoveSection([FromUri] int sectionId)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == sectionId);
                if (section == null)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("施工截面不存在,删除施工截面失败")));
                }

                // 删除传感器热点
                var hotspots = entity.T_DIM_HOTSPOT.Where(w => w.SECTION_ID == sectionId);
                foreach (var hotspot in hotspots)
                {
                    var entry1 = entity.Entry(hotspot);
                    entry1.State = EntityState.Deleted;
                }
                // 删除施工截面热点
                var sectionHotspot = entity.T_DIM_HOTSPOT_SECTION.Where(w => w.SectionId == sectionId);
                foreach (var shs in sectionHotspot)
                {
                    var entry2 = entity.Entry(shs);
                    entry2.State = EntityState.Deleted;
                }
                // 删除施工截面
                var entry = entity.Entry(section);
                entry.State = EntityState.Deleted;

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("删除施工截面成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("删除施工截面失败")));
                }
            }
        }
Ejemplo n.º 7
0
        public HttpResponseMessage RemoveSectionHotspotConfig(string hotspots)
        {
            int[] arrHotspotId = hotspots.Split(',').Select(s => Convert.ToInt32(s)).ToArray();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("共{0}条: ", arrHotspotId.Length);

            using (var entity = new SecureCloud_Entities())
            {
                foreach (var hotspotId in arrHotspotId)
                {
                    var hotspot = entity.T_DIM_HOTSPOT_SECTION.FirstOrDefault(s => s.SpotId == hotspotId);
                    if (hotspot == null)
                    {
                        return(Request.CreateResponse(
                                   System.Net.HttpStatusCode.BadRequest,
                                   StringHelper.GetMessageString("施工截面热点配置不存在,删除施工截面热点配置失败")));
                    }

                    #region 日志信息
                    sb.AppendFormat(" 截面:{0};", hotspot.T_DIM_SECTION.SectionName);
                    #endregion

                    DbEntityEntry <T_DIM_HOTSPOT_SECTION> entry = entity.Entry(hotspot);
                    entry.State = EntityState.Deleted;
                }

                #region 日志信息
                this.Request.Properties["ActionParameterShow"] = sb.ToString();
                #endregion

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("删除施工截面热点配置成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("删除施工截面热点配置失败")));
                }
            }
        }
Ejemplo n.º 8
0
        public object AddSection([FromUri] int structId, [FromBody] Section model)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var structure = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == structId);
                if (structure == null)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("结构物不存在,新增截面失败")));
                }
                if (entity.T_DIM_SECTION.Where(w => w.StructId == structId).Any(s => s.SectionName == model.SectionName))
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("该结构物已存在此截面名称,新增截面失败")));
                }

                var section = new T_DIM_SECTION
                {
                    SectionName   = model.SectionName,
                    SectionStatus = model.SectionStatus,
                    HeapMapName   = model.HeapMapName,
                    StructId      = structId
                };

                var entry = entity.Entry(section);
                entry.State = EntityState.Added;

                try
                {
                    entity.SaveChanges();
                    return
                        (new JObject(new JProperty("sectionId", section.SectionId))); // 200: "OK" (新增施工截面成功)
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("新增施工截面失败")));
                }
            }
        }
Ejemplo n.º 9
0
        public HttpResponseMessage ModifySection([FromUri] int sectionId, [FromBody] Section model)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == sectionId);
                if (section == null)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("结构物不存在,修改施工截面信息失败")));
                }
                if (model.SectionName != default(string))
                {
                    section.SectionName = model.SectionName;
                }
                if (model.SectionStatus != default(int?))
                {
                    section.SectionStatus = model.SectionStatus;
                }
                if (model.HeapMapName != default(string))
                {
                    section.HeapMapName = model.HeapMapName;
                }

                var entry = entity.Entry(section);
                entry.State = EntityState.Modified;

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("修改施工截面信息成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("修改施工截面信息失败")));
                }
            }
        }
Ejemplo n.º 10
0
        public HttpResponseMessage AddMap(int dtuId, int structId)
        {
            using (var entity = new SecureCloud_Entities())
            {
                if (entity.T_DIM_STRUCT_DTU.Any(d => d.DtuId == dtuId && d.StructureId == structId))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加DTU失败")));
                }

                // 添加关联关系
                var sdEntity = new T_DIM_STRUCT_DTU();
                sdEntity.DtuId       = dtuId;
                sdEntity.StructureId = structId;

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

                #region 日志信息

                var stc = entity.T_DIM_STRUCTURE.FirstOrDefault(s => s.ID == structId);
                var dtu = entity.T_DIM_REMOTE_DTU.FirstOrDefault(d => d.ID == dtuId);
                this.Request.Properties["ActionParameterShow"] = string.Format(
                    "dtu号:{0},结构物:{1}",
                    dtu == null ? string.Empty : dtu.REMOTE_DTU_NUMBER,
                    stc == null ? string.Empty : stc.STRUCTURE_NAME_CN);
                #endregion

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("添加DTU成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("添加DTU失败")));
                }
            }
        }
Ejemplo n.º 11
0
        public HttpResponseMessage AddStructureAggConfig([FromBody] AggConfigData model)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var newConfig = new T_DIM_AGG_CONFIG();
                    ToT_DIM_AGG_CONFIG(model, ref newConfig);

                    db.Entry(newConfig).State = System.Data.EntityState.Added;
                    db.SaveChanges();
                    SendAggConfigChangedMsg();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("聚集配置修改成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("聚集配置修改失败")));
                }
            }
        }
Ejemplo n.º 12
0
        public HttpResponseMessage Add([FromBody] SmsUser smsUser)
        {
            using (var db = new SecureCloud_Entities())
            {
                var receiver = new T_WARNING_SMS_RECIEVER
                {
                    RecieverName  = smsUser.ReceiverName,
                    RecieverPhone = smsUser.ReceiverPhone,
                    RecieverMail  = smsUser.ReceiverMail,
                    RoleId        = smsUser.RoleId,
                    FilterLevel   = smsUser.FilterLevel,
                    UserNo        = smsUser.UserId,
                    ReceiveMode   = smsUser.ReceiveMode,
                };
                var entry = db.Entry(receiver);
                entry.State = System.Data.EntityState.Added;

                #region 日志信息

                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(smsUser);
                this.Request.Properties["ActionParameterShow"] =
                    string.Format(
                        "接收人:{0},电话:{1},邮箱:{2},接收人角色:{3},接收等级:{4},接收模式:{5}",
                        smsUser.ReceiverName,
                        smsUser.ReceiverPhone,
                        smsUser.ReceiverMail,
                        smsUser.RoleId == 0 ? "用户" : "技术支持",
                        smsUser.FilterLevel,
                        smsUser.ReceiveMode ? "短信" : "邮箱");
                #endregion
                try
                {
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("添加成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加失败")));
                }
            }
        }
Ejemplo n.º 13
0
        public HttpResponseMessage Remove(int receiverId)
        {
            using (var db = new SecureCloud_Entities())
            {
                var smsUser = db.T_WARNING_SMS_RECIEVER.FirstOrDefault(r => r.ReceiverId == receiverId);

                #region 日志信息

                string sb = string.Empty;
                if (smsUser != null)
                {
                    sb = string.Format(
                        "接收人:{0},电话:{1},邮箱:{2},接收人角色:{3},接收等级:{4},接收模式:{5}",
                        smsUser.RecieverName,
                        smsUser.RecieverPhone,
                        smsUser.RecieverMail,
                        smsUser.RoleId == 0 ? "用户" : "技术支持",
                        smsUser.FilterLevel,
                        smsUser.ReceiveMode == null ? string.Empty : ((bool)smsUser.ReceiveMode ? "短信" : "邮箱"));
                }

                this.Request.Properties["ActionParameterShow"] = sb;

                #endregion

                var entry = db.Entry(smsUser);
                entry.State = System.Data.EntityState.Deleted;
                try
                {
                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("添加成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("添加失败")));
                }
            }
        }
Ejemplo n.º 14
0
        public HttpResponseMessage AddSectionHotSpotConfig([FromBody] SectionHotSpotConfig config)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var section = entity.T_DIM_SECTION.FirstOrDefault(s => s.SectionId == config.SectionId);
                if (section == null)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("施工截面不存在,新增截面热点失败")));
                }

                var hotspot = new T_DIM_HOTSPOT_SECTION
                {
                    SectionId   = config.SectionId,
                    Spot_X_Axis = config.SectionSpotX, // xAxis
                    Spot_Y_Axis = config.SectionSpotY, // yAxis
                    SpotPath    = config.SectionSpotPath
                };

                var entry = entity.Entry(hotspot);
                entry.State = EntityState.Added;

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.Accepted,
                               new JObject(new JProperty("hotspotId", hotspot.SpotId)).ToString()));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("新增施工截面热点失败")));
                }
            }
        }
Ejemplo n.º 15
0
        public HttpResponseMessage RegisterFilterInfo([FromBody] ConfigInfo config)
        {
            using (var db = new SecureCloud_Entities())
            {
                var sensors = db.T_DIM_SENSOR.FirstOrDefault(m => m.SENSOR_ID == config.SensorId);
                if (sensors == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                  StringHelper.GetMessageString("添加配置信息失败,传感器不存在")));
                }
                if (config.RvEnabled == true)
                {
                    if (config.RvLower == null || config.RvUpper == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                      StringHelper.GetMessageString("添加配置信息失败,上下限不能为空")));
                    }
                }
                if (config.SvEnabled == true)
                {
                    if (config.SvDt == null || config.SvKt == null || config.SvRt == null || config.SvWindowSize == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest,
                                                      StringHelper.GetMessageString("添加配置信息失败,Stable其它参数不能为空")));
                    }
                }
                var structId = Config.GetStructId(config.SensorId);
                try
                {
                    var rational =
                        db.T_DATA_RATIONAL_FILTER_CONFIG.Where(m => m.SensorId == config.SensorId)
                        .FirstOrDefault(m => m.ItemId == config.ItemId);
                    if (rational != null)
                    {
                        rational.Enabled       = config.RvEnabled;
                        rational.RationalLower = (config.RvLower ?? null);
                        rational.RationalUpper = (config.RvUpper ?? null);
                        var entryup = db.Entry(rational);
                        entryup.State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        //新增rational过滤
                        var rFilterConfig = new T_DATA_RATIONAL_FILTER_CONFIG();
                        rFilterConfig.SensorId      = config.SensorId;
                        rFilterConfig.ItemId        = config.ItemId;
                        rFilterConfig.Enabled       = config.RvEnabled;
                        rFilterConfig.RationalLower = (config.RvLower ?? null);
                        rFilterConfig.RationalUpper = (config.RvUpper ?? null);
                        var entry = db.Entry(rFilterConfig);
                        entry.State = EntityState.Added;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("配置失败")));
                }
                try
                {
                    var rational =
                        db.T_DATA_STABLE_FILTER_CONFIG.Where(m => m.SensorId == config.SensorId)
                        .FirstOrDefault(m => m.ItemId == config.ItemId);
                    if (rational != null)
                    {
                        rational.Enabled    = config.SvEnabled;
                        rational.KT         = (config.SvKt ?? null);
                        rational.DT         = (config.SvDt ?? null);
                        rational.RT         = (config.SvRt ?? null);
                        rational.WindowSize = (config.SvWindowSize ?? null);
                        var entryup = db.Entry(rational);
                        entryup.State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        //新增stable过滤
                        var sFilterConfig = new T_DATA_STABLE_FILTER_CONFIG();
                        sFilterConfig.SensorId   = config.SensorId;
                        sFilterConfig.ItemId     = config.ItemId;
                        sFilterConfig.Enabled    = config.SvEnabled;
                        sFilterConfig.WindowSize = (config.SvWindowSize ?? null);
                        sFilterConfig.DT         = (config.SvDt ?? null);
                        sFilterConfig.KT         = (config.SvKt ?? null);
                        sFilterConfig.RT         = (config.SvRt ?? null);
                        var entry1 = db.Entry(sFilterConfig);
                        entry1.State = EntityState.Added;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("配置失败")));
                }

                #region 日志信息
                this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(config);
                var sensorName = string.Empty;
                var sensor     = db.T_DIM_SENSOR.FirstOrDefault(s => s.SENSOR_ID == config.SensorId);
                var item       = string.Empty;
                if (sensor != null)
                {
                    sensorName = sensor.SENSOR_LOCATION_DESCRIPTION;
                    if (sensor.SAFETY_FACTOR_TYPE_ID != null)
                    {
                        var factor =
                            Config.GetConfigByFactors(new[] { (int)sensor.SAFETY_FACTOR_TYPE_ID }, structId).FirstOrDefault();
                        if (factor != null && config.ItemId >= 0 && config.ItemId < factor.Display.Length)
                        {
                            item = factor.Display[config.ItemId];
                        }
                    }
                }
                this.Request.Properties["ActionParameterShow"] = string.Format(
                    "传感器:{0},监测项:{1},启用合理范围:{2},合理范围下限:{3},合理范围上限:{4};启用滑窗:{5},窗口大小:{6},DT:{7},KT:{8},RT:{9}",
                    sensorName,
                    item,
                    config.RvEnabled,
                    config.RvLower,
                    config.RvUpper,
                    config.SvEnabled,
                    config.SvWindowSize,
                    config.SvDt,
                    config.SvKt,
                    config.SvRt);
                #endregion
                return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("配置成功")));
            }
        }
Ejemplo n.º 16
0
        public HttpResponseMessage ModifySensor([FromUri] int sensorId, [FromBody] Sensor model)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var sensor = db.T_DIM_SENSOR.FirstOrDefault(s => s.SENSOR_ID == sensorId && !s.IsDeleted);
                    if (sensor == null)
                    {
                        return(Request.CreateResponse(
                                   HttpStatusCode.BadRequest,
                                   StringHelper.GetMessageString("传感器修改失败:传感器不存在或已删除")));
                    }
                    int           dtuid     = sensor.DTU_ID.Value;
                    StringBuilder sb        = new StringBuilder();
                    var           sensorLoc = sensor.SENSOR_LOCATION_DESCRIPTION;
                    sb.AppendFormat("原传感器:{0}:", sensorLoc);

                    if (model.FactorId != default(int) && model.FactorId != sensor.SAFETY_FACTOR_TYPE_ID)
                    {
                        sensor.SAFETY_FACTOR_TYPE_ID = model.FactorId;
                        var fac =
                            db.T_DIM_SAFETY_FACTOR_TYPE.Where(f => f.SAFETY_FACTOR_TYPE_ID == model.FactorId)
                            .Select(f => f.SAFETY_FACTOR_TYPE_NAME)
                            .FirstOrDefault();
                        sb.AppendFormat("监测因素改为:{0};", fac);
                    }
                    if (model.DtuId != default(int) && model.DtuId != sensor.DTU_ID)
                    {
                        sensor.DTU_ID = model.DtuId;
                        var dtu =
                            db.T_DIM_REMOTE_DTU.Where(d => d.ID == model.DtuId)
                            .Select(d => d.REMOTE_DTU_NUMBER)
                            .FirstOrDefault();
                        sb.AppendFormat("dtu号改为:{0};", dtu);
                    }
                    if (model.ModuleNo != default(int) && model.ModuleNo != sensor.MODULE_NO)
                    {
                        sensor.MODULE_NO = model.ModuleNo;
                        sb.AppendFormat("模块号改为:{0};", model.ModuleNo);
                    }
                    if (model.Channel != null && model.Channel != sensor.DAI_CHANNEL_NUMBER)
                    {
                        sensor.DAI_CHANNEL_NUMBER = (byte?)model.Channel;
                        sb.AppendFormat("通道改为:{0};", model.Channel);
                    }
                    //2-26
                    if (model.Enable != sensor.Enable)
                    {
                        sensor.Enable = model.Enable;
                        sb.AppendFormat("使能改为:{0};", model.Enable);
                    }
                    if (model.ProductId != default(int) && model.ProductId != sensor.PRODUCT_SENSOR_ID)
                    {
                        sensor.PRODUCT_SENSOR_ID = model.ProductId;
                        var pdt =
                            db.T_DIM_SENSOR_PRODUCT.Where(p => p.PRODUCT_ID == model.ProductId)
                            .Select(p => new { p.PRODUCT_NAME, p.PRODUCT_CODE })
                            .FirstOrDefault();
                        sb.AppendFormat("设备改为{0}({1});", pdt.PRODUCT_NAME, pdt.PRODUCT_CODE);
                    }
                    if (model.Location != default(string) && model.Location != sensor.SENSOR_LOCATION_DESCRIPTION)
                    {
                        sensor.SENSOR_LOCATION_DESCRIPTION = model.Location;
                        sb.AppendFormat("位置标识改为{0};", model.Location);
                    }
                    if (model.Params != null)
                    {
                        var query = (from p in db.T_DIM_SENSOR_PRODUCT
                                     join fn in db.T_DIM_FORMULA_PARA on p.FORMAULAID equals fn.FormulaID into forluma
                                     from f in forluma.DefaultIfEmpty()
                                     join fname in db.T_DIM_FORMULA_PARA_NAME on f.ParaNameID equals fname.ParaNameID
                                     into name
                                     from n in name
                                     where p.PRODUCT_ID == model.ProductId
                                     orderby f.Order
                                     select new { f.FormulaParaID, n.ParaAlias }).ToList();

                        var para =
                            (from q in query
                             from v in model.Params
                             where q.FormulaParaID == v.Id
                             select new { q.FormulaParaID, v.Value }).ToList();

                        var paramStr = (from q in query
                                        from v in model.Params
                                        where q.FormulaParaID == v.Id
                                        select new { q.ParaAlias, v.Value }).ToList();

                        sb.AppendFormat(
                            "参数修改为:{0}",
                            string.Join(
                                "-",
                                paramStr.Select(p => string.Format("{0}:{1}", p.ParaAlias, p.Value)).ToArray()));

                        var old = from o in db.T_DIM_FORMULAID_SET where o.SENSOR_ID == sensor.SENSOR_ID select o;
                        foreach (var o in old)
                        {
                            db.Entry(o).State = System.Data.EntityState.Deleted;
                        }

                        var newParam = new T_DIM_FORMULAID_SET();
                        newParam.SENSOR_ID = sensor.SENSOR_ID;
                        for (int i = 0; i < para.Count(); i++)
                        {
                            newParam.GetType()
                            .GetProperty("FormulaParaID" + (i + 1))
                            .SetValue(newParam, para[i].FormulaParaID, null);
                            newParam.GetType()
                            .GetProperty("Parameter" + (i + 1))
                            .SetValue(newParam, (decimal?)para[i].Value, null);
                        }

                        db.Entry(newParam).State = System.Data.EntityState.Added;
                    }

                    //关联传感器
                    if (model.CorrentId != null)
                    {
                        var correntTable = from cp in db.T_DIM_SENSOR_CORRENT where cp.SensorId == sensorId select cp;

                        foreach (var o in correntTable)
                        {
                            db.T_DIM_SENSOR_CORRENT.Remove(o);
                        }
                        var array = model.CorrentId.Split(',');
                        for (int j = 0; j < array.Length; j++)
                        {
                            var correntSensor = new T_DIM_SENSOR_CORRENT();

                            correntSensor.SensorId = sensorId;
                            var correntId = array.GetValue(j);
                            correntSensor.CorrentSensorId = Convert.ToInt32(correntId);
                            db.T_DIM_SENSOR_CORRENT.Add(correntSensor);
                            db.SaveChanges();
                        }
                    }

                    #region 日志信息
                    this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                    this.Request.Properties["ActionParameterShow"] = sb.ToString();

                    #endregion


                    db.SaveChanges();
                    if (sensor.Identification != 2)
                    {
                        Entity.Config.Sensor sensorinfo = GetSensor(sensor);
                        var senopera = new SensorOperation
                        {
                            Sensor      = sensorinfo,
                            OldDtuId    = (uint)dtuid,
                            OldSensorId = sensorinfo.SensorID,
                            Action      = sensor.DTU_ID == dtuid ? Operations.Update : Operations.ChangedDtu
                        };
                        WebClientService.SendToET(ConfigChangedMsgHelper.GetSensorConfigChangedMsg(senopera));
                    }
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("传感器修改成功")));
                }
                catch (NullReferenceException e)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("传感器修改失败:参数无效")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器修改失败")));
                }
            }
        }
Ejemplo n.º 17
0
        public HttpResponseMessage AddSensor([FromBody] Sensor model)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var sensor = new T_DIM_SENSOR();
                    sensor.STRUCT_ID             = model.StructId;
                    sensor.SAFETY_FACTOR_TYPE_ID = model.FactorId;
                    sensor.DTU_ID                      = model.DtuId;
                    sensor.MODULE_NO                   = model.ModuleNo;
                    sensor.DAI_CHANNEL_NUMBER          = (byte?)model.Channel;
                    sensor.PRODUCT_SENSOR_ID           = model.ProductId;
                    sensor.SENSOR_LOCATION_DESCRIPTION = model.Location;
                    sensor.IsDeleted                   = false;
                    sensor.Identification              = model.Identify;
                    sensor.Enable                      = model.Enable;

                    var entry = db.Entry(sensor);
                    entry.State = System.Data.EntityState.Added;

                    var query = (from p in db.T_DIM_SENSOR_PRODUCT
                                 join fn in db.T_DIM_FORMULA_PARA on p.FORMAULAID equals fn.FormulaID into forluma
                                 from f in forluma.DefaultIfEmpty()
                                 join fname in db.T_DIM_FORMULA_PARA_NAME on f.ParaNameID equals fname.ParaNameID into
                                 name
                                 from n in name
                                 where p.PRODUCT_ID == model.ProductId
                                 orderby f.Order
                                 select f.FormulaParaID).ToList();

                    var para = (from q in query
                                from v in model.Params
                                where q == v.Id
                                select new { q, v.Value }).ToList();

                    var old = from o in db.T_DIM_FORMULAID_SET where o.SENSOR_ID == sensor.SENSOR_ID select o;
                    foreach (var o in old)
                    {
                        db.Entry(o).State = System.Data.EntityState.Deleted;
                    }

                    var newParam = new T_DIM_FORMULAID_SET();
                    newParam.SENSOR_ID = sensor.SENSOR_ID;
                    for (int i = 0; i < para.Count(); i++)
                    {
                        newParam.GetType().GetProperty("FormulaParaID" + (i + 1)).SetValue(newParam, para[i].q, null);
                        newParam.GetType().GetProperty("Parameter" + (i + 1)).SetValue(newParam, (decimal?)para[i].Value, null);
                    }

                    db.Entry(newParam).State = System.Data.EntityState.Added;

                    if (model.CorrentId != null)
                    {
                        var correntSensor = new T_DIM_SENSOR_CORRENT();
                        var array         = model.CorrentId.Split(',');
                        for (int j = 0; j < array.Length; j++)
                        {
                            correntSensor.SensorId = sensor.SENSOR_ID;
                            var correntId = array.GetValue(j);
                            correntSensor.CorrentSensorId = Convert.ToInt32(correntId);
                            db.T_DIM_SENSOR_CORRENT.Add(correntSensor);
                            db.SaveChanges();
                        }
                    }


                    #region 日志信息

                    var fac =
                        db.T_DIM_SAFETY_FACTOR_TYPE.Where(f => f.SAFETY_FACTOR_TYPE_ID == model.FactorId)
                        .Select(f => f.SAFETY_FACTOR_TYPE_NAME)
                        .FirstOrDefault();

                    var dtu =
                        db.T_DIM_REMOTE_DTU.Where(d => d.ID == model.DtuId)
                        .Select(d => d.REMOTE_DTU_NUMBER)
                        .FirstOrDefault();

                    var pdt =
                        db.T_DIM_SENSOR_PRODUCT.Where(p => p.PRODUCT_ID == model.ProductId)
                        .Select(p => new { p.PRODUCT_NAME, p.PRODUCT_CODE })
                        .FirstOrDefault();

                    this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                    this.Request.Properties["ActionParameterShow"] =
                        string.Format(
                            "位置:{0},监测因素:{1},dtu:{2},模块号:{3},通道号:{4},设备类型:{5},参数:{6}",
                            string.IsNullOrEmpty(model.Location) ? string.Empty : model.Location,
                            fac ?? string.Empty,
                            dtu ?? string.Empty,
                            model.ModuleNo,
                            model.Channel,
                            pdt == null ? string.Empty : string.Format("{0}({1})", pdt.PRODUCT_NAME, pdt.PRODUCT_CODE),
                            model.Params == null ? string.Empty : string.Join(",", model.Params.Select(p => p.Value)));

                    #endregion

                    db.SaveChanges();
                    if (sensor.Identification != 2)
                    {
                        Entity.Config.Sensor sensorinfo = GetSensor(sensor);
                        var senopera = new SensorOperation
                        {
                            Action      = Operations.Add,
                            Sensor      = sensorinfo,
                            OldDtuId    = sensorinfo.DtuID,
                            OldSensorId = sensorinfo.SensorID
                        };
                        WebClientService.SendToET(ConfigChangedMsgHelper.GetSensorConfigChangedMsg(senopera));
                    }
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("传感器新增成功")));
                }
                catch (NullReferenceException e)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("传感器新增失败:参数无效")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("传感器新增失败")));
                }
            }
        }
Ejemplo n.º 18
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失败")));
                }
            }
        }
Ejemplo n.º 19
0
        public HttpResponseMessage ModifyInfo([FromBody] UserInfo info)
        {
            #region 日志信息
            this.Request.Properties["AuthorizationInfo"] = new AuthorizationInfo
            {
                UserId = info.UserId,
                Token  = string.Empty
            };
            this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(info);
            if (!string.IsNullOrEmpty(info.NewPwd))
            {
                this.Request.Properties["ActionParameterShow"] = string.Format(
                    "新密码:{0}",
                    StringHelper.Confuse(info.NewPwd));
            }
            else if (!string.IsNullOrEmpty(info.Email))
            {
                this.Request.Properties["ActionParameterShow"] = string.Format(
                    "新邮箱:{0}",
                    StringHelper.Confuse(info.Email));
            }
            #endregion

            using (SecureCloud_Entities entity = new SecureCloud_Entities())
            {
                T_DIM_USER user;
                if (info.UserId != default(int))
                {
                    user = entity.T_DIM_USER.FirstOrDefault(u => u.USER_NO == info.UserId);
                }
                else
                {
                    user = entity.T_DIM_USER.FirstOrDefault(u => u.USER_NAME == info.UserName);
                }

                if (user == null)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("用户不存在")));
                }

                if (user.USER_PWD != info.OldPwd)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("密码有误")));
                }

                if (!string.IsNullOrEmpty(info.NewPwd)) // 修改密码
                {
                    user.USER_PWD = info.NewPwd;
                }
                else if (!string.IsNullOrEmpty(info.Email)) // 修改邮箱
                {
                    user.USER_EMAIL = info.Email;
                }
                else
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("内容不完整")));
                }

                var entry = entity.Entry(user);
                entry.State = System.Data.EntityState.Modified;

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("修改成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("修改失败")));
                }
            }
        }
Ejemplo n.º 20
0
        public HttpResponseMessage ModifyScheduleConfig([FromUri] int LineId, [FromBody] LineConfig config)
        {
            using (var db = new SecureCloud_Entities())
            {
                var paraShow = new StringBuilder(100);
                try
                {
                    var configEntity = db.T_DIM_STRUCTUER_LINE.FirstOrDefault(u => u.Id == LineId);
                    if (configEntity == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置不存在")));
                    }
                    if (config.LineName != default(string) && config.LineName != configEntity.Line_Name)
                    {
                        configEntity.Line_Name = config.LineName;
                        paraShow.AppendFormat("线路名称改为:{0},", config.LineName);
                    }
                    if (config.LineLength != default(decimal) && config.LineLength != configEntity.Line_Length)
                    {
                        configEntity.Line_Length = config.LineLength;
                        paraShow.AppendFormat("线路长度:{0},", config.LineLength);
                    }


                    if (config.StartId != default(string) && config.StartId != configEntity.Start_Id)
                    {
                        configEntity.Start_Id = config.StartId;
                        paraShow.AppendFormat("开始位置Id改为:{0},", config.StartId);
                    }

                    if (config.EndId != default(string) && config.EndId != configEntity.End_Id)
                    {
                        configEntity.End_Id = config.EndId;
                        paraShow.AppendFormat("结束位置Id改为:{0},", config.EndId);
                    }

                    var entry = db.Entry(configEntity);
                    entry.State = System.Data.EntityState.Modified;

                    if (config.Unit != default(string) && config.Unit != configEntity.Unit)
                    {
                        configEntity.Unit = config.Unit;
                        paraShow.AppendFormat("长度单位改为:{0},", config.Unit);
                    }

                    if (config.Color != default(string) && config.Color != configEntity.Color)
                    {
                        configEntity.Color = config.Color;
                        paraShow.AppendFormat("颜色改为:{0},", config.Color);
                    }


                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("线路配置信息修改成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("线路配置信息修改失败")));
                }
            }
        }
Ejemplo n.º 21
0
        public HttpResponseMessage ModifyOrg([FromUri] int orgId, [FromBody] OrgModel model)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var sb  = new StringBuilder(20);
                var org = entity.T_DIM_ORGANIZATION.FirstOrDefault(o => o.ID == orgId);
                if (org == null)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("组织不存在")));
                }

                sb.AppendFormat("组织名称:{0}:", org.ABB_NAME_CN);

                if (model.ProvinceCode != default(int) && org.ProvinceCode != model.ProvinceCode)
                {
                    org.ProvinceCode = model.ProvinceCode;
                    var province =
                        entity.T_DIM_REGION.Where(r => r.REGION_ID == model.ProvinceCode)
                        .Select(r => r.REGION_NAME_CN)
                        .FirstOrDefault();

                    sb.AppendFormat("省改为:{0},", province);
                }
                if (model.CityCode != default(int) && org.CityCode != model.CityCode)
                {
                    org.CityCode = model.CityCode;
                    var city =
                        entity.T_DIM_REGION.Where(r => r.REGION_ID == model.CityCode)
                        .Select(r => r.REGION_NAME_CN)
                        .FirstOrDefault();

                    sb.AppendFormat("市改为:{0},", city);
                }
                if (model.CountryCode != default(int) && org.CountryCode != model.CountryCode)
                {
                    org.CountryCode = model.CountryCode;
                    var country =
                        entity.T_DIM_REGION.Where(r => r.REGION_ID == model.CountryCode)
                        .Select(r => r.REGION_NAME_CN)
                        .FirstOrDefault();

                    sb.AppendFormat("县区改为:{0},", country);
                }
                if (model.Street != default(string) && org.ADDRESS_STREET_CN != model.Street)
                {
                    org.ADDRESS_STREET_CN = model.Street;
                    sb.AppendFormat("街道地址改为:{0},", model.Street);
                }
                if (model.ZipCode != default(string) && org.ZIPCODE != model.ZipCode)
                {
                    org.ZIPCODE = model.ZipCode;
                    sb.AppendFormat("邮编改为:{0},", model.ZipCode);
                }
                if (model.Phone != default(string) && org.MOBILE_PHONE_NUMBER != model.Phone)
                {
                    org.MOBILE_PHONE_NUMBER = model.Phone;
                    sb.AppendFormat("联系电话改为:{0},", model.Phone);
                }
                if (model.Fax != default(string) && org.FAX_NUMBER != model.Fax)
                {
                    org.FAX_NUMBER = model.Fax;
                    sb.AppendFormat("传真改为:{0},", model.Fax);
                }
                if (model.Website != default(string) && org.WEBSITE != model.Website)
                {
                    org.WEBSITE = model.Website;
                    sb.AppendFormat("网址改为:{0},", model.Website);
                }
                if (model.SystemName != default(string) && org.SystemName != model.SystemName)
                {
                    org.SystemName = model.SystemName;
                    sb.AppendFormat("系统名称改为:{0},", model.SystemName);
                }
                if (model.SystemAbbreviation != default(string) && org.SystemNameAbbreviation != model.SystemAbbreviation)
                {
                    org.SystemNameAbbreviation = model.SystemAbbreviation;
                    sb.AppendFormat("系统简称改为:{0},", model.SystemAbbreviation);
                }
                if (model.Logo != default(string) && org.Logo != model.Logo)
                {
                    org.Logo = model.Logo;
                    sb.AppendFormat("组织Logo改为:{0}", model.Logo);
                }

                var entry = entity.Entry(org);
                entry.State = System.Data.EntityState.Modified;

                #region 日志信息
                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                this.Request.Properties["ActionParameterShow"] = sb.ToString();
                #endregion

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("修改组织信息成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("修改组织信息失败")));
                }
            }
        }
Ejemplo n.º 22
0
        public HttpResponseMessage AddOrg(int userId, [FromBody] OrgModel model)
        {
            using (var entity = new SecureCloud_Entities())
            {
                var org = new T_DIM_ORGANIZATION();
                org.ABB_NAME_CN            = model.OrgName;
                org.ProvinceCode           = model.ProvinceCode;
                org.CityCode               = model.CityCode;
                org.CountryCode            = model.CountryCode;
                org.ADDRESS_STREET_CN      = model.Street;
                org.ZIPCODE                = model.ZipCode;
                org.MOBILE_PHONE_NUMBER    = model.Phone;
                org.FAX_NUMBER             = model.Fax;
                org.WEBSITE                = model.Website;
                org.IsDeleted              = false;
                org.SystemName             = model.SystemName;
                org.SystemNameAbbreviation = model.SystemAbbreviation;
                org.Logo = model.Logo;

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

                #region 日志信息

                var province =
                    entity.T_DIM_REGION.Where(r => r.REGION_ID == model.ProvinceCode)
                    .Select(r => r.REGION_NAME_CN)
                    .FirstOrDefault();

                var city =
                    entity.T_DIM_REGION.Where(r => r.REGION_ID == model.CityCode)
                    .Select(r => r.REGION_NAME_CN)
                    .FirstOrDefault();

                var country =
                    entity.T_DIM_REGION.Where(r => r.REGION_ID == model.CountryCode)
                    .Select(r => r.REGION_NAME_CN)
                    .FirstOrDefault();

                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                this.Request.Properties["ActionParameterShow"] =
                    string.Format(
                        "组织名称:{0},{1}-{2}-{3},{4},邮编:{5},联系电话:{6},传真:{7},网址:{8},系统名称:{9},组织logo:{10}",
                        model.OrgName ?? string.Empty,
                        province ?? string.Empty,
                        city ?? string.Empty,
                        country ?? string.Empty,
                        string.IsNullOrEmpty(model.Street) ? string.Empty : model.Street,
                        string.IsNullOrEmpty(model.ZipCode) ? string.Empty : model.ZipCode,
                        string.IsNullOrEmpty(model.Phone) ? string.Empty : model.Phone,
                        string.IsNullOrEmpty(model.Fax) ? string.Empty : model.Fax,
                        string.IsNullOrEmpty(model.Website) ? string.Empty : model.Website,
                        string.IsNullOrEmpty(model.SystemName) ? string.Empty : model.SystemName,
                        string.IsNullOrEmpty(model.Logo) ? string.Empty : model.Logo);

                #endregion

                try
                {
                    entity.SaveChanges();

                    /****start*add 用户自动关注组织*****/
                    int pk = org.ID;
                    var uo = new T_DIM_USER_ORG();
                    uo.ORGANIZATION_ID = pk;
                    uo.USER_NO         = userId;
                    var entryUserOrg = entity.Entry(uo);
                    entryUserOrg.State = System.Data.EntityState.Added;
                    entity.SaveChanges();
                    /****end******/

                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("新增组织成功")));
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("新增组织失败,请检查组织名称是否重复")));
                }
            }
        }
Ejemplo n.º 23
0
        public HttpResponseMessage AddReportConfigInfo([FromBody] ReportConfig rptConfig)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var us = new T_REPORT_CONFIG
                    {
                        OrgId          = rptConfig.OrgId,
                        StructId       = rptConfig.StructId,
                        ReportName     = rptConfig.ReportName,
                        DateType       = rptConfig.DateType,
                        CreateInterval = rptConfig.CreateInterval,
                        GetDataTime    = rptConfig.GetDataTime,
                        NeedConfirmed  = rptConfig.NeedConfirmed,
                        IsEnabled      = true
                    };
                    IQueryable <T_REPORT_CONFIG> congigTemp = from q in db.T_REPORT_CONFIG
                                                              where q.OrgId == rptConfig.OrgId &&
                                                              q.StructId == rptConfig.StructId &&
                                                              q.ReportName == rptConfig.ReportName &&
                                                              q.DateType == rptConfig.DateType &&
                                                              q.CreateInterval == rptConfig.CreateInterval &&
                                                              q.GetDataTime == rptConfig.GetDataTime &&
                                                              q.NeedConfirmed == rptConfig.NeedConfirmed &&
                                                              q.IsEnabled == rptConfig.IsEnabled
                                                              select q;

                    var stc = db.T_REPORT_CONFIG.Where(s => s.ReportName == rptConfig.ReportName && s.DateType == rptConfig.DateType);

                    var intervalCheck = CronExpression.IsValidExpression(rptConfig.CreateInterval);

                    if (!intervalCheck || congigTemp.Any() || rptConfig.Templates == null || stc.Any())
                    {
                        if (!intervalCheck)
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", false),
                                                                       new JProperty("exist", false),
                                                                       new JProperty("template", true),
                                                                       new JProperty("name", true)//无重名
                                                                       ));
                        }
                        else if (congigTemp.Any())
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", true),
                                                                       new JProperty("exist", true),
                                                                       new JProperty("template", true),
                                                                       new JProperty("name", true)
                                                                       ));
                        }
                        else if (rptConfig.Templates == null)
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", true),
                                                                       new JProperty("exist", false),
                                                                       new JProperty("template", false),
                                                                       new JProperty("name", true)
                                                                       ));
                        }
                        else if (stc.Any())
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", true),
                                                                       new JProperty("exist", false),
                                                                       new JProperty("template", true),
                                                                       new JProperty("name", false)
                                                                       ));
                        }
                    }

                    if (intervalCheck && !congigTemp.Any() && rptConfig.Templates != null && !stc.Any())
                    {
                        db.T_REPORT_CONFIG.Add(us);
                        db.SaveChanges();
                        int    configId    = us.Id;
                        string templateStr = string.Empty;
                        if (rptConfig.Templates != null)
                        {
                            var templates = rptConfig.Templates.Split(',').Select(o => Convert.ToInt32(o));
                            var template  = db.T_REPORT_TEMPLATE.Where(o => templates.Contains(o.Id)).Select(o => o.Name);

                            templateStr = string.Join(",", template);
                            foreach (var templateId in templates)
                            {
                                var uo = new T_REPORT_CONFIG_TEMPLATE {
                                    ReportConfigId = configId, ReportTemplateId = templateId
                                };
                                var entry = db.Entry(uo);
                                entry.State = System.Data.EntityState.Added;
                            }
                        }

                        db.SaveChanges();
                        #region 日志信息
                        this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(rptConfig);
                        this.Request.Properties["ActionParameterShow"]
                            = string.Format("组织:{0}, 结构物:{1}, 报表名称:{2}, 日期类型:{3},  生成周期:{4},  模板: {5}",
                                            us.OrgId,
                                            us.StructId,
                                            us.ReportName,
                                            us.DateType,
                                            us.CreateInterval,
                                            templateStr);

                        #endregion
                        response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                   new JProperty("interval", true),
                                                                   new JProperty("exist", false),
                                                                   new JProperty("template", true),
                                                                   new JProperty("name", true)
                                                                   ));
                    }

                    return(response);
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置添加失败")));
                }
            }
        }
Ejemplo n.º 24
0
        public HttpResponseMessage Login(string username, string password)
        {
            HttpResponseMessage response;

            using (SecureCloud_Entities entity = new SecureCloud_Entities())
            {
                int count = entity.T_DIM_USER.Count(u => u.USER_NAME == username && u.USER_PWD == password && u.USER_IS_ENABLED);
                if (count > 0)
                {
                    Guid guid = Guid.NewGuid();
                    response = this.Request.CreateResponse(
                        HttpStatusCode.OK,
                        new JObject(
                            new JProperty("authorized", true),
                            new JProperty("token", guid.ToString())));
                    int?roleId         = null;
                    int userId         = -1;
                    var firstOrDefault = entity.T_DIM_USER.FirstOrDefault(u => u.USER_NAME == username);
                    if (firstOrDefault != null)
                    {
                        roleId = firstOrDefault.ROLE_ID;
                        userId = firstOrDefault.USER_NO;
                    }

                    string deviceToken = this.Request.GetQueryString("deviceToken");
                    var    authInfo    = new AuthorizationInfo
                    {
                        UserId      = userId,
                        RoleId      = roleId,
                        DeviceToken = deviceToken,
                        Token       = guid.ToString(),
                        HashCode    =
                            this.auth.GetHashValue(
                                guid.ToString(),
                                Request.GetClientIp()),
                        AuthorisedResources = new List <string>()
                    };

                    var authorizationResources = from s in entity.T_DIM_ROLE_RESOURCE where s.ROLE_ID == roleId select s.RESOURCE_ID.Trim();

                    authInfo.AuthorisedResources.AddRange(authorizationResources);

                    this.auth.RemoveVerifyTicket(guid.ToString());
                    this.auth.SaveVerifyTicket(guid.ToString(), authInfo);
                    this.Request.Properties["AuthorizationInfo"] = authInfo;

                    // 更新设备令牌
                    if (deviceToken != null)
                    {
                        var item = entity.T_DIM_DEVICETOKEN.Where(d => d.DeviceToken == deviceToken);
                        foreach (var i in item)
                        {
                            var entry = entity.Entry(i);
                            entry.State = System.Data.EntityState.Deleted;
                        }

                        var record = new T_DIM_DEVICETOKEN {
                            DeviceToken = deviceToken, OnlineUser = username
                        };
                        var entry2 = entity.Entry(record);
                        entry2.State = System.Data.EntityState.Added;

                        entity.SaveChanges();
                    }
                }
                else
                {
                    response = this.Request.CreateResponse(
                        HttpStatusCode.OK,
                        new JObject(
                            new JProperty("authorized", false),
                            new JProperty("token", string.Empty)));
                }
            }

            return(response);
        }
Ejemplo n.º 25
0
        public HttpResponseMessage Add([FromBody] User user)
        {
            using (var db = new SecureCloud_Entities())
            {
                try
                {
                    var newUser = new T_DIM_USER
                    {
                        USER_NAME       = user.UserName,
                        USER_PWD        = user.Password,
                        USER_EMAIL      = user.Email,
                        USER_PHONE      = user.Phone,
                        USER_IS_TRIL    = false,
                        USER_IS_ENABLED = true,
                        ROLE_ID         = user.RoleId,
                        USER_ORG        = user.beOrg
                    };
                    db.T_DIM_USER.Add(newUser);
                    db.SaveChanges();
                    int userId = newUser.USER_NO;

                    string sbOrg = string.Empty;
                    // 配置组织
                    if (user.Orgs != null)
                    {
                        var orgs = user.Orgs.Split(',').Select(o => Convert.ToInt32(o));

                        var org = db.T_DIM_ORGANIZATION.Where(o => orgs.Contains(o.ID)).Select(o => o.ABB_NAME_CN);
                        sbOrg = string.Join(",", org);

                        foreach (var orgId in orgs)
                        {
                            var uo = new T_DIM_USER_ORG {
                                USER_NO = userId, ORGANIZATION_ID = orgId
                            };
                            var entry2 = db.Entry(uo);
                            entry2.State = System.Data.EntityState.Added;
                        }
                    }

                    string sbStc = string.Empty;
                    //配置结构物
                    if (user.Structs != null)
                    {
                        var stcs = user.Structs.Split(',').Select(o => Convert.ToInt32(o));
                        var st   = db.T_DIM_STRUCTURE.Where(s => stcs.Contains(s.ID)).Select(s => s.STRUCTURE_NAME_CN);
                        sbStc = string.Join(",", st);

                        foreach (var stcId in stcs)
                        {
                            var us = new T_DIM_USER_STRUCTURE {
                                USER_NO = userId, STRUCTURE_ID = stcId
                            };
                            var entry3 = db.Entry(us);
                            entry3.State = System.Data.EntityState.Added;
                        }
                    }
                    db.SaveChanges();

                    var role     = db.T_DIM_ROLE.FirstOrDefault(r => r.ROLE_ID == user.RoleId);
                    var roleName = role != null ? role.ROLE_DESCRIPTION : string.Empty;

                    #region 日志信息
                    this.Request.Properties["ActionParameter"] = JsonConvert.SerializeObject(user);
                    this.Request.Properties["ActionParameterShow"]
                        = string.Format("用户名:{0},密码:{1},邮箱:{2},联系电话:{3},角色:{4},所属组织:{5},关注结构物:{6}",
                                        user.UserName,
                                        StringHelper.Confuse(user.Password),
                                        StringHelper.Confuse(user.Email),
                                        user.Phone, roleName,
                                        sbOrg, sbStc);

                    #endregion

                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("用户添加成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("用户添加失败")));
                }
            }
        }
Ejemplo n.º 26
0
        public HttpResponseMessage ConfirmWarnings([FromUri] string warnIds, [FromBody] ConfirmModel model)
        {
            int[] warnArray = warnIds.Split(',').Select(s => Convert.ToInt32(s)).ToArray();

            if (model == null)
            {
                return(Request.CreateResponse(
                           System.Net.HttpStatusCode.BadRequest,
                           StringHelper.GetMessageString("参数无效,缺少确认信息")));
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("共{0}条:", warnArray.Length);

            using (SecureCloud_Entities entity = new SecureCloud_Entities())
            {
                foreach (var warnId in warnArray)
                {
                    var warn = entity.T_WARNING_SENSOR.FirstOrDefault(w => w.Id == warnId);
                    if (warn.DealFlag == WarningSupportProcessed || warn.DealFlag == WarningClientProcessed)
                    {
                        return(Request.CreateResponse(
                                   System.Net.HttpStatusCode.BadRequest,
                                   StringHelper.GetMessageString("告警已被处理!")));
                    }

                    int roleId = 5;
                    if (Request.Properties.ContainsKey("AuthorizationInfo"))
                    {
                        var info = Request.Properties["AuthorizationInfo"] as AuthorizationInfo;
                        roleId = info != null && info.RoleId != null ? (int)info.RoleId : 5;
                    }

                    warn.DealFlag = roleId == 5 ? WarningClientProcessed : WarningSupportProcessed; // update DealFlag for Client or Support.

                    var entry1 = entity.Entry(warn);
                    entry1.State = EntityState.Modified;

                    #region 日志信息
                    var stc =
                        entity.T_DIM_STRUCTURE.Where(s => s.ID == warn.StructId)
                        .Select(s => s.STRUCTURE_NAME_CN)
                        .FirstOrDefault();
                    string type = warn.DeviceTypeId == 1 ? "dtu" : "传感器";
                    string name = string.Empty;
                    if (warn.DeviceTypeId == 1)
                    {
                        string dtuId = warn.DeviceId.ToString();
                        name =
                            entity.T_DIM_REMOTE_DTU.Where(
                                d => d.ID == warn.DeviceId || d.REMOTE_DTU_NUMBER == dtuId)
                            .Select(d => d.REMOTE_DTU_NUMBER)
                            .FirstOrDefault();
                    }
                    else
                    {
                        name =
                            entity.T_DIM_SENSOR.Where(s => s.SENSOR_ID == warn.DeviceId)
                            .Select(s => s.SENSOR_LOCATION_DESCRIPTION)
                            .FirstOrDefault();
                    }
                    sb.AppendFormat("{0}.{1}:{2}-{3};", stc, type, name, warn.Content);
                    #endregion

                    var dealDetails = new T_WARNING_DEALDETAILS();
                    dealDetails.WarningId   = warnId;
                    dealDetails.UserNo      = model.Confirmor;
                    dealDetails.Suggestion  = model.Suggestion;
                    dealDetails.ConfirmTime = DateTime.Now;

                    DbEntityEntry <T_WARNING_DEALDETAILS> entry2 = entity.Entry <T_WARNING_DEALDETAILS>(dealDetails);
                    entry2.State = EntityState.Added;
                }

                #region 日志信息
                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(model);
                this.Request.Properties["ActionParameterShow"] = sb.ToString();
                #endregion

                try
                {
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("处理成功!")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               System.Net.HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("处理失败!")));
                }
            }
        }
Ejemplo n.º 27
0
        public HttpResponseMessage ModifyReportConfigInfo([FromUri] int id, [FromBody] ReportConfig rptConfig)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            using (var db = new SecureCloud_Entities())
            {
                var paraShow = new StringBuilder(100);
                try
                {
                    var rptConfigEntity = db.T_REPORT_CONFIG.ToList().Find(u => u.Id == id);
                    var intervalCheck   = CronExpression.IsValidExpression(rptConfig.CreateInterval);
                    if (!intervalCheck || rptConfigEntity == null || rptConfig.Templates == null)
                    {
                        if (!intervalCheck)
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", false),
                                                                       new JProperty("exist", true),
                                                                       new JProperty("template", true)
                                                                       ));
                        }
                        else if (rptConfigEntity == null)
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                       new JProperty("interval", true),
                                                                       new JProperty("exist", false),
                                                                       new JProperty("template", true)
                                                                       ));
                        }
                        else if (rptConfig.Templates == null)
                        {
                            response = this.Request.CreateResponse(HttpStatusCode.OK,
                                                                   new JObject(
                                                                       new JProperty("interval", true),
                                                                       new JProperty("exist", true),
                                                                       new JProperty("template", false)
                                                                       ));
                        }
                    }

                    if (intervalCheck && rptConfigEntity != null && rptConfig.Templates != null)
                    {
                        if (rptConfig.DateType != rptConfigEntity.DateType)
                        {
                            rptConfigEntity.DateType = rptConfig.DateType;
                            paraShow.AppendFormat("报表日期类型改为: {0} ", rptConfig.DateType);
                        }

                        if (rptConfig.CreateInterval != rptConfigEntity.CreateInterval)
                        {
                            rptConfigEntity.CreateInterval = rptConfig.CreateInterval;
                            paraShow.AppendFormat("报表生成周期改为: {0} ", rptConfig.CreateInterval);
                        }
                        if (rptConfig.GetDataTime != default(string) && rptConfig.GetDataTime != rptConfigEntity.GetDataTime)
                        {
                            rptConfigEntity.GetDataTime = rptConfig.GetDataTime;
                            paraShow.AppendFormat("报表数据获取时间改为: {0} ", rptConfig.GetDataTime);
                        }

                        if (rptConfig.IsEnabled != rptConfigEntity.IsEnabled)
                        {
                            rptConfigEntity.IsEnabled = rptConfig.IsEnabled;
                            paraShow.AppendFormat("报表启用状态改为: {0} ", rptConfig.IsEnabled);
                        }

                        if (rptConfig.NeedConfirmed != rptConfigEntity.NeedConfirmed)
                        {
                            rptConfigEntity.NeedConfirmed = rptConfig.NeedConfirmed;
                            paraShow.AppendFormat("报表是否需要确认状态改为: {0} ", rptConfig.NeedConfirmed);
                        }
                        var entry1 = db.Entry(rptConfigEntity);
                        entry1.State = System.Data.EntityState.Modified;

                        var queryTemp = from uo in db.T_REPORT_CONFIG_TEMPLATE where uo.ReportConfigId == id select uo;
                        foreach (var configTemp in queryTemp)
                        {
                            var entry2 = db.Entry(configTemp);
                            entry2.State = System.Data.EntityState.Deleted;
                        }

                        if (rptConfig.Templates.Length != 0)
                        {
                            var templates = rptConfig.Templates.Split(',').Select(o => Convert.ToInt32(o));
                            var temp      = db.T_REPORT_TEMPLATE.Where(o => templates.Contains(o.Id)).Select(o => o.Name);
                            paraShow.AppendFormat("模板改为: {0} ", string.Join(",", temp));

                            foreach (var tempId in templates)
                            {
                                var uo = new T_REPORT_CONFIG_TEMPLATE {
                                    ReportConfigId = id, ReportTemplateId = tempId
                                };
                                var entry3 = db.Entry(uo);
                                entry3.State = System.Data.EntityState.Added;
                            }
                        }
                        #region 日志信息
                        this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(rptConfig);
                        this.Request.Properties["ActionParameterShow"] = paraShow.ToString();

                        #endregion

                        db.SaveChanges();
                        response = this.Request.CreateResponse(HttpStatusCode.OK, new JObject(
                                                                   new JProperty("interval", true),
                                                                   new JProperty("exist", true),
                                                                   new JProperty("template", true)
                                                                   ));
                    }

                    return(response);
                }
                catch (Exception)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("报表配置信息修改失败")));
                }
            }
        }
Ejemplo n.º 28
0
        public HttpResponseMessage Modify([FromUri] int userId, [FromBody] User user)
        {
            using (var db = new SecureCloud_Entities())
            {
                var paraShow = new StringBuilder(20);
                try
                {
                    var userEntity = db.T_DIM_USER.FirstOrDefault(u => u.USER_NO == userId);

                    if (userEntity == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("用户不存在")));
                    }
                    paraShow.AppendFormat("用户名:{0},", userEntity.USER_NAME);

                    if (user.Password != default(string))
                    {
                        userEntity.USER_PWD = user.Password;
                        paraShow.AppendFormat("密码改为:{0},", StringHelper.Confuse(user.Password));
                    }
                    if (user.Email != default(string))
                    {
                        userEntity.USER_EMAIL = user.Email;
                        paraShow.AppendFormat("邮箱改为:{0},", StringHelper.Confuse(user.Email));
                    }
                    if (user.Phone != default(string))
                    {
                        userEntity.USER_PHONE = user.Phone;
                        paraShow.AppendFormat("联系电话改为:{0},", user.Phone);
                    }
                    if (user.RoleId != default(int))
                    {
                        userEntity.ROLE_ID = user.RoleId;
                        var role     = db.T_DIM_ROLE.FirstOrDefault(r => r.ROLE_ID == user.RoleId);
                        var roleName = role != null ? role.ROLE_DESCRIPTION : string.Empty;
                        paraShow.AppendFormat("角色改为:{0},", roleName);
                    }

                    // 配置组织
                    if (user.Orgs != null || user.Orgs == "clear")
                    {
                        var queryOrg = from uo in db.T_DIM_USER_ORG where uo.USER_NO == userId select uo;
                        foreach (var userOrg in queryOrg)
                        {
                            var entry = db.Entry(userOrg);
                            entry.State = System.Data.EntityState.Deleted;
                        }

                        if (user.Orgs == "clear")
                        {
                            paraShow.AppendFormat("清除所属组织单位,");
                        }

                        if (user.Orgs.Length != 0 && user.Orgs != "clear")
                        {
                            var orgs = user.Orgs.Split(',').Select(o => Convert.ToInt32(o));
                            var org  = db.T_DIM_ORGANIZATION.Where(o => orgs.Contains(o.ID)).Select(o => o.ABB_NAME_CN);
                            paraShow.AppendFormat("所属组织单位改为:{0},", string.Join(",", org));

                            foreach (var orgId in orgs)
                            {
                                var uo = new T_DIM_USER_ORG {
                                    USER_NO = userId, ORGANIZATION_ID = orgId
                                };
                                var entry2 = db.Entry(uo);
                                entry2.State = System.Data.EntityState.Added;
                            }
                        }
                    }

                    //配置结构物
                    if (user.Structs != null || user.Structs == "clear")
                    {
                        var queryStc = from us in db.T_DIM_USER_STRUCTURE where us.USER_NO == userId select us;
                        foreach (var userStructure in queryStc)
                        {
                            var entry = db.Entry(userStructure);
                            entry.State = System.Data.EntityState.Deleted;
                        }

                        if (user.Orgs == "clear")
                        {
                            paraShow.AppendFormat("清除关注结构物,");
                        }

                        if (user.Structs.Length != 0 && user.Structs != "clear")
                        {
                            var stcs = user.Structs.Split(',').Select(o => Convert.ToInt32(o));
                            var stc  = db.T_DIM_STRUCTURE.Where(o => stcs.Contains(o.ID)).Select(o => o.STRUCTURE_NAME_CN);
                            paraShow.AppendFormat("关注结构物改为:{0},", string.Join(",", stc));

                            foreach (var stcId in user.Structs.Split(',').Select(o => Convert.ToInt32(o)))
                            {
                                var us = new T_DIM_USER_STRUCTURE {
                                    USER_NO = userId, STRUCTURE_ID = stcId
                                };
                                var entry3 = db.Entry(us);
                                entry3.State = System.Data.EntityState.Added;
                            }
                        }
                    }

                    #region 日志信息
                    this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(user);
                    this.Request.Properties["ActionParameterShow"] = paraShow.ToString();

                    #endregion

                    db.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.Accepted, StringHelper.GetMessageString("用户信息修改成功")));
                }
                catch (Exception e)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, StringHelper.GetMessageString("用户信息修改失败")));
                }
            }
        }
Ejemplo n.º 29
0
        public HttpResponseMessage AddSensorWeight([FromBody] SensorWeightModel[] config)
        {
            var sb = new StringBuilder(50);

            using (var entity = new SecureCloud_Entities())
            {
                foreach (SensorWeightModel m in config)
                {
                    SensorWeightModel model = m;
                    var orgStc = (from os in entity.T_DIM_ORG_STUCTURE
                                  where os.ORGANIZATION_ID == model.OrgId && os.STRUCTURE_ID == model.StructId
                                  select os).FirstOrDefault();
                    if (orgStc == null)
                    {
                        return(Request.CreateResponse(
                                   HttpStatusCode.BadRequest,
                                   StringHelper.GetMessageString("组织下不存在该结构物")));
                    }
                    // 组织结构物代理键
                    var orgStcId = orgStc.ORG_STRUC_ID;
                    // 对应权重数据
                    var wei = (from sw in entity.T_FACT_SENSOR_WEIGHTS
                               where sw.ORG_STRUC_ID == orgStcId && sw.SENSOR_ID == model.SensorId
                               select sw).FirstOrDefault();
                    if (wei == null)
                    {
                        // 数据不存在,新增
                        var weight = new T_FACT_SENSOR_WEIGHTS();
                        weight.SENSOR_ID      = model.SensorId;
                        weight.SENSOR_WEIGHTS = (byte)model.Weight;
                        weight.ORG_STRUC_ID   = orgStcId;

                        var entry = entity.Entry(weight);
                        entry.State = System.Data.EntityState.Added;
                    }
                    else
                    {
                        // 数据已存在,修改
                        wei.SENSOR_WEIGHTS = (byte)model.Weight;
                        var entry = entity.Entry(wei);
                        entry.State = System.Data.EntityState.Modified;
                    }

                    #region 日志信息
                    var org =
                        entity.T_DIM_ORGANIZATION.Where(o => o.ID == m.OrgId)
                        .Select(o => o.ABB_NAME_CN)
                        .FirstOrDefault();

                    var stc =
                        entity.T_DIM_STRUCTURE.Where(s => s.ID == m.StructId)
                        .Select(s => s.STRUCTURE_NAME_CN)
                        .FirstOrDefault();

                    var sensor =
                        entity.T_DIM_SENSOR.Where(f => f.SENSOR_ID == m.SensorId)
                        .Select(f => f.SENSOR_LOCATION_DESCRIPTION)
                        .FirstOrDefault();

                    sb.AppendFormat(
                        "组织:{0},结构物:{1},传感器:{2},权重:{3};",
                        org ?? string.Empty,
                        stc ?? string.Empty,
                        sensor ?? string.Empty,
                        m.Weight);
                    #endregion
                }

                #region 日志信息

                this.Request.Properties["ActionParameter"]     = JsonConvert.SerializeObject(config);
                this.Request.Properties["ActionParameterShow"] = sb.ToString();
                #endregion

                try
                {
                    entity.Configuration.AutoDetectChangesEnabled = false;
                    entity.Configuration.ValidateOnSaveEnabled    = false;
                    entity.SaveChanges();
                    return(Request.CreateResponse(
                               HttpStatusCode.Accepted,
                               StringHelper.GetMessageString("配置成功")));
                }
                catch (Exception ex)
                {
                    return(Request.CreateResponse(
                               HttpStatusCode.BadRequest,
                               StringHelper.GetMessageString("配置失败")));
                }
                finally
                {
                    entity.Configuration.AutoDetectChangesEnabled = true;
                    entity.Configuration.ValidateOnSaveEnabled    = true;
                }
            }
        }
Ejemplo n.º 30
0
        public HttpResponseMessage LoginAndReturnInfo(string username, string password)
        {
            HttpResponseMessage response;

            using (SecureCloud_Entities entity = new SecureCloud_Entities())
            {
                var ur = (from r in entity.T_DIM_ROLE
                          from u in entity.T_DIM_USER
                          where u.ROLE_ID == r.ROLE_ID &&
                          u.USER_NAME == username &&
                          u.USER_PWD == password &&
                          u.USER_IS_ENABLED
                          select u.ROLE_ID);
                List <UserLogin> users = new List <UserLogin>();
                if (!ur.ToList().Any())
                {
                    response = this.Request.CreateResponse(
                        HttpStatusCode.OK,
                        new JObject(
                            new JProperty("authorized", false),
                            new JProperty("token", string.Empty),
                            new JProperty("userId", string.Empty),
                            new JProperty("email", string.Empty),
                            new JProperty("orgId", string.Empty),
                            new JProperty("organization", string.Empty),
                            new JProperty("roleId", string.Empty),
                            new JProperty("roleCode", string.Empty),
                            new JProperty("systemName", string.Empty),
                            new JProperty("logo", string.Empty)));
                }
                else
                {
                    var uos = (from u in entity.T_DIM_USER
                               from oo in entity.T_DIM_ORGANIZATION
                               where oo.ID == u.USER_ORG &&
                               u.USER_NAME == username &&
                               u.USER_PWD == password &&
                               u.USER_IS_ENABLED
                               select oo.SystemName);
                    if (ur.FirstOrDefault() == 1)
                    {
                        var query =
                            from u in entity.T_DIM_USER
                            from r in entity.T_DIM_ROLE
                            from o in entity.T_DIM_ORGANIZATION
                            where u.ROLE_ID == r.ROLE_ID &&
                            u.USER_NAME == username &&
                            u.USER_PWD == password &&
                            u.USER_IS_ENABLED
                            select new UserLogin
                        {
                            USER_NO     = u.USER_NO,
                            USER_EMAIL  = u.USER_EMAIL,
                            orgid       = o.ID,
                            ABB_NAME_CN = o.ABB_NAME_CN,
                            ROLE_ID     = r.ROLE_ID,
                            ROLE_CODE   = r.ROLE_CODE,
                            SystemName  = uos.FirstOrDefault() == null ? o.SystemName : uos.FirstOrDefault(),
                            Logo        = o.Logo
                        };
                        users = query.ToList();
                    }
                    else
                    {
                        var query =
                            from u in entity.T_DIM_USER
                            from r in entity.T_DIM_ROLE
                            join uo in entity.T_DIM_USER_ORG
                            on u.USER_NO equals uo.USER_NO into org
                            from or in org.DefaultIfEmpty()
                            join o in entity.T_DIM_ORGANIZATION
                            on or.ORGANIZATION_ID equals o.ID
                            into uor
                            from uo in uor.DefaultIfEmpty()
                            where u.ROLE_ID == r.ROLE_ID &&
                            u.USER_NAME == username &&
                            u.USER_PWD == password &&
                            u.USER_IS_ENABLED
                            select new UserLogin
                        {
                            USER_NO     = u.USER_NO,
                            USER_EMAIL  = u.USER_EMAIL,
                            orgid       = uo.ID,
                            ABB_NAME_CN = uo.ABB_NAME_CN,
                            ROLE_ID     = r.ROLE_ID,
                            ROLE_CODE   = r.ROLE_CODE,
                            SystemName  = uos.FirstOrDefault() == null ? uo.SystemName : uos.FirstOrDefault(),
                            Logo        = uo.Logo
                        };
                        users = query.ToList();
                    }
                    //var users = query.ToList();
                    if (users.Any())
                    {
                        Guid guid = Guid.NewGuid();
                        var  info = users.First();
                        response = this.Request.CreateResponse(
                            HttpStatusCode.OK,
                            new JObject(
                                new JProperty("authorized", true),
                                new JProperty("token", guid.ToString()),
                                new JProperty("userId", info.USER_NO),
                                new JProperty("email", info.USER_EMAIL),
                                new JProperty("orgId", info.orgid),
                                new JProperty("organization", info.ABB_NAME_CN),
                                new JProperty("roleId", info.ROLE_ID),
                                new JProperty("roleCode", info.ROLE_CODE),
                                new JProperty("systemName", info.SystemName),
                                new JProperty("logo", info.Logo)));

                        this.auth.RemoveVerifyTicket(guid.ToString());
                        string deviceToken = this.Request.GetQueryString("deviceToken");
                        var    authInfo    = new AuthorizationInfo
                        {
                            UserId      = (int)info.USER_NO,
                            RoleId      = info.ROLE_ID,
                            DeviceToken = deviceToken,
                            Token       = guid.ToString(),
                            HashCode    =
                                this.auth.GetHashValue(
                                    guid.ToString(),
                                    Request.GetClientIp()),
                            AuthorisedResources = new List <string>()
                        };

                        var authorizationResources = from s in entity.T_DIM_ROLE_RESOURCE where s.ROLE_ID == info.ROLE_ID select s.RESOURCE_ID.Trim();

                        authInfo.AuthorisedResources.AddRange(authorizationResources);

                        this.auth.SaveVerifyTicket(guid.ToString(), authInfo);
                        this.Request.Properties["AuthorizationInfo"] = authInfo;

                        // 更新移动令牌
                        if (deviceToken != null)
                        {
                            var item = entity.T_DIM_DEVICETOKEN.Where(d => d.DeviceToken == deviceToken);
                            foreach (var i in item)
                            {
                                var entry = entity.Entry(i);
                                entry.State = System.Data.EntityState.Deleted;
                            }

                            var record = new T_DIM_DEVICETOKEN {
                                DeviceToken = deviceToken, OnlineUser = username
                            };
                            var entry2 = entity.Entry(record);
                            entry2.State = System.Data.EntityState.Added;

                            entity.SaveChanges();
                        }
                    }
                    else
                    {
                        response = this.Request.CreateResponse(
                            HttpStatusCode.OK,
                            new JObject(
                                new JProperty("authorized", false),
                                new JProperty("token", string.Empty),
                                new JProperty("userId", string.Empty),
                                new JProperty("email", string.Empty),
                                new JProperty("orgId", string.Empty),
                                new JProperty("organization", string.Empty),
                                new JProperty("roleId", string.Empty),
                                new JProperty("roleCode", string.Empty),
                                new JProperty("systemName", string.Empty),
                                new JProperty("logo", string.Empty)));
                    }
                }
            }

            return(response);
        }