|
|
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;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 客户基本信息-模块
|
|
|
/// </summary>
|
|
|
public class ClientInfoController : ApiController
|
|
|
{
|
|
|
private readonly IClientInfoService _invokeService;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 构造函数
|
|
|
/// </summary>
|
|
|
/// <param name="invokeService"></param>
|
|
|
public ClientInfoController(IClientInfoService invokeService)
|
|
|
{
|
|
|
_invokeService = invokeService;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 提交审核
|
|
|
/// </summary>
|
|
|
/// <param name="idModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("SubmitAudit")]
|
|
|
public async Task<DataResult> SubmitAuditAsync([FromBody] IdModel idModel)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
|
return DataResult.Failed(ModelState.GetErrorMessage());
|
|
|
|
|
|
return await _invokeService.SubmitAuditAsync(idModel);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行审核
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("Audit")]
|
|
|
public async Task<DataResult> AuditAsync([FromBody] AuditRequest request)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
|
return DataResult.Failed(ModelState.GetErrorMessage());
|
|
|
|
|
|
return await _invokeService.AuditAsync(request);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 撤销审核
|
|
|
/// </summary>
|
|
|
/// <param name="idModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("Withdraw")]
|
|
|
public async Task<DataResult> WithdrawAsync([FromBody] IdModel idModel)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
|
return DataResult.Failed(ModelState.GetErrorMessage());
|
|
|
|
|
|
return await _invokeService.WithdrawAsync(idModel);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 审核完成回调
|
|
|
/// </summary>
|
|
|
/// <param name="callback">回调信息</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("AuditCallback")]
|
|
|
public async Task<DataResult> AuditCallbackAsync(FlowCallback callback)
|
|
|
{
|
|
|
return await _invokeService.AuditCallbackAsync(callback);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 列表
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost]
|
|
|
[Route("GetClientInfoList")]
|
|
|
public async Task<DataResult<List<ClientInfoRes>>> GetListAsync([FromBody] PageRequest<ClientQuery> request)
|
|
|
{
|
|
|
return await _invokeService.GetListAsync(request);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 供应商列表
|
|
|
/// </summary>
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost]
|
|
|
[Route("GetSupplierList")]
|
|
|
public async Task<DataResult<List<ClientInfoRes>>> GetSupplierListAsync([FromBody] PageRequest<ClientQuery> request)
|
|
|
{
|
|
|
return await _invokeService.GetSupplierListAsync(request);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 确定往来单位是否已使用
|
|
|
/// </summary>
|
|
|
/// <param name="idModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("GetUsage")]
|
|
|
public async Task<DataResult<List<ClientUsage>>> GetUsageAsync([FromBody] IdModel idModel)
|
|
|
{
|
|
|
return await _invokeService.GetUsageAsync(idModel.Ids);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 编辑
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("EditClientInfo")]
|
|
|
public async Task<DataResult> EditClientInfoAsync([FromBody] ClientInfoReq req)
|
|
|
{
|
|
|
var res = await _invokeService.EditAsync(req);
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 详情
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet]
|
|
|
[Route("GetClientInfo")]
|
|
|
public async Task<DataResult<ClientInfoRes>> GetClientInfoAsync([FromQuery] long id)
|
|
|
{
|
|
|
return await _invokeService.GetAsync(id);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID删除发票明细
|
|
|
/// </summary>
|
|
|
/// <param name="idModel"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("DeleteInvoiceHeader")]
|
|
|
public async Task<DataResult> DeleteInvoiceHeaderAsync(IdModel idModel)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
|
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
|
|
|
|
|
|
return await _invokeService.DeleteInvoiceHeaderAsync(idModel);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据ID删除往来单位
|
|
|
/// </summary>
|
|
|
/// <param name="model"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("Delete")]
|
|
|
public async Task<DataResult> DeleteAsync([FromBody] IdModel model)
|
|
|
{
|
|
|
if (!ModelState.IsValid)
|
|
|
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
|
|
|
|
|
|
return await _invokeService.DeleteAsync(model);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取往来单位详情(含有联系人列表)
|
|
|
/// </summary>
|
|
|
/// <param name="query">查询往来单位</param>
|
|
|
/// <returns>返回往来单位详情</returns>
|
|
|
[HttpPost]
|
|
|
[Route("GetClientInfoWithContact")]
|
|
|
public async Task<DataResult<ClientInfoRes>> GetClientInfoWithContact([FromBody] QueryClientInfo query)
|
|
|
{
|
|
|
return await _invokeService.GetClientInfoWithContact(query);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取推送通知可选项列表
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet, Route("GetNotifications")]
|
|
|
public DataResult<List<NotificationItem>> GetNotifications()
|
|
|
{
|
|
|
var list = typeof(PushNotification).GetDescriptionAndValue().Where(x => x.Value > 0)
|
|
|
.Select(x => new NotificationItem { Value = x.Value, Name = x.Key }).ToList();
|
|
|
|
|
|
return DataResult<List<NotificationItem>>.Success(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 检查客户信息是否重复
|
|
|
/// </summary>
|
|
|
/// <param name="req"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("IsAvailable")]
|
|
|
public async Task<DataResult> IsAvailableAsync([FromBody] ClientInfoReq req)
|
|
|
{
|
|
|
return await _invokeService.IsAvailableAsync(req);
|
|
|
}
|
|
|
|
|
|
#region 导入
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入客户
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <param name="mode">0=新增,1=更新字段</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("ImportClient")]
|
|
|
public async Task<DataResult> ImportClientAsync(IFormFile file, int mode = 0)
|
|
|
{
|
|
|
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();
|
|
|
List<InfoClientModel> list = [];
|
|
|
try
|
|
|
{
|
|
|
foreach (IDictionary<string, object> 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()?.Trim(),
|
|
|
ENName = item["I"]?.ToString()?.Trim(),
|
|
|
ShortName = item["J"]?.ToString()?.Trim(),
|
|
|
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(),
|
|
|
Country = item["AH"]?.ToString(),
|
|
|
LegalPerson = item["AI"]?.ToString(),
|
|
|
RegisteredCapital = item["AJ"]?.ToString(),
|
|
|
RegistrationTime = item["AK"] == null ? null : DateTime.Parse(item["AK"].ToString()!),
|
|
|
IsCustomer = true
|
|
|
};
|
|
|
|
|
|
//if (string.IsNullOrEmpty(model.DeptName))
|
|
|
// sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【所属部门】");
|
|
|
|
|
|
list.Add(model);
|
|
|
}
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
return DataResult.Failed("导入失败:" + sb.ToString());
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return DataResult.Failed("读取文件失败:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
return mode == 0 ? await _invokeService.ImportAsync(list) : await _invokeService.ImportUpdateAsync(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入供应商
|
|
|
/// </summary>
|
|
|
/// <param name="file"></param>
|
|
|
/// <param name="mode">0=新增,1=更新字段</param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("ImportSupplier")]
|
|
|
public async Task<DataResult> ImportSupplierAsync(IFormFile file, int mode = 0)
|
|
|
{
|
|
|
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();
|
|
|
List<InfoClientModel> list = [];
|
|
|
try
|
|
|
{
|
|
|
foreach (IDictionary<string, object> item in rows)
|
|
|
{
|
|
|
var model = new InfoClientModel
|
|
|
{
|
|
|
ContactTel = item["A"]?.ToString(),
|
|
|
Contact = item["B"]?.ToString(),
|
|
|
AgreementTerm = item["C"] == null ? null : DateTime.Parse(item["C"].ToString()),
|
|
|
StatusText = item["D"]?.ToString(),
|
|
|
Address = item["E"]?.ToString(),
|
|
|
CNName = item["F"]?.ToString()?.Trim(),
|
|
|
ENName = item["G"]?.ToString()?.Trim(),
|
|
|
ShortName = item["H"]?.ToString()?.Trim(),
|
|
|
TaxID = item["I"]?.ToString(),
|
|
|
Code = item["J"]?.ToString(),
|
|
|
StlType = item["K"]?.ToString(),
|
|
|
Attribute = item["L"]?.ToString(),
|
|
|
Business = item["M"]?.ToString(),
|
|
|
OP = item["N"]?.ToString(),
|
|
|
Sale = item["O"]?.ToString(),
|
|
|
CustomerService = item["P"]?.ToString(),
|
|
|
Authenticator = item["Q"]?.ToString(),
|
|
|
PrepaidRMB = item["R"] == null ? 0 : decimal.Parse(item["R"].ToString()),
|
|
|
PrepaidUSD = item["S"] == null ? 0 : decimal.Parse(item["S"].ToString()),
|
|
|
Quota = item["T"] == null ? 0 : decimal.Parse(item["T"].ToString()),
|
|
|
RestQuota = item["U"] == null ? 0 : decimal.Parse(item["U"].ToString()),
|
|
|
Country = item["V"]?.ToString(),
|
|
|
LegalPerson = item["W"]?.ToString(),
|
|
|
ContactName = item["B"]?.ToString(),
|
|
|
RegisteredCapital = item["X"]?.ToString(),
|
|
|
RegistrationTime = item["Y"] == null ? null : DateTime.Parse(item["Y"].ToString()!),
|
|
|
IsSupplier = true
|
|
|
};
|
|
|
|
|
|
//if (string.IsNullOrEmpty(model.DeptName))
|
|
|
// sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【所属部门】");
|
|
|
|
|
|
list.Add(model);
|
|
|
}
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
return DataResult.Failed("导入失败:" + sb.ToString());
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return DataResult.Failed("读取文件失败:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
return mode == 0 ? await _invokeService.ImportAsync(list) : await _invokeService.ImportUpdateAsync(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入银行与发票
|
|
|
/// </summary>
|
|
|
/// <param name="service"></param>
|
|
|
/// <param name="file"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("ImportBank")]
|
|
|
public async Task<DataResult> ImportBankAsync([FromServices] IClientBankService service, 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<InfoClientBankModel> list = [];
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (IDictionary<string, object> item in rows)
|
|
|
{
|
|
|
var model = new InfoClientBankModel
|
|
|
{
|
|
|
CompanyName = item["A"]?.ToString()?.Trim(),
|
|
|
Currency = item["B"]?.ToString(),
|
|
|
BankName = item["C"]?.ToString(),
|
|
|
BankAccount = item["E"]?.ToString(),
|
|
|
BankAddress = item["F"]?.ToString(),
|
|
|
InvoiceAddress = item["G"]?.ToString(),
|
|
|
InvoiceRecevier = item["H"]?.ToString(),
|
|
|
Tel = item["I"]?.ToString(),
|
|
|
TaxId = item["J"]?.ToString(),
|
|
|
InvoiceTel = item["K"]?.ToString(),
|
|
|
Remark = item["L"]?.ToString(),
|
|
|
InvoiceHeader = item["M"]?.ToString(),
|
|
|
IsDefaultP = int.TryParse(item["N"]?.ToString(), out int value1) && value1 == 1,
|
|
|
IsDefaultR = int.TryParse(item["O"]?.ToString(), out int value2) && value2 == 1,
|
|
|
IsDefault = int.TryParse(item["P"]?.ToString(), out int value3) && value3 == 1,
|
|
|
};
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.CompanyName))
|
|
|
model.CompanyName = model.InvoiceHeader;
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.CompanyName))
|
|
|
sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【公司名称】");
|
|
|
|
|
|
list.Add(model);
|
|
|
}
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
return DataResult.Failed("导入失败:" + sb.ToString());
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return DataResult.Failed("读取文件失败:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
return await service.ImportAsync(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入联系人
|
|
|
/// </summary>
|
|
|
/// <param name="service"></param>
|
|
|
/// <param name="file"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("ImportContact")]
|
|
|
public async Task<DataResult> ImportContactAsync([FromServices] IClientContactService service, 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<InfoClientContactModel> list = [];
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (IDictionary<string, object> item in rows)
|
|
|
{
|
|
|
var model = new InfoClientContactModel
|
|
|
{
|
|
|
CompanyName = item["A"]?.ToString()?.Trim(),
|
|
|
ContactName = item["B"]?.ToString(),
|
|
|
ContactEnName = item["C"]?.ToString(),
|
|
|
Tel = item["D"]?.ToString(),
|
|
|
Mobile = item["E"]?.ToString(),
|
|
|
Email = item["F"]?.ToString(),
|
|
|
QQ = item["G"]?.ToString(),
|
|
|
IsDefault = item["H"]?.ToString() == "是",
|
|
|
Job = item["I"]?.ToString()
|
|
|
};
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.CompanyName))
|
|
|
sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【公司名称】");
|
|
|
|
|
|
list.Add(model);
|
|
|
}
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
return DataResult.Failed("导入失败:" + sb.ToString());
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return DataResult.Failed("读取文件失败:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
return await service.ImportAsync(list);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 导入干系人
|
|
|
/// </summary>
|
|
|
/// <param name="service"></param>
|
|
|
/// <param name="file"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, Route("ImportStakeholder")]
|
|
|
public async Task<DataResult> ImportStakeholderAsync([FromServices] IClientStakeholderService service, 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();
|
|
|
List<InfoClientStakeholderModel> list = [];
|
|
|
|
|
|
try
|
|
|
{
|
|
|
foreach (IDictionary<string, object> item in rows)
|
|
|
{
|
|
|
var model = new InfoClientStakeholderModel
|
|
|
{
|
|
|
CustomerName = item["A"]?.ToString()?.Trim(),
|
|
|
StakeholderName = item["B"]?.ToString()?.Trim(),
|
|
|
StakeholderCode = item["C"]?.ToString()?.Trim(),
|
|
|
StartDate = DateTime.Parse(item["D"]?.ToString()),
|
|
|
EndDate = DateTime.Parse(item["E"]?.ToString()),
|
|
|
};
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.CustomerName))
|
|
|
sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【客户名称】");
|
|
|
|
|
|
if (string.IsNullOrEmpty(model.StakeholderCode))
|
|
|
sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【账号】");
|
|
|
|
|
|
list.Add(model);
|
|
|
}
|
|
|
|
|
|
if (sb.Length > 0)
|
|
|
return DataResult.Failed("导入失败:" + sb.ToString());
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
return DataResult.Failed("读取文件失败:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
return await service.ImportAsync(list);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
} |