kongzy
2023-11-28 59d9ea33f503e363f2e2941c7c00cc9dd9d9d1c7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.nanometer.smartlab.service;
 
import com.nanometer.smartlab.dao.SysWarehouseStatusDao;
import com.nanometer.smartlab.entity.SysWarehouse;
import com.nanometer.smartlab.entity.SysWarehouseStatus;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.exception.ExceptionEnumCode;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service("sysWarehouseStatusService")
public class SysWarehouseStatusServiceImpl implements SysWarehouseStatusService {
 
    @Resource
    private SysWarehouseStatusDao sysWarehouseStatusDao;
    @Resource
    private SysWarehouseService sysWarehouseService;
 
    @Override
    public void addOne(SysWarehouseStatus one) {
        if (one.getTemperature() == null || one.getHumidity() == null || one.getSelectDate() == null ||one.getWarehouseId() == null) {
            throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "参数不能为空");
        }
        if (StringUtils.isBlank(one.getName()) || StringUtils.isBlank(one.getType())) {
            throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "字符不能为空");
        }
        SysWarehouse sysWarehouse = sysWarehouseService.getSysWarehouse(one.getWarehouseId());
        if (sysWarehouse == null) {
            throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "查询不到仓库");
        }
        //温度
        BigDecimal temperatureMax = sysWarehouse.getTemperatureMax();
        BigDecimal temperatureMin = sysWarehouse.getTemperatureMin();
        if (temperatureMax == null || temperatureMin == null) {
            throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "仓库未设置温度阈值");
        }
        //湿度
        BigDecimal humidityMax = sysWarehouse.getHumidityMax();
        BigDecimal humidityMin = sysWarehouse.getHumidityMin();
        if (humidityMax == null || humidityMin == null) {
            throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "仓库未设置湿度阈值");
        }
 
        BigDecimal temperature = one.getTemperature();
        BigDecimal humidity = one.getHumidity();
        StringBuffer warningSb = new StringBuffer();
        if (temperature.compareTo(temperatureMin) < 0) {
            warningSb.append("温度小于仓库设置最小值;");
        }
        if (temperature.compareTo(temperatureMax) > 0) {
            warningSb.append("温度超过仓库设置最大值;");
        }
        if (humidity.compareTo(humidityMin) < 0) {
            warningSb.append("湿度小于仓库设置最小值;");
        }
        if (humidity.compareTo(humidityMax) > 0) {
            warningSb.append("湿度大于仓库设置最大值;");
        }
 
        one.setWarning(warningSb.toString());
        sysWarehouseStatusDao.insertOne(one);
    }
 
    @Override
    public int getCount(String name, Date startTime, Date endTime) {
        Map<String,Object> params = new HashMap<>();
        params.put("name", name);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        return sysWarehouseStatusDao.selectCount(params);
    }
 
    @Override
    public List<SysWarehouseStatus> selectList(String name, Date startTime, Date endTime, int first, int pageSize) {
        Map<String,Object> params = new HashMap<>();
        params.put("name", name);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("first", first);
        params.put("pageSize", pageSize);
        return sysWarehouseStatusDao.selectList(params);
    }
 
    @Override
    public SysWarehouseStatus getById(String rowKey) {
        return sysWarehouseStatusDao.selectById(rowKey);
    }
}