package com.fs.system.service.impl;

import java.util.List;
import com.fs.common.utils.DateUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.system.mapper.SysUserSetMapper;
import com.fs.system.domain.SysUserSet;
import com.fs.system.service.ISysUserSetService;

/**
 * 用户设置Service业务层处理
 *
 * @author fs
 * @date 2025-06-04
 */
@Service
public class SysUserSetServiceImpl extends ServiceImpl<SysUserSetMapper, SysUserSet> implements ISysUserSetService {

    /**
     * 查询用户设置
     *
     * @param userId 用户设置主键
     * @return 用户设置
     */
    @Override
    public SysUserSet selectSysUserSetByUserId(Long userId)
    {
        return baseMapper.selectSysUserSetByUserId(userId);
    }

    /**
     * 查询用户设置列表
     *
     * @param sysUserSet 用户设置
     * @return 用户设置
     */
    @Override
    public List<SysUserSet> selectSysUserSetList(SysUserSet sysUserSet)
    {
        return baseMapper.selectSysUserSetList(sysUserSet);
    }

    /**
     * 新增用户设置
     *
     * @param sysUserSet 用户设置
     * @return 结果
     */
    @Override
    public int insertSysUserSet(SysUserSet sysUserSet)
    {
        //查询是否存在
        SysUserSet temp = baseMapper.selectSysUserSetByUserId(sysUserSet.getUserId());
        if(temp!=null){
            temp.setRate(sysUserSet.getRate());
            return baseMapper.updateSysUserSet(sysUserSet);
        } else {
            sysUserSet.setCreateTime(DateUtils.getNowDate());
            return baseMapper.insertSysUserSet(sysUserSet);
        }

    }

    /**
     * 修改用户设置
     *
     * @param sysUserSet 用户设置
     * @return 结果
     */
    @Override
    public int updateSysUserSet(SysUserSet sysUserSet)
    {
        return baseMapper.updateSysUserSet(sysUserSet);
    }

    /**
     * 批量删除用户设置
     *
     * @param userIds 需要删除的用户设置主键
     * @return 结果
     */
    @Override
    public int deleteSysUserSetByUserIds(Long[] userIds)
    {
        return baseMapper.deleteSysUserSetByUserIds(userIds);
    }

    /**
     * 删除用户设置信息
     *
     * @param userId 用户设置主键
     * @return 结果
     */
    @Override
    public int deleteSysUserSetByUserId(Long userId)
    {
        return baseMapper.deleteSysUserSetByUserId(userId);
    }
}
