119 lines
5.1 KiB
C#
119 lines
5.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using ServerPartTransmission.Common;
|
||
|
||
namespace ServerPartTransmission.Business
|
||
{
|
||
public class SERVERPARTFEEDBACK
|
||
{
|
||
//存储数据库连接字符串
|
||
private string _OracleConnStr = ConfigurationManager.AppSettings["OracleConnStr"];
|
||
//声明数据库操作类
|
||
private OracleHelper oracleHelper;
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
public SERVERPARTFEEDBACK()
|
||
{
|
||
oracleHelper = new OracleHelper(_OracleConnStr.Split(',')[0], _OracleConnStr.Split(',')[1],
|
||
_OracleConnStr.Split(',')[2], _OracleConnStr.Split(',')[3]);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新或者插入来自区服上的心跳数据反馈数据
|
||
/// </summary>
|
||
/// <param name="jsonString"></param>
|
||
/// <returns></returns>
|
||
public string SaveServerpartFeedBack(string jsonString)
|
||
{
|
||
string strBack = "{\"error\": 1 ,\"msg\": \"添加成功!\",\"rows\":[]}";
|
||
//下列数组标记字段必须有值,需先做有效性判断。
|
||
string[] _RequiredDatas = new string[]
|
||
{
|
||
"SERVERPARTCODE",
|
||
"SHOPCODE",
|
||
"MACHINECODE"
|
||
};
|
||
string _ISCheckData = Validation.ISCheckData(jsonString, _RequiredDatas);
|
||
if (_ISCheckData != null)
|
||
{
|
||
strBack = _ISCheckData;
|
||
return strBack;
|
||
}
|
||
List<Model.EXCHANGE.SERVERPARTFEEDBACK> _DataStateFeedback =
|
||
JsonHelper.JSONStringToListUTC<Model.EXCHANGE.SERVERPARTFEEDBACK>(jsonString);
|
||
if (_DataStateFeedback == null || _DataStateFeedback.Count == 0)
|
||
{
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
return strBack;
|
||
}
|
||
string _strServerPart = "";
|
||
var _ServerPartList = _DataStateFeedback.Select(p => p.SERVERPARTCODE).Distinct().ToArray();
|
||
foreach (var _ServerPartTemp in _ServerPartList)
|
||
{
|
||
_strServerPart += (string.IsNullOrWhiteSpace(_strServerPart) ? "'" : ",'") + _ServerPartTemp.Trim() + "'";
|
||
}
|
||
|
||
//取出该(这些)服务区既定字段的所有数据
|
||
DataTable _DataTable = oracleHelper.ExcuteSqlGetDataSet(
|
||
string.Format(@"SELECT SERVERPARTCODE,SHOPCODE,MACHINECODE FROM HIGHWAY_EXCHANGE.T_SERVERPARTFEEDBACK
|
||
WHERE SERVERPARTCODE IN ({0}) ", _strServerPart)).Tables[0];
|
||
|
||
List<Model.EXCHANGE.SERVERPARTFEEDBACK> _InsertList = new List<Model.EXCHANGE.SERVERPARTFEEDBACK>();//需插入的集合
|
||
List<Model.EXCHANGE.SERVERPARTFEEDBACK> _UpdateList = new List<Model.EXCHANGE.SERVERPARTFEEDBACK>();//需更新的集合
|
||
DataRow[] _DataRows = null; //临时DataRow数组
|
||
|
||
foreach (Model.EXCHANGE.SERVERPARTFEEDBACK _STATEFEEDBACK in _DataStateFeedback)
|
||
{
|
||
if (_DataTable != null && _DataTable.Rows.Count > 0)
|
||
{
|
||
_DataRows = _DataTable.Select(
|
||
string.Format(@" SERVERPARTCODE = '{0}' AND SHOPCODE = '{1}' AND MACHINECODE = '{2}' ",
|
||
_STATEFEEDBACK.SERVERPARTCODE, _STATEFEEDBACK.SHOPCODE, _STATEFEEDBACK.MACHINECODE));
|
||
if (_DataRows != null && _DataRows.Length > 0)
|
||
{
|
||
//记录已存在、需更新的数据
|
||
_UpdateList.Add(_STATEFEEDBACK);
|
||
continue;
|
||
}
|
||
}
|
||
|
||
//需更新的集合
|
||
_InsertList.Add(_STATEFEEDBACK);
|
||
}
|
||
|
||
if (_InsertList.Count + _UpdateList.Count != _DataStateFeedback.Count)
|
||
{
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:数据分割失败!\",\"rows\":[]}";
|
||
return strBack;
|
||
}
|
||
if (_InsertList.Count > 0)
|
||
{
|
||
OperationDataHelper<Model.EXCHANGE.SERVERPARTFEEDBACK>.InsertTableData(
|
||
oracleHelper, _InsertList, "HIGHWAY_EXCHANGE.T_SERVERPARTFEEDBACK");
|
||
}
|
||
if (_UpdateList.Count > 0)
|
||
{
|
||
try
|
||
{
|
||
OperationDataHelper<Model.EXCHANGE.SERVERPARTFEEDBACK>.UpdateTableData(
|
||
oracleHelper, _UpdateList, "HIGHWAY_EXCHANGE.T_SERVERPARTFEEDBACK",
|
||
new string[] { "SERVERPARTCODE", "SHOPCODE", "MACHINECODE" }, true);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
strBack = "{\"error\": 2 ,\"msg\": \"添加成功,更新失败!\",\"rows\":" +
|
||
JsonHelper.ListToJson(_UpdateList, "rows", false) + "}";
|
||
return strBack;
|
||
}
|
||
}
|
||
|
||
return strBack;
|
||
}
|
||
}
|
||
} |