using Aop.Api.Domain; using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; using JNPF.FriendlyException; using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.System; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using JNPF.VisualDev.Entitys; using JNPF.VisualDev.Entitys.Dto.VisualDevModelData; using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using SqlSugar; using Tnb.BasicData; using Tnb.BasicData.Entities; using Tnb.BasicData.Entitys.Dto.BasProcess; using Tnb.BasicData.Interfaces; namespace Tnb.BasicData { /// /// 工序定义 /// [ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)] [Route("api/[area]/[controller]/[action]")] [OverideVisualDev(ModelId)] public class BasProcessService : IOverideVisualDevService, IDynamicApiController, ITransient { public const string ModelId = "25483283228965"; private readonly ISqlSugarRepository _repository; private readonly DataBaseManager _dbManager; private readonly IUserManager _userManager; private readonly IRunService _runService; private readonly IVisualDevService _visualDevService; public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); public BasProcessService( ISqlSugarRepository repository, IUserManager userManager, IRunService runService, IVisualDevService visualDevService, DataBaseManager dbManager) { _repository = repository; _userManager = userManager; _dbManager = dbManager; _runService = runService; _visualDevService = visualDevService; OverideFuncs.CreateAsync = Create; // OverideFuncs.GetListAsync = GetList; } /// /// 在线开发-获取工序列表 /// added by ly on 20230428 /// /// /// private async Task GetList(VisualDevModelListQueryInput input) { var result = new SqlSugarPagedList(); var db = _repository.AsSugarClient(); var organize = await db.Queryable().FirstAsync(it => it.EnCode == input.station_code && it.Category == DictConst.RegionCategoryStationCode); if (organize != null) { var whereExpr = Expressionable.Create(); var curProcessIds = await db.Queryable().Where(it => it.station_id == organize.Id).Select(it => it.process_id).Distinct().ToListAsync(); if (curProcessIds?.Count > 0) { whereExpr = whereExpr.And((a, b) => curProcessIds.Contains(a.id)).Or((a, b) => string.IsNullOrEmpty(b.process_id)); } else { whereExpr = whereExpr.And((a, b) => string.IsNullOrEmpty(b.process_id)); } result = await db.Queryable().LeftJoin((a, b) => a.id == b.process_id).Where(whereExpr.ToExpression()).Select(a => new ProcessListOutput { id = a.id, process_code = a.process_code, process_name = a.process_name, process_collection = a.process_collection, status = a.status, station = a.station, must_pass = a.must_pass, defective_products_put_into_production = a.defective_products_put_into_production, single_scan_type = a.single_scan_type, only_scan_type = a.only_scan_type, material_traced_back_relationship = a.material_traced_back_relationship, report_template = a.report_template, descrip = a.descrip, org_id = a.org_id, create_id = a.create_id, modify_id = a.modify_id, modify_time = a.modify_time, }).ToPagedListAsync(input.currentPage, input.pageSize); } return result; } /// /// 保存工序工位关联表 /// [HttpPost] public async Task Create(VisualDevModelDataCrInput visualDevModelDataCrInput) { DbResult result = await _repository.AsSugarClient().Ado.UseTranAsync(async () => { VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModelId, true); await _runService.Create(templateEntity, visualDevModelDataCrInput); string processId = visualDevModelDataCrInput.data["ReturnIdentity"].ToString() ?? ""; List list = new List(); foreach (var item in (JArray)visualDevModelDataCrInput.data["station"]) { string processStationId = SnowflakeIdHelper.NextId(); list.Add(new BasProcessStation() { id = processStationId, org_id = _userManager.GetUserInfo().Result.organizeId, process_id = processId, station_id = item.Last().ToString(), create_id = _userManager.UserId, create_time = DateTime.Now, }); } await _repository.AsSugarClient().Insertable(list).ExecuteCommandAsync(); }); if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008); return result.IsSuccess ? "保存成功" : result.ErrorMessage; } } }