using Hotline.Share.Dtos.Order;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Enums.Order;
using Hotline.Share.Enums.Snapshot;
using Hotline.Share.Requests;
using Hotline.Share.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using XF.Utility.EnumExtensions;
using JsonIgnoreAttribute = System.Text.Json.Serialization.JsonIgnoreAttribute;

namespace Hotline.Share.Dtos.Snapshot;

public record RedPackStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    [Required]
    public string? IndustryId { get; set; }

    /// <summary>
    /// 行业类型
    /// </summary>
    [Required]
    public int IndustryType { get; set; }
}

public class RedPackStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 办理时长
    /// </summary>
    public double CreationTimeHandleDuration { get; set; }

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 电话
    /// </summary>
    public string Contact { get; set; }

    /// <summary>
    /// 受理期满时间
    /// </summary>
    public DateTime? AcceptExpiredTime { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }

    /// <summary>
    /// 受理内容
    /// </summary>
    public string Content { get; set; }

    /// <summary>
    /// 办理结果
    /// </summary>
    public string FileOpinion { get; set; }
}

public class RedPackStatisticsInDto
{
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}

public class RedPackStatisticsOutDto
{
    /// <summary>
    /// 行业类型
    /// </summary>
    [JsonIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public string CaseName { get; set; }

    /// <summary>
    /// 行业类型Id
    /// </summary>
    [JsonIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public string CaseId { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    [JsonIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public string? Id { get; set; }

    /// <summary>
    /// 行业名字
    /// </summary>
    [JsonIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public string Name { get; set; }

    /// <summary>
    /// 配置金额(后端逻辑用, 前端不显示)
    /// </summary>
    [JsonIgnore]
    [Newtonsoft.Json.JsonIgnore]
    public double? ShouldAmount { get; set; } = 0;

    /// <summary>
    /// 审批同意总金额
    /// </summary>
    public double? ApprovalAmount { get; set; } = 0;

    /// <summary>
    /// 审批同意总金额
    /// </summary>
    public string? ApprovalAmountTxt => ApprovalAmount?.ToString("f2");

    /// <summary>
    /// 审批同意总个数
    /// </summary>
    public int ApprovalCount { get; set; }

    /// <summary>
    /// 发送成功金额
    /// </summary>
    public double? SentAmount { get; set; } = 0;

    /// <summary>
    /// 发送成功金额
    /// </summary>
    public string? SentAmountTxt => SentAmount?.ToString("f2");

    /// <summary>
    /// 发送成功个数
    /// </summary>
    public int SentCount { get; set; }

    /// <summary>
    /// 发送失败金额
    /// </summary>
    public double SendFailAmount { get; set; } = 0;

    /// <summary>
    /// 发送失败金额
    /// </summary>
    public string? SendFailAmountTxt => SendFailAmount.ToString("f2");

    /// <summary>
    /// 发送失败个数
    /// </summary>
    public int SendFailCount { get; set; }

    /// <summary>
    /// 待发金额
    /// </summary>
    public double? PendingAmount { get; set; } = 0;

    /// <summary>
    /// 待发金额
    /// </summary>
    public string? PendingAmountTxt => PendingAmount?.ToString("f2");

    /// <summary>
    /// 待发个数
    /// </summary>
    public int PendingCount { get; set; }

    /// <summary>
    /// 补充红包金额
    /// </summary>
    public double? SupplementAmount { get; set; } = 0;

    /// <summary>
    /// 补充红包金额
    /// </summary>
    public string? SupplementAmountTxt => SupplementAmount?.ToString("f2");

    /// <summary>
    /// 补充红包数
    /// </summary>
    public int SupplementCount { get; set; }

    /// <summary>
    /// 行业类型名称
    /// </summary>
    public string? IndustryName { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }

    /// <summary>
    /// 行业类型
    /// </summary>
    public int IndustryType { get; set; }
}

/// <summary>
/// 随手拍统计输出Dto
/// </summary>
public class SnapshotStatisticsOutDto
{
    /// <summary>
    /// 随手拍来件数
    /// </summary>
    public int SSPLJS => WZSLFWNJS + SSPZ12345JS + SLFWNZJS;

    /// <summary>
    /// 未在受理范围内件数
    /// </summary>
    public int WZSLFWNJS { get; set; }

    /// <summary>
    /// 随手拍转12345件数
    /// </summary>
    public int SSPZ12345JS { get; set; }

    /// <summary>
    /// 受理范围内总件数
    /// </summary>
    public int SLFWNZJS { get; set; }

    /// <summary>
    /// 受理范围内派给各网格员件数
    /// </summary>
    public int SLFWNPGGWGYJS => SLFWNPGWGYSXSNHFJS + SLFWNPGWGYCGSXSHFJS + SLFWNPGWGYWHFJS;

    /// <summary>
    /// 受理范围内派给网格员四小时内回复件数
    /// </summary>
    public int SLFWNPGWGYSXSNHFJS { get; set; }

    /// <summary>
    /// 受理范围内派给网格员超过四小时回复件数
    /// </summary>
    public int SLFWNPGWGYCGSXSHFJS { get; set; }

    /// <summary>
    /// 受理范围内派给网格员未回复件数
    /// </summary>
    public int SLFWNPGWGYWHFJS { get; set; }

    /// <summary>
    /// 受理范围内按12345直派给各区县或部门件数
    /// </summary>
    public int SLFWNA12345ZPGGQXHBMJS => SLFWNA12345ZPGGBMJS + SLFWNA12345ZPGGQXJS;

    /// <summary>
    /// 受理范围内按12345直派给各部门件数
    /// </summary>
    public int SLFWNA12345ZPGGBMJS { get; set; }

    /// <summary>
    /// 受理范围内按12345直派给各区县件数
    /// </summary>
    public int SLFWNA12345ZPGGQXJS { get; set; }

    /// <summary>
    /// 受理范围内已办信件
    /// </summary>
    public int SLFWNYBXJ => ZXYB + BMYB;

    /// <summary>
    /// 中心已办
    /// </summary>
    public int ZXYB { get; set; }

    /// <summary>
    /// 部门已办
    /// </summary>
    public int BMYB { get; set; }

    /// <summary>
    /// 受理范围满意度
    /// </summary>
    public double SLFWMYD => SLFWNZJS == 0 ? 0 : (double)MYL / SLFWNZJS;

    /// <summary>
    /// 计算率
    /// </summary>
    /// <returns></returns>
    public string CalcRate(int Quantity, int Count)
    {
        if (Count != 0 && Quantity != 0)
        {
            return Math.Round((Quantity / (double)Count) * 100, 2) + "%";
        }
        return "0%";
    }

    /// <summary>
    /// 受理范围满意度
    /// </summary>
    public string SLFWMYDTxt => CalcRate(MYL, SLFWNZJS);

    /// <summary>
    /// 满意量
    /// </summary>
    public int MYL { get; set; }

    /// <summary>
    /// 不满意量
    /// </summary>
    public int BMYL { get; set; }

    /// <summary>
    /// 审核发放奖励个数
    /// </summary>
    public int SHFFJLGS => SPBTYHBGS + SPTYHBGS;

    /// <summary>
    /// 审批不同意红包个数
    /// </summary>
    public int SPBTYHBGS { get; set; }

    /// <summary>
    /// 审批同意红包个数
    /// </summary>
    public int SPTYHBGS { get; set; }

    /// <summary>
    /// 特殊红包审批统计
    /// </summary>
    public int TSHBSP { get; set; }

    /// <summary>
    /// 审批同意个数
    /// </summary>
    public int SPTYGS { get; set; }

    /// <summary>
    /// 已发金额
    /// </summary>
    public double? YFJE { get; set; }

    /// <summary>
    /// 局审核发放网格员奖励个数
    /// </summary>
    public int JSHFFWGJLGS { get; set; }

    /// <summary>
    /// 审批同意（网格员）红包个数
    /// </summary>
    public int SPTYWGYHBGS { get; set; }

    /// <summary>
    /// 审批不同意（网格员）红包个数
    /// </summary>
    public int SPBTYWGYHBGS { get; set; }

    /// <summary>
    /// 市民奖励总额
    /// </summary>
    public double? SMJLZE { get; set; }

    /// <summary>
    /// 市民已发放奖励总额
    /// </summary>
    public double? SMYFFJLZE { get; set; }

    /// <summary>
    /// 市民待发奖励总额
    /// </summary>
    public double? SMDFFJLZE { get; set; }

    /// <summary>
    /// 已发（个）
    /// </summary>
    public int YFG { get; set; }

    /// <summary>
    /// 无法联系（个）
    /// </summary>
    public int WFLXG { get; set; }

    /// <summary>
    /// 婉拒红包（个）
    /// </summary>
    public int WJHBG { get; set; }

    /// <summary>
    /// 网格员应发奖励金额
    /// </summary>
    public double? WGYYFJLJE { get; set; }

    /// <summary>
    /// 网格员已发放奖励总额
    /// </summary>
    public double? WGYYFFJLZE { get; set; }

    /// <summary>
    /// 网格员待发放奖励总额
    /// </summary>
    public double? WGYDFFJLZE { get; set; }

    /// <summary>
    /// 网格员扣款总额（已发）
    /// </summary>
    public float WGYKKZEYF { get; set; }

    /// <summary>
    /// 网格员扣款总额（待发）
    /// </summary>
    public float WGYKKZEDF { get; set; }

    /// <summary>
    /// 受理范围内多部门会签件件数
    /// </summary>
    public int SLFWNDBMHQJJS { get; set; }

    /// <summary>
    /// 受理范围内热线中心归档件数
    /// </summary>
    public int SLFWNRXZXGDJS { get; set; }

    /// <summary>
    /// 热线中心发起会签件件数
    /// </summary>
    public int RXZXFQHQJJS { get; set; }

    /// <summary>
    /// 安全隐患
    /// </summary>
    public int AQYH { get; set; }

    /// <summary>
    /// 已完成安全隐患整改
    /// </summary>
    public int YWCAQYHZG { get; set; }

    /// <summary>
    /// 申请延期工单件数
    /// </summary>
    public int SQYQGDJS { get; set; }

    /// <summary>
    /// 申请延期工单次数
    /// </summary>
    public int SQYQGDCS { get; set; }

    /// <summary>
    /// 超期件
    /// </summary>
    public int CQJ { get; set; }

    /// <summary>
    /// 二次办理件数
    /// </summary>
    public int ECBLJS => ECBLJSTHBM + ECBLJSHFBMYCB + ECBLJSTTDYYJBM;

    /// <summary>
    /// 二次办理件数-退回部门
    /// </summary>
    public int ECBLJSTHBM { get; set; }

    /// <summary>
    /// 二次办理件数-回访不满意重办
    /// </summary>
    public int ECBLJSHFBMYCB { get; set; }

    /// <summary>
    /// 二次办理件数-回访满意
    /// </summary>
    public int ECBLJSHFMY { get; set; }

    /// <summary>
    /// 二次办理件数-特提到原一级部门
    /// </summary>
    public int ECBLJSTTDYYJBM { get; set; }

    /// <summary>
    /// 二次办理工单满意率
    /// </summary>
    public double ECBLGDMYL => ECBLJS == 0 ? 0 : (ECBLJSHFMY / ECBLJS) * 100;

    /// <summary>
    /// 二次办理工单满意率
    /// </summary>
    public string ECBLGDMYLTxt => ECBLGDMYL.ToString("f4") + "%";

    /// <summary>
    /// 二次办理工单件数-退回部门回访满意
    /// </summary>
    public int ECBLGDJSTMBMHFMYD { get; set; }

    /// <summary>
    /// 二次办理工单满意率-退回部门
    /// </summary>
    public double ECBLGDMYLTHBM => ECBLJSTHBM == 0 ? 0 : (ECBLGDJSTMBMHFMYD / ECBLJSTHBM) * 100;

    /// <summary>
    /// 二次办理工单满意率-退回部门
    /// </summary>
    public string ECBLGDMYLTHBMTxt => ECBLGDMYLTHBM.ToString("f4") + "%";

    /// <summary>
    /// 二次办理工单满意率-回访不满意重办
    /// </summary>
    public double ECBLGDMYLHFBMYCB => ECBLJS == 0 ? 0 : (ECBLJSHFBMYCB / ECBLJS) * 100;

    /// <summary>
    /// 二次办理工单满意率-回访不满意重办
    /// </summary>
    public string ECBLGDMYLHFBMYCBTxt => ECBLGDMYLHFBMYCB.ToString("f4") + "%";

    /// <summary>
    /// 特提件数
    /// </summary>
    public int TTJS => TTDYYJBMJS + TTDPDZJS + QTTTJS;

    /// <summary>
    /// 特提到原一级部门件数
    /// </summary>
    public int TTDYYJBMJS { get; set; }

    /// <summary>
    /// 特提到派单组件数
    /// </summary>
    public int TTDPDZJS { get; set; }

    /// <summary>
    /// 其他特提件数
    /// </summary>
    public int QTTTJS { get; set; }
}

/// <summary>
/// 随手拍统计输入Dto
/// </summary>
public class SnapshotStatisticsInDto
{
    /// <summary>
    /// 开始时间
    /// </summary>
    [Required]
    public DateTime StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}

public record SnapshotStatisticsDetailInDto : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    [Required]
    public DateTime StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }
}

public class SnapshotStatisticsDetailOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 办理时长
    /// </summary>
    public double CreationTimeHandleDuration { get; set; }

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 电话
    /// </summary>
    public string Contact { get; set; }

    /// <summary>
    /// 网格员名称
    /// </summary>
    public string MemberName { get; set; }

    /// <summary>
    /// 网格员电话
    /// </summary>
    public string MemberMobile { get; set; }

    /// <summary>
    /// 网格员回复
    /// </summary>
    public string NetworkRemark { get; set; }

    /// <summary>
    /// 网格E通编号
    /// </summary>
    public string? NetworkENumber { get; set; }

    /// <summary>
    /// 受理期满时间
    /// </summary>
    public DateTime? AcceptExpiredTime { get; set; }

    /// <summary>
    /// 一级部门
    /// </summary>
    public string OrgLevelOneCode { get; set; }

    /// <summary>
    /// 一级部门名称
    /// </summary>
    public string? OrgLevelOneName { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }

    /// <summary>
    /// 受理内容
    /// </summary>
    public string Content { get; set; }

    /// <summary>
    /// 办理结果
    /// </summary>
    public string FileOpinion { get; set; }
}
public class StatisticsDto
{
}

public class HotspotStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 分类Code
    /// </summary>
    public string? HotspotCode { get; set; }
}

public class HotspotStatisticsOutDto
{
    public string HotspotCode { get; set; }
    public int SumCount { get; set; }
    public string HotspotName { get; set; }
    public bool HasChild { get; set; }
}

public record HotspotStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }

    public string? HotspotCode { get; set; }

}
public class HotspotStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 甄别状态
    /// </summary>
    public EScreenStatus? OrderScreenStatus { get; set; }

    /// <summary>
    /// 甄别状态
    /// </summary>
    public string? OrderScreenStatusText => OrderScreenStatus.HasValue && OrderScreenStatus != null ? OrderScreenStatus?.GetDescription() : "未甄别";

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 办理时长
    /// </summary>
    public double CreationTimeHandleDuration { get; set; }

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 电话
    /// </summary>
    public string Contact { get; set; }

    /// <summary>
    /// 受理期满时间
    /// </summary>
    public DateTime? AcceptExpiredTime { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 满意度
    /// </summary>
    public Kv? OrgProcessingResults { get; set; }

    /// <summary>
    /// 满意度
    /// </summary>
    public string? OrgProcessingResultsTxt => OrgProcessingResults != null ? OrgProcessingResults.Value : "";

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }

    /// <summary>
    /// 受理内容
    /// </summary>
    public string Content { get; set; }

    /// <summary>
    /// 办理结果
    /// </summary>
    public string FileOpinion { get; set; }
}

