package com.usky.iot.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.backend.client.DataQueryClient;
import com.usky.backend.domain.StatusVO;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.iot.domain.BaseAlarm;
import com.usky.iot.domain.DmpDeviceInfo;
import com.usky.iot.domain.DmpDeviceStatus;
import com.usky.iot.mapper.DmpDeviceStatusMapper;
import com.usky.iot.service.BaseAlarmService;
import com.usky.iot.service.DmpDeviceStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备状态表 服务实现类
 * </p>
 *
 * @author ya
 * @since 2022-10-08
 */
@Service
public class DmpDeviceStatusServiceImpl extends AbstractCrudService<DmpDeviceStatusMapper, DmpDeviceStatus> implements DmpDeviceStatusService {

    @Override
    public List<Map<String, Object>> getCollectByProduct(List<Integer> productIds) {
        QueryWrapper<DmpDeviceStatus> query = Wrappers.query();
        query.select("product_id as productId","count(device_status != 2 or null) as deviceCount")
                .in(CollectionUtil.isNotEmpty(productIds),"product_id",productIds)
                .groupBy("product_id");
        return this.listMaps(query);
    }
}
