This commit is contained in:
FanLian
2023-07-17 11:33:30 +08:00
13 changed files with 301 additions and 112 deletions

View File

@@ -0,0 +1,16 @@
namespace Tnb.BasicData
{
public static class WebApiConst
{
#region wms
//mes生产入库接口
public const string MES_CREATE_INSTOCK = "/api/wms/wms-in-stock/mes-create-instock";
//载具签收接口
public const string MES_CARRY_SIGN = "/api/wms/wms-sign-for-delivery/mes-carry-sign";
#endregion
}
}

View File

@@ -0,0 +1,34 @@
namespace Tnb.ProductionMgr.Entities.Dto
{
public class PrdInstockInput
{
/// <summary>
/// 单据类型
/// </summary>
public string bill_type { get; set; } = string.Empty;
/// <summary>
/// 载具编号
/// </summary>
public string carry_code { get; set; } = string.Empty;
/// <summary>
/// 起始库位编号
/// </summary>
public string location_code { get; set; } = string.Empty;
/// <summary>
/// 检验(0-未检 1-已检)
/// </summary>
public int is_check { get; set; }
/// <summary>
/// 子表明细
/// </summary>
public List<Dictionary<string,string>> details { get; set; }
}
}

View File

@@ -37,7 +37,7 @@ public partial class PrdInstockD : BaseEntity<string>
/// <summary> /// <summary>
/// 数量 /// 数量
/// </summary> /// </summary>
public string quantity { get; set; } = string.Empty; public int quantity { get; set; }
/// <summary> /// <summary>
/// 批次 /// 批次
@@ -49,4 +49,9 @@ public partial class PrdInstockD : BaseEntity<string>
/// </summary> /// </summary>
public string barcode { get; set; } = string.Empty; public string barcode { get; set; } = string.Empty;
/// <summary>
/// 生产提报id
/// </summary>
public string report_id { get; set; } = string.Empty;
} }

View File

@@ -38,16 +38,12 @@ public partial class PrdInstockH : BaseEntity<string>
/// 起始库位编号 /// 起始库位编号
/// </summary> /// </summary>
public string location_code { get; set; } = string.Empty; public string location_code { get; set; } = string.Empty;
/// <summary>
/// 来源单据ID
/// </summary>
public string source_id { get; set; } = string.Empty;
/// <summary> /// <summary>
/// 检验(0-未检 1-已检) /// 检验(0-未检 1-已检)
/// </summary> /// </summary>
public string is_check { get; set; } = string.Empty; public int is_check { get; set; }
/// <summary> /// <summary>
/// 创建用户 /// 创建用户

View File

@@ -1,3 +1,5 @@
using Tnb.ProductionMgr.Entities.Dto;
namespace Tnb.ProductionMgr.Interfaces namespace Tnb.ProductionMgr.Interfaces
{ {
/// <summary> /// <summary>
@@ -6,6 +8,13 @@ namespace Tnb.ProductionMgr.Interfaces
public interface IPrdInstockService public interface IPrdInstockService
{ {
/// <summary>
/// 生产入库报错
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public Task<dynamic> SaveData(PrdInstockInput input);
/// <summary> /// <summary>
/// 入库申请同步 /// 入库申请同步
/// </summary> /// </summary>

View File

@@ -1,13 +1,16 @@
using JNPF;
using JNPF.Common.Core.Manager; using JNPF.Common.Core.Manager;
using JNPF.Common.Enums; using JNPF.Common.Enums;
using JNPF.Common.Security; using JNPF.Common.Security;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using JNPF.DynamicApiController; using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException; using JNPF.FriendlyException;
using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Interfaces.System; using JNPF.Systems.Interfaces.System;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.ClearScript.Util.Web; using Microsoft.ClearScript.Util.Web;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities; using Tnb.BasicData.Entities;
using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities;
@@ -16,6 +19,7 @@ using Tnb.ProductionMgr.Interfaces;
using Tnb.ProductionMgr.Entities.Consts; using Tnb.ProductionMgr.Entities.Consts;
using Tnb.WarehouseMgr; using Tnb.WarehouseMgr;
using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities;
using Tnb.BasicData;
namespace Tnb.ProductionMgr namespace Tnb.ProductionMgr
{ {
@@ -29,20 +33,20 @@ namespace Tnb.ProductionMgr
private readonly ISqlSugarRepository<PrdFeedingH> _repository; private readonly ISqlSugarRepository<PrdFeedingH> _repository;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IBillRullService _billRullService; private readonly IBillRullService _billRullService;
private readonly WmsSignForDeliveryService _wmsSignForDeliveryService; // private readonly WmsSignForDeliveryService _wmsSignForDeliveryService;
public PrdFeedingService( public PrdFeedingService(
ISqlSugarRepository<PrdFeedingH> repository, ISqlSugarRepository<PrdFeedingH> repository,
IBillRullService billRullService, IBillRullService billRullService,
WmsSignForDeliveryService wmsSignForDeliveryService, // WmsSignForDeliveryService wmsSignForDeliveryService,
IUserManager userManager IUserManager userManager
) )
{ {
_repository = repository; _repository = repository;
_userManager = userManager; _userManager = userManager;
_wmsSignForDeliveryService = _wmsSignForDeliveryService; // _wmsSignForDeliveryService = _wmsSignForDeliveryService;
_billRullService = billRullService; _billRullService = billRullService;
} }
@@ -143,12 +147,12 @@ namespace Tnb.ProductionMgr
if (result.IsSuccess) if (result.IsSuccess)
{ {
//签收后调用载具签收接口 //签收后调用载具签收接口
await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput() // await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
{ // {
org_id = _userManager.GetUserInfo().Result.organizeId, // org_id = _userManager.GetUserInfo().Result.organizeId,
create_id = _userManager.UserId, // create_id = _userManager.UserId,
carry_code = input.carry_code ?? "", // carry_code = input.carry_code ?? "",
}); // });
} }
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage); if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);
@@ -257,12 +261,26 @@ namespace Tnb.ProductionMgr
if (result.IsSuccess) if (result.IsSuccess)
{ {
//签收后调用载具签收接口 //签收后调用载具签收接口
await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput() // await _wmsSignForDeliveryService.MESCarrySign(new MESCarrySignInput()
// {
// org_id = _userManager.GetUserInfo().Result.organizeId,
// create_id = _userManager.UserId,
// carry_code = input.carry_code ?? "",
// });
var mesCarrySignInput = new MESCarrySignInput()
{ {
org_id = _userManager.GetUserInfo().Result.organizeId, org_id = _userManager.GetUserInfo().Result.organizeId,
create_id = _userManager.UserId, create_id = _userManager.UserId,
carry_code = input.carry_code ?? "", carry_code = input.carry_code ?? "",
}); };
string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host;
Dictionary<string, object> header = new Dictionary<string, object>()
{
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
};
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CARRY_SIGN,JsonConvert.SerializeObject(mesCarrySignInput),header);
} }
if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage); if(!result.IsSuccess) throw Oops.Oh(result.ErrorMessage);

View File

@@ -1,12 +1,24 @@
using JNPF;
using JNPF.Common.Core.Manager; using JNPF.Common.Core.Manager;
using JNPF.Common.Enums;
using JNPF.DependencyInjection; using JNPF.DependencyInjection;
using JNPF.DynamicApiController; using JNPF.DynamicApiController;
using JNPF.Extras.CollectiveOAuth.Utils;
using JNPF.FriendlyException;
using JNPF.RemoteRequest;
using JNPF.Systems.Interfaces.System; using JNPF.Systems.Interfaces.System;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using SqlSugar; using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.ProductionMgr.Entities; using Tnb.ProductionMgr.Entities;
using Tnb.ProductionMgr.Entities.Dto; using Tnb.ProductionMgr.Entities.Dto;
using Tnb.ProductionMgr.Interfaces; using Tnb.ProductionMgr.Interfaces;
using Tnb.WarehouseMgr;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.BasicData;
namespace Tnb.ProductionMgr namespace Tnb.ProductionMgr
{ {
@@ -19,18 +31,112 @@ namespace Tnb.ProductionMgr
{ {
private readonly ISqlSugarRepository<PrdInstockH> _repository; private readonly ISqlSugarRepository<PrdInstockH> _repository;
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IBillRullService _billRullService;
public PrdInstockService( public PrdInstockService(
ISqlSugarRepository<PrdInstockH> repository, ISqlSugarRepository<PrdInstockH> repository,
IBillRullService billRullService,
IUserManager userManager IUserManager userManager
) )
{ {
_repository = repository; _repository = repository;
_userManager = userManager; _userManager = userManager;
_billRullService = billRullService; }
[HttpPost]
public async Task<dynamic> SaveData(PrdInstockInput input)
{
var db = _repository.AsSugarClient();
var location = await db.Queryable<BasLocation>().FirstAsync(x => x.location_code == input.location_code);
PrdInstockH prdInstockH = null;
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
prdInstockH = new PrdInstockH()
{
bill_type = input.bill_type,
bill_date = DateTime.Now,
create_id = _userManager.UserId,
location_code = input.location_code,
carry_code = input.carry_code,
is_check = input.is_check,
org_id = _userManager.GetUserInfo().Result.organizeId,
warehouse_id = location?.wh_id,
status = 0,
};
List<PrdInstockD> prdInstockDs = new List<PrdInstockD>() { };
foreach (var item in input.details)
{
prdInstockDs.Add(new PrdInstockD()
{
instock_id = prdInstockH.id,
report_id = item.ContainsKey("report_id") ? item["report_id"] : "",
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
code_batch = item.ContainsKey("batch") ? item["batch"] : "",
barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "",
quantity = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
});
}
await _repository.InsertAsync(prdInstockH);
if (prdInstockDs.Count > 0)
{
await db.Insertable<PrdInstockD>(prdInstockDs).ExecuteCommandAsync();
}
});
if (result.IsSuccess)
{
MESCreateInstockInput mesCreateInstockInput = new MESCreateInstockInput();
mesCreateInstockInput.instock = new MESWmsInstockHInput()
{
org_id = _userManager.GetUserInfo().Result.organizeId,
bill_date = DateTime.Now,
bill_type = input.bill_type,
warehouse_id = location?.wh_id,
source_id = prdInstockH.id,
create_id = _userManager.UserId,
carry_code = input.carry_code,
location_code = input.location_code,
is_check = input.is_check,
};
mesCreateInstockInput.instockds = new List<MESWmsInstockDInput>();
mesCreateInstockInput.instockcodes = new List<MESWmsInstockCodeInput>();
foreach (var item in input.details)
{
mesCreateInstockInput.instockds.Add(new MESWmsInstockDInput()
{
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
code_batch = item.ContainsKey("batch") ? item["batch"] : "",
pr_qty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
});
mesCreateInstockInput.instockcodes.Add(new MESWmsInstockCodeInput()
{
material_id = item.ContainsKey("material_id") ? item["material_id"] : "",
material_code = item.ContainsKey("material_code") ? item["material_code"] : "",
unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "",
code_batch = item.ContainsKey("batch") ? item["batch"] : "",
barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "",
codeqty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"),
});
}
string domain = (App.HttpContext.Request.IsHttps ? "https://" : "http://") + App.HttpContext.Request.Host;
Dictionary<string, object> header = new Dictionary<string, object>()
{
["Authorization"] = App.HttpContext.Request.Headers["Authorization"]
};
var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header);
Console.WriteLine(sendResult);
}
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
} }
/// <summary> /// <summary>

View File

@@ -15,7 +15,6 @@
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" /> <ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" /> <ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" /> <ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr\Tnb.WarehouseMgr.csproj" />
<ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" /> <ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -555,20 +555,13 @@ namespace Tnb.WarehouseMgr
//根据载具ID更新是否锁定和赋值起始库位 //根据载具ID更新是否锁定和赋值起始库位
if (setCarryColumnsExp != null) if (setCarryColumnsExp != null)
{ {
if (input.CarryIds?.Count > 0) Expression<Func<WmsCarryH, bool>> whereExp = input.CarryIds?.Count > 0 ? it => input.CarryIds.Contains(it.id) : it => it.id == input.CarryId;
{ await _db.Updateable<WmsCarryH>().SetColumns(setCarryColumnsExp).Where(whereExp).ExecuteCommandAsync();
await _db.Updateable<WmsCarryH>().SetColumns(setCarryColumnsExp).Where(it => input.CarryIds.Contains(it.id)).ExecuteCommandAsync();
}
else
{
await _db.Updateable<WmsCarryH>().SetColumns(setCarryColumnsExp).Where(it => it.id == input.CarryId).ExecuteCommandAsync();
}
} }
//根据所有库位更新库位的锁定状态为“锁定” //根据所有库位更新库位的锁定状态为“锁定”
if (setLocaionColumbExp != null) if (setLocaionColumbExp != null && input.LocationIds?.Count > 0)
{ {
await _db.Updateable<BasLocation>().SetColumns(setLocaionColumbExp).Where(it => input.LocationIds!.Contains(it.id)).ExecuteCommandAsync(); await _db.Updateable<BasLocation>().SetColumns(setLocaionColumbExp).Where(it => input.LocationIds.Contains(it.id)).ExecuteCommandAsync();
} }
await _db.Ado.CommitTranAsync(); await _db.Ado.CommitTranAsync();
} }

View File

@@ -150,7 +150,7 @@ namespace Tnb.WarehouseMgr
carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch })
.Select(x => .Select(x =>
{ {
WmsCarryMat? carryMat = x.FirstOrDefault(); WmsCarryMat carryMat = new();
carryMat.need_qty = x.Sum(d => d.need_qty); carryMat.need_qty = x.Sum(d => d.need_qty);
return carryMat; return carryMat;
}) })
@@ -353,11 +353,19 @@ namespace Tnb.WarehouseMgr
{ {
List<WmsCarryMat> carryMats = new(); List<WmsCarryMat> carryMats = new();
List<WmsCarryCode> carryCodes = new(); List<WmsCarryCode> carryCodes = new();
var whereExp = Expressionable.Create<WmsCarryH, WmsCarryCode, BasLocation>()
.And((a, b, c) => a.is_lock == 0)
.And((a, b, c) => !string.IsNullOrEmpty(a.location_id))
.And((a, b, c) => a.status == (int)EnumCarryStatus.)
.And((a, b, c) => c.is_type == ((int)EnumLocationType.).ToString());
foreach (var os in outStockDList) foreach (var os in outStockDList)
{ {
whereExp.And((a, b, c) => b.material_id == os.material_id)
.AndIF(!string.IsNullOrEmpty(os.code_batch), (a, b, c) => b.code_batch == os.code_batch);
var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id) var carryCodesPart = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((a, b) => a.id == b.carry_id).InnerJoin<BasLocation>((a, b, c) => a.location_id == c.id)
.Where((a, b, c) => b.material_id == os.material_id && a.is_lock == 0 && !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus. && c.is_type == ((int)EnumLocationType.).ToString()) .Where(whereExp.ToExpression())
.WhereIF(!string.IsNullOrEmpty(os.code_batch), (a, b) => b.code_batch == os.code_batch)
.Select<WmsCarryCode>() .Select<WmsCarryCode>()
.ToListAsync(); .ToListAsync();
if (carryCodesPart?.Count > 0) if (carryCodesPart?.Count > 0)
@@ -399,7 +407,7 @@ namespace Tnb.WarehouseMgr
carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch })
.Select(x => .Select(x =>
{ {
WmsCarryMat? carryMat = x.FirstOrDefault()!; WmsCarryMat carryMat = new();
carryMat.need_qty = x.Sum(d => d.need_qty); carryMat.need_qty = x.Sum(d => d.need_qty);
return carryMat; return carryMat;
}) })
@@ -435,10 +443,8 @@ namespace Tnb.WarehouseMgr
List<string> locIds = new(); List<string> locIds = new();
foreach (var carry in carrys) foreach (var carry in carrys)
{ {
WmsPointH sPoint = null!; WmsPointH sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
WmsPointH ePoint = null!; WmsPointH ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == outstock.location_id.ToString());
sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == carry.location_id);
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == outstock.location_id.ToString());
if (sPoint != null && ePoint != null) if (sPoint != null && ePoint != null)
{ {

View File

@@ -50,7 +50,7 @@ namespace Tnb.WarehouseMgr
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public async Task PackSortingByAdd() public async Task PackSortingByAdd(WmsCarryMat? carryMat)
{ {
var setSortings = await _db.Queryable<WmsSetsortingH>() var setSortings = await _db.Queryable<WmsSetsortingH>()
.Where(a => a.status == WmsWareHouseConst.BILLSTATUS_ADD_ID).OrderBy(a => a.seq) .Where(a => a.status == WmsWareHouseConst.BILLSTATUS_ADD_ID).OrderBy(a => a.seq)
@@ -142,10 +142,11 @@ namespace Tnb.WarehouseMgr
List<WmsPretaskH> preTasks = new(); List<WmsPretaskH> preTasks = new();
List<string> locIds = new(); List<string> locIds = new();
string firstLocationId = "27010980724501", secondLocationId = "27010987857941"; string firstLocationId = "27010980724501", secondLocationId = "27010987857941";
if (carrys.Length > 6) var mid = 6;
if (carrys.Length > mid)
{ {
var leftCarrys = carrys[..6]; var leftCarrys = carrys[..mid];
var rightCarrys = carrys[6..]; var rightCarrys = carrys[mid..];
await InnerGenPreTask(leftCarrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks); await InnerGenPreTask(leftCarrys, locIds, firstLocationId, singleSorting.id, singleSorting.bill_code, preTasks);
await InnerGenPreTask(rightCarrys, locIds, secondLocationId, singleSorting.id, singleSorting.bill_code, preTasks); await InnerGenPreTask(rightCarrys, locIds, secondLocationId, singleSorting.id, singleSorting.bill_code, preTasks);
} }
@@ -167,7 +168,7 @@ namespace Tnb.WarehouseMgr
pretaskCodes.AddRange(curPreTaskCodes); pretaskCodes.AddRange(curPreTaskCodes);
} }
await _wareHouseService.GenPreTask(preTasks, pretaskCodes); await _wareHouseService.GenPreTask(preTasks, pretaskCodes);
await _db.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it=> it.id == singleSorting.id).ExecuteCommandAsync(); await _db.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == singleSorting.id).ExecuteCommandAsync();
GenPreTaskUpInput genPreTaskAfterUpInput = new(); GenPreTaskUpInput genPreTaskAfterUpInput = new();
genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList(); genPreTaskAfterUpInput.CarryIds = preTasks.Select(x => x.carry_id).ToList();
genPreTaskAfterUpInput.LocationIds = new HashSet<string>(locIds).ToList(); genPreTaskAfterUpInput.LocationIds = new HashSet<string>(locIds).ToList();
@@ -298,7 +299,7 @@ namespace Tnb.WarehouseMgr
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId); var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.id == carryId);
if (carry != null) if (carry != null)
{ {
if (carry!.location_id!.IsNotEmptyOrNull()) if (carry.location_id?.IsNotEmptyOrNull() ?? false)
{ {
await _db.Updateable<BasLocation>().SetColumns(it => new BasLocation { is_use = ((int)EnumCarryStatus.).ToString() }).Where(it => it.id == carry.location_id).ExecuteCommandAsync(); await _db.Updateable<BasLocation>().SetColumns(it => new BasLocation { is_use = ((int)EnumCarryStatus.).ToString() }).Where(it => it.id == carry.location_id).ExecuteCommandAsync();
} }

View File

@@ -81,11 +81,11 @@ namespace Tnb.WarehouseMgr
if (carrys?.Count > 0) if (carrys?.Count > 0)
{ {
var firstCarry = carrys.FirstOrDefault(); var firstCarry = carrys.FirstOrDefault();
GenPreTaskUpInput genPreTaskInput = new() { CarryId = firstCarry!.id! }; GenPreTaskUpInput genPreTaskInput = new() { CarryId = firstCarry?.id };
await _warehouseService.GenInStockTaskHandleAfter(genPreTaskInput, it => new WmsCarryH { is_lock = 1 }, null!); await _warehouseService.GenInStockTaskHandleAfter(genPreTaskInput, it => new WmsCarryH { is_lock = 1 }, null!);
ko.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID; ko.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID;
ko.carry_id = firstCarry.id; ko.carry_id = firstCarry?.id;
ko.carry_code = firstCarry.carry_code; ko.carry_code = firstCarry?.carry_code;
await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync(); await _db.Updateable(ko).UpdateColumns(it => new { it.status, it.carry_id, it.carry_code }).ExecuteCommandAsync();
} }
else else
@@ -172,7 +172,7 @@ namespace Tnb.WarehouseMgr
{ {
var sPoint = it.FirstOrDefault(); var sPoint = it.FirstOrDefault();
var ePoint = it.LastOrDefault(); var ePoint = it.LastOrDefault();
WmsPretaskH preTask = new(); WmsPretaskH preTask = new();
preTask.org_id = _userManager.User.OrganizeId; preTask.org_id = _userManager.User.OrganizeId;
preTask.startlocation_id = sPoint?.location_id!; preTask.startlocation_id = sPoint?.location_id!;
@@ -184,7 +184,7 @@ namespace Tnb.WarehouseMgr
preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(); preTask.bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult();
preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID; preTask.status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID;
preTask.biz_type = ko.biz_type; preTask.biz_type = ko.biz_type;
preTask.task_type = WmsWareHouseConst.WMS_PRETASK_OUTSTOCK_TYPE_ID; preTask.task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID;
preTask.carry_id = ko!.carry_id!; preTask.carry_id = ko!.carry_id!;
preTask.carry_code = ko!.carry_code!; preTask.carry_code = ko!.carry_code!;
preTask.area_id = sPoint?.area_id!; preTask.area_id = sPoint?.area_id!;

View File

@@ -22,74 +22,80 @@ namespace Tnb.TaskScheduler.Listener
/// <summary> /// <summary>
/// 生成质检任务 /// 生成质检任务
/// </summary> /// </summary>
public class QcTaskTimeWorker //: ISpareTimeWorker public class QcTaskTimeWorker : ISpareTimeWorker
{ {
private ISqlSugarClient repository => App.GetService<ISqlSugarClient>(); private ISqlSugarRepository<QcCheckPlanH> repository => App.GetService<ISqlSugarRepository<QcCheckPlanH>>();
//[SpareTime("0 0 0 * * ?", "生成质检任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)] [SpareTime("0 0 0 * * ?", "生成质检任务", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)]
public async void CreateTask(SpareTimer timer, long count) public async void CreateTask(SpareTimer timer, long count)
{ {
var timeTaskEntity = await repository.Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync(); try
if (timeTaskEntity == null)
return;
ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
var PlanH = await repository.Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
var PlanDs = await repository.Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
if (PlanH == null || PlanDs.Count == 0)
return;
var PlanMaterials = repository.Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToList();
var PlanProcesss = repository.Queryable<QcCheckPlanProcess>().Where(p => p.planid == PlanH.id).Select(p => p.processid).ToList();
var PlanWork = repository.Queryable<QcCheckPlanWork>().Where(p => p.planid == PlanH.id).Select(p => p.workid).ToList();
//物料工序工位不能同时为空
if (PlanMaterials.Count == 0 && PlanProcesss.Count == 0 && PlanWork.Count == 0)
return;
var PrdMoTasks = await repository.Queryable<PrdMoTask>()
.WhereIF(PlanMaterials.Count > 0, p => PlanMaterials.Contains(p.material_id))
.WhereIF(PlanProcesss.Count > 0, p => PlanProcesss.Contains(p.process_id))
.WhereIF(PlanWork.Count > 0, p => PlanWork.Contains(p.workstation_id))
.Where(p => p.mo_task_status == "InProgress")//进行中
.ToListAsync();
var DictionaryType = await repository.Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
var DictionaryData = await repository.Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
foreach (var PrdMoTask in PrdMoTasks)
{ {
QcCheckExecH qcCheckExecH = new QcCheckExecH(); var timeTaskEntity = await repository.AsSugarClient().Queryable<TimeTaskEntity>().Where(p => p.Id == timer.WorkerName && p.EnabledMark == 1).FirstAsync();
qcCheckExecH.id = SnowflakeIdHelper.NextId(); if (timeTaskEntity == null)
qcCheckExecH.checktype = PlanH.checktype; return;
qcCheckExecH.status = DictionaryData.Id; ContentModel? comtentModel = timeTaskEntity.ExecuteContent.ToObject<ContentModel>();
qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); var PlanH = await repository.AsSugarClient().Queryable<QcCheckPlanH>().Where(p => p.id == comtentModel.parameter.Where(p => p.field == "id").First().value).FirstAsync();
qcCheckExecH.materialid = PrdMoTask.material_id; var PlanDs = await repository.AsSugarClient().Queryable<QcCheckPlanD>().Where(p => p.mainid == PlanH.id).ToListAsync();
qcCheckExecH.processid = PrdMoTask.process_id; if (PlanH == null || PlanDs.Count == 0)
qcCheckExecH.workid = PrdMoTask.workstation_id; return;
var ExecDs = new List<QcCheckExecD>(); var PlanMaterials = repository.AsSugarClient().Queryable<QcCheckPlanMaterial>().Where(p => p.planid == PlanH.id).Select(p => p.materialid).ToList();
foreach (var PlanD in PlanDs) var PlanProcesss = repository.AsSugarClient().Queryable<QcCheckPlanProcess>().Where(p => p.planid == PlanH.id).Select(p => p.processid).ToList();
var PlanWork = repository.AsSugarClient().Queryable<QcCheckPlanWork>().Where(p => p.planid == PlanH.id).Select(p => p.workid).ToList();
//物料工序工位不能同时为空
if (PlanMaterials.Count == 0 && PlanProcesss.Count == 0 && PlanWork.Count == 0)
return;
var PrdMoTasks = await repository.AsSugarClient().Queryable<PrdMoTask>()
.WhereIF(PlanMaterials.Count > 0, p => PlanMaterials.Contains(p.material_id))
.WhereIF(PlanProcesss.Count > 0, p => PlanProcesss.Contains(p.process_id))
.WhereIF(PlanWork.Count > 0, p => PlanWork.Contains(p.workstation_id))
.Where(p => p.mo_task_status == "InProgress")//进行中
.ToListAsync();
var DictionaryType = await repository.AsSugarClient().Queryable<DictionaryTypeEntity>().Where(p => p.FullName == "质检状态").FirstAsync();
var DictionaryData = await repository.AsSugarClient().Queryable<DictionaryDataEntity>().Where(p => p.DictionaryTypeId == DictionaryType.Id && p.FullName == "待执行").FirstAsync();
foreach (var PrdMoTask in PrdMoTasks)
{ {
QcCheckExecD QcCheckExecD = new QcCheckExecD(); QcCheckExecH qcCheckExecH = new QcCheckExecH();
QcCheckExecD.mainid = qcCheckExecH.id; qcCheckExecH.id = SnowflakeIdHelper.NextId();
QcCheckExecD.extype = PlanD.extype; qcCheckExecH.checktype = PlanH.checktype;
QcCheckExecD.excontent = PlanD.excontent; qcCheckExecH.status = DictionaryData.Id;
QcCheckExecD.check = PlanD.check; qcCheckExecH.tasktime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
QcCheckExecD.errorcause = PlanD.errorcause; qcCheckExecH.materialid = PrdMoTask.material_id;
QcCheckExecD.errorlevel = PlanD.errorlevel; qcCheckExecH.processid = PrdMoTask.process_id;
QcCheckExecD.remark = PlanD.remark; qcCheckExecH.workid = PrdMoTask.workstation_id;
QcCheckExecD.attachment = PlanD.attachment; var ExecDs = new List<QcCheckExecD>();
QcCheckExecD.isexec = PlanD.isexec; foreach (var PlanD in PlanDs)
QcCheckExecD.custom = PlanD.custom; {
QcCheckExecD.typeid = PlanD.typeid; QcCheckExecD QcCheckExecD = new QcCheckExecD();
QcCheckExecD.itemid = PlanD.itemid; QcCheckExecD.mainid = qcCheckExecH.id;
ExecDs.Add(QcCheckExecD); QcCheckExecD.extype = PlanD.extype;
QcCheckExecD.excontent = PlanD.excontent;
QcCheckExecD.check = PlanD.check;
QcCheckExecD.errorcause = PlanD.errorcause;
QcCheckExecD.errorlevel = PlanD.errorlevel;
QcCheckExecD.remark = PlanD.remark;
QcCheckExecD.attachment = PlanD.attachment;
QcCheckExecD.isexec = PlanD.isexec;
QcCheckExecD.custom = PlanD.custom;
QcCheckExecD.typeid = PlanD.typeid;
QcCheckExecD.itemid = PlanD.itemid;
ExecDs.Add(QcCheckExecD);
}
await repository.AsSugarClient().Insertable(qcCheckExecH).ExecuteCommandAsync();
await repository.AsSugarClient().Insertable(ExecDs).ExecuteCommandAsync();
}
//只执行一次的 修改EnabledMark字段
var InterfaceParameter = comtentModel.parameter.Where(p => p.field == "doonce").FirstOrDefault();
if (InterfaceParameter != null && bool.Parse(InterfaceParameter.value))
{
timeTaskEntity.EnabledMark = 0;
await repository.AsSugarClient().Updateable(timeTaskEntity).ExecuteCommandAsync();
SpareTime.Cancel(timeTaskEntity.Id);
} }
await repository.Insertable(qcCheckExecH).ExecuteCommandAsync();
await repository.Insertable(ExecDs).ExecuteCommandAsync();
} }
//只执行一次的 修改EnabledMark字段 catch (Exception)
var InterfaceParameter = comtentModel.parameter.Where(p => p.field == "doonce").FirstOrDefault(); {
if (InterfaceParameter != null && bool.Parse(InterfaceParameter.value))
{
timeTaskEntity.EnabledMark = 0;
await repository.Updateable(timeTaskEntity).ExecuteCommandAsync();
SpareTime.Cancel(timeTaskEntity.Id);
} }
} }