Browse Source

部门服务点管理

pengjing 1 year ago
parent
commit
4d1efe44f2

+ 10 - 0
YLShipBuildLandMap.Entity/ViewModel/Build/DepOrServicePointView.cs

@@ -6,8 +6,18 @@ namespace YLShipBuildLandMap.Entity.ViewModel.Build
 {
     public class DepOrServicePointView:BdDepartmentOrServicePoint
     {
+        public Guid? BuildingId { get; set; }
         public string BuildingName { get; set; }
+        public Guid? FloorId { get; set; }
         public string FloorName { get; set; }
         public string RoomName { get; set; }
     }
+
+    public class DepOrServicePointRoomView
+    {
+        public Guid DepartmentOrServicePointId { get; set; }
+        public Guid? FloorId { get; set; }
+        public string RoomName { get; set; }
+        public int? RoomSort { get; set; }
+    }
 }

+ 3 - 1
YLShipBuildLandMap.IServices/Build/IDepOrServicePointService.cs

@@ -9,7 +9,7 @@ namespace YLShipBuildLandMap.Services.Build
 {
     public interface IDepOrServicePointService
     {
-        IGridResultSet<DepOrServicePointView> GetDepOrServicePointList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId);
+        IGridResultSet<DepOrServicePointView> GetDepOrServicePointList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId, string name);
 
         Task<DepOrServicePointView> GetDepOrServicePointById(Guid? depOrServicePointId);
 
@@ -17,5 +17,7 @@ namespace YLShipBuildLandMap.Services.Build
 
         Task<int> Delete(List<Guid> depOrServicePointIdList);
 
+        Task<List<RoomView>> GetRoomList(Guid depOrServicePointId);
+
     }
 }

+ 135 - 13
YLShipBuildLandMap.Services/Build/DepOrServicePointService.cs

@@ -10,6 +10,9 @@ 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
 {
@@ -23,37 +26,126 @@ namespace YLShipBuildLandMap.Services.Build
 
         }
 
-        private IQueryable<DepOrServicePointView> GetDepOrServicePointQuery(Expression<Func<BdDepartmentOrServicePoint, bool>> exp, Expression<Func<BdBuilding, bool>> expBuild, Expression<Func<BdBuildingFloor, bool>> expFloor)
+        private IQueryable<DepOrServicePointView> GetDepOrServicePointQuery(Expression<Func<BdDepartmentOrServicePoint, bool>> exp)
         {
-            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 DepOrServicePointView { };
+            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
+                     }
+                ) on ds.DepartmentOrServicePointId equals room.DepartmentOrServicePointId into dbBdDepartmentOrServicePointBmBuildingFloorRoom
+                from rds in dbBdDepartmentOrServicePointBmBuildingFloorRoom.DefaultIfEmpty()
+                group new { rds.RoomName } 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
+                } 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())*/
+                };
+
+            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)
+        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, expBuild, expFloor).OrderBy(e => e.BuildingName).ThenBy(e => e.FloorName).ThenBy(e => e.RoomName);
+            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.FloorName).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();
 
-            return query.ToGridResultSet(pageIndex, pageSize);
+            dataResult.rows.ForEach(item =>
+            {
+                item.RoomName = string.Join("、", roomList.Where(e => e.DepartmentOrServicePointId == item.DepartmentOrServicePointId && e.FloorId == item.FloorId).OrderBy(e => e.RoomSort).Select(s => s.RoomName).ToList());
+            });
+
+            return dataResult;
         }
 
         public Task<DepOrServicePointView> GetDepOrServicePointById(Guid? depOrServicePointId)
         {
             if (depOrServicePointId.HasValue)
             {
-                return Task.FromResult(GetDepOrServicePointQuery(e => e.DepartmentOrServicePointId == depOrServicePointId, e => true, e => true).FirstOrDefault());
+                return Task.FromResult(GetDepOrServicePointQuery(e => e.DepartmentOrServicePointId == depOrServicePointId).FirstOrDefault());
             }
             else
             {
@@ -72,6 +164,7 @@ namespace YLShipBuildLandMap.Services.Build
                 dbData.OpenTime = data.OpenTime;
                 dbData.ModifyTime = DateTime.Now;
                 dbData.ModifyUserId = userId;
+                dbData.ContactType = data.ContactType;
                 DbContext.BdDepartmentOrServicePoint.Update(dbData);
             }
             else
@@ -85,7 +178,8 @@ namespace YLShipBuildLandMap.Services.Build
                     Description = data.Description,
                     CreateTime = DateTime.Now,
                     CreateUserId = userId,
-                    RecordStatus = 1
+                    RecordStatus = 1,
+                    ContactType = data.ContactType
                 };
 
                 this.DbContext.Add(dbData);
