# GmwrOccSelloutConfigServiceImpl.java

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

    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.workperformance.entity.gmwr.GmwrOccSelloutConfig;
    import cloud.wconnect.workperformance.mapper.gmwr.GmwrOccSelloutConfigMapper;
    import cloud.wconnect.workperformance.pojo.dto.gmwr.selloutefficiency.GmwrOccSelloutConfigDTO;
    import cloud.wconnect.workperformance.service.gmwr.IGmwrOccSelloutConfigService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import jakarta.annotation.Resource;
    import org.springframework.stereotype.Service;

    import java.math.BigDecimal;
    import java.util.Objects;

    /**
     * <p>
     * GM Weekly Report OOO Rooms sellout config 服务实现类
     * </p>
     *
     * @author zc
     * @since 2024-12-30
     */
    @Service
    @DS("work_performance")
    public class GmwrOccSelloutConfigServiceImpl extends ServiceImpl<GmwrOccSelloutConfigMapper, GmwrOccSelloutConfig> implements IGmwrOccSelloutConfigService {
        @Resource
        private ObjectMapper objectMapper;

        private static final int DEFAULT_OCC_HOUR = 19;
        private static final BigDecimal DEFAULT_OCC_THRESHOLD = new BigDecimal("95");

        /**
         * 获取 OOO Rooms sellout 配置
         *
         * @param propertyId 资产 id
         * @return GmwrOccSelloutConfigDTO
         * @author zc
         * @date 2024/12/30
         */
        @Override
        public GmwrOccSelloutConfigDTO getByPropertyId(int propertyId) {
            GmwrOccSelloutConfig config = getOne(new LambdaQueryWrapper<GmwrOccSelloutConfig>()
                    .eq(GmwrOccSelloutConfig::getPropertyId, propertyId));
            if (Objects.isNull(config)) {
                return new GmwrOccSelloutConfigDTO(DEFAULT_OCC_HOUR, DEFAULT_OCC_THRESHOLD);
            }
            return JsonUtils.convertStringToObject(objectMapper, config.getDetail(), GmwrOccSelloutConfigDTO.class);
        }

        /**
         * 保存 OOO Rooms sellout 配置
         *
         * @param propertyId    资产 id
         * @param saveConfigDTO 保存配置
         * @param operatorId    操作人 id
         * @author zc
         * @date 2024/12/30
         */
        @Override
        public void save(int propertyId, GmwrOccSelloutConfigDTO saveConfigDTO, int operatorId) {
            GmwrOccSelloutConfig config = new GmwrOccSelloutConfig();
            config.setPropertyId(propertyId);
            config.setDetail(JsonUtils.convertObjToString(objectMapper, saveConfigDTO));
            config.setUpdatedBy(operatorId);
            config.setUpdatedTime(DateTimeUtils.nowTimestamp());
            baseMapper.insertOrUpdateByUnique(config);
        }
    }