Пример #1
1
        public IList<ESiteMessage> GetSiteMessages(int top, int userId, bool isRead = false)
        {
            Spec<ESiteMessage> sp = new Spec<ESiteMessage>();
            sp.And(p => p.IsRead == isRead);
            var userIds = _rep.GetList<EUser>(0, p => p.ParentUserId == userId, p => new Columns(p.Id))
                .Select(p => p.Id)
                .ToList();
            userIds.Add(userId);

            sp.And(p => p.ReceiveUserId.In(string.Join(",", userIds)));

            return _rep.GetList<ESiteMessage>(top, sp, p => new Columns(p.Id.Desc()));

        }
Пример #2
1
        public IPageList<ESiteMessage> SearchSiteMessages(int? userId, bool? isRead, string searchKeyword, string searchType, DateTime? startTime, DateTime? endTime, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<ESiteMessage> sp = new Spec<ESiteMessage>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.Title.Like(searchKeyword)).Or(p => p.Content.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (isRead.HasValue)
            {
                sp.And(p => p.IsRead == isRead);
            }

            if (userId.HasValue)
            {
                var userIds = _rep.GetList<EUser>(0, p => p.ParentUserId == userId, p => new Columns(p.Id))
                    .Select(p => p.Id)
                    .ToList();
                userIds.Add(userId.Value);

                sp.And(p => p.ReceiveUserId.In(string.Join(",", userIds)));
            }

            if (startTime.HasValue) sp.And(p => p.CreateTime >= startTime);
            if (endTime.HasValue) sp.And(p => p.CreateTime <= endTime);

            var cp = new CSpec<ESiteMessage>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<ESiteMessage>(pageIndex, pageSize, sp, cp);
        }
Пример #3
1
 public void AddingADelegateStepThrowsAnException()
 {
     var spec = new Spec("");
     try
     {
         //can't use Assert.Throws here as that would introduce an extra lambda
         spec.And(() => Foo("x"));
     }
     catch (ArgumentException e)
     {
         return; //pass
     }
     throw new Exception("Expected method to throw exception");
 }
Пример #4
1
        /// <summary>
        /// ËÑË÷
        /// </summary>
        /// <returns></returns>
        public IPageList<EGuestbook> SearchGuestbooks(int? userId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EGuestbook> sp = new Spec<EGuestbook>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.NickName.Like(searchKeyword))
                        //.Or(p => p.Phone.Like(searchKeyword))
                        //.Or(p => p.Email.Like(searchKeyword))
                        //.Or(p => p.Fax.Like(searchKeyword))
                        //.Or(p => p.Mobile.Like(searchKeyword))
                        //.Or(p => p.Phone.Like(searchKeyword))
                        //.Or(p => p.ReplyContent.Like(searchKeyword))
                        //.Or(p => p.ReplyUserName.Like(searchKeyword))
                        .Or(p => p.Content.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (userId.HasValue)
            {
                sp.And(p => p.UserId == userId);
            }

            var cp = new CSpec<EGuestbook>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EGuestbook>(pageIndex, pageSize, sp, cp);
        }
Пример #5
1
        public IPageList<EMileageReportDay> SearchMileageReportDays(int deviceId, DateTime st, DateTime et, string orderName, string orderType, int pageIndex, int pageSize)
        {

            if (et > DateTime.Now)
            {
                et = DateTime.Now;
            }

            //生成查询时间段
            var day = (et - st).TotalDays;
            var dts = new List<DateTime>();
            for (var i = 0; i <= day; i++)
            {
                dts.Add(st.AddDays(i).GetDayStartTime());
            }

            var sp = new Spec<EMileageReportDay>();
            sp.And(p => p.DeviceId == deviceId && p.ReportDay >= st.GetDayStartTime() && p.ReportDay <= et.GetDayStartTime());

            //获取已经生成的数据
            var haveddks =
                _rep.GetList<EMileageReportDay>(0, sp,
                    p => new Columns(p.ReportDay)).Select(p => p.ReportDay.GetDayStartTime()).ToList();

            foreach (var ddk in dts)
            {
                if (!haveddks.Contains(ddk))
                {
                    //发现当前日期的数据没有生成 那么开始生成
                    CreateMileageReportDayByReportDay(deviceId, ddk);
                }
            }

            var cp = new CSpec<EMileageReportDay>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }
            return _rep.GetPageList<EMileageReportDay>(pageIndex, pageSize, sp, cp);
        }
Пример #6
1
        /// <summary>
        /// 搜索内容分组内容
        /// </summary>
        /// <returns></returns>
        public IPageList<EContentsGroupContents> SearchContentsGroupContents(int? contentsGroupId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EContentsGroupContents, EContents, ENode> sp = new Spec<EContentsGroupContents, EContents, ENode>();

            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And((cgc, c, n) => c.Title.Like(searchKeyword));
                }
                else
                {
                    sp.And((cgc, c, n) => c.Column(searchType).Like(searchKeyword));
                }
            }

            if (contentsGroupId.HasValue)
            {
                sp.And(p => p.ContentsGroupId == contentsGroupId);
            }

            CSpec<EContentsGroupContents> cp = new CSpec<EContentsGroupContents>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            var query = DMContext.Query<EContentsGroupContents, EContents, ENode, EContentsGroupContents>()
                .LeftJoin<EContents>((cgc, c) => cgc.ContentsId == c.Id)
                .LeftJoin<EContents, ENode>((c, n) => c.NodeId == n.Id)
                .Select((cgc, c, n) => new Columns(cgc, c.Title, c.DefaultImageUrl, c.NodeId, c.CreateTime, c.LastUpdateTime, c.ContentStatus, n.NodeName))
                .Where(sp)
                .OrderBy(cp);

            return query.ToPageList(pageIndex, pageSize);
        }
Пример #7
1
        /// <summary>
        /// 根据车辆编号 时间 获取 当前故障码
        /// </summary>
        /// <param name="vehicleCode"></param>
        /// <returns></returns>
        public List<EOBDFaultreport> GeOBDFaultreports(string vehicleCodes, DateTime? st, DateTime? et)
        {

            Spec<EOBDFaultreport> sp = new Spec<EOBDFaultreport>();
            sp.And(p => p.VehicleCode.In(vehicleCodes));

            if (st.HasValue)
            {
                sp.And(p => p.ReportTime > st.Value.GetDayStartTime());
            }
            if (et.HasValue)
            {
                sp.And(p => p.ReportTime < et.Value.GetDayEndTime());
            }

            var query = DMContext.Query<EOBDFaultreport, EVehicle, EOBDFault, EOBDFaultreport>()
                .InnerJoin<EOBDFault>((fr, f) => fr.FaultType == f.FaultType)
                .InnerJoin<EVehicle>((fr, f) => fr.VehicleCode == f.VehicleCode.ToString())
                .Where(sp.Exp);

            return query.ToList();
        }
Пример #8
1
 public void SetSiteMessagesByUserId(int userId, bool isRead = true)
 {
     Spec<ESiteMessage> sp = new Spec<ESiteMessage>();
     var userIds = _rep.GetList<EUser>(0, p => p.ParentUserId == userId, p => new Columns(p.Id)).Select(p => p.Id).ToList();
     userIds.Add(userId);
     sp.And(p => p.ReceiveUserId.In(string.Join(",", userIds)));
     _rep.Save(new ESiteMessage() { IsRead = isRead }, sp, p => new Columns(p.IsRead));
 }
Пример #9
0
        public bool CheckIsLast(int noteid)
        {
            bool bRet = false;

            using (var repo = DMRepository.Get())
            {
                DeliveryNote note = repo.Get <DeliveryNote>(p => p.noteid == noteid);
                if (note != null)
                {
                    Spec <CustomerEntity> where = new Spec <CustomerEntity>();
                    where.And(p => p.customer == note.customer);
                    where.And(p => p.cyear == note.sdate.Year);
                    CustomerEntity customer = repo.Get <CustomerEntity>(where.Exp);
                    if (customer != null)
                    {
                        if (customer.sequence == note.deliverid)
                        {
                            bRet = true;
                        }
                    }
                }
            }


            return(bRet);
        }
Пример #10
0
        public SysDictEntity Select(string dictype, string dictvalue)
        {
            Spec <SysDictEntity> where = new Spec <SysDictEntity>();
            where.And(p => p.dictype == dictype);
            where.And(p => p.dictvalue == dictvalue);

            return(base.DMSelect(where.Exp));
        }
Пример #11
0
        public String Delete(int noteid, bool isdecrease)
        {
            String         bErr     = "";
            CustomerEntity customer = null;

            if (isdecrease)
            {
                using (var repo = DMRepository.Get())
                {
                    DeliveryNote note = repo.Get <DeliveryNote>(p => p.noteid == noteid);
                    if (note == null)
                    {
                        return("当前送货单不存在");
                    }

                    Spec <CustomerEntity> where = new Spec <CustomerEntity>();
                    where.And(p => p.customer == note.customer);
                    if (note.sdate.Year <= 1)
                    {
                        where.And(p => p.cyear == DateTime.Now.Year);
                    }
                    else
                    {
                        where.And(p => p.cyear == note.sdate.Year);
                    }
                    customer = repo.Get <CustomerEntity>(where.Exp);
                    if (customer == null)
                    {
                        return("系统中没有此客户信息");
                    }

                    if (customer.sequence != note.deliverid)
                    {
                        return("当前送货单已归档,不能删除");
                    }
                    customer.sequence = customer.sequence - 1;
                }
            }

            using (var dmt = DMContext.GetTransaction())
            {
                var trans = dmt.BeginTransaction();
                if (customer != null & isdecrease)
                {
                    DMContext.Update <CustomerEntity>(customer, p => p.cid == customer.cid, null, trans);
                }

                DMContext.Delete <DeliveryItem>(p => p.noteid == noteid, trans);
                DMContext.Delete <DeliveryNote>(p => p.noteid == noteid, trans);
                trans.Commit();
            }

            return(bErr);
        }
Пример #12
0
 public User Select(string loginId, int userId)
 {
     if (userId == 0)
     {
         return(base.DMSelect(p => p.loginid == loginId));
     }
     else
     {
         Spec <User> where = new Spec <User>();
         where.And(p => p.loginid == loginId);
         where.And(p => p.userid != userId);
         return(base.DMSelect(where.Exp));
     }
 }
Пример #13
0
        public void And()
        {
            // Arrange
            Drink coldWhiskey = Drink.ColdWhiskey();
            Drink appleJuice  = Drink.AppleJuice();
            ISpecification <Drink> whiskeySpec = new Spec <Drink>(d => d.Name.ToLower() == "whiskey");
            ISpecification <Drink> coldSpec    = new Spec <Drink>(d => d.With.Any(a => a.ToLower() == "ice"));

            // Act
            var coldWhiskeySpec = whiskeySpec.And(coldSpec);

            // Assert
            coldWhiskeySpec.IsSatisfiedBy(coldWhiskey).Should().BeTrue();
            coldWhiskeySpec.IsSatisfiedBy(appleJuice).Should().BeFalse();
        }
Пример #14
0
        public void AddingADelegateStepThrowsAnException()
        {
            var spec = new Spec("");

            try
            {
                //can't use Assert.Throws here as that would introduce an extra lambda
                spec.And(() => Foo("x"));
            }
            catch (ArgumentException e)
            {
                return; //pass
            }
            throw new Exception("Expected method to throw exception");
        }
Пример #15
0
        public void HardwareAndRaspberryPi()
        {
            // Arrange
            var rpi         = OrderItem.RaspberryPi3ModelB();
            var orangePiOne = OrderItem.OrangePiOne();
            ISpecification <OrderItem> hwSpec  = new Spec <OrderItem>(x => x.Type == OrderItem.OrderItemType.Hardware);
            ISpecification <OrderItem> rpiSpec = new Spec <OrderItem>(x => x.Name.ToLower().Contains("raspberry"));

            // Act
            var hwAndRpiSpec = hwSpec.And(rpiSpec);

            // Assert
            hwAndRpiSpec.IsSatisfiedBy(rpi).Should().BeTrue();
            hwAndRpiSpec.IsSatisfiedBy(orangePiOne).Should().BeFalse();
        }
Пример #16
0
        public void AnyHardwareAndRpiOrOrange()
        {
            // Arrange
            var rpi         = OrderItem.RaspberryPi3ModelB();
            var orangePiOne = OrderItem.OrangePiOne();
            var msOffice    = OrderItem.MicrosoftOffice2016();
            ISpecification <OrderItem> hwSpec     = new Spec <OrderItem>(x => x.Type == OrderItem.OrderItemType.Hardware);
            ISpecification <OrderItem> rpiSpec    = new Spec <OrderItem>(x => x.Name.ToLower().Contains("raspberry"));
            ISpecification <OrderItem> orangeSpec = new Spec <OrderItem>(x => x.Name.ToLower().Contains("orange"));

            // Act
            var anyHwSpecAndRpiOrOrange = hwSpec.And(rpiSpec.Or(orangeSpec));

            // Assert
            anyHwSpecAndRpiOrOrange.IsSatisfiedBy(rpi).Should().BeTrue();
            anyHwSpecAndRpiOrOrange.IsSatisfiedBy(orangePiOne).Should().BeTrue();
            anyHwSpecAndRpiOrOrange.IsSatisfiedBy(msOffice).Should().BeFalse();
        }
