using log4net;
using Microsoft.Extensions.Caching.Memory;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Http;
using UFIDA.U8.Framework.Api.ControlObject.Entity;
using UFIDA.U8.Framework.Api.ControlObject.Json;
using UFIDA.U8.Framework.Api.ControlObject.U8M;
using UFIDA.U8.Framework.Api.Entity;
using UFIDA.U8.Framework.Api.Unit;
// ReSharper disable InconsistentNaming
namespace UFIDA.U8.Framework.Api.Controllers.U8
{
///
/// 基础资料
///
public class AAController : ApiController
{
///
/// 日志组件
///
private readonly ILog _logInfo = LogManager.GetLogger("logInfo");
private static readonly MemoryCache _cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(10) });
///
/// 查询存货档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Inventory/Load")]
public async Task> Inventory_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Inventory,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var inventoryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"App_Data/Inventory.json"));
var inventorys = inventoryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer, ConfigId = cAccId, ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("Inventory", "Inventory")
.AddJoinInfo("Inventory_Sub", "Inventory_Sub", "Inventory.cInvCode=Inventory_Sub.cInvSubCode");
if (db.DbMaintenance.IsAnyTable("Inventory_extradefine", false))
{
query.AddJoinInfo("Inventory_extradefine", "Inventory_extradefine",
"Inventory.cInvCode=Inventory_extradefine.cInvCode");
}
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key == "cInvCode" && input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = "Inventory.cInvCode",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (o.Key == "cInvCode")
{
conModels.Add(new ConditionalModel
{
FieldName = "Inventory.cInvCode",
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
else if (o.Key == "cInvCode__2")
{
conModels.Add(new ConditionalModel
{
FieldName = "Inventory.cInvCode",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (inventorys != null && inventorys.Count > 0)
{
var selector = new List();
foreach (var inventory in inventorys)
{
var model = new SelectModel() { FieldName = $"{inventory.TableName}.{inventory.FieldName}" };
if (inventory.AsName != null && !string.IsNullOrWhiteSpace(inventory.AsName))
{
model.AsName = inventory.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询计量单位档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/ComputationUnit/Load")]
public async Task> ComputationUnit_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:ComputationUnit,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var computationunitTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/ComputationUnit.json"));
var computationunits = computationunitTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("ComputationUnit", "ComputationUnit");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (computationunits != null && computationunits.Count > 0)
{
var selector = new List();
foreach (var computationunit in computationunits)
{
var model = new SelectModel() { FieldName = $"{computationunit.TableName}.{computationunit.FieldName}" };
if (computationunit.AsName != null && !string.IsNullOrWhiteSpace(computationunit.AsName))
{
model.AsName = computationunit.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询部门档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Department/Load")]
public async Task> Department_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Department,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var departmentTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Department.json"));
var departments = departmentTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("Department", "Department");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (departments != null && departments.Count > 0)
{
var selector = new List();
foreach (var department in departments)
{
var model = new SelectModel() { FieldName = $"{department.TableName}.{department.FieldName}" };
if (department.AsName != null && !string.IsNullOrWhiteSpace(department.AsName))
{
model.AsName = department.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询仓库档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Warehouse/Load")]
public async Task> Warehouse_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Warehouse,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var warehouseTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Warehouse.json"));
var warehouses = warehouseTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("Warehouse", "Warehouse");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (warehouses != null && warehouses.Count > 0)
{
var selector = new List();
foreach (var warehouse in warehouses)
{
var model = new SelectModel() { FieldName = $"{warehouse.TableName}.{warehouse.FieldName}" };
if (warehouse.AsName != null && !string.IsNullOrWhiteSpace(warehouse.AsName))
{
model.AsName = warehouse.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询存货分类档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/InventoryClass/Load")]
public async Task> InventoryClass_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:InventoryClass,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var inventoryclassTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/InventoryClass.json"));
var inventoryclasss = inventoryclassTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("InventoryClass", "InventoryClass");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (inventoryclasss != null && inventoryclasss.Count > 0)
{
var selector = new List();
foreach (var inventoryclass in inventoryclasss)
{
var model = new SelectModel() { FieldName = $"{inventoryclass.TableName}.{inventoryclass.FieldName}" };
if (inventoryclass.AsName != null && !string.IsNullOrWhiteSpace(inventoryclass.AsName))
{
model.AsName = inventoryclass.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询供应商档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Vendor/Load")]
public async Task> Vendor_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Vendor,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var vendorTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Vendor.json"));
var vendors = vendorTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("Vendor", "Vendor");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (vendors != null && vendors.Count > 0)
{
var selector = new List();
foreach (var vendor in vendors)
{
var model = new SelectModel() { FieldName = $"{vendor.TableName}.{vendor.FieldName}" };
if (vendor.AsName != null && !string.IsNullOrWhiteSpace(vendor.AsName))
{
model.AsName = vendor.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询供应商分类档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/VendorClass/Load")]
public async Task> VendorClass_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:VendorClass,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var queryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/VendorClass.json"));
var querys = queryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("VendorClass", "VendorClass");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (querys != null && querys.Count > 0)
{
var selector = new List();
foreach (var q in querys)
{
var model = new SelectModel() { FieldName = $"{q.TableName}.{q.FieldName}" };
if (q.AsName != null && !string.IsNullOrWhiteSpace(q.AsName))
{
model.AsName = q.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询客户档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Customer/Load")]
public async Task> Customer_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Customer,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var queryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Customer.json"));
var querys = queryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("Customer", "Customer");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (querys != null && querys.Count > 0)
{
var selector = new List();
foreach (var q in querys)
{
var model = new SelectModel() { FieldName = $"{q.TableName}.{q.FieldName}" };
if (q.AsName != null && !string.IsNullOrWhiteSpace(q.AsName))
{
model.AsName = q.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询客户分类档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/CustomerClass/Load")]
public async Task> CustomerClass_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:CustomerClass,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var queryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/CustomerClass.json"));
var querys = queryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("CustomerClass", "CustomerClass");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (querys != null && querys.Count > 0)
{
var selector = new List();
foreach (var q in querys)
{
var model = new SelectModel() { FieldName = $"{q.TableName}.{q.FieldName}" };
if (q.AsName != null && !string.IsNullOrWhiteSpace(q.AsName))
{
model.AsName = q.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询人员档案
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Person/Load")]
public async Task> Person_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:CustomerClass,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var queryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Person.json"));
var querys = queryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("hr_hi_person", "hr_hi_person");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (querys != null && querys.Count > 0)
{
var selector = new List();
foreach (var q in querys)
{
var model = new SelectModel() { FieldName = $"{q.TableName}.{q.FieldName}" };
if (q.AsName != null && !string.IsNullOrWhiteSpace(q.AsName))
{
model.AsName = q.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
///
/// 查询标准工序资料
///
///
///
///
[HttpPost]
[Route("api/U8/AA/Operation/Load")]
public async Task> Operation_Load(string cAccId, [FromBody] Dictionary input)
{
var workId = SnowFlakeSingle.Instance.NextId();
try
{
//var userToken = Request.Headers.GetValues("userToken").First();
//if (userToken != "04fafa004ad8851485d9026229964a488f2080907248680178bae68a236b33bc086aa234c94927e4099f21209bea98640ad4e9b1b5319cd5f55144606d82f3dbeff44ec66575ca2438144df9fa3f3e1babd80a140d2170975a031fca1ade326234b4d9a61386")
//{
// throw new Exception("调用信息不正确,请确认参数");
//}
_logInfo.Debug($"作业Id:{workId}-----档案:Operation,操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin))
{
_logInfo.Debug($"作业Id:{workId}-----未获取到缓存的登录信息,正在重新构建");
baseLogin = new BaseLogin();
var param = await CommUnit.GetLoginParamter(cAccId);
if (param == null)
{
throw new Exception("未能加载指定系统号的登录信息");
}
baseLogin.Init(param, false);
_cache.Clear();
_cache.Set($"U8_{cAccId}", baseLogin);
}
var queryTxt = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data/Operation.json"));
var querys = queryTxt.ToObject>();
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConfigId = cAccId,
ConnectionString = baseLogin.UFDataConnstringForNet
});
var query = db.Queryable().AS("sfc_operation", "sfc_operation");
if (input != null)
{
var conModels = new List();
foreach (var o in input)
{
if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.Like,
FieldValue = $"{o.Value}"
});
}
else if (o.Key.EndsWith("__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key.Replace("__2", "")}",
ConditionalType = ConditionalType.LessThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else if (input.ContainsKey($"{o.Key}__2"))
{
conModels.Add(new ConditionalModel
{
FieldName = $"{o.Key}",
ConditionalType = ConditionalType.GreaterThanOrEqual,
FieldValue = $"{o.Value}"
});
}
else
{
conModels.Add(new ConditionalModel
{
FieldName = o.Key,
ConditionalType = ConditionalType.Equal,
FieldValue = $"{o.Value}"
});
}
}
query.Where(conModels);
}
if (querys != null && querys.Count > 0)
{
var selector = new List();
foreach (var q in querys)
{
var model = new SelectModel() { FieldName = $"{q.TableName}.{q.FieldName}" };
if (q.AsName != null && !string.IsNullOrWhiteSpace(q.AsName))
{
model.AsName = q.AsName;
}
selector.Add(model);
}
query.Select(selector);
}
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
return new BaseResult
{ bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
}
catch (Exception ex)
{
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace };
}
}
}
}