异常开始结束带代码提交
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 停机开始输入参数
|
||||
/// </summary>
|
||||
public class CloseDownStartInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备id
|
||||
/// </summary>
|
||||
public string eqp_id { get; set; }
|
||||
/// <summary>
|
||||
/// 停机类别
|
||||
/// </summary>
|
||||
public string category { get; set; }
|
||||
/// <summary>
|
||||
/// 停机原因
|
||||
/// </summary>
|
||||
public string reason { get; set; }
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities.Dto.PrdManage
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据设备id 获取生产任务列表,输入参数
|
||||
/// </summary>
|
||||
public class PrdMoTaskFromEqpIdInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备id
|
||||
/// </summary>
|
||||
public string eqp_id { get; set; }
|
||||
/// <summary>
|
||||
/// 生产状态
|
||||
/// </summary>
|
||||
public string status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable("prd_cancel_closedown")]
|
||||
public partial class PrdCancelClosedown : BaseEntity<string>
|
||||
{
|
||||
public PrdCancelClosedown()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 停机类别
|
||||
/// </summary>
|
||||
public string? catetory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机原因
|
||||
/// </summary>
|
||||
public string? reason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
/// <summary>
|
||||
/// 设备id
|
||||
/// </summary>
|
||||
public string eqp_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
/// <summary>
|
||||
/// 停机开始时间
|
||||
/// </summary>
|
||||
public DateTime? closedown_start_time { get; set; }
|
||||
/// <summary>
|
||||
/// 停机结束时间
|
||||
/// </summary>
|
||||
public DateTime? closedown_end_time { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable("prd_cancel_closedown_reason")]
|
||||
public partial class PrdCancelClosedownReason : BaseEntity<string>
|
||||
{
|
||||
public PrdCancelClosedownReason()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 停机类别字典id
|
||||
/// </summary>
|
||||
public string? category_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机原因编码
|
||||
/// </summary>
|
||||
public string? reason_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机原因
|
||||
/// </summary>
|
||||
public string? reason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Tnb.ProductionMgr.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 异常停机
|
||||
/// </summary>
|
||||
[SugarTable("prd_cancel_closedown_record")]
|
||||
public partial class PrdCancelClosedownRecord : BaseEntity<string>
|
||||
{
|
||||
public PrdCancelClosedownRecord()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 停机类别
|
||||
/// </summary>
|
||||
public string? catetory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机原因
|
||||
/// </summary>
|
||||
public string? reason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机开始时间
|
||||
/// </summary>
|
||||
public DateTime? closedown_start_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 停机结束时间
|
||||
/// </summary>
|
||||
public DateTime? closedown_end_time { get; set; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.ProductionMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 异常停机服务接口
|
||||
/// </summary>
|
||||
public interface IPrdCancelCloseDownService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||||
|
||||
namespace Tnb.ProductionMgr.Interfaces
|
||||
{
|
||||
@@ -11,5 +13,11 @@ namespace Tnb.ProductionMgr.Interfaces
|
||||
/// </summary>
|
||||
public interface IPrdMoTaskService
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据设备Id获取生产任务
|
||||
/// </summary>
|
||||
/// <param name="eqpId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<PrdMoTask>> GetListByEqpId(string eqpId);
|
||||
}
|
||||
}
|
||||
|
||||
241
ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs
Normal file
241
ProductionMgr/Tnb.ProductionMgr/PrdCancelCloseDownService.cs
Normal file
@@ -0,0 +1,241 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aop.Api.Domain;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
using Tnb.ProductionMgr.Entities;
|
||||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||||
using Tnb.ProductionMgr.Interfaces;
|
||||
|
||||
namespace Tnb.ProductionMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 业务实现:生产管理
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
|
||||
public class PrdCancelCloseDownService : IPrdCancelCloseDownService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IToolMoldMaintainTaskService _maintainTaskService;
|
||||
private readonly IToolMoldsService _moldService;
|
||||
private readonly IPrdMoTaskService _prdMoTaskService;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private static Dictionary<string, object> _dicWorkStationAndShopRelacion = new Dictionary<string, object>();
|
||||
private static Dictionary<string, object> _dicWorkShop = new Dictionary<string, object>();
|
||||
|
||||
|
||||
|
||||
public PrdCancelCloseDownService(
|
||||
ISqlSugarRepository<PrdCancelClosedown> repository,
|
||||
IPrdMoTaskService prdMoTaskService,
|
||||
IToolMoldsService moldsService,
|
||||
IToolMoldMaintainTaskService maintainTaskService,
|
||||
IUserManager userManager
|
||||
)
|
||||
{
|
||||
_prdMoTaskService = prdMoTaskService;
|
||||
_maintainTaskService = maintainTaskService;
|
||||
_moldService = moldsService;
|
||||
_userManager = userManager;
|
||||
_db = repository.AsSugarClient();
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据设备ID获取异常关机信息
|
||||
/// </summary>
|
||||
/// <param name="eqpId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetClosedownEndList([FromRoute] string eqpId)
|
||||
{
|
||||
if (_dicWorkShop.Count < 1)
|
||||
{
|
||||
var orgs = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workstation").ToListAsync();
|
||||
if (orgs?.Count > 0)
|
||||
{
|
||||
var shopIds = orgs.Select(x =>
|
||||
{
|
||||
var shopId = "";
|
||||
var orgTree = x.OrganizeIdTree.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (orgTree?.Length > 1)
|
||||
{
|
||||
shopId = orgTree[orgTree.Length - 2];
|
||||
_dicWorkStationAndShopRelacion[x.EnCode] = shopId;
|
||||
}
|
||||
return shopId;
|
||||
}).Where(x => !x.IsNullOrEmpty()).ToList();
|
||||
if (shopIds?.Count > 0)
|
||||
{
|
||||
_dicWorkShop = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "department" && shopIds.Contains(it.Id)).ToDictionaryAsync(x => x.Id, x => x.FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
var result = new List<ClosedownEndListOutput>();
|
||||
var closeDown = await _db.Queryable<PrdCancelClosedown>().FirstAsync(it => it.eqp_id == eqpId);
|
||||
if (closeDown != null)
|
||||
{
|
||||
if (!closeDown.reason.IsNullOrEmpty())
|
||||
{
|
||||
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == eqpId);
|
||||
EqpEquipType eqpTypeInfo = null;
|
||||
if (eqp != null)
|
||||
eqpTypeInfo = await _db.Queryable<EqpEquipType>().FirstAsync(it => it.id == eqp.equip_type_id);
|
||||
var reasonArr = closeDown.reason.Split(",");
|
||||
foreach (var reason in reasonArr)
|
||||
{
|
||||
ClosedownEndListOutput ot = new();
|
||||
if (eqp != null)
|
||||
{
|
||||
if (_dicWorkStationAndShopRelacion.ContainsKey(eqp.station_code))
|
||||
{
|
||||
var shopId = _dicWorkStationAndShopRelacion[eqp.station_code].ToString();
|
||||
ot.workshop_name = _dicWorkShop.ContainsKey(shopId) ? _dicWorkShop[shopId].ToString()! : "";
|
||||
}
|
||||
}
|
||||
ot.reason = reason;
|
||||
ot.eqp_code = eqp?.code;
|
||||
ot.eqp_type_code = eqpTypeInfo?.code;
|
||||
ot.operator_name = _userManager.RealName;
|
||||
ot.remark = closeDown.remark;
|
||||
ot.closeddown_start_time = closeDown.closedown_start_time;
|
||||
result.Add(ot);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.Count < 1)
|
||||
{
|
||||
ClosedownEndListOutput output = new();
|
||||
result.Add(output);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异常停机-开始
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task CloseDownStart(CloseDownStartInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
if (input.eqp_id.IsNullOrWhiteSpace()) throw new ArgumentException($"parameter {nameof(input.eqp_id)} not be null or empty");
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
||||
if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
||||
if (moTaskList.Count > 0)
|
||||
{
|
||||
var cancelCloseDown = input.Adapt<PrdCancelClosedown>();
|
||||
cancelCloseDown.id = SnowflakeIdHelper.NextId();
|
||||
cancelCloseDown.eqp_id = input.eqp_id;
|
||||
cancelCloseDown.create_id = _userManager.UserId;
|
||||
cancelCloseDown.create_time = DateTime.Now;
|
||||
cancelCloseDown.closedown_start_time = DateTime.Now;
|
||||
|
||||
await _db.Insertable(cancelCloseDown).ExecuteCommandAsync();
|
||||
var record = cancelCloseDown.Adapt<PrdCancelClosedownRecord>();
|
||||
await _db.Insertable(record).ExecuteCommandAsync();
|
||||
|
||||
var moldId = moTaskList.First().mold_id;
|
||||
if (!moldId.IsNullOrEmpty())
|
||||
{
|
||||
var mold = await _moldService.GetListById(moldId);
|
||||
var maintaindTask = new ToolMoldMaintainTask();
|
||||
maintaindTask.mold_id = moldId;
|
||||
maintaindTask.code = DictConst.MaintainStatusDWXCode;
|
||||
maintaindTask.create_id = _userManager.UserId;
|
||||
maintaindTask.create_time = DateTime.Now;
|
||||
|
||||
await _maintainTaskService.Create(maintaindTask);
|
||||
}
|
||||
}
|
||||
else throw Oops.Oh(ErrorCode.COM1001);
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("停机开始失败", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 停机结束
|
||||
/// </summary>
|
||||
/// <param name="maintainTaskId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task CloseDownEnd(CloseDownStartInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
if (input.eqp_id.IsNullOrWhiteSpace()) throw new ArgumentException($"parameter {nameof(input.eqp_id)} not be null or empty");
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
||||
if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
||||
|
||||
var cancelCloseDown = input.Adapt<PrdCancelClosedown>();
|
||||
cancelCloseDown.id = SnowflakeIdHelper.NextId();
|
||||
cancelCloseDown.create_id = _userManager.UserId;
|
||||
cancelCloseDown.create_time = DateTime.Now;
|
||||
cancelCloseDown.closedown_start_time = DateTime.Now;
|
||||
|
||||
var row = await _db.Insertable(cancelCloseDown).ExecuteCommandAsync();
|
||||
|
||||
var moldId = moTaskList.First().mold_id;
|
||||
if (moldId.IsNullOrEmpty())
|
||||
{
|
||||
var mold = await _moldService.GetListById(moldId);
|
||||
var maintaindTask = new ToolMoldMaintainTask();
|
||||
maintaindTask.mold_id = moldId;
|
||||
maintaindTask.code = DictConst.MaintainStatusYWCCode;
|
||||
maintaindTask.create_id = _userManager.UserId;
|
||||
maintaindTask.create_time = DateTime.Now;
|
||||
|
||||
|
||||
await _maintainTaskService.Create(maintaindTask);
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("停机开始失败", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
}
|
||||
//var row = await _db.Updateable<ToolMoldMaintainTask>().SetColumns(c => new ToolMoldMaintainTask
|
||||
//{
|
||||
// status = DictConst.MaintainStatusDWXCode,
|
||||
// modify_id = _userManager.UserId,
|
||||
// modify_end_time = DateTime.Now,
|
||||
//})
|
||||
// .ExecuteCommandAsync();
|
||||
//if (row < 1) throw Oops.Oh(ErrorCode.COM1001);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1185,5 +1185,9 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
}
|
||||
|
||||
public async Task<List<PrdMoTask>> GetListByEqpId(string eqpId)
|
||||
{
|
||||
return await _db.Queryable<PrdMoTask>().Where(it => it.eqp_id == eqpId && it.mo_task_status == DictConst.InProgressEnCode).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user