绑定库位
This commit is contained in:
9
BasicData/Tnb.BasicData.Entities/Dto/OrgLocOutput.cs
Normal file
9
BasicData/Tnb.BasicData.Entities/Dto/OrgLocOutput.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Tnb.BasicData.Entities
|
||||||
|
{
|
||||||
|
public class OrgLocOutput
|
||||||
|
{
|
||||||
|
public string id { get; set; }
|
||||||
|
public string f_organize_id { get; set; }
|
||||||
|
public string f_object_id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
104
BasicData/Tnb.BasicData/BasOrgLocationService.cs
Normal file
104
BasicData/Tnb.BasicData/BasOrgLocationService.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Dtos.VisualDev;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
|
using JNPF.Common.Filter;
|
||||||
|
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.VisualDev;
|
||||||
|
using JNPF.VisualDev.Entitys;
|
||||||
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
||||||
|
using JNPF.VisualDev.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData.Entities;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 工位绑定库位
|
||||||
|
/// </summary>
|
||||||
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
[OverideVisualDev(ModelId)]
|
||||||
|
public class BasOrgLocationService : IOverideVisualDevService, IDynamicApiController, ITransient
|
||||||
|
{
|
||||||
|
public const string ModelId = "35018844692245";
|
||||||
|
private readonly ISqlSugarRepository<OrganizeRelationEntity> _repository;
|
||||||
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly IVisualDevService _visualDevService;
|
||||||
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||||
|
|
||||||
|
public BasOrgLocationService(
|
||||||
|
ISqlSugarRepository<OrganizeRelationEntity> repository,
|
||||||
|
IUserManager userManager,
|
||||||
|
IVisualDevService visualDevService)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_userManager = userManager;
|
||||||
|
_visualDevService = visualDevService;
|
||||||
|
OverideFuncs.GetListAsync = GetList;
|
||||||
|
OverideFuncs.CreateAsync = Create;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
||||||
|
{
|
||||||
|
ISqlSugarClient db = _repository.AsSugarClient();
|
||||||
|
Dictionary<string, string>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(input.queryJson) : new Dictionary<string, string>();
|
||||||
|
string f_organize_id = queryJson.ContainsKey("f_organize_id") ? queryJson["f_organize_id"].ToString() : "";
|
||||||
|
SqlSugarPagedList<OrgLocOutput> result = await db.Queryable<OrganizeRelationEntity>()
|
||||||
|
.LeftJoin<BasLocation>((a, b) => a.ObjectId == b.id)
|
||||||
|
.LeftJoin<OrganizeEntity>((a,b,c)=>a.OrganizeId==c.Id)
|
||||||
|
.WhereIF(!string.IsNullOrEmpty(f_organize_id), (a, b) => a.OrganizeId.Contains(f_organize_id))
|
||||||
|
.Where(a=>a.ObjectType=="Loc")
|
||||||
|
.OrderByDescending(a => a.CreatorTime)
|
||||||
|
.Select((a, b,c) => new OrgLocOutput
|
||||||
|
{
|
||||||
|
id = a.Id,
|
||||||
|
f_organize_id = c.FullName,
|
||||||
|
f_object_id = b.location_name
|
||||||
|
}).ToPagedListAsync(input.currentPage, input.pageSize);
|
||||||
|
return PageResult<OrgLocOutput>.SqlSugarPageResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存工序工位关联表
|
||||||
|
/// </summary>
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
||||||
|
{
|
||||||
|
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(JsonConvert.SerializeObject(visualDevModelDataCrInput.data));
|
||||||
|
List<string> orgIds = JsonConvert.DeserializeObject<List<String>>(visualDevModelDataCrInput.data["f_organize_id"].ToString());
|
||||||
|
List<string> locIds = JsonConvert.DeserializeObject<List<String>>(visualDevModelDataCrInput.data["f_object_id"].ToString());
|
||||||
|
List<OrganizeRelationEntity> list = new List<OrganizeRelationEntity>();
|
||||||
|
foreach (var item in locIds)
|
||||||
|
{
|
||||||
|
list.Add(new OrganizeRelationEntity()
|
||||||
|
{
|
||||||
|
Id = SnowflakeIdHelper.NextId(),
|
||||||
|
OrganizeId = orgIds[orgIds.Count-1],
|
||||||
|
ObjectId = item,
|
||||||
|
ObjectType = "Loc",
|
||||||
|
CreatorTime = DateTime.Now,
|
||||||
|
CreatorUserId = _userManager.UserId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list.Count > 0)
|
||||||
|
{
|
||||||
|
await _repository.AsSugarClient().Insertable(list).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return !result.IsSuccess ? throw Oops.Oh(ErrorCode.COM1008) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user