whycxzp
2025-04-30 d19e91bcc4ed9ab08e8be375fb5fc0f7e874a6a9
src/main/java/com/whyc/service/EnvironmentThresholdService.java
@@ -1,5 +1,7 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.mapper.EnvironmentThresholdMapper;
import com.whyc.pojo.db_fire_robot.EnvironmentThreshold;
import org.springframework.stereotype.Service;
@@ -15,4 +17,16 @@
    public void add(EnvironmentThreshold threshold) {
        mapper.insert(threshold);
    }
    public void addOrUpdate(EnvironmentThreshold threshold) {
        QueryWrapper<EnvironmentThreshold> query = Wrappers.query();
        query.last(" limit 1");
        EnvironmentThreshold thresholdInDB = mapper.selectOne(query);
        if (thresholdInDB ==null) {
            mapper.insert(threshold);
        }else{
            threshold.setId(thresholdInDB.getId());
            mapper.updateById(threshold);
        }
    }
}