parent
6903b6c285
commit
6608743062
|
@ -56,12 +56,6 @@ public interface DisposeDeviceManager {
|
||||||
*/
|
*/
|
||||||
List<DisposeDevice> getAllNormalDisposeDevices();
|
List<DisposeDevice> getAllNormalDisposeDevices();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all dispose devices.
|
|
||||||
*
|
|
||||||
* @return the all dispose devices
|
|
||||||
*/
|
|
||||||
List<DisposeDevice> getAllDisposeDevices();
|
|
||||||
/**
|
/**
|
||||||
* Gets dispose device by id.
|
* Gets dispose device by id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -66,29 +66,6 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败
|
|
||||||
DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(),
|
|
||||||
dev.getDeviceType().getValue());
|
|
||||||
|
|
||||||
if (tDev != null) {
|
|
||||||
// 如果设备是删除状态,则更新设备信息
|
|
||||||
if (tDev.getStatus() == ObjectStatus.DELETED) {
|
|
||||||
// 重置状态
|
|
||||||
dev.setStatus(ObjectStatus.NORMAL);
|
|
||||||
|
|
||||||
MulReturnType<ErrorCode, Long> ret = upgradeDisposeDevice(dev);
|
|
||||||
|
|
||||||
if (ret.getFirstParam() == ErrorCode.ERR_OK) {
|
|
||||||
// 同步更新缓存中设备状态
|
|
||||||
disposeAbilityRouterService.upgradeDisposeDevice(ret.getSecondParam(), dev.getStatus());
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 添加设备到数据库
|
// 添加设备到数据库
|
||||||
if (disposeDeviceMapper.addNewDisposeDevice(dev) != 1 || dev.getId() == null) {
|
if (disposeDeviceMapper.addNewDisposeDevice(dev) != 1 || dev.getId() == null) {
|
||||||
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
|
return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L);
|
||||||
|
@ -301,16 +278,6 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all dispose devices.
|
|
||||||
*
|
|
||||||
* @return the all dispose devices
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<DisposeDevice> getAllDisposeDevices() {
|
|
||||||
return disposeDeviceMapper.selectAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets dispose device by id.
|
* Gets dispose device by id.
|
||||||
*
|
*
|
||||||
|
|
|
@ -65,6 +65,13 @@ public interface DisposeAbilityRouterService {
|
||||||
*/
|
*/
|
||||||
void upgradeDisposeDevice(Long id, ObjectStatus objStatus);
|
void upgradeDisposeDevice(Long id, ObjectStatus objStatus);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete dispose device.
|
||||||
|
*
|
||||||
|
* @param dev the dev
|
||||||
|
*/
|
||||||
|
void deleteDisposeDevice(DisposeDevice dev);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run period task.
|
* Run period task.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
*/
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void initDisposeAbility() {
|
private void initDisposeAbility() {
|
||||||
List<DisposeDevice> devList = disposeDeviceManager.getAllDisposeDevices();
|
List<DisposeDevice> devList = disposeDeviceManager.getAllNormalDisposeDevices();
|
||||||
devList.forEach(this::addDisposeAbilityDevice);
|
devList.forEach(this::addDisposeAbilityDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +111,18 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete dispose device.
|
||||||
|
*
|
||||||
|
* @param dev the dev
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteDisposeDevice(DisposeDevice dev) {
|
||||||
|
String hashKey = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(),
|
||||||
|
String.valueOf(dev.getDeviceType()));
|
||||||
|
disposeAbilityMap.remove(hashKey);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all ability devices.
|
* Gets all ability devices.
|
||||||
*
|
*
|
||||||
|
@ -190,7 +202,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType) {
|
public ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType) {
|
||||||
//处置平台无处置设备,直接报错
|
//处置平台无处置设备,直接报错
|
||||||
if(getAllAbilityDevices().size() == 0 ) {
|
if (getAllAbilityDevices().size() == 0) {
|
||||||
return ErrorCode.ERR_NOTFOUNDDEVICE;
|
return ErrorCode.ERR_NOTFOUNDDEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,10 +239,10 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ
|
||||||
DisposeDevice dev = disposeDeviceManager.getDisposeDeviceById(v.getDev().getId());
|
DisposeDevice dev = disposeDeviceManager.getDisposeDeviceById(v.getDev().getId());
|
||||||
|
|
||||||
if (dev == null || !dev.getStatus().equals(ObjectStatus.NORMAL)) {
|
if (dev == null || !dev.getStatus().equals(ObjectStatus.NORMAL)) {
|
||||||
if(!v.getDev().getStatus().equals(ObjectStatus.DELETED)){
|
String hashKey = getAbilityDeviceHashKey(v.getDev().getIpAddr(), v.getDev().getIpPort(),
|
||||||
// 如果数据库中设备不存在,那么删除该设备
|
String.valueOf(v.getDev().getDeviceType()));
|
||||||
v.getDev().setStatus(ObjectStatus.DELETED);
|
|
||||||
}
|
disposeAbilityMap.remove(hashKey);
|
||||||
} else {
|
} else {
|
||||||
v.getDev().setStatus(ObjectStatus.NORMAL);
|
v.getDev().setStatus(ObjectStatus.NORMAL);
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.dispose.common.ObjectStatus;
|
||||||
import com.dispose.manager.DisposeDeviceManager;
|
import com.dispose.manager.DisposeDeviceManager;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.po.MulReturnType;
|
import com.dispose.pojo.po.MulReturnType;
|
||||||
|
import com.dispose.service.DisposeAbilityRouterService;
|
||||||
import com.dispose.service.DisposeDeviceManagerService;
|
import com.dispose.service.DisposeDeviceManagerService;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -29,6 +30,9 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceManager disposeDeviceManager;
|
private DisposeDeviceManager disposeDeviceManager;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DisposeAbilityRouterService disposeAbilityRouterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add dispose device list.
|
* Add dispose device list.
|
||||||
*
|
*
|
||||||
|
@ -94,6 +98,9 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ
|
||||||
dev.setId(v);
|
dev.setId(v);
|
||||||
dev.setStatus(ret.getSecondParam());
|
dev.setStatus(ret.getSecondParam());
|
||||||
|
|
||||||
|
// 同步更新缓存中设备状态
|
||||||
|
disposeAbilityRouterService.deleteDisposeDevice(dev);
|
||||||
|
|
||||||
rspList.add(new MulReturnType<>(ret.getFirstParam(), dev));
|
rspList.add(new MulReturnType<>(ret.getFirstParam(), dev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
LEFT JOIN dispose_capacity c ON d.id = c.deviceId
|
||||||
WHERE d.ipAddr = #{ipAddr}
|
WHERE d.ipAddr = #{ipAddr}
|
||||||
AND d.deviceType = #{devType}
|
AND d.deviceType = #{devType}
|
||||||
|
AND d.status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getDeviceById" resultMap="dispose_device">
|
<select id="getDeviceById" resultMap="dispose_device">
|
||||||
|
|
Loading…
Reference in New Issue