using Hotline.FlowEngine.Workflows;
using Hotline.Settings.Hotspots;
using Hotline.Share.Dtos;
using Hotline.Share.Enums.FlowEngine;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Settings;
using Hotline.Users;
using SqlSugar;
using XF.Domain.Exceptions;
using XF.Domain.Extensions;
using XF.Domain.Repository;
namespace Hotline.Orders
{
///
/// 工单
///
public partial class Order : PositionWorkflowEntity
{
#region 来电信息
///
/// 来源渠道(电话、网站、APP等)
///
[SugarColumn(DefaultValue = "其他")]
public string SourceChannel { get; set; }
[SugarColumn(DefaultValue = "QT")]
public string SourceChannelCode { get; set; }
///
/// 渠道为电话时,此字段存在(Call.Id)
///
[SugarColumn(IsNullable = true)]
public string? CallId { get; set; }
///
/// 来电归属地
///
[SugarColumn(IsNullable = true)]
public string? CallAddress { get; set; }
///
/// 来电号码
///
[SugarColumn(IsNullable = true)]
public string? FromPhone { get; set; }
///
/// 转接号码(转接来源)
///
[SugarColumn(IsNullable = true)]
public string? TransferPhone { get; set; }
///
/// 来电/信人姓名
///
public string FromName { get; set; }
///
/// 来电/信人性别
///
public EGender FromGender { get; set; }
///
/// 来电/信人身份
///
public EIdentityType IdentityType { get; set; }
///
/// 证件类型
///
[SugarColumn(IsNullable = true)]
public string? LicenceTypeCode { get; set; }
[SugarColumn(IsNullable = true)]
public string? LicenceType { get; set; }
///
/// 证件号码
///
[SugarColumn(IsNullable = true)]
public string? LicenceNo { get; set; }
///
/// 年龄段
///
[SugarColumn(IsNullable = true)]
public string? AgeRangeCode { get; set; }
[SugarColumn(IsNullable = true)]
public string? AgeRange { get; set; }
///
/// 联系电话
///
[SugarColumn(ColumnDescription = "联系电话", IsNullable = true)]
public string? Contact { get; set; }
[SugarColumn(ColumnDescription = "联系电话脱敏", IsNullable = true)]
public string? ContactMask { get; set; }
///
/// 是否接受短信,勾选校验手机号
///
public bool AcceptSms { get; set; }
///
/// 是否已发送短信
///
public bool SmsSended { get; set; }
///
/// 是否保密
///
[SugarColumn(DefaultValue = "t")]
public bool IsSecret { get; set; }
///
/// 工作单位(当“来电/信人身份”为“企业”时必填,其他情况非必填)
///
[SugarColumn(ColumnDescription = "工作单位", IsNullable = true)]
public string? Company { get; set; }
#endregion
#region 诉求信息
///
/// 工单类型
///
public EOrderType OrderType { get; set; }
///
/// 受理类型
///
public EAcceptType AcceptType { get; set; }
///
/// 紧急程度
///
public EEmergencyLevel EmergencyLevel { get; set; } = EEmergencyLevel.Normal;
public string Title { get; set; }
#region 热点
///
/// 热点
///
public string HotspotId { get; set; }
public string HotspotName { get; set; }
public string HotspotSpliceName { get; set; }
///
/// 外部数据(为前端提供级联功能)
///
[SugarColumn(IsNullable = true)]
public string? HotspotExternal { get; set; }
#endregion
///
/// 事发时间
///
public DateTime? IncidentTime { get; set; }
///
/// 重复工单Id
///
[SugarColumn(ColumnDescription = "重复工单Id", ColumnDataType = "json", IsJson = true, IsNullable = true)]
public List? DuplicateIds { get; set; }
///
/// 推送分类
///
[SugarColumn(IsNullable = true)]
public string? PushTypeCode { get; set; }
[SugarColumn(IsNullable = true)]
public string? PushType { get; set; }
///
/// 附件
///
[SugarColumn(ColumnDataType = "json", IsJson = true)]
public List Additions { get; set; } = new();
///
/// 诉求内容
///
[SugarColumn(ColumnDataType = "varchar(2000)")]
public string Content { get; set; }
#endregion
#region 工单属性
///
/// 工单状态
///
public EOrderStatus Status { get; set; }
///
/// 过期状态 //todo 延迟消息更新此字段
///
public EExpiredStatus ExpiredStatus { get; set; }
///
/// 来源,区分省平台或110等其他平台同步过来的工单
///
public ESource Source { get; set; }
///
/// 处理方式(直办、交办)
///
[SugarColumn(DefaultValue = "10")]
public EProcessType ProcessType { get; set; } = EProcessType.Zhiban;
/////
///// 进展情况
/////
//[SugarColumn(DefaultValue = "0")]
//public EProgress Progress { get; set; }
///
/// 是否公开
///
[SugarColumn(DefaultValue = "f")]
public bool IsPublicity { get; set; }
///
/// 是否为省工单(省派发工单字段:get_case_result_receive == "中国政府网来源工单" 为true)
///
[SugarColumn(DefaultValue = "f")]
public bool IsProvince { get; set; }
///
/// 工单编码(20220101000001)
///
public string No { get; set; }
///
/// 省工单编号(冗余)
///
[SugarColumn(IsNullable = true)]
public string? FromProvinceNo { get; set; }
///
/// 同步省工单编号(按省工单要求生成的编号,冗余)
///
[SugarColumn(IsNullable = true)]
public string? ToProvinceNo { get; set; }
///
/// 省过期时间(省工单才有)
///
public DateTime? ExpiredTimeProvince { get; set; }
///
/// 110工单编号(从110来的和推送给110的都用该字段记录唯一标识)
///
[SugarColumn(IsNullable = true)]
public string? No110 { get; set; }
///
/// 是否已撤销
///
[SugarColumn(DefaultValue = "f")]
public bool IsCancel { get; set; }
#endregion
#region 流程信息
///
/// 工单开始时间(受理/接办时间=流程开启时间)
///
public DateTime? StartTime { get; set; }
///
/// 过期时间
///
public DateTime? ExpiredTime { get; set; }
///
/// 交办时间(中心交部门办理时间)
///
public DateTime? CenterToOrgTime { get; set; }
///
/// 归档时间(暂为流程结束时间,因流程结束自动归档)
///
public DateTime? FiledTime { get; set; }
///
/// 办结时长(分钟)
/// 办结时间-交办时间
///
[SugarColumn(DefaultValue = "0")]
public double HandleDuration { get; set; }
///
/// 办结工作日时长
///
[SugarColumn(DefaultValue = "0")]
public double HandleDurationWorkday { get; set; }
///
/// 全流程时长(分钟)
/// 归档时间-创建时间
///
[SugarColumn(DefaultValue = "0")]
public double AllDuration { get; set; }
///
/// 办理时间限制(如:24小时、7个工作日)
///
[SugarColumn(IsNullable = true, DefaultValue = "")]
public string? TimeLimit { get; set; }
public int? TimeLimitCount { get; set; }
public ETimeType? TimeLimitUnit { get; set; }
#region 实际办理信息(节点,部门,意见)
///
/// 实际办理节点code(会签状态此字段保存最外层会签发起节点code)
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleStepCode { get; set; }
///
/// 实际办理节点名称(会签状态此字段保存最外层会签发起节点名称)
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleStepName { get; set; }
///
/// 到达实际办理节点时间(stepBox创建时间)
///
public DateTime? ActualHandleStepCreateTime { get; set; }
///
/// 实际办理节点签收时间
///
public DateTime? ActualHandleStepAcceptTime { get; set; }
///
/// 实际办理时间
///
public DateTime? ActualHandleTime { get; set; }
///
/// 实际办理人id
///
[SugarColumn(IsNullable = true)]
public string? ActualHandlerId { get; set; }
///
/// 实际办理人名称
///
[SugarColumn(IsNullable = true)]
public string? ActualHandlerName { get; set; }
///
/// 实际办理部门名称
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleOrgName { get; set; }
///
/// 实际办理部门编码
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleOrgCode { get; set; }
///
/// 实际办理部门行政区划编码
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleOrgAreaCode { get; set; }
///
/// 实际办理部门行政区划名称
///
[SugarColumn(IsNullable = true)]
public string? ActualHandleOrgAreaName { get; set; }
///
/// 实际办理意见(办理中...or 最终办理意见)
///
[SugarColumn(Length = 2000)]
public string ActualOpinion { get; set; } = "办理中...";
///
/// 真实办理人姓名(手动填写)
///
[SugarColumn(IsNullable = true)]
public string? RealHandlerName { get; set; }
///
/// 真实办理人电话(手动填写)
///
[SugarColumn(IsNullable = true)]
public string? RealHandlerPhone { get; set; }
///
/// 沟通方式(手动填写)
///
public ERealCommunicationMode? RealCommunicationMode { get; set; }
///
/// 沟通时间(手动填写)
///
public DateTime? RealCommunicationTime { get; set; }
///
/// 沟通地点(手动填写)
///
[SugarColumn(IsNullable = true)]
public string? RealCommunicationAddress { get; set; }
#endregion
#region 当前办理节点信息
///
/// 当前办理节点code(非会签:当前被指派节点,会签:会签发起节点)
///
[SugarColumn(IsNullable = true)]
public string? CurrentStepCode { get; set; }
///
/// 当前节点名称
///
[SugarColumn(IsNullable = true)]
public string? CurrentStepName { get; set; }
///
/// 到达当前节点时间(stepBox创建时间)
///
public DateTime? CurrentStepCreateTime { get; set; }
#endregion
#region 一级部门
///
/// 一级部门code
///
[SugarColumn(IsNullable = true)]
public string? OrgLevelOneCode { get; set; }
///
/// 一级部门名称
///
[SugarColumn(IsNullable = true)]
public string? OrgLevelOneName { get; set; }
#endregion
#region 受理人(开启流程的话务员)
///
/// 受理人id
///
[SugarColumn(IsNullable = true)]
public string? AcceptorId { get; set; }
///
/// 受理人名称
///
[SugarColumn(IsNullable = true)]
public string? AcceptorName { get; set; }
///
/// 受理人工号
///
[SugarColumn(IsNullable = true)]
public string? AcceptorStaffNo { get; set; }
///
/// 受理人部门编码
///
public string? AcceptorOrgCode { get; set; }
///
/// 受理人部门名称
///
public string? AcceptorOrgName { get; set; }
#endregion
#endregion
///
/// 第一次评价结果
///
[SugarColumn(IsNullable = true, DefaultValue = "")]
public string? FirstVisitResult { get; set; }
[SugarColumn(IsNullable = true, DefaultValue = "")]
public string? FirstVisitResultCode { get; set; }
}
public partial class Order
{
///
/// 受理人
///
[Navigate(NavigateType.OneToOne, nameof(AcceptorId))]
public User Acceptor { get; set; }
///
/// 热点
///
[Navigate(NavigateType.OneToOne, nameof(HotspotId))]
public Hotspot Hotspot { get; set; }
///
/// 办理流程
///
[Navigate(NavigateType.OneToOne, nameof(WorkflowId))]
public Workflow Workflow { get; set; }
///
/// 工单扩展信息(12315-投诉)
///
[Navigate(NavigateType.OneToOne, nameof(Id))]
public OrderComplain OrderComplain { get; set; }
///
/// 工单扩展信息(12315-举报)
///
[Navigate(NavigateType.OneToOne, nameof(Id))]
public OrderReport OrderReport { get; set; }
///
/// 已发布工单
///
[Navigate(NavigateType.OneToOne, nameof(Id))]
public OrderPublish OrderPublish { get; set; }
///
/// 已回访工单
///
[Navigate(NavigateType.OneToMany, nameof(OrderVisit.OrderId))]
public List OrderVisits { get; set; }
[Navigate(NavigateType.OneToMany, nameof(OrderScreen.OrderId))]
public List OrderScreens { get; set; }
#region Method
public void Cancel()
{
IsCancel = true;
}
public void Redo()
{
Status = EOrderStatus.Handling;
ExpiredStatus = EExpiredStatus.Normal;
}
public void CheckIfFiled()
{
if (Status is EOrderStatus.Filed)
throw UserFriendlyException.SameMessage("工单已归档");
}
public void Init(string userId, string? userName, string? staffNo)
{
AcceptorId = userId;
AcceptorName = userName;
AcceptorStaffNo = staffNo;
if (!string.IsNullOrEmpty(Contact))
ContactMask = Contact.MaskPhoneNumber();
Status = EOrderStatus.WaitForAccept;
ExpiredStatus = EExpiredStatus.Normal;
}
///
/// 开始工单办理流程
///
public void StartManageFlow() => Status = EOrderStatus.Handling;
///
/// 更新工单办理中状态
///
public void UpdateHandlingStatus(bool isInCountersign) =>
Status = isInCountersign ? EOrderStatus.Countersigning : EOrderStatus.Handling;
/////
///// 接办
/////
//public void Accept()
//{
// if (Status is EOrderStatus.Countersigning) return;
// Status = EOrderStatus.Handling;
//}
/////
///// 最终办理
/////
//public void FinalManage()
//{
// Status = EOrderStatus.Completed;
//}
/////
///// 撤回最终办理
/////
//public void RecallFinalManage()
//{
// Status = EOrderStatus.WaitForSign;
//}
///
/// 归档
///
public void Filed()
{
if (Status is EOrderStatus.Filed) return;
Status = EOrderStatus.Filed;
FiledTime = DateTime.Now;
}
///
/// 发布
///
///
public void Publish(bool isPublicity)
{
//Progress = EProgress.Published;
Status = EOrderStatus.Published;
IsPublicity = isPublicity;
}
///
/// 已回访
///
public void Visited(string resultCode, string result)
{
if (string.IsNullOrEmpty(resultCode) || string.IsNullOrEmpty(result))
throw new UserFriendlyException("无效参数");
if (!string.IsNullOrEmpty(FirstVisitResultCode)) return;
FirstVisitResultCode = resultCode;
FirstVisitResult = result;
//Progress = EProgress.Visited;
Status = EOrderStatus.Visited;
}
#endregion
}
}