package com.usky.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.system.domain.SysPerson;
import com.usky.system.domain.SysUserPerson;
import com.usky.system.mapper.SysPersonMapper;
import com.usky.system.service.SysPersonService;
import com.usky.system.service.SysUserPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 人员信息 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-08-22
 */
@Service
public class SysPersonServiceImpl extends AbstractCrudService<SysPersonMapper, SysPerson> implements SysPersonService {
    @Autowired
    private SysUserPersonService sysUserPersonService;

    @Override
    public SysPerson getsysPerson(Long userid) {
        LambdaQueryWrapper<SysUserPerson> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(SysUserPerson::getUserId, userid);
        List<SysUserPerson> userPersonList = sysUserPersonService.list(queryWrapper);
        SysPerson sysPerson = new SysPerson();
        if (CollectionUtils.isNotEmpty(userPersonList)) {
            LambdaQueryWrapper<SysPerson> query = Wrappers.lambdaQuery();
            query.eq(SysPerson::getId, userPersonList.get(0).getPersonId());
            sysPerson = this.getOne(query);
        }
        return sysPerson;
    }
}
