123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using Bowin.Common.Linq.Entity;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading.Tasks;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel.Build;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- using Z.EntityFramework.Plus;
- using YLShipBuildLandMap.Entity.Extensions;
- namespace YLShipBuildLandMap.Services.Build
- {
- public class RoomService : IRoomService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public RoomService(YLShipBuildLandMapContext dbContext)
- {
- DbContext = dbContext;
- }
- private IQueryable<RoomView> GetRoomQuery(Expression<Func<BdBuildingFloorRoom, bool>> exp, Expression<Func<BdBuilding, bool>> expBuild)
- {
- var query = from b in DbContext.BdBuilding.Where(expBuild)
- join f in DbContext.BdBuildingFloor on b.BuildingId equals f.BuildingId
- join r in DbContext.BdBuildingFloorRoom.Where(exp) on f.BuildingFloorId equals r.BuildingFloorId
- select new RoomView
- {
- BuildingFloorRoomId = r.BuildingFloorRoomId,
- BuildingFloorId = r.BuildingFloorId,
- BuildingId = b.BuildingId,
- Name = r.Name,
- CreateTime = r.CreateTime,
- CreateUserId = r.CreateUserId,
- ModifyTime = r.ModifyTime,
- ModifyUserId = r.ModifyUserId,
- RecordStatus = r.RecordStatus,
- Sort = r.Sort,
- BuildingName = b.Name,
- FloorName = f.Name,
- FloorSort = f.Sort
- };
- return query;
- }
- public IGridResultSet<RoomView> GetRoomList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId)
- {
- Expression<Func<BdBuildingFloorRoom, bool>> exp = e => true;
- Expression<Func<BdBuilding, bool>> expBuild = e => true;
- exp = exp.AndIf(floorId.HasValue, e => e.BuildingFloorId == floorId);
- expBuild = expBuild.AndIf(buildingId.HasValue, e => e.BuildingId == buildingId);
- var query = GetRoomQuery(exp, expBuild).OrderBy(e => e.BuildingName).ThenBy(e => e.FloorSort).ThenBy(e => e.Name);
- return query.ToGridResultSet(pageIndex, pageSize);
- }
- public Task<RoomView> GetRoomById(Guid? roomId)
- {
- if (roomId.HasValue)
- {
- return Task.FromResult(GetRoomQuery(e => e.BuildingFloorRoomId == roomId, e => true).FirstOrDefault());
- }
- else
- {
- return Task.FromResult(new RoomView { BuildingFloorRoomId = Guid.NewGuid() });
- }
- }
- public async Task<int> Save(RoomView data, Guid? userId)
- {
- BdBuildingFloorRoom dbData = DbContext.BdBuildingFloorRoom.FirstOrDefault(e => e.BuildingFloorRoomId == data.BuildingFloorRoomId);
- if (dbData != null)
- {
- dbData.Name = data.Name;
- dbData.BuildingFloorId = data.BuildingFloorId;
- dbData.ModifyTime = DateTime.Now;
- dbData.ModifyUserId = userId;
- dbData.Sort = data.Sort;
- DbContext.BdBuildingFloorRoom.Update(dbData);
- }
- else
- {
- dbData = new BdBuildingFloorRoom
- {
- BuildingFloorRoomId = data.BuildingFloorRoomId,
- Name = data.Name,
- BuildingFloorId = data.BuildingFloorId,
- CreateTime = DateTime.Now,
- CreateUserId = userId,
- RecordStatus = 1,
- Sort = data.Sort
- };
- this.DbContext.Add(dbData);
- }
- return await this.DbContext.SaveChangesAsync();
- }
- public async Task<int> Delete(List<Guid> roomIdList)
- {
- await DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.Where(e => roomIdList.Contains(e.BuildingFloorRoomId)).DeleteAsync();
- await DbContext.BdBuildingFloorRoom.Where(e => roomIdList.Contains(e.BuildingFloorRoomId)).DeleteAsync();
- return await this.DbContext.SaveChangesAsync();
- }
- public Task<List<RoomDepOrServiceView>> GetRoomDepOrServiceList()
- {
- var query =
- from b in DbContext.BdBuilding
- join f in DbContext.BdBuildingFloor on b.BuildingId equals f.BuildingId
- join r in DbContext.BdBuildingFloorRoom on f.BuildingFloorId equals r.BuildingFloorId
- join rds in DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom on r.BuildingFloorRoomId equals rds.BuildingFloorRoomId
- join ds in DbContext.BdDepartmentOrServicePoint on rds.DepartmentOrServicePointId equals ds.DepartmentOrServicePointId
- select new RoomDepOrServiceView
- {
- BuildingId = b.BuildingId,
- BuildingName = b.Name,
- FloorName = f.Name,
- FloorSort = f.Sort,
- RoomName = r.Name,
- BuildingFloorId = r.BuildingFloorId,
- BuildingFloorRoomId = r.BuildingFloorRoomId,
- DepartmentOrServicePointId = ds.DepartmentOrServicePointId,
- DepartmentOrServiceName = ds.Name,
- Sort = r.Sort,
- OpenTime = ds.OpenTime,
- ContactType = ds.ContactType,
- Description = ds.Description
- };
- var list = query.OrderBy(e => e.BuildingName).ThenBy(e => e.FloorSort).ThenBy(e => e.FloorName).ThenBy(e => e.Sort).ThenBy(e => e.RoomName).ToList();
- var depOrServicePointIdList = list.Select(s => s.DepartmentOrServicePointId).ToList();
- var fileList = this.DbContext.SysAttachment.Where(e => depOrServicePointIdList.Contains((Guid)e.ReferenceId) && e.Type == 1).ToList();
- list.ForEach(item =>
- {
- item.ImgUrl = fileList.Where(e => e.ReferenceId == item.DepartmentOrServicePointId).FirstOrDefault()?.Url;
- });
- return Task.FromResult(list);
- }
- }
- }
|