public class SnapshotProcessingStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}

public class SnapshotProcessingStatisticsOutDto
{
    /// <summary>
    /// 部门Code
    /// </summary>
    public string OrgCode { get; set; }

    /// <summary>
    /// 部门名称
    /// </summary>
    public string OrgName { get; set; }

    /// <summary>
    /// 信件总量
    /// </summary>
    public int OrderCountNum => YbOrderCountNum + ZbOrderCountNum;

    /// <summary>
    /// 信件已办总量
    /// </summary>
    public int YbOrderCountNum { get; set; }

    /// <summary>
    /// 信件未办总量
    /// </summary>
    public int ZbOrderCountNum { get; set; }

    /// <summary>
    /// 按时办结
    /// </summary>
    public int CompleteOnTime { get; set; }

    /// <summary>
    /// 按时办结率
    /// </summary>
    public string CompleteOnTimeRate => CalcRate(YbOrderCountNum, CompleteOnTime);

    /// <summary>
    /// 办结率
    /// </summary>
    public string OrderCompletionRate => CalcRate(YbOrderCountNum, OrderCountNum);

    /// <summary>
    /// 20分钟内接件
    /// </summary>
    public int ReceiveIn20Minutes { get; set; }

    /// <summary>
    /// 20分钟后接件
    /// </summary>
    public int ReceiveOut20Minutes { get; set; }

    /// <summary>
    /// 工单及时响应率
    /// </summary>
    public string PromptResponse => CalcRate(ReceiveIn20Minutes, ReceiveIn20Minutes + ReceiveOut20Minutes);

    /// <summary>
    /// 退回件
    /// </summary>
    public int BackNum { get; set; }

    /// <summary>
    /// 办件总时长
    /// </summary>
    public double? TotalHandleDuration { get; set; }

    /// <summary>
    /// 3日内办结
    /// </summary>
    public int End3Day { get; set; }

    /// <summary>
    /// 3至5日办结
    /// </summary>
    public int End3To5Day { get; set; }

    /// <summary>
    /// 5至7日办结
    /// </summary>
    public int End5To7Day { get; set; }

    /// <summary>
    /// 7日外办结
    /// </summary>
    public int End7Day { get; set; }

    /// <summary>
    /// 按时办结个数
    /// </summary>
    public int OnTimeCount { get; set; }

    /// <summary>
    /// 按时办结率
    /// </summary>
    public string CloseOnTimeRate => CalcRate(OnTimeCount, OrderCountNum);

    /// <summary>
    /// 满意量
    /// </summary>
    public int SatisfiedCount { get; set; }

    /// <summary>
    /// 不满意量
    /// </summary>
    public int NoSatisfiedCount { get; set; }

    /// <summary>
    /// 满意率
    /// </summary>
    public string SatisfiedRate => CalcRate(SatisfiedCount, SatisfiedCount + NoSatisfiedCount);

    /// <summary>
    /// 二次办理个数
    /// </summary>
    public int SecondNum { get; set; }

    /// <summary>
    /// 计算率
    /// </summary>
    /// <returns></returns>
    public string CalcRate(int Quantity, int Count)
    {
        if (Count != 0 && Quantity != 0)
        {
            return Math.Round((Quantity / (double)Count) * 100, 2) + "%";
        }
        return "0%";
    }
}

public record SnapshotProcessingStatisticsDetailsInDto : PagedRequest
{
    /// <summary>
    /// 开始时间
    /// </summary>
    [Required]
    public DateTime StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }

    /// <summary>
    /// 部门Id
    /// </summary>
    [Required]
    public string OrgId { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}

public class SnapshotProcessingStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 甄别状态
    /// </summary>
    public EScreenStatus? OrderScreenStatus { get; set; }

    /// <summary>
    /// 甄别状态
    /// </summary>
    public string? OrderScreenStatusText => OrderScreenStatus.HasValue && OrderScreenStatus != null ? OrderScreenStatus?.GetDescription() : "未甄别";

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }
}

public class GuiderWorkStatisticsOutDto
{
    /// <summary>
    /// 网格员姓名
    /// </summary>
    public string MemberName { get; set; }

