123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using YLShipBuildLandMap.Entity;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Text;
- using System.Threading.Tasks;
- using Z.EntityFramework.Plus;
- using YLShipBuildLandMap.Entity.Extensions;
- using Bowin.Common.Linq.Entity;
- using YLShipBuildLandMap.Entity.ViewModel.Build;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- namespace YLShipBuildLandMap.Services.Build
- {
- public class DepOrServicePointService : IDepOrServicePointService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public DepOrServicePointService(YLShipBuildLandMapContext dbContext)
- {
- DbContext = dbContext;
- }
- private IQueryable<DepOrServicePointView> GetDepOrServicePointQuery(Expression<Func<BdDepartmentOrServicePoint, bool>> exp)
- {
- var query =
- from ds in DbContext.BdDepartmentOrServicePoint.Where(exp)
- /* join rds in DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom on ds.DepartmentOrServicePointId equals rds.DepartmentOrServicePointId into dbBdDepartmentOrServicePointBmBuildingFloorRoom
- from rds in dbBdDepartmentOrServicePointBmBuildingFloorRoom.DefaultIfEmpty()
- join r in DbContext.BdBuildingFloorRoom on rds.BuildingFloorRoomId equals r.BuildingFloorRoomId into dbRoom
- from r in dbRoom.DefaultIfEmpty()
- join f in DbContext.BdBuildingFloor on r.BuildingFloorId equals f.BuildingFloorId into dbFloor
- from f in dbFloor.DefaultIfEmpty()
- join b in DbContext.BdBuilding on f.BuildingId equals b.BuildingId into dbBuild
- from b in dbBuild.DefaultIfEmpty()*/
- join room in (
- 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
- select new
- {
- rds.DepartmentOrServicePointId,
- f.BuildingFloorId,
- FloorName = f.Name,
- b.BuildingId,
- BuildingName = b.Name,
- RoomName = r.Name,
- RoomSort = r.Sort,
- FloorSort = f.Sort
- }
- ) on ds.DepartmentOrServicePointId equals room.DepartmentOrServicePointId into dbBdDepartmentOrServicePointBmBuildingFloorRoom
- from rds in dbBdDepartmentOrServicePointBmBuildingFloorRoom.DefaultIfEmpty()
- group new { rds.RoomName, rds.RoomSort } by new
- {
- ds.DepartmentOrServicePointId,
- ds.Name,
- ds.OpenTime,
- ds.ContactType,
- ds.Description,
- ds.RecordStatus,
- ds.CreateUserId,
- ds.CreateTime,
- ds.ModifyTime,
- ds.ModifyUserId,
- rds.FloorName,
- rds.BuildingName,
- rds.BuildingId,
- rds.BuildingFloorId,
- rds.FloorSort
- } into g
- select new DepOrServicePointView
- {
- DepartmentOrServicePointId = g.Key.DepartmentOrServicePointId,
- Name = g.Key.Name,
- OpenTime = g.Key.OpenTime,
- ContactType = g.Key.ContactType,
- Description = g.Key.Description,
- RecordStatus = g.Key.RecordStatus,
- CreateUserId = g.Key.CreateUserId,
- CreateTime = g.Key.CreateTime,
- ModifyTime = g.Key.ModifyTime,
- ModifyUserId = g.Key.ModifyUserId,
- BuildingName = g.Key.BuildingName,
- BuildingId = g.Key.BuildingId,
- FloorName = g.Key.FloorName,
- FloorId = g.Key.BuildingFloorId,
- /* RoomName = string.Join("、", g.Select(s => s.RoomName).ToList())*/
- Sort = g.Min(s => s.RoomSort),
- FloorSort = g.Key.FloorSort
- };
- return query;
- }
- private IQueryable<DepOrServicePointRoomView> GetDepOrServicePointRoomQuery(Expression<Func<BdDepartmentOrServicePoint, bool>> exp)
- {
- var query =
- from ds in DbContext.BdDepartmentOrServicePoint
- join rds in DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom on ds.DepartmentOrServicePointId equals rds.DepartmentOrServicePointId
- join r in DbContext.BdBuildingFloorRoom on rds.BuildingFloorRoomId equals r.BuildingFloorRoomId
- join f in DbContext.BdBuildingFloor on r.BuildingFloorId equals f.BuildingFloorId
- join b in DbContext.BdBuilding on f.BuildingId equals b.BuildingId
- select new DepOrServicePointRoomView
- {
- DepartmentOrServicePointId = ds.DepartmentOrServicePointId,
- FloorId = f.BuildingFloorId,
- RoomName = r.Name,
- RoomSort = r.Sort
- };
- return query;
- }
- public IGridResultSet<DepOrServicePointView> GetDepOrServicePointList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId, string name)
- {
- Expression<Func<BdDepartmentOrServicePoint, bool>> exp = e => true;
- Expression<Func<BdBuilding, bool>> expBuild = e => true;
- Expression<Func<BdBuildingFloor, bool>> expFloor = e => true;
- exp = exp.AndIf(!string.IsNullOrEmpty(name), e => e.Name.Contains(name.Trim()));
- expFloor = expFloor.AndIf(floorId.HasValue, e => e.BuildingFloorId == floorId);
- expBuild = expBuild.AndIf(buildingId.HasValue, e => e.BuildingId == buildingId);
- var query = GetDepOrServicePointQuery(exp)
- .WhereIf(floorId.HasValue, e => e.FloorId == floorId)
- .WhereIf(buildingId.HasValue, e => e.BuildingId == buildingId)
- .OrderBy(e => e.BuildingName).ThenBy(e => e.FloorSort).ThenBy(e => e.Sort).ThenBy(e => e.Name);
- var dataResult = query.ToGridResultSet(pageIndex, pageSize);
- var depOrServicePointIdList = dataResult.rows.Select(s => s.DepartmentOrServicePointId).ToList();
- var roomList = GetDepOrServicePointRoomQuery(e => depOrServicePointIdList.Contains(e.DepartmentOrServicePointId)).ToList();
- var fileList = this.DbContext.SysAttachment.Where(e => depOrServicePointIdList.Contains((Guid)e.ReferenceId) && e.Type == 1).ToList();
- dataResult.rows.ForEach(item =>
- {
- item.RoomName = string.Join("、", roomList.Where(e => e.DepartmentOrServicePointId == item.DepartmentOrServicePointId && e.FloorId == item.FloorId).OrderBy(e => e.RoomSort).ThenBy(e => e.RoomName).Select(s => s.RoomName).ToList());
- item.ImgUrl = fileList.Where(e => e.ReferenceId == item.DepartmentOrServicePointId).FirstOrDefault()?.Url;
- });
- return dataResult;
- }
- public Task<DepOrServicePointView> GetDepOrServicePointById(Guid? depOrServicePointId)
- {
- if (depOrServicePointId.HasValue)
- {
- return Task.FromResult(GetDepOrServicePointQuery(e => e.DepartmentOrServicePointId == depOrServicePointId).FirstOrDefault());
- }
- else
- {
- return Task.FromResult(new DepOrServicePointView { DepartmentOrServicePointId = Guid.NewGuid() });
- }
- }
- public async Task<int> Save(DepOrServicePointView data, List<Guid> roomIdList, Guid? userId)
- {
- BdDepartmentOrServicePoint dbData = DbContext.BdDepartmentOrServicePoint.FirstOrDefault(e => e.DepartmentOrServicePointId == data.DepartmentOrServicePointId);
- if (dbData != null)
- {
- dbData.Name = data.Name;
- dbData.Description = data.Description;
- dbData.OpenTime = data.OpenTime;
- dbData.ModifyTime = DateTime.Now;
- dbData.ModifyUserId = userId;
- dbData.ContactType = data.ContactType;
- DbContext.BdDepartmentOrServicePoint.Update(dbData);
- }
- else
- {
- dbData = new BdDepartmentOrServicePoint
- {
- DepartmentOrServicePointId = data.DepartmentOrServicePointId,
- Name = data.Name,
- OpenTime = data.OpenTime,
- Description = data.Description,
- CreateTime = DateTime.Now,
- CreateUserId = userId,
- RecordStatus = 1,
- ContactType = data.ContactType
- };
- this.DbContext.Add(dbData);
- }
- await DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.Where(e => dbData.DepartmentOrServicePointId == e.DepartmentOrServicePointId).DeleteAsync();
- this.DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.AddRange(roomIdList.Select(s => new BdDepartmentOrServicePointBmBuildingFloorRoom
- {
- BuildingFloorRoomId = s,
- DepartmentOrServicePointId = dbData.DepartmentOrServicePointId
- }).ToList());
- return await this.DbContext.SaveChangesAsync();
- }
- public async Task<int> Delete(List<Guid> depOrServicePointIdList)
- {
- await DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.Where(e => depOrServicePointIdList.Contains(e.DepartmentOrServicePointId)).DeleteAsync();
- await DbContext.BdDepartmentOrServicePoint.Where(e => depOrServicePointIdList.Contains(e.DepartmentOrServicePointId)).DeleteAsync();
- return await this.DbContext.SaveChangesAsync();
- }
- public Task<List<RoomView>> GetRoomList(Guid depOrServicePointId)
- {
- 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 deppoint in DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom on r.BuildingFloorRoomId equals deppoint.BuildingFloorRoomId
- where deppoint.DepartmentOrServicePointId == depOrServicePointId
- 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 Task.FromResult(query.OrderBy(e => e.BuildingName).ThenBy(e => e.FloorSort).ThenBy(e => e.Name).ToList());
- }
- }
- }
|