81 lines
3.2 KiB
C#
81 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Logging;
|
|
using System.Reflection.Emit;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
[OverideVisualDev(ModuleConsts.MODULE_LOCATIONDEFINITION_ID)]
|
|
public class LocationDefinitionService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
public LocationDefinitionService(ISqlSugarRepository<BasLocation> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
OverideFuncs.ImportDataAsync = DataImport;
|
|
}
|
|
|
|
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
|
{
|
|
int row = 0;
|
|
try
|
|
{
|
|
List<Dictionary<string, object>> dics = input.list;
|
|
List<BasLocation> locs = new List<BasLocation>();
|
|
BasLocation loc = new BasLocation();
|
|
List<string> cCodes = new List<string>();
|
|
foreach (var d in dics)
|
|
{
|
|
var cCode = d["carrystd_id"].ToString() ?? string.Empty;
|
|
if (cCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}行载具规格不可为空", 500);
|
|
cCodes.Add(cCode);
|
|
d["create_time"] = DateTime.Now;
|
|
d.Remove("modify_time");
|
|
loc = d.Adapt<BasLocation>();
|
|
locs.Add(loc);
|
|
}
|
|
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
|
if (carryStdDic?.Count > 0)
|
|
{
|
|
locs.ForEach(x =>
|
|
{
|
|
if (!carryStdDic.Keys.Contains(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}行的载具规格有误", 500);
|
|
x.id = SnowflakeIdHelper.NextId();
|
|
x.org_id = _userManager.User.OrganizeId;
|
|
x.is_lock = 0;
|
|
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}行的载具规格有误", 500);
|
|
x.create_id = _userManager.UserId;
|
|
x.modify_id = null;
|
|
x.modify_time = null;
|
|
x.is_mix = 1;
|
|
});
|
|
}
|
|
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw Oops.Bah(ex.Message);
|
|
}
|
|
return row > 0;
|
|
}
|
|
}
|
|
}
|