# HkInventoryRoomTypeConfigController.java

    package cloud.wconnect.workperformance.controller.hkinventory;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.workperformance.entity.hkinventory.HkInventoryRoomTypeConfig;
    import cloud.wconnect.workperformance.pojo.dto.hkinventory.HkInventoryRoomTypeConfigDTO;
    import cloud.wconnect.workperformance.pojo.query.hkinventory.HkInventoryRoomTypeConfigQuery;
    import cloud.wconnect.workperformance.pojo.vo.hkinventory.HkInventoryRoomTypeConfigVO;
    import cloud.wconnect.workperformance.service.hkinventory.IHkInventoryRoomTypeConfigService;
    import com.google.common.collect.ImmutableMap;
    import jakarta.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import java.util.Collections;
    import java.util.List;
    import java.util.Map;

    /**
     * 客房库存管理-房型配置控制层
     *
     * @author lichen
     * @date 2025/4/21
     */
    @RestController
    @RequestMapping("/hk-inventory/room-type-config")
    public class HkInventoryRoomTypeConfigController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IHkInventoryRoomTypeConfigService roomTypeConfigService;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 查询房型配置
         *
         * @param property                       资产标识
         * @param hkInventoryRoomTypeConfigQuery 房型配置查询对象
         * @return java.util.List<cloud.wconnect.workperformance.pojo.vo.hkinventory.HkInventoryRoomTypeVO>
         * @author lichen
         * @date 2025/4/21
         */
        @ApiId(1419)
        @GetMapping
        public List<HkInventoryRoomTypeConfigVO> list(String property, HkInventoryRoomTypeConfigQuery hkInventoryRoomTypeConfigQuery) {
            int propertyId = sessionContext.getPropertyId(property);
            List<HkInventoryRoomTypeConfig> roomTypeConfigList = roomTypeConfigService.listByName(propertyId,
                    hkInventoryRoomTypeConfigQuery.getRoomTypeName());
            return beanMapper.mapList(roomTypeConfigList, HkInventoryRoomTypeConfigVO.class);
        }

        /**
         * 保存房型配置
         *
         * @param property                     资产标识
         * @param roomTypeId                   房型配置id
         * @param hkInventoryRoomTypeConfigDTO 房型配置DTO
         * @return java.util.Map<java.lang.String, java.lang.Integer>
         * @author lichen
         * @date 2025/4/21
         */
        @ApiId(1420)
        @PostMapping("/{roomTypeId:\\d+}")
        public Map<String, Integer> save(String property, @PathVariable Integer roomTypeId, @RequestBody @Valid HkInventoryRoomTypeConfigDTO hkInventoryRoomTypeConfigDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            Integer tenantId = sessionContext.getTenantSymbolBO().getId();
            int loginUserId = sessionContext.getLoginUserId();

            if (roomTypeId > 0) {
                //校验存在
                HkInventoryRoomTypeConfig hkInventoryRoomTypeConfig = roomTypeConfigService.checkExist(roomTypeId);
                //校验归属
                roomTypeConfigService.checkBelongProperty(hkInventoryRoomTypeConfig, propertyId);
                //校验名称是否重复
                roomTypeConfigService.checkNameRepeat(propertyId, hkInventoryRoomTypeConfigDTO.getRoomTypeName(), roomTypeId);
                //修改
                roomTypeConfigService.update(propertyId, hkInventoryRoomTypeConfig, hkInventoryRoomTypeConfigDTO, loginUserId);
                return ImmutableMap.of("id", roomTypeId);
            } else {
                //校验名称是否重复
                roomTypeConfigService.checkNameRepeat(propertyId, hkInventoryRoomTypeConfigDTO.getRoomTypeName(), roomTypeId);
                //新增
                return ImmutableMap.of("id", roomTypeConfigService.insert(tenantId, propertyId, hkInventoryRoomTypeConfigDTO, loginUserId));
            }
        }

        /**
         * 删除房型配置
         *
         * @param property   资产
         * @param roomTypeId 房型配置id
         * @return java.util.Map<java.lang.String, java.lang.String>
         * @author lichen
         * @date 2025/4/22
         */
        @ApiId(1421)
        @DeleteMapping("/{roomTypeId:\\d+}")
        public Map<String, String> delete(String property, @PathVariable Integer roomTypeId) {
            int propertyId = sessionContext.getPropertyId(property);
            //校验存在
            HkInventoryRoomTypeConfig hkInventoryRoomTypeConfig = roomTypeConfigService.checkExist(roomTypeId);
            //校验归属
            roomTypeConfigService.checkBelongProperty(hkInventoryRoomTypeConfig, propertyId);
            //删除
            roomTypeConfigService.delete(propertyId, hkInventoryRoomTypeConfig);
            return Collections.emptyMap();
        }

    }