using JNPF.Common.Core.Manager;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.Systems.Entitys.System;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.ProductionMgr.Entities;
namespace Tnb.ProductionMgr
{
///
/// 生产排产
///
[ApiDescriptionSettings(Tag = "ProductMgr", Name = "WorkOrderScheduling", Order = 700)]
[Route("api/production/[controller]")]
public class WorkOrderSchedulingService : IDynamicApiController, ITransient
{
private readonly IDataBaseManager _dataBaseManager;
private readonly ISqlSugarRepository _repository;
public WorkOrderSchedulingService(IDataBaseManager dataBaseManager, ISqlSugarRepository repository)
{
_dataBaseManager = dataBaseManager;
_repository = repository;
}
///
/// 测试数据导入
///
///
[HttpPost("data")]
[AllowAnonymous]
public async Task ImportMoldsData()
{
List<(string pId, string eqpId)> multi = new()
{
("25546268026149","25530823999765"),
("25546256076325","25530834099477"),
};
List list = new();
int index = 1;
foreach ((string pId, string eqpId) in multi)
{
MoldsEntity entity = new()
{
id = SnowflakeIdHelper.NextId(),
MoldCode = $"m00{index}",
MoldName = "磨具" + index,
ItemId = pId,
EqpId = eqpId
};
list.Add(entity);
index++;
}
DbLinkEntity link = await _repository.GetFirstAsync(x => x.FullName == "tnb_eqp");
SqlSugarScope db = _dataBaseManager.ChangeDataBase(link);
int row = await db.Insertable(list).ExecuteCommandAsync();
if (row > 0)
{
foreach (MoldsEntity item in list)
{
Dictionary dic = new()
{
{"id",item.EqpId },
{ "mold_id", item.id}
};
int row2 = await db.Updateable(dic).AS("eqp_equipment")
.WhereColumns("id").
ExecuteCommandAsync();
}
}
await Task.CompletedTask;
}
}
}