public VM_JSMind genMindStruct(string axisNumStr, string id, ref VM_JSMind mind, string parentId = "", bool isRoot = false) { if (string.IsNullOrEmpty(axisNumStr) || !HisMain.IsAxisNum(axisNumStr)) { return(null); } var bllMachine = new MesWeb.BLL.T_Machine(); var bllMachineType = new MesWeb.BLL.T_MachineType(); var bllEmployee = new MesWeb.BLL.T_Employee(); var bllMaterial = new MesWeb.BLL.T_MaterialOutput(); HisMain axisNum = new HisMain(); if (axisNumStr.StartsWith("ZD")) { axisNum.Year = axisNumStr.Substring(2, 4); axisNum.Month = axisNumStr.Substring(6, 2); axisNum.MachineTypeID = "5"; } else if (axisNumStr.StartsWith("CP")) { axisNum = new HisMain(axisNumStr); } var hisTabName = "HISMAIN" + axisNum.Year + axisNum.Month + axisNum.MachineTypeID.Trim(); var bllHisMain = new MesWeb.BLL.T_HisMain(hisTabName); var hisMain = bllHisMain.GetModelList("Axis_No like '%" + axisNumStr + "%'").FirstOrDefault(); if (hisMain == null) { return(null); } var machineType = bllMachineType.GetModel(int.Parse(axisNum.MachineTypeID)); MesWeb.Model.T_MaterialOutput material = null; if (hisMain != null) { material = bllMaterial.GetModelList("MaterialRFID = '" + hisMain.MaterialRFID + "'").FirstOrDefault(); } if (material != null) { hisMain.SpecColor = material.Color; hisMain.SpecName = material.MaterialType; hisMain.Supplier = material.SupplyCompany; hisMain.BatchNo = material.BatchNo; } var employeeCode = hisMain.EmployeeID_Main; var employee = bllEmployee.GetModelList("EmployeeCode = '" + employeeCode + "'").FirstOrDefault(); if (employee != null) { hisMain.EmployeeID_Main = employee.EmployeeName; } var machine = bllMachine.GetModel(hisMain.MachineID.Value); var node = new JSMind_Data(); node.topic = machineType.MachineType + machine.MachineName; node.id = id; node.parentid = parentId; node.isroot = isRoot; node.data = hisMain; mind.data.Add(node); if (hisMain != null) { var startAxisNums = ("" + hisMain.Start_Axis_No).Split(','); foreach (var stNum in startAxisNums) { genMindStruct(stNum, stNum, ref mind, id); } } return(mind); }
public JsonResult SearchTraceBrefAction(VM_Trace_Search_Cond cond) { var retData = new VM_Result_Data(); retData.Content = "查询失败"; if (string.IsNullOrEmpty(cond.MachineType)) { cond.MachineType = "5"; } var brefList = new List <VM_Trace_Bref>(); try { var isFirstSearch = true; List <MesWeb.Model.T_HisMain> hisMainListArray = new List <MesWeb.Model.T_HisMain>(); if (cond.StartTime.HasValue && cond.EndTime.HasValue && cond.StartTime < cond.EndTime) { isFirstSearch = false; List <List <MesWeb.Model.T_HisMain> > listArray = null; //同一年 if (cond.StartTime.Value.Year == cond.EndTime.Value.Year) { listArray = getSameYearData(cond.StartTime, cond.EndTime, cond.MachineType); filterListMainArrary(hisMainListArray, listArray, cond.AxisNum); } //不是同一年 else { for (var y = cond.StartTime.Value.Year; y <= cond.EndTime.Value.Year; ++y) { if (y == cond.StartTime.Value.Year) { listArray = getSameYearData(cond.StartTime, new DateTime(y, 12, 31), cond.MachineType); } else if (y == cond.EndTime.Value.Year) { listArray = getSameYearData(new DateTime(y, 1, 1), cond.EndTime, cond.MachineType); } else { listArray = getSameYearData(new DateTime(y, 1, 1), new DateTime(y, 12, 31), cond.MachineType); } filterListMainArrary(hisMainListArray, listArray, cond.AxisNum); } } } if (!string.IsNullOrEmpty(cond.AxisNum) && isFirstSearch) { var axisNum = new HisMain(cond.AxisNum); var hisTabName = "HISMAIN" + axisNum.Year + axisNum.Month + axisNum.MachineTypeID.Trim(); var bllHisMain = new MesWeb.BLL.T_HisMain(hisTabName); var hisMainList = bllHisMain.GetModelList("Axis_No like '%" + cond.AxisNum + "%'"); hisMainListArray.AddRange(hisMainList); } hisMainListArray.ForEach(h => { //生成结果 try { var bref = new VM_Trace_Bref(); bref.SpecNum = "未录入"; bref.Axis_No = h.Axis_No.Replace(",", ""); var axisNum = new HisMain(h.Axis_No); bref.Date = axisNum.Year + "-" + axisNum.Month + "-" + axisNum.Day; bref.PrintCode = string.IsNullOrEmpty(h.Printcode) ? "未录入" : h.Printcode; bref.Detail = "<a tabId=" + h.CurrentDataID + " tabName = '" + axisNum.GetHisDataTableName() + "' axisNum='" + axisNum.AxisNumStr + "' onclick='showTraceDetail(this)'>详情</a>"; brefList.Add(bref); } catch { } }); if (brefList.Count > 0) { retData.Code = RESULT_CODE.OK; retData.Appendix = brefList; retData.Content = "查询成功"; } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(Json(retData)); }
public JsonResult GetAxisDetailAction(string axisNumStr) { log = LogFactory.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.FullName + ":" + MethodBase.GetCurrentMethod().Name); var retData = new VM_Result_Data(); var procDetailList = new List <VM_ProcDetail>(); var hisData = new VM_ProcDetail(); axisNumStr = axisNumStr.Trim(); HisMain axisNum = new HisMain(axisNumStr); var tabName = axisNum.GetHisDataTableName(); if (string.IsNullOrEmpty(tabName)) { retData.Content = "轴号有误"; return(Json(retData)); } try { var bllHisData = new MesWeb.BLL.T_HisMain(tabName); var findData = bllHisData.GetModelList("Axis_No = '" + axisNumStr + "'").FirstOrDefault(); hisData = new VM_ProcDetail { Axis_No = findData.Axis_No, CurrentDataID = findData.CurrentDataID, SpecificationID = findData.SpecificationID, MachineID = findData.MachineID, MachineTypeID = findData.MachineTypeID, EmployeeID_Main = findData.EmployeeID_Main, EmployeeID_Assistant = findData.EmployeeID_Assistant, Start_Axis_No = findData.Start_Axis_No, Printcode = findData.Printcode }; var specID = hisData.SpecificationID; var bllMachine = new MesWeb.BLL.T_Machine(); var bllEmp = new MesWeb.BLL.T_Employee(); var bllSpec = new MesWeb.BLL.T_Specification(); var bllCodeUsed = new MesWeb.BLL.T_CodeUsed(); var bllLayout = new MesWeb.BLL.T_LayoutPicture(); var spec = bllSpec.GetModel((int)specID); hisData.SpecName = spec.SpecificationName; hisData.ODMax = spec.ODMax.ToString(); hisData.ODMin = spec.ODMin.ToString(); hisData.SpecColor = spec.SpecificationColor; hisData.RolledYield = "100%"; hisData.GeneratorTime = bllCodeUsed.GetModelList("Axis_No = '" + hisData.Axis_No + "'").FirstOrDefault().GeneratorTime.Value.ToShortDateString(); var machine = bllMachine.GetModel((int)hisData.MachineID); var machineLayout = bllLayout.GetModelList("LayoutTypeID = " + 1).Find(s => { return(s.TableRowID == machine.MachineID); }); // hisData.EmployeeName = bllEmp.GetModel((int)hisData.EmployeeID_Main).EmployeeName; hisData.EmployeeName = hisData.EmployeeID_Main; var tableName = axisNum.Year + axisNum.Month + ((int)(machine.MachineTypeID)).ToString("00"); hisData.MachineName = "<a href='/HistoryQuery/HistoryMachine/" + tableName + "," + axisNumStr + "'>" + machine.MachineName + "</a>"; retData.Code = RESULT_CODE.OK; } catch (Exception e) { log.Error("查询轴号信息失败", e); retData.Content = "查询失败,请联系管理员"; } procDetailList.Add(hisData); retData.Appendix = procDetailList; return(Json(retData)); }
//获取同一年的轴号数据集合 private List <List <MesWeb.Model.T_HisMain> > getSameYearData(DateTime?startTime, DateTime?endTime, string machineType = "5") { var bllCodeUsed = new MesWeb.BLL.T_CodeUsed(); var usedCodeList = new List <MesWeb.Model.T_CodeUsed>(); var bllSpec = new MesWeb.BLL.T_Specification(); List <MesWeb.Model.T_HisMain> hisMainList = new List <MesWeb.Model.T_HisMain>(); var startMonth = startTime.Value.Month; var endMonth = endTime.Value.Month; List <List <MesWeb.Model.T_HisMain> > hisMainListArray = new List <List <MesWeb.Model.T_HisMain> >(); string cp = "CP0" + machineType; List <MesWeb.Model.T_HisMain> hisMainTmps; try { if (startTime.Value.Year > DateTime.Now.Year) { return(hisMainListArray); } for (var i = startMonth; i <= endMonth; ++i) { if (i > DateTime.Now.Month) { hisMainListArray.Add(hisMainList); return(hisMainListArray); } var tableName = "HISMAIN" + startTime.Value.Year + i.ToString("00") + machineType; var bllHisMain = new MesWeb.BLL.T_HisMain(tableName); //同一月 if (startMonth == endMonth) { for (var j = startTime.Value.Day; j <= endTime.Value.Day; ++j) { hisMainTmps = bllHisMain.GetModelList("Axis_No like '" + cp + "" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } hisMainTmps = bllHisMain.GetModelList("Axis_No like 'ZD" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } } //不是同一月 } else { //起始月 if (i == startMonth) { //遍历起始月 for (var j = startTime.Value.Day; j <= 31; ++j) { hisMainTmps = bllHisMain.GetModelList("Axis_No like '" + cp + "" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } hisMainTmps = bllHisMain.GetModelList("Axis_No like 'ZD" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } } //遍历终止月 } else if (i == endMonth) { for (var j = 1; j <= endTime.Value.Day; ++j) { hisMainTmps = bllHisMain.GetModelList("Axis_No like '" + cp + "" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } hisMainTmps = bllHisMain.GetModelList("Axis_No like 'ZD" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } } //遍历其它月 } else { for (var j = 1; j <= 31; ++j) { hisMainTmps = bllHisMain.GetModelList("Axis_No like '" + cp + "" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } hisMainTmps = bllHisMain.GetModelList("Axis_No like 'ZD" + startTime.Value.Year + i.ToString("00") + j.ToString("00") + "%" + "'"); if (hisMainTmps.Count > 0) { hisMainList.AddRange(hisMainTmps); } } } } } hisMainListArray.Add(hisMainList); } catch (Exception e) { return(hisMainListArray); } return(hisMainListArray); }
/// <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 { //当月数据不存在,则从上月数据查找 } } }