修改服务项目状态推送和取消

optimize
jianghaiqing 1 year ago
parent ebe4205944
commit 70135e22ab

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
/// 服务项目来源类型
/// </summary>
public enum TrackingSourceTypeEnum
{
/// <summary>
/// 自动
/// </summary>
[Description("自动")]
AUTO,
/// <summary>
/// 人工
/// </summary>
[Description("人工")]
MANUAL,
}
}

@ -2095,6 +2095,7 @@ namespace Myshipping.Application
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
ProjectList = model.ProjectCodes.Select(a=> new TrackingMessageMainProjectInfo
{
ServiceProjectCode = a,
@ -2185,6 +2186,7 @@ namespace Myshipping.Application
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
ProjectList = model.ProjectCodes.Select(a => new TrackingMessageMainProjectInfo
{
ServiceProjectCode = a,
@ -2195,7 +2197,7 @@ namespace Myshipping.Application
_logger.LogInformation("批次={no} 推送取消服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.CancelProject(msgInfo);
var rlt = await _serviceWorkFlowManageService.CancelStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
@ -2225,6 +2227,184 @@ namespace Myshipping.Application
}
#endregion
/// <summary>
/// 保存服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingValueAdded/SaveServiceStatus")]
public async Task<TaskManageOrderResultDto> SaveServiceStatus([FromBody] ModifyServiceProjectStatusDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true)
.First(a => a.Id == model.BookingId);
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废");
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.BookingId.ToString(),
BusiSystemCode = "BOOKING_ORDER",
MBlNo = bookingOrder.MBLNO,
VesselVoyno = $"{bookingOrder.VESSEL}/{bookingOrder.VOYNO}",
OrderNo = bookingOrder.BSNO,
PushType = TrackingPushTypeEnum.Status,
OperTenantId = bookingOrder.TenantId.Value,
OperTenantName = bookingOrder.TenantName,
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
StatusList = model.StatusCodes.Select(a => new TrackingMessageMainStatusInfo
{
StatusCode = a,
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送保存服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.PushStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "推送成功";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目状态推送失败,原因:{ex.Message}";
}
return result;
}
/// <summary>
/// 取消服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingValueAdded/CancelServiceStatus")]
public async Task<TaskManageOrderResultDto> CancelServiceStatus([FromBody] ModifyServiceProjectStatusDto model)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
var bookingOrder = _bookingOrderRepository.AsQueryable().Filter(null, true)
.First(a => a.Id == model.BookingId);
if (bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废");
_logger.LogInformation("批次={no} 请求保存服务项目 modifyjson={msg}", batchNo, JSON.Serialize(model));
TrackingMessageInfo msgInfo = new TrackingMessageInfo
{
Head = new TrackingMessageHeadInfo
{
GID = IDGen.NextID().ToString(),
MessageType = "PROJECT",
ReceiverId = "ServiceProjectStatus",
ReceiverName = "服务项目和状态",
SenderId = "BookingOrder",
SenderName = "海运订舱",
RequestDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
Version = "2.0",
RequestAction = "AddOrModify",
},
Main = new TrackingMessageMainInfo
{
BusiId = model.BookingId.ToString(),
BusiSystemCode = "BOOKING_ORDER",
MBlNo = bookingOrder.MBLNO,
VesselVoyno = $"{bookingOrder.VESSEL}/{bookingOrder.VOYNO}",
OrderNo = bookingOrder.BSNO,
PushType = TrackingPushTypeEnum.Status,
OperTenantId = bookingOrder.TenantId.Value,
OperTenantName = bookingOrder.TenantName,
OpertType = TrackingOperTypeEnum.MANUAL,
OperUserId = UserManager.UserId.ToString(),
OperUserName = UserManager.Name,
SourceType = TrackingSourceTypeEnum.MANUAL,
StatusList = model.StatusCodes.Select(a => new TrackingMessageMainStatusInfo
{
StatusCode = a,
}).ToList()
}
};
DateTime bDate = DateTime.Now;
_logger.LogInformation("批次={no} 推送保存服务项目 msg={msg}", batchNo, JSON.Serialize(msgInfo));
var rlt = await _serviceWorkFlowManageService.CancelStatus(msgInfo);
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} 请求完成,耗时:{timeDiff}ms. 结果{msg} result={rlt}", batchNo, timeDiff, (rlt.succ ? "成功" : "失败")
, JSON.Serialize(rlt));
if (!rlt.succ)
{
result = rlt;
}
else
{
result.succ = true;
result.msg = "推送成功";
}
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"服务项目状态推送失败,原因:{ex.Message}";
}
return result;
}
#region 获取服务项目列表
/// <summary>
/// 获取服务项目列表

@ -21,4 +21,20 @@ namespace Myshipping.Application
/// </summary>
public string[] ProjectCodes { get; set; }
}
/// <summary>
/// 修改服务项目状态
/// </summary>
public class ModifyServiceProjectStatusDto
{
/// <summary>
/// 订舱主键
/// </summary>
public long BookingId { get; set; }
/// <summary>
/// 服务项目状态代码
/// </summary>
public string[] StatusCodes { get; set; }
}
}

