Ver código fonte

自贡任务 570 在【业务管理】目录下新增菜单【补充查询】等

tangjiang 1 semana atrás
pai
commit
49956cdfa4

+ 280 - 7
src/Hotline.Api/Controllers/OrderApi/OrderComplementController.cs

@@ -1,14 +1,22 @@
-using Hotline.Article;
+using Azure;
+using Hotline.Article;
 using Hotline.FlowEngine.Workflows;
 using Hotline.Orders;
+using Hotline.Share.Dtos;
 using Hotline.Share.Dtos.Article;
 using Hotline.Share.Dtos.Order;
 using Hotline.Share.Enums.Article;
 using Hotline.Users;
+using MapsterMapper;
 using Microsoft.AspNetCore.Mvc;
 using XF.Domain.Authentications;
 using XF.Domain.Exceptions;
 using XF.Domain.Repository;
+using Hotline.Repository.SqlSugar.Extensions;
+using Hotline.Tools;
+using Google.Protobuf.WellKnownTypes;
+using DocumentFormat.OpenXml.Drawing;
+using Hotline.Repository.SqlSugar.Orders;
 
 namespace Hotline.Api.Controllers.OrderApi;
 
@@ -20,13 +28,19 @@ public class OrderComplementController : BaseController
     private readonly IRepository<WorkflowStep> _workflowStepRepository;
     private readonly IRepository<User> _userRepository;
     private readonly ICircularRecordDomainService _circularRecordDomainService;
+    private readonly IComplementOrderService _complementOrderService;
+    private readonly IMapper _mapper;
+    private readonly IRepository<OrderComplementCopy> _orderComplementCopyRepository;
 
     public OrderComplementController(IOrderDomainService orderDomainService,
        ISessionContext sessionContext,
        IRepository<OrderComplement> orderComplementRepository,
        IRepository<WorkflowStep> workflowStepRepository,
        IRepository<User> userRepository,
-       ICircularRecordDomainService circularRecordDomainService)
+       ICircularRecordDomainService circularRecordDomainService,
+       IComplementOrderService complementOrderService,
+       IMapper mapper,
+       IRepository<OrderComplementCopy> orderComplementCopyRepository)
     {
         _orderDomainService = orderDomainService;
         _sessionContext = sessionContext;
@@ -34,8 +48,11 @@ public class OrderComplementController : BaseController
         _workflowStepRepository = workflowStepRepository;
         _userRepository = userRepository;
         _circularRecordDomainService = circularRecordDomainService;
+        _complementOrderService = complementOrderService;
+        _mapper = mapper;
+        _orderComplementCopyRepository = orderComplementCopyRepository;
     }
-    
+
     /// <summary>
     /// 补充
     /// </summary>
@@ -47,10 +64,8 @@ public class OrderComplementController : BaseController
         return await _orderDomainService.AddOrderComplementAsync(dto, HttpContext.RequestAborted);
     }
 
-    #region 添加补充
-
     /// <summary>
-    /// 添加补充 _notificationWaitSendRepository
+    /// 添加补充 
     /// </summary>
     /// <param name="dto"></param>
     /// <returns></returns>
@@ -72,6 +87,7 @@ public class OrderComplementController : BaseController
             OrderId = dto.OrderId,
             Opinion = dto.Opinion,
             SupplyName = _sessionContext.UserName,
+            SupplyOrg = _sessionContext.OrgName,
             SupplyTime = DateTime.Now,
             No = data.No,
             IsProComplement = false
@@ -146,5 +162,262 @@ public class OrderComplementController : BaseController
         }
     }
 
-    #endregion
+    /// <summary>
+    /// 修改补充
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("update_order_complement")]
+    public async Task UpdateOrderComplement([FromBody] UpdateComplementDto dto)
+    {
+        if (dto == null)
+            throw UserFriendlyException.SameMessage("数据错误!");
+        if (string.IsNullOrEmpty(dto.Opinion))
+            throw UserFriendlyException.SameMessage("补充内容不能为空!");
+        if (dto.Opinion.Length > 2000)
+            throw UserFriendlyException.SameMessage("补充内容限制2000字!");
+        var data = await _orderComplementRepository.GetAsync(p => p.Id == dto.Id, cancellationToken: HttpContext.RequestAborted);
+        if (data == null)
+            throw UserFriendlyException.SameMessage("补充查询失败!");
+        //修改记录
+        var dataCopy = new OrderComplementCopy
+        {
+            OperationType = "0",
+            OrderId = data.OrderId,
+            Opinion = data.Opinion,
+            SupplyName = data.SupplyName,
+            SupplyOrg = data.SupplyOrg,
+            SupplyTime = data.SupplyTime,
+            DsBisId = data.DsBisId,
+            No = data.No,
+            IsProComplement = data.IsProComplement,
+            FileJson = data.FileJson,
+            ComplementId = data.Id
+        };
+
+        await _orderComplementCopyRepository.AddAsync(dataCopy, HttpContext.RequestAborted);
+        //修改
+        data.Opinion = dto.Opinion;
+        await _orderComplementRepository.UpdateAsync(data, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 删除补充
+    /// </summary>
+    /// <returns></returns>
+    [HttpGet("delete_order_complement/{id}")]
+    public async Task DeleteOrderComplement(string id)
+    {
+        var data = await _orderComplementRepository.GetAsync(p => p.Id == id, cancellationToken: HttpContext.RequestAborted);
+        if (data == null)
+            throw UserFriendlyException.SameMessage("补充查询失败!");
+
+        //修改记录
+        var dataCopy = new OrderComplementCopy
+        {
+            OperationType = "1",
+            OrderId = data.OrderId,
+            Opinion = data.Opinion,
+            SupplyName = data.SupplyName,
+            SupplyOrg = data.SupplyOrg,
+            SupplyTime = data.SupplyTime,
+            DsBisId = data.DsBisId,
+            No = data.No,
+            IsProComplement = data.IsProComplement,
+            FileJson = data.FileJson,
+            ComplementId = data.Id
+        };
+
+        await _orderComplementCopyRepository.AddAsync(dataCopy, HttpContext.RequestAborted);
+
+        //删除
+        await _orderComplementRepository.RemoveAsync(p => p.Id == id, false, HttpContext.RequestAborted);
+    }
+
+    /// <summary>
+    /// 补充查询
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("get-order-complement-list")]
+    public async Task<PagedDto<ComplementOrderDto>> GetOrderComplementList([FromQuery] ComplementOrderRequestDto dto)
+    {
+        var (total, items) = await _complementOrderService.GetOrderComplementList(dto)
+              .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+        return new PagedDto<ComplementOrderDto>(total, _mapper.Map<IReadOnlyList<ComplementOrderDto>>(items));
+    }
+
+    /// <summary>
+    /// 补充查询列表导出
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+
+    [HttpPost("get-order-complement-list/export")]
+    public async Task<FileStreamResult> OrderTerminateListExport([FromBody] ExportExcelDto<ComplementOrderRequestDto> dto)
+    {
+        var query = _complementOrderService.GetOrderComplementList(dto.QueryDto);
+        List<OrderComplement> data;
+        if (dto.IsExportAll)
+        {
+            data = await query.ToListAsync(HttpContext.RequestAborted);
+        }
+        else
+        {
+            var (_, items) = await query.ToPagedListAsync(dto.QueryDto, HttpContext.RequestAborted);
+            data = items;
+        }
+
+        var dataDtos = _mapper.Map<ICollection<ComplementOrderDto>>(data);
+
+        dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<ComplementOrderDto>(dto.ColumnInfos);
+
+        var dtos = dataDtos
+            .Select(stu => _mapper.Map(stu, typeof(ComplementOrderDto), dynamicClass))
+            .Cast<object>()
+            .ToList();
+
+        var stream = ExcelHelper.CreateStream(dtos);
+
+        return ExcelStreamResult(stream, "补充查询列表");
+    }
+
+    /// <summary>
+    /// 补充操作记录查询
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpGet("get-order-complement-copy-list")]
+    public async Task<PagedDto<ComplementOrderCopDto>> GetOrderComplementCopyList([FromQuery] ComplementOrderCopyRequestDto dto)
+    {
+        var (total, items) = await _complementOrderService.GetOrderComplementCopyList(dto)
+              .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
+        return new PagedDto<ComplementOrderCopDto>(total, _mapper.Map<IReadOnlyList<ComplementOrderCopDto>>(items));
+    }
+
+    /// <summary>
+    /// 补充操作记录列表导出
+    /// </summary>
+    /// <param name="dto"></param>
+    /// <returns></returns>
+    [HttpPost("get-order-complement-copy-list/export")]
+    public async Task<FileStreamResult> OrderTerminateCopyListExport([FromBody] ExportExcelDto<ComplementOrderCopyRequestDto> dto)
+    {
+        var query = _complementOrderService.GetOrderComplementCopyList(dto.QueryDto);
+        List<OrderComplementCopy> data;
+        if (dto.IsExportAll)
+        {
+            data = await query.ToListAsync(HttpContext.RequestAborted);
+        }
+        else
+        {
+            var (_, items) = await query.ToPagedListAsync(dto.QueryDto, HttpContext.RequestAborted);
+            data = items;
+        }
+
+        var dataDtos = _mapper.Map<ICollection<ComplementOrderCopDto>>(data);
+
+        dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<ComplementOrderCopDto>(dto.ColumnInfos);
+
+        var dtos = dataDtos
+            .Select(stu => _mapper.Map(stu, typeof(ComplementOrderCopDto), dynamicClass))
+            .Cast<object>()
+            .ToList();
+
+        var stream = ExcelHelper.CreateStream(dtos);
+
+        return ExcelStreamResult(stream, " 补充操作记录列表");
+    }
+
+    /// <summary>
+    /// 查看记录删除
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("get-complement-order-copy-delete/{id}")]
+    public async Task<ComplementOrderCopyDetailDto> GetComplementOrderCopyDelete(string id)
+    {
+        ComplementOrderCopyDetailDto detailDto = new ComplementOrderCopyDetailDto();
+        var data = await _orderComplementCopyRepository.Queryable()
+            .Includes(p => p.Order)
+            .Where(p => p.Id == id)
+            .FirstAsync();
+        if (data != null)
+        {
+            detailDto.No = data.No;
+            detailDto.OrderTitle = data.Order.Title;
+            detailDto.UserName = data.SupplyName;
+            detailDto.OrgName = data.CreatorOrgName;
+            detailDto.Opinion = data.Opinion;
+            detailDto.OperationName = data.CreatorName;
+            detailDto.OperationTime = data.CreationTime;
+        }
+        return detailDto;
+    }
+
+    /// <summary>
+    /// 查看记录修改
+    /// </summary>
+    /// <param name="id"></param>
+    /// <returns></returns>
+    [HttpGet("get-complement-order-copy-update/{id}")]
+    public async Task<object> GetComplementOrderCopyUpdate(string id)
+    {
+        ComplementOrderCopyDetailListDto copyDetailListDto = new ComplementOrderCopyDetailListDto();
+        var updateData = await _orderComplementCopyRepository.Queryable()
+            .Includes(p => p.Order)
+            .Where(p => p.Id == id)
+            .FirstAsync();
+        if (updateData is null)
+            throw UserFriendlyException.SameMessage("修改明细查询失败!");
+
+        ComplementOrderCopyDetailDto oldInfo = new ComplementOrderCopyDetailDto
+        {
+            No = updateData.No,
+            OrderTitle = updateData.Order.Title,
+            UserName = updateData.SupplyName,
+            OrgName = updateData.SupplyOrg,
+            SupplyTime = updateData.SupplyTime,
+            Opinion = updateData.Opinion,
+        };
+
+        var copyNew = await _orderComplementCopyRepository.Queryable()
+            .Includes(p=>p.Order)
+            .OrderBy(x => x.CreationTime)
+            .FirstAsync(p => p.ComplementId == updateData.ComplementId && p.CreationTime > updateData.CreationTime);
+
+        ComplementOrderCopyDetailDto newInfo = null;
+        if (copyNew != null)
+        {
+            newInfo = new ComplementOrderCopyDetailDto
+            {
+                No = copyNew.No,
+                OrderTitle = copyNew.Order.Title,
+                UserName = copyNew.SupplyName,
+                OrgName = copyNew.SupplyOrg,
+                SupplyTime = copyNew.SupplyTime,
+                Opinion = copyNew.Opinion
+            };
+        }
+        else
+        {
+            var orderComplement = await _orderComplementRepository.Queryable()
+                .Includes(p=>p.Order)
+                .FirstAsync(d => d.Id == updateData.ComplementId);
+            if (orderComplement is not null)
+            {
+                newInfo = new ComplementOrderCopyDetailDto
+                {
+                    No = orderComplement.No,
+                    OrderTitle = orderComplement.Order.Title,
+                    UserName = orderComplement.SupplyName,
+                    OrgName = orderComplement.SupplyOrg,
+                    SupplyTime = orderComplement.SupplyTime,
+                    Opinion = orderComplement.Opinion
+                };
+            }
+        }
+
+        return new { OldInfo = oldInfo, NewInfo = newInfo };
+    }
 }

+ 8 - 0
src/Hotline.Share/Dtos/Order/AddOrderComplementDto.cs

@@ -54,3 +54,11 @@ public class AddComplementDto
     public string Opinion {  set; get; }
 }
 
+public class UpdateComplementDto: AddComplementDto
+{
+    /// <summary>
+    /// 补充Id
+    /// </summary>
+    public string Id { get; set; }
+}
+

+ 86 - 7
src/Hotline.Share/Dtos/Order/ComplementOrderDto.cs

@@ -1,12 +1,91 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Hotline.Share.Dtos.Order
+namespace Hotline.Share.Dtos.Order
 {
     public class ComplementOrderDto
     {
+        public string Id { get; set; }
+
+        public string OrderId { get; set; }
+
+        /// <summary>
+        /// 工单
+        /// </summary>
+        public OrderDto Order { get; set; }
+
+        /// <summary>
+        /// 补充意见
+        /// </summary>
+        public string Opinion { get; set; }
+
+        /// <summary>
+        /// 补充人员
+        /// </summary>
+        public string? SupplyName { get; set; }
+
+        /// <summary>
+        /// 补充时间
+        /// </summary>
+        public DateTime? SupplyTime { get; set; }
+
+        /// <summary>
+        /// 工单编号
+        /// </summary>
+        public string? No { get; set; }
+    }
+
+    public class ComplementOrderCopDto : ComplementOrderDto
+    {
+        public string? OperationType { get; set; }
+
+        public string? OperationTypeName => OperationType == "0" ? "编辑" : OperationType == "1" ? "删除" : "";
+    }
+
+    public class ComplementOrderCopyDetailDto
+    {
+        /// <summary>
+        /// 工单编号
+        /// </summary>
+        public string? No { get; set; }
+
+        /// <summary>
+        /// 工单标题
+        /// </summary>
+        public string? OrderTitle { get; set; }
+
+        /// <summary>
+        ///姓名
+        /// </summary>
+        public string? UserName { get; set; }
+
+        /// <summary>
+        /// 部门
+        /// </summary>
+        public string? OrgName { get; set; }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public DateTime? SupplyTime { get; set; }
+
+        /// <summary>
+        /// 补充意见
+        /// </summary>
+        public string Opinion { get; set; }
+
+        /// <summary>
+        /// 操作人
+        /// </summary>
+        public string? OperationName { get; set; }
+
+        /// <summary>
+        /// 操作时间
+        /// </summary>
+        public DateTime? OperationTime { get; set; }
+    }
+
+    public class ComplementOrderCopyDetailListDto
+    {
+        public ComplementOrderCopyDetailDto NewData { get; set; }
+
+        public ComplementOrderCopyDetailDto OldData { get; set; }
     }
 }

+ 34 - 0
src/Hotline.Share/Dtos/Order/ComplementOrderRequestDto.cs

@@ -0,0 +1,34 @@
+using Hotline.Share.Requests;
+
+namespace Hotline.Share.Dtos.Order
+{
+    public record ComplementOrderRequestDto : PagedKeywordRequest
+    {
+        /// <summary>
+        /// 工单编号
+        /// </summary>
+        public string? No { get; set; }
+
+        /// <summary>
+        /// 标题
+        /// </summary>
+        public string? Title { get; set; }
+
+        /// <summary>
+        /// 当前节点
+        /// </summary>
+        public string? CurrentStepName { get; set; }
+
+        /// <summary>
+        /// 补充人员
+        /// </summary>
+        public string? SupplyName { get; set; }
+    }
+    public record ComplementOrderCopyRequestDto : ComplementOrderRequestDto
+    {
+        /// <summary>
+        /// 操作类型(0:修改,1:删除)
+        /// </summary>
+        public string? OperationType { get; set; }
+    }
+}

+ 84 - 0
src/Hotline/Orders/ComplementOrderService.cs

@@ -0,0 +1,84 @@
+using Hotline.Article;
+using Hotline.FlowEngine.Workflows;
+using Hotline.Share.Dtos.Order;
+using Hotline.Share.Dtos;
+using Hotline.Users;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using XF.Domain.Authentications;
+using XF.Domain.Dependency;
+using XF.Domain.Repository;
+using SqlSugar;
+
+namespace Hotline.Orders
+{
+    public class ComplementOrderService : IComplementOrderService, IScopeDependency
+    {
+        private readonly ISessionContext _sessionContext;
+        private readonly IRepository<OrderComplement> _orderComplementRepository;
+        private readonly IRepository<WorkflowStep> _workflowStepRepository;
+        private readonly IRepository<User> _userRepository;
+        private readonly ICircularRecordDomainService _circularRecordDomainService;
+        private readonly IRepository<OrderComplementCopy> _orderComplementCopyRepository;
+
+        public ComplementOrderService(ISessionContext sessionContext,
+           IRepository<OrderComplement> orderComplementRepository,
+           IRepository<WorkflowStep> workflowStepRepository,
+           IRepository<User> userRepository,
+           ICircularRecordDomainService circularRecordDomainService,
+           IRepository<OrderComplementCopy> orderComplementCopyRepository)
+        {
+            _sessionContext = sessionContext;
+            _orderComplementRepository = orderComplementRepository;
+            _workflowStepRepository = workflowStepRepository;
+            _userRepository = userRepository;
+            _circularRecordDomainService = circularRecordDomainService;
+            _orderComplementCopyRepository = orderComplementCopyRepository;
+        }
+
+        /// <summary>
+        /// 补充列表查询
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public ISugarQueryable<OrderComplement> GetOrderComplementList(ComplementOrderRequestDto dto)
+        {
+            return _orderComplementRepository.Queryable()
+                  .Includes(p => p.Order)
+                  .WhereIF(_sessionContext.OrgIsCenter == false, p => p.CreatorOrgId.StartsWith(_sessionContext.RequiredOrgId))
+                  .WhereIF(!string.IsNullOrEmpty(dto.No), p => p.Order.No == dto.No)
+                  .WhereIF(!string.IsNullOrEmpty(dto.Title), p => p.Order.Title == dto.Title)
+                  .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepName), p => p.Order.CurrentStepName == dto.CurrentStepName)
+                  .WhereIF(!string.IsNullOrEmpty(dto.SupplyName), p => p.SupplyName == dto.SupplyName)
+                  .WhereIF(dto.StartTime.HasValue, p => p.SupplyTime >= dto.StartTime)
+                  .WhereIF(dto.EndTime.HasValue, p => p.SupplyTime <= dto.EndTime)
+                  .OrderByDescending(p => p.SupplyTime);
+
+        }
+
+        /// <summary>
+        /// 补充操作记录列表查询
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public ISugarQueryable<OrderComplementCopy> GetOrderComplementCopyList(ComplementOrderCopyRequestDto dto)
+        {
+            return _orderComplementCopyRepository.Queryable()
+                  .Includes(p => p.Order)
+                  .WhereIF(_sessionContext.OrgIsCenter == false, p => p.CreatorOrgId.StartsWith(_sessionContext.RequiredOrgId))
+                  .WhereIF(!string.IsNullOrEmpty(dto.No), p => p.Order.No == dto.No)
+                  .WhereIF(!string.IsNullOrEmpty(dto.Title), p => p.Order.Title == dto.Title)
+                  .WhereIF(!string.IsNullOrEmpty(dto.CurrentStepName), p => p.Order.CurrentStepName == dto.CurrentStepName)
+                  .WhereIF(!string.IsNullOrEmpty(dto.SupplyName), p => p.CreatorName == dto.SupplyName)
+                  .WhereIF(dto.StartTime.HasValue, p => p.CreationTime >= dto.StartTime)
+                  .WhereIF(dto.EndTime.HasValue, p => p.CreationTime <= dto.EndTime)
+                  .WhereIF(!string.IsNullOrEmpty(dto.OperationType), p => p.OperationType == dto.OperationType)
+                  .OrderByDescending(p => p.CreationTime);
+
+        }
+    }
+}

