package com.njcn.csdevice.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.mapper.CsEngineeringUserMapper;
import com.njcn.csdevice.pojo.po.CsEngineeringPO;
import com.njcn.csdevice.pojo.po.CsEngineeringUserPO;
import com.njcn.csdevice.service.CsEngineeringService;
import com.njcn.csdevice.service.ICsEngineeringUserService;
import com.njcn.web.utils.RequestUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 工程用户关系表 服务实现类
 * </p>
 *
 * @author xuyang
 * @since 2023-05-29
 */
@Service
@RequiredArgsConstructor
public class CsEngineeringUserServiceImpl extends ServiceImpl<CsEngineeringUserMapper, CsEngineeringUserPO> implements ICsEngineeringUserService {

    private final CsEngineeringService csEngineeringService;

    @Override
    public List<CsEngineeringPO> getEngineeringByUser() {
        List<CsEngineeringPO> result = new ArrayList<>();
        List<CsEngineeringUserPO> list = this.lambdaQuery().eq(CsEngineeringUserPO::getUserId, RequestUtil.getUserIndex()).list();
        List<String> engineering = list.stream().map(CsEngineeringUserPO::getEngineeringId).collect(Collectors.toList());
        if (CollectionUtil.isNotEmpty(engineering)) {
            result = csEngineeringService.getEngineerings(engineering);
        }
        return result;
    }
}
