新增修改状态管理

optimize
jianghaiqing 1 year ago
parent 2fc9ff1f4d
commit 3f63e245ea

@ -1,12 +1,46 @@
using System;
using Myshipping.Core;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application.Entity
{
internal class ServiceWorkFlowActivitiesInfo
/// <summary>
/// 服务流程活动表
/// </summary>
[Tenant(CommonConst.MasterDb)]
[SugarTable("service_workflow_activities")]
[Description("服务流程活动表")]
public class ServiceWorkFlowActivitiesInfo
{
/// <summary>
/// 主键
/// </summary>
[SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true)]
public string PK_ID { get; set; }
/// <summary>
/// 服务流程主键
/// </summary>
public string SERVICE_WORKFLOW_ID { get; set; }
/// <summary>
/// 状态主键
/// </summary>
public string STATUS_SKU_ID { get; set; }
/// <summary>
/// 状态显示名称
/// </summary>
public string SHOW_NAME { get; set; }
/// <summary>
/// 显示顺序号
/// </summary>
public int SORT_NO { get; set; }
}
}

@ -50,6 +50,6 @@ namespace Myshipping.Application.Entity
/// <summary>
/// 状态说明
/// </summary>
public string STATUS_NOTE { get; set; }
public string STATUS_SKU_NOTE { get; set; }
}
}

@ -9,7 +9,7 @@ namespace Myshipping.Application
/// <summary>
///
/// </summary>
public class QueryStatusSkuBaseDto
public class QueryStatusSkuBaseDto : QueryTaskManageBaseDto
{
/// <summary>
/// 创建日期起始

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Myshipping.Application
{
internal class StatusSkuBasePageDto
public class StatusSkuBasePageDto: StatusSkuBaseShowDto
{
}
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Myshipping.Application
{
/// <summary>
///
/// </summary>
public class StatusSkuBaseShowDto : StatusSkuBaseDto
{
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public Nullable<DateTime> UpdatedTime { get; set; }
/// <summary>
/// 创建人ID
/// </summary>
public long CreatedUserId { get; set; }
/// <summary>
/// 创建人名称
/// </summary>
public string CreatedUserName { get; set; }
/// <summary>
/// 修改人ID
/// </summary>
public long UpdatedUserId { get; set; }
/// <summary>
/// 修改人名称
/// </summary>
public string UpdatedUserName { get; set; }
}
}

@ -35,6 +35,54 @@ namespace Myshipping.Application
.Map(dest => dest.UpdatedUserName, src => src.UpdatedUserName)
.Map(dest => dest.ServiceProjectNote, src => src.SERVICE_PROJECT_NOTE);
config.ForType<ServiceProjectBaseInfo, ServiceProjectBasePageDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.ServiceProjectCode, src => src.SERVICE_PROJECT_CODE)
.Map(dest => dest.ServiceProjectName, src => src.SERVICE_PROJECT_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO)
.Map(dest => dest.CreatedTime, src => src.CreatedTime)
.Map(dest => dest.UpdatedTime, src => src.UpdatedTime)
.Map(dest => dest.CreatedUserId, src => src.CreatedUserId)
.Map(dest => dest.CreatedUserName, src => src.CreatedUserName)
.Map(dest => dest.UpdatedUserId, src => src.UpdatedUserId)
.Map(dest => dest.UpdatedUserName, src => src.UpdatedUserName)
.Map(dest => dest.ServiceProjectNote, src => src.SERVICE_PROJECT_NOTE);
config.ForType<StatusSkuBaseDto, StatusSkuBaseInfo>()
.Map(dest => dest.PK_ID, src => src.PKId)
.Map(dest => dest.STATUS_SKU_CODE, src => src.StatusSKUCode)
.Map(dest => dest.STATUS_SKU_NAME, src => src.StatusSKUName)
.Map(dest => dest.SORT_NO, src => src.SortNo)
.Map(dest => dest.STATUS_SKU_NOTE, src => src.StatusSKUNote)
.Map(dest => dest.BACKGROUND_COLOR, src => src.BackgroundColor);
config.ForType<StatusSkuBaseInfo, StatusSkuBaseShowDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUCode, src => src.STATUS_SKU_CODE)
.Map(dest => dest.StatusSKUName, src => src.STATUS_SKU_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO)
.Map(dest => dest.CreatedTime, src => src.CreatedTime)
.Map(dest => dest.UpdatedTime, src => src.UpdatedTime)
.Map(dest => dest.CreatedUserId, src => src.CreatedUserId)
.Map(dest => dest.CreatedUserName, src => src.CreatedUserName)
.Map(dest => dest.UpdatedUserId, src => src.UpdatedUserId)
.Map(dest => dest.UpdatedUserName, src => src.UpdatedUserName)
.Map(dest => dest.StatusSKUNote, src => src.STATUS_SKU_NOTE)
.Map(dest => dest.BackgroundColor, src => src.BACKGROUND_COLOR);
config.ForType<StatusSkuBaseInfo, StatusSkuBasePageDto>()
.Map(dest => dest.PKId, src => src.PK_ID)
.Map(dest => dest.StatusSKUCode, src => src.STATUS_SKU_CODE)
.Map(dest => dest.StatusSKUName, src => src.STATUS_SKU_NAME)
.Map(dest => dest.SortNo, src => src.SORT_NO)
.Map(dest => dest.CreatedTime, src => src.CreatedTime)
.Map(dest => dest.UpdatedTime, src => src.UpdatedTime)
.Map(dest => dest.CreatedUserId, src => src.CreatedUserId)
.Map(dest => dest.CreatedUserName, src => src.CreatedUserName)
.Map(dest => dest.UpdatedUserId, src => src.UpdatedUserId)
.Map(dest => dest.UpdatedUserName, src => src.UpdatedUserName)
.Map(dest => dest.StatusSKUNote, src => src.STATUS_SKU_NOTE)
.Map(dest => dest.BackgroundColor, src => src.BACKGROUND_COLOR);
}
}
}

