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

import cn.com.ctop.common.module.entity.SysUser;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.wps.entity.WpsUser;
import org.jeecg.modules.wps.mapper.WpsUserMapper;
import org.jeecg.modules.wps.service.IWpsUserService;
import org.springframework.beans.factory.annotation.Autowired;
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 {

    @Autowired
    private ISysUserService sysUserService;
    @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()) {
            for (String id : ids) {
                SysUser getUser = sysUserService.getById(id);
                if (getUser != null){
                    WpsUser user = new WpsUser();
                    user.setId(getUser.getId());
                    user.setName(getUser.getRealname());
                    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;
    }
}
