1.去掉编译条件
2.重写业务导入功能
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Tnb.WarehouseMgr
|
||||
protected Task<List<Dictionary<string, object>>> ImportExcelToMemory(IFormFile file)
|
||||
{
|
||||
int rowIndex = 1;
|
||||
List<Dictionary<string, object>> dics = new();
|
||||
List<Dictionary<string, object>>? dics = new();
|
||||
IWorkbook? workbook = null;
|
||||
try
|
||||
{
|
||||
@@ -71,18 +71,20 @@ namespace Tnb.WarehouseMgr
|
||||
dics.Add(dic);
|
||||
}
|
||||
}
|
||||
if (dics == null) throw new AppFriendlyException("输入的数据为空", 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//return Task.FromResult(dics);
|
||||
throw;
|
||||
}
|
||||
return Task.FromResult(dics);
|
||||
}
|
||||
|
||||
public async Task<dynamic?> GenImportTemplate(params string[] fields)
|
||||
public async Task<dynamic?> GenImportTemplate(params string[] fields)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.VisualDev;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 路段管理服务类
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleConsts.MODULE_WMSROAD_ID)]
|
||||
public class WmRoadService : ExcelDataImportManager
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
public WmRoadService(ISqlSugarRepository<WmsRoad> repository)
|
||||
{
|
||||
_db =repository.AsSugarClient();
|
||||
OverideFuncs.ImportAsync = DataImport;
|
||||
}
|
||||
|
||||
private async Task<dynamic> DataImport(IFormFile file)
|
||||
{
|
||||
return Task.FromResult<dynamic>(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace Tnb.WarehouseMgr
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IUserManager _userManager;
|
||||
public WmsCarryLedgerService(ISqlSugarRepository<WmsCarryH> repository, IRunService runService, IVisualDevService visualDevService,IUserManager userManager)
|
||||
public WmsCarryLedgerService(ISqlSugarRepository<WmsCarryH> repository, IRunService runService, IVisualDevService visualDevService, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
@@ -58,42 +58,36 @@ namespace Tnb.WarehouseMgr
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
//例1 获取所有表
|
||||
|
||||
List<Dictionary<string, object>> dics = await ImportExcelToMemory(file);
|
||||
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
|
||||
List<string> locCodes = new();
|
||||
List<string> cCodes = new();
|
||||
WmsCarryH carryH = new WmsCarryH();
|
||||
if (carryStdDic?.Count > 0)
|
||||
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
{
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var stdCodeKey = d["carrystd_id"].ToString();
|
||||
carryStdId = carryStdDic.ContainsKey(stdCodeKey) ? carryStdDic[stdCodeKey]?.ToString() ?? "" : "";
|
||||
d["carrystd_id"] = carryStdId;
|
||||
locCodes.Add(d["location_code"]?.ToString() ?? string.Empty);
|
||||
carryH = d.Adapt<WmsCarryH>();
|
||||
carrys.Add(carryH);
|
||||
}
|
||||
if (!locCodes.IsNullOrEmpty())
|
||||
{
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||
foreach (var loc in locCodes)
|
||||
{
|
||||
var c = carrys.Find(x => x.location_code == loc);
|
||||
if (c != null)
|
||||
c.location_id = locs[loc].ToString();
|
||||
}
|
||||
}
|
||||
var cCode = d["carrystd_id"].ToString() ?? string.Empty;
|
||||
if (cCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}行数据有误", 500);
|
||||
locCodes.Add(d["location_code"]?.ToString() ?? string.Empty);
|
||||
cCodes.Add(cCode);
|
||||
carryH = d.Adapt<WmsCarryH>();
|
||||
carrys.Add(carryH);
|
||||
}
|
||||
if (!locCodes.IsNullOrEmpty())
|
||||
{
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it=>cCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||
carrys.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.status = 1;
|
||||
x.is_lock = 0;
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id].ToString()!;
|
||||
x.carry_status = ((int)EnumCarryStatus.空闲).ToString();
|
||||
x.location_id = locs[x.location_code].ToString();
|
||||
x.out_status = ((int)EnumOutStatus.正常).ToString();
|
||||
x.is_check = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
|
||||
@@ -5,14 +5,20 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
@@ -25,19 +31,22 @@ namespace Tnb.WarehouseMgr
|
||||
/// </summary>
|
||||
[OverideVisualDev(ModuleId)]
|
||||
|
||||
public class WmsRouteMgrService : BaseWareHouseService, IWmsRouteMgrService
|
||||
public class WmsRouteMgrService : ExcelDataImportManager, IWmsRouteMgrService
|
||||
{
|
||||
private const string ModuleId = "26100621140773";//26100621140773
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public WmsRouteMgrService(ISqlSugarRepository<WmsRoad> repository, IRunService runService, IVisualDevService visualDevService)
|
||||
public WmsRouteMgrService(ISqlSugarRepository<WmsRoad> repository, IRunService runService, IVisualDevService visualDevService, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
_userManager = userManager;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
OverideFuncs.ImportDataAsync = DataImport;
|
||||
}
|
||||
|
||||
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
||||
@@ -55,5 +64,59 @@ namespace Tnb.WarehouseMgr
|
||||
await _runService.Create(templateEntity, input);
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
||||
{
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<WmsRoad> roads = new List<WmsRoad>();
|
||||
List<string> pointCodes = new List<string>();
|
||||
|
||||
List<string> locCodes = new();
|
||||
WmsRoad road = new WmsRoad();
|
||||
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var sCode = d["startpoint_code"]?.ToString() ?? string.Empty;
|
||||
var eCode = d["endpoint_code"].ToString() ?? string.Empty;
|
||||
if (sCode.IsEmpty() || eCode.IsEmpty())
|
||||
throw new AppFriendlyException($"第{dics.IndexOf(d) + 2}行数据有误", 500);
|
||||
pointCodes.Add(sCode);
|
||||
pointCodes.Add(eCode);
|
||||
road = d.Adapt<WmsRoad>();
|
||||
roads.Add(road);
|
||||
}
|
||||
var points = await _db.Queryable<WmsPointH>().Where(it => pointCodes.Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id);
|
||||
if (!points.IsNullOrEmpty())
|
||||
{
|
||||
roads.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.startpoint_id = points[x.startpoint_code].ToString()!;
|
||||
x.endpoint_id = points[x.endpoint_code].ToString()!;
|
||||
x.road_code = $"{x.startpoint_code}-{x.endpoint_code}";
|
||||
x.status = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
}
|
||||
await _db.Ado.BeginTranAsync();
|
||||
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
//Log.Error("导入失败", ex);
|
||||
throw Oops.Bah("导入失败");
|
||||
}
|
||||
return row > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +62,10 @@ public class Startup : AppStartup
|
||||
.AddSenparcWeixinServices(App.Configuration); // Senparc.Weixin 注册(如果使用Senparc.Weixin SDK则添加)
|
||||
|
||||
services.AddOverideVisualDev();
|
||||
#if !DEBUG
|
||||
|
||||
//定时任务
|
||||
services.AddHostedService<TimedTaskBackgroundService>();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
|
||||
|
||||
@@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -28,5 +29,6 @@ namespace JNPF.VisualDev
|
||||
public Func<VisualDevModelDataBatchDelInput, Task>? DeleteRangeAsync { get; set; } = null;
|
||||
public Func<VisualDevModelListQueryInput, Task<dynamic>>? ExportAsync { get; set; } = null;
|
||||
public Func<IFormFile, Task<dynamic>>? ImportAsync { get; set; } = null;
|
||||
}
|
||||
public Func<VisualDevImportDataInput, Task<dynamic>>? ImportDataAsync { get; set; } = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace JNPF.VisualDev
|
||||
[HttpGet("{modelId}/{id}")]
|
||||
public async Task<dynamic> GetInfo(string id, string modelId)
|
||||
{
|
||||
// modified by PhilPan 2023-04-12 重写接口
|
||||
// modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.GetAsync != null)
|
||||
{
|
||||
@@ -216,8 +216,8 @@ namespace JNPF.VisualDev
|
||||
// 有表
|
||||
if (!string.IsNullOrEmpty(templateEntity.Tables) && !"[]".Equals(templateEntity.Tables))
|
||||
// modified by PhilPan 2023-04-12 返回值不序列化成字符串
|
||||
return new { id = id, data = (await _runService.GetHaveTableInfo(id, templateEntity)) };
|
||||
else
|
||||
return new { id = id, data = (await _runService.GetHaveTableInfo(id, templateEntity)) };
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace JNPF.VisualDev
|
||||
[HttpGet("{modelId}/{id}/DataChange")]
|
||||
public async Task<dynamic> GetDetails(string id, string modelId)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.GetDetailsAsync != null)
|
||||
{
|
||||
@@ -306,7 +306,7 @@ namespace JNPF.VisualDev
|
||||
[HttpPost("{modelId}/List")]
|
||||
public async Task<dynamic> List(string modelId, [FromBody] VisualDevModelListQueryInput input)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.GetListAsync != null)
|
||||
{
|
||||
@@ -342,7 +342,7 @@ namespace JNPF.VisualDev
|
||||
[HttpPost("{modelId}")]
|
||||
public async Task Create(string modelId, [FromBody] VisualDevModelDataCrInput visualdevModelDataCrForm)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.CreateAsync != null)
|
||||
{
|
||||
@@ -365,7 +365,7 @@ namespace JNPF.VisualDev
|
||||
[HttpPut("{modelId}/{id}")]
|
||||
public async Task Update(string modelId, string id, [FromBody] VisualDevModelDataUpInput visualdevModelDataUpForm)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.UpdateAsync != null)
|
||||
{
|
||||
@@ -387,7 +387,7 @@ namespace JNPF.VisualDev
|
||||
[HttpDelete("{modelId}/{id}")]
|
||||
public async Task Delete(string id, string modelId)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.DeleteAsync != null)
|
||||
{
|
||||
@@ -409,7 +409,7 @@ namespace JNPF.VisualDev
|
||||
[HttpPost("batchDelete/{modelId}")]
|
||||
public async Task BatchDelete(string modelId, [FromBody] VisualDevModelDataBatchDelInput input)
|
||||
{
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
//modified by PhilPan 2023-04-12 重写接口
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.DeleteRangeAsync != null)
|
||||
{
|
||||
@@ -749,7 +749,7 @@ namespace JNPF.VisualDev
|
||||
|
||||
resData.ForEach(items =>
|
||||
{
|
||||
foreach(var item in items)
|
||||
foreach (var item in items)
|
||||
{
|
||||
var vmodel = tInfo.AllFieldsModel.FirstOrDefault(x => x.__vModel__.Equals(item.Key));
|
||||
if (vmodel != null && vmodel.__config__.jnpfKey.Equals(JnpfKeyConst.DATE) && item.Value.IsNotEmptyOrNull()) items[item.Key] = item.Value + " ";
|
||||
@@ -796,18 +796,27 @@ namespace JNPF.VisualDev
|
||||
[UnitOfWork]
|
||||
public async Task<dynamic> ImportData(string modelId, [FromBody] VisualDevImportDataInput list)
|
||||
{
|
||||
var tInfo = await GetUploaderTemplateInfoAsync(modelId);
|
||||
object[]? res = await ImportMenuData(tInfo, list.list, tInfo.visualDevEntity);
|
||||
var addlist = res.First() as List<Dictionary<string, object>>;
|
||||
var errorlist = res.Last() as List<Dictionary<string, object>>;
|
||||
var result = new VisualDevImportDataOutput()
|
||||
VisualDevImportDataOutput result = new VisualDevImportDataOutput();
|
||||
var overideSvc = OverideVisualDevManager.GetOrDefault(modelId);
|
||||
if (overideSvc != null && overideSvc.OverideFuncs.CreateAsync != null)
|
||||
{
|
||||
snum = addlist.Count,
|
||||
fnum = errorlist.Count,
|
||||
failResult = errorlist,
|
||||
resultType = errorlist.Count < 1 ? 0 : 1
|
||||
};
|
||||
await overideSvc.OverideFuncs.ImportDataAsync(list);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tInfo = await GetUploaderTemplateInfoAsync(modelId);
|
||||
object[]? res = await ImportMenuData(tInfo, list.list, tInfo.visualDevEntity);
|
||||
var addlist = res.First() as List<Dictionary<string, object>>;
|
||||
var errorlist = res.Last() as List<Dictionary<string, object>>;
|
||||
result = new VisualDevImportDataOutput()
|
||||
{
|
||||
snum = addlist.Count,
|
||||
fnum = errorlist.Count,
|
||||
failResult = errorlist,
|
||||
resultType = errorlist.Count < 1 ? 0 : 1
|
||||
};
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1204,7 +1213,7 @@ namespace JNPF.VisualDev
|
||||
for (var i = 1; i < vlist.Count; i++)
|
||||
{
|
||||
var errorTxt = tInfo.AllFieldsModel.Find(x => x.__vModel__.Equals(uniqueKey)).__config__.label + ": 值不能重复";
|
||||
if (!ctItemErrors.Any(x=>x.Equals(errorTxt))) ctItemErrors.Add(errorTxt);
|
||||
if (!ctItemErrors.Any(x => x.Equals(errorTxt))) ctItemErrors.Add(errorTxt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1524,7 +1533,7 @@ namespace JNPF.VisualDev
|
||||
foreach (var it in dictionaryDataList)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
if(propsValue.Equals("id")) dictionary.Add(it.Id, it.FullName);
|
||||
if (propsValue.Equals("id")) dictionary.Add(it.Id, it.FullName);
|
||||
if (propsValue.Equals("enCode")) dictionary.Add(it.EnCode, it.FullName);
|
||||
addItem.Add(dictionary);
|
||||
}
|
||||
@@ -1735,7 +1744,7 @@ namespace JNPF.VisualDev
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic[data.Value<string>(propsValue)] = data.Value<string>(propsLabel);
|
||||
list.Add(dic);
|
||||
if (children!=null && data.Value<object>(children) != null && data.Value<object>(children).ToString().IsNotEmptyOrNull())
|
||||
if (children != null && data.Value<object>(children) != null && data.Value<object>(children).ToString().IsNotEmptyOrNull())
|
||||
list.AddRange(GetDynamicInfiniteData(data.Value<object>(children).ToString(), item.props.props));
|
||||
}
|
||||
}
|
||||
@@ -2661,7 +2670,7 @@ namespace JNPF.VisualDev
|
||||
}
|
||||
}
|
||||
|
||||
if(newDataItems.ContainsKey(errorKey))
|
||||
if (newDataItems.ContainsKey(errorKey))
|
||||
{
|
||||
if (dataItems.ContainsKey(errorKey)) dataItems[errorKey] = newDataItems[errorKey].ToString();
|
||||
else dataItems.Add(errorKey, newDataItems[errorKey]);
|
||||
@@ -2955,7 +2964,7 @@ namespace JNPF.VisualDev
|
||||
/// <returns></returns>
|
||||
private VisualDevModelDataConfigOutput GetVisualDevModelDataConfig(VisualDevEntity config)
|
||||
{
|
||||
if(config.WebType.Equals(4)) return config.Adapt<VisualDevModelDataConfigOutput>();
|
||||
if (config.WebType.Equals(4)) return config.Adapt<VisualDevModelDataConfigOutput>();
|
||||
var tInfo = new TemplateParsingBase(config);
|
||||
if (tInfo.AllFieldsModel.Any(x => (x.__config__.defaultCurrent) && (x.__config__.jnpfKey.Equals(JnpfKeyConst.USERSELECT) || x.__config__.jnpfKey.Equals(JnpfKeyConst.DEPSELECT))))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user