whycxzp
2025-04-30 b278d488be1d5e626eecdcfc2201b97dc85937cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
 
import javax.annotation.Resource;
 
@Service
public class EnvironmentThresholdService {
 
    @Resource
    private EnvironmentThresholdMapper mapper;
 
    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);
        }
    }
}