@@ -93,7 +187,7 @@ namespace YLShipBuildLandMap.Services.Build
 
             await DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.Where(e => dbData.DepartmentOrServicePointId == e.DepartmentOrServicePointId).DeleteAsync();
 
-            this.DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.AddRange(roomIdList.Select(s => new BdDepartmentOrServicePointBmBuildingFloorRoom 
+            this.DbContext.BdDepartmentOrServicePointBmBuildingFloorRoom.AddRange(roomIdList.Select(s => new BdDepartmentOrServicePointBmBuildingFloorRoom
             {
                 BuildingFloorRoomId = s,
                 DepartmentOrServicePointId = dbData.DepartmentOrServicePointId
@@ -110,5 +204,33 @@ namespace YLShipBuildLandMap.Services.Build
             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());
+        }
+
+
     }
 }

+ 9 - 2
YLShipBuildLandMap.Web/Controllers/Build/DepOrServiceController.cs

@@ -24,9 +24,9 @@ namespace YLShipBuildLandMap.Web.Controllers.Build
         }
 
         [HttpGet]
-        public async Task<ResultMessage> GetDepOrServicePointList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId)
+        public async Task<ResultMessage> GetDepOrServicePointList(int pageIndex, int pageSize, Guid? buildingId, Guid? floorId,string name)
         {
-            return ResultMessage.Success(DepOrServicePointService.GetDepOrServicePointList(pageIndex, pageSize, buildingId, floorId));
+            return ResultMessage.Success(DepOrServicePointService.GetDepOrServicePointList(pageIndex, pageSize, buildingId, floorId, name));
         }
 
         [HttpGet]
@@ -52,5 +52,12 @@ namespace YLShipBuildLandMap.Web.Controllers.Build
 
             return ResultMessage.Success(await DepOrServicePointService.Save(data, roomIdList, LoginUser.Current.UserID));
         }
+
+
+        [HttpGet]
+        public async Task<ResultMessage> GetRoomList(Guid depOrServicePointId)
+        {
+            return ResultMessage.Success(await DepOrServicePointService.GetRoomList(depOrServicePointId));
+        }
     }
 }

+ 2 - 2
YLShipBuildLandMap.Web/wwwroot/app/main/depOrService/edit.html

@@ -61,9 +61,9 @@
                                         <td class="text-center">{{$index+1}}</td>
                                         <td>{{it.BuildingName}}</td>
                                         <td>{{it.FloorName}}</td>
-                                        <td>{{it.RoomName}}</td>
+                                        <td>{{it.Name}}</td>
                                         <td class="text-center">
-                                            <i class="glyphicon glyphicon-trash" ng-click="delete($index)"></i>
+                                            <i class="glyphicon glyphicon-trash" ng-click="deleteRoom($index)"></i>
                                         </td>
                                     </tr>
                                 </tbody>

+ 23 - 38
YLShipBuildLandMap.Web/wwwroot/app/main/depOrService/edit.js

@@ -2,8 +2,6 @@
     $scope.params = editDepOrServiceModal.params;
     $scope.parentLoad = editDepOrServiceModal.parentLoad;
     $scope.dataModel = { BuildingId: null };
-    $scope.buildingList = [];
-    $scope.floorList = [];
     $scope.roomList = [];
 
     $scope.loadData = function () {
@@ -17,8 +15,7 @@
         }).then(function (result) {
             $loading.hide();
             $scope.dataModel = result.data.Data;
-            $scope.getBuildingList();
-            $scope.getFloorList();
+            $scope.getRoomList();
 
         }, function (resp) {
             $loading.hide();
@@ -26,38 +23,6 @@
         });
     }
 
