|
@@ -622,6 +622,7 @@ namespace NB_IOT_TCP_HP_SOCKET.WWKJUtil
|
|
|
|
|
|
public static void SaveRecordNew(List<HistoryRecord> list)
|
|
|
{
|
|
|
+ string NetCumulativeFlowCol = ConfigurationManager.AppSettings["NetCumulativeFlow"];
|
|
|
|
|
|
string dataColumnHis = ConfigurationManager.AppSettings["DataColumnHis"];
|
|
|
string[] dataColumnHisArr = dataColumnHis.Split(',');
|
|
@@ -648,53 +649,148 @@ namespace NB_IOT_TCP_HP_SOCKET.WWKJUtil
|
|
|
|
|
|
if (!CheckRecordExsitNew(tablename, record2.RecordTime))
|
|
|
{
|
|
|
- StringBuilder strSql = new StringBuilder();
|
|
|
- strSql.Append(" insert into ").Append(tablename).Append(" ( GetDateTime,createTime");
|
|
|
List<CommData> dataList = record2.DataList;
|
|
|
- StringBuilder cellValue = new StringBuilder();
|
|
|
- foreach (KeyValuePair<string, string> kvp in cols)
|
|
|
+ StringBuilder strSql = new StringBuilder();
|
|
|
+ strSql.Append("SELECT * FROM MeterAssessmentBase where MeterAssessmentId = ").Append(meterId);
|
|
|
+ DataTable dataTable = DBHelper.ExecuteDataTable(strSql.ToString(), CommandType.Text, null);
|
|
|
+ strSql.Clear();
|
|
|
+
|
|
|
+ if (dataTable.Rows[0]["isHangup"].ToString() == "0" || dataTable.Rows[0]["IsKaoHe"].ToString() != "1")
|
|
|
{
|
|
|
- CommData commData = dataList.Find(e => e.Name == kvp.Value);
|
|
|
- if (commData != null)
|
|
|
+ bool isHangUp = false;
|
|
|
+
|
|
|
+ if (dataTable.Rows[0]["IsKaoHe"].ToString() == "1")
|
|
|
{
|
|
|
- strSql.Append(",").Append(kvp.Key);
|
|
|
- if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
+ CommData commData = dataList.Find(e => e.Name == NetCumulativeFlowCol);
|
|
|
+ decimal thisMeterNum = Convert.ToDecimal(commData.Value);
|
|
|
+
|
|
|
+ if (Convert.ToDecimal(dataTable.Rows[0]["NetCumulativeFlow"]) <= thisMeterNum)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (!CompareBigNumber(tablename, record2.RecordTime, thisMeterNum, Convert.ToDecimal(dataTable.Rows[0]["threshold"])))
|
|
|
+ {
|
|
|
+ isHangUp = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- cellValue.Append(",0");
|
|
|
+ isHangUp = true;
|
|
|
+
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ if (!isHangUp)
|
|
|
+ {
|
|
|
+ strSql.Append(" insert into ").Append(tablename).Append(" ( GetDateTime,createTime");
|
|
|
+ StringBuilder cellValue = new StringBuilder();
|
|
|
+ foreach (KeyValuePair<string, string> kvp in cols)
|
|
|
{
|
|
|
- if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
+ CommData commData = dataList.Find(e => e.Name == kvp.Value);
|
|
|
+ if (commData != null)
|
|
|
{
|
|
|
- cellValue.Append(",'").Append(commData.Value).Append("'");
|
|
|
+ strSql.Append(",").Append(kvp.Key);
|
|
|
+ if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
+ {
|
|
|
+ cellValue.Append(",0");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
+ {
|
|
|
+ cellValue.Append(",'").Append(commData.Value).Append("'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cellValue.Append(",").Append(commData.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ strSql.Append(") values ('").Append(record2.RecordTime.ToString()).Append("',GETDATE()").Append(cellValue.ToString()).Append(")");
|
|
|
+
|
|
|
+ int rs = DBHelper.Query(strSql.ToString());
|
|
|
+ if (rs > 0 && Convert.ToDateTime(record2.RecordTime.ToString()) >= Convert.ToDateTime(dataTable.Rows[0]["GetDateTime"]))
|
|
|
+ {
|
|
|
+ UpdateDeviceLastDataNew(meterId, record2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ strSql.Append(" insert into MeterAssessmentTableNameTemplate (meterId,GetDateTime,createTime");
|
|
|
+ StringBuilder cellValue = new StringBuilder();
|
|
|
+ foreach (KeyValuePair<string, string> kvp in cols)
|
|
|
+ {
|
|
|
+ CommData commData = dataList.Find(e => e.Name == kvp.Value);
|
|
|
+ if (commData != null)
|
|
|
{
|
|
|
- cellValue.Append(",").Append(commData.Value);
|
|
|
+ strSql.Append(",").Append(kvp.Key);
|
|
|
+ if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
+ {
|
|
|
+ cellValue.Append(",0");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
+ {
|
|
|
+ cellValue.Append(",'").Append(commData.Value).Append("'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cellValue.Append(",").Append(commData.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- strSql.Append(") values ('").Append(record2.RecordTime.ToString()).Append("',GETDATE()").Append(cellValue.ToString()).Append(")");
|
|
|
+ strSql.Append(") values (").Append(meterId).Append(",'").Append(record2.RecordTime.ToString()).Append("',GETDATE()").Append(cellValue.ToString()).Append(")");
|
|
|
|
|
|
- int rs = DBHelper.Query(strSql.ToString());
|
|
|
+ int rs = DBHelper.Query(strSql.ToString());
|
|
|
|
|
|
- if (rs > 0)
|
|
|
- {
|
|
|
- if (lastData.ContainsKey(meterId))
|
|
|
- {
|
|
|
- HistoryRecord historyRecord = lastData[meterId];
|
|
|
- if (record2.RecordTime >= historyRecord.RecordTime)
|
|
|
+ if (rs > 0)
|
|
|
{
|
|
|
- lastData[meterId] = record2;
|
|
|
+ strSql.Clear();
|
|
|
+ strSql.Append("UPDATE MeterAssessmentBase SET isHangup = 1 WHERE MeterAssessmentId = ").Append(meterId);
|
|
|
+
|
|
|
+ DBHelper.Query(strSql.ToString());
|
|
|
}
|
|
|
}
|
|
|
- else
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ strSql.Append(" insert into MeterAssessmentTableNameTemplate (meterId,GetDateTime,createTime");
|
|
|
+ StringBuilder cellValue = new StringBuilder();
|
|
|
+ foreach (KeyValuePair<string, string> kvp in cols)
|
|
|
{
|
|
|
- lastData[meterId] = record2;
|
|
|
+ CommData commData = dataList.Find(e => e.Name == kvp.Value);
|
|
|
+ if (commData != null)
|
|
|
+ {
|
|
|
+ strSql.Append(",").Append(kvp.Key);
|
|
|
+ if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
+ {
|
|
|
+ cellValue.Append(",0");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
+ {
|
|
|
+ cellValue.Append(",'").Append(commData.Value).Append("'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ cellValue.Append(",").Append(commData.Value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ strSql.Append(") values (").Append(meterId).Append(",'").Append(record2.RecordTime.ToString()).Append("',GETDATE()").Append(cellValue.ToString()).Append(")");
|
|
|
+
|
|
|
+ int rs = DBHelper.Query(strSql.ToString());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -703,19 +799,55 @@ namespace NB_IOT_TCP_HP_SOCKET.WWKJUtil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- foreach (KeyValuePair<string, HistoryRecord> kvp in lastData)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static bool CompareBigNumber(string tableName, DateTime getDataTime, decimal thisMeterNum, decimal threshold)
|
|
|
+ {
|
|
|
+ DateTime preTime, curTime;
|
|
|
+ int time = 30;
|
|
|
+ string timeIntStr = ConfigurationManager.AppSettings["BigNumberTimeScopeParam"];
|
|
|
+ string sql = "";
|
|
|
+ Object obj = new Object();
|
|
|
+ decimal meterNum = 0, dayUsedWater = 0;
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(timeIntStr))
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- UpdateDeviceLastDataNew(kvp);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- LogUtil.WriteLog(ex.Message + ">>>" + ex.StackTrace);
|
|
|
- continue;
|
|
|
- }
|
|
|
+ time = Convert.ToInt32(timeIntStr);
|
|
|
+ }
|
|
|
+ preTime = getDataTime.AddDays(-1).AddMinutes(0 - time);
|
|
|
+ curTime = getDataTime.AddDays(-1).AddMinutes(time);
|
|
|
+
|
|
|
+ sql = "SELECT AVG(NetCumulativeFlow) AS NetCumulativeFlow FROM " + tableName + " WHERE GetDateTime between '" + preTime + "' AND '" + curTime + "'";
|
|
|
+
|
|
|
+ obj = DBHelper.ExecuteScalar(sql, CommandType.Text, null);
|
|
|
+ if (obj == null || obj == DBNull.Value)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ meterNum = Convert.ToDecimal(obj);
|
|
|
+ }
|
|
|
+ dayUsedWater = thisMeterNum - meterNum;
|
|
|
+
|
|
|
+
|
|
|
+ if (threshold >= dayUsedWater || threshold == 0)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -882,7 +1014,7 @@ namespace NB_IOT_TCP_HP_SOCKET.WWKJUtil
|
|
|
|
|
|
|
|
|
|
|
|
- private static void UpdateDeviceLastDataNew(KeyValuePair<string, HistoryRecord> kvp)
|
|
|
+ private static void UpdateDeviceLastDataNew(string meterId, HistoryRecord historyRecord)
|
|
|
{
|
|
|
|
|
|
string dataColumnMeter = ConfigurationManager.AppSettings["DataColumnMeter"];
|
|
@@ -894,51 +1026,44 @@ namespace NB_IOT_TCP_HP_SOCKET.WWKJUtil
|
|
|
string[] dataColumnArr = dataColumn.Split('|');
|
|
|
cols[dataColumnArr[0]] = dataColumnArr[1];
|
|
|
}
|
|
|
- string meterId = kvp.Key;
|
|
|
- string recDate = kvp.Value.RecordTime.ToString();
|
|
|
- List<CommData> dataList = kvp.Value.DataList;
|
|
|
- string dataSource = kvp.Value.DataSource;
|
|
|
+ string recDate = historyRecord.RecordTime.ToString();
|
|
|
+ List<CommData> dataList = historyRecord.DataList;
|
|
|
+ string dataSource = historyRecord.DataSource;
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
|
- strSql.Append("SELECT * FROM MeterAssessmentBase where MeterAssessmentId = ").Append(meterId);
|
|
|
- DataTable dataTable = DBHelper.ExecuteDataTable(strSql.ToString(), CommandType.Text, null);
|
|
|
- strSql.Clear();
|
|
|
StringBuilder valueStr = new StringBuilder();
|
|
|
|
|
|
- if ((dataList == null) || (dataList.Count == 0))
|
|
|
+ if (dataList == null || dataList.Count == 0)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (Convert.ToDateTime(recDate) >= Convert.ToDateTime(dataTable.Rows[0]["GetDateTime"]))
|
|
|
- {
|
|
|
- strSql.Append("update MeterAssessmentBase set GetDateTime = '").Append(recDate).Append("'");
|
|
|
+ strSql.Append("update MeterAssessmentBase set GetDateTime = '").Append(recDate).Append("'");
|
|
|
|
|
|
- foreach (KeyValuePair<string, string> kvpTmp in cols)
|
|
|
+ foreach (KeyValuePair<string, string> kvpTmp in cols)
|
|
|
+ {
|
|
|
+ CommData commData = dataList.Find(e => e.Name == kvpTmp.Value);
|
|
|
+ if (commData != null)
|
|
|
{
|
|
|
- CommData commData = dataList.Find(e => e.Name == kvpTmp.Value);
|
|
|
- if (commData != null)
|
|
|
+ if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
{
|
|
|
- if ((((commData.Value == null) || (commData.Value == "")) || ((commData.Value == "未知") || (commData.Value == "--"))) || (commData.Value == "非数字"))
|
|
|
+ strSql.Append(",[").Append(kvpTmp.Key).Append("]='0'");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
{
|
|
|
- strSql.Append(",[").Append(kvpTmp.Key).Append("]='0'");
|
|
|
+ strSql.Append(",[").Append(kvpTmp.Key).Append("]='").Append(commData.Value).Append("'");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (commData.Tag == null || "".Equals(commData.Tag) || "BIT".Equals(commData.Tag.ToUpper()))
|
|
|
- {
|
|
|
- strSql.Append(",[").Append(kvpTmp.Key).Append("]='").Append(commData.Value).Append("'");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- strSql.Append(",[").Append(kvpTmp.Key).Append("]=").Append(commData.Value).Append("");
|
|
|
- }
|
|
|
+ strSql.Append(",[").Append(kvpTmp.Key).Append("]=").Append(commData.Value).Append("");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- strSql.Append(" where MeterAssessmentId = ").Append(meterId);
|
|
|
- DBHelper.Query(strSql.ToString());
|
|
|
}
|
|
|
+
|
|
|
+ strSql.Append(" where MeterAssessmentId = ").Append(meterId);
|
|
|
+ DBHelper.Query(strSql.ToString());
|
|
|
}
|
|
|
|
|
|
|