From ba7d9813b44f5fb63d203a079fd30db70115ef2a Mon Sep 17 00:00:00 2001 From: qianjiawei <1184704771@qq.com> Date: Wed, 29 Nov 2023 11:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=85=A5=E5=BA=93=E9=A2=86?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/EquipSparePartRecord.cs | 24 +++++++ .../Dto/EquipSparePartsQueryOutput.cs | 1 + .../Tnb.EquipMgr/EqpEquipSparePartsService.cs | 66 ++++++++++++++++++- .../GenerateMaintainPlanTimeWorker.cs | 23 ++++++- .../GenerateSpotInspectionPlanTimeWorker.cs | 21 +++++- 5 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartRecord.cs diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartRecord.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartRecord.cs new file mode 100644 index 00000000..4bd1b2b5 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartRecord.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.EquipMgr.Entities +{ + public class EquipSparePartRecordInput + { + public string? equip_id { get; set; } + } + public class EquipSparePartRecordOut + { + public string? id { get; set; } + public string? code { get; set; } + public string? name { get; set; } + public string? type { get; set; } + public string? execuser { get; set; } + public string? execdatetime { get; set; } + public int? num { get; set; } + + } +} diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartsQueryOutput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartsQueryOutput.cs index 33f096ac..37ccbbca 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartsQueryOutput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/EquipSparePartsQueryOutput.cs @@ -8,6 +8,7 @@ namespace Tnb.EquipMgr.Entities.Dto public string? code { get; set; } public string? name { get; set; } public string? specification { get; set; } + public int? num { get; set; } } } \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsService.cs b/EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsService.cs index bcd10817..2360799e 100644 --- a/EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsService.cs +++ b/EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsService.cs @@ -1,11 +1,14 @@ +using System.CodeDom.Compiler; using JNPF.Common.Core.Manager; using JNPF.Common.Filter; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using NPOI.SS.Formula.Functions; using SqlSugar; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; @@ -68,6 +71,9 @@ namespace Tnb.EquipMgr { queryJson = JsonConvert.DeserializeObject>(input.queryJson); } + var eqpSpareParts = await db.Queryable().ToListAsync(); + var InstockDs= await db.Queryable().ToListAsync(); + var RequisitionDs = await db.Queryable().ToListAsync(); SqlSugarPagedList result = await db.Queryable() .LeftJoin((a, b) => a.spare_parts_id == b.id) .LeftJoin((a, b, c) => c.EnCode == Tnb.BasicData.DictConst.SparePartsType && c.DeleteMark == null) @@ -82,10 +88,68 @@ namespace Tnb.EquipMgr type_name = d.FullName, code = b.code, name = b.name, - specification = b.specification + specification = b.specification, + num = 0 }).ToPagedListAsync(input.currentPage, input.pageSize); + foreach (var item in result.list) + { + try + { + var part = eqpSpareParts.Where(p => p.code == item.code).First(); + var Instocknum = InstockDs.Where(p => p.spare_parts_id == part.id).Sum(p => p.quantity); + var Requisitionum = RequisitionDs.Where(p => p.spare_parts_id == part.id).Sum(p => p.quantity); + item.num = Instocknum > Requisitionum ? Instocknum - Requisitionum : 0; + } + catch (Exception) + { + } + } return PageResult.SqlSugarPageResult(result); } + + //获取备品备件历史 + [HttpPost] + public async Task GetEquipSparePartRecord(EquipSparePartRecordInput input) + { + ISqlSugarClient db = _repository.AsSugarClient(); + var partsids = await db.Queryable().Where(p => p.equip_id == input.equip_id).Select(p => p.spare_parts_id).ToListAsync(); + var Instocks = await db.Queryable() + .LeftJoin((a, b) => a.instock_id == b.id) + .LeftJoin((a, b, c) => a.spare_parts_id == c.id) + .LeftJoin((a, b, c, d) => b.instock_id == d.Id) + .Where((a, b, c, d) => partsids.Contains(a.spare_parts_id!)) + .Select((a, b, c, d) => new EquipSparePartRecordOut() + { + id = a.id, + code = c.code, + name = c.name, + type = "入库", + execuser = d.RealName, + execdatetime = b.create_time != null ? b.create_time.ToString() : "", + num = a.quantity + }) + .ToListAsync(); + + var Requisitions = await db.Queryable() + .LeftJoin((a, b) => a.spare_parts_requisition_id == b.id) + .LeftJoin((a, b, c) => a.spare_parts_id == c.id) + .LeftJoin((a, b, c, d) => b.recipient_id == d.Id) + .Where((a, b, c, d) => partsids.Contains(a.spare_parts_id!)) + .Select((a, b, c, d) => new EquipSparePartRecordOut() + { + id = a.id, + code = c.code, + name = c.name, + type = "领用", + execuser = d.RealName, + execdatetime = b.create_time != null ? b.create_time.ToString()!.Substring(0,19) : "", + num = a.quantity + }) + .ToListAsync(); + Instocks.AddRange(Requisitions); + var result = Instocks.OrderByDescending(p => DateTime.Parse(p.execdatetime!)); + return result; + } } } \ No newline at end of file diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs index 192ca171..64fbc34b 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateMaintainPlanTimeWorker.cs @@ -1,5 +1,8 @@ using JNPF.Common.Security; using JNPF.Logging; +using JNPF.Message; +using JNPF.Message.Interfaces.Message; +using JNPF.Message.Service; using SqlSugar; using Tnb.EquipMgr.Entities; @@ -15,7 +18,7 @@ namespace JNPF.TaskScheduler.Listener // { // _repository = repository; // } - + private IMessageService _sendMessageService => App.GetService(); [SpareTime("0 0 0 * * ?", "生成设备保养计划", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)] public async void GenerateSpotInspectionPlan(SpareTimer timer, long count) { @@ -171,6 +174,24 @@ namespace JNPF.TaskScheduler.Listener Console.WriteLine(dbResult.ErrorMessage); Log.Error(dbResult.ErrorMessage); } + else + { + List equipments = await db.Queryable().Where(x => x.life == Tnb.EquipMgr.EquipmentLife.ENABLE).ToListAsync(); + foreach (var item in tobeCreateList) + { + try + { + if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) + continue; + var users = new List() { item.execute_user_id }; + var title = equipments.FirstOrDefault(x => x.id == item.equip_id).code + "设备保养提醒"; + await _sendMessageService.SentMessage(users, title, title); + } + catch (Exception) + { + } + } + } Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } } diff --git a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs index 14889bf3..a473253d 100644 --- a/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs +++ b/taskschedule/Tnb.TaskScheduler/Listener/GenerateSpotInspectionPlanTimeWorker.cs @@ -1,5 +1,6 @@ using JNPF.Common.Security; using JNPF.Logging; +using JNPF.Message.Interfaces.Message; using SqlSugar; using Tnb.EquipMgr.Entities; @@ -15,7 +16,7 @@ namespace JNPF.TaskScheduler.Listener // { // _repository = repository; // } - + private IMessageService _sendMessageService => App.GetService(); [SpareTime("0 0,30 * * * ?", "生成点巡检计划", ExecuteType = SpareTimeExecuteTypes.Serial, StartNow = false)] public async void GenerateSpotInspectionPlan(SpareTimer timer, long count) { @@ -172,6 +173,24 @@ namespace JNPF.TaskScheduler.Listener Console.WriteLine(dbResult.ErrorMessage); Log.Error(dbResult.ErrorMessage); } + else + { + List equipments = await db.Queryable().Where(x => x.life == Tnb.EquipMgr.EquipmentLife.ENABLE).ToListAsync(); + foreach (var item in tobeCreateList) + { + try + { + if (equipments.FirstOrDefault(x => x.id == item.equip_id) == null) + continue; + var users = new List() { item.spot_record_user_id }; + var title = equipments.FirstOrDefault(x => x.id == item.equip_id).code + "设备点巡检提醒"; + await _sendMessageService.SentMessage(users, title, title); + } + catch (Exception) + { + } + } + } Log.Information($"---------------生成{tobeCreateList.Count}个计划---------------"); } }