package com.huimv.admin.service.impl;

import com.huimv.admin.common.utils.Result;
import com.huimv.admin.entity.EnvData;
import com.huimv.admin.mapper.EnvDataMapper;
import com.huimv.admin.service.IEnvDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-02-14
 */
@Service
public class EnvDataServiceImpl extends ServiceImpl<EnvDataMapper, EnvData> implements IEnvDataService {

    @Autowired
    private EnvDataMapper dataMapper;

    @Override
    public Result add(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) throws ParseException {
        String temp = paramsMap.get("temp");
        String hum = paramsMap.get("hum");
        String time = paramsMap.get("time");
        String farmId = paramsMap.get("farmId");
        String unitId = paramsMap.get("unitId");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if ("".equals(time) || null == time) {
            time = sdf.format(new Date());
        }
        EnvData data = new EnvData();
        data.setEnvTemp(temp);
        data.setEnvHum(hum);
        data.setFarmId(Integer.parseInt(farmId));
        data.setCreateTime(sdf.parse(time));
        data.setUnitId(Integer.parseInt(unitId));
        data.setOther1("1");//表示为
        return null;
    }
}
