using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using EquipmentApi.IRepositories;
using MadRunFabric.Model;
using MadRunFabric.Common.Options;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MongoDB.Bson;
using MongoDB.Driver;
using MadRunFabric.Common;
using System.Linq;
using EquipmentApi.Model.Dto;
using MadRunFabric.Common.Enums;

namespace EquipmentApi.Repositories
{
    public class RunningChartRepository : BaseRepository<Pro_Project_Info, string>, IRunningChartRepository
    {
        protected readonly ILogger<BaseRepository<Pro_Project_Info, string>> _logger;
        protected readonly IMongoCollection<Sys_DictionaryValue> _collection_sys_dictionaryvalue;
        protected readonly IMongoCollection<Eqp_Equipment_Info> _collection_eqp_equipment_info;
        protected readonly IMongoCollection<Sys_User_Account> _collection_sys_user_account;
        protected readonly IMongoCollection<Wo_Repair_Base> _collection_wo_repair_base;
        protected readonly IMongoCollection<Wo_Maintain_Base> _collection_wo_maintain_base;
        protected readonly IMongoCollection<Wo_EquipmentRunning> _collection_equipmentrunning;
        protected readonly IMongoCollection<Sys_Role_Info> _collection_role_info;
        protected readonly IMongoCollection<Sys_SystemConfig> _collection_sys_systemconfig;
        protected readonly IMongoCollection<Sys_News> _collection_sys_news;
        public RunningChartRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Pro_Project_Info, string>> logger) : base(settings, logger)
        {
            _collection_sys_dictionaryvalue = _context.GetCollection<Sys_DictionaryValue>();
            _collection_eqp_equipment_info = _context.GetCollection<Eqp_Equipment_Info>();
            _collection_sys_user_account = _context.GetCollection<Sys_User_Account>();
            _collection_wo_repair_base= _context.GetCollection<Wo_Repair_Base>();
            _collection_wo_maintain_base = _context.GetCollection<Wo_Maintain_Base>();
            _collection_equipmentrunning = _context.GetCollection<Wo_EquipmentRunning>();
            _collection_role_info = _context.GetCollection<Sys_Role_Info>();
            _collection_sys_systemconfig = _context.GetCollection<Sys_SystemConfig>();
            _collection_sys_news = _context.GetCollection<Sys_News>();
            _logger = logger;
        }

        /// <summary>
        /// 维修工单-状态
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        public object GetRepairState(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from repair in _collection_wo_repair_base.AsQueryable()
                        where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
                        select repair;
            if (!string.IsNullOrEmpty(projectid))
                query = query.Where(it => it.projectid == projectid);
            if (!string.IsNullOrEmpty(start))
                query = query.Where(it => it.createtime >= DateTime.Parse(start ));
            if (!string.IsNullOrEmpty(end))
                query = query.Where(it => it.createtime <= DateTime.Parse(end ));
            if (userinfo.isallproject == 0)
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
            //总数量
            int total = query.Count();

            //未完成
            int wwcnum = query.Where(x => x.wostate < (int)EnumWorkOrderState.deal || x.wostate == (int)EnumWorkOrderState.hangup).Count();
            //已完成
            int ywcnum = query.Where(x => x.wostate == (int)EnumWorkOrderState.deal).Count();
            //已评价
            int ypjnum = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate).Count();

            string wwcrate = "0", ywcrrate = "0", ypjrate = "0";
            if (total > 0)
            {
                wwcrate = Math.Round(((double)wwcnum * 100 / total), 2) + "";
                ywcrrate = Math.Round(((double)ywcnum * 100 / total), 2) + "";
                ypjrate = Math.Round(((double)ypjnum * 100 / total), 2) + "";
            }

