public int SetAllotProjectInfo(int allotId, string userName, string userTrueName, int fxtCompanyId, int cityId, ProjectDto projectDto, int isValid, out long returnAllotId, out int returnProjectId) { Stopwatch sw = new Stopwatch(); sw.Start(); log.Info("Stopwatch开始计时," + allotId); int housecount = 0; int housedetailcount = 0; string message = string.Empty; returnAllotId = allotId; returnProjectId = projectDto.ProjectId; DateTime nowTime = DateTime.Now; Project project = Mapper.Map <ProjectDto, Project>(projectDto); AllotFlow allotFlow = _unitOfWork.AllotFlowRepository.GetById(allotId); if (allotFlow == null) { return(-5); } //不是当前用户的任务 if (allotFlow.SurveyUserName != userName.ToLower()) { return(-2); } else if (allotFlow.StateCode != SYSCodeManager.STATECODE_4) { //不是查勘中任务 return(-3); } //行政区 + 楼盘名称||已有的projectid||没有入库 //var exists = _unitOfWork.ProjectRepository.Get(m => // ( // (m.ProjectName == project.ProjectName && m.AreaID == project.AreaID) // && m.ProjectId != project.ProjectId // ) // && m.Status != SYSCodeManager.STATECODE_10 && m.Valid == 1 // ).FirstOrDefault(); //if (exists != null) //{ // message = "楼盘已存在"; // return -4; //} #region (Project更新值) if (isValid == 0 && !CheckProjectObj(project, out message)) { return(0); } allotFlow.Project.EndDate = projectDto.Enddate; allotFlow.Project.ManagerQuality = projectDto.Managerquality; allotFlow.Project.ParkingStatus = projectDto.ParkingStatus; allotFlow.Project.PhotoCount = projectDto.PhotoCount; allotFlow.Project.FxtProjectId = projectDto.FxtProjectId; allotFlow.Project.ProjectName = projectDto.ProjectName; allotFlow.Project.OtherName = projectDto.OtherName; allotFlow.Project.CityID = projectDto.CityID; allotFlow.Project.AreaID = projectDto.AreaID; allotFlow.Project.SubAreaId = projectDto.SubAreaId; allotFlow.Project.Address = projectDto.Address; allotFlow.Project.PurposeCode = projectDto.PurposeCode; allotFlow.Project.RightCode = projectDto.RightCode; allotFlow.Project.Detail = projectDto.Detail; allotFlow.Project.X = projectDto.X; allotFlow.Project.Y = projectDto.Y; allotFlow.Project.BuildingNum = projectDto.BuildingNum; allotFlow.Project.TotalNum = projectDto.Totalnum; allotFlow.Project.ParkingNumber = projectDto.Parkingnumber; allotFlow.Project.East = projectDto.East; allotFlow.Project.West = projectDto.West; allotFlow.Project.South = projectDto.South; allotFlow.Project.North = projectDto.North; allotFlow.Project.Status = SYSCodeManager.STATECODE_4; allotFlow.Project.FxtCompanyId = fxtCompanyId; allotFlow.Project.CityID = cityId; allotFlow.Project.Valid = 1; allotFlow.Project.SaveDateTime = nowTime; //最后修改时间 allotFlow.Project.SaveUser = userName; //修改人 returnProjectId = allotFlow.Project.ProjectId; #endregion #region (停车状况) int classcode = project.ParkingStatus.HasValue ? project.ParkingStatus.Value : 0; PAppendage pAppendage = new PAppendage() { CityId = cityId, ProjectId = project.ProjectId, ClassCode = classcode, AppendageCode = SYSCodeManager.APPENDAGECODE_14 }; PAppendage pAppend = _unitOfWork.P_AppendageRepository.GetBy(m => m.CityId == cityId && m.ProjectId == project.ProjectId && m.AppendageCode == SYSCodeManager.APPENDAGECODE_14); if (pAppend == null) { _unitOfWork.P_AppendageRepository.Insert(pAppendage); } else { pAppend.ClassCode = classcode; _unitOfWork.P_AppendageRepository.Update(pAppend); } #endregion #region (Project更新关联公司) //更新开发商 if (!string.IsNullOrEmpty(projectDto.Developers)) { var developers = _unitOfWork.P_CompanyRepository.GetBy(m => m.CityId == cityId && m.ProjectId == project.ProjectId && m.CompanyType == SYSCodeApi.COMPANYTYPECODE_1); if (developers == null) { PCompany pcompany = new PCompany() { CityId = cityId, CompanyName = projectDto.Developers, CompanyType = SYSCodeApi.COMPANYTYPECODE_1, ProjectId = project.ProjectId }; _unitOfWork.P_CompanyRepository.Insert(pcompany); } else { developers.CompanyName = projectDto.Developers; _unitOfWork.P_CompanyRepository.Update(developers); } } else { _unitOfWork.P_CompanyRepository.Delete(m => m.CityId == cityId && m.ProjectId == project.ProjectId && m.CompanyType == SYSCodeApi.COMPANYTYPECODE_1); } //更新物业管理公司 if (!string.IsNullOrEmpty(projectDto.ManagerCompany)) { var managerCompany = _unitOfWork.P_CompanyRepository.GetBy(m => m.CityId == cityId && m.ProjectId == project.ProjectId && m.CompanyType == SYSCodeApi.COMPANYTYPECODE_4); if (managerCompany == null) { PCompany pcompany = new PCompany() { CityId = cityId, CompanyName = projectDto.ManagerCompany, CompanyType = SYSCodeApi.COMPANYTYPECODE_4, ProjectId = project.ProjectId }; _unitOfWork.P_CompanyRepository.Insert(pcompany); } else { managerCompany.CompanyName = projectDto.ManagerCompany; _unitOfWork.P_CompanyRepository.Update(managerCompany); } } else { _unitOfWork.P_CompanyRepository.Delete(m => m.CityId == cityId && m.ProjectId == project.ProjectId && m.CompanyType == SYSCodeApi.COMPANYTYPECODE_4); } #endregion #region (Building更新值) if (projectDto.BuildingDtolist != null && projectDto.BuildingDtolist.Count > 0) { int bid = 0; foreach (var buildingDto in projectDto.BuildingDtolist) { var t = false; Stopwatch swbs = new Stopwatch(); swbs.Start(); //验证楼栋字段数据 if (!CheckBuildingObj(buildingDto, out message)) { return(0); } //给building各属性赋值 Building building = Mapper.Map <BuildingDto, Building>(buildingDto); building.Valid = 1; building.ProjectId = project.ProjectId; building.FxtCompanyId = allotFlow.FxtCompanyId; building.CityID = cityId; //删除楼栋 if (buildingDto.Valid == 0) { var build = _unitOfWork.BuildingRepository.GetBy(m => m.AppId == building.AppId); if (build != null) { _unitOfWork.HouseRepository.Delete(m => m.BuildingId == build.BuildingId); _unitOfWork.HouseDetailsRepository.Delete(m => m.BuildingId == build.BuildingId); _unitOfWork.BuildingRepository.Delete(m => m.AppId == building.AppId); } } else { if (allotFlow.Project.Buildings == null) { allotFlow.Project.Buildings = new List <Building>(); } Building eBuilding = allotFlow.Project.Buildings.Where(m => m.Valid == 1 && m.AppId == building.AppId).FirstOrDefault(); if (eBuilding == null) { building.Creator = userName; building.CreateTime = nowTime; eBuilding = building; eBuilding.BuildingId = bid++; allotFlow.Project.Buildings.Add(eBuilding); } else { eBuilding.AppId = buildingDto.AppId; eBuilding.BuildDate = buildingDto.BuildDate; eBuilding.BuildingName = buildingDto.BuildingName; eBuilding.ElevatorRate = buildingDto.ElevatorRate; eBuilding.IsElevator = buildingDto.IsElevator; eBuilding.LocationCode = buildingDto.LocationCode; eBuilding.MaintenanceCode = buildingDto.MaintenanceCode; eBuilding.OtherName = buildingDto.OtherName; eBuilding.PurposeCode = buildingDto.PurposeCode; eBuilding.Remark = buildingDto.Remark; eBuilding.StructureCode = buildingDto.StructureCode; eBuilding.TotalFloor = buildingDto.TotalFloor; eBuilding.UnitsNumber = buildingDto.UnitsNumber; eBuilding.X = buildingDto.X; eBuilding.Y = buildingDto.Y; eBuilding.SaveUser = userName; eBuilding.SaveDateTime = nowTime; } #region (设置house) if (buildingDto.HouseDtolist != null && buildingDto.HouseDtolist.Count > 0) { foreach (var houseDto in buildingDto.HouseDtolist) { //验证房号字段数据 if (!CheckHouseObj(houseDto, out message)) { return(0); } houseDto.HouseId = 0; housecount++; House house = Mapper.Map <HouseDto, House>(houseDto); //给house各属性赋值 house.BuildingId = eBuilding.BuildingId; house.Valid = 1; house.FxtCompanyId = fxtCompanyId; house.CityID = cityId; if (string.IsNullOrEmpty(houseDto.UnitNo) && string.IsNullOrEmpty(houseDto.HouseNo)) { house.UnitNo = houseDto.HouseName.Replace(houseDto.FloorNo.ToString(), "$"); } else { house.UnitNo = _houseService.SetHouseUnitNoAndHouseNo(house.UnitNo, houseDto.HouseNo); } //设置新增实体 if (houseDto.Valid == 0) { var hou = _unitOfWork.HouseRepository.GetBy(m => m.AppId == houseDto.AppId && m.BuildingId == eBuilding.BuildingId); if (hou != null) { _unitOfWork.HouseDetailsRepository.Delete(m => m.HouseId == hou.HouseId); _unitOfWork.HouseRepository.Delete(m => m.AppId == houseDto.AppId && m.BuildingId == eBuilding.BuildingId); } } else { House eHouse = eBuilding.Houses == null ? null : eBuilding.Houses.Where(m => m.AppId == houseDto.AppId && m.BuildingId == eBuilding.BuildingId && m.Valid == 1).FirstOrDefault(); if (eHouse == null) { house.CreateTime = nowTime; house.Creator = userName; eHouse = house; if (eBuilding.Houses == null) { eBuilding.Houses = new List <House>(); } eBuilding.Houses.Add(eHouse); } else { eHouse.BuildArea = house.BuildArea; eHouse.EndFloorNo = house.EndFloorNo; eHouse.FloorNo = house.FloorNo; eHouse.FrontCode = house.FrontCode; eHouse.HouseName = house.HouseName; eHouse.HouseTypeCode = house.HouseTypeCode; eHouse.NoiseCode = house.NoiseCode; eHouse.NominalFloor = house.NominalFloor; eHouse.PhotoName = house.PhotoName; eHouse.PurposeCode = house.PurposeCode; eHouse.Remark = house.Remark; eHouse.SightCode = house.SightCode; eHouse.Status = house.Status; eHouse.StructureCode = house.StructureCode; eHouse.UnitNo = house.UnitNo; eHouse.VDCode = house.VDCode; eHouse.SaveUser = userName; eHouse.SaveDateTime = nowTime; } //生成房号 if (house.EndFloorNo >= house.FloorNo) { string unitNo = _houseService.GetUnitNoByUnitNoStr(house.UnitNo); string houseNo = _houseService.GetHouseNoByUnitNoStr(house.UnitNo); for (int i = house.FloorNo; i <= house.EndFloorNo; i++) { housedetailcount++; List <int> cs = new List <int>() { SYSCodeManager.HOUSEPURPOSECODE_5, SYSCodeManager.HOUSEPURPOSECODE_6, SYSCodeManager.HOUSEPURPOSECODE_8, SYSCodeManager.HOUSEPURPOSECODE_27 }; HouseDetails detail = new HouseDetails(); detail = Mapper.Map <House, HouseDetails>(eHouse); detail.FloorNo = i; detail.NominalFloor = i.ToString(); detail.UnitNo = unitNo; detail.RoomNo = houseNo; detail.CreateTime = nowTime; detail.Creator = userName; if (detail.PurposeCode.HasValue && cs.Contains(detail.PurposeCode.Value)) { detail.HouseName = unitNo + houseNo; } else { if (i < 0) { detail.HouseName = "-" + unitNo + -i + houseNo; } else { detail.HouseName = unitNo + i + houseNo; } } if (i != 0) { if (eHouse.HouseDetails == null) { eHouse.HouseDetails = new List <HouseDetails>(); } var hd = eHouse.HouseDetails.Where(m => m.HouseId == detail.HouseId && m.RoomNo == houseNo && m.UnitNo == detail.UnitNo && m.FloorNo == detail.FloorNo).FirstOrDefault(); if (hd == null) { eHouse.HouseDetails.Add(detail); } else { hd.FloorNo = detail.FloorNo; hd.FrontCode = detail.FrontCode; hd.HouseName = detail.HouseName; hd.HouseTypeCode = detail.HouseTypeCode; hd.NoiseCode = detail.NoiseCode; hd.NominalFloor = detail.NominalFloor; hd.PurposeCode = detail.PurposeCode; hd.Remark = detail.Remark; hd.SightCode = detail.SightCode; hd.StructureCode = detail.StructureCode; hd.UnitNo = detail.UnitNo; hd.VDCode = detail.VDCode; hd.SaveUser = userName; hd.SaveDateTime = nowTime; } } } } } } } #endregion } swbs.Stop(); log.Info("循环一个楼栋需要" + swbs.Elapsed.TotalMilliseconds + "ms."); } } #endregion //更新任务 allotFlow.StateCode = SYSCodeManager.STATECODE_4; allotFlow.StateDate = nowTime; allotFlow.X = projectDto.X; allotFlow.Y = projectDto.Y; returnAllotId = allotFlow.Id; returnProjectId = allotFlow.Project.ProjectId; sw.Stop(); TimeSpan ts2 = sw.Elapsed; if (projectDto.BuildingDtolist != null) { log.Info("楼栋:" + projectDto.BuildingDtolist.Count + "条."); log.Info("单元室号:" + housecount + "条."); log.Info("房号:" + housedetailcount + "条."); } log.Info("循环操作总共花费" + ts2.TotalMilliseconds + "ms."); Stopwatch sw2 = new Stopwatch(); sw2.Start(); int r = _unitOfWork.Commit(); TimeSpan ts3 = sw2.Elapsed; log.Info("执行数据库操作总共花费" + ts3.TotalMilliseconds + "ms."); return(r); }
/// <summary> /// 新增任务 /// </summary> /// <param name="project">楼盘</param> /// <param name="developersCompany">开发商</param> /// <param name="managerCompany">物管公司</param> /// <returns>任务已存在返回任务状态,1.成功,0失败,-1未设置模板</returns> public ProjectAllotFlowSurveyDto AddAllot(Project project, string developersCompany, string managerCompany, string remark, int cityId, int fxtCompanyId, string userName, string userTrueName, int status) { ProjectAllotFlowSurveyDto dto = new ProjectAllotFlowSurveyDto(); DateTime now = DateTime.Now; //模板 var templet = _unitOfWork.TempletRepository.GetBy(m => m.FxtCompanyId == fxtCompanyId && m.DatType == SYSCodeManager.DATATYPECODE_1 && m.IsCurrent == true && m.Vaild == 1); if (templet == null) { dto.AllotState = -1; return(dto); } project.CityID = cityId; project.Status = status; project.FxtCompanyId = fxtCompanyId; project.CreateTime = now; project.Creator = userName; project.Valid = 1; project.TempletId = templet.TempletId; project = _unitOfWork.ProjectRepository.Insert(project); _unitOfWork.Commit(); //任务 var allot = new AllotFlow() { CityId = project.CityID, CreateTime = now, DatType = SYSCodeManager.DATATYPECODE_1, FxtCompanyId = project.FxtCompanyId.Value, UserName = userName, UserTrueName = userTrueName, StateCode = status, DatId = project.ProjectId, StateDate = now, SurveyUserName = status == SYSCodeManager.STATECODE_2 ? userName : "", SurveyUserTrueName = status == SYSCodeManager.STATECODE_2 ? userTrueName : "" }; allot = _unitOfWork.AllotFlowRepository.Insert(allot); _unitOfWork.Commit(); //任务记录 var allotSurvey = new AllotSurvey() { AllotId = allot.Id, CityId = allot.CityId, FxtCompanyId = fxtCompanyId, CreateDate = now, StateCode = status, StateDate = now, UserName = userName, TrueName = userTrueName, Remark = remark }; allotSurvey = _unitOfWork.AllotSurveyRepository.Insert(allotSurvey); //停车状况 var parkingStatus = _unitOfWork.P_AppendageRepository.Get(m => m.AppendageCode == SYSCodeManager.APPENDAGECODE_14 && m.CityId == project.CityID && m.ProjectId == project.ProjectId).FirstOrDefault(); if (parkingStatus != null) { parkingStatus.ClassCode = project.ParkingStatus; _unitOfWork.P_AppendageRepository.Update(parkingStatus); } else { parkingStatus = new PAppendage(); parkingStatus.ClassCode = project.ParkingStatus; parkingStatus.AppendageCode = SYSCodeManager.APPENDAGECODE_14; parkingStatus.CityId = project.CityID; parkingStatus.ProjectId = project.ProjectId; parkingStatus.IsInner = true; _unitOfWork.P_AppendageRepository.Insert(parkingStatus); } //开发商 if (!string.IsNullOrEmpty(developersCompany)) { var developcompany = _unitOfWork.P_CompanyRepository.Get(m => m.CompanyName == developersCompany && m.CompanyType == SYSCodeManager.COMPANYTYPECODE_1 && m.ProjectId == project.ProjectId && m.CityId == project.CityID).FirstOrDefault(); if (developcompany == null) { developcompany = new PCompany(); developcompany.CityId = project.CityID; developcompany.CompanyName = developersCompany; developcompany.CompanyType = SYSCodeManager.COMPANYTYPECODE_1; developcompany.ProjectId = project.ProjectId; _unitOfWork.P_CompanyRepository.Insert(developcompany); } } //物管公司 if (!string.IsNullOrEmpty(managerCompany)) { var managercompany = _unitOfWork.P_CompanyRepository.Get(m => m.CompanyName == managerCompany && m.CompanyType == SYSCodeManager.COMPANYTYPECODE_4 && m.ProjectId == project.ProjectId && m.CityId == project.CityID).FirstOrDefault(); if (managercompany == null) { managercompany = new PCompany(); managercompany.CityId = project.CityID; managercompany.CompanyName = managerCompany; managercompany.CompanyType = SYSCodeManager.COMPANYTYPECODE_4; managercompany.ProjectId = project.ProjectId; _unitOfWork.P_CompanyRepository.Insert(managercompany); } } dto.AllotId = allot.Id; dto.ProjectId = project.ProjectId; dto.AllotState = _unitOfWork.Commit() > 0 ? 1 : 0; return(dto); }
public ActionResult Call(string ids, UserCenter_LoginUserInfo loginUserInfo) { string mes = string.Empty; try { List <CAS.Entity.DBEntity.DATProject> projectList = DataCenterProjectApi.GetProjectBuildingHouse(loginUserInfo.NowCityId, ids, loginUserInfo.UserName, loginUserInfo.SignName, loginUserInfo.AppList); //log.Info("数据中心楼盘:" + projectList.Count); if (projectList != null && projectList.Count > 0) { foreach (var item in projectList) { //行政区 + 楼盘名称||已有的projectid||没有入库 var exists = _unitOfWork.ProjectRepository.Get(m => (m.ProjectName == item.projectname || m.ProjectName == item.areaname + item.projectname || m.FxtProjectId == item.projectid) && m.Status != SYSCodeManager.STATECODE_10 ).FirstOrDefault(); if (exists != null) { mes += item.projectname + ","; continue;//任务重复 } DateTime now = DateTime.Now; //楼盘 Project project = Mapper.Map <CAS.Entity.DBEntity.DATProject, Project>(item); project.FxtProjectId = item.projectid; project.FxtCompanyId = item.fxtcompanyid; project.Status = SYSCodeManager.STATECODE_1; project.ProjectId = 0; project.CreateTime = now; project.X = item.projectx; project.Y = item.projecty; project.Valid = 1; //_unitOfWork.ProjectRepository.Insert(project); project = _unitOfWork.ProjectRepository.Insert(project); _unitOfWork.Commit(); //任务 var allot = new AllotFlow() { CityId = project.CityID, CreateTime = now, DatType = SYSCodeManager.DATATYPECODE_1, FxtCompanyId = project.FxtCompanyId.Value, UserName = loginUserInfo.UserName, UserTrueName = loginUserInfo.TrueName, StateCode = SYSCodeManager.STATECODE_1, DatId = project.ProjectId, StateDate = now }; allot = _unitOfWork.AllotFlowRepository.Insert(allot); //_unitOfWork.Commit(); //任务记录 var allotSurvey = new AllotSurvey() { AllotId = allot.Id, CityId = allot.CityId, CreateDate = now, StateCode = SYSCodeManager.STATECODE_1, StateDate = now, UserName = loginUserInfo.UserName, TrueName = loginUserInfo.TrueName, Remark = "从调度中心(数据中心) <span class=\"red\">导入任务</span>" }; allotSurvey = _unitOfWork.AllotSurveyRepository.Insert(allotSurvey); //停车状况 var parkingStatus = _unitOfWork.P_AppendageRepository.Get(m => m.AppendageCode == SYSCodeManager.APPENDAGECODE_14 && m.CityId == project.CityID && m.ProjectId == project.ProjectId).FirstOrDefault(); if (parkingStatus != null) { parkingStatus.ClassCode = project.ParkingStatus; _unitOfWork.P_AppendageRepository.Update(parkingStatus); } else { parkingStatus = new PAppendage(); parkingStatus.ClassCode = project.ParkingStatus; parkingStatus.AppendageCode = SYSCodeManager.APPENDAGECODE_14; parkingStatus.CityId = project.CityID; parkingStatus.ProjectId = project.ProjectId; parkingStatus.IsInner = true; _unitOfWork.P_AppendageRepository.Insert(parkingStatus); } //开发商 if (!string.IsNullOrEmpty(item.devecompanyname)) { var developcompany = _unitOfWork.P_CompanyRepository.Get(m => m.CompanyName == item.devecompanyname && m.CompanyType == SYSCodeManager.COMPANYTYPECODE_1 && m.ProjectId == project.ProjectId && m.CityId == project.CityID).FirstOrDefault(); if (developcompany == null) { developcompany = new PCompany(); developcompany.CityId = project.CityID; developcompany.CompanyName = item.devecompanyname; developcompany.CompanyType = SYSCodeManager.COMPANYTYPECODE_1; developcompany.ProjectId = project.ProjectId; _unitOfWork.P_CompanyRepository.Insert(developcompany); } } //物管公司 if (!string.IsNullOrEmpty(item.managercompanyname)) { var managercompany = _unitOfWork.P_CompanyRepository.Get(m => m.CompanyName == item.managercompanyname && m.CompanyType == SYSCodeManager.COMPANYTYPECODE_4 && m.ProjectId == project.ProjectId && m.CityId == project.CityID).FirstOrDefault(); if (managercompany == null) { managercompany = new PCompany(); managercompany.CityId = project.CityID; managercompany.CompanyName = item.managercompanyname; managercompany.CompanyType = SYSCodeManager.COMPANYTYPECODE_4; managercompany.ProjectId = project.ProjectId; _unitOfWork.P_CompanyRepository.Insert(managercompany); } } } _unitOfWork.Commit(); } } catch (Exception ex) { log.Error(ex); } if (!string.IsNullOrEmpty(mes)) { //mes += "部分任务导入完成,楼盘:"; mes += ",不能重复导入。"; } return(Json(new { result = 1, message = mes })); }