This commit is contained in:
2025-04-07 21:06:39 +08:00
commit 461d514177
92 changed files with 12776 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilot_KD_Parino.Common
{
/// <summary>
/// 存储销售订单/应收单
/// </summary>
public class CombinaAddClass1
{
/// <summary>
/// 纸质合同号
/// </summary>
public string FCONTRACTNUMBER { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public int FClient { get; set; }
/// <summary>
/// 商务人员
/// </summary>
public int FCreated { get; set; }
/// <summary>
/// 销售员
/// </summary>
public int FSalesman { get; set; }
/// <summary>
/// 销售日期
/// </summary>
public string FDate { get; set; }
/// <summary>
/// 核销金额
/// </summary>
public decimal FALLAMOUNT { get; set; }
/// <summary>
/// 单据编号
/// </summary>
public string FBIllNO { get; set; }
/// <summary>
/// 类型
/// </summary>
public string FType { get; set; }
/// <summary>
/// 收款单列表
/// </summary>
public List<CombinaAddSK> SKList { get; set; } = new List<CombinaAddSK>();
}
/// <summary>
/// 存储收款单
/// </summary>
public class CombinaAddSK
{
/// <summary>
/// 纸质合同号
/// </summary>
public string FCONTRACTNUMBER { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public int FClient { get; set; }
/// <summary>
/// 商务人员
/// </summary>
public int FCreated { get; set; }
/// <summary>
/// 销售员
/// </summary>
public int FSalesman { get; set; }
/// <summary>
/// 收款日期
/// </summary>
public string FDate { get; set; }
/// <summary>
/// 核销金额
/// </summary>
public decimal FALLAMOUNT { get; set; }
/// <summary>
/// 收款单号
/// </summary>
public string FBIllNO { get; set; }
/// <summary>
/// 备注
/// </summary>
public string FRemark { get; set; }
/// <summary>
/// 销售订单/应收单列表
/// </summary>
public List<CombinaAddClass1> XSAPList { get; set; } = new List<CombinaAddClass1>();
}
}

View File

@@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilot_KD_Parino.Common
{
public class DataItem
{
/// <summary>
/// 单据编号
/// </summary>
public List<string> FBIllNO2 { get; set; }
/// <summary>
/// 纸质合同号
/// </summary>
public string FCONTRACTNUMBER2 { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public List<int> FClient2 { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public int FClient { get; set; }
/// <summary>
/// 项目名称
/// </summary>
public int FProject2 { get; set; }
/// <summary>
/// 制单人
/// </summary>
public int FCreated2 { get; set; }
/// <summary>
/// 备注
/// </summary>
public string FRemark2 { get; set; }
/// <summary>
/// 单据编号
/// </summary>
public List<string> FBIllNO { get; set; }
/// <summary>
/// 日期
/// </summary>
public string FDate { get; set; }
/// <summary>
/// 金额
/// </summary>
public double FALLAMOUNT { get; set; }
/// <summary>
/// 币别
/// </summary>
public int FCurr2 { get; set; }
/// <summary>
/// 金额(原币)
/// </summary>
public double FALLAMOUNTY2 { get; set; }
}
public class CombinaClass
{
/// <summary>
/// 行号
/// </summary>
public int FRow { get; set; }
/// <summary>
/// 行级
/// </summary>
public int F_RowNew { get; set; }
/// <summary>
/// 纸质合同号
/// </summary>
public string FCONTRACTNUMBER { get; set; }
/// <summary>
/// 客户名称
/// </summary>
public int FClient { get; set; }
/// <summary>
/// 项目名称
/// </summary>
public int FProject { get; set; }
/// <summary>
/// 制单人
/// </summary>
public int FCreated { get; set; }
/// <summary>
/// 币别
/// </summary>
public int FCurr { get; set; }
/// <summary>
/// 单据编号
/// </summary>
public string FBIllNO { get; set; }
/// <summary>
/// 单据编号(收款单)
/// </summary>
public string FSKBIllNO { get; set; }
/// <summary>
/// 日期
/// </summary>
public string FDate { get; set; }
/// <summary>
/// 是否核销配对
/// </summary>
public string FISHX { get; set; }
/// <summary>
/// 金额
/// </summary>
public double FALLAMOUNT { get; set; }
/// <summary>
/// 已核销金额
/// </summary>
public double FYAMOUNT { get; set; }
/// <summary>
/// 待核销金额
/// </summary>
public double FDAMOUNT { get; set; }
/// <summary>
/// 金额(原币)
/// </summary>
public double FALLAMOUNTY { get; set; }
/// <summary>
/// 是否超过30天
/// </summary>
public bool FIs30 { get; set; }
/// <summary>
/// 类型
/// </summary>
public string FType { get; set; }
/// <summary>
/// 备注
/// </summary>
public string FRemark { get; set; }
/// <summary>
/// 是否唯一
/// </summary>
public string FWeiYi { get; set; }
/// <summary>
/// 销售员
/// </summary>
public int FSalesman { get; set; }
}
}

View File

@@ -0,0 +1,192 @@
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilot_KD_Parino.Common
{
public class CombinationGenerator
{
public static List<DataItem> DeleteCombinationsDataByList(List<DataItem> List, List<string> FBILLNO)
{
foreach (var item in FBILLNO)
{
List.RemoveAll(t => t.FBIllNO.Contains(item));
}
return List;
}
public static List<DataItem> GetCombinationsDataByList(List<DataItem> List, double FAllAmount, int FClient)
{
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
}
public static List<DataItem> GetCombinationsDataByListTK(List<DataItem> List, double FAllAmount, int FClient)
{
var TestList = List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
foreach (var item in TestList)
{
var fbnumber = item.FBIllNO;
item.FBIllNO2 = fbnumber;
item.FBIllNO = new List<string>();
}
return TestList;
}
public static List<DataItem> GetCombinationsDataByList2(List<DataItem> List, double FAllAmount,int FClient)
{
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FBIllNO.Count == 1 && t.FClient2[0].Equals(FClient)).ToList();
}
/// <summary>
/// 计算取值
/// </summary>
/// <param name="List"></param>
/// <param name="index"></param>
/// <param name="FBILLNOLIST"></param>
/// <param name="result"></param>
/// <param name="FAllAmount"></param>
public static void GetCombinations(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
{
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
var FClient2 = new List<int>(FClient);
var item = List.GroupBy(a => a.FClient).ToList();
for (int i = index; i < List.Count; i++)
{
FBILLNOLIST2.Add(List[i].FBIllNO);
FClient2.Add(List[i].FClient);
DataItem DataItem = new DataItem();
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
DataItem.FClient2 = new List<int>(FClient2);
DataItem.FALLAMOUNT = FAllAmount + List[i].FALLAMOUNT;
result.Add(DataItem);
if (i < 9)
{
GetCombinations(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FALLAMOUNT);
}
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
}
}
/// <summary>
/// 计算取值
/// </summary>
/// <param name="List"></param>
/// <param name="index"></param>
/// <param name="FBILLNOLIST"></param>
/// <param name="result"></param>
/// <param name="FAllAmount"></param>
public static void GetCombinations2(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
{
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
var FClient2 = new List<int>(FClient);
var item = List.GroupBy(a => a.FClient).ToList();
for (int i = index; i < List.Count; i++)
{
FBILLNOLIST2.Add(List[i].FBIllNO);
FClient2.Add(List[i].FClient);
DataItem DataItem = new DataItem();
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
DataItem.FClient2 = new List<int>(FClient2);
DataItem.FALLAMOUNT = FAllAmount + List[i].FDAMOUNT;
result.Add(DataItem);
if (i < 10)
{
GetCombinations2(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FDAMOUNT);
}
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
}
}
public static List<List<T>> GetCombinations2<T>(T[] array)
{
List<double> FAllmount = new List<double>();
List<int> FDaySum = new List<int>();
List<List<T>> result = new List<List<T>>();
Combine2(array, 0, new List<T>(), FAllmount, FDaySum, ref result);
return result;
}
static void Combine2<T>(T[] array, int index, List<T> combination, List<double> FAllmount, List<int> FDaySum, ref List<List<T>> result)
{
for (int i = index; i < array.Length; i++)
{
combination.Add(array[i]);
Combine2(array, i + 1, combination, FAllmount, FDaySum, ref result);
combination.RemoveAt(combination.Count - 1); // 回溯
}
if (combination.Count > 0)
{
result.Add(new List<T>(combination));
}
}
public static List<string[]> GetCombinations(List<string[]> array)
{
List<string[]> result = new List<string[]>();
List<string> FIDList = new List<string>();
List<string> FEntryList = new List<string>();
List<double> FAllmount = new List<double>();
List<int> FDaySum = new List<int>();
Combine(array, 0, new List<string[]>(), FIDList, FEntryList, FAllmount, FDaySum, ref result);
return result;
}
static void Combine(List<string[]> array, int index, List<string[]> combination, List<string> FIDList, List<string> FEntryList,
List<double> FAllmount, List<int> FDaySum, ref List<string[]> result)
{
for (int i = index; i < array.Count; i++)
{
FIDList.Add(Convert.ToString(array[i][0]));
FEntryList.Add(Convert.ToString(array[i][3]));
FAllmount.Add(Convert.ToDouble(array[i][2]));
FDaySum.Add(CulDayByDate(Convert.ToDateTime(array[i][1]), DateTime.Now));
combination.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), "0", "0" });
Combine(array, i + 1, combination, FIDList, FEntryList, FAllmount, FDaySum, ref result);
//FIDList.RemoveAt(FIDList.Count - 1); // 回溯
//FEntryList.RemoveAt(FEntryList.Count - 1); // 回溯
//FAllmount.RemoveAt(combination.Count - 1); // 回溯
//FDaySum.RemoveAt(FDaySum.Count - 1); // 回溯
combination.RemoveAt(combination.Count - 1); // 回溯
}
//if (FIDList.Count > 0)
//{
result.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), FAllmount.Sum().ToString(), FDaySum.Sum().ToString() });
//}
}
/// <summary>
/// 计算两日期天数差
/// </summary>
/// <param name="date1"></param>
/// <param name="date2"></param>
/// <returns></returns>
public static int CulDayByDate(DateTime date1, DateTime date2)
{
TimeSpan difference = date2.Subtract(date1);
return difference.Days;
}
}
}

View File

@@ -0,0 +1,246 @@
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilot_KD_Parino.Common
{
public class CombinationGenerator_yuyubo
{
public static List<DataItem> DeleteCombinationsDataByList(List<DataItem> List, List<string> FBILLNO)
{
foreach (var item in FBILLNO)
{
List.RemoveAll(t => t.FBIllNO.Contains(item));
}
return List;
}
public static List<DataItem> GetCombinationsDataByList(List<DataItem> List, double FAllAmount, int FClient)
{
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
}
public static List<DataItem> GetCombinationsDataByListTK(List<DataItem> List, double FAllAmount, int FClient)
{
var TestList = List.Where(t => t.FALLAMOUNT == FAllAmount && t.FClient2.Contains(FClient)).ToList();
foreach (var item in TestList)
{
var fbnumber = item.FBIllNO;
item.FBIllNO2 = fbnumber;
item.FBIllNO = new List<string>();
}
return TestList;
}
public static List<DataItem> GetCombinationsDataByList2(List<DataItem> List, double FAllAmount,int FClient)
{
return List.Where(t => t.FALLAMOUNT == FAllAmount && t.FBIllNO.Count == 1 && t.FClient2[0].Equals(FClient)).ToList();
}
/// <summary>
/// 计算取值
/// </summary>
/// <param name="List"></param>
/// <param name="index"></param>
/// <param name="FBILLNOLIST"></param>
/// <param name="result"></param>
/// <param name="FAllAmount"></param>
public static void GetCombinations(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
{
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
var FClient2 = new List<int>(FClient);
var item = List.GroupBy(a => a.FClient).ToList();
for (int i = index; i < List.Count; i++)
{
FBILLNOLIST2.Add(List[i].FBIllNO);
FClient2.Add(List[i].FClient);
DataItem DataItem = new DataItem();
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
DataItem.FClient2 = new List<int>(FClient2);
DataItem.FALLAMOUNT = FAllAmount + List[i].FALLAMOUNT;
result.Add(DataItem);
if (i < 9)
{
GetCombinations(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FALLAMOUNT);
}
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
}
}
/// <summary>
/// 计算取值
/// </summary>
/// <param name="List"></param>
/// <param name="index"></param>
/// <param name="FBILLNOLIST"></param>
/// <param name="result"></param>
/// <param name="FAllAmount"></param>
public static void GetCombinations2(List<CombinaClass> List, int index, List<string> FBILLNOLIST, List<int> FClient, ref List<DataItem> result, double FAllAmount)
{
var FBILLNOLIST2 = new List<string>(FBILLNOLIST);
var FClient2 = new List<int>(FClient);
//var item = List.GroupBy(a => a.FClient).ToList();
for (int i = index; i < List.Count; i++)
{
FBILLNOLIST2.Add(List[i].FBIllNO);
FClient2.Add(List[i].FClient);
DataItem DataItem = new DataItem();
DataItem.FBIllNO = new List<string>(FBILLNOLIST2);
DataItem.FClient2 = new List<int>(FClient2);
DataItem.FALLAMOUNT = FAllAmount + List[i].FDAMOUNT;
result.Add(DataItem);
if (i < 10)
{
GetCombinations2(List, i + 1, FBILLNOLIST2, FClient2, ref result, FAllAmount + List[i].FDAMOUNT);
}
FBILLNOLIST2 = new List<string>(FBILLNOLIST);
}
}
public static List<List<T>> GetCombinations2<T>(T[] array)
{
List<double> FAllmount = new List<double>();
List<int> FDaySum = new List<int>();
List<List<T>> result = new List<List<T>>();
Combine2(array, 0, new List<T>(), FAllmount, FDaySum, ref result);
return result;
}
static void Combine2<T>(T[] array, int index, List<T> combination, List<double> FAllmount, List<int> FDaySum, ref List<List<T>> result)
{
for (int i = index; i < array.Length; i++)
{
combination.Add(array[i]);
Combine2(array, i + 1, combination, FAllmount, FDaySum, ref result);
combination.RemoveAt(combination.Count - 1); // 回溯
}
if (combination.Count > 0)
{
result.Add(new List<T>(combination));
}
}
public static List<string[]> GetCombinations(List<string[]> array)
{
List<string[]> result = new List<string[]>();
List<string> FIDList = new List<string>();
List<string> FEntryList = new List<string>();
List<double> FAllmount = new List<double>();
List<int> FDaySum = new List<int>();
Combine(array, 0, new List<string[]>(), FIDList, FEntryList, FAllmount, FDaySum, ref result);
return result;
}
static void Combine(List<string[]> array, int index, List<string[]> combination, List<string> FIDList, List<string> FEntryList,
List<double> FAllmount, List<int> FDaySum, ref List<string[]> result)
{
for (int i = index; i < array.Count; i++)
{
FIDList.Add(Convert.ToString(array[i][0]));
FEntryList.Add(Convert.ToString(array[i][3]));
FAllmount.Add(Convert.ToDouble(array[i][2]));
FDaySum.Add(CulDayByDate(Convert.ToDateTime(array[i][1]), DateTime.Now));
combination.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), "0", "0" });
Combine(array, i + 1, combination, FIDList, FEntryList, FAllmount, FDaySum, ref result);
//FIDList.RemoveAt(FIDList.Count - 1); // 回溯
//FEntryList.RemoveAt(FEntryList.Count - 1); // 回溯
//FAllmount.RemoveAt(combination.Count - 1); // 回溯
//FDaySum.RemoveAt(FDaySum.Count - 1); // 回溯
combination.RemoveAt(combination.Count - 1); // 回溯
}
//if (FIDList.Count > 0)
//{
result.Add(new string[4] { string.Join("-", FIDList), string.Join("-", FEntryList), FAllmount.Sum().ToString(), FDaySum.Sum().ToString() });
//}
}
/// <summary>
/// 计算两日期天数差
/// </summary>
/// <param name="date1"></param>
/// <param name="date2"></param>
/// <returns></returns>
public static int CulDayByDate(DateTime date1, DateTime date2)
{
TimeSpan difference = date2.Subtract(date1);
return difference.Days;
}
#region AI提供的回溯算法
// 主函数:匹配销售单与收款单组合
public static Dictionary<double, List<List<double>>> MatchSalesAndPayments(List<double> sales, List<double> payments)
{
var result = new Dictionary<double, List<List<double>>>();
for (int i = 0; i < sales.Count(); i++)
{
double target = sales[i];
var combinations = new List<List<double>>();
Backtrack(payments, target, 0, new List<double>(), combinations);
if (combinations.Count > 0)
{
result[i] = combinations; // 记录匹配的销售单索引及其收款单组合
}
}
return result;
}
// 回溯算法生成所有可能的组合
private static void Backtrack(List<double> payments, double target, int start, List<double> current, List<List<double>> result)
{
if (target == 0)
{
result.Add(new List<double>(current));
return;
}
for (int i = start; i < payments.Count(); i++)
{
if (payments[i] > target)
continue; // 剪枝:跳过金额超过剩余目标值的收款单
if (result.Count() >= 1) //如果已经找到一个组合,就不用继续找了
return;
current.Add(payments[i]);
Backtrack(payments, target - payments[i], i + 1, current, result); // 递归搜索下一个收款单
current.RemoveAt(current.Count - 1); // 回溯
}
}
// 示例用法
public static void Main()
{
List<double> sales =new List<double> { 100, 200 }; // 销售单金额数组
List<double> payments =new List<double> { 50, 30, 20, 50, 100 }; // 收款单金额数组
var matches = MatchSalesAndPayments(sales, payments);
foreach (var sale in matches)
{
Console.WriteLine($"销售单 {sale.Key + 1} 匹配的收款单组合:");
foreach (var combo in sale.Value)
{
Console.WriteLine($"金额组合:{string.Join(", ", combo)},总和:{combo.Sum()}");
}
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,102 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Pilot_KD_Parino.Common
{
public class HttpClient
{
/// <summary>
/// Seivice URL
/// </summary>
public string Url { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// Token
/// </summary>
public string Token { get; set; }
/// <summary>
/// Cookie保证登录后所有访问持有一个Cookie
/// </summary>
static CookieContainer Cookie = new CookieContainer();
/// <summary>
/// HTTP访问
/// </summary>
public string Post()
{
HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
httpRequest.CookieContainer = Cookie;
httpRequest.Timeout = 1000 * 60 * 10;//10min
//httpRequest.Headers.Add("JWT", string.Format("Bearer {0}", Token==null?"": Token.Trim().Replace("\"", "")));
httpRequest.Headers.Add("jwt", string.Format("Bearer {0}", Token == null ? "" : Token.Trim().Replace("\"", "")));
using (Stream reqStream = httpRequest.GetRequestStream())
{
JObject jObj = new JObject();
//jObj.Add("format", 1);
//jObj.Add("useragent", "ApiClient");
//jObj.Add("rid", Guid.NewGuid().ToString().GetHashCode().ToString());
//jObj.Add("parameters", Content);
//jObj.Add("timestamp", DateTime.Now);
//jObj.Add("v", "1.0");
string sContent = jObj.ToString();
var bytes = UnicodeEncoding.UTF8.GetBytes(Content);
reqStream.Write(bytes, 0, bytes.Length);
reqStream.Flush();
}
using (var repStream = httpRequest.GetResponse().GetResponseStream())
{
using (var reader = new StreamReader(repStream))
{
return ValidateResult(reader.ReadToEnd());
}
}
}
public string Get()
{
string result = string.Empty;
string error = string.Empty;
HttpWebRequest httpRequest = HttpWebRequest.Create(Url) as HttpWebRequest;
httpRequest.Timeout = 20000;
httpRequest.Method = "GET";
httpRequest.KeepAlive = true;
httpRequest.Headers.Add("Authorization", "token");
HttpWebResponse reponse = (HttpWebResponse)httpRequest.GetResponse();
string PostContent = new StreamReader(reponse.GetResponseStream()).ReadToEnd();
return PostContent;
}
private static string ValidateResult(string responseText)
{
if (responseText.StartsWith("response_error:"))
{
return responseText.TrimStart("response_error:".ToCharArray());
}
return responseText;
}
}
}