From 630a8b76d061ca5adc2a3193beff2d51b285b781 Mon Sep 17 00:00:00 2001 From: zhoukeda <1315948824@qq.com> Date: Wed, 19 Jul 2023 17:57:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=BA=8C=E7=BB=B4=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BasQrcode.cs | 47 ++++++++++ EquipMgr/Tnb.EquipMgr/EquipmentService.cs | 92 +++++++++++++++++- .../Tnb.EquipMgr/ToolMoldLocationService.cs | 94 ++++++++++++++++++- .../Permission/DepartmentService.cs | 63 +++++++++++++ 4 files changed, 292 insertions(+), 4 deletions(-) create mode 100644 BasicData/Tnb.BasicData.Entities/Entity/BasQrcode.cs diff --git a/BasicData/Tnb.BasicData.Entities/Entity/BasQrcode.cs b/BasicData/Tnb.BasicData.Entities/Entity/BasQrcode.cs new file mode 100644 index 00000000..8e0e5ebc --- /dev/null +++ b/BasicData/Tnb.BasicData.Entities/Entity/BasQrcode.cs @@ -0,0 +1,47 @@ +using JNPF.Common.Contracts; +using JNPF.Common.Security; +using SqlSugar; + +namespace Tnb.BasicData.Entities; + +/// +/// 系统二维码表 +/// +[SugarTable("bas_qrcode")] +public partial class BasQrcode : BaseEntity +{ + public BasQrcode() + { + id = SnowflakeIdHelper.NextId(); + } + /// + /// 编码 + /// + public string code { get; set; } = string.Empty; + + /// + /// 关联表id + /// + public string? source_id { get; set; } + + /// + /// 关联表名 + /// + public string? source_name { get; set; } + + /// + /// 创建用户 + /// + public string? create_id { get; set; } + + /// + /// 创建时间 + /// + public DateTime? create_time { get; set; } + + /// + /// 所属组织 + /// + public string? org_id { get; set; } + +} \ No newline at end of file diff --git a/EquipMgr/Tnb.EquipMgr/EquipmentService.cs b/EquipMgr/Tnb.EquipMgr/EquipmentService.cs index a904bcaa..610e4002 100644 --- a/EquipMgr/Tnb.EquipMgr/EquipmentService.cs +++ b/EquipMgr/Tnb.EquipMgr/EquipmentService.cs @@ -1,13 +1,19 @@ using Aop.Api.Domain; using Aspose.Cells.Drawing; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Filter; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.Extras.CollectiveOAuth.Models; +using JNPF.FriendlyException; +using JNPF.Logging; using JNPF.Systems.Entitys.Permission; using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; +using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using Senparc.NeuChar.ApiHandlers; @@ -16,6 +22,7 @@ using Tnb.BasicData; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Entities.Dto; using Tnb.EquipMgr.Interfaces; +using Tnb.BasicData.Entities; namespace Tnb.EquipMgr { @@ -29,12 +36,24 @@ namespace Tnb.EquipMgr public class EquipmentService : IOverideVisualDevService, IEquipmentService, IDynamicApiController, ITransient { public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - private const string ModuleId = "25064865727509"; + private const string ModuleId = "26012367560469"; private readonly ISqlSugarRepository _repository; + private readonly IVisualDevService _visualDevService; + private readonly IRunService _runService; + private readonly IUserManager _userManager; - public EquipmentService(ISqlSugarRepository repository) + public EquipmentService(ISqlSugarRepository repository, + IVisualDevService visualDevService, + IUserManager userManager, + IRunService runService + ) { _repository = repository; + _visualDevService = visualDevService; + _runService = runService; + _userManager = userManager; + OverideFuncs.CreateAsync = Create; + OverideFuncs.UpdateAsync = Update; } /// /// 在线开发-获取设备列表 @@ -67,6 +86,75 @@ namespace Tnb.EquipMgr .ToPagedListAsync(input.currentPage, input.pageSize); return pagedList; } + + private async Task Create(VisualDevModelDataCrInput visualDevModelDataCrInput) + { + string qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"].ToString() : ""; + if (!string.IsNullOrEmpty(qrcode) && await _repository.AsSugarClient().Queryable().AnyAsync(x => x.code == qrcode)) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + await _runService.Create(templateEntity, visualDevModelDataCrInput); + + string equipId = visualDevModelDataCrInput.data["ReturnIdentity"].ToString() ?? ""; + + if (!string.IsNullOrEmpty(qrcode)) + { + BasQrcode basQrcode = new BasQrcode() + { + code = visualDevModelDataCrInput.data["qrcode"].ToString(), + source_id = equipId, + source_name = "EQP_EQUIPMENT", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _repository.AsSugarClient().Insertable(basQrcode).ExecuteCommandAsync(); + } + } + return await Task.FromResult(true); + } + + private async Task Update(string id,VisualDevModelDataUpInput visualDevModelDataUpInput) + { + string qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"].ToString() : ""; + if (!string.IsNullOrEmpty(qrcode) && await _repository.AsSugarClient().Queryable().AnyAsync(x => x.code == visualDevModelDataUpInput.data["qrcode"] && x.source_id!=id)) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + await _runService.Update(id,templateEntity, visualDevModelDataUpInput); + + if (!string.IsNullOrEmpty(qrcode)) + { + if (await _repository.AsSugarClient().Queryable().AnyAsync(x => x.source_id == id)) + { + await _repository.AsSugarClient().Updateable() + .SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id) + .ExecuteCommandAsync(); + } + else + { + BasQrcode basQrcode = new BasQrcode() + { + code = visualDevModelDataUpInput.data["qrcode"].ToString(), + source_id = id, + source_name = "EQP_EQUIPMENT", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _repository.AsSugarClient().Insertable(basQrcode).ExecuteCommandAsync(); + } + } + } + return await Task.FromResult(true); + } [HttpPost] public async Task GetEntityById(Dictionary dic) diff --git a/EquipMgr/Tnb.EquipMgr/ToolMoldLocationService.cs b/EquipMgr/Tnb.EquipMgr/ToolMoldLocationService.cs index bfc73a31..465f1a23 100644 --- a/EquipMgr/Tnb.EquipMgr/ToolMoldLocationService.cs +++ b/EquipMgr/Tnb.EquipMgr/ToolMoldLocationService.cs @@ -4,10 +4,17 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Aspose.Cells.Drawing; +using JNPF.Common.Core.Manager; +using JNPF.Common.Dtos.VisualDev; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.FriendlyException; +using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; using Microsoft.AspNetCore.Mvc; using SqlSugar; +using Tnb.BasicData.Entities; using Tnb.EquipMgr.Entities; using Tnb.EquipMgr.Interfaces; @@ -18,16 +25,99 @@ namespace Tnb.EquipMgr /// [ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)] [Route("api/[area]/[controller]/[action]")] - public class ToolMoldLocationService : IToolMoldLocationService, IDynamicApiController, ITransient + [OverideVisualDev(ModuleId)] + public class ToolMoldLocationService : IToolMoldLocationService,IOverideVisualDevService, IDynamicApiController, ITransient { + public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + private const string ModuleId = "27207685649173"; private readonly ISqlSugarClient _db; - public ToolMoldLocationService(ISqlSugarRepository repository) + private readonly IVisualDevService _visualDevService; + private readonly IRunService _runService; + private readonly IUserManager _userManager; + public ToolMoldLocationService(ISqlSugarRepository repository, + IVisualDevService visualDevService, + IUserManager userManager, + IRunService runService) { _db = repository.AsSugarClient(); + _visualDevService = visualDevService; + _runService = runService; + _userManager = userManager; + OverideFuncs.CreateAsync = Create; + OverideFuncs.UpdateAsync = Update; } public async Task> GetLocationDictionary() { return await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.location_code); } + + private async Task Create(VisualDevModelDataCrInput visualDevModelDataCrInput) + { + string qrcode = visualDevModelDataCrInput.data.ContainsKey("qrcode") ? visualDevModelDataCrInput.data["qrcode"].ToString() : ""; + if (!string.IsNullOrEmpty(qrcode) && await _db.Queryable().AnyAsync(x => x.code == qrcode)) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + await _runService.Create(templateEntity, visualDevModelDataCrInput); + + string id = visualDevModelDataCrInput.data["ReturnIdentity"].ToString() ?? ""; + + if (!string.IsNullOrEmpty(qrcode)) + { + BasQrcode basQrcode = new BasQrcode() + { + code = visualDevModelDataCrInput.data["qrcode"].ToString(), + source_id = id, + source_name = "TOOL_LOCATION", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _db.Insertable(basQrcode).ExecuteCommandAsync(); + } + } + return await Task.FromResult(true); + } + + private async Task Update(string id,VisualDevModelDataUpInput visualDevModelDataUpInput) + { + string qrcode = visualDevModelDataUpInput.data.ContainsKey("qrcode") ? visualDevModelDataUpInput.data["qrcode"].ToString() : ""; + if (!string.IsNullOrEmpty(qrcode) && await _db.Queryable().AnyAsync(x => x.code == visualDevModelDataUpInput.data["qrcode"] && x.source_id!=id)) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true); + await _runService.Update(id,templateEntity, visualDevModelDataUpInput); + + if (!string.IsNullOrEmpty(qrcode)) + { + if (await _db.Queryable().AnyAsync(x => x.source_id == id)) + { + await _db.Updateable() + .SetColumns(x => x.code == visualDevModelDataUpInput.data["qrcode"].ToString()).Where(x => x.source_id == id) + .ExecuteCommandAsync(); + } + else + { + BasQrcode basQrcode = new BasQrcode() + { + code = visualDevModelDataUpInput.data["qrcode"].ToString(), + source_id = id, + source_name = "TOOL_LOCATION", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _db.Insertable(basQrcode).ExecuteCommandAsync(); + } + } + } + return await Task.FromResult(true); + } } } diff --git a/system/Tnb.Systems/Permission/DepartmentService.cs b/system/Tnb.Systems/Permission/DepartmentService.cs index 85325c15..17b56670 100644 --- a/system/Tnb.Systems/Permission/DepartmentService.cs +++ b/system/Tnb.Systems/Permission/DepartmentService.cs @@ -313,6 +313,32 @@ public class DepartmentService : IDepartmentService, IDynamicApiController, ITra if (adminlist.Any()) await _repository.AsSugarClient().Insertable(adminlist).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); #endregion + + if (input.category != DictConst.RegionCategoryCompanyCode) + { + var jsonObj = input.propertyJson; + var qrcode = jsonObj.GetValue("qrcode"); + if (qrcode is not null && !string.IsNullOrEmpty(qrcode.ToString())) + { + if (await _repository.AsSugarClient().Queryable().AnyAsync(x => x.code == qrcode.ToString())) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + BasQrcode basQrcode = new BasQrcode() + { + code = qrcode.ToString(), + source_id = entity.Id, + source_name = "BASE_ORGANIZE", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _repository.AsSugarClient().Insertable(basQrcode).ExecuteCommandAsync(); + } + } + } #region 第三方同步 @@ -450,6 +476,43 @@ public class DepartmentService : IDepartmentService, IDynamicApiController, ITra int isOK = await _repository.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).CallEntityMethod(m => m.LastModify()).ExecuteCommandAsync(); if (!(isOK > 0)) throw Oops.Oh(ErrorCode.D2018); + + //modified by zkd on 20230718 处理二维码 + if (input.category != DictConst.RegionCategoryCompanyCode) + { + var jsonObj = input.propertyJson; + var qrcode = jsonObj.GetValue("qrcode"); + if (qrcode is not null && !string.IsNullOrEmpty(qrcode.ToString())) + { + if (await _repository.AsSugarClient().Queryable().AnyAsync(x => x.code == qrcode.ToString() && x.source_id!=id)) + { + throw Oops.Bah("二维码总表中已存在该二维码"); + } + else + { + if (await _repository.AsSugarClient().Queryable().AnyAsync(x => x.source_id == id)) + { + await _repository.AsSugarClient().Updateable() + .SetColumns(x => x.code == qrcode.ToString()).Where(x => x.source_id == id) + .ExecuteCommandAsync(); + } + else + { + BasQrcode basQrcode = new BasQrcode() + { + code = qrcode.ToString(), + source_id = id, + source_name = "BASE_ORGANIZE", + create_id = _userManager.UserId, + create_time = DateTime.Now, + org_id = _userManager.GetUserInfo().Result.organizeId, + }; + await _repository.AsSugarClient().Insertable(basQrcode).ExecuteCommandAsync(); + } + } + } + } + //modified by ly on 20230426 处理工位信息,将工位插入到设备表 if (input.category == DictConst.RegionCategoryStationCode) {