412 lines
15 KiB
C#
412 lines
15 KiB
C#
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 Antlr.Runtime;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 基础资料
|
|
/// </summary>
|
|
public class AAController : ApiController
|
|
{
|
|
/// <summary>
|
|
/// 日志组件
|
|
/// </summary>
|
|
private readonly ILog _logInfo = LogManager.GetLogger("logInfo");
|
|
|
|
private static readonly MemoryCache _cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(10) });
|
|
|
|
/// <summary>
|
|
/// 查询存货档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Inventory/Load")]
|
|
public async Task<BaseResult<dynamic>> Inventory_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "Inventory", "" },
|
|
{ "Inventory_Sub", "Inventory_Sub.cInvSubCode=Inventory.cInvCode" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Inventory", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询计量单位档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/ComputationUnit/Load")]
|
|
public async Task<BaseResult<dynamic>> ComputationUnit_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "ComputationUnit", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "ComputationUnit", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询计量单位组档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/ComputationGroup/Load")]
|
|
public async Task<BaseResult<dynamic>> ComputationGroup_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "ComputationGroup", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "ComputationGroup", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询部门档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Department/Load")]
|
|
public async Task<BaseResult<dynamic>> Department_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "Department", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Department", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询仓库档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Warehouse/Load")]
|
|
public async Task<BaseResult<dynamic>> Warehouse_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "Warehouse", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Warehouse", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询存货分类档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/InventoryClass/Load")]
|
|
public async Task<BaseResult<dynamic>> InventoryClass_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "InventoryClass", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Vendor", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询供应商档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Vendor/Load")]
|
|
public async Task<BaseResult<dynamic>> Vendor_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "Vendor", "" },
|
|
//{ "VendorClass", "VendorClass.cVCCode = Vendor.cVCCode" },
|
|
//{ "DistrictClass", "DistrictClass.cDCCode = Vendor.cDCCode" },
|
|
//{ "Person", "Person.cPersonCode = dbo.Vendor.cVenPPerson" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Vendor", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询供应商分类档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/VendorClass/Load")]
|
|
public async Task<BaseResult<dynamic>> VendorClass_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "VendorClass", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "VendorClass", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询客户档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Customer/Load")]
|
|
public async Task<BaseResult<dynamic>> Customer_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "Customer", "" },
|
|
//{ "CustomerClass", "Customer.cCCCode = CustomerClass.cCCCode" },
|
|
//{ "DistrictClass", "DistrictClass.cDCCode = Customer.cDCCode" },
|
|
//{ "DistrictClass", "DistrictClass.cDCCode = Customer.cDCCode" },
|
|
//{ "Person", "Person.cPersonCode = Customer.cCusPerson" },
|
|
//{ "Warehouse", "Warehouse.cWhCode = Customer.cCusWhCode" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Customer", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询客户分类档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/CustomerClass/Load")]
|
|
public async Task<BaseResult<dynamic>> CustomerClass_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "CustomerClass", "" },
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "CustomerClass", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询人员档案
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Person/Load")]
|
|
public async Task<BaseResult<dynamic>> Person_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "hr_hi_person", "" },
|
|
//{ "Department", "Department.cDepCode = hr_hi_person.cDept_num" }
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Person", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询标准工序资料
|
|
/// </summary>
|
|
/// <param name="cAccId"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("api/U8/AA/Operation/Load")]
|
|
public async Task<BaseResult<dynamic>> Operation_Load(string cAccId, [FromBody] Dictionary<string, object> input)
|
|
{
|
|
var dict = new Dictionary<string, string>()
|
|
{
|
|
{ "sfc_operation", "" }
|
|
};
|
|
|
|
return await BaseLoad(cAccId, "Operation", dict, input);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 基础档案查询
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[NonAction]
|
|
public async Task<BaseResult<dynamic>> BaseLoad(string cAccId, string tableName,Dictionary<string,string> tables, [FromBody] Dictionary<string, object> input=null)
|
|
{
|
|
var workId = SnowFlakeSingle.Instance.NextId();
|
|
|
|
try
|
|
{
|
|
_logInfo.Debug($"作业Id:{workId}-----档案:{tableName},操作:查询,对接账套:{cAccId},条件:{input.ToJson()}");
|
|
|
|
if (tables == null || tables.Count == 0)
|
|
{
|
|
throw new Exception("未指定档案表");
|
|
}
|
|
|
|
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 db = new SqlSugarClient(new ConnectionConfig()
|
|
{
|
|
DbType = DbType.SqlServer,
|
|
ConfigId = cAccId,
|
|
ConnectionString = baseLogin.UFDataConnstringForNet,
|
|
IsAutoCloseConnection = true,
|
|
MoreSettings = new ConnMoreSettings()
|
|
{
|
|
IsWithNoLockQuery = true
|
|
}
|
|
});
|
|
|
|
var colList = new Dictionary<string,string>();
|
|
|
|
var query = db.Queryable<dynamic>();
|
|
var bFirst = true;
|
|
|
|
foreach (var table in tables)
|
|
{
|
|
if (!db.DbMaintenance.IsAnyTable(table.Key))
|
|
{
|
|
throw new Exception($"表:{table.Key}不存在");
|
|
}
|
|
|
|
var cols = db.DbMaintenance.GetColumnInfosByTableName(table.Key);
|
|
|
|
if(cols != null && cols.Count > 0)
|
|
{
|
|
foreach (var col in cols.Where(col => !colList.Any(a => string.Equals(a.Key, col.DbColumnName, StringComparison.CurrentCultureIgnoreCase))))
|
|
{
|
|
colList.Add(col.DbColumnName, $"{table.Key}.[{col.DbColumnName}]");
|
|
}
|
|
}
|
|
|
|
if (bFirst)
|
|
{
|
|
query.AS(table.Key, table.Key);
|
|
bFirst = false;
|
|
}
|
|
else
|
|
{
|
|
query.AddJoinInfo(table.Key, table.Key, table.Value);
|
|
}
|
|
}
|
|
|
|
if (input != null)
|
|
{
|
|
var conModels = new List<IConditionalModel>();
|
|
|
|
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 if (colList.Keys.Contains(o.Key) || colList.Values.Contains(o.Key))
|
|
{
|
|
conModels.Add(new ConditionalModel
|
|
{
|
|
FieldName = o.Key,
|
|
ConditionalType = ConditionalType.Equal,
|
|
FieldValue = $"{o.Value}"
|
|
});
|
|
}
|
|
}
|
|
|
|
query.Where(conModels);
|
|
}
|
|
|
|
if (colList != null && colList.Keys.Count > 0)
|
|
{
|
|
var selector = colList
|
|
.Select(col => new SelectModel { FieldName = $"{col.Value}", AsName = col.Key }).ToList();
|
|
|
|
query.Select(selector);
|
|
}
|
|
|
|
_logInfo.Debug($"作业Id:{workId}-----输出查询语句:{query.ToSqlString()}");
|
|
|
|
return new BaseResult<dynamic> { bSuccess = true, message = "查询成功", result = await query.ToListAsync() };
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logInfo.Error($"作业Id:{workId}-----错误信息:{ex.Message}", ex);
|
|
|
|
return new BaseResult<dynamic> { bSuccess = false, message = ex.Message, result = ex.StackTrace };
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|