135 lines
5.5 KiB
C#
135 lines
5.5 KiB
C#
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Logging;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData;
|
|
using Tnb.EquipMgr.Entities;
|
|
using Tnb.EquipMgr.Entities.Dto;
|
|
using Tnb.EquipMgr.Interfaces;
|
|
|
|
namespace Tnb.EquipMgr
|
|
{
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[OverideVisualDev(ModuleId)]
|
|
public class ToolMoldMaintainPlanService : BaseMoldMaintainService, IOverideVisualDevService, IToolMoldMaintainPlanService, IDynamicApiController, ITransient
|
|
{
|
|
private const string ModuleId = "26165768858389";
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IToolMoldHouseService _moldHouseService;
|
|
private readonly IToolMoldLocationService _moldLocationService;
|
|
private readonly IToolMoldsService _moldService;
|
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
|
|
|
private static Dictionary<string, object> _dicHouse = new();
|
|
private static Dictionary<string, object> _dicLocation = new();
|
|
|
|
public ToolMoldMaintainPlanService(
|
|
ISqlSugarRepository<ToolMoldMaintainPlan> repository,
|
|
IRunService runService,
|
|
IVisualDevService visualDevService,
|
|
IToolMoldHouseService moldHouseService,
|
|
IToolMoldLocationService moldLocationService,
|
|
IToolMoldsService moldService
|
|
) : base(repository.AsSugarClient())
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
_moldHouseService = moldHouseService;
|
|
_moldLocationService = moldLocationService;
|
|
_moldService = moldService;
|
|
OverideFuncs.CreateAsync = Create;
|
|
|
|
}
|
|
|
|
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
|
{
|
|
try
|
|
{
|
|
visualDevModelDataCrInput.data[nameof(ToolMoldMaintainPlan.plan_code)] = $"JHDM{DateTime.Now:yyyyMMddmmss}";
|
|
visualDevModelDataCrInput.data[nameof(ToolMoldMaintainPlan.status)] = DictConst.UnMaintainStatusCode;
|
|
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
|
await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error("新增时出错", ex);
|
|
}
|
|
return await Task.FromResult("ok");
|
|
}
|
|
/// <summary>
|
|
/// 根据规则id获取匹配的模具列表
|
|
/// </summary>
|
|
/// <param name="planId">计划Id</param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetMoldListByPlanId([FromRoute] string planId)
|
|
{
|
|
List<MaintainPlanMoldLstOutput> result = new();
|
|
if (_dicHouse.Count < 1)
|
|
{
|
|
_dicHouse = await _moldHouseService.GetHouseDictionary();
|
|
}
|
|
if (_dicLocation.Count < 1)
|
|
{
|
|
_dicLocation = await _moldLocationService.GetLocationDictionary();
|
|
}
|
|
List<ToolMoldMaintainPlanRelation> list = await _db.Queryable<ToolMoldMaintainPlanRelation>().Where(it => it.maintain_plan_id == planId).ToListAsync();
|
|
if (list?.Count > 0)
|
|
{
|
|
List<string> ids = list.Select(it => it.mold_id).Distinct().ToList();
|
|
if (ids?.Count > 0)
|
|
{
|
|
List<ToolMolds> items = await _moldService.GetListByIds(ids);
|
|
_db.ThenMapper(items, it =>
|
|
{
|
|
if (!it.warehosue_id!.IsNullOrEmpty())
|
|
{
|
|
it.whcode = _dicHouse.ContainsKey(it.warehosue_id!) ? _dicHouse[it.warehosue_id!].ToString()! : "";
|
|
}
|
|
if (!it.location_id!.IsNullOrEmpty())
|
|
{
|
|
it.location_code = _dicLocation.ContainsKey(it.location_id!) ? _dicLocation[it.location_id!].ToString()! : "";
|
|
}
|
|
});
|
|
|
|
result = items.Adapt<List<MaintainPlanMoldLstOutput>>();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计划关联模具
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task RelevanceMoldFromPlan(RelevanceMoldFromPlanInput input)
|
|
{
|
|
await Relevance<RelevanceMoldFromPlanInput, ToolMoldMaintainPlanRelation>(input, nameof(ToolMoldMaintainPlanRelation.maintain_plan_id), nameof(ToolMoldMaintainPlanRelation.mold_id), it => it.maintain_plan_id == input.id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除计划与模具关联关系
|
|
/// </summary>
|
|
/// <param name="input">输入参数</param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task DeleteMold(RelevanceMoldFromPlanInput input)
|
|
{
|
|
await Delete<ToolMoldMaintainPlanRelation>(it => it.maintain_plan_id == input.id && input.ids.Contains(it.mold_id));
|
|
}
|
|
}
|
|
|
|
}
|