# HotelKpiMonthlyReportFieldConfigServiceImpl.java

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

    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.workperformance.entity.hotelkpi.HotelKpiMonthlyReportFieldConfig;
    import cloud.wconnect.workperformance.mapper.hotelkpi.HotelKpiMonthlyReportFieldConfigMapper;
    import cloud.wconnect.workperformance.pojo.dto.hotelkpi.kpiv2.HotelKpiMonthlyReportFieldConfigDTO;
    import cloud.wconnect.workperformance.service.hotelkpi.IHotelKpiMonthlyReportFieldConfigService;
    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.util.Objects;

    /**
     * <p>
     * Hotel Kpi Monthly Report Filed Config 服务实现类
     * </p>
     *
     * @author zc
     * @since 2025-08-26
     */
    @Service
    @DS("work_performance")
    public class HotelKpiMonthlyReportFieldConfigServiceImpl extends ServiceImpl<HotelKpiMonthlyReportFieldConfigMapper, HotelKpiMonthlyReportFieldConfig> implements IHotelKpiMonthlyReportFieldConfigService {

        @Resource
        private ObjectMapper objectMapper;

        /**
         * 获取配置
         *
         * @param propertyId 资产 id
         * @return HotelKpiMonthlyReportFieldConfigDTO
         * @author zc
         * @date 2025/8/26
         */
        @Override
        public HotelKpiMonthlyReportFieldConfigDTO get(int propertyId) {
            HotelKpiMonthlyReportFieldConfig config = getOne(new LambdaQueryWrapper<HotelKpiMonthlyReportFieldConfig>()
                    .eq(HotelKpiMonthlyReportFieldConfig::getPropertyId, propertyId));
            if (Objects.isNull(config)) {
                return HotelKpiMonthlyReportFieldConfigDTO.getDefault();
            }
            return JsonUtils.convertStringToObject(objectMapper, config.getDetail(), HotelKpiMonthlyReportFieldConfigDTO.class);
        }

        /**
         * 保存配置
         *
         * @param propertyId 资产 id
         * @param saveDTO    保存数据
         * @param operatorId 操作人 id
         * @author zc
         * @date 2025/8/26
         */
        @Override
        public void save(int propertyId, HotelKpiMonthlyReportFieldConfigDTO saveDTO, int operatorId) {
            HotelKpiMonthlyReportFieldConfig config = new HotelKpiMonthlyReportFieldConfig();
            config.setPropertyId(propertyId);
            config.setDetail(JsonUtils.convertObjToString(objectMapper, saveDTO));
            config.setUpdatedBy(operatorId);
            config.setUpdatedTime(DateTimeUtils.nowTimestamp());

            baseMapper.insertOrUpdateByUnique(config);
        }

    }