# CompRoomNotifyRuleController.java

    package cloud.wconnect.frontoffice.controller.comproom;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.frontoffice.cons.comproom.CompRoomFieldConstant;
    import cloud.wconnect.frontoffice.cons.comproom.CompRoomNotifyConfigTypeEnum;
    import cloud.wconnect.frontoffice.entity.comproom.CompRoomNotifyRule;
    import cloud.wconnect.frontoffice.pojo.dto.comproom.CompRoomNotifyRuleDTO;
    import cloud.wconnect.frontoffice.service.comproom.ICompRoomNotifyRuleService;
    import com.google.common.collect.Sets;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import jakarta.validation.Valid;

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

    /**
     * <p>
     * 免费房通知规则表 前端控制器
     * </p>
     *
     * @author lichen
     * @since 2024-06-10
     */
    @RestController
    @RequestMapping("/comp-room/notify-rule")
    public class CompRoomNotifyRuleController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private ICompRoomNotifyRuleService notifyRuleService;
        @Autowired
        private I18nMessageUtils i18nMessageUtils;

        /**
         * 查询资产配置的通知规则
         *
         * @param property 资产标识
         * @return cloud.wconnect.frontoffice.entity.comproom.CompRoomNotifyRule
         * @author lichen
         * @date 2024/6/11
         */
        @ApiId(1190)
        @GetMapping
        public CompRoomNotifyRule get(String property) {
            int propertyId = sessionContext.getPropertyId(property);

            //查询免费房的通知规则
            return notifyRuleService.getByPropertyIdAndTypeOrDefault(propertyId, CompRoomNotifyConfigTypeEnum.COMP_ROOM_CHECK_IN.getType());
        }

        /**
         * 保存免费房的通知规则DTO
         *
         * @param property              资产
         * @param compRoomNotifyRuleDTO 通知规则DTO
         * @return java.util.Map
         * @author lichen
         * @date 2024/6/11
         */
        @ApiId(1191)
        @PostMapping
        public Map save(String property, @RequestBody @Valid CompRoomNotifyRuleDTO compRoomNotifyRuleDTO) {
            int propertyId = sessionContext.getPropertyId(property);

            //校验通知规则不能重复
            if (compRoomNotifyRuleDTO.getRules().size() != Sets.newHashSet(compRoomNotifyRuleDTO.getRules()).size()) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_CANNOT_REPEAT,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(CompRoomFieldConstant.RULES),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The rules cannot repeat");
            }

            // 保存免费房的通知规则
            notifyRuleService.save(propertyId, compRoomNotifyRuleDTO, sessionContext.getLoginUserId());
            return Collections.emptyMap();
        }

    }