Переглянути джерело

Merge branch 'master' of http://49.4.53.36:3000/hotel/hotel-saas-backend

qh 2 роки тому
батько
коміт
47d8dd1ba8

+ 17 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/DTO/CesRoomBuildingFloorDto.java

@@ -0,0 +1,17 @@
+package org.jeecg.modules.rooms.DTO;
+
+import lombok.Data;
+
+@Data
+public class CesRoomBuildingFloorDto {
+    private String id;
+
+    private String hotelId;
+
+    private String parentId;
+
+    private String name;
+
+    private Integer type;
+
+}

+ 41 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/Enum/CouponEnums.java

@@ -83,6 +83,47 @@ public class CouponEnums {
 		}
 	}
 
+	/**
+	 * 楼栋楼层 枚举
+	 */
+	public static enum RoomBuildingFloorTypeEnum {
+		BUILDING(1,"楼栋"), FLOOR(2,"楼层");
+
+		int code = 0;
+		String value = "";
+
+		private RoomBuildingFloorTypeEnum(int code,String value){
+			this.code = code;
+			this.value = value;
+		}
+
+		public int code(){
+			return code;
+		}
+
+		public String getValue(){
+			return value;
+		}
+
+		//根据CODE获取类型
+		public static RoomBuildingFloorTypeEnum val(int vcode){
+			for(RoomBuildingFloorTypeEnum bld: values()){
+				if(bld.code == vcode){
+					return bld;
+				}
+			}
+			return FLOOR;
+		}
+
+		public static RoomBuildingFloorTypeEnum val(String value){
+			for(RoomBuildingFloorTypeEnum bld : values()){
+				if(bld.value.equals(value)){
+					return bld;
+				}
+			}
+			return FLOOR;
+		}
+	}
 
 
 }

+ 83 - 4
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/controller/CesRoomBuildingFloorController.java

@@ -1,22 +1,24 @@
 package org.jeecg.modules.rooms.controller;
 
 
+import cn.hutool.core.util.EnumUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.Enum.ResultCode;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.modules.rooms.DTO.CesRoomBuildingFloorDto;
+import org.jeecg.modules.rooms.Enum.CouponEnums;
 import org.jeecg.modules.rooms.entity.CesRoomBuildingFloor;
 import org.jeecg.modules.rooms.service.CesRoomBuildingFloorServiceImpl;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.*;
 
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * <p>
@@ -48,5 +50,82 @@ public class CesRoomBuildingFloorController {
         }
     }
 