@ -117,5 +117,19 @@ namespace Myshipping.Application
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> GetServiceStatusList(QueryServiceProjectWithStatus model);
/// <summary>
/// 保存服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SaveServiceStatus(ModifyServiceProjectStatusDto model);
/// <summary>
/// 取消服务状态
/// </summary>
/// <param name="model">修改服务状态详情</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> CancelServiceStatus(ModifyServiceProjectStatusDto model);
}
}

@ -66,6 +66,11 @@ namespace Myshipping.Application
/// </summary>
public Nullable<DateTime> ActDate { get; set; }
/// <summary>
/// 状态数量(含子状态)
/// </summary>
public int StatusNum { get; set; }
/// <summary>
/// 状态列表
/// </summary>

@ -158,6 +158,11 @@ namespace Myshipping.Application
/// </summary>
public TrackingPushTypeEnum PushType { get; set; }
/// <summary>
/// 来源类型
/// </summary>
public TrackingSourceTypeEnum SourceType { get; set; }
/// <summary>
/// 服务项目列表
/// </summary>

@ -49,14 +49,6 @@ namespace Myshipping.Application
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> QueryServiceInfo(TrackingQueryMessageInfo info);
/// <summary>
/// 取消服务项目
/// </summary>
/// <param name="info">服务流程报文详情</param>
/// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> CancelProject(TrackingMessageInfo info);
/// <summary>
/// 校验取消状态
/// </summary>

