# GuestInHouseController.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.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.bo.SymbolBO;
    import cloud.wconnect.commonlib.pojo.dto.ListPagedDTO;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.redis.PropertyI18nRedisService;
    import cloud.wconnect.frontoffice.entity.clc.ClcGuestInhImportLog;
    import cloud.wconnect.frontoffice.pojo.dto.clc.ImportGuestInHouseDTO;
    import cloud.wconnect.frontoffice.pojo.dto.clc.ImportGuestInHouseLogDTO;
    import cloud.wconnect.frontoffice.pojo.query.clc.GuestInHouseImportLogQuery;
    import cloud.wconnect.frontoffice.service.clc.IClcGuestInhImportLogService;
    import cloud.wconnect.frontoffice.service.clc.guestinhouse.IGuestInHouseParse;
    import com.google.common.collect.Lists;
    import jakarta.validation.Valid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.multipart.MultipartFile;

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

    /**
     * 控制层：Guest In House
     *
     * @author yyt
     * 2023/7/25
     */
    @RestController
    @RequestMapping("/clc/guest-in-house")
    public class GuestInHouseController {

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private IClcGuestInhImportLogService clcGuestInhImportLogService;
        @Autowired
        private PropertyI18nRedisService propertyI18nRedisService;
        @Autowired
        private ApplicationContext applicationContext;

        /**
         * 手动导入 guest in house 报告
         *
         * @param property              资产标识
         * @param file                  报告
         * @param importGuestInHouseDTO 选择条件
         * @return {}
         * @author yyt
         * @date 2023/7/28
         */
        @ApiId(487)
        @PostMapping("/file")
        public Map importGuestInHouseReport(String property, MultipartFile file,
                                            @Valid ImportGuestInHouseDTO importGuestInHouseDTO) {
            SymbolBO tenant = sessionContext.getTenantSymbolBO();
            PropertyDTO propertyDTO = propertyI18nRedisService.get(sessionContext.getPropertyId(property));
            int userId = sessionContext.getLoginUserId();

            //校验source是否符合预期
            String pmsType = propertyDTO.getPmsType();
            //校验source是否符合预期
            if (!Lists.newArrayList(pmsType, SystemPlatformEnum.OTHER.getDesc()).contains(importGuestInHouseDTO.getSource())) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_INTEGRATION_SOURCE_SYSTEM_NOT_SUPPORTED,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The source must be in:" + pmsType + "|" + SystemPlatformEnum.OTHER.getDesc());
            }

            Map<String, IGuestInHouseParse> beans = applicationContext.getBeansOfType(IGuestInHouseParse.class);
            for (IGuestInHouseParse bean : beans.values()) {
                if (bean.supports(importGuestInHouseDTO.getSource())) {
                    bean.checkFile(propertyDTO, file);

                    ClcGuestInhImportLog importLog = bean.handleImportLog(tenant, propertyDTO, file, userId);

                    bean.handleFile(tenant, propertyDTO, file, importLog, userId);
                    return Collections.emptyMap();
                }
            }

            return Collections.emptyMap();
        }

        /**
         * 获取 guest in house 导入记录
         *
         * @param property 资产标识
         * @param query    查询条件
         * @return guest in house 导入记录
         * @author yyt
         * @date 2023/7/25
         */
        @ApiId(488)
        @GetMapping("/import-log")
        public ListPagedDTO<ImportGuestInHouseLogDTO> listImportGuestInHouseLog(String property, @Valid GuestInHouseImportLogQuery query) {
            return clcGuestInhImportLogService.listImportGuestInHouseLogDTO(sessionContext.getTenantSymbolBO().getId(), sessionContext.getPropertyId(property), query);
        }

    }