Files
tnb.server/ProductionMgr/Tnb.ProductionMgr/WorkOrderSchedulingService.cs
2023-04-21 09:26:04 +08:00

84 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Cells;
using DingTalk.Api.Request;
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 NPOI.SS.UserModel;
using SqlSugar;
using Tnb.ProductionMgr.Entitys.Entity;
namespace Tnb.ProductionPlanMgr
{
/// <summary>
/// 生产排产
/// </summary>
[ApiDescriptionSettings(Tag = "ProductMgr", Name = "WorkOrderScheduling", Order = 700)]
[Route("api/production/[controller]")]
public class WorkOrderSchedulingService : IDynamicApiController, ITransient
{
private readonly IDataBaseManager _dataBaseManager;
private readonly ISqlSugarRepository<DbLinkEntity> _repository;
public WorkOrderSchedulingService(IDataBaseManager dataBaseManager, ISqlSugarRepository<DbLinkEntity> repository)
{
_dataBaseManager = dataBaseManager;
_repository = repository;
}
/// <summary>
/// 测试数据导入
/// </summary>
/// <returns></returns>
[HttpPost("data")]
[AllowAnonymous]
public async Task ImportMoldsData()
{
List<(string pId, string eqpId)> multi = new()
{
("25546268026149","25530823999765"),
("25546256076325","25530834099477"),
};
List<MoldsEntity> list = new();
var index = 1;
foreach (var item in multi)
{
MoldsEntity entity = new();
entity.Id = SnowflakeIdHelper.NextId();
entity.MoldCode = $"m00{index}";
entity.MoldName = "磨具" + index;
entity.ItemId = item.pId;
entity.EqpId = item.eqpId;
list.Add(entity);
index++;
}
var link = await _repository.GetFirstAsync(x => x.FullName == "tnb_eqp");
var db = _dataBaseManager.ChangeDataBase(link);
var row = await db.Insertable(list).ExecuteCommandAsync();
if (row > 0)
{
foreach (var item in list)
{
var dic = new Dictionary<string, object>
{
{"id",item.EqpId },
{ "mold_id", item.Id}
};
var row2 = await db.Updateable(dic).AS("eqp_equipment")
.WhereColumns("id").
ExecuteCommandAsync();
}
}
await Task.CompletedTask;
}
}
}