# ParseHouseStatusServiceByOpera.java

    package cloud.wconnect.frontoffice.parsereport.endofshift.impl;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.frontoffice.parsereport.endofshift.IParseHouseStatusService;
    import cloud.wconnect.frontoffice.pojo.dto.endofshift.report.HouseStatusServiceDTO;
    import cloud.wconnect.frontoffice.service.AmazonS3Service;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.lang3.StringUtils;
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Node;
    import org.dom4j.io.SAXReader;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;

    import java.io.IOException;
    import java.io.InputStream;

    /**
     * @author lichen
     * @description 解析Opera系统的 House Status/Service 报告
     * @date 2023/3/10 15:47
     */
    @Slf4j
    @Component
    public class ParseHouseStatusServiceByOpera implements IParseHouseStatusService {

        @Autowired
        private AmazonS3Service amazonS3Service;

        @Override
        public boolean supports(String source) {
            return SystemPlatformEnum.OPERA.getDesc().equals(source);
        }

        @Override
        public HouseStatusServiceDTO parse(String path) throws ParseReportException {
            try(InputStream fileInputStream = amazonS3Service.getFile(path)){
                Document document = new SAXReader().read(fileInputStream);
                Node vdNodes = document.selectSingleNode("//CS_DI_OCC_REP");
                Integer vdRooms = StringUtils.isBlank(vdNodes.getText()) ? 0 : Integer.parseInt(vdNodes.getText().trim());
                // out of service rooms
                Node oosNodes = document.selectSingleNode("//CS_OS_OCC_REP");
                Integer oosRooms = StringUtils.isBlank(oosNodes.getText()) ? 0 : Integer.parseInt(oosNodes.getText().trim());
                return new HouseStatusServiceDTO().setOosRooms(oosRooms).setVdRooms(vdRooms);
            }catch (IOException | DocumentException e){
                log.error(e.getMessage(),e);
                throw new ParseReportException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),"source=opera, parse [house status/service] report error",e);
            }
        }
    }