306 lines
17 KiB
C#
306 lines
17 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using SuperMap.RealEstate.ServiceModel;
|
||
using HWSB = SuperMap.RealEstate.HighWay.Storage.Business;
|
||
using Newtonsoft.Json.Linq;
|
||
using Newtonsoft.Json;
|
||
using HZQR.Common;
|
||
|
||
namespace DataBaseProcessing
|
||
{
|
||
static class Program
|
||
{
|
||
/// <summary>
|
||
/// 应用程序的主入口点。
|
||
/// </summary>
|
||
//[STAThread]
|
||
//static void Main()
|
||
//{
|
||
// Application.EnableVisualStyles();
|
||
// Application.SetCompatibleTextRenderingDefault(false);
|
||
// Application.Run(new MainForm());
|
||
//}
|
||
|
||
//static async Task Main()
|
||
//{
|
||
// Transaction transaction = new Transaction();
|
||
// string SQLString = "WHERE PROVINCE_CODE = 3544 AND STATISTIC_TYPE = 1000 AND STATISTICS_TYPE = 1000 AND SPREGIONTYPE_ID <> 89";
|
||
// DataTable dtServerpart = new HWSB.SERVERPART(transaction).FillDataTable(SQLString);
|
||
|
||
// // 假设有多个服务区,一起计算
|
||
// var serviceAreas = dtServerpart.AsEnumerable().Select(o => o["SERVERPART_ID"].ToString()).ToList(); // 服务区ID列表
|
||
// var dates = new List<DateTime>
|
||
// {
|
||
// DateTime.Now.AddMonths(-1),
|
||
// //DateTime.Now.AddDays(-2),
|
||
// //DateTime.Now.AddDays(-3)
|
||
// };
|
||
|
||
// // 进行多个服务区的数据汇总并分析
|
||
// await TestForm.AnalyzeMultipleServiceAreas(serviceAreas, dates);
|
||
|
||
// transaction.Release();
|
||
// transaction.Dispose();
|
||
//}
|
||
|
||
// 主函数,程序的入口
|
||
//public static void Main(string[] args)
|
||
//{
|
||
// // 模拟通过API传递的月份参数,例如"September"
|
||
// string month = "September";
|
||
|
||
// // 调用API获取车辆数和总营收数据(在真实场景中,这部分可以由HTTP请求实现)
|
||
// var data = TestForm.FetchDataForMonth("202401", "202409", "419");
|
||
|
||
// // 将API获取到的数据进行处理并计算单车价值
|
||
// TestForm.CalculateSingleVehicleValue(data);
|
||
//}
|
||
|
||
//static void Main()
|
||
//{
|
||
// Transaction transaction = new Transaction();
|
||
// try
|
||
// {
|
||
// List<HWSB.SERVERPART> SERVERPARTList = new HWSB.SERVERPART(transaction).FillCollection(
|
||
// "WHERE PROVINCE_CODE = 3544 AND STATISTICS_TYPE = 1000 AND STATISTIC_TYPE = 1000 AND SPREGIONTYPE_ID NOT IN (89) " +
|
||
// "ORDER BY SPREGIONTYPE_INDEX,SPREGIONTYPE_ID,SERVERPART_INDEX,SERVERPART_CODE");
|
||
// string ServerpartId = string.Join(",", SERVERPARTList.Select(o => o.KeyID));
|
||
|
||
// int StatisticsMonth = 202412;
|
||
// string month = StatisticsMonth % 100 + "月"; // 月份
|
||
// // 模拟传入的参数:月份、总营收、各省份车辆数
|
||
// string selectedSQL;
|
||
// string SQLString = string.Format(@"SELECT SERVERPART_ID,SUM(REVENUE_AMOUNT) AS REVENUE_AMOUNT
|
||
// FROM PLATFORM_DASHBOARD.T_REVENUEMONTHLY
|
||
// WHERE SERVERPART_ID IN ({0}) AND STATISTICS_MONTH = {1}
|
||
// GROUP BY SERVERPART_ID", ServerpartId, StatisticsMonth);
|
||
// DataTable dtRevenue = new HWSB.SERVERPART(transaction).ExecuteDataTable(SQLString);
|
||
// SQLString = string.Format(@"SELECT
|
||
// SERVERPART_ID,PROVINCE_NAME,VEHICLE_TYPE,SUM(VEHICLE_COUNT) AS VEHICLE_COUNT
|
||
// FROM HIGHWAY_SELLDATA.T_BAYONETOWMONTHLY_AH
|
||
// WHERE SERVERPART_ID IN ({0}) AND STATISTICS_MONTH = {1}
|
||
// GROUP BY SERVERPART_ID,PROVINCE_NAME,VEHICLE_TYPE", ServerpartId, StatisticsMonth);
|
||
// DataTable dtBayonet = new HWSB.SERVERPART(transaction).ExecuteDataTable(SQLString);
|
||
|
||
// foreach (HWSB.SERVERPART _SERVERPART in SERVERPARTList)
|
||
// {
|
||
// LogUtil.WriteLog($"开始模拟{ _SERVERPART.SERVERPART_NAME }【{ _SERVERPART.SPREGIONTYPE_NAME }】");
|
||
|
||
// selectedSQL = "SERVERPART_ID = " + _SERVERPART.KeyID;
|
||
// // 总营收(替换为实际数据)
|
||
// double totalRevenue = dtRevenue.Compute("sum(REVENUE_AMOUNT)", selectedSQL).TryParseToDouble().Round(2);
|
||
|
||
// if (totalRevenue <= 0) continue;
|
||
// // 总车辆数(替换为实际数据)
|
||
// int totalVehicleCount = dtBayonet.Compute("sum(VEHICLE_COUNT)", selectedSQL).TryParseToInt();
|
||
|
||
// // 各省份车辆数(实际应用中从API或输入获取)
|
||
// Dictionary<string, Dictionary<string, int>> provinceVehicleCounts =
|
||
// new Dictionary<string, Dictionary<string, int>>();
|
||
// //{
|
||
// // { "安徽省", new Dictionary<string, int> {{"Small",99732},{"Medium",0},{"Large",17632}} },
|
||
// // { "江苏省", new Dictionary<string, int> {{"Small",45699},{"Medium",0},{ "Large",9118}} },
|
||
// // { "河南省", new Dictionary<string, int> {{"Small",23808},{"Medium",0},{ "Large",5422}} },
|
||
// // { "浙江省", new Dictionary<string, int> {{"Small",19334},{"Medium",0},{"Large",2137}} },
|
||
// // { "湖北省", new Dictionary<string, int> {{"Small",9689},{"Medium",0},{"Large",2277}} },
|
||
// // { "上海市", new Dictionary<string, int> {{"Small",7076},{"Medium",0},{"Large",2731}} },
|
||
// // { "山东省", new Dictionary<string, int> {{"Small",3889},{"Medium",0},{"Large",3768}} },
|
||
// // { "河北省", new Dictionary<string, int> {{"Small",1375},{"Medium",0},{"Large",1465}} },
|
||
// // { "江西省", new Dictionary<string, int> {{"Small",612},{"Medium",0},{"Large",1607}} },
|
||
// // { "广东省", new Dictionary<string, int> {{"Small",1863},{"Medium",0},{"Large",190}} },
|
||
// // { "湖南省", new Dictionary<string, int> {{"Small",997},{"Medium",0},{"Large",175}} },
|
||
// // { "山西省", new Dictionary<string, int> {{"Small",414},{"Medium",0},{"Large",754}} },
|
||
// // { "辽宁省", new Dictionary<string, int> {{"Small",432},{"Medium",0},{"Large",587}} },
|
||
// // { "福建省", new Dictionary<string, int> {{"Small",582},{"Medium",0},{"Large",272}} },
|
||
// // { "北京市", new Dictionary<string, int> {{"Small",590},{"Medium",0},{"Large",153}} },
|
||
// // { "其他省份", new Dictionary<string, int> {{"Small",38453},{"Medium",0},{"Large",12864}} }
|
||
// //};
|
||
|
||
// var summaryList = from t in dtBayonet.Select(selectedSQL).AsEnumerable()
|
||
// group t by new
|
||
// {
|
||
// t0 = t.Field<string>("PROVINCE_NAME"),
|
||
// } into m
|
||
// select new
|
||
// {
|
||
// PROVINCE_NAME = m.Key.t0,
|
||
// VEHICLE_COUNT = m.Sum(o => o["VEHICLE_COUNT"].TryParseToInt()),
|
||
// };
|
||
// foreach (var BayonetObj in summaryList.ToList().OrderByDescending(o => o.VEHICLE_COUNT))
|
||
// {
|
||
// switch (BayonetObj.PROVINCE_NAME)
|
||
// {
|
||
// case "安徽省":
|
||
// case "江苏省":
|
||
// case "山东省":
|
||
// case "河南省":
|
||
// case "浙江省":
|
||
// case "河北省":
|
||
// case "江西省":
|
||
// case "湖北省":
|
||
// case "广东省":
|
||
// case "上海市":
|
||
// case "福建省":
|
||
// case "湖南省":
|
||
// case "辽宁省":
|
||
// case "山西省":
|
||
// case "北京市":
|
||
// selectedSQL = "SERVERPART_ID = " + _SERVERPART.KeyID + " and PROVINCE_NAME = '" +
|
||
// BayonetObj.PROVINCE_NAME + "' and VEHICLE_TYPE ";
|
||
// //各个车型的数据汇总
|
||
// Dictionary<string, int> vehicleTypeCounts = new Dictionary<string, int>();
|
||
// vehicleTypeCounts.Add("Small", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " = '小型车'").TryParseToInt());
|
||
// vehicleTypeCounts.Add("Medium", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " = '中型车'").TryParseToInt());
|
||
// vehicleTypeCounts.Add("Large", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " like '大%'").TryParseToInt());
|
||
|
||
// provinceVehicleCounts.Add(BayonetObj.PROVINCE_NAME, vehicleTypeCounts);
|
||
// break;
|
||
// }
|
||
// }
|
||
|
||
// int curTotalCount = provinceVehicleCounts.Sum(o => o.Value.Sum(s => s.Value));
|
||
// if (totalVehicleCount != curTotalCount)
|
||
// {
|
||
// selectedSQL = "SERVERPART_ID = " + _SERVERPART.KeyID + " and VEHICLE_TYPE ";
|
||
// //各个车型的数据汇总
|
||
// Dictionary<string, int> vehicleTypeCounts = new Dictionary<string, int>();
|
||
// vehicleTypeCounts.Add("Small", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " = '小型车'").TryParseToInt() - provinceVehicleCounts.Sum(o => o.Value["Small"]));
|
||
// vehicleTypeCounts.Add("Medium", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " = '中型车'").TryParseToInt() - provinceVehicleCounts.Sum(o => o.Value["Medium"]));
|
||
// vehicleTypeCounts.Add("Large", dtBayonet.Compute("sum(VEHICLE_COUNT)",
|
||
// selectedSQL + " like '大%'").TryParseToInt() - provinceVehicleCounts.Sum(o => o.Value["Large"]));
|
||
// provinceVehicleCounts.Add("其他省份", vehicleTypeCounts);
|
||
// }
|
||
|
||
// // 调用计算流程
|
||
// List<Model.VEHICLEAMOUNTModel> resultList = new List<Model.VEHICLEAMOUNTModel>();
|
||
// TestForm.CalculateVehicleValues(month, totalRevenue, totalVehicleCount, provinceVehicleCounts, ref resultList);
|
||
// foreach (Model.VEHICLEAMOUNTModel vehicleamountModel in resultList)
|
||
// {
|
||
// SQLString = string.Format($@"INSERT INTO PLATFORM_DASHBOARD.T_VEHICLEAMOUNT (
|
||
// VEHICLEAMOUNT_ID,STATISTICS_MONTH,SERVERPART_ID,SERVERPART_NAME,PROVINCE_NAME,
|
||
// VEHICLE_TYPE,VEHICLE_COUNT,PERCAPITA_INCOME,CONSUMPTION_COEFFICIENT,VEHICLE_AMOUNT,
|
||
// ADJUST_COUNT,VEHICLE_ADJAMOUNT,REVENUE_ADJAMOUNT,REVENUE_ACTAMOUNT,VEHICLE_TOTALCOUNT)
|
||
// VALUES (PLATFORM_DASHBOARD.SEQ_VEHICLEAMOUNT.NEXTVAL,
|
||
// { StatisticsMonth },{ _SERVERPART.KeyID },'{ _SERVERPART.SERVERPART_NAME }',
|
||
// '{ vehicleamountModel.PROVINCE_NAME }','{ vehicleamountModel.VEHICLE_TYPE }',
|
||
// { (vehicleamountModel.VEHICLE_COUNT == null ? "NULL" : vehicleamountModel.VEHICLE_COUNT + "") },
|
||
// { (vehicleamountModel.PERCAPITA_INCOME == null ? "NULL" : vehicleamountModel.PERCAPITA_INCOME + "") },
|
||
// { (vehicleamountModel.CONSUMPTION_COEFFICIENT == null ? "NULL" : vehicleamountModel.CONSUMPTION_COEFFICIENT + "") },
|
||
// { (vehicleamountModel.VEHICLE_AMOUNT == null ? "NULL" : vehicleamountModel.VEHICLE_AMOUNT + "") },
|
||
// { (vehicleamountModel.ADJUST_COUNT == null ? "NULL" : vehicleamountModel.ADJUST_COUNT + "") },
|
||
// { (vehicleamountModel.VEHICLE_ADJAMOUNT == null ? "NULL" : vehicleamountModel.VEHICLE_ADJAMOUNT + "") },
|
||
// { (vehicleamountModel.REVENUE_ADJAMOUNT == null ? "NULL" : vehicleamountModel.REVENUE_ADJAMOUNT.Value.Round(2) + "") },
|
||
// { (vehicleamountModel.REVENUE_ACTAMOUNT == null ? "NULL" : vehicleamountModel.REVENUE_ACTAMOUNT + "") },
|
||
// { (vehicleamountModel.VEHICLE_TOTALCOUNT == null ? "NULL" : vehicleamountModel.VEHICLE_TOTALCOUNT + "") })");
|
||
// _SERVERPART.ExecuteNonQuery(SQLString, null);
|
||
// }
|
||
// //break;
|
||
// }
|
||
// transaction.Commit();
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// LogUtil.WriteLog(ex);
|
||
// }
|
||
// finally
|
||
// {
|
||
// transaction.Release();
|
||
// transaction.Dispose();
|
||
// }
|
||
//}
|
||
|
||
public static void Main(string[] args)
|
||
{
|
||
// 异步获取 Token
|
||
var token = GetPNTokenAsync().Result;
|
||
Console.WriteLine("Token: " + token);
|
||
}
|
||
|
||
public static async Task<string> GetPNTokenAsync()
|
||
{
|
||
string Access_Token = "";
|
||
try
|
||
{
|
||
string url = "http://test.api.pinuoc.com/access-token";
|
||
|
||
using (var client = new HttpClient())
|
||
{
|
||
// 设置超时时间为 300 秒(可以根据需要调整)
|
||
client.Timeout = TimeSpan.FromSeconds(300); // 设置超时为 300 秒
|
||
|
||
// 构造表单数据
|
||
var formData = new MultipartFormDataContent
|
||
{
|
||
{ new StringContent("1000070"), "appid" },
|
||
{ new StringContent("rdrel"), "appsecret" },
|
||
{ new StringContent("KMCYYG70"), "mchid" }
|
||
};
|
||
|
||
try
|
||
{
|
||
// 发送同步的 POST 请求
|
||
HttpResponseMessage response = await client.PostAsync(url, formData);
|
||
response.EnsureSuccessStatusCode(); // 确保响应成功
|
||
|
||
// 读取并输出响应内容
|
||
string result = await response.Content.ReadAsStringAsync();
|
||
|
||
// 解析响应数据
|
||
JObject keyValuePairs = JObject.Parse(result);
|
||
|
||
if (keyValuePairs["code"].ToString() == "200")
|
||
{
|
||
Access_Token = keyValuePairs["data"]["token"].ToString();
|
||
Console.WriteLine("Access Token: " + Access_Token);
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine("Failed to retrieve token. Response: " + result);
|
||
}
|
||
}
|
||
catch (TimeoutException e)
|
||
{
|
||
// 捕获超时异常
|
||
Console.WriteLine("Request Timeout: " + e.Message);
|
||
// 记录超时异常详细信息
|
||
LogUtil.WriteLog($"Timeout occurred: {e.Message}");
|
||
}
|
||
catch (HttpRequestException e)
|
||
{
|
||
// 捕获 HTTP 请求异常
|
||
Console.WriteLine("HTTP Request Error: " + e.Message);
|
||
// 记录 HTTP 请求异常详细信息
|
||
LogUtil.WriteLog($"HttpRequestException occurred: {e.Message}");
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
// 捕获其他类型的异常
|
||
Console.WriteLine("Error: " + e.Message);
|
||
// 记录其他异常详细信息
|
||
LogUtil.WriteLog($"Exception occurred: {e.Message}");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获外部异常
|
||
Console.WriteLine("An error occurred: " + ex.Message);
|
||
// 记录外部异常详细信息
|
||
LogUtil.WriteLog($"An error occurred: {ex.Message}");
|
||
}
|
||
|
||
return Access_Token;
|
||
}
|
||
}
|
||
}
|