package com.huimv.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.PjData;
import com.huimv.admin.entity.vo.EnergyAllDataVo;
import com.huimv.admin.mapper.PjDataMapper;
import com.huimv.admin.service.IPjDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-08-07
 */
@Service
public class PjDataServiceImpl extends ServiceImpl<PjDataMapper, PjData> implements IPjDataService {

    @Autowired
    private PjDataMapper pjDataMapper;

    @Override
    public Result listPjData(Map<String, String> paramsMap) {

        String farmId = paramsMap.get("farmId");
        QueryWrapper<PjData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId);
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
        queryWrapper.ge("create_date", calendar.getTime());
        List<EnergyAllDataVo> energyGasDataVos = pjDataMapper.listDayGas(queryWrapper);
        return new Result(ResultCode.SUCCESS, energyGasDataVos);

    }
}
