using log4net; using Microsoft.Extensions.Caching.Memory; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Web.Http; using UFIDA.U8.Framework.Api.Common.Entity; using UFIDA.U8.Framework.Api.ControlObject.Common; using UFIDA.U8.Framework.Api.ControlObject.Entity; using UFIDA.U8.Framework.Api.ControlObject.Json; using UFIDA.U8.Framework.Api.ControlObject.PU; using UFIDA.U8.Framework.Api.ControlObject.U8M; using UFIDA.U8.Framework.Api.Models; using UFIDA.U8.Framework.Api.Unit; namespace UFIDA.U8.Framework.Api.Controllers.U8 { /// /// 采购管理 /// public class PUController : ApiController { /// /// 日志组件 /// protected readonly ILog _logInfo = LogManager.GetLogger("logInfo"); private static readonly MemoryCache _cache = new MemoryCache(new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan.FromMinutes(10) }); /// /// 保存单据 /// /// 系统号 /// 单据类型编码 /// 报文 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// 单据状态:2新增,1修改,0非编辑 /// CS 0,BS 1;一般CS /// 为空 /// /// [HttpPost] [Route("api/U8/PU/{cCardNum}/VoucherSave")] public async Task> VoucherSave(string cAccId, string cCardNum, [FromBody] Dictionary input, bool bPositive = true, string sBillType = null, string sBusType = "", int VoucherState = 2, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:新增,对接账套:{cAccId},数据:{input.ToJson()}"); //LoginParamter param; 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); } //else //{ // param = await CommUnit.GetLoginParamter(cAccId); //} _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var defs = await db.Queryable().Where(s => s.CardNumber == cCardNum && s.cPosition == "H" && s.bEnable == true).ToListAsync(); //查询表头字段配置,供后续设置字段值 var newNumber = ""; var bGetCode = false; var codeKey = ""; if (defs.Any(a => a.bDefault == true && a.cPosition == "H" && a.DefaultValue == "单号" && a.bEnable == true)) { bGetCode = true; codeKey = defs.Where(a => a.bDefault == true && a.cPosition == "H" && a.DefaultValue == "单号" && a.bEnable == true).Select(a => a.FieldName).First(); _logInfo.Debug($"作业Id:{workId}-----配置获取单号"); } else { _logInfo.Debug($"作业Id:{workId}-----没有单号需要自动指定"); } #region 调整日期,去掉时间部分 if (input.ContainsKey("ddate")) { _logInfo.Debug($"作业Id:{workId}-----调整日期,去掉时间部分"); input["ddate"] = $"{Convert.ToDateTime(input["ddate"]):yyyy-MM-dd}"; } if (input.ContainsKey("dtvdate")) { _logInfo.Debug($"作业Id:{workId}-----调整日期,去掉时间部分"); input["dtvdate"] = $"{Convert.ToDateTime(input["dtvdate"]):yyyy-MM-dd}"; } #endregion _logInfo.Debug($"作业Id:{workId}-----设置表头数据"); input.SetDictionaryData(defs, baseLogin.Connection, newNumber); _logInfo.Debug($"作业Id:{workId}-----读取表体数据"); var bodyData = input[voucherInfo.BodyName].ToJson().ToList>(); //读取表体的数据 if (bodyData == null || bodyData.Count <= 0) throw new Exception("无表体数据!"); _logInfo.Debug($"作业Id:{workId}-----获取表体字段配置"); var defsBody = await db.Queryable().Where(s => s.CardNumber == cCardNum && s.cPosition == "B" && s.bEnable == true).ToListAsync(); //获取表体的字段配置 var rowNo = 1; foreach (var body in bodyData) { _logInfo.Debug($"作业Id:{workId}-----设置第{rowNo}行单据数据"); body.SetDictionaryData(defsBody, baseLogin.Connection, newNumber, rowNo); rowNo++; } input[voucherInfo.BodyName] = bodyData; var co = new clsVoucherCO_PU(); var res = await co.VoucherSave(baseLogin, input, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), bPositive, sBillType, sBusType, VoucherState, UserMode, sOverDetailsXml, bGetCode, codeKey, voucherInfo.bVerify, voucherInfo.bPrintDom, voucherInfo.iswfcontrolled, voucherInfo.cFlowFieldName); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 审核单据(单号) /// /// 系统号 /// 单据类型编码 /// 单号 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/Confirm/Code")] public async Task> Confirm(string cAccId, string cCardNum, string cCode, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:审核,对接账套:{cAccId},单号:{cCode}"); //LoginParamter param; if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin) || baseLogin == null) { _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); } //else //{ // param = await CommUnit.GetLoginParamter(cAccId); //} _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.Confirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCode, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "审核失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 审核单据(ID) /// /// 系统号 /// 单据类型编码 /// 单据ID /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/Confirm/ID")] public async Task> Confirm(string cAccId, string cCardNum, long voucherId, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:审核,对接账套:{cAccId},ID:{voucherId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.Confirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherId, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "审核失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 审核单据(批量) /// /// 系统号 /// 单据类型编码 /// 报文 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpPost] [Route("api/U8/PU/{cCardNum}/Confirm")] public async Task>>> Confirm(string cAccId, string cCardNum, [FromBody] STInput input, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (input == null) { throw new Exception("参数不能为空"); } var cCodes = input.cCode; var voucherIds = input.voucherId; if ((cCodes == null || cCodes.Count <= 0) && (voucherIds == null || voucherIds.Count <= 0)) { throw new Exception("没有数据需要审核"); } var strCode = ""; var strId = ""; var apiType = cCodes == null || cCodes.Count <= 0 ? 1 : 0; if (cCodes != null && cCodes.Count > 0) { strCode = string.Join(",", cCodes); } if (voucherIds != null && voucherIds.Count > 0) { strId = string.Join(",", voucherIds); } _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:审核,对接账套:{cAccId},单号:{strCode},ID:{strId}"); //LoginParamter param; 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); } //else //{ // param = await CommUnit.GetLoginParamter(cAccId); //} _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var result = apiType == 0 ? await co.Confirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCodes, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml) : await co.Confirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherIds, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); var res = new BaseResult>>() { bSuccess = true, message = "审核完成", result = result }; return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); return new BaseResult>> { bSuccess = false, message = ex.Message, result = null }; } } /// /// 弃审单据(单号) /// /// 系统号 /// 单据类型编码 /// 单号 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/CancelConfirm/Code")] public async Task> CancelConfirm(string cAccId, string cCardNum, string cCode, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:弃审,对接账套:{cAccId},单号:{cCode}"); if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin) || baseLogin == null) { _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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.CancelConfirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCode, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "弃审失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 弃审单据(ID) /// /// 系统号 /// 单据类型编码 /// 单据ID /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/CancelConfirm/ID")] public async Task> CancelConfirm(string cAccId, string cCardNum, long voucherId, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:弃审,对接账套:{cAccId},ID:{voucherId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.CancelConfirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherId, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "弃审失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 弃审单据(批量) /// /// 系统号 /// 单据类型编码 /// 报文 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpPost] [Route("api/U8/PU/{cCardNum}/CancelConfirm")] public async Task>>> CancelConfirm(string cAccId, string cCardNum, [FromBody] STInput input, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (input == null) { throw new Exception("参数不能为空"); } var cCodes = input.cCode; var voucherIds = input.voucherId; if ((cCodes == null || cCodes.Count <= 0) && (voucherIds == null || voucherIds.Count <= 0)) { throw new Exception("没有数据需要弃审"); } var strCode = ""; var strId = ""; var apiType = cCodes == null || cCodes.Count <= 0 ? 1 : 0; if (cCodes != null && cCodes.Count > 0) { strCode = string.Join(",", cCodes); } if (voucherIds != null && voucherIds.Count > 0) { strId = string.Join(",", voucherIds); } _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:弃审,对接账套:{cAccId},单号:{strCode},ID:{strId}"); //LoginParamter param; 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); } //else //{ // param = await CommUnit.GetLoginParamter(cAccId); //} _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var result = apiType == 0 ? await co.CancelConfirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCodes, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml) : await co.CancelConfirm(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherIds, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); var res = new BaseResult>>() { bSuccess = true, message = "弃审完成", result = result }; return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); return new BaseResult>> { bSuccess = false, message = ex.Message, result = null }; } } /// /// 删除单据(单号) /// /// 系统号 /// 单据类型编码 /// 单号 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/Delete/Code")] public async Task> Delete(string cAccId, string cCardNum, string cCode, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:删除,对接账套:{cAccId},单号:{cCode}"); if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin) || baseLogin == null) { _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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCode, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "删除失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 删除单据(ID) /// /// 系统号 /// 单据类型编码 /// 单据ID /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/Delete/ID")] public async Task> Delete(string cAccId, string cCardNum, long voucherId, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:删除,对接账套:{cAccId},ID:{voucherId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherId, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "删除失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 删除单据(批量) /// /// 系统号 /// 单据类型编码 /// 报文 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpPost] [Route("api/U8/PU/{cCardNum}/Delete")] public async Task>>> Delete(string cAccId, string cCardNum, [FromBody] STInput input, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null) { var workId = SnowFlakeSingle.Instance.NextId(); try { var db = CommUnit.GetDbClient(); if (input == null) { throw new Exception("参数不能为空"); } var cCodes = input.cCode; var voucherIds = input.voucherId; if ((cCodes == null || cCodes.Count <= 0) && (voucherIds == null || voucherIds.Count <= 0)) { throw new Exception("没有数据需要删除"); } var strCode = ""; var strId = ""; var apiType = cCodes == null || cCodes.Count <= 0 ? 1 : 0; if (cCodes != null && cCodes.Count > 0) { strCode = string.Join(",", cCodes); } if (voucherIds != null && voucherIds.Count > 0) { strId = string.Join(",", voucherIds); } _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:删除,对接账套:{cAccId},单号:{strCode},ID:{strId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var result = apiType == 0 ? await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCodes, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml) : await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherIds, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); var res = new BaseResult>>() { bSuccess = true, message = "删除完成", result = result }; return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); return new BaseResult>> { bSuccess = false, message = ex.Message, result = null }; } } /// /// 提交工作流(单号) /// /// 系统号 /// 单据类型编码 /// 单号 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/SubmintWf/Code")] public async Task> SubmintWf(string cAccId, string cCardNum, string cCode, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:提交工作流,对接账套:{cAccId},单号:{cCode}"); if (!_cache.TryGetValue($"U8_{cAccId}", out BaseLogin baseLogin) || baseLogin == null) { _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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.SubmintWf(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCode, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "提交工作流失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 提交工作流(ID) /// /// 系统号 /// 单据类型编码 /// 单据ID /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpGet] [Route("api/U8/PU/{cCardNum}/SubmintWf/ID")] public async Task> SubmintWf(string cAccId, string cCardNum, long voucherId, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null, string tradeid = null) { try { var db = CommUnit.GetDbClient(); var workId = SnowFlakeSingle.Instance.NextId(); if (string.IsNullOrWhiteSpace(tradeid)) { tradeid = $"{workId}"; } await CommUnit.SaveResult(tradeid, true); _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:提交工作流,对接账套:{cAccId},ID:{voucherId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var res = await co.SubmintWf(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherId, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); var res = new BaseResult { bSuccess = false, message = "提交工作流失败", result = ex.Message }; res.tradeid = tradeid; await CommUnit.SaveResult(tradeid, false, res); return res; } } /// /// 提交工作流(批量) /// /// 系统号 /// 单据类型编码 /// 报文 /// 红蓝标识:True,蓝字 /// 发票类型(普通发票 ppurbill,专用发票 purbill,运费发票 ypurbill);到货单类型(到货单 0,退货单 1,拒收单 2) /// 业务类型:普通采购,直运采购,受托代销 /// CS 0,BS 1;一般CS /// 为空 /// [HttpPost] [Route("api/U8/PU/{cCardNum}/SubmintWf")] public async Task>>> SubmintWf(string cAccId, string cCardNum, [FromBody] STInput input, bool bPositive = true, string sBillType = null, string sBusType = null, UseMode UserMode = UseMode.CS, string sOverDetailsXml = null) { var workId = SnowFlakeSingle.Instance.NextId(); try { var db = CommUnit.GetDbClient(); if (input == null) { throw new Exception("参数不能为空"); } var cCodes = input.cCode; var voucherIds = input.voucherId; if ((cCodes == null || cCodes.Count <= 0) && (voucherIds == null || voucherIds.Count <= 0)) { throw new Exception("没有数据需要提交工作流"); } var strCode = ""; var strId = ""; var apiType = cCodes == null || cCodes.Count <= 0 ? 1 : 0; if (cCodes != null && cCodes.Count > 0) { strCode = string.Join(",", cCodes); } if (voucherIds != null && voucherIds.Count > 0) { strId = string.Join(",", voucherIds); } _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:提交工作流,对接账套:{cAccId},单号:{strCode},ID:{strId}"); 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); } _logInfo.Debug($"作业Id:{workId}-----登录信息获取完成,缓存设置完成,开始加载单据配置信息"); var voucherInfo = await db.Queryable().FirstAsync(s => s.CardNumber == cCardNum); var co = new clsVoucherCO_PU(); var result = apiType == 0 ? await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), cCodes, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml) : await co.Delete(baseLogin, cCardNum, (vouchertype)Convert.ToInt32(voucherInfo.VoucherType), voucherIds, bPositive, sBillType, sBusType, UserMode, sOverDetailsXml); var res = new BaseResult>>() { bSuccess = true, message = "提交工作流完成", result = result }; return res; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); return new BaseResult>> { bSuccess = false, message = ex.Message, result = null }; } } /// /// 查询特定单据部分 /// /// 系统号 /// 单据类型编码 /// 查询条件 /// 查询所属区域 H:表头,B:表体, L:列表 /// /// [HttpPost] [Route("api/U8/PU/{cCardNum}/Load")] [Route("api/U8/PU/{cCardNum}/Load/{cCardPostion}")] public async Task> Load(string cAccId, string cCardNum, [FromBody] Dictionary input, string cCardPostion = "H") { var workId = SnowFlakeSingle.Instance.NextId(); try { _logInfo.Debug($"作业Id:{workId}-----单据:{cCardNum},操作:查询,对接账套:{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 vouchers = CommonHelper.GetVouchers(baseLogin.Connection, cCardNum); if (vouchers == null) { throw new Exception("未能获取到单据配置信息"); } var db = new SqlSugarClient(new ConnectionConfig() { DbType = DbType.SqlServer, ConfigId = cAccId, ConnectionString = baseLogin.UFDataConnstringForNet, IsAutoCloseConnection = true, MoreSettings = new ConnMoreSettings() { IsWithNoLockQuery = true } }); var cBTQName = vouchers.cBTQName; var cBWQName = vouchers.cBWQName; var cBTTblExtName = $"{vouchers.cBTTblName}_extradefine"; var cBWTblExtName = $"{vouchers.cBWTblName}_extradefine"; var voucherIdFieldName = vouchers.voucherIdFieldName; var vouchersIdFieldName = ""; var bExtHead = false; var bExtBody = false; var colList = new Dictionary(); var colListHead = new Dictionary(); var colListBody = new Dictionary(); var cols = db.DbMaintenance.GetColumnInfosByTableName(cBTQName); if (cols != null && cols.Count > 0) { foreach (var col in cols.Where(col => !colList.ContainsKey(col.DbColumnName.ToLower()))) { if (cCardPostion == "H" || cCardPostion == "L") colList.Add(col.DbColumnName.ToLower(), $"{cBTQName}.[{col.DbColumnName}]"); colListHead.Add(col.DbColumnName.ToLower(), $"{cBTQName}.[{col.DbColumnName}]"); } } if (db.DbMaintenance.IsAnyTable($"{cBTTblExtName}")) { bExtHead = true; var extcols = db.DbMaintenance.GetColumnInfosByTableName($"{cBTTblExtName}"); if (extcols != null && extcols.Count > 0) { foreach (var col in extcols.Where(col => !colList.ContainsKey(col.DbColumnName.ToLower()))) { if (cCardPostion == "H" || cCardPostion == "L") colList.Add(col.DbColumnName.ToLower(), $"{cBTTblExtName}.[{col.DbColumnName}]"); colListHead.Add(col.DbColumnName.ToLower(), $"{cBTTblExtName}.[{col.DbColumnName}]"); } } } cols = db.DbMaintenance.GetColumnInfosByTableName(cBWQName); if (cols != null && cols.Count > 0) { foreach (var col in cols.Where(col => !colList.ContainsKey(col.DbColumnName.ToLower()))) { if (cCardPostion == "B" || cCardPostion == "L") colList.Add(col.DbColumnName.ToLower(), $"{cBWQName}.[{col.DbColumnName}]"); colListBody.Add(col.DbColumnName.ToLower(), $"{cBWQName}.[{col.DbColumnName}]"); } } if (db.DbMaintenance.IsAnyTable(cBWTblExtName)) { bExtBody = true; var extcols = db.DbMaintenance.GetColumnInfosByTableName($"{cBWTblExtName}"); if (extcols != null && extcols.Count > 0) { foreach (var col in extcols) { if (colList.ContainsKey(col.DbColumnName.ToLower())) { vouchersIdFieldName = col.DbColumnName.ToLower(); } else { if (cCardPostion == "B" || cCardPostion == "L") colList.Add(col.DbColumnName.ToLower(), $"{cBWTblExtName}.[{col.DbColumnName}]"); colListBody.Add(col.DbColumnName.ToLower(), $"{cBWTblExtName}.[{col.DbColumnName}]"); } } } } var cDefWhere = vouchers.cDefWhere; var query = db.Queryable().AS(cBTQName, cBTQName); if (bExtHead) { query.AddJoinInfo(cBTTblExtName, cBTTblExtName, $"{cBTQName}.[{voucherIdFieldName}]={cBTTblExtName}.[{voucherIdFieldName}]"); } query.AddJoinInfo(cBWQName, cBWQName, $"{cBTQName}.[{voucherIdFieldName}]={cBWQName}.[{voucherIdFieldName}]"); if (bExtBody) { query.AddJoinInfo(cBWTblExtName, cBWTblExtName, $"{cBWQName}.[{vouchersIdFieldName}]={cBWTblExtName}.[{vouchersIdFieldName}]"); } if (input != null) { var conModels = new List(); foreach (var o in input) { if (o.Key == "dModifyDate" && !string.IsNullOrWhiteSpace($"{o.Value}")) { if (colListHead.Any(a => string.Equals(a.Key, "caudittime", StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, "caudittime", StringComparison.OrdinalIgnoreCase))) { var col = colListHead.First(a => string.Equals(a.Key, "caudittime", StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, "caudittime", StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = $"{o.Value}", }); } } else if (o.Key == "dModifyDate__2" && !string.IsNullOrWhiteSpace($"{o.Value}")) { if (colListHead.Any(a => string.Equals(a.Key, "caudittime", StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, "caudittime", StringComparison.OrdinalIgnoreCase))) { var col = colListHead.First(a => string.Equals(a.Key, "caudittime", StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, "caudittime", StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = $"{o.Value}" }); } } else if ($"{o.Value}".EndsWith("%") || $"{o.Value}".StartsWith("%")) { if (colListHead.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListHead.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.Like, FieldValue = $"{o.Value}" }); } if (colListBody.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListBody.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.Like, FieldValue = $"{o.Value}" }); } } else if (o.Key.EndsWith("__2") && !string.IsNullOrWhiteSpace($"{o.Value}")) { if (colListHead.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListHead.First(a => string.Equals(a.Key, o.Key.Replace("__2", ""), StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key.Replace("__2", ""), StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = $"{o.Value}" }); } if (colListBody.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListBody.First(a => string.Equals(a.Key, o.Key.Replace("__2", ""), StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key.Replace("__2", ""), StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.LessThanOrEqual, FieldValue = $"{o.Value}" }); } } else if (input.ContainsKey($"{o.Key}__2") && !string.IsNullOrWhiteSpace($"{o.Value}")) { if (colListHead.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListHead.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = $"{o.Value}" }); } if (colListBody.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase))) { var col = colListBody.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = $"{col.Value}", ConditionalType = ConditionalType.GreaterThanOrEqual, FieldValue = $"{o.Value}" }); } } else if (colListHead.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)) && !string.IsNullOrWhiteSpace($"{o.Value}")) { var col = colListHead.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = col.Value, ConditionalType = ConditionalType.Equal, FieldValue = $"{o.Value}" }); } else if (colListBody.Any(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)) && !string.IsNullOrWhiteSpace($"{o.Value}")) { var col = colListBody.First(a => string.Equals(a.Key, o.Key, StringComparison.OrdinalIgnoreCase) || string.Equals(a.Value, o.Key, StringComparison.OrdinalIgnoreCase)); conModels.Add(new ConditionalModel { FieldName = col.Value, ConditionalType = ConditionalType.Equal, FieldValue = $"{o.Value}" }); } } query.Where(conModels); } query.Where(cDefWhere); var selector = colList.Select(col => new SelectModel { FieldName = $"{col.Value}", AsName = col.Key }).ToList(); query.Select(selector).Distinct(); _logInfo.Debug(query.ToSqlString()); return new BaseResult() { bSuccess = true, message = "查询成功", result = await query.ToListAsync() }; } catch (Exception ex) { _logInfo.Error(ex.Message, ex); return new BaseResult { bSuccess = false, message = ex.Message, result = ex.StackTrace }; } } } }