2025-03-28 09:49:56 +08:00

178 lines
9.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HZQR.Common;
using Quartz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using MSPB = SuperMap.RealEstate.MobileServicePlatform.Business;
using SuperMap.RealEstate.CoreFrameWork;
using SuperMap.RealEstate.ServiceModel;
using SuperMap.RealEstate.Utility;
using SuperMap.RealEstate.Web.UI;
using SuperMap.RealEstate.Web.UI.WebControls;
using SuperMap.RealEstate.Web.Utility;
using JobApplication.Models;
using Newtonsoft.Json.Linq;
using System.Configuration;
namespace JobApplication
{
/// <summary>
/// 实现IJob接口
/// </summary>
class SysncEndAccount : IJob
{
SuperMap.RealEstate.ServiceModel.Transaction Transaction = new SuperMap.RealEstate.ServiceModel.Transaction();
string distributedProvinceCode = ConfigurationManager.AppSettings["distributedProvinceCode"];//获取配置文件中的分布在各省份的省份编码
string cloudsProvinceCode = ConfigurationManager.AppSettings["cloudsProvinceCode"];//获取配置文件中的部署在云端的省份编码
static string OracleConnCM = ConfigurationManager.ConnectionStrings["Coop_Merchant"].ConnectionString;
static OracleHelper oracleHelperCm = new OracleHelper(OracleConnCM);
void IJob.Execute(IJobExecutionContext context)
{
//各省份服务器的地址
LogUtil.WriteLog("job执行省份" + distributedProvinceCode);
try
{
foreach (string provinceCode in distributedProvinceCode.Split(','))
{
//同步各省份的结账表
SysncEndAccountData(provinceCode);
}
}
catch (Exception ex)
{
SuperMap.RealEstate.Utility.ErrorLogHelper.Write(ex, "SysncRevenueData", "调用接口同步结账单表");
}
//按自然日固化移动支付流水 JOB 开始
//FixedRevenueByNaturalDay();
}
#region SQL语句中用到的字段转换
public string GetSqlColumn(double? Column)
{
string val = Column == null ? "NULL" : Column.ToString();
return val;
}
public string GetSqlColumn(int? Column)
{
string val = Column == null ? "NULL" : Column.ToString();
return val;
}
#endregion
#region ->
/// <summary>
/// 同步结账单表
/// </summary>
/// <param name="provinceCode">省份编码(根据省份同步结账数据)</param>
public void SysncEndAccountData(string provinceCode)
{
//string beginDate = DateTime.Now.AddDays(-1).ToShortDateString();
string beginDate = "2020-7-01";
string endDate = DateTime.Now.ToString();
//判断已同步的最新的时间
string sql = string.Format(@"
SELECT MAX(DOWNLOAD_DATE) AS DOWNLOAD_DATE FROM HIGHWAY_SELLDATA.T_ENDACCOUNT
WHERE PROVINCE_CODE={0}", provinceCode);
DataTable dtTime = oracleHelperCm.ExcuteSqlGetDataSet(sql).Tables[0];//同步的数据的最新的时间
if (dtTime.Rows.Count > 0)
{
if (!string.IsNullOrEmpty(dtTime.Rows[0]["DOWNLOAD_DATE"].ToString()))
{
//已经同步过的时间GetEndAcountList接口DOWNLOAD_DATE时间比较为>=以防会重复加1秒
beginDate = Convert.ToDateTime(dtTime.Rows[0]["DOWNLOAD_DATE"]).AddSeconds(1).ToString();
LogUtil.WriteLog("同步结账单,更新时间=" + beginDate);
}
}
string _BaseUrl = ConfigurationManager.AppSettings[provinceCode];
string PostStr = string.Format("startDownLoadDate={0}&endDownLoadDate={1}&province_Code={2}",
beginDate, endDate, provinceCode);
string RequestUrl = _BaseUrl + "?action_type=GetEndAcountList&" + PostStr;
string format = "application/json;charset=UTF-8";
LogUtil.WriteLog("同步结账单,"+ provinceCode + "=" + RequestUrl);
string val = HttpHelper.HttpUrlPost(PostStr, RequestUrl, format, 0);
JObject jObj = new JObject();
jObj = JObject.Parse(val);
List<EndAccount> listResult = new List<EndAccount>();
listResult = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EndAccount>>
(jObj["Result_Data"]["List"].ToString()).ToList();
LogUtil.WriteLog("同步结账单listResult" + listResult.Count);
string Create_Date = DateTime.Now.ToString();
List<string> syncSqlList = new List<string>();
listResult.ForEach(o =>
{
try
{
string syncSql = string.Format(@"
INSERT INTO HIGHWAY_SELLDATA.T_ENDACCOUNT
(
ENDACCOUNT_ID,SERVERPART_ID,SERVERPART_CODE,SERVERPART_NAME,PROVINCE_CODE,
ENDACCOUNT_DATE,STATISTICS_DATE,ENDACCOUNT_STARTDATE,
SERVERPARTSHOP_ID,SERVERPARTSHOP_CODE,SERVERPARTSHOP_NAME,MACHINECODE,
ENDPERSONCODE,WORKER_NAME,CASHIER_NAME,TICKETCOUNT,TOTALCOUNT,TOTALSELLAMOUNT,TOTALOFFAMOUNT,
CASH,CREDITCARD,TICKETBILL,VIPPERSON,COSTBILL,OTHERPAY,REVENUE_AMOUNT,CASH_PAYMENT,
DIFFERENT_PRICE,DIFFERENCE_REASON,DESCRIPTION_STAFF,DESCRIPTION_DATE,
APPROVE_STAFF,APPROVE_DATE,APPROVED_INFO,
TREATMENT_MARK,DOWNLOAD_DATE,VALID,ENDACCOUNT_DESC,OPERATE_TYPE,
TICKET_COUNT,FACT_AMOUNT,SELLCOUNT_CIGARETTE,FACTAMOUNT_CIGARETTE,
SPOT_CHECK,REGIONAL_CHECK,COMPANY_CHECK,CHECK_COUNT,CHECK_INFO,
CASH_CORRECT,MOBILE_CORRECT,SALE_CORRECT,CORRECT_AMOUNT,ONLINETICKET,ONLINEAMOUNT)
VALUES
(
{0},{1},'{2}','{3}',{4},{5},{6},{7},
{8},'{9}','{10}','{11}','{12}','{13}','{14}',{15},{16},{17},{18},
{19},{20},{21},{22},{23},{24},{25},{26},
{27},'{28}','{29}',{30},'{31}',{32},'{33}',
{34},TO_DATE('{35}','YYYY-MM-DD HH24:MI:SS'),{36},'{37}',{38},
{39},{40},{41},{42},{43},{44},{45},{46},'{47}',{48},{49},{50},{51},{52},{53})",
o.EndAccount_Id, o.ServerPart_Id, o.ServerPart_Code, o.ServerPart_Name, provinceCode,//{0}-{4}
o.EndAccount_Date == null ? "NULL" : "TO_DATE('" + o.EndAccount_Date + "','YYYY-MM-DD HH24:MI:SS')", //{5}
o.Statistics_Date == null ? "NULL" : "TO_DATE('" + o.Statistics_Date + "','YYYY-MM-DD HH24:MI:SS')",//{6}
o.EndAccount_StartDate == null ? "NULL" : "TO_DATE('" + o.EndAccount_StartDate + "','YYYY-MM-DD HH24:MI:SS')",//{7}
o.ServerPartShop_Id, o.ServerPartShop_Code, o.ServerPartShop_Name, o.MachineCode,//{8}-{11}
o.EndPersonCode, o.Worker_Name, o.Cashier_Name,//{12}-{14}
GetSqlColumn(o.TicketCount), GetSqlColumn(o.TotalCount), GetSqlColumn(o.TotalSellAmount),//{15}-{17}
GetSqlColumn(o.TotalOffAmount), GetSqlColumn(o.Cash), GetSqlColumn(o.CreditCard),//{18}-{20}
GetSqlColumn(o.TicketBill), GetSqlColumn(o.VipPerson), GetSqlColumn(o.CostBill), //{21}-{23}
GetSqlColumn(o.OtherPay), GetSqlColumn(o.Revenue_Amount), GetSqlColumn(o.Cash_PayMent),//{24}-{26}
GetSqlColumn(o.Different_Price), o.Difference_Reason, o.Description_Staff,//{27}-{29}
o.Description_Date == null ? "NULL" : "TO_DATE('" + o.Description_Date + "', 'YYYY-MM-DD HH24:MI:SS')",//{30}
o.Approve_Staff,
o.Approve_Date == null ? "NULL" : "TO_DATE('" + o.Approve_Date + "', 'YYYY-MM-DD HH24:MI:SS')",//{32}
o.Approved_Info,GetSqlColumn(o.Treatment_Mark), o.Download_Date, //{33}{34}{35}
GetSqlColumn(o.Valid),o.EndAccount_Desc, GetSqlColumn(o.Operate_Type),//{36}{37}{38}
GetSqlColumn(o.Ticket_Count), GetSqlColumn(o.Fact_Amount), //{39}-{40}
GetSqlColumn(o.SellCount_Cigarette), GetSqlColumn(o.FactAmount_Cigarette), //{41}-{42}
GetSqlColumn(o.Spot_Check), GetSqlColumn(o.Regional_Check), GetSqlColumn(o.Company_Check), //{43}-{46}
GetSqlColumn(o.Check_Count), o.Check_Info,//{46}-{47}
GetSqlColumn(o.Cash_Correct), GetSqlColumn(o.Mobile_Correct), GetSqlColumn(o.Sale_Correct), //{48}-{53}
GetSqlColumn(o.Correct_Amount), GetSqlColumn(o.OnlineTicket), GetSqlColumn(o.OnlineAmount));
syncSqlList.Add(syncSql);
}
catch (Exception ex)
{
SuperMap.RealEstate.Utility.ErrorLogHelper.Write(ex, "SysncRevenueData", "同步结账单表");
}
});
LogUtil.WriteLog("同步结账单Start");
oracleHelperCm.ExecuteSqlTran(syncSqlList.ToArray()); //同步到合作商户结账单表
LogUtil.WriteLog("同步结账单End");
}
#endregion
}
}