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;
|
|
@Service
|
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);
|
}
|
}
|