parent
7441346137
commit
945a1ab3e4
@ -1,38 +0,0 @@
|
|||||||
package com.example.demo.searchService.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.example.demo.bean.Product;
|
|
||||||
import com.example.demo.searchService.service.ProductSearchService;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class SearchServiceController {
|
|
||||||
private ProductSearchService productSearchService;
|
|
||||||
@RequestMapping("/search")
|
|
||||||
public List<Product> productSearch(HttpServletRequest request, HttpServletResponse response){
|
|
||||||
List<Product> list = new ArrayList<Product>();
|
|
||||||
String productName = request.getParameter("productName");
|
|
||||||
String category = request.getParameter("category");
|
|
||||||
float intrate = Integer.parseInt(request.getParameter("intrate"));
|
|
||||||
if(productName!=null){
|
|
||||||
list = productSearchService.findByNameLike(productName);
|
|
||||||
//按关键字搜索
|
|
||||||
}else if(category!=null){
|
|
||||||
list = productSearchService.findByCategory(category);
|
|
||||||
//按产品类别搜索
|
|
||||||
}else if(intrate!=0){
|
|
||||||
list = productSearchService.findByIntrate(intrate);
|
|
||||||
//按利率排序由低到高
|
|
||||||
}else{
|
|
||||||
list = productSearchService.findByCount();
|
|
||||||
//默认按产品使用的产品的数量由高到低排序
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
package com.example.demo.searchService.service;
|
|
||||||
|
|
||||||
import com.example.demo.bean.Product;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ProductSearchService {
|
|
||||||
//按关键字查询
|
|
||||||
List<Product> findByNameLike(String productName);
|
|
||||||
|
|
||||||
//按类别查询
|
|
||||||
List<Product> findByCategory(String category);
|
|
||||||
|
|
||||||
//按利率从高到低
|
|
||||||
List<Product> findByIntrate(float intrate);
|
|
||||||
|
|
||||||
////默认按产品使用的产品的数量由高到低排序
|
|
||||||
List<Product> findByCount();
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
package com.example.demo.searchService.service.impl;
|
|
||||||
|
|
||||||
import com.example.demo.Dao.productMapper;
|
|
||||||
import com.example.demo.Dao.usageDateMapper;
|
|
||||||
import com.example.demo.bean.Product;
|
|
||||||
import com.example.demo.searchService.service.ProductSearchService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ProductSearchServiceImpl implements ProductSearchService {
|
|
||||||
@Autowired
|
|
||||||
productMapper productMapper;
|
|
||||||
usageDateMapper usageDateMapper;
|
|
||||||
Product product;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Product> findByNameLike(String productName){
|
|
||||||
return productMapper.findByNameLike(productName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Product> findByCategory(String category){
|
|
||||||
return productMapper.findByCategory(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Product> findByIntrate(float intrate){
|
|
||||||
return productMapper.findByIntrate(intrate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Product> findByCount(){
|
|
||||||
List<Product> productList = new ArrayList<Product>();
|
|
||||||
List<Integer> listusage = usageDateMapper.selectByCount();
|
|
||||||
int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray();
|
|
||||||
for(int i=0;i<arr.length;i++){
|
|
||||||
product = productMapper.selectProductByProductNum(arr[i]);
|
|
||||||
productList.add(product);
|
|
||||||
}
|
|
||||||
return productList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in new issue