package com.njcn.device.pms.service.majornetwork.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.device.pms.mapper.majornetwork.TerminalMapper;
import com.njcn.device.pms.pojo.param.RStatDevSignalParam;
import com.njcn.device.pms.pojo.po.RStatDevSignalD;
import com.njcn.device.pms.pojo.po.PmsTerminal;
import com.njcn.device.pms.pojo.vo.RStatDevSignalVO;
import com.njcn.device.pms.service.majornetwork.ITerminalService;
import com.njcn.device.pms.service.majornetwork.RStatDevSignalDService;
import com.njcn.device.pms.mapper.majornetwork.RStatDevSignalDMapper;
import com.njcn.event.pojo.po.RStatEventOrgQ;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import com.njcn.web.utils.WebUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @author jianghf
* @description 针对表【r_stat_dev_signal_d(终端通信管理日表)】的数据库操作Service实现
* @createDate 2022-11-11 15:35:35
*/
@Service
@RequiredArgsConstructor
public class RStatDevSignalDServiceImpl extends ServiceImpl<RStatDevSignalDMapper, RStatDevSignalD>
    implements RStatDevSignalDService{

    private final TerminalMapper terminalMapper;

    private final DeptFeignClient deptFeignClient;

    @Override
    public List<RStatDevSignalVO> getRStatDevSignalList(RStatDevSignalParam rStatDevSignalParam) {
        //提取查询条件
        String id = rStatDevSignalParam.getId(); //单位id

        if (StringUtils.isBlank(id)) {
            throw new BusinessException(CommonResponseEnum.NO_DATA, "单位id不可为空");
        }

        //获取所有子部门信息
        List<DeptDTO> deptDTOList = deptFeignClient.getDeptDescendantIndexes(id, WebUtil.filterDeptType()).getData();

        if (CollUtil.isEmpty(deptDTOList)) {
            throw new BusinessException(CommonResponseEnum.NO_DATA, "部门不存在");
        }
        //单位id集合
        List<String> orgCodeList = deptDTOList.stream().map(DeptDTO::getCode).collect(Collectors.toList());
        return terminalMapper.selectTerminalList(orgCodeList, rStatDevSignalParam);

    }
}




