WIP feature/listedArticles #15
|
@ -0,0 +1,32 @@
|
|||
package org.hso.ecommerce.components;
|
||||
|
||||
import org.hso.ecommerce.entities.warehouse.Slot;
|
||||
import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Component
|
||||
public class SlotInitializer {
|
||||
|
||||
@Autowired
|
||||
private final SlotRepository slotRepository = null;
|
||||
|
||||
// TODO: use values form cfg.
|
||||
private final int NUM_SLOTS = 50;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
for (int i = 1; i <= NUM_SLOTS; i++) {
|
||||
if (!slotRepository.findBySlotNum(i).isPresent()) {
|
||||
Slot slotAdded = new Slot();
|
||||
slotAdded.slotNum = i;
|
||||
slotRepository.save(slotAdded);
|
||||
|
||||
System.out.println("Added Slot " + i + " to DB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -122,14 +122,14 @@ public class ShopCheckoutController {
|
|||
expectedPrice,
|
||||
Address.fromString(address),
|
||||
PaymentMethod.fromCreditCarNumber(cardnumber),
|
||||
bookingEntryRepository.getByUser(user).orElse(BookingAccountEntry.newUser(user)),
|
||||
bookingEntryRepository.getByUser(user.id).orElse(BookingAccountEntry.newUser(user)),
|
||||
bookingEntryRepository.getByVat().orElse(BookingAccountEntry.newVat()),
|
||||
bookingEntryRepository.getByMain().orElse(BookingAccountEntry.newMain())
|
||||
);
|
||||
|
||||
for (ShoppingCart.ShoppingCartItem item : shoppingCart.getItems()) {
|
||||
Article article = articleRepository.findById(item.getArticleId()).get();
|
||||
action.addArticle(article, item.getAmount(), wbeseRepo.getByArticle(article));
|
||||
action.addArticle(article, item.getAmount(), wbeseRepo.getByArticle(article.id));
|
||||
}
|
||||
|
||||
CreateOrderAction.Result result = action.finish();
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.hso.ecommerce.entities.warehouse;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "warehouse_slots")
|
||||
public class Slot {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Basic
|
||||
public long id;
|
||||
|
||||
@NotNull
|
||||
@Column(unique = true)
|
||||
public int slotNum;
|
||||
}
|
|
@ -3,6 +3,7 @@ package org.hso.ecommerce.entities.warehouse;
|
|||
import org.hso.ecommerce.entities.shop.Article;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "warehouse_booking_position_entries")
|
||||
|
@ -13,6 +14,7 @@ public class WarehouseBookingPositionSlotEntry {
|
|||
@Basic
|
||||
public long id;
|
||||
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
public Article article;
|
||||
|
||||
|
@ -20,7 +22,9 @@ public class WarehouseBookingPositionSlotEntry {
|
|||
//public int newSumArticles;
|
||||
public int newSumSlot;
|
||||
|
||||
public int slot;
|
||||
@NotNull
|
||||
@ManyToOne
|
||||
public Slot slot;
|
||||
|
||||
public WarehouseBookingPositionSlotEntry copyAddAmount(int amount) {
|
||||
WarehouseBookingPositionSlotEntry e = new WarehouseBookingPositionSlotEntry();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.hso.ecommerce.repos.booking;
|
||||
|
||||
import org.hso.ecommerce.entities.booking.BookingAccountEntry;
|
||||
import org.hso.ecommerce.entities.user.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
@ -11,13 +10,13 @@ import java.util.Optional;
|
|||
@Repository
|
||||
public interface BookingAccountEntryRepository extends JpaRepository<BookingAccountEntry, Long> {
|
||||
|
||||
@Query("SELECT e FROM BookingAccountEntry e WHERE e.userAccount = :user ORDER BY e.id DESC")
|
||||
Optional<BookingAccountEntry> getByUser(User user);
|
||||
@Query(value = "SELECT * FROM booking_account_entries as e WHERE e.user_account_id = :user ORDER BY e.id DESC LIMIT 1", nativeQuery = true)
|
||||
Optional<BookingAccountEntry> getByUser(Long user);
|
||||
|
||||
@Query("SELECT e FROM BookingAccountEntry e WHERE e.isMainAccount = 1 ORDER BY e.id DESC")
|
||||
@Query(value = "SELECT * FROM booking_account_entries as e WHERE e.is_main_account = 1 ORDER BY e.id DESC LIMIT 1", nativeQuery = true)
|
||||
Optional<BookingAccountEntry> getByMain();
|
||||
|
||||
@Query("SELECT e FROM BookingAccountEntry e WHERE e.isVATAccount = 1 ORDER BY e.id DESC")
|
||||
@Query(value = "SELECT * FROM booking_account_entries as e WHERE e.isvataccount = 1 ORDER BY e.id DESC LIMIT 1", nativeQuery = true)
|
||||
Optional<BookingAccountEntry> getByVat();
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.hso.ecommerce.repos.warehouse;
|
||||
|
||||
import org.hso.ecommerce.entities.warehouse.Slot;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface SlotRepository extends JpaRepository<Slot, Long> {
|
||||
|
||||
@Query("SELECT s FROM Slot s WHERE s.slotNum = :slotNum")
|
||||
Optional<Slot> findBySlotNum(int slotNum);
|
||||
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package org.hso.ecommerce.repos.warehouse;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.Article;
|
||||
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
@ -12,7 +11,8 @@ import java.util.List;
|
|||
public interface WarehouseBookingPositionSlotEntryRepository extends JpaRepository<WarehouseBookingPositionSlotEntry, Long> {
|
||||
|
||||
// TODO this is wrong. revisit.
|
||||
@Query("SELECT e FROM WarehouseBookingPositionSlotEntry e WHERE e.article = :article ORDER BY e.id DESC")
|
||||
List<WarehouseBookingPositionSlotEntry> getByArticle(Article article);
|
||||
// @Query("SELECT e FROM WarehouseBookingPositionSlotEntry e, Slot s WHERE e.slot = s AND e.article = :article GROUP BY e.slot.slotNum HAVING max(e.id)")
|
||||
@Query(value = "Select e.id, e.article_id, e.new_sum_slot, e.slot_id from warehouse_booking_position_entries as e, warehouse_slots as s where e.slot_id = s.id AND e.article_id = :article GROUP BY s.slot_num HAVING max(e.id)", nativeQuery = true)
|
||||
List<WarehouseBookingPositionSlotEntry> getByArticle(long article);
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue