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.DmQAndADto;
import com.xueyi.system.digitalmans.domain.dto.DmQuestionsDto;
import com.xueyi.system.digitalmans.domain.query.DmQAndAQuery;
import com.xueyi.system.digitalmans.service.IDmQAndAService;
import com.xueyi.system.digitalmans.manager.IDmQAndAManager;
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 DmQAndAServiceImpl extends BaseServiceImpl<DmQAndAQuery, DmQAndADto, IDmQAndAManager> implements IDmQAndAService {

    @Autowired
    private ISysUserService iSysUserService;
    /**
     * 查询企业知识库问答对象列表 | 数据权限
     *
     * @param qAndA 企业知识库问答对象
     * @return 企业知识库问答对象集合
     */
    @Override
    //@DataScope(userAlias = "createBy", mapperScope = {"DmQAndAMapper"})
    public List<DmQAndADto> selectListScope(DmQAndAQuery qAndA) {

        SysUserQuery userQuery = new SysUserQuery();
        List<SysUserDto> userDtos = iSysUserService.selectList(userQuery);

        List<DmQAndADto> qAndADtos = baseManager.selectList(qAndA);
        qAndADtos.forEach(qAndADto -> {
            userDtos.forEach(userDto -> {
                if (userDto.getId().equals(qAndADto.getCreateBy())) {
                    qAndADto.setCreator(userDto.getUserName());
                }
            });
        });
        return baseManager.selectList(qAndA);
    }


    @Override
    public Integer batchInsert(List<DmQAndADto> queryList) {
        return baseManager.insertBatch(queryList);
    }
}