public JsonResult GetMahineHistoryDataAction(MesWeb.ViewModel.Mes.MahineHistoryQueryCond cond)
        {
            var retData = new MesWeb.ViewModel.Promise.VM_Result_Data();

            retData.Content = "获取机台历史数据失败,请联系管理员";

            try
            {
                var hisData    = new HisData(cond.axisNum);
                var bllHisData = new MesWeb.BLL.T_HisData(hisData.TableName);
                //string querySql = "select * From  "+hisData.TableName + " where Axis_No = '" + cond.axisNum + " order by 'CollectedTime'";
                var allData = bllHisData.GetModelList("Axis_No  LIKE '%" + hisData.AxisNumStr + "%' ORDER BY  'CollectedTime'");
                var bllSpec = new MesWeb.BLL.Specification();
                var spec    = bllSpec.GetModelList("procedureId = " + cond.machineType + " and paramTypeId = 2").FirstOrDefault();

                retData.Appendix = allData;
                retData.Content  = spec;
                if (allData.Count > 0)
                {
                    retData.Code = RESULT_CODE.OK;
                }
            }
            catch (Exception e)
            {
                retData.Content = e;
            }

            return(new ConfigurableJsonResult {
                Data = retData, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public JsonResult GetHistoryData(string axisNumStr)
        {
            log = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name);
            var retData = new VM_Result_Data();

            if (HisMain.IsAxisNum(axisNumStr))
            {
                var axisNum = new HisData(axisNumStr);

                var bllHisData = new MesWeb.BLL.T_HisData(axisNum.TableName);
                try {
                    var hisDataList    = bllHisData.GetModelList("machineID = " + axisNum.MachineId);
                    var sensorDataList = new List <VM_Sensor_Online>();

                    foreach (var item in ParamCodeDic)
                    {
                        //找出映射的数据
                        var data = (from s in hisDataList where s.ParameterCodeID == item.Key select s).ToList();
                        if (data.Count > 0)
                        {
                            //生成传感器的数据结构
                            var sensorData = new  VM_Sensor_Online {
                                ParamCodeId = item.Value
                            };
                            sensorData.SeriesData = new List <VM_Sensor_Data>();
                            foreach (var d in data)
                            {
                                try {
                                    var seriesData = new VM_Sensor_Data {
                                        X = ((DateTime)(d.CollectedTime)).AddHours(8).ToUniversalTime().ToString(), Y = float.Parse(d.CollectedValue)
                                    };
                                    sensorData.SeriesData.Add(seriesData);
                                } catch (Exception e) {
                                    log.Error(e);
                                    continue;
                                }
                            }
                            sensorDataList.Add(sensorData);
                        }
                    }


                    retData.Appendix = sensorDataList;
                    retData.Content  = "加载机台历史数据成功";
                    retData.Code     = RESULT_CODE.OK;
                } catch (Exception e) {
                    log.Error(e);
                    retData.Content = "加载机台历史数据失败";
                }
            }
            return(Json(retData));
        }
Beispiel #3
0
        public ActionResult HistoryMachine(string Id)
        {
            var     axisNumStr  = Id.Split(',')[1];
            var     tabStr      = Id.Split(',')[0];
            string  tabName     = "HISDATA" + tabStr;
            HisData historyInfo = new HisData(Id);

            var bllHistoryInfo = new MesWeb.BLL.T_HisData(tabName);
            var histories      = bllHistoryInfo.GetModelList("Axis_No = '" + axisNumStr + "'");

            if (histories.FirstOrDefault().MachineID.HasValue)
            {
                var machineID = histories.FirstOrDefault().MachineID.Value;

                HisMachInfo.MachindID      = machineID.ToString();
                HisMachInfo.AxisNumStr     = axisNumStr;
                HisMachInfo.HisDataTabName = tabName;

                var machineLayout = bllLayout.GetModelList("TableRowID = " + machineID + "AND LayoutTypeID=" + (int)LAYOUT_TPYE.MACHINE).FirstOrDefault();
                var layoutInfo    = new VM_LayoutPicture(machineLayout);
                if (!string.IsNullOrEmpty(machineLayout.PicUrl))
                {
                    layoutInfo = new VM_LayoutPicture(machineLayout);
                    layoutInfo = GetLayoutInfo(machineLayout);
                }
                else
                {
                    log.Error("机台信息为空");
                    var infoNotFound = new VM_Error_Info {
                        Title = "施工错误", ErrorMessage = "机台信息为空,请联系管理人员", ReturnUrl = "/Admin/Home", ReturnName = "主页"
                    };
                    return(RedirectToAction(ErrorManager.SystemError, ErrorManager.ErrorController, infoNotFound));
                }
                return(View(layoutInfo));
            }
            VM_Error_Info infoError = new VM_Error_Info {
                Title = "系统错误", ErrorMessage = "未找到该轴号的机台", ReturnUrl = "/Admin/Home", ReturnName = "主页"
            };

            return(RedirectToAction(ErrorManager.SystemError, ErrorManager.ErrorController));
        }
Beispiel #4
0
        /// <summary>
        /// 初始化字典缓存
        /// </summary>
        /// <param name="machineId"></param>
        /// <param name="axisNum"></param>
        /// <param name="meters"></param>
        private void initDicCache(int machineId, out string axisNum, out string meters)
        {
            var bllMachine = new MesWeb.BLL.T_Machine();
            var machine    = bllMachine.GetModel(machineId);

            //历史采集数据表
            var hisDatablaName = HisData.GetHisDataTableName(DateTime.Now, machine.MachineTypeID.Value);
            var bllHisData     = new MesWeb.BLL.T_HisData(hisDatablaName);
            //历史轴号表
            var hisMainTableName = HisMain.GetHisMainTableName(DateTime.Now, machine.MachineTypeID.Value);
            var bllHisMain       = new MesWeb.BLL.T_HisMain(hisMainTableName);

            //缓存中没有该机台的轴号
            if (!curAxisNumDic.TryGetValue(machineId, out axisNum))
            {
                //从当月历史数据更新缓存
                var hisMain = bllHisMain.GetModelList("MachineID = " + machineId).FirstOrDefault();
                //当月数据存在,则更新缓存
                if (hisMain != null)
                {
                    axisNum = hisMain.Axis_No;
                    curAxisNumDic.AddOrUpdate(machineId, hisMain.Axis_No,
                                              (key, oldValue) => { return(hisMain.Axis_No); });
                }
                else
                {
                    //当月数据不存在,则从上月数据查找 TODO
                }
            }

            //缓存中没有当前米数值
            if (!curMetersDic.TryGetValue(machineId, out meters))
            {
                //从当月历史数据更新缓存
                //var data = bllHisData.GetModelList("ParameterCodeID = " + (int)SPEC_PARAM_CODE.METERS_COUNT + " group by CollectedTime desc").FirstOrDefault();
                var ds1 = DbHelperSQL.Query("select top 1 * from "
                                            + bllHisData.TabName + " where ParameterCodeID = "
                                            + (int)SPEC_PARAM_CODE.METERS_COUNT
                                            + " AND machineID = " + machineId
                                            + " order by CollectedTime desc");
                //找到数据库最后一条数据
                var recentData = bllHisData.DataTableToList(ds1.Tables[0]).FirstOrDefault();
                //当月数据存在,则更新缓存
                if (recentData != null)
                {
                    //获取数据的轴号
                    var axisNo = recentData.Axis_No;
                    //找到该轴号的米数的最大值
                    var ds2 = DbHelperSQL.
                              Query("SELECT   MAX(CollectedValue) AS CollectedValue, CollectedTime, MachineID, ParameterCodeID, Axis_No" +
                                    " FROM  " + bllHisData.TabName +
                                    " WHERE (ParameterCodeID = " + (int)SPEC_PARAM_CODE.METERS_COUNT + ") AND (Axis_No = '" + axisNo + "')" +
                                    " GROUP BY MachineID,Axis_No,CollectedTime,ParameterCodeID");
                    var row      = ds2.Tables[0].Rows[0];
                    var maxMeter = row["CollectedValue"].ToString();
                    meters = maxMeter;
                    //更新缓存
                    curMetersDic.AddOrUpdate(machineId, maxMeter, (key, oldValue) => {
                        return(maxMeter);
                    });
                }
                else
                {
                    //当月数据不存在,则从上月数据查找
                }
            }
        }