@ -135,9 +135,11 @@ namespace Myshipping.Application
var projectList = _cache.Get<List<ServiceProjectBaseDto>>($"{CONST_CACHE_ENABLE_PROJECT}_{info.Main.OperTenantId}");
DateTime nowDate = DateTime.Now;
if (info.Main.PushType == TrackingPushTypeEnum.Project)
{
if(info.Main.ProjectList == null || info.Main.ProjectList.Count == 0)
if (info.Main.ProjectList == null || info.Main.ProjectList.Count == 0)
{
_logger.LogInformation("批次={no} 推送类型是【服务项目】,服务项目列表不能为空", batchNo);
@ -149,7 +151,7 @@ namespace Myshipping.Application
.Where(a => a.BUSI_ID == info.Main.BusiId && a.BUSI_SYSTEM_CODE.Equals(info.Main.BusiSystemCode)
&& !a.IsDeleted && a.TenantId == info.Main.OperTenantId).ToList();
var needProjectArg = info.Main.ProjectList.Select(a=>a.ServiceProjectCode).ToArray();
var needProjectArg = info.Main.ProjectList.Select(a => a.ServiceProjectCode).ToArray();
var needProjectList = statusList.Where(a => needProjectArg.Contains(a.ProjectCode)).ToList();
@ -168,10 +170,11 @@ namespace Myshipping.Application
return new { OperType = "Update", Info = l, Run = currList.FirstOrDefault() };
}).ToList();
DateTime nowDate = DateTime.Now;
tskList.ForEach(async tsk => {
if(tsk.OperType == "Insert")
tskList.ForEach(async tsk =>
{
if (tsk.OperType == "Insert")
{
ServiceWorkFlowRunInfo serviceWorkFlowRunInfo = new ServiceWorkFlowRunInfo
{
@ -200,10 +203,10 @@ namespace Myshipping.Application
await _serviceWorkFlowRunInfoRepository.InsertAsync(serviceWorkFlowRunInfo);
}
else if(tsk.OperType == "Update")
else if (tsk.OperType == "Update")
{
var runInfo = _serviceWorkFlowRunInfoRepository.AsQueryable()
.First(a => a.PK_ID == tsk.Run.PK_ID);
var runInfo = _serviceWorkFlowRunInfoRepository.AsQueryable()
.First(a => a.PK_ID == tsk.Run.PK_ID);
runInfo.IS_YIELD = 1;
runInfo.ACT_DATE = nowDate;
@ -221,259 +224,194 @@ namespace Myshipping.Application
return result;
}
//校验状态代码是否一致,不一致直接返回错误不允许推送
var statusArg = info.Main.StatusList.Select(a => a?.StatusCode.ToUpper())
.Where(a => !string.IsNullOrWhiteSpace(a)).Distinct().ToArray();
if (statusArg.Length == 0)
{
_logger.LogInformation("批次={no} 报文Main的状态列表至少需要提供一个以上的状态信息", batchNo);
throw Oops.Oh($"报文Main的状态列表至少需要提供一个以上的状态信息", typeof(InvalidOperationException));
}
UserTendDto userTendInfo = GetUserTendInfo(info.Main.OperUserId);
//检索状态对应所有的服务流程如果已经提取到的状态数量与推送的不一致提示错误不能入库s
var skuList = _statusSkuBaseInfoRepository.AsQueryable().Filter(null, true)
.LeftJoin<ServiceWorkFlowActivitiesInfo>((sts, act) => sts.PK_ID == act.STATUS_SKU_ID)
.LeftJoin<ServiceWorkFlowActivitiesRelation>((sts,act,rela)=>
act.PK_ID == rela.SERVICE_ACTIVITIES_ID)
.LeftJoin<ServiceWorkFlowBaseInfo>((sts, act, rela,wf)=>
rela.SERVICE_WORKFLOW_ID == wf.PK_ID && rela.WF_VERSION == wf.RELEASE_VERSION)
.Where((sts, act) => statusArg.Contains(sts.STATUS_SKU_CODE) && !sts.IsDeleted && sts.IS_ENABLE == 1
&& !act.IsDeleted)
.Select((sts, act,rela,wf) =>
new { Sku = sts, Act = act, Rela = rela,WF = wf }).ToList();
//推送状态与已有状态进行匹配
var reqStatusList =
info.Main.StatusList.GroupJoin(skuList, l => l.StatusCode, r => r.Sku.STATUS_SKU_CODE,
(l, r) =>
{
var currList = r.ToList();
if (currList.Count > 0)
return new { Exists = true, Sku = currList.FirstOrDefault().Sku,Act = currList.FirstOrDefault().Act,Req = l };
return new { Exists = false, Sku = new StatusSkuBaseInfo(), Act = new ServiceWorkFlowActivitiesInfo(),Req = l };
}).ToList();
_logger.LogInformation("批次={no} 服务状态列表不能为空", batchNo);
//如果有不存在的状态则提示无法入库
if (reqStatusList.Any(a => !a.Exists))
{
var errList =
reqStatusList.Where(a => !a.Exists)
.Select(a => a.Req.StatusCode).ToArray();
string errMsg = $"以下状态不存在 {(string.Join(",", errList))} 不能入库";
_logger.LogInformation("批次={no} {msg}", batchNo, errMsg);
throw Oops.Oh(errMsg, typeof(InvalidOperationException));
throw Oops.Oh($"服务状态列表不能为空", typeof(InvalidOperationException));
}
//先从运行表按主键获取运行主表和活动表
var runList = _serviceWorkFlowRunInfoRepository.AsQueryable().Filter(null, true)
.LeftJoin<ServiceWorkFlowRunActivitiesInfo>(
(m, s) => m.PK_ID == s.RUN_ID)
.Where((m, s) => m.BUSI_ID == info.Main.BusiId
&& m.BUSI_SYSTEM_CODE.Equals(info.Main.BusiSystemCode) && !m.IsDeleted && !s.IsDeleted)
.Select((m, s) => new { main = m, sub = s }).ToList();
var wfList = skuList.Select(a => a.WF)
.Distinct().ToList();
var checkList = wfList.GroupJoin(runList, l => l.PK_ID,
r => r.main.SERVICE_WF_ID,
(l, r) =>
{
var currList = r.ToList();
if (currList.Count > 0)
{
return new { Exists = true, WF = l };
}
return new { Exists = false, WF = l };
/*
1
2
3run
4run
5
*/
statusList = statusList.Where(a => a.StatusList.Any(b =>
statusArg.Contains(b.StatusSKUCode))).ToList();
}).ToList();
if (statusList.Count == 0)
throw Oops.Oh($"未检索到可用服务项目和状态列表", typeof(InvalidOperationException));
if(checkList.Any(a=>a.Exists))
{
reqStatusList.ForEach(async reqMd =>
{
var currRun =
runList.FirstOrDefault(x => x.sub.PK_ID == reqMd.Act.PK_ID);
var wfArgs = statusList.Select(a => a.WFPKId).ToArray();
var currRunAct = currRun.sub;
currRunAct.ACT_DATE = reqMd.Req.StatusDate;
currRunAct.IS_YIELD = 1;
await _serviceWorkFlowRunActivitiesInfoRepository.AsUpdateable(currRunAct).UpdateColumns(it => new
{
it.ACT_DATE,
it.IS_YIELD,
}).ExecuteCommandAsync();
});
}
//获取订单下所有Run表记录
var runHisList = _serviceWorkFlowRunInfoRepository.AsQueryable().Filter(null, true)
.LeftJoin<ServiceWorkFlowRunActivitiesInfo>((main, detail)
=> main.PK_ID == detail.RUN_ID)
.Where((main, detail)
=> main.BUSI_SYSTEM_CODE == info.Main.BusiSystemCode && main.BUSI_ID == info.Main.BusiId
&& !main.IsDeleted && !detail.IsDeleted && wfArgs.Contains(main.SERVICE_WF_ID))
.Select((main, detail) => new { Main = main, Detail = detail }).ToList();
/*
1run
2runrun
*/
if (checkList.Any(a => !a.Exists))
info.Main.StatusList.ForEach(async st =>
{
var noExistsList = checkList.Where(l => !l.Exists).Select(a=>a.WF.PK_ID).Distinct().ToList();
var relateList = statusList.Where(a => a.StatusList.Any(b =>
st.StatusCode.Contains(b.StatusSKUCode))).ToList();
//状态关联的服务流程与运行表中的服务流程对应,对已经有的进行更新,对未进入运行表的进行写入
var actArg = reqStatusList.Select(a => a.Act.PK_ID).ToArray();
//根据服务流程活动获取所有相关的服务流程
var wfRlt = _serviceWorkFlowBaseService.GetServiceWorkFlowListByActivities(actArg).GetAwaiter().GetResult();
if (!wfRlt.succ)
relateList.ForEach(async rt =>
{
string errMsg = $"获取服务流程失败,原因:{wfRlt.msg}";
_logger.LogInformation("批次={no} {msg}", batchNo, errMsg);
throw Oops.Oh(errMsg, typeof(InvalidOperationException));
}
var list = JSON.Deserialize<List<ServiceWorkFlowBaseShowDto>>(JSON.Serialize(wfRlt.ext));
var runList =
runHisList.Where(a => a.Main.SERVICE_WF_ID == rt.WFPKId).ToList();
if(list.Count > 0)
list = list.Where(a=> noExistsList.Contains( a.PKId)).ToList();
DateTime nowDate = DateTime.Now;
list.ForEach(async wf =>
{
ServiceWorkFlowRunInfo serviceWorkFlowRunInfo = new ServiceWorkFlowRunInfo
if(runList.Count == 0)
{
PK_ID = IDGen.NextID().ToString(),
SERVICE_WF_ID = wf.PKId,
BUSI_SYSTEM_CODE = info.Main.BusiSystemCode.ToUpper(),
BUSI_ID = info.Main.BusiId.ToUpper(),
MBL_NO = info.Main?.MBlNo.ToUpper(),
VESSEL_VOYNO = info.Main?.VesselVoyno.ToUpper(),
ORDER_NO = info.Main?.OrderNo,
STATUS = TaskStatusEnum.Create.ToString(),
RELEASE_VERSION = wf.ReleaseVersion,
ACTIVITIES_NUM = wf.StatusNum,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = userTendInfo.userId,
CreatedUserName = userTendInfo.userName,
TenantId = userTendInfo.tendId,
TenantName = userTendInfo.tenantName,
SERVICE_PROJECT_CODE = wf.ServiceProject.ServiceProjectCode,
SERVICE_PROJECT_NAME = wf.ServiceProject.ServiceProjectName,
};
await _serviceWorkFlowRunInfoRepository.InsertAsync(serviceWorkFlowRunInfo);
int endNum = wf.StatusSkuList.Max(sku => sku.SortNo);
string lastActId = string.Empty;
wf.StatusSkuList.ForEach(async sku => {
var currReq =
reqStatusList.FirstOrDefault(x => x.Act.PK_ID == sku.PKId);
ServiceWorkFlowRunActivitiesInfo activitiesRunInfo = new ServiceWorkFlowRunActivitiesInfo
#region 处理run表
//需要生成run表记录包含活动明细
ServiceWorkFlowRunInfo serviceWorkFlowRunInfo = new ServiceWorkFlowRunInfo
{
PK_ID = IDGen.NextID().ToString(),
RUN_ID = serviceWorkFlowRunInfo.PK_ID,
EXEC_SORT_NO = sku.SortNo,
IS_START = sku.SortNo == 1 ? 1 : 0,
IS_END = sku.SortNo == endNum ? 1 : 0,
ACT_ID = sku.PKId,
STATUS_SKU_CODE = sku.statusSkuBase.StatusSKUCode,
STATUS_SKU_ID = sku.StatusSKUId,
SHOW_NAME = sku.ShowName,
IS_SUB = 0,
IS_SUB_JUST = 0,
IS_YIELD = 0,
SERVICE_WF_ID = rt.WFPKId,
BUSI_SYSTEM_CODE = info.Main.BusiSystemCode.ToUpper(),
BUSI_ID = info.Main.BusiId.ToUpper(),
MBL_NO = info.Main?.MBlNo.ToUpper(),
VESSEL_VOYNO = info.Main?.VesselVoyno.ToUpper(),
ORDER_NO = info.Main?.OrderNo,
STATUS = TaskStatusEnum.Create.ToString(),
RELEASE_VERSION = rt.ReleaseVersion,
ACTIVITIES_NUM = rt.StatusNum,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = userTendInfo.userId,
CreatedUserName = userTendInfo.userName,
TenantId = userTendInfo.tendId,
TenantName = userTendInfo.tenantName,
IsDeleted = false,
SOURCE_TYPE = "AUTO"
CreatedUserId = long.Parse(info.Main.OperUserId),
CreatedUserName = info.Main.OperUserName,
TenantId = info.Main.OperTenantId,
TenantName = info.Main.OperTenantName,
SERVICE_PROJECT_CODE = rt.ProjectCode,
SERVICE_PROJECT_NAME = rt.ProjectName,
SERVICE_PROJECT_ID = rt.ProjectPKId,
IS_YIELD = 1,
ACT_DATE = nowDate,
};
if (currReq != null)
{
activitiesRunInfo.ACT_DATE = currReq.Req.StatusDate;
activitiesRunInfo.ACT_VAL = currReq.Req.StatusVal;
activitiesRunInfo.IS_YIELD = 1;
}
if (!string.IsNullOrWhiteSpace(lastActId))
activitiesRunInfo.NEXT_ACT_ID = lastActId;
//写入run主表
await _serviceWorkFlowRunInfoRepository.InsertAsync(serviceWorkFlowRunInfo);
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesRunInfo);
//获取状态最大数
int endNum = rt.StatusList.Max(sku => sku.SortNo);
lastActId = activitiesRunInfo.PK_ID;
string lastActId = string.Empty;
if (sku.IsContainsSub == 1)
rt.StatusList.ForEach(async sku =>
{
string lastSubActId = string.Empty;
ServiceWorkFlowRunActivitiesInfo activitiesRunInfo = new ServiceWorkFlowRunActivitiesInfo
{
PK_ID = IDGen.NextID().ToString(),
RUN_ID = serviceWorkFlowRunInfo.PK_ID,
EXEC_SORT_NO = sku.SortNo,
IS_START = sku.SortNo == 1 ? 1 : 0,
IS_END = sku.SortNo == endNum ? 1 : 0,
ACT_ID = sku.ActPKId,
STATUS_SKU_CODE = sku.StatusSKUCode,
STATUS_SKU_ID = sku.SkuPKId,
SHOW_NAME = sku.ShowName,
IS_SUB = 0,
IS_SUB_JUST = 0,
IS_YIELD = 0,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = long.Parse(info.Main.OperUserId),
CreatedUserName = info.Main.OperUserName,
TenantId = info.Main.OperTenantId,
TenantName = info.Main.OperTenantName,
IsDeleted = false,
SOURCE_TYPE = info.Main.SourceType.ToString(),
};
sku.SubList.ForEach(async sub => {
if (st.StatusCode.Equals(sku.StatusSKUCode,StringComparison.OrdinalIgnoreCase))
{
activitiesRunInfo.IS_YIELD = 1;
activitiesRunInfo.ACT_DATE = nowDate;
activitiesRunInfo.ACT_VAL = st.StatusVal;
}
var currSubReq =
reqStatusList.FirstOrDefault(x => x.Act.PK_ID == sub.PKId);
//写入run活动表
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesRunInfo);
ServiceWorkFlowRunActivitiesInfo activitiesSubRunInfo = new ServiceWorkFlowRunActivitiesInfo
{
PK_ID = IDGen.NextID().ToString(),
RUN_ID = serviceWorkFlowRunInfo.PK_ID,
EXEC_SORT_NO = sub.SortNo,
IS_START = sub.SortNo == 1 ? 1 : 0,
IS_END = sub.SortNo == endNum ? 1 : 0,
ACT_ID = sub.PKId,
STATUS_SKU_CODE = sub.statusSkuBase.StatusSKUCode,
STATUS_SKU_ID = sub.StatusSKUId,
SHOW_NAME = sub.ShowName,
IS_SUB = 1,
IS_SUB_JUST = 1,
IS_YIELD = 0,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = userTendInfo.userId,
CreatedUserName = userTendInfo.userName,
TenantId = userTendInfo.tendId,
TenantName = userTendInfo.tenantName,
IsDeleted = false,
SOURCE_TYPE = "AUTO",
PARENT_ID = activitiesRunInfo.PK_ID
};
if (currSubReq != null)
{
activitiesSubRunInfo.ACT_DATE = currSubReq.Req.StatusDate;
activitiesSubRunInfo.ACT_VAL = currSubReq.Req.StatusVal;
activitiesSubRunInfo.IS_YIELD = 1;
}
if (sku.SubStatusList != null && sku.SubStatusList.Count > 0)
{
string lastSubActId = string.Empty;
if (!string.IsNullOrWhiteSpace(lastSubActId))
activitiesSubRunInfo.NEXT_ACT_ID = lastSubActId;
sku.SubStatusList.ForEach(async sub => {
ServiceWorkFlowRunActivitiesInfo activitiesSubRunInfo = new ServiceWorkFlowRunActivitiesInfo
{
PK_ID = IDGen.NextID().ToString(),
RUN_ID = serviceWorkFlowRunInfo.PK_ID,
EXEC_SORT_NO = sub.SortNo,
IS_START = sub.SortNo == 1 ? 1 : 0,
IS_END = sub.SortNo == endNum ? 1 : 0,
ACT_ID = sub.ActPKId,
STATUS_SKU_CODE = sub.StatusSKUCode,
STATUS_SKU_ID = sub.SkuPKId,
SHOW_NAME = sub.ShowName,
IS_SUB = 1,
IS_SUB_JUST = 1,
IS_YIELD = 0,
CreatedTime = nowDate,
UpdatedTime = nowDate,
CreatedUserId = long.Parse(info.Main.OperUserId),
CreatedUserName = info.Main.OperUserName,
TenantId = info.Main.OperTenantId,
TenantName = info.Main.OperTenantName,
IsDeleted = false,
SOURCE_TYPE = info.Main.SourceType.ToString(),
PARENT_ID = activitiesRunInfo.PK_ID
};
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesSubRunInfo);
if (st.StatusCode.Equals(sub.StatusSKUCode, StringComparison.OrdinalIgnoreCase))
{
activitiesSubRunInfo.IS_YIELD = 1;
activitiesSubRunInfo.ACT_DATE = nowDate;
activitiesSubRunInfo.ACT_VAL = st.StatusVal;
}
lastSubActId = activitiesSubRunInfo.PK_ID;
if (!string.IsNullOrWhiteSpace(lastSubActId))
activitiesSubRunInfo.NEXT_ACT_ID = lastSubActId;
});
}
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesSubRunInfo);
});
lastSubActId = activitiesSubRunInfo.PK_ID;
});
}
});
#endregion
}
else
{
if (runList.Any(b => b.Detail == null))
{
//需要补充活动表明细
}
else
{
//只需要更新完成标记和完成时间
}
}
});
}
});
result.succ = true;
result.msg = "推送成功";
@ -772,10 +710,66 @@ namespace Myshipping.Application
throw Oops.Oh($"报文Main的业务主键不能为空", typeof(InvalidOperationException));
}
if (info.Main.StatusList == null || info.Main.StatusList.Count == 0)
var statusList = _serviceWorkFlowBaseService.GetEnableProjectWithStatusList(info.Main.OperTenantId.ToString()).GetAwaiter().GetResult();
var projectList = _cache.Get<List<ServiceProjectBaseDto>>($"{CONST_CACHE_ENABLE_PROJECT}_{info.Main.OperTenantId}");
if (info.Main.PushType == TrackingPushTypeEnum.Project)
{
_logger.LogInformation("批次={no} 接收推送状态错误 报文Main的状态列表不能为空并且至少需要提供一个以上的状态信息", batchNo);
throw Oops.Oh($"报文Main的状态列表不能为空并且至少需要提供一个以上的状态信息", typeof(InvalidOperationException));
if (info.Main.ProjectList == null || info.Main.ProjectList.Count == 0)
{
_logger.LogInformation("批次={no} 推送类型是【服务项目】,服务项目列表不能为空", batchNo);
throw Oops.Oh($"推送类型是【服务项目】,服务项目列表不能为空", typeof(InvalidOperationException));
}
//提取所有已经有run记录的
var runBaseList = _serviceWorkFlowRunInfoRepository.AsQueryable().Filter(null, true)
.Where(a => a.BUSI_ID == info.Main.BusiId && a.BUSI_SYSTEM_CODE.Equals(info.Main.BusiSystemCode)
&& !a.IsDeleted && a.TenantId == info.Main.OperTenantId).ToList();
var needProjectArg = info.Main.ProjectList.Select(a => a.ServiceProjectCode).ToArray();
var needProjectList = statusList.Where(a => needProjectArg.Contains(a.ProjectCode)).ToList();
var tskList = needProjectList.GroupJoin(runBaseList, l => l.WFPKId,
r => r.SERVICE_WF_ID,
(l, r) =>
{
var currList = r.ToList();
if (currList.Count == 0)
{
//标识当前服务项目写入运行主表
return new { OperType = "None", Info = l, Run = new ServiceWorkFlowRunInfo() };
}
return new { OperType = "Update", Info = l, Run = currList.FirstOrDefault() };
}).ToList();
DateTime nowDate = DateTime.Now;
tskList.ForEach(async tsk => {
if (tsk.OperType == "Update")
{
var runInfo = _serviceWorkFlowRunInfoRepository.AsQueryable()
.First(a => a.PK_ID == tsk.Run.PK_ID);
runInfo.IS_YIELD = 0;
runInfo.ACT_DATE = null;
await _serviceWorkFlowRunInfoRepository.AsUpdateable(runInfo).UpdateColumns(it => new
{
it.ACT_DATE,
it.IS_YIELD,
}).ExecuteCommandAsync();
}
});
result.succ = true;
result.msg = "取消成功";
return result;
}
@ -1170,24 +1164,6 @@ namespace Myshipping.Application
return result;
}
#region 取消服务项目
/// <summary>
/// 取消服务项目
/// </summary>
/// <param name="info">服务流程报文详情</param>
/// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> CancelProject(TrackingMessageInfo info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
_logger.LogInformation("批次={no} 接收推送状态 msg={msg}", batchNo, JSON.Serialize(info));
return result;
}
#endregion
#region 校验取消状态
/// <summary>
/// 校验取消状态

Loading…
Cancel
Save