Пример #17
0
        public ActionResult Filter()
        {
            //var model = _repositoryBook.GetAllPaged(2, 2);
            //var model = _repositoryBook.Query(m => m.Publisher.PublisherName=="Manning");
            ISpecification <Book> querySpec = new Spec <Book>(m => m.Publisher.PublisherName == "Manning");

            //add conditions in spec based on some logic
            querySpec = querySpec.And(new Spec <Book>(m => m.BookName.StartsWith("Clojure")));
            var model = _repositoryBook.Query(querySpec).ToPagedList(1, 5); //using specification

            //var model = _repositoryBook.GetAll();


            return(View("List", new ListViewModel <Book>()
            {
                Model = model
            }));
        }
Пример #18
0
        public void AppleOrOrangeJuice()
        {
            // Arrange
            Drink blackberryJuice             = Drink.BlackberryJuice();
            Drink appleJuice                  = Drink.AppleJuice();
            Drink orangeJuice                 = Drink.OrangeJuice();
            ISpecification <Drink> juiceSpec  = new Spec <Drink>(d => d.With.Any(w => w.ToLower().Contains("juice")));
            ISpecification <Drink> appleSpec  = new Spec <Drink>(d => d.With.Any(w => w.ToLower().Contains("apple")));
            ISpecification <Drink> orangeSpec = new Spec <Drink>(d => d.With.Any(w => w.ToLower().Contains("orange")));

            // Act
            var appleOrOrangeJuiceSpec = juiceSpec.And(appleSpec.Or(orangeSpec));

            // Assert
            appleOrOrangeJuiceSpec.IsSatisfiedBy(appleJuice).Should().BeTrue();
            appleOrOrangeJuiceSpec.IsSatisfiedBy(orangeJuice).Should().BeTrue();
            appleOrOrangeJuiceSpec.IsSatisfiedBy(blackberryJuice).Should().BeFalse();
        }
Пример #19
0
        /// <summary>
        /// 搜索用户角色 或者 搜索角色用户
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IPageList<VUserRole> SearchVUserRoles(int? userId, int? roleId, int pageIndex, int pageSize)
        {
            Spec<EUserRole, ERole, EUser> sp = new Spec<EUserRole, ERole, EUser>();
            if (userId.HasValue)
            {
                sp.And((ur, r, u) => ur.UserId == userId);
            }
            if (roleId.HasValue)
            {
                sp.And((ur, r, u) => ur.RoleId == roleId);
            }

            return _rep.Query<EUserRole, ERole, EUser, VUserRole>()
                .LeftJoin<EUser>((ur, u) => ur.UserId == u.Id)
                .LeftJoin<ERole>((ur, r) => ur.RoleId == r.Id)
                .Where(sp).ToPageList(pageIndex, pageSize);
        }
Пример #20
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <returns></returns>
        public IPageList<EUser> SearchUsers(int? parentUserId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EUser> sp = new Spec<EUser>();

            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.NickName.Like(searchKeyword))
                        .Or(p => p.Mobile.Like(searchKeyword))
                        .Or(p => p.QQ.Like(searchKeyword))
                        .Or(p => p.UserName.Like(searchKeyword))
                        .Or(p => p.Address.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (parentUserId.HasValue)
            {
                sp.And(p => p.ParentUserId == parentUserId);
            }

            CSpec<EUser> cp = new CSpec<EUser>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EUser>(pageIndex, pageSize, sp, cp);
        }
Пример #21
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <returns></returns>
        public IPageList<ERole> SearchRoles(string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<ERole> sp = new Spec<ERole>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.RoleName.Like(searchKeyword))
                        .Or(p => p.RoleDesc.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            CSpec<ERole> cp = new CSpec<ERole>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<ERole>(pageIndex, pageSize, sp, cp);
        }
Пример #22
0
        public IPageList<EShowItem> SearchShowItems(int? showItemCategoryId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EShowItem> sp = new Spec<EShowItem>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.ShowItemName.Like(searchKeyword))
                        .Or(p => p.ShowItemDesc.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (showItemCategoryId.HasValue) 
            {
                sp.And(p => p.ShowItemCategoryId == showItemCategoryId);
            }


            CSpec<EShowItem> cp = new CSpec<EShowItem>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EShowItem>(pageIndex, pageSize, sp, cp);
        }
Пример #23
0
        /// <summary>
        /// 搜索 广告
        /// </summary>
        /// <returns></returns>
        public IPageList<EAd> SearchAds(int? adZoneId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EAd> sp = new Spec<EAd>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.AdName.Like(searchKeyword))
                        .Or(p => p.AdDesc.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (adZoneId.HasValue)
            {
                sp.And(p => p.AdZoneId == adZoneId);
            }

            CSpec<EAd> cp = new CSpec<EAd>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EAd>(pageIndex, pageSize, sp, cp);
        }
Пример #24
0
        public IPageList<VDevice> SearchDevices(IList<int> userIds, int? userId, int? deviceTypeId, int? deviceGpsTypeId, int? deviceExpireTime, DateTime? startTime, DateTime? endTime, string searchKeyword, string orderName, string orderType, int pageIndex, int pageSize)
        {

            Spec<EDevice> sp = new Spec<EDevice>();

            if (searchKeyword.HasValue())
            {
                sp.And(p => p.DeviceName.Like(searchKeyword) || p.DeviceGpsSimNo.Like(searchKeyword) || p.DeviceGpsCode.Like(searchKeyword) || p.DeviceGpsNo.Like(searchKeyword));
            }

            if (deviceTypeId.HasValue)
            {
                sp.And(p => p.DeviceTypeId == deviceTypeId);
            }

            if (deviceGpsTypeId.HasValue)
            {
                sp.And(p => p.DeviceGpsTypeId == deviceGpsTypeId);
            }

            if (userIds != null)
            {
                sp.And(p => p.UserId.In(string.Join(",", userIds)));
            }

            if (userId.HasValue)
            {
                sp.And(p => p.UserId == userId);
            }

            if (startTime.HasValue)
            {
                sp.And(p => p.CreateTime > startTime);
            }

            if (endTime.HasValue)
            {
                sp.And(p => p.CreateTime < endTime);
            }

            if (deviceExpireTime.HasValue) 
            {
                if (deviceExpireTime.Value == 0)
                {
                    //未过期
                    sp.And(p => p.DeviceExpireTime > DateTime.Now || p.DeviceExpireTime.IsDBNull());
                }
                else 
                {
                    //已过期
                    sp.And(p => p.DeviceExpireTime < DateTime.Now && p.DeviceExpireTime.IsNotDBNull());
                }
            }

            CSpec<EDevice> cp = new CSpec<EDevice>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.Query<EDevice, EDeviceType, EDeviceGpsType, EUser, VDevice>()
                .LeftJoin<EDeviceType>((d, dt) => d.DeviceTypeId == dt.Id)
                .LeftJoin<EDeviceGpsType>((d, dgt) => d.DeviceGpsTypeId == dgt.Id)
                .LeftJoin<EUser>((d, u) => d.UserId == u.Id)
                .Where(sp)
                .OrderBy(cp)
                .Select((d, dt, dgt, u) => new Columns(
                    d,
                    dt.DeviceTypeName,
                    dgt.DeviceGpsTypeName,
                    dgt.DeviceGpsTypeProtocol,
                    dgt.DeviceGpsTypeGpsCodeCreateRule,
                    u.UserName,
                    u.NickName
                    )).ToPageList(pageIndex, pageSize);
        }
Пример #25
0
        /// <summary>
        /// 自动补全数据
        /// </summary>
        /// <returns></returns>
        public IList<EDicData> SearchDicDatasFromCache(int max, string name, int? dicDataId)
        {
            Spec<EDicData> sp = new Spec<EDicData>();

            if (name.HasValue())
            {
                sp.And(p => p.DicDataName.Contains(name) || p.DicDataAliase.Contains(name) || p.DicDataExtValue.Contains(name));
            }

            if (dicDataId.HasValue)
            {
                sp.And(p => p.DicDataParentId == dicDataId);
            }

            return GetAllDicDatasFromCache().Where(sp.Exp.Compile()).ToList();
        }
