从山证v2.3.0拷贝
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.TaskEventModule.Dto
|
||||
{
|
||||
public class AddGuoXinPushDataTaskResponse
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
|
||||
public string ErrorMsg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 任务Id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计时间
|
||||
/// </summary>
|
||||
public int PredictTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.TaskEventModule.Dto
|
||||
{
|
||||
public class GuoXinDataPushEventLogDto
|
||||
{
|
||||
public int id { get; set; }
|
||||
|
||||
public string EventArgs { get; set; }
|
||||
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
public int Status { get; set; }
|
||||
|
||||
public string ErrorMsg { get; set; }
|
||||
|
||||
public string OptName { get; set; }
|
||||
|
||||
public DateTime? OptDate { get; set; }
|
||||
|
||||
public string DateSelect
|
||||
{
|
||||
get
|
||||
{
|
||||
return StartDate.ToString("yyyy.MM.dd") + "-" + EndDate.ToString("yyyy.MM.dd");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.TaskEventModule.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 国信金阳数据推送任务参数
|
||||
/// </summary>
|
||||
public class GuoXinJinYangPushDataTaskArg
|
||||
{
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
public DateTime EndDate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using BaseOUDAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Modules.TaskEventModule.Dto
|
||||
{
|
||||
public class SearchTaskEventRequest:BaseSearchReq
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace YLErp.Modules.TaskEventModule.Enum
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时任务事件状态
|
||||
/// </summary>
|
||||
public enum TaskEventStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待执行
|
||||
/// </summary>
|
||||
WaitExcute=0,
|
||||
|
||||
/// <summary>
|
||||
/// 执行中
|
||||
/// </summary>
|
||||
Excuting=1,
|
||||
|
||||
/// <summary>
|
||||
/// 执行失败
|
||||
/// </summary>
|
||||
ExcuteFaliure=2,
|
||||
|
||||
/// <summary>
|
||||
/// 执行完成
|
||||
/// </summary>
|
||||
Complete=3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace YLErp.Modules.TaskEventModule.Enum
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时任务事件类型
|
||||
/// </summary>
|
||||
public enum TaskEventType
|
||||
{
|
||||
/// <summary>
|
||||
/// 第三方数据推送
|
||||
/// </summary>
|
||||
ThirdPartyDataPush=0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
using BaseOUDAL;
|
||||
using YLErp.Core.DBModels;
|
||||
using YLErp.Modules.TagModule.Dto;
|
||||
using YLErp.Modules.TaskEventModule.Dto;
|
||||
using YLErp.Modules.TaskEventModule.Enum;
|
||||
|
||||
namespace YLErp.Modules.TaskEventModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时任务事件服务
|
||||
/// </summary>
|
||||
public class TaskEventService : YLBaseService
|
||||
{
|
||||
public TaskEventService(OptUserInfo userInfo) : base(userInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public task_event GetWaitExecuteTaskEventByEventType(TaskEventType eventType)
|
||||
{
|
||||
return DbContext.task_event.AsNoTracking().FirstOrDefault(p => p.EventType == (int)eventType && (p.Status == (int)TaskEventStatus.WaitExcute || p.Status == (int)TaskEventStatus.ExcuteFaliure));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public SearchListResult<GuoXinDataPushEventLogDto> GetGuoXinDataPushEventLogs(SearchTaskEventRequest req)
|
||||
{
|
||||
var predicate = PredicateBuilder.True<task_event>();
|
||||
predicate = predicate.And(p => p.EventType == (int)TaskEventType.ThirdPartyDataPush);
|
||||
if (string.IsNullOrEmpty(req.sidx))
|
||||
{
|
||||
req.sidx = "id";
|
||||
req.sord = "desc";
|
||||
}
|
||||
|
||||
var result= DbContext.task_event.Where(predicate).Select(p => new GuoXinDataPushEventLogDto
|
||||
{
|
||||
id = p.id,
|
||||
EventArgs = p.EventArgs,
|
||||
Status = p.Status,
|
||||
ErrorMsg = p.ErrorMsg,
|
||||
OptName = p.OptName,
|
||||
OptDate = p.OptDate
|
||||
}).ToSearchList<GuoXinDataPushEventLogDto>(req);
|
||||
if (result != null&& result.rows.Any())
|
||||
{
|
||||
result.rows?.ToList().ForEach(p =>
|
||||
{
|
||||
var argDto = JsonHelper.Deserialize<GuoXinJinYangPushDataTaskArg>(p.EventArgs);
|
||||
p.StartDate = argDto.StartDate;
|
||||
p.EndDate = argDto.EndDate;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置国信金阳数据推送任务
|
||||
/// </summary>
|
||||
/// <param name="arg"></param>
|
||||
/// <returns></returns>
|
||||
public AddGuoXinPushDataTaskResponse AddGuoXinPushDataTask(GuoXinJinYangPushDataTaskArg arg)
|
||||
{
|
||||
AddGuoXinPushDataTaskResponse response = new AddGuoXinPushDataTaskResponse() { Success = true };
|
||||
if (arg.StartDate > arg.EndDate)
|
||||
{
|
||||
response.Success = false;
|
||||
response.ErrorMsg = "日期选择区间有误,开始时间不能大于结束时间";
|
||||
return response;
|
||||
}
|
||||
task_event task = new task_event
|
||||
{
|
||||
EventType=(int)TaskEventType.ThirdPartyDataPush,
|
||||
EventArgs=JsonHelper.Serialize(arg),
|
||||
Status=(int)TaskEventStatus.WaitExcute
|
||||
};
|
||||
SetDBModelOpt(task);
|
||||
DbContext.task_event.Add(task);
|
||||
DbContext.SaveChanges();
|
||||
response.Id = task.id;
|
||||
response.PredictTime = (int)((arg.EndDate - arg.StartDate).TotalDays + 1) * 30 + 5;
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置定时任务处于执行中
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void SetTaskEventIsExcuting(int id)
|
||||
{
|
||||
var task = DbContext.task_event.FirstOrDefault(p => p.id==id);
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
task.Status = (int)TaskEventStatus.Excuting;
|
||||
SetDBModelOpt(task);
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置定时任务处于完成
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void SetTaskEventIsComplete(int id)
|
||||
{
|
||||
var task = DbContext.task_event.FirstOrDefault(p => p.id == id);
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
task.Status = (int)TaskEventStatus.Complete;
|
||||
task.ErrorMsg = "";
|
||||
//SetDBModelOpt(task);
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除执行成功的定时任务
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void DeleteExcuteSuccessTaskEvent(int id)
|
||||
{
|
||||
var task = DbContext.task_event.FirstOrDefault(p => p.id == id);
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DbContext.task_event.Remove(task);
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置定时任务事件执行失败
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="errorMsg"></param>
|
||||
public void SetTaskEventIsExcuteFaliure(int id,string errorMsg)
|
||||
{
|
||||
var task = DbContext.task_event.FirstOrDefault(p => p.id == id);
|
||||
if (task == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
task.Status = (int)TaskEventStatus.ExcuteFaliure;
|
||||
SetDBModelOpt(task);
|
||||
task.ErrorMsg= errorMsg;
|
||||
DbContext.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user