Commit 5ebe065a authored by issei.miyajima's avatar issei.miyajima

Merge branch 'master' of http://gitlab.fox-hound.co.jp/shoei.kanno/Ecsite into 検索機能

# Conflicts:
#	src/main/java/com/example/repository/ShoesRepository.java
#	src/main/java/com/example/service/ShoesService.java
parents f7b06b21 6c5981d6
import org.springframework.web.multipart.MultipartFile;
import lombok.Getter;
import lombok.Setter;
//靴新規登録用フォーム
@Getter
@Setter
public class ShoesForm {
private String name;
private Integer price;
private Integer stock;
private Integer size;
private Integer product_status;
//画像を受け取る変数
private MultipartFile multipartFile;
}
......@@ -22,6 +22,7 @@ public class SalesLog {
private Integer id;
private Integer userId;
private Integer shoesId;
private Integer quantity;
private Integer price;
private Date created;
......
......@@ -11,10 +11,13 @@ import com.example.domain.SalesLog;
@Repository
public interface SalesLogRepository extends JpaRepository<SalesLog, Integer>{
@Query(value = "SELECT id,user_id, shoes_id, SUM(price) AS price, created FROM sales_logs AS sl WHERE sl.user_id = ?1 GROUP BY sl.created",
@Query(value = "SELECT id,user_id, shoes_id, quantity, SUM(price) AS price, created FROM sales_logs AS sl WHERE sl.user_id = ?1 GROUP BY sl.created",
nativeQuery = true)
public List <SalesLog> history(Integer id);
@Query(value = "SELECT id, user_id, shoes_id, price, created FROM sales_logs AS sl WHERE sl.created = ?1 && sl.user_id = ?2",
@Query(value = "SELECT id, user_id, shoes_id, quantity, price, created FROM sales_logs AS sl WHERE sl.created = ?1 && sl.user_id = ?2",
nativeQuery = true)
public List <SalesLog> historyDetails(Date created, Integer id);
@Query(value = "SELECT id, user_id, shoes_id, quantity, price, created FROM sales_logs AS sl WHERE sl.price >= ?1 && sl.price <= ?2 && sl.user_id = ?3",
nativeQuery = true)
public List <SalesLog> searchPrice(Integer lowPrice, Integer highPrice, Integer id);
}
......@@ -13,6 +13,7 @@ import com.example.domain.Shoes;
public interface ShoesRepository extends JpaRepository<Shoes, Integer>{
@Query(value = "SELECT * FROM shoes WHERE product_status = ?1 ORDER BY id DESC", nativeQuery = true)
public List <Shoes> findAllByStatus(Integer status);
<<<<<<< HEAD
//商品名あいまい検索
@Query(value = "SELECT * FROM shoes WHERE name LIKE %:keyword% ORDER BY id DESC", nativeQuery = true)
......@@ -22,3 +23,11 @@ public interface ShoesRepository extends JpaRepository<Shoes, Integer>{
@Query(value = "SELECT * FROM shoes WHERE size =?1 ORDER BY id DESC", nativeQuery = true)
public List <Shoes> findAllBySize(Integer size);
}
=======
//管理画面で使用
@Query(value = "SELECT * FROM shoes WHERE name = ?1 && size = ?2", nativeQuery = true)
public Shoes findOneAddStock(String name, Integer size);
}
>>>>>>> 6c5981d65b423f7ba8b4f9fef90d0047960002bb
......@@ -46,6 +46,7 @@ public class SalesLogService {
SalesLog salesLog = new SalesLog();
salesLog.setUserId(userId);
salesLog.setShoesId((cart.get(i)).getShoesId());
salesLog.setQuantity((cart.get(i)).getQuantity());
salesLog.setPrice((cart.get(i)).getPrice());
salesLog.setCreated(today);
salesLogRepository.save(salesLog);
......@@ -59,4 +60,8 @@ public class SalesLogService {
public List <SalesLog> historyDetails(Date created, Integer id) {
return salesLogRepository.historyDetails(created, id);
}
public List<SalesLog> searchPrice(Integer lowPrice, Integer highPrice, Integer id){
return salesLogRepository.searchPrice(lowPrice, highPrice, id);
}
}
......@@ -60,4 +60,8 @@ public class ShoesService {
return shoesRepository.findAllBySize(shoesSize);
}
//管理画面、重複商品のバリデーション
public Shoes findOneAddStock(String name, Integer size) {
return shoesRepository.findOneAddStock(name, size);
}
}
package com.example.web;
import java.sql.Date;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class DateSearchForm {
private Date date;
}
......@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -49,6 +50,16 @@ public class EcsiteController {
return new WalletsForm();
}
@ModelAttribute
DateSearchForm setForm() {
return new DateSearchForm();
}
@ModelAttribute
PriceSearchForm setPriceForm() {
return new PriceSearchForm();
}
int totalPrice = 0;
//写真の表示用メソッド
public String photoView(String Photo) {
......@@ -88,6 +99,8 @@ public class EcsiteController {
public String top(Model model, @AuthenticationPrincipal LoginUser userDetails) {
User user = userDetails.getUser();
model.addAttribute("user", user);
Wallets wallets = walletsService.findOne(user.getId());
model.addAttribute("wallets", wallets);
if(session.getAttribute("cartValue") == null) {
model.addAttribute("cartValue", 0);
}else {
......@@ -118,6 +131,8 @@ public class EcsiteController {
//user情報取得、格納
User user = userDetails.getUser();
model.addAttribute("user", user);
Wallets wallets = walletsService.findOne(user.getId());
model.addAttribute("wallets", wallets);
//カート個数取得、格納
if(session.getAttribute("cartValue") == null) {
model.addAttribute("cartValue", 0);
......@@ -159,13 +174,19 @@ public class EcsiteController {
public String history (@PathVariable Integer id, Model model, SalesLog salesLog, @AuthenticationPrincipal LoginUser userDetails) {
User user = userDetails.getUser();
model.addAttribute("user", user);
Wallets wallets = walletsService.findOne(user.getId());
model.addAttribute("wallets", wallets);
if(session.getAttribute("cartValue") == null) {
model.addAttribute("cartValue", 0);
}else {
model.addAttribute("cartValue",session.getAttribute("cartValue"));
}
List<SalesLog> list = salesLogService.history(id);
model.addAttribute("log", list);
ArrayList<SalesLog> newList = new ArrayList<SalesLog>();
for(int i = (list.size() - 1); i >= 0; i--){
newList.add(list.get(i));
}
model.addAttribute("log", newList);
return "log";
}
......@@ -174,6 +195,8 @@ public class EcsiteController {
public String historyDetails (@PathVariable Date created, Model model, @AuthenticationPrincipal LoginUser userDetails) {
User user = userDetails.getUser();
model.addAttribute("user", user);
Wallets wallets = walletsService.findOne(user.getId());
model.addAttribute("wallets", wallets);
if(session.getAttribute("cartValue") == null) {
model.addAttribute("cartValue", 0);
}else {
......@@ -187,6 +210,39 @@ public class EcsiteController {
return "logDetails";
}
//購入履歴検索
@PostMapping("log/search/{id}")
public String searchHistory(@PathVariable Integer id, DateSearchForm dateSerchform, PriceSearchForm priceSearchform, Model model, @AuthenticationPrincipal LoginUser userDetails){
User user = userDetails.getUser();
model.addAttribute("user", user);
Wallets wallets = walletsService.findOne(user.getId());
model.addAttribute("wallets", wallets);
if(session.getAttribute("cartValue") == null) {
model.addAttribute("cartValue", 0);
}else {
model.addAttribute("cartValue",session.getAttribute("cartValue"));
}
//金額の指定がなく日付での検索のみ
if(priceSearchform.getHighPrice() == null && priceSearchform.getLowPrice() == null && dateSerchform.getDate() != null){
List<SalesLog> list = salesLogService.historyDetails(dateSerchform.getDate(), user.getId());
model.addAttribute("log", list);
return "log";
}
//金額のみの検索
if(dateSerchform.getDate() == null && priceSearchform.getLowPrice() != null && priceSearchform.getHighPrice() != null){
if(priceSearchform.getLowPrice() == null){
priceSearchform.setLowPrice(0);
}
if(priceSearchform.getHighPrice() == null){
priceSearchform.setHighPrice(1000000000);
}
List<SalesLog> list = salesLogService.searchPrice(priceSearchform.getLowPrice(), priceSearchform.getHighPrice(), user.getId());
model.addAttribute("log", list);
return "log";
}
return "log";
}
//カート画面
@GetMapping("cart")
public String Cart(Model model, @AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){
......
......@@ -62,7 +62,23 @@ public class ManagementController {
if(result.hasErrors()) {
return "management";
}
multipartFile = form.getMultipartFile();
System.out.println(multipartFile);
//以前に登録されている商品の場合に登録できないバリデーション
Shoes sameShoes = shoesService.findOneAddStock(form.getName(), form.getSize());
System.out.println(sameShoes);
if (!(sameShoes == null)) {
Integer sumStock = form.getStock() + sameShoes.getStock();
if (sumStock >= 10) {
sameShoes.setStock(10);
shoesService.update(sameShoes);
} else {
sameShoes.setStock(sumStock);
shoesService.update(sameShoes);
}
} else {
Shoes shoes = new Shoes();
if (!multipartFile.isEmpty()) {
try {
......@@ -112,12 +128,19 @@ public class ManagementController {
} else {
shoes.setPhoto("noimage.jpg");
}
shoes.setName(form.getName());
shoes.setPrice(form.getPrice());
shoes.setStock(form.getStock());
shoes.setSize(form.getSize());
shoes.setProductStatus(form.getProductStatus());
shoesService.update(shoes);
}
//遷移先
return "redirect:/limited/admin/management";
}
......
package com.example.web;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class PriceSearchForm {
private Integer lowPrice;
private Integer highPrice;
}
/* Slider */
.slick-slider
{
position: relative;
display: block;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-touch-callout: none;
-khtml-user-select: none;
-ms-touch-action: pan-y;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}
.slick-list
{
position: relative;
display: block;
overflow: hidden;
margin: 0;
padding: 0;
}
.slick-list:focus
{
outline: none;
}
.slick-list.dragging
{
cursor: pointer;
cursor: hand;
}
.slick-slider .slick-track,
.slick-slider .slick-list
{
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
-ms-transform: translate3d(0, 0, 0);
-o-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.slick-track
{
position: relative;
top: 0;
left: 0;
display: block;
margin-left: auto;
margin-right: auto;
}
.slick-track:before,
.slick-track:after
{
display: table;
content: '';
}
.slick-track:after
{
clear: both;
}
.slick-loading .slick-track
{
visibility: hidden;
}
.slick-slide
{
display: none;
float: left;
height: 100%;
min-height: 1px;
}
[dir='rtl'] .slick-slide
{
float: right;
}
.slick-slide img
{
display: block;
}
.slick-slide.slick-loading img
{
display: none;
}
.slick-slide.dragging img
{
pointer-events: none;
}
.slick-initialized .slick-slide
{
display: block;
}
.slick-loading .slick-slide
{
visibility: hidden;
}
.slick-vertical .slick-slide
{
display: block;
height: auto;
border: 1px solid transparent;
}
.slick-arrow.slick-hidden {
display: none;
}
......@@ -1816,6 +1816,14 @@ label {
color: #000;
}
#sortButton{
margin: 100px;
}
#sort {
margin-left:200px;
}
/* 管理画面(宮嶋) */
#management_wrapper {
height: 100%;
......@@ -2062,3 +2070,8 @@ th, td {
#top-footer {
margin-top: 70px;
}
/* ヘッダーにBalance表示 */
#balance-li {
margin-top: 19px;
}
\ No newline at end of file
$('.slick01').slick({ //{}を入れる
autoplay: true, //「オプション名: 値」の形式で書く
dots: true //複数書く場合は「,」でつなぐ
});
\ No newline at end of file
$(function(){
$('#sort').click(function(){
window.location.href = ($('#purchase').attr('href'));
});
});
\ No newline at end of file
This diff is collapsed.
......@@ -70,6 +70,7 @@
<li><a id="wallets" th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallets.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li class="active"><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" th:text="${cartValue}">0</span></a></li>
</ul>
......@@ -129,7 +130,7 @@
</div>
<br/>
<div id="walletAmount">
<p id="total-price">Wallet Amount<span id="total-price-span" th:text="'&yen;' + ${wallets.amount}">10000</span></p>
<p id="total-price">Balance<span id="total-price-span" th:text="'&yen;' + ${wallets.amount}">10000</span></p>
</div>
<div id="buy">
<button class="js-modal-open" id="buy-btn">Buy</button>
......
......@@ -9,6 +9,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="icon" href="images/favicon.png" th:href="@{/images/favicon.png}"/>
<link rel="stylesheet" href="css/style.css" th:href="@{/css/style.css}"/>
<!-- スライドショー -->
<link rel="stylesheet" type="text/css" th:href="@{css/slick.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{css/commmon.css}"/>
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"/> -->
<!--[if lt IE 9]>
......@@ -69,6 +72,7 @@
<li><a th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallets.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" th:text="${cartValue}">0</span></a></li>
</ul>
......@@ -117,7 +121,7 @@
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="carousel-inner slick01" role="listbox">
<div class="item active">
<img th:src="@{/images/スニーカー1.jpg}" width="1648" height="600" alt=""/>
<div class="carousel-caption">
......@@ -271,5 +275,9 @@
integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"
integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<!-- スライドショー -->
<script type="text/javascript" th:src="@{js/slick.min.js}"></script>
<script type="text/javascript" th:src="@{js/common.js}"></script>
</body>
</html>
......@@ -92,6 +92,7 @@
<li><a th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallets.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" id="shoping-cart-span" th:text="${cartValue}">0</span></a></li>
</ul>
......
......@@ -66,10 +66,11 @@
<ul class="nav navbar-nav">
<li><a th:href="@{/limited/top}">Home</a></li>
<li><a th:href="@{/limited/list}">Shop</a></li>
<li class="active"><a th:href="@{/limited/log/{id}(id=${user.id})}">My Purchase Log</a></li>
<li class="active"><a id="purchase" th:href="@{/limited/log/{id}(id=${user.id})}">My Purchase Log</a></li>
<li><a th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallets.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" id="shoping-cart-span" th:text="${cartValue}">0</span></a></li>
</ul>
......@@ -81,21 +82,32 @@
<!-- ログインフォーム -->
<div class="container">
<p id="log-p-text"><span id="log-text" >Purchase History</span></p>
<!--<form id="login-form" method="post" th:action="@{/login}">
<div id="email-form">
<form id="dateSearch-form" method="post" th:action="@{/limited/log/search/{id}(id=${user.id})}" th:object="${DateSearchForm}">
<!-- <div id="email-form">
<label for="login-email">Email</label>
<input type="email" class="login" name="email" id="login-email" placeholder="Email" required="required"/>
</div>-->
<div id="date-form">
<label for="date-form">Date Search</label>
<input type="date" class="date" name="date" id="date"/>
</div>
<div id="password-form">
<label for="login-password">Password</label>
<input type="password" class="login" name="password" id="login-password" placeholder="Password" required="required"/>
<div id="submit-form">
<button type="submit" class="search-submit details-btn" id="dateserach-submit">Go</button>
</div>
</form>
<form id="PriceSearch-form" method="post" th:action="@{/limited/log/search/{id}(id=${user.id})}" th:object="${PriceSearchForm}">
<!-- <div id="email-form">
<label for="login-email">Email</label>
<input type="email" class="login" name="email" id="login-email" placeholder="Email" required="required"/>
</div>-->
<div id="Price-form">
<label for="Price-form">Price Search</label>
<input type="number" class="lowPrice" name="lowPrice" id="lowPrice" required="required"/><span><input type="number" class="highPrice" name="highPrice" id="highPrice" required="required"/></span>
</div>
<div id="submit-form">
<input type="submit" class="login" id="btn" value="Login"/>
会員登録ボタン
<button class="js-modal-open" id="sign-up">Sign Up</button>
<button type="submit" class="search-submit details-btn" id="serach-submit">Go</button>
</div>
</form>-->
</form>
<!-- 購入履歴一覧 -->
<div id="log">
......@@ -140,7 +152,7 @@
<script src="js/owl.carousel.min.js" th:src="@{/js/owl.carousel.min.js}"></script>
<script src="js/wow.min.js" th:src="@{/js/wow.min.js}"></script>
<script src="js/custom.js" th:src="@{/js/custom.js}"></script>-->
<script src="js/cart.js" th:src="@{/js/cart.js}"></script>
<script src="js/log.js" th:src="@{/js/log.js}"></script>
<!-- BootStrap -->
<!-- <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
......
......@@ -70,6 +70,7 @@
<li><a th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallets.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li class="active"><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" th:text="${cartValue}">0</span></a></li>
</ul>
......
......@@ -135,6 +135,7 @@
<tr>
<th>ID</th>
<th>商品名</th>
<th>サイズ</th>
<th>価格</th>
<th>在庫数</th>
<th>商品画像</th>
......@@ -144,6 +145,7 @@
<tr th:each="shoe : ${shoes}">
<td th:text="${shoe.id}">1</td>
<td th:text="${shoe.name}">AirMax</td>
<td th:text="${shoe.size}">27</td>
<td th:text="${shoe.price}">¥10,000</td>
<td th:text="${shoe.stock}">10</td>
<td><img class="shoeImage" th:src="@{/upload/{photo}(photo=${shoe.photo})}" alt="productImage" width="100" height="50"/></td>
......
......@@ -70,6 +70,7 @@
<li class="active"><a th:href="@{/limited/wallets/{id}(id=${user.id})}">Wallets</a></li>
</ul>
<ul class="nav navbar-nav navbar-right cart-menu">
<li id="balance-li">Balance<span th:text="'&yen;' + ${wallet.amount}">10000</span></li>
<li><a class="search-btn"><i class="fa fa-search" aria-hidden="true"></i></a></li>
<li><a th:href="@{/limited/cart}"><span> Cart</span> <span class="shoping-cart" th:text="${cartValue}">0</span></a></li>
</ul>
......
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