+ 22 - 0
src/Hotline/Orders/IComplementOrderService.cs

@@ -0,0 +1,22 @@
+using Hotline.Share.Dtos.Order;
+using SqlSugar;
+
+namespace Hotline.Orders
+{
+    public interface IComplementOrderService
+    {
+        /// <summary>
+        /// 补充列表查询
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        ISugarQueryable<OrderComplement> GetOrderComplementList(ComplementOrderRequestDto dto);
+
+        /// <summary>
+        /// 补充操作记录列表查询
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        ISugarQueryable<OrderComplementCopy> GetOrderComplementCopyList(ComplementOrderCopyRequestDto dto);
+    }
+}

+ 5 - 0
src/Hotline/Orders/OrderComplement.cs

@@ -28,6 +28,11 @@ public class OrderComplement : CreationEntity
     /// </summary>
     public string? SupplyName { get; set; }
 
+    /// <summary>
+    /// 补充部门
+    /// </summary>
+    public string? SupplyOrg { get; set; }
+
     /// <summary>
     /// 补充时间
     /// </summary>

+ 18 - 0
src/Hotline/Orders/OrderComplementCopy.cs

@@ -0,0 +1,18 @@
+using SqlSugar;
+
+namespace Hotline.Orders
+{
+    public class OrderComplementCopy : OrderComplement
+    {
+        /// <summary>
+        /// 操作类型(0:修改,1:删除)
+        /// </summary>
+        [SugarColumn(ColumnDescription = "操作类型(0:修改,1:删除)")]
+        public string? OperationType { get; set; }
+
+        /// <summary>
+        /// 补充Id
+        /// </summary>
+        public string? ComplementId { get; set; }
+    }
+}