执行代码清理,修复warning
This commit is contained in:
@@ -47,11 +47,11 @@ namespace Tnb.ProductionMgr
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IBillRullService _billRullService;
|
||||
private readonly TimeTaskService _timeTaskService;
|
||||
private SendMessageService _sendMessageService;
|
||||
private readonly SendMessageService _sendMessageService;
|
||||
|
||||
|
||||
private static Dictionary<string, object> _dicWorkStationAndShopRelacion = new Dictionary<string, object>();
|
||||
private static Dictionary<string, object> _dicWorkShop = new Dictionary<string, object>();
|
||||
private static readonly Dictionary<string, object> _dicWorkStationAndShopRelacion = new();
|
||||
private static Dictionary<string, object> _dicWorkShop = new();
|
||||
private const string PUSHRULEID = "27121606262805";//异常停机的推送规则id
|
||||
|
||||
|
||||
@@ -86,16 +86,16 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
if (_dicWorkShop.Count < 1)
|
||||
{
|
||||
var orgs = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workstation").ToListAsync();
|
||||
List<OrganizeEntity> orgs = await _db.Queryable<OrganizeEntity>().Where(it => it.Category == "workstation").ToListAsync();
|
||||
if (orgs?.Count > 0)
|
||||
{
|
||||
var shopIds = orgs.Select(x =>
|
||||
List<string> shopIds = orgs.Select(x =>
|
||||
{
|
||||
var shopId = "";
|
||||
var orgTree = x.OrganizeIdTree.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
string shopId = "";
|
||||
string[] orgTree = x.OrganizeIdTree.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (orgTree?.Length > 1)
|
||||
{
|
||||
shopId = orgTree[orgTree.Length - 2];
|
||||
shopId = orgTree[^2];
|
||||
_dicWorkStationAndShopRelacion[x.EnCode] = shopId;
|
||||
}
|
||||
return shopId;
|
||||
@@ -106,25 +106,28 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
}
|
||||
}
|
||||
var result = new List<ClosedownEndListOutput>();
|
||||
var closeDown = await _db.Queryable<PrdCancelClosedown>().FirstAsync(it => it.eqp_id == eqpId);
|
||||
List<ClosedownEndListOutput> result = new();
|
||||
PrdCancelClosedown 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;
|
||||
EqpEquipment? 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)
|
||||
}
|
||||
|
||||
string[] reasonArr = closeDown.reason.Split(",");
|
||||
foreach (string reason in reasonArr)
|
||||
{
|
||||
ClosedownEndListOutput ot = new();
|
||||
if (eqp != null)
|
||||
{
|
||||
if (_dicWorkStationAndShopRelacion.ContainsKey(eqp.station_code))
|
||||
{
|
||||
var shopId = _dicWorkStationAndShopRelacion[eqp.station_code].ToString();
|
||||
string? shopId = _dicWorkStationAndShopRelacion[eqp.station_code].ToString();
|
||||
ot.workshop_name = _dicWorkShop.ContainsKey(shopId) ? _dicWorkShop[shopId].ToString()! : "";
|
||||
}
|
||||
}
|
||||
@@ -153,7 +156,7 @@ namespace Tnb.ProductionMgr
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetClosedownHistory([FromQuery] ClosedownHistoryQuery input)
|
||||
{
|
||||
var pagedList = await _db.Queryable<PrdCancelClosedownRecord>()
|
||||
List<ClosedownHistoryOutput> pagedList = await _db.Queryable<PrdCancelClosedownRecord>()
|
||||
.WhereIF(!string.IsNullOrEmpty(input.eqpName), it => it.eqp_name.Contains(input.eqpName))
|
||||
.WhereIF(input.beginTime.HasValue, it => it.closedown_start_time.Value >= input.beginTime)
|
||||
.WhereIF(input.endTime.HasValue, it => it.closedown_start_time.Value <= input.endTime)
|
||||
@@ -184,10 +187,10 @@ namespace Tnb.ProductionMgr
|
||||
public async Task<dynamic> GetInfoFromEqpId([FromRoute] string eqpId)
|
||||
{
|
||||
dynamic info = new ExpandoObject();
|
||||
var moTask = await _db.Queryable<PrdMoTask>().Where(it => it.mo_task_status == DictConst.InProgressEnCode).FirstAsync(it => it.eqp_id == eqpId);
|
||||
PrdMoTask moTask = await _db.Queryable<PrdMoTask>().Where(it => it.mo_task_status == DictConst.InProgressEnCode).FirstAsync(it => it.eqp_id == eqpId);
|
||||
if (moTask != null)
|
||||
{
|
||||
var mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == moTask.mo_id);
|
||||
ToolMolds? mold = await _db.Queryable<ToolMolds>().FirstAsync(it => it.id == moTask.mo_id);
|
||||
info.mo_task_code = moTask.mo_task_code;
|
||||
info.mold_code = mold?.mold_code;
|
||||
info.mold_name = mold?.mold_name;
|
||||
@@ -204,19 +207,31 @@ namespace Tnb.ProductionMgr
|
||||
[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");
|
||||
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == input.eqp_id);
|
||||
var cancelCloseDown = input.Adapt<PrdCancelClosedown>();
|
||||
EqpRepairApply eqpRepairApply = null;
|
||||
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");
|
||||
}
|
||||
|
||||
EqpEquipment? eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == input.eqp_id);
|
||||
PrdCancelClosedown cancelCloseDown = input.Adapt<PrdCancelClosedown>();
|
||||
EqpRepairApply? eqpRepairApply = null;
|
||||
BasPushRuleD basPushRuleD = await _db.Queryable<BasPushRuleD>().FirstAsync(x => x.push_rule_id == PUSHRULEID && x.ordinal == 1);
|
||||
try
|
||||
{
|
||||
|
||||
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
||||
if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
||||
List<PrdMoTask>? moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
||||
if (moTaskList?.Count > 1)
|
||||
{
|
||||
throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
||||
}
|
||||
|
||||
if (moTaskList?.Count > 0)
|
||||
{
|
||||
|
||||
@@ -226,23 +241,25 @@ namespace Tnb.ProductionMgr
|
||||
cancelCloseDown.create_time = DateTime.Now;
|
||||
cancelCloseDown.closedown_start_time = DateTime.Now;
|
||||
|
||||
await _db.Insertable(cancelCloseDown).ExecuteCommandAsync();
|
||||
_ = await _db.Insertable(cancelCloseDown).ExecuteCommandAsync();
|
||||
|
||||
var record = cancelCloseDown.Adapt<PrdCancelClosedownRecord>();
|
||||
PrdCancelClosedownRecord record = cancelCloseDown.Adapt<PrdCancelClosedownRecord>();
|
||||
record.eqp_code = eqp?.code;
|
||||
record.eqp_name = eqp?.name;
|
||||
await _db.Insertable(record).ExecuteCommandAsync();
|
||||
_ = await _db.Insertable(record).ExecuteCommandAsync();
|
||||
|
||||
var moldId = moTaskList.First().mold_id;
|
||||
string? moldId = moTaskList.First().mold_id;
|
||||
if (!moldId.IsNullOrEmpty())
|
||||
{
|
||||
var mold = await _moldService.GetListById(moldId);
|
||||
var maintaindTask = new ToolMoldMaintainTask();
|
||||
maintaindTask.mold_id = moldId;
|
||||
maintaindTask.code = mold?.mold_code ?? "";
|
||||
maintaindTask.create_id = _userManager.UserId;
|
||||
maintaindTask.status = DictConst.UnMaintainStatusCode;
|
||||
maintaindTask.create_time = DateTime.Now;
|
||||
ToolMolds mold = await _moldService.GetListById(moldId);
|
||||
ToolMoldMaintainTask maintaindTask = new()
|
||||
{
|
||||
mold_id = moldId,
|
||||
code = mold?.mold_code ?? "",
|
||||
create_id = _userManager.UserId,
|
||||
status = DictConst.UnMaintainStatusCode,
|
||||
create_time = DateTime.Now
|
||||
};
|
||||
|
||||
await _maintainTaskService.Create(maintaindTask);
|
||||
}
|
||||
@@ -252,7 +269,7 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
List<PrdCancelClosedownReason> prdCancelClosedownReasons = await _db.Queryable<PrdCancelClosedownReason>().ToListAsync();
|
||||
string[] reasonArr = input.reason.Split(",");
|
||||
var reasonList = prdCancelClosedownReasons.Where(x => reasonArr.Contains(x.id)).Select(x => x.reason).ToList();
|
||||
List<string?> reasonList = prdCancelClosedownReasons.Where(x => reasonArr.Contains(x.id)).Select(x => x.reason).ToList();
|
||||
reason = string.Join(',', reasonList);
|
||||
|
||||
}
|
||||
@@ -269,16 +286,16 @@ namespace Tnb.ProductionMgr
|
||||
remark = input.remark,
|
||||
};
|
||||
|
||||
await _db.Insertable(eqpRepairApply).ExecuteCommandAsync();
|
||||
_ = await _db.Insertable(eqpRepairApply).ExecuteCommandAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(eqp.responsibler_id))
|
||||
{
|
||||
List<MessageSendModel> list = await _sendMessageService.SendTest(basPushRuleD.send_config_id);
|
||||
List<string> toUsers = JsonConvert.DeserializeObject<List<string>>(eqp.responsibler_id);
|
||||
|
||||
foreach (var item in list)
|
||||
foreach (MessageSendModel item in list)
|
||||
{
|
||||
foreach (var param in item.paramJson)
|
||||
foreach (MessageSendParam param in item.paramJson)
|
||||
{
|
||||
if (param.field == "equip_code")
|
||||
{
|
||||
@@ -288,15 +305,18 @@ namespace Tnb.ProductionMgr
|
||||
item.toUser = toUsers;
|
||||
}
|
||||
|
||||
foreach (var item in list)
|
||||
foreach (MessageSendModel item in list)
|
||||
{
|
||||
await _sendMessageService.SendMessage(item, new Dictionary<string, object>());
|
||||
_ = await _sendMessageService.SendMessage(item, new Dictionary<string, object>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else throw Oops.Oh(ErrorCode.COM1001);
|
||||
else
|
||||
{
|
||||
throw Oops.Oh(ErrorCode.COM1001);
|
||||
}
|
||||
});
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
@@ -312,23 +332,25 @@ namespace Tnb.ProductionMgr
|
||||
// string cron = $"0 {executeTime.Minute} {executeTime.Hour} {executeTime.Day} {executeTime.Month} ? {executeTime.Year}";
|
||||
string cron = $"0 {executeTime.Minute} {executeTime.Hour} {executeTime.Day} {executeTime.Month} ?";
|
||||
|
||||
var comtentModel = new ContentModel();
|
||||
// comtentModel.cron = (2 * 60).ToString();
|
||||
comtentModel.cron = cron;
|
||||
comtentModel.interfaceId = "";
|
||||
comtentModel.interfaceName = "";
|
||||
comtentModel.parameter = new List<InterfaceParameter>();
|
||||
comtentModel.localHostTaskId = "PushMsgTimeWorker/PushMsg";
|
||||
comtentModel.startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
|
||||
// comtentModel.endTime = DateTimeOffset.Now.AddSeconds(3).ToUnixTimeMilliseconds().ToString();
|
||||
comtentModel.TenantId = _userManager?.TenantId;
|
||||
comtentModel.TenantDbName = _userManager?.TenantDbName;
|
||||
comtentModel.ConnectionConfig = _userManager?.ConnectionConfig;
|
||||
comtentModel.Token = _userManager?.ToKen;
|
||||
|
||||
foreach (var item in sendModels)
|
||||
ContentModel comtentModel = new()
|
||||
{
|
||||
foreach (var param in item.paramJson)
|
||||
// comtentModel.cron = (2 * 60).ToString();
|
||||
cron = cron,
|
||||
interfaceId = "",
|
||||
interfaceName = "",
|
||||
parameter = new List<InterfaceParameter>(),
|
||||
localHostTaskId = "PushMsgTimeWorker/PushMsg",
|
||||
startTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(),
|
||||
// comtentModel.endTime = DateTimeOffset.Now.AddSeconds(3).ToUnixTimeMilliseconds().ToString();
|
||||
TenantId = _userManager?.TenantId,
|
||||
TenantDbName = _userManager?.TenantDbName,
|
||||
ConnectionConfig = _userManager?.ConnectionConfig,
|
||||
Token = _userManager?.ToKen
|
||||
};
|
||||
|
||||
foreach (MessageSendModel item in sendModels)
|
||||
{
|
||||
foreach (MessageSendParam param in item.paramJson)
|
||||
{
|
||||
if (param.field == "equip_code")
|
||||
{
|
||||
@@ -337,7 +359,7 @@ namespace Tnb.ProductionMgr
|
||||
}
|
||||
}
|
||||
|
||||
TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput()
|
||||
TimeTaskCrInput timeTaskCrInput = new()
|
||||
{
|
||||
enCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||
fullName = "临时推送消息" + DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||
@@ -352,7 +374,7 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
TimeTaskEntity timeTaskEntity = await _db.Queryable<TimeTaskEntity>().Where(x => x.EnCode == timeTaskCrInput.enCode).FirstAsync();
|
||||
|
||||
BasPushRuleLog basPushRuleLog = new BasPushRuleLog()
|
||||
BasPushRuleLog basPushRuleLog = new()
|
||||
{
|
||||
push_rule_id = PUSHRULEID,
|
||||
timetask_id = timeTaskEntity?.Id,
|
||||
@@ -361,7 +383,7 @@ namespace Tnb.ProductionMgr
|
||||
is_push = 1,
|
||||
};
|
||||
|
||||
await _db.Insertable<BasPushRuleLog>(basPushRuleLog).ExecuteCommandAsync();
|
||||
_ = await _db.Insertable<BasPushRuleLog>(basPushRuleLog).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,25 +406,33 @@ namespace Tnb.ProductionMgr
|
||||
[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");
|
||||
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 closeDown = await _db.Queryable<PrdCancelClosedown>().Where(it => it.eqp_id == input.eqp_id).OrderByDescending(it => it.closedown_start_time).FirstAsync();
|
||||
PrdCancelClosedown closeDown = await _db.Queryable<PrdCancelClosedown>().Where(it => it.eqp_id == input.eqp_id).OrderByDescending(it => it.closedown_start_time).FirstAsync();
|
||||
if (closeDown != null)
|
||||
{
|
||||
closeDown.closedown_end_time = DateTime.Now;
|
||||
await _db.Updateable(closeDown).ExecuteCommandAsync();
|
||||
var record = closeDown.Adapt<PrdCancelClosedownRecord>();
|
||||
_ = await _db.Updateable(closeDown).ExecuteCommandAsync();
|
||||
PrdCancelClosedownRecord record = closeDown.Adapt<PrdCancelClosedownRecord>();
|
||||
//计算停机时间间隔,以小时为单位
|
||||
if (record.closedown_start_time.HasValue && record.closedown_end_time.HasValue)
|
||||
{
|
||||
var interval = record.closedown_end_time.Value.Subtract(record.closedown_start_time.Value).TotalHours;
|
||||
double interval = record.closedown_end_time.Value.Subtract(record.closedown_start_time.Value).TotalHours;
|
||||
record.closedown_time = Convert.ToDecimal(interval);
|
||||
}
|
||||
await _db.Updateable(record).ExecuteCommandAsync();
|
||||
_ = await _db.Updateable(record).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
@@ -417,7 +447,7 @@ namespace Tnb.ProductionMgr
|
||||
|
||||
private async Task<List<MessageSendModel>> GetSendParamJson(string id)
|
||||
{
|
||||
var list = await _db.Queryable<MessageSendTemplateEntity, MessageTemplateEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id))
|
||||
List<MessageSendModel> list = await _db.Queryable<MessageSendTemplateEntity, MessageTemplateEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id))
|
||||
.Where((a, b) => a.SendConfigId == id && a.DeleteMark == null && b.DeleteMark == null)
|
||||
.Select((a, b) => new MessageSendModel
|
||||
{
|
||||
@@ -428,13 +458,12 @@ namespace Tnb.ProductionMgr
|
||||
sendConfigId = a.SendConfigId,
|
||||
templateId = a.TemplateId,
|
||||
}).ToListAsync();
|
||||
foreach (var item in list)
|
||||
foreach (MessageSendModel? item in list)
|
||||
{
|
||||
// 是否存在参数.
|
||||
var flag = await _db.Queryable<MessageSmsFieldEntity>().AnyAsync(x => x.TemplateId == item.templateId && x.DeleteMark == null);
|
||||
if (flag)
|
||||
{
|
||||
item.paramJson = await _db.Queryable<MessageTemplateParamEntity, MessageTemplateEntity, MessageSmsFieldEntity>((a, b, c) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id, JoinType.Left, a.TemplateId == c.TemplateId))
|
||||
bool flag = await _db.Queryable<MessageSmsFieldEntity>().AnyAsync(x => x.TemplateId == item.templateId && x.DeleteMark == null);
|
||||
item.paramJson = flag
|
||||
? await _db.Queryable<MessageTemplateParamEntity, MessageTemplateEntity, MessageSmsFieldEntity>((a, b, c) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id, JoinType.Left, a.TemplateId == c.TemplateId))
|
||||
.Where((a, b, c) => a.TemplateId == item.templateId && a.DeleteMark == null && b.DeleteMark == null && a.Field == c.Field && a.Field != "@flowLink")
|
||||
.Select((a, b) => new MessageSendParam
|
||||
{
|
||||
@@ -445,11 +474,8 @@ namespace Tnb.ProductionMgr
|
||||
templateId = a.TemplateId,
|
||||
templateName = b.FullName,
|
||||
templateType = b.TemplateType
|
||||
}).ToListAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.paramJson = await _db.Queryable<MessageTemplateParamEntity, MessageTemplateEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id))
|
||||
}).ToListAsync()
|
||||
: await _db.Queryable<MessageTemplateParamEntity, MessageTemplateEntity>((a, b) => new JoinQueryInfos(JoinType.Left, a.TemplateId == b.Id))
|
||||
.Where((a, b) => a.TemplateId == item.templateId && a.DeleteMark == null && b.DeleteMark == null && a.Field != "@flowLink")
|
||||
.Where((a, b) => b.Title.Contains(a.Field) || b.Content.Contains(a.Field))
|
||||
.Select((a, b) => new MessageSendParam
|
||||
@@ -462,7 +488,6 @@ namespace Tnb.ProductionMgr
|
||||
templateName = b.FullName,
|
||||
templateType = b.TemplateType
|
||||
}).ToListAsync();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user