274 lines
14 KiB
C#
274 lines
14 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Threading.Tasks;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using ServerPartTransmission.Common;
|
||
using Newtonsoft.Json.Linq;
|
||
|
||
namespace ServerPartTransmission.Method
|
||
{
|
||
public class UploadMethod
|
||
{
|
||
#region 方法 -> 数据上传子项
|
||
public static string DataUploading(OracleHelper _OracleHelper, string tableName, string jsonString,
|
||
string[] codes, string orderString, int maxDataQuantity = 4, Transaction _Transaction = null)
|
||
{
|
||
string strBack = string.Empty;
|
||
string _ISCheckData = string.Empty;
|
||
string[] _RequiredDatas = null;
|
||
try
|
||
{
|
||
switch (tableName)
|
||
{
|
||
case "HIGHWAY_EXCHANGE.T_ENDACCOUNT_NEW":
|
||
#region HIGHWAY_EXCHANGE.T_ENDACCOUNT_NEW 日结报表
|
||
//必填项
|
||
_RequiredDatas = new string[] { "SERVERPARTCODE", "STARTDATE", "ENDDATE", "TRANSFER_ID" };
|
||
_ISCheckData = Validation.ISCheckData(jsonString, _RequiredDatas);
|
||
if (_ISCheckData != null)
|
||
{
|
||
return _ISCheckData;
|
||
}
|
||
if (DataTransfer.UploadEndaccount(_Transaction, jsonString, 1))
|
||
{
|
||
_Transaction.Commit();
|
||
|
||
Task task = Task.Factory.StartNew(() =>
|
||
{
|
||
Transaction transaction = new Transaction();
|
||
//解析日结json数组
|
||
List<Model.EXCHANGE.ENDACCOUNT_NEW> _DataEndaccount_new =
|
||
JsonHelper.JSONStringToListUTC<Model.EXCHANGE.ENDACCOUNT_NEW>(jsonString);
|
||
foreach (Model.EXCHANGE.ENDACCOUNT_NEW _EndAccountNew in _DataEndaccount_new)
|
||
{
|
||
if (_EndAccountNew.ENDACCOUNT_TYPE == 1)
|
||
{
|
||
//比较自然日结账报表中的移动支付金额和第三方返回的到账金额
|
||
Method.BankAccountHelper.BankAccountCompare(transaction,
|
||
_EndAccountNew.ENDDATE.Value.AddDays(-1).ToString("yyyy-MM-dd"),
|
||
_EndAccountNew.SERVERPARTCODE, _EndAccountNew.SHOPCODE, _EndAccountNew.MACHINECODE);
|
||
}
|
||
else if (_EndAccountNew.ENDACCOUNT_TYPE == 2)
|
||
{
|
||
//比较自然日结账报表中的移动支付金额和第三方返回的到账金额
|
||
Method.BankAccountHelper.BankAccountCompare(transaction,
|
||
_EndAccountNew.ENDDATE.Value.ToString("yyyy-MM-dd"),
|
||
_EndAccountNew.SERVERPARTCODE, _EndAccountNew.SHOPCODE, _EndAccountNew.MACHINECODE);
|
||
}
|
||
}
|
||
//提交事务,并释放资源
|
||
transaction.Commit();
|
||
transaction.Dispose();
|
||
transaction.Release();
|
||
});
|
||
|
||
strBack = "{\"error\": 1 ,\"msg\": \"添加成功!\",\"rows\":[]}";
|
||
}
|
||
else
|
||
{
|
||
_Transaction.Rollback();
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
}
|
||
#endregion
|
||
break;
|
||
case "HIGHWAY_EXCHANGE.T_ENDACCOUNT":
|
||
#region HIGHWAY_EXCHANGE.T_ENDACCOUNT结账报表【旧表】
|
||
//必填项
|
||
_RequiredDatas = new string[]
|
||
{
|
||
"TRANSFER_ID",
|
||
"ENDACCOUNT_STARTDATE",
|
||
"ENDACCOUNT_DATE",
|
||
"SERVERPARTCODE",
|
||
"SHOPCODE",
|
||
"MACHINECODE" ,
|
||
"FLAG"
|
||
};
|
||
_ISCheckData = ISCheckData(jsonString, _RequiredDatas);
|
||
if (_ISCheckData != null)
|
||
{
|
||
strBack = _ISCheckData;
|
||
break;
|
||
}
|
||
if (DataTransfer.UploadEndaccount(_Transaction, jsonString, 0))
|
||
{
|
||
_Transaction.Commit();
|
||
strBack = "{\"error\": 1 ,\"msg\": \"添加成功!\",\"rows\":[]}";
|
||
}
|
||
else
|
||
{
|
||
_Transaction.Rollback();
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
}
|
||
#endregion
|
||
break;
|
||
|
||
case "HIGHWAY_EXCHANGE.T_PERSONSELL_NEW":
|
||
#region HIGHWAY_EXCHANGE.T_PERSONSELL_NEW 收银交班表
|
||
//必填项
|
||
_RequiredDatas = new string[]
|
||
{
|
||
"TRANSFER_ID",
|
||
"SERVERPARTCODE",
|
||
"ENDACCOUNT_CODE",
|
||
"WOKER_NUMBER",
|
||
"STARTDATE",
|
||
"ENDDATE"
|
||
};
|
||
_ISCheckData = ISCheckData(jsonString, _RequiredDatas);
|
||
if (_ISCheckData != null)
|
||
{
|
||
strBack = _ISCheckData;
|
||
break;
|
||
}
|
||
if (DataTransfer.UploadPersonSell(_Transaction, jsonString, 1))
|
||
{
|
||
_Transaction.Commit();
|
||
strBack = "{\"error\": 1 ,\"msg\": \"添加成功!\",\"rows\":[]}";
|
||
}
|
||
else
|
||
{
|
||
_Transaction.Rollback();
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
}
|
||
#endregion
|
||
break;
|
||
case "HIGHWAY_EXCHANGE.T_PERSONSELL":
|
||
#region HIGHWAY_EXCHANGE.T_PERSONSELL 收银员交班表【旧表】
|
||
//必填项
|
||
_RequiredDatas = new string[] { "TRANSFER_ID", "SERVERPARTCODE", "STARTDATE", "ENDDATE" };
|
||
_ISCheckData = ISCheckData(jsonString, _RequiredDatas);
|
||
if (_ISCheckData != null)
|
||
{
|
||
strBack = _ISCheckData;
|
||
break;
|
||
}
|
||
if (DataTransfer.UploadPersonSell(_Transaction, jsonString, 0))
|
||
{
|
||
_Transaction.Commit();
|
||
strBack = "{\"error\": 1 ,\"msg\": \"添加成功!\",\"rows\":[]}";
|
||
}
|
||
else
|
||
{
|
||
_Transaction.Rollback();
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
}
|
||
#endregion
|
||
break;
|
||
default:
|
||
strBack = "{\"error\": -1 ,\"msg\": \"数据上传表类型不正确\",\"rows\":[]}";
|
||
break;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
strBack = "{\"error\": -1 ,\"msg\": \"添加失败:" + ex.Message + "\",\"rows\":[]}";
|
||
}
|
||
return strBack;
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 检查必要参数
|
||
/// <summary>
|
||
/// 检查必要参数
|
||
/// </summary>
|
||
/// <param name="jsonString"></param>
|
||
/// <param name="_RequiredDatas"></param>
|
||
/// <returns></returns>
|
||
private static string ISCheckData(string jsonString, string[] _RequiredDatas, int maxDataQuantity = 4)
|
||
{
|
||
if (!string.IsNullOrEmpty(jsonString))
|
||
{
|
||
JArray _JsonArray = JArray.Parse(jsonString);
|
||
if (_JsonArray.Count > maxDataQuantity * 100)
|
||
{
|
||
return string.Format("{{\"error\": -1 ,\"msg\": \"添加失败:json数据包不可超过{0}条数据\",\"rows\":[]}}", maxDataQuantity * 100);
|
||
}
|
||
|
||
for (int i = 0; i < _JsonArray.Count; i++)
|
||
{
|
||
JObject _Json = JObject.Parse(_JsonArray[i].ToString());
|
||
foreach (string _RequiredData in _RequiredDatas)
|
||
{
|
||
if ((_Json.Property(_RequiredData.ToUpper()) == null &&
|
||
_Json.Property(_RequiredData.ToLower()) == null) ||
|
||
(_Json.Property(_RequiredData.ToUpper()) != null &&
|
||
_Json.Property(_RequiredData.ToUpper()).Value.ToString() == "") ||
|
||
(_Json.Property(_RequiredData.ToLower()) != null &&
|
||
_Json.Property(_RequiredData.ToLower()).Value.ToString() == ""))
|
||
{
|
||
return "{\"error\": -1 ,\"msg\": \"添加失败:第" + (i + 1) +
|
||
"组数据中,JSON缺少必要参数:" + _RequiredData + "\",\"rows\":[]}";
|
||
}
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
else
|
||
{
|
||
return "{\"error\": -1 ,\"msg\": \"添加失败:JSON参数解析异常!\",\"rows\":[]}";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 方法 -> 更新日结、交班、单品、稽核数据版本
|
||
/// <summary>
|
||
/// 更新日结、交班、单品、稽核数据版本
|
||
/// </summary>
|
||
/// <param name="_OracleHelper">数据库操作类</param>
|
||
/// <param name="ServerPartCode">服务区编码</param>
|
||
/// <param name="ShopCode">门店编码</param>
|
||
/// <param name="MachineCode">机器编码</param>
|
||
/// <param name="TableName">表名</param>
|
||
/// <param name="DataVersion">最新数据版本</param>
|
||
/// <returns>error:1、成功;-1、失败</returns>
|
||
public static string UpdateDataVersion(OracleHelper _OracleHelper, string ServerPartCode, string ShopCode, string MachineCode, string TableName, DateTime DataVersion)
|
||
{
|
||
if (string.IsNullOrEmpty(ServerPartCode) || string.IsNullOrEmpty(ShopCode) || string.IsNullOrEmpty(MachineCode) || string.IsNullOrEmpty(TableName) || DataVersion == null)
|
||
{
|
||
return "{\"error\": -1 ,\"msg\": \"参数错误\"}";
|
||
}
|
||
//判断数据版本表中是否已经含有对应的数据版本记录
|
||
string Sql = "SELECT DATAVERSION_ID,DATAVERSION FROM HIGHWAY_EXCHANGE.T_DATAVERSION WHERE SERVERPARTCODE='" + ServerPartCode + "' " +
|
||
"AND SHOPCODE='" + ShopCode + "' AND MACHINECODE='" + MachineCode + "' AND TABLENAME='" + TableName + "'";
|
||
DataSet ds_endcount = _OracleHelper.ExcuteSqlGetDataSet(Sql);
|
||
int SqlState = 0;//表示是否要执行添加或者更新操作,1:执行;0:不执行
|
||
if (ds_endcount == null || ds_endcount.Tables.Count == 0 || ds_endcount.Tables[0].Rows.Count == 0)
|
||
{
|
||
//新增数据
|
||
SqlState = 1;
|
||
Sql = string.Format(@"INSERT INTO HIGHWAY_EXCHANGE.T_DATAVERSION(DATAVERSION_ID,SERVERPARTCODE,SHOPCODE,MACHINECODE,TABLENAME,DATAVERSION)
|
||
VALUES(HIGHWAY_EXCHANGE.SEQ_DATAVERSION.NEXTVAL,'{0}','{1}','{2}','{3}',TO_DATE('{4}','YYYY-MM-DD HH24:MI:SS'))", ServerPartCode
|
||
, ShopCode, MachineCode, TableName, DataVersion.ToString());
|
||
}
|
||
else
|
||
{
|
||
//更新操作
|
||
if (DataVersion > Convert.ToDateTime(ds_endcount.Tables[0].Rows[0][1].ToString()))
|
||
{
|
||
SqlState = 1;
|
||
Sql = string.Format(@"UPDATE HIGHWAY_EXCHANGE.T_DATAVERSION SET DATAVERSION=TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS') WHERE
|
||
DATAVERSION_ID='{1}'", DataVersion.ToString(), ds_endcount.Tables[0].Rows[0][0].ToString());
|
||
}
|
||
}
|
||
//释放资源
|
||
if (ds_endcount != null)
|
||
{
|
||
ds_endcount.Clear();
|
||
ds_endcount.Dispose();
|
||
}
|
||
if (SqlState == 1)
|
||
{
|
||
object resultRows = _OracleHelper.ExcuteSqlBackData(Sql);
|
||
if (Convert.ToInt32(resultRows) > 0)
|
||
{
|
||
return "{\"error\": 1 ,\"msg\": \"更新成功!\"}";
|
||
}
|
||
}
|
||
return "{\"error\": 1 ,\"msg\": \"更新失败!\"}";
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
} |