|
|
|
@ -4,11 +4,16 @@ using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
|
using DS.Module.SqlSugar;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Core.Code.Dtos;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Dtos;
|
|
|
|
|
using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using DS.WMS.Core.Sys.Interface;
|
|
|
|
|
using DS.WMS.Core.TaskPlat.Dtos;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using MiniExcelLibs;
|
|
|
|
|
using Org.BouncyCastle.Ocsp;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Sys.Method;
|
|
|
|
@ -122,7 +127,7 @@ public class UserService : IUserService
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
var data = model.MapTo<UserReq, SysUser>();
|
|
|
|
|
data.PinYinCode = PinYinUtil.GetFristLetter(data.UserName);
|
|
|
|
|
data.PinYinCode = data.UserName + "(" + PinYinUtil.GetFristLetter(data.UserName) + ")";
|
|
|
|
|
data.MD5Password = MD5Helper.MD5Encrypt(data.Password);
|
|
|
|
|
|
|
|
|
|
var entity = db.Insertable(data).ExecuteReturnEntity();
|
|
|
|
@ -172,7 +177,7 @@ public class UserService : IUserService
|
|
|
|
|
var info = db.Queryable<SysUser>().Where(x => x.Id == userId).First();
|
|
|
|
|
|
|
|
|
|
info = model.MapTo<UserReq, SysUser>();
|
|
|
|
|
info.PinYinCode = PinYinUtil.GetFristLetter(info.UserName);
|
|
|
|
|
info.PinYinCode = info.UserName + "(" + PinYinUtil.GetFristLetter(info.UserName) + ")";
|
|
|
|
|
|
|
|
|
|
db.Updateable(info).IgnoreColumns(it => new { it.TenantId,it.TenantName, it.Password,it.MD5Password }).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand();
|
|
|
|
|
|
|
|
|
@ -302,4 +307,78 @@ public class UserService : IUserService
|
|
|
|
|
return await Task.FromResult(DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入用户信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportUserByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<UserExcelImportReq>();
|
|
|
|
|
var users = new List<SysUser>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var sysUser = new SysUser()
|
|
|
|
|
{
|
|
|
|
|
UserCode = item.UserCode,
|
|
|
|
|
UserName = item.UserName,
|
|
|
|
|
PinYinCode = item.UserName + "("+ PinYinUtil.GetFristLetter(item.UserName)+")",
|
|
|
|
|
UserNumber = item.UserNumber,
|
|
|
|
|
Password = "123456ABC",
|
|
|
|
|
MD5Password = MD5Helper.MD5Encrypt("123456ABC"),
|
|
|
|
|
UserEnName = item.UserEnName,
|
|
|
|
|
Sex = item.Sex == "女"? 2:1,
|
|
|
|
|
Duty = item.Duty,
|
|
|
|
|
OfficePhone = item.OfficePhone,
|
|
|
|
|
Email = item.Email,
|
|
|
|
|
Phone = item.Phone,
|
|
|
|
|
IsOperator = item.IsOperator == 1? true : false,
|
|
|
|
|
IsVouchingClerk = item.IsVouchingClerk == 1 ? true : false,
|
|
|
|
|
IsSale = item.IsSale == 1 ? true : false,
|
|
|
|
|
IsCustom = item.IsCustom == 1 ? true : false,
|
|
|
|
|
IsFinancialStaff = item.IsFinancialStaff == 1 ? true : false,
|
|
|
|
|
IsCustomerService = item.IsCustomerService == 1 ? true : false,
|
|
|
|
|
IsDriver = item.IsDriver == 1 ? true : false,
|
|
|
|
|
IsDispatcher = item.IsDispatcher == 1 ? true : false,
|
|
|
|
|
UserType = 2
|
|
|
|
|
};
|
|
|
|
|
users.Add(sysUser);
|
|
|
|
|
}
|
|
|
|
|
await db.Insertable(users).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|