Esempio n. 1
0
 public BasicResponse <JC_LargedataAnalysisConfigInfo> UpdateLargeDataAnalysisConfig(LargedataAnalysisConfigUpdateRequest jc_LargedataAnalysisConfigRequest)
 {
     return(_largedataAnalysisConfigService.UpdateLargeDataAnalysisConfig(jc_LargedataAnalysisConfigRequest));
 }
        /// <summary>
        /// 更新分析模型。
        /// </summary>
        /// <param name="jc_LargedataAnalysisConfigRsequest">更新模型请求对象</param>
        /// <returns>Mas应答对象包含分析模型</returns>
        public BasicResponse <JC_LargedataAnalysisConfigInfo> UpdateLargeDataAnalysisConfig(LargedataAnalysisConfigUpdateRequest jc_LargedataAnalysisConfigRsequest)
        {
            BasicResponse validationResponse = largeDataAnalysisConfigValidation(jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo);

            if (!validationResponse.IsSuccess)
            {
                return new BasicResponse <JC_LargedataAnalysisConfigInfo>()
                       {
                           Code = validationResponse.Code, Message = validationResponse.Message, Data = jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo
                       }
            }
            ;
            if (string.IsNullOrEmpty(jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo.Id))
            {
                return(new BasicResponse <JC_LargedataAnalysisConfigInfo>()
                {
                    Code = 1, Message = "分析模型ID为空", Data = jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo
                });
            }
            var _jC_Largedataanalysisconfig        = ObjectConverter.Copy <JC_LargedataAnalysisConfigInfo, JC_LargedataanalysisconfigModel>(jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo);
            var _jcSetAnalysisModelPointRecordList = ObjectConverter.CopyList <JC_SetAnalysisModelPointRecordInfo, JC_SetanalysismodelpointrecordModel>(jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo.AnalysisModelPointRecordInfoList);

            bool isSingleExpressionAndParameter1 = isSingleExpressionAndParameter(jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo.TempleteId);
            bool isBindDevType = jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo.AnalysisModelPointRecordInfoList[0].DevTypeId > -1;

            if (isSingleExpressionAndParameter1 && _jcSetAnalysisModelPointRecordList.Count > 0 && !isBindDevType)
            {
                _jC_Largedataanalysisconfig.Name = System.Text.RegularExpressions.Regex.Replace(_jC_Largedataanalysisconfig.Name, "\\(\\w+\\)", string.Format("({0})", jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo.AnalysisModelPointRecordInfoList[0].Point));
            }


            JC_LargedataanalysisconfigModel existsModel = _Repository.GetLargeDataAnalysisConfigByName(_jC_Largedataanalysisconfig.Name);

            if (null != existsModel && existsModel.Id != _jC_Largedataanalysisconfig.Id)
            {
                return new BasicResponse <JC_LargedataAnalysisConfigInfo>()
                       {
                           Code = -100, Message = "分析模型名称已存在", Data = jc_LargedataAnalysisConfigRsequest.JC_LargedataAnalysisConfigInfo
                       }
            }
            ;


            TransactionsManager.BeginTransaction(() =>
            {
                //更新分析模型
                //_jC_Largedataanalysisconfig.UpdatedTime = DateTime.Now;
                //更新时间不变化,这里将分析模型名称改了再改回来。
                string analysisModelName         = _jC_Largedataanalysisconfig.Name;
                _jC_Largedataanalysisconfig.Name = analysisModelName + "1";
                _Repository.UpdateJC_Largedataanalysisconfig(_jC_Largedataanalysisconfig);
                _jC_Largedataanalysisconfig.Name = analysisModelName;
                _Repository.UpdateJC_Largedataanalysisconfig(_jC_Largedataanalysisconfig);
                //先删除再插入
                _AnalysisModelPointRecordRepository.DeleteAnalysisModelPointRecordByAnalysisModelId(_jC_Largedataanalysisconfig.Id);
                foreach (var item in _jcSetAnalysisModelPointRecordList)
                {
                    //item.Id = IdHelper.CreateGuidId();
                    item.Id = IdHelper.CreateLongId().ToString();
                    item.AnalysisModelId = _jC_Largedataanalysisconfig.Id;
                }
                //插入模型测点关联记录
                _AnalysisModelPointRecordRepository.Insert(_jcSetAnalysisModelPointRecordList);
            });
            var jC_Largedataanalysisconfigresponse = new BasicResponse <JC_LargedataAnalysisConfigInfo>();

            jC_Largedataanalysisconfigresponse.Data = ObjectConverter.Copy <JC_LargedataanalysisconfigModel, JC_LargedataAnalysisConfigInfo>(_jC_Largedataanalysisconfig);
            BasicResponse <IList <JC_SetAnalysisModelPointRecordInfo> > pointListResponse = _AnalysisModelPointRecordService.GetCustomizationAnalysisModelPointRecordInfoByModelId(new SetAnalysisModelPointRecordByModelIdGetRequest()
            {
                AnalysisModelId = _jC_Largedataanalysisconfig.Id
            });

            if (pointListResponse != null && pointListResponse.Data != null)
            {
                jC_Largedataanalysisconfigresponse.Data.AnalysisModelPointRecordInfoList = pointListResponse.Data.ToList();
            }
            try
            {
                jC_Largedataanalysisconfigresponse.Data.AnalysisResult = 0;
                jC_Largedataanalysisconfigresponse.Data.AnalysisTime   = null;

                //更新实时显示到缓存,这样客户端刷新就可以看到。不用等到分析周期. 开始
                jC_Largedataanalysisconfigresponse.Data.ExpressionRealTimeResultList = new List <ExpressionRealTimeResultInfo>();
                if (jC_Largedataanalysisconfigresponse.Data.AnalysisModelPointRecordInfoList != null && jC_Largedataanalysisconfigresponse.Data.AnalysisModelPointRecordInfoList.Count > 0)
                {
                    IEnumerable <IGrouping <string, JC_SetAnalysisModelPointRecordInfo> > expressionGroup = jC_Largedataanalysisconfigresponse.Data.AnalysisModelPointRecordInfoList.GroupBy(p => p.ExpressionId);
                    foreach (IGrouping <string, JC_SetAnalysisModelPointRecordInfo> expressionParameterList in expressionGroup)
                    {
                        if (expressionParameterList.FirstOrDefault().DevTypeId == -1)//绑定测点的情况才更新实时显示的表达式
                        {
                            ExpressionRealTimeResultInfo addInitializeResultInfo = new ExpressionRealTimeResultInfo();
                            addInitializeResultInfo.AnalysisModelId     = jC_Largedataanalysisconfigresponse.Data.Id;
                            addInitializeResultInfo.AnalysisModelName   = jC_Largedataanalysisconfigresponse.Data.Name;
                            addInitializeResultInfo.ExpressionId        = expressionParameterList.FirstOrDefault().ExpressionId;
                            addInitializeResultInfo.Expression          = expressionParameterList.FirstOrDefault().Expresstion;
                            addInitializeResultInfo.ExpressionText      = expressionParameterList.FirstOrDefault().Expresstion;
                            addInitializeResultInfo.FirstSuccessfulTime = DateTime.MinValue;
                            addInitializeResultInfo.LastAnalysisTime    = DateTime.MinValue;
                            addInitializeResultInfo.AnalysisResult      = 0;
                            addInitializeResultInfo.AnalysisResultText  = "未知";
                            addInitializeResultInfo.ContinueTime        = expressionParameterList.FirstOrDefault().ContinueTime;
                            addInitializeResultInfo.MaxContinueTime     = expressionParameterList.FirstOrDefault().MaxContinueTime;
                            addInitializeResultInfo.ActualContinueTime  = 0;
                            foreach (var pointMapping in expressionParameterList)
                            {
                                addInitializeResultInfo.ExpressionText = addInitializeResultInfo.ExpressionText.Replace(pointMapping.ExpressionConfigId, string.Format("{0}->{1}", pointMapping.PointId, pointMapping.FactorName));
                            }
                            jC_Largedataanalysisconfigresponse.Data.ExpressionRealTimeResultList.Add(addInitializeResultInfo);
                        }
                    }
                }
                //更新实时显示到缓存,这样客户端刷新就可以看到。不用等到分析周期. 结束

                //更新缓存
                _LargeDataAnalysisConfigCacheService.UpdateLargeDataAnalysisConfigCahce(new LargeDataAnalysisConfigCacheUpdateRequest()
                {
                    LargeDataAnalysisConfigInfo = jC_Largedataanalysisconfigresponse.Data
                });
            }
            catch (Exception ex)
            {
                Basic.Framework.Logging.LogHelper.Error(string.Format("更新分析模型后再更新缓存出错:{0}", ex.StackTrace));
            }

            if (Basic.Framework.Data.PlatRuntime.Items.ContainsKey(DataContract.UserRoleAuthorize.KeyConst.AnalysisModelChangedKey))
            {
                Basic.Framework.Data.PlatRuntime.Items[DataContract.UserRoleAuthorize.KeyConst.AnalysisModelChangedKey] = DateTime.Now;
            }
            else
            {
                Basic.Framework.Data.PlatRuntime.Items.Add(DataContract.UserRoleAuthorize.KeyConst.AnalysisModelChangedKey, DateTime.Now);
            }
            return(jC_Largedataanalysisconfigresponse);
        }