package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.entity.CorpFeishuUser;
import cn.com.ctop.common.module.mapper.CorpFeishuUserMapper;
import cn.com.ctop.common.module.service.ICorpFeishuUserService;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 飞书用户信息
 * @author jeecg-boot
 * @date   2020-06-23
 * @version V1.0
 */
@Service
public class CorpFeishuUserServiceImpl extends ServiceImpl<CorpFeishuUserMapper, CorpFeishuUser> implements ICorpFeishuUserService {

    @Autowired
    private CorpFeishuUserMapper corpFeishuUserMapper;
    @Override
    public CorpFeishuUser getByUserId(String userId) {
        QueryWrapper<CorpFeishuUser>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.orderByDesc("id").last("limit 1");
        return this.getOne(queryWrapper);
    }

    @Override
    public JSONArray getOpenIdByParams(Long projectId) {
        List<String> openIds = corpFeishuUserMapper.getOpenIdByParams(projectId);
        if(null == openIds&&openIds.isEmpty()){
            return null;
        }
        JSONArray result = new JSONArray();
        for(int i=0;i<openIds.size();i++){
            result.add(openIds.get(i));
        }
        return result;
    }
}
