修复设备初次注册无通道

pull/1642/head
panlinlin 2024-07-20 06:35:42 +08:00
parent 1dc0cb0c83
commit d201be2f88
3 changed files with 9 additions and 18 deletions

View File

@ -26,6 +26,7 @@ public interface DeviceChannelMapper {
"#{ipAddress}, #{port}, #{password}, #{status}, #{longitude}, #{latitude}, #{ptzType}, #{positionType}, #{roomType}, #{useType}, " + "#{ipAddress}, #{port}, #{password}, #{status}, #{longitude}, #{latitude}, #{ptzType}, #{positionType}, #{roomType}, #{useType}, " +
"#{supplyLightType}, #{directionType}, #{resolution}, #{businessGroupId}, #{downloadSpeed}, #{svcSpaceSupportMod}," + "#{supplyLightType}, #{directionType}, #{resolution}, #{businessGroupId}, #{downloadSpeed}, #{svcSpaceSupportMod}," +
" #{svcTimeSupportMode}, #{createTime}, #{updateTime}, #{subCount}, #{streamId}, #{hasAudio}, #{gpsTime}, #{streamIdentification})") " #{svcTimeSupportMode}, #{createTime}, #{updateTime}, #{subCount}, #{streamId}, #{hasAudio}, #{gpsTime}, #{streamIdentification})")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int add(DeviceChannel channel); int add(DeviceChannel channel);
@Update(value = {" <script>" + @Update(value = {" <script>" +

View File

@ -110,6 +110,7 @@ public interface DeviceMapper {
"#{geoCoordSys}," + "#{geoCoordSys}," +
"#{onLine}" + "#{onLine}" +
")") ")")
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
int add(Device device); int add(Device device);
@Update(value = {" <script>" + @Update(value = {" <script>" +

View File

@ -35,6 +35,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import javax.sip.InvalidArgumentException; import javax.sip.InvalidArgumentException;
@ -537,29 +538,17 @@ public class DeviceServiceImpl implements IDeviceService {
} }
@Override @Override
@Transactional
public boolean delete(String deviceId) { public boolean delete(String deviceId) {
Device device = deviceMapper.getDeviceByDeviceId(deviceId); Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (device == null) { if (device == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId); throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到设备:" + deviceId);
} }
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
boolean result = false;
try {
platformChannelMapper.delChannelForDeviceId(deviceId); platformChannelMapper.delChannelForDeviceId(deviceId);
deviceChannelMapper.cleanChannelsByDeviceId(device.getId()); deviceChannelMapper.cleanChannelsByDeviceId(device.getId());
if ( deviceMapper.del(deviceId) < 0 ) { deviceMapper.del(deviceId);
//事务回滚
dataSourceTransactionManager.rollback(transactionStatus);
}
result = true;
dataSourceTransactionManager.commit(transactionStatus); //手动提交
}catch (Exception e) {
dataSourceTransactionManager.rollback(transactionStatus);
}
if (result) {
redisCatchStorage.removeDevice(deviceId); redisCatchStorage.removeDevice(deviceId);
} return true;
return result;
} }
@Override @Override