|
|
|
@ -196,13 +196,12 @@ public class ClientInfoController : ApiController
|
|
|
|
|
#region 导入
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导入客户/供应商
|
|
|
|
|
/// 导入客户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="type">类型:1=客户,2=供应商,3=客户+供应商</param>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("Import")]
|
|
|
|
|
public async Task<DataResult> ImportAsync([FromForm] int type, IFormFile file)
|
|
|
|
|
[HttpPost, Route("ImportClient")]
|
|
|
|
|
public async Task<DataResult> ImportClientAsync(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
if (file == null)
|
|
|
|
|
return DataResult.Failed("请求未包含文件流");
|
|
|
|
@ -248,20 +247,76 @@ public class ClientInfoController : ApiController
|
|
|
|
|
Email = item["AF"]?.ToString(),
|
|
|
|
|
ContactName = item["AG"]?.ToString(),
|
|
|
|
|
NFDS = item["AP"] == null ? null : int.Parse(item["AP"].ToString()),
|
|
|
|
|
IsCustomer = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//if (string.IsNullOrEmpty(model.DeptName))
|
|
|
|
|
// sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【所属部门】");
|
|
|
|
|
|
|
|
|
|
if (type == 3)
|
|
|
|
|
{
|
|
|
|
|
model.IsCustomer = model.IsSupplier = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导入供应商
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost, Route("ImportSupplier")]
|
|
|
|
|
public async Task<DataResult> ImportSupplierAsync(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<InfoClientModel> list = [];
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (IDictionary<string, object> item in rows)
|
|
|
|
|
{
|
|
|
|
|
var model = new InfoClientModel
|
|
|
|
|
{
|
|
|
|
|
model.IsCustomer = type == 1;
|
|
|
|
|
model.IsSupplier = type == 2;
|
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
|
ENName = item["G"]?.ToString(),
|
|
|
|
|
ShortName = item["H"]?.ToString(),
|
|
|
|
|
TaxID = item["I"]?.ToString(),
|
|
|
|
|
Code = item["J"]?.ToString(),
|
|
|
|
|
StlType = item["K"]?.ToString(),
|
|
|
|
|
Attribute = item["V"]?.ToString(),
|
|
|
|
|
Business = item["L"]?.ToString(),
|
|
|
|
|
OP = item["M"]?.ToString(),
|
|
|
|
|
Sale = item["N"]?.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()),
|
|
|
|
|
ContactName = item["B"]?.ToString(),
|
|
|
|
|
IsSupplier = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//if (string.IsNullOrEmpty(model.DeptName))
|
|
|
|
|
// sb.Append($"行号:{rows.IndexOf(item) + 2} 未填写【所属部门】");
|
|
|
|
|
|
|
|
|
|
list.Add(model);
|
|
|
|
|
}
|
|
|
|
@ -278,6 +333,115 @@ public class ClientInfoController : ApiController
|
|
|
|
|
return await _invokeService.ImportAsync(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(),
|
|
|
|
|
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))
|
|
|
|
|
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(),
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|