public BaseResultEntity Post(ImportHouseInfoRequestEntity ImportHouse) { Logger.LogDebug("ImportHouseInfo Request:" + JsonHelper.SerializeObject(ImportHouse), "ImportHouseInfoController", "Post"); var ret = new BaseResultEntity(); try { if (ImportHouse != null && ImportHouse.HouseList != null) { if (_projectBLL.GetModels(x => x.ID == ImportHouse.ProjectID) != null) { #region 创建楼盘 var _houseEstate = _houseEstateBLL.GetModels(x => x.Name == ImportHouse.HouseEstate); if (_houseEstate == null || _houseEstate.Count() == 0) { _houseEstateBLL.Add(new HouseEstate() { ProjectID = ImportHouse.ProjectID, Name = ImportHouse.HouseEstate, CreateTime = DateTime.Now, LastUpdate = DateTime.Now }); } #endregion #region 创建房源分组 var groupList = ImportHouse.HouseList.GroupBy(x => x.Group).ToList(); var _existGroup = _houseGroupBLL.GetModels(x => x.ProjectID == ImportHouse.ProjectID); List <string> addGroupList = new List <string>(); foreach (var group in groupList) { if (!_existGroup.Any(x => x.Name == group.Key)) { if (!addGroupList.Any(x => x == group.Key)) { addGroupList.Add(group.Key); } } } var _hsList = new List <HouseGroup>(); foreach (string a in addGroupList) { HouseGroup _hs = new HouseGroup() { ProjectID = ImportHouse.ProjectID, Name = a, CreateTime = DateTime.Now, LastUpdate = DateTime.Now }; _hsList.Add(_hs); } _houseGroupBLL.AddRange(_hsList); #endregion #region 创建户型 var roomTypeGroupList = ImportHouse.HouseList.GroupBy(x => x.RoomType).ToList(); var _existRoomType = _roomTypeBLL.GetModels(x => 1 == 1).ToList(); List <string> addRoomTypeList = new List <string>(); foreach (var group in roomTypeGroupList) { if (!_existRoomType.Any(x => x.Name == group.Key)) { if (!addRoomTypeList.Any(x => x == group.Key)) { addRoomTypeList.Add(group.Key); } } } var _rtList = new List <RoomType>(); foreach (string a in addRoomTypeList) { RoomType _rt = new RoomType() { Name = a, CreateTime = DateTime.Now, LastUpdate = DateTime.Now }; _rtList.Add(_rt); } _roomTypeBLL.AddRange(_rtList); #endregion #region 创建房源 var _houseGroup = _houseGroupBLL.GetModels(x => x.ProjectID == ImportHouse.ProjectID); var _roomTypeGroup = _roomTypeBLL.GetModels(x => 1 == 1); var _existhouse = _houseBLL.GetModels(x => x.ProjectID == ImportHouse.ProjectID); int _houseEstateID = _houseEstateBLL.GetModels(x => x.ProjectID == ImportHouse.ProjectID).FirstOrDefault().ID; List <House> addHouseList = new List <House>(); foreach (var house in ImportHouse.HouseList) { if (_existhouse.Any(x => x.SerialNumber == house.SerialNumber)) //去重 { continue; } else { int _groupID = _houseGroup.FirstOrDefault(x => x.Name == house.Group).ID; int _roomTypeID = _roomTypeGroup.FirstOrDefault(x => x.Name == house.RoomType).ID; House _house = new House() { ProjectID = ImportHouse.ProjectID, SerialNumber = house.SerialNumber, GroupID = _groupID, Block = house.Block == null ? "" : house.Block, Building = house.Building, Unit = house.Unit, RoomNumber = house.RoomNumber == null ? "" : house.RoomNumber, RoomTypeID = _roomTypeID, Toward = house.Toward == null ? "" : house.Toward, RoomTypeCode = house.RoomType, EstimateBuiltUpArea = house.EstimateBuiltUpArea, EstimateLivingArea = house.EstimateLivingArea, AreaUnitPrice = house.AreaUnitPrice, TotalPrice = house.TotalPrice, CreateTime = DateTime.Now, LastUpdate = DateTime.Now, HouseEstateID = _houseEstateID }; addHouseList.Add(_house); } } _houseBLL.AddRange(addHouseList); #endregion } else { ret.Code = 302; ret.ErrMsg = "导入的房源信息所属项目不存在!"; } } else { ret.Code = 301; ret.ErrMsg = "导入的房源信息不允许为空!"; } } catch (Exception ex) { Logger.LogException("导入房源信息时发生异常!", "ImportHouseInfoController", "Post", ex); ret.Code = 999; ret.ErrMsg = ex.Message; } return(ret); }
public GetValidHousesResultEntity Post(GetValidHousesRequestModel req) { var ret = new GetValidHousesResultEntity() { Code = 0, ErrMsg = "", Houses = new List <HouseInfo>() }; try { if (req.HouseEstateId <= 0 || req.ProjectId <= 0 || req.ShakingNumberResultId <= 0) { ret.Code = 401; ret.ErrMsg = "入参无效。"; } else { var houses = _houseBLL.GetModels(h => h.ProjectID == req.ProjectId && h.HouseEstateID == req.HouseEstateId && h.Building == req.BuildingId).ToList(); var validHouses = _houseBLL.GetValidHouses(req.ShakingNumberResultId, req.HouseEstateId, req.BuildingId); houses.ForEach(h => { var houseInfo = new HouseInfo(); houseInfo.Building = h.Building; houseInfo.Unit = h.Unit; //var subscriberInfo = _subscriberBLL.GetModels(i => i.ID == h.SubscriberID).FirstOrDefault(); //string subscriberName = string.Empty; //if (subscriberInfo != null) //{ // subscriberName = subscriberInfo.Name; //} var groupInfo = _houseGroupBLL.GetModels(g => g.ID == h.GroupID).FirstOrDefault(); string groupName = string.Empty; if (groupInfo != null) { groupName = groupInfo.Name; } var roomTypeInfo = _roomTypeBLL.GetModels(r => r.ID == h.RoomTypeID).FirstOrDefault(); string roomType = string.Empty; if (roomTypeInfo != null) { roomType = roomTypeInfo.Name; } bool isSelected = ((h.SubscriberID != null) && h.SubscriberID > 0); houseInfo.HouseDetail = new Model.HouseEntity() { AreaUnitPrice = h.AreaUnitPrice, Block = h.Block, Building = h.Building, EstimateBuiltUpArea = h.EstimateBuiltUpArea, EstimateLivingArea = h.EstimateLivingArea, Group = groupName, HouseID = h.ID, RoomNumber = h.RoomNumber, RoomType = roomType, SerialNumber = h.SerialNumber, TotalPrice = h.TotalPrice, Toward = h.Toward, Unit = h.Unit, IsSelected = isSelected ? 1 : 0, IsValid = validHouses.Any(x => x.ID == h.ID) ? 1 : 0 }; ret.Houses.Add(houseInfo); }); } } catch (Exception ex) { Logger.LogException("获取楼盘明细信息时发生异常!", "GetHouseEstateDetailsController", "Post", ex); ret.Code = 999; ret.ErrMsg = ex.Message; } return(ret); }