Example #1
0
        /// <summary>
        /// 获取最短距离的分店
        /// </summary>
        /// <param name="session"></param>
        /// <param name="loc">地址</param>
        /// <param name="maxDist">最长距离</param>
        /// <returns></returns>
        public static Department GetMinDistDept(ISession session, TbLocation loc, double maxDist)
        {
            Department retVal = null;
            double minDest = double.MaxValue;

            string addrCode = loc.AddrCode;
            string paddrCode = "";
            //如果达到街道级别
            if (addrCode.Length >= 9)
            {
                //获取上级地址码
                paddrCode = addrCode.Substring(0, 6);
            }
            else
            {
                //获取当级地址码
                paddrCode = addrCode;
            }

            ICriteria criteria=session.CreateCriteria(typeof(Department));
            //模糊查找当前代码
            ICriterion criterion = Restrictions.Or(
                Restrictions.Eq("AddrCode", addrCode),
                Restrictions.Like("AddrCode", paddrCode+"%")
                );
            criteria.Add(criterion);

            criterion = Restrictions.Eq("Del", false);
            criteria.Add(criterion);

            criteria.AddOrder(Order.Desc("AddrCode"));

            criteria.SetCacheable(true);

            IList<Department> depts = criteria.List<Department>();
            foreach (Department dept in depts)
            {
                //如果地址相同则返回该商店
                if (dept.Lat == loc.Lat && dept.Lng == loc.Lng)
                {
                    retVal = dept;
                    break;
                }
                else
                {
                    //计算距离
                    double dest = LocationUtil.GetDistance(dept.Lat, dept.Lng, loc.Lat, loc.Lng);
                    //取最短距离的分店
                    if (dest<=maxDist && dest < minDest)
                    {
                        minDest = dest;
                        retVal = dept;
                    }
                }
            }

            return retVal;
        }
Example #2
0
        /// <summary>
        /// 获取最短距离的分店
        /// </summary>
        /// <param name="hibernateOper"></param>
        /// <param name="loc">地址</param>
        /// <param name="maxDist">最长距离</param>
        /// <returns></returns>
        public static Department GetMinDistDept(IHibernateOper hibernateOper, TbLocation loc,double maxDist)
        {
            Department retVal = null;

            Exec(hibernateOper,
                delegate(ISession s)
                {
                    //查找地址码
                    retVal = GetMinDistDept(s, loc, maxDist);
                }
                );

            return retVal;
        }
Example #3
0
 /// <summary>
 /// 获取最短距离的分店
 /// </summary>
 /// <param name="session"></param>
 /// <param name="loc">地址</param>
 /// <returns></returns>
 public static Department GetMinDistDept(ISession session, TbLocation loc)
 {
     return GetMinDistDept(session,loc,double.MaxValue);
 }
Example #4
0
 /// <summary>
 /// 获取最短距离的分店
 /// </summary>
 /// <param name="hibernateOper"></param>
 /// <param name="loc">地址</param>
 /// <returns></returns>
 public static Department GetMinDistDept(IHibernateOper hibernateOper, TbLocation loc)
 {
     return GetMinDistDept(hibernateOper,loc,double.MaxValue);
 }