修改INTTRA

dev
jianghaiqing 1 week ago
parent f60d7f71bd
commit aded522dd5

@ -919,7 +919,6 @@ namespace DS.WMS.Core.Op.EDI
if (bill.BLFRT.IndexOf("COLLECT") >= 0)
str_pay = bill.PAYABLEAT;
/* 2024-04-08 JHQ
if (bill.CARRIEREDICODE == "HLCU")
{
r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " + bill.CONTRACTNO + " "
@ -936,9 +935,8 @@ namespace DS.WMS.Core.Op.EDI
+ bill.PKGS.ToString() + bill.KINDPKGS + " " + formatEdiStr("txt", bill.EDIREMARK.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")) + "'");
}
icount = icount + 2;
*/
icount = icount + 1;
//icount = icount + 1;
var Shipping = "";
Shipping = formatEdiStr("txt", bill.EDIREMARK);

@ -13,8 +13,14 @@ namespace DS.WMS.Core.Op.Entity
/// 服务流程主表
/// </summary>
[SqlSugar.SugarTable("service_workflow_base", "服务流程主表")]
public class ServiceWorkFlowBaseInfo : BaseModelV2<long>
public class ServiceWorkFlowBaseInfo
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true)]
public string PK_ID { get; set; }
/// <summary>
/// 服务流程代码
/// </summary>
@ -80,5 +86,75 @@ namespace DS.WMS.Core.Op.Entity
/// </summary>
public int IS_LOCK { get; set; } = 0;
/// <summary>
/// 创建时间
/// </summary>
[Description("创建时间")]
[SugarColumn(IsOnlyIgnoreUpdate = true, ColumnDescription = "创建时间")]
public DateTime CreateTime { get; set; }
/// <summary>
/// 创建人
/// </summary>
[Description("创建人")]
[SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人")]
public long CreateBy { get; set; }
/// <summary>
/// 修改人
/// </summary>
[Description("修改人")]
[SugarColumn(IsNullable = true, ColumnDescription = "修改人")]
public long? UpdateBy { get; set; }
/// <summary>
/// 更新时间
/// </summary>
[Description("更新时间")]
[SugarColumn(IsNullable = true, ColumnDescription = "更新时间")]
public Nullable<DateTime> UpdateTime { get; set; }
/// <summary>
/// 删除
/// </summary>
[Description("删除")]
[SugarColumn(ColumnDescription = "是否删除", DefaultValue = "0")]
public bool Deleted { get; set; }
/// <summary>
/// 删除时间
/// </summary>
[Description("删除时间")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除时间", IsOnlyIgnoreInsert = true)]
public Nullable<DateTime> DeleteTime { get; set; }
/// <summary>
/// 删除人
/// </summary>
[Description("删除人")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除人", IsOnlyIgnoreInsert = true)]
public Nullable<long> DeleteBy { get; set; }
/// <summary>
/// 创建人名称
/// </summary>
[Description("创建人名称")]
[SugarColumn(IsOnlyIgnoreUpdate = true, IsNullable = true, ColumnDescription = "创建人名称", Length = 50)]
public string CreateUserName { get; set; }
/// <summary>
/// 修改人名称
/// </summary>
[Description("修改人名称")]
[SugarColumn(IsNullable = true, ColumnDescription = "修改人名称", Length = 50)]
public string UpdateUserName { get; set; }
/// <summary>
/// 删除人名称
/// </summary>
[Description("删除人名称")]
[SugarColumn(IsNullable = true, ColumnDescription = "删除人名称", Length = 50, IsOnlyIgnoreInsert = true)]
public string DeleteUserName { get; set; }
}
}

@ -0,0 +1,474 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using DS.Module.UserModule;
using SqlSugar;
using DS.Module.SqlSugar;
using Microsoft.Extensions.DependencyInjection;
using DS.Module.DjyServiceStatus;
using DS.WMS.Core.Op.Dtos;
using DS.WMS.Core.Op.Entity;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using DS.Module.Core;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using DS.WMS.Core.Invoice.Dtos;
using Mapster;
using LanguageExt.Common;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Op.Dtos.Enum;
using DS.WMS.Core.Op.Interface;
using LanguageExt.Pretty;
namespace DS.WMS.Core.Op.Method
{
public class ServiceWorkFlowBaseService//: IServiceWorkFlowBaseService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
public ServiceWorkFlowBaseService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
/*
#region 保存
/// <summary>
/// 保存
/// </summary>
/// <param name="info">服务流程详情</param>
/// <returns>返回回执</returns>
public async Task<DataResult<long>> Save(ServiceWorkFlowBaseDto info)
{
return await InnerSave(info);
}
#endregion
#region 保存内部方法
/// <summary>
/// 保存内部方法
/// </summary>
/// <param name="info">服务流程详情</param>
/// <param name="isSetEnable">是否启用</param>
/// <returns>返回派车Id</returns>
private async Task<DataResult<long>> InnerSave(ServiceWorkFlowBaseDto info, bool isSetEnable = false)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
ServiceWorkFlowBaseInfo entity = info.Adapt<ServiceWorkFlowBaseInfo>();
if (isSetEnable)
{
if (string.IsNullOrWhiteSpace(entity.SERVICE_WORKFLOW_CODE) || string.IsNullOrWhiteSpace(entity.SERVICE_WORKFLOW_NAME))
{
throw Oops.Oh($"服务流程代码或名称不能为空", typeof(InvalidOperationException));
}
entity.IS_ENABLE = 1;
}
if (entity == null)
throw Oops.Oh($"服务流程不能为空", typeof(InvalidOperationException));
if (entity.BELONG_TENANT_ID == 0)
{
entity.BELONG_TENANT_ID = long.Parse(user.TenantId);
entity.BELONG_TENANT_NAME = user.TenantName;
}
if (string.IsNullOrWhiteSpace(info.ServiceWorkflowCode))
{
if (tenantDb.Queryable<ServiceWorkFlowBaseInfo>().Any(a => a.SERVICE_WORKFLOW_CODE.Equals(info.ServiceWorkflowCode) && a.PK_ID != info.PKId))
{
Logger.Log(NLog.LogLevel.Info, $"服务流程代码已存在不能重复保存");
throw Oops.Oh($"服务流程代码已存在不能重复保存", typeof(InvalidOperationException));
}
}
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
if (info.StatusSkuList.Any(a => a.IsContainsSub == 1 && (a.SubList == null || a.SubList.Count == 0)))
{
throw Oops.Oh($"状态已选择包含子状态,子状态列表不能为空", typeof(InvalidOperationException));
}
if (info.StatusSkuList.Any(a => a.SortNo == 0))
throw Oops.Oh($"状态必需指定大于零的顺序号", typeof(InvalidOperationException));
if (info.StatusSkuList.GroupBy(a => a.SortNo).Any(a => a.ToList().Count > 1))
throw Oops.Oh($"状态顺序号不能重复", typeof(InvalidOperationException));
info.StatusSkuList = info.StatusSkuList.OrderBy(a => a.SortNo).Select((a, idx) =>
{
if (a.SubList == null || a.SubList.Count == 0)
{
a.SortNo = idx + 1;
return a;
}
a.SortNo = idx + 1;
a.SubList = a.SubList.OrderBy(b => b.SortNo).Select((b, sidx) =>
{
b.SortNo = sidx + 1;
return b;
}).ToList();
return a;
}).ToList();
}
Logger.Log(NLog.LogLevel.Info, $"服务流程保存 JSON={JsonConvert.SerializeObject(entity)} user={user.UserId}");
string currVersion = string.Empty;
if (string.IsNullOrWhiteSpace(entity.PK_ID))
{
entity.PK_ID = SnowFlakeSingle.Instance.NextId().ToString();
entity.DEVELOP_VERSION = "DEVELOP";
currVersion = entity.DEVELOP_VERSION;
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
entity.STATUS_NUM = info.StatusSkuList.Sum(a =>
{
if (a.SubList != null)
return a.SubList.Count + 1;
return 1;
});
}
tenantDb.Insertable<ServiceWorkFlowBaseInfo>(entity).ExecuteCommand();
}
else
{
var model = InnerGetInfo(entity.PK_ID);
Logger.Log(NLog.LogLevel.Info, $"更新状态前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
ValidateServiceWorkFlow(entity, TrackingOperateTypeEnum.Save);
entity.UpdateTime = DateTime.Now;
entity.UpdateBy = long.Parse(user.UserId);
entity.UpdateUserName = user.UserName;
if (!isSetEnable)
{
entity.IS_ENABLE = model.IS_ENABLE;
}
entity.IS_LOCK = model.IS_LOCK;
if (string.IsNullOrWhiteSpace(model.DEVELOP_VERSION))
{
if (!string.IsNullOrWhiteSpace(model.RELEASE_VERSION))
{
entity.DEVELOP_VERSION = "DEVELOP";
}
}
else
{
entity.DEVELOP_VERSION = model.DEVELOP_VERSION;
}
currVersion = entity.DEVELOP_VERSION;
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
entity.STATUS_NUM = info.StatusSkuList.Sum(a =>
{
if (a.SubList != null)
return a.SubList.Count + 1;
return 1;
});
}
await tenantDb.Updateable<ServiceWorkFlowBaseInfo>(entity).IgnoreColumns(it => new
{
it.CreateTime,
it.CreateBy,
it.CreateUserName,
it.Deleted,
it.RELEASE_VERSION,
it.PUBLISH_DATE,
it.PUBLISH_ER,
it.PUBLISH_NAME,
it.IS_LOCK
}).ExecuteCommandAsync();
currVersion = entity.DEVELOP_VERSION;
//批量删除服务流程与服务项目关系(物理删除)
tenantDb.Deleteable<ServiceWorkFlowProjectRelation>().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程与服务活动关系(物理删除)
_serviceWorkFlowActivitiesRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程活动与子活动的关系(物理删除)
_serviceWorkFlowActivitiesSubRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesSubRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
//批量删除服务流程与服务流程活动触发器关系(物理删除)
_serviceWorkFlowActivitiesTriggerRelationRepository.EntityContext.Deleteable<ServiceWorkFlowActivitiesTriggerRelation>()
.EnableQueryFilter().Where(a => a.SERVICE_WORKFLOW_ID == entity.PK_ID && a.WF_VERSION == currVersion).ExecuteCommand();
}
//服务流程与服务项目关系
if (info.ServiceProject != null && !string.IsNullOrWhiteSpace(info.ServiceProject.PKId))
{
var wfRelationProject = new ServiceWorkFlowProjectRelation
{
PK_ID = SnowFlakeSingle.Instance.NextId().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_PROJECT_ID = info.ServiceProject.PKId,
WF_VERSION = currVersion
};
//插入关系
await _serviceWorkFlowProjectRelationRepository.InsertAsync(wfRelationProject);
}
//服务流程与服务活动关系
if (info.StatusSkuList != null && info.StatusSkuList.Count > 0)
{
info.StatusSkuList.ForEach(async sku =>
{
var wfRelationActivities = new ServiceWorkFlowActivitiesRelation
{
PK_ID = SnowFlakeSingle.Instance.NextId().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sku.PKId,
SORT_NO = sku.SortNo,
IS_CONTAINS_SUB = sku.IsContainsSub,
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType) ? sku.ValType : StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesRelationRepository.InsertAsync(wfRelationActivities);
//处理子状态
if (sku.IsContainsSub == 1)
{
sku.SubList.ForEach(async sub => {
var wfRelationActivitiesSub = new ServiceWorkFlowActivitiesSubRelation
{
PK_ID = SnowFlakeSingle.Instance.NextId().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sku.PKId,
SUB_SERVICE_ACTIVITIES_ID = sub.PKId,
SORT_NO = sub.SortNo,
VAL_TYPE = !string.IsNullOrWhiteSpace(sku.ValType) ? sku.ValType : StatusSKUValTypeEnum.DATETIME.ToString(),
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesSubRelationRepository.InsertAsync(wfRelationActivitiesSub);
if (sub != null && sub.StatusTriggerList != null && sub.StatusTriggerList.Count > 0)
{
sub.StatusTriggerList.ForEach(async trg =>
{
var triggerRela = new ServiceWorkFlowActivitiesTriggerRelation
{
PK_ID = SnowFlakeSingle.Instance.NextId().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sub.PKId,
STATUS_TRIGGER_ID = trg.PKId,
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesTriggerRelationRepository.InsertAsync(triggerRela);
});
}
});
}
if (sku.StatusTriggerList != null && sku.StatusTriggerList.Count > 0)
{
sku.StatusTriggerList.ForEach(async trg =>
{
var triggerRela = new ServiceWorkFlowActivitiesTriggerRelation
{
PK_ID = SnowFlakeSingle.Instance.NextId().ToString(),
SERVICE_WORKFLOW_ID = entity.PK_ID,
SERVICE_ACTIVITIES_ID = sku.PKId,
STATUS_TRIGGER_ID = trg.PKId,
WF_VERSION = currVersion
};
await _serviceWorkFlowActivitiesTriggerRelationRepository.InsertAsync(triggerRela);
});
}
});
}
return entity.PK_ID;
}
#endregion
#region 校验
/// <summary>
/// 校验
/// </summary>
/// <param name="entity">服务流程详情</param>
/// <param name="opTypeEnum">操作类型枚举</param>
/// <returns></returns>
private void ValidateServiceWorkFlow(ServiceWorkFlowBaseInfo entity, TrackingOperateTypeEnum opTypeEnum)
{
if (opTypeEnum == TrackingOperateTypeEnum.Save)
{
if (_serviceWorkFlowProjectRelationRepository.AsQueryable().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
{
throw Oops.Oh($"当前服务项目已关联服务流程,不能修改", typeof(InvalidOperationException));
}
if (entity.SERVICE_WORKFLOW_CODE.Length < 2 || entity.SERVICE_WORKFLOW_NAME.Length < 2)
throw Oops.Oh($"服务流程代码和状态名称不能小于2个字符不能修改", typeof(InvalidOperationException));
}
}
#endregion
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">服务流程详情</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> SaveAndEnable(ServiceWorkFlowBaseDto info);
/// <summary>
/// 启用
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<string>> SetEnable(string[] pkIds);
/// <summary>
/// 取消启用
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<string>> SetUnEnable(string[] pkIds);
/// <summary>
/// 删除
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<string>> Delete(string[] pkIds);
/// <summary>
/// 复制
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> Copy(string pkId);
/// <summary>
/// 获取服务流程详情
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
Task<DataResult<ServiceWorkFlowBaseShowDto>> GetInfo(string pkId);
/// <summary>
/// 检索服务流程列表
/// </summary>
/// <param name="queryItem">检索值</param>
/// <param name="topNum">最大返回行数默认15</param>
/// <returns>返回回执</returns>
Task<DataResult<List<ServiceWorkFlowBaseDto>>> QueryList(string queryItem, int topNum = 15);
/// <summary>
/// 服务流程台账查询
/// </summary>
/// <param name="QuerySearch">服务流程台账查询请求</param>
/// <returns>返回结果</returns>
Task<SqlSugarPagedList<ServiceWorkFlowBasePageDto>> GetPageAsync(QueryServiceWorkFlowBaseDto QuerySearch);
/// <summary>
/// 发布服务流程
/// </summary>
/// <param name="pkIds">服务流程主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<string>> PublishRelease(string[] pkIds);
/// <summary>
/// 获取展示服务流程时间轴列表
/// </summary>
/// <param name="pkId">服务流程主键</param>
/// <returns>返回回执</returns>
Task<DataResult<ServiceWorkFlowRunDto>> GetShowTimeLine(string pkId);
/// <summary>
/// 保存服务流程活动
/// </summary>
/// <param name="info">保存服务流程活动详情</param>
/// <returns>返回回执</returns>
Task<DataResult<long>> SaveWFActivities(ServiceWorkFlowActivitiesDto info);
/// <summary>
/// 通过服务活动主键获取所有相关服务流程列表
/// </summary>
/// <param name="activitiesArgs">服务活动主键数组</param>
/// <returns>返回回执</returns>
Task<DataResult<List<ServiceProjectBaseShowDto>>> GetServiceWorkFlowListByActivities(string[] activitiesArgs);
/// <summary>
/// 检索服务流程活动列表
/// </summary>
/// <param name="queryItem">检索值</param>
/// <param name="topNum">最大返回行数默认15</param>
/// <returns>返回回执</returns>
Task<DataResult<List<StatusSkuBaseDto>>> QueryActivitiesList(string queryItem, int topNum = 15);
/// <summary>
/// 检索可用的服务项目列表
/// </summary>
/// <param name="tenantId">租户ID</param>
/// <param name="isAvoidCache">是否不从缓存取值</param>
/// <returns>返回回执</returns>
Task<DataResult<List<ServiceProjectBaseDto>>> GetEnableProjectList(string tenantId, bool isAvoidCache = false);
/// <summary>
/// 检索可用的服务项目和状态列表
/// </summary>
/// <param name="tenantId">租户ID</param>
/// <param name="isAvoidCache">是否不从缓存取值</param>
/// <returns>返回回执</returns>
Task<DataResult<List<ServiceProjectWithStatusDto>>> GetEnableProjectWithStatusList(string tenantId, bool isAvoidCache = false);
/// <summary>
/// 获取可用的服务项目字典列表
/// </summary>
/// <param name="isAvoidCache">是否重新加载缓存</param>
/// <returns></returns>
Task<DataResult<List<DictTreeOutput>>> GetEnableProjectDictTreeList(bool isAvoidCache = false);
/// <summary>
/// 获取可用的服务状态字典列表
/// </summary>
/// <param name="isAvoidCache">是否重新加载缓存</param>
/// <returns></returns>
Task<DataResult<List<DictTreeOutput>>> GetEnableStatusDictTreeList(bool isAvoidCache = false);
}*/
}
}
Loading…
Cancel
Save