|
|
|
@ -1000,6 +1000,8 @@ 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)
|
|
|
|
@ -1033,8 +1035,6 @@ namespace Myshipping.Application
|
|
|
|
|
return new { OperType = "Update", Info = l, Run = currList.FirstOrDefault() };
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
DateTime nowDate = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
tskList.ForEach(async tsk => {
|
|
|
|
|
if (tsk.OperType == "Update")
|
|
|
|
|
{
|
|
|
|
@ -1058,7 +1058,6 @@ namespace Myshipping.Application
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//校验状态代码是否一致,不一致直接返回错误不允许推送
|
|
|
|
|
var statusArg = info.Main.StatusList.Select(a => a?.StatusCode.ToUpper())
|
|
|
|
|
.Where(a => !string.IsNullOrWhiteSpace(a)).Distinct().ToArray();
|
|
|
|
@ -1070,254 +1069,98 @@ namespace Myshipping.Application
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
//如果有不存在的状态则提示无法入库
|
|
|
|
|
if (reqStatusList.Any(a => !a.Exists))
|
|
|
|
|
{
|
|
|
|
|
var errList =
|
|
|
|
|
reqStatusList.Where(a => !a.Exists)
|
|
|
|
|
.Select(a => a.Req.StatusCode).ToArray();
|
|
|
|
|
|
|
|
|
|
string errMsg = $"以下状态不存在 {(string.Join(",", errList))} 不能入库";
|
|
|
|
|
//检索状态相关的服务流程
|
|
|
|
|
statusList = statusList.Where(a =>
|
|
|
|
|
a.StatusList.Any(b =>
|
|
|
|
|
{
|
|
|
|
|
if (statusArg.Contains(b.StatusSKUCode))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("批次={no} {msg}", batchNo, errMsg);
|
|
|
|
|
if (b.SubStatusList != null && b.SubStatusList.Any(c =>
|
|
|
|
|
statusArg.Contains(c.StatusSKUCode)))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
throw Oops.Oh(errMsg, typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
})).ToList();
|
|
|
|
|
|
|
|
|
|
//先从运行表按主键获取运行主表和活动表
|
|
|
|
|
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 (statusList.Count == 0)
|
|
|
|
|
throw Oops.Oh($"未检索到可用服务项目和状态列表", typeof(InvalidOperationException));
|
|
|
|
|
|
|
|
|
|
if (currList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return new { Exists = true, WF = l };
|
|
|
|
|
}
|
|
|
|
|
//提取关联的服务流程主键数组
|
|
|
|
|
var wfArgs = statusList.Select(a => a.WFPKId).ToArray();
|
|
|
|
|
|
|
|
|
|
return new { Exists = false, WF = l };
|
|
|
|
|
//获取订单下所有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
|
|
|
|
|
&& wfArgs.Contains(main.SERVICE_WF_ID))
|
|
|
|
|
.Select((main, detail) => new { Main = main, Detail = detail }).ToList();
|
|
|
|
|
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (checkList.Any(a => a.Exists))
|
|
|
|
|
//按照请求的状态列表轮询
|
|
|
|
|
info.Main.StatusList.ForEach(async st =>
|
|
|
|
|
{
|
|
|
|
|
reqStatusList.ForEach(async reqMd =>
|
|
|
|
|
{
|
|
|
|
|
var currRun =
|
|
|
|
|
runList.FirstOrDefault(x => x.sub.PK_ID == reqMd.Act.PK_ID);
|
|
|
|
|
|
|
|
|
|
var currRunAct = currRun.sub;
|
|
|
|
|
|
|
|
|
|
currRunAct.ACT_DATE = reqMd.Req.StatusDate;
|
|
|
|
|
currRunAct.IS_YIELD = 1;
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowRunActivitiesInfoRepository.AsUpdateable(currRunAct).UpdateColumns(it => new
|
|
|
|
|
var relateList = statusList.Where(a =>
|
|
|
|
|
a.StatusList.Any(b =>
|
|
|
|
|
{
|
|
|
|
|
it.ACT_DATE,
|
|
|
|
|
it.IS_YIELD,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (b.StatusSKUCode.Equals(st.StatusCode, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (b.SubStatusList != null && b.SubStatusList.Any(c => c.StatusSKUCode.Equals(st.StatusCode, StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (checkList.Any(a => !a.Exists))
|
|
|
|
|
{
|
|
|
|
|
var noExistsList = checkList.Where(l => !l.Exists).Select(a => a.WF.PK_ID).Distinct().ToList();
|
|
|
|
|
return false;
|
|
|
|
|
})).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);
|
|
|
|
|
var runList =
|
|
|
|
|
runHisList.Where(a
|
|
|
|
|
=> a.Main.SERVICE_WF_ID == rt.WFPKId).ToList();
|
|
|
|
|
|
|
|
|
|
throw Oops.Oh(errMsg, typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = JSON.Deserialize<List<ServiceWorkFlowBaseShowDto>>(JSON.Serialize(wfRlt.ext));
|
|
|
|
|
|
|
|
|
|
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.Any(b
|
|
|
|
|
=>b.Detail.STATUS_SKU_CODE.Equals(st.StatusCode,StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
CreatedTime = nowDate,
|
|
|
|
|
UpdatedTime = nowDate,
|
|
|
|
|
CreatedUserId = userTendInfo.userId,
|
|
|
|
|
CreatedUserName = userTendInfo.userName,
|
|
|
|
|
TenantId = userTendInfo.tendId,
|
|
|
|
|
TenantName = userTendInfo.tenantName,
|
|
|
|
|
IsDeleted = false,
|
|
|
|
|
SOURCE_TYPE = "AUTO"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
var detail = runList.FirstOrDefault(b
|
|
|
|
|
=> b.Detail.STATUS_SKU_CODE.Equals(st.StatusCode, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesRunInfo);
|
|
|
|
|
|
|
|
|
|
lastActId = activitiesRunInfo.PK_ID;
|
|
|
|
|
|
|
|
|
|
if (sku.IsContainsSub == 1)
|
|
|
|
|
{
|
|
|
|
|
string lastSubActId = string.Empty;
|
|
|
|
|
var activitiesRunInfo = _serviceWorkFlowRunActivitiesInfoRepository
|
|
|
|
|
.AsQueryable().First(b => b.STATUS_SKU_CODE == detail.Detail.STATUS_SKU_CODE);
|
|
|
|
|
|
|
|
|
|
sku.SubList.ForEach(async sub => {
|
|
|
|
|
activitiesRunInfo.ACT_VAL = null;
|
|
|
|
|
activitiesRunInfo.ACT_REMARK = null;
|
|
|
|
|
activitiesRunInfo.ACT_DATE = null;
|
|
|
|
|
activitiesRunInfo.IS_YIELD = 0;
|
|
|
|
|
|
|
|
|
|
var currSubReq =
|
|
|
|
|
reqStatusList.FirstOrDefault(x => x.Act.PK_ID == sub.PKId);
|
|
|
|
|
|
|
|
|
|
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 (!string.IsNullOrWhiteSpace(lastSubActId))
|
|
|
|
|
activitiesSubRunInfo.NEXT_ACT_ID = lastSubActId;
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowRunActivitiesInfoRepository.InsertAsync(activitiesSubRunInfo);
|
|
|
|
|
|
|
|
|
|
lastSubActId = activitiesSubRunInfo.PK_ID;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
activitiesRunInfo.UpdatedTime = nowDate;
|
|
|
|
|
activitiesRunInfo.UpdatedUserId = long.Parse(info.Main.OperUserId);
|
|
|
|
|
activitiesRunInfo.UpdatedUserName = info.Main.OperUserName;
|
|
|
|
|
|
|
|
|
|
await _serviceWorkFlowRunActivitiesInfoRepository.AsUpdateable(activitiesRunInfo)
|
|
|
|
|
.UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.ACT_DATE,
|
|
|
|
|
it.IS_YIELD,
|
|
|
|
|
it.ACT_REMARK,
|
|
|
|
|
it.ACT_VAL,
|
|
|
|
|
it.UpdatedTime,
|
|
|
|
|
it.UpdatedUserId,
|
|
|
|
|
it.UpdatedUserName
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result.succ = true;
|
|
|
|
|
result.msg = "推送成功";
|
|
|
|
|
result.msg = "取消成功";
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
result.succ = false;
|
|
|
|
|
result.msg = $"推送状态失败,原因:{ex.Message}";
|
|
|
|
|
result.msg = $"取消状态失败,原因:{ex.Message}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|