абалдеть сдала
This commit is contained in:
parent
86ee0dd881
commit
fc4a9c601c
BIN
data.mv.db
Normal file
BIN
data.mv.db
Normal file
Binary file not shown.
1112
data.trace.db
Normal file
1112
data.trace.db
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
||||
package ru.ulstu.is.sbapp.repair.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.repair.service.Order_FavorService;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
|
||||
public class ReportController {
|
||||
private final Order_FavorService orderFavorService;
|
||||
@Autowired
|
||||
public ReportController(Order_FavorService orderFavorService) {
|
||||
this.orderFavorService = orderFavorService;
|
||||
}
|
||||
@GetMapping("/report")
|
||||
public Map<String, Integer> GetReport (@RequestParam(value = "from") Object value1,
|
||||
@RequestParam(value = "to") Object value2) throws ParseException {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
Date d1 = formatter.parse(value1.toString());
|
||||
Date d2 = formatter.parse(value2.toString());
|
||||
return orderFavorService.makereport(d1, d2);
|
||||
}
|
||||
}
|
@ -72,7 +72,7 @@ public class Favor {
|
||||
ordersList = new ArrayList<>();
|
||||
if (!ordersList.contains(of)){
|
||||
ordersList.add(of);
|
||||
of.setFavor_id(this.id);
|
||||
of.setFavor_id(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class Order {
|
||||
favorsList = new ArrayList<>();
|
||||
if (!favorsList.contains(of)) {
|
||||
favorsList.add(of);
|
||||
of.setOrder_id(this.id);
|
||||
of.setOrder_id(this);
|
||||
}
|
||||
//favor.addOrder(this);
|
||||
|
||||
|
@ -14,8 +14,10 @@ public class Order_Favor {
|
||||
@Column(name = "amount")
|
||||
private Integer amount;
|
||||
|
||||
private Long Order_id;
|
||||
private Long Favor_id;
|
||||
@ManyToOne
|
||||
private Order Order_id;
|
||||
@ManyToOne
|
||||
private Favor Favor_id;
|
||||
|
||||
public Order_Favor() {
|
||||
}
|
||||
@ -36,19 +38,19 @@ public class Order_Favor {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public Long getFavor_id() {
|
||||
public Favor getFavor_id() {
|
||||
return Favor_id;
|
||||
}
|
||||
|
||||
public void setFavor_id(Long favor_id) {
|
||||
public void setFavor_id(Favor favor_id) {
|
||||
Favor_id = favor_id;
|
||||
}
|
||||
|
||||
public Long getOrder_id() {
|
||||
public Order getOrder_id() {
|
||||
return Order_id;
|
||||
}
|
||||
|
||||
public void setOrder_id(Long order_id) {
|
||||
public void setOrder_id(Order order_id) {
|
||||
Order_id = order_id;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,15 @@ import ru.ulstu.is.sbapp.repair.model.Order_Favor;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Tuple;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class Order_FavorService {
|
||||
@ -63,8 +71,17 @@ public class Order_FavorService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Order_Favor> makereport(){
|
||||
List<Order_Favor> OF = em.createQuery("SELECT s FROM Order_Favor s group by amount", Order_Favor.class).getResultList();
|
||||
return OF;
|
||||
public Map<String, Integer> makereport(Date d1, Date d2){
|
||||
//s = em.createQuery("SELECT sum(off.amount) * f.price from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > '2023-02-01' and o.date < '2023-03-01' group by f.favorName").getResultList().toString();
|
||||
//String s1 = em.createQuery("SELECT f.favorName from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > '2023-02-01' and o.date < '2023-03-01' group by f.favorName").getResultList().toString();
|
||||
//String s1 = em.createQuery("SELECT off.amount from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > '2023-02-01' and o.date < '2023-03-01' group by f.favorName").getResultList().toString();
|
||||
//s = em.createQuery("SELECT f.favorName from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > :d1 ").setParameter("d1", new Date(2023, 2, 1)).getResultList().toString();
|
||||
//s = em.createQuery("SELECT f.favorName, f.price, count(f.favorName) as count, count(f.favorName) * f.price as total from Order_Favor of join Order o on o.id = of.Order_id join Favor f on f.id = of.Favor_id where o.date > '01.02.2023' and o.date < '01.03.2023' group by f.favorName").getResultList().toString();
|
||||
//s = em.createQuery("SELECT count(f.favorName) * f.price from Favor f group by favorName").getResultList().toString();
|
||||
Map<String, Integer> answ = em.createQuery("SELECT f.favorName as n, sum(off.amount) * f.price as s from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > :date1 and o.date < :date2 group by f.favorName", Tuple.class).setParameter("date1", d1).setParameter("date2", d2).getResultStream().collect(Collectors.toMap(tuple -> ((String)tuple.get("n")).toString(), tuple -> ((Number) tuple.get("s")).intValue()));
|
||||
|
||||
//String ans = em.createQuery("SELECT f.favorName, sum(off.amount) * f.price from Order_Favor off join off.Favor_id f join off.Order_id o where o.date > '2023-02-01' and o.date < '2023-03-01' group by f.favorName").getResultList().toString();
|
||||
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user