package cn.pluss.platform.user.impl;

import cn.pluss.platform.converter.Converter;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserVoice;
import cn.pluss.platform.mapper.UserVoiceMapper;
import cn.pluss.platform.user.UserVoiceService;
import cn.pluss.platform.userApp.UserAppService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户播报配置表 服务实现类
 * </p>
 *
 * @author Djh
 * @since 2022-04-16
 */
@Service
public class UserVoiceServiceImpl extends ServiceImpl<UserVoiceMapper, UserVoice> implements UserVoiceService {

    @Autowired
    private UserAppService userAppService;

    @Override
    public UserVoice apiGetVoiceSetting() {
        UserApp userApp = userAppService.checkApiToken();

        return getByUserId(userApp.getUserId());
    }

    @Override
    public void apiSetVoiceSetting(UserVoice userVoice) {
        UserApp userApp = userAppService.checkApiToken();

        UserVoice currentData = getByUserId(userApp.getUserId());

        Converter.INSTANCE.cp(userVoice, currentData);

        saveOrUpdate(currentData);
    }
}
