|
@@ -3,15 +3,22 @@ package com.huaxu.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.huaxu.dao.DeviceParmMapper;
|
|
|
+import com.huaxu.dto.DeviceParmInfo;
|
|
|
import com.huaxu.dto.ReportAttributeDto;
|
|
|
import com.huaxu.dto.ReportDto;
|
|
|
import com.huaxu.entity.DeviceParmEntity;
|
|
|
+import com.huaxu.entity.DeviceSceneEntity;
|
|
|
+import com.huaxu.entity.SceneEntity;
|
|
|
import com.huaxu.model.LoginUser;
|
|
|
import com.huaxu.service.DeviceParmService;
|
|
|
+import com.huaxu.service.DeviceSceneService;
|
|
|
+import com.huaxu.service.SceneService;
|
|
|
import com.huaxu.util.UserUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -22,10 +29,14 @@ import java.util.List;
|
|
|
* @data 2020-11-17 11:02
|
|
|
*/
|
|
|
@Service
|
|
|
-public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
+public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
|
|
|
@Resource
|
|
|
private DeviceParmMapper deviceParmMapper;
|
|
|
+ @Autowired
|
|
|
+ private SceneService sceneService;
|
|
|
+ @Autowired
|
|
|
+ private DeviceSceneService deviceSceneService;
|
|
|
|
|
|
@Override
|
|
|
public DeviceParmEntity selectById(Integer id) {
|
|
@@ -33,8 +44,8 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DeviceParmEntity> selectByDeviceId(Integer id) {
|
|
|
- List<DeviceParmEntity> deviceParmEntities = deviceParmMapper.selectByDeviceId(id);
|
|
|
+ public List<DeviceParmEntity> selectByDeviceId(Integer sceneId, Integer id) {
|
|
|
+ List<DeviceParmEntity> deviceParmEntities = deviceParmMapper.selectByDeviceId(sceneId, id);
|
|
|
for (DeviceParmEntity item : deviceParmEntities) {
|
|
|
item.setDeviceId(id);
|
|
|
}
|
|
@@ -42,8 +53,8 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DeviceParmEntity> selectByDeviceIdForGis(Integer id) {
|
|
|
- List<DeviceParmEntity> deviceParmEntities = deviceParmMapper.selectByDeviceIdForGis(id);
|
|
|
+ public List<DeviceParmEntity> selectByDeviceIdForGis(Integer sceneId, Integer id) {
|
|
|
+ List<DeviceParmEntity> deviceParmEntities = deviceParmMapper.selectByDeviceIdForGis(sceneId, id);
|
|
|
for (DeviceParmEntity item : deviceParmEntities) {
|
|
|
item.setDeviceId(id);
|
|
|
}
|
|
@@ -64,9 +75,9 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Integer batchInsert(List<DeviceParmEntity> deviceParmEntities){
|
|
|
+ public Integer batchInsert(List<DeviceParmEntity> deviceParmEntities) {
|
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
- for(DeviceParmEntity deviceParmEntity:deviceParmEntities){
|
|
|
+ for (DeviceParmEntity deviceParmEntity : deviceParmEntities) {
|
|
|
deviceParmEntity.setDateUpdate(new Date());
|
|
|
deviceParmEntity.setUpdateBy(loginUser.getUsername());
|
|
|
deviceParmEntity.setDateCreate(new Date());
|
|
@@ -90,7 +101,7 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
@Override
|
|
|
public void batchUpdate(List<DeviceParmEntity> deviceParmEntities) {
|
|
|
LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
- for(DeviceParmEntity deviceParmEntity:deviceParmEntities){
|
|
|
+ for (DeviceParmEntity deviceParmEntity : deviceParmEntities) {
|
|
|
deviceParmEntity.setDateUpdate(new Date());
|
|
|
deviceParmEntity.setUpdateBy(loginUser.getUsername());
|
|
|
deviceParmMapper.update(deviceParmEntity);
|
|
@@ -116,7 +127,7 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
|
|
|
@Override
|
|
|
public IPage<DeviceParmEntity> selectPage(IPage<DeviceParmEntity> page, DeviceParmEntity deviceParmEntity) {
|
|
|
- return deviceParmMapper.selectPage(page,deviceParmEntity);
|
|
|
+ return deviceParmMapper.selectPage(page, deviceParmEntity);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -124,4 +135,72 @@ public class DeviceParmServiceImpl implements DeviceParmService {
|
|
|
return deviceParmMapper.findAttributeNameList(reportDto);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<DeviceParmInfo> selectBySceneAndDeviceId(Integer parentSceneId, Integer sceneId, Integer deviceId) {
|
|
|
+ List<DeviceParmInfo> deviceParmInfos = new ArrayList<>();
|
|
|
+ DeviceParmInfo deviceParmInfo = new DeviceParmInfo();
|
|
|
+ deviceParmInfo.setParentSceneId(parentSceneId.longValue());
|
|
|
+ deviceParmInfo.setSceneId(sceneId.longValue());
|
|
|
+ deviceParmInfo.setDeviceId(deviceId);
|
|
|
+ List<Long> ids = sceneService.findByParentIdsLike(parentSceneId.longValue());
|
|
|
+ if (ids.contains(sceneId.longValue())) {
|
|
|
+ ids.remove(sceneId.longValue());
|
|
|
+ }
|
|
|
+ deviceParmInfo.setSceneIds(ids);
|
|
|
+ deviceParmInfos = deviceParmMapper.findBySceneDeviceId(deviceParmInfo);
|
|
|
+ for (DeviceParmInfo item : deviceParmInfos) {
|
|
|
+ item.setSceneId(sceneId.longValue());
|
|
|
+ item.setParentSceneId(parentSceneId.longValue());
|
|
|
+ }
|
|
|
+ return deviceParmInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void batchSaveEdit(Long sceneId, Long deviceId, List<DeviceParmInfo> deviceParmInfos) {
|
|
|
+ //判断此设备是否已经被绑定
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ DeviceSceneEntity deviceSceneEntity = new DeviceSceneEntity();
|
|
|
+ deviceSceneEntity.setSceneId(sceneId);
|
|
|
+ deviceSceneEntity.setDeviceId(deviceId);
|
|
|
+ SceneEntity sceneEntity = sceneService.findParentSceneById(sceneId);
|
|
|
+ List<DeviceSceneEntity> deviceScenes = deviceSceneService.findList(deviceSceneEntity);
|
|
|
+ if (deviceParmInfos.size() == 0 && deviceScenes.size() > 0) {
|
|
|
+ //如果所有的参数未被选择,则取消掉设备与场景的关联关系
|
|
|
+ deviceSceneService.removeById(deviceScenes.get(0).getId());
|
|
|
+ } else if (deviceParmInfos.size() > 0) {
|
|
|
+ //没有的时候创建关联关系
|
|
|
+ if (deviceScenes.size() == 0) {
|
|
|
+ deviceSceneEntity.setParentSceneId(sceneEntity.getParentSceneId());
|
|
|
+ }
|
|
|
+ //查询已经绑定的所有参数
|
|
|
+ List<DeviceParmInfo> deviceParmInfoList = deviceParmMapper.selectBindByDeviceId(sceneId, deviceId);
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ for (DeviceParmInfo info : deviceParmInfoList) {
|
|
|
+ ids.add(info.getId());
|
|
|
+ }
|
|
|
+ for (DeviceParmInfo item : deviceParmInfos) {
|
|
|
+ if (ids.contains(item.getAttributeId().longValue())) {
|
|
|
+ ids.remove(item.getAttributeId().longValue());
|
|
|
+ } else if (!ids.contains(item.getAttributeId().longValue())) {
|
|
|
+ //新增
|
|
|
+ DeviceParmEntity deviceParmEntity = new DeviceParmEntity();
|
|
|
+ deviceParmEntity.setSceneId(sceneId);
|
|
|
+ deviceParmEntity.setParentSceneId(sceneEntity.getParentSceneId());
|
|
|
+ deviceParmEntity.setDeviceId(deviceId.intValue());
|
|
|
+ deviceParmEntity.setStatus(1);
|
|
|
+ deviceParmEntity.setAttributeId(item.getAttributeId());
|
|
|
+ deviceParmEntity.setAttributeName(item.getAttributeName());
|
|
|
+ deviceParmEntity.setCreateBy(loginUser.getName());
|
|
|
+ deviceParmEntity.setDateCreate(new Date());
|
|
|
+ deviceParmEntity.setUpdateBy(loginUser.getName());
|
|
|
+ deviceParmEntity.setDateUpdate(new Date());
|
|
|
+ this.insert(deviceParmEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //将ids 移除
|
|
|
+ for(Long id : ids) {
|
|
|
+ deviceParmMapper.deleteById(id.intValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|