Merge branch 'dev' of https://git.tuotong-tech.com/tnb/tnb.server into dev
This commit is contained in:
52
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleD.cs
Normal file
52
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleD.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using JNPF.Common.Contracts;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送规则子表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("bas_push_rule_d")]
|
||||||
|
public partial class BasPushRuleD : BaseEntity<string>
|
||||||
|
{
|
||||||
|
public BasPushRuleD()
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 推送规则主表id
|
||||||
|
/// </summary>
|
||||||
|
public string push_rule_id { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送人id
|
||||||
|
/// </summary>
|
||||||
|
public string? user_ids { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送角色id
|
||||||
|
/// </summary>
|
||||||
|
public string? role_ids { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送岗位id
|
||||||
|
/// </summary>
|
||||||
|
public string? position_ids { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 间隔(分)
|
||||||
|
/// </summary>
|
||||||
|
public int interval { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送配置id
|
||||||
|
/// </summary>
|
||||||
|
public string? send_config_id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 排序
|
||||||
|
/// </summary>
|
||||||
|
public long? ordinal { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
72
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleH.cs
Normal file
72
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleH.cs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using JNPF.Common.Contracts;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送规则主表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("bas_push_rule_h")]
|
||||||
|
public partial class BasPushRuleH : BaseEntity<string>
|
||||||
|
{
|
||||||
|
public BasPushRuleH()
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 编码
|
||||||
|
/// </summary>
|
||||||
|
public string code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 名称
|
||||||
|
/// </summary>
|
||||||
|
public string name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否启用
|
||||||
|
/// </summary>
|
||||||
|
public int enabled { 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 string? org_id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程任务Id
|
||||||
|
/// </summary>
|
||||||
|
public string? f_flowtaskid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 流程引擎Id
|
||||||
|
/// </summary>
|
||||||
|
public string? f_flowid { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
42
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleLog.cs
Normal file
42
BasicData/Tnb.BasicData.Entities/Entity/BasPushRuleLog.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using JNPF.Common.Contracts;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData.Entities;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 定时消息推送log
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable("bas_push_rule_log")]
|
||||||
|
public partial class BasPushRuleLog : BaseEntity<string>
|
||||||
|
{
|
||||||
|
public BasPushRuleLog()
|
||||||
|
{
|
||||||
|
id = SnowflakeIdHelper.NextId();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 推送规则id
|
||||||
|
/// </summary>
|
||||||
|
public string push_rule_id { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 定时任务id
|
||||||
|
/// </summary>
|
||||||
|
public string timetask_id { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 业务主键id
|
||||||
|
/// </summary>
|
||||||
|
public string biz_id { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 要推送的层级
|
||||||
|
/// </summary>
|
||||||
|
public long ordinal { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否推送
|
||||||
|
/// </summary>
|
||||||
|
public int is_push { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
15
BasicData/Tnb.BasicData.Interfaces/IBasPushRuleLogService.cs
Normal file
15
BasicData/Tnb.BasicData.Interfaces/IBasPushRuleLogService.cs
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
namespace Tnb.BasicData.Interfaces
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 推送记录服务
|
||||||
|
/// </summary>
|
||||||
|
public interface IBasPushRuleLogService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 停止推送
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dic"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Task<dynamic> Stop(Dictionary<string, string> dic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,7 +92,7 @@ namespace Tnb.BasicData
|
|||||||
{
|
{
|
||||||
var db = _repository.AsSugarClient();
|
var db = _repository.AsSugarClient();
|
||||||
BasMbom mbom = await _repository.GetSingleAsync(x => x.id == id);
|
BasMbom mbom = await _repository.GetSingleAsync(x => x.id == id);
|
||||||
List<BasMbomProcess> processes = await db.Queryable<BasMbomProcess>().Where(x => x.mbom_id == id).ToListAsync();
|
List<BasMbomProcess> processes = await db.Queryable<BasMbomProcess>().Where(x => x.mbom_id == id).OrderBy(x=>x.ordinal).ToListAsync();
|
||||||
List<BasMbomInput> inputs = await db.Queryable<BasMbomInput>().Where(x => x.mbom_id == id).ToListAsync();
|
List<BasMbomInput> inputs = await db.Queryable<BasMbomInput>().Where(x => x.mbom_id == id).ToListAsync();
|
||||||
List<BasMbomOutput> outputs = await db.Queryable<BasMbomOutput>().Where(x => x.mbom_id == id).ToListAsync();
|
List<BasMbomOutput> outputs = await db.Queryable<BasMbomOutput>().Where(x => x.mbom_id == id).ToListAsync();
|
||||||
MbomDataOutput mbomDataOutput = new MbomDataOutput();
|
MbomDataOutput mbomDataOutput = new MbomDataOutput();
|
||||||
|
|||||||
44
BasicData/Tnb.BasicData/BasPushRuleLogService.cs
Normal file
44
BasicData/Tnb.BasicData/BasPushRuleLogService.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.DependencyInjection;
|
||||||
|
using JNPF.DynamicApiController;
|
||||||
|
using JNPF.VisualDev.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData.Entities;
|
||||||
|
using Tnb.BasicData.Interfaces;
|
||||||
|
|
||||||
|
namespace Tnb.BasicData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 推送记录服务
|
||||||
|
/// </summary>
|
||||||
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 1102)]
|
||||||
|
[Route("api/[area]/[controller]/[action]")]
|
||||||
|
public class BasPushRuleLogService : IBasPushRuleLogService, IDynamicApiController, ITransient
|
||||||
|
{
|
||||||
|
private readonly ISqlSugarRepository<BasPushRuleLog> _repository;
|
||||||
|
private readonly DataBaseManager _dbManager;
|
||||||
|
private readonly IUserManager _userManager;
|
||||||
|
private readonly IRunService _runService;
|
||||||
|
private readonly IVisualDevService _visualDevService;
|
||||||
|
|
||||||
|
public BasPushRuleLogService(
|
||||||
|
ISqlSugarRepository<BasPushRuleLog> repository,
|
||||||
|
IUserManager userManager)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_userManager = userManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public async Task<dynamic> Stop(Dictionary<string, string> dic)
|
||||||
|
{
|
||||||
|
string id = dic["id"];
|
||||||
|
await _repository.UpdateAsync(x => new BasPushRuleLog()
|
||||||
|
{
|
||||||
|
is_push = 0,
|
||||||
|
}, x => x.biz_id == id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -198,4 +198,9 @@ public partial class EqpEquipment : BaseEntity<string>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime? warranty_end_time { get; set; }
|
public DateTime? warranty_end_time { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 责任人
|
||||||
|
/// </summary>
|
||||||
|
public string? responsibler_id { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,4 +154,14 @@ public partial class EqpRepairApply : BaseEntity<string>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? repair_img { get; set; }
|
public string? repair_img { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生产任务单id
|
||||||
|
/// </summary>
|
||||||
|
public string? mo_task_id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 生产任务单号
|
||||||
|
/// </summary>
|
||||||
|
public string? mo_task_code { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Aop.Api.Domain;
|
using Aop.Api.Domain;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Dtos.Message;
|
||||||
using JNPF.Common.Enums;
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
@@ -13,10 +14,17 @@ using JNPF.DependencyInjection;
|
|||||||
using JNPF.DynamicApiController;
|
using JNPF.DynamicApiController;
|
||||||
using JNPF.FriendlyException;
|
using JNPF.FriendlyException;
|
||||||
using JNPF.Logging;
|
using JNPF.Logging;
|
||||||
|
using JNPF.Message.Entitys.Entity;
|
||||||
|
using JNPF.Message.Service;
|
||||||
using JNPF.Systems.Entitys.Permission;
|
using JNPF.Systems.Entitys.Permission;
|
||||||
|
using JNPF.Systems.Entitys.System;
|
||||||
using JNPF.Systems.Interfaces.System;
|
using JNPF.Systems.Interfaces.System;
|
||||||
|
using JNPF.TaskScheduler;
|
||||||
|
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
|
||||||
|
using JNPF.TaskScheduler.Entitys.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Tnb.BasicData;
|
using Tnb.BasicData;
|
||||||
using Tnb.EquipMgr.Entities;
|
using Tnb.EquipMgr.Entities;
|
||||||
@@ -25,6 +33,8 @@ using Tnb.EquipMgr.Interfaces;
|
|||||||
using Tnb.ProductionMgr.Entities;
|
using Tnb.ProductionMgr.Entities;
|
||||||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
||||||
using Tnb.ProductionMgr.Interfaces;
|
using Tnb.ProductionMgr.Interfaces;
|
||||||
|
using Tnb.BasicData.Entities;
|
||||||
|
using MessageTemplateEntity = JNPF.Message.Entitys.Entity.MessageTemplateEntity;
|
||||||
|
|
||||||
namespace Tnb.ProductionMgr
|
namespace Tnb.ProductionMgr
|
||||||
{
|
{
|
||||||
@@ -42,9 +52,12 @@ namespace Tnb.ProductionMgr
|
|||||||
private readonly IPrdMoTaskService _prdMoTaskService;
|
private readonly IPrdMoTaskService _prdMoTaskService;
|
||||||
private readonly IUserManager _userManager;
|
private readonly IUserManager _userManager;
|
||||||
private readonly IBillRullService _billRullService;
|
private readonly IBillRullService _billRullService;
|
||||||
|
private readonly TimeTaskService _timeTaskService;
|
||||||
|
private SendMessageService _sendMessageService;
|
||||||
|
|
||||||
private static Dictionary<string, object> _dicWorkStationAndShopRelacion = new Dictionary<string, object>();
|
private static Dictionary<string, object> _dicWorkStationAndShopRelacion = new Dictionary<string, object>();
|
||||||
private static Dictionary<string, object> _dicWorkShop = new Dictionary<string, object>();
|
private static Dictionary<string, object> _dicWorkShop = new Dictionary<string, object>();
|
||||||
|
private const string PUSHRULEID = "27121606262805";//异常停机的推送规则id
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -54,6 +67,8 @@ namespace Tnb.ProductionMgr
|
|||||||
IToolMoldsService moldsService,
|
IToolMoldsService moldsService,
|
||||||
IToolMoldMaintainTaskService maintainTaskService,
|
IToolMoldMaintainTaskService maintainTaskService,
|
||||||
IBillRullService billRullService,
|
IBillRullService billRullService,
|
||||||
|
TimeTaskService timeTaskService,
|
||||||
|
SendMessageService sendMessageService,
|
||||||
IUserManager userManager
|
IUserManager userManager
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -62,6 +77,8 @@ namespace Tnb.ProductionMgr
|
|||||||
_moldService = moldsService;
|
_moldService = moldsService;
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_billRullService = billRullService;
|
_billRullService = billRullService;
|
||||||
|
_timeTaskService = timeTaskService;
|
||||||
|
_sendMessageService = sendMessageService;
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -194,77 +211,175 @@ namespace Tnb.ProductionMgr
|
|||||||
{
|
{
|
||||||
if (input == null) throw new ArgumentNullException("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.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;
|
||||||
|
BasPushRuleD basPushRuleD = await _db.Queryable<BasPushRuleD>().FirstAsync(x => x.push_rule_id == PUSHRULEID && x.ordinal == 1);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _db.Ado.BeginTranAsync();
|
|
||||||
|
|
||||||
var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
DbResult<bool> result = await _db.Ado.UseTranAsync(async () =>
|
||||||
if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
|
||||||
if (moTaskList?.Count > 0)
|
|
||||||
{
|
{
|
||||||
var cancelCloseDown = input.Adapt<PrdCancelClosedown>();
|
var moTaskList = await _prdMoTaskService.GetListByEqpId(input.eqp_id);
|
||||||
cancelCloseDown.id = SnowflakeIdHelper.NextId();
|
if (moTaskList?.Count > 1) throw new AppFriendlyException($"设备{input.eqp_id},目前有两条进行中的生产任务", 500);
|
||||||
cancelCloseDown.eqp_id = input.eqp_id;
|
if (moTaskList?.Count > 0)
|
||||||
cancelCloseDown.create_id = _userManager.UserId;
|
|
||||||
cancelCloseDown.create_time = DateTime.Now;
|
|
||||||
cancelCloseDown.closedown_start_time = DateTime.Now;
|
|
||||||
|
|
||||||
await _db.Insertable(cancelCloseDown).ExecuteCommandAsync();
|
|
||||||
var eqp = await _db.Queryable<EqpEquipment>().FirstAsync(it => it.id == input.eqp_id);
|
|
||||||
var record = cancelCloseDown.Adapt<PrdCancelClosedownRecord>();
|
|
||||||
record.eqp_code = eqp?.code;
|
|
||||||
record.eqp_name = eqp?.name;
|
|
||||||
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 = mold.mold_code;
|
|
||||||
maintaindTask.create_id = _userManager.UserId;
|
|
||||||
maintaindTask.status = DictConst.UnMaintainStatusCode;
|
|
||||||
maintaindTask.create_time = DateTime.Now;
|
|
||||||
|
|
||||||
await _maintainTaskService.Create(maintaindTask);
|
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>();
|
||||||
|
record.eqp_code = eqp?.code;
|
||||||
|
record.eqp_name = eqp?.name;
|
||||||
|
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 = mold?.mold_code ?? "";
|
||||||
|
maintaindTask.create_id = _userManager.UserId;
|
||||||
|
maintaindTask.status = DictConst.UnMaintainStatusCode;
|
||||||
|
maintaindTask.create_time = DateTime.Now;
|
||||||
|
|
||||||
|
await _maintainTaskService.Create(maintaindTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
string reason = "";
|
||||||
|
if (!string.IsNullOrEmpty(input.reason))
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
reason = string.Join(',', reasonList);
|
||||||
|
|
||||||
|
}
|
||||||
|
string code = await _billRullService.GetBillNumber("EqpRepair");
|
||||||
|
eqpRepairApply = new EqpRepairApply()
|
||||||
|
{
|
||||||
|
code = code,
|
||||||
|
name = eqp.name + "停机",
|
||||||
|
equip_id = input.eqp_id,
|
||||||
|
status = Tnb.EquipMgr.RepairApplyStatus.TOBEEXECUTED,
|
||||||
|
description = reason,
|
||||||
|
create_id = _userManager.UserId,
|
||||||
|
create_time = DateTime.Now,
|
||||||
|
remark = input.remark,
|
||||||
|
};
|
||||||
|
|
||||||
|
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 (var param in item.paramJson)
|
||||||
|
{
|
||||||
|
if (param.field=="equip_code")
|
||||||
|
{
|
||||||
|
param.value = eqp.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item.toUser = toUsers;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
await _sendMessageService.SendMessage(item, new Dictionary<string, object>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string reason = "";
|
|
||||||
if (!string.IsNullOrEmpty(input.reason))
|
|
||||||
{
|
|
||||||
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();
|
|
||||||
reason = string.Join(',', reasonList);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
string code = await _billRullService.GetBillNumber("EqpRepair");
|
else throw Oops.Oh(ErrorCode.COM1001);
|
||||||
EqpRepairApply eqpRepairApply = new EqpRepairApply()
|
});
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
BasPushRuleH basPushRuleH = await _db.Queryable<BasPushRuleH>().SingleAsync(x=>x.id==PUSHRULEID);
|
||||||
|
if (basPushRuleH?.enabled == 1)
|
||||||
{
|
{
|
||||||
code = code,
|
string sendConfigId = basPushRuleD?.send_config_id ?? "";
|
||||||
name = eqp.name + "停机",
|
List<MessageSendModel> sendModels = await GetSendParamJson(sendConfigId);
|
||||||
equip_id = input.eqp_id,
|
|
||||||
status = Tnb.EquipMgr.RepairApplyStatus.TOBEEXECUTED,
|
|
||||||
description = reason,
|
|
||||||
create_id = _userManager.UserId,
|
|
||||||
create_time = DateTime.Now,
|
|
||||||
remark = input.remark,
|
|
||||||
};
|
|
||||||
|
|
||||||
await _db.Insertable(eqpRepairApply).ExecuteCommandAsync();
|
if (sendModels != null && sendModels.Count > 0)
|
||||||
|
{
|
||||||
|
DateTime executeTime = DateTime.Now.AddMinutes(basPushRuleD.interval);
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
foreach (var param in item.paramJson)
|
||||||
|
{
|
||||||
|
if (param.field == "equip_code")
|
||||||
|
{
|
||||||
|
param.value = eqp?.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput()
|
||||||
|
{
|
||||||
|
enCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
fullName = "临时推送消息" + DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
executeType = "3",
|
||||||
|
executeContent = comtentModel.ToJsonString(),
|
||||||
|
description = JsonConvert.SerializeObject(sendModels[0].paramJson),
|
||||||
|
sortCode = 9999,
|
||||||
|
enabledMark = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
await _timeTaskService.Create(timeTaskCrInput,false);
|
||||||
|
|
||||||
|
TimeTaskEntity timeTaskEntity = await _db.Queryable<TimeTaskEntity>().Where(x => x.EnCode == timeTaskCrInput.enCode).FirstAsync();
|
||||||
|
|
||||||
|
BasPushRuleLog basPushRuleLog = new BasPushRuleLog()
|
||||||
|
{
|
||||||
|
push_rule_id = PUSHRULEID,
|
||||||
|
timetask_id = timeTaskEntity?.Id,
|
||||||
|
biz_id = eqpRepairApply.id,
|
||||||
|
ordinal = 1,
|
||||||
|
is_push = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
await _db.Insertable<BasPushRuleLog>(basPushRuleLog).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else throw Oops.Oh(ErrorCode.COM1001);
|
|
||||||
|
|
||||||
await _db.Ado.CommitTranAsync();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error("停机开始失败", ex);
|
Log.Error("停机开始失败", ex);
|
||||||
await _db.Ado.RollbackTranAsync();
|
// await _db.Ado.RollbackTranAsync();
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 停机结束
|
/// 停机结束
|
||||||
@@ -304,5 +419,57 @@ namespace Tnb.ProductionMgr
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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))
|
||||||
|
.Where((a, b) => a.SendConfigId == id && a.DeleteMark == null && b.DeleteMark == null)
|
||||||
|
.Select((a, b) => new MessageSendModel
|
||||||
|
{
|
||||||
|
accountConfigId = a.AccountConfigId,
|
||||||
|
id = a.Id,
|
||||||
|
messageType = SqlFunc.Subqueryable<MessageDataTypeEntity>().Where(u => u.Type == "1" && u.EnCode == a.MessageType).Select(u => u.FullName),
|
||||||
|
msgTemplateName = b.FullName,
|
||||||
|
sendConfigId = a.SendConfigId,
|
||||||
|
templateId = a.TemplateId,
|
||||||
|
}).ToListAsync();
|
||||||
|
foreach (var 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))
|
||||||
|
.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
|
||||||
|
{
|
||||||
|
field = a.Field,
|
||||||
|
fieldName = a.FieldName,
|
||||||
|
id = a.Id,
|
||||||
|
templateCode = b.TemplateCode,
|
||||||
|
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))
|
||||||
|
.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
|
||||||
|
{
|
||||||
|
field = a.Field,
|
||||||
|
fieldName = a.FieldName,
|
||||||
|
id = a.Id,
|
||||||
|
templateCode = b.TemplateCode,
|
||||||
|
templateId = a.TemplateId,
|
||||||
|
templateName = b.FullName,
|
||||||
|
templateType = b.TemplateType
|
||||||
|
}).ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
|
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
|
||||||
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Interfaces\Tnb.EquipMgr.Interfaces.csproj" />
|
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Interfaces\Tnb.EquipMgr.Interfaces.csproj" />
|
||||||
|
<ProjectReference Include="..\..\taskschedule\Tnb.TaskScheduler\Tnb.TaskScheduler.csproj" />
|
||||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
|
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
|
||||||
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
|
<ProjectReference Include="..\..\WarehouseMgr\Tnb.WarehouseMgr.Entities\Tnb.WarehouseMgr.Entities.csproj" />
|
||||||
<ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
|
<ProjectReference Include="..\Tnb.ProductionMgr.Interfaces\Tnb.ProductionMgr.Interfaces.csproj" />
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class UserManager : IUserManager, IScoped
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserId
|
public string UserId
|
||||||
{
|
{
|
||||||
get => _user.FindFirst(ClaimConst.CLAINMUSERID)?.Value;
|
get => _user?.FindFirst(ClaimConst.CLAINMUSERID)?.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -128,7 +128,7 @@ public class UserManager : IUserManager, IScoped
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ConnectionConfigOptions ConnectionConfig
|
public ConnectionConfigOptions ConnectionConfig
|
||||||
{
|
{
|
||||||
get => _user.FindFirst(ClaimConst.CONNECTIONCONFIG)?.Value.ToObject<ConnectionConfigOptions>();
|
get => _user?.FindFirst(ClaimConst.CONNECTIONCONFIG)?.Value.ToObject<ConnectionConfigOptions>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -22,4 +22,9 @@ public enum RequestType
|
|||||||
/// POST请求.
|
/// POST请求.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Run = 2,
|
Run = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 本地方法
|
||||||
|
/// </summary>
|
||||||
|
Local = 3,
|
||||||
}
|
}
|
||||||
@@ -410,13 +410,17 @@ public class MessageService : IMessageService, IDynamicApiController, ITransient
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//modifyby zhoukeda 20230704 定时任务发起的推送消息没有user
|
||||||
|
string userManagerUserId = _userManager.UserId ?? "";
|
||||||
|
string userManagerTenantId = _userManager.TenantId ?? "";
|
||||||
|
|
||||||
MessageEntity entity = new MessageEntity();
|
MessageEntity entity = new MessageEntity();
|
||||||
entity.Id = SnowflakeIdHelper.NextId();
|
entity.Id = SnowflakeIdHelper.NextId();
|
||||||
entity.Title = title;
|
entity.Title = title;
|
||||||
entity.BodyText = bodyText;
|
entity.BodyText = bodyText;
|
||||||
entity.Type = type;
|
entity.Type = type;
|
||||||
entity.LastModifyTime = DateTime.Now;
|
entity.LastModifyTime = DateTime.Now;
|
||||||
entity.LastModifyUserId = _userManager.UserId;
|
entity.LastModifyUserId = userManagerUserId;
|
||||||
entity.FlowType = flowType.ParseToInt();
|
entity.FlowType = flowType.ParseToInt();
|
||||||
List<MessageReceiveEntity> receiveEntityList = toUserIds
|
List<MessageReceiveEntity> receiveEntityList = toUserIds
|
||||||
.Select(x => new MessageReceiveEntity()
|
.Select(x => new MessageReceiveEntity()
|
||||||
@@ -434,7 +438,7 @@ public class MessageService : IMessageService, IDynamicApiController, ITransient
|
|||||||
{
|
{
|
||||||
var userId = item.Replace("-delegate", string.Empty);
|
var userId = item.Replace("-delegate", string.Empty);
|
||||||
// 消息推送 - 指定用户
|
// 消息推送 - 指定用户
|
||||||
await _imHandler.SendMessageToUserAsync(string.Format("{0}-{1}", _userManager.TenantId, userId), new { method = "messagePush", messageType = 2, userId = _userManager.UserId, toUserId = toUserIds, title = entity.Title, unreadNoticeCount = 1, id = entity.Id }.ToJsonString());
|
await _imHandler.SendMessageToUserAsync(string.Format("{0}-{1}", userManagerTenantId, userId), new { method = "messagePush", messageType = 2, userId = userManagerUserId, toUserId = toUserIds, title = entity.Title, unreadNoticeCount = 1, id = entity.Id }.ToJsonString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
233
taskschedule/Tnb.TaskScheduler/Listener/PushMsgTimeWorker.cs
Normal file
233
taskschedule/Tnb.TaskScheduler/Listener/PushMsgTimeWorker.cs
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
using JNPF.Common.Core.Manager;
|
||||||
|
using JNPF.Common.Dtos.Message;
|
||||||
|
using JNPF.Common.Enums;
|
||||||
|
using JNPF.Common.Security;
|
||||||
|
using JNPF.Logging;
|
||||||
|
using JNPF.Message.Entitys.Entity;
|
||||||
|
using JNPF.Message.Service;
|
||||||
|
using JNPF.Systems.Entitys.Permission;
|
||||||
|
using JNPF.Systems.Entitys.System;
|
||||||
|
using JNPF.TaskScheduler.Entitys.Dto.TaskScheduler;
|
||||||
|
using JNPF.TaskScheduler.Entitys.Model;
|
||||||
|
using JNPF.TaskScheduler.Interfaces.TaskScheduler;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SqlSugar;
|
||||||
|
using Tnb.BasicData.Entities;
|
||||||
|
using MessageTemplateEntity = JNPF.Systems.Entitys.System.MessageTemplateEntity;
|
||||||
|
|
||||||
|
namespace JNPF.TaskScheduler.Listener
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 根据推送规则推送消息
|
||||||
|
/// </summary>
|
||||||
|
public class PushMsgTimeWorker : ISpareTimeWorker
|
||||||
|
{
|
||||||
|
private ISqlSugarRepository<BasPushRuleH> _repository => App.GetService<ISqlSugarRepository<BasPushRuleH>>();
|
||||||
|
|
||||||
|
private TimeTaskService _timeTaskService => App.GetService<TimeTaskService>();
|
||||||
|
private SendMessageService _sendMessageService => App.GetService<SendMessageService>();
|
||||||
|
private IUserManager _userManager => App.GetService<IUserManager>();
|
||||||
|
|
||||||
|
|
||||||
|
// [SpareTime(2*60, "推送消息", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false,DoOnce = true)]
|
||||||
|
[SpareTime("* * * * * ?", "推送消息", ExecuteType = SpareTimeExecuteTypes.Serial,StartNow = false,DoOnce = true)]
|
||||||
|
public async void PushMsg(SpareTimer timer, long count)
|
||||||
|
{
|
||||||
|
// Log.Information("----------------------开始生成特种设备检验计划----------------------");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var db = _repository.AsSugarClient();
|
||||||
|
BasPushRuleLog basPushRuleLog = await db.Queryable<BasPushRuleLog>().FirstAsync(x => x.timetask_id == timer.WorkerName);
|
||||||
|
|
||||||
|
|
||||||
|
if (basPushRuleLog?.is_push == 1)
|
||||||
|
{
|
||||||
|
BasPushRuleH basPushRuleH = await db.Queryable<BasPushRuleH>().FirstAsync(x=>x.id==basPushRuleLog.push_rule_id);
|
||||||
|
BasPushRuleD basPushRuleD = await db.Queryable<BasPushRuleD>().FirstAsync(x=>x.push_rule_id==basPushRuleLog.push_rule_id && x.ordinal==basPushRuleLog.ordinal);
|
||||||
|
BasPushRuleD nextBasPushRuleD = await db.Queryable<BasPushRuleD>().FirstAsync(x=>x.push_rule_id==basPushRuleLog.push_rule_id && x.ordinal==basPushRuleLog.ordinal+1);
|
||||||
|
|
||||||
|
if (basPushRuleH?.enabled==1 && basPushRuleD != null)
|
||||||
|
{
|
||||||
|
TimeTaskEntity timeTaskEntity = await db.Queryable<TimeTaskEntity>().SingleAsync(x => x.Id == timer.WorkerName);
|
||||||
|
List<MessageSendModel> list = await _sendMessageService.SendTest(basPushRuleD.send_config_id);
|
||||||
|
List<string> toUsers = new List<string>();
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(basPushRuleD.user_ids))
|
||||||
|
{
|
||||||
|
toUsers.AddRange(JsonConvert.DeserializeObject<List<string>>(basPushRuleD.user_ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(basPushRuleD.position_ids))
|
||||||
|
{
|
||||||
|
|
||||||
|
toUsers.AddRange(db.Queryable<UserRelationEntity>().Where(x => basPushRuleD.position_ids.Contains(x.Id)).Select(s => s.UserId).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(basPushRuleD.role_ids))
|
||||||
|
{
|
||||||
|
|
||||||
|
toUsers.AddRange(db.Queryable<UserRelationEntity>().Where(x => basPushRuleD.role_ids.Contains(x.Id)).Select(s => s.UserId).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toUsers.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
item.paramJson = JsonConvert.DeserializeObject<List<MessageSendParam>>(timeTaskEntity.Description);
|
||||||
|
item.toUser = toUsers;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
await _sendMessageService.SendMessage(item, new Dictionary<string, object>());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextBasPushRuleD != null)
|
||||||
|
{
|
||||||
|
DateTime executeTime = DateTime.Now.AddMinutes(nextBasPushRuleD.interval);
|
||||||
|
string cron = $"0 {executeTime.Minute} {executeTime.Hour} {executeTime.Day} {executeTime.Month} ?";
|
||||||
|
|
||||||
|
var comtentModel = new ContentModel();
|
||||||
|
var timeTaskComtentModel = JsonConvert.DeserializeObject<ContentModel>(timeTaskEntity.ExecuteContent);
|
||||||
|
// comtentModel.cron = (nextBasPushRuleD.interval * 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(nextBasPushRuleD.interval+1).ToUnixTimeMilliseconds().ToString();
|
||||||
|
// comtentModel.TenantId = _userManager?.TenantId;
|
||||||
|
// comtentModel.TenantDbName = _userManager?.TenantDbName;
|
||||||
|
// comtentModel.ConnectionConfig = _userManager?.ConnectionConfig;
|
||||||
|
// comtentModel.Token = _userManager?.ToKen;
|
||||||
|
comtentModel.TenantId = timeTaskComtentModel?.TenantId;
|
||||||
|
comtentModel.TenantDbName = timeTaskComtentModel?.TenantDbName;
|
||||||
|
comtentModel.ConnectionConfig = timeTaskComtentModel?.ConnectionConfig;
|
||||||
|
comtentModel.Token = timeTaskComtentModel?.Token;
|
||||||
|
|
||||||
|
List<MessageSendModel> nextMessageList = await _sendMessageService.SendTest(nextBasPushRuleD.send_config_id);
|
||||||
|
List<MessageSendParam> messageSendParams = JsonConvert.DeserializeObject<List<MessageSendParam>>(timeTaskEntity.Description);
|
||||||
|
string paramJson = "";
|
||||||
|
foreach (var item in nextMessageList)
|
||||||
|
{
|
||||||
|
foreach (var param in item.paramJson)
|
||||||
|
{
|
||||||
|
var field = messageSendParams.FirstOrDefault(x=>x.fieldName==param.fieldName);
|
||||||
|
if (field != null)
|
||||||
|
{
|
||||||
|
param.value = field.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
paramJson = JsonConvert.SerializeObject(item.paramJson);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimeTaskEntity newTimeTaskEntity = new TimeTaskEntity()
|
||||||
|
// {
|
||||||
|
// EnCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
// FullName = "临时推送消息" + DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
// ExecuteType = RequestType.Local,
|
||||||
|
// ExecuteContent = comtentModel.ToJsonString(),
|
||||||
|
// ExecuteCycleJson = comtentModel.cron,
|
||||||
|
// Description = paramJson,
|
||||||
|
// CreatorTime = DateTime.Now,
|
||||||
|
// };
|
||||||
|
|
||||||
|
TimeTaskCrInput timeTaskCrInput = new TimeTaskCrInput()
|
||||||
|
{
|
||||||
|
enCode = DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
fullName = "临时推送消息" + DateTime.Now.ToString("yyyyMMddHHmmss"),
|
||||||
|
executeType = "3",
|
||||||
|
executeContent = comtentModel.ToJsonString(),
|
||||||
|
description = paramJson,
|
||||||
|
sortCode = 9999,
|
||||||
|
enabledMark = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
await _timeTaskService.Create(timeTaskCrInput,false);
|
||||||
|
TimeTaskEntity timeTaskEntityNew = await db.Queryable<TimeTaskEntity>().Where(x => x.EnCode == timeTaskCrInput.enCode).FirstAsync();
|
||||||
|
string newId = timeTaskEntityNew?.Id ?? "";
|
||||||
|
|
||||||
|
await db.Updateable<BasPushRuleLog>()
|
||||||
|
.SetColumns(x=>x.timetask_id==newId)
|
||||||
|
.SetColumns(x => x.ordinal == x.ordinal + 1)
|
||||||
|
.Where(x=>x.timetask_id==timer.WorkerName).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//进入次方法后删除次定时任务
|
||||||
|
// _timeTaskService.Delete(timer.WorkerName);
|
||||||
|
SpareTime.Cancel(timer.WorkerName);
|
||||||
|
await db.Deleteable<TimeTaskEntity>().Where(x => x.Id == timer.WorkerName).ExecuteCommandAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
|
Log.Error(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Log.Information("----------------------结束生成特种设备检验计划----------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<MessageSendModel> SendTest(string id)
|
||||||
|
{
|
||||||
|
var db = _repository.AsSugarClient();
|
||||||
|
var list = 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
|
||||||
|
{
|
||||||
|
accountConfigId = a.AccountConfigId,
|
||||||
|
id = a.Id,
|
||||||
|
messageType = SqlFunc.Subqueryable<MessageDataTypeEntity>().Where(u => u.Type == "1" && u.EnCode == a.MessageType).Select(u => u.FullName),
|
||||||
|
msgTemplateName = b.FullName,
|
||||||
|
sendConfigId = a.SendConfigId,
|
||||||
|
templateId = a.TemplateId,
|
||||||
|
}).ToList();
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
// 是否存在参数.
|
||||||
|
var flag = db.Queryable<MessageSmsFieldEntity>().Any(x => x.TemplateId == item.templateId && x.DeleteMark == null);
|
||||||
|
if (flag)
|
||||||
|
{
|
||||||
|
item.paramJson = db.Queryable<MessageTemplateParamEntity, JNPF.Message.Entitys.Entity.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
|
||||||
|
{
|
||||||
|
field = a.Field,
|
||||||
|
fieldName = a.FieldName,
|
||||||
|
id = a.Id,
|
||||||
|
templateCode = b.TemplateCode,
|
||||||
|
templateId = a.TemplateId,
|
||||||
|
templateName = b.FullName,
|
||||||
|
templateType = b.TemplateType
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
item.paramJson = db.Queryable<MessageTemplateParamEntity, JNPF.Message.Entitys.Entity.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
|
||||||
|
{
|
||||||
|
field = a.Field,
|
||||||
|
fieldName = a.FieldName,
|
||||||
|
id = a.Id,
|
||||||
|
templateCode = b.TemplateCode,
|
||||||
|
templateId = a.TemplateId,
|
||||||
|
templateName = b.FullName,
|
||||||
|
templateType = b.TemplateType
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -143,7 +143,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
|||||||
/// <param name="input">实体对象.</param>
|
/// <param name="input">实体对象.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("")]
|
[HttpPost("")]
|
||||||
public async Task Create([FromBody] TimeTaskCrInput input)
|
public async Task Create([FromBody] TimeTaskCrInput input,bool startNow = true)
|
||||||
{
|
{
|
||||||
if (await _repository.IsAnyAsync(x => (x.EnCode == input.enCode || x.FullName == input.fullName) && x.DeleteMark == null))
|
if (await _repository.IsAnyAsync(x => (x.EnCode == input.enCode || x.FullName == input.fullName) && x.DeleteMark == null))
|
||||||
throw Oops.Oh(ErrorCode.COM1004);
|
throw Oops.Oh(ErrorCode.COM1004);
|
||||||
@@ -162,7 +162,7 @@ public class TimeTaskService : ITimeTaskService, IDynamicApiController, ITransie
|
|||||||
_ = result ?? throw Oops.Oh(ErrorCode.COM1000);
|
_ = result ?? throw Oops.Oh(ErrorCode.COM1000);
|
||||||
|
|
||||||
// 添加到任务调度里
|
// 添加到任务调度里
|
||||||
AddTimerJob(result);
|
AddTimerJob(result,startNow);
|
||||||
//await AddJob(result);
|
//await AddJob(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Entities\Tnb.BasicData.Entities.csproj" />
|
||||||
<ProjectReference Include="..\..\common\Tnb.Common.Core\Tnb.Common.Core.csproj" />
|
<ProjectReference Include="..\..\common\Tnb.Common.Core\Tnb.Common.Core.csproj" />
|
||||||
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
|
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
|
||||||
|
<ProjectReference Include="..\..\message\Tnb.Message\Tnb.Message.csproj" />
|
||||||
<ProjectReference Include="..\..\system\Tnb.Systems.Interfaces\Tnb.Systems.Interfaces.csproj" />
|
<ProjectReference Include="..\..\system\Tnb.Systems.Interfaces\Tnb.Systems.Interfaces.csproj" />
|
||||||
<ProjectReference Include="..\Tnb.TaskScheduler.Interfaces\Tnb.TaskScheduler.Interfaces.csproj" />
|
<ProjectReference Include="..\Tnb.TaskScheduler.Interfaces\Tnb.TaskScheduler.Interfaces.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user