package com.fs.his.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fs.his.domain.FsUserWx;
import com.fs.his.mapper.FsUserWxMapper;
import com.fs.his.service.IFsUserWxService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class FsUserWxServiceImpl extends ServiceImpl<FsUserWxMapper, FsUserWx> implements IFsUserWxService {

    /**
     * 根据FsUserId和AppId唯一键保存或更新
     * @param wx    配置信息
     */
    @Override
    public void saveOrUpdateByUniqueKey(FsUserWx wx) {
        baseMapper.insertOrUpdateByUniqueKey(wx);
    }

    @Override
    public FsUserWx selectByAppIdAndUserId(String appId, Long userId,Integer type) {
        return this.baseMapper.selectOne(
                new QueryWrapper<FsUserWx>()
                        .eq("app_id", appId)
                        .eq("fs_user_id", userId)
                        .eq("type", type)
                        .orderByDesc("id")
                        .last("LIMIT 1")
        );
    }
}
