# RateShopPropertyOperationListener.java

    package cloud.wconnect.rateshop.springlistener.rateshop;

    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.rateshop.cons.rateshop.OperationCategoryCons;
    import cloud.wconnect.rateshop.pojo.dto.rateshop.internal.InternalOperationDTO;
    import cloud.wconnect.rateshop.pojo.dto.rateshop.operation.PropertyOperationDTO;
    import cloud.wconnect.rateshop.pojo.dto.rateshop.operation.PropertyOperationValueDTO;
    import cloud.wconnect.rateshop.service.rateshop.IPropertyOperationService;
    import cloud.wconnect.rateshop.springlistener.PropertyOperationEvent;
    import lombok.extern.slf4j.Slf4j;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.context.event.EventListener;
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Resource;
    import java.math.BigDecimal;
    import java.util.List;
    import java.util.Objects;

    /**
     * Group pickup 报告处理
     */
    @Slf4j
    @Service
    public class RateShopPropertyOperationListener {
        @Resource
        private IPropertyOperationService propertyOperationService;
        @Resource
        private PropertyInternalService propertyInternalService;

        /**
         * 异步监听事件处理
         *
         * @param event 事件对象
         * @author zc
         * @date 2024/3/26
         */
        @Async
        @EventListener(classes = {PropertyOperationEvent.class})
        public void handle(PropertyOperationEvent event) {
            log.info("Rate shop - RateShopPropertyOperationListener.start...");

            PropertyOperationDTO propertyOperation = event.getPropertyOperation();
            String tenant = propertyOperation.getTenant();
            String property = propertyOperation.getProperty();
            PropertyDTO propertyDTO = propertyInternalService.getOne(property, tenant);
            if (Objects.isNull(propertyDTO)) {
                log.warn("Rate shop - RateShopPropertyOperationListener.end... The property:{} is not exist", property);
                return;
            }
            if (!propertyDTO.getStatus()) {
                log.warn("Rate shop - RateShopPropertyOperationListener.end... The property:{} is closed", property);
                return;
            }
            List<PropertyOperationValueDTO> propertyOperationValueDTOList = propertyOperation.getValues();
            if (CollectionUtils.isEmpty(propertyOperationValueDTOList)) {
                log.warn("Rate shop - RateShopPropertyOperationListener.end... The values is empty, property:{}", property);
                return;
            }

            // 格式化数据
            List<InternalOperationDTO> operationDTOList = propertyOperationValueDTOList.stream().map(valueDTO -> {
                InternalOperationDTO operationDTO = new InternalOperationDTO();
                operationDTO.setTheDate(valueDTO.getTheDate());
                operationDTO.setCategory(OperationCategoryCons.CURRENT_HURDLE_POINT);
                BigDecimal value = valueDTO.getValue();
                operationDTO.setValue(Objects.isNull(value) ? null : value.toString());
                return operationDTO;
            }).toList();

            // 保存采集的 Operation 数据
            propertyOperationService.saveCollectOperation(propertyDTO, operationDTOList);

            log.info("Rate shop - RateShopPropertyOperationListener.end...");
        }

    }