1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Data;
- using LeaRun.Data;
- namespace LeaRun.Application.Service.PipeNetworkManage
- {
- public class AutoMeterService
- {
- SqlHelper sqlHelper = new SqlHelper("PipeNetworkDb");
- /// <summary>
- /// 智能配表数据
- /// </summary>
- /// <param name="meterId">设备ID</param>
- /// <param name="start">开始时间</param>
- /// <param name="end">结束时间</param>
- /// <returns></returns>
- public string AutoMeterData(string meterId, string start, string end)
- {
- try
- {
- StringBuilder sbJson = new StringBuilder();
- sbJson.Append("[{");
- string selSql = "SELECT MeterAssessmentId,TableName, MeterTypeId, MeterAssessmentName FROM dbo.MeterAssessmentBase WHERE MeterAssessmentId = " + meterId;
- DataTable dtResult = sqlHelper.ExecuteDataTable(selSql, CommandType.Text, null);
- string devName = dtResult.Rows[0]["MeterAssessmentName"].ToString();
- string devType = dtResult.Rows[0]["MeterTypeId"].ToString();
- string tabName = dtResult.Rows[0]["TableName"].ToString();
- string typeSql = "SELECT * FROM MeterType WHERE MeterAssessmentType="+devType;
- DataTable dtType = sqlHelper.ExecuteDataTable(typeSql, CommandType.Text, null);
- string Q1 = dtType.Rows[0]["Q1"].ToString();//起始流量
- string Q2 = dtType.Rows[0]["Q2"].ToString();//分界流量
- string Q3 = dtType.Rows[0]["Q3"].ToString();//常用流量
- string Q4 = dtType.Rows[0]["Q4"].ToString();//过载流量
- sbJson.Append("\"Q1\":\"" + Q1+ "\",\"Q2\":\"" + Q2 + "\",\"Q3\":\"" + Q3 + "\",\"Q4\":\"" + Q4 + "\",\"flowData\":[");
-
- string flowSql = "SELECT InstantaneousFlow,GetDateTime FROM " + tabName+" WHERE InstantaneousFlow<>0 AND GetDateTime BETWEEN '"+start+"' AND '"+end+"'";
- DataTable dtFlow = sqlHelper.ExecuteDataTable(flowSql,CommandType.Text,null);
-
- for (int row = 0; row < dtFlow.Rows.Count; row++)
- {
- sbJson.Append("{");
- sbJson.Append("\"flowTime\":\"").Append(Convert.ToDateTime(dtFlow.Rows[row]["GetDateTime"]).ToString("yyyy-MM-dd HH:mm:ss")).Append("\",");
- sbJson.Append("\"flow\":\"").Append(dtFlow.Rows[row]["InstantaneousFlow"]).Append("\"");
- sbJson.Append("}");
- if (row < dtFlow.Rows.Count-1)
- sbJson.Append(",");
- }
- sbJson.Append("]}]");
- return sbJson.ToString();
- }
- catch (Exception ex)
- {
- return "";
- }
- }
- }
- }
|