package com.usky.park.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.park.domain.DataGrHistory;
import com.usky.park.domain.DataLgHistory;
import com.usky.park.mapper.DataLgHistoryMapper;
import com.usky.park.service.DataLgHistoryService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 照明系统历史数据 服务实现类
 * </p>
 *
 * @author zyj
 * @since 2023-04-03
 */
@Service
public class DataLgHistoryServiceImpl extends AbstractCrudService<DataLgHistoryMapper, DataLgHistory> implements DataLgHistoryService {

    @Override
    public Map<String,Object> ElectricalStatistics(String deviceId,String startDate,String endDate)
    {
        Map<String,Object> map = new HashMap<>();
        LambdaQueryWrapper<DataLgHistory> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(StringUtils.isNotBlank(deviceId),DataLgHistory::getDeviceId,deviceId)
                .eq(DataLgHistory::getAttributeName,"switch_status")
                .between(DataLgHistory::getDataTime,startDate,endDate)
                .eq(DataLgHistory::getAttributeData,"1");
        int count = this.count(queryWrapper);
        map.put("count",count);

        return map;
    }
}