@ -130,6 +130,7 @@ namespace Myshipping.Application
}
#endregion
#region 校验
/// <summary>
/// 校验
/// </summary>
@ -140,11 +141,12 @@ namespace Myshipping.Application
{
if (_serviceWorkFlowProjectRelationRepository.Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
{
_logger.LogInformation($"当前服务项目已关联服务流程不能修改产品代码,{entity.SERVICE_PROJECT_CODE}");
_logger.LogInformation($"当前服务项目已关联服务流程不能修改,{entity.SERVICE_PROJECT_CODE}");
throw Oops.Oh($"当前服务项目已关联服务流程不能修改产品代码", typeof(InvalidOperationException));
throw Oops.Oh($"当前服务项目已关联服务流程不能修改", typeof(InvalidOperationException));
}
}
#endregion
#region 保存并启用
/// <summary>
@ -168,7 +170,7 @@ namespace Myshipping.Application
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
result.msg = $"保存并启用服务项目异常,原因:{ex.Message}";
}
return result;
@ -411,8 +413,8 @@ namespace Myshipping.Application
/// </summary>
/// <param name="QuerySearch">服务项目台账查询请求</param>
/// <returns>返回结果</returns>
[HttpGet("/ServiceProject/GetPage")]
public async Task<SqlSugarPagedList<ServiceProjectBasePageDto>> GetPageAsync(QueryServiceProjectBaseDto QuerySearch)
[HttpPost("/ServiceProject/GetPage")]
public async Task<SqlSugarPagedList<ServiceProjectBasePageDto>> GetPageAsync([FromBody]QueryServiceProjectBaseDto QuerySearch)
{
//制单日期
DateTime createBegin = DateTime.MinValue;

@ -1,4 +1,14 @@
using System;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Myshipping.Application.Entity;
using Myshipping.Application.Helper;
using Myshipping.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -6,7 +16,451 @@ using System.Threading.Tasks;
namespace Myshipping.Application
{
public class StatusSkuBaseService
[ApiDescriptionSettings("Application", Name = "StatusSkuBase", Order = 10)]
public class StatusSkuBaseService : IStatusSkuBaseService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<StatusSkuBaseInfo> _statusSkuBaseInfoRepository;
private readonly SqlSugarRepository<ServiceWorkFlowActivitiesInfo> _serviceWorkFlowActivitiesInfoRepository;
private readonly ILogger<StatusSkuBaseService> _logger;
public StatusSkuBaseService(SqlSugarRepository<StatusSkuBaseInfo> statusSkuBaseInfoRepository,
ILogger<StatusSkuBaseService> logger,
SqlSugarRepository<ServiceWorkFlowActivitiesInfo> serviceWorkFlowActivitiesInfoRepository)
{
_statusSkuBaseInfoRepository = statusSkuBaseInfoRepository;
_logger = logger;
_serviceWorkFlowActivitiesInfoRepository = serviceWorkFlowActivitiesInfoRepository;
}
#region 保存
/// <summary>
/// 保存
/// </summary>
/// <param name="info">状态详情</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusSkuBase/Save")]
public async Task<TaskManageOrderResultDto> Save([FromBody] StatusSkuBaseDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var id = await InnerSave(info);
result.succ = true;
result.msg = "保存成功";
result.ext = id;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存服务项目异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 保存内部方法
/// <summary>
/// 保存内部方法
/// </summary>
/// <param name="info">服务项目详情</param>
/// <param name="isSetEnable">是否启用</param>
/// <returns>返回派车Id</returns>
[SqlSugarUnitOfWork]
private async Task<string> InnerSave(StatusSkuBaseDto info, bool isSetEnable = false)
{
StatusSkuBaseInfo entity = info.Adapt<StatusSkuBaseInfo>();
if (isSetEnable)
{
entity.IS_ENABLE = 1;
}
if (entity == null)
throw Oops.Oh($"服务项目不能为空", typeof(InvalidOperationException));
_logger.LogInformation($"服务项目保存 JSON={JSON.Serialize(entity)} user={UserManager.UserId}");
if (string.IsNullOrWhiteSpace(entity.PK_ID))
{
_statusSkuBaseInfoRepository.Insert(entity);
}
else
{
var model = InnerGetInfo(entity.PK_ID);
_logger.LogInformation($"更新状态前,获取原始记录 JSON={JSON.Serialize(model)}");
/*
*/
if (!entity.STATUS_SKU_CODE.Equals(model.STATUS_SKU_CODE, StringComparison.OrdinalIgnoreCase))
{
ValidateServiceProject(entity, true);
}
entity.UpdatedTime = DateTime.Now;
entity.UpdatedUserId = UserManager.UserId;
entity.UpdatedUserName = UserManager.Name;
await _statusSkuBaseInfoRepository.AsUpdateable(entity).IgnoreColumns(it => new
{
it.TenantId,
it.TenantName,
it.CreatedTime,
it.CreatedUserId,
it.CreatedUserName,
it.IsDeleted,
}).ExecuteCommandAsync();
}
return entity.PK_ID;
}
#endregion
#region 单票查询
/// <summary>
/// 单票查询
/// </summary>
/// <param name="pkId">状态主键</param>
private StatusSkuBaseInfo InnerGetInfo(string pkId)
{
if (string.IsNullOrWhiteSpace(pkId))
{
throw Oops.Oh($"状态主键不能为空", typeof(InvalidOperationException));
}
var model = _statusSkuBaseInfoRepository.AsQueryable().First(a => a.PK_ID == pkId);
if (model == null)
throw Oops.Oh($"状态获取失败,状态信息不存在或已作废", typeof(InvalidOperationException));
return model;
}
#endregion
#region 校验
/// <summary>
/// 校验
/// </summary>
/// <param name="entity">服务项目详情</param>
/// <param name="isCheckRelation">是否校验关系</param>
/// <returns></returns>
private void ValidateServiceProject(StatusSkuBaseInfo entity, bool isCheckRelation = false)
{
if (isCheckRelation && _serviceWorkFlowActivitiesInfoRepository.Any(a => a.STATUS_SKU_ID == entity.PK_ID))
{
_logger.LogInformation($"当前状态已关联服务流程不能修改");
throw Oops.Oh($"当前状态已关联服务流程不能修改", typeof(InvalidOperationException));
}
}
#endregion
#region 保存并启用
/// <summary>
/// 保存并启用
/// </summary>
/// <param name="info">状态详情</param>
/// <returns>返回回执</returns>
[HttpPost("/StatusSkuBase/SaveAndEnable")]
public async Task<TaskManageOrderResultDto> SaveAndEnable([FromBody] StatusSkuBaseDto info)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var id = await InnerSave(info, true);
result.succ = true;
result.msg = "执行成功";
result.ext = id;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"保存并启用状态异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 启用
/// <summary>
/// 启用
/// </summary>
/// <param name="pkId">状态主键</param>
/// <returns>返回回执</returns>
[HttpGet("/StatusSkuBase/SetEnable")]
public async Task<TaskManageOrderResultDto> SetEnable([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerGetInfo(pkId);
_logger.LogInformation($"更新状态前,获取原始记录 JSON={JSON.Serialize(model)}");
ValidateServiceProject(model, true);
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
model.IS_ENABLE = 1;
await _statusSkuBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 取消启用
/// <summary>
/// 取消启用
/// </summary>
/// <param name="pkId">状态主键</param>
/// <returns>返回回执</returns>
[HttpGet("/StatusSkuBase/SetUnEnable")]
public async Task<TaskManageOrderResultDto> SetUnEnable([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerGetInfo(pkId);
_logger.LogInformation($"更新状态前,获取原始记录 JSON={JSON.Serialize(model)}");
ValidateServiceProject(model, true);
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
model.IS_ENABLE = 0;
await _statusSkuBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IS_ENABLE,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"执行启用异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <param name="pkId">状态主键</param>
/// <returns>返回回执</returns>
[HttpGet("/StatusSkuBase/Delete")]
public async Task<TaskManageOrderResultDto> Delete([FromQuery] string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerGetInfo(pkId);
_logger.LogInformation($"更新服务项目前,获取原始记录 JSON={JSON.Serialize(model)}");
if (model.IS_ENABLE == 1)
ValidateServiceProject(model, true);
model.UpdatedTime = DateTime.Now;
model.UpdatedUserId = UserManager.UserId;
model.UpdatedUserName = UserManager.Name;
model.IsDeleted = true;
await _statusSkuBaseInfoRepository.AsUpdateable(model).UpdateColumns(it => new
{
it.IsDeleted,
it.UpdatedTime,
it.UpdatedUserId,
it.UpdatedUserName
}).ExecuteCommandAsync();
result.succ = true;
result.msg = "执行成功";
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"删除状态异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 获取状态详情
/// <summary>
/// 获取状态详情
/// </summary>
/// <param name="pkId">状态主键</param>
/// <returns>返回回执</returns>
[HttpGet("/StatusSkuBase/GetInfo")]
public async Task<TaskManageOrderResultDto> GetInfo([FromQuery]string pkId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var model = InnerGetInfo(pkId);
var showModel = model.Adapt<ServiceProjectBaseShowDto>();
result.succ = true;
result.ext = showModel;
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"获取状态详情异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 检索状态列表
/// <summary>
/// 检索状态列表
/// </summary>
/// <param name="queryItem">检索值</param>
/// <param name="topNum">最大返回行数默认15</param>
/// <returns>返回回执</returns>
[HttpGet("/StatusSkuBase/QueryList")]
public async Task<TaskManageOrderResultDto> QueryList(string queryItem, int topNum = 15)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
try
{
var list = await _statusSkuBaseInfoRepository.AsQueryable().Where(a =>
a.IS_ENABLE == 1 && !a.IsDeleted && (a.STATUS_SKU_CODE.Contains(queryItem) || a.STATUS_SKU_NAME.Contains(queryItem)))
.Take(topNum).ToListAsync();
result.succ = true;
result.ext = list.Adapt<List<ServiceProjectBaseDto>>();
}
catch (Exception ex)
{
result.succ = false;
result.msg = $"检索状态列表异常,原因:{ex.Message}";
}
return result;
}
#endregion
#region 状态台账查询
/// <summary>
/// 状态台账查询
/// </summary>
/// <param name="QuerySearch">状态台账查询请求</param>
/// <returns>返回结果</returns>
[HttpPost("/StatusSkuBase/GetPage")]
public async Task<SqlSugarPagedList<StatusSkuBasePageDto>> GetPageAsync([FromBody]QueryStatusSkuBaseDto QuerySearch)
{
//制单日期
DateTime createBegin = DateTime.MinValue;
DateTime createEnd = DateTime.MinValue;
//更新日期
DateTime updateBegin = DateTime.MinValue;
DateTime updateEnd = DateTime.MinValue;
//制单日期
if (!string.IsNullOrWhiteSpace(QuerySearch.CreateBegin))
{
if (!DateTime.TryParse(QuerySearch.CreateBegin, out createBegin))
throw Oops.Oh($"创建起始日期格式错误,{QuerySearch.CreateBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.CreateEnd))
{
if (!DateTime.TryParse(QuerySearch.CreateEnd, out createEnd))
throw Oops.Oh($"创建结束日期格式错误,{QuerySearch.CreateEnd}");
createEnd = createEnd.AddDays(1);
}
//更新日期
if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateBegin))
{
if (!DateTime.TryParse(QuerySearch.UpdateBegin, out updateBegin))
throw Oops.Oh($"更新起始日期格式错误,{QuerySearch.UpdateBegin}");
}
if (!string.IsNullOrWhiteSpace(QuerySearch.UpdateEnd))
{
if (!DateTime.TryParse(QuerySearch.UpdateEnd, out updateEnd))
throw Oops.Oh($"更新结束日期格式错误,{QuerySearch.UpdateEnd}");
updateEnd = updateEnd.AddDays(1);
}
string entityOrderCol = "CreatedTime";
//这里因为返回给前端的台账数据是DTO所以这里排序时候需要转换成Entity对应的字段
if (!string.IsNullOrWhiteSpace(QuerySearch.SortField))
entityOrderCol = MapsterExtHelper.GetAdaptProperty<BookingTruckDto, BookingTruck>(QuerySearch.SortField);
var entities = await _statusSkuBaseInfoRepository.AsQueryable()
.WhereIF(createBegin != DateTime.MinValue, t => t.CreatedTime >= createBegin)
.WhereIF(createEnd != DateTime.MinValue, t => t.CreatedTime < createEnd)
.WhereIF(updateBegin != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value >= updateBegin)
.WhereIF(updateEnd != DateTime.MinValue, t => t.UpdatedTime.HasValue && t.UpdatedTime.Value < updateEnd)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.IsEnable) && QuerySearch.IsEnable == "1", t => t.IS_ENABLE == 1)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.IsEnable) && QuerySearch.IsEnable == "2", t => t.IS_ENABLE == 0)
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.StatusSKUName), t => t.STATUS_SKU_NAME.Contains(QuerySearch.StatusSKUName) ||
t.STATUS_SKU_CODE.Contains(QuerySearch.StatusSKUName))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.StatusSKUNote), t => t.STATUS_SKU_NOTE.Contains(QuerySearch.StatusSKUNote))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.CreateUser), t => t.CreatedUserName.Contains(QuerySearch.CreateUser))
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.UpdateUser), t => t.UpdatedUserName.Contains(QuerySearch.UpdateUser))
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc "))
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
return entities.Adapt<SqlSugarPagedList<StatusSkuBasePageDto>>();
}
#endregion
}
}

Loading…
Cancel
Save