package com.mosty.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.service.UserInfoService;
import com.mosty.common.core.business.entity.SysUser;
import com.mosty.common.core.business.mapper.SysUserMapper;
import com.mosty.common.core.business.service.TbJcglXfllInCommService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


@Service
@AllArgsConstructor
public class UserInfoServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
        implements UserInfoService {

    private final TbJcglXfllInCommService tbJcglXfllService;

    @Override
    public SysUser getUserInfo(String userId) {
        return this.baseMapper.selectById(userId);
    }

    @Override
    public SysUser getUserInfoBySfzh(String sfzh) {
        return this.baseMapper.selectOne(
                new LambdaQueryWrapper<SysUser>()
                        .eq(SysUser::getIdEntityCard, sfzh)
                        .last(" limit 1")
        );
    }

    @Override
    public SysUser getUserOrFjInfoBySfzh(String sfzh) {
        SysUser user = this.getUserInfoBySfzh(sfzh);
        if(ObjectUtils.isEmpty(user)){
            user = tbJcglXfllService.selectFjToUserBySfzh(sfzh);
        }
        return user;
    }

}
