package jnpf.attendance.service.impl;

import jnpf.attendance.mapper.AttendanceUserConfigMapper;
import jnpf.attendance.service.UserConfigService;
import jnpf.model.attendance.vo.attendance.UserConfigVo;
import jnpf.util.FtbUtil;
import jnpf.util.UserProvider;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author huanglinpan
 * @Date 2024/6/25 9:31
 * @Version 1.0 （版本号）
 */
@Service("attendanceUserConfigService")
public class UserConfigServiceImpl implements UserConfigService {

    @Resource
    private UserProvider userProvider;

    @Resource
    private AttendanceUserConfigMapper userConfigMapper;


    @Override
    public UserConfigVo getUserConfig() {
        return userConfigMapper.getUserConfig(userProvider.get().getUserId());
    }

    @Override
    public void updateUserConfig(UserConfigVo userConfigVo) {
        String userId = userProvider.get().getUserId();
        UserConfigVo userConfig = userConfigMapper.getUserConfig(userId);
        if (null != userConfig && null != userConfig.getConfigJson()){
            //修改用户配置
            userConfigMapper.updateUSerConfig(userConfigVo.getConfigJson(),userId);
        }else{
            userConfigVo.setId(FtbUtil.getId());
            //没有配置  新增保存用户配置
            userConfigMapper.addUserConfig(userId,userConfigVo);
        }
    }
}