            var obj = new
            {
                total,
                statenum = new { wwcnum, ywcnum, ypjnum },
                staterate = new { wwcrate, ywcrrate, ypjrate }
            };
            return obj;
        }

        /// <summary>
        /// 维修工单-来源
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        public object GetRepairSource(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from repair in _collection_wo_repair_base.AsQueryable()
                        where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
                        select repair;
            if (!string.IsNullOrEmpty(projectid))
                query = query.Where(it => it.projectid == projectid);
            if (!string.IsNullOrEmpty(start))
                query = query.Where(it => it.createtime >= DateTime.Parse(start ));
            if (!string.IsNullOrEmpty(end))
                query = query.Where(it => it.createtime <= DateTime.Parse(end ));
            if (userinfo.isallproject == 0)
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
            //总数量
            int total = query.Count();

            //电话来源数
            int pcnum = query.Where(x => x.channel == (int)EnumWorkOrderChannel.pc).Count();
            //微信来源数
            int wechatnum = query.Where(x => x.channel == (int)EnumWorkOrderChannel.wechat).Count();
            //APP来源数
            int appnum = query.Where(x => x.channel == (int)EnumWorkOrderChannel.ios || x.channel == (int)EnumWorkOrderChannel.android).Count();

            string pcrate = "0", wechatrate = "0", apprate = "0";
            if (total > 0)
            {
                //电话来源占比
                pcrate = Math.Round(((double)pcnum * 100 / total), 2) + "";
                //微信来源占比
                wechatrate = Math.Round(((double)wechatnum * 100 / total), 2) + "";
                //APP来源占比
                apprate = Math.Round(((double)appnum * 100 / total), 2) + "";
            }

            var obj = new
            {
                sourcenum = new { pcnum, wechatnum, appnum },
                sourcerate = new { pcrate, wechatrate, apprate }
            };
            return obj;
        }

        /// <summary>
        /// 维修工单-满意度
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        public object GetRepairScore(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from repair in _collection_wo_repair_base.AsQueryable()
                        where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
                        select repair;
            if (!string.IsNullOrEmpty(projectid))
                query = query.Where(it => it.projectid == projectid);
            if (!string.IsNullOrEmpty(start))
                query = query.Where(it => it.createtime >= DateTime.Parse(start ));
            if (!string.IsNullOrEmpty(end))
                query = query.Where(it => it.createtime <= DateTime.Parse(end ));
            if (userinfo.isallproject == 0)
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));

            //已评价
            int ypjnum = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate).Count();
            var pjquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate);

            //var wcpjnum = ywcnum + ypjnum;
            ////满意数量
            //int mynum = pjquery.Where(x => x.score >= 3).Count();
            ////不满意数量
            //int bmynum = pjquery.Where(x => x.score < 3).Count();

            //string wpjrate = "0", myrate = "0", bmyrate = "0";
            //if (wcpjnum > 0)
            //{
            //    //未评价占比
            //    wpjrate = Math.Round(((double)ywcnum * 100 / wcpjnum), 2) + "";
            //    //满意占比
            //    myrate = Math.Round(((double)mynum * 100 / wcpjnum), 2) + "";
            //    //不满意占比
            //    bmyrate = Math.Round(((double)bmynum * 100 / wcpjnum), 2) + "";
            //}

            int onestarnum = pjquery.Where(x => x.score == 1).Count();
            int twostarnum = pjquery.Where(x => x.score == 2).Count();
            int threestarnum = pjquery.Where(x => x.score == 3).Count();
            int fourstarnum = pjquery.Where(x => x.score == 4).Count();
            int fivestarnum = pjquery.Where(x => x.score == 5).Count();
            string onestarrate = "0", twostarrate = "0", threestarrate = "0", fourstarrate = "0", fivestarrate = "0", complexrate = "0";
            if (ypjnum > 0)
            {
                onestarrate = Math.Round(((double)onestarnum * 100 / ypjnum), 2) + "";
                twostarrate = Math.Round(((double)twostarnum * 100 / ypjnum), 2) + "";
                threestarrate = Math.Round(((double)threestarnum * 100 / ypjnum), 2) + "";
                fourstarrate = Math.Round(((double)fourstarnum * 100 / ypjnum), 2) + "";
                fivestarrate = Math.Round(((double)fivestarnum * 100 / ypjnum), 2) + "";

                //complexrate = Math.Round(((double)(onestarnum * 1 + twostarnum * 2 + threestarnum * 3 + fourstarnum * 4 + fivestarnum * 5) / (ypjnum * 5)), 2) + "";
                complexrate = Math.Round(((double)(pjquery.Sum(p => p.score)) * 100 / (ypjnum * 5)), 1) + "";
            }

            var obj = new
            {
                // wpjrate, myrate, bmyrate
                ypjnum,
                scorenum = new { onestarnum, twostarnum, threestarnum, fourstarnum, fivestarnum },
                scorerate = new { onestarrate, twostarrate, threestarrate, fourstarrate, fivestarrate },
                complexrate
            };
            return obj;
        }

        /// <summary>
        /// 维修工单-维修及时率
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        public object GetRepairTime(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from repair in _collection_wo_repair_base.AsQueryable()
                        where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
                        select repair;
            if (!string.IsNullOrEmpty(projectid))
                query = query.Where(it => it.projectid == projectid);
            if (!string.IsNullOrEmpty(start))
                query = query.Where(it => it.createtime >= DateTime.Parse(start ));
            if (!string.IsNullOrEmpty(end))
                query = query.Where(it => it.createtime <= DateTime.Parse(end ));
            if (userinfo.isallproject == 0)
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
            //已评价
            int ypjnum = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate).Count();

            var querylist = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate).ToList();
            //2小时内
            int twohournum = querylist.Where(x => (x.arrivetime.Value - x.repairtime.Value).Hours <= 2).Count();
            //4小时内
            int fourhournum = querylist.Where(x => (x.arrivetime.Value - x.repairtime.Value).Hours > 2 && (x.arrivetime.Value - x.repairtime.Value).Hours <= 4).Count();
            //8小时内
            int eighthournum = querylist.Where(x => (x.arrivetime.Value - x.repairtime.Value).Hours > 4 && (x.arrivetime.Value - x.repairtime.Value).Hours <= 8).Count();
            //24小时内
            int tfourhournum = querylist.Where(x => (x.arrivetime.Value - x.repairtime.Value).Hours > 8 && (x.arrivetime.Value - x.repairtime.Value).Hours <= 24).Count();
            //24小时以上
            int tfouruphournum = querylist.Where(x => (x.arrivetime.Value - x.repairtime.Value).Hours > 24).Count();

            string twohourrate = "0", fourhourrate = "0", eighthourrate = "0", tfourhourrate = "0", tfouruphourrate = "0";
            if (ypjnum > 0)
            {
                //2小时内占比
                twohourrate = Math.Round(((double)twohournum * 100 / ypjnum), 2) + "";
                //4小时内占比
                fourhourrate = Math.Round(((double)fourhournum * 100 / ypjnum), 2) + "";
                //8小时内占比
                eighthourrate = Math.Round(((double)eighthournum * 100 / ypjnum), 2) + "";
                //24小时内占比
                tfourhourrate = Math.Round(((double)tfourhournum * 100 / ypjnum), 2) + "";
                //24小时以上占比
                tfouruphourrate = Math.Round(((double)tfouruphournum * 100 / ypjnum), 2) + "";
            }

            var obj = new
            {
                ypjnum,
                timenum = new { twohournum, fourhournum, eighthournum, tfourhournum, tfouruphournum },
                timerate = new { twohourrate, fourhourrate, eighthourrate, tfourhourrate, tfouruphourrate }
            };
            return obj;
        }

        /// <summary>
        /// 维修工单-报修状态数量
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetRepairStateCount(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from repair in _collection_wo_repair_base.AsQueryable()
                        where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
                        select repair;
            if (!string.IsNullOrEmpty(projectid))
                query = query.Where(it => it.projectid == projectid);
            if (userinfo.isallproject == 0)
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));

            //var bxquery = query;
            //var cjquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.create);
            //var jdquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.assign);
            //var clquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.deal);
            //var pjquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate);
            //var gqquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.hangup);
            //if (!string.IsNullOrEmpty(start))
            //{
            //    bxquery = bxquery.Where(it => it.createtime >= DateTime.Parse(start ));
            //    cjquery = cjquery.Where(it => it.createtime >= DateTime.Parse(start));
            //    jdquery = jdquery.Where(it => it.totime >= DateTime.Parse(start ));
            //    clquery = clquery.Where(it => it.dealtime >= DateTime.Parse(start ));
            //    pjquery = pjquery.Where(it => it.evaluatetime >= DateTime.Parse(start ));
            //    gqquery = gqquery.Where(it => it.hanguptime >= DateTime.Parse(start ));
            //}
            //if (!string.IsNullOrEmpty(end))
            //{
            //    bxquery = bxquery.Where(it => it.createtime <= DateTime.Parse(end ));
            //    cjquery = cjquery.Where(it => it.createtime <= DateTime.Parse(end));
            //    jdquery = jdquery.Where(it => it.totime <= DateTime.Parse(end ));
            //    clquery = clquery.Where(it => it.dealtime <= DateTime.Parse(end ));
            //    pjquery = pjquery.Where(it => it.evaluatetime <= DateTime.Parse(end ));
            //    gqquery = gqquery.Where(it => it.hanguptime <= DateTime.Parse(end ));
            //}

            //var obj = new
            //{
            //    bxnum = bxquery.Count(),//报修
            //    cjnum = cjquery.Count(),//创建
            //    jdnum = jdquery.Count(),//接单
            //    clnum = clquery.Count(),//处理
            //    pjnum = pjquery.Count(),//评价
            //    gqnum = gqquery.Count()//挂起
            //};


            //未处理的按照创建时间，处理的按照处理时间，评价的按照评价时间
            var bxquery = query;
            var wclquery = query.Where(x => x.wostate < (int)EnumWorkOrderState.deal || x.wostate == (int)EnumWorkOrderState.hangup);
            var yclquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.deal || x.wostate == (int)EnumWorkOrderState.evaluate);
            var ypjquery = query.Where(x => x.wostate == (int)EnumWorkOrderState.evaluate);
            if (!string.IsNullOrEmpty(start))
            {
                bxquery = bxquery.Where(it => it.createtime >= DateTime.Parse(start));
                wclquery = wclquery.Where(it => it.createtime >= DateTime.Parse(start));
                yclquery = yclquery.Where(it => it.dealtime >= DateTime.Parse(start));
                ypjquery = ypjquery.Where(it => it.evaluatetime >= DateTime.Parse(start));
            }
            if (!string.IsNullOrEmpty(end))
            {
                bxquery = bxquery.Where(it => it.createtime <= DateTime.Parse(end));
                wclquery = wclquery.Where(it => it.createtime <= DateTime.Parse(end));
                yclquery = yclquery.Where(it => it.dealtime <= DateTime.Parse(end));
                ypjquery = ypjquery.Where(it => it.evaluatetime <= DateTime.Parse(end));
            }

            var obj = new
            {
                bxnum = bxquery.Count(),//报修
                wclnum = wclquery.Count(),//未处理
                yclnum = yclquery.Count(),//已处理
                ypjnum = ypjquery.Count()//已评价
            };
            return obj;
        }

        /// <summary>
        /// 维修工单-维修工满意度
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetUserRepairEval(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var repairlist = from repair in _collection_wo_repair_base.AsQueryable()
                             where repair.isdelete == 0 && (repair.wostate == (int)EnumWorkOrderState.evaluate || repair.wostate == (int)EnumWorkOrderState.deal)
                             select repair;

            var userlist = from p in _collection_sys_user_account.AsQueryable()
                           join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
                           where p.delete_flag == false
                           select new
                           {
                               p.head_img,
                               p.usercode,
                               p.username,
                               projectid = p.projectlist != null && p.projectlist.Count() > 0 ? p.projectlist.First() : null,
                               roleid = p.role_id,
                               rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
                               p.idcardno,
                               p.remark
                           };
            var wxlist = userlist.Where(p => p.rolecode == "YWYG");

            if (!string.IsNullOrEmpty(projectid))
            {
                repairlist = repairlist.Where(it => it.projectid.Equals(projectid));
                wxlist = wxlist.Where(it => it.projectid.Equals(projectid));
            }
            if (!string.IsNullOrEmpty(start))
            {
                repairlist = repairlist.Where(p => p.createtime >= DateTime.Parse(start ));
            }
            if (!string.IsNullOrEmpty(end))
            {
                repairlist = repairlist.Where(p => p.createtime <= DateTime.Parse(end ));
            }
            if (userinfo.isallproject == 0)
            {
                repairlist = repairlist.Where(it => userinfo.projectlist.Contains(it.projectid));
                wxlist = wxlist.Where(it => userinfo.projectlist.Contains(projectid));
            }

            var list = wxlist.ToList().Select(p =>
            {
                var userrepairs = repairlist.Where(q => q.dealuser.Contains(p.usercode));
                var total = userrepairs.Count();
                var hpnum = userrepairs.Where(u => u.wostate == (int)EnumWorkOrderState.evaluate && u.score >= 3).Count();
                var scores = userrepairs.Where(u => u.wostate == (int)EnumWorkOrderState.evaluate).Sum(u => u.score);
                double hprate = 0;
                double myrate = 0;
                if (total > 0)
                {
                    hprate = Math.Round(((double)hpnum * 100 / total), 2);
                    myrate = Math.Round(((double)scores * 100 / (total * 5)), 2);
                }
                return new
                {
                    p.head_img,
                    p.usercode,
                    p.username,
                    p.idcardno,
                    p.remark,
                    total,
                    hpnum,
                    hprate,
                    myrate
                };
            }).OrderByDescending(p => p.myrate);

            return list;
        }

        /// <summary>
        /// 维修工单-维修工接单量
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetUserAcceptCount(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var repairlist = from repair in _collection_wo_repair_base.AsQueryable()
                             where repair.isdelete == 0 && (repair.wostate >= (int)EnumWorkOrderState.assign && repair.wostate <= (int)EnumWorkOrderState.evaluate)
                             select repair;

            var userlist = from p in _collection_sys_user_account.AsQueryable()
                           join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
                           where p.delete_flag == false
                           select new
                           {
                               p.head_img,
                               p.usercode,
                               p.username,
                               projectid = p.projectlist != null && p.projectlist.Count() > 0 ? p.projectlist.First() : null,
                               roleid = p.role_id,
                               rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null,
                               p.idcardno,
                               p.remark
                           };
            var wxlist = userlist.Where(p => p.rolecode == "YWYG");

            if (!string.IsNullOrEmpty(projectid))
            {
                repairlist = repairlist.Where(it => it.projectid.Equals(projectid));
                wxlist = wxlist.Where(it => it.projectid.Equals(projectid));
            }
            if (!string.IsNullOrEmpty(start))
            {
                repairlist = repairlist.Where(p => p.createtime >= DateTime.Parse(start));
            }
            if (!string.IsNullOrEmpty(end))
            {
                repairlist = repairlist.Where(p => p.createtime <= DateTime.Parse(end));
            }
            if (userinfo.isallproject == 0)
            {
                repairlist = repairlist.Where(it => userinfo.projectlist.Contains(it.projectid));
                wxlist = wxlist.Where(it => userinfo.projectlist.Contains(projectid));
            }

            var list = wxlist.ToList().Select(p =>
            {
                var acceptcount = repairlist.Count(q => q.touser.Contains(p.usercode) || q.dealuser.Contains(p.usercode));

                return new
                {
                    p.head_img,
                    p.usercode,
                    p.username,
                    acceptcount
                };
            }).OrderByDescending(p => p.acceptcount);

            return list;
        }

        /// <summary>
        /// 维修工单-24小时报修统计
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object Get24HourRepairCount(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            //var query = from repair in _collection_wo_repair_base.AsQueryable()
            //            where repair.isdelete == 0 && repair.wostate != (int)EnumWorkOrderState.cancle
            //            select repair;
            //if (!string.IsNullOrEmpty(projectid))
            //    query = query.Where(it => it.projectid == projectid);
            //if (userinfo.isallproject == 0)
            //    query = query.Where(it => userinfo.projectlist.Contains(it.projectid));

            //var bxquery = query; var clquery = query.Where(it => it.dealtime != null);
            //if (!string.IsNullOrEmpty(start))
            //{
            //    bxquery = query.Where(it => it.createtime >= DateTime.Parse(start ));
            //    clquery = query.Where(it => it.dealtime >= DateTime.Parse(start ));
            //}
            //if (!string.IsNullOrEmpty(end))
            //{
            //    bxquery = query.Where(it => it.createtime <= DateTime.Parse(end ));
            //    clquery = query.Where(it => it.dealtime <= DateTime.Parse(end ));
            //}

            string bxwhere = "{isdelete:0},{wostate:{$ne:" + (int)EnumWorkOrderState.cancle + "}}";
            string clwhere = "{isdelete:0},{wostate:{$ne:" + (int)EnumWorkOrderState.cancle + "}},{dealtime:{$ne:null}}";
            if (!string.IsNullOrEmpty(start))
            {
                bxwhere = bxwhere + ",{createtime:{$gte:new Date('" + start + "')}}";
                clwhere = clwhere + ",{dealtime:{$gte:new Date('" + start + "')}}";
            }
            if (!string.IsNullOrEmpty(end))
            {
                bxwhere = bxwhere + ",{createtime:{$lte:new Date('" + end + "')}}";
                clwhere = clwhere + ",{dealtime:{$lte:new Date('" + end + "')}}";
            }

            var bxstages = new List<IPipelineStageDefinition>();
            bxstages.Add(new JsonPipelineStageDefinition<Wo_Repair_Base, BsonDocument>("{$match:{$and:["+ bxwhere + "]}}"));
            bxstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {$hour: {$add:[\"$createtime\",28800000]} }, count: {$sum: 1}}}"));
            var bxpipeline = new PipelineStagePipelineDefinition<Wo_Repair_Base, BsonDocument>(bxstages);
            var bxresult = _collection_wo_repair_base.Aggregate(bxpipeline).ToList();
            var clstages = new List<IPipelineStageDefinition>();
            clstages.Add(new JsonPipelineStageDefinition<Wo_Repair_Base, BsonDocument>("{$match:{$and:[" + clwhere + "]}}"));
            clstages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{$group:{_id: {$hour: {$add:[\"$dealtime\",28800000]} }, count: {$sum: 1}}}"));
            var clpipeline = new PipelineStagePipelineDefinition<Wo_Repair_Base, BsonDocument>(clstages);
            var clresult = _collection_wo_repair_base.Aggregate(clpipeline).ToList();


            int[] hours = Enumerable.Range(0, 24).ToArray<int>();
            int[] bxcounts = new int[24];//报修数量
            int[] clcounts = new int[24];//处理数量

            for (int i = 0; i < hours.Length; i++)
            {
                bxcounts[i] = 0;
                clcounts[i] = 0;

                var bx = bxresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
                if (bx != null)
                {
                    bxcounts[i]= Int32.Parse(bx.Values.ToArray()[1].ToString());
                }

                var cl = clresult.Where(p => p.Values.ToArray()[0].ToString() == i.ToString()).FirstOrDefault();
                if (cl != null)
                {
                    clcounts[i] = Int32.Parse(cl.Values.ToArray()[1].ToString());
                }
            }
            
            var obj = new
            {
                hours,
                bxcounts,
                clcounts
            };

            return obj;
        }

        /// <summary>
        /// 维修工单-工单未完成
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="top"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetNoDealList(string projectid, int top, UserAccountInfoModel userinfo)
        {
            var query = from p in _collection_wo_repair_base.AsQueryable()
                        where p.isdelete == 0 && (p.wostate < (int)EnumWorkOrderState.deal || p.wostate == (int)EnumWorkOrderState.hangup)
                        select p;

            var querys = from p in _collection_wo_repair_base.AsQueryable()
                        where p.isdelete == 0 && (p.wostate == (int)EnumWorkOrderState.deal || p.wostate == (int)EnumWorkOrderState.evaluate)
                        select p;

            if (!string.IsNullOrEmpty(projectid))
            {
                query = query.Where(it => it.projectid.Equals(projectid));
                querys = querys.Where(it => it.projectid.Equals(projectid));
            }
            if (userinfo.isallproject == 0)
            {
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
                querys = querys.Where(it => userinfo.projectlist.Contains(it.projectid));
            }

            var list = query.Select(p => new
            {
                p.wocode,
                p.wostate,
                p.createuser,
                p.createusername,
                p.repairman,
                p.contactway,
                p.repairreplace,
                p.faultdescripe,
                p.repairtime,
                p.totype,
                p.touser,
                p.tousername,
                p.totime,
                p.dealtime
            }).OrderByDescending(p => p.repairtime).ToList();

            if (list.Count < top)
            {
                var lists = querys.Select(p => new
                {
                    p.wocode,
                    p.wostate,
                    p.createuser,
                    p.createusername,
                    p.repairman,
                    p.contactway,
                    p.repairreplace,
                    p.faultdescripe,
                    p.repairtime,
                    p.totype,
                    p.touser,
                    p.tousername,
                    p.totime,
                    p.dealtime
                }).OrderByDescending(p => p.repairtime).Take(top - list.Count).ToList();

                list = list.Concat(lists).ToList();
            }

            var list_new = list.Select(p =>
            {
                var repairtimelong = "-";
                if (!string.IsNullOrEmpty(p.totime.ToString()) && !string.IsNullOrEmpty(p.dealtime.ToString()))
                {
                    DateTime beginTime1 = DateTime.Parse(p.totime.ToString());
                    DateTime endTime1 = DateTime.Parse(p.dealtime.ToString());
                    TimeSpan midTime = endTime1 - beginTime1;
                    repairtimelong = $"{midTime.Days}天{midTime.Hours}小时{midTime.Minutes}分";
                }
                return new
                {
                    p.wocode,
                    p.wostate,
                    p.createuser,
                    p.createusername,
                    p.repairman,
                    p.contactway,
                    p.repairreplace,
                    p.faultdescripe,
                    p.repairtime,
                    p.totype,
                    p.touser,
                    p.tousername,
                    p.totime,
                    p.dealtime,
                    repairtimelong = repairtimelong    //报修时长
                };
            });

            return list_new;
        }

        /// <summary>
        /// 项目-到期项目
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetProjectTimeOut(string projectid, UserAccountInfoModel userinfo)
        {
            var listApp = new List<FilterDefinition<Pro_Project_Info>>();
            listApp.Add(Builders<Pro_Project_Info>.Filter.Eq("isdelete", 0));

            //var dadays = (from p in _collection_sys_systemconfig.AsQueryable() where p.isdelete == false && p.paramcode == "XMDQTXDAYS" select p).FirstOrDefault();
            //if (dadays != null)
            //{
            //    int days = Int32.Parse(dadays.paramvalue);
            //    var dqdate = DateTime.Now.AddDays(days).ToString("yyyy-MM-dd");
            //    listApp.Add(Builders<Pro_Project_Info>.Filter.Lte("project_endtime", dqdate));
            //}
            if (userinfo.isallproject == 0)
                listApp.Add(Builders<Pro_Project_Info>.Filter.Where(s => userinfo.projectlist.Contains(s.id)));

            var filter = Builders<Pro_Project_Info>.Filter.And(listApp);

            var lists = _collection.Find(filter).ToList();
            var list = lists.Select(p =>
            {
                var date = DateTime.Parse(p.project_endtime);
                TimeSpan ts = date - DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                int day = int.Parse(ts.TotalDays.ToString());

                return new
                {
                    p.id,
                    name = p.project_name,
                    day
                };
            }).OrderBy(p => p.day);

            return list;
        }

        /// <summary>
        /// 项目-项目状态数量
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetProjectStateCount(string projectid, UserAccountInfoModel userinfo)
        {
            var listApp = new List<FilterDefinition<Pro_Project_Info>>();
            listApp.Add(Builders<Pro_Project_Info>.Filter.Eq("isdelete", 0));
            if (userinfo.isallproject == 0)
                listApp.Add(Builders<Pro_Project_Info>.Filter.Where(s => userinfo.projectlist.Contains(s.id)));
            //总数量
            int total = _collection.Find(Builders<Pro_Project_Info>.Filter.And(listApp)).ToList().Count();
            //过期数量
            var overduelistApp = new List<FilterDefinition<Pro_Project_Info>>();
            overduelistApp.AddRange(listApp);
            overduelistApp.Add(Builders<Pro_Project_Info>.Filter.Lt("project_endtime", DateTime.Now.ToString("yyyy-MM-dd")));
            int overduenum = _collection.Find(Builders<Pro_Project_Info>.Filter.And(overduelistApp)).ToList().Count();
            //提醒数量
            var remindlistApp = new List<FilterDefinition<Pro_Project_Info>>();
            remindlistApp.AddRange(listApp);
            int remindnum = 0;
            //正常数量
            var normallistApp = new List<FilterDefinition<Pro_Project_Info>>();
            normallistApp.AddRange(listApp);
            int normalnum = 0;

            int days = 0;
            var dadays = (from p in _collection_sys_systemconfig.AsQueryable() where p.isdelete == false && p.paramcode == "XMDQTXDAYS" select p).FirstOrDefault();
            if (dadays != null)
            {
                days = Int32.Parse(dadays.paramvalue);
                var dqdate = DateTime.Now.AddDays(days).ToString("yyyy-MM-dd");
                remindlistApp.Add(Builders<Pro_Project_Info>.Filter.Lte("project_endtime", dqdate));
                remindnum = _collection.Find(Builders<Pro_Project_Info>.Filter.And(remindlistApp)).ToList().Count();

                var normallistAppor = new List<FilterDefinition<Pro_Project_Info>>();
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Gt("project_endtime", dqdate));
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Eq("project_endtime", ""));
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Eq(p => p.project_endtime, null));
                normallistApp.Add(Builders<Pro_Project_Info>.Filter.Or(normallistAppor));
                normalnum = _collection.Find(Builders<Pro_Project_Info>.Filter.And(normallistApp)).ToList().Count();
            }
            else
            {
                var normallistAppor = new List<FilterDefinition<Pro_Project_Info>>();
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Gt("project_endtime", DateTime.Now.ToString("yyyy-MM-dd")));
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Eq("project_endtime", ""));
                normallistAppor.Add(Builders<Pro_Project_Info>.Filter.Eq(p => p.project_endtime, null));
                normallistApp.Add(Builders<Pro_Project_Info>.Filter.Or(normallistAppor));

                normalnum = _collection.Find(Builders<Pro_Project_Info>.Filter.And(normallistApp)).ToList().Count();
            }

            var obj = new
            {
                days,
                total,
                overduenum,
                remindnum,
                normalnum
            };
            return obj;
        }

        /// <summary>
        /// 项目-已维修工单
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetProjectRepair(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var query = from p in _collection.AsQueryable()
                        where p.isdelete == 0
                        select p;
            var repair = from p in _collection_wo_repair_base.AsQueryable()
                         where p.isdelete == 0 && p.wostate != (int)EnumWorkOrderState.cancle
                         select p;
            var userlist = from p in _collection_sys_user_account.AsQueryable()
                           join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
                           where p.delete_flag == false
                           select new
                           {
                               p.head_img,
                               p.usercode,
                               p.username,
                               projectid = p.projectlist != null && p.projectlist.Count() > 0 ? p.projectlist.First() : null,
                               roleid = p.role_id,
                               rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null
                           };
            var wxlist = userlist.Where(p => p.rolecode == "YWYG");

            if (!string.IsNullOrEmpty(projectid))
            {
                query = query.Where(it => it.id == projectid);
                repair = repair.Where(it => it.projectid == projectid);
                wxlist = wxlist.Where(it => it.projectid.Equals(projectid));
            }
            if (!string.IsNullOrEmpty(start))
            {
                query = query.Where(it => it.createtime >= DateTime.Parse(start));
                repair = repair.Where(it => it.createtime >= DateTime.Parse(start ));
            }
            if (!string.IsNullOrEmpty(end))
            {
                query = query.Where(it => it.createtime <= DateTime.Parse(end ));
                repair = repair.Where(it => it.createtime <= DateTime.Parse(end ));
            }
            if (userinfo.isallproject == 0)
            {
                query = query.Where(it => userinfo.projectlist.Contains(it.id));
                repair = repair.Where(it => userinfo.projectlist.Contains(it.projectid));
                wxlist = wxlist.Where(it => userinfo.projectlist.Contains(projectid));
            }

            var list = query.ToList().Select(p =>
            {
                int repairnum = repair.Where(r => r.projectid == p.id).Count();
                int repairusernum = wxlist.Where(r => r.projectid == p.id).Count();
                return new
                {
                    p.id,
                    name=p.project_name,
                    repairnum,
                    repairusernum
                };
            });
            return list;
        }

        /// <summary>
        /// 项目-项目信息列表
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetProjectList(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            string where = "{isdelete:0}";
            if (!string.IsNullOrEmpty(projectid))
                where = where + ",{_id:ObjectId('" + projectid + "')}";
            if (!string.IsNullOrEmpty(start))
                where = where + ",{project_starttime:{$gte:'" + start.Substring(0,10) + "'}}";
            if (!string.IsNullOrEmpty(end))
                where = where + ",{project_starttime:{$lte:'" + end.Substring(0, 10) + "'}}";
            if (userinfo.isallproject == 0)
            {
                string pros = string.Empty;
                foreach (string pro in userinfo.projectlist)
                {
                    if (string.IsNullOrEmpty(pros))
                    {
                        pros = "ObjectId('" + pro + "')";
                    }
                    else
                    {
                        pros = pros + ",ObjectId('" + pro + "')";
                    }
                }

                where = where + ",{_id:{$in:[" + pros + "]}}";
            }

            var stages = new List<IPipelineStageDefinition>();
            stages.Add(new JsonPipelineStageDefinition<Pro_Project_Info, BsonDocument>("{$match:{$and:[" + where + "]}}"));
            stages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{ \"$lookup\" : { from : \"sys_provinces\", localField : \"project_province\", foreignField : \"provincecode\", as : \"provinceinfo\" } }"));
            stages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{ \"$lookup\" : { from : \"sys_city\", localField : \"project_city\", foreignField : \"citycode\", as : \"cityinfo\" } }"));
            stages.Add(new JsonPipelineStageDefinition<BsonDocument, BsonDocument>("{ \"$project\" : { id : \"$_id\",name : \"$project_name\",startdate : \"$project_starttime\",enddate : \"$project_endtime\","
                + "provincename : { \"$cond\" : [{ \"$and\" : [{ \"$ne\" : [\"provinceinfo\", null] }, { \"$gt\" : [{ \"$size\" : \"$provinceinfo\" }, 0] }] }, { \"$arrayElemAt\" : [\"$provinceinfo.provincename\", 0] }, null] },"
                + "cityname : { \"$cond\" : [{ \"$and\" : [{ \"$ne\" : [\"cityinfo\", null] }, { \"$gt\" : [{ \"$size\" : \"$cityinfo\" }, 0] }] }, { \"$arrayElemAt\" : [\"$cityinfo.cityname\", 0] }, null] } } }"));
            var pipeline = new PipelineStagePipelineDefinition<Pro_Project_Info, BsonDocument>(stages);
            var result = _collection.Aggregate(pipeline).ToList();

            var equlist = from p in _collection_eqp_equipment_info.AsQueryable() where p.isdelete == 0 select p;
            var userlist = from p in _collection_sys_user_account.AsQueryable()
                           join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
                           where p.delete_flag == false
                           select new
                           {
                               p.head_img,
                               p.usercode,
                               p.username,
                               projectid = p.projectlist != null && p.projectlist.Count() > 0 ? p.projectlist.First() : null,
                               roleid = p.role_id,
                               rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null
                           };
            var wxlist = userlist.Where(p => p.rolecode == "YWYG");

            var list = result.Select(pro =>
            {
                var rts = pro.Values.ToArray();
                string remainderday = "";
                if (!rts[4].IsBsonNull && rts[4].ToString() != "")
                {
                    remainderday = (DateTime.Parse(rts[4].ToString()) - DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"))).TotalDays.ToString();
                }
                return new
                {
                    id = rts[1].ToString(),
                    name = rts[2].ToString(),
                    provincename = rts[5].ToString(),
                    cityname = rts[6].ToString(),
                    repairusernum = wxlist.Where(p => p.projectid == rts[0].ToString()).Count(),
                    equipmentnum = equlist.Where(p => p.projectid == rts[0].ToString()).Count(),
                    remainderday
                };
            });
            return list;
        }

        /// <summary>
        /// 项目-项目数量、维修人员、设备数量
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetProjectRepairUserEquipment(string projectid, UserAccountInfoModel userinfo)
        {
            var query = from p in _collection.AsQueryable() where p.isdelete == 0 select p;
            var equipment= from p in _collection_eqp_equipment_info.AsQueryable() where p.isdelete == 0 select p;
            var userlist = from p in _collection_sys_user_account.AsQueryable()
                           join r in _collection_role_info.AsQueryable() on p.role_id equals r.id into roleinfo
                           where p.delete_flag == false
                           select new
                           {
                               p.head_img,
                               p.usercode,
                               p.username,
                               projectid = p.projectlist != null && p.projectlist.Count() > 0 ? p.projectlist.First() : null,
                               roleid = p.role_id,
                               rolecode = roleinfo != null && roleinfo.Count() > 0 ? roleinfo.First().role_code : null
                           };
            var wxlist = userlist.Where(p => p.rolecode == "YWYG");

            if (!string.IsNullOrEmpty(projectid))
            {
                query = query.Where(it => it.id == projectid);
                wxlist = wxlist.Where(it => it.projectid.Equals(projectid));
                equipment= equipment.Where(it => it.projectid.Equals(projectid));
            }
            if (userinfo.isallproject == 0)
            {
                query = query.Where(it => userinfo.projectlist.Contains(it.id));
                wxlist = wxlist.Where(it => userinfo.projectlist.Contains(projectid));
                equipment = equipment.Where(it => userinfo.projectlist.Contains(projectid));
            }

            var obj = new
            {
                projectnum = query.Count(),
                repairusernum= wxlist.Count(),
                equipmentnum= equipment.Count()
            };
            return obj;
        }

        /// <summary>
        /// 项目-新闻列表
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetNewsList(string projectid, string rolecode, UserAccountInfoModel userinfo)
        {
            DateTime dtnow = DateTime.Now;
            var query = from p in _collection_sys_news.AsQueryable()
                        join pro in _collection.AsQueryable() on p.projectid equals pro.id into proinfo
                        join tp in _collection_sys_dictionaryvalue.AsQueryable() on p.typeid equals tp.id into typeinfo
                        where p.isdelete == 0 && p.state == 0 && (p.endtime == null || p.endtime >= dtnow)  //判断有效期
                        select new {
                            p.id,
                            p.projectid,
                            projectname= proinfo.Count() > 0 ? proinfo.First().project_name : "",
                            p.typeid,
                            typename= typeinfo.Count()>0? typeinfo.First().name:"",
                            p.title,
                            p.content,
                            p.level,
                            p.sort,
                            p.publishtype,
                            p.timingtime,
                            p.endtime,
                            p.rolecode,
                            p.createtime
                        };
            if (!string.IsNullOrEmpty(projectid))
            {
                query = query.Where(it => it.projectid == projectid);
            }
            if (userinfo.isallproject == 0)
            {
                if (!string.IsNullOrEmpty(rolecode))
                    query = query.Where(it => it.rolecode.Contains(rolecode) || it.rolecode == null || it.rolecode == "");
                query = query.Where(it => userinfo.projectlist.Contains(it.projectid));
            }
            return query.OrderBy(p=>p.level).ThenBy(p => p.sort);
        }

        /// <summary>
        /// 巡检统计
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetRunningList(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var queryrunning = from running in _collection_equipmentrunning.AsQueryable() where running.isdelete == 0 select running;
            if (!string.IsNullOrEmpty(projectid))
            {
                queryrunning = queryrunning.Where(p => p.projectid == projectid);
            }
            if (!string.IsNullOrEmpty(start))
            {
                var starttime = DateTime.Parse(start);
                queryrunning = queryrunning.Where(p => p.createtime >= starttime);
            }
            if (!string.IsNullOrEmpty(end))
            {
                var endtime = DateTime.Parse(end);
                queryrunning = queryrunning.Where(p => p.createtime <= endtime);
            }
            if (userinfo.isallproject == 0)
            {
                queryrunning = queryrunning.Where(it => userinfo.projectlist.Contains(it.projectid));
            }
            var runninglist = queryrunning.ToList();
            //设备巡检统计 工单总量/已巡检/未巡检/异常
            int rcount = runninglist.Count();
            int rycount = runninglist.Where(x => x.wostate == (int)EnumEquipmentRunningState.deal).Count();
            int rwcount = rcount - rycount;
            int ryycount = runninglist.Where(x => x.wostate >= (int)EnumEquipmentRunningState.deal && x.quipmenttype == (int)EnumWoREquipmentState.abnormal).Count();
            return new
            {
                rcount,
                rycount,
                rwcount,
                ryycount 
            };
        }

        /// <summary>
        /// 保养统计
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetMaintainList(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var querymaintain = from maintain in _collection_wo_maintain_base.AsQueryable() where maintain.isdelete == false select maintain;
            if (!string.IsNullOrEmpty(projectid))
            {
                querymaintain = querymaintain.Where(p => p.projectid == projectid);
            }
            if (!string.IsNullOrEmpty(start))
            {
                var starttime = DateTime.Parse(start);
                querymaintain = querymaintain.Where(p => p.createtime >= starttime);
            }
            if (!string.IsNullOrEmpty(end))
            {
                var endtime = DateTime.Parse(end);
                querymaintain = querymaintain.Where(p => p.createtime <= endtime);
            }
            if (userinfo.isallproject == 0)
            {
                querymaintain = querymaintain.Where(it => userinfo.projectlist.Contains(it.projectid));
            }
            var maintainlist = querymaintain.ToList();
            //设备巡检统计 工单总量/已巡检/未巡检/异常
            int mcount = maintainlist.Count();
            int mycount = maintainlist.Where(x => x.wostate == (int)EnumWoMaintainState.deal).Count();
            int mwcount = mcount - mycount;
            int myycount = maintainlist.Where(x => x.wostate >= (int)EnumWoMaintainState.deal && x.equipstate == (int)EnumWoMEquipmentState.abnormal).Count();
            return new
            {
                mcount,
                mycount,
                mwcount,
                myycount
            };
        }

        /// <summary>
        /// 维保事项
        /// </summary>
        /// <param name="projectid"></param>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public object GetMaintainMatter(string projectid, string start, string end, UserAccountInfoModel userinfo)
        {
            var querymaintain = from maintain in _collection_wo_maintain_base.AsQueryable()
                                where maintain.isdelete == false
                                select new {
                                    maintain.wocode,
                                    maintain.woname,
                                    maintain.maintaincontent,
                                    maintain.wostate,
                                    maintain.starttime,
                                    maintain.endtime,
                                    maintain.projectid,
                                };
            //querymaintain = querymaintain.Where(x => x.wostate != (int)EnumWoMaintainState.deal);
            if (!string.IsNullOrEmpty(start))
            {
                var starttime = DateTime.Parse(start);
                querymaintain = querymaintain.Where(p => p.starttime >= starttime);
            }
            if (!string.IsNullOrEmpty(end))
            {
                var endtime = DateTime.Parse(end);
                querymaintain = querymaintain.Where(p => p.starttime <= endtime);
            }
            if(!string.IsNullOrEmpty(projectid))
            {
                querymaintain = querymaintain.Where(p => p.projectid.Equals(projectid));
            }
            querymaintain = querymaintain.OrderBy(x => x.starttime);
            var list= querymaintain.Take(20);
            var reslist = new List<object>();
            foreach (var item in list)
            {
                string res = item.starttime.ToString("MM.dd日") + "开始" + item.woname + "检查";
                var obj = new
                {
                    content = res,
                    state = item.wostate,
                };
                reslist.Add(obj);
            }
            return reslist;
        }
    }
}