# ImportGuestConfigController.java

    package cloud.wconnect.frontoffice.controller.clc;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.exception.ForbiddenException;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.frontoffice.entity.clc.ClcGuestInhFilterConfig;
    import cloud.wconnect.frontoffice.pojo.dto.clc.ImportGuestConfigDTO;
    import cloud.wconnect.frontoffice.pojo.query.clc.ImportGuestConfigQuery;
    import cloud.wconnect.frontoffice.service.clc.IClcGuestInhFilterConfigService;
    import jakarta.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

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

    /**
     * 控制层：Import Guest Config
     *
     * @author yyt
     * 2023/7/25
     */
    @RestController
    @RequestMapping("/clc/import-guest/filter-config")
    public class ImportGuestConfigController {

        @Autowired
        private IClcGuestInhFilterConfigService clcGuestInhFilterConfigService;
        @Autowired
        private SessionContext sessionContext;

        /**
         * 获取导入 guest in house 报告配置规则
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return 配置规则
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(492)
        @GetMapping
        public ListPagedDTO<ImportGuestConfigDTO> listImportGuestConfigDTO(String property, ImportGuestConfigQuery query) {
            Integer propertyId = sessionContext.getPropertyId(property);
            return clcGuestInhFilterConfigService.listImportGuestConfigDTO(propertyId, query);
        }

        /**
         * 新增、编辑配置规则
         *
         * @param id        配置 id
         * @param property  资产标识
         * @param configDTO 配置规则
         * @return {}
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(493)
        @PostMapping("/{id:\\d+}")
        public Map save(@PathVariable int id, String property, @Valid @RequestBody ImportGuestConfigDTO configDTO) {
            Integer propertyId = sessionContext.getPropertyId(property);
            int userId = sessionContext.getLoginUserId();
            if (id == 0) {
                clcGuestInhFilterConfigService.checkExist(propertyId, configDTO.getRateCode(), null);

                clcGuestInhFilterConfigService.save(propertyId, configDTO, userId);
            } else {
                ClcGuestInhFilterConfig config = clcGuestInhFilterConfigService.checkExist(id);

                clcGuestInhFilterConfigService.checkExist(propertyId, configDTO.getRateCode(), id);

                checkBelong(config, propertyId);

                clcGuestInhFilterConfigService.update(id, configDTO, userId);
            }

            return Collections.emptyMap();
        }

        /**
         * 删除配置规则
         *
         * @param id       配置 id
         * @param property 资产标识
         * @return {}
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(494)
        @DeleteMapping("/{id:\\d+}")
        public Map delete(@PathVariable int id, String property) {
            ClcGuestInhFilterConfig config = clcGuestInhFilterConfigService.checkExist(id);

            checkBelong(config, sessionContext.getPropertyId(property));

            clcGuestInhFilterConfigService.delete(id);

            return Collections.emptyMap();
        }

        /**
         * 校验数据归属
         *
         * @param config     配置规则
         * @param propertyId 资产 id
         * @author yyt
         * @date 2023/7/25
         */
        private void checkBelong(ClcGuestInhFilterConfig config, Integer propertyId) {
            if (!config.getPropertyId().equals(propertyId)) {
                throw new ForbiddenException(BaseErrorCodeEnum.DATA_FORBIDDEN.getI18nCode(),
                        BaseErrorCodeEnum.DATA_FORBIDDEN.getCode(), "the property id parameter is different from " +
                        "the property id of the clcGuestInhFilterConfig;propertyId:" + propertyId + ",clcGuestInhFilterConfigPropertyId:" +
                        config.getPropertyId() + ",clcGuestInhFilterConfigId:" + config.getId());
            }
        }

    }