# RevenueHurdlerPointHandle.java

    package cloud.wconnect.rateshop.springlistener.revenue;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.rateshop.pojo.dto.rateshop.operation.PropertyOperationValueDTO;
    import cloud.wconnect.rateshop.pojo.dto.revenue.UpdateHurdlerPointDTO;
    import cloud.wconnect.rateshop.service.revenue.IRevenueHurdlePointFutureService;
    import cloud.wconnect.rateshop.service.revenue.IRevenueHurdlePointService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.time.ZonedDateTime;
    import java.time.format.DateTimeFormatter;
    import java.util.List;

    /**
     * @author: yyt
     * 2024-05-22
     */
    @Service
    @DS("rate_shop")
    public class RevenueHurdlerPointHandle {

        @Autowired
        private IRevenueHurdlePointService revenueHurdlePointService;
        @Autowired
        private IRevenueHurdlePointFutureService revenueHurdlePointFutureService;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 处理 hurdle point 数据
         *
         * @param propertyDTO 资产
         * @param values      hurdle point 数据
         * @author yyt
         * @date 2024/5/22
         **/
        @Transactional(rollbackFor = Exception.class)
        public void handleHurdlePointData(PropertyDTO propertyDTO, List<PropertyOperationValueDTO> values) {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(BaseConstant.DATE_FORMAT_YYYY_MM_DD);

            // 处理当天的 hurdle point（只关注未来14天的数据）
            String timezone = propertyDTO.getTimezone();
            ZonedDateTime startDateTime = DateTimeUtils.dateNow(timezone);
            ZonedDateTime endDateTime = startDateTime.plusDays(13);
            DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern(BaseConstant.DATE_FORMAT_YYYYMMDD);
            long startDateLong = Long.parseLong(startDateTime.format(dateTimeFormatter2));
            long endDateLong = Long.parseLong(endDateTime.format(dateTimeFormatter2));
            List<PropertyOperationValueDTO> effectiveData = values.stream()
                    .filter(item -> item.getTheDate() >= startDateLong && item.getTheDate() <= endDateLong).toList();
            if (CollectionUtils.isNotEmpty(effectiveData)) {
                String theDate = DateTimeUtils.dateNow(propertyDTO.getTimezone()).format(dateTimeFormatter);

                List<UpdateHurdlerPointDTO> updateHurdlerPointDTOs = beanMapper.mapList(effectiveData, UpdateHurdlerPointDTO.class, (item, entity) -> {
                    entity.setDate(DateTimeUtils.strToLocalDate(item.getTheDate() + "", BaseConstant.DATE_FORMAT_YYYYMMDD).format(dateTimeFormatter));
                });

                revenueHurdlePointService.updateHurdlePoint(propertyDTO, theDate, updateHurdlerPointDTOs, BaseConstant.ZERO);
            }

            // 将数据存到 未来数据的 db 中，供查看未来数据使用
            List<UpdateHurdlerPointDTO> updateHurdlerPointDTOs = beanMapper.mapList(values, UpdateHurdlerPointDTO.class, (item, entity) -> {
                entity.setDate(DateTimeUtils.strToLocalDate(item.getTheDate() + "", BaseConstant.DATE_FORMAT_YYYYMMDD).format(dateTimeFormatter));
            });
            revenueHurdlePointFutureService.updateHurdlePoint(propertyDTO, updateHurdlerPointDTOs, BaseConstant.ZERO);
        }

    }