# RevenueHurdlePointFutureServiceImpl.java

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

    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.rateshop.entity.revenue.RevenueHurdlePointFuture;
    import cloud.wconnect.rateshop.mapper.revenue.RevenueHurdlePointFutureMapper;
    import cloud.wconnect.rateshop.pojo.dto.revenue.UpdateHurdlerPointDTO;
    import cloud.wconnect.rateshop.service.revenue.IRevenueHurdlePointFutureService;
    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.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

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

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author yyt
     * @since 2024-05-08
     */
    @Service
    @DS("rate_shop")
    public class RevenueHurdlePointFutureServiceImpl extends ServiceImpl<RevenueHurdlePointFutureMapper, RevenueHurdlePointFuture> implements IRevenueHurdlePointFutureService {

        @Autowired
        private UpdateLogUtil updateLogUtil;

        /**
         * 查询 hurdle point
         *
         * @param propertyId  资产 id
         * @param targetDates 指定日期
         * @return hurdle point
         * @author yyt
         * @date 2024/5/22
         **/
        @Override
        public List<RevenueHurdlePointFuture> list(Integer propertyId, List<Integer> targetDates) {
            return list(new QueryWrapper<RevenueHurdlePointFuture>().lambda().eq(RevenueHurdlePointFuture::getPropertyId, propertyId)
                    .in(RevenueHurdlePointFuture::getTargetDate, targetDates));
        }

        /**
         * 保存 hurdle point
         *
         * @param propertyDTO         资产
         * @param updateHurdlerPoints hurdle point
         * @param userId              操作人
         * @author yyt
         * @date 2024/5/22
         **/
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void updateHurdlePoint(PropertyDTO propertyDTO, List<UpdateHurdlerPointDTO> updateHurdlerPoints, int userId) {
            Integer propertyId = propertyDTO.getId();
            List<Integer> targetDates = updateHurdlerPoints.stream()
                    .map(item -> Integer.parseInt(StringUtils.replace(item.getDate(), "-", "")))
                    .collect(Collectors.toList());
            Map<Integer, RevenueHurdlePointFuture> existHurdlerPointFutureByTargetDate = list(propertyId, targetDates)
                    .stream().collect(Collectors.toMap(RevenueHurdlePointFuture::getTargetDate, v -> v));

            saveOrUpdateBatch(updateHurdlerPoints.stream().map(item -> {
                Integer targetDate = Integer.parseInt(StringUtils.replace(item.getDate(), "-", ""));
                RevenueHurdlePointFuture revenueHurdlePointFuture = new RevenueHurdlePointFuture().setPropertyId(propertyId)
                        .setTargetDate(targetDate).setHurdlePoint(item.getValue()).setUpdatedLog(updateLogUtil.get(userId));

                RevenueHurdlePointFuture existHurdlerPointFuture = existHurdlerPointFutureByTargetDate.get(targetDate);
                if (Objects.nonNull(existHurdlerPointFuture)) {
                    revenueHurdlePointFuture.setId(existHurdlerPointFuture.getId())
                            .setUpdatedLog(updateLogUtil.append(existHurdlerPointFuture.getUpdatedLog(), userId));
                }
                return revenueHurdlePointFuture;
            }).toList());
        }

    }