Merge branch 'master' into 1.0.0

This commit is contained in:
pnoker
2020-07-07 23:00:19 +08:00
6 changed files with 82 additions and 61 deletions
@@ -18,12 +18,14 @@ package com.dc3.center.manager.api;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dc3.api.center.manager.feign.ProfileClient;
import com.dc3.center.manager.service.DriverService;
import com.dc3.center.manager.service.NotifyService;
import com.dc3.center.manager.service.ProfileService;
import com.dc3.common.bean.R;
import com.dc3.common.constant.Common;
import com.dc3.common.constant.Operation;
import com.dc3.common.dto.ProfileDto;
import com.dc3.common.model.Driver;
import com.dc3.common.model.Profile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -41,6 +43,8 @@ import javax.annotation.Resource;
@RequestMapping(Common.Service.DC3_MANAGER_PROFILE_URL_PREFIX)
public class ProfileApi implements ProfileClient {
@Resource
private DriverService driverService;
@Resource
private ProfileService profileService;
@Resource
@@ -51,7 +55,8 @@ public class ProfileApi implements ProfileClient {
try {
Profile add = profileService.add(profile);
if (null != add) {
notifyService.notifyDriverProfile(profile.getId(), Operation.Profile.ADD);
Driver driver = driverService.selectByProfileId(profile.getId());
notifyService.notifyDriverProfile(driver, profile.getId(), Operation.Profile.ADD);
return R.ok(add);
}
} catch (Exception e) {
@@ -63,8 +68,9 @@ public class ProfileApi implements ProfileClient {
@Override
public R<Boolean> delete(Long id) {
try {
Driver driver = driverService.selectByProfileId(id);
if (profileService.delete(id)) {
notifyService.notifyDriverProfile(id, Operation.Profile.DELETE);
notifyService.notifyDriverProfile(driver, id, Operation.Profile.DELETE);
return R.ok();
}
} catch (Exception e) {
@@ -45,6 +45,22 @@ public interface DriverService extends Service<Driver, DriverDto> {
*/
Driver selectByHostPort(String host, Integer port);
/**
* 根据 DEVICE ID 查询
*
* @param deviceId Device Id
* @return Driver
*/
Driver selectByDeviceId(Long deviceId);
/**
* 根据 PROFILE ID 查询
*
* @param profileId Profile Id
* @return Driver
*/
Driver selectByProfileId(Long profileId);
/**
* 查询 Driver 服务状态
*
@@ -16,6 +16,8 @@
package com.dc3.center.manager.service;
import com.dc3.common.model.Driver;
/**
* <p>Notify Interface
*
@@ -26,10 +28,11 @@ public interface NotifyService {
/**
* 通知驱动 新增模板(ADD) / 删除模板(DELETE)
*
* @param driver driver
* @param profileId Profile Id
* @param operationType Operation Type
*/
void notifyDriverProfile(Long profileId, String operationType);
void notifyDriverProfile(Driver driver, Long profileId, String operationType);
/**
* 通知驱动 新增设备(ADD) / 删除设备(DELETE) / 修改设备(UPDATE)
@@ -43,7 +46,7 @@ public interface NotifyService {
/**
* 通知驱动 新增位号(ADD) / 删除位号(DELETE) / 修改位号(UPDATE)
*
* @param pointId
* @param pointId Point Id
* @param profileId Profile Id
* @param operationType Operation Type
*/
@@ -33,7 +33,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -135,7 +134,7 @@ public class BatchServiceImpl implements BatchService {
throw new ServiceException("Add profile failed: " + batchProfile.getName());
}
notifyService.notifyDriverProfile(profile.getId(), Operation.Profile.ADD);
notifyService.notifyDriverProfile(driver, profile.getId(), Operation.Profile.ADD);
ThreadUtil.sleep(1, TimeUnit.SECONDS);
}
return profile;
@@ -20,6 +20,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dc3.center.manager.mapper.DriverMapper;
import com.dc3.center.manager.service.DeviceService;
import com.dc3.center.manager.service.DriverService;
import com.dc3.center.manager.service.ProfileService;
import com.dc3.common.bean.Pages;
@@ -27,6 +28,7 @@ import com.dc3.common.constant.Common;
import com.dc3.common.dto.DriverDto;
import com.dc3.common.dto.ProfileDto;
import com.dc3.common.exception.ServiceException;
import com.dc3.common.model.Device;
import com.dc3.common.model.Driver;
import com.dc3.common.model.Profile;
import com.netflix.discovery.EurekaClient;
@@ -54,6 +56,10 @@ public class DriverServiceImpl implements DriverService {
@Resource
private EurekaClient eurekaClient;
@Resource
private DriverService driverService;
@Resource
private DeviceService deviceService;
@Resource
private ProfileService profileService;
@Resource
private DriverMapper driverMapper;
@@ -155,6 +161,27 @@ public class DriverServiceImpl implements DriverService {
return driverMapper.selectOne(queryWrapper);
}
@Override
public Driver selectByDeviceId(Long deviceId) {
Device device = deviceService.selectById(deviceId);
if (null != device) {
Profile profile = profileService.selectById(device.getProfileId());
if (null != profile) {
return driverService.selectById(profile.getDriverId());
}
}
return null;
}
@Override
public Driver selectByProfileId(Long profileId) {
Profile profile = profileService.selectById(profileId);
if (null != profile) {
return driverService.selectById(profile.getDriverId());
}
return null;
}
@Override
public Map<String, Boolean> driverStatus(DriverDto driverDto) {
Map<String, Boolean> driverStatusMap = new HashMap<>(16);
@@ -16,15 +16,11 @@
package com.dc3.center.manager.service.impl;
import com.dc3.center.manager.service.DeviceService;
import com.dc3.center.manager.service.DriverService;
import com.dc3.center.manager.service.NotifyService;
import com.dc3.center.manager.service.ProfileService;
import com.dc3.common.bean.driver.DriverOperation;
import com.dc3.common.constant.Common;
import com.dc3.common.model.Device;
import com.dc3.common.model.Driver;
import com.dc3.common.model.Profile;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
@@ -43,46 +39,51 @@ public class NotifyServiceImpl implements NotifyService {
@Resource
private DriverService driverService;
@Resource
private DeviceService deviceService;
@Resource
private ProfileService profileService;
@Resource
private RabbitTemplate rabbitTemplate;
@Override
public void notifyDriverProfile(Long profileId, String operationType) {
Driver driver = getDriverByProfileId(profileId);
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(profileId);
notifyDriver(driver, operation);
public void notifyDriverProfile(Driver driver, Long profileId, String operationType) {
if (null != driver) {
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(profileId);
notifyDriver(driver, operation);
}
}
@Override
public void notifyDriverDevice(Long deviceId, Long profileId, String operationType) {
Driver driver = getDriverByProfileId(profileId);
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(deviceId);
notifyDriver(driver, operation);
Driver driver = driverService.selectByProfileId(profileId);
if (null != driver) {
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(deviceId);
notifyDriver(driver, operation);
}
}
@Override
public void notifyDriverPoint(Long pointId, Long profileId, String operationType) {
Driver driver = getDriverByProfileId(profileId);
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(pointId).setParentId(profileId);
notifyDriver(driver, operation);
Driver driver = driverService.selectByProfileId(profileId);
if (null != driver) {
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(pointId).setParentId(profileId);
notifyDriver(driver, operation);
}
}
@Override
public void notifyDriverDriverInfo(Long driverInfoId, Long attributeId, Long profileId, String operationType) {
Driver driver = getDriverByProfileId(profileId);
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(driverInfoId).setParentId(profileId).setAttributeId(attributeId);
notifyDriver(driver, operation);
Driver driver = driverService.selectByProfileId(profileId);
if (null != driver) {
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(driverInfoId).setParentId(profileId).setAttributeId(attributeId);
notifyDriver(driver, operation);
}
}
@Override
public void notifyDriverPointInfo(Long pointInfoId, Long attributeId, Long deviceId, String operationType) {
Driver driver = getDriverByDeviceId(deviceId);
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(pointInfoId).setParentId(deviceId).setAttributeId(attributeId);
notifyDriver(driver, operation);
Driver driver = driverService.selectByDeviceId(deviceId);
if (null != driver) {
DriverOperation operation = new DriverOperation().setCommand(operationType).setId(pointInfoId).setParentId(deviceId).setAttributeId(attributeId);
notifyDriver(driver, operation);
}
}
/**
@@ -96,35 +97,4 @@ public class NotifyServiceImpl implements NotifyService {
rabbitTemplate.convertAndSend(Common.Rabbit.TOPIC_EXCHANGE_NOTIFY, Common.Rabbit.ROUTING_KEY_PREFIX + driver.getServiceName(), operation);
}
/**
* get driver by device id
*
* @param deviceId Device Id
* @return Driver
*/
private Driver getDriverByDeviceId(Long deviceId) {
Device device = deviceService.selectById(deviceId);
if (null != device) {
Profile profile = profileService.selectById(device.getProfileId());
if (null != profile) {
return driverService.selectById(profile.getDriverId());
}
}
return null;
}
/**
* get driver by profile id
*
* @param profileId Profile Id
* @return Driver
*/
private Driver getDriverByProfileId(Long profileId) {
Profile profile = profileService.selectById(profileId);
if (null != profile) {
return driverService.selectById(profile.getDriverId());
}
return null;
}
}