|
@@ -30,8 +30,14 @@ import vip.xiaonuo.common.listener.CommonDataChangeEventCenter;
|
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
|
import vip.xiaonuo.common.page.CommonPageRequest;
|
|
import vip.xiaonuo.common.pojo.CommonResult;
|
|
import vip.xiaonuo.common.pojo.CommonResult;
|
|
import vip.xiaonuo.core.enums.EnvDataTypeEnum;
|
|
import vip.xiaonuo.core.enums.EnvDataTypeEnum;
|
|
|
|
+import vip.xiaonuo.modular.base.baseConfig.entity.BaseConfig;
|
|
|
|
+import vip.xiaonuo.modular.base.baseConfig.mapper.BaseConfigMapper;
|
|
|
|
+import vip.xiaonuo.modular.base.pigpen.entity.BasePigpen;
|
|
|
|
+import vip.xiaonuo.modular.base.pigpen.mapper.BasePigpenMapper;
|
|
|
|
+import vip.xiaonuo.modular.energy.energyDevice.entity.EnergyDevice;
|
|
import vip.xiaonuo.modular.env.entity.EnvDeviceEquipment;
|
|
import vip.xiaonuo.modular.env.entity.EnvDeviceEquipment;
|
|
import vip.xiaonuo.modular.env.envdevice.entity.EnvDevice;
|
|
import vip.xiaonuo.modular.env.envdevice.entity.EnvDevice;
|
|
|
|
+import vip.xiaonuo.modular.env.envdevice.entity.vo.EnvDeviceCountVo;
|
|
import vip.xiaonuo.modular.env.envdevice.mapper.EnvDeviceMapper;
|
|
import vip.xiaonuo.modular.env.envdevice.mapper.EnvDeviceMapper;
|
|
import vip.xiaonuo.modular.env.envdevice.param.EnvDeviceAddParam;
|
|
import vip.xiaonuo.modular.env.envdevice.param.EnvDeviceAddParam;
|
|
import vip.xiaonuo.modular.env.envdevice.param.EnvDeviceEditParam;
|
|
import vip.xiaonuo.modular.env.envdevice.param.EnvDeviceEditParam;
|
|
@@ -42,10 +48,8 @@ import vip.xiaonuo.modular.env.mapper.EnvDeviceEquipmentMapper;
|
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
import javax.validation.constraints.NotBlank;
|
|
import java.text.NumberFormat;
|
|
import java.text.NumberFormat;
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 环控设备Service接口实现类
|
|
* 环控设备Service接口实现类
|
|
@@ -60,22 +64,10 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
private EnvDeviceMapper envDeviceMapper;
|
|
private EnvDeviceMapper envDeviceMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private EnvDeviceEquipmentMapper equipmentMapper;
|
|
private EnvDeviceEquipmentMapper equipmentMapper;
|
|
-
|
|
|
|
-// @Override
|
|
|
|
-// public Page<EnvDevice> page(EnvDevicePageParam envDevicePageParam) {
|
|
|
|
-// String orgId = StpLoginUserUtil.getLoginUser().getOrgId();
|
|
|
|
-// QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
|
-// queryWrapper.eq("d.org_id",orgId).orderByAsc("d.id");
|
|
|
|
-// if(ObjectUtil.isNotEmpty(envDevicePageParam.getDeviceType())) {
|
|
|
|
-// queryWrapper.eq("d.device_type", envDevicePageParam.getDeviceType());
|
|
|
|
-// }
|
|
|
|
-// if(ObjectUtil.isNotEmpty(envDevicePageParam.getInstallPosition())) {
|
|
|
|
-// queryWrapper.eq("d.install_position", envDevicePageParam.getInstallPosition());
|
|
|
|
-// }
|
|
|
|
-// return envDeviceMapper.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
|
-//
|
|
|
|
-//
|
|
|
|
-// }
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseConfigMapper baseConfigMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BasePigpenMapper basePigpenMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Page<EnvDevice> page(EnvDevicePageParam envDevicePageParam) {
|
|
public Page<EnvDevice> page(EnvDevicePageParam envDevicePageParam) {
|
|
@@ -85,10 +77,36 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
if(ObjectUtil.isNotEmpty(envDevicePageParam.getDeviceType())) {
|
|
if(ObjectUtil.isNotEmpty(envDevicePageParam.getDeviceType())) {
|
|
queryWrapper.eq("device_type", envDevicePageParam.getDeviceType());
|
|
queryWrapper.eq("device_type", envDevicePageParam.getDeviceType());
|
|
}
|
|
}
|
|
- if(ObjectUtil.isNotEmpty(envDevicePageParam.getInstallPosition())) {
|
|
|
|
- queryWrapper.eq("install_position", envDevicePageParam.getInstallPosition());
|
|
|
|
|
|
+ String installPosition = envDevicePageParam.getInstallPosition();
|
|
|
|
+ List<String> pigpenList = new ArrayList<>();
|
|
|
|
+ if(ObjectUtil.isNotEmpty(installPosition)) {
|
|
|
|
+ BasePigpen basePigpen = basePigpenMapper.selectById(installPosition);
|
|
|
|
+ Integer type = basePigpen.getType();
|
|
|
|
+ switch (type) {
|
|
|
|
+ case 0:
|
|
|
|
+ List<BasePigpen> basePigpens = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().lambda().eq(BasePigpen::getParentId, basePigpen.getId()));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(basePigpens)) {
|
|
|
|
+ pigpenList.addAll(basePigpens.stream().map(basePigpen1 -> basePigpen1.getId()).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ for (BasePigpen pigpen : basePigpens) {
|
|
|
|
+ List<BasePigpen> childPigpens = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().lambda().eq(BasePigpen::getParentId, pigpen.getId()));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(childPigpens)) {
|
|
|
|
+ pigpenList.addAll(childPigpens.stream().map(basePigpen2 -> basePigpen2.getId()).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ List<BasePigpen> pigpens = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().lambda().eq(BasePigpen::getParentId, basePigpen.getId()));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(pigpens)) {
|
|
|
|
+ pigpenList.addAll(pigpens.stream().map(basePigpen3 -> basePigpen3.getId()).collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+ case 2:
|
|
|
|
+ pigpenList.add(installPosition);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ queryWrapper.lambda().in(EnvDevice::getInstallPosition, pigpenList);
|
|
}
|
|
}
|
|
- return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
|
|
|
+ return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -135,10 +153,28 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Override
|
|
@Override
|
|
public void edit(EnvDeviceEditParam envDeviceEditParam) {
|
|
public void edit(EnvDeviceEditParam envDeviceEditParam) {
|
|
|
|
+ String orgId = StpLoginUserUtil.getLoginUser().getOrgId();
|
|
EnvDevice envDevice = this.queryEntity(envDeviceEditParam.getId());
|
|
EnvDevice envDevice = this.queryEntity(envDeviceEditParam.getId());
|
|
BeanUtil.copyProperties(envDeviceEditParam, envDevice);
|
|
BeanUtil.copyProperties(envDeviceEditParam, envDevice);
|
|
|
|
+ if (this.count(new QueryWrapper<EnvDevice>().lambda()
|
|
|
|
+ .eq(EnvDevice::getOrgId,orgId)
|
|
|
|
+ .eq(EnvDevice::getDeviceCode,envDevice.getDeviceCode())
|
|
|
|
+ .ne(EnvDevice::getId,envDevice.getId())) > 0) {
|
|
|
|
+ throw new CommonException("存在相同设备编号,编号为:{}",envDevice.getDeviceCode());
|
|
|
|
+ }
|
|
|
|
+ if (this.count(new QueryWrapper<EnvDevice>().lambda()
|
|
|
|
+ .eq(EnvDevice::getOrgId,orgId)
|
|
|
|
+ .eq(EnvDevice::getDeviceName,envDevice.getDeviceName())
|
|
|
|
+ .ne(EnvDevice::getId,envDevice.getId())) > 0) {
|
|
|
|
+ throw new CommonException("存在相同设备名称,名称为:{}",envDevice.getDeviceName());
|
|
|
|
+ }
|
|
|
|
+ if (this.count(new QueryWrapper<EnvDevice>().lambda()
|
|
|
|
+ .eq(EnvDevice::getOrgId,orgId)
|
|
|
|
+ .eq(EnvDevice::getInstallPosition,envDevice.getInstallPosition())
|
|
|
|
+ .ne(EnvDevice::getId,envDevice.getId())) > 0) {
|
|
|
|
+ throw new CommonException("该位置已存在设备!");
|
|
|
|
+ }
|
|
this.updateById(envDevice);
|
|
this.updateById(envDevice);
|
|
-
|
|
|
|
CommonDataChangeEventCenter.doUpdateWithData(EnvDataTypeEnum.DEVICE.getValue(), JSONUtil.createArray().put(envDevice));
|
|
CommonDataChangeEventCenter.doUpdateWithData(EnvDataTypeEnum.DEVICE.getValue(), JSONUtil.createArray().put(envDevice));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -167,29 +203,40 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Map deviceCount() {
|
|
|
|
- Map resultMap = new HashMap();
|
|
|
|
|
|
+ public EnvDeviceCountVo deviceCount() {
|
|
|
|
+ EnvDeviceCountVo envDeviceCountVo = new EnvDeviceCountVo();
|
|
String orgId = StpLoginUserUtil.getLoginUser().getOrgId();
|
|
String orgId = StpLoginUserUtil.getLoginUser().getOrgId();
|
|
-// .eq(EnvDevice::getDeleteFlag,"NOT_DELETE")
|
|
|
|
long deviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getOrgId, orgId));
|
|
long deviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getOrgId, orgId));
|
|
if (deviceNum == 0){
|
|
if (deviceNum == 0){
|
|
- resultMap.put("deviceNum",0);
|
|
|
|
- resultMap.put("onDeviceNum",0);
|
|
|
|
- resultMap.put("offDeviceNum",0);
|
|
|
|
- resultMap.put("onlineRate",0);
|
|
|
|
|
|
+ envDeviceCountVo.setDeviceNum(0L);
|
|
|
|
+ envDeviceCountVo.setOnDeviceNum(0L);
|
|
|
|
+ envDeviceCountVo.setOffDeviceNum(0L);
|
|
|
|
+ envDeviceCountVo.setOnlineRate("0%");
|
|
}else {
|
|
}else {
|
|
- resultMap.put("deviceNum",deviceNum);
|
|
|
|
|
|
+ envDeviceCountVo.setDeviceNum(deviceNum);
|
|
long onDeviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getStatus,"1").eq(EnvDevice::getOrgId, orgId));
|
|
long onDeviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getStatus,"1").eq(EnvDevice::getOrgId, orgId));
|
|
- resultMap.put("onDeviceNum",onDeviceNum);
|
|
|
|
|
|
+ envDeviceCountVo.setOnDeviceNum(onDeviceNum);
|
|
long offDeviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getStatus,"1").eq(EnvDevice::getOrgId, orgId));
|
|
long offDeviceNum = this.count(new QueryWrapper<EnvDevice>().lambda().eq(EnvDevice::getStatus,"1").eq(EnvDevice::getOrgId, orgId));
|
|
- resultMap.put("offDeviceNum",offDeviceNum);
|
|
|
|
|
|
+ envDeviceCountVo.setOffDeviceNum(offDeviceNum);
|
|
//创建一个数值格式化对象
|
|
//创建一个数值格式化对象
|
|
NumberFormat numberFormat = NumberFormat.getInstance();
|
|
NumberFormat numberFormat = NumberFormat.getInstance();
|
|
//设置精确到小数点后两位
|
|
//设置精确到小数点后两位
|
|
numberFormat.setMaximumFractionDigits(2);
|
|
numberFormat.setMaximumFractionDigits(2);
|
|
String onlineRate = numberFormat.format((float)onDeviceNum / (float) deviceNum* 100) + "%";
|
|
String onlineRate = numberFormat.format((float)onDeviceNum / (float) deviceNum* 100) + "%";
|
|
- resultMap.put("onlineRate",onlineRate);
|
|
|
|
|
|
+ envDeviceCountVo.setOnlineRate(onlineRate);
|
|
|
|
+ }
|
|
|
|
+ return envDeviceCountVo;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<String> deviceTypeSelector() {
|
|
|
|
+ String orgId = StpLoginUserUtil.getLoginUser().getOrgId();
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ String parentId = baseConfigMapper.selectOne(new QueryWrapper<BaseConfig>().lambda().eq(BaseConfig::getParentId, 0).eq(BaseConfig::getConfigName, "设备类型")).getId();
|
|
|
|
+ List<BaseConfig> baseConfigs = baseConfigMapper.selectList(new QueryWrapper<BaseConfig>().lambda().eq(BaseConfig::getParentId, parentId).eq(BaseConfig::getOrgId, orgId));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(baseConfigs)){
|
|
|
|
+ list = baseConfigs.stream().map(baseConfig -> baseConfig.getConfigName()).collect(Collectors.toList());
|
|
}
|
|
}
|
|
- return resultMap;
|
|
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
}
|
|
}
|