    /// <summary>
    /// 网格员手机号
    /// </summary>
    public string MemberMobile { get; set; }

    /// <summary>
    /// 未回复
    /// </summary>
    public int UnReplyCount { get; set; }

    /// <summary>
    /// 4小时内回复
    /// </summary>
    public int ReplyIn4HourCount { get; set; }

    /// <summary>
    /// 4小时外回复
    /// </summary>
    public int ReplyOut4HourCount { get; set; }
}

public class GuiderWorkStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}

public record GuiderWorkStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }

    [Required]
    public string MemberMobile { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }
}

public class GuiderWorkStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 办理时长
    /// </summary>
    public double CreationTimeHandleDuration { get; set; }

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 电话
    /// </summary>
    public string Contact { get; set; }

    /// <summary>
    /// 网格员姓名
    /// </summary>
    public string MemberName { get; set; }

    /// <summary>
    /// 网格员手机号
    /// </summary>
    public string MemberMobile { get; set; }

    /// <summary>
    /// 网格员回复内容
    /// </summary>
    public string? NetworkRemark { get; set; }

    /// <summary>
    /// 受理期满时间
    /// </summary>
    public DateTime? AcceptExpiredTime { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }
}

public class HotspotDataStatisticsOutDto
{
    /// <summary>
    /// 热点名字
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 热点工单数量
    /// </summary>
    public int OrderCount { get; set; }
}

public class HotspotDataStatisticsInDto
{
    /// <summary>
    /// 类型:
    /// 0: 全部;
    /// 1: 市民;
    /// 2: 企业;
    /// </summary>
    [Required]
    public int TypeId { get; set; }

    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}

public class GuiderWorkLogsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// title
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 网格员回复内容
    /// </summary>
    public string? NetworkRemark { get; set; }

    /// <summary>
    /// 回复时间
    /// </summary>
    public DateTime? ReplyDate { get; set; }

    /// <summary>
    /// 网格员姓名
    /// </summary>
    public string? MemberName { get; set; }

    /// <summary>
    /// 网格员电话
    /// </summary>
    public string? MemberMobile { get; set; }

    /// <summary>
    /// 网格E通编号
    /// </summary>
    public string? NetworkENumber { get; set; }

    /// <summary>
    /// 网格员办理状态
    /// </summary>
    public EGuiderSystemReplyType? ReplyResultType { get; set; }

    /// <summary>
    /// 网格员办理状态
    /// </summary>
    public string ReplyResultTypeTxt => ReplyResultType == null ? "未知" : ReplyResultType.Value.GetDescription();
}

