using Amazon.Runtime.Internal.Transform;
using Hotline.Application.FlowEngine;
using Hotline.Application.Orders;
using Hotline.Application.Snapshot;
using Hotline.Caching.Interfaces;
using Hotline.Caching.Services;
using Hotline.FlowEngine.Definitions;
using Hotline.FlowEngine.Workflows;
using Hotline.Orders;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Repository.SqlSugar.Snapshot;
using Hotline.Settings;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Snapshot;
using Hotline.Share.Tools;
using Hotline.Snapshot;
using Hotline.Snapshot.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
using System.Text;
using XF.Domain.Authentications;
using XF.Domain.Exceptions;
using XF.Domain.Repository;
using XF.Utility.EnumExtensions;
namespace Hotline.Api.Controllers.Snapshot;
///
/// 随手拍工单
///
[Description("随手拍工单")]
public class SnapshotOrderController : BaseController
{
private readonly IOrderSnapshotRepository _orderSnapshotRepository;
private readonly IOrderSnapshotApplication _orderSnapshotApplication;
private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
private readonly ISystemAreaDomainService _systemAreaDomainService;
private readonly IIndustryRepository _industryRepository;
private readonly ISessionContext _sessionContext;
private readonly IWorkflowDomainService _workflowDomainService;
private readonly IOrderRepository _orderRepository;
private readonly IWorkflowApplication _workflowApplication;
private readonly IRepository _workflowDefinitionRepository;
private readonly IOrderApplication _orderApplication;
public SnapshotOrderController(IOrderSnapshotRepository orderSnapshotRepository, IOrderSnapshotApplication orderSnapshotApplication, ISystemAreaDomainService systemAreaDomainService, ISystemDicDataCacheManager systemDicDataCacheManager, IIndustryRepository industryRepository, ISessionContext sessionContext, IWorkflowDomainService workflowDomainService, IOrderRepository orderRepository, IWorkflowApplication workflowApplication, IRepository workflowDefinitionRepository, IOrderApplication orderApplication)
{
_orderSnapshotRepository = orderSnapshotRepository;
_orderSnapshotApplication = orderSnapshotApplication;
_systemAreaDomainService = systemAreaDomainService;
_systemDicDataCacheManager = systemDicDataCacheManager;
_industryRepository = industryRepository;
_sessionContext = sessionContext;
_workflowDomainService = workflowDomainService;
_orderRepository = orderRepository;
_workflowApplication = workflowApplication;
_workflowDefinitionRepository = workflowDefinitionRepository;
_orderApplication = orderApplication;
}
///
/// 随手拍所有工单集合
///
///
///
[HttpGet("order")]
public async Task> GetOrderSnapshotItems([FromQuery] OrderSnapshotItemsInDto dto)
=> (await _orderSnapshotApplication.GetOrderSnapshotItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 随手拍所有工单页面基础信息
///
[HttpGet("order/basedata")]
public async Task> GetOrderSnapshotItemsDatabaseAsync()
{
IList steps = new List();
await _workflowDefinitionRepository.Queryable()
.Where(m => m.Status == EDefinitionStatus.Enable && m.Code == "gdbl")
.OrderByDescending(m => m.Version)
.Select(m => new { m.Id, m.Steps})
.FirstAsync().Then(async workflowSteps =>
{
steps = workflowSteps.Steps.Adapt>()
.ToList().Select(m => new Kv
{
Key = m.Code,
Value = m.Name,
}).ToList();
});
return new Dictionary
{
{ "orderStatus", EnumExts.GetDescriptions()},
{ "area", await _systemAreaDomainService.GetAreaKeyValue(parentId: "510300")},
{ "steps", steps},
{ "orderTags", _systemDicDataCacheManager.OrderTag},
{ "industry", await _industryRepository.Queryable().Select(d => new { d.Id, d.Name, }).ToListAsync()},
{ "acceptType", _systemDicDataCacheManager.AcceptType.Adapt>() }
};
}
///
/// 获取网格员回复集合
///
///
///
[HttpGet("guider/reply")]
public async Task> GetGuiderReplyItems([FromQuery] GuiderReplyItemsInDto dto)
=> (await _orderSnapshotApplication.GetGuiderReplyItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 获取工单标注集合
///
///
///
[HttpGet("label")]
public async Task> GetSignOrderSnapshotItems([FromQuery] SignOrderSnapshotItemsInDto dto)
=> (await _orderSnapshotApplication.GetSignOrderSnapshotItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 获取工单已经标签集合
///
///
///
[HttpGet("labeled")]
public async Task> GetLabeledOrderSnapshotItems([FromQuery] LabeledOrderSnapshotItemsInDto dto)
=> (await _orderSnapshotApplication.GetLabeledOrderSnapshotItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 标签详情
///
///
///
[HttpGet("label/{id}")]
public async Task GetLabelOrderSnapshotDetailAsync(string id)
{
var order = await _orderRepository.Queryable()
.LeftJoin((order, snapshot) => order.Id == snapshot.Id)
.Where((order, snapshot) => order.Id == id)
.Select((order, snapshot) => new LabelOrderSnapshotDetailOutDto { Id = order.Id, Title = order.Title, Lables =snapshot.Labels })
.FirstAsync();
order.LabelsBaseData = _systemDicDataCacheManager.SnapshotOrderLabel;
return order;
}
///
/// 修改工单标签
///
///
///
[HttpPut("label")]
public async Task UpdateLabelOrderSnapshotAsync([FromBody] UpdateLabelOrderSnapshotInDto dto)
=> await _orderSnapshotApplication.UpdateLabelAsync(dto.Id, dto.SnapshotLabels);
///
/// 获取工单标签日志集合
///
///
///
[HttpGet("label/log")]
public async Task> GetLabelOrderSnapshotLogItems([FromQuery] LabelOrderSnapshotLogItemsInDto dto)
=> (await _orderSnapshotApplication.GetLabelOrderSnapshotLogItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 随手拍公开集合
///
///
///
[HttpGet("publish")]
public async Task> GetOrderSnapshotPublishItems([FromQuery] GetOrderSnapshotPublishItemsInDto dto)
=> (await _orderSnapshotApplication.GetOrderSnapshotPublishItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 随手拍公开详情
///
/// 工单Id
///
[HttpGet("publish/{id}")]
public async Task GetOrderSnapshotPublishDetailAsync(string id)
=> await _orderSnapshotApplication.GetOrderSnapshotPublishDetailAsync(id);
///
/// 添加公开审核
///
///
[HttpPost("publish")]
public async Task AddOrderSnapshotPublishItemsAsync([FromBody] AddSnapshotOrderPublishInDto dto)
=> await _orderSnapshotApplication.AddOrderPublishAsync(dto, HttpContext.RequestAborted);
///
/// 随手拍公开审批集合
///
///
[HttpGet("publish/audit")]
public async Task> GetOrderSnapshotPublishAuditItems([FromQuery] GetOrderSnapshotPublishAuditItemsInDto dto)
=> (await _orderSnapshotApplication.GetOrderSnapshotPublishAuditItems(dto).ToPagedListAsync(dto)).ToPaged();
///
/// 审核随手拍公开申请通过/不通过
///
///
[HttpPut("publish/status")]
public async Task UpdateOrderSnapshotPublishStatusAsync([FromBody] UpdateOrderSnapshotPublishStatusInDto dto)
=> await _orderSnapshotApplication.UpdateOrderSnapshotPublishStatusAsync(dto);
///
/// 随手拍公开审批详情
///
///
///
[HttpGet("publish/audit/{id}")]
public async Task GetOrderSnapshotPublishAuditDetailAsync(string id)
=> await _orderSnapshotApplication.GetOrderSnapshotPublishAuditDetailAsync(id);
///
/// 批量设置随手拍公开申请不通过
///
///
[HttpPut("publishs/status/refuse")]
public async Task UpdateOrderSnapshotPublishsStatusRefuseAsync(IList ids)
=> await _orderSnapshotApplication.UpdateOrderSnapshotPublishsStatusRefuseAsync(ids);
///
/// 随手拍公开集合基础数据
///
///
[HttpGet("publish/basedata")]
public async Task> GetOrderSnapshotPublishItemsBasedataAsync()
{
var industry = await _industryRepository.Queryable()
.Select(d => new { d.Id, d.Name, })
.ToListAsync();
return new Dictionary
{
{ "publishStatus", EnumExts.GetDescriptions()},
{ "acceptCode", _systemDicDataCacheManager.AcceptType.Adapt>() },
{ "orderStatus", EnumExts.GetDescriptions()},
{ "area", await _systemAreaDomainService.GetAreaKeyValue(parentId: "510300")},
{ "industry", industry}
};
}
///
/// 网格员超时未回复, 处理工单
///
/// 工单Id
///
[HttpPut("guider/timeout/{id}")]
public async Task HandleFromWanggeyuanToMaskAsync(string id)
{
await _orderApplication.HandleFromWanggeyuanToMaskAsync(id, HttpContext.RequestAborted);
}
}