145 lines
6.1 KiB
C#
145 lines
6.1 KiB
C#
using Aop.Api.Domain;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
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.Entities;
|
|
using Tnb.BasicData.Entities.Dto;
|
|
using Tnb.BasicData.Entitys.Dto.BasProcess;
|
|
using Tnb.BasicData.Interfaces;
|
|
|
|
namespace Tnb.BasicData
|
|
{
|
|
/// <summary>
|
|
/// 工序定义
|
|
/// </summary>
|
|
[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<BasProcess> _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<BasProcess> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在线开发-获取工序列表
|
|
/// added by ly on 20230428
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
var result = new SqlSugarPagedList<ProcessListOutput>();
|
|
var db = _repository.AsSugarClient();
|
|
var organize = await db.Queryable<OrganizeEntity>().FirstAsync(it => it.EnCode == input.station_code && it.Category == DictConst.RegionCategoryStationCode);
|
|
if (organize != null)
|
|
{
|
|
var whereExpr = Expressionable.Create<BasProcess, BasProcessStation>();
|
|
var curProcessIds = await db.Queryable<BasProcessStation>().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<BasProcess>().LeftJoin<BasProcessStation>((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;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 保存工序工位关联表
|
|
/// </summary>
|
|
/// <param name="processStationInput">process_id 工序id</param>
|
|
/// <param name="processStationInput">stationIds 工位id集合</param>
|
|
[HttpPost]
|
|
public async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
|
{
|
|
DbResult<bool> 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<BasProcessStation> list = new List<BasProcessStation>();
|
|
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<BasProcessStation>(list).ExecuteCommandAsync();
|
|
});
|
|
|
|
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
|
|
}
|
|
|
|
|
|
}
|
|
} |