using System.Text; using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.Core.Enums; using DS.Module.Core.Extensions; using DS.WMS.Core.Fee.Dtos; using DS.WMS.Core.Flow.Dtos; using DS.WMS.Core.Info.Dtos; using DS.WMS.Core.Info.Interface; using Masuit.Tools.Systems; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; namespace DS.WMS.MainApi.Controllers; /// /// 客户基本信息-模块 /// public class ClientInfoController : ApiController { private readonly IClientInfoService _invokeService; /// /// 构造函数 /// /// public ClientInfoController(IClientInfoService invokeService) { _invokeService = invokeService; } /// /// 提交审核 /// /// /// [HttpPost, Route("SubmitAudit")] public async Task SubmitAuditAsync([FromBody] IdModel idModel) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage()); return await _invokeService.SubmitAuditAsync(idModel); } /// /// 执行审核 /// /// /// [HttpPost, Route("Audit")] public async Task AuditAsync([FromBody] AuditRequest request) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage()); return await _invokeService.AuditAsync(request); } /// /// 撤销审核 /// /// /// [HttpPost, Route("Withdraw")] public async Task WithdrawAsync([FromBody] IdModel idModel) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage()); return await _invokeService.WithdrawAsync(idModel); } /// /// 审核完成回调 /// /// 回调信息 /// [HttpPost, Route("AuditCallback")] public async Task AuditCallbackAsync(FlowCallback callback) { return await _invokeService.AuditCallbackAsync(callback); } /// /// 列表 /// /// /// [HttpPost] [Route("GetClientInfoList")] public async Task>> GetListAsync([FromBody] PageRequest request) { return await _invokeService.GetListAsync(request); } /// /// 确定往来单位是否已使用 /// /// /// [HttpPost, Route("GetUsage")] public async Task>> GetUsageAsync([FromBody] IdModel idModel) { return await _invokeService.GetUsageAsync(idModel.Ids); } /// /// 编辑 /// /// /// [HttpPost, Route("EditClientInfo")] public async Task EditClientInfoAsync([FromBody] ClientInfoReq req) { var res = await _invokeService.EditAsync(req); return res; } /// /// 详情 /// /// /// [HttpGet] [Route("GetClientInfo")] public async Task> GetClientInfoAsync([FromQuery] string id) { return await _invokeService.GetAsync(id); } /// /// 根据ID删除发票明细 /// /// /// [HttpPost, Route("DeleteInvoiceHeader")] public async Task DeleteInvoiceHeaderAsync(IdModel idModel) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _invokeService.DeleteInvoiceHeaderAsync(idModel); } /// /// 根据ID删除往来单位 /// /// /// [HttpPost, Route("Delete")] public async Task DeleteAsync([FromBody] IdModel model) { if (!ModelState.IsValid) return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest); return await _invokeService.DeleteAsync(model); } /// /// 获取往来单位详情(含有联系人列表) /// /// 查询往来单位 /// 返回往来单位详情 [HttpPost] [Route("GetClientInfoWithContact")] public async Task> GetClientInfoWithContact([FromBody] QueryClientInfo query) { return await _invokeService.GetClientInfoWithContact(query); } /// /// 获取推送通知可选项列表 /// /// [HttpGet, Route("GetNotifications")] public DataResult> GetNotifications() { var list = typeof(PushNotification).GetDescriptionAndValue().Where(x => x.Value > 0) .Select(x => new NotificationItem { Value = x.Value, Name = x.Key }).ToList(); return DataResult>.Success(list); } /// /// 检查客户信息是否重复 /// /// /// [HttpPost, Route("IsAvailable")] public async Task IsAvailableAsync([FromBody] ClientInfoReq req) { return await _invokeService.IsAvailableAsync(req); } #region 导入 /// /// 导入客户/供应商 /// /// 类型:1=客户,2=供应商,3=客户+供应商 /// /// [HttpPost, Route("Import")] public async Task ImportAsync([FromForm] int type, IFormFile file) { if (file == null) return DataResult.Failed("请求未包含文件流"); var stream = file.OpenReadStream(); var rows = (await MiniExcel.QueryAsync(stream, excelType: ExcelType.XLSX, startCell: "A2")).ToList(); StringBuilder sb = new StringBuilder(); List list = []; try { foreach (IDictionary item in rows) { var model = new InfoClientModel { DeptName = item["A"]?.ToString(), ContactTel = item["C"]?.ToString(), Contact = item["D"]?.ToString(), AgreementTerm = item["E"] == null ? null : DateTime.Parse(item["E"].ToString()), StatusText = item["F"]?.ToString(), Address = item["G"]?.ToString(), CNName = item["H"]?.ToString(), ENName = item["I"]?.ToString(), ShortName = item["J"]?.ToString(), TaxID = item["K"]?.ToString(), Code = item["L"]?.ToString(), StlType = item["M"]?.ToString(), Class = item["N"]?.ToString(), Attribute = item["O"]?.ToString(), Business = item["P"]?.ToString(), OP = item["Q"]?.ToString(), Sale = item["R"]?.ToString(), CustomerService = item["S"]?.ToString(), Authenticator = item["T"]?.ToString(), PrepaidRMB = item["U"] == null ? 0 : decimal.Parse(item["U"].ToString()), PrepaidUSD = item["V"] == null ? 0 : decimal.Parse(item["V"].ToString()), Quota = item["W"] == null ? 0 : decimal.Parse(item["W"].ToString()), RestQuota = item["X"] == null ? 0 : decimal.Parse(item["X"].ToString()), Phone = item["AB"]?.ToString(), Tel = item["AC"]?.ToString(), QQ = item["AD"]?.ToString(), Wechat = item["AE"]?.ToString(), Email = item["AF"]?.ToString(), ContactName = item["AG"]?.ToString(), NFDS = item["AP"] == null ? null : int.Parse(item["AP"].ToString()), }; //if (string.IsNullOrEmpty(model.DeptName)) // sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【所属部门】"); if (type == 3) { model.IsCustomer = model.IsSupplier = true; } else { model.IsCustomer = type == 1; model.IsSupplier = type == 2; } list.Add(model); } if (sb.Length > 0) return DataResult.Failed("导入失败:" + sb.ToString()); } catch (Exception ex) { return DataResult.Failed("读取文件失败:" + ex.Message); } return await _invokeService.ImportAsync(list); } #endregion }