# SoldOutManagementServiceImpl.java

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

    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.workperformance.entity.monthlyreport.MonthlyReport;
    import cloud.wconnect.workperformance.entity.monthlyreport.SoldOutManagement;
    import cloud.wconnect.workperformance.mapper.monthlyreport.SoldOutManagementMapper;
    import cloud.wconnect.workperformance.pojo.dto.monthlyreport.soldoutmanagement.SoldOutManagementDTO;
    import cloud.wconnect.workperformance.service.monthlyreport.IHandlePropertySettingChange;
    import cloud.wconnect.workperformance.service.monthlyreport.ISoldOutManagementService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;

    import java.util.List;

    /**
     * <p>
     * 月报Sold Out Management区域表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2023-09-01
     */
    @Service
    @DS("monthly_report")
    public class SoldOutManagementServiceImpl extends ServiceImpl<SoldOutManagementMapper, SoldOutManagement> implements ISoldOutManagementService, IHandlePropertySettingChange {

        @Autowired
        private SoldOutManagementMapper soldOutManagementMapper;

        /**
         * 保存售罄管理区域数据
         *
         * @param monthlyReport        月报
         * @param propertyDTO          资产DTO
         * @param soldOutManagementDTO 售罄管理数据DTO
         * @param loginUserId          登录用户id
         * @return void
         * @author lichen
         * @date 2023/9/4
         */
        @Override
        public void save(MonthlyReport monthlyReport, PropertyDTO propertyDTO, SoldOutManagementDTO soldOutManagementDTO, int loginUserId) {
            SoldOutManagement soldOutManagement = SoldOutManagement.builder()
                    .tenantId(propertyDTO.getTenantId())
                    .propertyId(propertyDTO.getId())
                    .reportId(monthlyReport.getId())
                    .oooRooms(soldOutManagementDTO.getOoo())
                    .occ(soldOutManagementDTO.getOcc())
                    .updateId(loginUserId)
                    .updateTime(DateTimeUtils.nowTimestamp())
                    .build();
            soldOutManagementMapper.saveOrUpdateUnique(soldOutManagement);
        }

        /**
         * 根据资产id和月报id获取Sold Out Management区域数据
         *
         * @param propertyId 资产id
         * @param reportId   月报id
         * @return SoldOutManagement
         * @author lichen
         * @date 2025/12/30
         */
        @Override
        public SoldOutManagement getByReportId(int propertyId, long reportId) {
            return getOne(new LambdaQueryWrapper<SoldOutManagement>()
                    .eq(SoldOutManagement::getReportId, reportId)
                    .eq(SoldOutManagement::getPropertyId, propertyId)
                    .last("limit 1"));
        }

        /**
         * 删除区域数据
         *
         * @param propertyDTO    资产DTO
         * @param monthlyReports 月报集合
         * @return void
         * @author lichen
         * @date 2023/9/5
         */
        @Override
        public void delete(PropertyDTO propertyDTO, List<MonthlyReport> monthlyReports) {
            List<Long> reportIds = monthlyReports.stream().map(MonthlyReport::getId).toList();
            if (CollectionUtils.isEmpty(reportIds)) return;
            remove(new LambdaQueryWrapper<SoldOutManagement>()
                    .in(SoldOutManagement::getReportId, reportIds)
                    .eq(SoldOutManagement::getPropertyId, propertyDTO.getId()));
        }
    }