14 changed files with 382 additions and 31 deletions
-
2storeroom/src/main/java/com/storeroom/modules/device/controller/DeseCabinetController.java
-
73storeroom/src/main/java/com/storeroom/modules/device/controller/RotaryCabinetController.java
-
13storeroom/src/main/java/com/storeroom/modules/device/domain/DeseCabinet.java
-
6storeroom/src/main/java/com/storeroom/modules/device/domain/OperatingState.java
-
79storeroom/src/main/java/com/storeroom/modules/device/domain/RotaryCabinet.java
-
4storeroom/src/main/java/com/storeroom/modules/device/domain/Supplier.java
-
17storeroom/src/main/java/com/storeroom/modules/device/repository/RotaryCabinetRepository.java
-
23storeroom/src/main/java/com/storeroom/modules/device/service/RotaryCabinetService.java
-
2storeroom/src/main/java/com/storeroom/modules/device/service/dto/DeviceInfoDto.java
-
2storeroom/src/main/java/com/storeroom/modules/device/service/dto/SupplierDto.java
-
26storeroom/src/main/java/com/storeroom/modules/device/service/impl/DenseCabinetImpl.java
-
156storeroom/src/main/java/com/storeroom/modules/device/service/impl/RotaryCabinetImpl.java
-
4storeroom/src/main/java/com/storeroom/modules/device/service/impl/SupplierImpl.java
-
6storeroom/src/main/java/com/storeroom/modules/device/service/mapstruct/DeseCabinetMapper.java
@ -0,0 +1,73 @@ |
|||||
|
package com.storeroom.modules.device.controller; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.annotaion.rest.AnonymousPostMapping; |
||||
|
import com.storeroom.annotaion.rest.AnonymousPutMapping; |
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.modules.device.domain.DeseCabinet; |
||||
|
import com.storeroom.modules.device.domain.RotaryCabinet; |
||||
|
import com.storeroom.modules.device.service.RotaryCabinetService; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import com.storeroom.utils.StringUtils; |
||||
|
import com.storeroom.utils.enums.ResponseStatus; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
@Api(tags = "回转柜管理") |
||||
|
@RequiredArgsConstructor |
||||
|
@RequestMapping("/api/rotarycabinet/") |
||||
|
public class RotaryCabinetController { |
||||
|
|
||||
|
private final RotaryCabinetService rotaryCabinetService; |
||||
|
|
||||
|
|
||||
|
@ApiOperation("创建回转柜") |
||||
|
@AnonymousPostMapping("create") |
||||
|
public ApiResponse<Object> create(@RequestBody RotaryCabinet rotaryCabinet) { |
||||
|
if (!StringUtils.isEmpty(rotaryCabinet.getId())) { |
||||
|
throw new BaseException("id不为空"); |
||||
|
} |
||||
|
verifyValues(rotaryCabinet); |
||||
|
rotaryCabinetService.create(rotaryCabinet); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("修改回转柜") |
||||
|
@AnonymousPutMapping("update") |
||||
|
public ApiResponse<Object> update(@RequestBody RotaryCabinet rotaryCabinet) { |
||||
|
if (StringUtils.isEmpty(rotaryCabinet.getId())) { |
||||
|
throw new BaseException("id为空"); |
||||
|
} |
||||
|
verifyValues(rotaryCabinet); |
||||
|
rotaryCabinetService.update(rotaryCabinet); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 必填字段验证 |
||||
|
* |
||||
|
* @param rotaryCabinet / |
||||
|
*/ |
||||
|
private void verifyValues(@RequestBody RotaryCabinet rotaryCabinet) { |
||||
|
if (rotaryCabinet.getCupboardNo() != null |
||||
|
&& rotaryCabinet.getRowNo() != null |
||||
|
&& rotaryCabinet.getColumnRowNo() != null |
||||
|
&& rotaryCabinet.getStoreroomCode() != null |
||||
|
&& rotaryCabinet.getDeviceAccount() != null |
||||
|
&& rotaryCabinet.getDevicePassword() != null |
||||
|
&& StringUtils.isEmpty(rotaryCabinet.getDeviceInfo().getDeviceName()) |
||||
|
&& StringUtils.isEmpty(rotaryCabinet.getDeviceInfo().getStoreroomId().getId()) |
||||
|
&& StringUtils.isEmpty(rotaryCabinet.getDeviceInfo().getDeviceIp()) |
||||
|
&& rotaryCabinet.getDeviceInfo().getDevicePort() != null |
||||
|
) { |
||||
|
throw new BaseException("必填字段不能为空"); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,79 @@ |
|||||
|
package com.storeroom.modules.device.domain; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.base.BaseEntity; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Getter; |
||||
|
import lombok.Setter; |
||||
|
|
||||
|
import javax.persistence.*; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.Objects; |
||||
|
|
||||
|
@Entity |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@Table(name = "rotary_cabinet") |
||||
|
public class RotaryCabinet extends BaseEntity implements Serializable { |
||||
|
|
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
@NotNull(groups = Update.class) |
||||
|
@ApiModelProperty(value = "ID", hidden = true) |
||||
|
private String id; |
||||
|
|
||||
|
@OneToOne(cascade = CascadeType.ALL) |
||||
|
@JoinColumn(name = "device_info_id", referencedColumnName = "id") |
||||
|
@ApiModelProperty(value = "设备信息") |
||||
|
private DeviceInfo deviceInfo; |
||||
|
|
||||
|
@Column(name = "storeroom_code") |
||||
|
@ApiModelProperty(value = "库房代码") |
||||
|
private String storeroomCode; |
||||
|
|
||||
|
@Column(name = "column_row_No") |
||||
|
@ApiModelProperty(value = "层数") |
||||
|
private Integer columnRowNo; |
||||
|
|
||||
|
@Column(name = "device_account") |
||||
|
@ApiModelProperty(value = "设备账号") |
||||
|
private String deviceAccount; |
||||
|
|
||||
|
@Column(name = "device_password") |
||||
|
@ApiModelProperty(value = "设备密码") |
||||
|
private String devicePassword; |
||||
|
|
||||
|
@Column(name = "cupboard_No") |
||||
|
@ApiModelProperty(value = "柜号") |
||||
|
private Integer cupboardNo; |
||||
|
|
||||
|
@Column(name = "row_No") |
||||
|
@ApiModelProperty(value = "层数") |
||||
|
private String rowNo; |
||||
|
|
||||
|
@Column(name = "is_notice") |
||||
|
@ApiModelProperty(value = "下发通知") |
||||
|
private Boolean isNotice; |
||||
|
|
||||
|
@Transient |
||||
|
@ApiModelProperty(value = "联动操作") |
||||
|
private OperatingState isLinkage; |
||||
|
|
||||
|
@Transient |
||||
|
@ApiModelProperty(value = "是否回调") |
||||
|
private OperatingState isCallback; |
||||
|
|
||||
|
@Override |
||||
|
public boolean equals(Object o) { |
||||
|
if (this == o) return true; |
||||
|
if (o == null || getClass() != o.getClass()) return false; |
||||
|
RotaryCabinet that = (RotaryCabinet) o; |
||||
|
return Objects.equals(id, that.id) && Objects.equals(deviceInfo, that.deviceInfo) && Objects.equals(storeroomCode, that.storeroomCode) && Objects.equals(columnRowNo, that.columnRowNo) && Objects.equals(deviceAccount, that.deviceAccount) && Objects.equals(devicePassword, that.devicePassword) && Objects.equals(cupboardNo, that.cupboardNo) && Objects.equals(rowNo, that.rowNo) && Objects.equals(isNotice, that.isNotice) && Objects.equals(isLinkage, that.isLinkage) && Objects.equals(isCallback, that.isCallback); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public int hashCode() { |
||||
|
return Objects.hash(id, deviceInfo, storeroomCode, columnRowNo, deviceAccount, devicePassword, cupboardNo, rowNo, isNotice, isLinkage, isCallback); |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package com.storeroom.modules.device.repository; |
||||
|
|
||||
|
import com.storeroom.modules.device.domain.RotaryCabinet; |
||||
|
import org.springframework.data.jpa.repository.JpaRepository; |
||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
||||
|
import org.springframework.data.jpa.repository.Query; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public interface RotaryCabinetRepository extends JpaRepository<RotaryCabinet,String>, JpaSpecificationExecutor<RotaryCabinet> { |
||||
|
|
||||
|
|
||||
|
@Query(value = "SELECT * FROM rotary_cabinet a JOIN device_info b ON a.device_info_id=b.id WHERE a.cupboard_No=?1 AND b.device_ip=?2 AND b.device_port=?3", nativeQuery = true) |
||||
|
List<RotaryCabinet> findIpAndPortAndAreaNo(Integer cupBoardNo, String ip, Integer port ); |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
package com.storeroom.modules.device.service; |
||||
|
|
||||
|
import com.storeroom.modules.device.domain.RotaryCabinet; |
||||
|
|
||||
|
/** |
||||
|
* 回转柜 |
||||
|
*/ |
||||
|
public interface RotaryCabinetService { |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 创建回转柜 |
||||
|
* @param rotaryCabinet / |
||||
|
*/ |
||||
|
void create(RotaryCabinet rotaryCabinet); |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 修改回转柜 |
||||
|
* @param rotaryCabinet / |
||||
|
*/ |
||||
|
void update(RotaryCabinet rotaryCabinet); |
||||
|
} |
@ -0,0 +1,156 @@ |
|||||
|
package com.storeroom.modules.device.service.impl; |
||||
|
|
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.modules.device.domain.DeviceArchivesTag; |
||||
|
import com.storeroom.modules.device.domain.OperatingState; |
||||
|
import com.storeroom.modules.device.domain.RotaryCabinet; |
||||
|
import com.storeroom.modules.device.repository.DeviceArchivesTagRepository; |
||||
|
import com.storeroom.modules.device.repository.OperatingStateRepository; |
||||
|
import com.storeroom.modules.device.repository.RotaryCabinetRepository; |
||||
|
import com.storeroom.modules.device.service.RotaryCabinetService; |
||||
|
import com.storeroom.utils.NanoIdUtils; |
||||
|
import com.storeroom.utils.StringUtils; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
import org.springframework.util.ObjectUtils; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class RotaryCabinetImpl implements RotaryCabinetService { |
||||
|
|
||||
|
private final RotaryCabinetRepository rotaryCabinetRepository; |
||||
|
private final OperatingStateRepository operatingStateRepository; |
||||
|
private final DeviceArchivesTagRepository deviceArchivesTagRepository; |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void create(RotaryCabinet rotaryCabinet) { |
||||
|
List<RotaryCabinet> rotaryCabinetList = rotaryCabinetRepository.findIpAndPortAndAreaNo(rotaryCabinet.getCupboardNo(), rotaryCabinet.getDeviceInfo().getDeviceIp(), rotaryCabinet.getDeviceInfo().getDevicePort()); |
||||
|
|
||||
|
if (!ObjectUtils.isEmpty(rotaryCabinetList)) { |
||||
|
throw new BaseException("同一IP和端口号下不能重复添加设备"); |
||||
|
} |
||||
|
rotaryCabinet.setId(NanoIdUtils.randomNanoId()); |
||||
|
rotaryCabinet.getDeviceInfo().setId(NanoIdUtils.randomNanoId()); |
||||
|
|
||||
|
String position = rotaryCabinet.getCupboardNo() + |
||||
|
"-" + |
||||
|
rotaryCabinet.getRowNo() + |
||||
|
"-" + |
||||
|
rotaryCabinet.getRowNo() + |
||||
|
"-" + |
||||
|
rotaryCabinet.getColumnRowNo(); |
||||
|
|
||||
|
String positionName = rotaryCabinet.getCupboardNo() + |
||||
|
"柜" + |
||||
|
rotaryCabinet.getRowNo() + |
||||
|
"层" + |
||||
|
rotaryCabinet.getColumnRowNo() + |
||||
|
"列"; |
||||
|
|
||||
|
DeviceArchivesTag deviceArchivesTag = new DeviceArchivesTag(); |
||||
|
|
||||
|
deviceArchivesTag.setId(NanoIdUtils.randomNanoId()); |
||||
|
deviceArchivesTag.setPosition(position); |
||||
|
deviceArchivesTag.setPosition_name(positionName); |
||||
|
deviceArchivesTag.setDeviceInfoId(rotaryCabinet.getDeviceInfo().getId()); |
||||
|
//创建联动操作状态对象 |
||||
|
IsLinkageState(rotaryCabinet); |
||||
|
IsCallbackState(rotaryCabinet); |
||||
|
|
||||
|
deviceArchivesTagRepository.save(deviceArchivesTag); |
||||
|
|
||||
|
rotaryCabinetRepository.save(rotaryCabinet); |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
@Transactional(rollbackFor = Exception.class) |
||||
|
public void update(RotaryCabinet rotaryCabinet) { |
||||
|
List<RotaryCabinet> rotaryCabinetList = rotaryCabinetRepository.findIpAndPortAndAreaNo(rotaryCabinet.getCupboardNo(), rotaryCabinet.getDeviceInfo().getDeviceIp(), rotaryCabinet.getDeviceInfo().getDevicePort()); |
||||
|
if (!ObjectUtils.isEmpty(rotaryCabinetList)) { |
||||
|
throw new BaseException("同一IP和端口号下不能重复添加设备"); |
||||
|
} |
||||
|
RotaryCabinet rotaryCabinet1 = rotaryCabinetRepository.findById(rotaryCabinet.getId()).orElseGet(RotaryCabinet::new); |
||||
|
if (ObjectUtils.isEmpty(rotaryCabinet1)) { |
||||
|
throw new BaseException("数据不存在"); |
||||
|
} |
||||
|
|
||||
|
rotaryCabinet1.setDeviceAccount(rotaryCabinet.getDeviceAccount()); |
||||
|
rotaryCabinet1.setDevicePassword(rotaryCabinet.getDevicePassword()); |
||||
|
rotaryCabinet1.getDeviceInfo().setDeviceName(rotaryCabinet.getDeviceInfo().getDeviceName()); |
||||
|
rotaryCabinet1.getDeviceInfo().setDeviceIp(rotaryCabinet.getDeviceInfo().getDeviceIp()); |
||||
|
rotaryCabinet1.getDeviceInfo().setDevicePort(rotaryCabinet.getDeviceInfo().getDevicePort()); |
||||
|
rotaryCabinet1.setStoreroomCode(rotaryCabinet.getStoreroomCode()); |
||||
|
IsLinkageState(rotaryCabinet); |
||||
|
IsCallbackState(rotaryCabinet); |
||||
|
rotaryCabinetRepository.save(rotaryCabinet1); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 保存联动操作状态 |
||||
|
* |
||||
|
* @param rotaryCabinet / |
||||
|
*/ |
||||
|
private void IsLinkageState(RotaryCabinet rotaryCabinet) { |
||||
|
|
||||
|
if (StringUtils.isEmpty(rotaryCabinet.getIsLinkage().getId())){ |
||||
|
OperatingState operatingState = new OperatingState(); |
||||
|
operatingState.setId(NanoIdUtils.randomNanoId()); |
||||
|
operatingState.setDeviceId(rotaryCabinet.getId()); |
||||
|
operatingState.setBorrow(rotaryCabinet.getIsLinkage().getBorrow()); |
||||
|
operatingState.setInBound(rotaryCabinet.getIsLinkage().getInBound()); |
||||
|
operatingState.setOutBound(rotaryCabinet.getIsLinkage().getOutBound()); |
||||
|
operatingState.setLend(rotaryCabinet.getIsLinkage().getLend()); |
||||
|
operatingState.setStateType(rotaryCabinet.getIsLinkage().getStateType()); |
||||
|
operatingStateRepository.save(operatingState); |
||||
|
}else { |
||||
|
OperatingState operatingState1 = operatingStateRepository.findById(rotaryCabinet.getIsLinkage().getId()).orElseGet(OperatingState::new); |
||||
|
operatingState1.setDeviceId(rotaryCabinet.getId()); |
||||
|
operatingState1.setBorrow(rotaryCabinet.getIsLinkage().getBorrow()); |
||||
|
operatingState1.setInBound(rotaryCabinet.getIsLinkage().getInBound()); |
||||
|
operatingState1.setOutBound(rotaryCabinet.getIsLinkage().getOutBound()); |
||||
|
operatingState1.setLend(rotaryCabinet.getIsLinkage().getLend()); |
||||
|
operatingState1.setStateType(rotaryCabinet.getIsLinkage().getStateType()); |
||||
|
operatingStateRepository.save(operatingState1); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存回调操作状态 |
||||
|
* |
||||
|
* @param rotaryCabinet / |
||||
|
*/ |
||||
|
private void IsCallbackState(RotaryCabinet rotaryCabinet) { |
||||
|
|
||||
|
if (StringUtils.isEmpty(rotaryCabinet.getIsCallback().getId())){ |
||||
|
OperatingState operatingState = new OperatingState(); |
||||
|
operatingState.setId(NanoIdUtils.randomNanoId()); |
||||
|
operatingState.setDeviceId(rotaryCabinet.getId()); |
||||
|
operatingState.setBorrow(rotaryCabinet.getIsCallback().getBorrow()); |
||||
|
operatingState.setInBound(rotaryCabinet.getIsCallback().getInBound()); |
||||
|
operatingState.setOutBound(rotaryCabinet.getIsCallback().getOutBound()); |
||||
|
operatingState.setLend(rotaryCabinet.getIsCallback().getLend()); |
||||
|
operatingState.setStateType(rotaryCabinet.getIsCallback().getStateType()); |
||||
|
operatingStateRepository.save(operatingState); |
||||
|
}else { |
||||
|
OperatingState operatingState1 = operatingStateRepository.findById(rotaryCabinet.getIsLinkage().getId()).orElseGet(OperatingState::new); |
||||
|
operatingState1.setDeviceId(rotaryCabinet.getId()); |
||||
|
operatingState1.setBorrow(rotaryCabinet.getIsCallback().getBorrow()); |
||||
|
operatingState1.setInBound(rotaryCabinet.getIsCallback().getInBound()); |
||||
|
operatingState1.setOutBound(rotaryCabinet.getIsCallback().getOutBound()); |
||||
|
operatingState1.setLend(rotaryCabinet.getIsCallback().getLend()); |
||||
|
operatingState1.setStateType(rotaryCabinet.getIsCallback().getStateType()); |
||||
|
operatingStateRepository.save(operatingState1); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue