|
|
@ -1,11 +1,21 @@ |
|
|
|
package com.storeroom.modules.device.service.impl; |
|
|
|
|
|
|
|
import com.storeroom.exception.BaseException; |
|
|
|
import com.storeroom.modules.device.domain.*; |
|
|
|
import com.storeroom.modules.device.repository.DeviceArchivesTagRepository; |
|
|
|
import com.storeroom.modules.device.repository.DeviceInfoRepository; |
|
|
|
import com.storeroom.modules.device.repository.OperatingStateRepository; |
|
|
|
import com.storeroom.modules.device.service.DeviceService; |
|
|
|
import com.storeroom.modules.device.service.dto.DeviceInfoDto; |
|
|
|
import com.storeroom.modules.device.service.mapstruct.DeviceInfoMapper; |
|
|
|
import com.storeroom.utils.NanoIdUtils; |
|
|
|
import com.storeroom.utils.StringUtils; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.concurrent.ThreadLocalRandom; |
|
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
@ -13,8 +23,140 @@ import java.util.List; |
|
|
|
public class DeviceImpl implements DeviceService { |
|
|
|
|
|
|
|
|
|
|
|
private final DeviceInfoRepository deviceInfoRepository; |
|
|
|
private final DeviceInfoMapper deviceInfoMapper; |
|
|
|
private final OperatingStateRepository operatingStateRepository; |
|
|
|
private final DeviceArchivesTagRepository deviceArchivesTagRepository; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<DeviceInfoDto> findByDevice(String StoreRoomId) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void createDeseCabinet(DeviceInfoDto deviceInfoDto) { |
|
|
|
DeviceInfo deviceInfo = deviceInfoMapper.toEntity(deviceInfoDto); |
|
|
|
List<DeviceInfo> deviceInfoList = deviceInfoRepository.findByAreaNoAndAndDeviceIpAndAndDevicePort(deviceInfo.getAreaNo(), deviceInfo.getDeviceIp(), deviceInfo.getDevicePort()); |
|
|
|
if (deviceInfoList.size() != 0) { |
|
|
|
throw new BaseException("区号IP端口不能重复添加设备"); |
|
|
|
} |
|
|
|
//创建密集架id |
|
|
|
deviceInfo.setId(NanoIdUtils.randomNanoId()); |
|
|
|
//生成架位 |
|
|
|
String position = deviceInfo.getAreaNo() + |
|
|
|
"-" + |
|
|
|
deviceInfo.getFirstColumnNo() + |
|
|
|
"-" + |
|
|
|
deviceInfo.getPartNo() + |
|
|
|
"-" + |
|
|
|
deviceInfo.getRowNo() + |
|
|
|
"-" + |
|
|
|
GenerateNum(); |
|
|
|
String leftOrRight; |
|
|
|
if (GenerateNum().equals("1")) { |
|
|
|
leftOrRight = "左"; |
|
|
|
} else { |
|
|
|
leftOrRight = "右"; |
|
|
|
} |
|
|
|
String positionName = deviceInfo.getAreaNo() + |
|
|
|
"区" + |
|
|
|
deviceInfo.getFirstColumnNo() + |
|
|
|
"列" + |
|
|
|
deviceInfo.getPartNo() + |
|
|
|
"节" + |
|
|
|
deviceInfo.getRowNo() + |
|
|
|
"层" + |
|
|
|
leftOrRight; |
|
|
|
DeviceArchivesTag deviceArchivesTag = new DeviceArchivesTag(); |
|
|
|
//生成架位标签表id |
|
|
|
deviceArchivesTag.setId(NanoIdUtils.randomNanoId()); |
|
|
|
deviceArchivesTag.setPosition(position); |
|
|
|
deviceArchivesTag.setDeviceInfoId(deviceInfo.getId()); |
|
|
|
deviceArchivesTag.setPosition_name(positionName); |
|
|
|
//创建联动操作状态对象 |
|
|
|
IsLinkageState(deviceInfo); |
|
|
|
IsCallbackState(deviceInfo); |
|
|
|
deviceArchivesTagRepository.save(deviceArchivesTag); |
|
|
|
deviceInfoRepository.save(deviceInfo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateDeseCabinet(DeviceInfoDto deviceInfoDto) { |
|
|
|
DeviceInfo deviceInfo = deviceInfoMapper.toEntity(deviceInfoDto); |
|
|
|
List<DeviceInfo> deviceInfoList = deviceInfoRepository.findByAreaNoAndAndDeviceIpAndAndDevicePort(deviceInfo.getAreaNo(), deviceInfo.getDeviceIp(), deviceInfo.getDevicePort()); |
|
|
|
if (!ObjectUtils.isEmpty(deviceInfoList)){ |
|
|
|
throw new BaseException("区号IP端口不能重复添加设备"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 生成架位左右位置 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String GenerateNum() { |
|
|
|
ThreadLocalRandom tlr = ThreadLocalRandom.current(); |
|
|
|
return String.valueOf(tlr.nextInt(1, 2)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 保存联动操作状态 |
|
|
|
* |
|
|
|
* @param deviceInfo / |
|
|
|
*/ |
|
|
|
private void IsLinkageState(DeviceInfo deviceInfo) { |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceInfo.getIsLinkage().getId())){ |
|
|
|
OperatingState operatingState = new OperatingState(); |
|
|
|
operatingState.setId(NanoIdUtils.randomNanoId()); |
|
|
|
operatingState.setDeviceId(deviceInfo.getId()); |
|
|
|
operatingState.setBorrow(deviceInfo.getIsLinkage().getBorrow()); |
|
|
|
operatingState.setInBound(deviceInfo.getIsLinkage().getInBound()); |
|
|
|
operatingState.setOutBound(deviceInfo.getIsLinkage().getOutBound()); |
|
|
|
operatingState.setLend(deviceInfo.getIsLinkage().getLend()); |
|
|
|
operatingState.setStateType(deviceInfo.getIsLinkage().getStateType()); |
|
|
|
operatingStateRepository.save(operatingState); |
|
|
|
}else { |
|
|
|
OperatingState operatingState1 = operatingStateRepository.findById(deviceInfo.getIsLinkage().getId()).orElseGet(OperatingState::new); |
|
|
|
operatingState1.setDeviceId(deviceInfo.getId()); |
|
|
|
operatingState1.setBorrow(deviceInfo.getIsLinkage().getBorrow()); |
|
|
|
operatingState1.setInBound(deviceInfo.getIsLinkage().getInBound()); |
|
|
|
operatingState1.setOutBound(deviceInfo.getIsLinkage().getOutBound()); |
|
|
|
operatingState1.setLend(deviceInfo.getIsLinkage().getLend()); |
|
|
|
operatingState1.setStateType(deviceInfo.getIsLinkage().getStateType()); |
|
|
|
operatingStateRepository.save(operatingState1); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 保存回调操作状态 |
|
|
|
* |
|
|
|
* @param deviceInfo / |
|
|
|
*/ |
|
|
|
private void IsCallbackState(DeviceInfo deviceInfo) { |
|
|
|
|
|
|
|
if (StringUtils.isEmpty(deviceInfo.getIsCallback().getId())) { |
|
|
|
OperatingState operatingState = new OperatingState(); |
|
|
|
operatingState.setId(NanoIdUtils.randomNanoId()); |
|
|
|
operatingState.setDeviceId(deviceInfo.getId()); |
|
|
|
operatingState.setBorrow(deviceInfo.getIsCallback().getBorrow()); |
|
|
|
operatingState.setInBound(deviceInfo.getIsCallback().getInBound()); |
|
|
|
operatingState.setOutBound(deviceInfo.getIsCallback().getOutBound()); |
|
|
|
operatingState.setLend(deviceInfo.getIsCallback().getLend()); |
|
|
|
operatingState.setStateType(deviceInfo.getIsCallback().getStateType()); |
|
|
|
operatingStateRepository.save(operatingState); |
|
|
|
} else { |
|
|
|
OperatingState operatingState1 = operatingStateRepository.findById(deviceInfo.getIsLinkage().getId()).orElseGet(OperatingState::new); |
|
|
|
operatingState1.setDeviceId(deviceInfo.getId()); |
|
|
|
operatingState1.setBorrow(deviceInfo.getIsCallback().getBorrow()); |
|
|
|
operatingState1.setInBound(deviceInfo.getIsCallback().getInBound()); |
|
|
|
operatingState1.setOutBound(deviceInfo.getIsCallback().getOutBound()); |
|
|
|
operatingState1.setLend(deviceInfo.getIsCallback().getLend()); |
|
|
|
operatingState1.setStateType(deviceInfo.getIsCallback().getStateType()); |
|
|
|
operatingStateRepository.save(operatingState1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |