Commit ee6b4e0f authored by liudong1993's avatar liudong1993
parents 00faf639 1a9452b3
......@@ -17,77 +17,6 @@ namespace Mall.Module.BaseSetUp
{
private Rb_destinationRepository rb_DestinationRepository = new Rb_destinationRepository();
/// <summary>
/// 获取地区分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="where"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<RB_Destination_Extend> GetPageList(int pageIndex, int pageSize, RB_Destination_Extend where, out long count)
{
return rb_DestinationRepository.GetPageList(pageIndex, pageSize, where, out count);
}
/// <summary>
/// 根据洲获取国家
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetCountryByArea(string Area)
{
RB_Destination_Extend where = new RB_Destination_Extend()
{
QArea = Area,
CodeLevel = Common.Enum.AreaRegionEnum.CountryEnum
};
return rb_DestinationRepository.GetListExt(where);
}
/// <summary>
/// 获取国家
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetCountry()
{
RB_Destination_Extend where = new RB_Destination_Extend()
{
CodeLevel = Common.Enum.AreaRegionEnum.CountryEnum
};
return rb_DestinationRepository.GetListExt(where);
}
/// <summary>
/// 根据条件获取单个地区
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public RB_Destination_Extend GetEntityExt(RB_Destination_Extend where)
{
return rb_DestinationRepository.GetEntityExt(where);
}
/// <summary>
/// 根据地区名称获取地区列表
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public List<RB_Destination_Extend> GetListByNames(string[] where)
{
return rb_DestinationRepository.GetListByNames(where);
}
/// <summary>
/// 获取实体
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public RB_Destination GetEntity(object id)
{
return rb_DestinationRepository.GetEntity(id);
}
/// <summary>
/// 根据父节点编号获取子列表
/// </summary>
......@@ -102,62 +31,6 @@ namespace Mall.Module.BaseSetUp
return rb_DestinationRepository.GetListExt(where);
}
/// <summary>
/// 获取所有的地区数据
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetListByCountryId(RB_Destination_Extend where)
{
return rb_DestinationRepository.GetListByCountryId(where);
}
/// <summary>
/// 获取城市列表
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetCityList()
{
RB_Destination_Extend where = new RB_Destination_Extend()
{
CodeLevel = Common.Enum.AreaRegionEnum.CityEnum
};
return rb_DestinationRepository.GetListExt(where);
}
/// <summary>
/// 根据查询条件获取
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public List<RB_Destination_Extend> GetListModule(RB_Destination_Extend where)
{
return rb_DestinationRepository.GetListExt(where);
}
/// <summary>
/// 获取省份和城市列表
/// </summary>
/// <param name="isGetArea">是否查询区县</param>
/// <returns></returns>
public object GetProviceAndCityList(bool isGetArea = false)
{
var CommonList = Mall.Common.Data.AreaDataHelper.GetAreaList();
if (CommonList != null && CommonList.Count > 0)
{
if (isGetArea)
{
return CommonList.Where(qitem => (qitem.L == 3 || qitem.L == 2 || qitem.L == 4) && qitem.P != 2).Select(qitem => new { ID = qitem.I, Name = qitem.N });
}
else
{
return CommonList.Where(qitem => (qitem.L == 3 || qitem.L == 2) && qitem.P != 2).Select(qitem => new { ID = qitem.I, Name = qitem.N });
}
}
var list = rb_DestinationRepository.GetProviceAndCityList(isGetArea: isGetArea);
return list.Select(item => new { item.ID, item.Name });
}
/// <summary>
/// 获取列表
/// </summary>
......@@ -203,130 +76,5 @@ namespace Mall.Module.BaseSetUp
}
return flag;
}
/// <summary>
/// 删除数据
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public bool Remove(RB_Destination model)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{ nameof(RB_Destination_Extend.Status),(int)Common.Enum.DateStateEnum.Delete}
};
var flag = true;
var trans = rb_DestinationRepository.DbTransaction;
try
{
//省
List<RB_Destination_Extend> ProvinceList = new List<RB_Destination_Extend>();
//城市
List<RB_Destination_Extend> CityList = new List<RB_Destination_Extend>();
//区县
List<RB_Destination_Extend> DistrictList = new List<RB_Destination_Extend>();
switch (model.CodeLevel)
{
//删除国家及国家下面的所有数据
case Common.Enum.AreaRegionEnum.CountryEnum:
ProvinceList = this.GetChildList(model.ID);
foreach (var item in ProvinceList)
{
CityList = this.GetChildList(item.ID);
foreach (var subItem in DistrictList)
{
DistrictList = this.GetChildList(subItem.ID);
foreach (var thirdItem in DistrictList)
{
//删除区县
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), thirdItem.ID), trans);
}
//删除城市
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), subItem.ID), trans);
}
//删除省
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), item.ID), trans);
}
//删除国家
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), model.ID), trans);
break;
//删除省及省下面的市、区县
case Common.Enum.AreaRegionEnum.ProvinceEnum:
CityList = this.GetChildList(model.ID);
foreach (var item in DistrictList)
{
DistrictList = this.GetChildList(item.ID);
foreach (var subItem in DistrictList)
{
//删除区县
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), subItem.ID), trans);
}
//删除城市
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), item.ID), trans);
}
//删除省
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), model.ID), trans);
break;
//删除城市及下面的区县
case Common.Enum.AreaRegionEnum.CityEnum:
DistrictList = this.GetChildList(model.ID);
foreach (var item in DistrictList)
{
//删除区县
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), item.ID), trans);
}
//删除城市
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), model.ID), trans);
break;
//删除区县
case Common.Enum.AreaRegionEnum.DistrictEnum:
rb_DestinationRepository.Update(fileds, new WhereHelper(nameof(RB_Destination_Extend.ID), model.ID), trans);
break;
}
rb_DestinationRepository.DBSession.Commit();
}
catch (Exception ex)
{
LogHelper.Write(ex, "Remove");
rb_DestinationRepository.DBSession.Rollback("Remove");
flag = false;
}
return flag;
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public bool IsExists(RB_Destination where)
{
IList<WhereHelper> whereHelpers = new List<WhereHelper>()
{
new WhereHelper(){ FiledName=nameof(RB_Destination.Name), FiledValue=where.Name.Trim(), OperatorEnum= OperatorEnum.Equal},
new WhereHelper(){ FiledName=nameof(RB_Destination.Status), FiledValue=(int)Common.Enum.DateStateEnum.Normal, OperatorEnum= OperatorEnum.Equal},
new WhereHelper(){ FiledName=nameof(RB_Destination.CodeLevel), FiledValue=where.CodeLevel, OperatorEnum= OperatorEnum.Equal},
};
//地区,验证城市下面的区不重复
if (where.CodeLevel == Common.Enum.AreaRegionEnum.DistrictEnum)
{
whereHelpers.Add(new WhereHelper(nameof(RB_Destination.ParentID), where.ParentID));
}
if (where.ID > 0)
{
whereHelpers.Add(new WhereHelper()
{
FiledName = nameof(RB_Destination.ID),
FiledValue = where.ID,
OperatorEnum = OperatorEnum.NotEqual
});
}
return rb_DestinationRepository.Exists(whereHelpers);
}
}
}
......@@ -18,57 +18,6 @@ namespace Mall.Repository.BaseSetUp
/// </summary>
public string TableName { get { return nameof(RB_Destination); } }
/// <summary>
/// 获取地区分页列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="where"></param>
/// <param name="count"></param>
/// <returns></returns>
public List<RB_Destination_Extend> GetPageList(int pageIndex, int pageSize, RB_Destination_Extend where, out long count)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" SELECT * FROM {0} WHERE 1=1 ", TableName);
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
if (where != null)
{
if (where.Name != null && !string.IsNullOrEmpty(where.Name.Trim()))
{
sb.AppendFormat(" AND {0} LIKE '%{1}%' ", nameof(RB_Destination_Extend.Name), where.Name.Trim());
}
var QArea = Common.ConvertHelper.ConvertInt(where.QArea);
var QCountry = Common.ConvertHelper.ConvertInt(where.QCountry);
var QProvince = Common.ConvertHelper.ConvertInt(where.QProvince);
var QCity = Common.ConvertHelper.ConvertInt(where.QCity);
var QDistrict = Common.ConvertHelper.ConvertInt(where.QDistrict);
//区
if (QDistrict > 0)
{
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.ID), QDistrict);
}
if (QCity > 0 && QDistrict <= 0)
{
sb.AppendFormat(" AND ({0}={1} OR {2}={3}) ", nameof(RB_Destination_Extend.ParentID), QCity, nameof(RB_Destination_Extend.ID), QCity);
}
if (QProvince > 0 && QCity <= 0 && QDistrict <= 0)
{
sb.AppendFormat(" AND (({0}={1} AND {2}={3}) OR ({4}={5}) ) ", nameof(RB_Destination_Extend.ParentID), QProvince, nameof(RB_Destination_Extend.CodeLevel), (int)Common.Enum.AreaRegionEnum.CityEnum, nameof(RB_Destination_Extend.ID), QProvince);
}
if (QCountry > 0 && QProvince <= 0 && QCity <= 0 && QDistrict <= 0)
{
sb.AppendFormat(" AND (({0}={1} AND {2}={3}) OR ({4}={5})) ", nameof(RB_Destination_Extend.ParentID), QCountry, nameof(RB_Destination_Extend.CodeLevel), (int)Common.Enum.AreaRegionEnum.ProvinceEnum, nameof(RB_Destination_Extend.ID), QCountry);
}
if (QArea > 0 && QCountry <= 0 && QProvince <= 0 && QCity <= 0 && QDistrict <= 0)
{
sb.AppendFormat(" AND FIND_IN_SET({0},{1}) AND {2}={3} ", QArea, nameof(RB_Destination_Extend.Area), nameof(RB_Destination_Extend.CodeLevel), (int)Common.Enum.AreaRegionEnum.CountryEnum);
}
}
sb.AppendFormat(" ORDER BY {0} ASC ", nameof(RB_Destination_Extend.ID));
return GetPage<RB_Destination_Extend>(pageIndex, pageSize, out count, sb.ToString()).ToList();
}
/// <summary>
/// 获取所有的地区数据
/// </summary>
......@@ -100,75 +49,14 @@ namespace Mall.Repository.BaseSetUp
{
sb.AppendFormat(" AND {0} LIKE '%{1}%' ", nameof(RB_Destination_Extend.Name), where.Name.Trim());
}
if (!string.IsNullOrEmpty(where.NameStr)) {
sb.AppendFormat(" AND {0} in({1})", nameof(RB_Destination_Extend.Name), where.NameStr);
}
}
return Get<RB_Destination_Extend>(sb.ToString()).ToList();
}
/// <summary>
/// 获取所有的地区数据
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetListByCountryId(RB_Destination_Extend where)
if (!string.IsNullOrEmpty(where.NameStr))
{
string whereStr = string.Format(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
StringBuilder sb = new StringBuilder();
sb.AppendFormat(@"
SELECT * FROM {0} WHERE ParentID IN
(
SELECT ID FROM {0} WHERE ParentID IN({1}) {2}
) {2}
", TableName, where.QIds, whereStr);
return Get<RB_Destination_Extend>(sb.ToString()).ToList();
sb.AppendFormat(" AND {0} in({1})", nameof(RB_Destination_Extend.Name), where.NameStr);
}
/// <summary>
/// 获取所有的省份和城市数据
/// </summary>
/// <returns></returns>
public List<RB_Destination_Extend> GetProviceAndCityList(bool isGetArea = false)
{
string whereStr = " AND CodeLevel IN(2,3)";
if (isGetArea)
{
whereStr = " AND CodeLevel IN(2,3,4) ";
}
StringBuilder sb = new StringBuilder();
sb.AppendFormat(@"
SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
", TableName, whereStr);
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
return Get<RB_Destination_Extend>(sb.ToString()).ToList();
}
/// <summary>
/// 根据条件获取单个地区
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public RB_Destination_Extend GetEntityExt(RB_Destination_Extend where)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT * FROM {0} WHERE 1=1 ", TableName);
if (where != null)
{
if (where.Name != null && !string.IsNullOrEmpty(where.Name.Trim()))
{
sb.AppendFormat(" AND {0}='{1}'", nameof(RB_Destination_Extend.Name), where.Name.Trim());
}
if (where.ParentID != null && where.ParentID > 0)
{
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.ID), where.ParentID);
}
}
sb.Append(" LIMIT 1;");
return Get<RB_Destination_Extend>(sb.ToString()).ToList().FirstOrDefault();
}
/// <summary>
/// 根据地区名称获取地区列表
/// </summary>
......@@ -179,7 +67,6 @@ SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
StringBuilder sbWhere = new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT * FROM {0} WHERE 1=1 ", TableName);
//sb.AppendFormat(" AND {0}<>{1} ", nameof(RB_Destination_Extend.CodeLevel), (int)AreaRegionEnum.DistrictEnum);
if (where != null && where.Length > 0)
{
var index = 0;
......@@ -206,34 +93,6 @@ SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
return Get<RB_Destination_Extend>(sb.ToString()).ToList();
}
/// <summary>
/// 获取地区列表
/// </summary>
/// <returns></returns>
public List<Mall.Common.Data.Node> GetAllList()
{
List<Common.Data.Node> queryList = new List<Common.Data.Node>();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT * FROM {0} WHERE 1=1 ", TableName);
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
List<RB_Destination_Extend> list = Get<RB_Destination_Extend>(sb.ToString()).ToList();
foreach (var item in list)
{
Common.Data.Node model = new Common.Data.Node()
{
I = item.ID,
N = item.Name,
E = !string.IsNullOrWhiteSpace(item.EnName) ? item.EnName : "",
C = !string.IsNullOrWhiteSpace(item.ThreeCode) ? item.ThreeCode : "",
L = Convert.ToInt32(item.CodeLevel),
P = Convert.ToInt32(item.ParentID),
S = (int)item.Status
};
queryList.Add(model);
}
return queryList;
}
/// <summary>
/// 获取地区列表
......@@ -241,39 +100,13 @@ SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
/// <returns></returns>
public List<RB_Destination_Extend> GetAllDestinationList()
{
List<Common.Data.Node> queryList = new List<Common.Data.Node>();
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT * FROM {0} WHERE 1=1 ", TableName);
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
List<RB_Destination_Extend> list = Get<RB_Destination_Extend>(sb.ToString()).ToList();
return list;
}
/// <summary>
/// 根据Ids获取地区名称
/// </summary>
/// <param name="Ids">地区编号</param>
/// <returns></returns>
public string GetNames(string Ids)
{
if (!string.IsNullOrEmpty(Ids))
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("SELECT GROUP_CONCAT(Name) AS Name FROM {0} ", TableName);
sb.Append(" WHERE 1=1 ");
sb.AppendFormat(" AND {0}={1} ", nameof(RB_Destination_Extend.Status), (int)Common.Enum.DateStateEnum.Normal);
sb.AppendFormat(" AND Id in({0})", Ids.TrimStart(',').TrimEnd(','));
var obj = base.ExecuteScalar(sb.ToString());
if (obj != null)
{
return obj.ToString();
}
return "";
}
return "";
}
/// <summary>
/// 根据id 获取所有数据
/// </summary>
......@@ -292,36 +125,5 @@ SELECT * FROM {0} WHERE 1=1 AND ParentID<>2 {1}
}
return new List<RB_Destination>();
}
/// <summary>
/// 获取中国所有城市
/// </summary>
/// <returns></returns>
public List<RB_Destination> GetAllStartCity(int CountryId = 2)
{
string where = " 1=1";
if (CountryId > 0)
{
where += $@" and dpp.ID={CountryId}";
}
string sql = $@"SELECT d.* FROM rb_destination d
LEFT JOIN rb_destination dp ON d.ParentID=dp.ID
LEFT JOIN rb_destination dpp ON dp.ParentID=dpp.ID
WHERE {where} AND d.CodeLevel=3 AND d.`Status`=0";
return Get(sql).ToList();
}
/// <summary>
/// 获取中国所有城市
/// </summary>
/// <returns></returns>
public List<RB_Destination> GetAllStartCityTemp(int CountryId = 2)
{
string sql = $@"SELECT d.* FROM rb_destination d
LEFT JOIN rb_destination dp ON d.ParentID=dp.ID
LEFT JOIN rb_destination dpp ON dp.ParentID=dpp.ID ";
return Get(sql).ToList();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment