package com.njcn.product.event.transientes.service;

import cn.hutool.core.util.StrUtil;
import com.njcn.product.event.devcie.pojo.po.PqsDeptsline;
import com.njcn.product.event.devcie.service.PqsDeptslineService;
import com.njcn.product.event.transientes.pojo.param.LargeScreenCountParam;
import com.njcn.product.event.config.RedisUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

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

import static com.njcn.product.event.transientes.pojo.constant.RedisConstant.REDIS_DEPT_INDEX;

/**
 * @Author: cdf
 * @CreateTime: 2025-06-25
 * @Description:
 */
@Service
@RequiredArgsConstructor
public class CommGeneralService {
    @Value("${SYS_TYPE_ZT}")
    private String sysTypeZt;

    private final PqsDeptslineService pqsDeptslineService;
    private final PqsDeptsService pqsDeptsService;
    private final RedisUtil redisUtil;

    /**
     * 根据部门id获取部门所拥有的监测点
     * @param largeScreenCountParam
     * @return
     */
    public List<Integer> getLineIdsByDept(LargeScreenCountParam largeScreenCountParam){
        List<String> deptAndChildren = pqsDeptsService.findDeptAndChildren(largeScreenCountParam.getDeptId());
        List<PqsDeptsline> deptslines = pqsDeptslineService.lambdaQuery().in(PqsDeptsline::getDeptsIndex, deptAndChildren).eq(PqsDeptsline::getSystype, sysTypeZt).list();
        List<Integer> deptslineIds = deptslines.stream().map(PqsDeptsline::getLineIndex).collect(Collectors.toList());
        return deptslineIds;

    }


    public List<Integer> getLineIdsByRedis(String deptId){
      List<Integer> deptLineIds = (List<Integer>) redisUtil.getObjectByKey( REDIS_DEPT_INDEX+ StrUtil.DASHED+deptId);
      return  deptLineIds;
    }


}
