package org.jeecg.modules.wps.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.wps.mapper.WpsUserMapper;
import org.jeecg.modules.wps.entity.WpsUser;
import org.jeecg.modules.wps.service.IWpsUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * wps用户
 * @author jeecg-boot
 * @date   2020-06-01
 * @version V1.0
 */
@Service
public class WpsUserServiceImpl extends ServiceImpl<WpsUserMapper, WpsUser> implements IWpsUserService {

    @Override
    public Map<String,Object> userInfo(JSONObject reqObj){
        List<String> ids = null;

        if(reqObj != null) {
            if(reqObj.containsKey("ids")) {
                ids = JSONArray.parseArray(reqObj.getString("ids"), String.class);
            }
        }

        Map<String,Object> map = new HashMap<>();
        List<WpsUser> users = new ArrayList<>();
        if(ids != null && !ids.isEmpty()) {
            WpsUser user;
            for (String id : ids) {
                user = this.getById(id);
                if (user != null){
                    users.add(user);
                }
            }
        }
        map.put("users", users);
        return map;
    }

    @Override
    public List<WpsUser> findByIdIn(List<String> userIdList) {
        if(null==userIdList||userIdList.isEmpty()){
            return null;
        }
        List<WpsUser> userList = new ArrayList<>();
        for (String id :userIdList){
            WpsUser user = this.getById(id);
            if(null!=user){
                userList.add(user);
            }
        }
        return userList;
    }
}
