parent
456a4e8fbb
commit
dbe7feb01c
|
@ -115,3 +115,4 @@ buildNumber.properties
|
||||||
!/src/main/resources/git.properties
|
!/src/main/resources/git.properties
|
||||||
basedir/
|
basedir/
|
||||||
/.idea/
|
/.idea/
|
||||||
|
/phoenix_ddos_handle.iml
|
||||||
|
|
|
@ -12,8 +12,6 @@ import com.dispose.service.UserAccountService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -24,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Auth controller.
|
* The type Auth controller.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,12 +24,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -40,6 +34,13 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Dispose node info controller.
|
* The type Dispose node info controller.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,9 +15,6 @@ import com.dispose.service.DisposeNodeManager;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -29,6 +26,10 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Dispose node manager controller.
|
* The type Dispose node manager controller.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,13 +19,6 @@ import com.dispose.service.TaskService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -36,6 +29,14 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Dispose task controller.
|
* The type Dispose task controller.
|
||||||
*/
|
*/
|
||||||
|
@ -74,6 +75,8 @@ public class DisposeTaskController {
|
||||||
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
|
StartTaskReq reqInfo = mr.getRequestObject(StartTaskReq.class);
|
||||||
StartTaskRsp rspInfo = new StartTaskRsp();
|
StartTaskRsp rspInfo = new StartTaskRsp();
|
||||||
|
|
||||||
|
//taskService.createTask()
|
||||||
|
|
||||||
rspInfo.setTaskId(String.valueOf(reqInfo.getId()));
|
rspInfo.setTaskId(String.valueOf(reqInfo.getId()));
|
||||||
rspInfo.setStatus(err.getCode());
|
rspInfo.setStatus(err.getCode());
|
||||||
rspInfo.setMessage(err.getMsg());
|
rspInfo.setMessage(err.getMsg());
|
||||||
|
|
|
@ -4,42 +4,46 @@ import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author phoenix
|
* The interface Dispose device manager.
|
||||||
* @date 2020年4月27日
|
|
||||||
*/
|
*/
|
||||||
public interface DisposeDeviceManager {
|
public interface DisposeDeviceManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param dd
|
* Save dispose device int.
|
||||||
* @return
|
*
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
* @param dd the dd
|
||||||
|
* @return the int
|
||||||
*/
|
*/
|
||||||
int saveDisposeDevice(DisposeDevice dd);
|
int saveDisposeDevice(DisposeDevice dd);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ip
|
* Find dispose device by ip dispose device.
|
||||||
* @return
|
*
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
* @param ip the ip
|
||||||
|
* @return the dispose device
|
||||||
*/
|
*/
|
||||||
DisposeDevice findDisposeDeviceByIp(String ip);
|
DisposeDevice findDisposeDeviceByIp(String ip);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id
|
* Find dispose device by id dispose device.
|
||||||
* @return
|
*
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
* @param id the id
|
||||||
|
* @return the dispose device
|
||||||
*/
|
*/
|
||||||
DisposeDevice findDisposeDeviceById(Long id);
|
DisposeDevice findDisposeDeviceById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* Find all dispose device list.
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
*
|
||||||
|
* @return the list
|
||||||
*/
|
*/
|
||||||
List<DisposeDevice> findAllDisposeDevice();
|
List<DisposeDevice> findAllDisposeDevice();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ip
|
* Del dispose device by ip int.
|
||||||
* @return
|
*
|
||||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
* @param ip the ip
|
||||||
|
* @return the int
|
||||||
*/
|
*/
|
||||||
int delDisposeDeviceByIp(String ip);
|
int delDisposeDeviceByIp(String ip);
|
||||||
|
|
||||||
|
|
|
@ -8,5 +8,49 @@ import tk.mybatis.mapper.common.MySqlMapper;
|
||||||
* The interface Dispose device mapper.
|
* The interface Dispose device mapper.
|
||||||
*/
|
*/
|
||||||
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
public interface DisposeDeviceMapper extends Mapper<DisposeDevice>, MySqlMapper<DisposeDevice> {
|
||||||
|
/**
|
||||||
|
* Add new dispose device.
|
||||||
|
*
|
||||||
|
* @param dev the dev
|
||||||
|
*/
|
||||||
|
void addNewDisposeDevice(DisposeDevice dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is device exists by ip int.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @return the int
|
||||||
|
*/
|
||||||
|
int isDeviceExistsByIp(String ipAddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is device exists by id int.
|
||||||
|
*
|
||||||
|
* @param id the id
|
||||||
|
* @return the int
|
||||||
|
*/
|
||||||
|
int isDeviceExistsById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device by ip.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
* @return the device by ip
|
||||||
|
*/
|
||||||
|
DisposeDevice getDeviceByIp(String ipAddr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets device by id.
|
||||||
|
*
|
||||||
|
* @param id the id
|
||||||
|
* @return the device by id
|
||||||
|
*/
|
||||||
|
DisposeDevice getDeviceById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Del dispose device by ip.
|
||||||
|
*
|
||||||
|
* @param ipAddr the ip addr
|
||||||
|
*/
|
||||||
|
void delDisposeDeviceByIp(String ipAddr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class StartTaskReq {
|
||||||
/**
|
/**
|
||||||
* The Id.
|
* The Id.
|
||||||
*/
|
*/
|
||||||
private int id;
|
private Integer id;
|
||||||
/**
|
/**
|
||||||
* The Type.
|
* The Type.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -70,12 +70,4 @@ public interface DisposeNodeManager {
|
||||||
* @return the dispose device
|
* @return the dispose device
|
||||||
*/
|
*/
|
||||||
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
DisposeDevice getDisposeDevice(String ipAddr, DeviceCapacity capacity);
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断设备是否存在
|
|
||||||
*
|
|
||||||
* @param ip
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
boolean isExistsDisposeDeviceByIp(String ip);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.dispose.common.ErrorCode;
|
||||||
import com.dispose.common.IPAddrType;
|
import com.dispose.common.IPAddrType;
|
||||||
import com.dispose.dispose.DeviceRouter;
|
import com.dispose.dispose.DeviceRouter;
|
||||||
import com.dispose.dispose.DisposeEntryManager;
|
import com.dispose.dispose.DisposeEntryManager;
|
||||||
import com.dispose.manager.DisposeDeviceManager;
|
import com.dispose.mapper.DisposeDeviceMapper;
|
||||||
import com.dispose.pojo.entity.DisposeDevice;
|
import com.dispose.pojo.entity.DisposeDevice;
|
||||||
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
import com.dispose.pojo.po.DisposeDeviceCapacity;
|
||||||
import com.dispose.pojo.po.MReturnType;
|
import com.dispose.pojo.po.MReturnType;
|
||||||
|
@ -18,41 +18,34 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Dispose node manager.
|
* The type Dispose node manager.
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
|
||||||
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Dispose dev map.
|
* The Dispose dev map.
|
||||||
*/
|
*/
|
||||||
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<String, DisposeDevice> disposeDevMap = new ConcurrentHashMap<>();
|
||||||
|
/**
|
||||||
|
* The Dispose device mapper.
|
||||||
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private DisposeDeviceManager disposeDeviceManager;
|
private DisposeDeviceMapper disposeDeviceMapper;
|
||||||
/**
|
/**
|
||||||
* The User account service.
|
* The User account service.
|
||||||
*/
|
*/
|
||||||
@Resource
|
@Resource
|
||||||
private UserAccountService userAccountService;
|
private UserAccountService userAccountService;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isExistsDisposeDeviceByIp(String ip) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
log.info("查询该处置设备是否存在 {}", ip);
|
|
||||||
return disposeDeviceManager.findDisposeDeviceByIp(ip) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load dispose node from db.
|
* Load dispose node from db.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void loadDisposeNodeFromDB() {
|
public void loadDisposeNodeFromDB() {
|
||||||
List<DisposeDevice> devList = disposeDeviceManager.findAllDisposeDevice();
|
List<DisposeDevice> devList = disposeDeviceMapper.selectAll();
|
||||||
|
|
||||||
if (devList == null) {
|
if (devList == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -80,7 +73,8 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode delDisposeDeviceById(Long id) {
|
public ErrorCode delDisposeDeviceById(Long id) {
|
||||||
DisposeDevice dev = disposeDeviceManager.findDisposeDeviceById(id);
|
DisposeEntryManager dp;
|
||||||
|
DisposeDevice dev = disposeDeviceMapper.getDeviceById(id);
|
||||||
|
|
||||||
if (dev == null) {
|
if (dev == null) {
|
||||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||||
|
@ -97,7 +91,9 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode delDisposeDeviceByIp(String ipAddr) {
|
public ErrorCode delDisposeDeviceByIp(String ipAddr) {
|
||||||
if (!isExistsDisposeDeviceByIp(ipAddr)
|
DisposeEntryManager dp;
|
||||||
|
|
||||||
|
if (disposeDeviceMapper.isDeviceExistsByIp(ipAddr) == 0
|
||||||
|| !disposeDevMap.containsKey(ipAddr)) {
|
|| !disposeDevMap.containsKey(ipAddr)) {
|
||||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +104,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
return ErrorCode.ERR_NOSUCHDEVICE;
|
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
disposeDeviceManager.delDisposeDeviceByIp(ipAddr);
|
disposeDeviceMapper.delDisposeDeviceByIp(ipAddr);
|
||||||
disposeDevMap.remove(ipAddr);
|
disposeDevMap.remove(ipAddr);
|
||||||
|
|
||||||
return ErrorCode.ERR_OK;
|
return ErrorCode.ERR_OK;
|
||||||
|
@ -131,7 +127,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
return new MReturnType<>(ErrorCode.ERR_NOSUCHDEVICE, String.valueOf(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposeDevice dbDev = disposeDeviceManager.findDisposeDeviceByIp(dev.getIpAddr());
|
DisposeDevice dbDev = disposeDeviceMapper.getDeviceByIp(dev.getIpAddr());
|
||||||
|
|
||||||
if (dbDev != null) {
|
if (dbDev != null) {
|
||||||
return new MReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
return new MReturnType<>(ErrorCode.ERR_DEVICEEXISTS, String.valueOf(dbDev.getId()));
|
||||||
|
@ -149,7 +145,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
|
|
||||||
dev.setDevInfo(dp.getDeviceInfo());
|
dev.setDevInfo(dp.getDeviceInfo());
|
||||||
|
|
||||||
disposeDeviceManager.saveDisposeDevice(dev);
|
disposeDeviceMapper.addNewDisposeDevice(dev);
|
||||||
|
|
||||||
disposeDevMap.put(dev.getIpAddr(), dev);
|
disposeDevMap.put(dev.getIpAddr(), dev);
|
||||||
return new MReturnType<>(ErrorCode.ERR_OK, dev.getId().toString());
|
return new MReturnType<>(ErrorCode.ERR_OK, dev.getId().toString());
|
||||||
|
@ -228,15 +224,15 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
*/
|
*/
|
||||||
private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) {
|
private boolean isIpInRange(DisposeDeviceCapacity cap, String ipAddr) {
|
||||||
try {
|
try {
|
||||||
if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV4_TYPE) {
|
||||||
for (String s : cap.getProtectIpV4()) {
|
for(String s : cap.getProtectIpV4()) {
|
||||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
} else if(IPAddrType.getIpAddrType(ipAddr) == IPAddrType.IPV6_TYPE) {
|
||||||
for (String s : cap.getProtectIpV6()) {
|
for(String s : cap.getProtectIpV6()) {
|
||||||
if (IPAddrType.ipInRange(s, ipAddr)) {
|
if(IPAddrType.ipInRange(s, ipAddr)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -263,7 +259,7 @@ public class DisposeNodeManagerImpl implements DisposeNodeManager {
|
||||||
.filter(f -> f.getCapacity() == capacity.getCode())
|
.filter(f -> f.getCapacity() == capacity.getCode())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
if(capList.stream().anyMatch(k -> isIpInRange(k, ipAddr))) {
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,14 @@ import com.dispose.service.DisposeNodeManager;
|
||||||
import com.dispose.service.TaskService;
|
import com.dispose.service.TaskService;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Task service.
|
* The type Task service.
|
||||||
|
@ -119,6 +120,7 @@ public class TaskServiceImpl implements TaskService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ErrorCode startTask(Long taskId) {
|
public ErrorCode startTask(Long taskId) {
|
||||||
|
ErrorCode err = ErrorCode.ERR_OK;
|
||||||
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
TaskInfoDetail task = taskCacheManager.getTaskById(taskId);
|
||||||
|
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
|
@ -127,23 +129,27 @@ public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
DisposeEntryManager dp = getDisposeDeviceHandle(task);
|
DisposeEntryManager dp = getDisposeDeviceHandle(task);
|
||||||
|
|
||||||
|
if (dp == null) {
|
||||||
|
return ErrorCode.ERR_NOSUCHDEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
if (taskIsExpired(task)) {
|
if (taskIsExpired(task)) {
|
||||||
|
err = dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]);
|
||||||
|
|
||||||
|
if (err == ErrorCode.ERR_OK) {
|
||||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_FINISH.getCode());
|
||||||
if (dp != null) {
|
|
||||||
asyncService.asyncStopDisposeDeviceTask(dp, task.getDisposeIp(),
|
|
||||||
DeviceCapacity.values()[task.getType()]);
|
|
||||||
}
|
}
|
||||||
} else if (!taskIsRunning(task)) {
|
} else if (!taskIsRunning(task)) {
|
||||||
|
err = dp.runDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()]);
|
||||||
|
|
||||||
|
if (err == ErrorCode.ERR_OK) {
|
||||||
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
taskCacheManager.upgradeTaskStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||||
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
disposeTaskMapper.changeTaskCurrentStatus(taskId, DisposeTaskStatus.TASK_RUNNING.getCode());
|
||||||
if (dp != null) {
|
|
||||||
asyncService.asyncStartDisposeDeviceTask(dp, task.getDisposeIp(),
|
|
||||||
DeviceCapacity.values()[task.getType()]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ErrorCode.ERR_OK;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.dispose.mapper.DisposeDeviceMapper">
|
||||||
|
<insert id="addNewDisposeDevice" useGeneratedKeys="true" keyProperty="id" parameterType="com.dispose.pojo.entity.DisposeDevice">
|
||||||
|
INSERT IGNORE INTO
|
||||||
|
dispose_device(ipAddr, type,
|
||||||
|
areaCode, name, manufacturer,
|
||||||
|
model, version, readme, status)
|
||||||
|
VALUES
|
||||||
|
(#{ipAddr}, #{type},
|
||||||
|
#{areaCode}, #{name}, #{manufacturer},
|
||||||
|
#{model}, #{version}, #{readme}, 0)
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<select id="getDeviceByIp" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.String">
|
||||||
|
SELECT * FROM dispose_device
|
||||||
|
WHERE
|
||||||
|
ipAddr = #{ipAddr}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getDeviceById" resultType="com.dispose.pojo.entity.DisposeDevice" parameterType="java.lang.Long">
|
||||||
|
SELECT * FROM dispose_device
|
||||||
|
WHERE
|
||||||
|
id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="isDeviceExistsByIp" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*) FROM dispose_device
|
||||||
|
WHERE
|
||||||
|
ipAddr = #{ipAddr}
|
||||||
|
</select>
|
||||||
|
<select id="isDeviceExistsById" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*) FROM dispose_device
|
||||||
|
WHERE
|
||||||
|
id = #{id}
|
||||||
|
</select>
|
||||||
|
<delete id="delDisposeDeviceByIp" parameterType="java.lang.String">
|
||||||
|
DELETE
|
||||||
|
dispose_device
|
||||||
|
FROM
|
||||||
|
dispose_device
|
||||||
|
WHERE
|
||||||
|
dispose_device.ipAddr = #{ipAddr}
|
||||||
|
</delete>
|
||||||
|
<delete id="delDisposeDeviceById" parameterType="java.lang.Long">
|
||||||
|
DELETE
|
||||||
|
dispose_device
|
||||||
|
FROM
|
||||||
|
dispose_device
|
||||||
|
WHERE
|
||||||
|
dispose_device.id = #{id}
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue