From ed87bd712cbada7a293a89eed0759e9e25d2d64f Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Mon, 15 May 2023 18:11:11 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=8C=E7=BB=84=E8=A3=85=E5=8C=85=E8=A3=85?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEBomId=E6=8B=86=E8=A7=A3=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/DictConst.cs | 4 + .../PrdManage/PackingSchedulingListOutput.cs | 39 ++++ .../PrdManage/ProductionSchedulingCrInput.cs | 7 +- .../Tnb.ProductionMgr/PrdMoTaskService.cs | 218 +++++++++++------- .../System/DataInterfaceService.cs | 2 +- 5 files changed, 186 insertions(+), 84 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs index 1ec40090..65d4215e 100644 --- a/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs +++ b/BasicData/Tnb.BasicData.Entities/Consts/DictConst.cs @@ -26,6 +26,10 @@ public static class DictConst /// public const string AlreadyId = "26033187948309"; /// + /// 工单状态-已下发Id + /// + public const string ScheduledId = "25019232867093"; + /// /// 工单状态-待排产 /// public const string WaitProductId = "25019244276501"; diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs new file mode 100644 index 00000000..888e67ae --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 组装、包装排产列表输出类 + /// + public class PackingSchedulingListOutput + { + /// + /// 产线Id + /// + public string workline_id { get; set; } + /// + /// 产线名称 + /// + public string workline_name { get; set; } + /// + /// 生产任务单号 + /// + public string mo_task_code { get; set; } + /// + /// 物料编码 + /// + public string material_code { get; set; } + /// + /// 物料名称 + /// + public string material_name { get; set; } + /// + /// 产出数量 + /// + public string qty { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs index 1af7cedc..54744d0d 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/ProductionSchedulingCrInput.cs @@ -78,7 +78,7 @@ namespace Tnb.ProductionMgr.Entities.Dto /// Default:NULL::character varying /// Nullable:True /// - public string line_id { get; set; } + public string workline_id { get; set; } /// @@ -106,6 +106,11 @@ namespace Tnb.ProductionMgr.Entities.Dto /// 已排产数量 /// public int scheduled_qty { get; set; } + + /// + /// 生产bom id + /// + public string bom_id { get; set; } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index af168855..97cd1577 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -32,6 +32,7 @@ using JNPF.VisualDev.Entitys; using Aop.Api.Domain; using Senparc.Weixin.MP.AdvancedAPIs.Card; using Aspose.Cells.Drawing.Texts; +using JNPF.Systems.Entitys.Permission; namespace Tnb.ProductionMgr { @@ -48,6 +49,7 @@ namespace Tnb.ProductionMgr private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; private static Dictionary _dicDefect = new Dictionary(); + private static Dictionary _dicWorkLine = new Dictionary(); private readonly ISqlSugarClient _db; @@ -374,6 +376,7 @@ namespace Tnb.ProductionMgr } + #endregion @@ -403,99 +406,149 @@ namespace Tnb.ProductionMgr { var db = _repository.AsSugarClient(); var row = -1; - if (input.schedule_type.HasValue && input.schedule_type.Value == 1) + if (input.schedule_type.HasValue) { - var moTask = input.Adapt(); - moTask.id = SnowflakeIdHelper.NextId(); - moTask.create_id = _userManager.UserId; - moTask.create_time = DateTime.Now; - moTask.mo_task_status = DictConst.ToBeScheduledEncode; - moTask.scheduled_qty = input.scheduled_qty; + if (input.schedule_type.Value == 1) //注塑、基础排产 + { + var moTask = input.Adapt(); + moTask.id = SnowflakeIdHelper.NextId(); + moTask.create_id = _userManager.UserId; + moTask.create_time = DateTime.Now; + moTask.mo_task_status = DictConst.ToBeScheduledEncode; + moTask.scheduled_qty = input.scheduled_qty; - var mo = await db.Queryable().FirstAsync(it => it.id == input.mo_id); - var moCode = mo?.mo_code; - var taskCode = await db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); - if (taskCode.IsNullOrEmpty()) - { - moTask.mo_task_code = $"{moCode}-01"; - } - else - { - var pos = taskCode.IndexOf("-", StringComparison.Ordinal); - if (pos > -1) + var mo = await db.Queryable().FirstAsync(it => it.id == input.mo_id); + var moCode = mo?.mo_code; + var taskCode = await db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); + if (taskCode.IsNullOrEmpty()) { - var sb = new StringBuilder(); - var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); - var code = taskCode.AsSpan().Slice(0, pos).ToString(); - var n = (num + 1).ToString().PadLeft(2, '0'); - moTask.mo_task_code = sb.Append(code).Append("-").Append(n).ToString(); + moTask.mo_task_code = $"{moCode}-01"; } - } - try - { - await db.Ado.BeginTranAsync(); - row = await db.Insertable(moTask).ExecuteCommandAsync(); - - //根据工单号获取当前工单包含的已排产数 - var schedQty = db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty); - - if (mo != null) - {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产 - if (schedQty.HasValue && schedQty.Value >= mo.plan_qty) + else + { + var pos = taskCode.IndexOf("-", StringComparison.Ordinal); + if (pos > -1) { - mo.mo_status = DictConst.AlreadyId; - row = await db.Updateable(mo).ExecuteCommandAsync(); - } - else - { - if (schedQty.HasValue) - mo.scheduled_qty = schedQty.Value; + var sb = new StringBuilder(); + var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); + var code = taskCode.AsSpan().Slice(0, pos).ToString(); + var n = (num + 1).ToString().PadLeft(2, '0'); + moTask.mo_task_code = sb.Append(code).Append("-").Append(n).ToString(); } } - var material = await db.Queryable().FirstAsync(it => it.id == moTask.material_id); + try + { + await db.Ado.BeginTranAsync(); + row = await db.Insertable(moTask).ExecuteCommandAsync(); - var taskLog = new PrdTaskLog(); - taskLog.id = SnowflakeIdHelper.NextId(); - taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code; - taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code; - taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code; - taskLog.item_code = material?.code; - taskLog.item_standard = material?.material_standard; - taskLog.status = DictConst.ToBeScheduledEncode; - taskLog.operator_name = _userManager.RealName; - taskLog.create_id = _userManager.UserId; - taskLog.create_time = DateTime.Now; - taskLog.mo_task_id = moTask.id; - taskLog.mo_task_code = moTask.mo_task_code; + //根据工单号获取当前工单包含的已排产数 + var schedQty = db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty); - await db.Insertable(taskLog).ExecuteCommandAsync(); - //将生产任务插入到自检报废记录表 - var sacipRecord = new PrdMoTaskDefectRecord(); - sacipRecord.id = SnowflakeIdHelper.NextId(); - sacipRecord.material_code = material?.code; - sacipRecord.material_name = material?.name; - sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; - sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name; - sacipRecord.estimated_start_date = moTask.plan_start_date; - sacipRecord.estimated_end_date = moTask.plan_end_date; - sacipRecord.plan_qty = moTask.plan_qty; - sacipRecord.scrap_qty = moTask.scrap_qty; - sacipRecord.status = moTask.mo_task_status; - sacipRecord.create_id = _userManager.UserId; - sacipRecord.create_time = DateTime.Now; - sacipRecord.mo_task_id = moTask.id; - sacipRecord.mo_task_code = moTask.mo_task_code; - await db.Insertable(sacipRecord).ExecuteCommandAsync(); + if (mo != null) + {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产 + if (schedQty.HasValue && schedQty.Value >= mo.plan_qty) + { + mo.mo_status = DictConst.AlreadyId; + row = await db.Updateable(mo).ExecuteCommandAsync(); + } + else + { + if (schedQty.HasValue) + mo.scheduled_qty = schedQty.Value; + } + } + var material = await db.Queryable().FirstAsync(it => it.id == moTask.material_id); - await db.Ado.CommitTranAsync(); + var taskLog = new PrdTaskLog(); + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code; + taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code; + taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code; + taskLog.item_code = material?.code; + taskLog.item_standard = material?.material_standard; + taskLog.status = DictConst.ToBeScheduledEncode; + taskLog.operator_name = _userManager.RealName; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = moTask.id; + taskLog.mo_task_code = moTask.mo_task_code; + + await db.Insertable(taskLog).ExecuteCommandAsync(); + //将生产任务插入到自检报废记录表 + var sacipRecord = new PrdMoTaskDefectRecord(); + sacipRecord.id = SnowflakeIdHelper.NextId(); + sacipRecord.material_code = material?.code; + sacipRecord.material_name = material?.name; + sacipRecord.eqp_code = (await db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; + sacipRecord.mold_name = (await db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_name; + sacipRecord.estimated_start_date = moTask.plan_start_date; + sacipRecord.estimated_end_date = moTask.plan_end_date; + sacipRecord.plan_qty = moTask.plan_qty; + sacipRecord.scrap_qty = moTask.scrap_qty; + sacipRecord.status = moTask.mo_task_status; + sacipRecord.create_id = _userManager.UserId; + sacipRecord.create_time = DateTime.Now; + sacipRecord.mo_task_id = moTask.id; + sacipRecord.mo_task_code = moTask.mo_task_code; + await db.Insertable(sacipRecord).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + } + catch (Exception ex) + { + await db.Ado.RollbackTranAsync(); + } } - catch (Exception ex) + else if (input.schedule_type.Value == 2) //组装、包装排产 { - await db.Ado.RollbackTranAsync(); + } } return row > 0; } + /// + /// 获取组装包装排产任务列表 + /// + /// + /// + [HttpPost] + public async Task GetPackSchedulingTaskList(ProductionSchedulingCrInput input) + { + if (_dicWorkLine.Count < 1) + { + _dicWorkLine = await _db.Queryable().Where(it => it.Category == "workline").ToDictionaryAsync(x => x.Id, x => x.FullName); + } + var outputList = new List(); + var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); + if (bom != null && bom.route_id.IsNotEmptyOrNull()) + { + var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); + if (routes?.Count > 0) + { + var processIds = routes.Select(x => x.process_id).ToList(); + if (processIds?.Count > 0) + { + var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); + if (bomOutputs?.Count > 0) + { + foreach (var item in bomOutputs) + { + var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); + var output = new PackingSchedulingListOutput(); + output.workline_id = input.workline_id; + output.workline_name = _dicWorkLine.ContainsKey(input.workline_id) ? _dicWorkLine[input.workline_id].ToString() : ""; + output.material_code = material?.code; + output.material_name = material?.name; + output.qty = item.num; + outputList.Add(output); + } + } + } + } + } + return outputList; + } + /// /// 生产任务下发,开始 、结束、完成 /// @@ -588,8 +641,10 @@ namespace Tnb.ProductionMgr } else { - if (taskLog.status != status) + var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); + if (records != null && !records.Select(x => x.status).Contains(status)) { + taskLog.id = SnowflakeIdHelper.NextId(); taskLog.status = status; taskLogEntities.Add(taskLog); @@ -667,7 +722,6 @@ namespace Tnb.ProductionMgr var db = _repository.AsSugarClient(); var report = await db.Queryable().FirstAsync(it => it.mo_task_code == input.mo_task_code); - if (report is not null) { report.mo_task_code = input.mo_task_code; @@ -818,15 +872,15 @@ namespace Tnb.ProductionMgr var result = await db.Ado.UseTranAsync(async () => { var row = -1; - var prdTask = await db.Queryable().FirstAsync(it => it.id == id); + var prdTask = await db.Queryable().FirstAsync(it => it.id == id); row = await db.Deleteable().Where(it => it.id == id).ExecuteCommandAsync(); if (row > 0) { var prdMo = await db.Queryable().FirstAsync(it => it.id == prdTask.mo_id); if (prdMo is not null) { - prdMo.input_qty += prdTask.scheduled_qty; - //prdMo.icmo_status = DictConst.ToBeScheduledEncode; + prdMo.scheduled_qty += prdTask.scheduled_qty; + prdMo.mo_status = DictConst.ScheduledId; row = await db.Updateable(prdMo).ExecuteCommandAsync(); } } diff --git a/system/Tnb.Systems/System/DataInterfaceService.cs b/system/Tnb.Systems/System/DataInterfaceService.cs index 15af8000..ab5b29ba 100644 --- a/system/Tnb.Systems/System/DataInterfaceService.cs +++ b/system/Tnb.Systems/System/DataInterfaceService.cs @@ -1010,7 +1010,7 @@ public class DataInterfaceService : IDataInterfaceService, IDynamicApiController // 将逗号替换成一个单引号、逗号、单引号 item.defaultValue = item.defaultValue?.Replace(",", "','"); - entity.Query = entity.Query?.Replace("{" + item.field + "}", "'" + item.defaultValue + "'"); + entity.Query = entity.Query?.Replace("{" + item.field + "}", item.defaultValue); //自动加引号去掉 modify by ly on 20230515 } else entity.Query = entity.Query?.Replace("{" + item.field + "}", item.defaultValue); From e7e2cea7bd1e03defdf93abd3c71f5210f55ad81 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Tue, 16 May 2023 14:16:59 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=8D=95=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BasMbomOutput.cs | 11 +- .../Dto/PrdManage/MoldListOutput.cs | 4 +- .../Dto/PrdManage/PackSchedlingCrInput.cs | 59 +++++++++ .../PrdManage/PackingSchedulingListOutput.cs | 16 +++ .../Dto/PrdManage/UnPackSchedlingInput.cs | 46 +++++++ .../Entity/Molds.cs | 4 + .../Tnb.ProductionMgr/PrdMoTaskService.cs | 121 +++++++++++++++++- 7 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/UnPackSchedlingInput.cs diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasMbomOutput.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasMbomOutput.cs index 01718078..af24c68c 100644 --- a/BasicData/Tnb.BasicData.Entities/Entity/BasMbomOutput.cs +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasMbomOutput.cs @@ -9,10 +9,13 @@ namespace Tnb.BasicData.Entities [SugarTable("bas_mbom_output")] public class BasMbomOutput : BaseEntity { - public BasMbomOutput() - { - } - + + + /// + /// 工单Id + /// + [SugarColumn(IsIgnore = true)] + public string mo_id { get; set; } /// /// Desc:生产bomid /// Default: diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MoldListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MoldListOutput.cs index 5e689dd0..34be5b6d 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MoldListOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/MoldListOutput.cs @@ -33,9 +33,9 @@ namespace Tnb.ProductionMgr.Entities.Dto /// public string mold_type_code { get; set; } /// - /// 型腔数 + /// 可用台数 /// - public int? cavity_qty { get; set; } + public int available_stations { get; set; } public string mold_id { get; set;} } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs new file mode 100644 index 00000000..baed56c1 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 组装、包装排产输入参数 + /// + public class PackSchedlingCrInput + { + /// + /// bom任务集合 + /// + public List items{ get; set; } + } + + public class PackSchedlingItem + { + /// + /// 工单Id + /// + public string mo_id { get; set; } + /// + /// 生产bomId + /// + public string bom_id { get; set; } + /// + /// 工序id + /// + public string process_id { get; set; } + /// + /// 产线Id + /// + public string workline_id { get; set; } + /// + /// 物料Id + /// + public string material_id { get; set; } + /// + /// 生产任务单号 + /// + public string mo_task_code { get; set; } + /// + /// 物料编码 + /// + public string material_code { get; set; } + /// + /// 物料名称 + /// + public string material_name { get; set; } + /// + /// bom产出料数量 + /// + public string qty { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs index 888e67ae..581be5f6 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackingSchedulingListOutput.cs @@ -11,6 +11,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public class PackingSchedulingListOutput { + /// + /// 工单Id + /// + public string mo_id { get; set; } + /// + /// 工序Id + /// + public string process_id { get; set; } /// /// 产线Id /// @@ -24,6 +32,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public string mo_task_code { get; set; } /// + /// 物料Id + /// + public string material_id { get; set; } + /// /// 物料编码 /// public string material_code { get; set; } @@ -32,6 +44,10 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public string material_name { get; set; } /// + /// 工序名称 + /// + public string process_name { get; set; } + /// /// 产出数量 /// public string qty { get; set; } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/UnPackSchedlingInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/UnPackSchedlingInput.cs new file mode 100644 index 00000000..ba31a885 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/UnPackSchedlingInput.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 拆解组装包装排产输入参数 + /// + public class UnPackSchedlingInput + { + /// + /// 工单Id + /// + public string mo_id { get; set; } + /// + /// 生产任务Id + /// + public string mo_task_id { get; set; } + /// + /// 生产bom Id + /// + public string bom_id { get; set; } + /// + /// 产线Id + /// + public string workline_id { get; set; } + + /// + /// Desc:预计开始时间 + /// Default: + /// Nullable:True + /// + public DateTime? estimated_start_date { get; set; } + + /// + /// Desc:预计结束时间 + /// Default: + /// Nullable:True + /// + public DateTime? estimated_end_date { get; set; } + + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/Molds.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/Molds.cs index 8ec40565..dfd49b6c 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/Molds.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/Molds.cs @@ -177,6 +177,10 @@ namespace Tnb.ProductionMgr.Entities /// Nullable:True /// public string modify_id { get; set; } + /// + /// 模具型号 + /// + public string mold_type_code { get; set; } } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 97cd1577..0e56704d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -33,6 +33,7 @@ using Aop.Api.Domain; using Senparc.Weixin.MP.AdvancedAPIs.Card; using Aspose.Cells.Drawing.Texts; using JNPF.Systems.Entitys.Permission; +using WebSocketSharp.Frame; namespace Tnb.ProductionMgr { @@ -50,6 +51,7 @@ namespace Tnb.ProductionMgr private readonly IVisualDevService _visualDevService; private static Dictionary _dicDefect = new Dictionary(); private static Dictionary _dicWorkLine = new Dictionary(); + private static Dictionary _dicProcess = new Dictionary(); private readonly ISqlSugarClient _db; @@ -108,8 +110,10 @@ namespace Tnb.ProductionMgr mold_id = a.id, mold_code = a.mold_code, mold_name = a.mold_name, + mold_type_code = a.mold_type_code, material_name = b.name, - cavity_qty = a.cavity_qty, + material_code = b.code, + available_stations = SqlFunc.Subqueryable().Where(it => it.mold_id == a.id).Count(), }) .ToListAsync(); return list; @@ -429,11 +433,10 @@ namespace Tnb.ProductionMgr var pos = taskCode.IndexOf("-", StringComparison.Ordinal); if (pos > -1) { - var sb = new StringBuilder(); var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); var code = taskCode.AsSpan().Slice(0, pos).ToString(); var n = (num + 1).ToString().PadLeft(2, '0'); - moTask.mo_task_code = sb.Append(code).Append("-").Append(n).ToString(); + moTask.mo_task_code = $"{code}-{n}"; } } try @@ -509,15 +512,28 @@ namespace Tnb.ProductionMgr /// /// 获取组装包装排产任务列表 /// - /// - /// + /// 拆解bom,生成组装包装任务列表,输入参数 + /// + /// output: + ///
{ + ///
workline_id:产线Id + ///
workline_name:产线名称 + ///
material_code:物料编码 + ///
material_name:物料名称 + ///
qty:输出料数量 + ///
} + ///
[HttpPost] - public async Task GetPackSchedulingTaskList(ProductionSchedulingCrInput input) + public async Task GetPackSchedulingTaskList(UnPackSchedlingInput input) { if (_dicWorkLine.Count < 1) { _dicWorkLine = await _db.Queryable().Where(it => it.Category == "workline").ToDictionaryAsync(x => x.Id, x => x.FullName); } + if (_dicProcess.Count < 1) + { + _dicProcess = await _db.Queryable().Select(it => new { id = it.id, process_name = it.process_name }).Distinct().ToDictionaryAsync(x => x.id, x => x.process_name); + } var outputList = new List(); var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); if (bom != null && bom.route_id.IsNotEmptyOrNull()) @@ -535,8 +551,12 @@ namespace Tnb.ProductionMgr { var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); var output = new PackingSchedulingListOutput(); + output.mo_id = input.mo_id; + output.process_id = item.process_id; output.workline_id = input.workline_id; output.workline_name = _dicWorkLine.ContainsKey(input.workline_id) ? _dicWorkLine[input.workline_id].ToString() : ""; + output.process_name = _dicProcess[item.process_id]?.ToString(); + output.material_id = item.material_id; output.material_code = material?.code; output.material_name = material?.name; output.qty = item.num; @@ -546,8 +566,97 @@ namespace Tnb.ProductionMgr } } } + //生成任务单号 + if (outputList.Count > 0) + { + var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); + if (mo != null && mo.mo_code.IsNotEmptyOrNull()) + { + var taskCodes = outputList.Where(it => it.mo_task_code.IsNotEmptyOrNull()).ToList(); + if (taskCodes == null || taskCodes.Count < 1) + { + for (int i = 1, len = outputList.Count; i <= len; i++) + { + outputList[i - 1].mo_task_code = $"{mo.mo_code}-{i.ToString().PadLeft(2, '0')}"; + } + } + } + } return outputList; } + /// + /// 组装包装排产 + /// + /// + /// + /// + [HttpPost] + public async Task PackSchedling(PackSchedlingCrInput input) + { + if (input.items == null) + { + throw new ArgumentNullException(nameof(input.items)); + } + DbResult dbResult = null; + if (input.items.Count > 0) + { + var moTasks = input.items.Select(x => new PrdMoTask + { + id = SnowflakeIdHelper.NextId(), + mo_task_code = x.mo_task_code, + material_id = x.material_id, + mo_id = x.mo_id, + bom_id = x.bom_id, + create_id = _userManager.UserId, + scheduled_qty = x.qty.ParseToInt(), + create_time = DateTime.Now + }).ToList(); + dbResult = await _db.Ado.UseTranAsync(async () => + { + await _db.Insertable(moTasks).ExecuteCommandAsync(); + List taskLogList = new(); + List taskDefectRecordList = new(); + + foreach (var moTask in moTasks) + { + var material = await _db.Queryable().FirstAsync(it => it.id == moTask.material_id); + var mo = await _db.Queryable().FirstAsync(it => it.id == moTask.mo_id); + var taskLog = new PrdTaskLog(); + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.mo_code = mo?.mo_code; + taskLog.eqp_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; + taskLog.mold_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_code; + taskLog.item_code = material?.code; + taskLog.item_standard = material?.material_standard; + taskLog.status = DictConst.ToBeScheduledEncode; + taskLog.operator_name = _userManager.RealName; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = moTask.id; + taskLog.mo_task_code = moTask.mo_task_code; + taskLogList.Add(taskLog); + //将生产任务插入到自检报废记录表 + var sacipRecord = new PrdMoTaskDefectRecord(); + sacipRecord.id = SnowflakeIdHelper.NextId(); + sacipRecord.material_code = material?.code; + sacipRecord.material_name = material?.name; + sacipRecord.estimated_start_date = mo?.plan_start_date; + sacipRecord.estimated_end_date = mo?.plan_end_date; + sacipRecord.plan_qty = moTask.plan_qty; + sacipRecord.scrap_qty = moTask.scrap_qty; + sacipRecord.status = moTask.mo_task_status; + sacipRecord.create_id = _userManager.UserId; + sacipRecord.create_time = DateTime.Now; + sacipRecord.mo_task_id = moTask.id; + sacipRecord.mo_task_code = moTask.mo_task_code; + taskDefectRecordList.Add(sacipRecord); + } + await _db.Insertable(taskLogList).ExecuteCommandAsync(); + await _db.Insertable(taskDefectRecordList).ExecuteCommandAsync(); + }); + } + return dbResult!.IsSuccess; + } /// /// 生产任务下发,开始 、结束、完成 From 67d599dce61e60c54f5fb4e0e5c1a70da3ffd4eb Mon Sep 17 00:00:00 2001 From: PhilPan Date: Tue, 16 May 2023 15:21:04 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E6=B6=88=E9=99=A4=E9=83=A8=E5=88=86warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/WorklineCommService.cs | 20 +- common/Tnb.Common/DataValidation/Check.cs | 350 ++++++++++++++++++ .../Tnb.Common/Extension/BooleanExtensions.cs | 2 +- .../Extension/DictionaryExtensions.cs | 2 +- common/Tnb.Common/Extension/EnumExtensions.cs | 4 +- common/Tnb.Common/Extension/Extensions.cs | 8 +- .../Tnb.Common/Extension/RandomExtensions.cs | 4 +- common/Tnb.Common/Net/UserAgent.cs | 10 +- common/Tnb.Common/Security/CodeGenHelper.cs | 2 +- .../Tnb.Common/Security/ComparisonHelper.cs | 2 +- common/Tnb.Common/Security/EqualityHelper.cs | 9 +- .../Tnb.Common/Security/ExcelExportHelper.cs | 8 +- .../Tnb.Common/Security/ExcelImportHelper.cs | 2 +- common/Tnb.Common/Security/FileHelper.cs | 7 +- common/Tnb.Common/Security/JsonHelper.cs | 12 +- common/Tnb.Common/Security/MachineHelper.cs | 3 + .../Tnb.Common/Security/SuperQueryHelper.cs | 5 +- 17 files changed, 396 insertions(+), 54 deletions(-) create mode 100644 common/Tnb.Common/DataValidation/Check.cs diff --git a/ProductionMgr/Tnb.ProductionMgr/WorklineCommService.cs b/ProductionMgr/Tnb.ProductionMgr/WorklineCommService.cs index ac7ba7c1..63e4c92e 100644 --- a/ProductionMgr/Tnb.ProductionMgr/WorklineCommService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/WorklineCommService.cs @@ -1,29 +1,11 @@ -using System.Dynamic; -using System.Reflection.Emit; -using Aop.Api.Domain; -using JNPF.Common.Core.Manager; -using JNPF.Common.Enums; -using JNPF.Common.Extension; -using JNPF.Common.Security; +using JNPF.Common.Core.Manager; using JNPF.DependencyInjection; using JNPF.DynamicApiController; -using JNPF.Extensitions.EventBus; -using JNPF.FriendlyException; -using JNPF.Logging; using JNPF.Systems.Interfaces.System; -using JNPF.VisualDev; -using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; -using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Senparc.Weixin.Work.AdvancedAPIs.MailList; using SqlSugar; -using Tnb.BasicData; -using Tnb.BasicData.Entitys.Entity; -using Tnb.EquipMgr.Entities; using Tnb.ProductionMgr.Entities; -using Tnb.ProductionMgr.Entities.Dto; -using Tnb.ProductionMgr.Entities.Enums; using Tnb.ProductionMgr.Interfaces; namespace Tnb.ProductionMgr; diff --git a/common/Tnb.Common/DataValidation/Check.cs b/common/Tnb.Common/DataValidation/Check.cs new file mode 100644 index 00000000..cc102ead --- /dev/null +++ b/common/Tnb.Common/DataValidation/Check.cs @@ -0,0 +1,350 @@ +using JetBrains.Annotations; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; + +namespace Tnb.Common; + +[DebuggerStepThrough] +public static class Check +{ + public static T NotNull(T value, string parameterName) + { + if (value == null) + { + throw new ArgumentNullException(parameterName); + } + + return value; + } + + public static T NotNull( + T value, + string parameterName, + string message) + { + if (value == null) + { + throw new ArgumentNullException(parameterName, message); + } + + return value; + } + + public static string NotNull( + string value, + string parameterName, + int maxLength = int.MaxValue, + int minLength = 0) + { + if (value == null) + { + throw new ArgumentException($"{parameterName} can not be null!", parameterName); + } + + if (value.Length > maxLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); + } + + if (minLength > 0 && value.Length < minLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); + } + + return value; + } + + public static string NotNullOrWhiteSpace( + string value, + string parameterName, + int maxLength = int.MaxValue, + int minLength = 0) + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException($"{parameterName} can not be null, empty or white space!", parameterName); + } + + if (value.Length > maxLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); + } + + if (minLength > 0 && value.Length < minLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); + } + + return value; + } + + public static string NotNullOrEmpty( + string value, + string parameterName, + int maxLength = int.MaxValue, + int minLength = 0) + { + if (string.IsNullOrEmpty(value)) + { + throw new ArgumentException($"{parameterName} can not be null or empty!", parameterName); + } + + if (value.Length > maxLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); + } + + if (minLength > 0 && value.Length < minLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); + } + + return value; + } + + public static ICollection NotNullOrEmpty(ICollection value, string parameterName) + { + if (value == null || value.Count <= 0) + { + throw new ArgumentException(parameterName + " can not be null or empty!", parameterName); + } + + return value; + } + + public static Type AssignableTo( + Type type, + string parameterName) + { + NotNull(type, parameterName); + + if (!type.IsAssignableTo(typeof(TBaseType))) + { + throw new ArgumentException($"{parameterName} (type of {type.AssemblyQualifiedName}) should be assignable to the {typeof(TBaseType).FullName}!"); + } + + return type; + } + + public static string Length( + [AllowNull] string value, + string parameterName, + int maxLength, + int minLength = 0) + { + if (minLength > 0) + { + if (string.IsNullOrEmpty(value)) + { + throw new ArgumentException(parameterName + " can not be null or empty!", parameterName); + } + + if (value.Length < minLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or bigger than {minLength}!", parameterName); + } + } + + if (value != null && value.Length > maxLength) + { + throw new ArgumentException($"{parameterName} length must be equal to or lower than {maxLength}!", parameterName); + } + + return value!; + } + + public static short Positive( + short value, + string parameterName) + { + if(value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if(value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static Int32 Positive( + Int32 value, + string parameterName) + { + if (value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static Int64 Positive( + Int64 value, + string parameterName) + { + if (value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static float Positive( + float value, + string parameterName) + { + if (value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static double Positive( + double value, + string parameterName) + { + if (value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static decimal Positive( + decimal value, + string parameterName) + { + if (value == 0) + { + throw new ArgumentException($"{parameterName} is equal to zero"); + } + else if (value < 0) + { + throw new ArgumentException($"{parameterName} is less than zero"); + } + return value; + } + + public static Int16 Range( + Int16 value, + string parameterName, + Int16 minimumValue, + Int16 maximumValue = Int16.MaxValue) + { + if(value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return value; + } + public static Int32 Range( + Int32 value, + string parameterName, + Int32 minimumValue, + Int32 maximumValue = Int32.MaxValue) + { + if (value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return value; + } + + public static Int64 Range( + Int64 value, + string parameterName, + Int64 minimumValue, + Int64 maximumValue = Int64.MaxValue) + { + if (value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return value; + } + + + public static float Range( + float value, + string parameterName, + float minimumValue, + float maximumValue = float.MaxValue) + { + if (value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + return value; + } + + + public static double Range( + double value, + string parameterName, + double minimumValue, + double maximumValue = double.MaxValue) + { + if (value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return value; + } + + + public static decimal Range( + decimal value, + string parameterName, + decimal minimumValue, + decimal maximumValue = decimal.MaxValue) + { + if (value < minimumValue || value > maximumValue) + { + throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}"); + } + + return value; + } + + public static T NotDefaultOrNull( + T? value, + string parameterName) + where T : struct + { + if (value == null) + { + throw new ArgumentException($"{parameterName} is null!", parameterName); + } + + if (value.Value.Equals(default(T))) + { + throw new ArgumentException($"{parameterName} has a default value!", parameterName); + } + + return value.Value; + } +} diff --git a/common/Tnb.Common/Extension/BooleanExtensions.cs b/common/Tnb.Common/Extension/BooleanExtensions.cs index c163c4f9..5feffa27 100644 --- a/common/Tnb.Common/Extension/BooleanExtensions.cs +++ b/common/Tnb.Common/Extension/BooleanExtensions.cs @@ -31,7 +31,7 @@ public static class BooleanExtensions /// private static bool? GetBool(this object data) { - switch (data.ToString().Trim().ToLower()) + switch (data.ToString()?.Trim().ToLower()) { case "0": return false; diff --git a/common/Tnb.Common/Extension/DictionaryExtensions.cs b/common/Tnb.Common/Extension/DictionaryExtensions.cs index b9b052cd..962810bf 100644 --- a/common/Tnb.Common/Extension/DictionaryExtensions.cs +++ b/common/Tnb.Common/Extension/DictionaryExtensions.cs @@ -16,7 +16,7 @@ public static class DictionaryExtensions /// 要操作的字典. /// 指定键名. /// 获取到的值. - public static TValue GetOrDefault(this IDictionary dictionary, TKey key) + public static TValue? GetOrDefault(this IDictionary dictionary, TKey key) { return dictionary.TryGetValue(key, out TValue value) ? value : default(TValue); } diff --git a/common/Tnb.Common/Extension/EnumExtensions.cs b/common/Tnb.Common/Extension/EnumExtensions.cs index 8e438b11..15206eee 100644 --- a/common/Tnb.Common/Extension/EnumExtensions.cs +++ b/common/Tnb.Common/Extension/EnumExtensions.cs @@ -152,7 +152,7 @@ public static class EnumExtensions /// public static string GetDescription(this System.Enum value) { - return value.GetType().GetMember(value.ToString()).FirstOrDefault()?.GetCustomAttribute()?.Description; + return value.GetType().GetMember(value.ToString()).FirstOrDefault()?.GetCustomAttribute()?.Description ?? string.Empty; } /// @@ -162,7 +162,7 @@ public static class EnumExtensions /// public static string GetDescription(this object value) { - return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()?.GetCustomAttribute()?.Description; + return value.GetType().GetMember(value.ToString() ?? string.Empty).FirstOrDefault()?.GetCustomAttribute()?.Description ?? string.Empty; } /// diff --git a/common/Tnb.Common/Extension/Extensions.cs b/common/Tnb.Common/Extension/Extensions.cs index 0815e1d6..05718f61 100644 --- a/common/Tnb.Common/Extension/Extensions.cs +++ b/common/Tnb.Common/Extension/Extensions.cs @@ -219,7 +219,7 @@ public static partial class Extensions /// private static bool? GetBool(this object data) { - switch (data.ToString().Trim().ToLower()) + switch (data.ToString()?.Trim().ToLower()) { case "0": return false; @@ -466,7 +466,7 @@ public static partial class Extensions { try { - return obj == null ? string.Empty : obj.ToString(); + return obj == null ? string.Empty : obj.ToString()!; } catch { @@ -489,7 +489,7 @@ public static partial class Extensions return string.Join(",", list); } - return obj.ToString(); + return obj.ToString()!; } catch { @@ -678,7 +678,7 @@ public static partial class Extensions /// public static string ObjToString(this object thisValue) { - if (thisValue != null) return thisValue.ToString().Trim(); + if (thisValue != null) return thisValue.ToString()!.Trim(); return string.Empty; } diff --git a/common/Tnb.Common/Extension/RandomExtensions.cs b/common/Tnb.Common/Extension/RandomExtensions.cs index 2e1a62f5..b8466442 100644 --- a/common/Tnb.Common/Extension/RandomExtensions.cs +++ b/common/Tnb.Common/Extension/RandomExtensions.cs @@ -38,7 +38,7 @@ public static class RandomExtensions Array array = System.Enum.GetValues(type); int index = random.Next(array.GetLowerBound(0), array.GetUpperBound(0) + 1); - return (T)array.GetValue(index); + return (T)array.GetValue(index)!; } /// @@ -67,7 +67,7 @@ public static class RandomExtensions public static T NextItem(this Random random, T[] items) { if (items == null || items.Length == 0) - return default(T); + return default(T)!; return items[random.Next(items.Length)]; } diff --git a/common/Tnb.Common/Net/UserAgent.cs b/common/Tnb.Common/Net/UserAgent.cs index cd578d03..3407035a 100644 --- a/common/Tnb.Common/Net/UserAgent.cs +++ b/common/Tnb.Common/Net/UserAgent.cs @@ -111,10 +111,10 @@ public class UserAgent : IUserAgent private DeviceInfo _device; private OSInfo _os; - private bool? _isBot; + //private bool? _isBot; private bool? _isMobileDevice; private bool? _isTablet; - private bool? _isPdfConverter; + //private bool? _isPdfConverter; static UserAgent() { @@ -142,7 +142,7 @@ public class UserAgent : IUserAgent } } - return _rawValue; + return _rawValue ?? ""; } set @@ -151,10 +151,10 @@ public class UserAgent : IUserAgent _userAgent = null; _device = null; _os = null; - _isBot = null; + //_isBot = null; _isMobileDevice = null; _isTablet = null; - _isPdfConverter = null; + //_isPdfConverter = null; } } diff --git a/common/Tnb.Common/Security/CodeGenHelper.cs b/common/Tnb.Common/Security/CodeGenHelper.cs index e06dad23..5bf8591d 100644 --- a/common/Tnb.Common/Security/CodeGenHelper.cs +++ b/common/Tnb.Common/Security/CodeGenHelper.cs @@ -190,7 +190,7 @@ public static class CodeGenHelper field = entityInfo.Columns.Find(it => it.PropertyName.Equals(sort.ToUpperCase()))?.DbColumnName; break; } - return string.IsNullOrEmpty(field) ? null : field; + return string.IsNullOrEmpty(field) ? "" : field; } /// diff --git a/common/Tnb.Common/Security/ComparisonHelper.cs b/common/Tnb.Common/Security/ComparisonHelper.cs index 8248657c..0b540ac0 100644 --- a/common/Tnb.Common/Security/ComparisonHelper.cs +++ b/common/Tnb.Common/Security/ComparisonHelper.cs @@ -63,7 +63,7 @@ public static class ComparisonHelper /// /// /// - public int Compare(T x, T y) + public int Compare(T? x, T? y) { return _comparer.Compare(_keySelector(x), _keySelector(y)); } diff --git a/common/Tnb.Common/Security/EqualityHelper.cs b/common/Tnb.Common/Security/EqualityHelper.cs index 4d33b45b..2dc3b6b4 100644 --- a/common/Tnb.Common/Security/EqualityHelper.cs +++ b/common/Tnb.Common/Security/EqualityHelper.cs @@ -1,4 +1,5 @@ -using JNPF.DependencyInjection; +using System.Diagnostics.CodeAnalysis; +using JNPF.DependencyInjection; namespace JNPF.Common.Security; @@ -49,14 +50,14 @@ public static class EqualityHelper : this(keySelector, EqualityComparer.Default) { } - public bool Equals(T x, T y) + public bool Equals(T? x, T? y) { return _comparer.Equals(_keySelector(x), _keySelector(y)); } - public int GetHashCode(T obj) + public int GetHashCode([DisallowNull] T obj) { - return _comparer.GetHashCode(_keySelector(obj)); + return _comparer.GetHashCode(_keySelector(obj)!); } } } diff --git a/common/Tnb.Common/Security/ExcelExportHelper.cs b/common/Tnb.Common/Security/ExcelExportHelper.cs index 3b975fde..6ffcab01 100644 --- a/common/Tnb.Common/Security/ExcelExportHelper.cs +++ b/common/Tnb.Common/Security/ExcelExportHelper.cs @@ -11,6 +11,7 @@ using NPOI.XSSF.UserModel; namespace JNPF.Common.Security; +#pragma warning disable CS8602, CS0618, CA2200 /// /// Excel导出操作类 /// 版 本:V3.2.0 @@ -740,7 +741,7 @@ public class ExcelExportHelper } catch (Exception ex) { - throw; + throw ex; } } @@ -1039,7 +1040,7 @@ public class ExcelExportHelper } catch (Exception ex) { - throw; + throw ex; } } @@ -1168,4 +1169,5 @@ public class ExcelExportHelper } #endregion -} \ No newline at end of file +} +#pragma warning restore CS8602, CS0618, CA2200 diff --git a/common/Tnb.Common/Security/ExcelImportHelper.cs b/common/Tnb.Common/Security/ExcelImportHelper.cs index bd7e2883..1d1deff8 100644 --- a/common/Tnb.Common/Security/ExcelImportHelper.cs +++ b/common/Tnb.Common/Security/ExcelImportHelper.cs @@ -108,7 +108,7 @@ namespace JNPF.Common.Helper //} //else //{ - dataRow[j] = cell.ToString().Trim(); + dataRow[j] = cell.ToString()?.Trim(); //} } } diff --git a/common/Tnb.Common/Security/FileHelper.cs b/common/Tnb.Common/Security/FileHelper.cs index 35b377ef..519fa06c 100644 --- a/common/Tnb.Common/Security/FileHelper.cs +++ b/common/Tnb.Common/Security/FileHelper.cs @@ -505,6 +505,7 @@ public class FileHelper #endregion +#pragma warning disable CA1416 // 验证平台兼容性 #region 生成高清晰缩略图 /// @@ -669,6 +670,7 @@ public class FileHelper } #endregion +#pragma warning restore CA1416 // 验证平台兼容性 #region 将文件路径转为内存流 @@ -712,7 +714,8 @@ public class FileHelper if (selectFiles.Count > 0) { - return selectFiles.FirstOrDefault().FullName; + //modified by PhilPan + return selectFiles.First().FullName; } return Path.Combine(folderPath, $@"{prefix}_{DateTime.Now.ParseToUnixTime()}.log"); @@ -737,7 +740,7 @@ public class FileHelper Microsoft.AspNetCore.Http.HttpContext? httpContext = App.HttpContext; httpContext.Response.ContentType = "application/octet-stream"; httpContext.Response.Headers.Add("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8)); - httpContext.Response.Headers.Add("Content-Length", buff.Length.ToString()); + httpContext.Response.Headers.Add("Content-Length", buff?.Length.ToString()); httpContext.Response.Body.WriteAsync(buff); httpContext.Response.Body.Flush(); httpContext.Response.Body.Close(); diff --git a/common/Tnb.Common/Security/JsonHelper.cs b/common/Tnb.Common/Security/JsonHelper.cs index cbb2b901..0128eecc 100644 --- a/common/Tnb.Common/Security/JsonHelper.cs +++ b/common/Tnb.Common/Security/JsonHelper.cs @@ -46,7 +46,7 @@ public static class JsonHelper /// public static T ToObject(this string json) { - return _ = _jsonSerializer.Deserialize(json) ?? default(T); + return _jsonSerializer.Deserialize(json); } /// @@ -58,7 +58,7 @@ public static class JsonHelper /// public static T ToObject(this string json, object jsonSerializerOptions = default) { - return _ = _jsonSerializer.Deserialize(json, jsonSerializerOptions) ?? default(T); + return _jsonSerializer.Deserialize(json, jsonSerializerOptions); } /// @@ -69,7 +69,7 @@ public static class JsonHelper /// public static T ToObject(this object json) { - return _ = ToJsonString(json).ToObject() ?? default(T); + return ToJsonString(json).ToObject(); } /// @@ -81,7 +81,7 @@ public static class JsonHelper /// public static T ToObject(this object json, object jsonSerializerOptions = default) { - return _ = ToJsonString(json, jsonSerializerOptions).ToObject(jsonSerializerOptions) ?? default(T); + return ToJsonString(json, jsonSerializerOptions).ToObject(jsonSerializerOptions); } /// @@ -92,7 +92,7 @@ public static class JsonHelper /// public static List ToList(this string json) { - return _ = _jsonSerializer.Deserialize>(json) ?? null; + return _jsonSerializer.Deserialize>(json); } /// @@ -104,7 +104,7 @@ public static class JsonHelper /// public static List ToList(this string json, object jsonSerializerOptions = default) { - return _ = _jsonSerializer.Deserialize>(json, jsonSerializerOptions) ?? null; + return _jsonSerializer.Deserialize>(json, jsonSerializerOptions); } /// diff --git a/common/Tnb.Common/Security/MachineHelper.cs b/common/Tnb.Common/Security/MachineHelper.cs index 43597cb2..e435e49b 100644 --- a/common/Tnb.Common/Security/MachineHelper.cs +++ b/common/Tnb.Common/Security/MachineHelper.cs @@ -217,6 +217,7 @@ public static class MachineHelper } #endregion +#pragma warning disable CA1416 // 验证平台兼容性 #region Windows /// @@ -364,4 +365,6 @@ public static class MachineHelper } #endregion +#pragma warning restore CA1416 // 验证平台兼容性 + } \ No newline at end of file diff --git a/common/Tnb.Common/Security/SuperQueryHelper.cs b/common/Tnb.Common/Security/SuperQueryHelper.cs index eaa6f636..e42973c6 100644 --- a/common/Tnb.Common/Security/SuperQueryHelper.cs +++ b/common/Tnb.Common/Security/SuperQueryHelper.cs @@ -60,7 +60,7 @@ public class SuperQueryHelper { case JnpfKeyConst.COMINPUT: case JnpfKeyConst.TEXTAREA: - item.fieldValue = item.fieldValue?.ToString().Replace("\r\n", string.Empty); + item.fieldValue = item.fieldValue?.ToString()?.Replace("\r\n", string.Empty); switch (item.symbol) { case "==": // 等于 @@ -549,8 +549,9 @@ public class SuperQueryHelper queryOr.mainWhere = true; queryList.Add(queryOr); } + //modified by PhilPan + continue; } - continue; switch (item.symbol) { case ">=": // 大于等于 From 5145ea0e1a5ecc7b922a9296c52570d5e0d19084 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 16 May 2023 15:46:41 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E7=82=B9=E5=B7=A1=E6=A3=80=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Consts/EquipmentLife.cs | 25 +++ .../Entity/EqpSpotInsItem.cs | 150 ++++++++++++++++ .../Entity/EqpSpotInsRecordD.cs | 9 +- .../Entity/EqpSpotInsRecordH.cs | 85 ++++++++- .../Entity/EqpSpotInsTemEquipD.cs | 33 ++++ .../GenerateSpotInspectionPlanTimeWorker.cs | 164 +++++++++++++++++- .../Tnb.TaskScheduler/TimeTaskService.cs | 31 ++-- .../Tnb.TaskScheduler.csproj | 5 + 8 files changed, 480 insertions(+), 22 deletions(-) create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs b/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs new file mode 100644 index 00000000..7224dfc9 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Consts/EquipmentLife.cs @@ -0,0 +1,25 @@ +namespace Tnb.EquipMgr +{ + /// + /// 设备生命周期 + /// + public static class EquipmentLife + { + /// + /// 启用 + /// + public const string ENABLE = "1"; + /// + /// 停用 + /// + public const string DISABLE = "2"; + /// + /// 库存 + /// + public const string STOCK = "3"; + /// + /// 报废 + /// + public const string SCRAP = "4"; + } +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs new file mode 100644 index 00000000..13a649e8 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsItem.cs @@ -0,0 +1,150 @@ +using SqlSugar; +using Tnb.Common.Contracts; + +namespace Tnb.EquipMgr.Entities +{ + /// + ///设备点巡检项目 + /// + [SugarTable("eqp_spot_ins_item")] + public class EqpSpotInsItem : BaseEntity + { + public EqpSpotInsItem() + { + } + + /// + /// Desc:创建时间 + /// Default: + /// Nullable:True + /// + public DateTime? create_time { get; set; } + + /// + /// Desc:修改时间 + /// Default: + /// Nullable:True + /// + public DateTime? modify_time { get; set; } + + + /// + /// Desc:判断类型1数值2结果 + /// Default: + /// Nullable:False + /// + public string judge_type { get; set; } + + /// + /// Desc:上限值 + /// Default: + /// Nullable:True + /// + public decimal? high_value { get; set; } + + /// + /// Desc:是否包含上限值 + /// Default: + /// Nullable:True + /// + public int? high_value_is_include { get; set; } + + /// + /// Desc:下限值 + /// Default: + /// Nullable:True + /// + public decimal? low_value { get; set; } + + /// + /// Desc:是否包含下限值 + /// Default: + /// Nullable:True + /// + public int? low_value_is_include { get; set; } + + /// + /// Desc:标准值 + /// Default: + /// Nullable:True + /// + public decimal? standard_value { get; set; } + + /// + /// Desc:单位id + /// Default: + /// Nullable:False + /// + public string unit_id { get; set; } + + /// + /// Desc:排序 + /// Default: + /// Nullable:False + /// + public int ordinal { get; set; } + + /// + /// Desc:类型 1 点检 2巡检 + /// Default: + /// Nullable:False + /// + public string type { get; set; } + + /// + /// Desc:创建用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string create_id { get; set; } + + /// + /// Desc:修改用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string modify_id { get; set; } + + /// + /// Desc:编码 + /// Default:NULL::character varying + /// Nullable:True + /// + public string code { get; set; } + + /// + /// Desc:名称 + /// Default:NULL::character varying + /// Nullable:True + /// + public string name { get; set; } + + /// + /// Desc:判断内容 + /// Default:NULL::character varying + /// Nullable:True + /// + public string judge_content { get; set; } + + /// + /// Desc:点巡检方法 + /// Default:NULL::character varying + /// Nullable:True + /// + public string inspection_method { get; set; } + + /// + /// Desc:备注 + /// Default:NULL::character varying + /// Nullable:True + /// + public string remark { get; set; } + + /// + /// Desc:所属组织 + /// Default:NULL::character varying + /// Nullable:True + /// + public string org_id { get; set; } + } +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs index 7ac2a892..3e7c12bc 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordD.cs @@ -67,7 +67,7 @@ public partial class EqpSpotInsRecordD : BaseEntity /// Default: /// Nullable:True /// - public double? standard_value { get; set; } + public decimal? standard_value { get; set; } /// /// Desc:单位id @@ -131,4 +131,11 @@ public partial class EqpSpotInsRecordD : BaseEntity /// Nullable:True /// public string remark { get; set; } + + /// + /// Desc:点巡检设备模板id + /// Default:NULL::character varying + /// Nullable:True + /// + public string spot_ins_tem_equip_id {get;set;} } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs index 94a35273..cdcfec28 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsRecordH.cs @@ -27,6 +27,7 @@ namespace Tnb.EquipMgr.Entities /// public DateTime? modify_time { get; set; } + /// /// Desc:设备id /// Default: @@ -70,18 +71,18 @@ namespace Tnb.EquipMgr.Entities public DateTime? send_date_time { get; set; } /// - /// Desc:滞后推送时间 + /// Desc:计划执行通知提前量 /// Default: /// Nullable:True /// - public DateTime? after_send_date_time { get; set; } + public int? plan_run_notice { get; set; } /// - /// Desc:是否滞后推送 + /// Desc:执行滞后推送时间 /// Default: /// Nullable:True /// - public int? is_after_send { get; set; } + public int? plan_delay { get; set; } /// /// Desc:创建用户 @@ -131,5 +132,81 @@ namespace Tnb.EquipMgr.Entities /// Nullable:True /// public string send_id { get; set; } + + /// + /// Desc:编码 + /// Default:NULL::character varying + /// Nullable:True + /// + public string code { get; set; } + + /// + /// Desc:计划执行通知提前量单位 1 小时 2 天 3 周 + /// Default:NULL::character varying + /// Nullable:True + /// + public string plan_run_notice_unit { get; set; } + + /// + /// Desc:执行滞后推送时间单位 1 小时 2 天 3 周 + /// Default:NULL::character varying + /// Nullable:True + /// + public string plan_delay_unit { get; set; } + + /// + /// Desc:复核岗位id + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_post_info_user_id { get; set; } + + /// + /// Desc:责任岗位id + /// Default:NULL::character varying + /// Nullable:True + /// + public string send_post_info_user_id { get; set; } + + /// + /// Desc:是否复核 + /// Default:NULL::character varying + /// Nullable:True + /// + public string is_repeat { get; set; } + + /// + /// Desc:复核时间 + /// Default: + /// Nullable:True + /// + public DateTime? repeat_time {get;set;} + + /// + /// Desc:复核备注 + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_remark {get;set;} + + /// + /// Desc:复核人id + /// Default:NULL::character varying + /// Nullable:True + /// + public string repeat_user_id {get;set;} + + /// + /// Desc:仅用于关联表字段查询用不存储数据 + /// Default:NULL::character varying + /// Nullable:True + /// + [SugarColumn(ColumnName="query_info")] + public string query_info {get;set;} + + /// + /// 附件 + /// + public string attachment { get; set; } } } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs new file mode 100644 index 00000000..7d0042e5 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/EqpSpotInsTemEquipD.cs @@ -0,0 +1,33 @@ +using SqlSugar; +using Tnb.Common.Contracts; + + +namespace Tnb.EquipMgr.Entities +{ + /// + ///点巡检设备模板子表 + /// + [SugarTable("eqp_spot_ins_tem_equip_d")] + public class EqpSpotInsTemEquipD : BaseEntity + { + public EqpSpotInsTemEquipD(){ + + + } + + /// + /// Desc:设备模板id + /// Default: + /// Nullable:False + /// + public string spot_ins_tem_equip_id {get;set;} + + /// + /// Desc:点巡检项id + /// Default: + /// Nullable:False + /// + public string spot_ins_item_id {get;set;} + + } +} \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index b124ee33..d0de1e4d 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -1,11 +1,171 @@ +using JNPF.Common.Security; +using JNPF.Logging; +using Microsoft.AspNetCore.Components; +using SqlSugar; +using Tnb.EquipMgr.Entities; + namespace JNPF.TaskScheduler.Listener { + /// + /// 生成点巡检计划 + /// public class GenerateSpotInspectionPlanTimeWorker : ISpareTimeWorker { - [SpareTime("0 45 14 * * ? *", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] + private ISqlSugarRepository _repository => App.GetService>(); + // public GenerateSpotInspectionPlanTimeWorker(ISqlSugarRepository repository) + // { + // _repository = repository; + // } + + [SpareTime("0 0 0 * * ?", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false)] public void GenerateSpotInspectionPlan(SpareTimer timer, long count) { - Console.WriteLine("hello world"); + Log.Information("----------------------开始生成点巡检计划----------------------"); + + try + { + List eqpSpotInsTemEquipHsByOne = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "1"); + List eqpSpotInsTemEquipHsByCirculate = _repository.GetList(x => x.is_start=="1" && x.plan_cycle_unit == "2"); + List tobeCreateList = new List(); + List tobeCreateTemplets = new List(); + var db = _repository.AsSugarClient(); + + foreach (var item in eqpSpotInsTemEquipHsByOne) + { + if (item.start_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH:mm") == DateTime.Now.ToString("yyyy-MM-dd HH:mm")) + { + tobeCreateTemplets.Add(item); + } + } + + if (eqpSpotInsTemEquipHsByCirculate != null && eqpSpotInsTemEquipHsByCirculate.Count > 0) + { + List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); + List lastPlans = db.Queryable() + .GroupBy(a => new { a.spot_ins_tem_equip_id }) + .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) + .Select(a => new SpotInsRecordLastDTO() + { + spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, + create_time = SqlFunc.AggregateMax(a.create_time.Value) + }).ToList(); + + foreach (var item in eqpSpotInsTemEquipHsByCirculate) + { + var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); + if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + { + tobeCreateTemplets.Add(item); + } + } + } + + if (tobeCreateTemplets != null && tobeCreateTemplets.Count > 0) + { + List equipments = db.Queryable().Where(x => x.life==Tnb.EquipMgr.EquipmentLife.ENABLE).ToList(); + int index = 1; + foreach (var item in tobeCreateTemplets) + { + //只有启用设备才生成计划 + if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) + continue; + + string code = $"{DateTime.Now.ToString("yyyyMMddHH")+(index++).ToString().PadLeft(3,'0')}"; + tobeCreateList.Add(new EqpSpotInsRecordH() + { + id = SnowflakeIdHelper.NextId(), + code = code, + // equip_type_id = item.equip_type_id, + equip_id = item.equip_id, + spot_ins_tem_equip_id = item.id, + plan_run_notice = item.plan_run_notice, + plan_run_notice_unit = item.plan_run_notice_unit, + plan_delay = item.plan_delay, + plan_delay_unit = item.plan_delay_unit, + send_post_info_user_id = item.send_post_info_user_id, + is_repeat = item.is_repeat, + repeat_post_info_user_id = item.repeat_post_info_user_id, + is_send = item.is_send, + create_time = DateTime.Now, + }); + } + } + + + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + List templetIDs = tobeCreateList.Select(x => x.spot_ins_tem_equip_id).ToList(); + List spotInsTemEquipDs = db.Queryable().Where(x => templetIDs.Contains(x.spot_ins_tem_equip_id)).ToList(); + List spotInsItemIDs = spotInsTemEquipDs.Select(x => x.spot_ins_item_id).ToList(); + List spotCheckItems = db.Queryable().Where(x => spotInsItemIDs.Contains(x.id)).ToList(); + + + foreach (var tobeCreatePlan in tobeCreateList) + { + List spotInsRecordDs = new List(); + List spotInsItems = spotInsTemEquipDs + .Where(x => x.spot_ins_tem_equip_id == tobeCreatePlan.spot_ins_tem_equip_id) + .Select(x => x.spot_ins_item_id).ToList(); + List tobeCreateItems = spotCheckItems.Where(x => spotInsItems.Contains(x.id)).ToList(); + foreach (var tobeCreateItem in tobeCreateItems) + { + spotInsRecordDs.Add(new EqpSpotInsRecordD() + { + id = SnowflakeIdHelper.NextId(), + spot_ins_record_id = tobeCreatePlan.id, + spot_ins_tem_equip_id = tobeCreatePlan.spot_ins_tem_equip_id, + spot_ins_item_id = tobeCreateItem.id, + code = tobeCreateItem.code, + name = tobeCreateItem.name, + judge_type = tobeCreateItem.judge_type, + low_value = tobeCreateItem.low_value, + high_value = tobeCreateItem.high_value, + low_value_is_include = tobeCreateItem.low_value_is_include, + high_value_is_include = tobeCreateItem.high_value_is_include, + standard_value = tobeCreateItem.standard_value, + unit_id = tobeCreateItem.unit_id, + inspection_method = tobeCreateItem.inspection_method, + judge_content = tobeCreateItem.judge_content, + remark = tobeCreateItem.remark + }); + } + + var dbResult = db.Ado.UseTran(() => + { + if (tobeCreateList != null && tobeCreateList.Count > 0) + { + db.Insertable(tobeCreateList).ExecuteCommand(); + } + + if (spotInsRecordDs != null && spotInsRecordDs.Count > 0) + { + db.Insertable(spotInsRecordDs).ExecuteCommand(); + } + }); + if (!dbResult.IsSuccess) + { + Log.Error(dbResult.ErrorMessage); + } + Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); + } + } + } + catch (Exception e) + { + Log.Error(e.Message); + } + + + Log.Information("----------------------结束生成点巡检计划----------------------"); + } + + /// + /// 最后一个点巡检记录 + /// + private class SpotInsRecordLastDTO + { + public string spot_ins_tem_equip_id { get; set; } + public DateTime create_time { get; set; } } } } \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs index fb492e0f..93739262 100644 --- a/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs +++ b/taskschedule/Tnb.TaskScheduler/TimeTaskService.cs @@ -324,11 +324,12 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie Action? action = null; ContentModel? comtentModel = input.ExecuteContent.ToObject(); input.ExecuteCycleJson = comtentModel.cron; + TaskMethodInfo? taskMethod = null; switch (input.ExecuteType) { case "3": // 查询符合条件的任务方法 - TaskMethodInfo? taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId); + taskMethod = GetTaskMethods()?.Result.FirstOrDefault(m => m.id == comtentModel.localHostTaskId); if (taskMethod == null) break; // 创建任务对象 @@ -354,20 +355,20 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie { interval = (starTime.ParseToDateTime() - DateTime.Now).TotalMilliseconds.ParseToInt(); } - SpareTime.DoOnce(interval, action, "Once_" + input.Id); - SpareTime.Do( - () => - { - var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime; - if (isRun) - { - return SpareTime.GetCronNextOccurrence(comtentModel.cron); - } - else - { - return null; - } - }, + + if (taskMethod.StartNow) //modifyby zhoukeda 20230516 + { + SpareTime.DoOnce(interval, action, "Once_" + input.Id); + } + + Func nextHandle = null; + var isRun = comtentModel.endTime.IsNullOrEmpty() ? DateTime.Now >= starTime : DateTime.Now >= starTime && DateTime.Now < endTime; + if (isRun) + { + nextHandle = ()=>SpareTime.GetCronNextOccurrence(comtentModel.cron); + } + SpareTime.Do(nextHandle + , action, input.Id, comtentModel.ConnectionConfig.ToJsonString(), true, executeType: SpareTimeExecuteTypes.Parallel, cancelInNoneNextTime: false); } diff --git a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj index f2dfa7fb..36194190 100644 --- a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj +++ b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj @@ -10,8 +10,13 @@ + + + + + \ No newline at end of file From 21985f8f03501c58659afffb83994ef8cbdb06fc Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Tue, 16 May 2023 16:32:04 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenerateSpotInspectionPlanTimeWorker.cs | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index d0de1e4d..e4da44d1 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -40,20 +40,33 @@ namespace JNPF.TaskScheduler.Listener if (eqpSpotInsTemEquipHsByCirculate != null && eqpSpotInsTemEquipHsByCirculate.Count > 0) { - List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); - List lastPlans = db.Queryable() - .GroupBy(a => new { a.spot_ins_tem_equip_id }) - .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) - .Select(a => new SpotInsRecordLastDTO() - { - spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, - create_time = SqlFunc.AggregateMax(a.create_time.Value) - }).ToList(); - + //查询最后一条数据加上周期是否等于现在等于表示周期到了 已废除 + // List ids = eqpSpotInsTemEquipHsByCirculate.Select(x => x.id).ToList(); + // List lastPlans = db.Queryable() + // .GroupBy(a => new { a.spot_ins_tem_equip_id }) + // .Where(a => ids.Contains(a.spot_ins_tem_equip_id)) + // .Select(a => new SpotInsRecordLastDTO() + // { + // spot_ins_tem_equip_id = a.spot_ins_tem_equip_id, + // create_time = SqlFunc.AggregateMax(a.create_time.Value) + // }).ToList(); + // + // foreach (var item in eqpSpotInsTemEquipHsByCirculate) + // { + // var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); + // if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + // { + // tobeCreateTemplets.Add(item); + // } + // } + + //整除表示一个周期到了 foreach (var item in eqpSpotInsTemEquipHsByCirculate) { - var lastPlan = lastPlans.FirstOrDefault(x => x.spot_ins_tem_equip_id == item.id); - if (lastPlan == null || lastPlan.create_time == null || lastPlan.create_time.AddHours((double)item.plan_cycle).ToString("yyyy-MM-dd HH") == DateTime.Now.ToString("yyyy-MM-dd HH")) + TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Ticks); + TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(item.start_time.ToString("yyyy-MM-dd HH:mm")).Ticks); + TimeSpan ts3 = ts1.Subtract(ts2).Duration(); + if (ts3.TotalMinutes * 10 / 60 % (10 * (double)item.plan_cycle)==0) { tobeCreateTemplets.Add(item); } @@ -70,7 +83,7 @@ namespace JNPF.TaskScheduler.Listener if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) continue; - string code = $"{DateTime.Now.ToString("yyyyMMddHH")+(index++).ToString().PadLeft(3,'0')}"; + string code = $"{DateTime.Now.ToString("yyyyMMddHHmm")+(index++).ToString().PadLeft(3,'0')}"; tobeCreateList.Add(new EqpSpotInsRecordH() { id = SnowflakeIdHelper.NextId(), @@ -144,6 +157,7 @@ namespace JNPF.TaskScheduler.Listener }); if (!dbResult.IsSuccess) { + Console.WriteLine(dbResult.ErrorMessage); Log.Error(dbResult.ErrorMessage); } Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); @@ -152,6 +166,7 @@ namespace JNPF.TaskScheduler.Listener } catch (Exception e) { + Console.WriteLine(e.Message); Log.Error(e.Message); } From 1cb50e15d28ed865a7367c669040808747681f20 Mon Sep 17 00:00:00 2001 From: PhilPan Date: Tue, 16 May 2023 17:24:07 +0800 Subject: [PATCH 6/9] =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=B9=B3=E5=8F=B0warn,?= =?UTF-8?q?=E6=94=BE=E5=BC=80=E8=87=AA=E6=9C=89=E6=A8=A1=E5=9D=97warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apihost/Tnb.API.Entry/Handlers/JwtHandler.cs | 2 ++ apihost/Tnb.API.Entry/Startup.cs | 2 +- app/Tnb.Apps.Entitys/Tnb.Apps.Entitys.csproj | 1 + app/Tnb.Apps/Tnb.Apps.csproj | 1 + common.props | 2 +- .../Enums/EnumHelper/EnumExtensions.cs | 2 +- .../Request/AuthRequests/ElemeAuthRequest.cs | 2 ++ common/Tnb.CollectiveOAuth/Tnb.CollectiveOAuth.csproj | 1 + common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs | 4 +++- common/Tnb.CollectiveOAuth/Utils/TwitterBase.cs | 2 +- common/Tnb.Common.Core/Tnb.Common.Core.csproj | 1 + common/Tnb.Common/Extension/Extensions.cs | 2 +- common/Tnb.Common/Security/CodeGenExportDataHelper.cs | 2 +- common/Tnb.Common/Security/ExcelExportHelper.cs | 8 ++++++-- common/Tnb.Common/Security/FileHelper.cs | 2 ++ common/Tnb.Common/Tnb.Common.csproj | 1 + common/Tnb.Thirdparty/Tnb.Thirdparty.csproj | 1 + common/Tnb.WebSockets/Tnb.WebSockets.csproj | 1 + extend/Tnb.Extend.Entitys/Tnb.Extend.Entitys.csproj | 1 + extend/Tnb.Extend/OrderService.cs | 4 +++- extend/Tnb.Extend/Tnb.Extend.csproj | 1 + message/Tnb.Message.Entitys/Tnb.Message.Entitys.csproj | 1 + message/Tnb.Message/Tnb.Message.csproj | 1 + system/Tnb.OAuth/Tnb.OAuth.csproj | 3 ++- .../Entity/Permission/AuthorizeEntity.cs | 6 +++--- system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj | 1 + .../Tnb.Systems.Interfaces/Tnb.Systems.Interfaces.csproj | 1 + .../System/ModuleDataAuthorizeSchemeService.cs | 2 +- system/Tnb.Systems/Tnb.Systems.csproj | 3 ++- .../Tnb.TaskScheduler.Entitys.csproj | 1 + taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj | 1 + .../Tnb.VisualDev.Engine/Tnb.VisualDev.Engine.csproj | 3 ++- .../VisualDevModelData/VisualDevModelListQueryInput.cs | 9 +++++---- .../Tnb.VisualDev.Entitys/Tnb.VisualDev.Entitys.csproj | 1 + visualdev/Tnb.VisualDev/RunService.cs | 8 ++++---- visualdev/Tnb.VisualDev/Tnb.VisualDev.csproj | 1 + visualdev/Tnb.VisualDev/VisualDevModelDataService.cs | 2 +- visualdev/Tnb.VisualDev/VisualDevService.cs | 2 +- visualdev/Tnb.VisualDev/VisualdevModelAppService.cs | 2 +- .../Tnb.WorkFlow.Entitys/Tnb.WorkFlow.Entitys.csproj | 1 + .../Tnb.WorkFlow.Interfaces.csproj | 1 + workflow/Tnb.WorkFlow/Tnb.WorkFlow.csproj | 1 + 42 files changed, 66 insertions(+), 28 deletions(-) diff --git a/apihost/Tnb.API.Entry/Handlers/JwtHandler.cs b/apihost/Tnb.API.Entry/Handlers/JwtHandler.cs index ac713bd2..f0e9de90 100644 --- a/apihost/Tnb.API.Entry/Handlers/JwtHandler.cs +++ b/apihost/Tnb.API.Entry/Handlers/JwtHandler.cs @@ -59,6 +59,7 @@ public class JwtHandler : AppAuthorizeHandler return true; // 路由名称 + if (httpContext.Request.Path.Value == null) return false; var routeName = httpContext.Request.Path.Value[1..].Replace("/", ":"); if (httpContext.Request.Path.StartsWithSegments("/api")) routeName = httpContext.Request.Path.Value[5..].Replace("/", ":"); @@ -76,6 +77,7 @@ public class JwtHandler : AppAuthorizeHandler // 检查授权 //return permissionList.Contains(routeName); + await Task.CompletedTask; return true; } } diff --git a/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index e73e43ed..611eb99d 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -98,7 +98,7 @@ public class Startup : AppStartup app.UseInject(string.Empty); //app.MapWebSocketManager("/api/message/websocket", serviceProvider.GetService()); - app.MapWebSocketManager("/websocket", serviceProvider.GetService()); + app.MapWebSocketManager("/websocket", serviceProvider.GetRequiredService()); app.UseEndpoints(endpoints => { diff --git a/app/Tnb.Apps.Entitys/Tnb.Apps.Entitys.csproj b/app/Tnb.Apps.Entitys/Tnb.Apps.Entitys.csproj index 1e177c15..76aef262 100644 --- a/app/Tnb.Apps.Entitys/Tnb.Apps.Entitys.csproj +++ b/app/Tnb.Apps.Entitys/Tnb.Apps.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/app/Tnb.Apps/Tnb.Apps.csproj b/app/Tnb.Apps/Tnb.Apps.csproj index ff1045f7..b596a93b 100644 --- a/app/Tnb.Apps/Tnb.Apps.csproj +++ b/app/Tnb.Apps/Tnb.Apps.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS1572;CS1573; diff --git a/common.props b/common.props index eb6672a5..6734521c 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - $(NoWarn);CS1591;CA1307;CS8625;CS8600;CS8601;CS8604;CS8618; + $(NoWarn);CS1591; diff --git a/common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs b/common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs index 0fee4d6c..ec0ecded 100644 --- a/common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs +++ b/common/Tnb.CollectiveOAuth/Enums/EnumHelper/EnumExtensions.cs @@ -112,7 +112,7 @@ public static class EnumExtensions { if (field.FieldType.IsEnum) { - strValue = ((int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null)).ToString(); + strValue = ((int?)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null)).ToString(); object[] arr = field.GetCustomAttributes(typeDescription, true); if (arr.Length > 0) { diff --git a/common/Tnb.CollectiveOAuth/Request/AuthRequests/ElemeAuthRequest.cs b/common/Tnb.CollectiveOAuth/Request/AuthRequests/ElemeAuthRequest.cs index 6d0c1e8e..cf0ad9a1 100644 --- a/common/Tnb.CollectiveOAuth/Request/AuthRequests/ElemeAuthRequest.cs +++ b/common/Tnb.CollectiveOAuth/Request/AuthRequests/ElemeAuthRequest.cs @@ -253,7 +253,9 @@ public class ElemeAuthRequest : DefaultAuthRequest { //就是比string往后一直加要好的优化容器 StringBuilder sb = new StringBuilder(); +#pragma warning disable SYSLIB0021 //MD5CryptoServiceProvider已过时 using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()) +#pragma warning disable SYSLIB0021 //MD5CryptoServiceProvider已过时 { //将输入字符串转换为字节数组并计算哈希。 byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(willMd5Str)); diff --git a/common/Tnb.CollectiveOAuth/Tnb.CollectiveOAuth.csproj b/common/Tnb.CollectiveOAuth/Tnb.CollectiveOAuth.csproj index 34af77a4..015ae7e0 100644 --- a/common/Tnb.CollectiveOAuth/Tnb.CollectiveOAuth.csproj +++ b/common/Tnb.CollectiveOAuth/Tnb.CollectiveOAuth.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS1572;CS1573;CS0168; diff --git a/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs b/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs index 14ce2199..a908e1df 100644 --- a/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs +++ b/common/Tnb.CollectiveOAuth/Utils/HttpUtils.cs @@ -4,6 +4,7 @@ using System.Text; namespace JNPF.Extras.CollectiveOAuth.Utils; +#pragma warning disable SYSLIB0014 //WebRequest.Create已过时 public class HttpUtils { /// @@ -269,4 +270,5 @@ public class HttpUtils return result; } -} \ No newline at end of file +} +#pragma warning restore SYSLIB0014 //WebRequest.Create已过时 diff --git a/common/Tnb.CollectiveOAuth/Utils/TwitterBase.cs b/common/Tnb.CollectiveOAuth/Utils/TwitterBase.cs index 007ffa64..5ed2160e 100644 --- a/common/Tnb.CollectiveOAuth/Utils/TwitterBase.cs +++ b/common/Tnb.CollectiveOAuth/Utils/TwitterBase.cs @@ -52,7 +52,7 @@ public class TwitterBase #region IComparer Members - public int Compare(QueryParameter x, QueryParameter y) + public int Compare(QueryParameter? x, QueryParameter? y) { if (x.Name == y.Name) { diff --git a/common/Tnb.Common.Core/Tnb.Common.Core.csproj b/common/Tnb.Common.Core/Tnb.Common.Core.csproj index 2c81754d..f7e011f8 100644 --- a/common/Tnb.Common.Core/Tnb.Common.Core.csproj +++ b/common/Tnb.Common.Core/Tnb.Common.Core.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS1572;CS1573;CS0168;CS1998; diff --git a/common/Tnb.Common/Extension/Extensions.cs b/common/Tnb.Common/Extension/Extensions.cs index 05718f61..a46b4e1d 100644 --- a/common/Tnb.Common/Extension/Extensions.cs +++ b/common/Tnb.Common/Extension/Extensions.cs @@ -608,7 +608,7 @@ public static partial class Extensions /// 是否为空. /// /// 值. - public static bool IsEmpty(this string value) + public static bool IsEmpty(this string? value) { return string.IsNullOrWhiteSpace(value); } diff --git a/common/Tnb.Common/Security/CodeGenExportDataHelper.cs b/common/Tnb.Common/Security/CodeGenExportDataHelper.cs index 61b8e36a..11141240 100644 --- a/common/Tnb.Common/Security/CodeGenExportDataHelper.cs +++ b/common/Tnb.Common/Security/CodeGenExportDataHelper.cs @@ -54,7 +54,7 @@ public static class CodeGenExportDataHelper var len = rowChildDatas.Select(x => x.Value.Count()).OrderByDescending(x => x).FirstOrDefault(); - if (len != null && len > 0) + if (len > 0) { for (int i = 0; i < len; i++) { diff --git a/common/Tnb.Common/Security/ExcelExportHelper.cs b/common/Tnb.Common/Security/ExcelExportHelper.cs index 6ffcab01..0a34dfe4 100644 --- a/common/Tnb.Common/Security/ExcelExportHelper.cs +++ b/common/Tnb.Common/Security/ExcelExportHelper.cs @@ -1,6 +1,7 @@ using System.Drawing; using System.Reflection; using System.Text; +using JNPF.Common.Helper; using JNPF.Common.Models.NPOI; using JNPF.DependencyInjection; using NPOI.HPSF; @@ -8,10 +9,13 @@ using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; +using Spire.Doc; +using static Microsoft.AspNetCore.Razor.Language.TagHelperMetadata; namespace JNPF.Common.Security; -#pragma warning disable CS8602, CS0618, CA2200 +#pragma warning disable CS0618, CA2200 //再次引发捕获到的异常会更改堆栈信息 + /// /// Excel导出操作类 /// 版 本:V3.2.0 @@ -1170,4 +1174,4 @@ public class ExcelExportHelper #endregion } -#pragma warning restore CS8602, CS0618, CA2200 +#pragma warning restore CS0618, CA2200 //再次引发捕获到的异常会更改堆栈信息 diff --git a/common/Tnb.Common/Security/FileHelper.cs b/common/Tnb.Common/Security/FileHelper.cs index 519fa06c..55d4b8d8 100644 --- a/common/Tnb.Common/Security/FileHelper.cs +++ b/common/Tnb.Common/Security/FileHelper.cs @@ -494,7 +494,9 @@ public class FileHelper } catch (Exception ex) { +#pragma warning disable CA2200 //再次引发捕获到的异常会更改堆栈信息 throw ex; +#pragma warning disable CA2200 //再次引发捕获到的异常会更改堆栈信息 } finally { diff --git a/common/Tnb.Common/Tnb.Common.csproj b/common/Tnb.Common/Tnb.Common.csproj index 4d8a9838..b5e6e13b 100644 --- a/common/Tnb.Common/Tnb.Common.csproj +++ b/common/Tnb.Common/Tnb.Common.csproj @@ -7,6 +7,7 @@ enable False False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8605;CS8618;CS8619;CS8625;CS1572;CS1573; diff --git a/common/Tnb.Thirdparty/Tnb.Thirdparty.csproj b/common/Tnb.Thirdparty/Tnb.Thirdparty.csproj index ab91d29c..42576ee7 100644 --- a/common/Tnb.Thirdparty/Tnb.Thirdparty.csproj +++ b/common/Tnb.Thirdparty/Tnb.Thirdparty.csproj @@ -7,6 +7,7 @@ enable enable False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS1572;CS1573;CS0168;CS0618; diff --git a/common/Tnb.WebSockets/Tnb.WebSockets.csproj b/common/Tnb.WebSockets/Tnb.WebSockets.csproj index 39088182..081b83d5 100644 --- a/common/Tnb.WebSockets/Tnb.WebSockets.csproj +++ b/common/Tnb.WebSockets/Tnb.WebSockets.csproj @@ -7,6 +7,7 @@ enable enable False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS1572;CS1573;CS1998; diff --git a/extend/Tnb.Extend.Entitys/Tnb.Extend.Entitys.csproj b/extend/Tnb.Extend.Entitys/Tnb.Extend.Entitys.csproj index 1e177c15..76aef262 100644 --- a/extend/Tnb.Extend.Entitys/Tnb.Extend.Entitys.csproj +++ b/extend/Tnb.Extend.Entitys/Tnb.Extend.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/extend/Tnb.Extend/OrderService.cs b/extend/Tnb.Extend/OrderService.cs index 39923c73..25117549 100644 --- a/extend/Tnb.Extend/OrderService.cs +++ b/extend/Tnb.Extend/OrderService.cs @@ -44,12 +44,14 @@ public class OrderService : IDynamicApiController, ITransient ISqlSugarRepository repository, IUserManager userManager, IUsersService usersService, - ICacheManager cacheManager) + ICacheManager cacheManager, + IFileManager fileManager) { _repository = repository; _userManager = userManager; _usersService = usersService; _cacheManager = cacheManager; + _fileManager = fileManager; } #region GET diff --git a/extend/Tnb.Extend/Tnb.Extend.csproj b/extend/Tnb.Extend/Tnb.Extend.csproj index d7a0cd78..e5c49e58 100644 --- a/extend/Tnb.Extend/Tnb.Extend.csproj +++ b/extend/Tnb.Extend/Tnb.Extend.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS1572;CS1573;CS0168;CS4014; diff --git a/message/Tnb.Message.Entitys/Tnb.Message.Entitys.csproj b/message/Tnb.Message.Entitys/Tnb.Message.Entitys.csproj index 1e177c15..76aef262 100644 --- a/message/Tnb.Message.Entitys/Tnb.Message.Entitys.csproj +++ b/message/Tnb.Message.Entitys/Tnb.Message.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/message/Tnb.Message/Tnb.Message.csproj b/message/Tnb.Message/Tnb.Message.csproj index 0567e028..1894305e 100644 --- a/message/Tnb.Message/Tnb.Message.csproj +++ b/message/Tnb.Message/Tnb.Message.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS1572;CS1573;CS0168; diff --git a/system/Tnb.OAuth/Tnb.OAuth.csproj b/system/Tnb.OAuth/Tnb.OAuth.csproj index 927c3a91..1640baae 100644 --- a/system/Tnb.OAuth/Tnb.OAuth.csproj +++ b/system/Tnb.OAuth/Tnb.OAuth.csproj @@ -1,4 +1,4 @@ - + @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS1572;CS1573; diff --git a/system/Tnb.Systems.Entitys/Entity/Permission/AuthorizeEntity.cs b/system/Tnb.Systems.Entitys/Entity/Permission/AuthorizeEntity.cs index 2aa025f7..e3d66bdf 100644 --- a/system/Tnb.Systems.Entitys/Entity/Permission/AuthorizeEntity.cs +++ b/system/Tnb.Systems.Entitys/Entity/Permission/AuthorizeEntity.cs @@ -44,11 +44,11 @@ public class AuthorizeEntity : CEntityBase /// /// /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (obj is AuthorizeEntity) + if (obj is AuthorizeEntity authorizeEntity) { - AuthorizeEntity authorizeEntity = obj as AuthorizeEntity; + //AuthorizeEntity authorizeEntity = obj as AuthorizeEntity; return ItemType == authorizeEntity.ItemType && ItemId == authorizeEntity.ItemId && ObjectId == authorizeEntity.ObjectId && ObjectType == authorizeEntity.ObjectType; } diff --git a/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj b/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj index 43253c86..3c84db98 100644 --- a/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj +++ b/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/system/Tnb.Systems.Interfaces/Tnb.Systems.Interfaces.csproj b/system/Tnb.Systems.Interfaces/Tnb.Systems.Interfaces.csproj index 2d9293a0..42ab777d 100644 --- a/system/Tnb.Systems.Interfaces/Tnb.Systems.Interfaces.csproj +++ b/system/Tnb.Systems.Interfaces/Tnb.Systems.Interfaces.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8625; diff --git a/system/Tnb.Systems/System/ModuleDataAuthorizeSchemeService.cs b/system/Tnb.Systems/System/ModuleDataAuthorizeSchemeService.cs index 2ff51eba..b38d1292 100644 --- a/system/Tnb.Systems/System/ModuleDataAuthorizeSchemeService.cs +++ b/system/Tnb.Systems/System/ModuleDataAuthorizeSchemeService.cs @@ -143,7 +143,7 @@ public class ModuleDataAuthorizeSchemeService : IModuleDataAuthorizeSchemeServic /// 功能主键. /// [NonAction] - public async Task> GetList(string moduleId) + public async Task> GetList(string? moduleId) { return await _repository.AsQueryable().Where(x => x.DeleteMark == null && x.ModuleId == moduleId).OrderBy(a => a.SortCode).OrderBy(a => a.CreatorTime, OrderByType.Desc).OrderBy(a => a.LastModifyTime, OrderByType.Desc).ToListAsync(); } diff --git a/system/Tnb.Systems/Tnb.Systems.csproj b/system/Tnb.Systems/Tnb.Systems.csproj index 328587e7..35ba2198 100644 --- a/system/Tnb.Systems/Tnb.Systems.csproj +++ b/system/Tnb.Systems/Tnb.Systems.csproj @@ -1,4 +1,4 @@ - + @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8619;CS8625;CS8629;CS1572;CS1573;CS0168;CS4014;CS1998; diff --git a/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj b/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj index f0f0d51f..4abeef78 100644 --- a/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj +++ b/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn)CS8604; diff --git a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj index f2dfa7fb..966534a1 100644 --- a/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj +++ b/taskschedule/Tnb.TaskScheduler/Tnb.TaskScheduler.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS1572;CS1573; diff --git a/visualdev/Tnb.VisualDev.Engine/Tnb.VisualDev.Engine.csproj b/visualdev/Tnb.VisualDev.Engine/Tnb.VisualDev.Engine.csproj index 50f2e5c3..1d9eedd5 100644 --- a/visualdev/Tnb.VisualDev.Engine/Tnb.VisualDev.Engine.csproj +++ b/visualdev/Tnb.VisualDev.Engine/Tnb.VisualDev.Engine.csproj @@ -1,4 +1,4 @@ - + @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS8629;CS1572;CS1573;CS0168; diff --git a/visualdev/Tnb.VisualDev.Entitys/Dto/VisualDevModelData/VisualDevModelListQueryInput.cs b/visualdev/Tnb.VisualDev.Entitys/Dto/VisualDevModelData/VisualDevModelListQueryInput.cs index f05956df..5a5f52d8 100644 --- a/visualdev/Tnb.VisualDev.Entitys/Dto/VisualDevModelData/VisualDevModelListQueryInput.cs +++ b/visualdev/Tnb.VisualDev.Entitys/Dto/VisualDevModelData/VisualDevModelListQueryInput.cs @@ -8,10 +8,11 @@ namespace JNPF.VisualDev.Entitys.Dto.VisualDevModelData; /// public class VisualDevModelListQueryInput : PageInputBase { - /// - /// 菜单ID. - /// - public string menuId { get; set; } + //modified by PhilPan + ///// + ///// 菜单ID. + ///// + //public string menuId { get; set; } /// /// 选择导出数据key. diff --git a/visualdev/Tnb.VisualDev.Entitys/Tnb.VisualDev.Entitys.csproj b/visualdev/Tnb.VisualDev.Entitys/Tnb.VisualDev.Entitys.csproj index 1e177c15..76aef262 100644 --- a/visualdev/Tnb.VisualDev.Entitys/Tnb.VisualDev.Entitys.csproj +++ b/visualdev/Tnb.VisualDev.Entitys/Tnb.VisualDev.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/visualdev/Tnb.VisualDev/RunService.cs b/visualdev/Tnb.VisualDev/RunService.cs index fd1b9b98..498e1ba3 100644 --- a/visualdev/Tnb.VisualDev/RunService.cs +++ b/visualdev/Tnb.VisualDev/RunService.cs @@ -57,10 +57,10 @@ public class RunService : IRunService, ITransient /// private readonly IBillRullService _billRuleService; - /// - /// 缓存管理. - /// - private readonly ICacheManager _cacheManager; + ///// + ///// 缓存管理. + ///// + //private readonly ICacheManager _cacheManager; /// /// 用户管理. diff --git a/visualdev/Tnb.VisualDev/Tnb.VisualDev.csproj b/visualdev/Tnb.VisualDev/Tnb.VisualDev.csproj index 10a3c287..e6e5b41b 100644 --- a/visualdev/Tnb.VisualDev/Tnb.VisualDev.csproj +++ b/visualdev/Tnb.VisualDev/Tnb.VisualDev.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS8629;CS1572;CS1573;CS0168; diff --git a/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs b/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs index 13a2b694..64407b37 100644 --- a/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs +++ b/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs @@ -872,7 +872,7 @@ namespace JNPF.VisualDev var len = rowChildDatas.Select(x => x.Value.Count()).OrderByDescending(x => x).FirstOrDefault(); - if (len != null && len > 0) + if (len > 0) { for (int i = 0; i < len; i++) { diff --git a/visualdev/Tnb.VisualDev/VisualDevService.cs b/visualdev/Tnb.VisualDev/VisualDevService.cs index 94151705..7bf72960 100644 --- a/visualdev/Tnb.VisualDev/VisualDevService.cs +++ b/visualdev/Tnb.VisualDev/VisualDevService.cs @@ -1281,7 +1281,7 @@ public class VisualDevService : IVisualDevService, IDynamicApiController, ITrans foreach (DbTableAndFieldModel? item in addTableList) { bool res = await _changeDataBase.Create(link, item, item.FieldList); - if (!res) throw null; + if (!res) Oops.Oh(ErrorCode.COM1008); // throw null; } if (await _visualDevRepository.IsAnyAsync(x => x.Id.Equals(vEntity.Id))) diff --git a/visualdev/Tnb.VisualDev/VisualdevModelAppService.cs b/visualdev/Tnb.VisualDev/VisualdevModelAppService.cs index 1a1d04d7..04233a29 100644 --- a/visualdev/Tnb.VisualDev/VisualdevModelAppService.cs +++ b/visualdev/Tnb.VisualDev/VisualdevModelAppService.cs @@ -409,7 +409,7 @@ public class VisualdevModelAppService : IDynamicApiController, ITransient var len = rowChildDatas.Select(x => x.Value.Count()).OrderByDescending(x => x).FirstOrDefault(); - if (len != null && len > 0) + if (len > 0) { for (int i = 0; i < len; i++) { diff --git a/workflow/Tnb.WorkFlow.Entitys/Tnb.WorkFlow.Entitys.csproj b/workflow/Tnb.WorkFlow.Entitys/Tnb.WorkFlow.Entitys.csproj index 358cdc7b..938c5f8a 100644 --- a/workflow/Tnb.WorkFlow.Entitys/Tnb.WorkFlow.Entitys.csproj +++ b/workflow/Tnb.WorkFlow.Entitys/Tnb.WorkFlow.Entitys.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8618; diff --git a/workflow/Tnb.WorkFlow.Interfaces/Tnb.WorkFlow.Interfaces.csproj b/workflow/Tnb.WorkFlow.Interfaces/Tnb.WorkFlow.Interfaces.csproj index 23d1885c..04a146bb 100644 --- a/workflow/Tnb.WorkFlow.Interfaces/Tnb.WorkFlow.Interfaces.csproj +++ b/workflow/Tnb.WorkFlow.Interfaces/Tnb.WorkFlow.Interfaces.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8625; diff --git a/workflow/Tnb.WorkFlow/Tnb.WorkFlow.csproj b/workflow/Tnb.WorkFlow/Tnb.WorkFlow.csproj index 3f246622..261223a1 100644 --- a/workflow/Tnb.WorkFlow/Tnb.WorkFlow.csproj +++ b/workflow/Tnb.WorkFlow/Tnb.WorkFlow.csproj @@ -6,6 +6,7 @@ enable enable True + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8619;CS8620;CS8625;CS8629;CS1572;CS1573;CS0168;CS4014;CS1998; From ce0bff561f6f4ce3bc13052444d43fdb67e8c1b2 Mon Sep 17 00:00:00 2001 From: PhilPan Date: Tue, 16 May 2023 18:00:42 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=B9=B3=E5=8F=B0warn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/Tnb.Common.Core/Tnb.Common.Core.csproj | 2 +- .../Tnb.Common/Extension/StringExtensions.cs | 280 ++++++++++++++++++ common/Tnb.WebSockets/Tnb.WebSockets.csproj | 2 +- extend/Tnb.Extend/Tnb.Extend.csproj | 2 +- .../Tnb.Message.Interfaces.csproj | 1 + .../OrganizeAdminIsTratorUpInput.cs | 9 +- .../Tnb.Systems.Entitys.csproj | 4 +- .../Tnb.TaskScheduler.Entitys.csproj | 2 +- .../Listener/SpareTimeListener.cs | 3 +- .../CodeGen/CodeGenWay.cs | 2 - .../Model/IndexGridFieldModel.cs | 9 +- .../Model/IndexSearchFieldModel.cs | 9 +- .../Tnb.WorkFlow/Manager/FlowTaskOtherUtil.cs | 3 +- 13 files changed, 306 insertions(+), 22 deletions(-) diff --git a/common/Tnb.Common.Core/Tnb.Common.Core.csproj b/common/Tnb.Common.Core/Tnb.Common.Core.csproj index f7e011f8..d7c75c81 100644 --- a/common/Tnb.Common.Core/Tnb.Common.Core.csproj +++ b/common/Tnb.Common.Core/Tnb.Common.Core.csproj @@ -6,7 +6,7 @@ enable enable False - $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS1572;CS1573;CS0168;CS1998; + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS1572;CS1573;CS0168;CS1998; diff --git a/common/Tnb.Common/Extension/StringExtensions.cs b/common/Tnb.Common/Extension/StringExtensions.cs index 189a3c6d..02cce18e 100644 --- a/common/Tnb.Common/Extension/StringExtensions.cs +++ b/common/Tnb.Common/Extension/StringExtensions.cs @@ -950,4 +950,284 @@ public static class StringExtensions } #endregion + + #region 转换,来自Abp + /// + /// Converts PascalCase string to camelCase string. + /// + /// String to convert + /// set true to use current culture. Otherwise, invariant culture will be used. + /// set true to if you want to convert 'XYZ' to 'xyz'. + /// camelCase of the string + public static string ToCamelCase(this string str, bool useCurrentCulture = false, bool handleAbbreviations = false) + { + if (string.IsNullOrWhiteSpace(str)) + { + return str; + } + + if (str.Length == 1) + { + return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant(); + } + + if (handleAbbreviations && IsAllUpperCase(str)) + { + return useCurrentCulture ? str.ToLower() : str.ToLowerInvariant(); + } + + return (useCurrentCulture ? char.ToLower(str[0]) : char.ToLowerInvariant(str[0])) + str.Substring(1); + } + + /// + /// Converts given PascalCase/camelCase string to sentence (by splitting words by space). + /// Example: "ThisIsSampleSentence" is converted to "This is a sample sentence". + /// + /// String to convert. + /// set true to use current culture. Otherwise, invariant culture will be used. + public static string ToSentenceCase(this string str, bool useCurrentCulture = false) + { + if (string.IsNullOrWhiteSpace(str)) + { + return str; + } + + return useCurrentCulture + ? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLower(m.Value[1])) + : Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + " " + char.ToLowerInvariant(m.Value[1])); + } + + /// + /// Converts given PascalCase/camelCase string to kebab-case. + /// + /// String to convert. + /// set true to use current culture. Otherwise, invariant culture will be used. + public static string ToKebabCase(this string str, bool useCurrentCulture = false) + { + if (string.IsNullOrWhiteSpace(str)) + { + return str; + } + + str = str.ToCamelCase(); + + return useCurrentCulture + ? Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLower(m.Value[1])) + : Regex.Replace(str, "[a-z][A-Z]", m => m.Value[0] + "-" + char.ToLowerInvariant(m.Value[1])); + } + + /// + /// Converts given PascalCase/camelCase string to snake case. + /// Example: "ThisIsSampleSentence" is converted to "this_is_a_sample_sentence". + /// https://github.com/npgsql/npgsql/blob/dev/src/Npgsql/NameTranslation/NpgsqlSnakeCaseNameTranslator.cs#L51 + /// + /// String to convert. + /// + public static string ToSnakeCase(this string str) + { + if (string.IsNullOrWhiteSpace(str)) + { + return str; + } + + var builder = new StringBuilder(str.Length + Math.Min(2, str.Length / 5)); + var previousCategory = default(UnicodeCategory?); + + for (var currentIndex = 0; currentIndex < str.Length; currentIndex++) + { + var currentChar = str[currentIndex]; + if (currentChar == '_') + { + builder.Append('_'); + previousCategory = null; + continue; + } + + var currentCategory = char.GetUnicodeCategory(currentChar); + switch (currentCategory) + { + case UnicodeCategory.UppercaseLetter: + case UnicodeCategory.TitlecaseLetter: + if (previousCategory == UnicodeCategory.SpaceSeparator || + previousCategory == UnicodeCategory.LowercaseLetter || + previousCategory != UnicodeCategory.DecimalDigitNumber && + previousCategory != null && + currentIndex > 0 && + currentIndex + 1 < str.Length && + char.IsLower(str[currentIndex + 1])) + { + builder.Append('_'); + } + + currentChar = char.ToLower(currentChar); + break; + + case UnicodeCategory.LowercaseLetter: + case UnicodeCategory.DecimalDigitNumber: + if (previousCategory == UnicodeCategory.SpaceSeparator) + { + builder.Append('_'); + } + break; + + default: + if (previousCategory != null) + { + previousCategory = UnicodeCategory.SpaceSeparator; + } + continue; + } + + builder.Append(currentChar); + previousCategory = currentCategory; + } + + return builder.ToString(); + } + + /// + /// Converts camelCase string to PascalCase string. + /// + /// String to convert + /// set true to use current culture. Otherwise, invariant culture will be used. + /// PascalCase of the string + public static string ToPascalCase(this string str, bool useCurrentCulture = false) + { + if (string.IsNullOrWhiteSpace(str)) + { + return str; + } + + if (str.Length == 1) + { + return useCurrentCulture ? str.ToUpper() : str.ToUpperInvariant(); + } + + return (useCurrentCulture ? char.ToUpper(str[0]) : char.ToUpperInvariant(str[0])) + str.Substring(1); + } + + /// + /// Removes first occurrence of the given prefixes from beginning of the given string. + /// + /// The string. + /// one or more prefix. + /// Modified string or the same string if it has not any of given prefixes + public static string RemovePreFix(this string str, params string[] preFixes) + { + return str.RemovePreFix(StringComparison.Ordinal, preFixes); + } + + /// + /// Removes first occurrence of the given prefixes from beginning of the given string. + /// + /// The string. + /// String comparison type + /// one or more prefix. + /// Modified string or the same string if it has not any of given prefixes + public static string RemovePreFix(this string str, StringComparison comparisonType, params string[] preFixes) + { + if (str.IsNullOrEmpty()) + { + return str; + } + + if (preFixes.IsNullOrEmpty()) + { + return str; + } + + foreach (var preFix in preFixes) + { + if (str.StartsWith(preFix, comparisonType)) + { + return str.Right(str.Length - preFix.Length); + } + } + + return str; + } + + /// + /// Removes first occurrence of the given postfixes from end of the given string. + /// + /// The string. + /// one or more postfix. + /// Modified string or the same string if it has not any of given postfixes + public static string RemovePostFix(this string str, params string[] postFixes) + { + return str.RemovePostFix(StringComparison.Ordinal, postFixes); + } + + /// + /// Removes first occurrence of the given postfixes from end of the given string. + /// + /// The string. + /// String comparison type + /// one or more postfix. + /// Modified string or the same string if it has not any of given postfixes + public static string RemovePostFix(this string str, StringComparison comparisonType, params string[] postFixes) + { + if (str.IsNullOrEmpty()) + { + return str; + } + + if (postFixes.IsNullOrEmpty()) + { + return str; + } + + foreach (var postFix in postFixes) + { + if (str.EndsWith(postFix, comparisonType)) + { + return str.Left(str.Length - postFix.Length); + } + } + + return str; + } + + /// + /// Gets a substring of a string from beginning of the string. + /// + /// Thrown if is null + /// Thrown if is bigger that string's length + public static string Left(this string str, int len) + { + if (str.Length < len) + { + throw new ArgumentException("len argument can not be bigger than given string's length!"); + } + + return str.Substring(0, len); + } + /// + /// Gets a substring of a string from end of the string. + /// + /// Thrown if is null + /// Thrown if is bigger that string's length + public static string Right(this string str, int len) + { + if (str.Length < len) + { + throw new ArgumentException("len argument can not be bigger than given string's length!"); + } + + return str.Substring(str.Length - len, len); + } + private static bool IsAllUpperCase(string input) + { + for (int i = 0; i < input.Length; i++) + { + if (Char.IsLetter(input[i]) && !Char.IsUpper(input[i])) + { + return false; + } + } + + return true; + } + + #endregion } \ No newline at end of file diff --git a/common/Tnb.WebSockets/Tnb.WebSockets.csproj b/common/Tnb.WebSockets/Tnb.WebSockets.csproj index 081b83d5..b87a3d57 100644 --- a/common/Tnb.WebSockets/Tnb.WebSockets.csproj +++ b/common/Tnb.WebSockets/Tnb.WebSockets.csproj @@ -7,7 +7,7 @@ enable enable False - $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS1572;CS1573;CS1998; + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS1572;CS1573;CS1998; diff --git a/extend/Tnb.Extend/Tnb.Extend.csproj b/extend/Tnb.Extend/Tnb.Extend.csproj index e5c49e58..878a7f6d 100644 --- a/extend/Tnb.Extend/Tnb.Extend.csproj +++ b/extend/Tnb.Extend/Tnb.Extend.csproj @@ -6,7 +6,7 @@ enable enable True - $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8625;CS1572;CS1573;CS0168;CS4014; + $(NoWarn);CS8600;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS1572;CS1573;CS0168;CS4014; diff --git a/message/Tnb.Message.Interfaces/Tnb.Message.Interfaces.csproj b/message/Tnb.Message.Interfaces/Tnb.Message.Interfaces.csproj index 53b4b389..a01086ce 100644 --- a/message/Tnb.Message.Interfaces/Tnb.Message.Interfaces.csproj +++ b/message/Tnb.Message.Interfaces/Tnb.Message.Interfaces.csproj @@ -6,6 +6,7 @@ enable enable False + $(NoWarn);CS8625; diff --git a/system/Tnb.Systems.Entitys/Dto/Permission/OrganizeAdministrator/OrganizeAdminIsTratorUpInput.cs b/system/Tnb.Systems.Entitys/Dto/Permission/OrganizeAdministrator/OrganizeAdminIsTratorUpInput.cs index bf2e80b8..2bb1f6e2 100644 --- a/system/Tnb.Systems.Entitys/Dto/Permission/OrganizeAdministrator/OrganizeAdminIsTratorUpInput.cs +++ b/system/Tnb.Systems.Entitys/Dto/Permission/OrganizeAdministrator/OrganizeAdminIsTratorUpInput.cs @@ -7,10 +7,11 @@ namespace JNPF.Systems.Entitys.Dto.OrganizeAdministrator; /// public class OrganizeAdminIsTratorUpInput : OrganizeAdminCrInput { - /// - /// 主键. - /// - public string id { get; set; } + //modified by PhilPan + ///// + ///// 主键. + ///// + //public string id { get; set; } /// /// 权限组织集合. diff --git a/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj b/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj index 3c84db98..1418d2c1 100644 --- a/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj +++ b/system/Tnb.Systems.Entitys/Tnb.Systems.Entitys.csproj @@ -1,4 +1,4 @@ - + @@ -6,7 +6,7 @@ enable enable False - $(NoWarn);CS8618; + $(NoWarn);CS8603;CS8618; diff --git a/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj b/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj index 4abeef78..fe747c12 100644 --- a/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj +++ b/taskschedule/Tnb.TaskScheduler.Entitys/Tnb.TaskScheduler.Entitys.csproj @@ -6,7 +6,7 @@ enable enable False - $(NoWarn)CS8604; + $(NoWarn)CS8604;CS8618; diff --git a/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeListener.cs b/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeListener.cs index 09f0d238..4cd08159 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeListener.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/SpareTimeListener.cs @@ -86,7 +86,8 @@ public class SpareTimeListener : ISpareTimeListener, ISingleton } var taskEntity = await _sqlSugarClient.Queryable().FirstAsync(x => x.Id == executer.Timer.WorkerName); - var nextRunTime = ((DateTimeOffset)SpareTime.GetCronNextOccurrence(taskEntity.ExecuteCycleJson)).DateTime; + //modified by PhilPan + var nextRunTime = SpareTime.GetCronNextOccurrence(taskEntity.ExecuteCycleJson)?.DateTime; await _eventPublisher.PublishAsync(new TaskEventSource("Task:UpdateTask", connectionConfig, new TimeTaskEntity() { diff --git a/visualdev/Tnb.VisualDev.Engine/CodeGen/CodeGenWay.cs b/visualdev/Tnb.VisualDev.Engine/CodeGen/CodeGenWay.cs index d7bbce5b..ba30ffbf 100644 --- a/visualdev/Tnb.VisualDev.Engine/CodeGen/CodeGenWay.cs +++ b/visualdev/Tnb.VisualDev.Engine/CodeGen/CodeGenWay.cs @@ -1269,7 +1269,6 @@ public class CodeGenWay IsRelationForm = isRelationForm, ChildTableStyle = columnDesignModel.childTableStyle, }; - break; default: return new FrontEndGenConfigModel() { @@ -1339,7 +1338,6 @@ public class CodeGenWay ChildTableStyle = columnDesignModel.childTableStyle, IsFixed = isFixed, }; - break; } } diff --git a/visualdev/Tnb.VisualDev.Engine/Model/IndexGridFieldModel.cs b/visualdev/Tnb.VisualDev.Engine/Model/IndexGridFieldModel.cs index bba29120..cfdc7458 100644 --- a/visualdev/Tnb.VisualDev.Engine/Model/IndexGridFieldModel.cs +++ b/visualdev/Tnb.VisualDev.Engine/Model/IndexGridFieldModel.cs @@ -8,10 +8,11 @@ namespace JNPF.VisualDev.Engine; [SuppressSniffer] public class IndexGridFieldModel : IndexEachConfigBase { - /// - /// 对齐. - /// - public string align { get; set; } + //modified by PhilPan + ///// + ///// 对齐. + ///// + //public string align { get; set; } /// /// 固定. diff --git a/visualdev/Tnb.VisualDev.Engine/Model/IndexSearchFieldModel.cs b/visualdev/Tnb.VisualDev.Engine/Model/IndexSearchFieldModel.cs index f2ab0a13..ba618fc0 100644 --- a/visualdev/Tnb.VisualDev.Engine/Model/IndexSearchFieldModel.cs +++ b/visualdev/Tnb.VisualDev.Engine/Model/IndexSearchFieldModel.cs @@ -14,8 +14,9 @@ public class IndexSearchFieldModel : IndexEachConfigBase /// public string value { get; set; } - /// - /// 查询类型. - /// - public int? searchType { get; set; } + //modified by PhilPan + ///// + ///// 查询类型. + ///// + //public int? searchType { get; set; } } diff --git a/workflow/Tnb.WorkFlow/Manager/FlowTaskOtherUtil.cs b/workflow/Tnb.WorkFlow/Manager/FlowTaskOtherUtil.cs index a54f81ad..77a6daeb 100644 --- a/workflow/Tnb.WorkFlow/Manager/FlowTaskOtherUtil.cs +++ b/workflow/Tnb.WorkFlow/Manager/FlowTaskOtherUtil.cs @@ -361,7 +361,8 @@ public class FlowTaskOtherUtil { try { - if (jobj[timeOutConfig.formField] is long) + //modified by PhilPan + if (jobj[timeOutConfig.formField].Type == Newtonsoft.Json.Linq.JTokenType.Integer) { dt = jobj[timeOutConfig.formField].ParseToLong().TimeStampToDateTime(); } From 408bbd87893614a622c9832dcac1e70c731d6270 Mon Sep 17 00:00:00 2001 From: PhilPan Date: Tue, 16 May 2023 19:52:52 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90,=E5=A2=9E=E5=8A=A0string?= =?UTF-8?q?=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BasCustomer.cs | 174 ++++++++++++++++++ common/Tnb.SqlSugar/Tnb.SqlSugar.csproj | 2 +- system/Tnb.Systems/System/DataBaseService.cs | 64 +++---- 3 files changed, 201 insertions(+), 39 deletions(-) create mode 100644 BasicData/Tnb.BasicData.Entities/Entity/BasCustomer.cs diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasCustomer.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasCustomer.cs new file mode 100644 index 00000000..698ae11b --- /dev/null +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasCustomer.cs @@ -0,0 +1,174 @@ +using System; +using System.Linq; +using System.Text; +using SqlSugar; + +namespace Tnb.BasicData.Entities +{ + /// + ///客户信息 + /// + [SugarTable("bas_customer")] + public partial class BasCustomer + { + public BasCustomer(){ + + this.org_id =Convert.ToString("NULL::character varying"); + this.short_name =Convert.ToString("NULL::character varying"); + this.full_address =Convert.ToString("NULL::character varying"); + this.postal_code =Convert.ToString("NULL::character varying"); + this.country =Convert.ToString("NULL::character varying"); + this.province =Convert.ToString("NULL::character varying"); + this.city =Convert.ToString("NULL::character varying"); + this.district =Convert.ToString("NULL::character varying"); + this.street =Convert.ToString("NULL::character varying"); + this.contact_name =Convert.ToString("NULL::character varying"); + this.contact_phone =Convert.ToString("NULL::character varying"); + this.contact_mobile =Convert.ToString("NULL::character varying"); + this.create_id =Convert.ToString("NULL::character varying"); + this.modify_id =Convert.ToString("NULL::character varying"); + + } + /// + /// Desc:编号 + /// Default: + /// Nullable:False + /// + [SugarColumn(IsPrimaryKey=true)] + public string id {get;set;} + + /// + /// Desc:客户代码 + /// Default: + /// Nullable:False + /// + public string customer_code {get;set;} + + /// + /// Desc:客户名称 + /// Default: + /// Nullable:False + /// + public string customer_name {get;set;} + + /// + /// Desc:所属组织 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? org_id {get;set;} + + /// + /// Desc:客户简称 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? short_name {get;set;} + + /// + /// Desc:详细地址 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? full_address {get;set;} + + /// + /// Desc:邮编 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? postal_code {get;set;} + + /// + /// Desc:国家 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? country {get;set;} + + /// + /// Desc:省 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? province {get;set;} + + /// + /// Desc:市 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? city {get;set;} + + /// + /// Desc:区 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? district {get;set;} + + /// + /// Desc:街道地址 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? street {get;set;} + + /// + /// Desc:联系人名称 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? contact_name {get;set;} + + /// + /// Desc:联系人电话 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? contact_phone {get;set;} + + /// + /// Desc:联系人手机 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? contact_mobile {get;set;} + + /// + /// Desc:创建用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? create_id {get;set;} + + /// + /// Desc:创建时间 + /// Default: + /// Nullable:True + /// + public DateTime? create_time {get;set;} + + /// + /// Desc:修改用户 + /// Default:NULL::character varying + /// Nullable:True + /// + public string? modify_id {get;set;} + + /// + /// Desc:修改时间 + /// Default: + /// Nullable:True + /// + public DateTime? modify_time {get;set;} + + /// + /// Desc:扩展字段 + /// Default: + /// Nullable:True + /// + public string? extras {get;set;} + + } +} diff --git a/common/Tnb.SqlSugar/Tnb.SqlSugar.csproj b/common/Tnb.SqlSugar/Tnb.SqlSugar.csproj index e71e8896..197c66e6 100644 --- a/common/Tnb.SqlSugar/Tnb.SqlSugar.csproj +++ b/common/Tnb.SqlSugar/Tnb.SqlSugar.csproj @@ -18,7 +18,7 @@ - + diff --git a/system/Tnb.Systems/System/DataBaseService.cs b/system/Tnb.Systems/System/DataBaseService.cs index 592ef1c1..da72766c 100644 --- a/system/Tnb.Systems/System/DataBaseService.cs +++ b/system/Tnb.Systems/System/DataBaseService.cs @@ -386,51 +386,39 @@ public class DataBaseService : IDynamicApiController, ITransient sugarClient = _dataBaseManager.ChangeDataBase(link); } - string CustomFormatName(string s) + var entityName = string.Join("", input.TableName.Split('_').Select(a => a.ToPascalCase())); + foreach (var item in sugarClient.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName)) { - var pos = 0; - if ((pos = s.IndexOf("_", StringComparison.Ordinal)) > -1) - { - var separatorStrings = Regex.Split(s, @"_", RegexOptions.Compiled); - if (separatorStrings.Length > 2) - { - var sb = new StringBuilder(); - foreach (var item in separatorStrings) - { - sb.Append(item.ToUpperCase()); - } - return sb.ToString(); - } - else - { - var first = s.AsSpan().Slice(0, pos).ToString().ToUpperCase(); - var second = s.AsSpan().Slice(pos + 1).ToString().ToUpperCase(); - return $"{first}{second}"; - } - } - else - { - return s.ToUpperCase(); - } - } - - foreach (var item in sugarClient!.DbMaintenance.GetTableInfoList().Where(t => t.Name == input.TableName)) - { - string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/ + //string entityName = CustomFormatName(item.Name);/*实体名首字母大写*/ sugarClient.MappingTables.Add(entityName, item.Name); - foreach (var col in sugarClient.DbMaintenance.GetColumnInfosByTableName(item.Name)) - { - //var colName = CustomFormatName(col.DbColumnName); - sugarClient.MappingColumns.Add(col.DbColumnName /*类的属性首字母大写*/, col.DbColumnName, entityName); - } + //foreach (var col in sugarClient.DbMaintenance.GetColumnInfosByTableName(item.Name)) + //{ + // //var colName = CustomFormatName(col.DbColumnName); + // sugarClient.MappingColumns.Add(col.DbColumnName /*类的属性首字母大写*/, col.DbColumnName, entityName); + //} } + var prefix = input.TableName.Split('_')[0]; + Dictionary nsMapper = new() + { + {"bas", "Tnb.BasicData.Entities" }, + {"prd", "Tnb.ProductionMgr.Entities" }, + {"wms", "Tnb.WarehouseMgr.Entities" }, + {"eqp", "Tnb.EquipMgr.Entities" }, + {"tool", "Tnb.EquipMgr.Entities" }, + {"qc", "Tnb.QcMgr.Entities" }, + }; sugarClient.DbFirst.Where(input.TableName) - .FormatFileName(CustomFormatName) + .SettingConstructorTemplate(a => + { + return a; + }) + //.IsCreateDefaultValue(true) .IsCreateAttribute() - .CreateClassFile(dir, "DbModels"); + .StringNullable() + .CreateClassFile(dir, nsMapper.ContainsKey(prefix) ? nsMapper[prefix] : "Tnb.Entities"); var previewContent = ""; - var codeFile = Path.Combine(dir, $"{CustomFormatName(input.TableName)}.cs"); + var codeFile = Path.Combine(dir, $"{entityName}.cs"); if (File.Exists(codeFile)) { using (var sr = File.OpenText(codeFile)) From 8519f7af2ec2846e631bb86b30f2570d8791fa62 Mon Sep 17 00:00:00 2001 From: "DEVICE8\\12494" Date: Wed, 17 May 2023 08:34:52 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E7=BB=84=E8=A3=85=E5=8C=85=E8=A3=85?= =?UTF-8?q?=E6=8E=92=E4=BA=A7=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/PrdManage/PackSchedlingCrInput.cs | 41 +- .../PackSechelToBeIssueListOutput.cs | 57 +++ .../Dto/PrdManage/PrdMoTaskOutput.cs | 8 + .../Entity/PrdMoTask.cs | 8 + .../Entity/PrdTaskLog.cs | 6 + .../Tnb.ProductionMgr/PrdMoTaskService.cs | 430 ++++++++++++------ 6 files changed, 394 insertions(+), 156 deletions(-) create mode 100644 ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs index baed56c1..ad2901da 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSchedlingCrInput.cs @@ -10,14 +10,6 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// 组装、包装排产输入参数 /// public class PackSchedlingCrInput - { - /// - /// bom任务集合 - /// - public List items{ get; set; } - } - - public class PackSchedlingItem { /// /// 工单Id @@ -28,10 +20,6 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public string bom_id { get; set; } /// - /// 工序id - /// - public string process_id { get; set; } - /// /// 产线Id /// public string workline_id { get; set; } @@ -39,21 +27,26 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// 物料Id /// public string material_id { get; set; } + /// - /// 生产任务单号 + /// 排产数量 /// - public string mo_task_code { get; set; } + public string scheduled_qty { get; set; } + /// - /// 物料编码 - /// - public string material_code { get; set; } + /// Desc:预计开始时间 + /// Default: + /// Nullable:True + /// + public DateTime estimated_start_date { get; set; } + /// - /// 物料名称 - /// - public string material_name { get; set; } - /// - /// bom产出料数量 - /// - public string qty { get; set; } + /// Desc:预计结束时间 + /// Default: + /// Nullable:True + /// + public DateTime estimated_end_date { get; set; } + + } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs new file mode 100644 index 00000000..5413c2e7 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PackSechelToBeIssueListOutput.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.DirectoryServices.Protocols; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + /// + /// 组装、包装生产任务待下发输出参数列表 + /// + public class PackSechelToBeIssueListOutput + { + /// + /// 生产任务ID + /// + public string mo_task_id { get; set; } + /// + /// 生产任务编号 + /// + public string mo_task_code { get; set; } + /// + /// 物料编号 + /// + public string material_code { get; set; } + /// + /// 物料名称 + /// + public string material_name { get; set; } + /// + /// 产线编号 + /// + public string workline_code { get; set; } + /// + /// 产线名称 + /// + public string workline_name { get; set; } + /// + /// 任务单状态 + /// + public string mo_task_status { get; set; } + /// + /// 生产任务数量 + /// + public int scheduled_qty { get; set; } + /// + /// 计划数量 + /// + public int plan_qty { get; set; } + /// + /// 工序任务量 + /// + public int process_task_qty { get; set; } + + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs index e419ce92..dc48353f 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/PrdMoTaskOutput.cs @@ -47,6 +47,14 @@ namespace Tnb.ProductionMgr.Entities.Dto.PrdManage /// public string eqp_type_code { get; set; } /// + /// 产线编码 + /// + public string workline_code { get; set; } + /// + /// 产线名称 + /// + public string workline_name { get; set; } + /// /// 任务单数量 /// public int mo_task_qty { get; set; } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs index c9b236bd..74d97ddb 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdMoTask.cs @@ -93,6 +93,10 @@ namespace DbModels /// [SugarColumn(IsPrimaryKey = true)] public string id { get; set; } + /// + /// 父任务ID + /// + public string parent_id { get; set; } /// /// Desc:生产任务编号 @@ -229,6 +233,10 @@ namespace DbModels /// [SugarColumn(IsIgnore = true)] public int mold_cavity_qty { get; set; } + /// + /// 工序任务量 + /// + public int process_task_qty { get; set; } } diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs index bf099d85..28792475 100644 --- a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/PrdTaskLog.cs @@ -108,6 +108,12 @@ namespace Tnb.ProductionMgr.Entities /// 任务单编号 /// public string mo_task_code { get; set; } + /// + /// 产线Code + /// + [SugarColumn(IsIgnore = true)] + public string workline_code { get; set; } + } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index 0e56704d..79d2f067 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -34,6 +34,7 @@ using Senparc.Weixin.MP.AdvancedAPIs.Card; using Aspose.Cells.Drawing.Texts; using JNPF.Systems.Entitys.Permission; using WebSocketSharp.Frame; +using JNPF.Logging; namespace Tnb.ProductionMgr { @@ -344,40 +345,130 @@ namespace Tnb.ProductionMgr ///
} /// [HttpGet("{moId}")] - public async Task GetPrdTaskInfoByMoId(string moId) + public async Task GetPrdTaskInfoByMoId(string moId, int schedType = 1) { + List result = new(); var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); - var result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id) - .LeftJoin((a, b, c) => a.material_id == c.id) - .LeftJoin((a, b, c, d) => a.mold_id == d.id) - .LeftJoin((a, b, c, d, e) => a.eqp_id == e.id) - .Where((a, b, c, d, e) => a.mo_id == moId) - .Select((a, b, c, d, e) => new PrdMoTaskOutput - { - mo_task_code = a.mo_task_code, - mo_task_status = a.mo_task_status, - mold_code = d.mold_code, - mold_name = d.mold_name, - material_code = c.code, - material_name = c.name, - eqp_code = e.code, - eqp_name = e.name, - eqp_type_code = SqlFunc.Subqueryable().Where(it => it.id == e.equip_type_id).Select(it => it.code), - mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(), - estimated_start_date = a.estimated_start_date, - estimated_end_date = a.estimated_end_date, - plan_qty = b.plan_qty, - complete_qty = a.complete_qty, - }) - .Mapper(it => - { - it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; - }) - .ToListAsync(); + if (schedType == 1) + { + result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id) + .LeftJoin((a, b, c) => a.material_id == c.id) + .LeftJoin((a, b, c, d) => a.mold_id == d.id) + .LeftJoin((a, b, c, d, e) => a.eqp_id == e.id) + .Where((a, b, c, d, e) => a.mo_id == moId) + .Select((a, b, c, d, e) => new PrdMoTaskOutput + { + mo_task_code = a.mo_task_code, + mo_task_status = a.mo_task_status, + mold_code = d.mold_code, + mold_name = d.mold_name, + material_code = c.code, + material_name = c.name, + eqp_code = e.code, + eqp_name = e.name, + eqp_type_code = SqlFunc.Subqueryable().Where(it => it.id == e.equip_type_id).Select(it => it.code), + mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(), + estimated_start_date = a.estimated_start_date, + estimated_end_date = a.estimated_end_date, + plan_qty = b.plan_qty, + complete_qty = a.complete_qty, + }) + .Mapper(it => + { + it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; + }) + .ToListAsync(); + } + else + { + result = await _db.Queryable().LeftJoin((a, b) => a.mo_id == b.id) + .LeftJoin((a, b, c) => a.material_id == c.id) + .LeftJoin((a, b, c, d) => a.workline_id == d.Id) + .Where((a, b, c, d) => a.mo_id == moId) + .Select((a, b, c, d) => new PrdMoTaskOutput + { + mo_task_code = a.mo_task_code, + mo_task_status = a.mo_task_status, + workline_code = d.EnCode, + workline_name = d.FullName, + material_code = c.code, + material_name = c.name, + mo_task_qty = SqlFunc.Subqueryable().Where(a => a.mo_id == moId).Count(), + estimated_start_date = a.estimated_start_date, + estimated_end_date = a.estimated_end_date, + plan_qty = b.plan_qty, + complete_qty = a.complete_qty, + }) + .Mapper(it => + { + it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : ""; + }) + .ToListAsync(); + } + return result; } + /// + ///组装、包装 获取待下发任务列表 + /// + /// + [HttpGet] + public async Task GetPackScheldToBeIssueList() + { + var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); + var result = await _db.Queryable().Where(it => it.schedule_type == 2) + .LeftJoin((a, b) => a.material_id == b.id) + .LeftJoin((a, b, c) => a.workline_id == c.Id) + .LeftJoin((a, b, c, d) => a.mo_id == d.id) + .Select((a, b, c, d) => new PackSechelToBeIssueListOutput + { + mo_task_id = a.id, + mo_task_code = a.mo_task_code, + material_code = b.code, + material_name = b.name, + workline_code = c.EnCode, + workline_name = c.FullName, + mo_task_status = a.mo_task_status, + scheduled_qty = a.scheduled_qty, + plan_qty = d.plan_qty + }) + .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "") + .ToListAsync(); + return result; + } + /// + /// 根据生产任务ID获取子任务列表 + /// + /// + /// + [HttpGet("{mo_task_id}")] + public async Task GetSubMoTaskListByTaskId(string mo_task_id) + { + var dic = await _dictionaryDataService.GetDicByTypeId(DictConst.PrdTaskStatusTypeId); + var result = await _db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .LeftJoin((a, b, c) => a.workline_id == c.Id) + .LeftJoin((a, b, c, d) => a.mo_id == d.id) + .Where((a, b, c, d) => a.parent_id == mo_task_id) + .Select((a, b, c, d) => new PackSechelToBeIssueListOutput + { + mo_task_id = a.id, + mo_task_code = a.mo_task_code, + material_code = b.code, + material_name = b.name, + workline_code = c.EnCode, + workline_name = c.FullName, + mo_task_status = a.mo_task_status, + scheduled_qty = a.scheduled_qty, + plan_qty = d.plan_qty, + process_task_qty = a.process_task_qty, + }) + .Mapper(it => it.mo_task_status = dic.ContainsKey(it.mo_task_status) ? dic[it.mo_task_status].ToString() : "") + .ToListAsync(); + return result; + } @@ -593,69 +684,126 @@ namespace Tnb.ProductionMgr [HttpPost] public async Task PackSchedling(PackSchedlingCrInput input) { - if (input.items == null) + var row = -1; + try { - throw new ArgumentNullException(nameof(input.items)); - } - DbResult dbResult = null; - if (input.items.Count > 0) - { - var moTasks = input.items.Select(x => new PrdMoTask + await _db.Ado.BeginTranAsync(); + var moTask = input.Adapt(); + moTask.id = SnowflakeIdHelper.NextId(); + moTask.create_id = _userManager.UserId; + moTask.create_time = DateTime.Now; + moTask.schedule_type = 2; + moTask.mo_task_status = DictConst.ToBeScheduledEncode; + moTask.estimated_start_date = input.estimated_start_date; + moTask.estimated_end_date = input.estimated_end_date; + var mo = await _db.Queryable().FirstAsync(it => it.id == input.mo_id); + var moCode = mo?.mo_code; + var taskCode = await _db.Queryable().Where(it => !string.IsNullOrEmpty(it.mo_task_code) && it.mo_task_code.Contains(moCode)).OrderByDescending(it => it.mo_task_code).Select(it => it.mo_task_code).FirstAsync(); + if (taskCode.IsNullOrEmpty()) { - id = SnowflakeIdHelper.NextId(), - mo_task_code = x.mo_task_code, - material_id = x.material_id, - mo_id = x.mo_id, - bom_id = x.bom_id, - create_id = _userManager.UserId, - scheduled_qty = x.qty.ParseToInt(), - create_time = DateTime.Now - }).ToList(); - dbResult = await _db.Ado.UseTranAsync(async () => + moTask.mo_task_code = $"{moCode}-01"; + } + else { - await _db.Insertable(moTasks).ExecuteCommandAsync(); - List taskLogList = new(); - List taskDefectRecordList = new(); - - foreach (var moTask in moTasks) + var pos = taskCode.IndexOf("-", StringComparison.Ordinal); + if (pos > -1) { - var material = await _db.Queryable().FirstAsync(it => it.id == moTask.material_id); - var mo = await _db.Queryable().FirstAsync(it => it.id == moTask.mo_id); - var taskLog = new PrdTaskLog(); - taskLog.id = SnowflakeIdHelper.NextId(); - taskLog.mo_code = mo?.mo_code; - taskLog.eqp_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.eqp_id))?.code; - taskLog.mold_code = (await _db.Queryable().FirstAsync(it => it.id == moTask.mold_id))?.mold_code; - taskLog.item_code = material?.code; - taskLog.item_standard = material?.material_standard; - taskLog.status = DictConst.ToBeScheduledEncode; - taskLog.operator_name = _userManager.RealName; - taskLog.create_id = _userManager.UserId; - taskLog.create_time = DateTime.Now; - taskLog.mo_task_id = moTask.id; - taskLog.mo_task_code = moTask.mo_task_code; - taskLogList.Add(taskLog); - //将生产任务插入到自检报废记录表 - var sacipRecord = new PrdMoTaskDefectRecord(); - sacipRecord.id = SnowflakeIdHelper.NextId(); - sacipRecord.material_code = material?.code; - sacipRecord.material_name = material?.name; - sacipRecord.estimated_start_date = mo?.plan_start_date; - sacipRecord.estimated_end_date = mo?.plan_end_date; - sacipRecord.plan_qty = moTask.plan_qty; - sacipRecord.scrap_qty = moTask.scrap_qty; - sacipRecord.status = moTask.mo_task_status; - sacipRecord.create_id = _userManager.UserId; - sacipRecord.create_time = DateTime.Now; - sacipRecord.mo_task_id = moTask.id; - sacipRecord.mo_task_code = moTask.mo_task_code; - taskDefectRecordList.Add(sacipRecord); + var num = taskCode.AsSpan().Slice(pos + 1).ToString().ParseToInt(); + var code = taskCode.AsSpan().Slice(0, pos).ToString(); + var n = (num + 1).ToString().PadLeft(2, '0'); + moTask.mo_task_code = $"{code}-{n}"; } - await _db.Insertable(taskLogList).ExecuteCommandAsync(); - await _db.Insertable(taskDefectRecordList).ExecuteCommandAsync(); - }); + } + row = await _db.Insertable(moTask).ExecuteCommandAsync(); + var material_h = await _db.Queryable().FirstAsync(it => it.id == moTask.material_id); + //添加生产任务操作记录日志s + var taskLog = new PrdTaskLog(); + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.mo_code = (await _db.Queryable().FirstAsync(it => it.id == input.mo_id))?.mo_code; + //taskLog.eqp_code = (await _db.Queryable().FirstAsync(it => it.id == input.eqp_id))?.code; + //taskLog.mold_code = (await _db.Queryable().FirstAsync(it => it.id == input.mold_id))?.mold_code; + taskLog.item_code = material_h?.code; + taskLog.item_standard = material_h?.material_standard; + taskLog.status = DictConst.ToBeScheduledEncode; + taskLog.operator_name = _userManager.RealName; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = moTask.id; + taskLog.mo_task_code = moTask.mo_task_code; + row = await _db.Insertable(taskLog).ExecuteCommandAsync(); + //根据工单号获取当前工单包含的已排产数 + var schedQty = _db.Queryable().Where(it => it.mo_id == input.mo_id)?.Sum(d => d.scheduled_qty); + if (mo != null) + {//判断如果当前 工单的已排产数大于工单计划数量则更新工单状态为 已排产 + if (schedQty.HasValue && schedQty.Value >= mo.plan_qty) + { + mo.mo_status = DictConst.AlreadyId; + await _db.Updateable(mo).ExecuteCommandAsync(); + } + else + { + if (schedQty.HasValue) + { + mo.scheduled_qty += schedQty.Value; + await _db.Updateable(mo).ExecuteCommandAsync(); + } + } + } + //根据生产bomId 拆解生产子任务 + var outputList = new List(); + var bom = await _db.Queryable().FirstAsync(it => it.id == input.bom_id); + if (bom != null && bom.route_id.IsNotEmptyOrNull()) + { + var routes = await _db.Queryable().Where(it => it.route_id == bom.route_id).ToListAsync(); + if (routes?.Count > 0) + { + var processIds = routes.Select(x => x.process_id).ToList(); + if (processIds?.Count > 0) + { + var bomOutputs = await _db.Queryable().Where(it => processIds.Contains(it.process_id)).ToListAsync(); + if (bomOutputs?.Count > 0) + { + List subMoTasks = new(); + foreach (var item in bomOutputs) + { + var material = await _db.Queryable().FirstAsync(it => it.id == item.material_id); + PrdMoTask subMoTask = new(); + subMoTask.id = SnowflakeIdHelper.NextId(); + subMoTask.schedule_type = 2; + subMoTask.parent_id = moTask.id; + subMoTask.bom_id = input.bom_id; + subMoTask.mo_task_status = DictConst.ToBeScheduledEncode; + subMoTask.workline_id = input.workline_id; + subMoTask.material_id = item.material_id; + subMoTask.process_task_qty = item.num.ParseToInt() * moTask.scheduled_qty; + subMoTask.estimated_start_date = input.estimated_start_date; + subMoTask.estimated_end_date = input.estimated_end_date; + subMoTask.create_id = _userManager.UserId; + subMoTask.create_time = DateTime.Now; + subMoTasks.Add(subMoTask); + } + //根据生产任务编号生成子任务编号 + if (moTask.mo_task_code.IsNotEmptyOrNull()) + { + for (int i = 1; i <= subMoTasks.Count; i++) + { + string n = i.ToString(); + subMoTasks[i - 1].mo_task_code = $"{moTask.mo_task_code}-{n.PadLeft(2, '0')}"; + } + } + row = await _db.Insertable(subMoTasks).ExecuteCommandAsync(); + } + } + } + } + await _db.Ado.CommitTranAsync(); } - return dbResult!.IsSuccess; + catch (Exception ex) + { + Log.Error("组装包装排产时报错", ex); + await _db.Ado.RollbackTranAsync(); + } + return row > 0; } /// @@ -710,57 +858,75 @@ namespace Tnb.ProductionMgr .SetColumns(it => new PrdMoTask { mo_task_status = status }) .Where(it => input.TaskIds.Contains(it.id)) .ExecuteCommandAsync(); - //插入操作记录日志 - List taskLogEntities = new(); - foreach (var taskId in input.TaskIds) + if (row > 0) { - var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId); - if (taskLog is null) + //更新子任务 + var subMoTaskList = await db.Queryable().Where(it => input.TaskIds.Contains(it.parent_id)).ToListAsync(); + if (subMoTaskList?.Count > 0) { - var taskItem = list?.Find(x => x.id == taskId); - taskLog = new PrdTaskLog(); - taskLog.id = SnowflakeIdHelper.NextId(); - if (taskItem != null) - { - if (taskItem.mo_id.IsNotEmptyOrNull()) - { - taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code; - } - if (taskItem.eqp_id.IsNotEmptyOrNull()) - { - taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code; - } - if (taskItem.mold_id.IsNotEmptyOrNull()) - { - taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code; - } - if (taskItem.material_id.IsNotEmptyOrNull()) - { - var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id); - taskLog.item_code = material?.code; - taskLog.item_standard = material?.material_standard; - } - taskLog.operator_name = _userManager.RealName; - taskLog.status = status; - taskLog.create_id = _userManager.UserId; - taskLog.create_time = DateTime.Now; - taskLog.mo_task_id = taskItem.id; - } - taskLogEntities.Add(taskLog); - } - else - { - var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); - if (records != null && !records.Select(x => x.status).Contains(status)) - { - - taskLog.id = SnowflakeIdHelper.NextId(); - taskLog.status = status; - taskLogEntities.Add(taskLog); - } + var subTaskIds = subMoTaskList.Select(it => it.id).ToList(); + row = await db.Updateable() + .SetColumns(it => new PrdMoTask { mo_task_status = status }) + .Where(it => subTaskIds.Contains(it.id)) + .ExecuteCommandAsync(); } } - row = await db.Insertable(taskLogEntities).ExecuteCommandAsync(); + //插入操作记录日志 + var prdMOTasks = await _db.Queryable().Where(it => input.TaskIds.Contains(it.id) && string.IsNullOrEmpty(it.parent_id)).ToListAsync(); + if (prdMOTasks?.Count > 0) + { + List taskLogEntities = new(); + foreach (var taskId in input.TaskIds) + { + var taskLog = await db.Queryable().FirstAsync(it => it.mo_task_id == taskId); + if (taskLog is null) + { + var taskItem = list?.Find(x => x.id == taskId); + taskLog = new PrdTaskLog(); + taskLog.id = SnowflakeIdHelper.NextId(); + if (taskItem != null) + { + if (taskItem.mo_id.IsNotEmptyOrNull()) + { + taskLog.mo_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mo_id))?.mo_code; + } + if (taskItem.eqp_id.IsNotEmptyOrNull()) + { + taskLog.eqp_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.eqp_id))?.code; + } + if (taskItem.mold_id.IsNotEmptyOrNull()) + { + taskLog.mold_code = (await db.Queryable().FirstAsync(it => it.id == taskItem.mold_id))?.mold_code; + } + if (taskItem.material_id.IsNotEmptyOrNull()) + { + var material = await db.Queryable().FirstAsync(it => it.id == taskItem.material_id); + taskLog.item_code = material?.code; + taskLog.item_standard = material?.material_standard; + } + taskLog.operator_name = _userManager.RealName; + taskLog.status = status; + taskLog.create_id = _userManager.UserId; + taskLog.create_time = DateTime.Now; + taskLog.mo_task_id = taskItem.id; + } + taskLogEntities.Add(taskLog); + } + else + { + var records = await db.Queryable().Where(it => it.mo_task_id == taskLog.mo_task_id).ToListAsync(); + if (records != null && !records.Select(x => x.status).Contains(status)) + { + + taskLog.id = SnowflakeIdHelper.NextId(); + taskLog.status = status; + taskLogEntities.Add(taskLog); + } + } + } + row = await db.Insertable(taskLogEntities).ExecuteCommandAsync(); + + } return (row > 0); }