|
|
|
@ -3,10 +3,746 @@ 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.ServiceProject
|
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
|
|
|
{
|
|
|
|
|
internal class ServiceProjectService
|
|
|
|
|
public class ServiceProjectService: IServiceProjectService
|
|
|
|
|
{
|
|
|
|
|
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 ServiceProjectService(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<string>> Save(ServiceProjectBaseDto info)
|
|
|
|
|
{
|
|
|
|
|
return await InnerSave(info);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存内部方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">服务项目详情</param>
|
|
|
|
|
/// <param name="isSetEnable">是否启用</param>
|
|
|
|
|
/// <returns>返回派车Id</returns>
|
|
|
|
|
private async Task<DataResult<string>> InnerSave(ServiceProjectBaseDto info, bool isSetEnable = false)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
ServiceProjectBaseInfo entity = info.Adapt<ServiceProjectBaseInfo>();
|
|
|
|
|
|
|
|
|
|
if (isSetEnable)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.SERVICE_PROJECT_CODE) || string.IsNullOrWhiteSpace(entity.SERVICE_PROJECT_NAME))
|
|
|
|
|
{
|
|
|
|
|
//服务项目代码或名称不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveNameNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.SORT_NO <= 0)
|
|
|
|
|
{
|
|
|
|
|
//排序值不能小于等于0
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveSortNotEqualLessZero)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.IS_ENABLE = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity == null)
|
|
|
|
|
{
|
|
|
|
|
//服务项目不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveModelNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"服务项目保存 JSON={JsonConvert.SerializeObject(entity)} user={user.UserId}");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(info.ServiceProjectCode))
|
|
|
|
|
{
|
|
|
|
|
string pkId = !string.IsNullOrWhiteSpace(info.PKId) ? info.PKId : string.Empty;
|
|
|
|
|
|
|
|
|
|
if (tenantDb.Queryable<ServiceProjectBaseInfo>().Any(a => a.SERVICE_PROJECT_CODE.Equals(info.ServiceProjectCode) && a.PK_ID != pkId))
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"服务项目代码已存在不能重复保存");
|
|
|
|
|
|
|
|
|
|
//服务项目代码已存在不能重复保存
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectSaveCodeExists)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
entity.PK_ID = SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
|
|
|
|
tenantDb.Insertable<ServiceProjectBaseInfo>(entity).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var model = tenantDb.Queryable<ServiceProjectBaseInfo>().First(a => a.PK_ID == entity.PK_ID);
|
|
|
|
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
//服务项目获取失败,服务项目信息不存在或已作废
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"更新服务项目前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
|
|
|
|
|
|
|
|
|
|
ValidateServiceProject(entity, TrackingOperateTypeEnum.Save);
|
|
|
|
|
|
|
|
|
|
entity.UpdateTime = DateTime.Now;
|
|
|
|
|
entity.UpdateBy = long.Parse(user.UserId);
|
|
|
|
|
entity.UpdateUserName = user.UserName;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable<ServiceProjectBaseInfo>(entity).IgnoreColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.UpdateTime,
|
|
|
|
|
it.UpdateBy,
|
|
|
|
|
it.UpdateUserName,
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(entity.PK_ID);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校验
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entity">服务项目详情</param>
|
|
|
|
|
/// <param name="opTypeEnum">操作类型枚举</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private void ValidateServiceProject(ServiceProjectBaseInfo entity, TrackingOperateTypeEnum opTypeEnum)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
1、服务项目代码和名称不能低于2个字符。
|
|
|
|
|
2、服务项目修改,需要判断当前服务项目是否关联服务流程。已关联的不能修改服务项目。
|
|
|
|
|
3、取消启用时,需要判断当前服务项目是否关联服务流程。已关联的不能取消启用。
|
|
|
|
|
*/
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.Save)
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<ServiceWorkFlowProjectRelation>().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
//当前服务项目已关联服务流程,不能修改
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectHasRelateWFActNotSave)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entity.SERVICE_PROJECT_CODE.Length < 2 || entity.SERVICE_PROJECT_NAME.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
//服务项目代码和状态名称不能小于2个字符,不能修改
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectCodeNameLessTwoChar)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
|
|
|
|
|
{
|
|
|
|
|
if (tenantDb.Queryable<ServiceWorkFlowProjectRelation>().Any(a => a.SERVICE_PROJECT_ID == entity.PK_ID))
|
|
|
|
|
{
|
|
|
|
|
//当前服务项目已关联服务流程,不能取消启用
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectHasRelateWFActNotSetUnEnable)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 保存并启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存并启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="info">服务项目详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SaveAndEnable([FromBody] ServiceProjectBaseDto info)
|
|
|
|
|
{
|
|
|
|
|
return await InnerSave(info, true);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">服务项目主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SetEnable([FromBody] string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//服务项目主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//当前服务项目已关联服务流程,不能取消启用
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分服务项目获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceProject(pr, TrackingOperateTypeEnum.SetEnable).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"启用服务项目异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"启用服务项目异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 取消启用
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消启用
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">服务项目主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> SetUnEnable(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//服务项目主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//当前服务项目已关联服务流程,不能取消启用
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分服务项目获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceProject(pr, TrackingOperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"取消启用服务项目异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"取消启用服务项目异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 删除
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkIds">服务项目主键数组</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<string>> Delete(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string batchTotal = string.Empty;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (ids.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
//服务项目主键数组不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectBatchIdsNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var list = tenantDb.Queryable<ServiceProjectBaseInfo>()
|
|
|
|
|
.Where(a => ids.Contains(a.PK_ID)).ToList();
|
|
|
|
|
|
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
//当前服务项目已关联服务流程,不能取消启用
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (list.Count != ids.Length)
|
|
|
|
|
{
|
|
|
|
|
//部分服务项目获取失败,请服务项目信息是否存在
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityPartNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<DataResult<string>> rltList = new List<DataResult<string>>();
|
|
|
|
|
|
|
|
|
|
list.ForEach(pr => {
|
|
|
|
|
|
|
|
|
|
rltList.Add(InnerExcuteServiceProject(pr, TrackingOperateTypeEnum.SetUnEnable).GetAwaiter().GetResult());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var succ = rltList.Count(x => x.Succeeded);
|
|
|
|
|
var fail = rltList.Count(x => !x.Succeeded);
|
|
|
|
|
|
|
|
|
|
if (succ > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal = succ.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal = "- ";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fail > 0)
|
|
|
|
|
{
|
|
|
|
|
batchTotal += "/" + fail.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
batchTotal += " -";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"删除服务项目异常,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"删除服务项目异常,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(batchTotal);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 处理服务项目内部方法
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理服务项目内部方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">服务项目详情</param>
|
|
|
|
|
/// <param name="opTypeEnum">操作类型</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
private async Task<DataResult<string>> InnerExcuteServiceProject(ServiceProjectBaseInfo model, TrackingOperateTypeEnum opTypeEnum)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
string name = model?.SERVICE_PROJECT_NAME;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
//服务项目获取失败,服务项目信息不存在或已作废
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"更新服务项目前,获取原始记录 JSON={JsonConvert.SerializeObject(model)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (opTypeEnum == TrackingOperateTypeEnum.SetEnable)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.SERVICE_PROJECT_CODE) || string.IsNullOrWhiteSpace(model.SERVICE_PROJECT_NAME))
|
|
|
|
|
{
|
|
|
|
|
//throw Oops.Oh($"服务项代码或名称不能为空", typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.SORT_NO <= 0)
|
|
|
|
|
{
|
|
|
|
|
//throw Oops.Oh($"排序值不能小于等于0", typeof(InvalidOperationException));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.IS_ENABLE = 1;
|
|
|
|
|
|
|
|
|
|
model.UpdateTime = DateTime.Now;
|
|
|
|
|
model.UpdateBy = long.Parse(user.UserId);
|
|
|
|
|
model.UpdateUserName = user.UserName;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.IS_ENABLE,
|
|
|
|
|
it.UpdateTime,
|
|
|
|
|
it.UpdateBy,
|
|
|
|
|
it.UpdateUserName
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (opTypeEnum == TrackingOperateTypeEnum.SetUnEnable)
|
|
|
|
|
{
|
|
|
|
|
ValidateServiceProject(model, opTypeEnum);
|
|
|
|
|
|
|
|
|
|
model.IS_ENABLE = 0;
|
|
|
|
|
model.UpdateTime = DateTime.Now;
|
|
|
|
|
model.UpdateBy = long.Parse(user.UserId);
|
|
|
|
|
model.UpdateUserName = user.UserName;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.IS_ENABLE,
|
|
|
|
|
it.UpdateTime,
|
|
|
|
|
it.UpdateBy,
|
|
|
|
|
it.UpdateUserName
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (opTypeEnum == TrackingOperateTypeEnum.Delete)
|
|
|
|
|
{
|
|
|
|
|
ValidateServiceProject(model, opTypeEnum);
|
|
|
|
|
|
|
|
|
|
model.Deleted = true;
|
|
|
|
|
model.DeleteTime = DateTime.Now;
|
|
|
|
|
model.DeleteBy = long.Parse(user.UserId);
|
|
|
|
|
model.DeleteUserName = user.UserName;
|
|
|
|
|
|
|
|
|
|
await tenantDb.Updateable<ServiceProjectBaseInfo>(model).UpdateColumns(it => new
|
|
|
|
|
{
|
|
|
|
|
it.Deleted,
|
|
|
|
|
it.DeleteTime,
|
|
|
|
|
it.DeleteBy,
|
|
|
|
|
it.DeleteUserName
|
|
|
|
|
|
|
|
|
|
}).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Log(NLog.LogLevel.Info, $"执行失败,原因:{ex.Message}");
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Failed($"执行失败,原因:{ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<string>.Success(name);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取服务项目详情
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取服务项目详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pkId">服务项目主键</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<ServiceProjectBaseShowDto>> GetInfo(string pkId)
|
|
|
|
|
{
|
|
|
|
|
var model = InnerGetInfo(pkId);
|
|
|
|
|
|
|
|
|
|
var showModel = model.Adapt<ServiceProjectBaseShowDto>();
|
|
|
|
|
|
|
|
|
|
return DataResult<ServiceProjectBaseShowDto>.Success(showModel);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 单票查询
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单票查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">状态主键</param>
|
|
|
|
|
private ServiceProjectBaseInfo InnerGetInfo(string id)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(id))
|
|
|
|
|
{
|
|
|
|
|
//服务项目主键不能为空
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuSaveIdNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var model = tenantDb.Queryable<ServiceProjectBaseInfo>().First(a => a.PK_ID == id);
|
|
|
|
|
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
//服务项目获取失败,服务项目信息不存在或已作废
|
|
|
|
|
throw new Exception(MultiLanguageConst.GetDescription(nameof(MultiLanguageConst.ServiceProjectStatusSkuEntityNull)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 检索服务项目列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 检索服务项目列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="queryItem">检索值</param>
|
|
|
|
|
/// <param name="topNum">最大返回行数(默认15)</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DataResult<List<ServiceProjectBaseDto>>> QueryList([FromQuery] string queryItem, [FromQuery] int topNum = 15)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
var list = await tenantDb.Queryable<ServiceProjectBaseInfo>().Where(a => a.IS_ENABLE == 1 && a.Deleted == false)
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(queryItem), a => (a.SERVICE_PROJECT_CODE.Contains(queryItem) || a.SERVICE_PROJECT_NAME.Contains(queryItem)))
|
|
|
|
|
.Take(topNum).ToListAsync();
|
|
|
|
|
|
|
|
|
|
var rltList = list.Adapt<List<ServiceProjectBaseDto>>();
|
|
|
|
|
|
|
|
|
|
return DataResult<List<ServiceProjectBaseDto>>.Success(rltList);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 服务项目台账查询
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 服务项目台账查询
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="QuerySearch">服务项目台账查询请求</param>
|
|
|
|
|
/// <returns>返回结果</returns>
|
|
|
|
|
public async Task<DataResult<List<ServiceProjectBasePageDto>>> GetPageAsync(PageRequest querySearch)
|
|
|
|
|
{
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
List<IConditionalModel> whereList = null;
|
|
|
|
|
|
|
|
|
|
ServiceProjectBaseQueryExtDto otherQueryCondition = new ServiceProjectBaseQueryExtDto();
|
|
|
|
|
|
|
|
|
|
whereList = GetPageCondition(querySearch, out otherQueryCondition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var query = tenantDb.Queryable<ServiceProjectBaseInfo>()
|
|
|
|
|
.Where(whereList)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.ServiceProjectName), a =>
|
|
|
|
|
a.SERVICE_PROJECT_CODE.Contains(otherQueryCondition.ServiceProjectName) || a.SERVICE_PROJECT_NAME.Contains(otherQueryCondition.ServiceProjectName))
|
|
|
|
|
.WhereIF(otherQueryCondition != null && !string.IsNullOrWhiteSpace(otherQueryCondition.ServiceProjectNote), a =>
|
|
|
|
|
a.SERVICE_PROJECT_NOTE.Contains(otherQueryCondition.ServiceProjectNote))
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.CreateStart.HasValue, a => a.CreateTime >= otherQueryCondition.CreateStart)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.CreateEnd.HasValue, a => a.CreateTime < otherQueryCondition.CreateEnd)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.UpdateStart.HasValue, a => a.UpdateTime >= otherQueryCondition.UpdateStart)
|
|
|
|
|
.WhereIF(otherQueryCondition != null && otherQueryCondition.UpdateEnd.HasValue, a => a.UpdateTime < otherQueryCondition.UpdateEnd);
|
|
|
|
|
|
|
|
|
|
if (whereList != null)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(whereList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await query.ToQueryPageAsync(querySearch.PageCondition);
|
|
|
|
|
|
|
|
|
|
List<ServiceProjectBasePageDto> resultList = new List<ServiceProjectBasePageDto>();
|
|
|
|
|
|
|
|
|
|
if (result.Data.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
resultList = result.Data.Adapt<List<ServiceProjectBasePageDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return DataResult<List<ServiceProjectBasePageDto>>.PageList(result.Count, resultList, MultiLanguageConst.DataQuerySuccess);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取台账查询条件
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取台账查询条件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="querySearch">原始查询条件</param>
|
|
|
|
|
/// <param name="queryExt">其他查询条件</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private List<IConditionalModel> GetPageCondition(PageRequest querySearch, out ServiceProjectBaseQueryExtDto queryExt)
|
|
|
|
|
{
|
|
|
|
|
List<IConditionalModel> whereList = null;
|
|
|
|
|
|
|
|
|
|
queryExt = new ServiceProjectBaseQueryExtDto();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(querySearch.OtherQueryCondition))
|
|
|
|
|
{
|
|
|
|
|
queryExt = JsonConvert.DeserializeObject<ServiceProjectBaseQueryExtDto>(querySearch.OtherQueryCondition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(querySearch.QueryCondition))
|
|
|
|
|
{
|
|
|
|
|
whereList = querySearch.GetConditionalModels(db);
|
|
|
|
|
|
|
|
|
|
#region 处理查询条件
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectName", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectName", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.ServiceProjectName = ((ConditionalModel)t).FieldValue;
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectNote", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("ServiceProjectNote", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.ServiceProjectNote = ((ConditionalModel)t).FieldValue;
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("CreateBy", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("CreateBy", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.CreateBy = long.Parse(((ConditionalModel)t).FieldValue);
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("UpdateBy", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var t = whereList.FirstOrDefault(t => ((ConditionalModel)t).FieldName.Equals("UpdateBy", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
queryExt.UpdateBy = long.Parse(((ConditionalModel)t).FieldValue);
|
|
|
|
|
|
|
|
|
|
whereList.Remove(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("CreateTime", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("CreateTime", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (ConditionalModel b in curList)
|
|
|
|
|
{
|
|
|
|
|
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.CreateStart = currDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.CreateEnd = currDate.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whereList.Remove(b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (whereList.Any(t => ((ConditionalModel)t).FieldName.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase)))
|
|
|
|
|
{
|
|
|
|
|
var curList = whereList.Where(t => ((ConditionalModel)t).FieldName.Equals("UpdateTime", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (ConditionalModel b in curList)
|
|
|
|
|
{
|
|
|
|
|
if (b.ConditionalType == ConditionalType.GreaterThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.UpdateStart = currDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (b.ConditionalType == ConditionalType.LessThanOrEqual)
|
|
|
|
|
{
|
|
|
|
|
DateTime currDate = DateTime.MinValue;
|
|
|
|
|
if (DateTime.TryParse(b.FieldValue, out currDate))
|
|
|
|
|
{
|
|
|
|
|
queryExt.UpdateEnd = currDate.AddDays(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
whereList.Remove(b);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return whereList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|