package com.njcn.prepare.harmonic.service.mysql.Impl.area;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.harmonic.pojo.po.PmsMonitorPO;
import com.njcn.prepare.harmonic.constant.PqsPrepareExceptionEnum;
import com.njcn.prepare.harmonic.mapper.mysql.area.PmsMonitorPOMapper;
import com.njcn.prepare.harmonic.service.mysql.area.PmsMonitorPOService;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.user.api.DeptFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

import static com.njcn.system.pojo.constant.DicDataConstant.NAME_KEY;
import static com.njcn.system.pojo.constant.DicDataConstant.SPLIT_SIGN;

/**
 *
 * Description:
 * 接口文档访问地址：http://serverIP:port/swagger-ui.html
 * Date: 2022/11/29  15:32【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
public class PmsMonitorPOServiceImpl extends ServiceImpl<PmsMonitorPOMapper, PmsMonitorPO> implements PmsMonitorPOService{

    private @Autowired
    RedisUtil redisUtil;

    private @Autowired
    PmsMonitorPOMapper pmsMonitorPOMapper;

    private @Autowired
    DeptFeignClient deptFeignClient;

    /**
     * @Description: 在运监测点集合
     * @Param: [orgid]
     * @return: java.lang.Integer
     * @Author: clam
     * @Date: 2022/11/25
     */
    @Override
    public List<PmsMonitorPO> qurymeasurementRunPoints(String orgid) {

        LambdaQueryWrapper<PmsMonitorPO> monitorPOLambdaQueryWrapper = new LambdaQueryWrapper ( );
        /*获取当前部门及子部门*/
        List<String> deptIds = deptFeignClient.getDepSonSelfCodetByDeptId(orgid).getData();

        monitorPOLambdaQueryWrapper.in (PmsMonitorPO::getOrgId, deptIds);
//        List<DictData> data = dicDataFeignClient.getDicDataByTypeCode (DicDataTypeEnum.LINE_STATE.getCode ( )).getData ( );
//        List<DictData> collect = data.stream ( ).filter (temp -> Objects.equals (temp.getCode ( ), DicDataEnum.RUN.getCode ())).collect (Collectors.toList ( ));
        String state = redisUtil.getStringByKey (NAME_KEY+
                SPLIT_SIGN+ DicDataTypeEnum.LINE_STATE.getCode ( )+
                SPLIT_SIGN+ DicDataEnum.RUN.getCode ( ));
        if(StringUtils.isEmpty (state)){
            throw  new BusinessException (PqsPrepareExceptionEnum.REDIS_NULL_EXCEPTION);
        }
        monitorPOLambdaQueryWrapper.eq (PmsMonitorPO::getMonitorState, state);
        List<PmsMonitorPO> pmsMonitorPOS = pmsMonitorPOMapper.selectList (monitorPOLambdaQueryWrapper);
        return pmsMonitorPOS;
    }
}
