diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainInfoQueryinput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainInfoQueryinput.cs new file mode 100644 index 00000000..55b6bc50 --- /dev/null +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainInfoQueryinput.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.EquipMgr.Entities.Dto +{ + public class MaintainInfoQueryinput + { + public string? sort { get; set; } + public string? keyword { get; set; } + + public string? status { get; set; } + } +} diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs index be0a99c5..d66bd684 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Dto/MoldMaintainRunUpInput.cs @@ -29,6 +29,9 @@ namespace Tnb.EquipMgr.Entities.Dto /// 保养项Ids /// public List items { get; set; } + + + public string starttime { get; set; } } public class MaintainItemInfo @@ -37,5 +40,7 @@ namespace Tnb.EquipMgr.Entities.Dto public string item_group_id { get; set; } public string item_id { get; set; } + public string result { get; set; } + } } diff --git a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainItemRecord.cs b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainItemRecord.cs index 9444c8e8..4483c96c 100644 --- a/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainItemRecord.cs +++ b/EquipMgr/Tnb.EquipMgr.Entities/Entity/ToolMoldMaintainItemRecord.cs @@ -47,4 +47,6 @@ public partial class ToolMoldMaintainItemRecord : BaseEntity /// public string plan_id { get; set; } + public string result { get; set; } + } diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs index 72038c0d..2fe6f947 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldMaintainRunService.cs @@ -2,9 +2,12 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; +using System.Reactive.Joins; using System.Text; using System.Threading.Tasks; +using Aop.Api.Domain; using Aspose.Cells.Drawing; +using Aspose.Words; using DingTalk.Api.Request; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; @@ -13,7 +16,10 @@ using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SqlSugar; @@ -64,35 +70,120 @@ namespace Tnb.EquipMgr plan_start_time = c.plan_start_time, }) .ToListAsync(); - if (planMoldRelations?.Count > 0) + var moldids = planMoldRelations.Select(x => x.mold_id).ToList(); + var molds = await _db.Queryable().Where(it => moldids.Contains(it.id)).ToListAsync(); + foreach (var planMoldRelation in planMoldRelations) + { - var mids = planMoldRelations.Select(x => x.mold_id).ToList(); - var molds = await _db.Queryable().Where(it => mids.Contains(it.id)).ToListAsync(); - if (molds?.Count > 0) + var mold= molds.Where(p=>p.id== planMoldRelation.mold_id).FirstOrDefault(); + if (mold != null) { - for (int i = 0, cnt = molds.Count; i < cnt; i++) + dynamic info = new ExpandoObject(); + info.mold_id = mold.id; + info.mold_code = mold.mold_code; + info.mold_name = mold.mold_name; + info.mold_status = (await _dictionaryDataService.GetInfo(mold.mold_status!))?.FullName; + info.maintain_qty = mold.maintain_qty; + info.plan_start_time = planMoldRelation.plan_start_time == null ? "" : ((DateTime)planMoldRelation.plan_start_time).ToString("yyyy-MM-dd"); + var moldEqpRelation = await _db.Queryable().FirstAsync(it => it.mold_id == mold.id); + if (moldEqpRelation != null) { - var mold = molds[i]; - dynamic info = new ExpandoObject(); - info.mold_id = mold.id; - info.mold_code = mold.mold_code; - info.mold_name = mold.mold_name; - info.mold_status = (await _dictionaryDataService.GetInfo(mold.mold_status))?.FullName; - info.maintain_qty = mold.maintain_qty; - info.plan_start_time = planMoldRelations[i].plan_start_time; - var moldEqpRelation = await _db.Queryable().FirstAsync(it => it.mold_id == mold.id); - if (moldEqpRelation != null) - { - var eqp = await _db.Queryable().FirstAsync(it => it.id == moldEqpRelation.equipment_id); - info.eqp_code = eqp.code; - info.eqp_name = eqp.name; - } - result.Add(info); + var eqp = await _db.Queryable().FirstAsync(it => it.id == moldEqpRelation.equipment_id); + info.eqp_code = eqp.code; + info.eqp_name = eqp.name; } + result.Add(info); } } return result; } + + [HttpGet] + [AllowAnonymous] + public async Task GetMaintainInfo([FromQuery] MaintainInfoQueryinput input) + { + Dictionary dicstatus = new Dictionary(); + dicstatus.Add("UnMaintain", "待保养"); + dicstatus.Add("Completed", "已完成"); + List result = new(); + var plans = await _db.Queryable().ToListAsync(); + var ToolMolds = await _db.Queryable().ToListAsync(); + var ToolMoldsEquipments = await _db.Queryable().ToListAsync(); + var EqpEquipments = await _db.Queryable().ToListAsync(); + var dic = await _db.Queryable().Where(p => p.DictionaryTypeId == "26149299883285").ToListAsync(); + var users = await _db.Queryable().ToListAsync(); + var records = _db.Queryable().ToList(); + var runrecords = _db.Queryable().ToList(); + foreach (var plan in plans) + { + var planMoldRelations = await _db.Queryable() + .LeftJoin((a, b) => a.maintain_plan_id == b.id) + .LeftJoin((a, b, c) => b.plan_code == c.plan_code) + .Where(a => a.maintain_plan_id == plan.id) + .Select((a, b, c) => new + { + mold_id = a.mold_id, + plan_start_time = c.plan_start_time, + }).ToListAsync(); + if (planMoldRelations?.Count > 0) + { + var mids = planMoldRelations.Select(x => x.mold_id).ToList(); + var molds = ToolMolds.Where(it => mids.Contains(it.id)) + .WhereIF(!string.IsNullOrEmpty(input.keyword), p => p.mold_code!.Contains(input.keyword!) || p.mold_name!.Contains(input.keyword!)) + .ToList(); + if (molds?.Count > 0) + { + for (int i = 0, cnt = molds.Count; i < cnt; i++) + { + var mold = molds[i]; + if (!string.IsNullOrEmpty(input.status)) + { + var moldstatus = records.Where(p => p.mold_id == mold.id && p.plan_id == plan.id).Any() ? "已完成" : "待保养"; + if (input.status != moldstatus) + continue; + } + dynamic info = new ExpandoObject(); + info.mold_id = mold.id; + info.mold_code = mold.mold_code; + info.mold_name = mold.mold_name; + info.mold_status = dic.Where(p => p.Id == mold.mold_status).Any() ? dic.Where(p => p.Id == mold.mold_status).First().FullName : ""; + info.maintain_qty = mold.maintain_qty; + info.plan_start_time = plan.plan_start_date == null ? "" : ((DateTime)plan.plan_start_date!).ToString("yyyy-MM-dd"); + info.createtime = plan.create_time == null ? "" : ((DateTime)plan.create_time).ToString("yyyy-MM-dd"); + info.status = records.Where(p=>p.mold_id== mold.id&&p.plan_id== plan.id).Any()? "已完成" : "待保养";//plan.status == "UnMaintain" ? "待保养" : "已完成"; + info.createuser = string.IsNullOrEmpty(plan.create_id) ? "" : users.Where(p => p.Id == plan.create_id).First().RealName; + info.plan_id = plan.id; + info.starttime = ""; + if (runrecords.Where(p => p.mold_code == mold.mold_code && p.plan_code == plan.plan_code).Any()) + { + var run = runrecords.Where(p => p.mold_code == mold.mold_code && p.plan_code == plan.plan_code).First(); + info.starttime = run.plan_start_time!=null? ((DateTime)run.plan_start_time).ToString("yyyy-MM-dd") : ""; + } + var moldEqpRelation = ToolMoldsEquipments.Where(it => it.mold_id == mold.id).FirstOrDefault(); + if (moldEqpRelation != null) + { + var eqp = EqpEquipments.Where(it => it.id == moldEqpRelation.equipment_id).FirstOrDefault(); + if (eqp != null) + { + info.eqp_code = eqp.code; + info.eqp_name = eqp.name; + } + } + result.Add(info); + } + } + } + } + if (!string.IsNullOrEmpty(input.sort)) + { + if (input.sort == "createtime") + result = result.OrderByDescending(p => p.createtime).ToList(); + if (input.sort == "plan_start_time") + result = result.OrderByDescending(p => p.plan_start_time).ToList(); ; + } + return result; + } + /// /// 根据计划Id、模具ID获取,保养组及项目信息 /// @@ -175,6 +266,14 @@ namespace Tnb.EquipMgr public async Task MaintainStart(MoldMaintainRunUpInput input) { if (input == null) throw new ArgumentNullException("input"); + var flag= _db.Queryable() + .LeftJoin((a, b) => a.plan_code == b.plan_code) + .LeftJoin((a,b,c)=>a.mold_code==c.mold_code) + .Where((a,b,c)=>b.id== input.plan_id&&c.id==input.mold_id).Any(); + if (flag) + { + return; + } try { await _db.Ado.BeginTranAsync(); @@ -200,7 +299,7 @@ namespace Tnb.EquipMgr record.designer_time = DateTime.Now; record.mold_code = mold.mold_code; record.mold_name = mold.mold_name; - record.plan_start_time = DateTime.Now; + record.plan_start_time = string.IsNullOrEmpty(input.starttime) ? DateTime.Now :DateTime.Parse(input.starttime); var row = await _db.Insertable(record).ExecuteCommandAsync(); if (row < 1) throw Oops.Oh(ErrorCode.COM1001); @@ -264,6 +363,37 @@ namespace Tnb.EquipMgr } + /// + /// 模具保养完成 + /// + /// + [HttpPost] + public async Task FinishMaintain(MoldMaintainRunUpInput input) + { + if (input == null) throw new ArgumentNullException("input"); + if (input.items == null || input.items.Count == 0) throw new ArgumentException($"parameter {nameof(input.items)} not be null or empty"); + List records = new(); + foreach (var item in input.items) + { + ToolMoldMaintainItemRecord record = new(); + record.plan_id = input.plan_id; + record.mold_id = input.mold_id; + record.item_group_id = item.item_group_id; + record.item_id = item.item_id; + record.status = 1; + record.result = item.result; + records.Add(record); + } + await _db.Insertable(records).ExecuteCommandAsync(); + await _db.Updateable().SetColumns(it => new ToolMolds { mold_status = MoldUseStatus.MOLD_USE_STATUS_ZK_ID }).Where(it => it.id == input.mold_id).ExecuteCommandAsync(); + var count = await _db.Queryable().Where(p => p.maintain_plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync(); + var finish = await _db.Queryable().Where(p => p.plan_id == input.plan_id).Select(p => p.mold_id).Distinct().CountAsync(); + if (count == finish) + await _db.Updateable().SetColumns(it => new ToolMoldMaintainPlan { status = MoldPlanMaintainStatus.MOLDPLAN_MAINTAIN_STATUS_COMPLETED_CODE }).Where(it => it.id == input.plan_id).ExecuteCommandAsync(); + + } + + [HttpPost] public async Task MaintainItemFinish(MoldMaintainRunUpInput input) { if (input == null) throw new ArgumentNullException("input"); diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/AndonRecordInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/AndonRecordInput.cs new file mode 100644 index 00000000..c9100230 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/AndonRecordInput.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class AndonRecordInput + { + /// + /// 关联工单 + /// + public string? mo_id { get; set; } + + /// + /// 故障 + /// + public string? breakdown { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GanntSaveInput.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GanntSaveInput.cs new file mode 100644 index 00000000..393c24fd --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Dto/PrdManage/GanntSaveInput.cs @@ -0,0 +1,22 @@ +namespace Tnb.ProductionMgr.Entities.Dto.PrdManage +{ + public class GanntSaveInput + { + public string id { get; set; } + public string row_id { get; set; } + public GanntTime time { get; set; } + } + + public class GanntTime + { + public DateTime? start { get; set; } + public DateTime? end { get; set; } + } + + public class GanntTimeTips + { + public string mo_task_code { get; set; } + public DateTime? start_time { get; set; } + public DateTime? end_time { get; set; } + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonBreakDown.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonBreakDown.cs new file mode 100644 index 00000000..38142fc2 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonBreakDown.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities +{ + [SugarTable("andon_breakdown")] + public partial class AndonBreakDown : BaseEntity + { + public AndonBreakDown() + { + id = SnowflakeIdHelper.NextId(); + } + public string? name { get; set; } + public string? code { get; set; } + public string? description { get; set; } + + public string? type_id { get; set; } + public string? remark { get; set; } + public string? create_id { get; set; } + public DateTime? create_time { get; set; } + public string? modify_id { get; set; } + public DateTime? modify_time { get; set; } + + } +} \ No newline at end of file diff --git a/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonRecords.cs b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonRecords.cs new file mode 100644 index 00000000..68b8deb0 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Entities/Entity/AndonRecords.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.ProductionMgr.Entities +{ + [SugarTable("andon_records")] + public partial class AndonRecords : BaseEntity + { + public AndonRecords() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 关联工单 + /// + public string? mo_id { get; set; } + + /// + /// 故障类别 + /// + public string? breakdown_type { get; set; } + + /// + /// 故障 + /// + public string? breakdown { get; set; } + + public string? create_id { get; set; } + public DateTime? create_time { get; set; } + public string? modify_id { get; set; } + public DateTime? modify_time { get; set; } + public string? remark { get; set; } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr.Interfaces/IAndonService.cs b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IAndonService.cs new file mode 100644 index 00000000..31e453dc --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr.Interfaces/IAndonService.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tnb.ProductionMgr.Entities.Dto.PrdManage; + +namespace Tnb.ProductionMgr.Interfaces +{ + public interface IAndonService + { + Task GetPrdTask(string stationId); + Task SaveData(AndonRecordInput AndonRecordInput); + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr/AndonService.cs b/ProductionMgr/Tnb.ProductionMgr/AndonService.cs new file mode 100644 index 00000000..24c38703 --- /dev/null +++ b/ProductionMgr/Tnb.ProductionMgr/AndonService.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Numerics; +using System.Reactive.Joins; +using System.Text; +using System.Threading.Tasks; +using Aop.Api.Domain; +using Aspose.Cells.Drawing; +using JNPF.Common.Core.Manager; +using JNPF.DependencyInjection; +using JNPF.DynamicApiController; +using JNPF.Message.Service; +using JNPF.Systems.Interfaces.System; +using JNPF.TaskScheduler; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using Tnb.BasicData.Entities; +using Tnb.EquipMgr.Interfaces; +using Tnb.ProductionMgr.Entities; +using Tnb.ProductionMgr.Entities.Dto.PrdManage; +using Tnb.ProductionMgr.Entities.Entity; +using Tnb.ProductionMgr.Interfaces; + +namespace Tnb.ProductionMgr +{ + [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)] + [Route("api/[area]/[controller]/[action]")] + public class AndonService : IAndonService, IDynamicApiController, ITransient + { + private readonly ISqlSugarClient _db; + private readonly IUserManager _userManager; + public AndonService(ISqlSugarRepository repository,IUserManager userManager) + { + _userManager = userManager; + _db = repository.AsSugarClient(); + } + [HttpGet] + public async Task GetPrdTask(string stationId) + { + Dictionary dic = new Dictionary(); + dic.Add("ToBeStarted", "待开工"); + dic.Add("InProgress", "进行中"); + dic.Add("Closed", "关闭"); + dic.Add("Complated", "完工"); + dic.Add("ToBeScheduled", "待下发"); + dic.Add("Pause", "暂停"); + dic.Add("Exception", "异常"); + dic.Add("Revoke", "撤销"); + List result = new(); + var List = await _db.Queryable() + .WhereIF(!string.IsNullOrEmpty(stationId), p => p.workstation_id == stationId) + .ToListAsync(); + var materials = await _db.Queryable().ToListAsync(); + foreach (var data in List) + { + dynamic info = new ExpandoObject(); + info.id = data.id; + info.material_id = materials.Where(p => p.id == data.material_id).Any() ? materials.Where(p => p.id == data.material_id).First().name : ""; + info.material_id_id = data.material_id; + info.status = dic.Where(p => p.Key == data.mo_task_status).Any() ? dic.Where(p => p.Key == data.mo_task_status).First().Value : ""; + info.mo_code = data.mo_task_code; + info.mo_type = data.schedule_type == 1 ? "注塑工单" : "组装工单"; + info.plan_gty = data.plan_qty; + info.plan_start_date = data.estimated_start_date == null ? "" : ((DateTime)data.estimated_start_date!).ToString("yyyy-MM-dd"); + info.plan_end_date = data.estimated_end_date == null ? "" : ((DateTime)data.estimated_end_date!).ToString("yyyy-MM-dd"); + result.Add(info); + } + result.OrderByDescending(p => p.plan_start_date); + return result; + } + [HttpPost] + public async Task SaveData(AndonRecordInput AndonRecordInput) + { + var list = _db.Queryable().ToList(); + AndonRecords andonRecord = new AndonRecords(); + andonRecord.mo_id = AndonRecordInput.mo_id; + andonRecord.breakdown_type = list.Where(p => p.id == AndonRecordInput.breakdown).Any() ? list.Where(p => p.id == AndonRecordInput.breakdown).First().type_id : ""; + andonRecord.breakdown = AndonRecordInput.breakdown; + andonRecord.create_time = DateTime.Now; + andonRecord.create_id = _userManager.UserId; + await _db.Insertable(andonRecord).ExecuteCommandAsync(); + } + } +} diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs index 10b21f06..183953d8 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdFeedingService.cs @@ -235,7 +235,7 @@ namespace Tnb.ProductionMgr throw new Exception("该物料不是生产bom投入物料,不能签收"); var detail = await db.Queryable() - .Where(x => x.carry_id == carry.id && x.is_all_feeding == 0).FirstAsync(); + .Where(x => x.member_carry_code == input.carry_code && x.is_all_feeding == 0).FirstAsync(); decimal num = Convert.ToDecimal(item["num"]); list.Add(new PrdFeedingD { @@ -283,8 +283,8 @@ namespace Tnb.ProductionMgr } - // await db.Insertable(prdFeedingH).ExecuteCommandAsync(); - // await db.Insertable(list).ExecuteCommandAsync(); + await db.Insertable(prdFeedingH).ExecuteCommandAsync(); + await db.Insertable(list).ExecuteCommandAsync(); }); diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs index 64429b5e..2e5d2d2f 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdInstockService.cs @@ -27,6 +27,10 @@ using Tnb.EquipMgr.Entities; using Tnb.ProductionMgr.Entities.Dto.PrdManage; using JNPF.Common.Filter; using JNPF.Common.Security; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Interfaces.Permission; +using SQLitePCL; +using SqlSugar.Extensions; namespace Tnb.ProductionMgr { @@ -40,15 +44,18 @@ namespace Tnb.ProductionMgr { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; + private readonly IOrganizeService _organizeService; private const string ModuleId = "25572529329173"; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); public PrdInstockService( ISqlSugarRepository repository, + IOrganizeService organizeService, IUserManager userManager ) { _repository = repository; + _organizeService = organizeService; _userManager = userManager; OverideFuncs.GetListAsync = GetList; } @@ -100,8 +107,18 @@ namespace Tnb.ProductionMgr PrdInstockH prdInstockH = null; List prdInstockDs = new List() { }; DbResult result2 = new DbResult(); + + if (string.IsNullOrEmpty(input.station_id)) + { + throw Oops.Bah("请先选择工位"); + } + DbResult result = await db.Ado.UseTranAsync(async () => { + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorklineCode); + OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorkshopCode); + + prdInstockH = new PrdInstockH() { bill_type = input.bill_type, @@ -111,8 +128,8 @@ namespace Tnb.ProductionMgr carry_code = input.carry_code, is_check = input.is_check, station_id = input.station_id, - workline_id = input.workline_id, - workshop_id = input.workshop_id, + workline_id = workline?.Id ?? "", + workshop_id = workshop?.Id ?? "", org_id = _userManager.GetUserInfo().Result.organizeId, warehouse_id = location?.wh_id, status = 0, @@ -127,8 +144,10 @@ namespace Tnb.ProductionMgr material_id = item.ContainsKey("material_id") ? item["material_id"] : "", material_code = item.ContainsKey("material_code") ? item["material_code"] : "", unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "", - code_batch = item.ContainsKey("batch") ? item["batch"] : "", - barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "", + // code_batch = item.ContainsKey("batch") ? item["batch"] : "", + // barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "", + barcode = item.ContainsKey("barcode") ? item["barcode"] : "", + code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "", quantity = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"), }); } @@ -166,7 +185,7 @@ namespace Tnb.ProductionMgr material_id = item.ContainsKey("material_id") ? item["material_id"] : "", material_code = item.ContainsKey("material_code") ? item["material_code"] : "", unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "", - code_batch = item.ContainsKey("batch") ? item["batch"] : "", + code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "", pr_qty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"), }); @@ -175,8 +194,10 @@ namespace Tnb.ProductionMgr material_id = item.ContainsKey("material_id") ? item["material_id"] : "", material_code = item.ContainsKey("material_code") ? item["material_code"] : "", unit_id = item.ContainsKey("unit_id") ? item["unit_id"] : "", - code_batch = item.ContainsKey("batch") ? item["batch"] : "", - barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "", + // code_batch = item.ContainsKey("batch") ? item["batch"] : "", + // barcode = item.ContainsKey("batch") ? item["batch"]+"0001" : "", + barcode = item.ContainsKey("barcode") ? item["barcode"] : "", + code_batch = item.ContainsKey("barcode") ? item["barcode"]+"0001" : "", codeqty = Convert.ToInt32(item.ContainsKey("quantity") ? item["quantity"] : "0"), }); } @@ -188,7 +209,7 @@ namespace Tnb.ProductionMgr var sendResult = HttpUtils.RequestPost(domain + WebApiConst.MES_CREATE_INSTOCK,JsonConvert.SerializeObject(mesCreateInstockInput),header); Log.Information(sendResult); AuthResponse authResponse = JsonConvert.DeserializeObject(sendResult); - if (authResponse.code != 200) + if (authResponse.code != 200 || !authResponse.data.ObjToBool()) { throw Oops.Bah(authResponse.msg); } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdKittingOutService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdKittingOutService.cs index 5674bd65..e94f3915 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdKittingOutService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdKittingOutService.cs @@ -7,6 +7,8 @@ using JNPF.Extras.CollectiveOAuth.Models; using JNPF.Extras.CollectiveOAuth.Utils; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Interfaces.Permission; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; @@ -37,15 +39,21 @@ namespace Tnb.ProductionMgr private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; private readonly IUserManager _userManager; + private readonly IOrganizeService _organizeService; private readonly IBillRullService _billRullService; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - public PrdKittingOutService(ISqlSugarRepository repository, IRunService runService, IBillRullService billRullService,IUserManager userManager,IVisualDevService visualDevService) + public PrdKittingOutService(ISqlSugarRepository repository, IRunService runService, + IBillRullService billRullService, + IUserManager userManager, + IOrganizeService organizeService, + IVisualDevService visualDevService) { _runService = runService; _visualDevService = visualDevService; _repository = repository; _userManager = userManager; + _organizeService = organizeService; _billRullService = billRullService; // OverideFuncs.CreateAsync = Create; } @@ -161,7 +169,9 @@ namespace Tnb.ProductionMgr try { var db = _repository.AsSugarClient(); - + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(kittingOutInput.workstation_id, DictConst.RegionCategoryWorklineCode); + kittingOutInput.workline_id = workline?.Id ?? ""; + List input = new List(); input.Add(new MESKittingOutStkInput() { diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs index b956c738..ed200e3d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMaterialReceiptService.cs @@ -8,6 +8,8 @@ using JNPF.Extras.CollectiveOAuth.Models; using JNPF.Extras.CollectiveOAuth.Utils; using JNPF.FriendlyException; using JNPF.Logging; +using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Interfaces.Permission; using JNPF.Systems.Interfaces.System; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; @@ -38,17 +40,20 @@ namespace Tnb.ProductionMgr { private readonly ISqlSugarRepository _repository; private readonly IUserManager _userManager; + private readonly IOrganizeService _organizeService; private readonly IBillRullService _billRullService; public PrdMaterialReceiptService( ISqlSugarRepository repository, IBillRullService billRullService, + IOrganizeService organizeService, IUserManager userManager ) { _repository = repository; _userManager = userManager; + _organizeService = organizeService; _billRullService = billRullService; } @@ -148,6 +153,9 @@ namespace Tnb.ProductionMgr .ToListAsync(); string code = await _billRullService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.MATERIAL_RECEIPT_CODE); + OrganizeEntity workline = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorklineCode); + OrganizeEntity workshop = await _organizeService.GetAnyParentByWorkstationId(input.station_id, DictConst.RegionCategoryWorkshopCode); + prdMaterialReceiptH = new PrdMaterialReceiptH() { code = code, @@ -155,9 +163,9 @@ namespace Tnb.ProductionMgr mo_task_id = input.mo_task_id, process_id = input.process_id, equip_id = input.equip_id, - workshop_id = input.workshop_id, + workshop_id = workshop?.Id ?? "", carry_id = input.carry_id, - workline_id = input.workline_id, + workline_id = workline?.Id ?? "", carry_code = input.carry_code, remark = input.remark, mbom_process_id = input.mbom_process_id, @@ -186,9 +194,9 @@ namespace Tnb.ProductionMgr member_carry_id = item["member_carry_id"]?.ToString(), member_carry_code = item["member_carry_code"]?.ToString(), feeding_num = 0, - supplier_id = item["supplier_id"]?.ToString(), - instock_time = (DateTime)item["instock_time"], - check_conclusion = item["check_conclusion"]?.ToString() + supplier_id = item.ContainsKey("supplier_id") ? item["supplier_id"]?.ToString() : "", + instock_time = item.ContainsKey("instock_time") ? (DateTime)item["instock_time"] : DateTime.Now, + check_conclusion = item.ContainsKey("check_conclusion") ? item["check_conclusion"]?.ToString() : "", }); } } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs index 4f4b9344..9c7ca149 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoService.cs @@ -888,8 +888,8 @@ namespace Tnb.ProductionMgr .Where((a, b) => a.barcode == barcode).SumAsync((a, b) => b.num); output.list[0].material_name = basMaterial.name; output.list[0].material_standard = basMaterial.material_standard; - output.list[0].supplier_name = basSupplier.supplier_name; - output.list[0].unit_name = unit.FullName; + output.list[0].supplier_name = basSupplier?.supplier_name ?? ""; + output.list[0].unit_name = unit?.FullName ?? ""; return output.list[0]; } @@ -913,11 +913,11 @@ namespace Tnb.ProductionMgr .LeftJoin((a, b, c) => b.feeding_id == c.id) .Where(a => a.barcode == barcode) .Select((a, b, c) => c.mo_task_id).ToListAsync(); - - return await _db.Queryable() + + var result = await _db.Queryable() .LeftJoin((a, b) => a.mo_id == b.id) - .LeftJoin((a,b,c)=>a.material_id==c.id) - .Where((a,b,c)=>ids.Contains(a.id)) + .LeftJoin((a, b, c) => a.material_id == c.id) + .Where((a, b, c) => ids.Contains(a.id)) .Select((a, b, c) => new PrdMoReverseFromFeedingOutput { mo_task_id = a.id, @@ -927,22 +927,28 @@ namespace Tnb.ProductionMgr material_name = c.name, material_standard = c.material_standard, children = SqlFunc.Subqueryable() - .LeftJoin((x,y)=>x.feeding_id==y.id) - .LeftJoin((x,y,z)=>y.create_id==z.Id) - .LeftJoin((x,y,z,org)=>y.station_id==org.Id) - .LeftJoin((x,y,z,org,process)=>y.process_id==process.id) - .LeftJoin((x,y,z,org,process,mp)=>x.material_receipt_detail_id==mp.id) - .Where((x,y,z)=>y.mo_task_id==a.id).ToList((x,y,z,org,process,mp)=>new PrdMoReverseFromFeedingDetailOutput - { - feeding_detail_id = x.id, - feeding_time = y.create_time==null ? "" : y.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), - num = x.num, - check_conclusion = mp.check_conclusion, - feeding_name = z.RealName, - station_name = org.FullName, - process_name = process.process_name - }), + .LeftJoin((x, y) => x.feeding_id == y.id) + .LeftJoin((x, y, z) => y.create_id == z.Id) + .LeftJoin((x, y, z, org) => y.station_id == org.Id) + .LeftJoin((x, y, z, org, process) => y.process_id == process.id) + .LeftJoin((x, y, z, org, process, mp) => + x.material_receipt_detail_id == mp.id) + .Where((x, y, z) => y.mo_task_id == a.id).ToList((x, y, z, org, process, mp) => + new PrdMoReverseFromFeedingDetailOutput + { + feeding_detail_id = x.id, + feeding_time = y.create_time == null + ? "" + : y.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"), + num = x.num, + check_conclusion = mp.check_conclusion, + feeding_name = z.RealName, + station_name = org.FullName, + process_name = process.process_name + }), }).ToListAsync(); + return result; + // return PageResult.SqlSugarPageResult(result); } /// diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs index dca6214a..87d405c5 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdMoTaskService.cs @@ -2221,5 +2221,122 @@ namespace Tnb.ProductionMgr } + /// + /// 获取组装包装生产排产甘特图信息 + /// + /// + [HttpPost] + public async Task GetGanntInfo2() + { + var db = _repository.AsSugarClient(); + Dictionary result = new Dictionary(); + var listRows = await db.Queryable() + .Where(x => x.DeleteMark==null && (x.Category == DictConst.RegionCategoryWorklineCode || x.Category == DictConst.RegionCategoryWorkshopCode)) + .OrderByDescending(x=>x.Category) + .Select(x => new + { + id = x.Id, + expanded = true, + label = x.FullName, + parentId = x.Category==DictConst.RegionCategoryWorklineCode ? x.ParentId : "" + }).ToListAsync(); + + DateTime startTime = Convert.ToDateTime(new DateTime(DateTime.Now.Year,DateTime.Now.Month,1).AddDays(-15).ToString("yyyy-MM-dd 00:00:00")); + DateTime endTime = Convert.ToDateTime(new DateTime(DateTime.Now.Year,DateTime.Now.Month,1).AddMonths(1).AddDays(-1).AddDays(15).ToString("yyyy-MM-dd 23:59:59")); + var charItems = await db.Queryable() + .LeftJoin((a, b) => a.material_id == b.id) + .LeftJoin((a,b,c)=>c.DictionaryTypeId==DictConst.PrdTaskStatusTypeId && a.mo_task_status==c.EnCode) + .Where((a, b) => a.mo_task_status == DictConst.ToBeStartedEnCode || a.mo_task_status == DictConst.ToBeScheduledEncode || a.mo_task_status == DictConst.MoStatusPauseCode || a.mo_task_status == DictConst.InProgressEnCode) + .Where((a,b)=>a.schedule_type==2 && string.IsNullOrEmpty(a.parent_id)) + .Where((a,b)=>a.estimated_start_date!=null && a.estimated_end_date!=null) + .Where((a,b)=>a.estimated_start_date>=startTime && a.estimated_end_date<=endTime) + .Select((a, b,c) => new + { + id = a.id, + label = b.name, + material_name = b.name, + reported_work_qty = a.reported_work_qty==null ? 0 : a.reported_work_qty, + scheduled_qty = a.scheduled_qty, + mo_task_status = c.FullName, + // label = b.name +" " +(a.reported_work_qty==null?0:a.reported_work_qty)+"/"+a.scheduled_qty + " " +c.FullName, + rowId = a.workline_id, + time = new GanntTime + { + start = a.estimated_start_date, + end = a.estimated_end_date + }, + //linkedWith = SqlFunc.Subqueryable().Where(x=>a.schedule_type==2 && string.IsNullOrEmpty(a.parent_id) && a.workline_id==x.workline_id && (x.mo_task_status==DictConst.ToBeStartedEnCode || x.mo_task_status==DictConst.MoStatusPauseCode || x.mo_task_status==DictConst.ToBeScheduledEncode)).ToList(x=>x.id), + tips = new GanntTimeTips + { + // material_code = b.code, + // material_name = b.name, + mo_task_code = a.mo_task_code, + // start_time = a.estimated_start_date==null ? "" : a.estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm:ss"), + // end_time = a.estimated_end_date==null ? "" : a.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm:ss"), + start_time = a.estimated_start_date, + end_time = a.estimated_end_date, + } + }) + .ToListAsync(); + // DateTime min = (DateTime)charItems.Min(x => x.time.start); + TimeSpan ts1 = new TimeSpan(Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).Ticks); + TimeSpan ts2 = new TimeSpan(Convert.ToDateTime(startTime.ToString("yyyy-MM-dd")).Ticks); + TimeSpan ts3 = ts1.Subtract(ts2).Duration(); + + + result.Add("listRows",listRows); + result.Add("charItems",charItems); + result.Add("startTime",startTime); + result.Add("endTime",endTime); + result.Add("totalDays",ts3.TotalDays); + return result; + } + + /// + /// 保存组装包装生产排产甘特图信息 + /// + /// + [HttpPost] + public async Task SaveData2(List input) + { + var db = _repository.AsSugarClient(); + DbResult result = await db.Ado.UseTranAsync(async () => + { + foreach (var item in input) + { + + if(await db.Queryable().Where(x=>x.Id==item.row_id && x.Category==DictConst.RegionCategoryWorkshopCode).AnyAsync()) + throw Oops.Bah("不能排在车间上"); + var prdMoTask = await db.Queryable().SingleAsync(x => x.id == item.id); + if (prdMoTask.workline_id != item.row_id) + { + await db.Updateable() + .SetColumns(x=>x.workline_id == item.row_id) + .Where(x=>x.id==item.id).ExecuteCommandAsync(); + } + + if (prdMoTask.estimated_start_date.Value.ToString("yyyy-MM-dd HH:mm") != item.time.start.Value.ToString("yyyy-MM-dd HH:mm")) + { + await db.Updateable() + .SetColumns(x=>x.estimated_start_date==item.time.start) + .Where(x=>x.id==item.id).ExecuteCommandAsync(); + } + + if (prdMoTask.estimated_end_date.Value.ToString("yyyy-MM-dd HH:mm")!=item.time.end.Value.ToString("yyyy-MM-dd HH:mm")) + { + await db.Updateable() + .SetColumns(x=>x.estimated_end_date==item.time.end) + .Where(x=>x.id==item.id).ExecuteCommandAsync(); + } + } + }); + if(!result.IsSuccess) throw Oops.Bah(result.ErrorMessage); + + return result.IsSuccess ? "排产成功" : result.ErrorMessage; + } + } + + + } diff --git a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs index 91be4166..fef2d924 100644 --- a/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs +++ b/ProductionMgr/Tnb.ProductionMgr/PrdOutstockService.cs @@ -65,7 +65,8 @@ namespace Tnb.ProductionMgr BasLocation location = await db.Queryable().SingleAsync(x => x.id == locationId); input.outstock.bill_type = visualDevModelDataCrInput.data.ContainsKey("bill_type") ? visualDevModelDataCrInput.data["bill_type"].ToString() : ""; - input.outstock.bill_date = visualDevModelDataCrInput.data.ContainsKey("bill_date") ? Convert.ToDateTime(visualDevModelDataCrInput.data["bill_date"].ToString()) : DateTime.Now; + // input.outstock.bill_date = visualDevModelDataCrInput.data.ContainsKey("bill_date") ? Convert.ToDateTime(visualDevModelDataCrInput.data["bill_date"].ToString()) : DateTime.Now; + input.outstock.bill_date = DateTime.Now; input.outstock.org_id = _userManager.GetUserInfo().Result.organizeId; input.outstock.warehouse_id = visualDevModelDataCrInput.data.ContainsKey("warehouse_id") ? visualDevModelDataCrInput.data["warehouse_id"].ToString() : ""; input.outstock.create_id = _userManager.UserId; diff --git a/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSampleCode.cs b/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSampleCode.cs new file mode 100644 index 00000000..40291e15 --- /dev/null +++ b/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSampleCode.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.QcMgr.Entities +{ + // + /// 抽样检验程序样本量字码表 + /// + [SugarTable("qc_aql_sample_code")] + public partial class QcAqlSampleCode : BaseEntity + { + public QcAqlSampleCode() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 检验水平 + /// + public string? checklevel { get; set; } + + /// + /// 最小值 + /// + public int? min { get; set; } + + /// + /// 最大值 + /// + public int? max { get; set; } + + /// + /// 字码 + /// + public string? code { get; set; } + + } +} diff --git a/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSamplePlan.cs b/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSamplePlan.cs new file mode 100644 index 00000000..a17387ae --- /dev/null +++ b/QcMgr/Tnb.QcMgr.Entities/Entity/QcAqlSamplePlan.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.QcMgr.Entities +{ + /// + /// aql抽样方案 + /// + [SugarTable("qc_aql_sample_plan")] + public partial class QcAqlSamplePlan : BaseEntity + { + public QcAqlSamplePlan() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 检验类型 + /// + public string? checktype { get; set; } + + /// + /// 字码 + /// + public string? code { get; set; } + + /// + /// 样本量 + /// + public int? samplesize { get; set; } + + /// + /// aql值 + /// + public decimal? aqlvalue { get; set; } + + /// + /// 接受 + /// + public int? ac { get; set; } + + /// + /// 拒收 + /// + public int? re { get; set; } + + } +} diff --git a/QcMgr/Tnb.QcMgr/QcSpcService.cs b/QcMgr/Tnb.QcMgr/QcSpcService.cs index 36753845..70a74eb1 100644 --- a/QcMgr/Tnb.QcMgr/QcSpcService.cs +++ b/QcMgr/Tnb.QcMgr/QcSpcService.cs @@ -10,6 +10,7 @@ using JNPF.Common.Enums; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Spire.Xls.Core; using SqlSugar; @@ -377,5 +378,8 @@ namespace Tnb.QcMgr } return floats.Average(); } + + + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs b/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs index 5149ce15..8484d02f 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs @@ -20,6 +20,10 @@ using JNPF.VisualDev.Entitys.Dto.VisualDev; using NPOI.SS.Formula.Functions; using Spire.Pdf.Lists; using Aop.Api.Domain; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using NPOI.HSSF.UserModel; +using Microsoft.AspNetCore.Mvc; namespace Tnb.WarehouseMgr { @@ -55,6 +59,10 @@ namespace Tnb.WarehouseMgr //遍历字典,找出需要查询数据库拿的相关字段 foreach (var d in dics) { + if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null) + { + continue; + } var LCode = d["location_code"]?.ToString() ?? string.Empty; if (LCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位编号不可为空", 500); var isType = d["is_type"]?.ToString() ?? string.Empty; @@ -79,36 +87,38 @@ namespace Tnb.WarehouseMgr locs.Add(loc); } - var carryStdDic = await _db.Queryable().Where(it => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id); - var whDic = await _db.Queryable().Where(it => whCodes.Contains(it.whcode)).ToDictionaryAsync(x => x.whcode, x => x.id); - var rgDic = await _db.Queryable().Where(it => rgCodes.Contains(it.region_code)).ToDictionaryAsync(x => x.region_code, x => x.id); - - locs.ForEach(x => + var carryStdDic = await _db.Queryable().Where(it => cStdCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id); + var whDic = await _db.Queryable().Where(it => whCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.whcode)).ToDictionaryAsync(x => x.whcode, x => x.id); + var rgDic = await _db.Queryable().Where(it => rgCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.region_code)).ToDictionaryAsync(x => x.region_code, x => x.id); + var orgId = _userManager.User.OrganizeId; + var userId = _userManager.UserId; + foreach (var l in locs) { - if (!carryStdDic.ContainsKey(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的载具规格有误", 500); - if (!whDic.ContainsKey(x.wh_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的仓库有误", 500); - if (!rgDic.ContainsKey(x.region_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的区域名称有误", 500); - x.id = SnowflakeIdHelper.NextId(); - x.org_id = _userManager.User.OrganizeId; - x.location_name = x.location_code; - x.is_lock = 0; - x.carrystd_id = carryStdDic[x.carrystd_id]?.ToString()!; - x.wh_id = whDic[x.wh_id]?.ToString()!; - x.region_id = rgDic[x.region_id]?.ToString(); - x.create_id = _userManager.UserId; - x.modify_id = null; - x.modify_time = null; - x.is_mix = 1; - x.is_use = "0"; - }); + if (!carryStdDic.ContainsKey(l.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的载具规格有误", 500); + if (!whDic.ContainsKey(l.wh_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的仓库有误", 500); + if (!rgDic.ContainsKey(l.region_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的区域名称有误", 500); + l.id = SnowflakeIdHelper.NextId(); + l.org_id = orgId; + l.location_name = l.location_code; + l.is_lock = 0; + l.carrystd_id = carryStdDic[l.carrystd_id]?.ToString()!; + l.wh_id = whDic[l.wh_id]?.ToString()!; + l.region_id = rgDic[l.region_id]?.ToString(); + l.create_id = userId; + l.modify_id = null; + l.modify_time = null; + l.is_mix = 1; + l.is_use = "0"; + } + if (locs.Count > 1000) { - await _db.Fastest().BulkCopyAsync(locs); + row = await _db.Fastest().BulkCopyAsync(locs); } else if (locs.Count > 400) { _db.Utilities.PageEach(locs, 100, async pageList => { - await _db.Insertable(pageList).ExecuteCommandAsync(); + row = await _db.Insertable(pageList).ExecuteCommandAsync(); }); } else @@ -130,5 +140,6 @@ namespace Tnb.WarehouseMgr }; return result; } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs index 7a455402..991c2dbd 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryLedgerService.cs @@ -96,7 +96,20 @@ namespace Tnb.WarehouseMgr x.modify_id = null; x.modify_time = null; }); - row = await _db.Insertable(carrys).ExecuteCommandAsync(); + if (carrys.Count > 1000) + { + await _db.Fastest().BulkCopyAsync(carrys); + } + else if (carrys.Count > 400) + { + _db.Utilities.PageEach(carrys, 100, async pageList => { + await _db.Insertable(pageList).ExecuteCommandAsync(); + }); + } + else + { + row = await _db.Insertable(carrys).ExecuteCommandAsync(); + } } catch (Exception ex) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs index 003c35f9..b2786d36 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPointService.cs @@ -10,7 +10,11 @@ using JNPF.FriendlyException; using JNPF.VisualDev; using JNPF.VisualDev.Entitys.Dto.VisualDev; using Mapster; +using Microsoft.AspNetCore.Mvc; +using NPOI.HSSF.UserModel; using NPOI.SS.Formula; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.WarehouseMgr.Entities; @@ -39,6 +43,7 @@ namespace Tnb.WarehouseMgr VisualDevImportDataOutput result = new VisualDevImportDataOutput(); try { + List> dics = input.list; List points = new List(); WmsPointH pt = new WmsPointH(); @@ -47,6 +52,10 @@ namespace Tnb.WarehouseMgr //遍历字典,找出需要查询数据库拿的相关字段 foreach (var d in dics) { + if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null) + { + continue; + } d.ContainsKey("location_code"); var pCode = d["point_code"]?.ToString() ?? string.Empty; var pName = d["point_name"]?.ToString() ?? string.Empty; @@ -63,39 +72,41 @@ namespace Tnb.WarehouseMgr pt = d.Adapt(); points.Add(pt); } - var aDic = await _db.Queryable().Where(it => aCodes.Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id); - var lDic = await _db.Queryable().Where(it => lCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id); - points.ForEach(x => + var aDic = await _db.Queryable().Where(it => aCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id); + var lDic = await _db.Queryable().Where(it => lCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id); + var orgId = _userManager.User.OrganizeId; + var userId = _userManager.UserId; + foreach (var p in points) { - if (!aDic.ContainsKey(x.area_code)) throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号有误", 500); - x.id = SnowflakeIdHelper.NextId(); - x.org_id = _userManager.User.OrganizeId; - x.is_lock = 0; - x.status = 1; - x.point_x = 0; - x.point_y = 0; - x.point_z = 0; - x.location_id = x.location_code != null ? lDic[x.location_code]?.ToString() : null; - x.area_id = aDic[x.area_code]?.ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号编号有误", 500); - x.create_id = _userManager.UserId; - x.modify_id = null; - x.modify_time = null; - }); + if (!aDic.ContainsKey(p.area_code)) throw new AppFriendlyException($"第{points.IndexOf(p) + 1}个数据的管理区编号有误", 500); + p.id = SnowflakeIdHelper.NextId(); + p.org_id = orgId; + p.is_lock = 0; + p.status = 1; + p.point_x = 0; + p.point_y = 0; + p.point_z = 0; + p.location_id = p.location_code != null && p.location_code != string.Empty ? lDic[p.location_code]?.ToString() : null; + p.area_id = aDic[p.area_code]?.ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(p) + 1}个数据的管理区编号编号有误", 500); + p.create_id = userId; + p.modify_id = null; + p.modify_time = null; + } if (points.Count > 1000) { - await _db.Fastest().BulkCopyAsync(points); + row = await _db.Fastest().BulkCopyAsync(points); } else if (points.Count > 400) { - _db.Utilities.PageEach(points, 100, async pageList => { - await _db.Insertable(pageList).ExecuteCommandAsync(); + _db.Utilities.PageEach(points, 100, async pageList => + { + row = await _db.Insertable(pageList).ExecuteCommandAsync(); }); } else { row = await _db.Insertable(points).ExecuteCommandAsync(); } - row = await _db.Insertable(points).ExecuteCommandAsync(); } catch (Exception ex) { @@ -110,5 +121,6 @@ namespace Tnb.WarehouseMgr }; return result; } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsRouteMgrService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsRouteMgrService.cs index 560b37ad..1b405274 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsRouteMgrService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsRouteMgrService.cs @@ -20,7 +20,10 @@ using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using NPOI.HSSF.UserModel; using NPOI.SS.Formula; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; using SqlSugar; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Interfaces; @@ -81,10 +84,15 @@ namespace Tnb.WarehouseMgr //遍历字典,找出需要查询数据库拿的相关字段 foreach (var d in dics) { + if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null) + { + continue; + } var sCode = d["startpoint_code"]?.ToString() ?? string.Empty; var eCode = d["endpoint_code"]?.ToString() ?? string.Empty; var dis = d["distance"]?.ToString() ?? string.Empty; - if(sCode == eCode) throw new AppFriendlyException("起始点位不能等于终止点位", 500); + if (sCode == eCode) + throw new AppFriendlyException("起始点位不能等于终止点位", 500); if (dis.IsEmpty()) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据距离不可为空", 500); pointCodes.Add(sCode); @@ -94,32 +102,35 @@ namespace Tnb.WarehouseMgr road = d.Adapt(); roads.Add(road); } - var points = await _db.Queryable().Where(it => pointCodes.Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id); + var points = await _db.Queryable().Where(it => pointCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id); if (!points.IsNullOrEmpty()) { - roads.ForEach(x => + var orgId = _userManager.User.OrganizeId; + var userId = _userManager.UserId; + foreach (var r in roads) { - if (!points.ContainsKey(x.startpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500); - if (!points.ContainsKey(x.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500); - x.id = SnowflakeIdHelper.NextId(); - x.org_id = _userManager.User.OrganizeId; - x.startpoint_id = points[x.startpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500); - x.endpoint_id = points[x.endpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500); - x.road_code = $"{x.startpoint_code}-{x.endpoint_code}"; - x.status = 1; - x.create_id = _userManager.UserId; - x.modify_id = null; - x.modify_time = null; - }); + if (!points.ContainsKey(r.startpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500); + if (!points.ContainsKey(r.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500); + r.id = SnowflakeIdHelper.NextId(); + r.org_id = orgId; + r.startpoint_id = points[r.startpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500); + r.endpoint_id = points[r.endpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500); + r.road_code = $"{r.startpoint_code}-{r.endpoint_code}"; + r.status = 1; + r.create_id = userId; + r.modify_id = null; + r.modify_time = null; + } } if (roads.Count > 1000) { - await _db.Fastest().BulkCopyAsync(roads); + row = await _db.Fastest().BulkCopyAsync(roads); } else if (roads.Count > 400) { - _db.Utilities.PageEach(roads, 100, async pageList => { - await _db.Insertable(pageList).ExecuteCommandAsync(); + _db.Utilities.PageEach(roads, 100, async pageList => + { + row = await _db.Insertable(pageList).ExecuteCommandAsync(); }); } else @@ -129,7 +140,7 @@ namespace Tnb.WarehouseMgr } catch (Exception ex) - { + { throw Oops.Bah(ex.Message); } result = new VisualDevImportDataOutput() @@ -141,5 +152,6 @@ namespace Tnb.WarehouseMgr }; return result; } + } } diff --git a/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs b/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs index adc31b40..66b953c8 100644 --- a/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs +++ b/visualdev/Tnb.VisualDev/VisualDevModelDataService.cs @@ -800,7 +800,7 @@ namespace JNPF.VisualDev var overideSvc = OverideVisualDevManager.GetOrDefault(modelId); if (overideSvc != null && overideSvc.OverideFuncs.ImportDataAsync != null) { - await overideSvc.OverideFuncs.ImportDataAsync(list); + result = await overideSvc.OverideFuncs.ImportDataAsync(list); } else {