Commit d81f80a4 authored by keita.onoguchi's avatar keita.onoguchi

Merge branch '購入履歴調整' into 'master'

購入履歴検索機能追加

See merge request !85
parents 44523d91 92a98090
......@@ -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);
}
......@@ -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);
}
}
package com.example.web;
import java.sql.Date;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class DateSearchForm {
private Date date;
}
......@@ -18,6 +18,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 com.example.domain.Items;
......@@ -47,6 +48,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) {
......@@ -143,7 +154,11 @@ public class EcsiteController {
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";
}
......@@ -167,6 +182,37 @@ 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);
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){
......
package com.example.web;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class PriceSearchForm {
private Integer lowPrice;
private Integer highPrice;
}
......@@ -1816,6 +1816,14 @@ label {
color: #000;
}
#sortButton{
margin: 100px;
}
#sort {
margin-left:200px;
}
/* 管理画面(宮嶋) */
#management_wrapper {
height: 100%;
......
$(function(){
$('#sort').click(function(){
window.location.href = ($('#purchase').attr('href'));
});
});
\ No newline at end of file
......@@ -66,7 +66,7 @@
<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">
......@@ -82,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">
......@@ -141,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>
......
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