SHARE
TWEET

Untitled

a guest Jan 17th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.nano.shoppingonline2.controller;
  7.  
  8. import com.nano.shoppingonline2.entity.Category;
  9. import com.nano.shoppingonline2.entity.Report;
  10. import com.nano.shoppingonline2.repository.CategoryRepository;
  11. import com.nano.shoppingonline2.repository.ProductRepository;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.ui.ModelMap;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RequestMethod;
  19. import org.springframework.web.servlet.ModelAndView;
  20.  
  21. /**
  22.  *
  23.  * @author JunBu
  24.  */
  25. @Controller
  26. @RequestMapping("report")
  27. public class ReportController {
  28.  
  29.     @Autowired
  30.     private CategoryRepository categoryRepository;
  31.     @Autowired
  32.     private ProductRepository productRepository;
  33.  
  34.     @RequestMapping(value = "sanphamdanhmuc", method = RequestMethod.GET)
  35.     public ModelAndView getProductReport(ModelMap model) {
  36.  
  37.         List<Category> listCate = categoryRepository.findAll();
  38.         List<Report> listReportItem = new ArrayList<Report>();
  39.  
  40.         for (Category c : listCate) {
  41.             Integer countProduct = productRepository.countProductWithCate(c.getId());
  42.             Double sum = productRepository.sumPriceProduct(c.getId());
  43.             Double max = productRepository.maxPriceProduct(c.getId());
  44.             Double min = productRepository.minPriceProduct(c.getId());
  45.             Double avg = productRepository.avgPriceProduct(c.getId());
  46.  
  47.             if (countProduct == null) {
  48.                 countProduct = 0;
  49.             }
  50.            
  51.             if(sum == null){
  52.                 sum = 0.0;
  53.             }
  54.            
  55.             if(max == null){
  56.                 max = 0.0;
  57.             }
  58.            
  59.             if(min == null){
  60.                 min = 0.0;
  61.             }
  62.            
  63.             if(avg == null){
  64.                 avg = 0.0;
  65.             }
  66.  
  67.             Report report = new Report();
  68.             report.setGroup(c.getName());
  69.             report.setCount(countProduct);
  70.             report.setSum(sum);
  71.             report.setMin(min);
  72.             report.setMax(max);
  73.             report.setAvg(avg);
  74.  
  75.             listReportItem.add(report);
  76.  
  77.         }
  78.  
  79.         return new ModelAndView("/report/sanphamdanhmuc", "listReportItem", listReportItem);
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top