public record GuiderWorkLogsInDto : PagedRequest
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// No
    /// </summary>
    public string? No { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 网格员姓名
    /// </summary>
    public string? MemberName { get; set; }

    /// <summary>
    /// 网格员电话
    /// </summary>
    public string? MemberMobile { get; set; }

    /// <summary>
    /// 编号
    /// </summary>
    public string? NetworkENumber { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public EOrderStatus? Status { get; set; }

    /// <summary>
    /// 受理时间开始
    /// </summary>
    public DateTime? BeginCreationTime { get; set; }

    /// <summary>
    /// 受理时间结束
    /// </summary>
    public DateTime? EndCreationTime { get; set; }
}

public record DuplicateItemsInDto : PagedRequest
{
    /// <summary>
    /// 编号
    /// </summary>
    public string? No { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 来电号码
    /// </summary>
    public string? FromPhone { get; set; }

    /// <summary>
    /// 联系号码
    /// </summary>
    public string? Contact { get; set; }

    /// <summary>
    /// 来电人
    /// </summary>
    public string? FromName { get; set; }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime? BeginCreationTime { get; set; }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime? EndCreationTime { get; set; }

    /// <summary>
    /// 期满时间开始
    /// </summary>
    public DateTime? BeginExpiredTime { get; set; }

    /// <summary>
    /// 期满时间结束
    /// </summary>
    public DateTime? EndExpiredTime { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string? ActualHandleOrgName { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string? AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string? HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string? AcceptorName { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}
public class DuplicateItemsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// No
    /// </summary>
    public string? No { get; set; }

    /// <summary>
    /// 类型
    /// </summary>
    public string? OrderSnapshotType { get; set; }

    /// <summary>
    /// 重复工单Id
    /// </summary>
    public List<string>? DuplicateIds { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 网格员姓名
    /// </summary>
    public string? MemberName { get; set; }

    /// <summary>
    /// 网格员电话
    /// </summary>
    public string? MemberMobile { get; set; }

    /// <summary>
    /// 编号
    /// </summary>
    public string? NetworkENumber { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public EOrderStatus? Status { get; set; }

    /// <summary>
    /// 受理时间开始
    /// </summary>
    public DateTime? BeginCreationTime { get; set; }

    /// <summary>
    /// 受理时间结束
    /// </summary>
    public DateTime? EndCreationTime { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }
}

public class CommunityStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }

    public string? CommunityCode { get; set; }
}

public class CommunityStatisticsOutDto
{
    public string CommunityCode { get; set; }
    public int SumCount { get; set; }
    public string CommunityName { get; set; }
    public bool HasChild { get; set; }
    public string CommunityFullName { get; set; }
}

public class CommunityStatisticsDetailsOutDto
{

    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 社区名称
    /// </summary>
    public string CommunityName { get; set; }
}

public record CommunityStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 社区全称
    /// </summary>
    [Required]
    public string CommunityFullName { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}

public class CountyRedPackStatisticsOutDto
{
    /// <summary>
    /// 区域
    /// </summary>
    public string? County { get; set; }

    /// <summary>
    /// 举报总数
    /// </summary>
    public int JuBaoZongShu { get; set; }

    /// <summary>
    /// 已办结数
    /// </summary>
    public int YiBanJieShu { get; set; }

    /// <summary>
    /// 办结率
    /// </summary>
    public string BanJieLv => CalcRate(YiBanJieShu, JuBaoZongShu);

    /// <summary>
    /// 市民审核通过数
    /// </summary>
    public int ShiMinShenHeTongGuoShu { get; set; }

    /// <summary>
    /// 市民总金额
    /// </summary>
    public double? ShiMinZongJinE { get; set; }

    /// <summary>
    /// 市民已领
    /// </summary>
    public double ShiMinYiLing { get; set; }

    /// <summary>
    /// 市民待领
    /// </summary>
    public double ShiMinDaiLing { get; set; }

    /// <summary>
    /// 市民待补领
    /// </summary>
    public double? ShiMinDaiBuLing { get; set; }

    /// <summary>
    /// 网格员总件数
    /// </summary>
    public int WangGeYuanZongJianShu { get; set; }

    /// <summary>
    /// 网格员审核通过数
    /// </summary>
    public int WangGeYuanShenHeTongGuoShu { get; set; }

    /// <summary>
    /// 网格员总金额
    /// </summary>
    public double? WangGeYuanZongJinE { get; set; }

    /// <summary>
    /// 网格员已领
    /// </summary>
    public double WangGeYuanYiLing { get; set; }

    /// <summary>
    /// 网格员待领
    /// </summary>
    public double WangGeYuanDaiLing { get; set; }

    /// <summary>
    /// 网格员待补领
    /// </summary>
    public double WangGeYuianDaiBuLing { get; set; } = 0;

    /// <summary>
    /// 计算率
    /// </summary>
    /// <returns></returns>
    public string CalcRate(int Quantity, int Count)
    {
        if (Count != 0 && Quantity != 0)
        {
            return Math.Round((Quantity / (double)Count) * 100, 2) + "%";
        }
        return "0%";
    }

}

public class CountyRedPackStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    public string? IndustryId { get; set; }
}


public class SnapshotDepartmentStatisticsOutDto
{
    /// <summary>
    /// 部门Code
    /// </summary>
    public string OrgCode { get; set; }

    /// <summary>
    /// 部门名称
    /// </summary>
    public string OrgName { get; set; }

    /// <summary>
    /// 信件总量
    /// </summary>
    public int OrderCountNum { get; set; }

    /// <summary>
    /// 按时办结个数
    /// </summary>
    public int OnTimeCount { get; set; }

    /// <summary>
    /// 工单及时率
    /// </summary>
    public string TimelinessRatio { get; set; } = "0.00";

    /// <summary>
    /// 4小时内
    /// </summary>
    public int ReceiveIn4Hour { get; set; }

    /// <summary>
    /// 超期办结
    /// </summary>
    public int TimeOutField { get; set; }

    /// <summary>
    /// 超期未办结
    /// </summary>
    public int TimeOutNoField { get; set; }

    /// <summary>
    /// 超期率
    /// </summary>
    public string TimeOutRate => CalcRate(TimeOutNoField + TimeOutField, OrderCountNum);

    /// <summary>
    /// 超期量
    /// </summary>
    public int TimeOutCount => TimeOutField + TimeOutNoField;

    /// <summary>
    /// 按时办结率
    /// </summary>
    public string CloseOnTimeRate => CalcRate(OnTimeCount, OrderCountNum);

    /// <summary>
    /// 满意工单
    /// </summary>
    public int SatisfiedCount { get; set; }

    /// <summary>
    /// 回访满意率
    /// </summary>
    public string SatisfiedRate => CalcRate(SatisfiedCount, SatisfiedCount + NoSatisfiedCount);

    /// <summary>
    /// 不满意量
    /// </summary>
    public int NoSatisfiedCount { get; set; }

    /// <summary>
    /// 一次办结工单
    /// </summary>
    public int FirstFiledOrderCount { get; set; }

    /// <summary>
    /// 一次办结率
    /// </summary>
    public string FirstFiledOrderRate => CalcRate(FirstFiledOrderCount, OrderCountNum);

    /// <summary>
    /// 二次办理个数
    /// </summary>
    public int SecondNum { get; set; }

    /// <summary>
    /// 二次办理满意率
    /// </summary>
    public int SecondSatisfied { get; set; }

    /// <summary>
    /// 二次办理率
    /// </summary>
    public string SecondRate => CalcRate(SecondNum, OrderCountNum);

    /// <summary>
    /// 计算率
    /// </summary>
    /// <returns></returns>
    public string CalcRate(int Quantity, int Count)
    {
        if (Count != 0 && Quantity != 0)
        {
            return Math.Round((Quantity / (double)Count) * 100, 2) + "%";
        }
        return "0%";
    }
}

public class SnapshotDepartmentStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}

public class SnapshotDepartmentAveTimeStatisticsOutDto
{
    public string OrgCode { get; set; }
    public object OrgName { get; set; }

    /// <summary>
    /// 工单数
    /// </summary>
    public int OrderCountNum { get; set; }

    /// <summary>
    /// 总秒数
    /// </summary>
    public double? TotalSeconds { get; set; }

    /// <summary>
    /// 总分钟数
    /// </summary>
    public string TotalMinutes => TotalSeconds == null ? "0" : ((double)TotalSeconds / 60).ToString("f0");

    /// <summary>
    /// 平均分钟数
    /// </summary>
    public string AvgMinutes => OrderCountNum == 0 ? "0" : (double.Parse(TotalMinutes) / OrderCountNum).ToString("f2");

    /// <summary>
    /// 平均小时数
    /// </summary>
    public string AvgHours => OrderCountNum == 0 ? "0" : (double.Parse(TotalMinutes) / 60 / OrderCountNum).ToString("f2");
}

public class SnapshotDepartmentAveTimeStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

}

public record SnapshotDepartmentAveTimeStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 部门编号
    /// </summary>
    [Required]
    public string OrgCode { get; set; }
}

public class SnapshotDepartmentAveTimeStatisticsDetailsOutDto
{

    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 办理时长(秒)
    /// </summary>
    public double? AllDuration { get; set; }

    /// <summary>
    /// 办理时长(分)
    /// </summary>
    public string TotalMinutes => AllDuration == null ? "0" : ((double)AllDuration / 60).ToString("f0");

    /// <summary>
    /// 办理时长(时)
    /// </summary>
    public string TotalHours => AllDuration == null ? "0" : ((double)AllDuration / 60 / 60).ToString("f2");

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

}

public class CompliantStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}


public class CompliantStatisticsOutDto
{
    public string OrgCode { get; set; }

    /// <summary>
    /// 部门名称
    /// </summary>
    public string OrgName { get; set; }

    /// <summary>
    /// 工单总数
    /// </summary>
    public int OrderCountNum => First + Second + Third + Not;

    /// <summary>
    /// 首次
    /// </summary>
    public int First { get; set; }

    /// <summary>
    /// 二次
    /// </summary>
    public int Second { get; set; }

    /// <summary>
    /// 三次及以上
    /// </summary>
    public int Third { get; set; }

    /// <summary>
    /// 不合规
    /// </summary>
    public int Not { get; set; }
}

public record CompliantStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }

    /// <summary>
    /// 部门编号
    /// </summary>
    public string? OrgCode { get; set; }
}

public class CompliantStatisticsDetailsOutDto
{

    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

}

public class ReTransactStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}

public class ReTransactStatisticsOutDto
{
    /// <summary>
    /// 表头
    /// </summary>
    public IList<SystemDicDataOutDto> Headers { get; set; }

    /// <summary>
    /// 数据
    /// </summary>
    public List<Dictionary<string, object>> Data { get; set; }
}

public class ReTransactStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// No
    /// </summary>
    public string? No { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 被重办部门
    /// </summary>
    public string? ReTransactOrgName { get; set; }

    /// <summary>
    /// 被重办一级部门
    /// </summary>
    public string? ReTransactOneOrgName { get; set; }

    /// <summary>
    /// 重办时间
    /// </summary>
    public DateTime? ReTransactTime { get; set; }

    /// <summary>
    /// 重办操作人
    /// </summary>
    public string? ReTransactHandlerName { get; set; }

    /// <summary>
    /// 重办理由
    /// </summary>
    public string ReTransactContent { get; set; }

    /// <summary>
    /// 受理时间开始
    /// </summary>
    public DateTime? BeginCreationTime { get; set; }

    /// <summary>
    /// 受理时间结束
    /// </summary>
    public DateTime? EndCreationTime { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }

}

