package com.xueyi.system.digitalmans.service.impl;

import com.xueyi.system.api.organize.domain.dto.SysUserDto;
import com.xueyi.system.api.organize.domain.query.SysUserQuery;
import com.xueyi.system.digitalmans.domain.dto.DmQuestionsDto;
import com.xueyi.system.digitalmans.domain.query.DmQuestionsQuery;
import com.xueyi.system.digitalmans.service.IDmQuestionsService;
import com.xueyi.system.digitalmans.manager.IDmQuestionsManager;
import com.xueyi.common.web.entity.service.impl.BaseServiceImpl;
import com.xueyi.system.organize.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 企业知识库问题管理 服务层处理
 *
 * @author yinruoxi
 */
@Service
public class DmQuestionsServiceImpl extends BaseServiceImpl<DmQuestionsQuery, DmQuestionsDto, IDmQuestionsManager> implements IDmQuestionsService {

    @Autowired
    private ISysUserService iSysUserService;
    /**
     * 查询企业知识库问题对象列表 | 数据权限
     *
     * @param questions 企业知识库问题对象
     * @return 企业知识库问题对象集合
     */
    @Override
    //@DataScope(userAlias = "createBy", mapperScope = {"DmQuestionsMapper"})
    public List<DmQuestionsDto> selectListScope(DmQuestionsQuery questions) {
        SysUserQuery userQuery = new SysUserQuery();
        List<SysUserDto> userDtos = iSysUserService.selectList(userQuery);

        List<DmQuestionsDto> questionsDtos = baseManager.selectList(questions);
        questionsDtos.forEach(questionsDto -> {
            userDtos.forEach(userDto -> {
                if (userDto.getId().equals(questionsDto.getCreateBy())) {
                    questionsDto.setCreator(userDto.getUserName());
                }
            });
        });
        return questionsDtos;
    }

}