Пример #26
0
        /// <summary>
        /// 根据车辆编号获取 行程数据
        /// </summary>
        /// <param name="vehicleCode"></param>
        /// <returns></returns>
        public List<OBDRouteVM> GetOBDRoutes(string vehicleCodes, DateTime? st, DateTime? et)
        {
            List<OBDRouteVM> vms = new List<OBDRouteVM>();
            var rep = DMRepository.Get<EOBDRoute>();
            var vehicles = rep.GetList<EVehicle>(0, p => p.VehicleCode.In(vehicleCodes), p => new Columns(p.CreateTime.Desc()));
            foreach (var vehicle in vehicles)
            {
                string vehicleCode = vehicle.VehicleCode.ToString();
                //获取当前车辆的所有行程
                Spec<EOBDRoute> sp = new Spec<EOBDRoute>();
                sp.And(p => p.VehicleCode == vehicleCode);

                if (st.HasValue)
                {
                    sp.And(p => p.RouteStartTime > st.Value.GetDayStartTime());
                }
                if (et.HasValue)
                {
                    sp.And(p => p.RouteEndTime < et.Value.GetDayEndTime());
                }

                var todayRoutes = rep.GetList(0, sp.Exp, p => new Columns(p.CreateTime.Desc())).Where(p => p.RouteStartTime != p.RouteEndTime);
                foreach (var route in todayRoutes)
                {
                    OBDRouteVM vm = new OBDRouteVM();
                    //车牌号
                    vm.LicenceNumber = vehicle.LicenceNumber;
                    //里程
                    vm.Mileage = route.RouteMileage;
                    //油耗
                    vm.Fuel = route.RouteFuel;

                    //平均油耗
                    vm.AverageFuel = vm.Mileage != 0 ? Math.Round((vm.Fuel / vm.Mileage) * 100, 2) : 0;

                    //开始时间
                    vm.StartTime = route.RouteStartTime;
                    //结束时间
                    vm.EndTime = route.RouteEndTime;

                    vm.StartTimeString = route.RouteStartTime.ToString("yyyy-MM-dd HH:mm");
                    vm.EndTimeString = route.RouteEndTime.ToString("yyyy-MM-dd HH:mm");


                    //时长
                    var ticks = (route.RouteEndTime - route.RouteStartTime).Ticks;
                    TimeSpan ts = new TimeSpan(ticks);
                    vm.TravelTime = ts.ToString();

                    //平均速度
                    vm.AverageSpeed = ts.TotalHours != 0 ? Math.Round(vm.Mileage / (decimal)ts.TotalHours, 2) : 0;

                    //怠速
                    ticks = (long)route.RouteIdleSpeed * 1000;
                    ts = new TimeSpan(ticks);
                    vm.IdleSpeed = ts.ToString();

                    var countItem = rep.GetList<EOBDAlarmtreport>(0, p => p.VehicleCode == vehicleCode && p.ReportTime > route.RouteStartTime.GetDayStartTime() && p.ReportTime < route.RouteEndTime.GetDayEndTime());
                    if (countItem != null && countItem.Count > 0)
                    {
                        //急加速次数
                        vm.SpeedUpCount = countItem.Where(p => p.AlarmType == ((int)OBDAlarmType.SpeedUp).ToString("X2")).Count();
                        //急减速次数
                        vm.SlowDownCount = countItem.Where(p => p.AlarmType == ((int)OBDAlarmType.SlowDown).ToString("X2")).Count();
                        //急变道次数
                        vm.ChangeLaneCount = countItem.Where(p => p.AlarmType == ((int)OBDAlarmType.ChangeLan).ToString("X2")).Count();
                        //急转弯次数
                        vm.TurnToCount = countItem.Where(p => p.AlarmType == ((int)OBDAlarmType.TurnTo).ToString("X2")).Count();
                    }

                    //地球坐标 转换成 火星坐标
                    var marLatLon = bMapSrv.LatLonToMar(new PES.GPSExpressEdition.MapService.Entity.LatLon { Longitude = (double)route.RouteStartLongitude, Latitude = (double)route.RouteStartLatitude });
                    //地址解析
                    var location = bMapSrv.LatLngToAddr(marLatLon);
                    vm.StartAddress = location.Address;


                    //地球坐标 转换成 火星坐标
                    marLatLon = bMapSrv.LatLonToMar(new PES.GPSExpressEdition.MapService.Entity.LatLon { Longitude = (double)route.RouteEndLongitude, Latitude = (double)route.RouteEndLatitude });
                    //地址解析
                    location = bMapSrv.LatLngToAddr(marLatLon);
                    vm.EndAddress = location.Address;

                    vms.Add(vm);
                }

            }

           
            return vms;
        }
Пример #27
0
        public IList<VDevice> GetNoDeviceGroupVDevices(string deviceName, int userId)
        {

            Spec<EDevice> sp = new Spec<EDevice>();
            if (deviceName.HasValue())
            {
                sp.And(p => p.DeviceName.Like(deviceName));
            }

            sp.And(p => p.DeviceGroupId == 0);
            sp.And(p => p.UserId == userId);

            return _rep.Query<EDevice, EDeviceType, EDeviceGpsType, EUser, VDevice>()
                          .LeftJoin<EDeviceType>((d, dt) => d.DeviceTypeId == dt.Id)
                          .LeftJoin<EDeviceGpsType>((d, dgt) => d.DeviceGpsTypeId == dgt.Id)
                          .LeftJoin<EUser>((d, u) => d.UserId == u.Id)
                          .Where(sp)
                          .Select((d, dt, dgt, u) => new Columns(
                              d,
                              dt.DeviceTypeName,
                              dgt.DeviceGpsTypeName,
                              dgt.DeviceGpsTypeProtocol,
                              dgt.DeviceGpsTypeGpsCodeCreateRule,
                              u.UserName
                             )).ToList();
        }
Пример #28
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <returns></returns>
        public IPageList<EContents> SearchContents(int? nodeId, DateTime? startTime, DateTime? endTime, EnumContentStatus? contentStatus, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EContents> sp = new Spec<EContents>();
            if (searchKeyword.HasValue())
            {
                sp.And(p => p.Title.Like(searchKeyword));
            }

            if (nodeId.HasValue)
            {
                sp.And(p => p.NodeId == nodeId);
            }

            if (startTime.HasValue)
            {
                sp.And(p => p.LastUpdateTime > startTime);
            }

            if (endTime.HasValue)
            {
                sp.And(p => p.LastUpdateTime < endTime);
            }

            if (contentStatus.HasValue)
            {
                sp.And(p => p.ContentStatus == (EnumContentStatus)contentStatus);
            }

            CSpec<EContents> cp = new CSpec<EContents>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EContents>(pageIndex, pageSize, sp, cp);
        }
Пример #29
0
        /// <summary>
        /// 搜索内容 排除指定内容分组
        /// </summary>
        /// <returns></returns>
        public IPageList<EContents> SearchNoHaveContentsByContentsGroupId(int contentsGroupId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            var hasIds = _rep.GetList<EContentsGroupContents>(0, p => p.ContentsGroupId == contentsGroupId).Select(p => p.ContentsId);

            Spec<EContents> sp = new Spec<EContents>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.Title.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (hasIds.Count() > 0)
            {
                sp.And(p => p.Id.NotIn(string.Join(",", hasIds)));
            }

            CSpec<EContents> cp = new CSpec<EContents>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EContents>(pageIndex, pageSize, sp, cp);
        }
Пример #30
0
        public IList<EContents> GetContentsByNodeId(int nodeId, int top, string orderName, string orderType)
        {
            Spec<EContents> sp = new Spec<EContents>();
            sp.And(p => p.NodeId == nodeId).And(p => p.ContentStatus == EnumContentStatus.PassAudit);

            CSpec<EContents> cp = new CSpec<EContents>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }
            return _rep.GetList<EContents>(top, sp, cp);
        }
Пример #31
0
        public IPageList<EFriendlyLink> SearchFriendlyLinks(int? friendlyLinkCategoryId, string searchKeyword, string searchType, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EFriendlyLink> sp = new Spec<EFriendlyLink>();
            if (searchKeyword.HasValue())
            {
                if (!searchType.HasValue())
                {
                    sp.And(p => p.FriendlyLinkName.Like(searchKeyword))
                        .Or(p => p.FriendlyLinkDesc.Like(searchKeyword));
                }
                else
                {
                    sp.And(p => p.Column(searchType).Like(searchKeyword));
                }
            }

            if (friendlyLinkCategoryId.HasValue) 
            {
                sp.And(p => p.FriendlyLinkCategoryId == friendlyLinkCategoryId);
            }


            CSpec<EFriendlyLink> cp = new CSpec<EFriendlyLink>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EFriendlyLink>(pageIndex, pageSize, sp, cp);
        }
Пример #32
0
        public IPageList<EDeviceLog> SearchDeviceLogs(int? deviceId, EnumDeviceLogType? deviceLogType, DateTime? startTime, DateTime? endTime, string searchKeyword, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<EDeviceLog> sp = new Spec<EDeviceLog>();

            if (searchKeyword.HasValue())
            {
                sp.And(p => p.LogContent.Like(searchKeyword));
            }

            if (deviceId.HasValue)
            {
                sp.And(p => p.DeviceId == deviceId);
            }

            if (deviceLogType.HasValue)
            {
                sp.And(p => p.LogType == deviceLogType);
            }

            if (startTime.HasValue)
            {
                sp.And(p => p.CreateTime > startTime);
            }

            if (endTime.HasValue)
            {
                sp.And(p => p.CreateTime < endTime);
            }

            CSpec<EDeviceLog> cp = new CSpec<EDeviceLog>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.GetPageList<EDeviceLog>(pageIndex, pageSize, sp, cp);
        }
Пример #33
0
        public IPageList<ELine> SearchLines(int userId, EnumMapCoordinates coordinates, string searchKeyword, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<ELine> sp = new Spec<ELine>();
            sp.And(p => p.UserId == userId);
            if (searchKeyword.HasValue())
            {
                sp.And(p => p.LineName.Like(searchKeyword));
            }

            CSpec<ELine> csp = new CSpec<ELine>();

            if (orderName.HasValue())
            {
                csp.And(orderName, orderType);
            }

            var list = _rep.GetPageList<ELine>(pageIndex, pageSize, sp, csp);
            switch (coordinates)
            {
                case EnumMapCoordinates.Gcj02:
                    foreach (var item in list.List)
                    {
                        item.LinePoints = _mapService.Wgs84ToGcj02(item.LinePoints.ToObject<IList<EMapPoint>>().ToArray()).ToJson();
                    }
                    break;
                case EnumMapCoordinates.Bd09:
                    foreach (var item in list.List)
                    {
                        item.LinePoints = _mapService.Wgs84ToBd09(item.LinePoints.ToObject<IList<EMapPoint>>().ToArray()).ToJson();
                    }
                    break;
                default:
                    break;
            }
            return list;
        }
Пример #34
0
 /// <summary>
 /// 获取当前定位数据
 /// </summary>
 /// <param name="coordinates"></param>
 /// <returns></returns>
 public VDeviceCurrentDataDetail GetVDeviceCurrentDataDetail(int? userId, int? deviceGroupId, EnumMapCoordinates coordinates)
 {
     var sp = new Spec<EDevice, EDeviceCurrentData>();
     if (userId.HasValue)
     {
         sp.And(p => p.UserId == userId);
     }
     if (deviceGroupId.HasValue)
     {
         var deviceGroup = _rep.Get<EDeviceGroup>(p => p.Id == deviceGroupId);
         if (deviceGroup.IsRoot)
         {
             //如果当前查询的是根分类 那么把没有分类的车辆一并查询了
             sp.And(p => p.DeviceGroupId == deviceGroupId || (p.UserId == deviceGroup.UserId && p.DeviceGroupId == 0));
         }
         else
         {
             sp.And(p => p.DeviceGroupId == deviceGroupId);
         }
     }
     var list = _rep.Query<EDevice, EDeviceCurrentData, VDeviceCurrentData>()
         .LeftJoin<EDeviceCurrentData>((d, c) => d.Id == c.DeviceId)
         .Where(sp)
         .Select((d, c) => new Columns(d.Id.As("DeviceId"), d.DeviceName, c)).ToList();
     return GetVDeviceCurrentDataDetailWrap(list, coordinates);
 }
Пример #35
0
        public IPageList<ETravel> SearchTravels(IList<int> userIds, int? userId, bool? isPraise, bool? isGood,
            string searchKeyword, string orderName, string orderType, int pageIndex, int pageSize)
        {
            Spec<ETravel> sp = new Spec<ETravel>();
            sp.And(p => p.TravelCover.IsNotDBNull());


            if (searchKeyword.HasValue())
            {
                sp.And(p => p.TravelName.Like(searchKeyword));
            }

            if (userId.HasValue)
            {
                sp.And(p => p.UserId == userId.Value);
            }

            if (userIds != null)
            {
                sp.And(p => p.UserId.In(string.Join(",", userIds)));
            }

            if (isPraise.HasValue)
            {
                sp.And(p => p.TravelIsPraise == isPraise.Value);
            }

            if (isGood.HasValue)
            {
                sp.And(p => p.TravelIsGood == isGood.Value);
            }

            CSpec<ETravel> cp = new CSpec<ETravel>();

            if (orderType.HasValue())
            {
                cp.And(orderName, orderType);
            }

            return _rep.Query<ETravel, EUser, ETravel>()
                .LeftJoin<EUser>((t, u) => t.UserId == u.Id)
                .Select((t, u) => new Columns(t, u.NickName.As("ExtNickName"), u.UserAvatar.As("ExtUserAvatar")))
                .Where(sp).OrderBy(cp).ToPageList(pageIndex, pageSize);
        }