From 47a751cb301d05276ae5d75145d57b2d090fe4e1 Mon Sep 17 00:00:00 2001
From: kongzy <kongzy>
Date: 星期一, 01 七月 2024 10:58:35 +0800
Subject: [PATCH] change

---
 src/main/java/com/nanometer/smartlab/service/SysWarehouseStatusServiceImpl.java |   71 ++++++++++++++++++++++++++++++++++-
 1 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/nanometer/smartlab/service/SysWarehouseStatusServiceImpl.java b/src/main/java/com/nanometer/smartlab/service/SysWarehouseStatusServiceImpl.java
index 6fe341b..0d1db46 100644
--- a/src/main/java/com/nanometer/smartlab/service/SysWarehouseStatusServiceImpl.java
+++ b/src/main/java/com/nanometer/smartlab/service/SysWarehouseStatusServiceImpl.java
@@ -1,6 +1,7 @@
 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;
@@ -9,21 +10,87 @@
 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
+@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) {
+        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);
+    }
 }

--
Gitblit v1.9.2