# SalesKpiMonthlyRevenueConfigServiceImpl.java

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

    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.workperformance.entity.saleskpi.SalesKpiMonthlyRevenueConfig;
    import cloud.wconnect.workperformance.mapper.saleskpi.SalesKpiMonthlyRevenueConfigMapper;
    import cloud.wconnect.workperformance.pojo.dto.saleskpi.config.SalesConfigMonthlyRoomRevenueDTO;
    import cloud.wconnect.workperformance.service.saleskpi.ISalesKpiMonthlyRevenueConfigService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import org.springframework.stereotype.Service;

    import jakarta.annotation.Resource;

    import java.util.Objects;

    /**
     * <p>
     * sales kpi monthly revenue config 服务实现类
     * </p>
     *
     * @author zc
     * @since 2023-09-07
     */
    @Service
    @DS("work_performance")
    public class SalesKpiMonthlyRevenueConfigServiceImpl extends ServiceImpl<SalesKpiMonthlyRevenueConfigMapper, SalesKpiMonthlyRevenueConfig> implements ISalesKpiMonthlyRevenueConfigService {
        @Resource
        private UpdateLogUtil updateLogUtil;
        @Resource
        private ObjectMapper objectMapper;

        /**
         * 获取需要提取月报功能中Room Revenue数据的分类名称配置
         *
         * @param propertyId 资产 id
         * @return SalesConfigMonthlyRoomRevenueDTO
         * @author zc
         * @date 2023/9/7
         */
        @Override
        public SalesConfigMonthlyRoomRevenueDTO getByPropertyId(int propertyId) {
            SalesKpiMonthlyRevenueConfig revenueConfig = getOne(new QueryWrapper<SalesKpiMonthlyRevenueConfig>().lambda()
                    .eq(SalesKpiMonthlyRevenueConfig::getPropertyId, propertyId));
            if (Objects.isNull(revenueConfig)) {
                return null;
            }
            return JsonUtils.convertStringToObject(objectMapper, revenueConfig.getMonthlyRevenue(),
                    SalesConfigMonthlyRoomRevenueDTO.class);
        }

        /**
         * 设置需要提取月报功能中Room Revenue数据的分类名称
         *
         * @param propertyId  资产 id
         * @param loginUserId 登录用户id
         * @author zc
         * @date 2023/9/7
         */
        @Override
        public void saveMonthlyRoomRevenueConfig(int propertyId, SalesConfigMonthlyRoomRevenueDTO roomRevenueDTO, int loginUserId) {
            SalesKpiMonthlyRevenueConfig originRevenueConfig = getOne(new QueryWrapper<SalesKpiMonthlyRevenueConfig>().lambda()
                    .eq(SalesKpiMonthlyRevenueConfig::getPropertyId, propertyId));

            SalesKpiMonthlyRevenueConfig revenueConfig = new SalesKpiMonthlyRevenueConfig();
            revenueConfig.setPropertyId(propertyId);
            revenueConfig.setMonthlyRevenue(JsonUtils.convertObjToString(objectMapper, roomRevenueDTO));

            if (Objects.isNull(originRevenueConfig)) {
                revenueConfig.setUpdateLog(updateLogUtil.get(loginUserId));
            } else {
                revenueConfig.setId(originRevenueConfig.getId());
                revenueConfig.setUpdateLog(updateLogUtil.append(originRevenueConfig.getUpdateLog(), loginUserId));
            }
            saveOrUpdate(revenueConfig);
        }
    }