# HotelKpiWconnectHKEfficiencyServiceImpl.java

    package cloud.wconnect.workperformance.service.hotelkpi.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.workperformance.entity.hotelkpi.HotelKpiWconnectHKEfficiency;
    import cloud.wconnect.workperformance.mapper.hotelkpi.HotelKpiWconnectHKEfficiencyMapper;
    import cloud.wconnect.workperformance.pojo.bo.modelevent.hkefficiency.HKEfficiencyBO;
    import cloud.wconnect.workperformance.service.hotelkpi.IHotelKpiWconnectHKEfficiencyService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import jakarta.annotation.Resource;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import java.util.Comparator;
    import java.util.List;

    /**
     * <p>
     * Hotel KPI wconnect HK Efficiency 数据 服务实现类
     * </p>
     *
     * @author zc
     * @since 2024-07-24
     */
    @Service
    @DS("work_performance")
    public class HotelKpiWconnectHKEfficiencyServiceImpl extends ServiceImpl<HotelKpiWconnectHKEfficiencyMapper, HotelKpiWconnectHKEfficiency> implements IHotelKpiWconnectHKEfficiencyService {

        @Resource
        private BeanMapper beanMapper;

        /**
         * 保存数据
         *
         * @param HKEfficiencyBOList 数据集合
         * @author zc
         * @date 2024/8/8
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(List<HKEfficiencyBO> HKEfficiencyBOList) {
            if (CollectionUtils.isEmpty(HKEfficiencyBOList)) {
                return;
            }
            List<HotelKpiWconnectHKEfficiency> hkEfficiencyList = beanMapper.mapList(HKEfficiencyBOList,
                    HotelKpiWconnectHKEfficiency.class);

            // 按唯一索引字段排序，避免死锁
            hkEfficiencyList.sort(Comparator.comparing(HotelKpiWconnectHKEfficiency::getPropertyId)
                    .thenComparing(HotelKpiWconnectHKEfficiency::getDate));

            baseMapper.insertOrUpdateBatchByUnique(hkEfficiencyList);
        }

        /**
         * 根据指定日期范围获取数据
         *
         * @param propertyId 资产 id
         * @param startDate  开始日期（yyyyMMdd）
         * @param endDate    结束日期（yyyyMMdd）
         * @return HotelKpiWconnectHkEfficiency 集合
         * @author zc
         * @date 2024/8/6
         */
        @Override
        public List<HotelKpiWconnectHKEfficiency> listByDateRange(int propertyId, long startDate, long endDate) {
            return list(new LambdaQueryWrapper<HotelKpiWconnectHKEfficiency>()
                    .between(HotelKpiWconnectHKEfficiency::getDate, startDate, endDate)
                    .eq(HotelKpiWconnectHKEfficiency::getPropertyId, propertyId));
        }

    }