-    $scope.getBuildingList = function () {
-        $http({
-            method: "get",
-            url: "../../api/build/building/GetBuildingList",
-            params: {
-
-            }
-        }).then(function (result) {
-            $scope.buildingList = result.data.Data;
-
-        }, function (resp) {
-        });
-    };
-
-    $scope.getFloorList = function () {
-        if ($scope.dataModel.BuildingId) {
-            $http({
-                method: "get",
-                url: "../../api/build/building/GetFloorList",
-                params: {
-                    buildingId: $scope.dataModel.BuildingId
-                }
-            }).then(function (result) {
-                $scope.floorList = result.data.Data;
-
-            }, function (resp) {
-            });
-        }
-        else {
-            $scope.floorList = [];
-        }
-    };
 
     $scope.save = function (isflag) {
         if (!isflag) {
@@ -65,12 +30,14 @@
             return false;
         }
         if (isflag) {
+            var roomIds = $.map($filter('filter')($scope.roomList, { }), function (x) { return x.BuildingFloorRoomId; });
             $loading.show();
             $http({
                 method: "post",
-                url: "../../api/build/room/Save",
+                url: "../../api/build/DepOrService/Save",
                 data: {
-                    data: $scope.dataModel
+                    data: $scope.dataModel,
+                    roomIdList: roomIds
                 }
             }).then(function (result) {
                 $loading.hide();
@@ -120,6 +87,24 @@
         selectRoomModal.$promise.then(selectRoomModal.show);
     };
 
+    $scope.deleteRoom = function (index) {
+        $scope.roomList.splice(index, 1);
+    }
+
+    $scope.getRoomList = function () {
+        $http({
+            method: "get",
+            url: "../../api/build/DepOrService/GetRoomList",
+            params: {
+                depOrServicePointId: $scope.dataModel.DepartmentOrServicePointId
+            }
+        }).then(function (result) {
+            $scope.roomList = result.data.Data;
+
+        }, function (resp) {
+        });
+    };
+
     $scope.loadData();
 
 };

+ 6 - 5
YLShipBuildLandMap.Web/wwwroot/app/main/depOrService/list.html

@@ -45,7 +45,7 @@
                                 <div class="form-line">
                                     <input type="text" class="form-control" name="name"
                                            ng-model="selectparams.name"
-                                           placeholder="" ng-keypress="search()" />
+                                           placeholder="" />
                                 </div>
                             </div>
                         </div>
@@ -77,10 +77,11 @@
                     <tr>
                         <th class="th-select" th-select-all datalist="dataList"></th>
                         <th class="th-rownum">序号</th>
-                        <th>部门/服务点名称</th>
-                        <th>房间</th>
                         <th>大楼</th>
                         <th>楼层</th>
+                        <th>部门/服务点名称</th>
+                        <th>房间</th>
+
                         <th class="col-md-1">操作</th>
                     </tr>
                 </thead>
@@ -90,10 +91,10 @@
                             <input type="checkbox" ng-model="it.rowChecked" />
                         </td>
                         <td class="text-center" td-rownum index="$index" pageindex="selectparams.pageIndex" pagesize="selectparams.pageSize"></td>
-                        <td class="text-center">{{it.Name}}</td>
-                        <td class="text-center">{{it.RoomName}}</td>
                         <td class="text-center">{{it.BuildingName}}</td>
                         <td class="text-center">{{it.FloorName}}</td>
+                        <td class="text-center">{{it.Name}}</td>
+                        <td class="text-center">{{it.RoomName}}</td>
                         <td class="text-center">
                             <i class="glyphicon glyphicon-pencil" ng-click="edit(it.DepartmentOrServicePointId)"></i>
                         </td>

+ 3 - 2
YLShipBuildLandMap.Web/wwwroot/app/main/depOrService/selectRoom.html

@@ -87,7 +87,7 @@
                                                 <td class="text-center">
                                                     <input type="checkbox" ng-model="it.rowChecked" />
                                                 </td>
-                                                <td class="text-center" td-rownum index="$index" pageindex="selectparams.pageindex" pagesize="selectparams.pagesize"></td>
+                                                <td class="text-center" td-rownum index="$index" pageindex="selectparams.pageIndex" pagesize="selectparams.pageSize"></td>
                                                 <td class="text-center">{{it.BuildingName}}</td>
                                                 <td class="text-center">{{it.FloorName}}</td>
                                                 <td class="text-center">{{it.Name}}</td>
@@ -98,7 +98,7 @@
                                         </tbody>
                                     </table>
                                 </div>
-                                <pagination data-pageindex="selectparams.pageindex" data-pagesize="selectparams.pagesize"
+                                <pagination data-pageindex="selectparams.pageIndex" data-pagesize="selectparams.pageSize"
                                             data-ptotal="pageInfo.ptotal"></pagination>
                             </div>
                         </div>
@@ -122,6 +122,7 @@
                                                 <th>大楼</th>
                                                 <th>楼层</th>
                                                 <th>房间</th>
+                                                <th>操作</th>
                                             </tr>
                                         </thead>
                                         <tbody>