# RevenueHurdlePointServiceImpl.java

    package cloud.wconnect.rateshop.service.revenue.impl;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.rateshop.entity.revenue.RevenueHurdlePoint;
    import cloud.wconnect.rateshop.mapper.revenue.RevenueHurdlePointMapper;
    import cloud.wconnect.rateshop.pojo.dto.revenue.UpdateHurdlerPointDTO;
    import cloud.wconnect.rateshop.service.revenue.IRevenueHurdlePointService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.time.ZoneId;
    import java.util.List;
    import java.util.Map;
    import java.util.Objects;
    import java.util.stream.Collectors;

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author lichen
     * @since 2024-03-25
     */
    @Service
    @DS("rate_shop")
    public class RevenueHurdlePointServiceImpl extends ServiceImpl<RevenueHurdlePointMapper, RevenueHurdlePoint> implements IRevenueHurdlePointService {

        @Autowired
        private UpdateLogUtil updateLogUtil;

        /**
         * 查询指定日期的 hurdler point
         *
         * @param propertyId 资产 id
         * @param theDate    日期
         * @return hurdler point
         * @author yyt
         * @date 2024/3/26
         **/
        @Override
        public List<RevenueHurdlePoint> list(Integer propertyId, Long theDate) {
            return list(new QueryWrapper<RevenueHurdlePoint>().lambda().eq(RevenueHurdlePoint::getPropertyId, propertyId)
                    .eq(RevenueHurdlePoint::getTheDate, theDate));
        }

        /**
         * 修改 hurdler point
         *
         * @param propertyDTO  资产
         * @param date         指定日期（YYYY-MM-DD)
         * @param hurdlePoints hurdler point
         * @param userId       操作人
         * @author yyt
         * @date 2024/3/27
         **/
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void updateHurdlePoint(PropertyDTO propertyDTO, String date, List<UpdateHurdlerPointDTO> hurdlePoints, int userId) {
            Integer propertyId = propertyDTO.getId();
            ZoneId zoneId = ZoneId.of(propertyDTO.getTimezone());
            long theDate = DateTimeUtils.strToLocalDate(date, BaseConstant.DATE_FORMAT_YYYY_MM_DD)
                    .atStartOfDay(ZoneId.of(propertyDTO.getTimezone())).toEpochSecond();

            Map<Long, RevenueHurdlePoint> existHurdlerPointByTargetDate = list(propertyDTO.getId(), theDate)
                    .stream().collect(Collectors.toMap(RevenueHurdlePoint::getTargetDate, v -> v));
            saveOrUpdateBatch(hurdlePoints.stream().map(item -> {
                long targetDate = DateTimeUtils.strToLocalDate(item.getDate(), BaseConstant.DATE_FORMAT_YYYY_MM_DD)
                        .atStartOfDay(zoneId).toEpochSecond();
                RevenueHurdlePoint existHurdlerPoint = existHurdlerPointByTargetDate.get(targetDate);
                RevenueHurdlePoint revenueHurdlePoint = new RevenueHurdlePoint().setPropertyId(propertyId).setTheDate(theDate)
                        .setTargetDate(targetDate).setHurdlePoint(item.getValue()).setUpdatedLog(updateLogUtil.get(userId));
                if (Objects.nonNull(existHurdlerPoint)) {
                    revenueHurdlePoint.setId(existHurdlerPoint.getId())
                            .setUpdatedLog(updateLogUtil.append(existHurdlerPoint.getUpdatedLog(), userId));
                }
                return revenueHurdlePoint;
            }).toList());
        }

    }