Merge branch 'master' into feature/intern_warehouse
This commit is contained in:
commit
f6554629d7
|
@ -1,6 +1,15 @@
|
|||
INSERT INTO article_offers ("manufacturer", "article_number", "price_per_unit_net", "title", "vat_percent", "should_be_advertised")
|
||||
VALUES ("McDonalds", "1", 4242, "McPizza", 7, 1);
|
||||
/*
|
||||
* add a supplier first
|
||||
*/
|
||||
|
||||
INSERT INTO article_offers ("manufacturer", "article_number", "price_per_unit_net", "title", "vat_percent", "should_be_advertised", "cheapest_supplier_id")
|
||||
VALUES ("McDonalds", "1", 4242, "McPizza", 7, 1, 1);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* There is no need for the add article, you can add one form the UI on the offerd article page
|
||||
*/
|
||||
INSERT INTO articles ("related_id", "shop_price_per_unit_net_cent", "warehouse_units_per_slot", "should_reorder", "reorder_max_price", "title", "description", "image_id")
|
||||
VALUES (1, 19.99, 10, 1, 15, "Huge Hamburger", "This huge Hamburger is awesome!", NULL);
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
INSERT INTO suppliers ("api_url", "name", "uuid")
|
||||
VALUES ("https://api.com", "Conrad", "fdfdfg4gdfgdf4gfg");
|
||||
|
||||
|
||||
|
|
@ -30,9 +30,10 @@ public class UpdateOffersAction {
|
|||
public List<ArticleOffer> finish() {
|
||||
HashMap<ArticleIdentifier, ArticleOffer> availableOffers = mapOffers();
|
||||
|
||||
// Reset all advertise-flags first. They are set again below.
|
||||
// Reset all advertise-flags and supplier relations first. They are set again below.
|
||||
for (ArticleOffer offer : availableOffers.values()) {
|
||||
offer.shouldBeAdvertised = false;
|
||||
offer.cheapestSupplier = null;
|
||||
}
|
||||
|
||||
for (Entry<ArticleIdentifier, Offer> cheapestOffer : cheapestOffer.entrySet()) {
|
||||
|
@ -47,7 +48,10 @@ public class UpdateOffersAction {
|
|||
}
|
||||
Article currentOfferedArticle = cheapestOffer.getValue().apiSupplier.findArticle(manufacturer,
|
||||
articleNumber);
|
||||
currentOffer.title = currentOfferedArticle.title;
|
||||
currentOffer.vatPercent = currentOfferedArticle.vatPercent;
|
||||
currentOffer.cheapestSupplier = cheapestOffer.getValue().dbSupplier;
|
||||
currentOffer.pricePerUnitNet = currentOfferedArticle.pricePerUnitNet;
|
||||
|
||||
// Set advertise-flag if any supplier wants it to be set
|
||||
if (currentOfferedArticle.shouldBeAdvertised) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package org.hso.ecommerce.action.shop;
|
||||
|
||||
import org.hso.ecommerce.entities.shop.Article;
|
||||
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchByTermAction {
|
||||
|
||||
public static List<Article> searchByTerm(String sourceTerm, ArticleRepository repository) {
|
||||
|
||||
List<String> terms = Arrays.asList(sourceTerm.split(" "));
|
||||
List<Article> resultArticles = new ArrayList<>();
|
||||
|
||||
terms.forEach(term -> {
|
||||
List<Article> titleArticles = repository.getArticlesByTermInTitle(term); //search in Title
|
||||
titleArticles.forEach(article -> {
|
||||
if(!resultArticles.contains(article)){
|
||||
resultArticles.add(article);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
terms.forEach(term -> {
|
||||
List<Article> descArticles = repository.getArticlesByTermInDescription(term); //search by Term
|
||||
descArticles.forEach(article -> {
|
||||
if(!resultArticles.contains(article)){
|
||||
resultArticles.add(article);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
return resultArticles;
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
|
@ -30,7 +31,8 @@ public class RegisterController {
|
|||
@RequestParam("name") String name,
|
||||
@RequestParam("address") String address,
|
||||
@RequestParam("type") String type,
|
||||
@RequestParam("ad") String ad
|
||||
@RequestParam("ad") String ad,
|
||||
HttpSession session
|
||||
)
|
||||
{
|
||||
Optional<User> user = userRepository.findByEmail(username);
|
||||
|
@ -64,7 +66,10 @@ public class RegisterController {
|
|||
|
||||
userRepository.save(newUser); // save newUser
|
||||
|
||||
return "redirect:/login";
|
||||
user = userRepository.findByEmail(username);
|
||||
session.setAttribute("userId", user.get().getId());
|
||||
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
@GetMapping("/register")
|
||||
|
|
|
@ -148,9 +148,9 @@ public class InternArticleController {
|
|||
File tmpFile = new File(defaultImagePath);
|
||||
// test if default img file exits
|
||||
if (!tmpFile.exists()) {
|
||||
// fallback if the file not exists
|
||||
// fallback if the file not exists
|
||||
// create new file
|
||||
BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB);
|
||||
BufferedImage bufferedImage = new BufferedImage(422, 428, BufferedImage.TYPE_INT_RGB);
|
||||
try {
|
||||
ImageIO.write(bufferedImage, "jpg", new File(defaultImagePath)); // save new file on disk
|
||||
} catch (IOException e) {
|
||||
|
@ -208,7 +208,10 @@ public class InternArticleController {
|
|||
public long id;
|
||||
|
||||
void addListedArticle(Article article, int stock) {
|
||||
this.imgPath = article.image.path;
|
||||
|
||||
if (article.image != null) {
|
||||
this.imgPath = article.image.path;
|
||||
}
|
||||
this.title = article.title;
|
||||
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
||||
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
||||
|
@ -338,7 +341,9 @@ public class InternArticleController {
|
|||
}
|
||||
|
||||
void addArticle(Article article, int stock) {
|
||||
this.imgPath = article.image.path;
|
||||
if (article.image != null) {
|
||||
this.imgPath = article.image.path;
|
||||
}
|
||||
this.title = article.title;
|
||||
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
|
||||
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
|
||||
|
|
|
@ -26,11 +26,11 @@ public class SupplierOfferController {
|
|||
@GetMapping("supplierOffers")
|
||||
public String internListedArticles(Model model) {
|
||||
|
||||
List<UImodelOfferedArticle> totals = new ArrayList<UImodelOfferedArticle>();
|
||||
List<UImodelOfferedArticle> totals = new ArrayList<>();
|
||||
|
||||
for (ArticleOffer article : offersRepository.findAll()) {
|
||||
UImodelOfferedArticle tmp = new UImodelOfferedArticle();
|
||||
tmp.addData(article, "supplierName01", 4884, articleRepository.findArticleIDByRelatedID(article.id)); //TODO display supplier name with link
|
||||
tmp.addData(article, articleRepository.findArticleIDByRelatedID(article.id));
|
||||
totals.add(tmp);
|
||||
}
|
||||
|
||||
|
@ -40,16 +40,15 @@ public class SupplierOfferController {
|
|||
|
||||
public class UImodelOfferedArticle {
|
||||
|
||||
long offer_id;
|
||||
long offer_id;
|
||||
String title;
|
||||
String manufacturer;
|
||||
String articlenumber;
|
||||
String supplierName;
|
||||
int supplierId;
|
||||
String price;
|
||||
String ads;
|
||||
int listedArticleId;
|
||||
boolean offerIsListed; //true --> offered article is listed
|
||||
boolean offerIsListed; // true --> offered article is listed
|
||||
|
||||
public long getOffer_id() {
|
||||
return offer_id;
|
||||
|
@ -58,7 +57,7 @@ public class SupplierOfferController {
|
|||
public void setOffer_id(long offer_id) {
|
||||
this.offer_id = offer_id;
|
||||
}
|
||||
|
||||
|
||||
public boolean isOfferIsListed() {
|
||||
return offerIsListed;
|
||||
}
|
||||
|
@ -99,14 +98,6 @@ public class SupplierOfferController {
|
|||
this.supplierName = supplierName;
|
||||
}
|
||||
|
||||
public int getSupplierId() {
|
||||
return supplierId;
|
||||
}
|
||||
|
||||
public void setSupplierId(int supplierId) {
|
||||
this.supplierId = supplierId;
|
||||
}
|
||||
|
||||
public String getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
@ -131,15 +122,13 @@ public class SupplierOfferController {
|
|||
this.listedArticleId = listedArticleId;
|
||||
}
|
||||
|
||||
public void addData(ArticleOffer article, String supplierName, int supplierId,
|
||||
Optional<Integer> listedArticleId) {
|
||||
public void addData(ArticleOffer article, Optional<Integer> listedArticleId) {
|
||||
|
||||
this.offer_id = article.id;
|
||||
this.title = article.title;
|
||||
this.manufacturer = article.manufacturer;
|
||||
this.articlenumber = article.articleNumber;
|
||||
this.supplierName = supplierName;
|
||||
this.supplierId = supplierId;
|
||||
this.supplierName = article.cheapestSupplier.name;
|
||||
this.price = String.format("%.2f", ((float) article.pricePerUnitNet / 100));
|
||||
this.ads = (article.shouldBeAdvertised) ? "Ja" : "Nein";
|
||||
|
||||
|
|
|
@ -100,8 +100,11 @@ public class ShopArticleController {
|
|||
@PathVariable("id") Long id
|
||||
) throws IOException {
|
||||
Article article = articleRepository.findArticleById(id);
|
||||
InputStream in = new FileInputStream(article.image.path);
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
IOUtils.copy(in, response.getOutputStream());
|
||||
|
||||
if(article.image != null) {
|
||||
InputStream in = new FileInputStream(article.image.path);
|
||||
response.setContentType(MediaType.IMAGE_JPEG_VALUE);
|
||||
IOUtils.copy(in, response.getOutputStream());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.hso.ecommerce.controller.shop;
|
||||
|
||||
import org.hso.ecommerce.action.shop.SearchByTermAction;
|
||||
import org.hso.ecommerce.entities.shop.Article;
|
||||
import org.hso.ecommerce.repos.shop.ArticleRepository;
|
||||
import org.hso.ecommerce.repos.shop.CategoryRepository;
|
||||
|
@ -31,8 +32,10 @@ public class ShopSearchController {
|
|||
) {
|
||||
model.addAttribute("categories", categoryRepository.getCategories()); //for sidebar
|
||||
|
||||
term = term.trim();
|
||||
|
||||
if (term != null) { //if search by Term
|
||||
List<Article> articles = articleRepository.getArticlesByTerm(term); //search by Term
|
||||
List<Article> articles = SearchByTermAction.searchByTerm(term, articleRepository);
|
||||
model.addAttribute("articles", articles);
|
||||
} else if (category != null) { //if search by Category
|
||||
List<Article> articles = articleRepository.getArticlesByCategory(category); //search by Category
|
||||
|
|
|
@ -28,5 +28,6 @@ public class ArticleOffer {
|
|||
|
||||
public boolean shouldBeAdvertised;
|
||||
|
||||
|
||||
@ManyToOne(optional = true)
|
||||
public Supplier cheapestSupplier;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,10 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
|||
Optional<Integer> findArticleIDByRelatedID(@Param("relatedId") long relatedId);
|
||||
|
||||
@Query(value = "Select a.* from articles as a, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and a.title LIKE %:term% group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||
List<Article> getArticlesByTerm(String term);
|
||||
List<Article> getArticlesByTermInTitle(String term);
|
||||
|
||||
@Query(value = "Select a.* from articles as a, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and a.description LIKE %:term% group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||
List<Article> getArticlesByTermInDescription(String term);
|
||||
|
||||
@Query(value = "Select a.* from articles as a, categories as c, article_categories_bindings as acb, warehouse_booking_position_entries as wbpe where wbpe.article_id = a.id and acb.articles_id = a.id and acb.categories_id = c.id and c.name = :category group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||
List<Article> getArticlesByCategory(String category);
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
<td><span th:text="${article.title}"></span></td>
|
||||
<td><span th:text="${article.manufacturer}"></span></td>
|
||||
<td><span th:text="${article.articlenumber}"></span></td>
|
||||
<td><a th:href="@{/intern/suppliers/{id}(id = ${article.supplierId})}" th:text="${article.supplierName}"></a></td>
|
||||
<td><a th:href="${'/intern/suppliers/#q=' + article.supplierName}" th:text="${article.supplierName}"></a></td>
|
||||
<td><span th:text="${article.price}"></span> €</td>
|
||||
<td><span th:text="${article.ads}"></span></td>
|
||||
<td>
|
||||
|
|
Reference in New Issue