Commit 49c6287c authored by lemin's avatar lemin

JPA JPA !!!!1

parent 69b7b1a4
......@@ -33,7 +33,7 @@ public class WMSController {
@PostMapping("/")
public ResponseEntity<Map<String, String>> inventoryCreate(@RequestBody InventoryCreateDto inventoryCreateDto) {
String inventoryId = inventoryService.createInventory(inventoryCreateDto.getProductId(), inventoryCreateDto.getWhName(),
String inventoryId = inventoryService.createInventory(inventoryCreateDto.getWhId(), inventoryCreateDto.getProductId(), inventoryCreateDto.getWhName(),
inventoryCreateDto.getQuantity());
HashMap<String, String> m = new HashMap<>();
m.put("inventoryId", inventoryId);
......
......@@ -6,7 +6,7 @@ import lombok.Setter;
@Getter
@Setter
public class InventoryCreateDto {
// private String whId;
private String whId;
private String productId;
private String whName;
private Integer quantity;
......
package com.showcase.synapse.wms.entity;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ChannelEntity {
@Id
@Column(name = "channel_id")
private Integer id;
@Column(name = "name")
private String name;
@Column(name = "discount_rate")
private BigDecimal discountRate;
}
package com.showcase.synapse.wms.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class InventoryEntity {
@Id
private String whId;
private String productId;
@Id
@Column(name = "wh_id")
private String whid;
@Column(name = "ref_product_id")
private String productid;
private String whName;
private int quantity;
private Integer quantity;
}
package com.showcase.synapse.wms.entity;
import java.math.BigDecimal;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ProductEntity {
@Id
private String id;
private String name;
private String comment;
private BigDecimal price;
// @Column(name = "channel", nullable = false)
// private Integer channel;
@OneToOne(fetch= FetchType.EAGER,cascade = CascadeType.PERSIST)
@JoinColumn(name = "channel_id")
private ChannelEntity channel;
@OneToOne(fetch= FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "ref_product_id")
private InventoryEntity inventory;
}
......@@ -2,6 +2,9 @@ package com.showcase.synapse.wms.event.handler;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.Optional;
import org.axonframework.eventhandling.EventHandler;
import org.springframework.stereotype.Component;
......@@ -22,13 +25,19 @@ public class InventoryEventHandler {
log.info("InventoryCreatedEvent 이벤트 받음?");
log.info("InventoryEventHandler > [InventoryCreatedEvent] productCreatedEvent");
InventoryEntity inventoryEntity = new InventoryEntity();
inventoryEntity.setProductId(inventoryCreatedEvent.getProductId());
inventoryEntity.setWhId(inventoryCreatedEvent.getWhId());
inventoryEntity.setWhName(inventoryCreatedEvent.getWhName());
inventoryEntity.setQuantity(inventoryCreatedEvent.getQuantity());
inventoryRepository.save(inventoryEntity);
Optional<InventoryEntity> optional = inventoryRepository.findById(inventoryCreatedEvent.getWhId());
if(optional.isPresent()) {
InventoryEntity inventoryEntity = optional.get();
// InventoryEntity inventoryEntity = new InventoryEntity();
inventoryEntity.setProductid(inventoryCreatedEvent.getProductId());
inventoryEntity.setWhid(inventoryCreatedEvent.getWhId());
inventoryEntity.setWhName(inventoryCreatedEvent.getWhName());
inventoryEntity.setQuantity(inventoryCreatedEvent.getQuantity());
inventoryRepository.save(inventoryEntity);
}
// inventoryRepository.save(inventoryEntity);
}
......
......@@ -27,11 +27,11 @@ public class InventoryService {
this.queryGateway = queryGateway;
}
public String createInventory(String productId, String whName, int quantity) {
public String createInventory(String whId, String productId, String whName, int quantity) {
log.info("[@Service createProduct] new CreateInventoryCommand");
// command생성
CreateInventoryCommand createInventoryCommand = new CreateInventoryCommand(
UUID.randomUUID().toString(), productId, whName, quantity
whId, productId, whName, quantity
);
// 여기
// 생성한 command전송(비동기)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment