|
|
using Furion.DependencyInjection;
|
|
|
using Furion.DistributedIDGenerator;
|
|
|
using Furion.DynamicApiController;
|
|
|
using Furion.FriendlyException;
|
|
|
using Furion.RemoteRequest;
|
|
|
using Mapster;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Myshipping.Application.Entity;
|
|
|
using Myshipping.Application.Helper;
|
|
|
using Myshipping.Core;
|
|
|
using Myshipping.Core.Entity;
|
|
|
using MySqlX.XDevAPI.Common;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using SqlSugar;
|
|
|
using StackExchange.Profiling.Internal;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 任务管理
|
|
|
/// </summary>
|
|
|
[ApiDescriptionSettings("Application", Name = "TaskManage", Order = 10)]
|
|
|
public class TaskManageService : ITaskManageService, IDynamicApiController
|
|
|
{
|
|
|
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskSIFeedBackInfo> _taskSIFeedBackInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskSIFeedBackContaInfo> _taskSIFeedBackContaInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskBillFeeDetailInfo> _taskBillFeeDetailInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskFileInfo> _taskFileInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskEmailInfo> _taskEmailInfoRepository;
|
|
|
private readonly SqlSugarRepository<TaskVGMFeedBackInfo> _taskVGMFeedBackInfoRepository;
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRepository;
|
|
|
private readonly SqlSugarRepository<TaskStatManageInfo> _taskStatManageInfoRepository;
|
|
|
|
|
|
|
|
|
private readonly ILogger<BookingOrderService> _logger;
|
|
|
|
|
|
public TaskManageService(SqlSugarRepository<TaskBaseInfo> taskBaseInfoRepository,
|
|
|
SqlSugarRepository<TaskSIFeedBackInfo> taskSIFeedBackInfoRepository,
|
|
|
SqlSugarRepository<TaskSIFeedBackContaInfo> taskSIFeedBackContaInfoRepository,
|
|
|
SqlSugarRepository<TaskBillFeeDetailInfo> taskBillFeeDetailInfoRepository,
|
|
|
SqlSugarRepository<TaskFileInfo> taskFileInfoRepository,
|
|
|
SqlSugarRepository<TaskEmailInfo> taskEmailInfoRepository,
|
|
|
SqlSugarRepository<TaskVGMFeedBackInfo> taskVGMFeedBackInfoRepository,
|
|
|
SqlSugarRepository<SysUser> sysUserRepository,
|
|
|
SqlSugarRepository<TaskStatManageInfo> taskStatManageInfoRepository,
|
|
|
ILogger<BookingOrderService> logger)
|
|
|
{
|
|
|
_taskBaseInfoRepository = taskBaseInfoRepository;
|
|
|
_taskSIFeedBackInfoRepository = taskSIFeedBackInfoRepository;
|
|
|
_taskSIFeedBackContaInfoRepository = taskSIFeedBackContaInfoRepository;
|
|
|
_taskBillFeeDetailInfoRepository = taskBillFeeDetailInfoRepository;
|
|
|
_taskFileInfoRepository = taskFileInfoRepository;
|
|
|
_taskEmailInfoRepository = taskEmailInfoRepository;
|
|
|
_taskVGMFeedBackInfoRepository = taskVGMFeedBackInfoRepository;
|
|
|
_sysUserRepository = sysUserRepository;
|
|
|
_taskStatManageInfoRepository = taskStatManageInfoRepository;
|
|
|
|
|
|
_logger = logger;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 创建任务
|
|
|
/// </summary>
|
|
|
/// <param name="info">任务详情</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[AllowAnonymous,HttpPost("/TaskManage/CreateTaskJob")]
|
|
|
public async Task<TaskManageOrderResultDto> CreateTaskJob(TaskManageOrderMessageInfo info)
|
|
|
{
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
/*
|
|
|
创建任务
|
|
|
1、判断当前任务的主键是否已入库,已入库不允许重复,返回错误提示。
|
|
|
2、
|
|
|
*/
|
|
|
result = await InitTaskJob(info);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.succ = false;
|
|
|
result.msg = $"请求任务异常,{ex.Message}";
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新增任务
|
|
|
/// </summary>
|
|
|
/// <param name="info">任务详情</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
private async Task<TaskManageOrderResultDto> InitTaskJob(TaskManageOrderMessageInfo info)
|
|
|
{
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
|
|
|
try
|
|
|
{
|
|
|
var taskInfo = _taskBaseInfoRepository.AsQueryable().First(t => t.OUT_BUSI_NO == info.Head.GID);
|
|
|
|
|
|
if (taskInfo != null)
|
|
|
throw Oops.Oh($"任务已经存在不能重复提交");
|
|
|
|
|
|
taskInfo = new TaskBaseInfo
|
|
|
{
|
|
|
PK_ID = IDGen.NextID().ToString(),
|
|
|
TASK_NO = info.Head.GID,
|
|
|
STATUS = TaskStatusEnum.Create.ToString(),
|
|
|
IsDeleted = false,
|
|
|
IS_EXCEPT = 0,
|
|
|
IS_COMPLETE = 0,
|
|
|
MBL_NO = info.Main.MBlNo,
|
|
|
TASK_BASE_TYPE = info.Main.TaskType.ToString(),
|
|
|
CARRIER_ID = info.Main.CarrierId?.Trim(),
|
|
|
IS_PUBLIC = string.IsNullOrWhiteSpace(info.Main.TaskUserId) ? 1 : 0,
|
|
|
BOOK_ORDER_NO = info.Main.BookingOrderNo,
|
|
|
OUT_BUSI_NO = info.Head.GID,
|
|
|
TASK_TITLE = info.Main.TaskTitle,
|
|
|
TASK_DESP = info.Main.TaskDesp,
|
|
|
TASK_SOURCE = info.Main.TaskSource.ToString(),
|
|
|
TASK_TYPE = info.Main.TaskType.ToString(),
|
|
|
};
|
|
|
|
|
|
taskInfo.CreatedTime = DateTime.Now;
|
|
|
taskInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(taskInfo.CARRIER_ID)
|
|
|
&& taskInfo.CARRIER_ID == "MSC")
|
|
|
{
|
|
|
if (TaskBaseTypeEnum.BC.ToString() == taskInfo.TASK_BASE_TYPE)
|
|
|
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_BC.ToString();
|
|
|
|
|
|
if(taskInfo.IS_EXCEPT == 1)
|
|
|
taskInfo.TASK_TYPE = TaskBusiTypeEnum.MSC_EXCEPT.ToString();
|
|
|
}
|
|
|
|
|
|
//新增
|
|
|
await _taskBaseInfoRepository.InsertAsync(taskInfo);
|
|
|
|
|
|
//附件
|
|
|
if(info.Main.FileList != null && info.Main.FileList.Count > 0)
|
|
|
{
|
|
|
info.Main.FileList.ForEach(async file => {
|
|
|
var fileInfo = new TaskFileInfo();
|
|
|
|
|
|
fileInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
fileInfo.TASK_PKID = taskInfo.PK_ID;
|
|
|
|
|
|
fileInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
fileInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
fileInfo.FILE_PATH = file.FilePath;
|
|
|
fileInfo.FILE_NAME = file.FileName;
|
|
|
fileInfo.FILE_TYPE = file.FileType;
|
|
|
|
|
|
if(string.IsNullOrWhiteSpace(fileInfo.FILE_NAME))
|
|
|
{
|
|
|
var fileModel = new FileInfo(file.FilePath);
|
|
|
|
|
|
fileInfo.FILE_NAME = fileModel.Name;
|
|
|
fileInfo.FILE_TYPE = fileModel.Extension?.Replace(".","");
|
|
|
}
|
|
|
|
|
|
await _taskFileInfoRepository.InsertAsync(fileInfo);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//邮件
|
|
|
if (info.Main.EmailList != null && info.Main.EmailList.Count > 0)
|
|
|
{
|
|
|
info.Main.EmailList.ForEach(async email => {
|
|
|
var emailInfo = new TaskEmailInfo();
|
|
|
|
|
|
emailInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
emailInfo.TASK_PKID = taskInfo.PK_ID;
|
|
|
|
|
|
emailInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
emailInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
emailInfo.MAIL_PATH = email.MailPath;
|
|
|
|
|
|
await _taskEmailInfoRepository.InsertAsync(emailInfo);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//SI反馈入库
|
|
|
if (info.Main.TaskType == TaskBaseTypeEnum.SI_FEEDBACK)
|
|
|
{
|
|
|
if(info.Main.SIFeedBack == null)
|
|
|
throw Oops.Oh($"任务类型={info.Main.TaskType.ToString()} SIFeedBack信息必传");
|
|
|
|
|
|
TaskSIFeedBackInfo taskSIFeedBackInfo = info.Main.SIFeedBack.Adapt<TaskSIFeedBackInfo>();
|
|
|
|
|
|
taskSIFeedBackInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
taskSIFeedBackInfo.TASK_PKID = taskInfo.PK_ID;
|
|
|
|
|
|
taskSIFeedBackInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
taskSIFeedBackInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
await _taskSIFeedBackInfoRepository.InsertAsync(taskSIFeedBackInfo);
|
|
|
|
|
|
//SI反馈箱信息入库
|
|
|
if(info.Main.SIFeedBack.ContaList != null && info.Main.SIFeedBack.ContaList.Count > 0)
|
|
|
{
|
|
|
info.Main.SIFeedBack.ContaList.ForEach( async ctn => {
|
|
|
var contaInfo = ctn.Adapt<TaskSIFeedBackContaInfo>();
|
|
|
|
|
|
contaInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
contaInfo.P_PKID = taskSIFeedBackInfo.PK_ID;
|
|
|
|
|
|
contaInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
contaInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
await _taskSIFeedBackContaInfoRepository.InsertAsync(contaInfo);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//费用明细
|
|
|
if(info.Main.TaskType == TaskBaseTypeEnum.INVOICE_BILL_MAIL || info.Main.TaskType == TaskBaseTypeEnum.PER_BILL)
|
|
|
{
|
|
|
if (info.Main.FeeList != null && info.Main.FeeList.Count > 0)
|
|
|
{
|
|
|
info.Main.FeeList.ForEach(async fee => {
|
|
|
var feeInfo = fee.Adapt<TaskBillFeeDetailInfo>();
|
|
|
|
|
|
feeInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
feeInfo.TASK_PKID = taskInfo.PK_ID;
|
|
|
|
|
|
feeInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
feeInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
await _taskBillFeeDetailInfoRepository.InsertAsync(feeInfo);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//VGM反馈入库
|
|
|
if (info.Main.VGMFeedBackList != null && info.Main.VGMFeedBackList.Count > 0)
|
|
|
{
|
|
|
info.Main.VGMFeedBackList.ForEach(async vgm => {
|
|
|
var vgmInfo = vgm.Adapt<TaskVGMFeedBackInfo>();
|
|
|
|
|
|
vgmInfo.PK_ID = IDGen.NextID().ToString();
|
|
|
vgmInfo.TASK_PKID = taskInfo.PK_ID;
|
|
|
|
|
|
vgmInfo.CreatedTime = taskInfo.CreatedTime;
|
|
|
vgmInfo.UpdatedTime = taskInfo.CreatedTime;
|
|
|
|
|
|
await _taskVGMFeedBackInfoRepository.InsertAsync(vgmInfo);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
result.succ = true;
|
|
|
result.msg = "新增任务成功";
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
throw Oops.Oh($"{ex.Message}");
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取查询参数
|
|
|
/// </summary>
|
|
|
/// <param name="ParaType">参数类型 STATUS-任务状态;TASK_TYPE-任务类型;SOURCE-任务来源</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
/// <example>TASK_TYPE</example>
|
|
|
[HttpGet("/TaskManage/GetParaInfo")]
|
|
|
public async Task<TaskManageOrderResultDto> GetParaInfo([QueryString]string ParaType)
|
|
|
{
|
|
|
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
|
|
|
try
|
|
|
{
|
|
|
Dictionary<string, string> dict = new Dictionary<string, string>();
|
|
|
|
|
|
if (ParaType == "STATUS")
|
|
|
{
|
|
|
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskStatusEnum));
|
|
|
}
|
|
|
else if (ParaType == "TASK_TYPE")
|
|
|
{
|
|
|
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskBusiTypeEnum));
|
|
|
}
|
|
|
else if (ParaType == "SOURCE")
|
|
|
{
|
|
|
dict = EnumUtil.GetEnumDictionaryWithKey(typeof(TaskSourceEnum));
|
|
|
}
|
|
|
|
|
|
result.succ = true;
|
|
|
result.rows = dict.Select(t => new { Code = t.Key, Name = t.Value }).ToList();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result.succ = false;
|
|
|
result.msg = ex.Message;
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取登陆人相关的任务统计信息
|
|
|
/// </summary>
|
|
|
/// <param name="isReCalc">是否强制计算</param>
|
|
|
/// <returns>返回回执</returns>
|
|
|
[HttpGet("/TaskManage/GetCurrentTotalStat")]
|
|
|
public async Task<TaskUserStatResultInfo> GetCurrentTotalStat([FromQuery]bool isReCalc = false)
|
|
|
{
|
|
|
TaskUserStatResultInfo resultInfo = new TaskUserStatResultInfo {
|
|
|
LevelTop = new List<TaskUserStatItem>(),
|
|
|
LevelNext = new List<TaskUserStatItemNext>(),
|
|
|
LevelTree = new List<TaskUserStatItemTree>()
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
1、首先判断当前登陆人是否有统计记录,如果没有触发统计生成统计记录。
|
|
|
2、如果isReCalc=true,表示强制重新统计数据,并重新更新统计数据。
|
|
|
3、按照统计类型(个人/公共)、任务状态、是否异常分组汇总,并写入统计表。
|
|
|
*/
|
|
|
try
|
|
|
{
|
|
|
var userTendInfo = await _sysUserRepository.AsQueryable()
|
|
|
.LeftJoin<SysTenant>((usr, ten) => usr.TenantId == ten.Id)
|
|
|
.Where(usr => usr.Id == UserManager.UserId)
|
|
|
.Select((usr, ten) => new { User = usr, Tend = ten }).FirstAsync();
|
|
|
|
|
|
if(userTendInfo == null)
|
|
|
throw Oops.Oh($"当前用户关联租户信息获取失败");
|
|
|
|
|
|
var statList = _taskStatManageInfoRepository.AsQueryable().Where(t => (t.USER_ID == userTendInfo.User.Id
|
|
|
&& t.STAT_TYPE == TaskStatLevelEnum.PERSON.ToString()) || (t.COMP_ID == userTendInfo.Tend.Id && t.STAT_TYPE == TaskStatLevelEnum.PUBLIC.ToString())).ToList();
|
|
|
|
|
|
if (isReCalc)
|
|
|
{
|
|
|
//任务列表分组统计
|
|
|
var groupList = _taskBaseInfoRepository.AsQueryable()
|
|
|
.Where(t => (t.CreatedUserId == UserManager.UserId && t.IS_PUBLIC == 0) || (t.TenantId == userTendInfo.Tend.Id && t.IS_PUBLIC == 1))
|
|
|
.GroupBy(p => new { p.TASK_TYPE, p.STATUS, p.IS_EXCEPT, p.IS_PUBLIC })
|
|
|
.Select(p => new
|
|
|
{
|
|
|
Total = SqlFunc.AggregateCount(p.PK_ID),
|
|
|
TaskType = p.TASK_TYPE,
|
|
|
Status = p.STATUS,
|
|
|
IsExcept = p.IS_EXCEPT,
|
|
|
IsPublic = p.IS_PUBLIC
|
|
|
}).ToList();
|
|
|
|
|
|
var exceptList = groupList
|
|
|
.Where(t => t.IsExcept == 1).ToList();
|
|
|
|
|
|
var personList = groupList
|
|
|
.Where(t => t.IsExcept == 0 && t.IsPublic == 0).ToList();
|
|
|
|
|
|
var publicList = groupList
|
|
|
.Where(t => t.IsExcept == 1 && t.IsPublic == 1).ToList();
|
|
|
|
|
|
#region 异常
|
|
|
if (exceptList.Count > 0)
|
|
|
{
|
|
|
resultInfo.LevelTop.Add(new TaskUserStatItem
|
|
|
{
|
|
|
Key = TaskStatLevelEnum.EXCPTION.ToString(),
|
|
|
Name = TaskStatLevelEnum.EXCPTION.GetDescription(),
|
|
|
Total = exceptList.Sum(t=>t.Total),
|
|
|
SortNo = (int)TaskStatLevelEnum.EXCPTION,
|
|
|
ActionKey = TaskStatLevelEnum.EXCPTION.ToString()
|
|
|
});
|
|
|
|
|
|
exceptList.GroupBy(t => t.Status)
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
|
|
|
|
|
|
resultInfo.LevelNext.Add(new TaskUserStatItemNext
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.EXCPTION.ToString(),
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.EXCPTION.ToString()}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
exceptList.GroupBy(t => new { t.Status,t.TaskType})
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
|
|
|
|
|
|
resultInfo.LevelTree.Add(new TaskUserStatItemTree
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.EXCPTION.ToString(),
|
|
|
NextKey = t.Key.Status,
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.EXCPTION.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 个人
|
|
|
if (personList.Count > 0)
|
|
|
{
|
|
|
resultInfo.LevelTop.Add(new TaskUserStatItem
|
|
|
{
|
|
|
Key = TaskStatLevelEnum.PERSON.ToString(),
|
|
|
Name = TaskStatLevelEnum.PERSON.GetDescription(),
|
|
|
Total = personList.Sum(t => t.Total),
|
|
|
SortNo = (int)TaskStatLevelEnum.PERSON,
|
|
|
ActionKey = TaskStatLevelEnum.PERSON.ToString()
|
|
|
});
|
|
|
|
|
|
personList.GroupBy(t => t.Status)
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
|
|
|
|
|
|
resultInfo.LevelNext.Add(new TaskUserStatItemNext
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.PERSON.ToString(),
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.PERSON.ToString()}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
personList.GroupBy(t => new { t.Status, t.TaskType })
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
|
|
|
|
|
|
resultInfo.LevelTree.Add(new TaskUserStatItemTree
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.PERSON.ToString(),
|
|
|
NextKey = t.Key.Status,
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.PERSON.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 公共
|
|
|
if (publicList.Count > 0)
|
|
|
{
|
|
|
resultInfo.LevelTop.Add(new TaskUserStatItem
|
|
|
{
|
|
|
Key = TaskStatLevelEnum.PUBLIC.ToString(),
|
|
|
Name = TaskStatLevelEnum.PUBLIC.GetDescription(),
|
|
|
Total = publicList.Sum(t => t.Total),
|
|
|
SortNo = (int)TaskStatLevelEnum.PUBLIC,
|
|
|
ActionKey = TaskStatLevelEnum.PUBLIC.ToString()
|
|
|
});
|
|
|
|
|
|
publicList.GroupBy(t => t.Status)
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskStatusEnum currEnum = (TaskStatusEnum)System.Enum.Parse(typeof(TaskStatusEnum), t.Key);
|
|
|
|
|
|
resultInfo.LevelNext.Add(new TaskUserStatItemNext
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.PUBLIC.ToString()}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
publicList.GroupBy(t => new { t.Status, t.TaskType })
|
|
|
.Select(t => new { Key = t.Key, Total = t.ToList().Sum(p => p.Total) })
|
|
|
.ToList().ForEach(t => {
|
|
|
TaskBusiTypeEnum currEnum = (TaskBusiTypeEnum)System.Enum.Parse(typeof(TaskBusiTypeEnum), t.Key.TaskType);
|
|
|
|
|
|
resultInfo.LevelTree.Add(new TaskUserStatItemTree
|
|
|
{
|
|
|
TopKey = TaskStatLevelEnum.PUBLIC.ToString(),
|
|
|
NextKey = t.Key.Status,
|
|
|
Key = currEnum.ToString(),
|
|
|
Name = currEnum.GetDescription(),
|
|
|
Total = t.Total,
|
|
|
SortNo = (int)currEnum,
|
|
|
ActionKey = $"{TaskStatLevelEnum.PUBLIC.ToString()}#{t.Key.Status}#{currEnum.ToString()}"
|
|
|
});
|
|
|
|
|
|
});
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
throw Oops.Bah($"获取登陆人相关的任务统计信息异常,{0}", ex.Message);
|
|
|
}
|
|
|
|
|
|
return resultInfo;
|
|
|
}
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// 任务台账查询
|
|
|
/// </summary>
|
|
|
/// <param name="QuerySearch">任务台账查询请求</param>
|
|
|
/// <returns>返回结果</returns>
|
|
|
[HttpPost("/TaskManage/GetPage")]
|
|
|
public async Task<dynamic> GetPageAsync(QueryTaskManageDto QuerySearch)
|
|
|
{
|
|
|
List<string> mblList = new List<string>();
|
|
|
|
|
|
if(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo))
|
|
|
{
|
|
|
if (Regex.IsMatch(QuerySearch.MBlNo, "(\\t|\\n\\r|\\n)"))
|
|
|
{
|
|
|
mblList = Regex.Replace(QuerySearch.MBlNo, "(\\t |\\n\\r |\\n)", "#").Split(new char[] { '#' }).Select(t=>t?.Trim()).ToList();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
mblList.Add(QuerySearch.MBlNo.Trim());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
DateTime etdBegin = DateTime.MinValue;
|
|
|
DateTime etdEnd = DateTime.MinValue;
|
|
|
|
|
|
DateTime taskDateBegin = DateTime.MinValue;
|
|
|
DateTime taskDateEnd = DateTime.MinValue;
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(QuerySearch.ETDBegin))
|
|
|
{
|
|
|
if(!DateTime.TryParse(QuerySearch.ETDBegin, out etdBegin))
|
|
|
throw Oops.Oh($"开船起始日期格式错误,{QuerySearch.ETDBegin}");
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(QuerySearch.ETDEnd))
|
|
|
{
|
|
|
if (!DateTime.TryParse(QuerySearch.ETDEnd, out etdEnd))
|
|
|
throw Oops.Oh($"开船结束日期格式错误,{QuerySearch.ETDEnd}");
|
|
|
|
|
|
etdEnd = etdEnd.AddDays(1);
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(QuerySearch.TaskDateBegin))
|
|
|
{
|
|
|
if (!DateTime.TryParse(QuerySearch.TaskDateBegin, out taskDateBegin))
|
|
|
throw Oops.Oh($"任务起始日期格式错误,{QuerySearch.TaskDateBegin}");
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(QuerySearch.TaskDateEnd))
|
|
|
{
|
|
|
if (!DateTime.TryParse(QuerySearch.TaskDateEnd, out taskDateEnd))
|
|
|
throw Oops.Oh($"任务结束日期格式错误,{QuerySearch.TaskDateEnd}");
|
|
|
|
|
|
etdEnd = etdEnd.AddDays(1);
|
|
|
}
|
|
|
|
|
|
string entityOrderCol = "CreatedTime";
|
|
|
|
|
|
//这里因为返回给前端的台账数据是DTO,所以这里排序时候需要转换成Entity对应的字段
|
|
|
if (!string.IsNullOrWhiteSpace(QuerySearch.SortField))
|
|
|
entityOrderCol = MapsterExtHelper.GetAdaptProperty<TaskBaseInfoDto, TaskBaseInfo>(QuerySearch.SortField);
|
|
|
|
|
|
var entities = await _taskBaseInfoRepository.AsQueryable().Filter(null, true)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.MBlNo), t => mblList.Any(p => p.Contains(t.MBL_NO, StringComparison.OrdinalIgnoreCase)))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskRecvName), t => t.CreatedUserName.Contains(QuerySearch.TaskRecvName.Trim(), StringComparison.OrdinalIgnoreCase))
|
|
|
.WhereIF(etdBegin != DateTime.MinValue, t => t.ETD.HasValue && t.ETD.Value >= etdBegin)
|
|
|
.WhereIF(etdEnd != DateTime.MinValue, t => t.ETD.HasValue && t.ETD.Value < etdEnd)
|
|
|
.WhereIF(taskDateBegin != DateTime.MinValue, t => t.CreatedTime >= taskDateBegin)
|
|
|
.WhereIF(taskDateEnd != DateTime.MinValue, t => t.CreatedTime < taskDateEnd)
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskType), t => t.TASK_TYPE.Equals(QuerySearch.TaskType, StringComparison.OrdinalIgnoreCase))
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(QuerySearch.TaskSource), t => t.TASK_SOURCE.Equals(QuerySearch.TaskSource, StringComparison.OrdinalIgnoreCase))
|
|
|
.OrderBy(entityOrderCol + (QuerySearch.descSort ? " asc " : " desc "))
|
|
|
.ToPagedListAsync(QuerySearch.PageNo, QuerySearch.PageSize);
|
|
|
return new
|
|
|
{
|
|
|
PageNo = entities.PageIndex,
|
|
|
PageSize = entities.PageSize,
|
|
|
TotalPage = entities.TotalPages,
|
|
|
TotalRows = entities.TotalCount,
|
|
|
Rows = entities.Items.Select(t => t.Adapt<TaskBaseInfoDto>()).ToList()
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
}
|