public record ReTransactStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    public string? FieldName { get; set; }

    /// <summary>
    /// 部门Code
    /// </summary>
    [Required]
    public string OrgCode { get; set; }
}

public class IndustryStatisticsOutDto
{
    /// <summary>
    /// 表头
    /// </summary>
    public IList<SystemDicDataOutDto> Headers { get; set; }

    /// <summary>
    /// 数据
    /// </summary>
    public List<Dictionary<string, object>> Data { get; set; }

}

public class IndustryStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }
}

public record IndustryStatisticsDetailsInDto : PagedRequest
{
    [Required]
    public DateTime StartTime { get; set; }
    [Required]
    public DateTime EndTime { get; set; }

    /// <summary>
    /// 字段名称
    /// </summary>
    [Required]
    public string FieldName { get; set; }

    /// <summary>
    /// 行业Id
    /// </summary>
    [Required]
    public string IndustryId { get; set; }
}

public class IndustryStatisticsDetailsOutDto
{
    /// <summary>
    /// Id
    /// </summary>
    public string Id { get; set; }

    /// <summary>
    /// 过期状态
    /// </summary>
    public EExpiredStatus? ExpiredStatus => FiledTime.CalculateExpiredState(Status, this.ExpiredTime, this.NearlyExpiredTime, this.NearlyExpiredTimeOne);

    /// <summary>
    /// 过期状态
    /// </summary>
    public string ExpiredStatusText => ExpiredStatus?.GetDescription();

    /// <summary>
    /// 受理编号
    /// </summary>
    public string No { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public EOrderStatus Status { get; set; }

    /// <summary>
    /// 信件状态
    /// </summary>
    public string StatusTxt => Status.GetDescription();

    /// <summary>
    /// 来源
    /// </summary>
    public string SourceChannel { get; set; }

    /// <summary>
    /// 当前节点
    /// </summary>
    public string CurrentStepName { get; set; }

    /// <summary>
    /// 重办次数
    /// </summary>
    public int ReTransactNum { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public bool IsUrgent { get; set; }

    /// <summary>
    /// 是否紧急
    /// </summary>
    public string IsUrgentText => IsUrgent ? "紧急" : "-";

    /// <summary>
    /// 期满时间
    /// </summary>
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间
    /// </summary>
    public DateTime? NearlyExpiredTime { get; set; }

    /// <summary>
    /// 即将超期时间第一级
    /// </summary>
    public DateTime? NearlyExpiredTimeOne { get; set; }

    /// <summary>
    /// 是否超期
    /// </summary>
    public bool IsExpired
    {
        get
        {
            if (ExpiredTime.HasValue)
                return DateTime.Now > ExpiredTime.Value;
            return false;
        }
    }

    /// <summary>
    /// 受理时间
    /// </summary>
    public DateTime CreationTime { get; set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 行业
    /// </summary>
    public string IndustryName { get; set; }

    /// <summary>
    /// 办理时长
    /// </summary>
    public double? AllDuration { get; set; }

    /// <summary>
    /// 办理时长(时)
    /// </summary>
    public string TotalHours => AllDuration == null ? "0" : ((double)AllDuration / 60 / 60).ToString("f2");

    /// <summary>
    /// 区域
    /// </summary>
    public string County { get; set; }

    /// <summary>
    /// 电话
    /// </summary>
    public string Contact { get; set; }

    /// <summary>
    /// 受理期满时间
    /// </summary>
    public DateTime? AcceptExpiredTime { get; set; }

    /// <summary>
    /// 接办部门
    /// </summary>
    public string ActualHandleOrgName { get; set; }

    /// <summary>
    /// 一级部门
    /// </summary>
    public string? OrgLevelOneName { get; set; }

    /// <summary>
    /// 接办时间
    /// </summary>
    public DateTime? ActualHandleTime { get; set; }

    /// <summary>
    /// 办结时间
    /// </summary>
    public DateTime? FiledTime { get; set; }

    /// <summary>
    /// 受理类型
    /// </summary>
    public string AcceptType { get; set; }

    /// <summary>
    /// 热点类型
    /// </summary>
    public string HotspotName { get; set; }

    /// <summary>
    /// 受理人
    /// </summary>
    public string AcceptorName { get; set; }

    /// <summary>
    /// 受理内容
    /// </summary>
    public string Content { get; set; }

    /// <summary>
    /// 办理结果
    /// </summary>
    public string FileOpinion { get; set; }

}

public class SnapshotCountyPointsStatisticsInDto
{
    [Required]
    public DateTime StartTime { get; set; }

    [Required]
    public DateTime EndTime { get; set; }

}

public class SnapshotCountyPointsStatisticsOutDto
{
    /// <summary>
    /// 区域名称
    /// </summary>
    public string CountyName { get; set; }

    /// <summary>
    /// 积分
    /// </summary>
    public long Points { get; set; }

    /// <summary>
    /// 兑换积分
    /// </summary>
    public long ExchangePoints { get; set; }
}