+    @AutoLog(value = "创建楼栋或者楼层")
+    @ApiOperation(value="创建楼栋或者楼层", notes="创建楼栋或者楼层")
+    @PostMapping(value = "/save")
+    public Result save(@RequestBody  CesRoomBuildingFloorDto dto){
+        if(StringUtils.isBlank(dto.getHotelId())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(StringUtils.isBlank(dto.getParentId())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(StringUtils.isBlank(dto.getName())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(dto.getType() != null && dto.getType().intValue() != 0){
+            List<Object> codes = EnumUtil.getFieldValues(CouponEnums.RoomBuildingFloorTypeEnum.class, "code");
+            if(!codes.contains(dto.getType().intValue())){
+                return Result.error("参数不正确!请选择正确的类型!");
+            }
+        }else{
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        try{
+            return buildingFloorService.create(dto);
+        }catch (Exception e){
+            return Result.error(e.getMessage());
+        }
+    }
+
+    @AutoLog(value = "修改楼栋或者楼层")
+    @ApiOperation(value="修改楼栋或者楼层", notes="修改楼栋或者楼层")
+    @PutMapping(value = "/modify")
+    public Result modify(@RequestBody CesRoomBuildingFloorDto dto){
+        if(StringUtils.isBlank(dto.getId())){
+            return Result.error(ResultCode.PARAM_MISS,"数据ID 必传!");
+        }
+        if(StringUtils.isBlank(dto.getHotelId())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(StringUtils.isBlank(dto.getParentId())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(StringUtils.isBlank(dto.getName())){
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        if(dto.getType() != null && dto.getType().intValue() != 0){
+            List<Object> codes = EnumUtil.getFieldValues(CouponEnums.RoomBuildingFloorTypeEnum.class, "code");
+            if(!codes.contains(dto.getType().intValue())){
+                return Result.error("参数不正确!请选择正确的类型!");
+            }
+        }else{
+            return Result.error(ResultCode.PARAM_MISS);
+        }
+        try{
+            return buildingFloorService.modify(dto);
+        }catch (Exception e){
+            return Result.error(e.getMessage());
+        }
+    }
+
+
+    @AutoLog(value = "删除楼栋或者楼层")
+    @ApiOperation(value="删除楼栋或者楼层", notes="删除楼栋或者楼层")
+    @DeleteMapping(value = "/delete")
+    public Result delete(@RequestBody CesRoomBuildingFloorDto dto){
+        if(StringUtils.isBlank(dto.getId())){
+            return Result.error(ResultCode.PARAM_MISS,"数据ID 必传!");
+        }
+        try{
+            return buildingFloorService.delete(dto);
+        }catch (Exception e){
+            return Result.error(e.getMessage());
+        }
+    }
+
+
+
+
 }
 

+ 86 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/rooms/service/CesRoomBuildingFloorServiceImpl.java

@@ -1,18 +1,24 @@
 package org.jeecg.modules.rooms.service;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.tree.Tree;
 import cn.hutool.core.lang.tree.TreeNode;
 import cn.hutool.core.lang.tree.TreeUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.rooms.DTO.CesRoomBuildingFloorDto;
+import org.jeecg.modules.rooms.Enum.CouponEnums;
 import org.jeecg.modules.rooms.entity.CesRoomBuildingFloor;
 import org.jeecg.modules.rooms.mapper.CesRoomBuildingFloorMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -48,4 +54,84 @@ public class CesRoomBuildingFloorServiceImpl extends ServiceImpl<CesRoomBuilding
     }
 
 
+    /**
+     * 创建楼栋或者楼层
+     * @param floorDto
+     * @return
+     */
+    public Result create(CesRoomBuildingFloorDto floorDto){
+        QueryWrapper<CesRoomBuildingFloor> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(CesRoomBuildingFloor.HOTELID,floorDto.getHotelId());
+        queryWrapper.eq(CesRoomBuildingFloor.TYPE, floorDto.getType().intValue());
+        queryWrapper.eq(CesRoomBuildingFloor.NAME,floorDto.getName());
+        if(CouponEnums.RoomBuildingFloorTypeEnum.FLOOR.code() == floorDto.getType().intValue()){
+            queryWrapper.eq(CesRoomBuildingFloor.PARENT_ID, floorDto.getParentId());
+        }
+       List<CesRoomBuildingFloor> floorList =  buildingFloorMapper.selectList(queryWrapper);
+        if(!CollectionUtil.isEmpty(floorList)) return Result.error("该名称已有!");
+        CesRoomBuildingFloor buildingFloor = new CesRoomBuildingFloor();
+        buildingFloor.setName(floorDto.getName());
+        buildingFloor.setHotelId(floorDto.getHotelId());
+        buildingFloor.setParentId(floorDto.getParentId());
+        buildingFloor.setType(floorDto.getType());
+        buildingFloor.setCreateAt(LocalDateTime.now());
+        buildingFloor.setUpdateAt(LocalDateTime.now());
+        buildingFloor.setInvalid(false);
+        buildingFloorMapper.insert(buildingFloor);
+        return Result.OK("创建成功!");
+    }
+
+
+    /**
+     * 修改楼层或者楼栋
+     * @param floorDto
+     * @return
+     */
+    public Result modify(CesRoomBuildingFloorDto floorDto){
+        QueryWrapper<CesRoomBuildingFloor> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(CesRoomBuildingFloor.HOTELID,floorDto.getHotelId());
+        queryWrapper.eq(CesRoomBuildingFloor.TYPE, floorDto.getType().intValue());
+        queryWrapper.eq(CesRoomBuildingFloor.NAME,floorDto.getName());
+        if(CouponEnums.RoomBuildingFloorTypeEnum.FLOOR.code() == floorDto.getType().intValue()){
+            queryWrapper.eq(CesRoomBuildingFloor.PARENT_ID, floorDto.getParentId());
+        }
+        queryWrapper.ne(CesRoomBuildingFloor.ID,floorDto.getId());
+
+        List<CesRoomBuildingFloor> floorList =  buildingFloorMapper.selectList(queryWrapper);
+        if(!CollectionUtil.isEmpty(floorList)) return Result.error("该名称已有!");
+        CesRoomBuildingFloor  cesRoomBuildingFloor =  buildingFloorMapper.selectById(floorDto.getId());
+        if(ObjectUtils.isEmpty(cesRoomBuildingFloor)) return Result.error("该楼层或者楼栋未找到!");
+
+        cesRoomBuildingFloor.setName(floorDto.getName());
+        cesRoomBuildingFloor.setUpdateAt(LocalDateTime.now());
+        buildingFloorMapper.updateById(cesRoomBuildingFloor);
+        return Result.OK("修改成功!");
+    }
+
+
+    /**
+     * 删除楼栋或者楼层
+     * @param floorDto
+     * @return
+     */
+    public Result delete(CesRoomBuildingFloorDto floorDto){
+        CesRoomBuildingFloor  cesRoomBuildingFloor =  buildingFloorMapper.selectById(floorDto.getId());
+        if(ObjectUtils.isEmpty(cesRoomBuildingFloor)) return Result.error("该楼层或者楼栋未找到!");
+
+       List<CesRoomBuildingFloor> children = buildingFloorMapper.selectList(Wrappers.<CesRoomBuildingFloor>lambdaQuery()
+                .eq(CesRoomBuildingFloor::getParentId,cesRoomBuildingFloor.getId())
+                .eq(CesRoomBuildingFloor::getInvalid,false)
+        );
+
+       if(!ObjectUtils.isEmpty(children)) return Result.error("该楼栋下还有楼栋数据,请全部删除后再删除楼栋!");
+
+        cesRoomBuildingFloor.setInvalid(true);
+        cesRoomBuildingFloor.setUpdateAt(LocalDateTime.now());
+        buildingFloorMapper.updateById(cesRoomBuildingFloor);
+
+        return Result.ok("删除成功!");
+    }
+
+
+
 }